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 11 #ifndef MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_CONTROLLER_H_ 12 #define MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_CONTROLLER_H_ 13 14 #include <stdint.h> 15 16 #include <initializer_list> 17 #include <vector> 18 19 #include "absl/types/optional.h" 20 #include "api/rtc_event_log/rtc_event_log.h" 21 #include "api/transport/network_control.h" 22 #include "api/transport/webrtc_key_value_config.h" 23 #include "api/units/data_rate.h" 24 #include "rtc_base/constructor_magic.h" 25 #include "rtc_base/experiments/field_trial_parser.h" 26 #include "rtc_base/system/unused.h" 27 28 namespace webrtc { 29 30 struct 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. 41 FieldTrialParameter<double> first_exponential_probe_scale; 42 FieldTrialOptional<double> second_exponential_probe_scale; 43 FieldTrialParameter<double> further_exponential_probe_scale; 44 FieldTrialParameter<double> further_probe_threshold; 45 46 // Configures how often we send ALR probes and how big they are. 47 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; 54 FieldTrialParameter<DataRate> allocation_probe_max; 55 }; 56 57 // 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. 60 class ProbeController { 61 public: 62 explicit ProbeController(const WebRtcKeyValueConfig* key_value_config, 63 RtcEventLog* event_log); 64 ~ProbeController(); 65 66 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> SetBitrates( 67 int64_t min_bitrate_bps, 68 int64_t start_bitrate_bps, 69 int64_t max_bitrate_bps, 70 int64_t at_time_ms); 71 72 // The total bitrate, as opposed to the max bitrate, is the sum of the 73 // configured bitrates for all active streams. 74 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> 75 OnMaxTotalAllocatedBitrate(int64_t max_total_allocated_bitrate, 76 int64_t at_time_ms); 77 78 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> OnNetworkAvailability( 79 NetworkAvailability msg); 80 81 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> SetEstimatedBitrate( 82 int64_t bitrate_bps, 83 int64_t at_time_ms); 84 85 void EnablePeriodicAlrProbing(bool enable); 86 87 void SetAlrStartTimeMs(absl::optional<int64_t> alr_start_time); 88 void SetAlrEndedTimeMs(int64_t alr_end_time); 89 90 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> RequestProbe( 91 int64_t at_time_ms); 92 93 // Sets a new maximum probing bitrate, without generating a new probe cluster. 94 void SetMaxBitrate(int64_t max_bitrate_bps); 95 96 // Resets the ProbeController to a state equivalent to as if it was just 97 // created EXCEPT for |enable_periodic_alr_probing_|. 98 void Reset(int64_t at_time_ms); 99 100 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> Process( 101 int64_t at_time_ms); 102 103 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 113 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> 114 InitiateExponentialProbing(int64_t at_time_ms); 115 RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> InitiateProbing( 116 int64_t now_ms, 117 std::vector<int64_t> bitrates_to_probe, 118 bool probe_further); 119 120 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_; 128 absl::optional<int64_t> alr_start_time_ms_; 129 absl::optional<int64_t> alr_end_time_ms_; 130 bool enable_periodic_alr_probing_; 131 int64_t time_of_last_large_drop_ms_; 132 int64_t bitrate_before_last_large_drop_bps_; 133 int64_t max_total_allocated_bitrate_; 134 135 const bool in_rapid_recovery_experiment_; 136 const bool limit_probes_with_allocateable_rate_; 137 // 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_; 141 RtcEventLog* event_log_; 142 143 int32_t next_probe_cluster_id_ = 1; 144 145 ProbeControllerConfig config_; 146 147 RTC_DISALLOW_COPY_AND_ASSIGN(ProbeController); 148 }; 149 150 } // namespace webrtc 151 152 #endif // MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_CONTROLLER_H_ 153