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 CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_CLOCK_DEVICE_H_ | 5 #ifndef CHROMECAST_PUBLIC_MEDIA_MEDIA_CLOCK_DEVICE_H_ |
6 #define CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_CLOCK_DEVICE_H_ | 6 #define CHROMECAST_PUBLIC_MEDIA_MEDIA_CLOCK_DEVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | |
11 #include "base/macros.h" | |
12 #include "base/threading/non_thread_safe.h" | |
13 #include "base/time/time.h" | |
14 | |
15 namespace chromecast { | 10 namespace chromecast { |
16 namespace media { | 11 namespace media { |
17 | 12 |
18 // MediaClockDevice - | 13 // MediaClockDevice - |
19 // | 14 // |
20 // State machine: | 15 // State machine: |
21 // ------------------- | 16 // ------------------- |
22 // | | | 17 // | | |
23 // v | | 18 // v | |
24 // kUninitialized --> kIdle --------- kRunning | 19 // kUninitialized --> kIdle --------- kRunning |
25 // | 20 // |
26 // {any state} --> kError | 21 // {any state} --> kError |
27 // | 22 // |
28 // Notes: | 23 // Notes: |
29 // - Hardware resources are acquired when transitioning from the | 24 // - Hardware resources are acquired when transitioning from the |
30 // |kUninitialized| state to the |kIdle| state. | 25 // |kUninitialized| state to the |kIdle| state. |
31 // - The initial value of the timeline can only be set in the kIdle state. | 26 // - The initial value of the timeline can only be set in the kIdle state. |
32 // | 27 // |
33 class MediaClockDevice | 28 class MediaClockDevice { |
34 : NON_EXPORTED_BASE(public base::NonThreadSafe) { | |
35 public: | 29 public: |
36 enum State { | 30 enum State { |
37 kStateUninitialized, | 31 kStateUninitialized, |
38 kStateIdle, | 32 kStateIdle, |
39 kStateRunning, | 33 kStateRunning, |
40 kStateError, | 34 kStateError, |
41 }; | 35 }; |
42 | 36 |
43 // Return true if transition from |state1| to |state2| is a valid state | 37 virtual ~MediaClockDevice() {} |
44 // transition. | |
45 static bool IsValidStateTransition(State state1, State state2); | |
46 | |
47 // Returns string representation of state (for logging) | |
48 static std::string StateToString(const State& state); | |
49 | |
50 MediaClockDevice(); | |
51 virtual ~MediaClockDevice(); | |
52 | 38 |
53 // Return the current state of the media clock. | 39 // Return the current state of the media clock. |
54 virtual State GetState() const = 0; | 40 virtual State GetState() const = 0; |
55 | 41 |
56 // Changes the state and performs any necessary transitions. | 42 // Changes the state and performs any necessary transitions. |
57 // Returns true when successful. | 43 // Returns true when successful. |
58 virtual bool SetState(State new_state) = 0; | 44 virtual bool SetState(State new_state) = 0; |
59 | 45 |
60 // Sets the initial value of the timeline. | 46 // Sets the initial value of the timeline in microseconds. |
61 // Can only be invoked in state kStateIdle. | 47 // Can only be invoked in state kStateIdle. |
62 // Returns true when successful. | 48 // Returns true when successful. |
63 virtual bool ResetTimeline(base::TimeDelta time) = 0; | 49 virtual bool ResetTimeline(int64_t time_microseconds) = 0; |
64 | 50 |
65 // Sets the clock rate. | 51 // Sets the clock rate. |
66 // Setting it to 0 means the clock is not progressing and that the renderer | 52 // Setting it to 0 means the clock is not progressing and that the renderer |
67 // tied to this media clock should pause rendering. | 53 // tied to this media clock should pause rendering. |
68 // Can only be invoked in states kStateIdle or kStateRunning. | 54 // Can only be invoked in states kStateIdle or kStateRunning. |
69 virtual bool SetRate(float rate) = 0; | 55 virtual bool SetRate(float rate) = 0; |
70 | 56 |
71 // Retrieves the media clock time. | 57 // Retrieves the media clock time in microseconds. |
72 // Can only be invoked in states kStateIdle or kStateRunning. | 58 // Can only be invoked in states kStateIdle or kStateRunning. |
73 virtual base::TimeDelta GetTime() = 0; | 59 virtual int64_t GetTime() = 0; |
74 | |
75 private: | |
76 DISALLOW_COPY_AND_ASSIGN(MediaClockDevice); | |
77 }; | 60 }; |
78 | 61 |
79 } // namespace media | 62 } // namespace media |
80 } // namespace chromecast | 63 } // namespace chromecast |
81 | 64 |
82 #endif // CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_CLOCK_DEVICE_H_ | 65 #endif // CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_CLOCK_DEVICE_H_ |
OLD | NEW |