Chromium Code Reviews| 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" | 10 #include "chromecast/public/time_delta.h" |
|
byungchul
2015/07/27 18:22:23
relative to chromecast/public
halliwell
2015/07/28 02:19:36
TimeDelta removed now anyway.
| |
| 11 #include "base/macros.h" | |
| 12 #include "base/threading/non_thread_safe.h" | |
| 13 #include "base/time/time.h" | |
| 14 | 11 |
| 15 namespace chromecast { | 12 namespace chromecast { |
| 16 namespace media { | 13 namespace media { |
| 17 | 14 |
| 18 // MediaClockDevice - | 15 // MediaClockDevice - |
| 19 // | 16 // |
| 20 // State machine: | 17 // State machine: |
| 21 // ------------------- | 18 // ------------------- |
| 22 // | | | 19 // | | |
| 23 // v | | 20 // v | |
| 24 // kUninitialized --> kIdle --------- kRunning | 21 // kUninitialized --> kIdle --------- kRunning |
| 25 // | 22 // |
| 26 // {any state} --> kError | 23 // {any state} --> kError |
| 27 // | 24 // |
| 28 // Notes: | 25 // Notes: |
| 29 // - Hardware resources are acquired when transitioning from the | 26 // - Hardware resources are acquired when transitioning from the |
| 30 // |kUninitialized| state to the |kIdle| state. | 27 // |kUninitialized| state to the |kIdle| state. |
| 31 // - The initial value of the timeline can only be set in the kIdle state. | 28 // - The initial value of the timeline can only be set in the kIdle state. |
| 32 // | 29 // |
| 33 class MediaClockDevice | 30 class MediaClockDevice { |
| 34 : NON_EXPORTED_BASE(public base::NonThreadSafe) { | |
| 35 public: | 31 public: |
| 36 enum State { | 32 enum State { |
| 37 kStateUninitialized, | 33 kStateUninitialized, |
| 38 kStateIdle, | 34 kStateIdle, |
| 39 kStateRunning, | 35 kStateRunning, |
| 40 kStateError, | 36 kStateError, |
| 41 }; | 37 }; |
| 42 | 38 |
| 43 // Return true if transition from |state1| to |state2| is a valid state | 39 // Return true if transition from |state1| to |state2| is a valid state |
| 44 // transition. | 40 // transition. |
| 45 static bool IsValidStateTransition(State state1, State state2); | 41 inline static bool IsValidStateTransition(State state1, State state2) { |
| 42 if (state2 == state1) | |
| 43 return true; | |
| 44 | |
| 45 // All states can transition to |kStateError|. | |
| 46 bool is_transition_valid = (state2 == kStateError); | |
| 47 | |
| 48 // All the other valid FSM transitions. | |
| 49 is_transition_valid = | |
| 50 is_transition_valid || | |
| 51 (state1 == kStateUninitialized && (state2 == kStateIdle)) || | |
| 52 (state1 == kStateIdle && | |
| 53 (state2 == kStateRunning || state2 == kStateUninitialized)) || | |
| 54 (state1 == kStateRunning && (state2 == kStateIdle)) || | |
| 55 (state1 == kStateError && (state2 == kStateUninitialized)); | |
| 56 | |
| 57 return is_transition_valid; | |
| 58 } | |
| 46 | 59 |
| 47 // Returns string representation of state (for logging) | 60 // Returns string representation of state (for logging) |
| 48 static std::string StateToString(const State& state); | 61 inline static std::string StateToString(const State& state) { |
| 62 switch (state) { | |
| 63 case kStateUninitialized: | |
| 64 return "Uninitialized"; | |
| 65 case kStateIdle: | |
| 66 return "Idle"; | |
| 67 case kStateRunning: | |
| 68 return "Running"; | |
| 69 case kStateError: | |
| 70 return "Error"; | |
| 71 default: | |
| 72 return ""; | |
| 73 } | |
| 74 } | |
|
byungchul
2015/07/27 18:22:23
Why are these 2 files defined here inline? Is it a
halliwell
2015/07/28 02:19:36
Yes, it's allowed. And all vendors call these fun
byungchul
2015/07/28 18:05:43
I think
1) StateToString() is not necessary to be
halliwell
2015/07/28 23:26:06
StateToString now moved out into implementation co
| |
| 49 | 75 |
| 50 MediaClockDevice(); | 76 MediaClockDevice() {} |
| 51 virtual ~MediaClockDevice(); | 77 virtual ~MediaClockDevice() {} |
| 52 | 78 |
| 53 // Return the current state of the media clock. | 79 // Return the current state of the media clock. |
| 54 virtual State GetState() const = 0; | 80 virtual State GetState() const = 0; |
| 55 | 81 |
| 56 // Changes the state and performs any necessary transitions. | 82 // Changes the state and performs any necessary transitions. |
| 57 // Returns true when successful. | 83 // Returns true when successful. |
| 58 virtual bool SetState(State new_state) = 0; | 84 virtual bool SetState(State new_state) = 0; |
| 59 | 85 |
| 60 // Sets the initial value of the timeline. | 86 // Sets the initial value of the timeline. |
| 61 // Can only be invoked in state kStateIdle. | 87 // Can only be invoked in state kStateIdle. |
| 62 // Returns true when successful. | 88 // Returns true when successful. |
| 63 virtual bool ResetTimeline(base::TimeDelta time) = 0; | 89 virtual bool ResetTimeline(TimeDelta time) = 0; |
| 64 | 90 |
| 65 // Sets the clock rate. | 91 // Sets the clock rate. |
| 66 // Setting it to 0 means the clock is not progressing and that the renderer | 92 // Setting it to 0 means the clock is not progressing and that the renderer |
| 67 // tied to this media clock should pause rendering. | 93 // tied to this media clock should pause rendering. |
| 68 // Can only be invoked in states kStateIdle or kStateRunning. | 94 // Can only be invoked in states kStateIdle or kStateRunning. |
| 69 virtual bool SetRate(float rate) = 0; | 95 virtual bool SetRate(float rate) = 0; |
| 70 | 96 |
| 71 // Retrieves the media clock time. | 97 // Retrieves the media clock time. |
| 72 // Can only be invoked in states kStateIdle or kStateRunning. | 98 // Can only be invoked in states kStateIdle or kStateRunning. |
| 73 virtual base::TimeDelta GetTime() = 0; | 99 virtual TimeDelta GetTime() = 0; |
| 74 | |
| 75 private: | |
| 76 DISALLOW_COPY_AND_ASSIGN(MediaClockDevice); | |
| 77 }; | 100 }; |
| 78 | 101 |
| 79 } // namespace media | 102 } // namespace media |
| 80 } // namespace chromecast | 103 } // namespace chromecast |
| 81 | 104 |
| 82 #endif // CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_CLOCK_DEVICE_H_ | 105 #endif // CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_CLOCK_DEVICE_H_ |
| OLD | NEW |