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

Side by Side Diff: media/base/moving_average.h

Issue 1459923003: Fix Bug: Video with Variable Frame Rate plays at incorrect speed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « no previous file | media/base/moving_average.cc » ('j') | media/base/moving_average.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_BASE_MOVING_AVERAGE_H_ 5 #ifndef MEDIA_BASE_MOVING_AVERAGE_H_
6 #define MEDIA_BASE_MOVING_AVERAGE_H_ 6 #define MEDIA_BASE_MOVING_AVERAGE_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "media/base/media_export.h" 11 #include "media/base/media_export.h"
12 12
13 namespace media { 13 namespace media {
14 14
15 // Simple class for calculating a moving average of fixed size. 15 // Simple class for calculating a moving average of fixed size.
16 class MEDIA_EXPORT MovingAverage { 16 class MEDIA_EXPORT MovingAverage {
17 public: 17 public:
18 // Creates a MovingAverage instance with space for |depth| samples. 18 // Creates a MovingAverage instance with space for |depth| samples.
19 explicit MovingAverage(size_t depth); 19 explicit MovingAverage(size_t depth);
20 ~MovingAverage(); 20 ~MovingAverage();
21 21
22 // Adds a new sample to the average; replaces the oldest sample if |depth_| 22 // Adds a new sample to the average; replaces the oldest sample if |depth_|
23 // has been exceeded. Updates |total_| to the new sum of values. 23 // has been exceeded. Updates |total_| to the new sum of values.
24 void AddSample(base::TimeDelta sample); 24 void AddSample(base::TimeDelta sample);
25 25
26 // Returns the current average of all held samples. 26 // Returns the current average of all held samples.
27 base::TimeDelta Average() const; 27 base::TimeDelta Average() const;
28 28
29 // Returns the standard deviation of all held samples.
30 base::TimeDelta Deviation() const;
31
29 // Resets the state of the class to its initial post-construction state. 32 // Resets the state of the class to its initial post-construction state.
30 void Reset(); 33 void Reset();
31 34
32 size_t count() const { return count_; } 35 size_t count() const { return count_; }
33 36
34 private: 37 private:
35 // Maximum number of elements allowed in the average. 38 // Maximum number of elements allowed in the average.
36 const size_t depth_; 39 const size_t depth_;
37 40
38 // Number of elements seen thus far. 41 // Number of elements seen thus far.
39 uint64_t count_; 42 uint64_t count_;
40 43
41 std::vector<base::TimeDelta> samples_; 44 std::vector<base::TimeDelta> samples_;
42 base::TimeDelta total_; 45 base::TimeDelta total_;
46 double square_sum_ms_;
DaleCurtis 2015/11/20 23:50:46 Store as base::TimeDelta
qiangchen 2015/11/25 18:06:33 Probably may not be a good idea. As the unit is
43 47
44 DISALLOW_COPY_AND_ASSIGN(MovingAverage); 48 DISALLOW_COPY_AND_ASSIGN(MovingAverage);
45 }; 49 };
46 50
47 } // namespace media 51 } // namespace media
48 52
49 #endif // MEDIA_BASE_MOVING_AVERAGE_H_ 53 #endif // MEDIA_BASE_MOVING_AVERAGE_H_
OLDNEW
« no previous file with comments | « no previous file | media/base/moving_average.cc » ('j') | media/base/moving_average.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698