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

Side by Side Diff: media/cast/base/clock_drift_smoother.h

Issue 388663003: Cast: Reshuffle files under media/cast (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: missing includes Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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_CAST_BASE_CLOCK_DRIFT_SMOOTHER_H_
6 #define MEDIA_CAST_BASE_CLOCK_DRIFT_SMOOTHER_H_
7
8 #include "base/time/time.h"
9
10 namespace media {
11 namespace cast {
12
13 // Tracks the jitter and drift between clocks, providing a smoothed offset.
14 // Internally, a Simple IIR filter is used to maintain a running average that
15 // moves at a rate based on the passage of time.
16 class ClockDriftSmoother {
17 public:
18 // |time_constant| is the amount of time an impulse signal takes to decay by
19 // ~62.6%. Interpretation: If the value passed to several Update() calls is
20 // held constant for T seconds, then the running average will have moved
21 // towards the value by ~62.6% from where it started.
22 explicit ClockDriftSmoother(base::TimeDelta time_constant);
23 ~ClockDriftSmoother();
24
25 // Returns the current offset.
26 base::TimeDelta Current() const;
27
28 // Discard all history and reset to exactly |offset|, measured |now|.
29 void Reset(base::TimeTicks now, base::TimeDelta offset);
30
31 // Update the current offset, which was measured |now|. The weighting that
32 // |measured_offset| will have on the running average is influenced by how
33 // much time has passed since the last call to this method (or Reset()).
34 // |now| should be monotonically non-decreasing over successive calls of this
35 // method.
36 void Update(base::TimeTicks now, base::TimeDelta measured_offset);
37
38 // Returns a time constant suitable for most use cases, where the clocks
39 // are expected to drift very little with respect to each other, and the
40 // jitter caused by clock imprecision is effectively canceled out.
41 static base::TimeDelta GetDefaultTimeConstant();
42
43 private:
44 const base::TimeDelta time_constant_;
45 base::TimeTicks last_update_time_;
46 double estimate_us_;
47 };
48
49 } // namespace cast
50 } // namespace media
51
52 #endif // MEDIA_CAST_BASE_CLOCK_DRIFT_SMOOTHER_H_
OLDNEW
« no previous file with comments | « media/cast/audio_sender/audio_sender_unittest.cc ('k') | media/cast/base/clock_drift_smoother.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698