blob: a193aa7f019878e9e4647fe657315d7f9145a24d [file] [log] [blame]
palmkvist349092b2016-12-13 02:45:57 -08001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef VIDEO_QUALITY_THRESHOLD_H_
12#define VIDEO_QUALITY_THRESHOLD_H_
palmkvist349092b2016-12-13 02:45:57 -080013
14#include <memory>
15
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020016#include "absl/types/optional.h"
palmkvist349092b2016-12-13 02:45:57 -080017
18namespace webrtc {
19
20class 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);
Mirko Bonadei8fdcac32018-08-28 16:30:18 +020028 ~QualityThreshold();
palmkvist349092b2016-12-13 02:45:57 -080029
30 void AddMeasurement(int measurement);
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020031 absl::optional<bool> IsHigh() const;
32 absl::optional<double> CalculateVariance() const;
33 absl::optional<double> FractionHigh(int min_required_samples) const;
palmkvist349092b2016-12-13 02:45:57 -080034
35 private:
36 const std::unique_ptr<int[]> buffer_;
37 const int max_measurements_;
38 const float fraction_;
39 const int low_threshold_;
40 const int high_threshold_;
41 int until_full_;
42 int next_index_;
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020043 absl::optional<bool> is_high_;
palmkvist349092b2016-12-13 02:45:57 -080044 int sum_;
45 int count_low_;
46 int count_high_;
palmkvista40672a2017-01-13 05:58:34 -080047 int num_high_states_;
48 int num_certain_states_;
palmkvist349092b2016-12-13 02:45:57 -080049};
50
51} // namespace webrtc
52
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020053#endif // VIDEO_QUALITY_THRESHOLD_H_