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 | #ifndef MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_CONTROLLER_H_ |
| 12 | #define MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_CONTROLLER_H_ |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 13 | |
| 14 | #include <stdint.h> |
| 15 | |
| 16 | #include <initializer_list> |
Sebastian Jansson | f2e3e7a | 2018-04-06 17:16:06 +0200 | [diff] [blame] | 17 | #include <vector> |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 18 | |
Danil Chapovalov | 098da17 | 2021-01-14 16:15:31 +0100 | [diff] [blame] | 19 | #include "absl/base/attributes.h" |
Danil Chapovalov | 0040b66 | 2018-06-18 10:48:16 +0200 | [diff] [blame] | 20 | #include "absl/types/optional.h" |
Jonas Oreland | e62c2f2 | 2022-03-29 11:04:48 +0200 | [diff] [blame] | 21 | #include "api/field_trials_view.h" |
Danil Chapovalov | 83bbe91 | 2019-08-07 12:24:53 +0200 | [diff] [blame] | 22 | #include "api/rtc_event_log/rtc_event_log.h" |
Sebastian Jansson | c6c4426 | 2018-05-09 10:33:39 +0200 | [diff] [blame] | 23 | #include "api/transport/network_control.h" |
Christoffer Rodbro | 377f5a2 | 2020-02-12 10:11:13 +0100 | [diff] [blame] | 24 | #include "api/units/data_rate.h" |
Jonas Olsson | e096004 | 2019-03-12 13:49:26 +0100 | [diff] [blame] | 25 | #include "rtc_base/experiments/field_trial_parser.h" |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | |
Jonas Olsson | e096004 | 2019-03-12 13:49:26 +0100 | [diff] [blame] | 29 | struct ProbeControllerConfig { |
Jonas Oreland | e62c2f2 | 2022-03-29 11:04:48 +0200 | [diff] [blame] | 30 | explicit ProbeControllerConfig(const FieldTrialsView* key_value_config); |
Jonas Olsson | e096004 | 2019-03-12 13:49:26 +0100 | [diff] [blame] | 31 | ProbeControllerConfig(const ProbeControllerConfig&); |
| 32 | ProbeControllerConfig& operator=(const ProbeControllerConfig&) = default; |
| 33 | ~ProbeControllerConfig(); |
| 34 | |
| 35 | // These parameters configure the initial probes. First we send one or two |
| 36 | // probes of sizes p1 * start_bitrate_bps_ and p2 * start_bitrate_bps_. |
| 37 | // Then whenever we get a bitrate estimate of at least further_probe_threshold |
| 38 | // times the size of the last sent probe we'll send another one of size |
| 39 | // step_size times the new estimate. |
Jonas Olsson | 01d3618 | 2019-03-27 15:57:02 +0100 | [diff] [blame] | 40 | FieldTrialParameter<double> first_exponential_probe_scale; |
| 41 | FieldTrialOptional<double> second_exponential_probe_scale; |
| 42 | FieldTrialParameter<double> further_exponential_probe_scale; |
Jonas Olsson | e096004 | 2019-03-12 13:49:26 +0100 | [diff] [blame] | 43 | FieldTrialParameter<double> further_probe_threshold; |
| 44 | |
| 45 | // Configures how often we send ALR probes and how big they are. |
Jonas Olsson | 01d3618 | 2019-03-27 15:57:02 +0100 | [diff] [blame] | 46 | FieldTrialParameter<TimeDelta> alr_probing_interval; |
| 47 | FieldTrialParameter<double> alr_probe_scale; |
| 48 | |
| 49 | // Configures the probes emitted by changed to the allocated bitrate. |
| 50 | FieldTrialOptional<double> first_allocation_probe_scale; |
| 51 | FieldTrialOptional<double> second_allocation_probe_scale; |
| 52 | FieldTrialFlag allocation_allow_further_probing; |
Christoffer Rodbro | 377f5a2 | 2020-02-12 10:11:13 +0100 | [diff] [blame] | 53 | FieldTrialParameter<DataRate> allocation_probe_max; |
Per Kjellander | 88af203 | 2022-05-16 19:58:40 +0200 | [diff] [blame] | 54 | |
| 55 | // The minimum number probing packets used. |
| 56 | FieldTrialParameter<int> min_probe_packets_sent; |
| 57 | // The minimum probing duration. |
| 58 | FieldTrialParameter<TimeDelta> min_probe_duration; |
Jonas Olsson | e096004 | 2019-03-12 13:49:26 +0100 | [diff] [blame] | 59 | }; |
| 60 | |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 61 | // This class controls initiation of probing to estimate initial channel |
| 62 | // capacity. There is also support for probing during a session when max |
| 63 | // bitrate is adjusted by an application. |
| 64 | class ProbeController { |
| 65 | public: |
Jonas Oreland | e62c2f2 | 2022-03-29 11:04:48 +0200 | [diff] [blame] | 66 | explicit ProbeController(const FieldTrialsView* key_value_config, |
Piotr (Peter) Slatala | c39f462 | 2019-02-15 07:38:04 -0800 | [diff] [blame] | 67 | RtcEventLog* event_log); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 68 | ~ProbeController(); |
| 69 | |
Byoungchan Lee | 604fd2f | 2022-01-21 09:49:39 +0900 | [diff] [blame] | 70 | ProbeController(const ProbeController&) = delete; |
| 71 | ProbeController& operator=(const ProbeController&) = delete; |
| 72 | |
Danil Chapovalov | 098da17 | 2021-01-14 16:15:31 +0100 | [diff] [blame] | 73 | ABSL_MUST_USE_RESULT std::vector<ProbeClusterConfig> SetBitrates( |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 74 | int64_t min_bitrate_bps, |
| 75 | int64_t start_bitrate_bps, |
| 76 | int64_t max_bitrate_bps, |
| 77 | int64_t at_time_ms); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 78 | |
philipel | db4fa4b | 2018-03-06 18:29:22 +0100 | [diff] [blame] | 79 | // The total bitrate, as opposed to the max bitrate, is the sum of the |
| 80 | // configured bitrates for all active streams. |
Danil Chapovalov | 098da17 | 2021-01-14 16:15:31 +0100 | [diff] [blame] | 81 | ABSL_MUST_USE_RESULT std::vector<ProbeClusterConfig> |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 82 | OnMaxTotalAllocatedBitrate(int64_t max_total_allocated_bitrate, |
| 83 | int64_t at_time_ms); |
philipel | db4fa4b | 2018-03-06 18:29:22 +0100 | [diff] [blame] | 84 | |
Danil Chapovalov | 098da17 | 2021-01-14 16:15:31 +0100 | [diff] [blame] | 85 | ABSL_MUST_USE_RESULT std::vector<ProbeClusterConfig> OnNetworkAvailability( |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 86 | NetworkAvailability msg); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 87 | |
Danil Chapovalov | 098da17 | 2021-01-14 16:15:31 +0100 | [diff] [blame] | 88 | ABSL_MUST_USE_RESULT std::vector<ProbeClusterConfig> SetEstimatedBitrate( |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 89 | int64_t bitrate_bps, |
| 90 | int64_t at_time_ms); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 91 | |
| 92 | void EnablePeriodicAlrProbing(bool enable); |
| 93 | |
Danil Chapovalov | 0040b66 | 2018-06-18 10:48:16 +0200 | [diff] [blame] | 94 | void SetAlrStartTimeMs(absl::optional<int64_t> alr_start_time); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 95 | void SetAlrEndedTimeMs(int64_t alr_end_time); |
| 96 | |
Danil Chapovalov | 098da17 | 2021-01-14 16:15:31 +0100 | [diff] [blame] | 97 | ABSL_MUST_USE_RESULT std::vector<ProbeClusterConfig> RequestProbe( |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 98 | int64_t at_time_ms); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 99 | |
Erik Språng | 791d43c | 2019-01-08 15:46:06 +0100 | [diff] [blame] | 100 | // Sets a new maximum probing bitrate, without generating a new probe cluster. |
| 101 | void SetMaxBitrate(int64_t max_bitrate_bps); |
| 102 | |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 103 | // Resets the ProbeController to a state equivalent to as if it was just |
Artem Titov | 6f4b4fa | 2021-07-28 20:26:13 +0200 | [diff] [blame] | 104 | // created EXCEPT for `enable_periodic_alr_probing_`. |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 105 | void Reset(int64_t at_time_ms); |
| 106 | |
Danil Chapovalov | 098da17 | 2021-01-14 16:15:31 +0100 | [diff] [blame] | 107 | ABSL_MUST_USE_RESULT std::vector<ProbeClusterConfig> Process( |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 108 | int64_t at_time_ms); |
Sebastian Jansson | f2e3e7a | 2018-04-06 17:16:06 +0200 | [diff] [blame] | 109 | |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 110 | private: |
| 111 | enum class State { |
| 112 | // Initial state where no probing has been triggered yet. |
| 113 | kInit, |
| 114 | // Waiting for probing results to continue further probing. |
| 115 | kWaitingForProbingResult, |
| 116 | // Probing is complete. |
| 117 | kProbingComplete, |
| 118 | }; |
| 119 | |
Danil Chapovalov | 098da17 | 2021-01-14 16:15:31 +0100 | [diff] [blame] | 120 | ABSL_MUST_USE_RESULT std::vector<ProbeClusterConfig> |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 121 | InitiateExponentialProbing(int64_t at_time_ms); |
Danil Chapovalov | 098da17 | 2021-01-14 16:15:31 +0100 | [diff] [blame] | 122 | ABSL_MUST_USE_RESULT std::vector<ProbeClusterConfig> InitiateProbing( |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 123 | int64_t now_ms, |
Jonas Olsson | e096004 | 2019-03-12 13:49:26 +0100 | [diff] [blame] | 124 | std::vector<int64_t> bitrates_to_probe, |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 125 | bool probe_further); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 126 | |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 127 | bool network_available_; |
| 128 | State state_; |
| 129 | int64_t min_bitrate_to_probe_further_bps_; |
| 130 | int64_t time_last_probing_initiated_ms_; |
| 131 | int64_t estimated_bitrate_bps_; |
| 132 | int64_t start_bitrate_bps_; |
| 133 | int64_t max_bitrate_bps_; |
| 134 | int64_t last_bwe_drop_probing_time_ms_; |
Danil Chapovalov | 0040b66 | 2018-06-18 10:48:16 +0200 | [diff] [blame] | 135 | absl::optional<int64_t> alr_start_time_ms_; |
| 136 | absl::optional<int64_t> alr_end_time_ms_; |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 137 | bool enable_periodic_alr_probing_; |
| 138 | int64_t time_of_last_large_drop_ms_; |
| 139 | int64_t bitrate_before_last_large_drop_bps_; |
philipel | 0676f22 | 2018-04-17 16:12:21 +0200 | [diff] [blame] | 140 | int64_t max_total_allocated_bitrate_; |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 141 | |
Erik Språng | cfe36ca | 2018-11-29 17:32:48 +0100 | [diff] [blame] | 142 | const bool in_rapid_recovery_experiment_; |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 143 | // For WebRTC.BWE.MidCallProbing.* metric. |
| 144 | bool mid_call_probing_waiting_for_result_; |
| 145 | int64_t mid_call_probing_bitrate_bps_; |
| 146 | int64_t mid_call_probing_succcess_threshold_; |
Piotr (Peter) Slatala | c39f462 | 2019-02-15 07:38:04 -0800 | [diff] [blame] | 147 | RtcEventLog* event_log_; |
| 148 | |
| 149 | int32_t next_probe_cluster_id_ = 1; |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 150 | |
Jonas Olsson | e096004 | 2019-03-12 13:49:26 +0100 | [diff] [blame] | 151 | ProbeControllerConfig config_; |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 152 | }; |
| 153 | |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 154 | } // namespace webrtc |
| 155 | |
Sebastian Jansson | fc7ec8e | 2018-02-28 16:48:00 +0100 | [diff] [blame] | 156 | #endif // MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_CONTROLLER_H_ |