diff --git a/webrtc/video/video_send_stream_tests.cc b/webrtc/video/video_send_stream_tests.cc index 8330b9df4..f5ec59b53 100644 --- a/webrtc/video/video_send_stream_tests.cc +++ b/webrtc/video/video_send_stream_tests.cc @@ -1423,14 +1423,17 @@ TEST_F(VideoSendStreamTest, EncoderSetupPropagatesVp8Config) { } TEST_F(VideoSendStreamTest, RtcpSenderReportContainsMediaBytesSent) { - class RtcpByeTest : public test::SendTest { + class RtcpSenderReportTest : public test::SendTest { public: - RtcpByeTest() : SendTest(kDefaultTimeoutMs), media_bytes_sent_(0) {} + RtcpSenderReportTest() : SendTest(kDefaultTimeoutMs), + rtp_packets_sent_(0), + media_bytes_sent_(0) {} private: virtual Action OnSendRtp(const uint8_t* packet, size_t length) OVERRIDE { RTPHeader header; EXPECT_TRUE(parser_->Parse(packet, length, &header)); + ++rtp_packets_sent_; media_bytes_sent_ += length - header.headerLength - header.paddingLength; return SEND_PACKET; } @@ -1440,15 +1443,17 @@ TEST_F(VideoSendStreamTest, RtcpSenderReportContainsMediaBytesSent) { EXPECT_TRUE(parser.IsValid()); RTCPUtility::RTCPPacketTypes packet_type = parser.Begin(); - uint32_t sender_octet_count = 0; while (packet_type != RTCPUtility::kRtcpNotValidCode) { if (packet_type == RTCPUtility::kRtcpSrCode) { - sender_octet_count = parser.Packet().SR.SenderOctetCount; - EXPECT_EQ(sender_octet_count, media_bytes_sent_); - if (sender_octet_count > 0) + // Only compare sent media bytes if SenderPacketCount matches the + // number of sent rtp packets (a new rtp packet could be sent before + // the rtcp packet). + if (parser.Packet().SR.SenderOctetCount > 0 && + parser.Packet().SR.SenderPacketCount == rtp_packets_sent_) { + EXPECT_EQ(media_bytes_sent_, parser.Packet().SR.SenderOctetCount); observation_complete_->Set(); + } } - packet_type = parser.Iterate(); } @@ -1460,6 +1465,7 @@ TEST_F(VideoSendStreamTest, RtcpSenderReportContainsMediaBytesSent) { << "Timed out while waiting for RTCP sender report."; } + size_t rtp_packets_sent_; size_t media_bytes_sent_; } test;