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

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

Issue 2684353004: Reduce the BWE with 50% when feedback is received too late. (Closed)
Patch Set: rebase 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
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 current_input_.incoming_bitrate = input->incoming_bitrate; 126 current_input_.incoming_bitrate = input->incoming_bitrate;
127 } else { 127 } else {
128 updated_ = true; 128 updated_ = true;
129 current_input_ = *input; 129 current_input_ = *input;
130 } 130 }
131 } 131 }
132 132
133 void AimdRateControl::SetEstimate(int bitrate_bps, int64_t now_ms) { 133 void AimdRateControl::SetEstimate(int bitrate_bps, int64_t now_ms) {
134 updated_ = true; 134 updated_ = true;
135 bitrate_is_initialized_ = true; 135 bitrate_is_initialized_ = true;
136 current_bitrate_bps_ = ChangeBitrate(bitrate_bps, bitrate_bps, now_ms); 136 current_bitrate_bps_ = ClampBitrate(bitrate_bps, bitrate_bps);
137 time_last_bitrate_change_ = now_ms;
137 } 138 }
138 139
139 int AimdRateControl::GetNearMaxIncreaseRateBps() const { 140 int AimdRateControl::GetNearMaxIncreaseRateBps() const {
140 RTC_DCHECK_GT(current_bitrate_bps_, 0); 141 RTC_DCHECK_GT(current_bitrate_bps_, 0);
141 double bits_per_frame = static_cast<double>(current_bitrate_bps_) / 30.0; 142 double bits_per_frame = static_cast<double>(current_bitrate_bps_) / 30.0;
142 double packets_per_frame = std::ceil(bits_per_frame / (8.0 * 1200.0)); 143 double packets_per_frame = std::ceil(bits_per_frame / (8.0 * 1200.0));
143 double avg_packet_size_bits = bits_per_frame / packets_per_frame; 144 double avg_packet_size_bits = bits_per_frame / packets_per_frame;
144 // Approximate the over-use estimator delay to 100 ms. 145 // Approximate the over-use estimator delay to 100 ms.
145 const int64_t response_time = in_experiment_ ? (rtt_ + 100) * 2 : rtt_ + 100; 146 const int64_t response_time = in_experiment_ ? (rtt_ + 100) * 2 : rtt_ + 100;
146 147
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 uint32_t multiplicative_increase_bps = MultiplicativeRateIncrease( 192 uint32_t multiplicative_increase_bps = MultiplicativeRateIncrease(
192 now_ms, time_last_bitrate_change_, current_bitrate_bps); 193 now_ms, time_last_bitrate_change_, current_bitrate_bps);
193 current_bitrate_bps += multiplicative_increase_bps; 194 current_bitrate_bps += multiplicative_increase_bps;
194 } 195 }
195 196
196 time_last_bitrate_change_ = now_ms; 197 time_last_bitrate_change_ = now_ms;
197 break; 198 break;
198 199
199 case kRcDecrease: 200 case kRcDecrease:
200 bitrate_is_initialized_ = true; 201 bitrate_is_initialized_ = true;
201 if (incoming_bitrate_bps < min_configured_bitrate_bps_) { 202 // Set bit rate to something slightly lower than max
202 current_bitrate_bps = min_configured_bitrate_bps_; 203 // to get rid of any self-induced delay.
203 } else { 204 current_bitrate_bps =
terelius 2017/02/10 15:21:12 Maybe rename current_bitrate_bps to new_bitrate_bp
stefan-webrtc 2017/02/13 08:22:48 Yes, great suggestion
204 // Set bit rate to something slightly lower than max 205 static_cast<uint32_t>(beta_ * incoming_bitrate_bps + 0.5);
205 // to get rid of any self-induced delay. 206 if (current_bitrate_bps > current_bitrate_bps_) {
206 current_bitrate_bps = static_cast<uint32_t>(beta_ * 207 // Avoid increasing the rate when over-using.
207 incoming_bitrate_bps + 0.5); 208 if (rate_control_region_ != kRcMaxUnknown) {
208 if (current_bitrate_bps > current_bitrate_bps_) { 209 current_bitrate_bps = static_cast<uint32_t>(
209 // Avoid increasing the rate when over-using. 210 beta_ * avg_max_bitrate_kbps_ * 1000 + 0.5f);
210 if (rate_control_region_ != kRcMaxUnknown) {
211 current_bitrate_bps = static_cast<uint32_t>(
212 beta_ * avg_max_bitrate_kbps_ * 1000 + 0.5f);
213 }
214 current_bitrate_bps = std::min(current_bitrate_bps,
215 current_bitrate_bps_);
216 } 211 }
217 ChangeRegion(kRcNearMax); 212 current_bitrate_bps =
213 std::min(current_bitrate_bps, current_bitrate_bps_);
214 }
215 ChangeRegion(kRcNearMax);
218 216
219 if (incoming_bitrate_bps < current_bitrate_bps_) { 217 if (incoming_bitrate_bps < current_bitrate_bps_) {
220 last_decrease_ = 218 last_decrease_ =
221 rtc::Optional<int>(current_bitrate_bps_ - current_bitrate_bps); 219 rtc::Optional<int>(current_bitrate_bps_ - current_bitrate_bps);
222 } 220 }
223 if (incoming_bitrate_kbps < avg_max_bitrate_kbps_ - 221 if (incoming_bitrate_kbps <
224 3 * std_max_bit_rate) { 222 avg_max_bitrate_kbps_ - 3 * std_max_bit_rate) {
225 avg_max_bitrate_kbps_ = -1.0f; 223 avg_max_bitrate_kbps_ = -1.0f;
226 } 224 }
227 225
228 UpdateMaxBitRateEstimate(incoming_bitrate_kbps); 226 UpdateMaxBitRateEstimate(incoming_bitrate_kbps);
229 }
230 // Stay on hold until the pipes are cleared. 227 // Stay on hold until the pipes are cleared.
231 ChangeState(kRcHold); 228 ChangeState(kRcHold);
232 time_last_bitrate_change_ = now_ms; 229 time_last_bitrate_change_ = now_ms;
233 break; 230 break;
234 231
235 default: 232 default:
236 assert(false); 233 assert(false);
237 } 234 }
235 return ClampBitrate(current_bitrate_bps, incoming_bitrate_bps);
236 }
237
238 uint32_t AimdRateControl::ClampBitrate(uint32_t new_bitrate_bps,
239 uint32_t incoming_bitrate_bps) const {
238 // Don't change the bit rate if the send side is too far off. 240 // Don't change the bit rate if the send side is too far off.
239 // We allow a bit more lag at very low rates to not too easily get stuck if 241 // We allow a bit more lag at very low rates to not too easily get stuck if
240 // the encoder produces uneven outputs. 242 // the encoder produces uneven outputs.
241 const uint32_t max_bitrate_bps = 243 const uint32_t max_bitrate_bps =
242 static_cast<uint32_t>(1.5f * incoming_bitrate_bps) + 10000; 244 static_cast<uint32_t>(1.5f * incoming_bitrate_bps) + 10000;
243 if (current_bitrate_bps > current_bitrate_bps_ && 245 if (new_bitrate_bps > current_bitrate_bps_ &&
244 current_bitrate_bps > max_bitrate_bps) { 246 new_bitrate_bps > max_bitrate_bps) {
245 current_bitrate_bps = std::max(current_bitrate_bps_, max_bitrate_bps); 247 new_bitrate_bps = std::max(current_bitrate_bps_, max_bitrate_bps);
246 time_last_bitrate_change_ = now_ms;
247 } 248 }
248 return current_bitrate_bps; 249 new_bitrate_bps = std::max(new_bitrate_bps, min_configured_bitrate_bps_);
250 return new_bitrate_bps;
249 } 251 }
250 252
251 uint32_t AimdRateControl::MultiplicativeRateIncrease( 253 uint32_t AimdRateControl::MultiplicativeRateIncrease(
252 int64_t now_ms, int64_t last_ms, uint32_t current_bitrate_bps) const { 254 int64_t now_ms, int64_t last_ms, uint32_t current_bitrate_bps) const {
253 double alpha = 1.08; 255 double alpha = 1.08;
254 if (last_ms > -1) { 256 if (last_ms > -1) {
255 int time_since_last_update_ms = std::min(static_cast<int>(now_ms - last_ms), 257 int time_since_last_update_ms = std::min(static_cast<int>(now_ms - last_ms),
256 1000); 258 1000);
257 alpha = pow(alpha, time_since_last_update_ms / 1000.0); 259 alpha = pow(alpha, time_since_last_update_ms / 1000.0);
258 } 260 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 } 316 }
315 317
316 void AimdRateControl::ChangeRegion(RateControlRegion region) { 318 void AimdRateControl::ChangeRegion(RateControlRegion region) {
317 rate_control_region_ = region; 319 rate_control_region_ = region;
318 } 320 }
319 321
320 void AimdRateControl::ChangeState(RateControlState new_state) { 322 void AimdRateControl::ChangeState(RateControlState new_state) {
321 rate_control_state_ = new_state; 323 rate_control_state_ = new_state;
322 } 324 }
323 } // namespace webrtc 325 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698