Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: media/base/clock_impl.h

Issue 159517: Implemented a proper clock for audio/video synchronization. (Closed)
Patch Set: Now with convenience! Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/clock.h ('k') | media/base/clock_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_
OLDNEW
« no previous file with comments | « media/base/clock.h ('k') | media/base/clock_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698