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
3 // found in the LICENSE file.
5 #ifndef MEDIA_BASE_WALL_CLOCK_TIME_SOURCE_H_
6 #define MEDIA_BASE_WALL_CLOCK_TIME_SOURCE_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/synchronization/lock.h"
10 #include "media/base/media_export.h"
11 #include "media/base/time_source.h"
19 // A time source that uses interpolation based on the system clock.
20 class MEDIA_EXPORT WallClockTimeSource
: public TimeSource
{
22 WallClockTimeSource();
23 ~WallClockTimeSource() override
;
25 // TimeSource implementation.
26 void StartTicking() override
;
27 void StopTicking() override
;
28 void SetPlaybackRate(float playback_rate
) override
;
29 void SetMediaTime(base::TimeDelta time
) override
;
30 base::TimeDelta
CurrentMediaTime() override
;
31 base::TimeDelta
CurrentMediaTimeForSyncingVideo() override
;
33 void SetTickClockForTesting(scoped_ptr
<base::TickClock
> tick_clock
);
36 base::TimeDelta
CurrentMediaTime_Locked();
38 scoped_ptr
<base::TickClock
> tick_clock_
;
41 // While ticking we can interpolate the current media time by measuring the
42 // delta between our reference ticks and the current system ticks and scaling
43 // that time by the playback rate.
45 base::TimeDelta base_time_
;
46 base::TimeTicks reference_wall_ticks_
;
48 // TODO(scherkus): Remove internal locking from this class after access to
49 // Renderer::CurrentMediaTime() is single threaded http://crbug.com/370634
52 DISALLOW_COPY_AND_ASSIGN(WallClockTimeSource
);
57 #endif // MEDIA_BASE_WALL_CLOCK_TIME_SOURCE_H_