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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 bitrate_is_initialized_ = true; | 119 bitrate_is_initialized_ = true; |
120 current_bitrate_bps_ = ClampBitrate(bitrate_bps, bitrate_bps); | 120 current_bitrate_bps_ = ClampBitrate(bitrate_bps, bitrate_bps); |
121 time_last_bitrate_change_ = now_ms; | 121 time_last_bitrate_change_ = now_ms; |
122 } | 122 } |
123 | 123 |
124 int AimdRateControl::GetNearMaxIncreaseRateBps() const { | 124 int AimdRateControl::GetNearMaxIncreaseRateBps() const { |
125 RTC_DCHECK_GT(current_bitrate_bps_, 0); | 125 RTC_DCHECK_GT(current_bitrate_bps_, 0); |
126 double bits_per_frame = static_cast<double>(current_bitrate_bps_) / 30.0; | 126 double bits_per_frame = static_cast<double>(current_bitrate_bps_) / 30.0; |
127 double packets_per_frame = std::ceil(bits_per_frame / (8.0 * 1200.0)); | 127 double packets_per_frame = std::ceil(bits_per_frame / (8.0 * 1200.0)); |
128 double avg_packet_size_bits = bits_per_frame / packets_per_frame; | 128 double avg_packet_size_bits = bits_per_frame / packets_per_frame; |
| 129 |
129 // Approximate the over-use estimator delay to 100 ms. | 130 // Approximate the over-use estimator delay to 100 ms. |
130 const int64_t response_time = in_experiment_ ? (rtt_ + 100) * 2 : rtt_ + 100; | 131 const int64_t response_time = in_experiment_ ? (rtt_ + 100) * 2 : rtt_ + 100; |
131 | |
132 constexpr double kMinIncreaseRateBps = 4000; | 132 constexpr double kMinIncreaseRateBps = 4000; |
133 return static_cast<int>(std::max( | 133 return static_cast<int>(std::max( |
134 kMinIncreaseRateBps, (avg_packet_size_bits * 1000) / response_time)); | 134 kMinIncreaseRateBps, (avg_packet_size_bits * 1000) / response_time)); |
135 } | 135 } |
136 | 136 |
137 rtc::Optional<int> AimdRateControl::GetLastBitrateDecreaseBps() const { | 137 int AimdRateControl::GetExpectedBandwidthPeriodMs() const { |
138 return last_decrease_; | 138 constexpr int kMinIntervalMs = 2000; |
| 139 constexpr int kDefaultIntervalMs = 3000; |
| 140 constexpr int kMaxIntervalMs = 50000; |
| 141 |
| 142 int increase_rate = GetNearMaxIncreaseRateBps(); |
| 143 if (!last_decrease_) |
| 144 return kDefaultIntervalMs; |
| 145 |
| 146 return std::min(kMaxIntervalMs, |
| 147 std::max<int>(1000 * static_cast<int64_t>(*last_decrease_) / |
| 148 increase_rate, |
| 149 kMinIntervalMs)); |
139 } | 150 } |
140 | 151 |
141 uint32_t AimdRateControl::ChangeBitrate(uint32_t new_bitrate_bps, | 152 uint32_t AimdRateControl::ChangeBitrate(uint32_t new_bitrate_bps, |
142 const RateControlInput& input, | 153 const RateControlInput& input, |
143 int64_t now_ms) { | 154 int64_t now_ms) { |
144 uint32_t incoming_bitrate_bps = | 155 uint32_t incoming_bitrate_bps = |
145 input.incoming_bitrate.value_or(current_bitrate_bps_); | 156 input.incoming_bitrate.value_or(current_bitrate_bps_); |
146 | 157 |
147 // An over-use should always trigger us to reduce the bitrate, even though | 158 // An over-use should always trigger us to reduce the bitrate, even though |
148 // we have not yet established our first estimate. By acting on the over-use, | 159 // we have not yet established our first estimate. By acting on the over-use, |
(...skipping 27 matching lines...) Expand all Loading... |
176 } else { | 187 } else { |
177 uint32_t multiplicative_increase_bps = MultiplicativeRateIncrease( | 188 uint32_t multiplicative_increase_bps = MultiplicativeRateIncrease( |
178 now_ms, time_last_bitrate_change_, new_bitrate_bps); | 189 now_ms, time_last_bitrate_change_, new_bitrate_bps); |
179 new_bitrate_bps += multiplicative_increase_bps; | 190 new_bitrate_bps += multiplicative_increase_bps; |
180 } | 191 } |
181 | 192 |
182 time_last_bitrate_change_ = now_ms; | 193 time_last_bitrate_change_ = now_ms; |
183 break; | 194 break; |
184 | 195 |
185 case kRcDecrease: | 196 case kRcDecrease: |
186 bitrate_is_initialized_ = true; | |
187 // Set bit rate to something slightly lower than max | 197 // Set bit rate to something slightly lower than max |
188 // to get rid of any self-induced delay. | 198 // to get rid of any self-induced delay. |
189 new_bitrate_bps = | 199 new_bitrate_bps = |
190 static_cast<uint32_t>(beta_ * incoming_bitrate_bps + 0.5); | 200 static_cast<uint32_t>(beta_ * incoming_bitrate_bps + 0.5); |
191 if (new_bitrate_bps > current_bitrate_bps_) { | 201 if (new_bitrate_bps > current_bitrate_bps_) { |
192 // Avoid increasing the rate when over-using. | 202 // Avoid increasing the rate when over-using. |
193 if (rate_control_region_ != kRcMaxUnknown) { | 203 if (rate_control_region_ != kRcMaxUnknown) { |
194 new_bitrate_bps = static_cast<uint32_t>( | 204 new_bitrate_bps = static_cast<uint32_t>( |
195 beta_ * avg_max_bitrate_kbps_ * 1000 + 0.5f); | 205 beta_ * avg_max_bitrate_kbps_ * 1000 + 0.5f); |
196 } | 206 } |
197 new_bitrate_bps = std::min(new_bitrate_bps, current_bitrate_bps_); | 207 new_bitrate_bps = std::min(new_bitrate_bps, current_bitrate_bps_); |
198 } | 208 } |
199 ChangeRegion(kRcNearMax); | 209 ChangeRegion(kRcNearMax); |
200 | 210 |
201 if (incoming_bitrate_bps < current_bitrate_bps_) { | 211 if (bitrate_is_initialized_ && |
| 212 incoming_bitrate_bps < current_bitrate_bps_) { |
202 last_decrease_ = | 213 last_decrease_ = |
203 rtc::Optional<int>(current_bitrate_bps_ - new_bitrate_bps); | 214 rtc::Optional<int>(current_bitrate_bps_ - new_bitrate_bps); |
204 } | 215 } |
205 if (incoming_bitrate_kbps < | 216 if (incoming_bitrate_kbps < |
206 avg_max_bitrate_kbps_ - 3 * std_max_bit_rate) { | 217 avg_max_bitrate_kbps_ - 3 * std_max_bit_rate) { |
207 avg_max_bitrate_kbps_ = -1.0f; | 218 avg_max_bitrate_kbps_ = -1.0f; |
208 } | 219 } |
209 | 220 |
| 221 bitrate_is_initialized_ = true; |
210 UpdateMaxBitRateEstimate(incoming_bitrate_kbps); | 222 UpdateMaxBitRateEstimate(incoming_bitrate_kbps); |
211 // Stay on hold until the pipes are cleared. | 223 // Stay on hold until the pipes are cleared. |
212 rate_control_state_ = kRcHold; | 224 rate_control_state_ = kRcHold; |
213 time_last_bitrate_change_ = now_ms; | 225 time_last_bitrate_change_ = now_ms; |
214 break; | 226 break; |
215 | 227 |
216 default: | 228 default: |
217 assert(false); | 229 assert(false); |
218 } | 230 } |
219 return ClampBitrate(new_bitrate_bps, incoming_bitrate_bps); | 231 return ClampBitrate(new_bitrate_bps, incoming_bitrate_bps); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 default: | 309 default: |
298 assert(false); | 310 assert(false); |
299 } | 311 } |
300 } | 312 } |
301 | 313 |
302 void AimdRateControl::ChangeRegion(RateControlRegion region) { | 314 void AimdRateControl::ChangeRegion(RateControlRegion region) { |
303 rate_control_region_ = region; | 315 rate_control_region_ = region; |
304 } | 316 } |
305 | 317 |
306 } // namespace webrtc | 318 } // namespace webrtc |
OLD | NEW |