Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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_BASE_TIME_DELTA_INTERPOLATOR_H_ | |
| 6 #define MEDIA_BASE_TIME_DELTA_INTERPOLATOR_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/time/time.h" | |
| 10 #include "media/base/media_export.h" | |
| 11 | |
| 12 namespace base { | |
| 13 class TickClock; | |
| 14 } // namespace base | |
| 15 | |
| 16 namespace media { | |
| 17 | |
| 18 // Interpolates between two TimeDeltas based on the passage of wall clock time | |
| 19 // and the current playback rate. | |
| 20 // | |
| 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. | |
| 25 // | |
| 26 // |tick_clock| is used for sampling wall clock time for interpolating. | |
| 27 explicit TimeDeltaInterpolator(base::TickClock* tick_clock); | |
| 28 ~TimeDeltaInterpolator(); | |
| 29 | |
| 30 bool interpolating() { return interpolating_; } | |
| 31 | |
| 32 // Starts returning interpolated TimeDelta values. | |
| 33 // | |
| 34 // |tick_clock| will be queried for a new reference time value. | |
| 35 base::TimeDelta StartInterpolating(); | |
| 36 | |
| 37 // Stops returning interpolated TimeDelta values. | |
| 38 // | |
| 39 // |tick_clock| will be queried for a new reference time value. | |
| 40 base::TimeDelta StopInterpolating(); | |
| 41 | |
| 42 // Sets a new rate at which to interpolate. | |
| 43 // | |
| 44 // |tick_clock| will be queried for a new reference time value. | |
| 45 void SetPlaybackRate(float playback_rate); | |
| 46 | |
| 47 // Sets the two timestamps to interpolate between at |playback_rate_|. | |
| 48 // | |
| 49 // |max_time| is typically the media timestamp of the last audio frame | |
| 50 // buffered by the audio hardware. | |
| 51 void SetTime(base::TimeDelta current_time, base::TimeDelta max_time); | |
|
acolwell GONE FROM CHROMIUM
2014/07/09 00:42:46
s/SetTime/SetInterpolationRange/ , s/SetTime/SetBo
scherkus (not reviewing)
2014/07/09 01:54:32
Agreed -- done.
| |
| 52 | |
| 53 // Sets the upper bound used for interpolation. Note that if |max_time| is | |
| 54 // less than what was previously set via SetTime(), then all future calls | |
| 55 // to GetInterpolatedTime() will return |max_time|. | |
| 56 void SetMaxTime(base::TimeDelta max_time); | |
|
acolwell GONE FROM CHROMIUM
2014/07/09 00:42:46
s/SetMaxTime/SetUpperBound/ since that is what the
scherkus (not reviewing)
2014/07/09 01:54:32
Done.
| |
| 57 | |
| 58 // Computes an interpolated time based on SetTime(). | |
| 59 base::TimeDelta GetInterpolatedTime(); | |
| 60 | |
| 61 private: | |
| 62 // Updates the reference points based on the current calculated time. | |
| 63 void UpdateReferencePoints(); | |
| 64 | |
| 65 // Updates the reference points based on the given |current_time|. | |
| 66 void UpdateReferencePoints(base::TimeDelta current_time); | |
| 67 | |
| 68 // Returns the time elapsed based on the current reference points, ignoring | |
| 69 // the |max_time_| cap. | |
| 70 base::TimeDelta EstimatedElapsedTime(); | |
| 71 | |
| 72 // Translates |time| into the current media time, based on the perspective of | |
| 73 // the monotonically-increasing system clock. | |
| 74 base::TimeDelta ElapsedViaProvidedTime(const base::TimeTicks& time) const; | |
| 75 | |
| 76 base::TimeDelta ClampToValidTimeRange(base::TimeDelta time) const; | |
| 77 | |
| 78 base::TickClock* const tick_clock_; | |
| 79 | |
| 80 bool interpolating_; | |
| 81 | |
| 82 // Whether the clock is stalled because it has reached the |max_time_| | |
| 83 // allowed. | |
| 84 bool underflow_; | |
| 85 | |
| 86 // The monotonic system clock time when this Clock last started playing or had | |
| 87 // its time set via SetTime(). | |
| 88 base::TimeTicks reference_; | |
| 89 | |
| 90 // Current accumulated amount of media time. The remaining portion must be | |
| 91 // calculated by comparing the system time to the reference time. | |
| 92 base::TimeDelta media_time_; | |
|
acolwell GONE FROM CHROMIUM
2014/07/09 00:42:46
nit: s/media_time_/lower_bound_/?
scherkus (not reviewing)
2014/07/09 01:54:32
Done.
| |
| 93 | |
| 94 // Current playback rate. | |
| 95 float playback_rate_; | |
| 96 | |
| 97 // The maximum time that can be returned by calls to Elapsed(). | |
| 98 base::TimeDelta max_time_; | |
|
acolwell GONE FROM CHROMIUM
2014/07/09 00:42:46
nit: s/max_time_/upper_bound_/?
scherkus (not reviewing)
2014/07/09 01:54:32
Done.
| |
| 99 | |
| 100 DISALLOW_COPY_AND_ASSIGN(TimeDeltaInterpolator); | |
| 101 }; | |
| 102 | |
| 103 } // namespace media | |
| 104 | |
| 105 #endif // MEDIA_BASE_TIME_DELTA_INTERPOLATOR_H_ | |
| OLD | NEW |