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;