OLD | NEW |
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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 base::TimeDelta Play(); | 41 base::TimeDelta Play(); |
42 | 42 |
43 // 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 |
44 // constant until Play() is called. | 44 // constant until Play() is called. |
45 base::TimeDelta Pause(); | 45 base::TimeDelta Pause(); |
46 | 46 |
47 // Sets a new playback rate. The rate at which the media time will increase | 47 // Sets a new playback rate. The rate at which the media time will increase |
48 // will now change. | 48 // will now change. |
49 void SetPlaybackRate(float playback_rate); | 49 void SetPlaybackRate(float playback_rate); |
50 | 50 |
51 // Forcefully sets the media time to the given time. This should only be used | 51 // Forcefully sets the media time to |current_time|. The second parameter is |
52 // where a discontinuity in the media is found (i.e., seeking). | 52 // the |max_time| that the clock should progress after a call to Play(). This |
53 void SetTime(const base::TimeDelta& time); | 53 // value is often the time of the end of the last frame buffered and decoded. |
| 54 // |
| 55 // These values are clamped to the duration of the video, which is initially |
| 56 // set to 0 (before SetDuration() is called). |
| 57 void SetTime(base::TimeDelta current_time, base::TimeDelta max_time); |
54 | 58 |
55 // Returns the current elapsed media time. | 59 // Sets the |max_time| to be returned by a call to Elapsed(). |max_time| must |
56 base::TimeDelta Elapsed() const; | 60 // be greater than or equal to the current Elapsed() time. |
| 61 void SetMaxTime(base::TimeDelta max_time); |
| 62 |
| 63 // Returns the current elapsed media time. Returns 0 if SetDuration() has |
| 64 // never been called. |
| 65 base::TimeDelta Elapsed(); |
| 66 |
| 67 // Sets the duration of the video. Clock expects the duration will be set |
| 68 // exactly once. |
| 69 void SetDuration(base::TimeDelta duration); |
| 70 |
| 71 // Resets clock to an uninitialized state. |
| 72 void Reset(); |
| 73 |
| 74 // Notifies the clock that the end of stream has been reached. The clock state |
| 75 // is updated accordingly. |
| 76 void EndOfStream(); |
| 77 |
| 78 // Returns the duration of the clock, or 0 if not set. |
| 79 base::TimeDelta Duration() const; |
57 | 80 |
58 private: | 81 private: |
| 82 // Returns true if the clock is advancing, false otherwise. |
| 83 bool IsTimeProgressing() const; |
| 84 |
| 85 // Updates the reference points based on the current calculated time. |
| 86 void UpdateReferencePoints(); |
| 87 |
| 88 // Updates the reference points based on the given |current_time|. |
| 89 void UpdateReferencePoints(base::TimeDelta current_time); |
| 90 |
| 91 // Returns the time elapsed based on the current reference points, ignoring |
| 92 // the |max_time_| cap. |
| 93 base::TimeDelta EstimatedElapsedTime(); |
| 94 |
59 // Returns the current media time treating the given time as the latest | 95 // Returns the current media time treating the given time as the latest |
60 // value as returned by |time_provider_|. | 96 // value as returned by |time_provider_|. |
61 base::TimeDelta ElapsedViaProvidedTime(const base::Time& time) const; | 97 base::TimeDelta ElapsedViaProvidedTime(const base::Time& time) const; |
62 | 98 |
63 base::Time GetTimeFromProvider() const; | 99 base::Time GetTimeFromProvider() const; |
64 | 100 |
| 101 base::TimeDelta ClampToValidTimeRange(base::TimeDelta time) const; |
| 102 |
65 // Function returning current time in base::Time units. | 103 // Function returning current time in base::Time units. |
66 TimeProvider* time_provider_; | 104 TimeProvider* time_provider_; |
67 | 105 |
68 // Whether the clock is running. | 106 // Whether the clock is running. |
69 bool playing_; | 107 bool playing_; |
70 | 108 |
| 109 // Whether the clock is stalled because it has reached the |max_time_| |
| 110 // allowed. |
| 111 bool underflow_; |
| 112 |
71 // The system clock time when this clock last starting playing or had its | 113 // The system clock time when this clock last starting playing or had its |
72 // time set via SetTime(). | 114 // time set via SetTime(). |
73 base::Time reference_; | 115 base::Time reference_; |
74 | 116 |
75 // Current accumulated amount of media time. The remaining portion must be | 117 // Current accumulated amount of media time. The remaining portion must be |
76 // calculated by comparing the system time to the reference time. | 118 // calculated by comparing the system time to the reference time. |
77 base::TimeDelta media_time_; | 119 base::TimeDelta media_time_; |
78 | 120 |
79 // Current playback rate. | 121 // Current playback rate. |
80 float playback_rate_; | 122 float playback_rate_; |
81 | 123 |
| 124 // The maximum time that can be returned by calls to GetCurrentTime. |
| 125 base::TimeDelta max_time_; |
| 126 |
| 127 // Duration of the media. |
| 128 base::TimeDelta duration_; |
| 129 |
82 DISALLOW_COPY_AND_ASSIGN(Clock); | 130 DISALLOW_COPY_AND_ASSIGN(Clock); |
83 }; | 131 }; |
84 | 132 |
85 } // namespace media | 133 } // namespace media |
86 | 134 |
87 #endif // MEDIA_BASE_CLOCK_H_ | 135 #endif // MEDIA_BASE_CLOCK_H_ |
OLD | NEW |