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