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

Side by Side 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, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/base/moving_average.h"
6
7 #include <algorithm>
8
9 namespace media {
10
11 MovingAverage::MovingAverage(size_t depth)
12 : depth_(depth), count_(0), samples_(new base::TimeDelta[depth]) {
13 }
14
15 MovingAverage::~MovingAverage() {
16 }
17
18 void MovingAverage::AddSample(base::TimeDelta sample) {
19 if (count_ < depth_) {
20 samples_[count_++] = sample;
21 total_ += sample;
22 return;
23 }
24
25 base::TimeDelta& oldest = samples_[count_++ % depth_];
26 total_ += sample - oldest;
27 oldest = sample;
28 }
29
30 base::TimeDelta MovingAverage::Average() const {
31 DCHECK_GT(count_, 0u);
32 return total_ / std::min(depth_, count_);
33 }
34
35 void MovingAverage::Reset() {
36 count_ = 0;
37 total_ = base::TimeDelta();
38 }
39
40 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698