quality_threshold.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #ifndef VIDEO_QUALITY_THRESHOLD_H_
  11. #define VIDEO_QUALITY_THRESHOLD_H_
  12. #include <memory>
  13. #include "absl/types/optional.h"
  14. namespace webrtc {
  15. class QualityThreshold {
  16. public:
  17. // Both thresholds are inclusive, i.e. measurement >= high signifies a high
  18. // state, while measurement <= low signifies a low state.
  19. QualityThreshold(int low_threshold,
  20. int high_threshold,
  21. float fraction,
  22. int max_measurements);
  23. ~QualityThreshold();
  24. void AddMeasurement(int measurement);
  25. absl::optional<bool> IsHigh() const;
  26. absl::optional<double> CalculateVariance() const;
  27. absl::optional<double> FractionHigh(int min_required_samples) const;
  28. private:
  29. const std::unique_ptr<int[]> buffer_;
  30. const int max_measurements_;
  31. const float fraction_;
  32. const int low_threshold_;
  33. const int high_threshold_;
  34. int until_full_;
  35. int next_index_;
  36. absl::optional<bool> is_high_;
  37. int sum_;
  38. int count_low_;
  39. int count_high_;
  40. int num_high_states_;
  41. int num_certain_states_;
  42. };
  43. } // namespace webrtc
  44. #endif // VIDEO_QUALITY_THRESHOLD_H_