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_WALL_CLOCK_TIME_SOURCE_H_ | 5 #ifndef MEDIA_BASE_WALL_CLOCK_TIME_SOURCE_H_ |
6 #define MEDIA_BASE_WALL_CLOCK_TIME_SOURCE_H_ | 6 #define MEDIA_BASE_WALL_CLOCK_TIME_SOURCE_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
10 #include "base/time/default_tick_clock.h" | 10 #include "base/time/default_tick_clock.h" |
11 #include "media/base/media_export.h" | 11 #include "media/base/media_export.h" |
12 #include "media/base/time_source.h" | 12 #include "media/base/time_source.h" |
13 | 13 |
14 namespace media { | 14 namespace media { |
15 | 15 |
16 // A time source that uses interpolation based on the system clock. | 16 // A time source that uses interpolation based on the system clock. |
17 class MEDIA_EXPORT WallClockTimeSource : public TimeSource { | 17 class MEDIA_EXPORT WallClockTimeSource : public TimeSource { |
18 public: | 18 public: |
19 WallClockTimeSource(); | 19 WallClockTimeSource(); |
20 ~WallClockTimeSource() override; | 20 ~WallClockTimeSource() override; |
21 | 21 |
22 // TimeSource implementation. | 22 // TimeSource implementation. |
23 void StartTicking() override; | 23 void StartTicking() override; |
24 void StopTicking() override; | 24 void StopTicking() override; |
25 void SetPlaybackRate(double playback_rate) override; | 25 void SetPlaybackRate(double playback_rate) override; |
26 void SetMediaTime(base::TimeDelta time) override; | 26 void SetMediaTime(base::TimeDelta time) override; |
27 base::TimeDelta CurrentMediaTime() override; | 27 base::TimeDelta CurrentMediaTime(base::TimeTicks* reference) override; |
28 bool GetWallClockTimes( | 28 bool GetWallClockTimes( |
29 const std::vector<base::TimeDelta>& media_timestamps, | 29 const std::vector<base::TimeDelta>& media_timestamps, |
30 std::vector<base::TimeTicks>* wall_clock_times) override; | 30 std::vector<base::TimeTicks>* wall_clock_times) override; |
31 | 31 |
32 void set_tick_clock_for_testing(base::TickClock* tick_clock) { | 32 void set_tick_clock_for_testing(base::TickClock* tick_clock) { |
33 tick_clock_ = tick_clock; | 33 tick_clock_ = tick_clock; |
34 } | 34 } |
35 | 35 |
36 private: | 36 private: |
37 base::TimeDelta CurrentMediaTime_Locked(); | 37 base::TimeDelta CurrentMediaTime_Locked(base::TimeTicks* reference); |
38 | 38 |
39 // Allow for an injectable tick clock for testing. | 39 // Allow for an injectable tick clock for testing. |
40 base::DefaultTickClock default_tick_clock_; | 40 base::DefaultTickClock default_tick_clock_; |
41 | 41 |
42 // If specified, used instead of |default_tick_clock_|. | 42 // If specified, used instead of |default_tick_clock_|. |
43 base::TickClock* tick_clock_; | 43 base::TickClock* tick_clock_; |
44 | 44 |
45 bool ticking_; | 45 bool ticking_; |
46 | 46 |
47 // While ticking we can interpolate the current media time by measuring the | 47 // While ticking we can interpolate the current media time by measuring the |
48 // delta between our reference ticks and the current system ticks and scaling | 48 // delta between our reference ticks and the current system ticks and scaling |
49 // that time by the playback rate. | 49 // that time by the playback rate. |
50 double playback_rate_; | 50 double playback_rate_; |
51 base::TimeDelta base_timestamp_; | 51 base::TimeDelta base_timestamp_; |
52 base::TimeTicks reference_time_; | 52 base::TimeTicks reference_time_; |
53 | 53 |
54 // TODO(scherkus): Remove internal locking from this class after access to | 54 // TODO(scherkus): Remove internal locking from this class after access to |
55 // Renderer::CurrentMediaTime() is single threaded http://crbug.com/370634 | 55 // Renderer::CurrentMediaTime() is single threaded http://crbug.com/370634 |
56 base::Lock lock_; | 56 base::Lock lock_; |
57 | 57 |
58 DISALLOW_COPY_AND_ASSIGN(WallClockTimeSource); | 58 DISALLOW_COPY_AND_ASSIGN(WallClockTimeSource); |
59 }; | 59 }; |
60 | 60 |
61 } // namespace media | 61 } // namespace media |
62 | 62 |
63 #endif // MEDIA_BASE_WALL_CLOCK_TIME_SOURCE_H_ | 63 #endif // MEDIA_BASE_WALL_CLOCK_TIME_SOURCE_H_ |
OLD | NEW |