Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [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 | |
| 11 | #ifndef WEBRTC_MODULES_CONGESTION_CONTROLLER_PROBE_CONTROLLER_H_ |
| 12 | #define WEBRTC_MODULES_CONGESTION_CONTROLLER_PROBE_CONTROLLER_H_ |
| 13 | |
| 14 | #include <initializer_list> |
| 15 | |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 16 | #include "webrtc/common_types.h" |
| 17 | #include "webrtc/modules/pacing/paced_sender.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 18 | #include "webrtc/rtc_base/criticalsection.h" |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | class Clock; |
| 23 | |
| 24 | // This class controls initiation of probing to estimate initial channel |
| 25 | // capacity. There is also support for probing during a session when max |
| 26 | // bitrate is adjusted by an application. |
| 27 | class ProbeController { |
| 28 | public: |
elad.alon | 61ce37e | 2017-03-09 07:09:31 -0800 | [diff] [blame] | 29 | ProbeController(PacedSender* pacer, const Clock* clock); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 30 | |
sergeyu | 5bc3945 | 2016-12-15 10:42:09 -0800 | [diff] [blame] | 31 | void SetBitrates(int64_t min_bitrate_bps, |
| 32 | int64_t start_bitrate_bps, |
| 33 | int64_t max_bitrate_bps); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 34 | |
| 35 | void OnNetworkStateChanged(NetworkState state); |
| 36 | |
sergeyu | 5bc3945 | 2016-12-15 10:42:09 -0800 | [diff] [blame] | 37 | void SetEstimatedBitrate(int64_t bitrate_bps); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 38 | |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 39 | void EnablePeriodicAlrProbing(bool enable); |
philipel | cb9ba30 | 2017-03-07 06:30:59 -0800 | [diff] [blame] | 40 | |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 41 | void SetAlrEndedTimeMs(int64_t alr_end_time); |
| 42 | |
| 43 | void RequestProbe(); |
| 44 | |
philipel | cb9ba30 | 2017-03-07 06:30:59 -0800 | [diff] [blame] | 45 | // Resets the ProbeController to a state equivalent to as if it was just |
| 46 | // created EXCEPT for |enable_periodic_alr_probing_|. |
| 47 | void Reset(); |
| 48 | |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 49 | void Process(); |
| 50 | |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 51 | private: |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 52 | enum class State { |
| 53 | // Initial state where no probing has been triggered yet. |
| 54 | kInit, |
| 55 | // Waiting for probing results to continue further probing. |
| 56 | kWaitingForProbingResult, |
| 57 | // Probing is complete. |
| 58 | kProbingComplete, |
| 59 | }; |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 60 | |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 61 | void InitiateExponentialProbing() RTC_EXCLUSIVE_LOCKS_REQUIRED(critsect_); |
sergeyu | 80ed35e | 2016-11-28 13:11:13 -0800 | [diff] [blame] | 62 | void InitiateProbing(int64_t now_ms, |
sergeyu | 5bc3945 | 2016-12-15 10:42:09 -0800 | [diff] [blame] | 63 | std::initializer_list<int64_t> bitrates_to_probe, |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 64 | bool probe_further) |
| 65 | RTC_EXCLUSIVE_LOCKS_REQUIRED(critsect_); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 66 | |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 67 | rtc::CriticalSection critsect_; |
| 68 | PacedSender* const pacer_; |
elad.alon | 61ce37e | 2017-03-09 07:09:31 -0800 | [diff] [blame] | 69 | const Clock* const clock_; |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 70 | NetworkState network_state_ RTC_GUARDED_BY(critsect_); |
| 71 | State state_ RTC_GUARDED_BY(critsect_); |
| 72 | int64_t min_bitrate_to_probe_further_bps_ RTC_GUARDED_BY(critsect_); |
| 73 | int64_t time_last_probing_initiated_ms_ RTC_GUARDED_BY(critsect_); |
| 74 | int64_t estimated_bitrate_bps_ RTC_GUARDED_BY(critsect_); |
| 75 | int64_t start_bitrate_bps_ RTC_GUARDED_BY(critsect_); |
| 76 | int64_t max_bitrate_bps_ RTC_GUARDED_BY(critsect_); |
| 77 | int64_t last_bwe_drop_probing_time_ms_ RTC_GUARDED_BY(critsect_); |
| 78 | rtc::Optional<int64_t> alr_end_time_ms_ RTC_GUARDED_BY(critsect_); |
| 79 | bool enable_periodic_alr_probing_ RTC_GUARDED_BY(critsect_); |
| 80 | int64_t time_of_last_large_drop_ms_ RTC_GUARDED_BY(critsect_); |
| 81 | int64_t bitrate_before_last_large_drop_bps_ RTC_GUARDED_BY(critsect_); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 82 | |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 83 | bool in_rapid_recovery_experiment_ RTC_GUARDED_BY(critsect_); |
philipel | 2df0734 | 2017-01-16 09:31:49 -0800 | [diff] [blame] | 84 | // For WebRTC.BWE.MidCallProbing.* metric. |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 85 | bool mid_call_probing_waiting_for_result_ RTC_GUARDED_BY(&critsect_); |
| 86 | int64_t mid_call_probing_bitrate_bps_ RTC_GUARDED_BY(&critsect_); |
| 87 | int64_t mid_call_probing_succcess_threshold_ RTC_GUARDED_BY(&critsect_); |
philipel | 2df0734 | 2017-01-16 09:31:49 -0800 | [diff] [blame] | 88 | |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 89 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(ProbeController); |
| 90 | }; |
| 91 | |
| 92 | } // namespace webrtc |
| 93 | |
| 94 | #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_PROBE_CONTROLLER_H_ |