palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef VIDEO_QUALITY_THRESHOLD_H_ |
| 12 | #define VIDEO_QUALITY_THRESHOLD_H_ |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "api/optional.h" |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | class QualityThreshold { |
| 21 | public: |
| 22 | // Both thresholds are inclusive, i.e. measurement >= high signifies a high |
| 23 | // state, while measurement <= low signifies a low state. |
| 24 | QualityThreshold(int low_threshold, |
| 25 | int high_threshold, |
| 26 | float fraction, |
| 27 | int max_measurements); |
| 28 | |
| 29 | void AddMeasurement(int measurement); |
| 30 | rtc::Optional<bool> IsHigh() const; |
| 31 | rtc::Optional<double> CalculateVariance() const; |
palmkvist | a40672a | 2017-01-13 05:58:34 -0800 | [diff] [blame] | 32 | rtc::Optional<double> FractionHigh(int min_required_samples) const; |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 33 | |
| 34 | private: |
| 35 | const std::unique_ptr<int[]> buffer_; |
| 36 | const int max_measurements_; |
| 37 | const float fraction_; |
| 38 | const int low_threshold_; |
| 39 | const int high_threshold_; |
| 40 | int until_full_; |
| 41 | int next_index_; |
| 42 | rtc::Optional<bool> is_high_; |
| 43 | int sum_; |
| 44 | int count_low_; |
| 45 | int count_high_; |
palmkvist | a40672a | 2017-01-13 05:58:34 -0800 | [diff] [blame] | 46 | int num_high_states_; |
| 47 | int num_certain_states_; |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | } // namespace webrtc |
| 51 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 52 | #endif // VIDEO_QUALITY_THRESHOLD_H_ |