1 /*
2  * Copyright 2018 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 "GoldfishOMXComponent"
19 #include "GoldfishOMXComponent.h"
20 
21 #include <log/log.h>
22 
23 #include <media/stagefright/foundation/ADebug.h>
24 
25 namespace android {
26 
GoldfishOMXComponent(const char * name,const OMX_CALLBACKTYPE * callbacks,OMX_PTR appData,OMX_COMPONENTTYPE ** component)27 GoldfishOMXComponent::GoldfishOMXComponent(
28         const char *name,
29         const OMX_CALLBACKTYPE *callbacks,
30         OMX_PTR appData,
31         OMX_COMPONENTTYPE **component)
32     : mName(name),
33       mCallbacks(callbacks),
34       mComponent(new OMX_COMPONENTTYPE),
35       mLibHandle(NULL) {
36     mComponent->nSize = sizeof(*mComponent);
37     mComponent->nVersion.s.nVersionMajor = 1;
38     mComponent->nVersion.s.nVersionMinor = 0;
39     mComponent->nVersion.s.nRevision = 0;
40     mComponent->nVersion.s.nStep = 0;
41     mComponent->pComponentPrivate = this;
42     mComponent->pApplicationPrivate = appData;
43 
44     mComponent->GetComponentVersion = NULL;
45     mComponent->SendCommand = SendCommandWrapper;
46     mComponent->GetParameter = GetParameterWrapper;
47     mComponent->SetParameter = SetParameterWrapper;
48     mComponent->GetConfig = GetConfigWrapper;
49     mComponent->SetConfig = SetConfigWrapper;
50     mComponent->GetExtensionIndex = GetExtensionIndexWrapper;
51     mComponent->GetState = GetStateWrapper;
52     mComponent->ComponentTunnelRequest = NULL;
53     mComponent->UseBuffer = UseBufferWrapper;
54     mComponent->AllocateBuffer = AllocateBufferWrapper;
55     mComponent->FreeBuffer = FreeBufferWrapper;
56     mComponent->EmptyThisBuffer = EmptyThisBufferWrapper;
57     mComponent->FillThisBuffer = FillThisBufferWrapper;
58     mComponent->SetCallbacks = NULL;
59     mComponent->ComponentDeInit = NULL;
60     mComponent->UseEGLImage = NULL;
61     mComponent->ComponentRoleEnum = NULL;
62 
63     *component = mComponent;
64 }
65 
~GoldfishOMXComponent()66 GoldfishOMXComponent::~GoldfishOMXComponent() {
67     delete mComponent;
68     mComponent = NULL;
69 }
70 
setLibHandle(void * libHandle)71 void GoldfishOMXComponent::setLibHandle(void *libHandle) {
72     CHECK(libHandle != NULL);
73     mLibHandle = libHandle;
74 }
75 
libHandle() const76 void *GoldfishOMXComponent::libHandle() const {
77     return mLibHandle;
78 }
79 
initCheck()80 OMX_ERRORTYPE GoldfishOMXComponent::initCheck() {
81     return OMX_ErrorNone;
82 }
83 
84 void
prepareForDestruction()85 GoldfishOMXComponent::prepareForDestruction() {
86 }
87 
name() const88 const char *GoldfishOMXComponent::name() const {
89     return mName.c_str();
90 }
91 
notify(OMX_EVENTTYPE event,OMX_U32 data1,OMX_U32 data2,OMX_PTR data)92 void GoldfishOMXComponent::notify(
93         OMX_EVENTTYPE event,
94         OMX_U32 data1, OMX_U32 data2, OMX_PTR data) {
95     (*mCallbacks->EventHandler)(
96             mComponent,
97             mComponent->pApplicationPrivate,
98             event,
99             data1,
100             data2,
101             data);
102 }
103 
notifyEmptyBufferDone(OMX_BUFFERHEADERTYPE * header)104 void GoldfishOMXComponent::notifyEmptyBufferDone(OMX_BUFFERHEADERTYPE *header) {
105     (*mCallbacks->EmptyBufferDone)(
106             mComponent, mComponent->pApplicationPrivate, header);
107 }
108 
notifyFillBufferDone(OMX_BUFFERHEADERTYPE * header)109 void GoldfishOMXComponent::notifyFillBufferDone(OMX_BUFFERHEADERTYPE *header) {
110     (*mCallbacks->FillBufferDone)(
111             mComponent, mComponent->pApplicationPrivate, header);
112 }
113 
114 // static
SendCommandWrapper(OMX_HANDLETYPE component,OMX_COMMANDTYPE cmd,OMX_U32 param,OMX_PTR data)115 OMX_ERRORTYPE GoldfishOMXComponent::SendCommandWrapper(
116         OMX_HANDLETYPE component,
117         OMX_COMMANDTYPE cmd,
118         OMX_U32 param,
119         OMX_PTR data) {
120     GoldfishOMXComponent *me =
121         (GoldfishOMXComponent *)
122             ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
123 
124     return me->sendCommand(cmd, param, data);
125 }
126 
127 // static
GetParameterWrapper(OMX_HANDLETYPE component,OMX_INDEXTYPE index,OMX_PTR params)128 OMX_ERRORTYPE GoldfishOMXComponent::GetParameterWrapper(
129         OMX_HANDLETYPE component,
130         OMX_INDEXTYPE index,
131         OMX_PTR params) {
132     GoldfishOMXComponent *me =
133         (GoldfishOMXComponent *)
134             ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
135 
136     return me->getParameter(index, params);
137 }
138 
139 // static
SetParameterWrapper(OMX_HANDLETYPE component,OMX_INDEXTYPE index,OMX_PTR params)140 OMX_ERRORTYPE GoldfishOMXComponent::SetParameterWrapper(
141         OMX_HANDLETYPE component,
142         OMX_INDEXTYPE index,
143         OMX_PTR params) {
144     GoldfishOMXComponent *me =
145         (GoldfishOMXComponent *)
146             ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
147 
148     return me->setParameter(index, params);
149 }
150 
151 // static
GetConfigWrapper(OMX_HANDLETYPE component,OMX_INDEXTYPE index,OMX_PTR params)152 OMX_ERRORTYPE GoldfishOMXComponent::GetConfigWrapper(
153         OMX_HANDLETYPE component,
154         OMX_INDEXTYPE index,
155         OMX_PTR params) {
156     GoldfishOMXComponent *me =
157         (GoldfishOMXComponent *)
158             ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
159 
160     return me->getConfig(index, params);
161 }
162 
163 // static
SetConfigWrapper(OMX_HANDLETYPE component,OMX_INDEXTYPE index,OMX_PTR params)164 OMX_ERRORTYPE GoldfishOMXComponent::SetConfigWrapper(
165         OMX_HANDLETYPE component,
166         OMX_INDEXTYPE index,
167         OMX_PTR params) {
168     GoldfishOMXComponent *me =
169         (GoldfishOMXComponent *)
170             ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
171 
172     return me->setConfig(index, params);
173 }
174 
175 // static
GetExtensionIndexWrapper(OMX_HANDLETYPE component,OMX_STRING name,OMX_INDEXTYPE * index)176 OMX_ERRORTYPE GoldfishOMXComponent::GetExtensionIndexWrapper(
177         OMX_HANDLETYPE component,
178         OMX_STRING name,
179         OMX_INDEXTYPE *index) {
180     GoldfishOMXComponent *me =
181         (GoldfishOMXComponent *)
182             ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
183 
184     return me->getExtensionIndex(name, index);
185 }
186 
187 // static
UseBufferWrapper(OMX_HANDLETYPE component,OMX_BUFFERHEADERTYPE ** buffer,OMX_U32 portIndex,OMX_PTR appPrivate,OMX_U32 size,OMX_U8 * ptr)188 OMX_ERRORTYPE GoldfishOMXComponent::UseBufferWrapper(
189         OMX_HANDLETYPE component,
190         OMX_BUFFERHEADERTYPE **buffer,
191         OMX_U32 portIndex,
192         OMX_PTR appPrivate,
193         OMX_U32 size,
194         OMX_U8 *ptr) {
195     GoldfishOMXComponent *me =
196         (GoldfishOMXComponent *)
197             ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
198 
199     return me->useBuffer(buffer, portIndex, appPrivate, size, ptr);
200 }
201 
202 // static
AllocateBufferWrapper(OMX_HANDLETYPE component,OMX_BUFFERHEADERTYPE ** buffer,OMX_U32 portIndex,OMX_PTR appPrivate,OMX_U32 size)203 OMX_ERRORTYPE GoldfishOMXComponent::AllocateBufferWrapper(
204         OMX_HANDLETYPE component,
205         OMX_BUFFERHEADERTYPE **buffer,
206         OMX_U32 portIndex,
207         OMX_PTR appPrivate,
208         OMX_U32 size) {
209     GoldfishOMXComponent *me =
210         (GoldfishOMXComponent *)
211             ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
212 
213     return me->allocateBuffer(buffer, portIndex, appPrivate, size);
214 }
215 
216 // static
FreeBufferWrapper(OMX_HANDLETYPE component,OMX_U32 portIndex,OMX_BUFFERHEADERTYPE * buffer)217 OMX_ERRORTYPE GoldfishOMXComponent::FreeBufferWrapper(
218         OMX_HANDLETYPE component,
219         OMX_U32 portIndex,
220         OMX_BUFFERHEADERTYPE *buffer) {
221     GoldfishOMXComponent *me =
222         (GoldfishOMXComponent *)
223             ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
224 
225     return me->freeBuffer(portIndex, buffer);
226 }
227 
228 // static
EmptyThisBufferWrapper(OMX_HANDLETYPE component,OMX_BUFFERHEADERTYPE * buffer)229 OMX_ERRORTYPE GoldfishOMXComponent::EmptyThisBufferWrapper(
230         OMX_HANDLETYPE component,
231         OMX_BUFFERHEADERTYPE *buffer) {
232     GoldfishOMXComponent *me =
233         (GoldfishOMXComponent *)
234             ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
235 
236     return me->emptyThisBuffer(buffer);
237 }
238 
239 // static
FillThisBufferWrapper(OMX_HANDLETYPE component,OMX_BUFFERHEADERTYPE * buffer)240 OMX_ERRORTYPE GoldfishOMXComponent::FillThisBufferWrapper(
241         OMX_HANDLETYPE component,
242         OMX_BUFFERHEADERTYPE *buffer) {
243     GoldfishOMXComponent *me =
244         (GoldfishOMXComponent *)
245             ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
246 
247     return me->fillThisBuffer(buffer);
248 }
249 
250 // static
GetStateWrapper(OMX_HANDLETYPE component,OMX_STATETYPE * state)251 OMX_ERRORTYPE GoldfishOMXComponent::GetStateWrapper(
252         OMX_HANDLETYPE component,
253         OMX_STATETYPE *state) {
254     GoldfishOMXComponent *me =
255         (GoldfishOMXComponent *)
256             ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
257 
258     return me->getState(state);
259 }
260 
261 ////////////////////////////////////////////////////////////////////////////////
262 
sendCommand(OMX_COMMANDTYPE,OMX_U32,OMX_PTR)263 OMX_ERRORTYPE GoldfishOMXComponent::sendCommand(
264         OMX_COMMANDTYPE /* cmd */, OMX_U32 /* param */, OMX_PTR /* data */) {
265     return OMX_ErrorUndefined;
266 }
267 
getParameter(OMX_INDEXTYPE,OMX_PTR)268 OMX_ERRORTYPE GoldfishOMXComponent::getParameter(
269         OMX_INDEXTYPE /* index */, OMX_PTR /* params */) {
270     return OMX_ErrorUndefined;
271 }
272 
setParameter(OMX_INDEXTYPE,const OMX_PTR)273 OMX_ERRORTYPE GoldfishOMXComponent::setParameter(
274         OMX_INDEXTYPE /* index */, const OMX_PTR /* params */) {
275     return OMX_ErrorUndefined;
276 }
277 
getConfig(OMX_INDEXTYPE,OMX_PTR)278 OMX_ERRORTYPE GoldfishOMXComponent::getConfig(
279         OMX_INDEXTYPE /* index */, OMX_PTR /* params */) {
280     return OMX_ErrorUndefined;
281 }
282 
setConfig(OMX_INDEXTYPE,const OMX_PTR)283 OMX_ERRORTYPE GoldfishOMXComponent::setConfig(
284         OMX_INDEXTYPE /* index */, const OMX_PTR /* params */) {
285     return OMX_ErrorUndefined;
286 }
287 
getExtensionIndex(const char *,OMX_INDEXTYPE *)288 OMX_ERRORTYPE GoldfishOMXComponent::getExtensionIndex(
289         const char * /* name */, OMX_INDEXTYPE * /* index */) {
290     return OMX_ErrorUnsupportedIndex;
291 }
292 
useBuffer(OMX_BUFFERHEADERTYPE **,OMX_U32,OMX_PTR,OMX_U32,OMX_U8 *)293 OMX_ERRORTYPE GoldfishOMXComponent::useBuffer(
294         OMX_BUFFERHEADERTYPE ** /* buffer */,
295         OMX_U32 /* portIndex */,
296         OMX_PTR /* appPrivate */,
297         OMX_U32 /* size */,
298         OMX_U8 * /* ptr */) {
299     return OMX_ErrorUndefined;
300 }
301 
allocateBuffer(OMX_BUFFERHEADERTYPE **,OMX_U32,OMX_PTR,OMX_U32)302 OMX_ERRORTYPE GoldfishOMXComponent::allocateBuffer(
303         OMX_BUFFERHEADERTYPE ** /* buffer */,
304         OMX_U32 /* portIndex */,
305         OMX_PTR /* appPrivate */,
306         OMX_U32 /* size */) {
307     return OMX_ErrorUndefined;
308 }
309 
freeBuffer(OMX_U32,OMX_BUFFERHEADERTYPE *)310 OMX_ERRORTYPE GoldfishOMXComponent::freeBuffer(
311         OMX_U32 /* portIndex */,
312         OMX_BUFFERHEADERTYPE * /* buffer */) {
313     return OMX_ErrorUndefined;
314 }
315 
emptyThisBuffer(OMX_BUFFERHEADERTYPE *)316 OMX_ERRORTYPE GoldfishOMXComponent::emptyThisBuffer(
317         OMX_BUFFERHEADERTYPE * /* buffer */) {
318     return OMX_ErrorUndefined;
319 }
320 
fillThisBuffer(OMX_BUFFERHEADERTYPE *)321 OMX_ERRORTYPE GoldfishOMXComponent::fillThisBuffer(
322         OMX_BUFFERHEADERTYPE * /* buffer */) {
323     return OMX_ErrorUndefined;
324 }
325 
getState(OMX_STATETYPE *)326 OMX_ERRORTYPE GoldfishOMXComponent::getState(OMX_STATETYPE * /* state */) {
327     return OMX_ErrorUndefined;
328 }
329 
330 }  // namespace android
331