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 | |
| 19 | #include "api/optional.h" |
Sebastian Jansson | 8acd5f8 | 2018-02-28 16:47:49 +0100 | [diff] [blame] | 20 | #include "modules/congestion_controller/network_control/include/network_control.h" |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | |
| 24 | class Clock; |
| 25 | |
Sebastian Jansson | 83b1842 | 2018-02-27 17:07:11 +0100 | [diff] [blame] | 26 | namespace webrtc_cc { |
| 27 | |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 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 | |
| 36 | void SetBitrates(int64_t min_bitrate_bps, |
| 37 | int64_t start_bitrate_bps, |
| 38 | int64_t max_bitrate_bps, |
| 39 | int64_t at_time_ms); |
| 40 | |
philipel | db4fa4b | 2018-03-06 18:29:22 +0100 | [diff] [blame] | 41 | // The total bitrate, as opposed to the max bitrate, is the sum of the |
| 42 | // configured bitrates for all active streams. |
| 43 | void OnMaxTotalAllocatedBitrate(int64_t max_total_allocated_bitrate, |
| 44 | int64_t at_time_ms); |
| 45 | |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 46 | void OnNetworkAvailability(NetworkAvailability msg); |
| 47 | |
| 48 | void SetEstimatedBitrate(int64_t bitrate_bps, int64_t at_time_ms); |
| 49 | |
| 50 | void EnablePeriodicAlrProbing(bool enable); |
| 51 | |
| 52 | void SetAlrStartTimeMs(rtc::Optional<int64_t> alr_start_time); |
| 53 | void SetAlrEndedTimeMs(int64_t alr_end_time); |
| 54 | |
| 55 | void RequestProbe(int64_t at_time_ms); |
| 56 | |
| 57 | // Resets the ProbeController to a state equivalent to as if it was just |
| 58 | // created EXCEPT for |enable_periodic_alr_probing_|. |
| 59 | void Reset(int64_t at_time_ms); |
| 60 | |
| 61 | void Process(int64_t at_time_ms); |
| 62 | |
Sebastian Jansson | f2e3e7a | 2018-04-06 17:16:06 +0200 | [diff] [blame] | 63 | std::vector<ProbeClusterConfig> GetAndResetPendingProbes(); |
| 64 | |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 65 | private: |
| 66 | enum class State { |
| 67 | // Initial state where no probing has been triggered yet. |
| 68 | kInit, |
| 69 | // Waiting for probing results to continue further probing. |
| 70 | kWaitingForProbingResult, |
| 71 | // Probing is complete. |
| 72 | kProbingComplete, |
| 73 | }; |
| 74 | |
| 75 | void InitiateExponentialProbing(int64_t at_time_ms); |
| 76 | void InitiateProbing(int64_t now_ms, |
| 77 | std::initializer_list<int64_t> bitrates_to_probe, |
| 78 | bool probe_further); |
| 79 | |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 80 | bool network_available_; |
| 81 | State state_; |
| 82 | int64_t min_bitrate_to_probe_further_bps_; |
| 83 | int64_t time_last_probing_initiated_ms_; |
| 84 | int64_t estimated_bitrate_bps_; |
| 85 | int64_t start_bitrate_bps_; |
| 86 | int64_t max_bitrate_bps_; |
| 87 | int64_t last_bwe_drop_probing_time_ms_; |
| 88 | rtc::Optional<int64_t> alr_start_time_ms_; |
| 89 | rtc::Optional<int64_t> alr_end_time_ms_; |
| 90 | bool enable_periodic_alr_probing_; |
| 91 | int64_t time_of_last_large_drop_ms_; |
| 92 | int64_t bitrate_before_last_large_drop_bps_; |
| 93 | |
| 94 | bool in_rapid_recovery_experiment_; |
| 95 | // For WebRTC.BWE.MidCallProbing.* metric. |
| 96 | bool mid_call_probing_waiting_for_result_; |
| 97 | int64_t mid_call_probing_bitrate_bps_; |
| 98 | int64_t mid_call_probing_succcess_threshold_; |
| 99 | |
Sebastian Jansson | f2e3e7a | 2018-04-06 17:16:06 +0200 | [diff] [blame] | 100 | std::vector<ProbeClusterConfig> pending_probes_; |
| 101 | |
| 102 | RTC_DISALLOW_COPY_AND_ASSIGN(ProbeController); |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 103 | }; |
| 104 | |
Sebastian Jansson | 83b1842 | 2018-02-27 17:07:11 +0100 | [diff] [blame] | 105 | } // namespace webrtc_cc |
Sebastian Jansson | 6bcd7f6 | 2018-02-27 17:07:02 +0100 | [diff] [blame] | 106 | } // namespace webrtc |
| 107 | |
Sebastian Jansson | fc7ec8e | 2018-02-28 16:48:00 +0100 | [diff] [blame] | 108 | #endif // MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_CONTROLLER_H_ |