From a3a3b6d7981d475b4018fda2cbcce212e83686a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Bostr=C3=B6m?= Date: Tue, 22 Nov 2022 09:56:49 +0100 Subject: [PATCH] [Stats] If remote-inbound-rtp has no RTT, leave it undefined. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:14692 Change-Id: I49878449cd91b590f1aedef7676c3715d563ac61 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/284660 Commit-Queue: Henrik Boström Auto-Submit: Henrik Boström Reviewed-by: Harald Alvestrand Commit-Queue: Harald Alvestrand Cr-Commit-Position: refs/heads/main@{#38706} --- pc/rtc_stats_collector.cc | 8 +++++--- pc/rtc_stats_collector_unittest.cc | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/pc/rtc_stats_collector.cc b/pc/rtc_stats_collector.cc index e4a541805a..f0070dfda6 100644 --- a/pc/rtc_stats_collector.cc +++ b/pc/rtc_stats_collector.cc @@ -815,9 +815,11 @@ ProduceRemoteInboundRtpStreamStatsFromReportBlockData( remote_inbound->packets_lost = report_block.packets_lost; remote_inbound->fraction_lost = static_cast(report_block.fraction_lost) / (1 << 8); - remote_inbound->round_trip_time = - static_cast(report_block_data.last_rtt_ms()) / - rtc::kNumMillisecsPerSec; + if (report_block_data.num_rtts() > 0) { + remote_inbound->round_trip_time = + static_cast(report_block_data.last_rtt_ms()) / + rtc::kNumMillisecsPerSec; + } remote_inbound->total_round_trip_time = static_cast(report_block_data.sum_rtt_ms()) / rtc::kNumMillisecsPerSec; diff --git a/pc/rtc_stats_collector_unittest.cc b/pc/rtc_stats_collector_unittest.cc index a3a17801c1..1982446667 100644 --- a/pc/rtc_stats_collector_unittest.cc +++ b/pc/rtc_stats_collector_unittest.cc @@ -3557,6 +3557,32 @@ TEST_P(RTCStatsCollectorTestWithParamKind, } } +TEST_P(RTCStatsCollectorTestWithParamKind, + RTCRemoteInboundRtpStreamStatsRttMissingBeforeMeasurement) { + constexpr int64_t kReportBlockTimestampUtcUs = 123456789; + + RTCPReportBlock report_block; + // The remote-inbound-rtp SSRC and the outbound-rtp SSRC is the same as the + // `source_ssrc`, "SSRC of the RTP packet sender". + report_block.source_ssrc = 12; + ReportBlockData report_block_data; // AddRoundTripTimeSample() not called. + report_block_data.SetReportBlock(report_block, kReportBlockTimestampUtcUs); + + AddSenderInfoAndMediaChannel("TransportName", {report_block_data}, + absl::nullopt); + + rtc::scoped_refptr report = stats_->GetStatsReport(); + + std::string remote_inbound_rtp_id = "RI" + MediaTypeCharStr() + "12"; + ASSERT_TRUE(report->Get(remote_inbound_rtp_id)); + auto& remote_inbound_rtp = report->Get(remote_inbound_rtp_id) + ->cast_to(); + + EXPECT_TRUE(remote_inbound_rtp.round_trip_time_measurements.is_defined()); + EXPECT_EQ(0, *remote_inbound_rtp.round_trip_time_measurements); + EXPECT_FALSE(remote_inbound_rtp.round_trip_time.is_defined()); +} + TEST_P(RTCStatsCollectorTestWithParamKind, RTCRemoteInboundRtpStreamStatsWithTimestampFromReportBlock) { const int64_t kReportBlockTimestampUtcUs = 123456789;