Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Sebastian Jansson | fc7ec8e | 2018-02-28 16:48:00 +0100 | [diff] [blame] | 11 | #include "modules/congestion_controller/goog_cc/probe_controller.h" |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 12 | |
| 13 | #include <algorithm> |
| 14 | #include <initializer_list> |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 15 | #include <string> |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 16 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 17 | #include "api/units/data_rate.h" |
| 18 | #include "api/units/time_delta.h" |
| 19 | #include "api/units/timestamp.h" |
| 20 | #include "rtc_base/checks.h" |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 21 | #include "rtc_base/logging.h" |
| 22 | #include "rtc_base/numerics/safe_conversions.h" |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 23 | #include "system_wrappers/include/metrics.h" |
| 24 | |
| 25 | namespace webrtc { |
| 26 | |
| 27 | namespace { |
| 28 | // The minimum number probing packets used. |
| 29 | constexpr int kMinProbePacketsSent = 5; |
| 30 | |
| 31 | // The minimum probing duration in ms. |
| 32 | constexpr int kMinProbeDurationMs = 15; |
| 33 | |
| 34 | // Maximum waiting time from the time of initiating probing to getting |
| 35 | // the measured results back. |
| 36 | constexpr int64_t kMaxWaitingTimeForProbingResultMs = 1000; |
| 37 | |
| 38 | // Value of |min_bitrate_to_probe_further_bps_| that indicates |
| 39 | // further probing is disabled. |
| 40 | constexpr int kExponentialProbingDisabled = 0; |
| 41 | |
| 42 | // Default probing bitrate limit. Applied only when the application didn't |
| 43 | // specify max bitrate. |
| 44 | constexpr int64_t kDefaultMaxProbingBitrateBps = 5000000; |
| 45 | |
| 46 | // Interval between probes when ALR periodic probing is enabled. |
| 47 | constexpr int64_t kAlrPeriodicProbingIntervalMs = 5000; |
| 48 | |
| 49 | // Minimum probe bitrate percentage to probe further for repeated probes, |
| 50 | // relative to the previous probe. For example, if 1Mbps probe results in |
| 51 | // 80kbps, then we'll probe again at 1.6Mbps. In that case second probe won't be |
| 52 | // sent if we get 600kbps from the first one. |
| 53 | constexpr int kRepeatedProbeMinPercentage = 70; |
| 54 | |
| 55 | // If the bitrate drops to a factor |kBitrateDropThreshold| or lower |
| 56 | // and we recover within |kBitrateDropTimeoutMs|, then we'll send |
| 57 | // a probe at a fraction |kProbeFractionAfterDrop| of the original bitrate. |
| 58 | constexpr double kBitrateDropThreshold = 0.66; |
| 59 | constexpr int kBitrateDropTimeoutMs = 5000; |
| 60 | constexpr double kProbeFractionAfterDrop = 0.85; |
| 61 | |
| 62 | // Timeout for probing after leaving ALR. If the bitrate drops significantly, |
| 63 | // (as determined by the delay based estimator) and we leave ALR, then we will |
| 64 | // send a probe if we recover within |kLeftAlrTimeoutMs| ms. |
| 65 | constexpr int kAlrEndedTimeoutMs = 3000; |
| 66 | |
| 67 | // The expected uncertainty of probe result (as a fraction of the target probe |
| 68 | // This is a limit on how often probing can be done when there is a BW |
| 69 | // drop detected in ALR. |
| 70 | constexpr int64_t kMinTimeBetweenAlrProbesMs = 5000; |
| 71 | |
| 72 | // bitrate). Used to avoid probing if the probe bitrate is close to our current |
| 73 | // estimate. |
| 74 | constexpr double kProbeUncertainty = 0.05; |
| 75 | |
| 76 | // Use probing to recover faster after large bitrate estimate drops. |
| 77 | constexpr char kBweRapidRecoveryExperiment[] = |
| 78 | "WebRTC-BweRapidRecoveryExperiment"; |
| 79 | |
Erik Språng | cfe36ca | 2018-11-29 17:32:48 +0100 | [diff] [blame] | 80 | // Never probe higher than configured by OnMaxTotalAllocatedBitrate(). |
| 81 | constexpr char kCappedProbingFieldTrialName[] = "WebRTC-BweCappedProbing"; |
| 82 | |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 83 | } // namespace |
| 84 | |
Sebastian Jansson | 95edb03 | 2019-01-17 16:24:12 +0100 | [diff] [blame^] | 85 | ProbeController::ProbeController(const WebRtcKeyValueConfig* key_value_config) |
Erik Språng | cfe36ca | 2018-11-29 17:32:48 +0100 | [diff] [blame] | 86 | : enable_periodic_alr_probing_(false), |
| 87 | in_rapid_recovery_experiment_( |
Sebastian Jansson | 95edb03 | 2019-01-17 16:24:12 +0100 | [diff] [blame^] | 88 | key_value_config->Lookup(kBweRapidRecoveryExperiment) |
| 89 | .find("Enabled") == 0), |
Erik Språng | cfe36ca | 2018-11-29 17:32:48 +0100 | [diff] [blame] | 90 | limit_probes_with_allocateable_rate_( |
Sebastian Jansson | 95edb03 | 2019-01-17 16:24:12 +0100 | [diff] [blame^] | 91 | key_value_config->Lookup(kCappedProbingFieldTrialName) |
| 92 | .find("Disabled") != 0) { |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 93 | Reset(0); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | ProbeController::~ProbeController() {} |
| 97 | |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 98 | std::vector<ProbeClusterConfig> ProbeController::SetBitrates( |
| 99 | int64_t min_bitrate_bps, |
| 100 | int64_t start_bitrate_bps, |
| 101 | int64_t max_bitrate_bps, |
| 102 | int64_t at_time_ms) { |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 103 | if (start_bitrate_bps > 0) { |
| 104 | start_bitrate_bps_ = start_bitrate_bps; |
| 105 | estimated_bitrate_bps_ = start_bitrate_bps; |
| 106 | } else if (start_bitrate_bps_ == 0) { |
| 107 | start_bitrate_bps_ = min_bitrate_bps; |
| 108 | } |
| 109 | |
| 110 | // The reason we use the variable |old_max_bitrate_pbs| is because we |
| 111 | // need to set |max_bitrate_bps_| before we call InitiateProbing. |
| 112 | int64_t old_max_bitrate_bps = max_bitrate_bps_; |
| 113 | max_bitrate_bps_ = max_bitrate_bps; |
| 114 | |
| 115 | switch (state_) { |
| 116 | case State::kInit: |
| 117 | if (network_available_) |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 118 | return InitiateExponentialProbing(at_time_ms); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 119 | break; |
| 120 | |
| 121 | case State::kWaitingForProbingResult: |
| 122 | break; |
| 123 | |
| 124 | case State::kProbingComplete: |
| 125 | // If the new max bitrate is higher than the old max bitrate and the |
| 126 | // estimate is lower than the new max bitrate then initiate probing. |
| 127 | if (estimated_bitrate_bps_ != 0 && |
| 128 | old_max_bitrate_bps < max_bitrate_bps_ && |
| 129 | estimated_bitrate_bps_ < max_bitrate_bps_) { |
| 130 | // The assumption is that if we jump more than 20% in the bandwidth |
| 131 | // estimate or if the bandwidth estimate is within 90% of the new |
| 132 | // max bitrate then the probing attempt was successful. |
| 133 | mid_call_probing_succcess_threshold_ = |
| 134 | std::min(estimated_bitrate_bps_ * 1.2, max_bitrate_bps_ * 0.9); |
| 135 | mid_call_probing_waiting_for_result_ = true; |
| 136 | mid_call_probing_bitrate_bps_ = max_bitrate_bps_; |
| 137 | |
| 138 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.MidCallProbing.Initiated", |
| 139 | max_bitrate_bps_ / 1000); |
| 140 | |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 141 | return InitiateProbing(at_time_ms, {max_bitrate_bps}, false); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 142 | } |
| 143 | break; |
| 144 | } |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 145 | return std::vector<ProbeClusterConfig>(); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 146 | } |
| 147 | |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 148 | std::vector<ProbeClusterConfig> ProbeController::OnMaxTotalAllocatedBitrate( |
philipel | db4fa4b | 2018-03-06 18:29:22 +0100 | [diff] [blame] | 149 | int64_t max_total_allocated_bitrate, |
| 150 | int64_t at_time_ms) { |
philipel | 9fd6b98 | 2018-04-19 16:58:07 +0200 | [diff] [blame] | 151 | if (state_ == State::kProbingComplete && |
| 152 | max_total_allocated_bitrate != max_total_allocated_bitrate_ && |
philipel | 0676f22 | 2018-04-17 16:12:21 +0200 | [diff] [blame] | 153 | estimated_bitrate_bps_ != 0 && |
| 154 | (max_bitrate_bps_ <= 0 || estimated_bitrate_bps_ < max_bitrate_bps_) && |
philipel | db4fa4b | 2018-03-06 18:29:22 +0100 | [diff] [blame] | 155 | estimated_bitrate_bps_ < max_total_allocated_bitrate) { |
Sebastian Jansson | b2ecc3d | 2018-07-13 17:22:01 +0200 | [diff] [blame] | 156 | max_total_allocated_bitrate_ = max_total_allocated_bitrate; |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 157 | return InitiateProbing(at_time_ms, {max_total_allocated_bitrate}, false); |
philipel | db4fa4b | 2018-03-06 18:29:22 +0100 | [diff] [blame] | 158 | } |
Sebastian Jansson | f5e767d | 2018-10-15 13:24:31 +0200 | [diff] [blame] | 159 | max_total_allocated_bitrate_ = max_total_allocated_bitrate; |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 160 | return std::vector<ProbeClusterConfig>(); |
philipel | db4fa4b | 2018-03-06 18:29:22 +0100 | [diff] [blame] | 161 | } |
| 162 | |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 163 | std::vector<ProbeClusterConfig> ProbeController::OnNetworkAvailability( |
| 164 | NetworkAvailability msg) { |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 165 | network_available_ = msg.network_available; |
philipel | 9fd6b98 | 2018-04-19 16:58:07 +0200 | [diff] [blame] | 166 | |
| 167 | if (!network_available_ && state_ == State::kWaitingForProbingResult) { |
| 168 | state_ = State::kProbingComplete; |
| 169 | min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; |
| 170 | } |
| 171 | |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 172 | if (network_available_ && state_ == State::kInit && start_bitrate_bps_ > 0) |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 173 | return InitiateExponentialProbing(msg.at_time.ms()); |
| 174 | return std::vector<ProbeClusterConfig>(); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 175 | } |
| 176 | |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 177 | std::vector<ProbeClusterConfig> ProbeController::InitiateExponentialProbing( |
| 178 | int64_t at_time_ms) { |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 179 | RTC_DCHECK(network_available_); |
| 180 | RTC_DCHECK(state_ == State::kInit); |
| 181 | RTC_DCHECK_GT(start_bitrate_bps_, 0); |
| 182 | |
| 183 | // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of |
| 184 | // 1.2 Mbps to continue probing. |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 185 | return InitiateProbing( |
| 186 | at_time_ms, {3 * start_bitrate_bps_, 6 * start_bitrate_bps_}, true); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 187 | } |
| 188 | |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 189 | std::vector<ProbeClusterConfig> ProbeController::SetEstimatedBitrate( |
| 190 | int64_t bitrate_bps, |
| 191 | int64_t at_time_ms) { |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 192 | int64_t now_ms = at_time_ms; |
| 193 | |
| 194 | if (mid_call_probing_waiting_for_result_ && |
| 195 | bitrate_bps >= mid_call_probing_succcess_threshold_) { |
| 196 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.MidCallProbing.Success", |
| 197 | mid_call_probing_bitrate_bps_ / 1000); |
| 198 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.MidCallProbing.ProbedKbps", |
| 199 | bitrate_bps / 1000); |
| 200 | mid_call_probing_waiting_for_result_ = false; |
| 201 | } |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 202 | std::vector<ProbeClusterConfig> pending_probes; |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 203 | if (state_ == State::kWaitingForProbingResult) { |
| 204 | // Continue probing if probing results indicate channel has greater |
| 205 | // capacity. |
| 206 | RTC_LOG(LS_INFO) << "Measured bitrate: " << bitrate_bps |
| 207 | << " Minimum to probe further: " |
| 208 | << min_bitrate_to_probe_further_bps_; |
| 209 | |
| 210 | if (min_bitrate_to_probe_further_bps_ != kExponentialProbingDisabled && |
| 211 | bitrate_bps > min_bitrate_to_probe_further_bps_) { |
| 212 | // Double the probing bitrate. |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 213 | pending_probes = InitiateProbing(now_ms, {2 * bitrate_bps}, true); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
| 217 | if (bitrate_bps < kBitrateDropThreshold * estimated_bitrate_bps_) { |
| 218 | time_of_last_large_drop_ms_ = now_ms; |
| 219 | bitrate_before_last_large_drop_bps_ = estimated_bitrate_bps_; |
| 220 | } |
| 221 | |
| 222 | estimated_bitrate_bps_ = bitrate_bps; |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 223 | return pending_probes; |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | void ProbeController::EnablePeriodicAlrProbing(bool enable) { |
| 227 | enable_periodic_alr_probing_ = enable; |
| 228 | } |
| 229 | |
| 230 | void ProbeController::SetAlrStartTimeMs( |
Danil Chapovalov | 0040b66 | 2018-06-18 10:48:16 +0200 | [diff] [blame] | 231 | absl::optional<int64_t> alr_start_time_ms) { |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 232 | alr_start_time_ms_ = alr_start_time_ms; |
| 233 | } |
| 234 | void ProbeController::SetAlrEndedTimeMs(int64_t alr_end_time_ms) { |
| 235 | alr_end_time_ms_.emplace(alr_end_time_ms); |
| 236 | } |
| 237 | |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 238 | std::vector<ProbeClusterConfig> ProbeController::RequestProbe( |
| 239 | int64_t at_time_ms) { |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 240 | // Called once we have returned to normal state after a large drop in |
| 241 | // estimated bandwidth. The current response is to initiate a single probe |
| 242 | // session (if not already probing) at the previous bitrate. |
| 243 | // |
| 244 | // If the probe session fails, the assumption is that this drop was a |
| 245 | // real one from a competing flow or a network change. |
| 246 | bool in_alr = alr_start_time_ms_.has_value(); |
| 247 | bool alr_ended_recently = |
| 248 | (alr_end_time_ms_.has_value() && |
| 249 | at_time_ms - alr_end_time_ms_.value() < kAlrEndedTimeoutMs); |
| 250 | if (in_alr || alr_ended_recently || in_rapid_recovery_experiment_) { |
| 251 | if (state_ == State::kProbingComplete) { |
| 252 | uint32_t suggested_probe_bps = |
| 253 | kProbeFractionAfterDrop * bitrate_before_last_large_drop_bps_; |
| 254 | uint32_t min_expected_probe_result_bps = |
| 255 | (1 - kProbeUncertainty) * suggested_probe_bps; |
| 256 | int64_t time_since_drop_ms = at_time_ms - time_of_last_large_drop_ms_; |
| 257 | int64_t time_since_probe_ms = at_time_ms - last_bwe_drop_probing_time_ms_; |
| 258 | if (min_expected_probe_result_bps > estimated_bitrate_bps_ && |
| 259 | time_since_drop_ms < kBitrateDropTimeoutMs && |
| 260 | time_since_probe_ms > kMinTimeBetweenAlrProbesMs) { |
| 261 | RTC_LOG(LS_INFO) << "Detected big bandwidth drop, start probing."; |
| 262 | // Track how often we probe in response to bandwidth drop in ALR. |
| 263 | RTC_HISTOGRAM_COUNTS_10000( |
| 264 | "WebRTC.BWE.BweDropProbingIntervalInS", |
| 265 | (at_time_ms - last_bwe_drop_probing_time_ms_) / 1000); |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 266 | return InitiateProbing(at_time_ms, {suggested_probe_bps}, false); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 267 | last_bwe_drop_probing_time_ms_ = at_time_ms; |
| 268 | } |
| 269 | } |
| 270 | } |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 271 | return std::vector<ProbeClusterConfig>(); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 272 | } |
| 273 | |
Sebastian Jansson | 8d33c0c | 2018-10-22 10:22:03 +0200 | [diff] [blame] | 274 | std::vector<ProbeClusterConfig> ProbeController::InitiateCapacityProbing( |
| 275 | int64_t bitrate_bps, |
| 276 | int64_t at_time_ms) { |
| 277 | if (state_ != State::kWaitingForProbingResult) { |
| 278 | RTC_DCHECK(network_available_); |
| 279 | return InitiateProbing(at_time_ms, {2 * bitrate_bps}, true); |
| 280 | } |
| 281 | return std::vector<ProbeClusterConfig>(); |
| 282 | } |
| 283 | |
Erik Språng | 791d43c | 2019-01-08 15:46:06 +0100 | [diff] [blame] | 284 | void ProbeController::SetMaxBitrate(int64_t max_bitrate_bps) { |
| 285 | max_bitrate_bps_ = max_bitrate_bps; |
| 286 | } |
| 287 | |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 288 | void ProbeController::Reset(int64_t at_time_ms) { |
| 289 | network_available_ = true; |
| 290 | state_ = State::kInit; |
| 291 | min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; |
| 292 | time_last_probing_initiated_ms_ = 0; |
| 293 | estimated_bitrate_bps_ = 0; |
| 294 | start_bitrate_bps_ = 0; |
| 295 | max_bitrate_bps_ = 0; |
| 296 | int64_t now_ms = at_time_ms; |
| 297 | last_bwe_drop_probing_time_ms_ = now_ms; |
| 298 | alr_end_time_ms_.reset(); |
| 299 | mid_call_probing_waiting_for_result_ = false; |
| 300 | time_of_last_large_drop_ms_ = now_ms; |
| 301 | bitrate_before_last_large_drop_bps_ = 0; |
philipel | 0676f22 | 2018-04-17 16:12:21 +0200 | [diff] [blame] | 302 | max_total_allocated_bitrate_ = 0; |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 303 | } |
| 304 | |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 305 | std::vector<ProbeClusterConfig> ProbeController::Process(int64_t at_time_ms) { |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 306 | int64_t now_ms = at_time_ms; |
| 307 | |
| 308 | if (now_ms - time_last_probing_initiated_ms_ > |
| 309 | kMaxWaitingTimeForProbingResultMs) { |
| 310 | mid_call_probing_waiting_for_result_ = false; |
| 311 | |
| 312 | if (state_ == State::kWaitingForProbingResult) { |
| 313 | RTC_LOG(LS_INFO) << "kWaitingForProbingResult: timeout"; |
| 314 | state_ = State::kProbingComplete; |
| 315 | min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; |
| 316 | } |
| 317 | } |
| 318 | |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 319 | if (enable_periodic_alr_probing_ && state_ == State::kProbingComplete) { |
| 320 | // Probe bandwidth periodically when in ALR state. |
| 321 | if (alr_start_time_ms_ && estimated_bitrate_bps_ > 0) { |
| 322 | int64_t next_probe_time_ms = |
| 323 | std::max(*alr_start_time_ms_, time_last_probing_initiated_ms_) + |
| 324 | kAlrPeriodicProbingIntervalMs; |
| 325 | if (now_ms >= next_probe_time_ms) { |
| 326 | return InitiateProbing(now_ms, {estimated_bitrate_bps_ * 2}, true); |
| 327 | } |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 328 | } |
| 329 | } |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 330 | return std::vector<ProbeClusterConfig>(); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 331 | } |
| 332 | |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 333 | std::vector<ProbeClusterConfig> ProbeController::InitiateProbing( |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 334 | int64_t now_ms, |
| 335 | std::initializer_list<int64_t> bitrates_to_probe, |
| 336 | bool probe_further) { |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 337 | std::vector<ProbeClusterConfig> pending_probes; |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 338 | for (int64_t bitrate : bitrates_to_probe) { |
| 339 | RTC_DCHECK_GT(bitrate, 0); |
| 340 | int64_t max_probe_bitrate_bps = |
| 341 | max_bitrate_bps_ > 0 ? max_bitrate_bps_ : kDefaultMaxProbingBitrateBps; |
Erik Språng | cfe36ca | 2018-11-29 17:32:48 +0100 | [diff] [blame] | 342 | if (limit_probes_with_allocateable_rate_ && |
| 343 | max_total_allocated_bitrate_ > 0) { |
Erik Språng | 74fb822 | 2018-12-03 18:43:50 +0100 | [diff] [blame] | 344 | // If a max allocated bitrate has been configured, allow probing up to 2x |
| 345 | // that rate. This allows some overhead to account for bursty streams, |
| 346 | // which otherwise would have to ramp up when the overshoot is already in |
| 347 | // progress. |
| 348 | // It also avoids minor quality reduction caused by probes often being |
| 349 | // received at slightly less than the target probe bitrate. |
Erik Språng | cfe36ca | 2018-11-29 17:32:48 +0100 | [diff] [blame] | 350 | max_probe_bitrate_bps = |
Erik Språng | 74fb822 | 2018-12-03 18:43:50 +0100 | [diff] [blame] | 351 | std::min(max_probe_bitrate_bps, max_total_allocated_bitrate_ * 2); |
Erik Språng | cfe36ca | 2018-11-29 17:32:48 +0100 | [diff] [blame] | 352 | } |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 353 | if (bitrate > max_probe_bitrate_bps) { |
| 354 | bitrate = max_probe_bitrate_bps; |
| 355 | probe_further = false; |
| 356 | } |
| 357 | |
| 358 | ProbeClusterConfig config; |
| 359 | config.at_time = Timestamp::ms(now_ms); |
| 360 | config.target_data_rate = DataRate::bps(rtc::dchecked_cast<int>(bitrate)); |
| 361 | config.target_duration = TimeDelta::ms(kMinProbeDurationMs); |
| 362 | config.target_probe_count = kMinProbePacketsSent; |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 363 | pending_probes.push_back(config); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 364 | } |
| 365 | time_last_probing_initiated_ms_ = now_ms; |
| 366 | if (probe_further) { |
| 367 | state_ = State::kWaitingForProbingResult; |
| 368 | min_bitrate_to_probe_further_bps_ = |
| 369 | (*(bitrates_to_probe.end() - 1)) * kRepeatedProbeMinPercentage / 100; |
| 370 | } else { |
| 371 | state_ = State::kProbingComplete; |
| 372 | min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; |
| 373 | } |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 374 | return pending_probes; |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 375 | } |
| 376 | |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 377 | } // namespace webrtc |