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/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/synchronization/lock.h" |
9 #include "media/base/media_export.h" | 10 #include "media/base/media_export.h" |
10 #include "media/base/time_source.h" | 11 #include "media/base/time_source.h" |
11 | 12 |
12 namespace base { | 13 namespace base { |
13 class TickClock; | 14 class TickClock; |
14 } | 15 } |
15 | 16 |
16 namespace media { | 17 namespace media { |
17 | 18 |
18 // A time source that uses interpolation based on the system clock. | 19 // A time source that uses interpolation based on the system clock. |
19 class MEDIA_EXPORT WallClockTimeSource : public TimeSource { | 20 class MEDIA_EXPORT WallClockTimeSource : public TimeSource { |
20 public: | 21 public: |
21 WallClockTimeSource(); | 22 WallClockTimeSource(); |
22 virtual ~WallClockTimeSource(); | 23 virtual ~WallClockTimeSource(); |
23 | 24 |
24 // TimeSource implementation. | 25 // TimeSource implementation. |
25 virtual void StartTicking() OVERRIDE; | 26 virtual void StartTicking() OVERRIDE; |
26 virtual void StopTicking() OVERRIDE; | 27 virtual void StopTicking() OVERRIDE; |
27 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; | 28 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; |
28 virtual void SetMediaTime(base::TimeDelta time) OVERRIDE; | 29 virtual void SetMediaTime(base::TimeDelta time) OVERRIDE; |
29 virtual base::TimeDelta CurrentMediaTime() OVERRIDE; | 30 virtual base::TimeDelta CurrentMediaTime() OVERRIDE; |
30 virtual base::TimeDelta CurrentMediaTimeForSyncingVideo() OVERRIDE; | 31 virtual base::TimeDelta CurrentMediaTimeForSyncingVideo() OVERRIDE; |
31 | 32 |
32 void SetTickClockForTesting(scoped_ptr<base::TickClock> tick_clock); | 33 void SetTickClockForTesting(scoped_ptr<base::TickClock> tick_clock); |
33 | 34 |
34 private: | 35 private: |
| 36 base::TimeDelta CurrentMediaTime_Locked(); |
| 37 |
35 scoped_ptr<base::TickClock> tick_clock_; | 38 scoped_ptr<base::TickClock> tick_clock_; |
36 bool ticking_; | 39 bool ticking_; |
37 | 40 |
38 // While ticking we can interpolate the current media time by measuring the | 41 // While ticking we can interpolate the current media time by measuring the |
39 // delta between our reference ticks and the current system ticks and scaling | 42 // delta between our reference ticks and the current system ticks and scaling |
40 // that time by the playback rate. | 43 // that time by the playback rate. |
41 float playback_rate_; | 44 float playback_rate_; |
42 base::TimeDelta base_time_; | 45 base::TimeDelta base_time_; |
43 base::TimeTicks reference_wall_ticks_; | 46 base::TimeTicks reference_wall_ticks_; |
44 | 47 |
| 48 // TODO(scherkus): Remove internal locking from this class after access to |
| 49 // Renderer::CurrentMediaTime() is single threaded http://crbug.com/370634 |
| 50 base::Lock lock_; |
| 51 |
45 DISALLOW_COPY_AND_ASSIGN(WallClockTimeSource); | 52 DISALLOW_COPY_AND_ASSIGN(WallClockTimeSource); |
46 }; | 53 }; |
47 | 54 |
48 } // namespace media | 55 } // namespace media |
49 | 56 |
50 #endif // MEDIA_BASE_WALL_CLOCK_TIME_SOURCE_H_ | 57 #endif // MEDIA_BASE_WALL_CLOCK_TIME_SOURCE_H_ |
OLD | NEW |