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

Side by Side Diff: webrtc/modules/congestion_controller/congestion_controller.cc

Issue 2235373004: Probing: Add support for exponential startup probing (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@fix_probing2
Patch Set: Refactored probe_controller Created 4 years, 3 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) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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/congestion_controller/include/congestion_controller.h" 11 #include "webrtc/modules/congestion_controller/include/congestion_controller.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <memory> 14 #include <memory>
15 #include <vector> 15 #include <vector>
16 16
17 #include "webrtc/base/checks.h" 17 #include "webrtc/base/checks.h"
18 #include "webrtc/base/constructormagic.h" 18 #include "webrtc/base/constructormagic.h"
19 #include "webrtc/base/logging.h" 19 #include "webrtc/base/logging.h"
20 #include "webrtc/base/rate_limiter.h" 20 #include "webrtc/base/rate_limiter.h"
21 #include "webrtc/base/socket.h" 21 #include "webrtc/base/socket.h"
22 #include "webrtc/base/thread_annotations.h" 22 #include "webrtc/base/thread_annotations.h"
23 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" 23 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
24 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" 24 #include "webrtc/modules/congestion_controller/delay_based_bwe.h"
25 #include "webrtc/modules/congestion_controller/probe_controller.h"
25 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h" 26 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h"
26 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h" 27 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h"
27 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h" 28 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h"
28 #include "webrtc/modules/utility/include/process_thread.h" 29 #include "webrtc/modules/utility/include/process_thread.h"
29 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 30 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
30 #include "webrtc/video/payload_router.h" 31 #include "webrtc/video/payload_router.h"
31 32
32 namespace webrtc { 33 namespace webrtc {
33 namespace { 34 namespace {
34 35
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 RemoteBitrateObserver* remote_bitrate_observer, 160 RemoteBitrateObserver* remote_bitrate_observer,
160 RtcEventLog* event_log) 161 RtcEventLog* event_log)
161 : clock_(clock), 162 : clock_(clock),
162 observer_(observer), 163 observer_(observer),
163 packet_router_(new PacketRouter()), 164 packet_router_(new PacketRouter()),
164 pacer_(new PacedSender(clock_, packet_router_.get())), 165 pacer_(new PacedSender(clock_, packet_router_.get())),
165 remote_bitrate_estimator_( 166 remote_bitrate_estimator_(
166 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), 167 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
167 bitrate_controller_( 168 bitrate_controller_(
168 BitrateController::CreateBitrateController(clock_, event_log)), 169 BitrateController::CreateBitrateController(clock_, event_log)),
170 probe_controller_(new ProbeController(pacer_.get(), clock_)),
169 retransmission_rate_limiter_( 171 retransmission_rate_limiter_(
170 new RateLimiter(clock, kRetransmitWindowSizeMs)), 172 new RateLimiter(clock, kRetransmitWindowSizeMs)),
171 remote_estimator_proxy_(clock_, packet_router_.get()), 173 remote_estimator_proxy_(clock_, packet_router_.get()),
172 transport_feedback_adapter_(bitrate_controller_.get(), clock_), 174 transport_feedback_adapter_(clock_),
173 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), 175 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
174 max_bitrate_bps_(0), 176 max_bitrate_bps_(0),
175 initial_probing_triggered_(false),
176 last_reported_bitrate_bps_(0), 177 last_reported_bitrate_bps_(0),
177 last_reported_fraction_loss_(0), 178 last_reported_fraction_loss_(0),
178 last_reported_rtt_(0), 179 last_reported_rtt_(0),
179 network_state_(kNetworkUp) { 180 network_state_(kNetworkUp) {
180 Init(); 181 Init();
181 } 182 }
182 183
183 CongestionController::CongestionController( 184 CongestionController::CongestionController(
184 Clock* clock, 185 Clock* clock,
185 Observer* observer, 186 Observer* observer,
186 RemoteBitrateObserver* remote_bitrate_observer, 187 RemoteBitrateObserver* remote_bitrate_observer,
187 RtcEventLog* event_log, 188 RtcEventLog* event_log,
188 std::unique_ptr<PacketRouter> packet_router, 189 std::unique_ptr<PacketRouter> packet_router,
189 std::unique_ptr<PacedSender> pacer) 190 std::unique_ptr<PacedSender> pacer)
190 : clock_(clock), 191 : clock_(clock),
191 observer_(observer), 192 observer_(observer),
192 packet_router_(std::move(packet_router)), 193 packet_router_(std::move(packet_router)),
193 pacer_(std::move(pacer)), 194 pacer_(std::move(pacer)),
194 remote_bitrate_estimator_( 195 remote_bitrate_estimator_(
195 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), 196 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
196 // Constructed last as this object calls the provided callback on 197 // Constructed last as this object calls the provided callback on
197 // construction. 198 // construction.
198 bitrate_controller_( 199 bitrate_controller_(
199 BitrateController::CreateBitrateController(clock_, event_log)), 200 BitrateController::CreateBitrateController(clock_, event_log)),
201 probe_controller_(new ProbeController(pacer_.get(), clock_)),
200 retransmission_rate_limiter_( 202 retransmission_rate_limiter_(
201 new RateLimiter(clock, kRetransmitWindowSizeMs)), 203 new RateLimiter(clock, kRetransmitWindowSizeMs)),
202 remote_estimator_proxy_(clock_, packet_router_.get()), 204 remote_estimator_proxy_(clock_, packet_router_.get()),
203 transport_feedback_adapter_(bitrate_controller_.get(), clock_), 205 transport_feedback_adapter_(clock_),
204 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), 206 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
205 max_bitrate_bps_(0), 207 max_bitrate_bps_(0),
206 initial_probing_triggered_(false),
207 last_reported_bitrate_bps_(0), 208 last_reported_bitrate_bps_(0),
208 last_reported_fraction_loss_(0), 209 last_reported_fraction_loss_(0),
209 last_reported_rtt_(0), 210 last_reported_rtt_(0),
210 network_state_(kNetworkUp) { 211 network_state_(kNetworkUp) {
211 Init(); 212 Init();
212 } 213 }
213 214
214 CongestionController::~CongestionController() {} 215 CongestionController::~CongestionController() {}
215 216
216 void CongestionController::Init() { 217 void CongestionController::Init() {
217 transport_feedback_adapter_.SetBitrateEstimator( 218 transport_feedback_adapter_.SetBitrateEstimator(
218 new DelayBasedBwe(&transport_feedback_adapter_, clock_)); 219 new DelayBasedBwe(this, clock_));
219 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate( 220 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate(
220 min_bitrate_bps_); 221 min_bitrate_bps_);
221 } 222 }
222 223
223 void CongestionController::SetBweBitrates(int min_bitrate_bps, 224 void CongestionController::SetBweBitrates(int min_bitrate_bps,
224 int start_bitrate_bps, 225 int start_bitrate_bps,
225 int max_bitrate_bps) { 226 int max_bitrate_bps) {
226 ClampBitrates(&start_bitrate_bps, &min_bitrate_bps, &max_bitrate_bps); 227 ClampBitrates(&start_bitrate_bps, &min_bitrate_bps, &max_bitrate_bps);
227 bitrate_controller_->SetBitrates(start_bitrate_bps, 228 bitrate_controller_->SetBitrates(start_bitrate_bps,
228 min_bitrate_bps, 229 min_bitrate_bps,
229 max_bitrate_bps); 230 max_bitrate_bps);
230 231
231 { 232 probe_controller_->SetBitrates(min_bitrate_bps, start_bitrate_bps,
232 rtc::CritScope cs(&critsect_); 233 max_bitrate_bps);
233 if (!initial_probing_triggered_) {
234 pacer_->CreateProbeCluster(start_bitrate_bps * 3, 6);
235 pacer_->CreateProbeCluster(start_bitrate_bps * 6, 5);
236 initial_probing_triggered_ = true;
237 }
238
239 // Only do probing if:
240 // - we are mid-call, which we consider to be if
241 // |last_reported_bitrate_bps_| != 0, and
242 // - the current bitrate is lower than the new |max_bitrate_bps|, and
243 // - we actually want to increase the |max_bitrate_bps_|.
244 if (last_reported_bitrate_bps_ != 0 &&
245 last_reported_bitrate_bps_ < static_cast<uint32_t>(max_bitrate_bps) &&
246 max_bitrate_bps > max_bitrate_bps_) {
247 pacer_->CreateProbeCluster(max_bitrate_bps, 5);
248 }
249 }
250 max_bitrate_bps_ = max_bitrate_bps; 234 max_bitrate_bps_ = max_bitrate_bps;
251 235
252 if (remote_bitrate_estimator_) 236 if (remote_bitrate_estimator_)
253 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); 237 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps);
254 min_bitrate_bps_ = min_bitrate_bps; 238 min_bitrate_bps_ = min_bitrate_bps;
255 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate( 239 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate(
256 min_bitrate_bps_); 240 min_bitrate_bps_);
257 MaybeTriggerOnNetworkChanged(); 241 MaybeTriggerOnNetworkChanged();
258 } 242 }
259 243
260 void CongestionController::ResetBweAndBitrates(int bitrate_bps, 244 void CongestionController::ResetBweAndBitrates(int bitrate_bps,
261 int min_bitrate_bps, 245 int min_bitrate_bps,
262 int max_bitrate_bps) { 246 int max_bitrate_bps) {
263 ClampBitrates(&bitrate_bps, &min_bitrate_bps, &max_bitrate_bps); 247 ClampBitrates(&bitrate_bps, &min_bitrate_bps, &max_bitrate_bps);
264 // TODO(honghaiz): Recreate this object once the bitrate controller is 248 // TODO(honghaiz): Recreate this object once the bitrate controller is
265 // no longer exposed outside CongestionController. 249 // no longer exposed outside CongestionController.
266 bitrate_controller_->ResetBitrates(bitrate_bps, min_bitrate_bps, 250 bitrate_controller_->ResetBitrates(bitrate_bps, min_bitrate_bps,
267 max_bitrate_bps); 251 max_bitrate_bps);
268 min_bitrate_bps_ = min_bitrate_bps; 252 min_bitrate_bps_ = min_bitrate_bps;
269 max_bitrate_bps_ = max_bitrate_bps; 253 max_bitrate_bps_ = max_bitrate_bps;
270 // TODO(honghaiz): Recreate this object once the remote bitrate estimator is 254 // TODO(honghaiz): Recreate this object once the remote bitrate estimator is
271 // no longer exposed outside CongestionController. 255 // no longer exposed outside CongestionController.
272 if (remote_bitrate_estimator_) 256 if (remote_bitrate_estimator_)
273 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); 257 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps);
274 258
275 RemoteBitrateEstimator* rbe = new DelayBasedBwe( 259 RemoteBitrateEstimator* rbe = new DelayBasedBwe(this, clock_);
276 &transport_feedback_adapter_, clock_);
277 transport_feedback_adapter_.SetBitrateEstimator(rbe); 260 transport_feedback_adapter_.SetBitrateEstimator(rbe);
278 rbe->SetMinBitrate(min_bitrate_bps); 261 rbe->SetMinBitrate(min_bitrate_bps);
279 // TODO(holmer): Trigger a new probe once mid-call probing is implemented. 262 // TODO(holmer): Trigger a new probe once mid-call probing is implemented.
280 MaybeTriggerOnNetworkChanged(); 263 MaybeTriggerOnNetworkChanged();
281 } 264 }
282 265
283 BitrateController* CongestionController::GetBitrateController() const { 266 BitrateController* CongestionController::GetBitrateController() const {
284 return bitrate_controller_.get(); 267 return bitrate_controller_.get();
285 } 268 }
286 269
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 network_state_ = state; 308 network_state_ = state;
326 } 309 }
327 MaybeTriggerOnNetworkChanged(); 310 MaybeTriggerOnNetworkChanged();
328 } 311 }
329 312
330 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) { 313 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) {
331 transport_feedback_adapter_.OnSentPacket(sent_packet.packet_id, 314 transport_feedback_adapter_.OnSentPacket(sent_packet.packet_id,
332 sent_packet.send_time_ms); 315 sent_packet.send_time_ms);
333 } 316 }
334 317
318 void CongestionController::OnDelayBasedBweChanged(int bitrate_bps) {
philipel 2016/09/08 12:52:46 Where can I find the changes to the .h file?
Irfan 2016/09/09 08:12:52 The .h file is part of this patchset, its in inclu
philipel 2016/09/09 08:59:08 Oops
319 bitrate_controller_->UpdateDelayBasedEstimate(bitrate_bps);
320 }
321
322 void CongestionController::OnProbeBitrate(int bitrate_bps) {
323 bitrate_controller_->UpdateProbeBitrate(bitrate_bps);
324 }
325
335 void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { 326 void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) {
336 remote_bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); 327 remote_bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms);
337 transport_feedback_adapter_.OnRttUpdate(avg_rtt_ms, max_rtt_ms); 328 transport_feedback_adapter_.OnRttUpdate(avg_rtt_ms, max_rtt_ms);
338 } 329 }
339 330
340 int64_t CongestionController::TimeUntilNextProcess() { 331 int64_t CongestionController::TimeUntilNextProcess() {
341 return std::min(bitrate_controller_->TimeUntilNextProcess(), 332 return std::min(bitrate_controller_->TimeUntilNextProcess(),
342 remote_bitrate_estimator_->TimeUntilNextProcess()); 333 remote_bitrate_estimator_->TimeUntilNextProcess());
343 } 334 }
344 335
345 void CongestionController::Process() { 336 void CongestionController::Process() {
346 bitrate_controller_->Process(); 337 bitrate_controller_->Process();
347 remote_bitrate_estimator_->Process(); 338 remote_bitrate_estimator_->Process();
339 probe_controller_->Process();
348 MaybeTriggerOnNetworkChanged(); 340 MaybeTriggerOnNetworkChanged();
349 } 341 }
350 342
351 void CongestionController::MaybeTriggerOnNetworkChanged() { 343 void CongestionController::MaybeTriggerOnNetworkChanged() {
352 // TODO(perkj): |observer_| can be nullptr if the ctor that accepts a 344 // TODO(perkj): |observer_| can be nullptr if the ctor that accepts a
353 // BitrateObserver is used. Remove this check once the ctor is removed. 345 // BitrateObserver is used. Remove this check once the ctor is removed.
354 if (!observer_) 346 if (!observer_)
355 return; 347 return;
356 348
357 uint32_t bitrate_bps; 349 uint32_t bitrate_bps;
358 uint8_t fraction_loss; 350 uint8_t fraction_loss;
359 int64_t rtt; 351 int64_t rtt;
360 bool estimate_changed = bitrate_controller_->GetNetworkParameters( 352 bool estimate_changed = bitrate_controller_->GetNetworkParameters(
361 &bitrate_bps, &fraction_loss, &rtt); 353 &bitrate_bps, &fraction_loss, &rtt);
362 if (estimate_changed) { 354 if (estimate_changed) {
363 pacer_->SetEstimatedBitrate(bitrate_bps); 355 pacer_->SetEstimatedBitrate(bitrate_bps);
356 probe_controller_->SetEstimatedBitrate(bitrate_bps);
364 retransmission_rate_limiter_->SetMaxRate(bitrate_bps); 357 retransmission_rate_limiter_->SetMaxRate(bitrate_bps);
365 } 358 }
366 359
367 bitrate_bps = IsNetworkDown() || IsSendQueueFull() ? 0 : bitrate_bps; 360 bitrate_bps = IsNetworkDown() || IsSendQueueFull() ? 0 : bitrate_bps;
368 361
369 if (HasNetworkParametersToReportChanged(bitrate_bps, fraction_loss, rtt)) { 362 if (HasNetworkParametersToReportChanged(bitrate_bps, fraction_loss, rtt)) {
370 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt); 363 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt);
371 } 364 }
372 } 365 }
373 366
(...skipping 19 matching lines...) Expand all
393 bool CongestionController::IsSendQueueFull() const { 386 bool CongestionController::IsSendQueueFull() const {
394 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; 387 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs;
395 } 388 }
396 389
397 bool CongestionController::IsNetworkDown() const { 390 bool CongestionController::IsNetworkDown() const {
398 rtc::CritScope cs(&critsect_); 391 rtc::CritScope cs(&critsect_);
399 return network_state_ == kNetworkDown; 392 return network_state_ == kNetworkDown;
400 } 393 }
401 394
402 } // namespace webrtc 395 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698