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/test/gtest.h" | 11 #include "webrtc/test/gtest.h" |
12 #include "webrtc/modules/pacing/alr_detector.h" | 12 #include "webrtc/modules/pacing/alr_detector.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 constexpr int kMeasuredIntervalMs = 110; | 16 constexpr int kMeasuredIntervalMs = 110; |
17 constexpr int kEstimatedBitrateBps = 300000; | 17 constexpr int kEstimatedBitrateBps = 300000; |
18 constexpr int kBytesInIntervalAtEstimatedBitrate = | 18 constexpr int kBytesInIntervalAtEstimatedBitrate = |
19 (kEstimatedBitrateBps / 8) * kMeasuredIntervalMs / 1000; | 19 (kEstimatedBitrateBps / 8) * kMeasuredIntervalMs / 1000; |
20 | 20 |
21 } // namespace | 21 } // namespace |
22 | 22 |
23 namespace webrtc { | 23 namespace webrtc { |
24 | 24 |
25 TEST(AlrDetectorTest, ApplicationLimitedWhenLittleDataSent) { | 25 TEST(AlrDetectorTest, ApplicationLimitedWhenLittleDataSent) { |
26 AlrDetector alr_detector; | 26 AlrDetector alr_detector; |
| 27 int now_ms = 0; |
| 28 alr_detector.SetEstimatedBitrate(kEstimatedBitrateBps); |
| 29 for (int i = 0; i < 6; i++) { |
| 30 now_ms += kMeasuredIntervalMs; |
| 31 alr_detector.OnBytesSent(0, now_ms); |
| 32 } |
| 33 EXPECT_TRUE(alr_detector.InApplicationLimitedRegion()); |
27 | 34 |
28 alr_detector.SetEstimatedBitrate(kEstimatedBitrateBps); | 35 for (int i = 0; i < 6; i++) { |
29 for (int i = 0; i < 6; i++) | 36 now_ms += kMeasuredIntervalMs; |
30 alr_detector.OnBytesSent(0, kMeasuredIntervalMs); | 37 alr_detector.OnBytesSent(100, now_ms); |
31 EXPECT_EQ(alr_detector.InApplicationLimitedRegion(), true); | 38 } |
32 | 39 EXPECT_TRUE(alr_detector.InApplicationLimitedRegion()); |
33 for (int i = 0; i < 6; i++) | |
34 alr_detector.OnBytesSent(100, kMeasuredIntervalMs); | |
35 EXPECT_EQ(alr_detector.InApplicationLimitedRegion(), true); | |
36 } | 40 } |
37 | 41 |
38 TEST(AlrDetectorTest, NetworkLimitedWhenSendingCloseToEstimate) { | 42 TEST(AlrDetectorTest, NetworkLimitedWhenSendingCloseToEstimate) { |
39 AlrDetector alr_detector; | 43 AlrDetector alr_detector; |
40 | 44 int64_t now_ms = 0; |
41 alr_detector.SetEstimatedBitrate(kEstimatedBitrateBps); | 45 alr_detector.SetEstimatedBitrate(kEstimatedBitrateBps); |
42 for (int i = 0; i < 6; i++) | 46 for (int i = 0; i < 6; i++) { |
43 alr_detector.OnBytesSent(kBytesInIntervalAtEstimatedBitrate, | 47 now_ms += kMeasuredIntervalMs; |
44 kMeasuredIntervalMs); | 48 alr_detector.OnBytesSent(kBytesInIntervalAtEstimatedBitrate, now_ms); |
45 EXPECT_EQ(alr_detector.InApplicationLimitedRegion(), false); | 49 } |
| 50 EXPECT_FALSE(alr_detector.InApplicationLimitedRegion()); |
46 } | 51 } |
47 | 52 |
48 } // namespace webrtc | 53 } // namespace webrtc |
OLD | NEW |