diff --git a/pc/rtc_stats_collector.cc b/pc/rtc_stats_collector.cc index 5b21d33f89..aaeb721dc0 100644 --- a/pc/rtc_stats_collector.cc +++ b/pc/rtc_stats_collector.cc @@ -1074,24 +1074,14 @@ void RTCStatsCollector::GetStatsReportInternal( num_pending_partial_reports_ = 2; partial_report_timestamp_us_ = cache_now_us; - // Prepare |transceiver_stats_infos_| for use in + // Prepare |transceiver_stats_infos_| and |call_stats_| for use in // |ProducePartialResultsOnNetworkThread| and // |ProducePartialResultsOnSignalingThread|. - transceiver_stats_infos_ = PrepareTransceiverStatsInfos_s_w(); + PrepareTransceiverStatsInfosAndCallStats_s_w(); // Prepare |transport_names_| for use in // |ProducePartialResultsOnNetworkThread|. transport_names_ = PrepareTransportNames_s(); - // Prepare |call_stats_| here since GetCallStats() will hop to the worker - // thread. - // TODO(holmer): To avoid the hop we could move BWE and BWE stats to the - // network thread, where it more naturally belongs. - // TODO(https://crbug.com/webrtc/11767): In the meantime we can piggyback on - // the blocking-invoke that is already performed in - // PrepareTransceiverStatsInfos_s_w() so that we can call GetCallStats() - // without additional blocking-invokes. - call_stats_ = pc_->GetCallStats(); - // Don't touch |network_report_| on the signaling thread until // ProducePartialResultsOnNetworkThread() has signaled the // |network_report_event_|. @@ -1898,11 +1888,10 @@ RTCStatsCollector::PrepareTransportCertificateStats_n( return transport_cert_stats; } -std::vector -RTCStatsCollector::PrepareTransceiverStatsInfos_s_w() const { +void RTCStatsCollector::PrepareTransceiverStatsInfosAndCallStats_s_w() { RTC_DCHECK(signaling_thread_->IsCurrent()); - std::vector transceiver_stats_infos; + transceiver_stats_infos_.clear(); // These are used to invoke GetStats for all the media channels together in // one worker thread hop. std::mapinternal(); stats.media_type = media_type; @@ -1952,9 +1941,10 @@ RTCStatsCollector::PrepareTransceiverStatsInfos_s_w() const { } } - // We jump to the worker thread and call GetStats() on each media channel. At - // the same time we construct the TrackMediaInfoMaps, which also needs info - // from the worker thread. This minimizes the number of thread jumps. + // We jump to the worker thread and call GetStats() on each media channel as + // well as GetCallStats(). At the same time we construct the + // TrackMediaInfoMaps, which also needs info from the worker thread. This + // minimizes the number of thread jumps. worker_thread_->Invoke(RTC_FROM_HERE, [&] { rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; @@ -1971,7 +1961,7 @@ RTCStatsCollector::PrepareTransceiverStatsInfos_s_w() const { } // Create the TrackMediaInfoMap for each transceiver stats object. - for (auto& stats : transceiver_stats_infos) { + for (auto& stats : transceiver_stats_infos_) { auto transceiver = stats.transceiver; std::unique_ptr voice_media_info; std::unique_ptr video_media_info; @@ -2003,9 +1993,9 @@ RTCStatsCollector::PrepareTransceiverStatsInfos_s_w() const { std::move(voice_media_info), std::move(video_media_info), senders, receivers); } - }); - return transceiver_stats_infos; + call_stats_ = pc_->GetCallStats(); + }); } std::set RTCStatsCollector::PrepareTransportNames_s() const { diff --git a/pc/rtc_stats_collector.h b/pc/rtc_stats_collector.h index e1bc27d9e5..35576e91d8 100644 --- a/pc/rtc_stats_collector.h +++ b/pc/rtc_stats_collector.h @@ -215,7 +215,8 @@ class RTCStatsCollector : public virtual rtc::RefCountInterface, PrepareTransportCertificateStats_n( const std::map& transport_stats_by_name) const; - std::vector PrepareTransceiverStatsInfos_s_w() const; + // The results are stored in |transceiver_stats_infos_| and |call_stats_|. + void PrepareTransceiverStatsInfosAndCallStats_s_w(); std::set PrepareTransportNames_s() const; // Stats gathering on a particular thread.