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

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

Issue 2380883003: Add interval estimator to remote bitrate estimator (Closed)
Patch Set: Respond to comments. Created 4 years, 1 month 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 current_input_ = *input; 123 current_input_ = *input;
124 } 124 }
125 } 125 }
126 126
127 void AimdRateControl::SetEstimate(int bitrate_bps, int64_t now_ms) { 127 void AimdRateControl::SetEstimate(int bitrate_bps, int64_t now_ms) {
128 updated_ = true; 128 updated_ = true;
129 bitrate_is_initialized_ = true; 129 bitrate_is_initialized_ = true;
130 current_bitrate_bps_ = ChangeBitrate(bitrate_bps, bitrate_bps, now_ms); 130 current_bitrate_bps_ = ChangeBitrate(bitrate_bps, bitrate_bps, now_ms);
131 } 131 }
132 132
133 int AimdRateControl::GetNearMaxIncreaseRateBps() const {
134 RTC_DCHECK_GT(current_bitrate_bps_, 0);
135 double bits_per_frame = static_cast<double>(current_bitrate_bps_) / 30.0;
136 double packets_per_frame = std::ceil(bits_per_frame / (8.0 * 1200.0));
137 double avg_packet_size_bits = bits_per_frame / packets_per_frame;
138 // Approximate the over-use estimator delay to 100 ms.
139 const int64_t response_time = in_experiment_ ? (rtt_ + 100) * 2 : rtt_ + 100;
140
141 constexpr double kMinIncreaseRateBps = 4000;
142 return static_cast<int>(std::max(
143 kMinIncreaseRateBps, (avg_packet_size_bits * 1000) / response_time));
144 }
145
146 rtc::Optional<int> AimdRateControl::GetLastBitrateDecreaseBps() const {
147 return last_decrease_;
148 }
149
133 uint32_t AimdRateControl::ChangeBitrate(uint32_t current_bitrate_bps, 150 uint32_t AimdRateControl::ChangeBitrate(uint32_t current_bitrate_bps,
134 uint32_t incoming_bitrate_bps, 151 uint32_t incoming_bitrate_bps,
135 int64_t now_ms) { 152 int64_t now_ms) {
136 if (!updated_) { 153 if (!updated_) {
137 return current_bitrate_bps_; 154 return current_bitrate_bps_;
138 } 155 }
139 // An over-use should always trigger us to reduce the bitrate, even though 156 // An over-use should always trigger us to reduce the bitrate, even though
140 // we have not yet established our first estimate. By acting on the over-use, 157 // we have not yet established our first estimate. By acting on the over-use,
141 // we will end up with a valid estimate. 158 // we will end up with a valid estimate.
142 if (!bitrate_is_initialized_ && current_input_.bw_state != kBwOverusing) 159 if (!bitrate_is_initialized_ && current_input_.bw_state != kBwOverusing)
(...skipping 11 matching lines...) Expand all
154 break; 171 break;
155 172
156 case kRcIncrease: 173 case kRcIncrease:
157 if (avg_max_bitrate_kbps_ >= 0 && 174 if (avg_max_bitrate_kbps_ >= 0 &&
158 incoming_bitrate_kbps > 175 incoming_bitrate_kbps >
159 avg_max_bitrate_kbps_ + 3 * std_max_bit_rate) { 176 avg_max_bitrate_kbps_ + 3 * std_max_bit_rate) {
160 ChangeRegion(kRcMaxUnknown); 177 ChangeRegion(kRcMaxUnknown);
161 avg_max_bitrate_kbps_ = -1.0; 178 avg_max_bitrate_kbps_ = -1.0;
162 } 179 }
163 if (rate_control_region_ == kRcNearMax) { 180 if (rate_control_region_ == kRcNearMax) {
164 // Approximate the over-use estimator delay to 100 ms. 181 uint32_t additive_increase_bps =
165 const int64_t response_time = rtt_ + 100; 182 AdditiveRateIncrease(now_ms, time_last_bitrate_change_);
166 uint32_t additive_increase_bps = AdditiveRateIncrease(
167 now_ms, time_last_bitrate_change_, response_time);
168 current_bitrate_bps += additive_increase_bps; 183 current_bitrate_bps += additive_increase_bps;
169
170 } else { 184 } else {
171 uint32_t multiplicative_increase_bps = MultiplicativeRateIncrease( 185 uint32_t multiplicative_increase_bps = MultiplicativeRateIncrease(
172 now_ms, time_last_bitrate_change_, current_bitrate_bps); 186 now_ms, time_last_bitrate_change_, current_bitrate_bps);
173 current_bitrate_bps += multiplicative_increase_bps; 187 current_bitrate_bps += multiplicative_increase_bps;
174 } 188 }
175 189
176 time_last_bitrate_change_ = now_ms; 190 time_last_bitrate_change_ = now_ms;
177 break; 191 break;
178 192
179 case kRcDecrease: 193 case kRcDecrease:
180 bitrate_is_initialized_ = true; 194 bitrate_is_initialized_ = true;
181 if (incoming_bitrate_bps < min_configured_bitrate_bps_) { 195 if (incoming_bitrate_bps < min_configured_bitrate_bps_) {
182 current_bitrate_bps = min_configured_bitrate_bps_; 196 current_bitrate_bps = min_configured_bitrate_bps_;
183 } else { 197 } else {
184 // Set bit rate to something slightly lower than max 198 // Set bit rate to something slightly lower than max
185 // to get rid of any self-induced delay. 199 // to get rid of any self-induced delay.
186 current_bitrate_bps = static_cast<uint32_t>(beta_ * 200 current_bitrate_bps = static_cast<uint32_t>(beta_ *
187 incoming_bitrate_bps + 0.5); 201 incoming_bitrate_bps + 0.5);
188 if (current_bitrate_bps > current_bitrate_bps_) { 202 if (current_bitrate_bps > current_bitrate_bps_) {
189 // Avoid increasing the rate when over-using. 203 // Avoid increasing the rate when over-using.
190 if (rate_control_region_ != kRcMaxUnknown) { 204 if (rate_control_region_ != kRcMaxUnknown) {
191 current_bitrate_bps = static_cast<uint32_t>( 205 current_bitrate_bps = static_cast<uint32_t>(
192 beta_ * avg_max_bitrate_kbps_ * 1000 + 0.5f); 206 beta_ * avg_max_bitrate_kbps_ * 1000 + 0.5f);
193 } 207 }
194 current_bitrate_bps = std::min(current_bitrate_bps, 208 current_bitrate_bps = std::min(current_bitrate_bps,
195 current_bitrate_bps_); 209 current_bitrate_bps_);
196 } 210 }
197 ChangeRegion(kRcNearMax); 211 ChangeRegion(kRcNearMax);
198 212
213 if (incoming_bitrate_bps < current_bitrate_bps_) {
214 last_decrease_ =
215 rtc::Optional<int>(current_bitrate_bps_ - current_bitrate_bps);
216 }
199 if (incoming_bitrate_kbps < avg_max_bitrate_kbps_ - 217 if (incoming_bitrate_kbps < avg_max_bitrate_kbps_ -
200 3 * std_max_bit_rate) { 218 3 * std_max_bit_rate) {
201 avg_max_bitrate_kbps_ = -1.0f; 219 avg_max_bitrate_kbps_ = -1.0f;
202 } 220 }
203 221
204 UpdateMaxBitRateEstimate(incoming_bitrate_kbps); 222 UpdateMaxBitRateEstimate(incoming_bitrate_kbps);
205 } 223 }
206 // Stay on hold until the pipes are cleared. 224 // Stay on hold until the pipes are cleared.
207 ChangeState(kRcHold); 225 ChangeState(kRcHold);
208 time_last_bitrate_change_ = now_ms; 226 time_last_bitrate_change_ = now_ms;
(...skipping 18 matching lines...) Expand all
227 if (last_ms > -1) { 245 if (last_ms > -1) {
228 int time_since_last_update_ms = std::min(static_cast<int>(now_ms - last_ms), 246 int time_since_last_update_ms = std::min(static_cast<int>(now_ms - last_ms),
229 1000); 247 1000);
230 alpha = pow(alpha, time_since_last_update_ms / 1000.0); 248 alpha = pow(alpha, time_since_last_update_ms / 1000.0);
231 } 249 }
232 uint32_t multiplicative_increase_bps = std::max( 250 uint32_t multiplicative_increase_bps = std::max(
233 current_bitrate_bps * (alpha - 1.0), 1000.0); 251 current_bitrate_bps * (alpha - 1.0), 1000.0);
234 return multiplicative_increase_bps; 252 return multiplicative_increase_bps;
235 } 253 }
236 254
237 uint32_t AimdRateControl::AdditiveRateIncrease( 255 uint32_t AimdRateControl::AdditiveRateIncrease(int64_t now_ms,
238 int64_t now_ms, int64_t last_ms, int64_t response_time_ms) const { 256 int64_t last_ms) const {
239 assert(response_time_ms > 0); 257 return (now_ms - last_ms) * GetNearMaxIncreaseRateBps() / 1000;
minyue-webrtc 2016/11/15 12:20:36 there is some cast too. and should we return uint3
michaelt 2016/11/15 13:08:15 Did a explicit cast to unit32_t => we may could sw
minyue-webrtc 2016/11/16 08:54:03 Acknowledged.
240 double beta = 0.0;
241 if (last_ms > 0) {
242 beta = std::min((now_ms - last_ms) / static_cast<double>(response_time_ms),
243 1.0);
244 if (in_experiment_)
245 beta /= 2.0;
246 }
247 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));
249 double avg_packet_size_bits = bits_per_frame / packets_per_frame;
250 uint32_t additive_increase_bps = std::max(
251 1000.0, beta * avg_packet_size_bits);
252 return additive_increase_bps;
253 } 258 }
254 259
255 void AimdRateControl::UpdateMaxBitRateEstimate(float incoming_bitrate_kbps) { 260 void AimdRateControl::UpdateMaxBitRateEstimate(float incoming_bitrate_kbps) {
256 const float alpha = 0.05f; 261 const float alpha = 0.05f;
257 if (avg_max_bitrate_kbps_ == -1.0f) { 262 if (avg_max_bitrate_kbps_ == -1.0f) {
258 avg_max_bitrate_kbps_ = incoming_bitrate_kbps; 263 avg_max_bitrate_kbps_ = incoming_bitrate_kbps;
259 } else { 264 } else {
260 avg_max_bitrate_kbps_ = (1 - alpha) * avg_max_bitrate_kbps_ + 265 avg_max_bitrate_kbps_ = (1 - alpha) * avg_max_bitrate_kbps_ +
261 alpha * incoming_bitrate_kbps; 266 alpha * incoming_bitrate_kbps;
262 } 267 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 304 }
300 305
301 void AimdRateControl::ChangeRegion(RateControlRegion region) { 306 void AimdRateControl::ChangeRegion(RateControlRegion region) {
302 rate_control_region_ = region; 307 rate_control_region_ = region;
303 } 308 }
304 309
305 void AimdRateControl::ChangeState(RateControlState new_state) { 310 void AimdRateControl::ChangeState(RateControlState new_state) {
306 rate_control_state_ = new_state; 311 rate_control_state_ = new_state;
307 } 312 }
308 } // namespace webrtc 313 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698