From 56fa0501257da6facaf8540bf50e52f775b89a6c Mon Sep 17 00:00:00 2001 From: Sebastian Jansson Date: Thu, 1 Feb 2018 13:00:57 +0100 Subject: [PATCH] Improved accuracy of packet loss calculation in tests. Test of packet loss used a simplified calculation of lost packets and loss ratio. Changed the calculation to be more accurate. This protects against triggering for future implementations with more precise calculations. Bug: webrtc:8415 Change-Id: I721dc83954e8738fdf8ea729dee4cc8b8c8fa091 Reviewed-on: https://webrtc-review.googlesource.com/46740 Reviewed-by: Stefan Holmer Commit-Queue: Sebastian Jansson Cr-Commit-Position: refs/heads/master@{#21845} --- video/video_send_stream_tests.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/video/video_send_stream_tests.cc b/video/video_send_stream_tests.cc index d5226bfedb..3512b8585f 100644 --- a/video/video_send_stream_tests.cc +++ b/video/video_send_stream_tests.cc @@ -893,6 +893,9 @@ void VideoSendStreamTest::TestPacketFragmentationSize(VideoFormat format, test_generic_packetization_(test_generic_packetization), use_fec_(use_fec), packet_count_(0), + packets_lost_(0), + last_packet_count_(0), + last_packets_lost_(0), accumulated_size_(0), accumulated_payload_(0), fec_packet_received_(false), @@ -984,11 +987,18 @@ void VideoSendStreamTest::TestPacketFragmentationSize(VideoFormat format, void TriggerLossReport(const RTPHeader& header) { // Send lossy receive reports to trigger FEC enabling. const int kLossPercent = 5; - if (packet_count_++ % (100 / kLossPercent) != 0) { + if (++packet_count_ % (100 / kLossPercent) == 0) { + packets_lost_++; + int loss_delta = packets_lost_ - last_packets_lost_; + int packets_delta = packet_count_ - last_packet_count_; + last_packet_count_ = packet_count_; + last_packets_lost_ = packets_lost_; + uint8_t loss_ratio = + static_cast(loss_delta * 255 / packets_delta); FakeReceiveStatistics lossy_receive_stats( kVideoSendSsrcs[0], header.sequenceNumber, - (packet_count_ * (100 - kLossPercent)) / 100, // Cumulative lost. - static_cast((255 * kLossPercent) / 100)); // Loss percent. + packets_lost_, // Cumulative lost. + loss_ratio); // Loss percent. RTCPSender rtcp_sender(false, Clock::GetRealTimeClock(), &lossy_receive_stats, nullptr, nullptr, transport_adapter_.get(), RtcpIntervalConfig{}); @@ -1085,6 +1095,9 @@ void VideoSendStreamTest::TestPacketFragmentationSize(VideoFormat format, const bool use_fec_; uint32_t packet_count_; + uint32_t packets_lost_; + uint32_t last_packet_count_; + uint32_t last_packets_lost_; size_t accumulated_size_; size_t accumulated_payload_; bool fec_packet_received_;