123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #ifndef RTC_BASE_NUMERICS_MOVING_AVERAGE_H_
- #define RTC_BASE_NUMERICS_MOVING_AVERAGE_H_
- #include <stddef.h>
- #include <stdint.h>
- #include <vector>
- #include "absl/types/optional.h"
- namespace rtc {
- class MovingAverage {
- public:
-
- explicit MovingAverage(size_t window_size);
- ~MovingAverage();
-
- MovingAverage(const MovingAverage&) = delete;
- MovingAverage& operator=(const MovingAverage&) = delete;
-
- void AddSample(int sample);
-
-
-
- absl::optional<int> GetAverageRoundedDown() const;
-
- absl::optional<int> GetAverageRoundedToClosest() const;
-
- absl::optional<double> GetUnroundedAverage() const;
-
- void Reset();
-
- size_t Size() const;
- private:
-
- size_t count_ = 0;
-
- int64_t sum_ = 0;
-
-
- std::vector<int> history_;
- };
- }
- #endif
|