Chromium Code Reviews| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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; | |
|
minyue-webrtc
2016/11/14 16:50:42
possible division of zero?
michaelt
2016/11/15 09:41:59
Theoretical yes. Added a DCHECK of current_bitrate
| |
| 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; | |
| 141 return std::max(kMinIncreaseRateBps, | |
| 142 (avg_packet_size_bits * 1000) / response_time); | |
|
minyue-webrtc
2016/11/14 16:50:42
Add explicit cast
michaelt
2016/11/15 09:41:59
Done.
| |
| 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 Loading... | |
| 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_) { | |
| 213 last_decrease_ = | |
| 214 rtc::Optional<int>(current_bitrate_bps_ - current_bitrate_bps); | |
| 215 } | |
| 199 if (incoming_bitrate_kbps < avg_max_bitrate_kbps_ - | 216 if (incoming_bitrate_kbps < avg_max_bitrate_kbps_ - |
| 200 3 * std_max_bit_rate) { | 217 3 * std_max_bit_rate) { |
| 201 avg_max_bitrate_kbps_ = -1.0f; | 218 avg_max_bitrate_kbps_ = -1.0f; |
| 202 } | 219 } |
| 203 | 220 |
| 204 UpdateMaxBitRateEstimate(incoming_bitrate_kbps); | 221 UpdateMaxBitRateEstimate(incoming_bitrate_kbps); |
| 205 } | 222 } |
| 206 // Stay on hold until the pipes are cleared. | 223 // Stay on hold until the pipes are cleared. |
| 207 ChangeState(kRcHold); | 224 ChangeState(kRcHold); |
| 208 time_last_bitrate_change_ = now_ms; | 225 time_last_bitrate_change_ = now_ms; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 227 if (last_ms > -1) { | 244 if (last_ms > -1) { |
| 228 int time_since_last_update_ms = std::min(static_cast<int>(now_ms - last_ms), | 245 int time_since_last_update_ms = std::min(static_cast<int>(now_ms - last_ms), |
| 229 1000); | 246 1000); |
| 230 alpha = pow(alpha, time_since_last_update_ms / 1000.0); | 247 alpha = pow(alpha, time_since_last_update_ms / 1000.0); |
| 231 } | 248 } |
| 232 uint32_t multiplicative_increase_bps = std::max( | 249 uint32_t multiplicative_increase_bps = std::max( |
| 233 current_bitrate_bps * (alpha - 1.0), 1000.0); | 250 current_bitrate_bps * (alpha - 1.0), 1000.0); |
| 234 return multiplicative_increase_bps; | 251 return multiplicative_increase_bps; |
| 235 } | 252 } |
| 236 | 253 |
| 237 uint32_t AimdRateControl::AdditiveRateIncrease( | 254 uint32_t AimdRateControl::AdditiveRateIncrease(int64_t now_ms, |
| 238 int64_t now_ms, int64_t last_ms, int64_t response_time_ms) const { | 255 int64_t last_ms) const { |
| 239 assert(response_time_ms > 0); | 256 return (now_ms - last_ms) * GetNearMaxIncreaseRateBps() / 1000.0; |
|
minyue-webrtc
2016/11/14 16:50:42
why double on 1000.0 or do we want to return a dou
michaelt
2016/11/15 09:41:59
Removed ".0" from 1000
| |
| 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 } | 257 } |
| 254 | 258 |
| 255 void AimdRateControl::UpdateMaxBitRateEstimate(float incoming_bitrate_kbps) { | 259 void AimdRateControl::UpdateMaxBitRateEstimate(float incoming_bitrate_kbps) { |
| 256 const float alpha = 0.05f; | 260 const float alpha = 0.05f; |
| 257 if (avg_max_bitrate_kbps_ == -1.0f) { | 261 if (avg_max_bitrate_kbps_ == -1.0f) { |
| 258 avg_max_bitrate_kbps_ = incoming_bitrate_kbps; | 262 avg_max_bitrate_kbps_ = incoming_bitrate_kbps; |
| 259 } else { | 263 } else { |
| 260 avg_max_bitrate_kbps_ = (1 - alpha) * avg_max_bitrate_kbps_ + | 264 avg_max_bitrate_kbps_ = (1 - alpha) * avg_max_bitrate_kbps_ + |
| 261 alpha * incoming_bitrate_kbps; | 265 alpha * incoming_bitrate_kbps; |
| 262 } | 266 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 } | 303 } |
| 300 | 304 |
| 301 void AimdRateControl::ChangeRegion(RateControlRegion region) { | 305 void AimdRateControl::ChangeRegion(RateControlRegion region) { |
| 302 rate_control_region_ = region; | 306 rate_control_region_ = region; |
| 303 } | 307 } |
| 304 | 308 |
| 305 void AimdRateControl::ChangeState(RateControlState new_state) { | 309 void AimdRateControl::ChangeState(RateControlState new_state) { |
| 306 rate_control_state_ = new_state; | 310 rate_control_state_ = new_state; |
| 307 } | 311 } |
| 308 } // namespace webrtc | 312 } // namespace webrtc |
| OLD | NEW |