blob: bc31cd5213f9f1cac08a4b911c442c683b51b34a [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
11#ifndef WEBRTC_MODULES_VIDEO_CODING_UTILITY_MOVING_AVERAGE_H_
12#define WEBRTC_MODULES_VIDEO_CODING_UTILITY_MOVING_AVERAGE_H_
13
kthelgason194f40a2016-09-14 02:14:58 -070014#include <vector>
Niels Möller718a7632016-06-13 13:06:01 +020015
Edward Lemurc20978e2017-07-06 19:44:34 +020016#include "webrtc/rtc_base/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);
22 void AddSample(int sample);
23 rtc::Optional<int> GetAverage() const;
24 rtc::Optional<int> GetAverage(size_t num_samples) const;
jackychen61b4d512015-04-21 15:30:11 -070025 void Reset();
kthelgason194f40a2016-09-14 02:14:58 -070026 size_t size() const;
jackychen61b4d512015-04-21 15:30:11 -070027
28 private:
kthelgason194f40a2016-09-14 02:14:58 -070029 size_t count_ = 0;
30 int sum_ = 0;
31 std::vector<int> sum_history_;
jackychen61b4d512015-04-21 15:30:11 -070032};
jackychen61b4d512015-04-21 15:30:11 -070033} // namespace webrtc
34
kjellander@webrtc.orgb7ce9642015-11-18 23:04:10 +010035#endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_MOVING_AVERAGE_H_