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) { | 73 TEST(AimdRateControlTest, GetIncreaseRateAndBandwidthPeriod) { |
70 auto states = CreateAimdRateControlStates(); | |
71 EXPECT_EQ(rtc::Optional<int>(), | |
72 states.aimd_rate_control->GetLastBitrateDecreaseBps()); | |
73 } | |
74 | |
75 TEST(AimdRateControlTest, GetLastBitrateDecrease) { | |
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, BandwidthUsage::kBwOverusing, kBitrate - 2000, | 78 UpdateRateControl(states, BandwidthUsage::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(), |
83 states.aimd_rate_control->GetLastBitrateDecreaseBps()); | 81 1000); |
82 EXPECT_EQ(3000, states.aimd_rate_control->GetExpectedBandwidthPeriodMs()); | |
84 } | 83 } |
85 | 84 |
86 TEST(AimdRateControlTest, BweLimitedByAckedBitrate) { | 85 TEST(AimdRateControlTest, BweLimitedByAckedBitrate) { |
87 auto states = CreateAimdRateControlStates(); | 86 auto states = CreateAimdRateControlStates(); |
88 constexpr int kAckedBitrate = 10000; | 87 constexpr int kAckedBitrate = 10000; |
89 states.aimd_rate_control->SetEstimate( | 88 states.aimd_rate_control->SetEstimate( |
90 kAckedBitrate, states.simulated_clock->TimeInMilliseconds()); | 89 kAckedBitrate, states.simulated_clock->TimeInMilliseconds()); |
91 while (states.simulated_clock->TimeInMilliseconds() - kClockInitialTime < | 90 while (states.simulated_clock->TimeInMilliseconds() - kClockInitialTime < |
92 20000) { | 91 20000) { |
93 UpdateRateControl(states, BandwidthUsage::kBwNormal, kAckedBitrate, | 92 UpdateRateControl(states, BandwidthUsage::kBwNormal, kAckedBitrate, |
(...skipping 20 matching lines...) Expand all Loading... | |
114 // If the acked bitrate decreases the BWE shouldn't be reduced to 1.5x | 113 // 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. | 114 // what's being acked, but also shouldn't get to increase more. |
116 uint32_t prev_estimate = states.aimd_rate_control->LatestEstimate(); | 115 uint32_t prev_estimate = states.aimd_rate_control->LatestEstimate(); |
117 UpdateRateControl(states, BandwidthUsage::kBwNormal, kAckedBitrate / 2, | 116 UpdateRateControl(states, BandwidthUsage::kBwNormal, kAckedBitrate / 2, |
118 states.simulated_clock->TimeInMilliseconds()); | 117 states.simulated_clock->TimeInMilliseconds()); |
119 uint32_t new_estimate = states.aimd_rate_control->LatestEstimate(); | 118 uint32_t new_estimate = states.aimd_rate_control->LatestEstimate(); |
120 EXPECT_NEAR(new_estimate, static_cast<uint32_t>(1.5 * kAckedBitrate + 10000), | 119 EXPECT_NEAR(new_estimate, static_cast<uint32_t>(1.5 * kAckedBitrate + 10000), |
121 2000); | 120 2000); |
122 EXPECT_EQ(new_estimate, prev_estimate); | 121 EXPECT_EQ(new_estimate, prev_estimate); |
123 } | 122 } |
123 | |
124 TEST(AimdRateControlTest, DefaultPeriodUntilFirstOveruse) { | |
125 auto states = CreateAimdRateControlStates(); | |
126 states.aimd_rate_control->SetStartBitrate(300000); | |
127 EXPECT_EQ(kDefaultPeriodMs, | |
128 states.aimd_rate_control->GetExpectedBandwidthPeriodMs()); | |
129 states.simulated_clock->AdvanceTimeMilliseconds(100); | |
130 UpdateRateControl(states, BandwidthUsage::kBwOverusing, 100000, | |
131 states.simulated_clock->TimeInMilliseconds()); | |
132 EXPECT_NE(kDefaultPeriodMs, | |
133 states.aimd_rate_control->GetExpectedBandwidthPeriodMs()); | |
134 } | |
135 | |
136 TEST(AimdRateControlTest, ExpectedPeriodAfter20kbpsDropAnd5kbpsIncrease) { | |
137 auto states = CreateAimdRateControlStates(); | |
138 constexpr int kInitialBitrate = 110000; | |
139 states.aimd_rate_control->SetEstimate( | |
140 kInitialBitrate, states.simulated_clock->TimeInMilliseconds()); | |
141 states.simulated_clock->AdvanceTimeMilliseconds(100); | |
142 // Make the bitrate drop by 20 kbps to get to 90 kbps. | |
143 // The rate increase at 90 kbps should be 5 kbps, so the period should be 4 s. | |
144 UpdateRateControl(states, BandwidthUsage::kBwOverusing, | |
145 (kInitialBitrate - 20000) / 0.85, | |
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, BandwidthPeriodIsNotBelowMin) { | |
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, BandwidthUsage::kBwOverusing, kInitialBitrate - 1, | |
159 states.simulated_clock->TimeInMilliseconds()); | |
160 EXPECT_EQ(kMinBwePeriodMs, | |
161 states.aimd_rate_control->GetExpectedBandwidthPeriodMs()); | |
162 } | |
163 | |
164 TEST(AimdRateControlTest, BandwidthPeriodIsNotAboveMax) { | |
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, BandwidthUsage::kBwOverusing, 10000 / 0.85, | |
minyue-webrtc
2017/04/19 07:49:05
a name to 0,85, as commented at another place.
| |
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 |