| OLD | NEW |
| 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/send_side_congestion_cont
roller.h" | 11 #include "webrtc/modules/congestion_controller/include/send_side_congestion_cont
roller.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/modules/bitrate_controller/include/bitrate_controller.h" | 17 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
| 18 #include "webrtc/modules/congestion_controller/acknowledged_bitrate_estimator.h" | 18 #include "webrtc/modules/congestion_controller/acknowledged_bitrate_estimator.h" |
| 19 #include "webrtc/modules/congestion_controller/probe_controller.h" | 19 #include "webrtc/modules/congestion_controller/probe_controller.h" |
| 20 #include "webrtc/modules/pacing/alr_detector.h" | 20 #include "webrtc/modules/pacing/alr_detector.h" |
| 21 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h" | 21 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h" |
| 22 #include "webrtc/rtc_base/checks.h" | 22 #include "webrtc/rtc_base/checks.h" |
| 23 #include "webrtc/rtc_base/format_macros.h" | |
| 24 #include "webrtc/rtc_base/logging.h" | 23 #include "webrtc/rtc_base/logging.h" |
| 25 #include "webrtc/rtc_base/ptr_util.h" | 24 #include "webrtc/rtc_base/ptr_util.h" |
| 26 #include "webrtc/rtc_base/rate_limiter.h" | 25 #include "webrtc/rtc_base/rate_limiter.h" |
| 27 #include "webrtc/rtc_base/socket.h" | 26 #include "webrtc/rtc_base/socket.h" |
| 28 #include "webrtc/rtc_base/timeutils.h" | 27 #include "webrtc/rtc_base/timeutils.h" |
| 29 #include "webrtc/system_wrappers/include/field_trial.h" | 28 #include "webrtc/system_wrappers/include/field_trial.h" |
| 30 | 29 |
| 31 namespace webrtc { | 30 namespace webrtc { |
| 32 namespace { | 31 namespace { |
| 33 | 32 |
| 34 const char kCwndExperiment[] = "WebRTC-CwndExperiment"; | 33 const char kCwndExperiment[] = "WebRTC-CwndExperiment"; |
| 35 const int64_t kDefaultAcceptedQueueMs = 250; | |
| 36 | 34 |
| 37 bool CwndExperimentEnabled() { | 35 bool CwndExperimentEnabled() { |
| 38 std::string experiment_string = | 36 std::string experiment_string = |
| 39 webrtc::field_trial::FindFullName(kCwndExperiment); | 37 webrtc::field_trial::FindFullName(kCwndExperiment); |
| 40 // The experiment is enabled iff the field trial string begins with "Enabled". | 38 // The experiment is enabled iff the field trial string begins with "Enabled". |
| 41 return experiment_string.find("Enabled") == 0; | 39 return experiment_string.find("Enabled") == 0; |
| 42 } | 40 } |
| 43 | 41 |
| 44 bool ReadCwndExperimentParameter(int64_t* accepted_queue_ms) { | |
| 45 RTC_DCHECK(accepted_queue_ms); | |
| 46 std::string experiment_string = | |
| 47 webrtc::field_trial::FindFullName(kCwndExperiment); | |
| 48 int parsed_values = | |
| 49 sscanf(experiment_string.c_str(), "Enabled-%" PRId64, accepted_queue_ms); | |
| 50 if (parsed_values == 1) { | |
| 51 RTC_CHECK_GE(*accepted_queue_ms, 0) | |
| 52 << "Accepted must be greater than or equal to 0."; | |
| 53 return true; | |
| 54 } | |
| 55 return false; | |
| 56 } | |
| 57 | |
| 58 static const int64_t kRetransmitWindowSizeMs = 500; | 42 static const int64_t kRetransmitWindowSizeMs = 500; |
| 59 | 43 |
| 60 // Makes sure that the bitrate and the min, max values are in valid range. | 44 // Makes sure that the bitrate and the min, max values are in valid range. |
| 61 static void ClampBitrates(int* bitrate_bps, | 45 static void ClampBitrates(int* bitrate_bps, |
| 62 int* min_bitrate_bps, | 46 int* min_bitrate_bps, |
| 63 int* max_bitrate_bps) { | 47 int* max_bitrate_bps) { |
| 64 // TODO(holmer): We should make sure the default bitrates are set to 10 kbps, | 48 // TODO(holmer): We should make sure the default bitrates are set to 10 kbps, |
| 65 // and that we don't try to set the min bitrate to 0 from any applications. | 49 // and that we don't try to set the min bitrate to 0 from any applications. |
| 66 // The congestion controller should allow a min bitrate of 0. | 50 // The congestion controller should allow a min bitrate of 0. |
| 67 if (*min_bitrate_bps < congestion_controller::GetMinBitrateBps()) | 51 if (*min_bitrate_bps < congestion_controller::GetMinBitrateBps()) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 transport_feedback_adapter_(clock_), | 108 transport_feedback_adapter_(clock_), |
| 125 last_reported_bitrate_bps_(0), | 109 last_reported_bitrate_bps_(0), |
| 126 last_reported_fraction_loss_(0), | 110 last_reported_fraction_loss_(0), |
| 127 last_reported_rtt_(0), | 111 last_reported_rtt_(0), |
| 128 network_state_(kNetworkUp), | 112 network_state_(kNetworkUp), |
| 129 pause_pacer_(false), | 113 pause_pacer_(false), |
| 130 pacer_paused_(false), | 114 pacer_paused_(false), |
| 131 min_bitrate_bps_(congestion_controller::GetMinBitrateBps()), | 115 min_bitrate_bps_(congestion_controller::GetMinBitrateBps()), |
| 132 delay_based_bwe_(new DelayBasedBwe(event_log_, clock_)), | 116 delay_based_bwe_(new DelayBasedBwe(event_log_, clock_)), |
| 133 in_cwnd_experiment_(CwndExperimentEnabled()), | 117 in_cwnd_experiment_(CwndExperimentEnabled()), |
| 134 accepted_queue_ms_(kDefaultAcceptedQueueMs), | |
| 135 was_in_alr_(0) { | 118 was_in_alr_(0) { |
| 136 delay_based_bwe_->SetMinBitrate(min_bitrate_bps_); | 119 delay_based_bwe_->SetMinBitrate(min_bitrate_bps_); |
| 137 if (in_cwnd_experiment_ && | |
| 138 !ReadCwndExperimentParameter(&accepted_queue_ms_)) { | |
| 139 LOG(LS_WARNING) << "Failed to parse parameters for CwndExperiment " | |
| 140 "from field trial string. Experiment disabled."; | |
| 141 in_cwnd_experiment_ = false; | |
| 142 } | |
| 143 } | 120 } |
| 144 | 121 |
| 145 SendSideCongestionController::~SendSideCongestionController() {} | 122 SendSideCongestionController::~SendSideCongestionController() {} |
| 146 | 123 |
| 147 void SendSideCongestionController::RegisterPacketFeedbackObserver( | 124 void SendSideCongestionController::RegisterPacketFeedbackObserver( |
| 148 PacketFeedbackObserver* observer) { | 125 PacketFeedbackObserver* observer) { |
| 149 transport_feedback_adapter_.RegisterPacketFeedbackObserver(observer); | 126 transport_feedback_adapter_.RegisterPacketFeedbackObserver(observer); |
| 150 } | 127 } |
| 151 | 128 |
| 152 void SendSideCongestionController::DeRegisterPacketFeedbackObserver( | 129 void SendSideCongestionController::DeRegisterPacketFeedbackObserver( |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 if (!in_cwnd_experiment_) | 337 if (!in_cwnd_experiment_) |
| 361 return; | 338 return; |
| 362 { | 339 { |
| 363 rtc::CritScope lock(&network_state_lock_); | 340 rtc::CritScope lock(&network_state_lock_); |
| 364 rtc::Optional<int64_t> min_rtt_ms = | 341 rtc::Optional<int64_t> min_rtt_ms = |
| 365 transport_feedback_adapter_.GetMinFeedbackLoopRtt(); | 342 transport_feedback_adapter_.GetMinFeedbackLoopRtt(); |
| 366 // No valid RTT. Could be because send-side BWE isn't used, in which case | 343 // No valid RTT. Could be because send-side BWE isn't used, in which case |
| 367 // we don't try to limit the outstanding packets. | 344 // we don't try to limit the outstanding packets. |
| 368 if (!min_rtt_ms) | 345 if (!min_rtt_ms) |
| 369 return; | 346 return; |
| 347 const int64_t kAcceptedQueueMs = 250; |
| 370 const size_t kMinCwndBytes = 2 * 1500; | 348 const size_t kMinCwndBytes = 2 * 1500; |
| 371 size_t max_outstanding_bytes = | 349 size_t max_outstanding_bytes = |
| 372 std::max<size_t>((*min_rtt_ms + accepted_queue_ms_) * | 350 std::max<size_t>((*min_rtt_ms + kAcceptedQueueMs) * |
| 373 last_reported_bitrate_bps_ / 1000 / 8, | 351 last_reported_bitrate_bps_ / 1000 / 8, |
| 374 kMinCwndBytes); | 352 kMinCwndBytes); |
| 375 LOG(LS_INFO) << clock_->TimeInMilliseconds() | 353 LOG(LS_INFO) << clock_->TimeInMilliseconds() |
| 376 << " Outstanding bytes: " << num_outstanding_bytes | 354 << " Outstanding bytes: " << num_outstanding_bytes |
| 377 << " pacer queue: " << pacer_->QueueInMs() | 355 << " pacer queue: " << pacer_->QueueInMs() |
| 378 << " max outstanding: " << max_outstanding_bytes; | 356 << " max outstanding: " << max_outstanding_bytes; |
| 379 LOG(LS_INFO) << "Feedback rtt: " << *min_rtt_ms | 357 LOG(LS_INFO) << "Feedback rtt: " << *min_rtt_ms |
| 380 << " Bitrate: " << last_reported_bitrate_bps_; | 358 << " Bitrate: " << last_reported_bitrate_bps_; |
| 381 pause_pacer_ = num_outstanding_bytes > max_outstanding_bytes; | 359 pause_pacer_ = num_outstanding_bytes > max_outstanding_bytes; |
| 382 } | 360 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 bool SendSideCongestionController::IsSendQueueFull() const { | 418 bool SendSideCongestionController::IsSendQueueFull() const { |
| 441 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; | 419 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; |
| 442 } | 420 } |
| 443 | 421 |
| 444 bool SendSideCongestionController::IsNetworkDown() const { | 422 bool SendSideCongestionController::IsNetworkDown() const { |
| 445 rtc::CritScope cs(&network_state_lock_); | 423 rtc::CritScope cs(&network_state_lock_); |
| 446 return network_state_ == kNetworkDown; | 424 return network_state_ == kNetworkDown; |
| 447 } | 425 } |
| 448 | 426 |
| 449 } // namespace webrtc | 427 } // namespace webrtc |
| OLD | NEW |