| 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 static const int64_t kDefaultRttMs = 200; |
| 26 static const int64_t kLogIntervalMs = 1000; | |
| 27 static const double kWithinIncomingBitrateHysteresis = 1.05; | 26 static const double kWithinIncomingBitrateHysteresis = 1.05; |
| 28 static const int64_t kMaxFeedbackIntervalMs = 1000; | 27 static const int64_t kMaxFeedbackIntervalMs = 1000; |
| 29 | 28 |
| 30 AimdRateControl::AimdRateControl() | 29 AimdRateControl::AimdRateControl() |
| 31 : min_configured_bitrate_bps_( | 30 : min_configured_bitrate_bps_( |
| 32 RemoteBitrateEstimator::kDefaultMinBitrateBps), | 31 RemoteBitrateEstimator::kDefaultMinBitrateBps), |
| 33 max_configured_bitrate_bps_(30000000), | 32 max_configured_bitrate_bps_(30000000), |
| 34 current_bitrate_bps_(max_configured_bitrate_bps_), | 33 current_bitrate_bps_(max_configured_bitrate_bps_), |
| 35 avg_max_bitrate_kbps_(-1.0f), | 34 avg_max_bitrate_kbps_(-1.0f), |
| 36 var_max_bitrate_kbps_(0.4f), | 35 var_max_bitrate_kbps_(0.4f), |
| 37 rate_control_state_(kRcHold), | 36 rate_control_state_(kRcHold), |
| 38 rate_control_region_(kRcMaxUnknown), | 37 rate_control_region_(kRcMaxUnknown), |
| 39 time_last_bitrate_change_(-1), | 38 time_last_bitrate_change_(-1), |
| 40 current_input_(kBwNormal, rtc::Optional<uint32_t>(), 1.0), | 39 current_input_(kBwNormal, rtc::Optional<uint32_t>(), 1.0), |
| 41 updated_(false), | 40 updated_(false), |
| 42 time_first_incoming_estimate_(-1), | 41 time_first_incoming_estimate_(-1), |
| 43 bitrate_is_initialized_(false), | 42 bitrate_is_initialized_(false), |
| 44 beta_(0.85f), | 43 beta_(0.85f), |
| 45 rtt_(kDefaultRttMs), | 44 rtt_(kDefaultRttMs), |
| 46 time_of_last_log_(-1), | |
| 47 in_experiment_(!AdaptiveThresholdExperimentIsDisabled()) {} | 45 in_experiment_(!AdaptiveThresholdExperimentIsDisabled()) {} |
| 48 | 46 |
| 49 void AimdRateControl::SetMinBitrate(int min_bitrate_bps) { | 47 void AimdRateControl::SetMinBitrate(int min_bitrate_bps) { |
| 50 min_configured_bitrate_bps_ = min_bitrate_bps; | 48 min_configured_bitrate_bps_ = min_bitrate_bps; |
| 51 current_bitrate_bps_ = std::max<int>(min_bitrate_bps, current_bitrate_bps_); | 49 current_bitrate_bps_ = std::max<int>(min_bitrate_bps, current_bitrate_bps_); |
| 52 } | 50 } |
| 53 | 51 |
| 54 bool AimdRateControl::ValidEstimate() const { | 52 bool AimdRateControl::ValidEstimate() const { |
| 55 return bitrate_is_initialized_; | 53 return bitrate_is_initialized_; |
| 56 } | 54 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 83 } | 81 } |
| 84 | 82 |
| 85 uint32_t AimdRateControl::LatestEstimate() const { | 83 uint32_t AimdRateControl::LatestEstimate() const { |
| 86 return current_bitrate_bps_; | 84 return current_bitrate_bps_; |
| 87 } | 85 } |
| 88 | 86 |
| 89 uint32_t AimdRateControl::UpdateBandwidthEstimate(int64_t now_ms) { | 87 uint32_t AimdRateControl::UpdateBandwidthEstimate(int64_t now_ms) { |
| 90 current_bitrate_bps_ = ChangeBitrate( | 88 current_bitrate_bps_ = ChangeBitrate( |
| 91 current_bitrate_bps_, | 89 current_bitrate_bps_, |
| 92 current_input_.incoming_bitrate.value_or(current_bitrate_bps_), now_ms); | 90 current_input_.incoming_bitrate.value_or(current_bitrate_bps_), now_ms); |
| 93 if (now_ms - time_of_last_log_ > kLogIntervalMs) { | |
| 94 time_of_last_log_ = now_ms; | |
| 95 } | |
| 96 return current_bitrate_bps_; | 91 return current_bitrate_bps_; |
| 97 } | 92 } |
| 98 | 93 |
| 99 void AimdRateControl::SetRtt(int64_t rtt) { | 94 void AimdRateControl::SetRtt(int64_t rtt) { |
| 100 rtt_ = rtt; | 95 rtt_ = rtt; |
| 101 } | 96 } |
| 102 | 97 |
| 103 void AimdRateControl::Update(const RateControlInput* input, int64_t now_ms) { | 98 void AimdRateControl::Update(const RateControlInput* input, int64_t now_ms) { |
| 104 RTC_CHECK(input); | 99 RTC_CHECK(input); |
| 105 | 100 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 } | 299 } |
| 305 | 300 |
| 306 void AimdRateControl::ChangeRegion(RateControlRegion region) { | 301 void AimdRateControl::ChangeRegion(RateControlRegion region) { |
| 307 rate_control_region_ = region; | 302 rate_control_region_ = region; |
| 308 } | 303 } |
| 309 | 304 |
| 310 void AimdRateControl::ChangeState(RateControlState new_state) { | 305 void AimdRateControl::ChangeState(RateControlState new_state) { |
| 311 rate_control_state_ = new_state; | 306 rate_control_state_ = new_state; |
| 312 } | 307 } |
| 313 } // namespace webrtc | 308 } // namespace webrtc |
| OLD | NEW |