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

Unified Diff: media/base/moving_average.cc

Issue 1021943002: Introduce cadence based VideoRendererAlgorithm. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix frame expiration when Render() never called. 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.cc
diff --git a/media/base/moving_average.cc b/media/base/moving_average.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c012941378723cbe03cdc2aff0c9d546fa1ab134
--- /dev/null
+++ b/media/base/moving_average.cc
@@ -0,0 +1,40 @@
+// 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.
+
+#include "media/base/moving_average.h"
+
+#include <algorithm>
+
+namespace media {
+
+MovingAverage::MovingAverage(size_t depth)
+ : depth_(depth), count_(0), samples_(new base::TimeDelta[depth]) {
+}
+
+MovingAverage::~MovingAverage() {
+}
+
+void MovingAverage::AddSample(base::TimeDelta sample) {
+ if (count_ < depth_) {
+ samples_[count_++] = sample;
+ total_ += sample;
+ return;
+ }
+
+ base::TimeDelta& oldest = samples_[count_++ % depth_];
+ total_ += sample - oldest;
+ oldest = sample;
+}
+
+base::TimeDelta MovingAverage::Average() const {
+ DCHECK_GT(count_, 0u);
+ return total_ / std::min(depth_, count_);
+}
+
+void MovingAverage::Reset() {
+ count_ = 0;
+ total_ = base::TimeDelta();
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698