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/modules/remote_bitrate_estimator/overuse_detector.h" | 18 #include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h" |
18 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" | 19 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" |
19 | 20 |
20 namespace webrtc { | 21 namespace webrtc { |
21 | 22 |
22 static const int64_t kDefaultRttMs = 200; | 23 static const int64_t kDefaultRttMs = 200; |
23 static const int64_t kLogIntervalMs = 1000; | 24 static const int64_t kLogIntervalMs = 1000; |
24 static const double kWithinIncomingBitrateHysteresis = 1.05; | 25 static const double kWithinIncomingBitrateHysteresis = 1.05; |
25 static const int64_t kMaxFeedbackIntervalMs = 1000; | 26 static const int64_t kMaxFeedbackIntervalMs = 1000; |
26 | 27 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 void AimdRateControl::SetRtt(int64_t rtt) { | 96 void AimdRateControl::SetRtt(int64_t rtt) { |
96 rtt_ = rtt; | 97 rtt_ = rtt; |
97 } | 98 } |
98 | 99 |
99 void AimdRateControl::Update(const RateControlInput* input, int64_t now_ms) { | 100 void AimdRateControl::Update(const RateControlInput* input, int64_t now_ms) { |
100 assert(input); | 101 assert(input); |
101 | 102 |
102 // Set the initial bit rate value to what we're receiving the first half | 103 // Set the initial bit rate value to what we're receiving the first half |
103 // second. | 104 // second. |
104 if (!bitrate_is_initialized_) { | 105 if (!bitrate_is_initialized_) { |
| 106 const int64_t kInitializationTimeMs = 5000; |
| 107 DCHECK_LE(kBitrateWindowMs, kInitializationTimeMs); |
105 if (time_first_incoming_estimate_ < 0) { | 108 if (time_first_incoming_estimate_ < 0) { |
106 if (input->_incomingBitRate > 0) { | 109 if (input->_incomingBitRate > 0) { |
107 time_first_incoming_estimate_ = now_ms; | 110 time_first_incoming_estimate_ = now_ms; |
108 } | 111 } |
109 } else if (now_ms - time_first_incoming_estimate_ > 500 && | 112 } else if (now_ms - time_first_incoming_estimate_ > kInitializationTimeMs && |
110 input->_incomingBitRate > 0) { | 113 input->_incomingBitRate > 0) { |
111 current_bitrate_bps_ = input->_incomingBitRate; | 114 current_bitrate_bps_ = input->_incomingBitRate; |
112 bitrate_is_initialized_ = true; | 115 bitrate_is_initialized_ = true; |
113 } | 116 } |
114 } | 117 } |
115 | 118 |
116 if (updated_ && current_input_._bwState == kBwOverusing) { | 119 if (updated_ && current_input_._bwState == kBwOverusing) { |
117 // Only update delay factor and incoming bit rate. We always want to react | 120 // Only update delay factor and incoming bit rate. We always want to react |
118 // on an over-use. | 121 // on an over-use. |
119 current_input_._noiseVar = input->_noiseVar; | 122 current_input_._noiseVar = input->_noiseVar; |
120 current_input_._incomingBitRate = input->_incomingBitRate; | 123 current_input_._incomingBitRate = input->_incomingBitRate; |
121 } else { | 124 } else { |
122 updated_ = true; | 125 updated_ = true; |
123 current_input_ = *input; | 126 current_input_ = *input; |
124 } | 127 } |
125 } | 128 } |
126 | 129 |
127 void AimdRateControl::SetEstimate(int bitrate_bps, int64_t now_ms) { | 130 void AimdRateControl::SetEstimate(int bitrate_bps, int64_t now_ms) { |
128 updated_ = true; | 131 updated_ = true; |
129 bitrate_is_initialized_ = true; | 132 bitrate_is_initialized_ = true; |
130 current_bitrate_bps_ = ChangeBitrate(bitrate_bps, bitrate_bps, now_ms); | 133 current_bitrate_bps_ = ChangeBitrate(bitrate_bps, bitrate_bps, now_ms); |
131 } | 134 } |
132 | 135 |
133 uint32_t AimdRateControl::ChangeBitrate(uint32_t current_bitrate_bps, | 136 uint32_t AimdRateControl::ChangeBitrate(uint32_t current_bitrate_bps, |
134 uint32_t incoming_bitrate_bps, | 137 uint32_t incoming_bitrate_bps, |
135 int64_t now_ms) { | 138 int64_t now_ms) { |
136 if (!updated_) { | 139 if (!updated_) { |
137 return current_bitrate_bps_; | 140 return current_bitrate_bps_; |
138 } | 141 } |
| 142 // An over-use should always trigger us to reduce the bitrate, even though |
| 143 // we have not yet established our first estimate. By acting on the over-use, |
| 144 // we will end up with a valid estimate. |
| 145 if (!bitrate_is_initialized_ && current_input_._bwState != kBwOverusing) |
| 146 return current_bitrate_bps_; |
139 updated_ = false; | 147 updated_ = false; |
140 ChangeState(current_input_, now_ms); | 148 ChangeState(current_input_, now_ms); |
141 // Calculated here because it's used in multiple places. | 149 // Calculated here because it's used in multiple places. |
142 const float incoming_bitrate_kbps = incoming_bitrate_bps / 1000.0f; | 150 const float incoming_bitrate_kbps = incoming_bitrate_bps / 1000.0f; |
143 // Calculate the max bit rate std dev given the normalized | 151 // Calculate the max bit rate std dev given the normalized |
144 // variance and the current incoming bit rate. | 152 // variance and the current incoming bit rate. |
145 const float std_max_bit_rate = sqrt(var_max_bitrate_kbps_ * | 153 const float std_max_bit_rate = sqrt(var_max_bitrate_kbps_ * |
146 avg_max_bitrate_kbps_); | 154 avg_max_bitrate_kbps_); |
147 switch (rate_control_state_) { | 155 switch (rate_control_state_) { |
148 case kRcHold: | 156 case kRcHold: |
(...skipping 16 matching lines...) Expand all Loading... |
165 } else { | 173 } else { |
166 uint32_t multiplicative_increase_bps = MultiplicativeRateIncrease( | 174 uint32_t multiplicative_increase_bps = MultiplicativeRateIncrease( |
167 now_ms, time_last_bitrate_change_, current_bitrate_bps); | 175 now_ms, time_last_bitrate_change_, current_bitrate_bps); |
168 current_bitrate_bps += multiplicative_increase_bps; | 176 current_bitrate_bps += multiplicative_increase_bps; |
169 } | 177 } |
170 | 178 |
171 time_last_bitrate_change_ = now_ms; | 179 time_last_bitrate_change_ = now_ms; |
172 break; | 180 break; |
173 | 181 |
174 case kRcDecrease: | 182 case kRcDecrease: |
| 183 bitrate_is_initialized_ = true; |
175 if (incoming_bitrate_bps < min_configured_bitrate_bps_) { | 184 if (incoming_bitrate_bps < min_configured_bitrate_bps_) { |
176 current_bitrate_bps = min_configured_bitrate_bps_; | 185 current_bitrate_bps = min_configured_bitrate_bps_; |
177 } else { | 186 } else { |
178 // Set bit rate to something slightly lower than max | 187 // Set bit rate to something slightly lower than max |
179 // to get rid of any self-induced delay. | 188 // to get rid of any self-induced delay. |
180 current_bitrate_bps = static_cast<uint32_t>(beta_ * | 189 current_bitrate_bps = static_cast<uint32_t>(beta_ * |
181 incoming_bitrate_bps + 0.5); | 190 incoming_bitrate_bps + 0.5); |
182 if (current_bitrate_bps > current_bitrate_bps_) { | 191 if (current_bitrate_bps > current_bitrate_bps_) { |
183 // Avoid increasing the rate when over-using. | 192 // Avoid increasing the rate when over-using. |
184 if (rate_control_region_ != kRcMaxUnknown) { | 193 if (rate_control_region_ != kRcMaxUnknown) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 } | 302 } |
294 | 303 |
295 void AimdRateControl::ChangeRegion(RateControlRegion region) { | 304 void AimdRateControl::ChangeRegion(RateControlRegion region) { |
296 rate_control_region_ = region; | 305 rate_control_region_ = region; |
297 } | 306 } |
298 | 307 |
299 void AimdRateControl::ChangeState(RateControlState new_state) { | 308 void AimdRateControl::ChangeState(RateControlState new_state) { |
300 rate_control_state_ = new_state; | 309 rate_control_state_ = new_state; |
301 } | 310 } |
302 } // namespace webrtc | 311 } // namespace webrtc |
OLD | NEW |