diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index dd7a616b8c..3b094f99de 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -629,8 +629,8 @@ RTCError PeerConnection::Initialize( stats_ = std::make_unique(this); stats_collector_ = RTCStatsCollector::Create(this); - sdp_handler_ = - SdpOfferAnswerHandler::Create(this, configuration, dependencies); + sdp_handler_ = SdpOfferAnswerHandler::Create(this, configuration, + dependencies, context_); rtp_manager_ = std::make_unique( IsUnifiedPlan(), signaling_thread(), worker_thread(), channel_manager(), @@ -1648,6 +1648,10 @@ void PeerConnection::AddAdaptationResource( call_->AddAdaptationResource(resource); } +cricket::ChannelManager* PeerConnection::channel_manager() { + return context_->channel_manager(); +} + bool PeerConnection::StartRtcEventLog(std::unique_ptr output, int64_t output_period_ms) { return worker_thread()->Invoke( @@ -2090,10 +2094,6 @@ bool PeerConnection::ReconfigurePortAllocator_n( stun_candidate_keepalive_interval); } -cricket::ChannelManager* PeerConnection::channel_manager() { - return context_->channel_manager(); -} - bool PeerConnection::StartRtcEventLog_w( std::unique_ptr output, int64_t output_period_ms) { diff --git a/pc/peer_connection.h b/pc/peer_connection.h index cb321f07eb..3555ffbfe9 100644 --- a/pc/peer_connection.h +++ b/pc/peer_connection.h @@ -267,11 +267,6 @@ class PeerConnection : public PeerConnectionInternal, return context_->signaling_thread(); } - // PeerConnectionInternal implementation. - rtc::Thread* signaling_thread_internal() const final { - return context_->signaling_thread(); - } - rtc::Thread* network_thread() const final { return context_->network_thread(); } @@ -360,7 +355,7 @@ class PeerConnection : public PeerConnectionInternal, const RtpTransmissionManager* rtp_manager() const override { return rtp_manager_.get(); } - cricket::ChannelManager* channel_manager() override; + cricket::ChannelManager* channel_manager(); JsepTransportController* transport_controller() override { return transport_controller_.get(); diff --git a/pc/peer_connection_internal.h b/pc/peer_connection_internal.h index dc8204521b..266ce238c0 100644 --- a/pc/peer_connection_internal.h +++ b/pc/peer_connection_internal.h @@ -36,13 +36,6 @@ class PeerConnectionSdpMethods { public: virtual ~PeerConnectionSdpMethods() = default; - // NOTE - signaling_thread() is a member of PeerConnectionInterface, - // so we have to use a different name for this function as long as - // PeerConnection is a subclass of PeerConnectionSdpMethods. - virtual rtc::Thread* signaling_thread_internal() const = 0; - virtual rtc::Thread* network_thread() const = 0; - virtual rtc::Thread* worker_thread() const = 0; - // The SDP session ID as defined by RFC 3264. virtual std::string session_id() const = 0; @@ -78,7 +71,6 @@ class PeerConnectionSdpMethods { // return the RTCConfiguration.crypto_options if set and will only default // back to the PeerConnectionFactory settings if nothing was set. virtual CryptoOptions GetCryptoOptions() = 0; - virtual cricket::ChannelManager* channel_manager() = 0; virtual JsepTransportController* transport_controller() = 0; virtual DataChannelController* data_channel_controller() = 0; virtual cricket::PortAllocator* port_allocator() = 0; @@ -137,6 +129,9 @@ class PeerConnectionSdpMethods { class PeerConnectionInternal : public PeerConnectionInterface, public PeerConnectionSdpMethods { public: + virtual rtc::Thread* network_thread() const = 0; + virtual rtc::Thread* worker_thread() const = 0; + // Returns true if we were the initial offerer. virtual bool initial_offerer() const = 0; diff --git a/pc/sdp_offer_answer.cc b/pc/sdp_offer_answer.cc index 39416ce58d..2495f2b575 100644 --- a/pc/sdp_offer_answer.cc +++ b/pc/sdp_offer_answer.cc @@ -1161,8 +1161,10 @@ class SdpOfferAnswerHandler::LocalIceCredentialsToReplace { std::set> ice_credentials_; }; -SdpOfferAnswerHandler::SdpOfferAnswerHandler(PeerConnectionSdpMethods* pc) +SdpOfferAnswerHandler::SdpOfferAnswerHandler(PeerConnectionSdpMethods* pc, + ConnectionContext* context) : pc_(pc), + context_(context), local_streams_(StreamCollection::Create()), remote_streams_(StreamCollection::Create()), operations_chain_(rtc::OperationsChain::Create()), @@ -1183,8 +1185,9 @@ SdpOfferAnswerHandler::~SdpOfferAnswerHandler() {} std::unique_ptr SdpOfferAnswerHandler::Create( PeerConnectionSdpMethods* pc, const PeerConnectionInterface::RTCConfiguration& configuration, - PeerConnectionDependencies& dependencies) { - auto handler = absl::WrapUnique(new SdpOfferAnswerHandler(pc)); + PeerConnectionDependencies& dependencies, + ConnectionContext* context) { + auto handler = absl::WrapUnique(new SdpOfferAnswerHandler(pc, context)); handler->Initialize(configuration, dependencies); return handler; } @@ -1248,7 +1251,7 @@ void SdpOfferAnswerHandler::Initialize( // ================================================================== // Access to pc_ variables cricket::ChannelManager* SdpOfferAnswerHandler::channel_manager() const { - return pc_->channel_manager(); + return context_->channel_manager(); } TransceiverList* SdpOfferAnswerHandler::transceivers() { if (!pc_->rtp_manager()) { @@ -1308,7 +1311,7 @@ void SdpOfferAnswerHandler::RestartIce() { } rtc::Thread* SdpOfferAnswerHandler::signaling_thread() const { - return pc_->signaling_thread_internal(); + return context_->signaling_thread(); } void SdpOfferAnswerHandler::CreateOffer( @@ -1544,7 +1547,8 @@ RTCError SdpOfferAnswerHandler::ApplyLocalDescription( // information about DTLS transports. if (transceiver->mid()) { auto dtls_transport = LookupDtlsTransportByMid( - pc_->network_thread(), transport_controller(), *transceiver->mid()); + context_->network_thread(), transport_controller(), + *transceiver->mid()); transceiver->sender_internal()->set_transport(dtls_transport); transceiver->receiver_internal()->set_transport(dtls_transport); } @@ -1978,7 +1982,8 @@ void SdpOfferAnswerHandler::ApplyRemoteDescriptionUpdateTransceiverState( // 2.2.8.1.11.[3-6]: Set the transport internal slots. if (transceiver->mid()) { auto dtls_transport = LookupDtlsTransportByMid( - pc_->network_thread(), transport_controller(), *transceiver->mid()); + context_->network_thread(), transport_controller(), + *transceiver->mid()); transceiver->sender_internal()->set_transport(dtls_transport); transceiver->receiver_internal()->set_transport(dtls_transport); } @@ -2158,7 +2163,7 @@ void SdpOfferAnswerHandler::DoSetLocalDescription( // TODO(deadbeef): We already had to hop to the network thread for // MaybeStartGathering... - pc_->network_thread()->Invoke( + context_->network_thread()->Invoke( RTC_FROM_HERE, [this] { port_allocator()->DiscardCandidatePool(); }); // Make UMA notes about what was agreed to. ReportNegotiatedSdpSemantics(*local_description()); @@ -2358,7 +2363,7 @@ void SdpOfferAnswerHandler::SetRemoteDescriptionPostProcess(bool was_answer) { if (was_answer) { // TODO(deadbeef): We already had to hop to the network thread for // MaybeStartGathering... - pc_->network_thread()->Invoke( + context_->network_thread()->Invoke( RTC_FROM_HERE, [this] { port_allocator()->DiscardCandidatePool(); }); // Make UMA notes about what was agreed to. ReportNegotiatedSdpSemantics(*remote_description()); @@ -3724,7 +3729,7 @@ void SdpOfferAnswerHandler::GetOptionsForOffer( session_options->rtcp_cname = rtcp_cname_; session_options->crypto_options = pc_->GetCryptoOptions(); session_options->pooled_ice_credentials = - pc_->network_thread()->Invoke>( + context_->network_thread()->Invoke>( RTC_FROM_HERE, [this] { return port_allocator()->GetPooledIceCredentials(); }); session_options->offer_extmap_allow_mixed = @@ -3979,7 +3984,7 @@ void SdpOfferAnswerHandler::GetOptionsForAnswer( session_options->rtcp_cname = rtcp_cname_; session_options->crypto_options = pc_->GetCryptoOptions(); session_options->pooled_ice_credentials = - pc_->network_thread()->Invoke>( + context_->network_thread()->Invoke>( RTC_FROM_HERE, [this] { return port_allocator()->GetPooledIceCredentials(); }); } @@ -4439,11 +4444,12 @@ RTCError SdpOfferAnswerHandler::PushdownMediaDescription( // - crbug.com/1187289 for (const auto& entry : channels) { std::string error; - bool success = pc_->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); - }); + 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); } @@ -4808,8 +4814,8 @@ cricket::VideoChannel* SdpOfferAnswerHandler::CreateVideoChannel( bool SdpOfferAnswerHandler::CreateDataChannel(const std::string& mid) { RTC_DCHECK_RUN_ON(signaling_thread()); - if (!pc_->network_thread()->Invoke(RTC_FROM_HERE, [this, &mid] { - RTC_DCHECK_RUN_ON(pc_->network_thread()); + if (!context_->network_thread()->Invoke(RTC_FROM_HERE, [this, &mid] { + RTC_DCHECK_RUN_ON(context_->network_thread()); return pc_->SetupDataChannelTransport_n(mid); })) { return false; @@ -4830,8 +4836,8 @@ void SdpOfferAnswerHandler::DestroyDataChannelTransport(RTCError error) { if (has_sctp) data_channel_controller()->OnTransportChannelClosed(error); - pc_->network_thread()->Invoke(RTC_FROM_HERE, [this] { - RTC_DCHECK_RUN_ON(pc_->network_thread()); + context_->network_thread()->Invoke(RTC_FROM_HERE, [this] { + RTC_DCHECK_RUN_ON(context_->network_thread()); pc_->TeardownDataChannelTransport_n(); }); @@ -5128,7 +5134,7 @@ bool SdpOfferAnswerHandler::UpdatePayloadTypeDemuxingState( // needs to be fully (and only) managed on the network thread and once that's // the case, there's no need to stop by on the worker. Ideally we could also // do this without blocking. - return pc_->worker_thread()->Invoke( + return context_->worker_thread()->Invoke( RTC_FROM_HERE, [&channels_to_update]() { for (const auto& it : channels_to_update) { if (!it.second->SetPayloadTypeDemuxingEnabled(it.first)) { diff --git a/pc/sdp_offer_answer.h b/pc/sdp_offer_answer.h index 019e4371c8..a42e9bacec 100644 --- a/pc/sdp_offer_answer.h +++ b/pc/sdp_offer_answer.h @@ -96,7 +96,8 @@ class SdpOfferAnswerHandler : public SdpStateProvider, static std::unique_ptr Create( PeerConnectionSdpMethods* pc, const PeerConnectionInterface::RTCConfiguration& configuration, - PeerConnectionDependencies& dependencies); + PeerConnectionDependencies& dependencies, + ConnectionContext* context); void ResetSessionDescFactory() { RTC_DCHECK_RUN_ON(signaling_thread()); @@ -205,7 +206,8 @@ class SdpOfferAnswerHandler : public SdpStateProvider, class LocalIceCredentialsToReplace; // Only called by the Create() function. - explicit SdpOfferAnswerHandler(PeerConnectionSdpMethods* pc); + explicit SdpOfferAnswerHandler(PeerConnectionSdpMethods* pc, + ConnectionContext* context); // Called from the `Create()` function. Can only be called // once. Modifies dependencies. void Initialize( @@ -592,6 +594,7 @@ class SdpOfferAnswerHandler : public SdpStateProvider, const cricket::VideoOptions& video_options() { return video_options_; } PeerConnectionSdpMethods* const pc_; + ConnectionContext* const context_; std::unique_ptr webrtc_session_desc_factory_ RTC_GUARDED_BY(signaling_thread()); diff --git a/pc/test/fake_peer_connection_base.h b/pc/test/fake_peer_connection_base.h index 71ce7bca20..cca84197f7 100644 --- a/pc/test/fake_peer_connection_base.h +++ b/pc/test/fake_peer_connection_base.h @@ -296,7 +296,6 @@ class FakePeerConnectionBase : public PeerConnectionInternal { return nullptr; } - rtc::Thread* signaling_thread_internal() const override { return nullptr; } void ReportSdpFormatReceived( const SessionDescriptionInterface& remote_description) override {} @@ -312,7 +311,6 @@ class FakePeerConnectionBase : public PeerConnectionInternal { } CryptoOptions GetCryptoOptions() override { return CryptoOptions(); } - cricket::ChannelManager* channel_manager() override { return nullptr; } JsepTransportController* transport_controller() override { return nullptr; } DataChannelController* data_channel_controller() override { return nullptr; } cricket::PortAllocator* port_allocator() override { return nullptr; }