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

Side by Side Diff: chromecast/public/media/media_component_device.h

Issue 1257013003: Load CMA backend from shared library (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unit test + android fixes Created 5 years, 4 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
OLDNEW
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_COMPONENT_DEVICE_H_ 5 #ifndef CHROMECAST_PUBLIC_MEDIA_MEDIA_COMPONENT_DEVICE_H_
6 #define CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_COMPONENT_DEVICE_H_ 6 #define CHROMECAST_PUBLIC_MEDIA_MEDIA_COMPONENT_DEVICE_H_
7 7
8 #include <stdint.h>
8 #include <string> 9 #include <string>
9 10
10 #include "base/basictypes.h" 11 #include "cast_key_system.h"
11 #include "base/callback.h" 12 #include "chromecast/public/time_delta.h"
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "base/time/time.h"
16 13
17 namespace chromecast { 14 namespace chromecast {
18 namespace media { 15 namespace media {
19 class DecoderBufferBase; 16 class DecoderBuffer;
20 class DecryptContext;
21 17
22 // MediaComponentDevice - 18 // MediaComponentDevice -
23 // 19 //
24 // State machine: 20 // State machine:
25 // -------------- kRunning <--- 21 // -------------- kRunning <---
26 // | ^ | 22 // | ^ |
27 // v | | 23 // v | |
28 // kUninitialized <--> kIdle -------------- | 24 // kUninitialized <--> kIdle -------------- |
29 // ^ | | 25 // ^ | |
30 // | v | 26 // | v |
31 // -------------- kPaused <---- 27 // -------------- kPaused <----
32 // {any state} --> kError 28 // {any state} --> kError
33 // kError --> kUninitialized 29 // kError --> kUninitialized
34 // 30 //
35 // Notes: 31 // Notes:
36 // - Hardware resources are acquired when transitioning from the 32 // - Hardware resources are acquired when transitioning from the
37 // |kUninitialized| state to the |kIdle| state. 33 // |kUninitialized| state to the |kIdle| state.
38 // - Buffers can be pushed only in the kRunning or kPaused states. 34 // - Buffers can be pushed only in the kRunning or kPaused states.
39 // - The end of stream is signaled through a special buffer. 35 // - The end of stream is signaled through a special buffer.
40 // Once the end of stream buffer is fed, no other buffer 36 // Once the end of stream buffer is fed, no other buffer
41 // can be fed until the FSM goes through the kIdle state again. 37 // can be fed until the FSM goes through the kIdle state again.
42 // - In both kPaused and kRunning states, frames can be fed. 38 // - In both kPaused and kRunning states, frames can be fed.
43 // However, frames are possibly rendered only in the kRunning state. 39 // However, frames are possibly rendered only in the kRunning state.
44 // - In the kRunning state, frames are rendered according to the clock rate. 40 // - In the kRunning state, frames are rendered according to the clock rate.
45 // - All the hardware resources must be released in the |kError| state. 41 // - All the hardware resources must be released in the |kError| state.
46 // 42 //
47 class MediaComponentDevice 43 class MediaComponentDevice {
48 : NON_EXPORTED_BASE(public base::NonThreadSafe) {
49 public: 44 public:
50 enum State { 45 enum State {
51 kStateUninitialized, 46 kStateUninitialized,
52 kStateIdle, 47 kStateIdle,
53 kStateRunning, 48 kStateRunning,
54 kStatePaused, 49 kStatePaused,
55 kStateError, 50 kStateError,
56 }; 51 };
57 52
58 enum FrameStatus { 53 enum FrameStatus {
59 kFrameSuccess, 54 kFrameSuccess,
60 kFrameFailed, 55 kFrameFailed,
61 kFramePending, 56 kFramePending,
62 }; 57 };
63 typedef base::Callback<void(FrameStatus)> FrameStatusCB;
64 58
65 struct Client { 59 // Interface for receiving status when PushFrame has completed.
66 Client(); 60 class FrameStatusCB {
67 ~Client(); 61 public:
62 virtual ~FrameStatusCB() {}
63 virtual void Run(FrameStatus status) = 0;
64 };
68 65
69 // Invoked when playback reaches the end of stream. 66 // Client callbacks interface
70 base::Closure eos_cb; 67 class Client {
68 public:
69 virtual ~Client() {}
70 virtual void OnEndOfStream() = 0;
71 }; 71 };
72 72
73 // The statistics are computed since the media component left the idle state. 73 // The statistics are computed since the media component left the idle state.
74 // For video, a sample is defined as a frame. 74 // For video, a sample is defined as a frame.
75 struct Statistics { 75 struct Statistics {
76 uint64 decoded_bytes; 76 uint64_t decoded_bytes;
77 uint64 decoded_samples; 77 uint64_t decoded_samples;
78 uint64 dropped_samples; 78 uint64_t dropped_samples;
79 }; 79 };
80 80
81 // Returns whether or not transitioning from |state1| to |state2| is valid. 81 // Returns whether or not transitioning from |state1| to |state2| is valid.
82 static bool IsValidStateTransition(State state1, State state2); 82 inline static bool IsValidStateTransition(State state1, State state2) {
83 if (state2 == state1)
84 return true;
85
86 // All states can transition to |kStateError|.
87 bool is_transition_valid = (state2 == kStateError);
88
89 // All the other valid FSM transitions.
90 is_transition_valid =
91 is_transition_valid ||
92 (state1 == kStateUninitialized && (state2 == kStateIdle)) ||
93 (state1 == kStateIdle &&
94 (state2 == kStateRunning || state2 == kStatePaused ||
95 state2 == kStateUninitialized)) ||
96 (state1 == kStatePaused &&
97 (state2 == kStateIdle || state2 == kStateRunning)) ||
98 (state1 == kStateRunning &&
99 (state2 == kStateIdle || state2 == kStatePaused)) ||
100 (state1 == kStateError && (state2 == kStateUninitialized));
101
102 return is_transition_valid;
103 }
83 104
84 // Returns string representation of state (for logging) 105 // Returns string representation of state (for logging)
85 static std::string StateToString(const State& state); 106 inline static std::string StateToString(const State& state) {
107 switch (state) {
108 case kStateUninitialized:
109 return "Uninitialized";
110 case kStateIdle:
111 return "Idle";
112 case kStateRunning:
113 return "Running";
114 case kStatePaused:
115 return "Paused";
116 case kStateError:
117 return "Error";
118 default:
119 return "";
120 }
121 }
byungchul 2015/07/27 18:22:23 Are they necessary for shlibs?
halliwell 2015/07/28 02:19:36 yes, all vendors rely on these currently.
byungchul 2015/07/28 18:05:43 See the other comment in media_clock_device.h
halliwell 2015/07/28 23:26:06 As for clock, removed from public headers.
86 122
87 MediaComponentDevice(); 123 MediaComponentDevice() {}
88 virtual ~MediaComponentDevice(); 124 virtual ~MediaComponentDevice() {}
89 125
90 // Register |client| as the media event handler. 126 // Register |client| as the media event handler. Implementation
91 virtual void SetClient(const Client& client) = 0; 127 // takes ownership of |client|.
128 virtual void SetClient(Client* client) = 0;
92 129
93 // Changes the state and performs any necessary transitions. 130 // Changes the state and performs any necessary transitions.
94 // Returns true when successful. 131 // Returns true when successful.
95 virtual bool SetState(State new_state) = 0; 132 virtual bool SetState(State new_state) = 0;
96 133
97 // Returns the current state of the media component. 134 // Returns the current state of the media component.
98 virtual State GetState() const = 0; 135 virtual State GetState() const = 0;
99 136
100 // Sets the time where rendering should start. 137 // Sets the time where rendering should start.
101 // Return true when successful. 138 // Return true when successful.
102 // Can only be invoked in state kStateIdle. 139 // Can only be invoked in state kStateIdle.
103 virtual bool SetStartPts(base::TimeDelta time) = 0; 140 virtual bool SetStartPts(TimeDelta time) = 0;
104 141
105 // Pushes a frame. 142 // Pushes a frame.
143 // The implementation takes ownership of |buffer|.
106 // |completion_cb| is only invoked if the returned value is |kFramePending|. 144 // |completion_cb| is only invoked if the returned value is |kFramePending|.
107 // In this specific case, no additional frame can be pushed before 145 // In this specific case, no additional frame can be pushed before
108 // |completion_cb| is invoked. 146 // |completion_cb| is invoked.
109 // Note: |completion_cb| cannot be invoked with |kFramePending|. 147 // Note: |completion_cb| cannot be invoked with |kFramePending|.
110 // Note: pushing the pending frame should be aborted when the state goes back 148 // Note: pushing the pending frame should be aborted when the state goes back
111 // to kStateIdle. |completion_cb| is not invoked in that case. 149 // to kStateIdle. |completion_cb| is not invoked in that case.
112 virtual FrameStatus PushFrame( 150 // Implementation must take ownership of completion_cb and free after calling.
113 const scoped_refptr<DecryptContext>& decrypt_context, 151 virtual FrameStatus PushFrame(CastKeySystem key_system,
114 const scoped_refptr<DecoderBufferBase>& buffer, 152 DecoderBuffer* buffer,
115 const FrameStatusCB& completion_cb) = 0; 153 FrameStatusCB* completion_cb) = 0;
116
117 // Returns the rendering time of the latest rendered sample.
118 // Can be invoked only in states kStateRunning or kStatePaused.
119 // Returns |kNoTimestamp()| if the playback time cannot be retrieved.
120 virtual base::TimeDelta GetRenderingTime() const = 0;
121 154
122 // Returns the pipeline latency: i.e. the amount of data 155 // Returns the pipeline latency: i.e. the amount of data
123 // in the pipeline that have not been rendered yet. 156 // in the pipeline that have not been rendered yet.
124 // Returns |kNoTimestamp()| if the latency is not available. 157 // Returns |kNoTimestamp()| if the latency is not available.
125 virtual base::TimeDelta GetRenderingDelay() const = 0; 158 virtual TimeDelta GetRenderingDelay() const = 0;
126 159
127 // Returns the playback statistics. Statistics are computed since the media 160 // Returns the playback statistics. Statistics are computed since the media
128 // component left the idle state. 161 // component left the idle state.
129 // Returns true when successful. 162 // Returns true when successful.
130 // Can only be invoked in state kStateRunning. 163 // Can only be invoked in state kStateRunning.
131 virtual bool GetStatistics(Statistics* stats) const = 0; 164 virtual bool GetStatistics(Statistics* stats) const = 0;
132
133 private:
134 DISALLOW_COPY_AND_ASSIGN(MediaComponentDevice);
135 }; 165 };
136 166
137 } // namespace media 167 } // namespace media
138 } // namespace chromecast 168 } // namespace chromecast
139 169
140 #endif // CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_COMPONENT_DEVICE_H_ 170 #endif // CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_COMPONENT_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698