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