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 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "webrtc/modules/remote_bitrate_estimator/aimd_rate_control.h" | 12 #include "webrtc/modules/remote_bitrate_estimator/aimd_rate_control.h" |
13 #include "webrtc/system_wrappers/include/clock.h" | 13 #include "webrtc/system_wrappers/include/clock.h" |
14 #include "webrtc/test/gtest.h" | 14 #include "webrtc/test/gtest.h" |
15 | 15 |
16 namespace webrtc { | 16 namespace webrtc { |
17 namespace { | 17 namespace { |
18 | 18 |
19 constexpr int64_t kClockInitialTime = 123456; | 19 constexpr int64_t kClockInitialTime = 123456; |
20 | 20 |
21 constexpr int kMinBwePeriodMs = 2000; | |
22 constexpr int kMaxBwePeriodMs = 50000; | |
23 constexpr int kDefaultPeriodMs = 3000; | |
24 | |
21 struct AimdRateControlStates { | 25 struct AimdRateControlStates { |
22 std::unique_ptr<AimdRateControl> aimd_rate_control; | 26 std::unique_ptr<AimdRateControl> aimd_rate_control; |
23 std::unique_ptr<SimulatedClock> simulated_clock; | 27 std::unique_ptr<SimulatedClock> simulated_clock; |
24 }; | 28 }; |
25 | 29 |
26 AimdRateControlStates CreateAimdRateControlStates() { | 30 AimdRateControlStates CreateAimdRateControlStates() { |
27 AimdRateControlStates states; | 31 AimdRateControlStates states; |
28 states.aimd_rate_control.reset(new AimdRateControl()); | 32 states.aimd_rate_control.reset(new AimdRateControl()); |
29 states.simulated_clock.reset(new SimulatedClock(kClockInitialTime)); | 33 states.simulated_clock.reset(new SimulatedClock(kClockInitialTime)); |
30 return states; | 34 return states; |
(...skipping 28 matching lines...) Expand all Loading... | |
59 | 63 |
60 TEST(AimdRateControlTest, NearMaxIncreaseRateIs5kbpsOn60kbpsAnd100msRtt) { | 64 TEST(AimdRateControlTest, NearMaxIncreaseRateIs5kbpsOn60kbpsAnd100msRtt) { |
61 auto states = CreateAimdRateControlStates(); | 65 auto states = CreateAimdRateControlStates(); |
62 constexpr int kBitrate = 60000; | 66 constexpr int kBitrate = 60000; |
63 states.aimd_rate_control->SetEstimate( | 67 states.aimd_rate_control->SetEstimate( |
64 kBitrate, states.simulated_clock->TimeInMilliseconds()); | 68 kBitrate, states.simulated_clock->TimeInMilliseconds()); |
65 states.aimd_rate_control->SetRtt(100); | 69 states.aimd_rate_control->SetRtt(100); |
66 EXPECT_EQ(5000, states.aimd_rate_control->GetNearMaxIncreaseRateBps()); | 70 EXPECT_EQ(5000, states.aimd_rate_control->GetNearMaxIncreaseRateBps()); |
67 } | 71 } |
68 | 72 |
69 TEST(AimdRateControlTest, UnknownBitrateDecreaseBeforeFirstOveruse) { | |
70 auto states = CreateAimdRateControlStates(); | |
71 EXPECT_EQ(rtc::Optional<int>(), | |
72 states.aimd_rate_control->GetLastBitrateDecreaseBps()); | |
73 } | |
74 | |
75 TEST(AimdRateControlTest, GetLastBitrateDecrease) { | 73 TEST(AimdRateControlTest, GetLastBitrateDecrease) { |
minyue-webrtc
2017/04/11 10:50:02
rename test
terelius
2017/04/19 07:36:01
Done.
| |
76 auto states = CreateAimdRateControlStates(); | 74 auto states = CreateAimdRateControlStates(); |
77 constexpr int kBitrate = 300000; | 75 constexpr int kBitrate = 300000; |
78 states.aimd_rate_control->SetEstimate( | 76 states.aimd_rate_control->SetEstimate( |
79 kBitrate, states.simulated_clock->TimeInMilliseconds()); | 77 kBitrate, states.simulated_clock->TimeInMilliseconds()); |
80 UpdateRateControl(states, kBwOverusing, kBitrate - 2000, | 78 UpdateRateControl(states, kBwOverusing, kBitrate, |
81 states.simulated_clock->TimeInMilliseconds()); | 79 states.simulated_clock->TimeInMilliseconds()); |
82 EXPECT_EQ(rtc::Optional<int>(46700), | 80 EXPECT_NEAR(14000, states.aimd_rate_control->GetNearMaxIncreaseRateBps(), |
minyue-webrtc
2017/04/11 10:50:02
can we be stricter on this?
terelius
2017/04/19 07:36:01
Yes, we could enforce strict equality but that wou
minyue-webrtc
2017/04/19 07:49:05
Sure, if you think 1s a good margin.
| |
83 states.aimd_rate_control->GetLastBitrateDecreaseBps()); | 81 1000); |
82 ASSERT_TRUE(states.aimd_rate_control->GetExpectedBandwidthPeriodMs()); | |
minyue-webrtc
2017/04/11 10:50:02
what does 82 do?
terelius
2017/04/19 07:36:01
Left-over from previous version. Removed.
| |
83 EXPECT_EQ(3000, states.aimd_rate_control->GetExpectedBandwidthPeriodMs()); | |
84 } | 84 } |
85 | 85 |
86 TEST(AimdRateControlTest, BweLimitedByAckedBitrate) { | 86 TEST(AimdRateControlTest, BweLimitedByAckedBitrate) { |
87 auto states = CreateAimdRateControlStates(); | 87 auto states = CreateAimdRateControlStates(); |
88 constexpr int kAckedBitrate = 10000; | 88 constexpr int kAckedBitrate = 10000; |
89 states.aimd_rate_control->SetEstimate( | 89 states.aimd_rate_control->SetEstimate( |
90 kAckedBitrate, states.simulated_clock->TimeInMilliseconds()); | 90 kAckedBitrate, states.simulated_clock->TimeInMilliseconds()); |
91 while (states.simulated_clock->TimeInMilliseconds() - kClockInitialTime < | 91 while (states.simulated_clock->TimeInMilliseconds() - kClockInitialTime < |
92 20000) { | 92 20000) { |
93 UpdateRateControl(states, kBwNormal, kAckedBitrate, | 93 UpdateRateControl(states, kBwNormal, kAckedBitrate, |
(...skipping 20 matching lines...) Expand all Loading... | |
114 // If the acked bitrate decreases the BWE shouldn't be reduced to 1.5x | 114 // If the acked bitrate decreases the BWE shouldn't be reduced to 1.5x |
115 // what's being acked, but also shouldn't get to increase more. | 115 // what's being acked, but also shouldn't get to increase more. |
116 uint32_t prev_estimate = states.aimd_rate_control->LatestEstimate(); | 116 uint32_t prev_estimate = states.aimd_rate_control->LatestEstimate(); |
117 UpdateRateControl(states, kBwNormal, kAckedBitrate / 2, | 117 UpdateRateControl(states, kBwNormal, kAckedBitrate / 2, |
118 states.simulated_clock->TimeInMilliseconds()); | 118 states.simulated_clock->TimeInMilliseconds()); |
119 uint32_t new_estimate = states.aimd_rate_control->LatestEstimate(); | 119 uint32_t new_estimate = states.aimd_rate_control->LatestEstimate(); |
120 EXPECT_NEAR(new_estimate, static_cast<uint32_t>(1.5 * kAckedBitrate + 10000), | 120 EXPECT_NEAR(new_estimate, static_cast<uint32_t>(1.5 * kAckedBitrate + 10000), |
121 2000); | 121 2000); |
122 EXPECT_EQ(new_estimate, prev_estimate); | 122 EXPECT_EQ(new_estimate, prev_estimate); |
123 } | 123 } |
124 | |
125 TEST(AimdRateControlTest, DefaultPeriodUntilFirstOveruse) { | |
126 auto states = CreateAimdRateControlStates(); | |
127 states.aimd_rate_control->SetStartBitrate(300000); | |
128 EXPECT_EQ(kDefaultPeriodMs, | |
129 states.aimd_rate_control->GetExpectedBandwidthPeriodMs()); | |
130 states.simulated_clock->AdvanceTimeMilliseconds(100); | |
131 UpdateRateControl(states, kBwOverusing, 100000, | |
132 states.simulated_clock->TimeInMilliseconds()); | |
133 EXPECT_NE(kDefaultPeriodMs, | |
134 states.aimd_rate_control->GetExpectedBandwidthPeriodMs()); | |
135 } | |
136 | |
137 TEST(AimdRateControlTest, ExpectedPeriodAfter20kbpsDrop5kbpsIncrease) { | |
minyue-webrtc
2017/04/11 10:50:02
Preferrably not hard code numerics in the name
terelius
2017/04/19 07:36:01
I'm following the convention used in the other tes
| |
138 auto states = CreateAimdRateControlStates(); | |
139 constexpr int kInitialBitrate = 110000; | |
140 states.aimd_rate_control->SetEstimate( | |
141 kInitialBitrate, states.simulated_clock->TimeInMilliseconds()); | |
142 states.simulated_clock->AdvanceTimeMilliseconds(100); | |
143 // Make the bitrate drop to 20 kbps fo get to 90 kbps. | |
minyue-webrtc
2017/04/11 10:50:02
fo -> to
terelius
2017/04/19 07:36:01
Done.
| |
144 // The rate increase at 90 kbps should be 5 kbps, so the period should be 4 s. | |
145 UpdateRateControl(states, kBwOverusing, (kInitialBitrate - 20000) / 0.85, | |
minyue-webrtc
2017/04/11 10:50:02
what is 0.85
terelius
2017/04/19 07:36:01
We back off to 85% of the measured bitrate after a
minyue-webrtc
2017/04/19 07:49:05
can we give a name to it and constexpr?
terelius
2017/04/19 15:15:04
Done.
| |
146 states.simulated_clock->TimeInMilliseconds()); | |
147 EXPECT_EQ(5000, states.aimd_rate_control->GetNearMaxIncreaseRateBps()); | |
148 EXPECT_EQ(4000, states.aimd_rate_control->GetExpectedBandwidthPeriodMs()); | |
149 } | |
150 | |
151 TEST(AimdRateControlTest, BandwidthPeriodNotBelowMin) { | |
minyue-webrtc
2017/04/11 10:50:02
Not -> CanNot
terelius
2017/04/19 07:36:01
Done. (IsNot)
| |
152 auto states = CreateAimdRateControlStates(); | |
153 constexpr int kInitialBitrate = 10000; | |
154 states.aimd_rate_control->SetEstimate( | |
155 kInitialBitrate, states.simulated_clock->TimeInMilliseconds()); | |
156 states.simulated_clock->AdvanceTimeMilliseconds(100); | |
157 // Make a small (1.5 kbps) bitrate drop to 8.5 kbps. | |
158 UpdateRateControl(states, kBwOverusing, kInitialBitrate - 1, | |
159 states.simulated_clock->TimeInMilliseconds()); | |
160 EXPECT_EQ(kMinBwePeriodMs, | |
161 states.aimd_rate_control->GetExpectedBandwidthPeriodMs()); | |
162 } | |
163 | |
164 TEST(AimdRateControlTest, BandwidthPeriodNotAboveMax) { | |
minyue-webrtc
2017/04/11 10:50:02
Not -> CanNot
terelius
2017/04/19 07:36:01
Done. (IsNot)
| |
165 auto states = CreateAimdRateControlStates(); | |
166 constexpr int kInitialBitrate = 10010000; | |
167 states.aimd_rate_control->SetEstimate( | |
168 kInitialBitrate, states.simulated_clock->TimeInMilliseconds()); | |
169 states.simulated_clock->AdvanceTimeMilliseconds(100); | |
170 // Make a large (10 Mbps) bitrate drop to 10 kbps. | |
171 UpdateRateControl(states, kBwOverusing, 10000 / 0.85, | |
172 states.simulated_clock->TimeInMilliseconds()); | |
173 EXPECT_EQ(kMaxBwePeriodMs, | |
174 states.aimd_rate_control->GetExpectedBandwidthPeriodMs()); | |
175 } | |
176 | |
124 } // namespace webrtc | 177 } // namespace webrtc |
OLD | NEW |