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

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/aimd_rate_control_unittest.cc

Issue 2684353004: Reduce the BWE with 50% when feedback is received too late. (Closed)
Patch Set: Updated comment. Created 3 years, 10 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/remote_bitrate_estimator/aimd_rate_control.cc ('k') | no next file » | 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 #include <memory> 10 #include <memory>
(...skipping 12 matching lines...) Expand all
23 std::unique_ptr<SimulatedClock> simulated_clock; 23 std::unique_ptr<SimulatedClock> simulated_clock;
24 }; 24 };
25 25
26 AimdRateControlStates CreateAimdRateControlStates() { 26 AimdRateControlStates CreateAimdRateControlStates() {
27 AimdRateControlStates states; 27 AimdRateControlStates states;
28 states.aimd_rate_control.reset(new AimdRateControl()); 28 states.aimd_rate_control.reset(new AimdRateControl());
29 states.simulated_clock.reset(new SimulatedClock(kClockInitialTime)); 29 states.simulated_clock.reset(new SimulatedClock(kClockInitialTime));
30 return states; 30 return states;
31 } 31 }
32 32
33 void InitBitrate(const AimdRateControlStates& states,
34 int bitrate,
35 int64_t now_ms) {
36 // Reduce the bitrate by 1000 to compensate for the Update after SetEstimate.
37 bitrate -= 1000;
38
39 states.aimd_rate_control->SetEstimate(bitrate, now_ms);
40 }
41
42 void UpdateRateControl(const AimdRateControlStates& states, 33 void UpdateRateControl(const AimdRateControlStates& states,
43 const BandwidthUsage& bandwidth_usage, 34 const BandwidthUsage& bandwidth_usage,
44 int bitrate, 35 int bitrate,
45 int64_t now_ms) { 36 int64_t now_ms) {
46 RateControlInput input(bandwidth_usage, rtc::Optional<uint32_t>(bitrate), 37 RateControlInput input(bandwidth_usage, rtc::Optional<uint32_t>(bitrate),
47 now_ms); 38 now_ms);
48 states.aimd_rate_control->Update(&input, now_ms); 39 states.aimd_rate_control->Update(&input, now_ms);
49 states.aimd_rate_control->UpdateBandwidthEstimate(now_ms); 40 states.aimd_rate_control->UpdateBandwidthEstimate(now_ms);
50 } 41 }
51 42
52 } // namespace 43 } // namespace
53 44
54 TEST(AimdRateControlTest, MinNearMaxIncreaseRateOnLowBandwith) { 45 TEST(AimdRateControlTest, MinNearMaxIncreaseRateOnLowBandwith) {
55 auto states = CreateAimdRateControlStates(); 46 auto states = CreateAimdRateControlStates();
56 constexpr int kBitrate = 30000; 47 constexpr int kBitrate = 30000;
57 InitBitrate(states, kBitrate, states.simulated_clock->TimeInMilliseconds()); 48 states.aimd_rate_control->SetEstimate(
49 kBitrate, states.simulated_clock->TimeInMilliseconds());
58 EXPECT_EQ(4000, states.aimd_rate_control->GetNearMaxIncreaseRateBps()); 50 EXPECT_EQ(4000, states.aimd_rate_control->GetNearMaxIncreaseRateBps());
59 } 51 }
60 52
61 TEST(AimdRateControlTest, NearMaxIncreaseRateIs5kbpsOn90kbpsAnd200msRtt) { 53 TEST(AimdRateControlTest, NearMaxIncreaseRateIs5kbpsOn90kbpsAnd200msRtt) {
62 auto states = CreateAimdRateControlStates(); 54 auto states = CreateAimdRateControlStates();
63 constexpr int kBitrate = 90000; 55 constexpr int kBitrate = 90000;
64 InitBitrate(states, kBitrate, states.simulated_clock->TimeInMilliseconds()); 56 states.aimd_rate_control->SetEstimate(
57 kBitrate, states.simulated_clock->TimeInMilliseconds());
65 EXPECT_EQ(5000, states.aimd_rate_control->GetNearMaxIncreaseRateBps()); 58 EXPECT_EQ(5000, states.aimd_rate_control->GetNearMaxIncreaseRateBps());
66 } 59 }
67 60
68 TEST(AimdRateControlTest, NearMaxIncreaseRateIs5kbpsOn60kbpsAnd100msRtt) { 61 TEST(AimdRateControlTest, NearMaxIncreaseRateIs5kbpsOn60kbpsAnd100msRtt) {
69 auto states = CreateAimdRateControlStates(); 62 auto states = CreateAimdRateControlStates();
70 constexpr int kBitrate = 60000; 63 constexpr int kBitrate = 60000;
71 InitBitrate(states, kBitrate, states.simulated_clock->TimeInMilliseconds()); 64 states.aimd_rate_control->SetEstimate(
65 kBitrate, states.simulated_clock->TimeInMilliseconds());
72 states.aimd_rate_control->SetRtt(100); 66 states.aimd_rate_control->SetRtt(100);
73 EXPECT_EQ(5000, states.aimd_rate_control->GetNearMaxIncreaseRateBps()); 67 EXPECT_EQ(5000, states.aimd_rate_control->GetNearMaxIncreaseRateBps());
74 } 68 }
75 69
76 TEST(AimdRateControlTest, UnknownBitrateDecreaseBeforeFirstOveruse) { 70 TEST(AimdRateControlTest, UnknownBitrateDecreaseBeforeFirstOveruse) {
77 auto states = CreateAimdRateControlStates(); 71 auto states = CreateAimdRateControlStates();
78 EXPECT_EQ(rtc::Optional<int>(), 72 EXPECT_EQ(rtc::Optional<int>(),
79 states.aimd_rate_control->GetLastBitrateDecreaseBps()); 73 states.aimd_rate_control->GetLastBitrateDecreaseBps());
80 } 74 }
81 75
82 TEST(AimdRateControlTest, GetLastBitrateDecrease) { 76 TEST(AimdRateControlTest, GetLastBitrateDecrease) {
83 auto states = CreateAimdRateControlStates(); 77 auto states = CreateAimdRateControlStates();
84 constexpr int kBitrate = 300000; 78 constexpr int kBitrate = 300000;
85 InitBitrate(states, kBitrate, states.simulated_clock->TimeInMilliseconds()); 79 states.aimd_rate_control->SetEstimate(
80 kBitrate, states.simulated_clock->TimeInMilliseconds());
86 UpdateRateControl(states, kBwOverusing, kBitrate - 2000, 81 UpdateRateControl(states, kBwOverusing, kBitrate - 2000,
87 states.simulated_clock->TimeInMilliseconds()); 82 states.simulated_clock->TimeInMilliseconds());
88 EXPECT_EQ(rtc::Optional<int>(46700), 83 EXPECT_EQ(rtc::Optional<int>(46700),
89 states.aimd_rate_control->GetLastBitrateDecreaseBps()); 84 states.aimd_rate_control->GetLastBitrateDecreaseBps());
90 } 85 }
91 86
92 TEST(AimdRateControlTest, BweLimitedByAckedBitrate) { 87 TEST(AimdRateControlTest, BweLimitedByAckedBitrate) {
93 auto states = CreateAimdRateControlStates(); 88 auto states = CreateAimdRateControlStates();
94 constexpr int kAckedBitrate = 10000; 89 constexpr int kAckedBitrate = 10000;
95 InitBitrate(states, kAckedBitrate, 90 states.aimd_rate_control->SetEstimate(
96 states.simulated_clock->TimeInMilliseconds()); 91 kAckedBitrate, states.simulated_clock->TimeInMilliseconds());
97 while (states.simulated_clock->TimeInMilliseconds() - kClockInitialTime < 92 while (states.simulated_clock->TimeInMilliseconds() - kClockInitialTime <
98 20000) { 93 20000) {
99 UpdateRateControl(states, kBwNormal, kAckedBitrate, 94 UpdateRateControl(states, kBwNormal, kAckedBitrate,
100 states.simulated_clock->TimeInMilliseconds()); 95 states.simulated_clock->TimeInMilliseconds());
101 states.simulated_clock->AdvanceTimeMilliseconds(100); 96 states.simulated_clock->AdvanceTimeMilliseconds(100);
102 } 97 }
103 ASSERT_TRUE(states.aimd_rate_control->ValidEstimate()); 98 ASSERT_TRUE(states.aimd_rate_control->ValidEstimate());
104 EXPECT_EQ(static_cast<uint32_t>(1.5 * kAckedBitrate + 10000), 99 EXPECT_EQ(static_cast<uint32_t>(1.5 * kAckedBitrate + 10000),
105 states.aimd_rate_control->LatestEstimate()); 100 states.aimd_rate_control->LatestEstimate());
106 } 101 }
107 102
108 TEST(AimdRateControlTest, BweNotLimitedByDecreasingAckedBitrate) { 103 TEST(AimdRateControlTest, BweNotLimitedByDecreasingAckedBitrate) {
109 auto states = CreateAimdRateControlStates(); 104 auto states = CreateAimdRateControlStates();
110 constexpr int kAckedBitrate = 100000; 105 constexpr int kAckedBitrate = 100000;
111 InitBitrate(states, kAckedBitrate, 106 states.aimd_rate_control->SetEstimate(
112 states.simulated_clock->TimeInMilliseconds()); 107 kAckedBitrate, states.simulated_clock->TimeInMilliseconds());
113 while (states.simulated_clock->TimeInMilliseconds() - kClockInitialTime < 108 while (states.simulated_clock->TimeInMilliseconds() - kClockInitialTime <
114 20000) { 109 20000) {
115 UpdateRateControl(states, kBwNormal, kAckedBitrate, 110 UpdateRateControl(states, kBwNormal, kAckedBitrate,
116 states.simulated_clock->TimeInMilliseconds()); 111 states.simulated_clock->TimeInMilliseconds());
117 states.simulated_clock->AdvanceTimeMilliseconds(100); 112 states.simulated_clock->AdvanceTimeMilliseconds(100);
118 } 113 }
119 ASSERT_TRUE(states.aimd_rate_control->ValidEstimate()); 114 ASSERT_TRUE(states.aimd_rate_control->ValidEstimate());
120 // If the acked bitrate decreases the BWE shouldn't be reduced to 1.5x 115 // If the acked bitrate decreases the BWE shouldn't be reduced to 1.5x
121 // what's being acked, but also shouldn't get to increase more. 116 // what's being acked, but also shouldn't get to increase more.
122 uint32_t prev_estimate = states.aimd_rate_control->LatestEstimate(); 117 uint32_t prev_estimate = states.aimd_rate_control->LatestEstimate();
123 UpdateRateControl(states, kBwNormal, kAckedBitrate / 2, 118 UpdateRateControl(states, kBwNormal, kAckedBitrate / 2,
124 states.simulated_clock->TimeInMilliseconds()); 119 states.simulated_clock->TimeInMilliseconds());
125 uint32_t new_estimate = states.aimd_rate_control->LatestEstimate(); 120 uint32_t new_estimate = states.aimd_rate_control->LatestEstimate();
126 EXPECT_NEAR(new_estimate, static_cast<uint32_t>(1.5 * kAckedBitrate + 10000), 121 EXPECT_NEAR(new_estimate, static_cast<uint32_t>(1.5 * kAckedBitrate + 10000),
127 2000); 122 2000);
128 EXPECT_EQ(new_estimate, prev_estimate); 123 EXPECT_EQ(new_estimate, prev_estimate);
129 } 124 }
130 } // namespace webrtc 125 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/remote_bitrate_estimator/aimd_rate_control.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698