Revert of Cleanup NQE (patchset #5 id:80001 of https://codereview.chromium.org/127748...
[chromium-blink-merge.git] / media / base / time_delta_interpolator.h
blob7dbda69387bb1a9439d1a4997766abe0196854ff
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.
5 #ifndef MEDIA_BASE_TIME_DELTA_INTERPOLATOR_H_
6 #define MEDIA_BASE_TIME_DELTA_INTERPOLATOR_H_
8 #include "base/basictypes.h"
9 #include "base/time/time.h"
10 #include "media/base/media_export.h"
12 namespace base {
13 class TickClock;
14 } // namespace base
16 namespace media {
18 // Interpolates between two TimeDeltas based on the passage of wall clock time
19 // and the current playback rate.
21 // TimeDeltaInterpolator is not thread-safe and must be externally locked.
22 class MEDIA_EXPORT TimeDeltaInterpolator {
23 public:
24 // Constructs an interpolator initialized to zero with a rate of 1.0.
26 // |tick_clock| is used for sampling wall clock time for interpolating.
27 explicit TimeDeltaInterpolator(base::TickClock* tick_clock);
28 ~TimeDeltaInterpolator();
30 bool interpolating() { return interpolating_; }
32 // Starts returning interpolated TimeDelta values.
34 // |tick_clock| will be queried for a new reference time value.
35 base::TimeDelta StartInterpolating();
37 // Stops returning interpolated TimeDelta values.
39 // |tick_clock| will be queried for a new reference time value.
40 base::TimeDelta StopInterpolating();
42 // Sets a new rate at which to interpolate.
44 // |tick_clock| will be queried for a new reference time value.
45 void SetPlaybackRate(double playback_rate);
47 // Sets the two timestamps to interpolate between at |playback_rate_|.
48 // |upper_bound| must be greater or equal to |lower_bound|.
50 // |upper_bound| is typically the media timestamp of the last audio frame
51 // buffered by the audio hardware.
52 void SetBounds(base::TimeDelta lower_bound, base::TimeDelta upper_bound);
54 // Sets the upper bound used for interpolation. Note that if |upper_bound| is
55 // less than what was previously set via SetTime(), then all future calls
56 // to GetInterpolatedTime() will return |upper_bound|.
57 void SetUpperBound(base::TimeDelta upper_bound);
59 // Computes an interpolated time based on SetTime().
60 base::TimeDelta GetInterpolatedTime();
62 private:
63 base::TickClock* const tick_clock_;
65 bool interpolating_;
67 // The range of time to interpolate between.
68 base::TimeDelta lower_bound_;
69 base::TimeDelta upper_bound_;
71 // The monotonic system clock time used for interpolating between
72 // |lower_bound_| and |upper_bound_|.
73 base::TimeTicks reference_;
75 double playback_rate_;
77 DISALLOW_COPY_AND_ASSIGN(TimeDeltaInterpolator);
80 } // namespace media
82 #endif // MEDIA_BASE_TIME_DELTA_INTERPOLATOR_H_