OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/video/send_delay_stats.h" | 11 #include "webrtc/video/send_delay_stats.h" |
12 | 12 |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "webrtc/system_wrappers/include/metrics.h" | 14 #include "webrtc/system_wrappers/include/metrics.h" |
15 #include "webrtc/system_wrappers/include/metrics_default.h" | 15 #include "webrtc/system_wrappers/include/metrics_default.h" |
16 | 16 |
17 namespace webrtc { | 17 namespace webrtc { |
18 namespace { | 18 namespace { |
19 const uint32_t kSsrc1 = 17; | 19 const uint32_t kSsrc1 = 17; |
20 const uint32_t kSsrc2 = 42; | 20 const uint32_t kSsrc2 = 42; |
21 const uint32_t kRtxSsrc1 = 18; | 21 const uint32_t kRtxSsrc1 = 18; |
22 const uint32_t kRtxSsrc2 = 43; | 22 const uint32_t kRtxSsrc2 = 43; |
23 const uint16_t kPacketId = 2345; | 23 const uint16_t kPacketId = 2345; |
24 const int64_t kMaxPacketDelayMs = 11000; | 24 const int64_t kMaxPacketDelayMs = 11000; |
25 const int kMinRequiredSamples = 200; | 25 const int kMinRequiredPeriodicSamples = 5; |
| 26 const int kProcessIntervalMs = 2000; |
26 } // namespace | 27 } // namespace |
27 | 28 |
28 class SendDelayStatsTest : public ::testing::Test { | 29 class SendDelayStatsTest : public ::testing::Test { |
29 public: | 30 public: |
30 SendDelayStatsTest() : clock_(1234), config_(CreateConfig()) {} | 31 SendDelayStatsTest() : clock_(1234), config_(CreateConfig()) {} |
31 virtual ~SendDelayStatsTest() {} | 32 virtual ~SendDelayStatsTest() {} |
32 | 33 |
33 protected: | 34 protected: |
34 virtual void SetUp() { | 35 virtual void SetUp() { |
35 stats_.reset(new SendDelayStats(&clock_)); | 36 stats_.reset(new SendDelayStats(&clock_)); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 98 |
98 EXPECT_FALSE(OnSentPacket(0xffffu)); // Old removed. | 99 EXPECT_FALSE(OnSentPacket(0xffffu)); // Old removed. |
99 EXPECT_FALSE(OnSentPacket(0u)); // Old removed. | 100 EXPECT_FALSE(OnSentPacket(0u)); // Old removed. |
100 EXPECT_TRUE(OnSentPacket(1u)); | 101 EXPECT_TRUE(OnSentPacket(1u)); |
101 EXPECT_TRUE(OnSentPacket(2u)); | 102 EXPECT_TRUE(OnSentPacket(2u)); |
102 } | 103 } |
103 | 104 |
104 TEST_F(SendDelayStatsTest, HistogramsAreUpdated) { | 105 TEST_F(SendDelayStatsTest, HistogramsAreUpdated) { |
105 metrics::Reset(); | 106 metrics::Reset(); |
106 const int64_t kDelayMs1 = 5; | 107 const int64_t kDelayMs1 = 5; |
107 const int64_t kDelayMs2 = 10; | 108 const int64_t kDelayMs2 = 15; |
| 109 const int kNumSamples = kMinRequiredPeriodicSamples * kProcessIntervalMs / |
| 110 (kDelayMs1 + kDelayMs2) + 1; |
| 111 |
108 uint16_t id = 0; | 112 uint16_t id = 0; |
109 for (int i = 0; i < kMinRequiredSamples; ++i) { | 113 for (int i = 0; i < kNumSamples; ++i) { |
110 OnSendPacket(++id, kSsrc1); | 114 OnSendPacket(++id, kSsrc1); |
111 clock_.AdvanceTimeMilliseconds(kDelayMs1); | 115 clock_.AdvanceTimeMilliseconds(kDelayMs1); |
112 EXPECT_TRUE(OnSentPacket(id)); | 116 EXPECT_TRUE(OnSentPacket(id)); |
113 OnSendPacket(++id, kSsrc2); | 117 OnSendPacket(++id, kSsrc2); |
114 clock_.AdvanceTimeMilliseconds(kDelayMs2); | 118 clock_.AdvanceTimeMilliseconds(kDelayMs2); |
115 EXPECT_TRUE(OnSentPacket(id)); | 119 EXPECT_TRUE(OnSentPacket(id)); |
116 } | 120 } |
117 stats_.reset(); | 121 stats_.reset(); |
118 EXPECT_EQ(2, metrics::NumSamples("WebRTC.Video.SendDelayInMs")); | 122 EXPECT_EQ(2, metrics::NumSamples("WebRTC.Video.SendDelayInMs")); |
119 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SendDelayInMs", kDelayMs1)); | 123 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SendDelayInMs", kDelayMs1)); |
120 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SendDelayInMs", kDelayMs2)); | 124 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SendDelayInMs", kDelayMs2)); |
121 } | 125 } |
122 | 126 |
123 } // namespace webrtc | 127 } // namespace webrtc |
OLD | NEW |