Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_BASE_TIME_SOURCE_H_ | 5 #ifndef MEDIA_BASE_TIME_SOURCE_H_ |
| 6 #define MEDIA_BASE_TIME_SOURCE_H_ | 6 #define MEDIA_BASE_TIME_SOURCE_H_ |
| 7 | 7 |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 8 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 9 #include "media/base/media_export.h" | 12 #include "media/base/media_export.h" |
| 10 | 13 |
| 11 namespace media { | 14 namespace media { |
| 12 | 15 |
| 13 // A TimeSource is capable of providing the current media time. | 16 // A TimeSource is capable of providing the current media time. |
| 14 class MEDIA_EXPORT TimeSource { | 17 class MEDIA_EXPORT TimeSource { |
| 15 public: | 18 public: |
| 19 // Helper alias for converting media timestamps into a wall clock timestamps. | |
| 20 using WallClockTimeCB = | |
| 21 base::Callback<bool(const std::vector<base::TimeDelta>&, | |
| 22 std::vector<base::TimeTicks>*)>; | |
| 23 | |
| 16 TimeSource() {} | 24 TimeSource() {} |
| 17 virtual ~TimeSource() {} | 25 virtual ~TimeSource() {} |
| 18 | 26 |
| 19 // Signal the time source to start ticking. It is expected that values from | 27 // Signal the time source to start ticking. It is expected that values from |
| 20 // CurrentMediaTime() will start increasing. | 28 // CurrentMediaTime() will start increasing. |
| 21 virtual void StartTicking() = 0; | 29 virtual void StartTicking() = 0; |
| 22 | 30 |
| 23 // Signal the time source to stop ticking. It is expected that values from | 31 // Signal the time source to stop ticking. It is expected that values from |
| 24 // CurrentMediaTime() will remain constant. | 32 // CurrentMediaTime() will remain constant. |
| 25 virtual void StopTicking() = 0; | 33 virtual void StopTicking() = 0; |
| 26 | 34 |
| 27 // Updates the current playback rate. It is expected that values from | 35 // Updates the current playback rate. It is expected that values from |
| 28 // CurrentMediaTime() will eventually reflect the new playback rate (e.g., the | 36 // CurrentMediaTime() will eventually reflect the new playback rate (e.g., the |
| 29 // media time will advance at half speed if the rate was set to 0.5f). | 37 // media time will advance at half speed if the rate was set to 0.5). |
| 30 virtual void SetPlaybackRate(double playback_rate) = 0; | 38 virtual void SetPlaybackRate(double playback_rate) = 0; |
| 31 | 39 |
| 32 // Sets the media time to start ticking from. Only valid to call while the | 40 // Sets the media time to start ticking from. Only valid to call while the |
| 33 // time source is not ticking. | 41 // time source is not ticking. |
| 34 virtual void SetMediaTime(base::TimeDelta time) = 0; | 42 virtual void SetMediaTime(base::TimeDelta time) = 0; |
| 35 | 43 |
| 36 // Returns the current media timestamp relative to the timestamp set by | 44 // Returns the current media timestamp relative to the timestamp set by |
| 37 // SetMediaTime(). | 45 // SetMediaTime(). |
| 38 // | 46 // |
| 39 // Values returned are intended for informational purposes, such as displaying | 47 // Values returned are intended for informational purposes, such as displaying |
| 40 // UI with the current minute and second count. While it is guaranteed values | 48 // UI with the current minute and second count. While it is guaranteed values |
| 41 // will never go backwards, the frequency at which they update may be low. | 49 // will never go backwards, the frequency at which they update may be low. |
| 42 virtual base::TimeDelta CurrentMediaTime() = 0; | 50 virtual base::TimeDelta CurrentMediaTime() = 0; |
| 43 | 51 |
| 44 // Converts a media timestamp into a wall clock time. If the media time is | 52 // Converts a vector of media timestamps into a vector of wall clock times. If |
| 45 // stopped, returns a null TimeTicks. | 53 // the media time is stopped, returns false and does not modify the output |
| 54 // vector. Returns true and converts all timestamps otherwise. Guarantees that | |
| 55 // wall clock time does not go backwards for monotonically increasing media | |
|
xhwang
2015/05/12 04:46:53
Q for "does not go backwards": Can f(a) == f(b) fo
DaleCurtis
2015/05/12 05:35:42
Not unless there's a rounding error, f(a) != f(b)
xhwang
2015/05/12 05:45:42
nit: "does not go backwards" means a >= b, which s
DaleCurtis
2015/05/12 16:50:04
I'm still not clear on your nit here :) Within a s
xhwang
2015/05/12 17:20:55
Just say the wall clock time is a strictly increas
| |
| 56 // timestamps. | |
| 46 // | 57 // |
| 47 // |media_time| values too far ahead of the current media time will return an | 58 // Each timestamp converted from |media_timestamps| will be pushed into |
| 48 // estimated value; as such, these values may go backwards in time slightly. | 59 // |wall_clock_times| such that after all timestamps are converted, the two |
| 60 // vectors are parallel (media_timestamps[i] -> wall_clock_times[i]). | |
| 49 // | 61 // |
| 50 // |media_time| values behind the current media time may be significantly | 62 // |media_timestamps| values too far ahead of the current media time will |
| 51 // incorrect if the playback rate has changed recently. The only guarantee is | 63 // be converted to an estimated value; as such, these values may go backwards |
| 52 // that the returned time will be less than the current wall clock time. | 64 // in time slightly between calls to GetWallClockTime(). |
| 53 virtual base::TimeTicks GetWallClockTime(base::TimeDelta media_time) = 0; | 65 // |
| 66 // |media_timestamps| values behind the current media time may be | |
| 67 // significantly incorrect if the playback rate has changed recently. The only | |
| 68 // guarantee is that the returned time will be less than the current wall | |
| 69 // clock time. | |
| 70 virtual bool GetWallClockTime( | |
|
xhwang
2015/05/12 04:46:53
bike shedding: should it be GetWallClockTime_s_?
DaleCurtis
2015/05/12 05:35:42
Done.
| |
| 71 const std::vector<base::TimeDelta>& media_timestamps, | |
| 72 std::vector<base::TimeTicks>* wall_clock_times) = 0; | |
| 54 }; | 73 }; |
| 55 | 74 |
| 56 } // namespace media | 75 } // namespace media |
| 57 | 76 |
| 58 #endif // MEDIA_BASE_TIME_SOURCE_H_ | 77 #endif // MEDIA_BASE_TIME_SOURCE_H_ |
| OLD | NEW |