blob: e5a6d1fd01e665ab14b7d276f616ce6999e5e7bc [file] [log] [blame]
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +01001/*
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 Janssonfc7ec8e2018-02-28 16:48:00 +010011#include "modules/congestion_controller/goog_cc/probe_controller.h"
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010012
13#include <algorithm>
14#include <initializer_list>
Yves Gerey3e707812018-11-28 16:47:49 +010015#include <string>
Piotr (Peter) Slatalac39f4622019-02-15 07:38:04 -080016#include "absl/memory/memory.h"
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010017
Yves Gerey3e707812018-11-28 16:47:49 +010018#include "api/units/data_rate.h"
19#include "api/units/time_delta.h"
20#include "api/units/timestamp.h"
Piotr (Peter) Slatalac39f4622019-02-15 07:38:04 -080021#include "logging/rtc_event_log/events/rtc_event_probe_cluster_created.h"
Yves Gerey3e707812018-11-28 16:47:49 +010022#include "rtc_base/checks.h"
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010023#include "rtc_base/logging.h"
24#include "rtc_base/numerics/safe_conversions.h"
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010025#include "system_wrappers/include/metrics.h"
26
27namespace webrtc {
28
29namespace {
30// The minimum number probing packets used.
31constexpr int kMinProbePacketsSent = 5;
32
33// The minimum probing duration in ms.
34constexpr int kMinProbeDurationMs = 15;
35
36// Maximum waiting time from the time of initiating probing to getting
37// the measured results back.
38constexpr int64_t kMaxWaitingTimeForProbingResultMs = 1000;
39
40// Value of |min_bitrate_to_probe_further_bps_| that indicates
41// further probing is disabled.
42constexpr int kExponentialProbingDisabled = 0;
43
44// Default probing bitrate limit. Applied only when the application didn't
45// specify max bitrate.
46constexpr int64_t kDefaultMaxProbingBitrateBps = 5000000;
47
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010048// If the bitrate drops to a factor |kBitrateDropThreshold| or lower
49// and we recover within |kBitrateDropTimeoutMs|, then we'll send
50// a probe at a fraction |kProbeFractionAfterDrop| of the original bitrate.
51constexpr double kBitrateDropThreshold = 0.66;
52constexpr int kBitrateDropTimeoutMs = 5000;
53constexpr double kProbeFractionAfterDrop = 0.85;
54
55// Timeout for probing after leaving ALR. If the bitrate drops significantly,
56// (as determined by the delay based estimator) and we leave ALR, then we will
57// send a probe if we recover within |kLeftAlrTimeoutMs| ms.
58constexpr int kAlrEndedTimeoutMs = 3000;
59
60// The expected uncertainty of probe result (as a fraction of the target probe
61// This is a limit on how often probing can be done when there is a BW
62// drop detected in ALR.
63constexpr int64_t kMinTimeBetweenAlrProbesMs = 5000;
64
65// bitrate). Used to avoid probing if the probe bitrate is close to our current
66// estimate.
67constexpr double kProbeUncertainty = 0.05;
68
69// Use probing to recover faster after large bitrate estimate drops.
70constexpr char kBweRapidRecoveryExperiment[] =
71 "WebRTC-BweRapidRecoveryExperiment";
72
Erik Språngcfe36ca2018-11-29 17:32:48 +010073// Never probe higher than configured by OnMaxTotalAllocatedBitrate().
74constexpr char kCappedProbingFieldTrialName[] = "WebRTC-BweCappedProbing";
75
Piotr (Peter) Slatalac39f4622019-02-15 07:38:04 -080076void MaybeLogProbeClusterCreated(RtcEventLog* event_log,
77 const ProbeClusterConfig& probe) {
78 RTC_DCHECK(event_log);
79 if (!event_log) {
80 return;
81 }
82
83 size_t min_bytes = static_cast<int32_t>(probe.target_data_rate.bps() *
84 probe.target_duration.ms() / 8000);
85 event_log->Log(absl::make_unique<RtcEventProbeClusterCreated>(
86 probe.id, probe.target_data_rate.bps(), probe.target_probe_count,
87 min_bytes));
88}
89
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010090} // namespace
91
Jonas Olssone0960042019-03-12 13:49:26 +010092ProbeControllerConfig::ProbeControllerConfig(
93 const WebRtcKeyValueConfig* key_value_config)
94 : first_exponential_probe_scale_("p1", 3.0),
95 second_exponential_probe_scale_("p2", 6.0),
96 further_exponential_probe_scale_("step_size", 2),
97 further_probe_threshold("further_probe_threshold", 0.7),
98 alr_probing_interval_("alr_interval", TimeDelta::seconds(5)),
99 alr_probe_scale_("alr_scale", 2) {
100 ParseFieldTrial(
101 {&first_exponential_probe_scale_, &second_exponential_probe_scale_,
102 &further_exponential_probe_scale_, &further_probe_threshold,
103 &alr_probing_interval_, &alr_probe_scale_},
Jonas Olsson24923e82019-03-27 14:19:04 +0100104 key_value_config->Lookup("WebRTC-Bwe-ProbingConfiguration"));
Jonas Olssone0960042019-03-12 13:49:26 +0100105}
106
107ProbeControllerConfig::ProbeControllerConfig(const ProbeControllerConfig&) =
108 default;
109ProbeControllerConfig::~ProbeControllerConfig() = default;
110
Piotr (Peter) Slatalac39f4622019-02-15 07:38:04 -0800111ProbeController::ProbeController(const WebRtcKeyValueConfig* key_value_config,
112 RtcEventLog* event_log)
Erik Språngcfe36ca2018-11-29 17:32:48 +0100113 : enable_periodic_alr_probing_(false),
114 in_rapid_recovery_experiment_(
Sebastian Jansson95edb032019-01-17 16:24:12 +0100115 key_value_config->Lookup(kBweRapidRecoveryExperiment)
116 .find("Enabled") == 0),
Erik Språngcfe36ca2018-11-29 17:32:48 +0100117 limit_probes_with_allocateable_rate_(
Sebastian Jansson95edb032019-01-17 16:24:12 +0100118 key_value_config->Lookup(kCappedProbingFieldTrialName)
Piotr (Peter) Slatalac39f4622019-02-15 07:38:04 -0800119 .find("Disabled") != 0),
Jonas Olssone0960042019-03-12 13:49:26 +0100120 event_log_(event_log),
121 config_(ProbeControllerConfig(key_value_config)) {
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100122 Reset(0);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100123}
124
125ProbeController::~ProbeController() {}
126
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200127std::vector<ProbeClusterConfig> ProbeController::SetBitrates(
128 int64_t min_bitrate_bps,
129 int64_t start_bitrate_bps,
130 int64_t max_bitrate_bps,
131 int64_t at_time_ms) {
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100132 if (start_bitrate_bps > 0) {
133 start_bitrate_bps_ = start_bitrate_bps;
134 estimated_bitrate_bps_ = start_bitrate_bps;
135 } else if (start_bitrate_bps_ == 0) {
136 start_bitrate_bps_ = min_bitrate_bps;
137 }
138
139 // The reason we use the variable |old_max_bitrate_pbs| is because we
140 // need to set |max_bitrate_bps_| before we call InitiateProbing.
141 int64_t old_max_bitrate_bps = max_bitrate_bps_;
142 max_bitrate_bps_ = max_bitrate_bps;
143
144 switch (state_) {
145 case State::kInit:
146 if (network_available_)
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200147 return InitiateExponentialProbing(at_time_ms);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100148 break;
149
150 case State::kWaitingForProbingResult:
151 break;
152
153 case State::kProbingComplete:
Jonas Olssonf441ea92019-03-05 16:24:48 +0100154 // If the new max bitrate is higher than both the old max bitrate and the
155 // estimate then initiate probing.
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100156 if (estimated_bitrate_bps_ != 0 &&
157 old_max_bitrate_bps < max_bitrate_bps_ &&
158 estimated_bitrate_bps_ < max_bitrate_bps_) {
159 // The assumption is that if we jump more than 20% in the bandwidth
160 // estimate or if the bandwidth estimate is within 90% of the new
161 // max bitrate then the probing attempt was successful.
162 mid_call_probing_succcess_threshold_ =
163 std::min(estimated_bitrate_bps_ * 1.2, max_bitrate_bps_ * 0.9);
164 mid_call_probing_waiting_for_result_ = true;
165 mid_call_probing_bitrate_bps_ = max_bitrate_bps_;
166
167 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.MidCallProbing.Initiated",
168 max_bitrate_bps_ / 1000);
169
Jonas Olssonf441ea92019-03-05 16:24:48 +0100170 return InitiateProbing(at_time_ms, {max_bitrate_bps_}, false);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100171 }
172 break;
173 }
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200174 return std::vector<ProbeClusterConfig>();
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100175}
176
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200177std::vector<ProbeClusterConfig> ProbeController::OnMaxTotalAllocatedBitrate(
philipeldb4fa4b2018-03-06 18:29:22 +0100178 int64_t max_total_allocated_bitrate,
179 int64_t at_time_ms) {
philipel9fd6b982018-04-19 16:58:07 +0200180 if (state_ == State::kProbingComplete &&
181 max_total_allocated_bitrate != max_total_allocated_bitrate_ &&
philipel0676f222018-04-17 16:12:21 +0200182 estimated_bitrate_bps_ != 0 &&
183 (max_bitrate_bps_ <= 0 || estimated_bitrate_bps_ < max_bitrate_bps_) &&
philipeldb4fa4b2018-03-06 18:29:22 +0100184 estimated_bitrate_bps_ < max_total_allocated_bitrate) {
Sebastian Janssonb2ecc3d2018-07-13 17:22:01 +0200185 max_total_allocated_bitrate_ = max_total_allocated_bitrate;
Rasmus Brandt681de202019-02-04 15:09:34 +0100186 // Also probe at 2x the max bitrate, to account for the transmission max
187 // bitrate multiplier functionality of the BitrateAllocator.
188 return InitiateProbing(
189 at_time_ms,
190 {max_total_allocated_bitrate, 2 * max_total_allocated_bitrate}, false);
philipeldb4fa4b2018-03-06 18:29:22 +0100191 }
Sebastian Janssonf5e767d2018-10-15 13:24:31 +0200192 max_total_allocated_bitrate_ = max_total_allocated_bitrate;
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200193 return std::vector<ProbeClusterConfig>();
philipeldb4fa4b2018-03-06 18:29:22 +0100194}
195
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200196std::vector<ProbeClusterConfig> ProbeController::OnNetworkAvailability(
197 NetworkAvailability msg) {
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100198 network_available_ = msg.network_available;
philipel9fd6b982018-04-19 16:58:07 +0200199
200 if (!network_available_ && state_ == State::kWaitingForProbingResult) {
201 state_ = State::kProbingComplete;
202 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled;
203 }
204
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100205 if (network_available_ && state_ == State::kInit && start_bitrate_bps_ > 0)
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200206 return InitiateExponentialProbing(msg.at_time.ms());
207 return std::vector<ProbeClusterConfig>();
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100208}
209
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200210std::vector<ProbeClusterConfig> ProbeController::InitiateExponentialProbing(
211 int64_t at_time_ms) {
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100212 RTC_DCHECK(network_available_);
213 RTC_DCHECK(state_ == State::kInit);
214 RTC_DCHECK_GT(start_bitrate_bps_, 0);
215
216 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of
217 // 1.2 Mbps to continue probing.
Jonas Olssone0960042019-03-12 13:49:26 +0100218 std::vector<int64_t> probes = {static_cast<int64_t>(
219 config_.first_exponential_probe_scale_ * start_bitrate_bps_)};
220 if (config_.second_exponential_probe_scale_) {
221 probes.push_back(config_.second_exponential_probe_scale_.Value() *
222 start_bitrate_bps_);
223 }
224 return InitiateProbing(at_time_ms, probes, true);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100225}
226
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200227std::vector<ProbeClusterConfig> ProbeController::SetEstimatedBitrate(
228 int64_t bitrate_bps,
229 int64_t at_time_ms) {
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100230 if (mid_call_probing_waiting_for_result_ &&
231 bitrate_bps >= mid_call_probing_succcess_threshold_) {
232 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.MidCallProbing.Success",
233 mid_call_probing_bitrate_bps_ / 1000);
234 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.MidCallProbing.ProbedKbps",
235 bitrate_bps / 1000);
236 mid_call_probing_waiting_for_result_ = false;
237 }
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200238 std::vector<ProbeClusterConfig> pending_probes;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100239 if (state_ == State::kWaitingForProbingResult) {
240 // Continue probing if probing results indicate channel has greater
241 // capacity.
242 RTC_LOG(LS_INFO) << "Measured bitrate: " << bitrate_bps
243 << " Minimum to probe further: "
244 << min_bitrate_to_probe_further_bps_;
245
246 if (min_bitrate_to_probe_further_bps_ != kExponentialProbingDisabled &&
247 bitrate_bps > min_bitrate_to_probe_further_bps_) {
Jonas Olssone0960042019-03-12 13:49:26 +0100248 pending_probes = InitiateProbing(
249 at_time_ms,
250 {static_cast<int64_t>(config_.further_exponential_probe_scale_ *
251 bitrate_bps)},
252 true);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100253 }
254 }
255
256 if (bitrate_bps < kBitrateDropThreshold * estimated_bitrate_bps_) {
Jonas Olssonf441ea92019-03-05 16:24:48 +0100257 time_of_last_large_drop_ms_ = at_time_ms;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100258 bitrate_before_last_large_drop_bps_ = estimated_bitrate_bps_;
259 }
260
261 estimated_bitrate_bps_ = bitrate_bps;
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200262 return pending_probes;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100263}
264
265void ProbeController::EnablePeriodicAlrProbing(bool enable) {
266 enable_periodic_alr_probing_ = enable;
267}
268
269void ProbeController::SetAlrStartTimeMs(
Danil Chapovalov0040b662018-06-18 10:48:16 +0200270 absl::optional<int64_t> alr_start_time_ms) {
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100271 alr_start_time_ms_ = alr_start_time_ms;
272}
273void ProbeController::SetAlrEndedTimeMs(int64_t alr_end_time_ms) {
274 alr_end_time_ms_.emplace(alr_end_time_ms);
275}
276
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200277std::vector<ProbeClusterConfig> ProbeController::RequestProbe(
278 int64_t at_time_ms) {
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100279 // Called once we have returned to normal state after a large drop in
280 // estimated bandwidth. The current response is to initiate a single probe
281 // session (if not already probing) at the previous bitrate.
282 //
283 // If the probe session fails, the assumption is that this drop was a
284 // real one from a competing flow or a network change.
285 bool in_alr = alr_start_time_ms_.has_value();
286 bool alr_ended_recently =
287 (alr_end_time_ms_.has_value() &&
288 at_time_ms - alr_end_time_ms_.value() < kAlrEndedTimeoutMs);
289 if (in_alr || alr_ended_recently || in_rapid_recovery_experiment_) {
290 if (state_ == State::kProbingComplete) {
291 uint32_t suggested_probe_bps =
292 kProbeFractionAfterDrop * bitrate_before_last_large_drop_bps_;
293 uint32_t min_expected_probe_result_bps =
294 (1 - kProbeUncertainty) * suggested_probe_bps;
295 int64_t time_since_drop_ms = at_time_ms - time_of_last_large_drop_ms_;
296 int64_t time_since_probe_ms = at_time_ms - last_bwe_drop_probing_time_ms_;
297 if (min_expected_probe_result_bps > estimated_bitrate_bps_ &&
298 time_since_drop_ms < kBitrateDropTimeoutMs &&
299 time_since_probe_ms > kMinTimeBetweenAlrProbesMs) {
300 RTC_LOG(LS_INFO) << "Detected big bandwidth drop, start probing.";
301 // Track how often we probe in response to bandwidth drop in ALR.
302 RTC_HISTOGRAM_COUNTS_10000(
303 "WebRTC.BWE.BweDropProbingIntervalInS",
304 (at_time_ms - last_bwe_drop_probing_time_ms_) / 1000);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100305 last_bwe_drop_probing_time_ms_ = at_time_ms;
Sebastian Janssonc9d0b082019-02-26 15:29:53 +0100306 return InitiateProbing(at_time_ms, {suggested_probe_bps}, false);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100307 }
308 }
309 }
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200310 return std::vector<ProbeClusterConfig>();
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100311}
312
Erik Språng791d43c2019-01-08 15:46:06 +0100313void ProbeController::SetMaxBitrate(int64_t max_bitrate_bps) {
314 max_bitrate_bps_ = max_bitrate_bps;
315}
316
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100317void ProbeController::Reset(int64_t at_time_ms) {
318 network_available_ = true;
319 state_ = State::kInit;
320 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled;
321 time_last_probing_initiated_ms_ = 0;
322 estimated_bitrate_bps_ = 0;
323 start_bitrate_bps_ = 0;
324 max_bitrate_bps_ = 0;
325 int64_t now_ms = at_time_ms;
326 last_bwe_drop_probing_time_ms_ = now_ms;
327 alr_end_time_ms_.reset();
328 mid_call_probing_waiting_for_result_ = false;
329 time_of_last_large_drop_ms_ = now_ms;
330 bitrate_before_last_large_drop_bps_ = 0;
philipel0676f222018-04-17 16:12:21 +0200331 max_total_allocated_bitrate_ = 0;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100332}
333
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200334std::vector<ProbeClusterConfig> ProbeController::Process(int64_t at_time_ms) {
Jonas Olssonf441ea92019-03-05 16:24:48 +0100335 if (at_time_ms - time_last_probing_initiated_ms_ >
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100336 kMaxWaitingTimeForProbingResultMs) {
337 mid_call_probing_waiting_for_result_ = false;
338
339 if (state_ == State::kWaitingForProbingResult) {
340 RTC_LOG(LS_INFO) << "kWaitingForProbingResult: timeout";
341 state_ = State::kProbingComplete;
342 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled;
343 }
344 }
345
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200346 if (enable_periodic_alr_probing_ && state_ == State::kProbingComplete) {
347 // Probe bandwidth periodically when in ALR state.
348 if (alr_start_time_ms_ && estimated_bitrate_bps_ > 0) {
349 int64_t next_probe_time_ms =
350 std::max(*alr_start_time_ms_, time_last_probing_initiated_ms_) +
Jonas Olssone0960042019-03-12 13:49:26 +0100351 config_.alr_probing_interval_->ms();
Jonas Olssonf441ea92019-03-05 16:24:48 +0100352 if (at_time_ms >= next_probe_time_ms) {
Jonas Olssone0960042019-03-12 13:49:26 +0100353 return InitiateProbing(at_time_ms,
354 {static_cast<int64_t>(estimated_bitrate_bps_ *
355 config_.alr_probe_scale_)},
356 true);
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200357 }
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100358 }
359 }
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200360 return std::vector<ProbeClusterConfig>();
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100361}
362
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200363std::vector<ProbeClusterConfig> ProbeController::InitiateProbing(
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100364 int64_t now_ms,
Jonas Olssone0960042019-03-12 13:49:26 +0100365 std::vector<int64_t> bitrates_to_probe,
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100366 bool probe_further) {
Jonas Olssonf441ea92019-03-05 16:24:48 +0100367 int64_t max_probe_bitrate_bps =
368 max_bitrate_bps_ > 0 ? max_bitrate_bps_ : kDefaultMaxProbingBitrateBps;
369 if (limit_probes_with_allocateable_rate_ &&
370 max_total_allocated_bitrate_ > 0) {
371 // If a max allocated bitrate has been configured, allow probing up to 2x
372 // that rate. This allows some overhead to account for bursty streams,
373 // which otherwise would have to ramp up when the overshoot is already in
374 // progress.
375 // It also avoids minor quality reduction caused by probes often being
376 // received at slightly less than the target probe bitrate.
377 max_probe_bitrate_bps =
378 std::min(max_probe_bitrate_bps, max_total_allocated_bitrate_ * 2);
379 }
380
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200381 std::vector<ProbeClusterConfig> pending_probes;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100382 for (int64_t bitrate : bitrates_to_probe) {
383 RTC_DCHECK_GT(bitrate, 0);
Jonas Olssonf441ea92019-03-05 16:24:48 +0100384
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100385 if (bitrate > max_probe_bitrate_bps) {
386 bitrate = max_probe_bitrate_bps;
387 probe_further = false;
388 }
389
390 ProbeClusterConfig config;
391 config.at_time = Timestamp::ms(now_ms);
392 config.target_data_rate = DataRate::bps(rtc::dchecked_cast<int>(bitrate));
393 config.target_duration = TimeDelta::ms(kMinProbeDurationMs);
394 config.target_probe_count = kMinProbePacketsSent;
Piotr (Peter) Slatalac39f4622019-02-15 07:38:04 -0800395 config.id = next_probe_cluster_id_;
396 next_probe_cluster_id_++;
397 MaybeLogProbeClusterCreated(event_log_, config);
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200398 pending_probes.push_back(config);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100399 }
400 time_last_probing_initiated_ms_ = now_ms;
401 if (probe_further) {
402 state_ = State::kWaitingForProbingResult;
403 min_bitrate_to_probe_further_bps_ =
Jonas Olssone0960042019-03-12 13:49:26 +0100404 (*(bitrates_to_probe.end() - 1)) * config_.further_probe_threshold;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100405 } else {
406 state_ = State::kProbingComplete;
407 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled;
408 }
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200409 return pending_probes;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100410}
411
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100412} // namespace webrtc