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