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

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

Issue 2503643003: More reliable ALR detection (Closed)
Patch Set: const Created 4 years, 1 month 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/paced_sender.cc » ('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"
12
11 #include "webrtc/test/gtest.h" 13 #include "webrtc/test/gtest.h"
12 #include "webrtc/modules/pacing/alr_detector.h"
13 14
14 namespace { 15 namespace {
15 16
16 constexpr int kMeasuredIntervalMs = 110;
17 constexpr int kEstimatedBitrateBps = 300000; 17 constexpr int kEstimatedBitrateBps = 300000;
18 constexpr int kBytesInIntervalAtEstimatedBitrate =
19 (kEstimatedBitrateBps / 8) * kMeasuredIntervalMs / 1000;
20 18
21 } // namespace 19 } // namespace
22 20
23 namespace webrtc { 21 namespace webrtc {
24 22
25 TEST(AlrDetectorTest, ApplicationLimitedWhenLittleDataSent) { 23 class AlrDetectorTest : public testing::Test {
26 AlrDetector alr_detector; 24 public:
25 void SetUp() override {
26 alr_detector_.SetEstimatedBitrate(kEstimatedBitrateBps);
27 }
27 28
28 alr_detector.SetEstimatedBitrate(kEstimatedBitrateBps); 29 void SimulateOutgoingTraffic(int interval_ms, int usage_percentage) {
29 for (int i = 0; i < 6; i++) 30 const int kTimeStepMs = 10;
30 alr_detector.OnBytesSent(0, kMeasuredIntervalMs); 31 for (int t = 0; t < interval_ms; t += kTimeStepMs) {
31 EXPECT_EQ(alr_detector.InApplicationLimitedRegion(), true); 32 now_ms += kTimeStepMs;
33 alr_detector_.OnBytesSent(kEstimatedBitrateBps * usage_percentage *
34 kTimeStepMs / (8 * 100 * 1000),
35 now_ms);
36 }
32 37
33 for (int i = 0; i < 6; i++) 38 int remainder_ms = interval_ms % kTimeStepMs;
34 alr_detector.OnBytesSent(100, kMeasuredIntervalMs); 39 now_ms += remainder_ms;
35 EXPECT_EQ(alr_detector.InApplicationLimitedRegion(), true); 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:
48 AlrDetector alr_detector_;
49 int64_t now_ms = 1;
50 };
51
52 TEST_F(AlrDetectorTest, AlrDetection) {
53 // Start in non-ALR state.
54 EXPECT_FALSE(alr_detector_.InApplicationLimitedRegion());
55
56 // Stay in non-ALR state when usage is close to 100%.
57 SimulateOutgoingTraffic(500, 90);
58 EXPECT_FALSE(alr_detector_.InApplicationLimitedRegion());
59
60 // Verify that we ALR starts when bitrate drops below 20%.
61 SimulateOutgoingTraffic(500, 20);
62 EXPECT_TRUE(alr_detector_.InApplicationLimitedRegion());
63
64 // Verify that we remain in ALR state while usage is still below 50%.
65 SimulateOutgoingTraffic(500, 40);
66 EXPECT_TRUE(alr_detector_.InApplicationLimitedRegion());
67
68 // Verify that ALR ends when usage is above 50%.
69 SimulateOutgoingTraffic(500, 60);
70 EXPECT_FALSE(alr_detector_.InApplicationLimitedRegion());
36 } 71 }
37 72
38 TEST(AlrDetectorTest, NetworkLimitedWhenSendingCloseToEstimate) { 73 TEST_F(AlrDetectorTest, ShortSpike) {
39 AlrDetector alr_detector; 74 // Start in non-ALR state.
75 EXPECT_FALSE(alr_detector_.InApplicationLimitedRegion());
40 76
41 alr_detector.SetEstimatedBitrate(kEstimatedBitrateBps); 77 // Verify that we ALR starts when bitrate drops below 20%.
42 for (int i = 0; i < 6; i++) 78 SimulateOutgoingTraffic(500, 20);
43 alr_detector.OnBytesSent(kBytesInIntervalAtEstimatedBitrate, 79 EXPECT_TRUE(alr_detector_.InApplicationLimitedRegion());
44 kMeasuredIntervalMs); 80
45 EXPECT_EQ(alr_detector.InApplicationLimitedRegion(), false); 81 // Verify that we stay in ALR region even after a short bitrate spike.
82 SimulateOutgoingTraffic(100, 150);
83 EXPECT_TRUE(alr_detector_.InApplicationLimitedRegion());
84
85 SimulateOutgoingTraffic(200, 20);
86 EXPECT_TRUE(alr_detector_.InApplicationLimitedRegion());
87
88 // ALR ends when usage is above 50%.
89 SimulateOutgoingTraffic(500, 60);
90 EXPECT_FALSE(alr_detector_.InApplicationLimitedRegion());
91 }
92
93 TEST_F(AlrDetectorTest, BandwidthEstimateChanges) {
94 // Start in non-ALR state.
95 EXPECT_FALSE(alr_detector_.InApplicationLimitedRegion());
96
97 // ALR starts when bitrate drops below 20%.
98 SimulateOutgoingTraffic(500, 20);
99 EXPECT_TRUE(alr_detector_.InApplicationLimitedRegion());
100
101 // 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
103 // traffic. This is necessary to ensure that ProbeController can still react
104 // to the BWE drop by initiating a new probe.
105 alr_detector_.SetEstimatedBitrate(kEstimatedBitrateBps / 5);
106 EXPECT_TRUE(alr_detector_.InApplicationLimitedRegion());
107 SimulateOutgoingTraffic(10, 20);
108 EXPECT_FALSE(alr_detector_.InApplicationLimitedRegion());
46 } 109 }
47 110
48 } // namespace webrtc 111 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/pacing/alr_detector.cc ('k') | webrtc/modules/pacing/paced_sender.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698