From 3dc4d4a21f80cdf44c508412d784b254957696eb Mon Sep 17 00:00:00 2001 From: Steve Anton Date: Wed, 27 Sep 2017 17:30:05 -0700 Subject: [PATCH] Move clients of WebRtcSession to use PeerConnection This change is part of the work to merge WebRtcSession into PeerConnection. To make that work easier, this moves all clients of WebRtcSession to use shims added to PeerConnection. That way when the classes are merged they won't need to be modified. Bug: webrtc:8183 Change-Id: I43de7acf7e38c9fcf2dbf55d50eb05e73767c251 Reviewed-on: https://webrtc-review.googlesource.com/4320 Reviewed-by: Taylor Brandstetter Commit-Queue: Steve Anton Cr-Commit-Position: refs/heads/master@{#20030} --- pc/peerconnection.cc | 28 +++++------ pc/peerconnection.h | 70 +++++++++++++++++++++++---- pc/rtcstatscollector.cc | 56 +++++++++++----------- pc/rtcstatscollector_unittest.cc | 13 ++--- pc/statscollector.cc | 81 ++++++++++++++++---------------- pc/statscollector_unittest.cc | 2 +- pc/test/mock_peerconnection.h | 1 - 7 files changed, 149 insertions(+), 102 deletions(-) diff --git a/pc/peerconnection.cc b/pc/peerconnection.cc index 91d0c90a12..7ebe300ea1 100644 --- a/pc/peerconnection.cc +++ b/pc/peerconnection.cc @@ -421,12 +421,16 @@ PeerConnection::~PeerConnection() { // Now destroy session_ before destroying other members, // because its destruction fires signals (such as VoiceChannelDestroyed) // which will trigger some final actions in PeerConnection... - session_.reset(nullptr); + if (borrowed_session_) { + session_.release(); + } else { + session_.reset(nullptr); + } // port_allocator_ lives on the network thread and should be destroyed there. network_thread()->Invoke(RTC_FROM_HERE, [this] { port_allocator_.reset(); }); // call_ and event_log_ must be destroyed on the worker thread. - factory_->worker_thread()->Invoke(RTC_FROM_HERE, [this] { + worker_thread()->Invoke(RTC_FROM_HERE, [this] { call_.reset(); event_log_.reset(); }); @@ -467,12 +471,9 @@ bool PeerConnection::Initialize( return false; } - session_.reset(new WebRtcSession( call_.get(), factory_->channel_manager(), configuration.media_config, - event_log_.get(), - factory_->network_thread(), - factory_->worker_thread(), factory_->signaling_thread(), + event_log_.get(), network_thread(), worker_thread(), signaling_thread(), port_allocator_.get(), std::unique_ptr( factory_->CreateTransportController( @@ -480,7 +481,7 @@ bool PeerConnection::Initialize( configuration.redetermine_role_on_ice_restart)), #ifdef HAVE_SCTP std::unique_ptr( - new cricket::SctpTransportFactory(factory_->network_thread())) + new cricket::SctpTransportFactory(network_thread())) #else nullptr #endif @@ -1240,9 +1241,8 @@ void PeerConnection::RegisterUMAObserver(UMAObserver* observer) { } RTCError PeerConnection::SetBitrate(const BitrateParameters& bitrate) { - rtc::Thread* worker_thread = factory_->worker_thread(); - if (!worker_thread->IsCurrent()) { - return worker_thread->Invoke( + if (!worker_thread()->IsCurrent()) { + return worker_thread()->Invoke( RTC_FROM_HERE, rtc::Bind(&PeerConnection::SetBitrate, this, bitrate)); } @@ -1289,13 +1289,13 @@ RTCError PeerConnection::SetBitrate(const BitrateParameters& bitrate) { bool PeerConnection::StartRtcEventLog(rtc::PlatformFile file, int64_t max_size_bytes) { - return factory_->worker_thread()->Invoke( + return worker_thread()->Invoke( RTC_FROM_HERE, rtc::Bind(&PeerConnection::StartRtcEventLog_w, this, file, max_size_bytes)); } void PeerConnection::StopRtcEventLog() { - factory_->worker_thread()->Invoke( + worker_thread()->Invoke( RTC_FROM_HERE, rtc::Bind(&PeerConnection::StopRtcEventLog_w, this)); } @@ -1339,7 +1339,7 @@ void PeerConnection::Close() { rtc::Bind(&cricket::PortAllocator::DiscardCandidatePool, port_allocator_.get())); - factory_->worker_thread()->Invoke(RTC_FROM_HERE, [this] { + worker_thread()->Invoke(RTC_FROM_HERE, [this] { call_.reset(); // The event log must outlive call (and any other object that uses it). event_log_.reset(); @@ -1437,7 +1437,7 @@ void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream, rtc::scoped_refptr> receiver = RtpReceiverProxyWithInternal::Create( signaling_thread(), - new VideoRtpReceiver(track_id, factory_->worker_thread(), ssrc, + new VideoRtpReceiver(track_id, worker_thread(), ssrc, session_->video_channel())); stream->AddTrack( static_cast(receiver->internal()->track().get())); diff --git a/pc/peerconnection.h b/pc/peerconnection.h index 2d6be60d59..30f1a838db 100644 --- a/pc/peerconnection.h +++ b/pc/peerconnection.h @@ -65,8 +65,6 @@ class PeerConnection : public PeerConnectionInterface, std::vector streams) override; bool RemoveTrack(RtpSenderInterface* sender) override; - virtual WebRtcSession* session() { return session_.get(); } - rtc::scoped_refptr CreateDtmfSender( AudioTrackInterface* track) override; @@ -146,6 +144,65 @@ class PeerConnection : public PeerConnectionInterface, return sctp_data_channels_; } + // TODO(steveanton): These methods are temporarily added to facilitate work + // towards merging WebRtcSession into PeerConnection. To make this easier, we + // want only PeerConnection to interact with WebRtcSession so they can be + // merged easily. A few outside classes still access WebRtcSession methods + // directly, so these have been added to PeerConnection to remove the + // dependency from WebRtcSession. + + rtc::Thread* network_thread() const { return factory_->network_thread(); } + rtc::Thread* worker_thread() const { return factory_->worker_thread(); } + rtc::Thread* signaling_thread() const { return factory_->signaling_thread(); } + virtual const std::string& session_id() const { return session_->id(); } + virtual bool session_created() const { return session_ != nullptr; } + virtual bool initial_offerer() const { return session_->initial_offerer(); } + virtual std::unique_ptr GetSessionStats_s() { + return session_->GetStats_s(); + } + virtual std::unique_ptr GetSessionStats( + const ChannelNamePairs& channel_name_pairs) { + return session_->GetStats(channel_name_pairs); + } + virtual bool GetLocalCertificate( + const std::string& transport_name, + rtc::scoped_refptr* certificate) { + return session_->GetLocalCertificate(transport_name, certificate); + } + virtual std::unique_ptr GetRemoteSSLCertificate( + const std::string& transport_name) { + return session_->GetRemoteSSLCertificate(transport_name); + } + virtual Call::Stats GetCallStats() { return session_->GetCallStats(); } + virtual cricket::VoiceChannel* voice_channel() { + return session_->voice_channel(); + } + virtual cricket::VideoChannel* video_channel() { + return session_->video_channel(); + } + virtual cricket::RtpDataChannel* rtp_data_channel() { + return session_->rtp_data_channel(); + } + virtual rtc::Optional sctp_content_name() const { + return session_->sctp_content_name(); + } + virtual rtc::Optional sctp_transport_name() const { + return session_->sctp_transport_name(); + } + virtual bool GetLocalTrackIdBySsrc(uint32_t ssrc, std::string* track_id) { + return session_->GetLocalTrackIdBySsrc(ssrc, track_id); + } + virtual bool GetRemoteTrackIdBySsrc(uint32_t ssrc, std::string* track_id) { + return session_->GetRemoteTrackIdBySsrc(ssrc, track_id); + } + + // This is needed for stats tests to inject a MockWebRtcSession. Once + // WebRtcSession has been merged in, this will no longer be needed. + void set_session_for_testing(WebRtcSession* session) { + session_.reset(session); + borrowed_session_ = true; + } + protected: ~PeerConnection() override; @@ -210,12 +267,6 @@ class PeerConnection : public PeerConnectionInterface, void OnVideoTrackRemoved(VideoTrackInterface* track, MediaStreamInterface* stream); - rtc::Thread* signaling_thread() const { - return factory_->signaling_thread(); - } - - rtc::Thread* network_thread() const { return factory_->network_thread(); } - void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer, const std::string& error); void PostCreateSessionDescriptionFailure( @@ -434,6 +485,9 @@ class PeerConnection : public PeerConnectionInterface, std::unique_ptr call_; std::unique_ptr session_; + // TODO(steveanton): Some tests need to inject a mock WebRtcSession. This + // indicates that we should not delete the WebRtcSession ourself. + bool borrowed_session_ = false; std::unique_ptr stats_; // A pointer is passed to senders_ rtc::scoped_refptr stats_collector_; diff --git a/pc/rtcstatscollector.cc b/pc/rtcstatscollector.cc index 161d224bc5..8e6e420be1 100644 --- a/pc/rtcstatscollector.cc +++ b/pc/rtcstatscollector.cc @@ -588,9 +588,9 @@ rtc::scoped_refptr RTCStatsCollector::Create( RTCStatsCollector::RTCStatsCollector(PeerConnection* pc, int64_t cache_lifetime_us) : pc_(pc), - signaling_thread_(pc->session()->signaling_thread()), - worker_thread_(pc->session()->worker_thread()), - network_thread_(pc->session()->network_thread()), + signaling_thread_(pc->signaling_thread()), + worker_thread_(pc->worker_thread()), + network_thread_(pc->network_thread()), num_pending_partial_reports_(0), partial_report_timestamp_us_(0), cache_timestamp_us_(0), @@ -636,26 +636,25 @@ void RTCStatsCollector::GetStatsReport( // Prepare |channel_name_pairs_| for use in // |ProducePartialResultsOnNetworkThread|. channel_name_pairs_.reset(new ChannelNamePairs()); - if (pc_->session()->voice_channel()) { + if (pc_->voice_channel()) { channel_name_pairs_->voice = rtc::Optional( - ChannelNamePair(pc_->session()->voice_channel()->content_name(), - pc_->session()->voice_channel()->transport_name())); + ChannelNamePair(pc_->voice_channel()->content_name(), + pc_->voice_channel()->transport_name())); } - if (pc_->session()->video_channel()) { + if (pc_->video_channel()) { channel_name_pairs_->video = rtc::Optional( - ChannelNamePair(pc_->session()->video_channel()->content_name(), - pc_->session()->video_channel()->transport_name())); + ChannelNamePair(pc_->video_channel()->content_name(), + pc_->video_channel()->transport_name())); } - if (pc_->session()->rtp_data_channel()) { + if (pc_->rtp_data_channel()) { + channel_name_pairs_->data = rtc::Optional( + ChannelNamePair(pc_->rtp_data_channel()->content_name(), + pc_->rtp_data_channel()->transport_name())); + } + if (pc_->sctp_content_name()) { channel_name_pairs_->data = rtc::Optional(ChannelNamePair( - pc_->session()->rtp_data_channel()->content_name(), - pc_->session()->rtp_data_channel()->transport_name())); - } - if (pc_->session()->sctp_content_name()) { - channel_name_pairs_->data = rtc::Optional( - ChannelNamePair(*pc_->session()->sctp_content_name(), - *pc_->session()->sctp_transport_name())); + *pc_->sctp_content_name(), *pc_->sctp_transport_name())); } // Prepare |track_media_info_map_| for use in // |ProducePartialResultsOnNetworkThread| and @@ -670,7 +669,7 @@ void RTCStatsCollector::GetStatsReport( // thread. // TODO(holmer): To avoid the hop we could move BWE and BWE stats to the // network thread, where it more naturally belongs. - call_stats_ = pc_->session()->GetCallStats(); + call_stats_ = pc_->GetCallStats(); invoker_.AsyncInvoke( RTC_FROM_HERE, network_thread_, @@ -716,7 +715,7 @@ void RTCStatsCollector::ProducePartialResultsOnNetworkThread( timestamp_us); std::unique_ptr session_stats = - pc_->session()->GetStats(*channel_name_pairs_); + pc_->GetSessionStats(*channel_name_pairs_); if (session_stats) { std::map transport_cert_stats = PrepareTransportCertificateStats_n(*session_stats); @@ -976,7 +975,7 @@ void RTCStatsCollector::ProduceRTPStreamStats_n( // Audio if (track_media_info_map.voice_media_info()) { std::string transport_id = RTCTransportStatsIDFromBaseChannel( - session_stats.proxy_to_transport, *pc_->session()->voice_channel()); + session_stats.proxy_to_transport, *pc_->voice_channel()); RTC_DCHECK(!transport_id.empty()); // Inbound for (const cricket::VoiceReceiverInfo& voice_receiver_info : @@ -1038,7 +1037,7 @@ void RTCStatsCollector::ProduceRTPStreamStats_n( // Video if (track_media_info_map.video_media_info()) { std::string transport_id = RTCTransportStatsIDFromBaseChannel( - session_stats.proxy_to_transport, *pc_->session()->video_channel()); + session_stats.proxy_to_transport, *pc_->video_channel()); RTC_DCHECK(!transport_id.empty()); // Inbound for (const cricket::VideoReceiverInfo& video_receiver_info : @@ -1173,14 +1172,13 @@ RTCStatsCollector::PrepareTransportCertificateStats_n( for (const auto& transport_stats : session_stats.transport_stats) { CertificateStatsPair certificate_stats_pair; rtc::scoped_refptr local_certificate; - if (pc_->session()->GetLocalCertificate( - transport_stats.second.transport_name, &local_certificate)) { + if (pc_->GetLocalCertificate(transport_stats.second.transport_name, + &local_certificate)) { certificate_stats_pair.local = local_certificate->ssl_certificate().GetStats(); } std::unique_ptr remote_certificate = - pc_->session()->GetRemoteSSLCertificate( - transport_stats.second.transport_name); + pc_->GetRemoteSSLCertificate(transport_stats.second.transport_name); if (remote_certificate) { certificate_stats_pair.remote = remote_certificate->GetStats(); } @@ -1195,16 +1193,16 @@ std::unique_ptr RTCStatsCollector::PrepareTrackMediaInfoMap_s() const { RTC_DCHECK(signaling_thread_->IsCurrent()); std::unique_ptr voice_media_info; - if (pc_->session()->voice_channel()) { + if (pc_->voice_channel()) { voice_media_info.reset(new cricket::VoiceMediaInfo()); - if (!pc_->session()->voice_channel()->GetStats(voice_media_info.get())) { + if (!pc_->voice_channel()->GetStats(voice_media_info.get())) { voice_media_info.reset(); } } std::unique_ptr video_media_info; - if (pc_->session()->video_channel()) { + if (pc_->video_channel()) { video_media_info.reset(new cricket::VideoMediaInfo()); - if (!pc_->session()->video_channel()->GetStats(video_media_info.get())) { + if (!pc_->video_channel()->GetStats(video_media_info.get())) { video_media_info.reset(); } } diff --git a/pc/rtcstatscollector_unittest.cc b/pc/rtcstatscollector_unittest.cc index 14f669cc35..9a34bfef22 100644 --- a/pc/rtcstatscollector_unittest.cc +++ b/pc/rtcstatscollector_unittest.cc @@ -286,10 +286,10 @@ class RTCStatsCollectorTestHelper : public SetSessionDescriptionObserver { network_thread_)), session_(channel_manager_.get(), cricket::MediaConfig()), pc_() { + pc_.set_session_for_testing(&session_); // Default return values for mocks. EXPECT_CALL(pc_, local_streams()).WillRepeatedly(Return(nullptr)); EXPECT_CALL(pc_, remote_streams()).WillRepeatedly(Return(nullptr)); - EXPECT_CALL(pc_, session()).WillRepeatedly(Return(&session_)); EXPECT_CALL(pc_, GetSenders()).WillRepeatedly(Return( std::vector>())); EXPECT_CALL(pc_, GetReceivers()).WillRepeatedly(Return( @@ -561,14 +561,11 @@ class FakeRTCStatsCollector : public RTCStatsCollector, } protected: - FakeRTCStatsCollector( - PeerConnection* pc, - int64_t cache_lifetime) + FakeRTCStatsCollector(PeerConnection* pc, int64_t cache_lifetime) : RTCStatsCollector(pc, cache_lifetime), - signaling_thread_(pc->session()->signaling_thread()), - worker_thread_(pc->session()->worker_thread()), - network_thread_(pc->session()->network_thread()) { - } + signaling_thread_(pc->signaling_thread()), + worker_thread_(pc->worker_thread()), + network_thread_(pc->network_thread()) {} void ProducePartialResultsOnSignalingThread(int64_t timestamp_us) override { EXPECT_TRUE(signaling_thread_->IsCurrent()); diff --git a/pc/statscollector.cc b/pc/statscollector.cc index 070c942118..eedd2286bc 100644 --- a/pc/statscollector.cc +++ b/pc/statscollector.cc @@ -447,7 +447,7 @@ StatsCollector::StatsCollector(PeerConnection* pc) } StatsCollector::~StatsCollector() { - RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); + RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); } // Wallclock time in ms. @@ -459,7 +459,7 @@ double StatsCollector::GetTimeNow() { // Adds a MediaStream with tracks that can be used as a |selector| in a call // to GetStats. void StatsCollector::AddStream(MediaStreamInterface* stream) { - RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); + RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); RTC_DCHECK(stream != NULL); CreateTrackReports(stream->GetAudioTracks(), @@ -470,7 +470,7 @@ void StatsCollector::AddStream(MediaStreamInterface* stream) { void StatsCollector::AddLocalAudioTrack(AudioTrackInterface* audio_track, uint32_t ssrc) { - RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); + RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); RTC_DCHECK(audio_track != NULL); #if RTC_DCHECK_IS_ON for (const auto& track : local_audio_tracks_) @@ -504,7 +504,7 @@ void StatsCollector::RemoveLocalAudioTrack(AudioTrackInterface* audio_track, void StatsCollector::GetStats(MediaStreamTrackInterface* track, StatsReports* reports) { - RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); + RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); RTC_DCHECK(reports != NULL); RTC_DCHECK(reports->empty()); @@ -518,7 +518,7 @@ void StatsCollector::GetStats(MediaStreamTrackInterface* track, } StatsReport* report = reports_.Find(StatsReport::NewTypedId( - StatsReport::kStatsReportTypeSession, pc_->session()->id())); + StatsReport::kStatsReportTypeSession, pc_->session_id())); if (report) reports->push_back(report); @@ -544,7 +544,7 @@ void StatsCollector::GetStats(MediaStreamTrackInterface* track, void StatsCollector::UpdateStats(PeerConnectionInterface::StatsOutputLevel level) { - RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); + RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); double time_now = GetTimeNow(); // Calls to UpdateStats() that occur less than kMinGatherStatsPeriod number of // ms apart will be ignored. @@ -557,7 +557,7 @@ StatsCollector::UpdateStats(PeerConnectionInterface::StatsOutputLevel level) { // TODO(pthatcher): Merge PeerConnection and WebRtcSession so there is no // pc_->session(). - if (pc_->session()) { + if (pc_->session_created()) { // TODO(tommi): All of these hop over to the worker thread to fetch // information. We could use an AsyncInvoker to run all of these and post // the information back to the signaling thread where we can create and @@ -579,7 +579,7 @@ StatsReport* StatsCollector::PrepareReport( uint32_t ssrc, const StatsReport::Id& transport_id, StatsReport::Direction direction) { - RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); + RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); StatsReport::Id id(StatsReport::NewIdWithDirection( local ? StatsReport::kStatsReportTypeSsrc : StatsReport::kStatsReportTypeRemoteSsrc, @@ -623,7 +623,7 @@ bool StatsCollector::IsValidTrack(const std::string& track_id) { StatsReport* StatsCollector::AddCertificateReports( const rtc::SSLCertificate* cert) { - RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); + RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); RTC_DCHECK(cert != NULL); std::unique_ptr first_stats = cert->GetStats(); @@ -734,17 +734,17 @@ StatsReport* StatsCollector::AddCandidateReport( } void StatsCollector::ExtractSessionInfo() { - RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); + RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); // Extract information from the base session. StatsReport::Id id(StatsReport::NewTypedId( - StatsReport::kStatsReportTypeSession, pc_->session()->id())); + StatsReport::kStatsReportTypeSession, pc_->session_id())); StatsReport* report = reports_.ReplaceOrAddNew(id); report->set_timestamp(stats_gathering_started_); report->AddBoolean(StatsReport::kStatsValueNameInitiator, - pc_->session()->initial_offerer()); + pc_->initial_offerer()); - std::unique_ptr stats = pc_->session()->GetStats_s(); + std::unique_ptr stats = pc_->GetSessionStats_s(); if (!stats) { return; } @@ -764,16 +764,15 @@ void StatsCollector::ExtractSessionInfo() { // StatsReport::Id local_cert_report_id, remote_cert_report_id; rtc::scoped_refptr certificate; - if (pc_->session()->GetLocalCertificate( - transport_iter.second.transport_name, &certificate)) { + if (pc_->GetLocalCertificate(transport_iter.second.transport_name, + &certificate)) { StatsReport* r = AddCertificateReports(&(certificate->ssl_certificate())); if (r) local_cert_report_id = r->id(); } std::unique_ptr cert = - pc_->session()->GetRemoteSSLCertificate( - transport_iter.second.transport_name); + pc_->GetRemoteSSLCertificate(transport_iter.second.transport_name); if (cert) { StatsReport* r = AddCertificateReports(cert.get()); if (r) @@ -828,20 +827,20 @@ void StatsCollector::ExtractSessionInfo() { } void StatsCollector::ExtractBweInfo() { - RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); + RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); - if (pc_->session()->state() == WebRtcSession::State::STATE_CLOSED) + if (pc_->signaling_state() == PeerConnectionInterface::kClosed) return; - webrtc::Call::Stats call_stats = pc_->session()->GetCallStats(); + webrtc::Call::Stats call_stats = pc_->GetCallStats(); cricket::BandwidthEstimationInfo bwe_info; bwe_info.available_send_bandwidth = call_stats.send_bandwidth_bps; bwe_info.available_recv_bandwidth = call_stats.recv_bandwidth_bps; bwe_info.bucket_delay = call_stats.pacer_delay_ms; // Fill in target encoder bitrate, actual encoder bitrate, rtx bitrate, etc. // TODO(holmer): Also fill this in for audio. - if (pc_->session()->video_channel()) { - pc_->session()->video_channel()->FillBitrateInfo(&bwe_info); + if (pc_->video_channel()) { + pc_->video_channel()->FillBitrateInfo(&bwe_info); } StatsReport::Id report_id(StatsReport::NewBandwidthEstimationId()); StatsReport* report = reports_.FindOrAddNew(report_id); @@ -849,13 +848,13 @@ void StatsCollector::ExtractBweInfo() { } void StatsCollector::ExtractVoiceInfo() { - RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); + RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); - if (!pc_->session()->voice_channel()) { + if (!pc_->voice_channel()) { return; } cricket::VoiceMediaInfo voice_info; - if (!pc_->session()->voice_channel()->GetStats(&voice_info)) { + if (!pc_->voice_channel()->GetStats(&voice_info)) { LOG(LS_ERROR) << "Failed to get voice channel stats."; return; } @@ -865,10 +864,10 @@ void StatsCollector::ExtractVoiceInfo() { rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; StatsReport::Id transport_id(GetTransportIdFromProxy( - proxy_to_transport_, pc_->session()->voice_channel()->content_name())); + proxy_to_transport_, pc_->voice_channel()->content_name())); if (!transport_id.get()) { LOG(LS_ERROR) << "Failed to get transport name for proxy " - << pc_->session()->voice_channel()->content_name(); + << pc_->voice_channel()->content_name(); return; } @@ -882,13 +881,13 @@ void StatsCollector::ExtractVoiceInfo() { void StatsCollector::ExtractVideoInfo( PeerConnectionInterface::StatsOutputLevel level) { - RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); + RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); - if (!pc_->session()->video_channel()) + if (!pc_->video_channel()) return; cricket::VideoMediaInfo video_info; - if (!pc_->session()->video_channel()->GetStats(&video_info)) { + if (!pc_->video_channel()->GetStats(&video_info)) { LOG(LS_ERROR) << "Failed to get video channel stats."; return; } @@ -898,10 +897,10 @@ void StatsCollector::ExtractVideoInfo( rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; StatsReport::Id transport_id(GetTransportIdFromProxy( - proxy_to_transport_, pc_->session()->video_channel()->content_name())); + proxy_to_transport_, pc_->video_channel()->content_name())); if (!transport_id.get()) { LOG(LS_ERROR) << "Failed to get transport name for proxy " - << pc_->session()->video_channel()->content_name(); + << pc_->video_channel()->content_name(); return; } ExtractStatsFromList(video_info.receivers, transport_id, this, @@ -911,7 +910,7 @@ void StatsCollector::ExtractVideoInfo( } void StatsCollector::ExtractSenderInfo() { - RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); + RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); for (const auto& sender : pc_->GetSenders()) { // TODO(nisse): SSRC == 0 currently means none. Delete check when @@ -944,7 +943,7 @@ void StatsCollector::ExtractSenderInfo() { } void StatsCollector::ExtractDataInfo() { - RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); + RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; @@ -967,14 +966,14 @@ void StatsCollector::ExtractDataInfo() { StatsReport* StatsCollector::GetReport(const StatsReport::StatsType& type, const std::string& id, StatsReport::Direction direction) { - RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); + RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); RTC_DCHECK(type == StatsReport::kStatsReportTypeSsrc || type == StatsReport::kStatsReportTypeRemoteSsrc); return reports_.Find(StatsReport::NewIdWithDirection(type, id, direction)); } void StatsCollector::UpdateStatsFromExistingLocalAudioTracks() { - RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); + RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); // Loop through the existing local audio tracks. for (const auto& it : local_audio_tracks_) { AudioTrackInterface* track = it.first; @@ -1002,7 +1001,7 @@ void StatsCollector::UpdateStatsFromExistingLocalAudioTracks() { void StatsCollector::UpdateReportFromAudioTrack(AudioTrackInterface* track, StatsReport* report) { - RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); + RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); RTC_DCHECK(track != NULL); // Don't overwrite report values if they're not available. @@ -1033,16 +1032,16 @@ void StatsCollector::UpdateReportFromAudioTrack(AudioTrackInterface* track, bool StatsCollector::GetTrackIdBySsrc(uint32_t ssrc, std::string* track_id, StatsReport::Direction direction) { - RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); + RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); if (direction == StatsReport::kSend) { - if (!pc_->session()->GetLocalTrackIdBySsrc(ssrc, track_id)) { + if (!pc_->GetLocalTrackIdBySsrc(ssrc, track_id)) { LOG(LS_WARNING) << "The SSRC " << ssrc << " is not associated with a sending track"; return false; } } else { RTC_DCHECK(direction == StatsReport::kReceive); - if (!pc_->session()->GetRemoteTrackIdBySsrc(ssrc, track_id)) { + if (!pc_->GetRemoteTrackIdBySsrc(ssrc, track_id)) { LOG(LS_WARNING) << "The SSRC " << ssrc << " is not associated with a receiving track"; return false; @@ -1053,7 +1052,7 @@ bool StatsCollector::GetTrackIdBySsrc(uint32_t ssrc, } void StatsCollector::UpdateTrackReports() { - RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); + RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; diff --git a/pc/statscollector_unittest.cc b/pc/statscollector_unittest.cc index 6a1d82702b..5e34f7f4e3 100644 --- a/pc/statscollector_unittest.cc +++ b/pc/statscollector_unittest.cc @@ -573,12 +573,12 @@ class StatsCollectorTest : public testing::Test { network_thread_)), session_(channel_manager_.get(), cricket::MediaConfig()) { + pc_.set_session_for_testing(&session_); // By default, we ignore session GetStats calls. EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(ReturnNull()); // Add default returns for mock classes. EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull()); EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull()); - EXPECT_CALL(pc_, session()).WillRepeatedly(Return(&session_)); EXPECT_CALL(pc_, sctp_data_channels()) .WillRepeatedly(ReturnRef(data_channels_)); EXPECT_CALL(pc_, GetSenders()).WillRepeatedly(Return( diff --git a/pc/test/mock_peerconnection.h b/pc/test/mock_peerconnection.h index 73f4a4b5ba..7944a4d966 100644 --- a/pc/test/mock_peerconnection.h +++ b/pc/test/mock_peerconnection.h @@ -47,7 +47,6 @@ class MockPeerConnection rtc::scoped_refptr()); MOCK_METHOD0(remote_streams, rtc::scoped_refptr()); - MOCK_METHOD0(session, WebRtcSession*()); MOCK_CONST_METHOD0(GetSenders, std::vector>()); MOCK_CONST_METHOD0(GetReceivers,