Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1217)

Unified Diff: webrtc/modules/video_coding/utility/moving_average.h

Issue 2310853002: Refactor QualityScaler and MovingAverage (Closed)
Patch Set: fix build error Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/modules/video_coding/BUILD.gn ('k') | webrtc/modules/video_coding/utility/moving_average.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/video_coding/utility/moving_average.h
diff --git a/webrtc/modules/video_coding/utility/moving_average.h b/webrtc/modules/video_coding/utility/moving_average.h
index cdad50f0f9096b3bd8df3f0ac2de49a7ec020a2c..dd4238503854f60c922e15a203c63db377475ebd 100644
--- a/webrtc/modules/video_coding/utility/moving_average.h
+++ b/webrtc/modules/video_coding/utility/moving_average.h
@@ -11,63 +11,25 @@
#ifndef WEBRTC_MODULES_VIDEO_CODING_UTILITY_MOVING_AVERAGE_H_
#define WEBRTC_MODULES_VIDEO_CODING_UTILITY_MOVING_AVERAGE_H_
-#include <stddef.h>
+#include <vector>
-#include <list>
-
-#include "webrtc/typedefs.h"
+#include "webrtc/base/optional.h"
namespace webrtc {
-template <class T>
class MovingAverage {
public:
- MovingAverage();
- void AddSample(T sample);
- bool GetAverage(size_t num_samples, T* average);
+ explicit MovingAverage(size_t s);
+ void AddSample(int sample);
+ rtc::Optional<int> GetAverage() const;
+ rtc::Optional<int> GetAverage(size_t num_samples) const;
void Reset();
- int size();
+ size_t size() const;
private:
- T sum_;
- std::list<T> samples_;
+ size_t count_ = 0;
+ int sum_ = 0;
+ std::vector<int> sum_history_;
};
-
-template <class T>
-MovingAverage<T>::MovingAverage()
- : sum_(static_cast<T>(0)) {}
-
-template <class T>
-void MovingAverage<T>::AddSample(T sample) {
- samples_.push_back(sample);
- sum_ += sample;
-}
-
-template <class T>
-bool MovingAverage<T>::GetAverage(size_t num_samples, T* avg) {
- if (num_samples > samples_.size())
- return false;
-
- // Remove old samples.
- while (num_samples < samples_.size()) {
- sum_ -= samples_.front();
- samples_.pop_front();
- }
-
- *avg = sum_ / static_cast<T>(num_samples);
- return true;
-}
-
-template <class T>
-void MovingAverage<T>::Reset() {
- sum_ = static_cast<T>(0);
- samples_.clear();
-}
-
-template <class T>
-int MovingAverage<T>::size() {
- return samples_.size();
-}
-
} // namespace webrtc
#endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_MOVING_AVERAGE_H_
« no previous file with comments | « webrtc/modules/video_coding/BUILD.gn ('k') | webrtc/modules/video_coding/utility/moving_average.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698