OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include "webrtc/video/send_delay_stats.h" |
| 12 |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "webrtc/system_wrappers/include/metrics.h" |
| 15 #include "webrtc/test/histogram.h" |
| 16 |
| 17 namespace webrtc { |
| 18 namespace { |
| 19 const uint32_t kSsrc1 = 17; |
| 20 const uint32_t kSsrc2 = 42; |
| 21 const uint32_t kRtxSsrc1 = 18; |
| 22 const uint32_t kRtxSsrc2 = 43; |
| 23 const uint16_t kPacketId = 2345; |
| 24 const int64_t kMaxPacketDelayMs = 11000; |
| 25 const int kMinRequiredSamples = 200; |
| 26 } // namespace |
| 27 |
| 28 class SendDelayStatsTest : public ::testing::Test { |
| 29 public: |
| 30 SendDelayStatsTest() : clock_(1234), config_(CreateConfig()) {} |
| 31 virtual ~SendDelayStatsTest() {} |
| 32 |
| 33 protected: |
| 34 virtual void SetUp() { |
| 35 stats_.reset(new SendDelayStats(&clock_)); |
| 36 stats_->AddSsrcs(config_); |
| 37 } |
| 38 |
| 39 VideoSendStream::Config CreateConfig() { |
| 40 VideoSendStream::Config config(nullptr); |
| 41 config.rtp.ssrcs.push_back(kSsrc1); |
| 42 config.rtp.ssrcs.push_back(kSsrc2); |
| 43 config.rtp.rtx.ssrcs.push_back(kRtxSsrc1); |
| 44 config.rtp.rtx.ssrcs.push_back(kRtxSsrc2); |
| 45 return config; |
| 46 } |
| 47 |
| 48 void OnSendPacket(uint16_t id, uint32_t ssrc) { |
| 49 OnSendPacket(id, ssrc, clock_.TimeInMilliseconds()); |
| 50 } |
| 51 |
| 52 void OnSendPacket(uint16_t id, uint32_t ssrc, int64_t capture_ms) { |
| 53 SendPacketObserver* observer = stats_.get(); |
| 54 observer->OnSendPacket(id, capture_ms, ssrc); |
| 55 } |
| 56 |
| 57 bool OnSentPacket(uint16_t id) { |
| 58 return stats_->OnSentPacket(id, clock_.TimeInMilliseconds()); |
| 59 } |
| 60 |
| 61 SimulatedClock clock_; |
| 62 VideoSendStream::Config config_; |
| 63 std::unique_ptr<SendDelayStats> stats_; |
| 64 }; |
| 65 |
| 66 TEST_F(SendDelayStatsTest, SentPacketFound) { |
| 67 EXPECT_FALSE(OnSentPacket(kPacketId)); |
| 68 OnSendPacket(kPacketId, kSsrc1); |
| 69 EXPECT_TRUE(OnSentPacket(kPacketId)); // Packet found. |
| 70 EXPECT_FALSE(OnSentPacket(kPacketId)); // Packet removed when found. |
| 71 } |
| 72 |
| 73 TEST_F(SendDelayStatsTest, SentPacketNotFoundForNonRegisteredSsrc) { |
| 74 OnSendPacket(kPacketId, kSsrc1); |
| 75 EXPECT_TRUE(OnSentPacket(kPacketId)); |
| 76 OnSendPacket(kPacketId + 1, kSsrc2); |
| 77 EXPECT_TRUE(OnSentPacket(kPacketId + 1)); |
| 78 OnSendPacket(kPacketId + 2, kRtxSsrc1); // RTX SSRC not registered. |
| 79 EXPECT_FALSE(OnSentPacket(kPacketId + 2)); |
| 80 } |
| 81 |
| 82 TEST_F(SendDelayStatsTest, SentPacketFoundWithMaxSendDelay) { |
| 83 OnSendPacket(kPacketId, kSsrc1); |
| 84 clock_.AdvanceTimeMilliseconds(kMaxPacketDelayMs - 1); |
| 85 OnSendPacket(kPacketId + 1, kSsrc1); // kPacketId -> not old/removed. |
| 86 EXPECT_TRUE(OnSentPacket(kPacketId)); // Packet found. |
| 87 EXPECT_TRUE(OnSentPacket(kPacketId + 1)); // Packet found. |
| 88 } |
| 89 |
| 90 TEST_F(SendDelayStatsTest, OldPacketsRemoved) { |
| 91 const int64_t kCaptureTimeMs = clock_.TimeInMilliseconds(); |
| 92 OnSendPacket(0xffffu, kSsrc1, kCaptureTimeMs); |
| 93 OnSendPacket(0u, kSsrc1, kCaptureTimeMs); |
| 94 OnSendPacket(1u, kSsrc1, kCaptureTimeMs + 1); |
| 95 clock_.AdvanceTimeMilliseconds(kMaxPacketDelayMs); // 0xffff, 0 -> old. |
| 96 OnSendPacket(2u, kSsrc1, kCaptureTimeMs + 2); |
| 97 |
| 98 EXPECT_FALSE(OnSentPacket(0xffffu)); // Old removed. |
| 99 EXPECT_FALSE(OnSentPacket(0u)); // Old removed. |
| 100 EXPECT_TRUE(OnSentPacket(1u)); |
| 101 EXPECT_TRUE(OnSentPacket(2u)); |
| 102 } |
| 103 |
| 104 TEST_F(SendDelayStatsTest, HistogramsAreUpdated) { |
| 105 test::ClearHistograms(); |
| 106 const int64_t kDelayMs1 = 5; |
| 107 const int64_t kDelayMs2 = 10; |
| 108 uint16_t id = 0; |
| 109 for (int i = 0; i < kMinRequiredSamples; ++i) { |
| 110 OnSendPacket(++id, kSsrc1); |
| 111 clock_.AdvanceTimeMilliseconds(kDelayMs1); |
| 112 EXPECT_TRUE(OnSentPacket(id)); |
| 113 OnSendPacket(++id, kSsrc2); |
| 114 clock_.AdvanceTimeMilliseconds(kDelayMs2); |
| 115 EXPECT_TRUE(OnSentPacket(id)); |
| 116 } |
| 117 stats_.reset(); |
| 118 EXPECT_EQ(2, test::NumHistogramSamples("WebRTC.Video.SendDelayInMs")); |
| 119 EXPECT_EQ(kDelayMs2, test::LastHistogramSample("WebRTC.Video.SendDelayInMs")); |
| 120 } |
| 121 |
| 122 } // namespace webrtc |
OLD | NEW |