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 |
11 #include "webrtc/modules/remote_bitrate_estimator/aimd_rate_control.h" | 11 #include "webrtc/modules/remote_bitrate_estimator/aimd_rate_control.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <cassert> | 14 #include <cassert> |
15 #include <cmath> | 15 #include <cmath> |
16 | 16 |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 | 18 |
19 #include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h" | 19 #include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h" |
20 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" | 20 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" |
21 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" | 21 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" |
22 | 22 |
23 namespace webrtc { | 23 namespace webrtc { |
24 | 24 |
25 static const int64_t kDefaultRttMs = 200; | 25 namespace { |
26 static const double kWithinIncomingBitrateHysteresis = 1.05; | 26 constexpr int64_t kDefaultRttMs = 200; |
27 static const int64_t kMaxFeedbackIntervalMs = 1000; | 27 constexpr double kWithinIncomingBitrateHysteresis = 1.05; |
| 28 constexpr int64_t kMaxFeedbackIntervalMs = 1000; |
| 29 constexpr double kMinIncreaseBps = 250.0; |
| 30 } // namespace |
28 | 31 |
29 AimdRateControl::AimdRateControl() | 32 AimdRateControl::AimdRateControl() |
30 : min_configured_bitrate_bps_( | 33 : min_configured_bitrate_bps_( |
31 RemoteBitrateEstimator::kDefaultMinBitrateBps), | 34 RemoteBitrateEstimator::kDefaultMinBitrateBps), |
32 max_configured_bitrate_bps_(30000000), | 35 max_configured_bitrate_bps_(30000000), |
33 current_bitrate_bps_(max_configured_bitrate_bps_), | 36 current_bitrate_bps_(max_configured_bitrate_bps_), |
34 avg_max_bitrate_kbps_(-1.0f), | 37 avg_max_bitrate_kbps_(-1.0f), |
35 var_max_bitrate_kbps_(0.4f), | 38 var_max_bitrate_kbps_(0.4f), |
36 rate_control_state_(kRcHold), | 39 rate_control_state_(kRcHold), |
37 rate_control_region_(kRcMaxUnknown), | 40 rate_control_region_(kRcMaxUnknown), |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 225 } |
223 | 226 |
224 uint32_t AimdRateControl::MultiplicativeRateIncrease( | 227 uint32_t AimdRateControl::MultiplicativeRateIncrease( |
225 int64_t now_ms, int64_t last_ms, uint32_t current_bitrate_bps) const { | 228 int64_t now_ms, int64_t last_ms, uint32_t current_bitrate_bps) const { |
226 double alpha = 1.08; | 229 double alpha = 1.08; |
227 if (last_ms > -1) { | 230 if (last_ms > -1) { |
228 int time_since_last_update_ms = std::min(static_cast<int>(now_ms - last_ms), | 231 int time_since_last_update_ms = std::min(static_cast<int>(now_ms - last_ms), |
229 1000); | 232 1000); |
230 alpha = pow(alpha, time_since_last_update_ms / 1000.0); | 233 alpha = pow(alpha, time_since_last_update_ms / 1000.0); |
231 } | 234 } |
232 uint32_t multiplicative_increase_bps = std::max( | 235 uint32_t multiplicative_increase_bps = |
233 current_bitrate_bps * (alpha - 1.0), 1000.0); | 236 std::max(current_bitrate_bps * (alpha - 1.0), kMinIncreaseBps); |
234 return multiplicative_increase_bps; | 237 return multiplicative_increase_bps; |
235 } | 238 } |
236 | 239 |
237 uint32_t AimdRateControl::AdditiveRateIncrease( | 240 uint32_t AimdRateControl::AdditiveRateIncrease( |
238 int64_t now_ms, int64_t last_ms, int64_t response_time_ms) const { | 241 int64_t now_ms, int64_t last_ms, int64_t response_time_ms) const { |
239 assert(response_time_ms > 0); | 242 assert(response_time_ms > 0); |
240 double beta = 0.0; | 243 double beta = 0.0; |
241 if (last_ms > 0) { | 244 if (last_ms > 0) { |
242 beta = std::min((now_ms - last_ms) / static_cast<double>(response_time_ms), | 245 beta = std::min((now_ms - last_ms) / static_cast<double>(response_time_ms), |
243 1.0); | 246 1.0); |
244 if (in_experiment_) | 247 if (in_experiment_) |
245 beta /= 2.0; | 248 beta /= 2.0; |
246 } | 249 } |
247 double bits_per_frame = static_cast<double>(current_bitrate_bps_) / 30.0; | 250 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)); | 251 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; | 252 double avg_packet_size_bits = bits_per_frame / packets_per_frame; |
250 uint32_t additive_increase_bps = std::max( | 253 uint32_t additive_increase_bps = |
251 1000.0, beta * avg_packet_size_bits); | 254 std::max(kMinIncreaseBps, beta * avg_packet_size_bits); |
252 return additive_increase_bps; | 255 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; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
OLD | NEW |