OLD | NEW |
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 140 |
141 uint32_t AimdRateControl::ChangeBitrate(uint32_t new_bitrate_bps, | 141 uint32_t AimdRateControl::ChangeBitrate(uint32_t new_bitrate_bps, |
142 const RateControlInput& input, | 142 const RateControlInput& input, |
143 int64_t now_ms) { | 143 int64_t now_ms) { |
144 uint32_t incoming_bitrate_bps = | 144 uint32_t incoming_bitrate_bps = |
145 input.incoming_bitrate.value_or(current_bitrate_bps_); | 145 input.incoming_bitrate.value_or(current_bitrate_bps_); |
146 | 146 |
147 // An over-use should always trigger us to reduce the bitrate, even though | 147 // An over-use should always trigger us to reduce the bitrate, even though |
148 // we have not yet established our first estimate. By acting on the over-use, | 148 // we have not yet established our first estimate. By acting on the over-use, |
149 // we will end up with a valid estimate. | 149 // we will end up with a valid estimate. |
150 if (!bitrate_is_initialized_ && input.bw_state != kBwOverusing) | 150 if (!bitrate_is_initialized_ && |
| 151 input.bw_state != BandwidthUsage::kBwOverusing) |
151 return current_bitrate_bps_; | 152 return current_bitrate_bps_; |
152 | 153 |
153 ChangeState(input, now_ms); | 154 ChangeState(input, now_ms); |
154 // Calculated here because it's used in multiple places. | 155 // Calculated here because it's used in multiple places. |
155 const float incoming_bitrate_kbps = incoming_bitrate_bps / 1000.0f; | 156 const float incoming_bitrate_kbps = incoming_bitrate_bps / 1000.0f; |
156 // Calculate the max bit rate std dev given the normalized | 157 // Calculate the max bit rate std dev given the normalized |
157 // variance and the current incoming bit rate. | 158 // variance and the current incoming bit rate. |
158 const float std_max_bit_rate = sqrt(var_max_bitrate_kbps_ * | 159 const float std_max_bit_rate = sqrt(var_max_bitrate_kbps_ * |
159 avg_max_bitrate_kbps_); | 160 avg_max_bitrate_kbps_); |
160 switch (rate_control_state_) { | 161 switch (rate_control_state_) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 } | 273 } |
273 // 2.5f ~= 35 kbit/s at 500 kbit/s | 274 // 2.5f ~= 35 kbit/s at 500 kbit/s |
274 if (var_max_bitrate_kbps_ > 2.5f) { | 275 if (var_max_bitrate_kbps_ > 2.5f) { |
275 var_max_bitrate_kbps_ = 2.5f; | 276 var_max_bitrate_kbps_ = 2.5f; |
276 } | 277 } |
277 } | 278 } |
278 | 279 |
279 void AimdRateControl::ChangeState(const RateControlInput& input, | 280 void AimdRateControl::ChangeState(const RateControlInput& input, |
280 int64_t now_ms) { | 281 int64_t now_ms) { |
281 switch (input.bw_state) { | 282 switch (input.bw_state) { |
282 case kBwNormal: | 283 case BandwidthUsage::kBwNormal: |
283 if (rate_control_state_ == kRcHold) { | 284 if (rate_control_state_ == kRcHold) { |
284 time_last_bitrate_change_ = now_ms; | 285 time_last_bitrate_change_ = now_ms; |
285 rate_control_state_ = kRcIncrease; | 286 rate_control_state_ = kRcIncrease; |
286 } | 287 } |
287 break; | 288 break; |
288 case kBwOverusing: | 289 case BandwidthUsage::kBwOverusing: |
289 if (rate_control_state_ != kRcDecrease) { | 290 if (rate_control_state_ != kRcDecrease) { |
290 rate_control_state_ = kRcDecrease; | 291 rate_control_state_ = kRcDecrease; |
291 } | 292 } |
292 break; | 293 break; |
293 case kBwUnderusing: | 294 case BandwidthUsage::kBwUnderusing: |
294 rate_control_state_ = kRcHold; | 295 rate_control_state_ = kRcHold; |
295 break; | 296 break; |
296 default: | 297 default: |
297 assert(false); | 298 assert(false); |
298 } | 299 } |
299 } | 300 } |
300 | 301 |
301 void AimdRateControl::ChangeRegion(RateControlRegion region) { | 302 void AimdRateControl::ChangeRegion(RateControlRegion region) { |
302 rate_control_region_ = region; | 303 rate_control_region_ = region; |
303 } | 304 } |
304 | 305 |
305 } // namespace webrtc | 306 } // namespace webrtc |
OLD | NEW |