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

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

Issue 2380883003: Add interval estimator to remote bitrate estimator (Closed)
Patch Set: Response to an offline discussion. 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 current_input_ = *input; 123 current_input_ = *input;
124 } 124 }
125 } 125 }
126 126
127 void AimdRateControl::SetEstimate(int bitrate_bps, int64_t now_ms) { 127 void AimdRateControl::SetEstimate(int bitrate_bps, int64_t now_ms) {
128 updated_ = true; 128 updated_ = true;
129 bitrate_is_initialized_ = true; 129 bitrate_is_initialized_ = true;
130 current_bitrate_bps_ = ChangeBitrate(bitrate_bps, bitrate_bps, now_ms); 130 current_bitrate_bps_ = ChangeBitrate(bitrate_bps, bitrate_bps, now_ms);
131 } 131 }
132 132
133 int AimdRateControl::GetNearMaxIncreaseRateBps() const {
134 double bits_per_frame = static_cast<double>(current_bitrate_bps_) / 30.0;
135 double packets_per_frame = std::ceil(bits_per_frame / (8.0 * 1200.0));
136 double avg_packet_size_bits = bits_per_frame / packets_per_frame;
137 // Approximate the over-use estimator delay to 100 ms.
138 const int64_t response_time = in_experiment_ ? (rtt_ + 100) * 2 : rtt_ + 100;
139
140 constexpr double kMinIncreaseRateBps = 4000;
stefan-webrtc 2016/11/08 13:06:28 4000 is larger than before when it was 1000, right
michaelt 2016/11/09 07:54:44 No its actually smaller. Before we had 1kbps per c
stefan-webrtc 2016/11/09 18:01:10 Should we keep 5 kbps then? BTW, how come it was a
michaelt 2016/11/10 08:57:31 this 200ms are not const as you expected, they are
stefan-webrtc 2016/11/14 14:53:48 SG
141 return std::max(kMinIncreaseRateBps,
142 (avg_packet_size_bits * 1000) / response_time);
143 }
144
145 rtc::Optional<int> AimdRateControl::GetLastDecrease() const {
146 return last_decrease_;
147 }
148
133 uint32_t AimdRateControl::ChangeBitrate(uint32_t current_bitrate_bps, 149 uint32_t AimdRateControl::ChangeBitrate(uint32_t current_bitrate_bps,
134 uint32_t incoming_bitrate_bps, 150 uint32_t incoming_bitrate_bps,
135 int64_t now_ms) { 151 int64_t now_ms) {
136 if (!updated_) { 152 if (!updated_) {
137 return current_bitrate_bps_; 153 return current_bitrate_bps_;
138 } 154 }
139 // An over-use should always trigger us to reduce the bitrate, even though 155 // An over-use should always trigger us to reduce the bitrate, even though
140 // we have not yet established our first estimate. By acting on the over-use, 156 // we have not yet established our first estimate. By acting on the over-use,
141 // we will end up with a valid estimate. 157 // we will end up with a valid estimate.
142 if (!bitrate_is_initialized_ && current_input_.bw_state != kBwOverusing) 158 if (!bitrate_is_initialized_ && current_input_.bw_state != kBwOverusing)
(...skipping 11 matching lines...) Expand all
154 break; 170 break;
155 171
156 case kRcIncrease: 172 case kRcIncrease:
157 if (avg_max_bitrate_kbps_ >= 0 && 173 if (avg_max_bitrate_kbps_ >= 0 &&
158 incoming_bitrate_kbps > 174 incoming_bitrate_kbps >
159 avg_max_bitrate_kbps_ + 3 * std_max_bit_rate) { 175 avg_max_bitrate_kbps_ + 3 * std_max_bit_rate) {
160 ChangeRegion(kRcMaxUnknown); 176 ChangeRegion(kRcMaxUnknown);
161 avg_max_bitrate_kbps_ = -1.0; 177 avg_max_bitrate_kbps_ = -1.0;
162 } 178 }
163 if (rate_control_region_ == kRcNearMax) { 179 if (rate_control_region_ == kRcNearMax) {
164 // Approximate the over-use estimator delay to 100 ms. 180 uint32_t additive_increase_bps =
165 const int64_t response_time = rtt_ + 100; 181 AdditiveRateIncrease(now_ms, time_last_bitrate_change_);
166 uint32_t additive_increase_bps = AdditiveRateIncrease(
167 now_ms, time_last_bitrate_change_, response_time);
168 current_bitrate_bps += additive_increase_bps; 182 current_bitrate_bps += additive_increase_bps;
169
170 } else { 183 } else {
171 uint32_t multiplicative_increase_bps = MultiplicativeRateIncrease( 184 uint32_t multiplicative_increase_bps = MultiplicativeRateIncrease(
172 now_ms, time_last_bitrate_change_, current_bitrate_bps); 185 now_ms, time_last_bitrate_change_, current_bitrate_bps);
173 current_bitrate_bps += multiplicative_increase_bps; 186 current_bitrate_bps += multiplicative_increase_bps;
174 } 187 }
175 188
176 time_last_bitrate_change_ = now_ms; 189 time_last_bitrate_change_ = now_ms;
177 break; 190 break;
178 191
179 case kRcDecrease: 192 case kRcDecrease:
180 bitrate_is_initialized_ = true; 193 bitrate_is_initialized_ = true;
181 if (incoming_bitrate_bps < min_configured_bitrate_bps_) { 194 if (incoming_bitrate_bps < min_configured_bitrate_bps_) {
182 current_bitrate_bps = min_configured_bitrate_bps_; 195 current_bitrate_bps = min_configured_bitrate_bps_;
183 } else { 196 } else {
184 // Set bit rate to something slightly lower than max 197 // Set bit rate to something slightly lower than max
185 // to get rid of any self-induced delay. 198 // to get rid of any self-induced delay.
186 current_bitrate_bps = static_cast<uint32_t>(beta_ * 199 current_bitrate_bps = static_cast<uint32_t>(beta_ *
187 incoming_bitrate_bps + 0.5); 200 incoming_bitrate_bps + 0.5);
188 if (current_bitrate_bps > current_bitrate_bps_) { 201 if (current_bitrate_bps > current_bitrate_bps_) {
189 // Avoid increasing the rate when over-using. 202 // Avoid increasing the rate when over-using.
190 if (rate_control_region_ != kRcMaxUnknown) { 203 if (rate_control_region_ != kRcMaxUnknown) {
191 current_bitrate_bps = static_cast<uint32_t>( 204 current_bitrate_bps = static_cast<uint32_t>(
192 beta_ * avg_max_bitrate_kbps_ * 1000 + 0.5f); 205 beta_ * avg_max_bitrate_kbps_ * 1000 + 0.5f);
193 } 206 }
194 current_bitrate_bps = std::min(current_bitrate_bps, 207 current_bitrate_bps = std::min(current_bitrate_bps,
195 current_bitrate_bps_); 208 current_bitrate_bps_);
196 } 209 }
197 ChangeRegion(kRcNearMax); 210 ChangeRegion(kRcNearMax);
198 211
212 if (incoming_bitrate_bps < current_bitrate_bps_)
stefan-webrtc 2016/11/08 13:06:28 {}
michaelt 2016/11/09 07:54:44 Done.
213 last_decrease_ =
214 rtc::Optional<int>(current_bitrate_bps_ - current_bitrate_bps);
199 if (incoming_bitrate_kbps < avg_max_bitrate_kbps_ - 215 if (incoming_bitrate_kbps < avg_max_bitrate_kbps_ -
200 3 * std_max_bit_rate) { 216 3 * std_max_bit_rate) {
201 avg_max_bitrate_kbps_ = -1.0f; 217 avg_max_bitrate_kbps_ = -1.0f;
202 } 218 }
203 219
204 UpdateMaxBitRateEstimate(incoming_bitrate_kbps); 220 UpdateMaxBitRateEstimate(incoming_bitrate_kbps);
205 } 221 }
206 // Stay on hold until the pipes are cleared. 222 // Stay on hold until the pipes are cleared.
207 ChangeState(kRcHold); 223 ChangeState(kRcHold);
208 time_last_bitrate_change_ = now_ms; 224 time_last_bitrate_change_ = now_ms;
(...skipping 18 matching lines...) Expand all
227 if (last_ms > -1) { 243 if (last_ms > -1) {
228 int time_since_last_update_ms = std::min(static_cast<int>(now_ms - last_ms), 244 int time_since_last_update_ms = std::min(static_cast<int>(now_ms - last_ms),
229 1000); 245 1000);
230 alpha = pow(alpha, time_since_last_update_ms / 1000.0); 246 alpha = pow(alpha, time_since_last_update_ms / 1000.0);
231 } 247 }
232 uint32_t multiplicative_increase_bps = std::max( 248 uint32_t multiplicative_increase_bps = std::max(
233 current_bitrate_bps * (alpha - 1.0), 1000.0); 249 current_bitrate_bps * (alpha - 1.0), 1000.0);
234 return multiplicative_increase_bps; 250 return multiplicative_increase_bps;
235 } 251 }
236 252
237 uint32_t AimdRateControl::AdditiveRateIncrease( 253 uint32_t AimdRateControl::AdditiveRateIncrease(int64_t now_ms,
238 int64_t now_ms, int64_t last_ms, int64_t response_time_ms) const { 254 int64_t last_ms) const {
239 assert(response_time_ms > 0); 255 return (GetNearMaxIncreaseRateBps() / 1000.0) * (now_ms - last_ms);
stefan-webrtc 2016/11/08 13:06:28 You can remove () around GetNear...
michaelt 2016/11/09 07:54:44 Done.
240 double beta = 0.0;
241 if (last_ms > 0) {
242 beta = std::min((now_ms - last_ms) / static_cast<double>(response_time_ms),
243 1.0);
244 if (in_experiment_)
245 beta /= 2.0;
246 }
247 double bits_per_frame = static_cast<double>(current_bitrate_bps_) / 30.0;
248 double packets_per_frame = std::ceil(bits_per_frame / (8.0 * 1200.0));
249 double avg_packet_size_bits = bits_per_frame / packets_per_frame;
250 uint32_t additive_increase_bps = std::max(
251 1000.0, beta * avg_packet_size_bits);
252 return additive_increase_bps;
253 } 256 }
254 257
255 void AimdRateControl::UpdateMaxBitRateEstimate(float incoming_bitrate_kbps) { 258 void AimdRateControl::UpdateMaxBitRateEstimate(float incoming_bitrate_kbps) {
256 const float alpha = 0.05f; 259 const float alpha = 0.05f;
257 if (avg_max_bitrate_kbps_ == -1.0f) { 260 if (avg_max_bitrate_kbps_ == -1.0f) {
258 avg_max_bitrate_kbps_ = incoming_bitrate_kbps; 261 avg_max_bitrate_kbps_ = incoming_bitrate_kbps;
259 } else { 262 } else {
260 avg_max_bitrate_kbps_ = (1 - alpha) * avg_max_bitrate_kbps_ + 263 avg_max_bitrate_kbps_ = (1 - alpha) * avg_max_bitrate_kbps_ +
261 alpha * incoming_bitrate_kbps; 264 alpha * incoming_bitrate_kbps;
262 } 265 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 302 }
300 303
301 void AimdRateControl::ChangeRegion(RateControlRegion region) { 304 void AimdRateControl::ChangeRegion(RateControlRegion region) {
302 rate_control_region_ = region; 305 rate_control_region_ = region;
303 } 306 }
304 307
305 void AimdRateControl::ChangeState(RateControlState new_state) { 308 void AimdRateControl::ChangeState(RateControlState new_state) {
306 rate_control_state_ = new_state; 309 rate_control_state_ = new_state;
307 } 310 }
308 } // namespace webrtc 311 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698