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

Unified Diff: media/base/moving_average.h

Issue 1021943002: Introduce cadence based VideoRendererAlgorithm. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Switch to MovingAverage. Created 5 years, 8 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
Index: media/base/moving_average.h
diff --git a/media/base/moving_average.h b/media/base/moving_average.h
new file mode 100644
index 0000000000000000000000000000000000000000..0e6305e304b4d2aacda4f7310a1ce813494428e2
--- /dev/null
+++ b/media/base/moving_average.h
@@ -0,0 +1,46 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_BASE_MOVING_AVERAGE_H_
+#define MEDIA_BASE_MOVING_AVERAGE_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "base/time/time.h"
+#include "media/base/media_export.h"
+
+namespace media {
+
+// Simple class for calculating a moving average of fixed size.
+class MEDIA_EXPORT MovingAverage {
+ public:
+ // Creates a MovingAverage instance with space for |depth| samples.
+ explicit MovingAverage(size_t depth);
+ ~MovingAverage();
+
+ // Add a new sample to the average; replaces the oldest sample if |depth_| has
xhwang 2015/04/28 16:01:07 nit: s/Add/Adds
DaleCurtis 2015/04/28 21:45:24 Done.
+ // been exceeded. Updates |total_| to the new sum of values.
+ void AddSample(base::TimeDelta sample);
+
+ // Returns the current average of all held samples.
+ base::TimeDelta Average() const;
+
+ // Resets the state of the class to its initial post-construction state.
+ void Reset();
+
+ private:
+ // Maximum number of elements allowed in the average.
+ const size_t depth_;
+
+ // Number of elements seen thus far.
+ size_t count_;
+
+ scoped_ptr<base::TimeDelta[]> samples_;
xhwang 2015/04/28 16:01:07 Will a vector work?
DaleCurtis 2015/04/28 21:45:24 Done.
+ base::TimeDelta total_;
+
+ DISALLOW_COPY_AND_ASSIGN(MovingAverage);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_MOVING_AVERAGE_H_
« no previous file with comments | « media/base/BUILD.gn ('k') | media/base/moving_average.cc » ('j') | media/base/moving_average.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698