From c6c02efb56b24df04ed9ab61252c14c7bddcca93 Mon Sep 17 00:00:00 2001 From: Artem Titov Date: Mon, 9 May 2022 08:30:09 +0000 Subject: [PATCH] Revert "Don't create channel_manager when media_engine is not set" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit c48ad732d6eb69f14dd6d44f801d62997cef2c2f. Reason for revert: breaks downstream project Original change's description: > Don't create channel_manager when media_engine is not set > > Also remove a bunch of functions in ChannelManager that were just > forwarding to MediaEngineInterface. > > Bug: webrtc:13931 > Change-Id: Ia38591fd22c665cace16d032f5c1e384e413cded > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/261304 > Reviewed-by: Tomas Gunnarsson > Reviewed-by: Henrik Boström > Commit-Queue: Harald Alvestrand > Cr-Commit-Position: refs/heads/main@{#36801} Bug: webrtc:13931 Change-Id: I1e260a2489547bd9483b50e043c28d2805b0fa5a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/261660 Commit-Queue: Artem Titov Reviewed-by: Harald Alvestrand Owners-Override: Artem Titov Bot-Commit: rubber-stamper@appspot.gserviceaccount.com Cr-Commit-Position: refs/heads/main@{#36811} --- pc/BUILD.gn | 1 - pc/channel_manager.cc | 50 ++- pc/channel_manager.h | 13 +- pc/connection_context.cc | 8 +- pc/media_session.cc | 41 +- pc/media_session.h | 10 +- pc/peer_connection.cc | 111 ++--- pc/peer_connection.h | 4 - pc/peer_connection_factory.cc | 14 +- pc/peer_connection_factory.h | 2 - pc/rtp_transceiver.cc | 11 +- pc/rtp_transceiver.h | 2 - pc/rtp_transceiver_unittest.cc | 2 +- pc/rtp_transmission_manager.cc | 8 +- pc/rtp_transmission_manager.h | 2 - pc/sdp_offer_answer.cc | 534 ++++++++++------------- pc/sdp_offer_answer.h | 4 +- pc/test/fake_peer_connection_for_stats.h | 5 +- 18 files changed, 377 insertions(+), 445 deletions(-) diff --git a/pc/BUILD.gn b/pc/BUILD.gn index 4796de3e2d..1edbd24502 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -377,7 +377,6 @@ rtc_source_set("media_session") { "../rtc_base:checks", "../rtc_base:logging", "../rtc_base:stringutils", - "../rtc_base/memory:always_valid_pointer", "../rtc_base/third_party/base64", ] absl_deps = [ diff --git a/pc/channel_manager.cc b/pc/channel_manager.cc index 9ee2bca4d0..e13db54806 100644 --- a/pc/channel_manager.cc +++ b/pc/channel_manager.cc @@ -31,7 +31,6 @@ std::unique_ptr ChannelManager::Create( bool enable_rtx, rtc::Thread* worker_thread, rtc::Thread* network_thread) { - RTC_CHECK(media_engine); RTC_DCHECK(network_thread); RTC_DCHECK(worker_thread); @@ -52,11 +51,12 @@ ChannelManager::ChannelManager( RTC_DCHECK_RUN_ON(signaling_thread_); RTC_DCHECK(worker_thread_); RTC_DCHECK(network_thread_); - RTC_CHECK(media_engine_); - // TODO(tommi): Change VoiceEngine to do ctor time initialization so that - // this isn't necessary. - worker_thread_->Invoke(RTC_FROM_HERE, [&] { media_engine_->Init(); }); + if (media_engine_) { + // TODO(tommi): Change VoiceEngine to do ctor time initialization so that + // this isn't necessary. + worker_thread_->Invoke(RTC_FROM_HERE, [&] { media_engine_->Init(); }); + } } ChannelManager::~ChannelManager() { @@ -71,8 +71,27 @@ ChannelManager::~ChannelManager() { }); } +void ChannelManager::GetSupportedAudioSendCodecs( + std::vector* codecs) const { + if (!media_engine_) { + return; + } + *codecs = media_engine_->voice().send_codecs(); +} + +void ChannelManager::GetSupportedAudioReceiveCodecs( + std::vector* codecs) const { + if (!media_engine_) { + return; + } + *codecs = media_engine_->voice().recv_codecs(); +} + void ChannelManager::GetSupportedVideoSendCodecs( std::vector* codecs) const { + if (!media_engine_) { + return; + } codecs->clear(); std::vector video_codecs = media_engine_->video().send_codecs(); @@ -87,6 +106,9 @@ void ChannelManager::GetSupportedVideoSendCodecs( void ChannelManager::GetSupportedVideoReceiveCodecs( std::vector* codecs) const { + if (!media_engine_) { + return; + } codecs->clear(); std::vector video_codecs = media_engine_->video().recv_codecs(); @@ -101,14 +123,32 @@ void ChannelManager::GetSupportedVideoReceiveCodecs( RtpHeaderExtensions ChannelManager::GetDefaultEnabledAudioRtpHeaderExtensions() const { + if (!media_engine_) + return {}; return GetDefaultEnabledRtpHeaderExtensions(media_engine_->voice()); } +std::vector +ChannelManager::GetSupportedAudioRtpHeaderExtensions() const { + if (!media_engine_) + return {}; + return media_engine_->voice().GetRtpHeaderExtensions(); +} + RtpHeaderExtensions ChannelManager::GetDefaultEnabledVideoRtpHeaderExtensions() const { + if (!media_engine_) + return {}; return GetDefaultEnabledRtpHeaderExtensions(media_engine_->video()); } +std::vector +ChannelManager::GetSupportedVideoRtpHeaderExtensions() const { + if (!media_engine_) + return {}; + return media_engine_->video().GetRtpHeaderExtensions(); +} + std::unique_ptr ChannelManager::CreateVoiceChannel( webrtc::Call* call, const MediaConfig& media_config, diff --git a/pc/channel_manager.h b/pc/channel_manager.h index 23adac3b5c..8d1ec28001 100644 --- a/pc/channel_manager.h +++ b/pc/channel_manager.h @@ -47,7 +47,7 @@ namespace cricket { class ChannelManager : public ChannelFactoryInterface { public: // Returns an initialized instance of ChannelManager. - // `media_engine` cannot be null. The returned ChannelManager instance + // If media_engine is non-nullptr, then the returned ChannelManager instance // will own that reference and media engine initialization static std::unique_ptr Create( std::unique_ptr media_engine, @@ -63,11 +63,18 @@ class ChannelManager : public ChannelFactoryInterface { MediaEngineInterface* media_engine() { return media_engine_.get(); } rtc::UniqueRandomIdGenerator& ssrc_generator() { return ssrc_generator_; } - // Retrieves the list of supported video codec types. + // Retrieves the list of supported audio & video codec types. + // Can be called before starting the media engine. + void GetSupportedAudioSendCodecs(std::vector* codecs) const; + void GetSupportedAudioReceiveCodecs(std::vector* codecs) const; void GetSupportedVideoSendCodecs(std::vector* codecs) const; void GetSupportedVideoReceiveCodecs(std::vector* codecs) const; RtpHeaderExtensions GetDefaultEnabledAudioRtpHeaderExtensions() const; + std::vector + GetSupportedAudioRtpHeaderExtensions() const; RtpHeaderExtensions GetDefaultEnabledVideoRtpHeaderExtensions() const; + std::vector + GetSupportedVideoRtpHeaderExtensions() const; // The operations below all occur on the worker thread. // The caller is responsible for ensuring that destruction happens @@ -116,7 +123,7 @@ class ChannelManager : public ChannelFactoryInterface { void DestroyVideoChannel(VideoChannel* video_channel); private: - const std::unique_ptr media_engine_; + const std::unique_ptr media_engine_; // Nullable. rtc::Thread* const signaling_thread_; rtc::Thread* const worker_thread_; rtc::Thread* const network_thread_; diff --git a/pc/connection_context.cc b/pc/connection_context.cc index e2e066665c..818283d636 100644 --- a/pc/connection_context.cc +++ b/pc/connection_context.cc @@ -144,11 +144,9 @@ ConnectionContext::ConnectionContext( default_socket_factory_ = std::make_unique(socket_factory); - if (dependencies->media_engine) { - channel_manager_ = cricket::ChannelManager::Create( - std::move(dependencies->media_engine), - /*enable_rtx=*/true, worker_thread(), network_thread()); - } + channel_manager_ = cricket::ChannelManager::Create( + std::move(dependencies->media_engine), + /*enable_rtx=*/true, worker_thread(), network_thread()); // Set warning levels on the threads, to give warnings when response // may be slower than is expected of the thread. diff --git a/pc/media_session.cc b/pc/media_session.cc index 91a0b88dd0..71a6d0a19c 100644 --- a/pc/media_session.cc +++ b/pc/media_session.cc @@ -1557,22 +1557,21 @@ MediaSessionDescriptionFactory::MediaSessionDescriptionFactory( const TransportDescriptionFactory* transport_desc_factory, rtc::UniqueRandomIdGenerator* ssrc_generator) : ssrc_generator_(ssrc_generator), - transport_desc_factory_(transport_desc_factory) {} + transport_desc_factory_(transport_desc_factory) { + RTC_DCHECK(ssrc_generator_); +} MediaSessionDescriptionFactory::MediaSessionDescriptionFactory( ChannelManager* channel_manager, const TransportDescriptionFactory* transport_desc_factory) - : MediaSessionDescriptionFactory( - transport_desc_factory, - channel_manager ? &channel_manager->ssrc_generator() : nullptr) { - if (channel_manager) { - audio_send_codecs_ = channel_manager->media_engine()->voice().send_codecs(); - audio_recv_codecs_ = channel_manager->media_engine()->voice().recv_codecs(); - channel_manager->GetSupportedVideoSendCodecs(&video_send_codecs_); - channel_manager->GetSupportedVideoReceiveCodecs(&video_recv_codecs_); - ComputeAudioCodecsIntersectionAndUnion(); - ComputeVideoCodecsIntersectionAndUnion(); - } + : MediaSessionDescriptionFactory(transport_desc_factory, + &channel_manager->ssrc_generator()) { + channel_manager->GetSupportedAudioSendCodecs(&audio_send_codecs_); + channel_manager->GetSupportedAudioReceiveCodecs(&audio_recv_codecs_); + channel_manager->GetSupportedVideoSendCodecs(&video_send_codecs_); + channel_manager->GetSupportedVideoReceiveCodecs(&video_recv_codecs_); + ComputeAudioCodecsIntersectionAndUnion(); + ComputeVideoCodecsIntersectionAndUnion(); } const AudioCodecs& MediaSessionDescriptionFactory::audio_sendrecv_codecs() @@ -2355,7 +2354,7 @@ bool MediaSessionDescriptionFactory::AddAudioContentForOffer( if (!CreateMediaContentOffer( media_description_options, session_options, filtered_codecs, sdes_policy, GetCryptos(current_content), crypto_suites, - audio_rtp_extensions, ssrc_generator(), current_streams, audio.get(), + audio_rtp_extensions, ssrc_generator_, current_streams, audio.get(), transport_desc_factory_->trials())) { return false; } @@ -2467,7 +2466,7 @@ bool MediaSessionDescriptionFactory::AddVideoContentForOffer( if (!CreateMediaContentOffer( media_description_options, session_options, filtered_codecs, sdes_policy, GetCryptos(current_content), crypto_suites, - video_rtp_extensions, ssrc_generator(), current_streams, video.get(), + video_rtp_extensions, ssrc_generator_, current_streams, video.get(), transport_desc_factory_->trials())) { return false; } @@ -2520,8 +2519,8 @@ bool MediaSessionDescriptionFactory::AddDataContentForOffer( if (!CreateContentOffer(media_description_options, session_options, sdes_policy, GetCryptos(current_content), - crypto_suites, RtpHeaderExtensions(), - ssrc_generator(), current_streams, data.get())) { + crypto_suites, RtpHeaderExtensions(), ssrc_generator_, + current_streams, data.get())) { return false; } @@ -2655,7 +2654,7 @@ bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( audio_transport->secure() ? cricket::SEC_DISABLED : secure(); if (!SetCodecsInAnswer(offer_audio_description, filtered_codecs, media_description_options, session_options, - ssrc_generator(), current_streams, audio_answer.get(), + ssrc_generator_, current_streams, audio_answer.get(), transport_desc_factory_->trials())) { return false; } @@ -2663,7 +2662,7 @@ bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( offer_audio_description, media_description_options, session_options, sdes_policy, GetCryptos(current_content), filtered_rtp_header_extensions(default_audio_rtp_header_extensions), - ssrc_generator(), enable_encrypted_rtp_header_extensions_, + ssrc_generator_, enable_encrypted_rtp_header_extensions_, current_streams, bundle_enabled, audio_answer.get())) { return false; // Fails the session setup. } @@ -2784,7 +2783,7 @@ bool MediaSessionDescriptionFactory::AddVideoContentForAnswer( video_transport->secure() ? cricket::SEC_DISABLED : secure(); if (!SetCodecsInAnswer(offer_video_description, filtered_codecs, media_description_options, session_options, - ssrc_generator(), current_streams, video_answer.get(), + ssrc_generator_, current_streams, video_answer.get(), transport_desc_factory_->trials())) { return false; } @@ -2792,7 +2791,7 @@ bool MediaSessionDescriptionFactory::AddVideoContentForAnswer( offer_video_description, media_description_options, session_options, sdes_policy, GetCryptos(current_content), filtered_rtp_header_extensions(default_video_rtp_header_extensions), - ssrc_generator(), enable_encrypted_rtp_header_extensions_, + ssrc_generator_, enable_encrypted_rtp_header_extensions_, current_streams, bundle_enabled, video_answer.get())) { return false; // Failed the sessin setup. } @@ -2865,7 +2864,7 @@ bool MediaSessionDescriptionFactory::AddDataContentForAnswer( if (!CreateMediaContentAnswer( offer_data_description, media_description_options, session_options, sdes_policy, GetCryptos(current_content), RtpHeaderExtensions(), - ssrc_generator(), enable_encrypted_rtp_header_extensions_, + ssrc_generator_, enable_encrypted_rtp_header_extensions_, current_streams, bundle_enabled, data_answer.get())) { return false; // Fails the session setup. } diff --git a/pc/media_session.h b/pc/media_session.h index 8f97538e77..9a67ad1e3c 100644 --- a/pc/media_session.h +++ b/pc/media_session.h @@ -34,7 +34,6 @@ #include "pc/media_protocol_names.h" #include "pc/session_description.h" #include "pc/simulcast_description.h" -#include "rtc_base/memory/always_valid_pointer.h" #include "rtc_base/unique_id_generator.h" namespace webrtc { @@ -329,10 +328,6 @@ class MediaSessionDescriptionFactory { void ComputeVideoCodecsIntersectionAndUnion(); - rtc::UniqueRandomIdGenerator* ssrc_generator() const { - return ssrc_generator_.get(); - } - bool is_unified_plan_ = false; AudioCodecs audio_send_codecs_; AudioCodecs audio_recv_codecs_; @@ -346,9 +341,8 @@ class MediaSessionDescriptionFactory { VideoCodecs video_sendrecv_codecs_; // Union of send and recv. VideoCodecs all_video_codecs_; - // This object may or may not be owned by this class. - webrtc::AlwaysValidPointer const - ssrc_generator_; + // This object is not owned by the channel so it must outlive it. + rtc::UniqueRandomIdGenerator* const ssrc_generator_; bool enable_encrypted_rtp_header_extensions_ = false; // TODO(zhihuang): Rename secure_ to sdec_policy_; rename the related getter // and setter. diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index c139d0ad9d..f914fc8365 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -646,27 +646,25 @@ RTCError PeerConnection::Initialize( sdp_handler_ = SdpOfferAnswerHandler::Create(this, configuration, dependencies, context_.get()); - if (ConfiguredForMedia()) { - rtp_manager_ = std::make_unique( - IsUnifiedPlan(), signaling_thread(), worker_thread(), channel_manager(), - &usage_pattern_, observer_, stats_.get(), [this]() { - RTC_DCHECK_RUN_ON(signaling_thread()); - sdp_handler_->UpdateNegotiationNeeded(); - }); + rtp_manager_ = std::make_unique( + IsUnifiedPlan(), signaling_thread(), worker_thread(), channel_manager(), + &usage_pattern_, observer_, stats_.get(), [this]() { + RTC_DCHECK_RUN_ON(signaling_thread()); + sdp_handler_->UpdateNegotiationNeeded(); + }); - // Add default audio/video transceivers for Plan B SDP. - if (!IsUnifiedPlan()) { - rtp_manager()->transceivers()->Add( - RtpTransceiverProxyWithInternal::Create( - signaling_thread(), - rtc::make_ref_counted(cricket::MEDIA_TYPE_AUDIO, - channel_manager()))); - rtp_manager()->transceivers()->Add( - RtpTransceiverProxyWithInternal::Create( - signaling_thread(), - rtc::make_ref_counted(cricket::MEDIA_TYPE_VIDEO, - channel_manager()))); - } + // Add default audio/video transceivers for Plan B SDP. + if (!IsUnifiedPlan()) { + rtp_manager()->transceivers()->Add( + RtpTransceiverProxyWithInternal::Create( + signaling_thread(), + rtc::make_ref_counted(cricket::MEDIA_TYPE_AUDIO, + channel_manager()))); + rtp_manager()->transceivers()->Add( + RtpTransceiverProxyWithInternal::Create( + signaling_thread(), + rtc::make_ref_counted(cricket::MEDIA_TYPE_VIDEO, + channel_manager()))); } int delay_ms = configuration.report_usage_pattern_delay_ms @@ -1180,10 +1178,8 @@ std::vector> PeerConnection::GetSenders() const { RTC_DCHECK_RUN_ON(signaling_thread()); std::vector> ret; - if (ConfiguredForMedia()) { - for (const auto& sender : rtp_manager()->GetSendersInternal()) { - ret.push_back(sender); - } + for (const auto& sender : rtp_manager()->GetSendersInternal()) { + ret.push_back(sender); } return ret; } @@ -1192,10 +1188,8 @@ std::vector> PeerConnection::GetReceivers() const { RTC_DCHECK_RUN_ON(signaling_thread()); std::vector> ret; - if (ConfiguredForMedia()) { - for (const auto& receiver : rtp_manager()->GetReceiversInternal()) { - ret.push_back(receiver); - } + for (const auto& receiver : rtp_manager()->GetReceiversInternal()) { + ret.push_back(receiver); } return ret; } @@ -1206,10 +1200,8 @@ PeerConnection::GetTransceivers() const { RTC_CHECK(IsUnifiedPlan()) << "GetTransceivers is only supported with Unified Plan SdpSemantics."; std::vector> all_transceivers; - if (ConfiguredForMedia()) { - for (const auto& transceiver : rtp_manager()->transceivers()->List()) { - all_transceivers.push_back(transceiver); - } + for (const auto& transceiver : rtp_manager()->transceivers()->List()) { + all_transceivers.push_back(transceiver); } return all_transceivers; } @@ -1688,7 +1680,8 @@ void PeerConnection::SetAudioPlayout(bool playout) { RTC_FROM_HERE, [this, playout] { SetAudioPlayout(playout); }); return; } - auto audio_state = media_engine()->voice().GetAudioState(); + auto audio_state = + context_->channel_manager()->media_engine()->voice().GetAudioState(); audio_state->SetPlayout(playout); } @@ -1698,7 +1691,8 @@ void PeerConnection::SetAudioRecording(bool recording) { RTC_FROM_HERE, [this, recording] { SetAudioRecording(recording); }); return; } - auto audio_state = media_engine()->voice().GetAudioState(); + auto audio_state = + context_->channel_manager()->media_engine()->voice().GetAudioState(); audio_state->SetRecording(recording); } @@ -1718,7 +1712,7 @@ void PeerConnection::AddAdaptationResource( } bool PeerConnection::ConfiguredForMedia() const { - return context_->channel_manager(); + return context_->channel_manager()->media_engine(); } bool PeerConnection::StartRtcEventLog(std::unique_ptr output, @@ -1828,13 +1822,12 @@ void PeerConnection::Close() { NoteUsageEvent(UsageEvent::CLOSE_CALLED); - if (ConfiguredForMedia()) { - for (const auto& transceiver : rtp_manager()->transceivers()->List()) { - transceiver->internal()->SetPeerConnectionClosed(); - if (!transceiver->stopped()) - transceiver->StopInternal(); - } + for (const auto& transceiver : rtp_manager()->transceivers()->List()) { + transceiver->internal()->SetPeerConnectionClosed(); + if (!transceiver->stopped()) + transceiver->StopInternal(); } + // Ensure that all asynchronous stats requests are completed before destroying // the transport controller below. if (stats_collector_) { @@ -1851,9 +1844,7 @@ void PeerConnection::Close() { // WebRTC session description factory, the session description factory would // call the transport controller. sdp_handler_->ResetSessionDescFactory(); - if (ConfiguredForMedia()) { - rtp_manager_->Close(); - } + rtp_manager_->Close(); network_thread()->Invoke(RTC_FROM_HERE, [this] { // Data channels will already have been unset via the DestroyAllChannels() @@ -2744,15 +2735,12 @@ void PeerConnection::ReportTransportStats() { rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; std::map> media_types_by_transport_name; - if (ConfiguredForMedia()) { - for (const auto& transceiver : - rtp_manager()->transceivers()->UnsafeList()) { - if (transceiver->internal()->channel()) { - std::string transport_name( - transceiver->internal()->channel()->transport_name()); - media_types_by_transport_name[transport_name].insert( - transceiver->media_type()); - } + for (const auto& transceiver : rtp_manager()->transceivers()->UnsafeList()) { + if (transceiver->internal()->channel()) { + std::string transport_name( + transceiver->internal()->channel()->transport_name()); + media_types_by_transport_name[transport_name].insert( + transceiver->media_type()); } } @@ -2900,13 +2888,10 @@ bool PeerConnection::OnTransportChanged( DataChannelTransportInterface* data_channel_transport) { RTC_DCHECK_RUN_ON(network_thread()); bool ret = true; - if (ConfiguredForMedia()) { - for (const auto& transceiver : - rtp_manager()->transceivers()->UnsafeList()) { - cricket::ChannelInterface* channel = transceiver->internal()->channel(); - if (channel && channel->mid() == mid) { - ret = channel->SetRtpTransport(rtp_transport); - } + for (const auto& transceiver : rtp_manager()->transceivers()->UnsafeList()) { + cricket::ChannelInterface* channel = transceiver->internal()->channel(); + if (channel && channel->mid() == mid) { + ret = channel->SetRtpTransport(rtp_transport); } } @@ -2991,10 +2976,4 @@ PeerConnection::InitializeRtcpCallback() { }; } -cricket::MediaEngineInterface* PeerConnection::media_engine() { - RTC_DCHECK(context_); - RTC_DCHECK(context_->channel_manager()); - return context_->channel_manager()->media_engine(); -} - } // namespace webrtc diff --git a/pc/peer_connection.h b/pc/peer_connection.h index 8c578d59e2..2907cb565b 100644 --- a/pc/peer_connection.h +++ b/pc/peer_connection.h @@ -273,9 +273,6 @@ class PeerConnection : public PeerConnectionInternal, rtc::scoped_refptr>> GetTransceiversInternal() const override { RTC_DCHECK_RUN_ON(signaling_thread()); - if (!ConfiguredForMedia()) { - return {}; - } return rtp_manager()->transceivers()->List(); } @@ -599,7 +596,6 @@ class PeerConnection : public PeerConnectionInternal, cricket::ChannelManager* channel_manager() { return context_->channel_manager(); } - cricket::MediaEngineInterface* media_engine(); const rtc::scoped_refptr context_; // Field trials active for this PeerConnection is the first of: diff --git a/pc/peer_connection_factory.cc b/pc/peer_connection_factory.cc index 33803580de..6e6a72ced8 100644 --- a/pc/peer_connection_factory.cc +++ b/pc/peer_connection_factory.cc @@ -129,14 +129,14 @@ RtpCapabilities PeerConnectionFactory::GetRtpSenderCapabilities( switch (kind) { case cricket::MEDIA_TYPE_AUDIO: { cricket::AudioCodecs cricket_codecs; - cricket_codecs = media_engine()->voice().send_codecs(); + channel_manager()->GetSupportedAudioSendCodecs(&cricket_codecs); return ToRtpCapabilities( cricket_codecs, channel_manager()->GetDefaultEnabledAudioRtpHeaderExtensions()); } case cricket::MEDIA_TYPE_VIDEO: { cricket::VideoCodecs cricket_codecs; - cricket_codecs = media_engine()->video().send_codecs(); + channel_manager()->GetSupportedVideoSendCodecs(&cricket_codecs); return ToRtpCapabilities( cricket_codecs, channel_manager()->GetDefaultEnabledVideoRtpHeaderExtensions()); @@ -156,7 +156,7 @@ RtpCapabilities PeerConnectionFactory::GetRtpReceiverCapabilities( switch (kind) { case cricket::MEDIA_TYPE_AUDIO: { cricket::AudioCodecs cricket_codecs; - cricket_codecs = media_engine()->voice().recv_codecs(); + channel_manager()->GetSupportedAudioReceiveCodecs(&cricket_codecs); return ToRtpCapabilities( cricket_codecs, channel_manager()->GetDefaultEnabledAudioRtpHeaderExtensions()); @@ -195,12 +195,6 @@ void PeerConnectionFactory::StopAecDump() { channel_manager()->StopAecDump(); } -cricket::MediaEngineInterface* PeerConnectionFactory::media_engine() const { - RTC_DCHECK(context_); - RTC_DCHECK(context_->channel_manager()); - return context_->channel_manager()->media_engine(); -} - RTCErrorOr> PeerConnectionFactory::CreatePeerConnectionOrError( const PeerConnectionInterface::RTCConfiguration& configuration, @@ -318,7 +312,7 @@ std::unique_ptr PeerConnectionFactory::CreateCall_w( RTC_DCHECK_RUN_ON(worker_thread()); webrtc::Call::Config call_config(event_log, network_thread()); - if (!channel_manager() || !context_->call_factory()) { + if (!channel_manager()->media_engine() || !context_->call_factory()) { return nullptr; } call_config.audio_state = diff --git a/pc/peer_connection_factory.h b/pc/peer_connection_factory.h index 917f054fd9..ff3d515964 100644 --- a/pc/peer_connection_factory.h +++ b/pc/peer_connection_factory.h @@ -120,8 +120,6 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface { return context_->field_trials(); } - cricket::MediaEngineInterface* media_engine() const; - protected: // Constructor used by the static Create() method. Modifies the dependencies. PeerConnectionFactory(rtc::scoped_refptr context, diff --git a/pc/rtp_transceiver.cc b/pc/rtp_transceiver.cc index 1f6f879942..caa9ba5d64 100644 --- a/pc/rtp_transceiver.cc +++ b/pc/rtp_transceiver.cc @@ -22,7 +22,6 @@ #include "api/sequence_checker.h" #include "media/base/codec.h" #include "media/base/media_constants.h" -#include "media/base/media_engine.h" #include "pc/channel.h" #include "pc/channel_manager.h" #include "pc/rtp_media_utils.h" @@ -563,6 +562,7 @@ void RtpTransceiver::StopTransceiverProcedure() { RTCError RtpTransceiver::SetCodecPreferences( rtc::ArrayView codec_capabilities) { RTC_DCHECK(unified_plan_); + // 3. If codecs is an empty list, set transceiver's [[PreferredCodecs]] slot // to codecs and abort these steps. if (codec_capabilities.empty()) { @@ -581,14 +581,15 @@ RTCError RtpTransceiver::SetCodecPreferences( RTCError result; if (media_type_ == cricket::MEDIA_TYPE_AUDIO) { std::vector recv_codecs, send_codecs; - recv_codecs = media_engine()->voice().recv_codecs(); - send_codecs = media_engine()->voice().send_codecs(); + channel_manager_->GetSupportedAudioReceiveCodecs(&recv_codecs); + channel_manager_->GetSupportedAudioSendCodecs(&send_codecs); result = VerifyCodecPreferences(codecs, send_codecs, recv_codecs); } else if (media_type_ == cricket::MEDIA_TYPE_VIDEO) { std::vector recv_codecs, send_codecs; channel_manager_->GetSupportedVideoReceiveCodecs(&recv_codecs); channel_manager_->GetSupportedVideoSendCodecs(&send_codecs); + result = VerifyCodecPreferences(codecs, send_codecs, recv_codecs); } @@ -671,8 +672,4 @@ void RtpTransceiver::SetPeerConnectionClosed() { is_pc_closed_ = true; } -cricket::MediaEngineInterface* RtpTransceiver::media_engine() const { - return channel_manager_->media_engine(); -} - } // namespace webrtc diff --git a/pc/rtp_transceiver.h b/pc/rtp_transceiver.h index bbcbf2399c..b61ca752d1 100644 --- a/pc/rtp_transceiver.h +++ b/pc/rtp_transceiver.h @@ -47,7 +47,6 @@ namespace cricket { class ChannelManager; -class MediaEngineInterface; } namespace webrtc { @@ -339,7 +338,6 @@ class RtpTransceiver : public RtpTransceiverInterface, RTC_GUARDED_BY(thread_); const std::function on_negotiation_needed_; - cricket::MediaEngineInterface* media_engine() const; }; BEGIN_PRIMARY_PROXY_MAP(RtpTransceiver) diff --git a/pc/rtp_transceiver_unittest.cc b/pc/rtp_transceiver_unittest.cc index 3c4b2c93e4..ce2eefc974 100644 --- a/pc/rtp_transceiver_unittest.cc +++ b/pc/rtp_transceiver_unittest.cc @@ -126,7 +126,7 @@ class RtpTransceiverUnifiedPlanTest : public ::testing::Test { rtc::Thread::Current(), receiver_), &channel_manager_, - channel_manager_.media_engine()->voice().GetRtpHeaderExtensions(), + channel_manager_.GetSupportedAudioRtpHeaderExtensions(), /* on_negotiation_needed= */ [] {})) {} static rtc::scoped_refptr MockReceiver() { diff --git a/pc/rtp_transmission_manager.cc b/pc/rtp_transmission_manager.cc index b2520d58be..6939a07dec 100644 --- a/pc/rtp_transmission_manager.cc +++ b/pc/rtp_transmission_manager.cc @@ -273,8 +273,8 @@ RtpTransmissionManager::CreateAndAddTransceiver( rtc::make_ref_counted( sender, receiver, channel_manager(), sender->media_type() == cricket::MEDIA_TYPE_AUDIO - ? media_engine()->voice().GetRtpHeaderExtensions() - : media_engine()->video().GetRtpHeaderExtensions(), + ? channel_manager()->GetSupportedAudioRtpHeaderExtensions() + : channel_manager()->GetSupportedVideoRtpHeaderExtensions(), [this_weak_ptr = weak_ptr_factory_.GetWeakPtr()]() { if (this_weak_ptr) { this_weak_ptr->OnNegotiationNeeded(); @@ -690,8 +690,4 @@ RtpTransmissionManager::FindReceiverById(const std::string& receiver_id) const { return nullptr; } -cricket::MediaEngineInterface* RtpTransmissionManager::media_engine() const { - return channel_manager()->media_engine(); -} - } // namespace webrtc diff --git a/pc/rtp_transmission_manager.h b/pc/rtp_transmission_manager.h index 532adcfbfd..6e25f2d9b7 100644 --- a/pc/rtp_transmission_manager.h +++ b/pc/rtp_transmission_manager.h @@ -244,8 +244,6 @@ class RtpTransmissionManager : public RtpSenderBase::SetStreamsObserver { PeerConnectionObserver* Observer() const; void OnNegotiationNeeded(); - cricket::MediaEngineInterface* media_engine() const; - TransceiverList transceivers_; // These lists store sender info seen in local/remote descriptions. diff --git a/pc/sdp_offer_answer.cc b/pc/sdp_offer_answer.cc index 95f22b79f9..1d34081bce 100644 --- a/pc/sdp_offer_answer.cc +++ b/pc/sdp_offer_answer.cc @@ -1258,17 +1258,10 @@ void SdpOfferAnswerHandler::Initialize( } // ================================================================== -// Access to pc_ and context_ variables +// Access to pc_ variables cricket::ChannelManager* SdpOfferAnswerHandler::channel_manager() const { return context_->channel_manager(); } - -cricket::MediaEngineInterface* SdpOfferAnswerHandler::media_engine() const { - RTC_DCHECK(context_); - RTC_DCHECK(context_->channel_manager()); - return context_->channel_manager()->media_engine(); -} - TransceiverList* SdpOfferAnswerHandler::transceivers() { if (!pc_->rtp_manager()) { return nullptr; @@ -1564,60 +1557,56 @@ RTCError SdpOfferAnswerHandler::ApplyLocalDescription( << ")"; return error; } - if (ConfiguredForMedia()) { - std::vector> remove_list; - std::vector> removed_streams; - for (const auto& transceiver_ext : transceivers()->List()) { - auto transceiver = transceiver_ext->internal(); - if (transceiver->stopped()) { - continue; - } + std::vector> remove_list; + std::vector> removed_streams; + for (const auto& transceiver_ext : transceivers()->List()) { + auto transceiver = transceiver_ext->internal(); + if (transceiver->stopped()) { + continue; + } - // 2.2.7.1.1.(6-9): Set sender and receiver's transport slots. - // Note that code paths that don't set MID won't be able to use - // information about DTLS transports. - if (transceiver->mid()) { - auto dtls_transport = LookupDtlsTransportByMid( - context_->network_thread(), transport_controller_s(), - *transceiver->mid()); - transceiver->sender_internal()->set_transport(dtls_transport); - transceiver->receiver_internal()->set_transport(dtls_transport); - } + // 2.2.7.1.1.(6-9): Set sender and receiver's transport slots. + // Note that code paths that don't set MID won't be able to use + // information about DTLS transports. + if (transceiver->mid()) { + auto dtls_transport = LookupDtlsTransportByMid( + context_->network_thread(), transport_controller_s(), + *transceiver->mid()); + transceiver->sender_internal()->set_transport(dtls_transport); + transceiver->receiver_internal()->set_transport(dtls_transport); + } - const ContentInfo* content = - FindMediaSectionForTransceiver(transceiver, local_description()); - if (!content) { - continue; - } - const MediaContentDescription* media_desc = - content->media_description(); - // 2.2.7.1.6: If description is of type "answer" or "pranswer", then run - // the following steps: - if (type == SdpType::kPrAnswer || type == SdpType::kAnswer) { - // 2.2.7.1.6.1: If direction is "sendonly" or "inactive", and - // transceiver's [[FiredDirection]] slot is either "sendrecv" or - // "recvonly", process the removal of a remote track for the media - // description, given transceiver, removeList, and muteTracks. - if (!RtpTransceiverDirectionHasRecv(media_desc->direction()) && - (transceiver->fired_direction() && - RtpTransceiverDirectionHasRecv( - *transceiver->fired_direction()))) { - ProcessRemovalOfRemoteTrack(transceiver_ext, &remove_list, - &removed_streams); - } - // 2.2.7.1.6.2: Set transceiver's [[CurrentDirection]] and - // [[FiredDirection]] slots to direction. - transceiver->set_current_direction(media_desc->direction()); - transceiver->set_fired_direction(media_desc->direction()); + const ContentInfo* content = + FindMediaSectionForTransceiver(transceiver, local_description()); + if (!content) { + continue; + } + const MediaContentDescription* media_desc = content->media_description(); + // 2.2.7.1.6: If description is of type "answer" or "pranswer", then run + // the following steps: + if (type == SdpType::kPrAnswer || type == SdpType::kAnswer) { + // 2.2.7.1.6.1: If direction is "sendonly" or "inactive", and + // transceiver's [[FiredDirection]] slot is either "sendrecv" or + // "recvonly", process the removal of a remote track for the media + // description, given transceiver, removeList, and muteTracks. + if (!RtpTransceiverDirectionHasRecv(media_desc->direction()) && + (transceiver->fired_direction() && + RtpTransceiverDirectionHasRecv(*transceiver->fired_direction()))) { + ProcessRemovalOfRemoteTrack(transceiver_ext, &remove_list, + &removed_streams); } + // 2.2.7.1.6.2: Set transceiver's [[CurrentDirection]] and + // [[FiredDirection]] slots to direction. + transceiver->set_current_direction(media_desc->direction()); + transceiver->set_fired_direction(media_desc->direction()); } - auto observer = pc_->Observer(); - for (const auto& transceiver : remove_list) { - observer->OnRemoveTrack(transceiver->receiver()); - } - for (const auto& stream : removed_streams) { - observer->OnRemoveStream(stream); - } + } + auto observer = pc_->Observer(); + for (const auto& transceiver : remove_list) { + observer->OnRemoveTrack(transceiver->receiver()); + } + for (const auto& stream : removed_streams) { + observer->OnRemoveStream(stream); } } else { // Media channels will be created only when offer is set. These may use new @@ -1661,39 +1650,35 @@ RTCError SdpOfferAnswerHandler::ApplyLocalDescription( } if (IsUnifiedPlan()) { - if (ConfiguredForMedia()) { - // We must use List and not ListInternal here because - // transceivers()->StableState() is indexed by the non-internal refptr. - for (const auto& transceiver_ext : transceivers()->List()) { - auto transceiver = transceiver_ext->internal(); - if (transceiver->stopped()) { - continue; - } - const ContentInfo* content = - FindMediaSectionForTransceiver(transceiver, local_description()); - if (!content) { - continue; - } - cricket::ChannelInterface* channel = transceiver->channel(); - if (content->rejected || !channel || channel->local_streams().empty()) { - // 0 is a special value meaning "this sender has no associated send - // stream". Need to call this so the sender won't attempt to configure - // a no longer existing stream and run into DCHECKs in the lower - // layers. - transceiver->sender_internal()->SetSsrc(0); - } else { - // Get the StreamParams from the channel which could generate SSRCs. - const std::vector& streams = channel->local_streams(); - transceiver->sender_internal()->set_stream_ids( - streams[0].stream_ids()); - auto encodings = - transceiver->sender_internal()->init_send_encodings(); - transceiver->sender_internal()->SetSsrc(streams[0].first_ssrc()); - if (!encodings.empty()) { - transceivers() - ->StableState(transceiver_ext) - ->SetInitSendEncodings(encodings); - } + // We must use List and not ListInternal here because + // transceivers()->StableState() is indexed by the non-internal refptr. + for (const auto& transceiver_ext : transceivers()->List()) { + auto transceiver = transceiver_ext->internal(); + if (transceiver->stopped()) { + continue; + } + const ContentInfo* content = + FindMediaSectionForTransceiver(transceiver, local_description()); + if (!content) { + continue; + } + cricket::ChannelInterface* channel = transceiver->channel(); + if (content->rejected || !channel || channel->local_streams().empty()) { + // 0 is a special value meaning "this sender has no associated send + // stream". Need to call this so the sender won't attempt to configure + // a no longer existing stream and run into DCHECKs in the lower + // layers. + transceiver->sender_internal()->SetSsrc(0); + } else { + // Get the StreamParams from the channel which could generate SSRCs. + const std::vector& streams = channel->local_streams(); + transceiver->sender_internal()->set_stream_ids(streams[0].stream_ids()); + auto encodings = transceiver->sender_internal()->init_send_encodings(); + transceiver->sender_internal()->SetSsrc(streams[0].first_ssrc()); + if (!encodings.empty()) { + transceivers() + ->StableState(transceiver_ext) + ->SetInitSendEncodings(encodings); } } } @@ -1953,9 +1938,6 @@ void SdpOfferAnswerHandler::ApplyRemoteDescriptionUpdateTransceiverState( SdpType sdp_type) { RTC_DCHECK_RUN_ON(signaling_thread()); RTC_DCHECK(IsUnifiedPlan()); - if (!ConfiguredForMedia()) { - return; - } std::vector> now_receiving_transceivers; std::vector> remove_list; @@ -2743,9 +2725,7 @@ RTCError SdpOfferAnswerHandler::UpdateSessionState( } else { RTC_DCHECK(type == SdpType::kAnswer); ChangeSignalingState(PeerConnectionInterface::kStable); - if (ConfiguredForMedia()) { - transceivers()->DiscardStableStates(); - } + transceivers()->DiscardStableStates(); } // Update internal objects according to the session description's media @@ -3171,9 +3151,6 @@ bool SdpOfferAnswerHandler::CheckIfNegotiationIsNeeded() { if (!cricket::GetFirstDataContent(description->description()->contents())) return true; } - if (!ConfiguredForMedia()) { - return false; - } // 5. For each transceiver in connection's set of transceivers, perform the // following checks: @@ -3285,6 +3262,7 @@ bool SdpOfferAnswerHandler::CheckIfNegotiationIsNeeded() { } } } + // If all the preceding checks were performed and true was not returned, // nothing remains to be negotiated; return false. return false; @@ -3863,43 +3841,38 @@ void SdpOfferAnswerHandler::GetOptionsForOffer( void SdpOfferAnswerHandler::GetOptionsForPlanBOffer( const PeerConnectionInterface::RTCOfferAnswerOptions& offer_answer_options, cricket::MediaSessionOptions* session_options) { - bool offer_new_data_description = - data_channel_controller()->HasDataChannels(); - bool send_audio = false; - bool send_video = false; - bool recv_audio = false; - bool recv_video = false; - if (ConfiguredForMedia()) { - // Figure out transceiver directional preferences. - send_audio = - !rtp_manager()->GetAudioTransceiver()->internal()->senders().empty(); - send_video = - !rtp_manager()->GetVideoTransceiver()->internal()->senders().empty(); + // Figure out transceiver directional preferences. + bool send_audio = + !rtp_manager()->GetAudioTransceiver()->internal()->senders().empty(); + bool send_video = + !rtp_manager()->GetVideoTransceiver()->internal()->senders().empty(); + + // By default, generate sendrecv/recvonly m= sections. + bool recv_audio = true; + bool recv_video = true; - // By default, generate sendrecv/recvonly m= sections. - recv_audio = true; - recv_video = true; - } // By default, only offer a new m= section if we have media to send with it. bool offer_new_audio_description = send_audio; bool offer_new_video_description = send_video; - if (ConfiguredForMedia()) { - // The "offer_to_receive_X" options allow those defaults to be overridden. - if (offer_answer_options.offer_to_receive_audio != - PeerConnectionInterface::RTCOfferAnswerOptions::kUndefined) { - recv_audio = (offer_answer_options.offer_to_receive_audio > 0); - offer_new_audio_description = - offer_new_audio_description || - (offer_answer_options.offer_to_receive_audio > 0); - } - if (offer_answer_options.offer_to_receive_video != - RTCOfferAnswerOptions::kUndefined) { - recv_video = (offer_answer_options.offer_to_receive_video > 0); - offer_new_video_description = - offer_new_video_description || - (offer_answer_options.offer_to_receive_video > 0); - } + bool offer_new_data_description = + data_channel_controller()->HasDataChannels(); + + // The "offer_to_receive_X" options allow those defaults to be overridden. + if (offer_answer_options.offer_to_receive_audio != + PeerConnectionInterface::RTCOfferAnswerOptions::kUndefined) { + recv_audio = (offer_answer_options.offer_to_receive_audio > 0); + offer_new_audio_description = + offer_new_audio_description || + (offer_answer_options.offer_to_receive_audio > 0); } + if (offer_answer_options.offer_to_receive_video != + RTCOfferAnswerOptions::kUndefined) { + recv_video = (offer_answer_options.offer_to_receive_video > 0); + offer_new_video_description = + offer_new_video_description || + (offer_answer_options.offer_to_receive_video > 0); + } + absl::optional audio_index; absl::optional video_index; absl::optional data_index; @@ -3914,44 +3887,42 @@ void SdpOfferAnswerHandler::GetOptionsForPlanBOffer( &audio_index, &video_index, &data_index, session_options); } - if (ConfiguredForMedia()) { - // Add audio/video/data m= sections to the end if needed. - if (!audio_index && offer_new_audio_description) { - cricket::MediaDescriptionOptions options( - cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO, - RtpTransceiverDirectionFromSendRecv(send_audio, recv_audio), false); - options.header_extensions = - media_engine()->voice().GetRtpHeaderExtensions(); - session_options->media_description_options.push_back(options); - audio_index = session_options->media_description_options.size() - 1; - } - if (!video_index && offer_new_video_description) { - cricket::MediaDescriptionOptions options( - cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO, - RtpTransceiverDirectionFromSendRecv(send_video, recv_video), false); - options.header_extensions = - media_engine()->video().GetRtpHeaderExtensions(); - session_options->media_description_options.push_back(options); - video_index = session_options->media_description_options.size() - 1; - } - cricket::MediaDescriptionOptions* audio_media_description_options = - !audio_index - ? nullptr - : &session_options->media_description_options[*audio_index]; - cricket::MediaDescriptionOptions* video_media_description_options = - !video_index - ? nullptr - : &session_options->media_description_options[*video_index]; - - AddPlanBRtpSenderOptions(rtp_manager()->GetSendersInternal(), - audio_media_description_options, - video_media_description_options, - offer_answer_options.num_simulcast_layers); + // Add audio/video/data m= sections to the end if needed. + if (!audio_index && offer_new_audio_description) { + cricket::MediaDescriptionOptions options( + cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO, + RtpTransceiverDirectionFromSendRecv(send_audio, recv_audio), false); + options.header_extensions = + channel_manager()->GetSupportedAudioRtpHeaderExtensions(); + session_options->media_description_options.push_back(options); + audio_index = session_options->media_description_options.size() - 1; + } + if (!video_index && offer_new_video_description) { + cricket::MediaDescriptionOptions options( + cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO, + RtpTransceiverDirectionFromSendRecv(send_video, recv_video), false); + options.header_extensions = + channel_manager()->GetSupportedVideoRtpHeaderExtensions(); + session_options->media_description_options.push_back(options); + video_index = session_options->media_description_options.size() - 1; } if (!data_index && offer_new_data_description) { session_options->media_description_options.push_back( GetMediaDescriptionOptionsForActiveData(cricket::CN_DATA)); + data_index = session_options->media_description_options.size() - 1; } + + cricket::MediaDescriptionOptions* audio_media_description_options = + !audio_index ? nullptr + : &session_options->media_description_options[*audio_index]; + cricket::MediaDescriptionOptions* video_media_description_options = + !video_index ? nullptr + : &session_options->media_description_options[*video_index]; + + AddPlanBRtpSenderOptions(rtp_manager()->GetSendersInternal(), + audio_media_description_options, + video_media_description_options, + offer_answer_options.num_simulcast_layers); } void SdpOfferAnswerHandler::GetOptionsForUnifiedPlanOffer( @@ -4057,29 +4028,27 @@ void SdpOfferAnswerHandler::GetOptionsForUnifiedPlanOffer( // and not associated). Reuse media sections marked as recyclable first, // otherwise append to the end of the offer. New media sections should be // added in the order they were added to the PeerConnection. - if (ConfiguredForMedia()) { - for (const auto& transceiver : transceivers()->ListInternal()) { - if (transceiver->mid() || transceiver->stopping()) { - continue; - } - size_t mline_index; - if (!recycleable_mline_indices.empty()) { - mline_index = recycleable_mline_indices.front(); - recycleable_mline_indices.pop(); - session_options->media_description_options[mline_index] = - GetMediaDescriptionOptionsForTransceiver( - transceiver, mid_generator_.GenerateString(), - /*is_create_offer=*/true); - } else { - mline_index = session_options->media_description_options.size(); - session_options->media_description_options.push_back( - GetMediaDescriptionOptionsForTransceiver( - transceiver, mid_generator_.GenerateString(), - /*is_create_offer=*/true)); - } - // See comment above for why CreateOffer changes the transceiver's state. - transceiver->set_mline_index(mline_index); + for (const auto& transceiver : transceivers()->ListInternal()) { + if (transceiver->mid() || transceiver->stopping()) { + continue; } + size_t mline_index; + if (!recycleable_mline_indices.empty()) { + mline_index = recycleable_mline_indices.front(); + recycleable_mline_indices.pop(); + session_options->media_description_options[mline_index] = + GetMediaDescriptionOptionsForTransceiver( + transceiver, mid_generator_.GenerateString(), + /*is_create_offer=*/true); + } else { + mline_index = session_options->media_description_options.size(); + session_options->media_description_options.push_back( + GetMediaDescriptionOptionsForTransceiver( + transceiver, mid_generator_.GenerateString(), + /*is_create_offer=*/true)); + } + // See comment above for why CreateOffer changes the transceiver's state. + transceiver->set_mline_index(mline_index); } // Lastly, add a m-section if we have local data channels and an m section // does not already exist. @@ -4119,32 +4088,25 @@ void SdpOfferAnswerHandler::GetOptionsForAnswer( void SdpOfferAnswerHandler::GetOptionsForPlanBAnswer( const PeerConnectionInterface::RTCOfferAnswerOptions& offer_answer_options, cricket::MediaSessionOptions* session_options) { - bool send_audio = false; - bool recv_audio = false; - bool send_video = false; - bool recv_video = false; + // Figure out transceiver directional preferences. + bool send_audio = + !rtp_manager()->GetAudioTransceiver()->internal()->senders().empty(); + bool send_video = + !rtp_manager()->GetVideoTransceiver()->internal()->senders().empty(); - if (ConfiguredForMedia()) { - // Figure out transceiver directional preferences. - send_audio = - !rtp_manager()->GetAudioTransceiver()->internal()->senders().empty(); - send_video = - !rtp_manager()->GetVideoTransceiver()->internal()->senders().empty(); + // By default, generate sendrecv/recvonly m= sections. The direction is also + // restricted by the direction in the offer. + bool recv_audio = true; + bool recv_video = true; - // By default, generate sendrecv/recvonly m= sections. The direction is also - // restricted by the direction in the offer. - recv_audio = true; - recv_video = true; - - // The "offer_to_receive_X" options allow those defaults to be overridden. - if (offer_answer_options.offer_to_receive_audio != - RTCOfferAnswerOptions::kUndefined) { - recv_audio = (offer_answer_options.offer_to_receive_audio > 0); - } - if (offer_answer_options.offer_to_receive_video != - RTCOfferAnswerOptions::kUndefined) { - recv_video = (offer_answer_options.offer_to_receive_video > 0); - } + // The "offer_to_receive_X" options allow those defaults to be overridden. + if (offer_answer_options.offer_to_receive_audio != + RTCOfferAnswerOptions::kUndefined) { + recv_audio = (offer_answer_options.offer_to_receive_audio > 0); + } + if (offer_answer_options.offer_to_receive_video != + RTCOfferAnswerOptions::kUndefined) { + recv_video = (offer_answer_options.offer_to_receive_video > 0); } absl::optional audio_index; @@ -4167,12 +4129,10 @@ void SdpOfferAnswerHandler::GetOptionsForPlanBAnswer( !video_index ? nullptr : &session_options->media_description_options[*video_index]; - if (ConfiguredForMedia()) { - AddPlanBRtpSenderOptions(rtp_manager()->GetSendersInternal(), - audio_media_description_options, - video_media_description_options, - offer_answer_options.num_simulcast_layers); - } + AddPlanBRtpSenderOptions(rtp_manager()->GetSendersInternal(), + audio_media_description_options, + video_media_description_options, + offer_answer_options.num_simulcast_layers); } void SdpOfferAnswerHandler::GetOptionsForUnifiedPlanAnswer( @@ -4517,9 +4477,6 @@ void SdpOfferAnswerHandler::UpdateRemoteSendersList( void SdpOfferAnswerHandler::EnableSending() { TRACE_EVENT0("webrtc", "SdpOfferAnswerHandler::EnableSending"); RTC_DCHECK_RUN_ON(signaling_thread()); - if (!ConfiguredForMedia()) { - return; - } for (const auto& transceiver : transceivers()->ListInternal()) { cricket::ChannelInterface* channel = transceiver->channel(); if (channel) { @@ -4540,63 +4497,60 @@ RTCError SdpOfferAnswerHandler::PushdownMediaDescription( RTC_DCHECK_RUN_ON(signaling_thread()); RTC_DCHECK(sdesc); - if (ConfiguredForMedia()) { - // Note: This will perform an Invoke over to the worker thread, which we'll - // also do in a loop below. - if (!UpdatePayloadTypeDemuxingState(source, bundle_groups_by_mid)) { - // Note that this is never expected to fail, since RtpDemuxer doesn't - // return an error when changing payload type demux criteria, which is all - // this does. - return RTCError(RTCErrorType::INTERNAL_ERROR, - "Failed to update payload type demuxing state."); + // Note: This will perform an Invoke over to the worker thread, which we'll + // also do in a loop below. + if (!UpdatePayloadTypeDemuxingState(source, bundle_groups_by_mid)) { + // Note that this is never expected to fail, since RtpDemuxer doesn't return + // an error when changing payload type demux criteria, which is all this + // does. + return RTCError(RTCErrorType::INTERNAL_ERROR, + "Failed to update payload type demuxing state."); + } + + // Push down the new SDP media section for each audio/video transceiver. + auto rtp_transceivers = transceivers()->ListInternal(); + std::vector< + std::pair> + channels; + for (const auto& transceiver : rtp_transceivers) { + const ContentInfo* content_info = + FindMediaSectionForTransceiver(transceiver, sdesc); + cricket::ChannelInterface* channel = transceiver->channel(); + if (!channel || !content_info || content_info->rejected) { + continue; + } + const MediaContentDescription* content_desc = + content_info->media_description(); + if (!content_desc) { + continue; } - // Push down the new SDP media section for each audio/video transceiver. - auto rtp_transceivers = transceivers()->ListInternal(); - std::vector< - std::pair> - channels; - for (const auto& transceiver : rtp_transceivers) { - const ContentInfo* content_info = - FindMediaSectionForTransceiver(transceiver, sdesc); - cricket::ChannelInterface* channel = transceiver->channel(); - if (!channel || !content_info || content_info->rejected) { - continue; - } - const MediaContentDescription* content_desc = - content_info->media_description(); - if (!content_desc) { - continue; - } + transceiver->OnNegotiationUpdate(type, content_desc); + channels.push_back(std::make_pair(channel, content_desc)); + } - transceiver->OnNegotiationUpdate(type, content_desc); - channels.push_back(std::make_pair(channel, content_desc)); - } - - // This for-loop of invokes helps audio impairment during re-negotiations. - // One of the causes is that downstairs decoder creation is synchronous at - // the moment, and that a decoder is created for each codec listed in the - // SDP. - // - // TODO(bugs.webrtc.org/12840): consider merging the invokes again after - // these projects have shipped: - // - bugs.webrtc.org/12462 - // - crbug.com/1157227 - // - crbug.com/1187289 - for (const auto& entry : channels) { - std::string error; - bool success = - context_->worker_thread()->Invoke(RTC_FROM_HERE, [&]() { - return (source == cricket::CS_LOCAL) - ? entry.first->SetLocalContent(entry.second, type, error) - : entry.first->SetRemoteContent(entry.second, type, - error); - }); - if (!success) { - return RTCError(RTCErrorType::INVALID_PARAMETER, error); - } + // This for-loop of invokes helps audio impairment during re-negotiations. + // One of the causes is that downstairs decoder creation is synchronous at the + // moment, and that a decoder is created for each codec listed in the SDP. + // + // TODO(bugs.webrtc.org/12840): consider merging the invokes again after + // these projects have shipped: + // - bugs.webrtc.org/12462 + // - crbug.com/1157227 + // - crbug.com/1187289 + for (const auto& entry : channels) { + std::string error; + bool success = + context_->worker_thread()->Invoke(RTC_FROM_HERE, [&]() { + return (source == cricket::CS_LOCAL) + ? entry.first->SetLocalContent(entry.second, type, error) + : entry.first->SetRemoteContent(entry.second, type, error); + }); + if (!success) { + return RTCError(RTCErrorType::INVALID_PARAMETER, error); } } + // Need complete offer/answer with an SCTP m= section before starting SCTP, // according to https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-19 if (pc_->sctp_mid() && local_description() && remote_description()) { @@ -4650,9 +4604,6 @@ void SdpOfferAnswerHandler::RemoveStoppedTransceivers() { // run the following steps: if (!IsUnifiedPlan()) return; - if (!ConfiguredForMedia()) { - return; - } // Traverse a copy of the transceiver list. auto transceiver_list = transceivers()->List(); for (auto transceiver : transceiver_list) { @@ -4687,21 +4638,18 @@ void SdpOfferAnswerHandler::RemoveStoppedTransceivers() { void SdpOfferAnswerHandler::RemoveUnusedChannels( const SessionDescription* desc) { RTC_DCHECK_RUN_ON(signaling_thread()); - if (ConfiguredForMedia()) { - // Destroy video channel first since it may have a pointer to the - // voice channel. - const cricket::ContentInfo* video_info = - cricket::GetFirstVideoContent(desc); - if (!video_info || video_info->rejected) { - rtp_manager()->GetVideoTransceiver()->internal()->ClearChannel(); - } - - const cricket::ContentInfo* audio_info = - cricket::GetFirstAudioContent(desc); - if (!audio_info || audio_info->rejected) { - rtp_manager()->GetAudioTransceiver()->internal()->ClearChannel(); - } + // Destroy video channel first since it may have a pointer to the + // voice channel. + const cricket::ContentInfo* video_info = cricket::GetFirstVideoContent(desc); + if (!video_info || video_info->rejected) { + rtp_manager()->GetVideoTransceiver()->internal()->ClearChannel(); } + + const cricket::ContentInfo* audio_info = cricket::GetFirstAudioContent(desc); + if (!audio_info || audio_info->rejected) { + rtp_manager()->GetAudioTransceiver()->internal()->ClearChannel(); + } + const cricket::ContentInfo* data_info = cricket::GetFirstDataContent(desc); if (!data_info) { RTCError error(RTCErrorType::OPERATION_ERROR_WITH_DATA, @@ -5019,7 +4967,7 @@ void SdpOfferAnswerHandler::GenerateMediaDescriptionOptions( *audio_index = session_options->media_description_options.size() - 1; } session_options->media_description_options.back().header_extensions = - media_engine()->voice().GetRtpHeaderExtensions(); + channel_manager()->GetSupportedAudioRtpHeaderExtensions(); } else if (IsVideoContent(&content)) { // If we already have an video m= section, reject this extra one. if (*video_index) { @@ -5036,7 +4984,7 @@ void SdpOfferAnswerHandler::GenerateMediaDescriptionOptions( *video_index = session_options->media_description_options.size() - 1; } session_options->media_description_options.back().header_extensions = - media_engine()->video().GetRtpHeaderExtensions(); + channel_manager()->GetSupportedVideoRtpHeaderExtensions(); } else if (IsUnsupportedContent(&content)) { session_options->media_description_options.push_back( cricket::MediaDescriptionOptions(cricket::MEDIA_TYPE_UNSUPPORTED, @@ -5260,8 +5208,4 @@ bool SdpOfferAnswerHandler::UpdatePayloadTypeDemuxingState( }); } -bool SdpOfferAnswerHandler::ConfiguredForMedia() const { - return context_->channel_manager(); -} - } // namespace webrtc diff --git a/pc/sdp_offer_answer.h b/pc/sdp_offer_answer.h index 6a0aaaad27..de814ec737 100644 --- a/pc/sdp_offer_answer.h +++ b/pc/sdp_offer_answer.h @@ -478,7 +478,7 @@ class SdpOfferAnswerHandler : public SdpStateProvider, // This enables media to flow on all configured audio/video channels. void EnableSending(); // Push the media parts of the local or remote session description - // down to all of the channels, and start SCTP if needed. + // down to all of the channels. RTCError PushdownMediaDescription( SdpType type, cricket::ContentSource source, @@ -576,7 +576,6 @@ class SdpOfferAnswerHandler : public SdpStateProvider, // ================================================================== // Access to pc_ variables cricket::ChannelManager* channel_manager() const; - cricket::MediaEngineInterface* media_engine() const; TransceiverList* transceivers(); const TransceiverList* transceivers() const; DataChannelController* data_channel_controller(); @@ -596,7 +595,6 @@ class SdpOfferAnswerHandler : public SdpStateProvider, // =================================================================== const cricket::AudioOptions& audio_options() { return audio_options_; } const cricket::VideoOptions& video_options() { return video_options_; } - bool ConfiguredForMedia() const; PeerConnectionSdpMethods* const pc_; ConnectionContext* const context_; diff --git a/pc/test/fake_peer_connection_for_stats.h b/pc/test/fake_peer_connection_for_stats.h index e7ed804814..e612f0d10f 100644 --- a/pc/test/fake_peer_connection_for_stats.h +++ b/pc/test/fake_peer_connection_for_stats.h @@ -415,10 +415,7 @@ class FakePeerConnectionForStats : public FakePeerConnectionBase { class TestChannelManager : public cricket::ChannelManager { public: TestChannelManager(rtc::Thread* worker, rtc::Thread* network) - : cricket::ChannelManager(std::make_unique(), - true, - worker, - network) {} + : cricket::ChannelManager(nullptr, true, worker, network) {} }; rtc::Thread* const network_thread_;