blob: 77ce633b18fcc16f6f001d717d01d16dd5adb796 [file] [log] [blame]
jackychen61b4d512015-04-21 15:30:11 -07001/*
2 * Copyright (c) 2015 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 MODULES_VIDEO_CODING_UTILITY_MOVING_AVERAGE_H_
12#define MODULES_VIDEO_CODING_UTILITY_MOVING_AVERAGE_H_
jackychen61b4d512015-04-21 15:30:11 -070013
kthelgason194f40a2016-09-14 02:14:58 -070014#include <vector>
Niels Möller718a7632016-06-13 13:06:01 +020015
Danil Chapovalov0040b662018-06-18 10:48:16 +020016#include "absl/types/optional.h"
jackychen61b4d512015-04-21 15:30:11 -070017
18namespace webrtc {
jackychen61b4d512015-04-21 15:30:11 -070019class MovingAverage {
20 public:
kthelgason194f40a2016-09-14 02:14:58 -070021 explicit MovingAverage(size_t s);
Paulina Hensmana680a6a2018-04-05 11:42:24 +020022 ~MovingAverage();
kthelgason194f40a2016-09-14 02:14:58 -070023 void AddSample(int sample);
Danil Chapovalov0040b662018-06-18 10:48:16 +020024 absl::optional<int> GetAverage() const;
25 absl::optional<int> GetAverage(size_t num_samples) const;
jackychen61b4d512015-04-21 15:30:11 -070026 void Reset();
kthelgason194f40a2016-09-14 02:14:58 -070027 size_t size() const;
jackychen61b4d512015-04-21 15:30:11 -070028
29 private:
kthelgason194f40a2016-09-14 02:14:58 -070030 size_t count_ = 0;
31 int sum_ = 0;
32 std::vector<int> sum_history_;
jackychen61b4d512015-04-21 15:30:11 -070033};
jackychen61b4d512015-04-21 15:30:11 -070034} // namespace webrtc
35
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020036#endif // MODULES_VIDEO_CODING_UTILITY_MOVING_AVERAGE_H_