diff --git a/webrtc/video_engine/report_block_stats.cc b/webrtc/video_engine/report_block_stats.cc index 61167f167c..ea18e830e3 100644 --- a/webrtc/video_engine/report_block_stats.cc +++ b/webrtc/video_engine/report_block_stats.cc @@ -100,6 +100,9 @@ void ReportBlockStats::StoreAndAddPacketIncrement( } int ReportBlockStats::FractionLostInPercent() const { + if (num_sequence_numbers_ == 0) { + return -1; + } return FractionLost( num_lost_sequence_numbers_, num_sequence_numbers_) * 100 / 255; } diff --git a/webrtc/video_engine/report_block_stats.h b/webrtc/video_engine/report_block_stats.h index 2d6b16e657..dadcc9d410 100644 --- a/webrtc/video_engine/report_block_stats.h +++ b/webrtc/video_engine/report_block_stats.h @@ -36,7 +36,8 @@ class ReportBlockStats { uint32_t remote_ssrc, uint32_t source_ssrc); - // Returns the total fraction of lost packets. + // Returns the total fraction of lost packets (or -1 if less than two report + // blocks have been stored). int FractionLostInPercent() const; private: diff --git a/webrtc/video_engine/report_block_stats_unittest.cc b/webrtc/video_engine/report_block_stats_unittest.cc index 10c4104241..e688d2eb01 100644 --- a/webrtc/video_engine/report_block_stats_unittest.cc +++ b/webrtc/video_engine/report_block_stats_unittest.cc @@ -129,11 +129,11 @@ TEST_F(ReportBlockStatsTest, AggregateAndStore_TwoSsrcs) { TEST_F(ReportBlockStatsTest, StoreAndGetFractionLost) { const uint32_t kRemoteSsrc = 1; ReportBlockStats stats; - EXPECT_EQ(0, stats.FractionLostInPercent()); + EXPECT_EQ(-1, stats.FractionLostInPercent()); - // First block => 0% + // First block. stats.Store(RtcpReportBlockToRtcpStatistics(block1_1_), kRemoteSsrc, kSsrc1); - EXPECT_EQ(0, stats.FractionLostInPercent()); + EXPECT_EQ(-1, stats.FractionLostInPercent()); // fl: 100 * (15-10) / (24100-24000) = 5% stats.Store(RtcpReportBlockToRtcpStatistics(block1_2_), kRemoteSsrc, kSsrc1); EXPECT_EQ(5, stats.FractionLostInPercent()); diff --git a/webrtc/video_engine/vie_channel.cc b/webrtc/video_engine/vie_channel.cc index ee560b42c8..a83e30fc8c 100644 --- a/webrtc/video_engine/vie_channel.cc +++ b/webrtc/video_engine/vie_channel.cc @@ -212,8 +212,11 @@ void ViEChannel::UpdateHistograms() { "WebRTC.Video.UniqueNackRequestsReceivedInPercent", rtcp_received.UniqueNackRequestsInPercent()); } - RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.SentPacketsLostInPercent", - report_block_stats_sender_->FractionLostInPercent()); + int fraction_lost = report_block_stats_sender_->FractionLostInPercent(); + if (fraction_lost != -1) { + RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.SentPacketsLostInPercent", + fraction_lost); + } } } else if (vie_receiver_.GetRemoteSsrc() > 0) { // Get receive stats if we are receiving packets, i.e. there is a remote @@ -230,8 +233,11 @@ void ViEChannel::UpdateHistograms() { RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.UniqueNackRequestsSentInPercent", rtcp_sent.UniqueNackRequestsInPercent()); } - RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.ReceivedPacketsLostInPercent", - report_block_stats_receiver_->FractionLostInPercent()); + int fraction_lost = report_block_stats_receiver_->FractionLostInPercent(); + if (fraction_lost != -1) { + RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.ReceivedPacketsLostInPercent", + fraction_lost); + } } StreamDataCounters rtp;