Chromium Code Reviews| 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/base/safe_conversions.h" | |
| 17 #include "webrtc/system_wrappers/include/metrics.h" | 18 #include "webrtc/system_wrappers/include/metrics.h" |
| 18 | 19 |
| 19 namespace webrtc { | 20 namespace webrtc { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // Number of deltas between probes per cluster. On the very first cluster, | 24 // Number of deltas between probes per cluster. On the very first cluster, |
| 24 // we will need kProbeDeltasPerCluster + 1 probes, but on a cluster following | 25 // we will need kProbeDeltasPerCluster + 1 probes, but on a cluster following |
| 25 // another, we need kProbeDeltasPerCluster probes. | 26 // another, we need kProbeDeltasPerCluster probes. |
| 26 constexpr int kProbeDeltasPerCluster = 5; | 27 constexpr int kProbeDeltasPerCluster = 5; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 37 // specify max bitrate. | 38 // specify max bitrate. |
| 38 constexpr int kDefaultMaxProbingBitrateBps = 5000000; | 39 constexpr int kDefaultMaxProbingBitrateBps = 5000000; |
| 39 | 40 |
| 40 // This is a limit on how often probing can be done when there is a BW | 41 // This is a limit on how often probing can be done when there is a BW |
| 41 // drop detected in ALR. | 42 // drop detected in ALR. |
| 42 constexpr int64_t kAlrProbingIntervalMinMs = 5000; | 43 constexpr int64_t kAlrProbingIntervalMinMs = 5000; |
| 43 | 44 |
| 44 // Interval between probes when ALR periodic probing is enabled. | 45 // Interval between probes when ALR periodic probing is enabled. |
| 45 constexpr int64_t kAlrPeriodicProbingIntervalMs = 5000; | 46 constexpr int64_t kAlrPeriodicProbingIntervalMs = 5000; |
| 46 | 47 |
| 47 // Minimum probe bitrate percentage to probe further for repeated probes. | 48 // Minimum probe bitrate percentage to probe further for repeated probes, |
| 48 constexpr int kRepeatedProbeMinPercentage = 125; | 49 // relative to the previous probe. For example, if 1Mbps probe results in |
| 50 // 80kbps, then we'll probe again at 1.6Mbps. In that case second probe won't be | |
| 51 // sent if we get 600kbps from the first one. | |
| 52 constexpr int kRepeatedProbeMinPercentage = 70; | |
| 49 | 53 |
| 50 } // namespace | 54 } // namespace |
| 51 | 55 |
| 52 ProbeController::ProbeController(PacedSender* pacer, Clock* clock) | 56 ProbeController::ProbeController(PacedSender* pacer, Clock* clock) |
| 53 : pacer_(pacer), | 57 : pacer_(pacer), |
| 54 clock_(clock), | 58 clock_(clock), |
| 55 network_state_(kNetworkUp), | 59 network_state_(kNetworkUp), |
| 56 state_(State::kInit), | 60 state_(State::kInit), |
| 57 min_bitrate_to_probe_further_bps_(kExponentialProbingDisabled), | 61 min_bitrate_to_probe_further_bps_(kExponentialProbingDisabled), |
| 58 time_last_probing_initiated_ms_(0), | 62 time_last_probing_initiated_ms_(0), |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 80 case State::kInit: | 84 case State::kInit: |
| 81 if (network_state_ == kNetworkUp) | 85 if (network_state_ == kNetworkUp) |
| 82 InitiateExponentialProbing(); | 86 InitiateExponentialProbing(); |
| 83 break; | 87 break; |
| 84 | 88 |
| 85 case State::kWaitingForProbingResult: | 89 case State::kWaitingForProbingResult: |
| 86 break; | 90 break; |
| 87 | 91 |
| 88 case State::kProbingComplete: | 92 case State::kProbingComplete: |
| 89 // Initiate probing when |max_bitrate_| was increased mid-call. | 93 // Initiate probing when |max_bitrate_| was increased mid-call. |
| 90 if (estimated_bitrate_bps_ != 0 && | 94 if (estimated_bitrate_bps_ != kExponentialProbingDisabled && |
| 91 estimated_bitrate_bps_ < old_max_bitrate_bps && | 95 estimated_bitrate_bps_ < old_max_bitrate_bps && |
| 92 max_bitrate_bps_ > old_max_bitrate_bps) { | 96 max_bitrate_bps_ > old_max_bitrate_bps) { |
| 93 InitiateProbing(clock_->TimeInMilliseconds(), {max_bitrate_bps}, | 97 InitiateProbing(clock_->TimeInMilliseconds(), {max_bitrate_bps}, |
| 94 kExponentialProbingDisabled); | 98 /*probe_furter=*/false); |
|
philipel
2016/12/13 14:26:27
In general, if you want to describe the parameter
Sergey Ulanov
2016/12/13 19:38:09
Done.
| |
| 95 } | 99 } |
| 96 break; | 100 break; |
| 97 } | 101 } |
| 98 } | 102 } |
| 99 | 103 |
| 100 void ProbeController::OnNetworkStateChanged(NetworkState network_state) { | 104 void ProbeController::OnNetworkStateChanged(NetworkState network_state) { |
| 101 rtc::CritScope cs(&critsect_); | 105 rtc::CritScope cs(&critsect_); |
| 102 network_state_ = network_state; | 106 network_state_ = network_state; |
| 103 if (network_state_ == kNetworkUp && state_ == State::kInit) | 107 if (network_state_ == kNetworkUp && state_ == State::kInit) |
| 104 InitiateExponentialProbing(); | 108 InitiateExponentialProbing(); |
| 105 } | 109 } |
| 106 | 110 |
| 107 void ProbeController::InitiateExponentialProbing() { | 111 void ProbeController::InitiateExponentialProbing() { |
| 108 RTC_DCHECK(network_state_ == kNetworkUp); | 112 RTC_DCHECK(network_state_ == kNetworkUp); |
| 109 RTC_DCHECK(state_ == State::kInit); | 113 RTC_DCHECK(state_ == State::kInit); |
| 110 RTC_DCHECK_GT(start_bitrate_bps_, 0); | 114 RTC_DCHECK_GT(start_bitrate_bps_, 0); |
| 111 | 115 |
| 112 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of | 116 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of |
| 113 // 1.2 Mbps to continue probing. | 117 // 1.2 Mbps to continue probing. |
| 114 InitiateProbing(clock_->TimeInMilliseconds(), | 118 InitiateProbing(clock_->TimeInMilliseconds(), |
| 115 {3 * start_bitrate_bps_, 6 * start_bitrate_bps_}, | 119 {3 * static_cast<int64_t>(start_bitrate_bps_), |
| 116 4 * start_bitrate_bps_); | 120 6 * static_cast<int64_t>(start_bitrate_bps_)}, |
| 121 /*probe_furter=*/true); | |
| 117 } | 122 } |
| 118 | 123 |
| 119 void ProbeController::SetEstimatedBitrate(int bitrate_bps) { | 124 void ProbeController::SetEstimatedBitrate(int bitrate_bps) { |
| 120 rtc::CritScope cs(&critsect_); | 125 rtc::CritScope cs(&critsect_); |
| 121 int64_t now_ms = clock_->TimeInMilliseconds(); | 126 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 122 | 127 |
| 123 if (state_ == State::kWaitingForProbingResult) { | 128 if (state_ == State::kWaitingForProbingResult) { |
| 124 // Continue probing if probing results indicate channel has greater | 129 // Continue probing if probing results indicate channel has greater |
| 125 // capacity. | 130 // capacity. |
| 126 LOG(LS_INFO) << "Measured bitrate: " << bitrate_bps | 131 LOG(LS_INFO) << "Measured bitrate: " << bitrate_bps |
| 127 << " Minimum to probe further: " | 132 << " Minimum to probe further: " |
| 128 << min_bitrate_to_probe_further_bps_; | 133 << min_bitrate_to_probe_further_bps_; |
| 129 if (min_bitrate_to_probe_further_bps_ != kExponentialProbingDisabled && | 134 if (min_bitrate_to_probe_further_bps_ != kExponentialProbingDisabled && |
| 130 bitrate_bps > min_bitrate_to_probe_further_bps_) { | 135 bitrate_bps > min_bitrate_to_probe_further_bps_) { |
| 131 // Double the probing bitrate and expect a minimum of 25% gain to | 136 // Double the probing bitrate. |
| 132 // continue probing. | 137 InitiateProbing(now_ms, {2 * static_cast<int64_t>(bitrate_bps)}, |
| 133 InitiateProbing(now_ms, {2 * bitrate_bps}, | 138 /*probe_furter=*/true); |
| 134 bitrate_bps * kRepeatedProbeMinPercentage / 100); | |
| 135 } | 139 } |
| 136 } | 140 } |
| 137 | 141 |
| 138 // Detect a drop in estimated BW when operating in ALR and not already | 142 // Detect a drop in estimated BW when operating in ALR and not already |
| 139 // probing. The current response is to initiate a single probe session at the | 143 // probing. The current response is to initiate a single probe session at the |
| 140 // previous bitrate and immediately use the reported bitrate as the new | 144 // previous bitrate and immediately use the reported bitrate as the new |
| 141 // bitrate. | 145 // bitrate. |
| 142 // | 146 // |
| 143 // If the probe session fails, the assumption is that this drop was a | 147 // If the probe session fails, the assumption is that this drop was a |
| 144 // real one from a competing flow or something else on the network and | 148 // real one from a competing flow or something else on the network and |
| 145 // it ramps up from bitrate_bps. | 149 // it ramps up from bitrate_bps. |
| 146 if (state_ == State::kProbingComplete && | 150 if (state_ == State::kProbingComplete && |
| 147 pacer_->GetApplicationLimitedRegionStartTime() && | 151 pacer_->GetApplicationLimitedRegionStartTime() && |
| 148 bitrate_bps < estimated_bitrate_bps_ / 2 && | 152 bitrate_bps < estimated_bitrate_bps_ / 2 && |
| 149 (now_ms - last_alr_probing_time_) > kAlrProbingIntervalMinMs) { | 153 (now_ms - last_alr_probing_time_) > kAlrProbingIntervalMinMs) { |
| 150 LOG(LS_INFO) << "Detected big BW drop in ALR, start probe."; | 154 LOG(LS_INFO) << "Detected big BW drop in ALR, start probe."; |
| 151 // Track how often we probe in response to BW drop in ALR. | 155 // Track how often we probe in response to BW drop in ALR. |
| 152 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.AlrProbingIntervalInS", | 156 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.AlrProbingIntervalInS", |
| 153 (now_ms - last_alr_probing_time_) / 1000); | 157 (now_ms - last_alr_probing_time_) / 1000); |
| 154 InitiateProbing(now_ms, {estimated_bitrate_bps_}, | 158 InitiateProbing(now_ms, {estimated_bitrate_bps_}, /*probe_furter=*/false); |
| 155 kExponentialProbingDisabled); | |
| 156 last_alr_probing_time_ = now_ms; | 159 last_alr_probing_time_ = now_ms; |
| 157 | 160 |
| 158 // TODO(isheriff): May want to track when we did ALR probing in order | 161 // TODO(isheriff): May want to track when we did ALR probing in order |
| 159 // to reset |last_alr_probing_time_| if we validate that it was a | 162 // to reset |last_alr_probing_time_| if we validate that it was a |
| 160 // drop due to exogenous event. | 163 // drop due to exogenous event. |
| 161 } | 164 } |
| 162 | 165 |
| 163 estimated_bitrate_bps_ = bitrate_bps; | 166 estimated_bitrate_bps_ = bitrate_bps; |
| 164 } | 167 } |
| 165 | 168 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 185 return; | 188 return; |
| 186 | 189 |
| 187 // Probe bandwidth periodically when in ALR state. | 190 // Probe bandwidth periodically when in ALR state. |
| 188 rtc::Optional<int64_t> alr_start_time = | 191 rtc::Optional<int64_t> alr_start_time = |
| 189 pacer_->GetApplicationLimitedRegionStartTime(); | 192 pacer_->GetApplicationLimitedRegionStartTime(); |
| 190 if (alr_start_time) { | 193 if (alr_start_time) { |
| 191 int64_t next_probe_time_ms = | 194 int64_t next_probe_time_ms = |
| 192 std::max(*alr_start_time, time_last_probing_initiated_ms_) + | 195 std::max(*alr_start_time, time_last_probing_initiated_ms_) + |
| 193 kAlrPeriodicProbingIntervalMs; | 196 kAlrPeriodicProbingIntervalMs; |
| 194 if (now_ms >= next_probe_time_ms) { | 197 if (now_ms >= next_probe_time_ms) { |
| 195 InitiateProbing( | 198 InitiateProbing(now_ms, |
| 196 now_ms, {estimated_bitrate_bps_ * 2}, | 199 {static_cast<int64_t>(estimated_bitrate_bps_) * 2}, |
| 197 estimated_bitrate_bps_ * kRepeatedProbeMinPercentage / 100); | 200 /*probe_furter=*/true); |
| 198 } | 201 } |
| 199 } | 202 } |
| 200 } | 203 } |
| 201 | 204 |
| 202 void ProbeController::InitiateProbing( | 205 void ProbeController::InitiateProbing( |
| 203 int64_t now_ms, | 206 int64_t now_ms, |
| 204 std::initializer_list<int> bitrates_to_probe, | 207 std::initializer_list<int64_t> bitrates_to_probe, |
| 205 int min_bitrate_to_probe_further_bps) { | 208 bool probe_further) { |
| 206 bool first_cluster = true; | 209 bool first_cluster = true; |
| 207 for (int bitrate : bitrates_to_probe) { | 210 for (int64_t bitrate : bitrates_to_probe) { |
| 208 int max_probe_bitrate_bps = | 211 int max_probe_bitrate_bps = |
| 209 max_bitrate_bps_ > 0 ? max_bitrate_bps_ : kDefaultMaxProbingBitrateBps; | 212 max_bitrate_bps_ > 0 ? max_bitrate_bps_ : kDefaultMaxProbingBitrateBps; |
| 210 bitrate = std::min(bitrate, max_probe_bitrate_bps); | 213 if (bitrate > max_probe_bitrate_bps) { |
| 214 bitrate = max_probe_bitrate_bps; | |
| 215 probe_further = false; | |
| 216 } | |
| 211 if (first_cluster) { | 217 if (first_cluster) { |
| 212 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster + 1); | 218 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster + 1); |
| 213 first_cluster = false; | 219 first_cluster = false; |
| 214 } else { | 220 } else { |
| 215 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster); | 221 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster); |
| 216 } | 222 } |
| 217 } | 223 } |
| 218 min_bitrate_to_probe_further_bps_ = min_bitrate_to_probe_further_bps; | |
| 219 time_last_probing_initiated_ms_ = now_ms; | 224 time_last_probing_initiated_ms_ = now_ms; |
| 220 if (min_bitrate_to_probe_further_bps == kExponentialProbingDisabled) | 225 if (probe_further) { |
| 226 state_ = State::kWaitingForProbingResult; | |
| 227 min_bitrate_to_probe_further_bps_ = rtc::checked_cast<int>( | |
|
philipel
2016/12/13 14:26:27
As I see it, we are ok to store bitrates in 32 bit
Sergey Ulanov
2016/12/13 19:38:09
Changed all bps variables in this class to int64_t
| |
| 228 (*(bitrates_to_probe.end() - 1)) * kRepeatedProbeMinPercentage / 100); | |
| 229 } else { | |
| 221 state_ = State::kProbingComplete; | 230 state_ = State::kProbingComplete; |
| 222 else | 231 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; |
| 223 state_ = State::kWaitingForProbingResult; | 232 } |
| 224 } | 233 } |
| 225 | 234 |
| 226 } // namespace webrtc | 235 } // namespace webrtc |
| OLD | NEW |