bjornv@webrtc.org | cb89c6f | 2012-06-05 12:25:35 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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 | */ |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 10 | #ifndef MODULES_REMOTE_BITRATE_ESTIMATOR_OVERUSE_DETECTOR_H_ |
| 11 | #define MODULES_REMOTE_BITRATE_ESTIMATOR_OVERUSE_DETECTOR_H_ |
bjornv@webrtc.org | cb89c6f | 2012-06-05 12:25:35 | [diff] [blame] | 12 | |
Yves Gerey | 988cc08 | 2018-10-23 10:03:01 | [diff] [blame] | 13 | #include <stdint.h> |
bjornv@webrtc.org | cb89c6f | 2012-06-05 12:25:35 | [diff] [blame] | 14 | |
Niels Möller | 0d863f7 | 2020-11-24 16:50:31 | [diff] [blame] | 15 | #include "api/network_state_predictor.h" |
Per Kjellander | 494947b | 2019-04-16 12:50:08 | [diff] [blame] | 16 | #include "api/transport/webrtc_key_value_config.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 17 | #include "rtc_base/constructor_magic.h" |
bjornv@webrtc.org | cb89c6f | 2012-06-05 12:25:35 | [diff] [blame] | 18 | |
bjornv@webrtc.org | cb89c6f | 2012-06-05 12:25:35 | [diff] [blame] | 19 | namespace webrtc { |
bjornv@webrtc.org | cb89c6f | 2012-06-05 12:25:35 | [diff] [blame] | 20 | |
Per Kjellander | 494947b | 2019-04-16 12:50:08 | [diff] [blame] | 21 | bool AdaptiveThresholdExperimentIsDisabled( |
| 22 | const WebRtcKeyValueConfig& key_value_config); |
stefan | c62642c | 2015-07-07 11:20:34 | [diff] [blame] | 23 | |
stefan@webrtc.org | 976a7e6 | 2012-09-21 13:20:21 | [diff] [blame] | 24 | class OveruseDetector { |
bjornv@webrtc.org | cb89c6f | 2012-06-05 12:25:35 | [diff] [blame] | 25 | public: |
Per Kjellander | 494947b | 2019-04-16 12:50:08 | [diff] [blame] | 26 | explicit OveruseDetector(const WebRtcKeyValueConfig* key_value_config); |
stefan | c62642c | 2015-07-07 11:20:34 | [diff] [blame] | 27 | virtual ~OveruseDetector(); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 28 | |
| 29 | // Update the detection state based on the estimated inter-arrival time delta |
Artem Titov | 1fd7af5 | 2021-07-28 18:29:52 | [diff] [blame] | 30 | // offset. `timestamp_delta` is the delta between the last timestamp which the |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 31 | // estimated offset is based on and the last timestamp on which the last |
| 32 | // offset was based on, representing the time between detector updates. |
Artem Titov | 1fd7af5 | 2021-07-28 18:29:52 | [diff] [blame] | 33 | // `num_of_deltas` is the number of deltas the offset estimate is based on. |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 34 | // Returns the state after the detection update. |
Stefan Holmer | dcbd3ac | 2015-04-10 08:35:30 | [diff] [blame] | 35 | BandwidthUsage Detect(double offset, |
| 36 | double timestamp_delta, |
| 37 | int num_of_deltas, |
| 38 | int64_t now_ms); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 39 | |
| 40 | // Returns the current detector state. |
bjornv@webrtc.org | cb89c6f | 2012-06-05 12:25:35 | [diff] [blame] | 41 | BandwidthUsage State() const; |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 42 | |
bjornv@webrtc.org | cb89c6f | 2012-06-05 12:25:35 | [diff] [blame] | 43 | private: |
stefan | c62642c | 2015-07-07 11:20:34 | [diff] [blame] | 44 | void UpdateThreshold(double modified_offset, int64_t now_ms); |
Per Kjellander | 494947b | 2019-04-16 12:50:08 | [diff] [blame] | 45 | void InitializeExperiment(const WebRtcKeyValueConfig& key_value_config); |
stefan | c62642c | 2015-07-07 11:20:34 | [diff] [blame] | 46 | |
Stefan Holmer | 44c65e9 | 2016-02-16 17:22:21 | [diff] [blame] | 47 | bool in_experiment_; |
stefan | c62642c | 2015-07-07 11:20:34 | [diff] [blame] | 48 | double k_up_; |
| 49 | double k_down_; |
| 50 | double overusing_time_threshold_; |
bjornv@webrtc.org | cb89c6f | 2012-06-05 12:25:35 | [diff] [blame] | 51 | double threshold_; |
stefan | c62642c | 2015-07-07 11:20:34 | [diff] [blame] | 52 | int64_t last_update_ms_; |
astor@webrtc.org | bd7aeba | 2012-06-26 10:47:04 | [diff] [blame] | 53 | double prev_offset_; |
| 54 | double time_over_using_; |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 55 | int overuse_counter_; |
bjornv@webrtc.org | cb89c6f | 2012-06-05 12:25:35 | [diff] [blame] | 56 | BandwidthUsage hypothesis_; |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 57 | |
henrikg | 3c089d7 | 2015-09-16 12:37:44 | [diff] [blame] | 58 | RTC_DISALLOW_COPY_AND_ASSIGN(OveruseDetector); |
bjornv@webrtc.org | cb89c6f | 2012-06-05 12:25:35 | [diff] [blame] | 59 | }; |
| 60 | } // namespace webrtc |
| 61 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 62 | #endif // MODULES_REMOTE_BITRATE_ESTIMATOR_OVERUSE_DETECTOR_H_ |