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" |
| 21 | #include "rtc_base/constructormagic.h" |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 22 | #include "rtc_base/system/unused.h" |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
| 26 | class Clock; |
| 27 | |
| 28 | // This class controls initiation of probing to estimate initial channel |
| 29 | // capacity. There is also support for probing during a session when max |
| 30 | // bitrate is adjusted by an application. |
| 31 | class ProbeController { |
| 32 | public: |
Sebastian Jansson | f2e3e7a | 2018-04-06 17:16:06 +0200 | [diff] [blame] | 33 | ProbeController(); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 34 | ~ProbeController(); |
| 35 | |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 36 | RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> SetBitrates( |
| 37 | int64_t min_bitrate_bps, |
| 38 | int64_t start_bitrate_bps, |
| 39 | int64_t max_bitrate_bps, |
| 40 | int64_t at_time_ms); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 41 | |
philipel | db4fa4b | 2018-03-06 18:29:22 +0100 | [diff] [blame] | 42 | // The total bitrate, as opposed to the max bitrate, is the sum of the |
| 43 | // configured bitrates for all active streams. |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 44 | RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> |
| 45 | OnMaxTotalAllocatedBitrate(int64_t max_total_allocated_bitrate, |
| 46 | int64_t at_time_ms); |
philipel | db4fa4b | 2018-03-06 18:29:22 +0100 | [diff] [blame] | 47 | |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 48 | RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> OnNetworkAvailability( |
| 49 | NetworkAvailability msg); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 50 | |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 51 | RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> SetEstimatedBitrate( |
| 52 | int64_t bitrate_bps, |
| 53 | int64_t at_time_ms); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 54 | |
| 55 | void EnablePeriodicAlrProbing(bool enable); |
| 56 | |
Danil Chapovalov | 0040b66 | 2018-06-18 10:48:16 +0200 | [diff] [blame] | 57 | void SetAlrStartTimeMs(absl::optional<int64_t> alr_start_time); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 58 | void SetAlrEndedTimeMs(int64_t alr_end_time); |
| 59 | |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 60 | RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> RequestProbe( |
| 61 | int64_t at_time_ms); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 62 | |
Sebastian Jansson | 8d33c0c | 2018-10-22 10:22:03 +0200 | [diff] [blame] | 63 | RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> |
| 64 | InitiateCapacityProbing(int64_t bitrate_bps, int64_t at_time_ms); |
| 65 | |
Erik Språng | 791d43c | 2019-01-08 15:46:06 +0100 | [diff] [blame] | 66 | // Sets a new maximum probing bitrate, without generating a new probe cluster. |
| 67 | void SetMaxBitrate(int64_t max_bitrate_bps); |
| 68 | |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 69 | // Resets the ProbeController to a state equivalent to as if it was just |
| 70 | // created EXCEPT for |enable_periodic_alr_probing_|. |
| 71 | void Reset(int64_t at_time_ms); |
| 72 | |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 73 | RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> Process( |
| 74 | int64_t at_time_ms); |
Sebastian Jansson | f2e3e7a | 2018-04-06 17:16:06 +0200 | [diff] [blame] | 75 | |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 76 | private: |
| 77 | enum class State { |
| 78 | // Initial state where no probing has been triggered yet. |
| 79 | kInit, |
| 80 | // Waiting for probing results to continue further probing. |
| 81 | kWaitingForProbingResult, |
| 82 | // Probing is complete. |
| 83 | kProbingComplete, |
| 84 | }; |
| 85 | |
Sebastian Jansson | da2ec40 | 2018-08-02 16:27:28 +0200 | [diff] [blame] | 86 | RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> |
| 87 | InitiateExponentialProbing(int64_t at_time_ms); |
| 88 | RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> InitiateProbing( |
| 89 | int64_t now_ms, |
| 90 | std::initializer_list<int64_t> bitrates_to_probe, |
| 91 | bool probe_further); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 92 | |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 93 | bool network_available_; |
| 94 | State state_; |
| 95 | int64_t min_bitrate_to_probe_further_bps_; |
| 96 | int64_t time_last_probing_initiated_ms_; |
| 97 | int64_t estimated_bitrate_bps_; |
| 98 | int64_t start_bitrate_bps_; |
| 99 | int64_t max_bitrate_bps_; |
| 100 | int64_t last_bwe_drop_probing_time_ms_; |
Danil Chapovalov | 0040b66 | 2018-06-18 10:48:16 +0200 | [diff] [blame] | 101 | absl::optional<int64_t> alr_start_time_ms_; |
| 102 | absl::optional<int64_t> alr_end_time_ms_; |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 103 | bool enable_periodic_alr_probing_; |
| 104 | int64_t time_of_last_large_drop_ms_; |
| 105 | int64_t bitrate_before_last_large_drop_bps_; |
philipel | 0676f22 | 2018-04-17 16:12:21 +0200 | [diff] [blame] | 106 | int64_t max_total_allocated_bitrate_; |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 107 | |
Erik Språng | cfe36ca | 2018-11-29 17:32:48 +0100 | [diff] [blame] | 108 | const bool in_rapid_recovery_experiment_; |
| 109 | const bool limit_probes_with_allocateable_rate_; |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 110 | // For WebRTC.BWE.MidCallProbing.* metric. |
| 111 | bool mid_call_probing_waiting_for_result_; |
| 112 | int64_t mid_call_probing_bitrate_bps_; |
| 113 | int64_t mid_call_probing_succcess_threshold_; |
| 114 | |
Sebastian Jansson | f2e3e7a | 2018-04-06 17:16:06 +0200 | [diff] [blame] | 115 | RTC_DISALLOW_COPY_AND_ASSIGN(ProbeController); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 116 | }; |
| 117 | |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 118 | } // namespace webrtc |
| 119 | |
Sebastian Jansson | fc7ec8e | 2018-02-28 16:48:00 +0100 | [diff] [blame] | 120 | #endif // MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_CONTROLLER_H_ |