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  */
10 #ifndef MODULES_REMOTE_BITRATE_ESTIMATOR_OVERUSE_DETECTOR_H_
11 #define MODULES_REMOTE_BITRATE_ESTIMATOR_OVERUSE_DETECTOR_H_
12 
13 #include <stdint.h>
14 
15 #include "api/transport/webrtc_key_value_config.h"
16 #include "modules/remote_bitrate_estimator/include/bwe_defines.h"
17 #include "rtc_base/constructor_magic.h"
18 
19 namespace webrtc {
20 
21 bool AdaptiveThresholdExperimentIsDisabled(
22     const WebRtcKeyValueConfig& key_value_config);
23 
24 class OveruseDetector {
25  public:
26   explicit OveruseDetector(const WebRtcKeyValueConfig* key_value_config);
27   virtual ~OveruseDetector();
28 
29   // Update the detection state based on the estimated inter-arrival time delta
30   // offset. |timestamp_delta| is the delta between the last timestamp which the
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.
33   // |num_of_deltas| is the number of deltas the offset estimate is based on.
34   // Returns the state after the detection update.
35   BandwidthUsage Detect(double offset,
36                         double timestamp_delta,
37                         int num_of_deltas,
38                         int64_t now_ms);
39 
40   // Returns the current detector state.
41   BandwidthUsage State() const;
42 
43  private:
44   void UpdateThreshold(double modified_offset, int64_t now_ms);
45   void InitializeExperiment(const WebRtcKeyValueConfig& key_value_config);
46 
47   bool in_experiment_;
48   double k_up_;
49   double k_down_;
50   double overusing_time_threshold_;
51   double threshold_;
52   int64_t last_update_ms_;
53   double prev_offset_;
54   double time_over_using_;
55   int overuse_counter_;
56   BandwidthUsage hypothesis_;
57 
58   RTC_DISALLOW_COPY_AND_ASSIGN(OveruseDetector);
59 };
60 }  // namespace webrtc
61 
62 #endif  // MODULES_REMOTE_BITRATE_ESTIMATOR_OVERUSE_DETECTOR_H_
63