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