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