| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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/probe_controller.h" | 11 #include "webrtc/modules/congestion_controller/probe_controller.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <initializer_list> | 14 #include <initializer_list> |
| 15 | 15 |
| 16 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
| 17 #include "webrtc/system_wrappers/include/metrics.h" |
| 17 | 18 |
| 18 namespace webrtc { | 19 namespace webrtc { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // Number of deltas between probes per cluster. On the very first cluster, | 23 // Number of deltas between probes per cluster. On the very first cluster, |
| 23 // we will need kProbeDeltasPerCluster + 1 probes, but on a cluster following | 24 // we will need kProbeDeltasPerCluster + 1 probes, but on a cluster following |
| 24 // another, we need kProbeDeltasPerCluster probes. | 25 // another, we need kProbeDeltasPerCluster probes. |
| 25 constexpr int kProbeDeltasPerCluster = 5; | 26 constexpr int kProbeDeltasPerCluster = 5; |
| 26 | 27 |
| 27 // Maximum waiting time from the time of initiating probing to getting | 28 // Maximum waiting time from the time of initiating probing to getting |
| 28 // the measured results back. | 29 // the measured results back. |
| 29 constexpr int64_t kMaxWaitingTimeForProbingResultMs = 1000; | 30 constexpr int64_t kMaxWaitingTimeForProbingResultMs = 1000; |
| 30 | 31 |
| 31 // Value of |min_bitrate_to_probe_further_bps_| that indicates | 32 // Value of |min_bitrate_to_probe_further_bps_| that indicates |
| 32 // further probing is disabled. | 33 // further probing is disabled. |
| 33 constexpr int kExponentialProbingDisabled = 0; | 34 constexpr int kExponentialProbingDisabled = 0; |
| 34 | 35 |
| 35 // A limit to prevent probing at excessive bitrates. | 36 // A limit to prevent probing at excessive bitrates. |
| 36 constexpr int kMaxProbingBitrateBps = 10000000; | 37 constexpr int kMaxProbingBitrateBps = 10000000; |
| 37 | 38 |
| 39 // This is a limit on how often probing can be done when there is a BW |
| 40 // drop detected in ALR region. |
| 41 constexpr int kAlrProbingIntervalLimitMs = 5000; |
| 42 |
| 38 } // namespace | 43 } // namespace |
| 39 | 44 |
| 40 ProbeController::ProbeController(PacedSender* pacer, Clock* clock) | 45 ProbeController::ProbeController(PacedSender* pacer, Clock* clock) |
| 41 : pacer_(pacer), | 46 : pacer_(pacer), |
| 42 clock_(clock), | 47 clock_(clock), |
| 43 state_(State::kInit), | 48 state_(State::kInit), |
| 44 min_bitrate_to_probe_further_bps_(kExponentialProbingDisabled), | 49 min_bitrate_to_probe_further_bps_(kExponentialProbingDisabled), |
| 45 time_last_probing_initiated_ms_(0), | 50 time_last_probing_initiated_ms_(0), |
| 46 estimated_bitrate_bps_(0), | 51 estimated_bitrate_bps_(0), |
| 47 max_bitrate_bps_(0) {} | 52 max_bitrate_bps_(0), |
| 53 last_alr_probing_time_(clock_->TimeInMilliseconds()) {} |
| 48 | 54 |
| 49 void ProbeController::SetBitrates(int min_bitrate_bps, | 55 void ProbeController::SetBitrates(int min_bitrate_bps, |
| 50 int start_bitrate_bps, | 56 int start_bitrate_bps, |
| 51 int max_bitrate_bps) { | 57 int max_bitrate_bps) { |
| 52 rtc::CritScope cs(&critsect_); | 58 rtc::CritScope cs(&critsect_); |
| 53 if (state_ == State::kInit) { | 59 if (state_ == State::kInit) { |
| 54 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of | 60 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of |
| 55 // 1.2 Mbps to continue probing. | 61 // 1.2 Mbps to continue probing. |
| 56 InitiateProbing({3 * start_bitrate_bps, 6 * start_bitrate_bps}, | 62 InitiateProbing({3 * start_bitrate_bps, 6 * start_bitrate_bps}, |
| 57 4 * start_bitrate_bps); | 63 4 * start_bitrate_bps); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 85 LOG(LS_INFO) << "Measured bitrate: " << bitrate_bps | 91 LOG(LS_INFO) << "Measured bitrate: " << bitrate_bps |
| 86 << " Minimum to probe further: " | 92 << " Minimum to probe further: " |
| 87 << min_bitrate_to_probe_further_bps_; | 93 << min_bitrate_to_probe_further_bps_; |
| 88 if (min_bitrate_to_probe_further_bps_ != kExponentialProbingDisabled && | 94 if (min_bitrate_to_probe_further_bps_ != kExponentialProbingDisabled && |
| 89 bitrate_bps > min_bitrate_to_probe_further_bps_) { | 95 bitrate_bps > min_bitrate_to_probe_further_bps_) { |
| 90 // Double the probing bitrate and expect a minimum of 25% gain to | 96 // Double the probing bitrate and expect a minimum of 25% gain to |
| 91 // continue probing. | 97 // continue probing. |
| 92 InitiateProbing({2 * bitrate_bps}, 1.25 * bitrate_bps); | 98 InitiateProbing({2 * bitrate_bps}, 1.25 * bitrate_bps); |
| 93 } | 99 } |
| 94 } | 100 } |
| 101 } else { |
| 102 // A drop in estimated BW when operating in ALR and not already probing. |
| 103 // The current response is to initiate a single probe session at the |
| 104 // previous bitrate and immediately use the reported bitrate as the new |
| 105 // bitrate. |
| 106 // |
| 107 // If the probe session fails, the assumption is that this drop was a |
| 108 // real one from a competing flow or something else on the network and |
| 109 // it ramps up from bitrate_bps. |
| 110 if (pacer_->InApplicationLimitedRegion() && |
| 111 bitrate_bps < 0.5 * estimated_bitrate_bps_) { |
| 112 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 113 if ((now_ms - last_alr_probing_time_) > kAlrProbingIntervalLimitMs) { |
| 114 LOG(LS_INFO) << "Detected big BW drop in ALR, start probe."; |
| 115 // Track how often we probe in response to BW drop in ALR. |
| 116 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.AlrProbingIntervalInS", |
| 117 (now_ms - last_alr_probing_time_) / 1000); |
| 118 InitiateProbing({estimated_bitrate_bps_}, kExponentialProbingDisabled); |
| 119 last_alr_probing_time_ = now_ms; |
| 120 } |
| 121 } |
| 122 // TODO(isheriff): May want to track when we did ALR probing in order |
| 123 // to reset |last_alr_probing_time_| if we validate that it was a |
| 124 // drop due to exogenous event. |
| 95 } | 125 } |
| 96 estimated_bitrate_bps_ = bitrate_bps; | 126 estimated_bitrate_bps_ = bitrate_bps; |
| 97 } | 127 } |
| 98 | 128 |
| 99 void ProbeController::InitiateProbing( | 129 void ProbeController::InitiateProbing( |
| 100 std::initializer_list<int> bitrates_to_probe, | 130 std::initializer_list<int> bitrates_to_probe, |
| 101 int min_bitrate_to_probe_further_bps) { | 131 int min_bitrate_to_probe_further_bps) { |
| 102 bool first_cluster = true; | 132 bool first_cluster = true; |
| 103 for (int bitrate : bitrates_to_probe) { | 133 for (int bitrate : bitrates_to_probe) { |
| 104 bitrate = std::min(bitrate, kMaxProbingBitrateBps); | 134 bitrate = std::min(bitrate, kMaxProbingBitrateBps); |
| 105 if (first_cluster) { | 135 if (first_cluster) { |
| 106 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster + 1); | 136 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster + 1); |
| 107 first_cluster = false; | 137 first_cluster = false; |
| 108 } else { | 138 } else { |
| 109 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster); | 139 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster); |
| 110 } | 140 } |
| 111 } | 141 } |
| 112 min_bitrate_to_probe_further_bps_ = min_bitrate_to_probe_further_bps; | 142 min_bitrate_to_probe_further_bps_ = min_bitrate_to_probe_further_bps; |
| 113 time_last_probing_initiated_ms_ = clock_->TimeInMilliseconds(); | 143 time_last_probing_initiated_ms_ = clock_->TimeInMilliseconds(); |
| 114 if (min_bitrate_to_probe_further_bps == kExponentialProbingDisabled) | 144 if (min_bitrate_to_probe_further_bps == kExponentialProbingDisabled) |
| 115 state_ = State::kProbingComplete; | 145 state_ = State::kProbingComplete; |
| 116 else | 146 else |
| 117 state_ = State::kWaitingForProbingResult; | 147 state_ = State::kWaitingForProbingResult; |
| 118 } | 148 } |
| 119 | 149 |
| 120 } // namespace webrtc | 150 } // namespace webrtc |
| OLD | NEW |