diff --git a/pc/rtc_stats_collector.cc b/pc/rtc_stats_collector.cc index a9fb3b7d76..afb819f8f0 100644 --- a/pc/rtc_stats_collector.cc +++ b/pc/rtc_stats_collector.cc @@ -1249,7 +1249,10 @@ void ProduceReceiverMediaTrackStats( } } -rtc::scoped_refptr CreateReportFilteredBySelector( +} // namespace + +rtc::scoped_refptr +RTCStatsCollector::CreateReportFilteredBySelector( bool filter_by_sender_selector, rtc::scoped_refptr report, rtc::scoped_refptr sender_selector, @@ -1258,40 +1261,40 @@ rtc::scoped_refptr CreateReportFilteredBySelector( if (filter_by_sender_selector) { // Filter mode: RTCStatsCollector::RequestInfo::kSenderSelector if (sender_selector) { - // Find outbound-rtp(s) of the sender, i.e. the outbound-rtp(s) that - // reference the sender stats. - // Because we do not implement sender stats, we look at outbound-rtp(s) - // that reference the track attachment stats for the sender instead. - std::string track_id = - DEPRECATED_RTCMediaStreamTrackStatsIDFromDirectionAndAttachment( - kDirectionOutbound, sender_selector->AttachmentId()); - for (const auto& stats : *report) { - if (stats.type() != RTCOutboundRTPStreamStats::kType) - continue; - const auto& outbound_rtp = stats.cast_to(); - if (outbound_rtp.track_id.is_defined() && - *outbound_rtp.track_id == track_id) { - rtpstream_ids.push_back(outbound_rtp.id()); + // Find outbound-rtp(s) of the sender using ssrc lookup. + auto encodings = sender_selector->GetParametersInternal().encodings; + for (const auto* outbound_rtp : + report->GetStatsOfType()) { + RTC_DCHECK(outbound_rtp->ssrc.is_defined()); + auto it = std::find_if( + encodings.begin(), encodings.end(), + [ssrc = + *outbound_rtp->ssrc](const RtpEncodingParameters& encoding) { + return encoding.ssrc.has_value() && encoding.ssrc.value() == ssrc; + }); + if (it != encodings.end()) { + rtpstream_ids.push_back(outbound_rtp->id()); } } } } else { // Filter mode: RTCStatsCollector::RequestInfo::kReceiverSelector if (receiver_selector) { - // Find inbound-rtp(s) of the receiver, i.e. the inbound-rtp(s) that - // reference the receiver stats. - // Because we do not implement receiver stats, we look at inbound-rtp(s) - // that reference the track attachment stats for the receiver instead. - std::string track_id = - DEPRECATED_RTCMediaStreamTrackStatsIDFromDirectionAndAttachment( - kDirectionInbound, receiver_selector->AttachmentId()); - for (const auto& stats : *report) { - if (stats.type() != RTCInboundRTPStreamStats::kType) - continue; - const auto& inbound_rtp = stats.cast_to(); - if (inbound_rtp.track_id.is_defined() && - *inbound_rtp.track_id == track_id) { - rtpstream_ids.push_back(inbound_rtp.id()); + // Find the inbound-rtp of the receiver using ssrc lookup. + absl::optional ssrc; + worker_thread_->BlockingCall([&] { + auto encodings = receiver_selector->GetParameters().encodings; + if (!encodings.empty()) { + ssrc = encodings[0].ssrc; + } + }); + if (ssrc.has_value()) { + for (const auto* inbound_rtp : + report->GetStatsOfType()) { + RTC_DCHECK(inbound_rtp->ssrc.is_defined()); + if (*inbound_rtp->ssrc == *ssrc) { + rtpstream_ids.push_back(inbound_rtp->id()); + } } } } @@ -1301,8 +1304,6 @@ rtc::scoped_refptr CreateReportFilteredBySelector( return TakeReferencedStats(report->Copy(), rtpstream_ids); } -} // namespace - RTCStatsCollector::CertificateStatsPair RTCStatsCollector::CertificateStatsPair::Copy() const { CertificateStatsPair copy; diff --git a/pc/rtc_stats_collector.h b/pc/rtc_stats_collector.h index 91175289e8..0f1cab19db 100644 --- a/pc/rtc_stats_collector.h +++ b/pc/rtc_stats_collector.h @@ -244,6 +244,12 @@ class RTCStatsCollector : public rtc::RefCountInterface, // This is a NO-OP if `network_report_` is null. void MergeNetworkReport_s(); + rtc::scoped_refptr CreateReportFilteredBySelector( + bool filter_by_sender_selector, + rtc::scoped_refptr report, + rtc::scoped_refptr sender_selector, + rtc::scoped_refptr receiver_selector); + // Slots for signals (sigslot) that are wired up to `pc_`. void OnSctpDataChannelCreated(SctpDataChannel* channel); // Slots for signals (sigslot) that are wired up to `channel`. diff --git a/pc/rtc_stats_collector_unittest.cc b/pc/rtc_stats_collector_unittest.cc index 5388355eb7..31ccfed839 100644 --- a/pc/rtc_stats_collector_unittest.cc +++ b/pc/rtc_stats_collector_unittest.cc @@ -388,7 +388,10 @@ rtc::scoped_refptr CreateMockSender( EXPECT_CALL(*sender, track()).WillRepeatedly(Return(track)); EXPECT_CALL(*sender, ssrc()).WillRepeatedly(Return(ssrc)); EXPECT_CALL(*sender, media_type()).WillRepeatedly(Return(media_type)); - EXPECT_CALL(*sender, GetParameters()).WillRepeatedly(Invoke([ssrc]() { + EXPECT_CALL(*sender, GetParameters()) + .WillRepeatedly( + Invoke([s = sender.get()]() { return s->GetParametersInternal(); })); + EXPECT_CALL(*sender, GetParametersInternal()).WillRepeatedly(Invoke([ssrc]() { RtpParameters params; params.encodings.push_back(RtpEncodingParameters()); params.encodings[0].ssrc = ssrc;