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

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: Simplify probing estimator. 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 rtc::Optional<int> AimdRateControl::GetNearMaxIncreaseRate() const {
134 return near_max_increase_rate_bps_;
135 }
136
137 rtc::Optional<int> AimdRateControl::GetLastDecrease() const {
138 return last_decrease_;
139 }
140
133 uint32_t AimdRateControl::ChangeBitrate(uint32_t current_bitrate_bps, 141 uint32_t AimdRateControl::ChangeBitrate(uint32_t current_bitrate_bps,
134 uint32_t incoming_bitrate_bps, 142 uint32_t incoming_bitrate_bps,
135 int64_t now_ms) { 143 int64_t now_ms) {
136 if (!updated_) { 144 if (!updated_) {
137 return current_bitrate_bps_; 145 return current_bitrate_bps_;
138 } 146 }
139 // An over-use should always trigger us to reduce the bitrate, even though 147 // 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, 148 // we have not yet established our first estimate. By acting on the over-use,
141 // we will end up with a valid estimate. 149 // we will end up with a valid estimate.
142 if (!bitrate_is_initialized_ && current_input_.bw_state != kBwOverusing) 150 if (!bitrate_is_initialized_ && current_input_.bw_state != kBwOverusing)
(...skipping 15 matching lines...) Expand all
158 incoming_bitrate_kbps > 166 incoming_bitrate_kbps >
159 avg_max_bitrate_kbps_ + 3 * std_max_bit_rate) { 167 avg_max_bitrate_kbps_ + 3 * std_max_bit_rate) {
160 ChangeRegion(kRcMaxUnknown); 168 ChangeRegion(kRcMaxUnknown);
161 avg_max_bitrate_kbps_ = -1.0; 169 avg_max_bitrate_kbps_ = -1.0;
162 } 170 }
163 if (rate_control_region_ == kRcNearMax) { 171 if (rate_control_region_ == kRcNearMax) {
164 // Approximate the over-use estimator delay to 100 ms. 172 // Approximate the over-use estimator delay to 100 ms.
165 const int64_t response_time = rtt_ + 100; 173 const int64_t response_time = rtt_ + 100;
166 uint32_t additive_increase_bps = AdditiveRateIncrease( 174 uint32_t additive_increase_bps = AdditiveRateIncrease(
167 now_ms, time_last_bitrate_change_, response_time); 175 now_ms, time_last_bitrate_change_, response_time);
176 if (last_near_max_increase_rate_update_) {
177 near_max_increase_rate_bps_ = rtc::Optional<int>(
178 additive_increase_bps * 1000.0 /
179 (now_ms - *last_near_max_increase_rate_update_));
stefan-webrtc 2016/10/26 14:30:06 An alternative to this would be to do something li
michaelt 2016/10/31 11:10:22 I taught a little what would be the best solution.
180 }
168 current_bitrate_bps += additive_increase_bps; 181 current_bitrate_bps += additive_increase_bps;
169 182 last_near_max_increase_rate_update_ = rtc::Optional<int64_t>(now_ms);
170 } else { 183 } else {
184 last_near_max_increase_rate_update_ = rtc::Optional<int64_t>();
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:
194 last_near_max_increase_rate_update_ = rtc::Optional<int64_t>();
180 bitrate_is_initialized_ = true; 195 bitrate_is_initialized_ = true;
181 if (incoming_bitrate_bps < min_configured_bitrate_bps_) { 196 if (incoming_bitrate_bps < min_configured_bitrate_bps_) {
182 current_bitrate_bps = min_configured_bitrate_bps_; 197 current_bitrate_bps = min_configured_bitrate_bps_;
183 } else { 198 } else {
184 // Set bit rate to something slightly lower than max 199 // Set bit rate to something slightly lower than max
185 // to get rid of any self-induced delay. 200 // to get rid of any self-induced delay.
186 current_bitrate_bps = static_cast<uint32_t>(beta_ * 201 current_bitrate_bps = static_cast<uint32_t>(beta_ *
187 incoming_bitrate_bps + 0.5); 202 incoming_bitrate_bps + 0.5);
188 if (current_bitrate_bps > current_bitrate_bps_) { 203 if (current_bitrate_bps > current_bitrate_bps_) {
189 // Avoid increasing the rate when over-using. 204 // Avoid increasing the rate when over-using.
190 if (rate_control_region_ != kRcMaxUnknown) { 205 if (rate_control_region_ != kRcMaxUnknown) {
191 current_bitrate_bps = static_cast<uint32_t>( 206 current_bitrate_bps = static_cast<uint32_t>(
192 beta_ * avg_max_bitrate_kbps_ * 1000 + 0.5f); 207 beta_ * avg_max_bitrate_kbps_ * 1000 + 0.5f);
193 } 208 }
194 current_bitrate_bps = std::min(current_bitrate_bps, 209 current_bitrate_bps = std::min(current_bitrate_bps,
195 current_bitrate_bps_); 210 current_bitrate_bps_);
196 } 211 }
197 ChangeRegion(kRcNearMax); 212 ChangeRegion(kRcNearMax);
198 213
214 if (incoming_bitrate_bps < current_bitrate_bps_)
215 last_decrease_ =
216 rtc::Optional<int>(current_bitrate_bps_ - current_bitrate_bps);
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 double beta = 0.0; 258 double beta = 0.0;
241 if (last_ms > 0) { 259 if (last_ms > 0) {
242 beta = std::min((now_ms - last_ms) / static_cast<double>(response_time_ms), 260 beta = std::min((now_ms - last_ms) / static_cast<double>(response_time_ms),
243 1.0); 261 1.0);
244 if (in_experiment_) 262 if (in_experiment_)
245 beta /= 2.0; 263 beta /= 2.0;
246 } 264 }
247 double bits_per_frame = static_cast<double>(current_bitrate_bps_) / 30.0; 265 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)); 266 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; 267 double avg_packet_size_bits = bits_per_frame / packets_per_frame;
250 uint32_t additive_increase_bps = std::max( 268 uint32_t additive_increase_bps = std::max(
stefan-webrtc 2016/10/26 14:30:06 If we compute near_max_increase_rate_bps_ here ins
michaelt 2016/10/31 11:10:22 Without the max function it would be: near_max_in
251 1000.0, beta * avg_packet_size_bits); 269 1000.0, beta * avg_packet_size_bits);
252 return additive_increase_bps; 270 return additive_increase_bps;
253 } 271 }
254 272
255 void AimdRateControl::UpdateMaxBitRateEstimate(float incoming_bitrate_kbps) { 273 void AimdRateControl::UpdateMaxBitRateEstimate(float incoming_bitrate_kbps) {
256 const float alpha = 0.05f; 274 const float alpha = 0.05f;
257 if (avg_max_bitrate_kbps_ == -1.0f) { 275 if (avg_max_bitrate_kbps_ == -1.0f) {
258 avg_max_bitrate_kbps_ = incoming_bitrate_kbps; 276 avg_max_bitrate_kbps_ = incoming_bitrate_kbps;
259 } else { 277 } else {
260 avg_max_bitrate_kbps_ = (1 - alpha) * avg_max_bitrate_kbps_ + 278 avg_max_bitrate_kbps_ = (1 - alpha) * avg_max_bitrate_kbps_ +
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 317 }
300 318
301 void AimdRateControl::ChangeRegion(RateControlRegion region) { 319 void AimdRateControl::ChangeRegion(RateControlRegion region) {
302 rate_control_region_ = region; 320 rate_control_region_ = region;
303 } 321 }
304 322
305 void AimdRateControl::ChangeState(RateControlState new_state) { 323 void AimdRateControl::ChangeState(RateControlState new_state) {
306 rate_control_state_ = new_state; 324 rate_control_state_ = new_state;
307 } 325 }
308 } // namespace webrtc 326 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698