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

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

Issue 3004783002: Push back on the video encoder to avoid building queues in the pacer. (Closed)
Patch Set: feedback Created 3 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
« no previous file with comments | « webrtc/modules/congestion_controller/include/send_side_congestion_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 14 matching lines...) Expand all
25 #include "webrtc/rtc_base/ptr_util.h" 25 #include "webrtc/rtc_base/ptr_util.h"
26 #include "webrtc/rtc_base/rate_limiter.h" 26 #include "webrtc/rtc_base/rate_limiter.h"
27 #include "webrtc/rtc_base/socket.h" 27 #include "webrtc/rtc_base/socket.h"
28 #include "webrtc/rtc_base/timeutils.h" 28 #include "webrtc/rtc_base/timeutils.h"
29 #include "webrtc/system_wrappers/include/field_trial.h" 29 #include "webrtc/system_wrappers/include/field_trial.h"
30 30
31 namespace webrtc { 31 namespace webrtc {
32 namespace { 32 namespace {
33 33
34 const char kCwndExperiment[] = "WebRTC-CwndExperiment"; 34 const char kCwndExperiment[] = "WebRTC-CwndExperiment";
35 const char kPacerPushbackExperiment[] = "WebRTC-PacerPushbackExperiment";
35 const int64_t kDefaultAcceptedQueueMs = 250; 36 const int64_t kDefaultAcceptedQueueMs = 250;
36 37
37 bool CwndExperimentEnabled() { 38 bool CwndExperimentEnabled() {
38 std::string experiment_string = 39 std::string experiment_string =
39 webrtc::field_trial::FindFullName(kCwndExperiment); 40 webrtc::field_trial::FindFullName(kCwndExperiment);
40 // The experiment is enabled iff the field trial string begins with "Enabled". 41 // The experiment is enabled iff the field trial string begins with "Enabled".
41 return experiment_string.find("Enabled") == 0; 42 return experiment_string.find("Enabled") == 0;
42 } 43 }
43 44
45 bool PacerPushbackExperimentEnabled() {
46 return webrtc::field_trial::IsEnabled(kPacerPushbackExperiment);
stefan-webrtc 2017/09/01 09:01:08 Might as well call this function directly below.
philipel 2017/09/01 11:46:19 Done.
47 }
48
44 bool ReadCwndExperimentParameter(int64_t* accepted_queue_ms) { 49 bool ReadCwndExperimentParameter(int64_t* accepted_queue_ms) {
45 RTC_DCHECK(accepted_queue_ms); 50 RTC_DCHECK(accepted_queue_ms);
46 std::string experiment_string = 51 std::string experiment_string =
47 webrtc::field_trial::FindFullName(kCwndExperiment); 52 webrtc::field_trial::FindFullName(kCwndExperiment);
48 int parsed_values = 53 int parsed_values =
49 sscanf(experiment_string.c_str(), "Enabled-%" PRId64, accepted_queue_ms); 54 sscanf(experiment_string.c_str(), "Enabled-%" PRId64, accepted_queue_ms);
50 if (parsed_values == 1) { 55 if (parsed_values == 1) {
51 RTC_CHECK_GE(*accepted_queue_ms, 0) 56 RTC_CHECK_GE(*accepted_queue_ms, 0)
52 << "Accepted must be greater than or equal to 0."; 57 << "Accepted must be greater than or equal to 0.";
53 return true; 58 return true;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 last_reported_bitrate_bps_(0), 120 last_reported_bitrate_bps_(0),
116 last_reported_fraction_loss_(0), 121 last_reported_fraction_loss_(0),
117 last_reported_rtt_(0), 122 last_reported_rtt_(0),
118 network_state_(kNetworkUp), 123 network_state_(kNetworkUp),
119 pause_pacer_(false), 124 pause_pacer_(false),
120 pacer_paused_(false), 125 pacer_paused_(false),
121 min_bitrate_bps_(congestion_controller::GetMinBitrateBps()), 126 min_bitrate_bps_(congestion_controller::GetMinBitrateBps()),
122 delay_based_bwe_(new DelayBasedBwe(event_log_, clock_)), 127 delay_based_bwe_(new DelayBasedBwe(event_log_, clock_)),
123 in_cwnd_experiment_(CwndExperimentEnabled()), 128 in_cwnd_experiment_(CwndExperimentEnabled()),
124 accepted_queue_ms_(kDefaultAcceptedQueueMs), 129 accepted_queue_ms_(kDefaultAcceptedQueueMs),
125 was_in_alr_(0) { 130 was_in_alr_(false),
131 pacer_pushback_experiment_(PacerPushbackExperimentEnabled()) {
126 delay_based_bwe_->SetMinBitrate(min_bitrate_bps_); 132 delay_based_bwe_->SetMinBitrate(min_bitrate_bps_);
127 if (in_cwnd_experiment_ && 133 if (in_cwnd_experiment_ &&
128 !ReadCwndExperimentParameter(&accepted_queue_ms_)) { 134 !ReadCwndExperimentParameter(&accepted_queue_ms_)) {
129 LOG(LS_WARNING) << "Failed to parse parameters for CwndExperiment " 135 LOG(LS_WARNING) << "Failed to parse parameters for CwndExperiment "
130 "from field trial string. Experiment disabled."; 136 "from field trial string. Experiment disabled.";
131 in_cwnd_experiment_ = false; 137 in_cwnd_experiment_ = false;
132 } 138 }
133 } 139 }
134 140
135 SendSideCongestionController::SendSideCongestionController( 141 SendSideCongestionController::SendSideCongestionController(
(...skipping 16 matching lines...) Expand all
152 last_reported_bitrate_bps_(0), 158 last_reported_bitrate_bps_(0),
153 last_reported_fraction_loss_(0), 159 last_reported_fraction_loss_(0),
154 last_reported_rtt_(0), 160 last_reported_rtt_(0),
155 network_state_(kNetworkUp), 161 network_state_(kNetworkUp),
156 pause_pacer_(false), 162 pause_pacer_(false),
157 pacer_paused_(false), 163 pacer_paused_(false),
158 min_bitrate_bps_(congestion_controller::GetMinBitrateBps()), 164 min_bitrate_bps_(congestion_controller::GetMinBitrateBps()),
159 delay_based_bwe_(new DelayBasedBwe(event_log_, clock_)), 165 delay_based_bwe_(new DelayBasedBwe(event_log_, clock_)),
160 in_cwnd_experiment_(CwndExperimentEnabled()), 166 in_cwnd_experiment_(CwndExperimentEnabled()),
161 accepted_queue_ms_(kDefaultAcceptedQueueMs), 167 accepted_queue_ms_(kDefaultAcceptedQueueMs),
162 was_in_alr_(0) { 168 was_in_alr_(false),
169 pacer_pushback_experiment_(PacerPushbackExperimentEnabled()) {
163 delay_based_bwe_->SetMinBitrate(min_bitrate_bps_); 170 delay_based_bwe_->SetMinBitrate(min_bitrate_bps_);
164 if (in_cwnd_experiment_ && 171 if (in_cwnd_experiment_ &&
165 !ReadCwndExperimentParameter(&accepted_queue_ms_)) { 172 !ReadCwndExperimentParameter(&accepted_queue_ms_)) {
166 LOG(LS_WARNING) << "Failed to parse parameters for CwndExperiment " 173 LOG(LS_WARNING) << "Failed to parse parameters for CwndExperiment "
167 "from field trial string. Experiment disabled."; 174 "from field trial string. Experiment disabled.";
168 in_cwnd_experiment_ = false; 175 in_cwnd_experiment_ = false;
169 } 176 }
170 } 177 }
171 178
172 SendSideCongestionController::~SendSideCongestionController() {} 179 SendSideCongestionController::~SendSideCongestionController() {}
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 uint8_t fraction_loss; 416 uint8_t fraction_loss;
410 int64_t rtt; 417 int64_t rtt;
411 bool estimate_changed = bitrate_controller_->GetNetworkParameters( 418 bool estimate_changed = bitrate_controller_->GetNetworkParameters(
412 &bitrate_bps, &fraction_loss, &rtt); 419 &bitrate_bps, &fraction_loss, &rtt);
413 if (estimate_changed) { 420 if (estimate_changed) {
414 pacer_->SetEstimatedBitrate(bitrate_bps); 421 pacer_->SetEstimatedBitrate(bitrate_bps);
415 probe_controller_->SetEstimatedBitrate(bitrate_bps); 422 probe_controller_->SetEstimatedBitrate(bitrate_bps);
416 retransmission_rate_limiter_->SetMaxRate(bitrate_bps); 423 retransmission_rate_limiter_->SetMaxRate(bitrate_bps);
417 } 424 }
418 425
419 bitrate_bps = IsNetworkDown() || IsSendQueueFull() ? 0 : bitrate_bps; 426 if (!pacer_pushback_experiment_) {
427 bitrate_bps = IsNetworkDown() || IsSendQueueFull() ? 0 : bitrate_bps;
428 } else {
429 if (IsNetworkDown()) {
430 bitrate_bps = 0;
431 } else {
432 int64_t queue_length_ms = pacer_->ExpectedQueueTimeMs();
433
434 if (queue_length_ms == 0) {
435 encoding_rate_ = 1.0;
436 } else if (queue_length_ms > 50) {
437 float encoding_rate = 1.0 - queue_length_ms / 1000.0;
438 encoding_rate_ = std::min(encoding_rate_, encoding_rate);
439 encoding_rate_ = std::max(encoding_rate_, 0.0f);
440 }
441
442 bitrate_bps *= encoding_rate_;
443 }
444 }
420 445
421 if (HasNetworkParametersToReportChanged(bitrate_bps, fraction_loss, rtt)) { 446 if (HasNetworkParametersToReportChanged(bitrate_bps, fraction_loss, rtt)) {
422 int64_t probing_interval_ms; 447 int64_t probing_interval_ms;
423 { 448 {
424 rtc::CritScope cs(&bwe_lock_); 449 rtc::CritScope cs(&bwe_lock_);
425 probing_interval_ms = delay_based_bwe_->GetExpectedBwePeriodMs(); 450 probing_interval_ms = delay_based_bwe_->GetExpectedBwePeriodMs();
426 } 451 }
427 { 452 {
428 rtc::CritScope cs(&observer_lock_); 453 rtc::CritScope cs(&observer_lock_);
429 if (observer_) { 454 if (observer_) {
(...skipping 26 matching lines...) Expand all
456 bool SendSideCongestionController::IsSendQueueFull() const { 481 bool SendSideCongestionController::IsSendQueueFull() const {
457 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; 482 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs;
458 } 483 }
459 484
460 bool SendSideCongestionController::IsNetworkDown() const { 485 bool SendSideCongestionController::IsNetworkDown() const {
461 rtc::CritScope cs(&network_state_lock_); 486 rtc::CritScope cs(&network_state_lock_);
462 return network_state_ == kNetworkDown; 487 return network_state_ == kNetworkDown;
463 } 488 }
464 489
465 } // namespace webrtc 490 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/congestion_controller/include/send_side_congestion_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698