xref: /aosp_15_r20/external/webrtc/video/quality_threshold.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker  *
4*d9f75844SAndroid Build Coastguard Worker  *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker  *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker  *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker  *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker  *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker  */
10*d9f75844SAndroid Build Coastguard Worker 
11*d9f75844SAndroid Build Coastguard Worker #ifndef VIDEO_QUALITY_THRESHOLD_H_
12*d9f75844SAndroid Build Coastguard Worker #define VIDEO_QUALITY_THRESHOLD_H_
13*d9f75844SAndroid Build Coastguard Worker 
14*d9f75844SAndroid Build Coastguard Worker #include <memory>
15*d9f75844SAndroid Build Coastguard Worker 
16*d9f75844SAndroid Build Coastguard Worker #include "absl/types/optional.h"
17*d9f75844SAndroid Build Coastguard Worker 
18*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
19*d9f75844SAndroid Build Coastguard Worker 
20*d9f75844SAndroid Build Coastguard Worker class QualityThreshold {
21*d9f75844SAndroid Build Coastguard Worker  public:
22*d9f75844SAndroid Build Coastguard Worker   // Both thresholds are inclusive, i.e. measurement >= high signifies a high
23*d9f75844SAndroid Build Coastguard Worker   // state, while measurement <= low signifies a low state.
24*d9f75844SAndroid Build Coastguard Worker   QualityThreshold(int low_threshold,
25*d9f75844SAndroid Build Coastguard Worker                    int high_threshold,
26*d9f75844SAndroid Build Coastguard Worker                    float fraction,
27*d9f75844SAndroid Build Coastguard Worker                    int max_measurements);
28*d9f75844SAndroid Build Coastguard Worker   ~QualityThreshold();
29*d9f75844SAndroid Build Coastguard Worker 
30*d9f75844SAndroid Build Coastguard Worker   void AddMeasurement(int measurement);
31*d9f75844SAndroid Build Coastguard Worker   absl::optional<bool> IsHigh() const;
32*d9f75844SAndroid Build Coastguard Worker   absl::optional<double> CalculateVariance() const;
33*d9f75844SAndroid Build Coastguard Worker   absl::optional<double> FractionHigh(int min_required_samples) const;
34*d9f75844SAndroid Build Coastguard Worker 
35*d9f75844SAndroid Build Coastguard Worker  private:
36*d9f75844SAndroid Build Coastguard Worker   const std::unique_ptr<int[]> buffer_;
37*d9f75844SAndroid Build Coastguard Worker   const int max_measurements_;
38*d9f75844SAndroid Build Coastguard Worker   const float fraction_;
39*d9f75844SAndroid Build Coastguard Worker   const int low_threshold_;
40*d9f75844SAndroid Build Coastguard Worker   const int high_threshold_;
41*d9f75844SAndroid Build Coastguard Worker   int until_full_;
42*d9f75844SAndroid Build Coastguard Worker   int next_index_;
43*d9f75844SAndroid Build Coastguard Worker   absl::optional<bool> is_high_;
44*d9f75844SAndroid Build Coastguard Worker   int sum_;
45*d9f75844SAndroid Build Coastguard Worker   int count_low_;
46*d9f75844SAndroid Build Coastguard Worker   int count_high_;
47*d9f75844SAndroid Build Coastguard Worker   int num_high_states_;
48*d9f75844SAndroid Build Coastguard Worker   int num_certain_states_;
49*d9f75844SAndroid Build Coastguard Worker };
50*d9f75844SAndroid Build Coastguard Worker 
51*d9f75844SAndroid Build Coastguard Worker }  // namespace webrtc
52*d9f75844SAndroid Build Coastguard Worker 
53*d9f75844SAndroid Build Coastguard Worker #endif  // VIDEO_QUALITY_THRESHOLD_H_
54