| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 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 // An implementation of Clock based on the system clock. ClockImpl uses linear |
| 6 // interpolation to calculate the current media time since the last time |
| 7 // SetTime() was called. |
| 8 // |
| 9 // ClockImpl is not thread-safe and must be externally locked. |
| 10 |
| 11 #ifndef MEDIA_BASE_CLOCK_IMPL_H_ |
| 12 #define MEDIA_BASE_CLOCK_IMPL_H_ |
| 13 |
| 14 #include "media/base/clock.h" |
| 15 |
| 16 namespace media { |
| 17 |
| 18 // Type for a static function pointer that acts as a time source. |
| 19 typedef base::Time(TimeProvider)(); |
| 20 |
| 21 class ClockImpl : public Clock { |
| 22 public: |
| 23 ClockImpl(TimeProvider* time_provider); |
| 24 virtual ~ClockImpl(); |
| 25 |
| 26 // Clock implementation. |
| 27 virtual base::TimeDelta Play(); |
| 28 virtual base::TimeDelta Pause(); |
| 29 virtual void SetPlaybackRate(float playback_rate); |
| 30 virtual void SetTime(const base::TimeDelta& time); |
| 31 virtual base::TimeDelta Elapsed() const; |
| 32 |
| 33 private: |
| 34 // Returns the current media time treating the given time as the latest |
| 35 // value as returned by |time_provider_|. |
| 36 base::TimeDelta ElapsedViaProvidedTime(const base::Time& time) const; |
| 37 |
| 38 // Function returning current time in base::Time units. |
| 39 TimeProvider* time_provider_; |
| 40 |
| 41 // Whether the clock is running. |
| 42 bool playing_; |
| 43 |
| 44 // The system clock time when this clock last starting playing or had its |
| 45 // time set via SetTime(). |
| 46 base::Time reference_; |
| 47 |
| 48 // Current accumulated amount of media time. The remaining portion must be |
| 49 // calculated by comparing the system time to the reference time. |
| 50 base::TimeDelta media_time_; |
| 51 |
| 52 // Current playback rate. |
| 53 float playback_rate_; |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(ClockImpl); |
| 56 }; |
| 57 |
| 58 } // namespace media |
| 59 |
| 60 #endif // MEDIA_BASE_CLOCK_IMPL_H_ |
| OLD | NEW |