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

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: Switch to MovingAverage. 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),
13 count_(0),
14 samples_(new base::TimeDelta[depth]) {
15 }
16
17 MovingAverage::~MovingAverage() {}
18
19 void MovingAverage::AddSample(base::TimeDelta sample) {
20 if (count_ < depth_) {
21 samples_[count_++] = sample;
22 total_ += sample;
23 return;
24 }
xhwang 2015/04/28 16:01:07 If you initialize |samples_| with all zeros (which
DaleCurtis 2015/04/28 21:45:23 Done.
25
26 base::TimeDelta& oldest = samples_[count_++ % depth_];
27 total_ += sample - oldest;
28 oldest = sample;
29 }
30
31 base::TimeDelta MovingAverage::Average() const {
32 DCHECK_GT(count_, 0u);
33 return total_ / std::min(depth_, count_);
xhwang 2015/04/28 16:01:07 nit: If we always choose a |depth_| of a power of
DaleCurtis 2015/04/28 21:45:24 Hmm, I feel that's a bit of premature optimization
34 }
35
36 void MovingAverage::Reset() {
37 count_ = 0;
38 total_ = base::TimeDelta();
39 }
40
41 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698