blob: dfcb7f6fd5eebf81ce8f97a83e0d6f70adc9b73d [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
Jonas Olssone0960042019-03-12 13:49:26 +010076constexpr char kConfigurableProbingFieldTrialName[] =
77 "WebRTC-Bwe-ConfigurableProbing";
78
Piotr (Peter) Slatalac39f4622019-02-15 07:38:04 -080079void MaybeLogProbeClusterCreated(RtcEventLog* event_log,
80 const ProbeClusterConfig& probe) {
81 RTC_DCHECK(event_log);
82 if (!event_log) {
83 return;
84 }
85
86 size_t min_bytes = static_cast<int32_t>(probe.target_data_rate.bps() *
87 probe.target_duration.ms() / 8000);
88 event_log->Log(absl::make_unique<RtcEventProbeClusterCreated>(
89 probe.id, probe.target_data_rate.bps(), probe.target_probe_count,
90 min_bytes));
91}
92
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010093} // namespace
94
Jonas Olssone0960042019-03-12 13:49:26 +010095ProbeControllerConfig::ProbeControllerConfig(
96 const WebRtcKeyValueConfig* key_value_config)
97 : first_exponential_probe_scale_("p1", 3.0),
98 second_exponential_probe_scale_("p2", 6.0),
99 further_exponential_probe_scale_("step_size", 2),
100 further_probe_threshold("further_probe_threshold", 0.7),
101 alr_probing_interval_("alr_interval", TimeDelta::seconds(5)),
102 alr_probe_scale_("alr_scale", 2) {
103 ParseFieldTrial(
104 {&first_exponential_probe_scale_, &second_exponential_probe_scale_,
105 &further_exponential_probe_scale_, &further_probe_threshold,
106 &alr_probing_interval_, &alr_probe_scale_},
107 key_value_config->Lookup(kConfigurableProbingFieldTrialName));
108}
109
110ProbeControllerConfig::ProbeControllerConfig(const ProbeControllerConfig&) =
111 default;
112ProbeControllerConfig::~ProbeControllerConfig() = default;
113
Piotr (Peter) Slatalac39f4622019-02-15 07:38:04 -0800114ProbeController::ProbeController(const WebRtcKeyValueConfig* key_value_config,
115 RtcEventLog* event_log)
Erik Språngcfe36ca2018-11-29 17:32:48 +0100116 : enable_periodic_alr_probing_(false),
117 in_rapid_recovery_experiment_(
Sebastian Jansson95edb032019-01-17 16:24:12 +0100118 key_value_config->Lookup(kBweRapidRecoveryExperiment)
119 .find("Enabled") == 0),
Erik Språngcfe36ca2018-11-29 17:32:48 +0100120 limit_probes_with_allocateable_rate_(
Sebastian Jansson95edb032019-01-17 16:24:12 +0100121 key_value_config->Lookup(kCappedProbingFieldTrialName)
Piotr (Peter) Slatalac39f4622019-02-15 07:38:04 -0800122 .find("Disabled") != 0),
Jonas Olssone0960042019-03-12 13:49:26 +0100123 event_log_(event_log),
124 config_(ProbeControllerConfig(key_value_config)) {
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100125 Reset(0);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100126}
127
128ProbeController::~ProbeController() {}
129
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200130std::vector<ProbeClusterConfig> ProbeController::SetBitrates(
131 int64_t min_bitrate_bps,
132 int64_t start_bitrate_bps,
133 int64_t max_bitrate_bps,
134 int64_t at_time_ms) {
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100135 if (start_bitrate_bps > 0) {
136 start_bitrate_bps_ = start_bitrate_bps;
137 estimated_bitrate_bps_ = start_bitrate_bps;
138 } else if (start_bitrate_bps_ == 0) {
139 start_bitrate_bps_ = min_bitrate_bps;
140 }
141
142 // The reason we use the variable |old_max_bitrate_pbs| is because we
143 // need to set |max_bitrate_bps_| before we call InitiateProbing.
144 int64_t old_max_bitrate_bps = max_bitrate_bps_;
145 max_bitrate_bps_ = max_bitrate_bps;
146
147 switch (state_) {
148 case State::kInit:
149 if (network_available_)
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200150 return InitiateExponentialProbing(at_time_ms);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100151 break;
152
153 case State::kWaitingForProbingResult:
154 break;
155
156 case State::kProbingComplete:
Jonas Olssonf441ea92019-03-05 16:24:48 +0100157 // If the new max bitrate is higher than both the old max bitrate and the
158 // estimate then initiate probing.
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100159 if (estimated_bitrate_bps_ != 0 &&
160 old_max_bitrate_bps < max_bitrate_bps_ &&
161 estimated_bitrate_bps_ < max_bitrate_bps_) {
162 // The assumption is that if we jump more than 20% in the bandwidth
163 // estimate or if the bandwidth estimate is within 90% of the new
164 // max bitrate then the probing attempt was successful.
165 mid_call_probing_succcess_threshold_ =
166 std::min(estimated_bitrate_bps_ * 1.2, max_bitrate_bps_ * 0.9);
167 mid_call_probing_waiting_for_result_ = true;
168 mid_call_probing_bitrate_bps_ = max_bitrate_bps_;
169
170 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.MidCallProbing.Initiated",
171 max_bitrate_bps_ / 1000);
172
Jonas Olssonf441ea92019-03-05 16:24:48 +0100173 return InitiateProbing(at_time_ms, {max_bitrate_bps_}, false);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100174 }
175 break;
176 }
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200177 return std::vector<ProbeClusterConfig>();
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100178}
179
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200180std::vector<ProbeClusterConfig> ProbeController::OnMaxTotalAllocatedBitrate(
philipeldb4fa4b2018-03-06 18:29:22 +0100181 int64_t max_total_allocated_bitrate,
182 int64_t at_time_ms) {
philipel9fd6b982018-04-19 16:58:07 +0200183 if (state_ == State::kProbingComplete &&
184 max_total_allocated_bitrate != max_total_allocated_bitrate_ &&
philipel0676f222018-04-17 16:12:21 +0200185 estimated_bitrate_bps_ != 0 &&
186 (max_bitrate_bps_ <= 0 || estimated_bitrate_bps_ < max_bitrate_bps_) &&
philipeldb4fa4b2018-03-06 18:29:22 +0100187 estimated_bitrate_bps_ < max_total_allocated_bitrate) {
Sebastian Janssonb2ecc3d2018-07-13 17:22:01 +0200188 max_total_allocated_bitrate_ = max_total_allocated_bitrate;
Rasmus Brandt681de202019-02-04 15:09:34 +0100189 // Also probe at 2x the max bitrate, to account for the transmission max
190 // bitrate multiplier functionality of the BitrateAllocator.
191 return InitiateProbing(
192 at_time_ms,
193 {max_total_allocated_bitrate, 2 * max_total_allocated_bitrate}, false);
philipeldb4fa4b2018-03-06 18:29:22 +0100194 }
Sebastian Janssonf5e767d2018-10-15 13:24:31 +0200195 max_total_allocated_bitrate_ = max_total_allocated_bitrate;
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200196 return std::vector<ProbeClusterConfig>();
philipeldb4fa4b2018-03-06 18:29:22 +0100197}
198
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200199std::vector<ProbeClusterConfig> ProbeController::OnNetworkAvailability(
200 NetworkAvailability msg) {
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100201 network_available_ = msg.network_available;
philipel9fd6b982018-04-19 16:58:07 +0200202
203 if (!network_available_ && state_ == State::kWaitingForProbingResult) {
204 state_ = State::kProbingComplete;
205 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled;
206 }
207
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100208 if (network_available_ && state_ == State::kInit && start_bitrate_bps_ > 0)
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200209 return InitiateExponentialProbing(msg.at_time.ms());
210 return std::vector<ProbeClusterConfig>();
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100211}
212
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200213std::vector<ProbeClusterConfig> ProbeController::InitiateExponentialProbing(
214 int64_t at_time_ms) {
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100215 RTC_DCHECK(network_available_);
216 RTC_DCHECK(state_ == State::kInit);
217 RTC_DCHECK_GT(start_bitrate_bps_, 0);
218
219 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of
220 // 1.2 Mbps to continue probing.
Jonas Olssone0960042019-03-12 13:49:26 +0100221 std::vector<int64_t> probes = {static_cast<int64_t>(
222 config_.first_exponential_probe_scale_ * start_bitrate_bps_)};
223 if (config_.second_exponential_probe_scale_) {
224 probes.push_back(config_.second_exponential_probe_scale_.Value() *
225 start_bitrate_bps_);
226 }
227 return InitiateProbing(at_time_ms, probes, true);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100228}
229
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200230std::vector<ProbeClusterConfig> ProbeController::SetEstimatedBitrate(
231 int64_t bitrate_bps,
232 int64_t at_time_ms) {
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100233 if (mid_call_probing_waiting_for_result_ &&
234 bitrate_bps >= mid_call_probing_succcess_threshold_) {
235 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.MidCallProbing.Success",
236 mid_call_probing_bitrate_bps_ / 1000);
237 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.MidCallProbing.ProbedKbps",
238 bitrate_bps / 1000);
239 mid_call_probing_waiting_for_result_ = false;
240 }
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200241 std::vector<ProbeClusterConfig> pending_probes;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100242 if (state_ == State::kWaitingForProbingResult) {
243 // Continue probing if probing results indicate channel has greater
244 // capacity.
245 RTC_LOG(LS_INFO) << "Measured bitrate: " << bitrate_bps
246 << " Minimum to probe further: "
247 << min_bitrate_to_probe_further_bps_;
248
249 if (min_bitrate_to_probe_further_bps_ != kExponentialProbingDisabled &&
250 bitrate_bps > min_bitrate_to_probe_further_bps_) {
Jonas Olssone0960042019-03-12 13:49:26 +0100251 pending_probes = InitiateProbing(
252 at_time_ms,
253 {static_cast<int64_t>(config_.further_exponential_probe_scale_ *
254 bitrate_bps)},
255 true);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100256 }
257 }
258
259 if (bitrate_bps < kBitrateDropThreshold * estimated_bitrate_bps_) {
Jonas Olssonf441ea92019-03-05 16:24:48 +0100260 time_of_last_large_drop_ms_ = at_time_ms;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100261 bitrate_before_last_large_drop_bps_ = estimated_bitrate_bps_;
262 }
263
264 estimated_bitrate_bps_ = bitrate_bps;
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200265 return pending_probes;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100266}
267
268void ProbeController::EnablePeriodicAlrProbing(bool enable) {
269 enable_periodic_alr_probing_ = enable;
270}
271
272void ProbeController::SetAlrStartTimeMs(
Danil Chapovalov0040b662018-06-18 10:48:16 +0200273 absl::optional<int64_t> alr_start_time_ms) {
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100274 alr_start_time_ms_ = alr_start_time_ms;
275}
276void ProbeController::SetAlrEndedTimeMs(int64_t alr_end_time_ms) {
277 alr_end_time_ms_.emplace(alr_end_time_ms);
278}
279
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200280std::vector<ProbeClusterConfig> ProbeController::RequestProbe(
281 int64_t at_time_ms) {
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100282 // Called once we have returned to normal state after a large drop in
283 // estimated bandwidth. The current response is to initiate a single probe
284 // session (if not already probing) at the previous bitrate.
285 //
286 // If the probe session fails, the assumption is that this drop was a
287 // real one from a competing flow or a network change.
288 bool in_alr = alr_start_time_ms_.has_value();
289 bool alr_ended_recently =
290 (alr_end_time_ms_.has_value() &&
291 at_time_ms - alr_end_time_ms_.value() < kAlrEndedTimeoutMs);
292 if (in_alr || alr_ended_recently || in_rapid_recovery_experiment_) {
293 if (state_ == State::kProbingComplete) {
294 uint32_t suggested_probe_bps =
295 kProbeFractionAfterDrop * bitrate_before_last_large_drop_bps_;
296 uint32_t min_expected_probe_result_bps =
297 (1 - kProbeUncertainty) * suggested_probe_bps;
298 int64_t time_since_drop_ms = at_time_ms - time_of_last_large_drop_ms_;
299 int64_t time_since_probe_ms = at_time_ms - last_bwe_drop_probing_time_ms_;
300 if (min_expected_probe_result_bps > estimated_bitrate_bps_ &&
301 time_since_drop_ms < kBitrateDropTimeoutMs &&
302 time_since_probe_ms > kMinTimeBetweenAlrProbesMs) {
303 RTC_LOG(LS_INFO) << "Detected big bandwidth drop, start probing.";
304 // Track how often we probe in response to bandwidth drop in ALR.
305 RTC_HISTOGRAM_COUNTS_10000(
306 "WebRTC.BWE.BweDropProbingIntervalInS",
307 (at_time_ms - last_bwe_drop_probing_time_ms_) / 1000);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100308 last_bwe_drop_probing_time_ms_ = at_time_ms;
Sebastian Janssonc9d0b082019-02-26 15:29:53 +0100309 return InitiateProbing(at_time_ms, {suggested_probe_bps}, false);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100310 }
311 }
312 }
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200313 return std::vector<ProbeClusterConfig>();
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100314}
315
Erik Språng791d43c2019-01-08 15:46:06 +0100316void ProbeController::SetMaxBitrate(int64_t max_bitrate_bps) {
317 max_bitrate_bps_ = max_bitrate_bps;
318}
319
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100320void ProbeController::Reset(int64_t at_time_ms) {
321 network_available_ = true;
322 state_ = State::kInit;
323 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled;
324 time_last_probing_initiated_ms_ = 0;
325 estimated_bitrate_bps_ = 0;
326 start_bitrate_bps_ = 0;
327 max_bitrate_bps_ = 0;
328 int64_t now_ms = at_time_ms;
329 last_bwe_drop_probing_time_ms_ = now_ms;
330 alr_end_time_ms_.reset();
331 mid_call_probing_waiting_for_result_ = false;
332 time_of_last_large_drop_ms_ = now_ms;
333 bitrate_before_last_large_drop_bps_ = 0;
philipel0676f222018-04-17 16:12:21 +0200334 max_total_allocated_bitrate_ = 0;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100335}
336
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200337std::vector<ProbeClusterConfig> ProbeController::Process(int64_t at_time_ms) {
Jonas Olssonf441ea92019-03-05 16:24:48 +0100338 if (at_time_ms - time_last_probing_initiated_ms_ >
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100339 kMaxWaitingTimeForProbingResultMs) {
340 mid_call_probing_waiting_for_result_ = false;
341
342 if (state_ == State::kWaitingForProbingResult) {
343 RTC_LOG(LS_INFO) << "kWaitingForProbingResult: timeout";
344 state_ = State::kProbingComplete;
345 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled;
346 }
347 }
348
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200349 if (enable_periodic_alr_probing_ && state_ == State::kProbingComplete) {
350 // Probe bandwidth periodically when in ALR state.
351 if (alr_start_time_ms_ && estimated_bitrate_bps_ > 0) {
352 int64_t next_probe_time_ms =
353 std::max(*alr_start_time_ms_, time_last_probing_initiated_ms_) +
Jonas Olssone0960042019-03-12 13:49:26 +0100354 config_.alr_probing_interval_->ms();
Jonas Olssonf441ea92019-03-05 16:24:48 +0100355 if (at_time_ms >= next_probe_time_ms) {
Jonas Olssone0960042019-03-12 13:49:26 +0100356 return InitiateProbing(at_time_ms,
357 {static_cast<int64_t>(estimated_bitrate_bps_ *
358 config_.alr_probe_scale_)},
359 true);
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200360 }
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100361 }
362 }
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200363 return std::vector<ProbeClusterConfig>();
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100364}
365
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200366std::vector<ProbeClusterConfig> ProbeController::InitiateProbing(
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100367 int64_t now_ms,
Jonas Olssone0960042019-03-12 13:49:26 +0100368 std::vector<int64_t> bitrates_to_probe,
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100369 bool probe_further) {
Jonas Olssonf441ea92019-03-05 16:24:48 +0100370 int64_t max_probe_bitrate_bps =
371 max_bitrate_bps_ > 0 ? max_bitrate_bps_ : kDefaultMaxProbingBitrateBps;
372 if (limit_probes_with_allocateable_rate_ &&
373 max_total_allocated_bitrate_ > 0) {
374 // If a max allocated bitrate has been configured, allow probing up to 2x
375 // that rate. This allows some overhead to account for bursty streams,
376 // which otherwise would have to ramp up when the overshoot is already in
377 // progress.
378 // It also avoids minor quality reduction caused by probes often being
379 // received at slightly less than the target probe bitrate.
380 max_probe_bitrate_bps =
381 std::min(max_probe_bitrate_bps, max_total_allocated_bitrate_ * 2);
382 }
383
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200384 std::vector<ProbeClusterConfig> pending_probes;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100385 for (int64_t bitrate : bitrates_to_probe) {
386 RTC_DCHECK_GT(bitrate, 0);
Jonas Olssonf441ea92019-03-05 16:24:48 +0100387
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100388 if (bitrate > max_probe_bitrate_bps) {
389 bitrate = max_probe_bitrate_bps;
390 probe_further = false;
391 }
392
393 ProbeClusterConfig config;
394 config.at_time = Timestamp::ms(now_ms);
395 config.target_data_rate = DataRate::bps(rtc::dchecked_cast<int>(bitrate));
396 config.target_duration = TimeDelta::ms(kMinProbeDurationMs);
397 config.target_probe_count = kMinProbePacketsSent;
Piotr (Peter) Slatalac39f4622019-02-15 07:38:04 -0800398 config.id = next_probe_cluster_id_;
399 next_probe_cluster_id_++;
400 MaybeLogProbeClusterCreated(event_log_, config);
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200401 pending_probes.push_back(config);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100402 }
403 time_last_probing_initiated_ms_ = now_ms;
404 if (probe_further) {
405 state_ = State::kWaitingForProbingResult;
406 min_bitrate_to_probe_further_bps_ =
Jonas Olssone0960042019-03-12 13:49:26 +0100407 (*(bitrates_to_probe.end() - 1)) * config_.further_probe_threshold;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100408 } else {
409 state_ = State::kProbingComplete;
410 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled;
411 }
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200412 return pending_probes;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100413}
414
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100415} // namespace webrtc