OLD | NEW |
---|---|
(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 #ifndef MEDIA_BASE_MOVING_AVERAGE_H_ | |
6 #define MEDIA_BASE_MOVING_AVERAGE_H_ | |
7 | |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "base/time/time.h" | |
10 #include "media/base/media_export.h" | |
11 | |
12 namespace media { | |
13 | |
14 // Simple class for calculating a moving average of fixed size. | |
15 class MEDIA_EXPORT MovingAverage { | |
16 public: | |
17 // Creates a MovingAverage instance with space for |depth| samples. | |
18 explicit MovingAverage(size_t depth); | |
19 ~MovingAverage(); | |
20 | |
21 // 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.
| |
22 // been exceeded. Updates |total_| to the new sum of values. | |
23 void AddSample(base::TimeDelta sample); | |
24 | |
25 // Returns the current average of all held samples. | |
26 base::TimeDelta Average() const; | |
27 | |
28 // Resets the state of the class to its initial post-construction state. | |
29 void Reset(); | |
30 | |
31 private: | |
32 // Maximum number of elements allowed in the average. | |
33 const size_t depth_; | |
34 | |
35 // Number of elements seen thus far. | |
36 size_t count_; | |
37 | |
38 scoped_ptr<base::TimeDelta[]> samples_; | |
xhwang
2015/04/28 16:01:07
Will a vector work?
DaleCurtis
2015/04/28 21:45:24
Done.
| |
39 base::TimeDelta total_; | |
40 | |
41 DISALLOW_COPY_AND_ASSIGN(MovingAverage); | |
42 }; | |
43 | |
44 } // namespace media | |
45 | |
46 #endif // MEDIA_BASE_MOVING_AVERAGE_H_ | |
OLD | NEW |