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

Side by Side Diff: content/browser/media/capture/feedback_signal_accumulator.h

Issue 1097633005: FeedbackSignalAccumulator utility class for averaging feedback signals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: TimeWeightedAverage --> FeedbackSignalAccumulator, with simplifications! 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 (c) 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 CONTENT_BROWSER_MEDIA_CAPTURE_FEEDBACK_SIGNAL_ACCUMULATOR_H_
6 #define CONTENT_BROWSER_MEDIA_CAPTURE_FEEDBACK_SIGNAL_ACCUMULATOR_H_
7
8 #include "base/time/time.h"
9 #include "content/common/content_export.h"
10
11 namespace content {
12
13 // Utility class for maintaining an exponentially-decaying average of feedback
14 // signal values whose updates occur at undetermined, possibly irregular time
15 // intervals.
16 //
17 // Usage note: Reset() must be called at least once before the first call to
18 // Update().
19 class CONTENT_EXPORT FeedbackSignalAccumulator {
20 public:
21 // |half_life| is the amount of time that must pass between two data points to
22 // move the accumulated average value halfway in-between. Example: If
23 // |half_life| is one second, then calling Reset(0.0, t=0s) and then
24 // Update(1.0, t=1s) will result in an accumulated average value of 0.5.
25 explicit FeedbackSignalAccumulator(base::TimeDelta half_life);
26
27 // Erase all memory of historical values, re-starting with the given
28 // |starting_value|.
29 void Reset(double starting_value, base::TimeTicks timestamp);
30 base::TimeTicks reset_time() const { return reset_time_; }
31
32 // Apply the given |value|, which was observed at the given |timestamp|, to
33 // the accumulated average. If the timestamp is in chronological order, the
34 // update succeeds and this method returns true. Otherwise the update has no
35 // effect and false is returned. If there are two or more updates at the same
36 // |timestamp|, only the one with the greatest value will be accounted for.
hubbe 2015/05/12 19:10:07 Document why "greatest value" makes sense.
miu 2015/05/12 20:58:37 Done. (Documented at class-level comments.)
37 bool Update(double value, base::TimeTicks timestamp);
38 base::TimeTicks update_time() const { return update_time_; }
39
40 // Returns the current accumulated average value.
41 double current() const { return average_; }
42
43 private:
44 // In conjunction with the |update_time_| and |prior_update_time_|, this is
45 // used to compute the weight of the current update value versus the prior
46 // accumulated average.
47 const base::TimeDelta half_life_;
48
49 base::TimeTicks reset_time_; // |timestamp| passed in last call to Reset().
50 double average_; // Current accumulated average.
51 double update_value_; // Latest |value| accepted by Update().
52 base::TimeTicks update_time_; // Latest |timestamp| accepted by Update().
53 double prior_average_; // Accumulated average before last call to Update().
54 base::TimeTicks prior_update_time_; // |timestamp| in prior call to Update().
55 };
56
57 } // namespace content
58
59 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_FEEDBACK_SIGNAL_ACCUMULATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698