Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/aimd_rate_control.cc

Issue 2789233005: Move BWE period calculation from ProbingIntervalEstimator to AimdRateControl. (Closed)
Patch Set: Remove unused include. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 constexpr double kMinIncreaseRateBps = 4000;
michaelt 2017/04/05 07:06:02 What was the reason for this change ?
terelius 2017/04/05 10:58:03 Originally wanted to make avg_packet_size into a c
michaelt 2017/04/06 11:35:13 Would be nice since then the const is defined wher
terelius 2017/04/07 11:55:04 Done. However, I don't think there is any advantag
130
129 // Approximate the over-use estimator delay to 100 ms. 131 // Approximate the over-use estimator delay to 100 ms.
130 const int64_t response_time = in_experiment_ ? (rtt_ + 100) * 2 : rtt_ + 100; 132 const int64_t response_time = in_experiment_ ? (rtt_ + 100) * 2 : rtt_ + 100;
131
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 26 matching lines...) Expand all
175 } else { 186 } else {
176 uint32_t multiplicative_increase_bps = MultiplicativeRateIncrease( 187 uint32_t multiplicative_increase_bps = MultiplicativeRateIncrease(
177 now_ms, time_last_bitrate_change_, new_bitrate_bps); 188 now_ms, time_last_bitrate_change_, new_bitrate_bps);
178 new_bitrate_bps += multiplicative_increase_bps; 189 new_bitrate_bps += multiplicative_increase_bps;
179 } 190 }
180 191
181 time_last_bitrate_change_ = now_ms; 192 time_last_bitrate_change_ = now_ms;
182 break; 193 break;
183 194
184 case kRcDecrease: 195 case kRcDecrease:
185 bitrate_is_initialized_ = true;
michaelt 2017/04/05 07:06:02 This change seams unrelated with the topic of the
terelius 2017/04/05 10:58:03 Since the unit tests now use the AimdRateControl l
michaelt 2017/04/06 11:35:13 Acknowledged.
186 // Set bit rate to something slightly lower than max 196 // Set bit rate to something slightly lower than max
187 // to get rid of any self-induced delay. 197 // to get rid of any self-induced delay.
188 new_bitrate_bps = 198 new_bitrate_bps =
189 static_cast<uint32_t>(beta_ * incoming_bitrate_bps + 0.5); 199 static_cast<uint32_t>(beta_ * incoming_bitrate_bps + 0.5);
190 if (new_bitrate_bps > current_bitrate_bps_) { 200 if (new_bitrate_bps > current_bitrate_bps_) {
191 // Avoid increasing the rate when over-using. 201 // Avoid increasing the rate when over-using.
192 if (rate_control_region_ != kRcMaxUnknown) { 202 if (rate_control_region_ != kRcMaxUnknown) {
193 new_bitrate_bps = static_cast<uint32_t>( 203 new_bitrate_bps = static_cast<uint32_t>(
194 beta_ * avg_max_bitrate_kbps_ * 1000 + 0.5f); 204 beta_ * avg_max_bitrate_kbps_ * 1000 + 0.5f);
195 } 205 }
196 new_bitrate_bps = std::min(new_bitrate_bps, current_bitrate_bps_); 206 new_bitrate_bps = std::min(new_bitrate_bps, current_bitrate_bps_);
197 } 207 }
198 ChangeRegion(kRcNearMax); 208 ChangeRegion(kRcNearMax);
199 209
200 if (incoming_bitrate_bps < current_bitrate_bps_) { 210 if (bitrate_is_initialized_ &&
211 incoming_bitrate_bps < current_bitrate_bps_) {
201 last_decrease_ = 212 last_decrease_ =
202 rtc::Optional<int>(current_bitrate_bps_ - new_bitrate_bps); 213 rtc::Optional<int>(current_bitrate_bps_ - new_bitrate_bps);
203 } 214 }
204 if (incoming_bitrate_kbps < 215 if (incoming_bitrate_kbps <
205 avg_max_bitrate_kbps_ - 3 * std_max_bit_rate) { 216 avg_max_bitrate_kbps_ - 3 * std_max_bit_rate) {
206 avg_max_bitrate_kbps_ = -1.0f; 217 avg_max_bitrate_kbps_ = -1.0f;
207 } 218 }
208 219
220 bitrate_is_initialized_ = true;
209 UpdateMaxBitRateEstimate(incoming_bitrate_kbps); 221 UpdateMaxBitRateEstimate(incoming_bitrate_kbps);
210 // Stay on hold until the pipes are cleared. 222 // Stay on hold until the pipes are cleared.
211 rate_control_state_ = kRcHold; 223 rate_control_state_ = kRcHold;
212 time_last_bitrate_change_ = now_ms; 224 time_last_bitrate_change_ = now_ms;
213 break; 225 break;
214 226
215 default: 227 default:
216 assert(false); 228 assert(false);
217 } 229 }
218 return ClampBitrate(new_bitrate_bps, incoming_bitrate_bps); 230 return ClampBitrate(new_bitrate_bps, incoming_bitrate_bps);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 default: 308 default:
297 assert(false); 309 assert(false);
298 } 310 }
299 } 311 }
300 312
301 void AimdRateControl::ChangeRegion(RateControlRegion region) { 313 void AimdRateControl::ChangeRegion(RateControlRegion region) {
302 rate_control_region_ = region; 314 rate_control_region_ = region;
303 } 315 }
304 316
305 } // namespace webrtc 317 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698