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

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

Issue 11607003: Add a Clock and TickClock interface for mocking out time (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix warnings Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « base/time/tick_clock.cc ('k') | media/base/clock.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_CLOCK_H_ 5 #ifndef MEDIA_BASE_CLOCK_H_
6 #define MEDIA_BASE_CLOCK_H_ 6 #define MEDIA_BASE_CLOCK_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "media/base/media_export.h" 10 #include "media/base/media_export.h"
11 11
12 namespace base {
13 class Clock;
14 } // namespace base
15
12 namespace media { 16 namespace media {
13 17
14 // A clock represents a single source of time to allow audio and video streams 18 // A clock represents a single source of time to allow audio and video streams
15 // to synchronize with each other. Clock essentially tracks the media time with 19 // to synchronize with each other. Clock essentially tracks the media time with
16 // respect to some other source of time, whether that may be the system clock or 20 // respect to some other source of time, whether that may be the system clock or
17 // updates via SetTime(). Clock uses linear interpolation to calculate the 21 // updates via SetTime(). Clock uses linear interpolation to calculate the
18 // current media time since the last time SetTime() was called. 22 // current media time since the last time SetTime() was called.
19 // 23 //
20 // Clocks start off paused with a playback rate of 1.0f and a media time of 0. 24 // Clocks start off paused with a playback rate of 1.0f and a media time of 0.
21 // 25 //
22 // Clock is not thread-safe and must be externally locked. 26 // Clock is not thread-safe and must be externally locked.
23 // 27 //
24 // TODO(scherkus): Clock will some day be responsible for executing callbacks 28 // TODO(scherkus): Clock will some day be responsible for executing callbacks
25 // given a media time. This will be used primarily by video renderers. For now 29 // given a media time. This will be used primarily by video renderers. For now
26 // we'll keep using a poll-and-sleep solution. 30 // we'll keep using a poll-and-sleep solution.
27 class MEDIA_EXPORT Clock { 31 class MEDIA_EXPORT Clock {
28 public: 32 public:
29 // Type for a static function pointer that acts as a time source. 33 explicit Clock(base::Clock* clock);
30 typedef base::Time(TimeProvider)();
31
32 explicit Clock(TimeProvider* time_provider);
33 ~Clock(); 34 ~Clock();
34 35
35 // Returns true if the clock is running. 36 // Returns true if the clock is running.
36 bool IsPlaying() const; 37 bool IsPlaying() const;
37 38
38 // Starts the clock and returns the current media time, which will increase 39 // Starts the clock and returns the current media time, which will increase
39 // with respect to the current playback rate. 40 // with respect to the current playback rate.
40 base::TimeDelta Play(); 41 base::TimeDelta Play();
41 42
42 // Stops the clock and returns the current media time, which will remain 43 // Stops the clock and returns the current media time, which will remain
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 void UpdateReferencePoints(base::TimeDelta current_time); 85 void UpdateReferencePoints(base::TimeDelta current_time);
85 86
86 // Returns the time elapsed based on the current reference points, ignoring 87 // Returns the time elapsed based on the current reference points, ignoring
87 // the |max_time_| cap. 88 // the |max_time_| cap.
88 base::TimeDelta EstimatedElapsedTime(); 89 base::TimeDelta EstimatedElapsedTime();
89 90
90 // Returns the current media time treating the given time as the latest 91 // Returns the current media time treating the given time as the latest
91 // value as returned by |time_provider_|. 92 // value as returned by |time_provider_|.
92 base::TimeDelta ElapsedViaProvidedTime(const base::Time& time) const; 93 base::TimeDelta ElapsedViaProvidedTime(const base::Time& time) const;
93 94
94 base::Time GetTimeFromProvider() const;
95
96 base::TimeDelta ClampToValidTimeRange(base::TimeDelta time) const; 95 base::TimeDelta ClampToValidTimeRange(base::TimeDelta time) const;
97 96
98 // Function returning current time in base::Time units. 97 base::Clock* const clock_;
99 TimeProvider* time_provider_;
100 98
101 // Whether the clock is running. 99 // Whether the clock is running.
102 bool playing_; 100 bool playing_;
103 101
104 // Whether the clock is stalled because it has reached the |max_time_| 102 // Whether the clock is stalled because it has reached the |max_time_|
105 // allowed. 103 // allowed.
106 bool underflow_; 104 bool underflow_;
107 105
108 // The system clock time when this clock last starting playing or had its 106 // The system clock time when this clock last starting playing or had its
109 // time set via SetTime(). 107 // time set via SetTime().
(...skipping 11 matching lines...) Expand all
121 119
122 // Duration of the media. 120 // Duration of the media.
123 base::TimeDelta duration_; 121 base::TimeDelta duration_;
124 122
125 DISALLOW_COPY_AND_ASSIGN(Clock); 123 DISALLOW_COPY_AND_ASSIGN(Clock);
126 }; 124 };
127 125
128 } // namespace media 126 } // namespace media
129 127
130 #endif // MEDIA_BASE_CLOCK_H_ 128 #endif // MEDIA_BASE_CLOCK_H_
OLDNEW
« no previous file with comments | « base/time/tick_clock.cc ('k') | media/base/clock.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698