OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 CONTENT_BROWSER_MEDIA_CAPTURE_FEEDBACK_SIGNAL_ACCUMULATOR_H_ | 5 #ifndef MEDIA_CAPTURE_FEEDBACK_SIGNAL_ACCUMULATOR_H_ |
6 #define CONTENT_BROWSER_MEDIA_CAPTURE_FEEDBACK_SIGNAL_ACCUMULATOR_H_ | 6 #define MEDIA_CAPTURE_FEEDBACK_SIGNAL_ACCUMULATOR_H_ |
7 | 7 |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "content/common/content_export.h" | 9 #include "media/base/media_export.h" |
10 | 10 |
11 namespace content { | 11 namespace media { |
12 | 12 |
13 // Utility class for maintaining an exponentially-decaying average of feedback | 13 // Utility class for maintaining an exponentially-decaying average of feedback |
14 // signal values whose updates occur at undetermined, possibly irregular time | 14 // signal values whose updates occur at undetermined, possibly irregular time |
15 // intervals. | 15 // intervals. |
16 // | 16 // |
17 // Feedback signals can be made by multiple sources. Meaning, there can be | 17 // Feedback signals can be made by multiple sources. Meaning, there can be |
18 // several values provided for the same timestamp. In this case, the greatest | 18 // several values provided for the same timestamp. In this case, the greatest |
19 // value is retained and used to re-compute the average. Therefore, the values | 19 // value is retained and used to re-compute the average. Therefore, the values |
20 // provided to this class' methods should be appropriately translated with this | 20 // provided to this class' methods should be appropriately translated with this |
21 // in mind. For example, an "fraction available" metric should be translated | 21 // in mind. For example, an "fraction available" metric should be translated |
22 // into a "fraction utilized" one. | 22 // into a "fraction utilized" one. |
23 // | 23 // |
24 // Usage note: Reset() must be called at least once before the first call to | 24 // Usage note: Reset() must be called at least once before the first call to |
25 // Update(). | 25 // Update(). |
26 class CONTENT_EXPORT FeedbackSignalAccumulator { | 26 class MEDIA_EXPORT FeedbackSignalAccumulator { |
27 public: | 27 public: |
28 // |half_life| is the amount of time that must pass between two data points to | 28 // |half_life| is the amount of time that must pass between two data points to |
29 // move the accumulated average value halfway in-between. Example: If | 29 // move the accumulated average value halfway in-between. Example: If |
30 // |half_life| is one second, then calling Reset(0.0, t=0s) and then | 30 // |half_life| is one second, then calling Reset(0.0, t=0s) and then |
31 // Update(1.0, t=1s) will result in an accumulated average value of 0.5. | 31 // Update(1.0, t=1s) will result in an accumulated average value of 0.5. |
32 explicit FeedbackSignalAccumulator(base::TimeDelta half_life); | 32 explicit FeedbackSignalAccumulator(base::TimeDelta half_life); |
33 | 33 |
34 // Erase all memory of historical values, re-starting with the given | 34 // Erase all memory of historical values, re-starting with the given |
35 // |starting_value|. | 35 // |starting_value|. |
36 void Reset(double starting_value, base::TimeTicks timestamp); | 36 void Reset(double starting_value, base::TimeTicks timestamp); |
(...skipping 18 matching lines...) Expand all Loading... |
55 const base::TimeDelta half_life_; | 55 const base::TimeDelta half_life_; |
56 | 56 |
57 base::TimeTicks reset_time_; // |timestamp| passed in last call to Reset(). | 57 base::TimeTicks reset_time_; // |timestamp| passed in last call to Reset(). |
58 double average_; // Current accumulated average. | 58 double average_; // Current accumulated average. |
59 double update_value_; // Latest |value| accepted by Update(). | 59 double update_value_; // Latest |value| accepted by Update(). |
60 base::TimeTicks update_time_; // Latest |timestamp| accepted by Update(). | 60 base::TimeTicks update_time_; // Latest |timestamp| accepted by Update(). |
61 double prior_average_; // Accumulated average before last call to Update(). | 61 double prior_average_; // Accumulated average before last call to Update(). |
62 base::TimeTicks prior_update_time_; // |timestamp| in prior call to Update(). | 62 base::TimeTicks prior_update_time_; // |timestamp| in prior call to Update(). |
63 }; | 63 }; |
64 | 64 |
65 } // namespace content | 65 } // namespace media |
66 | 66 |
67 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_FEEDBACK_SIGNAL_ACCUMULATOR_H_ | 67 #endif // MEDIA_CAPTURE_FEEDBACK_SIGNAL_ACCUMULATOR_H_ |
OLD | NEW |