1 /*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 //#define LOG_NDEBUG 0
18 #define LOG_TAG "SoftOMXComponent"
19 #include <utils/Log.h>
20
21 #include <media/stagefright/omx/SoftOMXComponent.h>
22 #include <media/stagefright/foundation/ADebug.h>
23
24 namespace android {
25
SoftOMXComponent(const char * name,const OMX_CALLBACKTYPE * callbacks,OMX_PTR appData,OMX_COMPONENTTYPE ** component)26 SoftOMXComponent::SoftOMXComponent(
27 const char *name,
28 const OMX_CALLBACKTYPE *callbacks,
29 OMX_PTR appData,
30 OMX_COMPONENTTYPE **component)
31 : mName(name),
32 mCallbacks(callbacks),
33 mComponent(new OMX_COMPONENTTYPE),
34 mLibHandle(NULL) {
35 mComponent->nSize = sizeof(*mComponent);
36 mComponent->nVersion.s.nVersionMajor = 1;
37 mComponent->nVersion.s.nVersionMinor = 0;
38 mComponent->nVersion.s.nRevision = 0;
39 mComponent->nVersion.s.nStep = 0;
40 mComponent->pComponentPrivate = this;
41 mComponent->pApplicationPrivate = appData;
42
43 mComponent->GetComponentVersion = NULL;
44 mComponent->SendCommand = SendCommandWrapper;
45 mComponent->GetParameter = GetParameterWrapper;
46 mComponent->SetParameter = SetParameterWrapper;
47 mComponent->GetConfig = GetConfigWrapper;
48 mComponent->SetConfig = SetConfigWrapper;
49 mComponent->GetExtensionIndex = GetExtensionIndexWrapper;
50 mComponent->GetState = GetStateWrapper;
51 mComponent->ComponentTunnelRequest = NULL;
52 mComponent->UseBuffer = UseBufferWrapper;
53 mComponent->AllocateBuffer = AllocateBufferWrapper;
54 mComponent->FreeBuffer = FreeBufferWrapper;
55 mComponent->EmptyThisBuffer = EmptyThisBufferWrapper;
56 mComponent->FillThisBuffer = FillThisBufferWrapper;
57 mComponent->SetCallbacks = NULL;
58 mComponent->ComponentDeInit = NULL;
59 mComponent->UseEGLImage = NULL;
60 mComponent->ComponentRoleEnum = NULL;
61
62 *component = mComponent;
63 }
64
~SoftOMXComponent()65 SoftOMXComponent::~SoftOMXComponent() {
66 delete mComponent;
67 mComponent = NULL;
68 }
69
setLibHandle(void * libHandle)70 void SoftOMXComponent::setLibHandle(void *libHandle) {
71 CHECK(libHandle != NULL);
72 mLibHandle = libHandle;
73 }
74
libHandle() const75 void *SoftOMXComponent::libHandle() const {
76 return mLibHandle;
77 }
78
initCheck() const79 OMX_ERRORTYPE SoftOMXComponent::initCheck() const {
80 return OMX_ErrorNone;
81 }
82
name() const83 const char *SoftOMXComponent::name() const {
84 return mName.c_str();
85 }
86
notify(OMX_EVENTTYPE event,OMX_U32 data1,OMX_U32 data2,OMX_PTR data)87 void SoftOMXComponent::notify(
88 OMX_EVENTTYPE event,
89 OMX_U32 data1, OMX_U32 data2, OMX_PTR data) {
90 (*mCallbacks->EventHandler)(
91 mComponent,
92 mComponent->pApplicationPrivate,
93 event,
94 data1,
95 data2,
96 data);
97 }
98
notifyEmptyBufferDone(OMX_BUFFERHEADERTYPE * header)99 void SoftOMXComponent::notifyEmptyBufferDone(OMX_BUFFERHEADERTYPE *header) {
100 (*mCallbacks->EmptyBufferDone)(
101 mComponent, mComponent->pApplicationPrivate, header);
102 }
103
notifyFillBufferDone(OMX_BUFFERHEADERTYPE * header)104 void SoftOMXComponent::notifyFillBufferDone(OMX_BUFFERHEADERTYPE *header) {
105 (*mCallbacks->FillBufferDone)(
106 mComponent, mComponent->pApplicationPrivate, header);
107 }
108
109 // static
SendCommandWrapper(OMX_HANDLETYPE component,OMX_COMMANDTYPE cmd,OMX_U32 param,OMX_PTR data)110 OMX_ERRORTYPE SoftOMXComponent::SendCommandWrapper(
111 OMX_HANDLETYPE component,
112 OMX_COMMANDTYPE cmd,
113 OMX_U32 param,
114 OMX_PTR data) {
115 SoftOMXComponent *me =
116 (SoftOMXComponent *)
117 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
118
119 return me->sendCommand(cmd, param, data);
120 }
121
122 // static
GetParameterWrapper(OMX_HANDLETYPE component,OMX_INDEXTYPE index,OMX_PTR params)123 OMX_ERRORTYPE SoftOMXComponent::GetParameterWrapper(
124 OMX_HANDLETYPE component,
125 OMX_INDEXTYPE index,
126 OMX_PTR params) {
127 SoftOMXComponent *me =
128 (SoftOMXComponent *)
129 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
130
131 return me->getParameter(index, params);
132 }
133
134 // static
SetParameterWrapper(OMX_HANDLETYPE component,OMX_INDEXTYPE index,OMX_PTR params)135 OMX_ERRORTYPE SoftOMXComponent::SetParameterWrapper(
136 OMX_HANDLETYPE component,
137 OMX_INDEXTYPE index,
138 OMX_PTR params) {
139 SoftOMXComponent *me =
140 (SoftOMXComponent *)
141 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
142
143 return me->setParameter(index, params);
144 }
145
146 // static
GetConfigWrapper(OMX_HANDLETYPE component,OMX_INDEXTYPE index,OMX_PTR params)147 OMX_ERRORTYPE SoftOMXComponent::GetConfigWrapper(
148 OMX_HANDLETYPE component,
149 OMX_INDEXTYPE index,
150 OMX_PTR params) {
151 SoftOMXComponent *me =
152 (SoftOMXComponent *)
153 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
154
155 return me->getConfig(index, params);
156 }
157
158 // static
SetConfigWrapper(OMX_HANDLETYPE component,OMX_INDEXTYPE index,OMX_PTR params)159 OMX_ERRORTYPE SoftOMXComponent::SetConfigWrapper(
160 OMX_HANDLETYPE component,
161 OMX_INDEXTYPE index,
162 OMX_PTR params) {
163 SoftOMXComponent *me =
164 (SoftOMXComponent *)
165 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
166
167 return me->setConfig(index, params);
168 }
169
170 // static
GetExtensionIndexWrapper(OMX_HANDLETYPE component,OMX_STRING name,OMX_INDEXTYPE * index)171 OMX_ERRORTYPE SoftOMXComponent::GetExtensionIndexWrapper(
172 OMX_HANDLETYPE component,
173 OMX_STRING name,
174 OMX_INDEXTYPE *index) {
175 SoftOMXComponent *me =
176 (SoftOMXComponent *)
177 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
178
179 return me->getExtensionIndex(name, index);
180 }
181
182 // static
UseBufferWrapper(OMX_HANDLETYPE component,OMX_BUFFERHEADERTYPE ** buffer,OMX_U32 portIndex,OMX_PTR appPrivate,OMX_U32 size,OMX_U8 * ptr)183 OMX_ERRORTYPE SoftOMXComponent::UseBufferWrapper(
184 OMX_HANDLETYPE component,
185 OMX_BUFFERHEADERTYPE **buffer,
186 OMX_U32 portIndex,
187 OMX_PTR appPrivate,
188 OMX_U32 size,
189 OMX_U8 *ptr) {
190 SoftOMXComponent *me =
191 (SoftOMXComponent *)
192 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
193
194 return me->useBuffer(buffer, portIndex, appPrivate, size, ptr);
195 }
196
197 // static
AllocateBufferWrapper(OMX_HANDLETYPE component,OMX_BUFFERHEADERTYPE ** buffer,OMX_U32 portIndex,OMX_PTR appPrivate,OMX_U32 size)198 OMX_ERRORTYPE SoftOMXComponent::AllocateBufferWrapper(
199 OMX_HANDLETYPE component,
200 OMX_BUFFERHEADERTYPE **buffer,
201 OMX_U32 portIndex,
202 OMX_PTR appPrivate,
203 OMX_U32 size) {
204 SoftOMXComponent *me =
205 (SoftOMXComponent *)
206 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
207
208 return me->allocateBuffer(buffer, portIndex, appPrivate, size);
209 }
210
211 // static
FreeBufferWrapper(OMX_HANDLETYPE component,OMX_U32 portIndex,OMX_BUFFERHEADERTYPE * buffer)212 OMX_ERRORTYPE SoftOMXComponent::FreeBufferWrapper(
213 OMX_HANDLETYPE component,
214 OMX_U32 portIndex,
215 OMX_BUFFERHEADERTYPE *buffer) {
216 SoftOMXComponent *me =
217 (SoftOMXComponent *)
218 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
219
220 return me->freeBuffer(portIndex, buffer);
221 }
222
223 // static
EmptyThisBufferWrapper(OMX_HANDLETYPE component,OMX_BUFFERHEADERTYPE * buffer)224 OMX_ERRORTYPE SoftOMXComponent::EmptyThisBufferWrapper(
225 OMX_HANDLETYPE component,
226 OMX_BUFFERHEADERTYPE *buffer) {
227 SoftOMXComponent *me =
228 (SoftOMXComponent *)
229 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
230
231 return me->emptyThisBuffer(buffer);
232 }
233
234 // static
FillThisBufferWrapper(OMX_HANDLETYPE component,OMX_BUFFERHEADERTYPE * buffer)235 OMX_ERRORTYPE SoftOMXComponent::FillThisBufferWrapper(
236 OMX_HANDLETYPE component,
237 OMX_BUFFERHEADERTYPE *buffer) {
238 SoftOMXComponent *me =
239 (SoftOMXComponent *)
240 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
241
242 return me->fillThisBuffer(buffer);
243 }
244
245 // static
GetStateWrapper(OMX_HANDLETYPE component,OMX_STATETYPE * state)246 OMX_ERRORTYPE SoftOMXComponent::GetStateWrapper(
247 OMX_HANDLETYPE component,
248 OMX_STATETYPE *state) {
249 SoftOMXComponent *me =
250 (SoftOMXComponent *)
251 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
252
253 return me->getState(state);
254 }
255
256 ////////////////////////////////////////////////////////////////////////////////
257
sendCommand(OMX_COMMANDTYPE,OMX_U32,OMX_PTR)258 OMX_ERRORTYPE SoftOMXComponent::sendCommand(
259 OMX_COMMANDTYPE /* cmd */, OMX_U32 /* param */, OMX_PTR /* data */) {
260 return OMX_ErrorUndefined;
261 }
262
getParameter(OMX_INDEXTYPE,OMX_PTR)263 OMX_ERRORTYPE SoftOMXComponent::getParameter(
264 OMX_INDEXTYPE /* index */, OMX_PTR /* params */) {
265 return OMX_ErrorUndefined;
266 }
267
setParameter(OMX_INDEXTYPE,const OMX_PTR)268 OMX_ERRORTYPE SoftOMXComponent::setParameter(
269 OMX_INDEXTYPE /* index */, const OMX_PTR /* params */) {
270 return OMX_ErrorUndefined;
271 }
272
getConfig(OMX_INDEXTYPE,OMX_PTR)273 OMX_ERRORTYPE SoftOMXComponent::getConfig(
274 OMX_INDEXTYPE /* index */, OMX_PTR /* params */) {
275 return OMX_ErrorUndefined;
276 }
277
setConfig(OMX_INDEXTYPE,const OMX_PTR)278 OMX_ERRORTYPE SoftOMXComponent::setConfig(
279 OMX_INDEXTYPE /* index */, const OMX_PTR /* params */) {
280 return OMX_ErrorUndefined;
281 }
282
getExtensionIndex(const char *,OMX_INDEXTYPE *)283 OMX_ERRORTYPE SoftOMXComponent::getExtensionIndex(
284 const char * /* name */, OMX_INDEXTYPE * /* index */) {
285 return OMX_ErrorUnsupportedIndex;
286 }
287
useBuffer(OMX_BUFFERHEADERTYPE **,OMX_U32,OMX_PTR,OMX_U32,OMX_U8 *)288 OMX_ERRORTYPE SoftOMXComponent::useBuffer(
289 OMX_BUFFERHEADERTYPE ** /* buffer */,
290 OMX_U32 /* portIndex */,
291 OMX_PTR /* appPrivate */,
292 OMX_U32 /* size */,
293 OMX_U8 * /* ptr */) {
294 return OMX_ErrorUndefined;
295 }
296
allocateBuffer(OMX_BUFFERHEADERTYPE **,OMX_U32,OMX_PTR,OMX_U32)297 OMX_ERRORTYPE SoftOMXComponent::allocateBuffer(
298 OMX_BUFFERHEADERTYPE ** /* buffer */,
299 OMX_U32 /* portIndex */,
300 OMX_PTR /* appPrivate */,
301 OMX_U32 /* size */) {
302 return OMX_ErrorUndefined;
303 }
304
freeBuffer(OMX_U32,OMX_BUFFERHEADERTYPE *)305 OMX_ERRORTYPE SoftOMXComponent::freeBuffer(
306 OMX_U32 /* portIndex */,
307 OMX_BUFFERHEADERTYPE * /* buffer */) {
308 return OMX_ErrorUndefined;
309 }
310
emptyThisBuffer(OMX_BUFFERHEADERTYPE *)311 OMX_ERRORTYPE SoftOMXComponent::emptyThisBuffer(
312 OMX_BUFFERHEADERTYPE * /* buffer */) {
313 return OMX_ErrorUndefined;
314 }
315
fillThisBuffer(OMX_BUFFERHEADERTYPE *)316 OMX_ERRORTYPE SoftOMXComponent::fillThisBuffer(
317 OMX_BUFFERHEADERTYPE * /* buffer */) {
318 return OMX_ErrorUndefined;
319 }
320
getState(OMX_STATETYPE *)321 OMX_ERRORTYPE SoftOMXComponent::getState(OMX_STATETYPE * /* state */) {
322 return OMX_ErrorUndefined;
323 }
324
325 } // namespace android
326