| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 81 } |
| 82 return false; | 82 return false; |
| 83 } | 83 } |
| 84 | 84 |
| 85 uint32_t AimdRateControl::LatestEstimate() const { | 85 uint32_t AimdRateControl::LatestEstimate() const { |
| 86 return current_bitrate_bps_; | 86 return current_bitrate_bps_; |
| 87 } | 87 } |
| 88 | 88 |
| 89 uint32_t AimdRateControl::UpdateBandwidthEstimate(int64_t now_ms) { | 89 uint32_t AimdRateControl::UpdateBandwidthEstimate(int64_t now_ms) { |
| 90 current_bitrate_bps_ = ChangeBitrate(current_bitrate_bps_, | 90 current_bitrate_bps_ = ChangeBitrate(current_bitrate_bps_, |
| 91 current_input_._incomingBitRate, | 91 current_input_.incoming_bitrate, now_ms); |
| 92 now_ms); | |
| 93 if (now_ms - time_of_last_log_ > kLogIntervalMs) { | 92 if (now_ms - time_of_last_log_ > kLogIntervalMs) { |
| 94 time_of_last_log_ = now_ms; | 93 time_of_last_log_ = now_ms; |
| 95 } | 94 } |
| 96 return current_bitrate_bps_; | 95 return current_bitrate_bps_; |
| 97 } | 96 } |
| 98 | 97 |
| 99 void AimdRateControl::SetRtt(int64_t rtt) { | 98 void AimdRateControl::SetRtt(int64_t rtt) { |
| 100 rtt_ = rtt; | 99 rtt_ = rtt; |
| 101 } | 100 } |
| 102 | 101 |
| 103 void AimdRateControl::Update(const RateControlInput* input, int64_t now_ms) { | 102 void AimdRateControl::Update(const RateControlInput* input, int64_t now_ms) { |
| 104 assert(input); | 103 assert(input); |
| 105 | 104 |
| 106 // Set the initial bit rate value to what we're receiving the first half | 105 // Set the initial bit rate value to what we're receiving the first half |
| 107 // second. | 106 // second. |
| 108 if (!bitrate_is_initialized_) { | 107 if (!bitrate_is_initialized_) { |
| 109 const int64_t kInitializationTimeMs = 5000; | 108 const int64_t kInitializationTimeMs = 5000; |
| 110 RTC_DCHECK_LE(kBitrateWindowMs, kInitializationTimeMs); | 109 RTC_DCHECK_LE(kBitrateWindowMs, kInitializationTimeMs); |
| 111 if (time_first_incoming_estimate_ < 0) { | 110 if (time_first_incoming_estimate_ < 0) { |
| 112 if (input->_incomingBitRate > 0) { | 111 if (input->incoming_bitrate > 0) { |
| 113 time_first_incoming_estimate_ = now_ms; | 112 time_first_incoming_estimate_ = now_ms; |
| 114 } | 113 } |
| 115 } else if (now_ms - time_first_incoming_estimate_ > kInitializationTimeMs && | 114 } else if (now_ms - time_first_incoming_estimate_ > kInitializationTimeMs && |
| 116 input->_incomingBitRate > 0) { | 115 input->incoming_bitrate > 0) { |
| 117 current_bitrate_bps_ = input->_incomingBitRate; | 116 current_bitrate_bps_ = input->incoming_bitrate; |
| 118 bitrate_is_initialized_ = true; | 117 bitrate_is_initialized_ = true; |
| 119 } | 118 } |
| 120 } | 119 } |
| 121 | 120 |
| 122 if (updated_ && current_input_._bwState == kBwOverusing) { | 121 if (updated_ && current_input_.bw_state == kBwOverusing) { |
| 123 // Only update delay factor and incoming bit rate. We always want to react | 122 // Only update delay factor and incoming bit rate. We always want to react |
| 124 // on an over-use. | 123 // on an over-use. |
| 125 current_input_._noiseVar = input->_noiseVar; | 124 current_input_.noise_var = input->noise_var; |
| 126 current_input_._incomingBitRate = input->_incomingBitRate; | 125 current_input_.incoming_bitrate = input->incoming_bitrate; |
| 127 } else { | 126 } else { |
| 128 updated_ = true; | 127 updated_ = true; |
| 129 current_input_ = *input; | 128 current_input_ = *input; |
| 130 } | 129 } |
| 131 } | 130 } |
| 132 | 131 |
| 133 void AimdRateControl::SetEstimate(int bitrate_bps, int64_t now_ms) { | 132 void AimdRateControl::SetEstimate(int bitrate_bps, int64_t now_ms) { |
| 134 updated_ = true; | 133 updated_ = true; |
| 135 bitrate_is_initialized_ = true; | 134 bitrate_is_initialized_ = true; |
| 136 current_bitrate_bps_ = ChangeBitrate(bitrate_bps, bitrate_bps, now_ms); | 135 current_bitrate_bps_ = ChangeBitrate(bitrate_bps, bitrate_bps, now_ms); |
| 137 } | 136 } |
| 138 | 137 |
| 139 uint32_t AimdRateControl::ChangeBitrate(uint32_t current_bitrate_bps, | 138 uint32_t AimdRateControl::ChangeBitrate(uint32_t current_bitrate_bps, |
| 140 uint32_t incoming_bitrate_bps, | 139 uint32_t incoming_bitrate_bps, |
| 141 int64_t now_ms) { | 140 int64_t now_ms) { |
| 142 if (!updated_) { | 141 if (!updated_) { |
| 143 return current_bitrate_bps_; | 142 return current_bitrate_bps_; |
| 144 } | 143 } |
| 145 // An over-use should always trigger us to reduce the bitrate, even though | 144 // An over-use should always trigger us to reduce the bitrate, even though |
| 146 // we have not yet established our first estimate. By acting on the over-use, | 145 // we have not yet established our first estimate. By acting on the over-use, |
| 147 // we will end up with a valid estimate. | 146 // we will end up with a valid estimate. |
| 148 if (!bitrate_is_initialized_ && current_input_._bwState != kBwOverusing) | 147 if (!bitrate_is_initialized_ && current_input_.bw_state != kBwOverusing) |
| 149 return current_bitrate_bps_; | 148 return current_bitrate_bps_; |
| 150 updated_ = false; | 149 updated_ = false; |
| 151 ChangeState(current_input_, now_ms); | 150 ChangeState(current_input_, now_ms); |
| 152 // Calculated here because it's used in multiple places. | 151 // Calculated here because it's used in multiple places. |
| 153 const float incoming_bitrate_kbps = incoming_bitrate_bps / 1000.0f; | 152 const float incoming_bitrate_kbps = incoming_bitrate_bps / 1000.0f; |
| 154 // Calculate the max bit rate std dev given the normalized | 153 // Calculate the max bit rate std dev given the normalized |
| 155 // variance and the current incoming bit rate. | 154 // variance and the current incoming bit rate. |
| 156 const float std_max_bit_rate = sqrt(var_max_bitrate_kbps_ * | 155 const float std_max_bit_rate = sqrt(var_max_bitrate_kbps_ * |
| 157 avg_max_bitrate_kbps_); | 156 avg_max_bitrate_kbps_); |
| 158 switch (rate_control_state_) { | 157 switch (rate_control_state_) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 var_max_bitrate_kbps_ = 0.4f; | 276 var_max_bitrate_kbps_ = 0.4f; |
| 278 } | 277 } |
| 279 // 2.5f ~= 35 kbit/s at 500 kbit/s | 278 // 2.5f ~= 35 kbit/s at 500 kbit/s |
| 280 if (var_max_bitrate_kbps_ > 2.5f) { | 279 if (var_max_bitrate_kbps_ > 2.5f) { |
| 281 var_max_bitrate_kbps_ = 2.5f; | 280 var_max_bitrate_kbps_ = 2.5f; |
| 282 } | 281 } |
| 283 } | 282 } |
| 284 | 283 |
| 285 void AimdRateControl::ChangeState(const RateControlInput& input, | 284 void AimdRateControl::ChangeState(const RateControlInput& input, |
| 286 int64_t now_ms) { | 285 int64_t now_ms) { |
| 287 switch (current_input_._bwState) { | 286 switch (current_input_.bw_state) { |
| 288 case kBwNormal: | 287 case kBwNormal: |
| 289 if (rate_control_state_ == kRcHold) { | 288 if (rate_control_state_ == kRcHold) { |
| 290 time_last_bitrate_change_ = now_ms; | 289 time_last_bitrate_change_ = now_ms; |
| 291 ChangeState(kRcIncrease); | 290 ChangeState(kRcIncrease); |
| 292 } | 291 } |
| 293 break; | 292 break; |
| 294 case kBwOverusing: | 293 case kBwOverusing: |
| 295 if (rate_control_state_ != kRcDecrease) { | 294 if (rate_control_state_ != kRcDecrease) { |
| 296 ChangeState(kRcDecrease); | 295 ChangeState(kRcDecrease); |
| 297 } | 296 } |
| 298 break; | 297 break; |
| 299 case kBwUnderusing: | 298 case kBwUnderusing: |
| 300 ChangeState(kRcHold); | 299 ChangeState(kRcHold); |
| 301 break; | 300 break; |
| 302 default: | 301 default: |
| 303 assert(false); | 302 assert(false); |
| 304 } | 303 } |
| 305 } | 304 } |
| 306 | 305 |
| 307 void AimdRateControl::ChangeRegion(RateControlRegion region) { | 306 void AimdRateControl::ChangeRegion(RateControlRegion region) { |
| 308 rate_control_region_ = region; | 307 rate_control_region_ = region; |
| 309 } | 308 } |
| 310 | 309 |
| 311 void AimdRateControl::ChangeState(RateControlState new_state) { | 310 void AimdRateControl::ChangeState(RateControlState new_state) { |
| 312 rate_control_state_ = new_state; | 311 rate_control_state_ = new_state; |
| 313 } | 312 } |
| 314 } // namespace webrtc | 313 } // namespace webrtc |
| OLD | NEW |