blob: 7f24ff98c8ad569746102c4f478b98163cf09b39 [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#ifndef MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_CONTROLLER_H_
12#define MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_CONTROLLER_H_
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010013
14#include <stdint.h>
15
16#include <initializer_list>
Sebastian Janssonf2e3e7a2018-04-06 17:16:06 +020017#include <vector>
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010018
Danil Chapovalov098da172021-01-14 16:15:31 +010019#include "absl/base/attributes.h"
Danil Chapovalov0040b662018-06-18 10:48:16 +020020#include "absl/types/optional.h"
Danil Chapovalov83bbe912019-08-07 12:24:53 +020021#include "api/rtc_event_log/rtc_event_log.h"
Sebastian Janssonc6c44262018-05-09 10:33:39 +020022#include "api/transport/network_control.h"
Sebastian Jansson95edb032019-01-17 16:24:12 +010023#include "api/transport/webrtc_key_value_config.h"
Christoffer Rodbro377f5a22020-02-12 10:11:13 +010024#include "api/units/data_rate.h"
Steve Anton10542f22019-01-11 09:11:00 -080025#include "rtc_base/constructor_magic.h"
Jonas Olssone0960042019-03-12 13:49:26 +010026#include "rtc_base/experiments/field_trial_parser.h"
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010027
28namespace webrtc {
29
Jonas Olssone0960042019-03-12 13:49:26 +010030struct ProbeControllerConfig {
31 explicit ProbeControllerConfig(const WebRtcKeyValueConfig* key_value_config);
32 ProbeControllerConfig(const ProbeControllerConfig&);
33 ProbeControllerConfig& operator=(const ProbeControllerConfig&) = default;
34 ~ProbeControllerConfig();
35
36 // These parameters configure the initial probes. First we send one or two
37 // probes of sizes p1 * start_bitrate_bps_ and p2 * start_bitrate_bps_.
38 // Then whenever we get a bitrate estimate of at least further_probe_threshold
39 // times the size of the last sent probe we'll send another one of size
40 // step_size times the new estimate.
Jonas Olsson01d36182019-03-27 15:57:02 +010041 FieldTrialParameter<double> first_exponential_probe_scale;
42 FieldTrialOptional<double> second_exponential_probe_scale;
43 FieldTrialParameter<double> further_exponential_probe_scale;
Jonas Olssone0960042019-03-12 13:49:26 +010044 FieldTrialParameter<double> further_probe_threshold;
45
46 // Configures how often we send ALR probes and how big they are.
Jonas Olsson01d36182019-03-27 15:57:02 +010047 FieldTrialParameter<TimeDelta> alr_probing_interval;
48 FieldTrialParameter<double> alr_probe_scale;
49
50 // Configures the probes emitted by changed to the allocated bitrate.
51 FieldTrialOptional<double> first_allocation_probe_scale;
52 FieldTrialOptional<double> second_allocation_probe_scale;
53 FieldTrialFlag allocation_allow_further_probing;
Christoffer Rodbro377f5a22020-02-12 10:11:13 +010054 FieldTrialParameter<DataRate> allocation_probe_max;
Jonas Olssone0960042019-03-12 13:49:26 +010055};
56
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010057// This class controls initiation of probing to estimate initial channel
58// capacity. There is also support for probing during a session when max
59// bitrate is adjusted by an application.
60class ProbeController {
61 public:
Piotr (Peter) Slatalac39f4622019-02-15 07:38:04 -080062 explicit ProbeController(const WebRtcKeyValueConfig* key_value_config,
63 RtcEventLog* event_log);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010064 ~ProbeController();
65
Danil Chapovalov098da172021-01-14 16:15:31 +010066 ABSL_MUST_USE_RESULT std::vector<ProbeClusterConfig> SetBitrates(
Sebastian Janssonda2ec402018-08-02 16:27:28 +020067 int64_t min_bitrate_bps,
68 int64_t start_bitrate_bps,
69 int64_t max_bitrate_bps,
70 int64_t at_time_ms);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010071
philipeldb4fa4b2018-03-06 18:29:22 +010072 // The total bitrate, as opposed to the max bitrate, is the sum of the
73 // configured bitrates for all active streams.
Danil Chapovalov098da172021-01-14 16:15:31 +010074 ABSL_MUST_USE_RESULT std::vector<ProbeClusterConfig>
Sebastian Janssonda2ec402018-08-02 16:27:28 +020075 OnMaxTotalAllocatedBitrate(int64_t max_total_allocated_bitrate,
76 int64_t at_time_ms);
philipeldb4fa4b2018-03-06 18:29:22 +010077
Danil Chapovalov098da172021-01-14 16:15:31 +010078 ABSL_MUST_USE_RESULT std::vector<ProbeClusterConfig> OnNetworkAvailability(
Sebastian Janssonda2ec402018-08-02 16:27:28 +020079 NetworkAvailability msg);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010080
Danil Chapovalov098da172021-01-14 16:15:31 +010081 ABSL_MUST_USE_RESULT std::vector<ProbeClusterConfig> SetEstimatedBitrate(
Sebastian Janssonda2ec402018-08-02 16:27:28 +020082 int64_t bitrate_bps,
83 int64_t at_time_ms);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010084
85 void EnablePeriodicAlrProbing(bool enable);
86
Danil Chapovalov0040b662018-06-18 10:48:16 +020087 void SetAlrStartTimeMs(absl::optional<int64_t> alr_start_time);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010088 void SetAlrEndedTimeMs(int64_t alr_end_time);
89
Danil Chapovalov098da172021-01-14 16:15:31 +010090 ABSL_MUST_USE_RESULT std::vector<ProbeClusterConfig> RequestProbe(
Sebastian Janssonda2ec402018-08-02 16:27:28 +020091 int64_t at_time_ms);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010092
Erik Språng791d43c2019-01-08 15:46:06 +010093 // Sets a new maximum probing bitrate, without generating a new probe cluster.
94 void SetMaxBitrate(int64_t max_bitrate_bps);
95
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010096 // Resets the ProbeController to a state equivalent to as if it was just
Artem Titov6f4b4fa2021-07-28 20:26:13 +020097 // created EXCEPT for `enable_periodic_alr_probing_`.
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +010098 void Reset(int64_t at_time_ms);
99
Danil Chapovalov098da172021-01-14 16:15:31 +0100100 ABSL_MUST_USE_RESULT std::vector<ProbeClusterConfig> Process(
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200101 int64_t at_time_ms);
Sebastian Janssonf2e3e7a2018-04-06 17:16:06 +0200102
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100103 private:
104 enum class State {
105 // Initial state where no probing has been triggered yet.
106 kInit,
107 // Waiting for probing results to continue further probing.
108 kWaitingForProbingResult,
109 // Probing is complete.
110 kProbingComplete,
111 };
112
Danil Chapovalov098da172021-01-14 16:15:31 +0100113 ABSL_MUST_USE_RESULT std::vector<ProbeClusterConfig>
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200114 InitiateExponentialProbing(int64_t at_time_ms);
Danil Chapovalov098da172021-01-14 16:15:31 +0100115 ABSL_MUST_USE_RESULT std::vector<ProbeClusterConfig> InitiateProbing(
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200116 int64_t now_ms,
Jonas Olssone0960042019-03-12 13:49:26 +0100117 std::vector<int64_t> bitrates_to_probe,
Sebastian Janssonda2ec402018-08-02 16:27:28 +0200118 bool probe_further);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100119
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100120 bool network_available_;
121 State state_;
122 int64_t min_bitrate_to_probe_further_bps_;
123 int64_t time_last_probing_initiated_ms_;
124 int64_t estimated_bitrate_bps_;
125 int64_t start_bitrate_bps_;
126 int64_t max_bitrate_bps_;
127 int64_t last_bwe_drop_probing_time_ms_;
Danil Chapovalov0040b662018-06-18 10:48:16 +0200128 absl::optional<int64_t> alr_start_time_ms_;
129 absl::optional<int64_t> alr_end_time_ms_;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100130 bool enable_periodic_alr_probing_;
131 int64_t time_of_last_large_drop_ms_;
132 int64_t bitrate_before_last_large_drop_bps_;
philipel0676f222018-04-17 16:12:21 +0200133 int64_t max_total_allocated_bitrate_;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100134
Erik Språngcfe36ca2018-11-29 17:32:48 +0100135 const bool in_rapid_recovery_experiment_;
136 const bool limit_probes_with_allocateable_rate_;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100137 // For WebRTC.BWE.MidCallProbing.* metric.
138 bool mid_call_probing_waiting_for_result_;
139 int64_t mid_call_probing_bitrate_bps_;
140 int64_t mid_call_probing_succcess_threshold_;
Piotr (Peter) Slatalac39f4622019-02-15 07:38:04 -0800141 RtcEventLog* event_log_;
142
143 int32_t next_probe_cluster_id_ = 1;
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100144
Jonas Olssone0960042019-03-12 13:49:26 +0100145 ProbeControllerConfig config_;
146
Sebastian Janssonf2e3e7a2018-04-06 17:16:06 +0200147 RTC_DISALLOW_COPY_AND_ASSIGN(ProbeController);
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100148};
149
Sebastian Jansson6bcd7f62018-02-27 17:07:02 +0100150} // namespace webrtc
151
Sebastian Janssonfc7ec8e2018-02-28 16:48:00 +0100152#endif // MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_CONTROLLER_H_