Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(491)

Side by Side Diff: webrtc/modules/pacing/alr_detector_unittest.cc

Issue 2965233002: Let alr dectector use a budged to detect underuse. (Closed)
Patch Set: Rebased. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/modules/pacing/alr_detector.cc ('k') | webrtc/modules/pacing/interval_budget.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/modules/pacing/alr_detector.h" 11 #include "webrtc/modules/pacing/alr_detector.h"
12 12
13 #include "webrtc/test/gtest.h" 13 #include "webrtc/test/gtest.h"
14 14
15 namespace { 15 namespace {
16 16
17 constexpr int kEstimatedBitrateBps = 300000; 17 constexpr int kEstimatedBitrateBps = 300000;
18 18
19 } // namespace 19 } // namespace
20 20
21 namespace webrtc { 21 namespace webrtc {
22 22
23 namespace {
24 class SimulateOutgoingTrafficIn {
25 public:
26 explicit SimulateOutgoingTrafficIn(AlrDetector* alr_detector)
27 : alr_detector_(alr_detector) {
28 RTC_CHECK(alr_detector_);
29 }
30
31 SimulateOutgoingTrafficIn& ForTimeMs(int time_ms) {
32 interval_ms_ = rtc::Optional<int>(time_ms);
33 interval_ms_.emplace(time_ms);
34 ProduceTraffic();
35 return *this;
36 }
37
38 SimulateOutgoingTrafficIn& AtPercentOfEstimatedBitrate(int usage_percentage) {
39 usage_percentage_.emplace(usage_percentage);
40 ProduceTraffic();
41 return *this;
42 }
43
44 private:
45 void ProduceTraffic() {
46 if (!interval_ms_ || !usage_percentage_)
47 return;
48 const int kTimeStepMs = 10;
49 for (int t = 0; t < *interval_ms_; t += kTimeStepMs) {
50 alr_detector_->OnBytesSent(kEstimatedBitrateBps * *usage_percentage_ *
51 kTimeStepMs / (8 * 100 * 1000),
52 kTimeStepMs);
53 }
54 int remainder_ms = *interval_ms_ % kTimeStepMs;
55 if (remainder_ms > 0) {
56 alr_detector_->OnBytesSent(kEstimatedBitrateBps * *usage_percentage_ *
57 remainder_ms / (8 * 100 * 1000),
58 kTimeStepMs);
59 }
60 }
61 AlrDetector* const alr_detector_;
62 rtc::Optional<int> interval_ms_;
63 rtc::Optional<int> usage_percentage_;
64 };
65 } // namespace
66
23 class AlrDetectorTest : public testing::Test { 67 class AlrDetectorTest : public testing::Test {
24 public: 68 public:
25 void SetUp() override { 69 void SetUp() override {
26 alr_detector_.SetEstimatedBitrate(kEstimatedBitrateBps); 70 alr_detector_.SetEstimatedBitrate(kEstimatedBitrateBps);
27 } 71 }
28 72
29 void SimulateOutgoingTraffic(int interval_ms, int usage_percentage) {
30 const int kTimeStepMs = 10;
31 for (int t = 0; t < interval_ms; t += kTimeStepMs) {
32 now_ms += kTimeStepMs;
33 alr_detector_.OnBytesSent(kEstimatedBitrateBps * usage_percentage *
34 kTimeStepMs / (8 * 100 * 1000),
35 now_ms);
36 }
37
38 int remainder_ms = interval_ms % kTimeStepMs;
39 now_ms += remainder_ms;
40 if (remainder_ms > 0) {
41 alr_detector_.OnBytesSent(kEstimatedBitrateBps * usage_percentage *
42 remainder_ms / (8 * 100 * 1000),
43 remainder_ms);
44 }
45 }
46
47 protected: 73 protected:
48 AlrDetector alr_detector_; 74 AlrDetector alr_detector_;
49 int64_t now_ms = 1;
50 }; 75 };
51 76
52 TEST_F(AlrDetectorTest, AlrDetection) { 77 TEST_F(AlrDetectorTest, AlrDetection) {
53 // Start in non-ALR state. 78 // Start in non-ALR state.
54 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime()); 79 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
55 80
56 // Stay in non-ALR state when usage is close to 100%. 81 // Stay in non-ALR state when usage is close to 100%.
57 SimulateOutgoingTraffic(500, 90); 82 SimulateOutgoingTrafficIn(&alr_detector_)
83 .ForTimeMs(1000)
84 .AtPercentOfEstimatedBitrate(90);
58 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime()); 85 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
59 86
60 // Verify that we ALR starts when bitrate drops below 20%. 87 // Verify that we ALR starts when bitrate drops below 20%.
61 SimulateOutgoingTraffic(500, 20); 88 SimulateOutgoingTrafficIn(&alr_detector_)
89 .ForTimeMs(1000)
90 .AtPercentOfEstimatedBitrate(20);
62 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime()); 91 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime());
63 92
64 // Verify that we remain in ALR state while usage is still below 70%. 93 // Verify that ALR ends when usage is above 65%.
65 SimulateOutgoingTraffic(500, 69); 94 SimulateOutgoingTrafficIn(&alr_detector_)
66 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime()); 95 .ForTimeMs(1000)
67 96 .AtPercentOfEstimatedBitrate(100);
68 // Verify that ALR ends when usage is above 70%.
69 SimulateOutgoingTraffic(500, 75);
70 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime()); 97 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
71 } 98 }
72 99
73 TEST_F(AlrDetectorTest, ShortSpike) { 100 TEST_F(AlrDetectorTest, ShortSpike) {
74 // Start in non-ALR state. 101 // Start in non-ALR state.
75 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime()); 102 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
76 103
77 // Verify that we ALR starts when bitrate drops below 20%. 104 // Verify that we ALR starts when bitrate drops below 20%.
78 SimulateOutgoingTraffic(500, 20); 105 SimulateOutgoingTrafficIn(&alr_detector_)
106 .ForTimeMs(1000)
107 .AtPercentOfEstimatedBitrate(20);
79 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime()); 108 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime());
80 109
81 // Verify that we stay in ALR region even after a short bitrate spike. 110 // Verify that we stay in ALR region even after a short bitrate spike.
82 SimulateOutgoingTraffic(100, 150); 111 SimulateOutgoingTrafficIn(&alr_detector_)
112 .ForTimeMs(200)
113 .AtPercentOfEstimatedBitrate(150);
83 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime()); 114 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime());
84 115
85 SimulateOutgoingTraffic(200, 20); 116 // ALR ends when usage is above 65%.
86 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime()); 117 SimulateOutgoingTrafficIn(&alr_detector_)
87 118 .ForTimeMs(1000)
88 // ALR ends when usage is above 70%. 119 .AtPercentOfEstimatedBitrate(100);
89 SimulateOutgoingTraffic(500, 75);
90 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime()); 120 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
91 } 121 }
92 122
93 TEST_F(AlrDetectorTest, BandwidthEstimateChanges) { 123 TEST_F(AlrDetectorTest, BandwidthEstimateChanges) {
94 // Start in non-ALR state. 124 // Start in non-ALR state.
95 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime()); 125 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
96 126
97 // ALR starts when bitrate drops below 20%. 127 // ALR starts when bitrate drops below 20%.
98 SimulateOutgoingTraffic(500, 20); 128 SimulateOutgoingTrafficIn(&alr_detector_)
129 .ForTimeMs(1000)
130 .AtPercentOfEstimatedBitrate(20);
99 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime()); 131 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime());
100 132
101 // When bandwidth estimate drops the detector should stay in ALR mode and quit 133 // When bandwidth estimate drops the detector should stay in ALR mode and quit
102 // it shortly afterwards as the sender continues sending the same amount of 134 // it shortly afterwards as the sender continues sending the same amount of
103 // traffic. This is necessary to ensure that ProbeController can still react 135 // traffic. This is necessary to ensure that ProbeController can still react
104 // to the BWE drop by initiating a new probe. 136 // to the BWE drop by initiating a new probe.
105 alr_detector_.SetEstimatedBitrate(kEstimatedBitrateBps / 5); 137 alr_detector_.SetEstimatedBitrate(kEstimatedBitrateBps / 5);
106 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime()); 138 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime());
107 SimulateOutgoingTraffic(10, 20); 139 SimulateOutgoingTrafficIn(&alr_detector_)
140 .ForTimeMs(1000)
141 .AtPercentOfEstimatedBitrate(50);
108 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime()); 142 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
109 } 143 }
110 144
111 } // namespace webrtc 145 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/pacing/alr_detector.cc ('k') | webrtc/modules/pacing/interval_budget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698