Chromium Code Reviews| Index: media/base/time_delta_interpolator.h |
| diff --git a/media/base/time_delta_interpolator.h b/media/base/time_delta_interpolator.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..986425918c5a679998ecaccc194aa29fdc72cb65 |
| --- /dev/null |
| +++ b/media/base/time_delta_interpolator.h |
| @@ -0,0 +1,105 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MEDIA_BASE_TIME_DELTA_INTERPOLATOR_H_ |
| +#define MEDIA_BASE_TIME_DELTA_INTERPOLATOR_H_ |
| + |
| +#include "base/basictypes.h" |
| +#include "base/time/time.h" |
| +#include "media/base/media_export.h" |
| + |
| +namespace base { |
| +class TickClock; |
| +} // namespace base |
| + |
| +namespace media { |
| + |
| +// Interpolates between two TimeDeltas based on the passage of wall clock time |
| +// and the current playback rate. |
| +// |
| +// TimeDeltaInterpolator is not thread-safe and must be externally locked. |
| +class MEDIA_EXPORT TimeDeltaInterpolator { |
| + public: |
| + // Constructs an interpolator initialized to zero with a rate of 1.0. |
| + // |
| + // |tick_clock| is used for sampling wall clock time for interpolating. |
| + explicit TimeDeltaInterpolator(base::TickClock* tick_clock); |
| + ~TimeDeltaInterpolator(); |
| + |
| + bool interpolating() { return interpolating_; } |
| + |
| + // Starts returning interpolated TimeDelta values. |
| + // |
| + // |tick_clock| will be queried for a new reference time value. |
| + base::TimeDelta StartInterpolating(); |
| + |
| + // Stops returning interpolated TimeDelta values. |
| + // |
| + // |tick_clock| will be queried for a new reference time value. |
| + base::TimeDelta StopInterpolating(); |
| + |
| + // Sets a new rate at which to interpolate. |
| + // |
| + // |tick_clock| will be queried for a new reference time value. |
| + void SetPlaybackRate(float playback_rate); |
| + |
| + // Sets the two timestamps to interpolate between at |playback_rate_|. |
| + // |
| + // |max_time| is typically the media timestamp of the last audio frame |
| + // buffered by the audio hardware. |
| + 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.
|
| + |
| + // Sets the upper bound used for interpolation. Note that if |max_time| is |
| + // less than what was previously set via SetTime(), then all future calls |
| + // to GetInterpolatedTime() will return |max_time|. |
| + 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.
|
| + |
| + // Computes an interpolated time based on SetTime(). |
| + base::TimeDelta GetInterpolatedTime(); |
| + |
| + private: |
| + // Updates the reference points based on the current calculated time. |
| + void UpdateReferencePoints(); |
| + |
| + // Updates the reference points based on the given |current_time|. |
| + void UpdateReferencePoints(base::TimeDelta current_time); |
| + |
| + // Returns the time elapsed based on the current reference points, ignoring |
| + // the |max_time_| cap. |
| + base::TimeDelta EstimatedElapsedTime(); |
| + |
| + // Translates |time| into the current media time, based on the perspective of |
| + // the monotonically-increasing system clock. |
| + base::TimeDelta ElapsedViaProvidedTime(const base::TimeTicks& time) const; |
| + |
| + base::TimeDelta ClampToValidTimeRange(base::TimeDelta time) const; |
| + |
| + base::TickClock* const tick_clock_; |
| + |
| + bool interpolating_; |
| + |
| + // Whether the clock is stalled because it has reached the |max_time_| |
| + // allowed. |
| + bool underflow_; |
| + |
| + // The monotonic system clock time when this Clock last started playing or had |
| + // its time set via SetTime(). |
| + base::TimeTicks reference_; |
| + |
| + // Current accumulated amount of media time. The remaining portion must be |
| + // calculated by comparing the system time to the reference time. |
| + 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.
|
| + |
| + // Current playback rate. |
| + float playback_rate_; |
| + |
| + // The maximum time that can be returned by calls to Elapsed(). |
| + 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.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(TimeDeltaInterpolator); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_BASE_TIME_DELTA_INTERPOLATOR_H_ |