• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2013 Rockchip Electronics Co., LTD.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 /*
19  * @file       Rockchip_OMX_Basecomponent.c
20  * @brief
21  * @author     csy (csy@rock-chips.com)
22  * @version    1.0.0
23  * @history
24  *    2013.11.26 : Create
25  */
26 #undef  ROCKCHIP_LOG_TAG
27 #define ROCKCHIP_LOG_TAG    "omx_base_comp"
28 
29 #include "Rockchip_OMX_Basecomponent.h"
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <unistd.h>
34 #include <sys/prctl.h>
35 
36 #include "Rockchip_OSAL_Event.h"
37 #include "Rockchip_OSAL_Thread.h"
38 #include "Rockchip_OSAL_ETC.h"
39 #include "Rockchip_OSAL_Semaphore.h"
40 #include "Rockchip_OSAL_Mutex.h"
41 #include "Rockchip_OSAL_Log.h"
42 #include "Rockchip_OMX_Baseport.h"
43 #include "Rockchip_OMX_Resourcemanager.h"
44 #include "Rockchip_OMX_Macros.h"
45 
46 /* Change CHECK_SIZE_VERSION Macro */
Rockchip_OMX_Check_SizeVersion(OMX_PTR header,OMX_U32 size)47 OMX_ERRORTYPE Rockchip_OMX_Check_SizeVersion(OMX_PTR header, OMX_U32 size)
48 {
49     OMX_ERRORTYPE ret = OMX_ErrorNone;
50 
51     OMX_VERSIONTYPE* version = NULL;
52     if (header == NULL) {
53         ret = OMX_ErrorBadParameter;
54         goto EXIT;
55     }
56     version = (OMX_VERSIONTYPE*)((char*)header + sizeof(OMX_U32));
57     if (*((OMX_U32*)header) != size) {
58         ret = OMX_ErrorBadParameter;
59         goto EXIT;
60     }
61     if (version->s.nVersionMajor != VERSIONMAJOR_NUMBER ||
62         version->s.nVersionMinor != VERSIONMINOR_NUMBER) {
63         ret = OMX_ErrorVersionMismatch;
64         goto EXIT;
65     }
66     ret = OMX_ErrorNone;
67 EXIT:
68     return ret;
69 }
70 
Rockchip_OMX_GetComponentVersion(OMX_IN OMX_HANDLETYPE hComponent,OMX_OUT OMX_STRING pComponentName,OMX_OUT OMX_VERSIONTYPE * pComponentVersion,OMX_OUT OMX_VERSIONTYPE * pSpecVersion,OMX_OUT OMX_UUIDTYPE * pComponentUUID)71 OMX_ERRORTYPE Rockchip_OMX_GetComponentVersion(
72     OMX_IN  OMX_HANDLETYPE   hComponent,
73     OMX_OUT OMX_STRING       pComponentName,
74     OMX_OUT OMX_VERSIONTYPE *pComponentVersion,
75     OMX_OUT OMX_VERSIONTYPE *pSpecVersion,
76     OMX_OUT OMX_UUIDTYPE    *pComponentUUID)
77 {
78     OMX_ERRORTYPE             ret = OMX_ErrorNone;
79     OMX_COMPONENTTYPE        *pOMXComponent = NULL;
80     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
81     OMX_U32                   compUUID[3];
82 
83     FunctionIn();
84 
85     /* check parameters */
86     if (hComponent     == NULL ||
87         pComponentName == NULL || pComponentVersion == NULL ||
88         pSpecVersion   == NULL || pComponentUUID    == NULL) {
89         ret = OMX_ErrorBadParameter;
90         goto EXIT;
91     }
92     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
93     ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
94     if (ret != OMX_ErrorNone) {
95         goto EXIT;
96     }
97 
98     if (pOMXComponent->pComponentPrivate == NULL) {
99         ret = OMX_ErrorBadParameter;
100         goto EXIT;
101     }
102     pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
103 
104     if (pRockchipComponent->currentState == OMX_StateInvalid) {
105         ret = OMX_ErrorInvalidState;
106         goto EXIT;
107     }
108 
109     Rockchip_OSAL_Strcpy(pComponentName, pRockchipComponent->componentName);
110     Rockchip_OSAL_Memcpy(pComponentVersion, &(pRockchipComponent->componentVersion), sizeof(OMX_VERSIONTYPE));
111     Rockchip_OSAL_Memcpy(pSpecVersion, &(pRockchipComponent->specVersion), sizeof(OMX_VERSIONTYPE));
112 
113     /* Fill UUID with handle address, PID and UID.
114      * This should guarantee uiniqness */
115     compUUID[0] = (OMX_U32)pOMXComponent;
116     compUUID[1] = getpid();
117     compUUID[2] = getuid();
118     Rockchip_OSAL_Memcpy(*pComponentUUID, compUUID, 3 * sizeof(*compUUID));
119 
120     ret = OMX_ErrorNone;
121 
122 EXIT:
123     FunctionOut();
124 
125     return ret;
126 }
127 
Rockchip_OMX_GetState(OMX_IN OMX_HANDLETYPE hComponent,OMX_OUT OMX_STATETYPE * pState)128 OMX_ERRORTYPE Rockchip_OMX_GetState (
129     OMX_IN OMX_HANDLETYPE  hComponent,
130     OMX_OUT OMX_STATETYPE *pState)
131 {
132     OMX_ERRORTYPE             ret = OMX_ErrorNone;
133     OMX_COMPONENTTYPE        *pOMXComponent = NULL;
134     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
135 
136     FunctionIn();
137 
138     if (hComponent == NULL || pState == NULL) {
139         ret = OMX_ErrorBadParameter;
140         goto EXIT;
141     }
142     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
143     ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
144     if (ret != OMX_ErrorNone) {
145         goto EXIT;
146     }
147 
148     if (pOMXComponent->pComponentPrivate == NULL) {
149         ret = OMX_ErrorBadParameter;
150         goto EXIT;
151     }
152     pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
153 
154     *pState = pRockchipComponent->currentState;
155     ret = OMX_ErrorNone;
156 
157 EXIT:
158     FunctionOut();
159 
160     return ret;
161 }
162 
Rockchip_OMX_ComponentStateSet(OMX_COMPONENTTYPE * pOMXComponent,OMX_U32 messageParam)163 OMX_ERRORTYPE Rockchip_OMX_ComponentStateSet(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 messageParam)
164 {
165     OMX_ERRORTYPE             ret = OMX_ErrorNone;
166     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
167     ROCKCHIP_OMX_MESSAGE       *message;
168     OMX_STATETYPE             destState = messageParam;
169     OMX_STATETYPE             currentState = pRockchipComponent->currentState;
170     ROCKCHIP_OMX_BASEPORT      *pRockchipPort = NULL;
171     unsigned int              i = 0, j = 0;
172     int                       k = 0;
173 
174     FunctionIn();
175 
176     /* check parameters */
177     if (currentState == destState) {
178         ret = OMX_ErrorSameState;
179         goto EXIT;
180     }
181     if (currentState == OMX_StateInvalid) {
182         ret = OMX_ErrorInvalidState;
183         goto EXIT;
184     }
185 
186     if ((currentState == OMX_StateLoaded) && (destState == OMX_StateIdle)) {
187         ret = Rockchip_OMX_Get_Resource(pOMXComponent);
188         if (ret != OMX_ErrorNone) {
189             Rockchip_OSAL_SignalSet(pRockchipComponent->abendStateEvent);
190             goto EXIT;
191         }
192     }
193     if (((currentState == OMX_StateIdle) && (destState == OMX_StateLoaded))       ||
194         ((currentState == OMX_StateIdle) && (destState == OMX_StateInvalid))      ||
195         ((currentState == OMX_StateExecuting) && (destState == OMX_StateInvalid)) ||
196         ((currentState == OMX_StatePause) && (destState == OMX_StateInvalid))) {
197         Rockchip_OMX_Release_Resource(pOMXComponent);
198     }
199 
200     omx_trace("destState: %d currentState: %d", destState, currentState);
201     switch (destState) {
202         case OMX_StateInvalid:
203             switch (currentState) {
204                 case OMX_StateWaitForResources:
205                     Rockchip_OMX_Out_WaitForResource(pOMXComponent);
206                 case OMX_StateIdle:
207                 case OMX_StateExecuting:
208                 case OMX_StatePause:
209                 case OMX_StateLoaded:
210                     pRockchipComponent->currentState = OMX_StateInvalid;
211                     ret = pRockchipComponent->rockchip_BufferProcessTerminate(pOMXComponent);
212 
213                     for (i = 0; i < ALL_PORT_NUM; i++) {
214                         if (pRockchipComponent->pRockchipPort[i].portWayType == WAY1_PORT) {
215                             Rockchip_OSAL_MutexTerminate(pRockchipComponent->pRockchipPort[i].way.port1WayDataBuffer. \
216                                 dataBuffer.bufferMutex);
217                             pRockchipComponent->pRockchipPort[i].way.port1WayDataBuffer.dataBuffer.bufferMutex = NULL;
218                         } else if (pRockchipComponent->pRockchipPort[i].portWayType == WAY2_PORT) {
219                             Rockchip_OSAL_MutexTerminate(pRockchipComponent->pRockchipPort[i].way.port2WayDataBuffer. \
220                                 inputDataBuffer.bufferMutex);
221                             pRockchipComponent->pRockchipPort[i].way.port2WayDataBuffer.inputDataBuffer. \
222                                 bufferMutex = NULL;
223                             Rockchip_OSAL_MutexTerminate(pRockchipComponent->pRockchipPort[i].way.port2WayDataBuffer. \
224                                 outputDataBuffer.bufferMutex);
225                             pRockchipComponent->pRockchipPort[i].way.port2WayDataBuffer.outputDataBuffer. \
226                                 bufferMutex = NULL;
227                         }
228                         Rockchip_OSAL_MutexTerminate(pRockchipComponent->pRockchipPort[i].hPortMutex);
229                         pRockchipComponent->pRockchipPort[i].hPortMutex = NULL;
230                         Rockchip_OSAL_MutexTerminate(pRockchipComponent->pRockchipPort[i].secureBufferMutex);
231                         pRockchipComponent->pRockchipPort[i].secureBufferMutex = NULL;
232                     }
233 
234                     if (pRockchipComponent->bMultiThreadProcess == OMX_FALSE) {
235                         Rockchip_OSAL_SignalTerminate(pRockchipComponent->pauseEvent);
236                         pRockchipComponent->pauseEvent = NULL;
237                     } else {
238                         for (i = 0; i < ALL_PORT_NUM; i++) {
239                             Rockchip_OSAL_SignalTerminate(pRockchipComponent->pRockchipPort[i].pauseEvent);
240                             pRockchipComponent->pRockchipPort[i].pauseEvent = NULL;
241                             if (pRockchipComponent->pRockchipPort[i].bufferProcessType == BUFFER_SHARE) {
242                                 Rockchip_OSAL_SignalTerminate(pRockchipComponent->pRockchipPort[i]. \
243                                     hAllCodecBufferReturnEvent);
244                                 pRockchipComponent->pRockchipPort[i].hAllCodecBufferReturnEvent = NULL;
245                             }
246                         }
247                     }
248                     for (i = 0; i < ALL_PORT_NUM; i++) {
249                         Rockchip_OSAL_SemaphoreTerminate(pRockchipComponent->pRockchipPort[i].bufferSemID);
250                         pRockchipComponent->pRockchipPort[i].bufferSemID = NULL;
251                     }
252                     if (pRockchipComponent->rockchip_codec_componentTerminate != NULL)
253                         pRockchipComponent->rockchip_codec_componentTerminate(pOMXComponent);
254 
255                     ret = OMX_ErrorInvalidState;
256                     break;
257                 default:
258                     ret = OMX_ErrorInvalidState;
259                     break;
260             }
261             break;
262         case OMX_StateLoaded:
263             switch (currentState) {
264                 case OMX_StateIdle:
265                     ret = pRockchipComponent->rockchip_BufferProcessTerminate(pOMXComponent);
266 
267                     for (i = 0; i < ALL_PORT_NUM; i++) {
268                         if (pRockchipComponent->pRockchipPort[i].portWayType == WAY1_PORT) {
269                             Rockchip_OSAL_MutexTerminate(pRockchipComponent->pRockchipPort[i].way.port1WayDataBuffer. \
270                                 dataBuffer.bufferMutex);
271                             pRockchipComponent->pRockchipPort[i].way.port1WayDataBuffer.dataBuffer.bufferMutex = NULL;
272                         } else if (pRockchipComponent->pRockchipPort[i].portWayType == WAY2_PORT) {
273                             Rockchip_OSAL_MutexTerminate(pRockchipComponent->pRockchipPort[i].way.port2WayDataBuffer. \
274                                 inputDataBuffer.bufferMutex);
275                             pRockchipComponent->pRockchipPort[i].way.port2WayDataBuffer. \
276                                 inputDataBuffer.bufferMutex = NULL;
277                             Rockchip_OSAL_MutexTerminate(pRockchipComponent->pRockchipPort[i].way.port2WayDataBuffer. \
278                                 outputDataBuffer.bufferMutex);
279                             pRockchipComponent->pRockchipPort[i].way.port2WayDataBuffer. \
280                                 outputDataBuffer.bufferMutex = NULL;
281                         }
282                         Rockchip_OSAL_MutexTerminate(pRockchipComponent->pRockchipPort[i].hPortMutex);
283                         pRockchipComponent->pRockchipPort[i].hPortMutex = NULL;
284                         Rockchip_OSAL_MutexTerminate(pRockchipComponent->pRockchipPort[i].secureBufferMutex);
285                         pRockchipComponent->pRockchipPort[i].secureBufferMutex = NULL;
286                     }
287                     if (pRockchipComponent->bMultiThreadProcess == OMX_FALSE) {
288                         Rockchip_OSAL_SignalTerminate(pRockchipComponent->pauseEvent);
289                         pRockchipComponent->pauseEvent = NULL;
290                     } else {
291                         for (i = 0; i < ALL_PORT_NUM; i++) {
292                             Rockchip_OSAL_SignalTerminate(pRockchipComponent->pRockchipPort[i].pauseEvent);
293                             pRockchipComponent->pRockchipPort[i].pauseEvent = NULL;
294                             if (pRockchipComponent->pRockchipPort[i].bufferProcessType == BUFFER_SHARE) {
295                                 Rockchip_OSAL_SignalTerminate(pRockchipComponent->pRockchipPort[i]. \
296                                     hAllCodecBufferReturnEvent);
297                                 pRockchipComponent->pRockchipPort[i].hAllCodecBufferReturnEvent = NULL;
298                             }
299                         }
300                     }
301                     for (i = 0; i < ALL_PORT_NUM; i++) {
302                         Rockchip_OSAL_SemaphoreTerminate(pRockchipComponent->pRockchipPort[i].bufferSemID);
303                         pRockchipComponent->pRockchipPort[i].bufferSemID = NULL;
304                     }
305 
306                     pRockchipComponent->rockchip_codec_componentTerminate(pOMXComponent);
307 
308                     for (i = 0; i < (pRockchipComponent->portParam.nPorts); i++) {
309                         pRockchipPort = (pRockchipComponent->pRockchipPort + i);
310                         if (CHECK_PORT_TUNNELED(pRockchipPort) && CHECK_PORT_BUFFER_SUPPLIER(pRockchipPort)) {
311                             while (Rockchip_OSAL_GetElemNum(&pRockchipPort->bufferQ) > 0) {
312                                 message = (ROCKCHIP_OMX_MESSAGE*)Rockchip_OSAL_Dequeue(&pRockchipPort->bufferQ);
313                                 if (message != NULL)
314                                     Rockchip_OSAL_Free(message);
315                             }
316                             ret = pRockchipComponent->rockchip_FreeTunnelBuffer(pRockchipPort, i);
317                             if (OMX_ErrorNone != ret) {
318                                 goto EXIT;
319                             }
320                         } else {
321                             if (CHECK_PORT_ENABLED(pRockchipPort)) {
322                                 Rockchip_OSAL_SemaphoreWait(pRockchipPort->unloadedResource);
323                                 pRockchipPort->portDefinition.bPopulated = OMX_FALSE;
324                             }
325                         }
326                     }
327                     pRockchipComponent->currentState = OMX_StateLoaded;
328                     break;
329                 case OMX_StateWaitForResources:
330                     ret = Rockchip_OMX_Out_WaitForResource(pOMXComponent);
331                     pRockchipComponent->currentState = OMX_StateLoaded;
332                     break;
333                 case OMX_StateExecuting:
334                 case OMX_StatePause:
335                 default:
336                     ret = OMX_ErrorIncorrectStateTransition;
337                     break;
338             }
339             break;
340         case OMX_StateIdle:
341             switch (currentState) {
342                 case OMX_StateLoaded:
343                     omx_trace("OMX_StateLoaded in loadedResource");
344                     for (i = 0; i < pRockchipComponent->portParam.nPorts; i++) {
345                         pRockchipPort = (pRockchipComponent->pRockchipPort + i);
346                         if (pRockchipPort == NULL) {
347                             ret = OMX_ErrorBadParameter;
348                             goto EXIT;
349                         }
350                         if (CHECK_PORT_TUNNELED(pRockchipPort) && CHECK_PORT_BUFFER_SUPPLIER(pRockchipPort)) {
351                             if (CHECK_PORT_ENABLED(pRockchipPort)) {
352                                 ret = pRockchipComponent->rockchip_AllocateTunnelBuffer(pRockchipPort, i);
353                                 if (ret != OMX_ErrorNone)
354                                     goto EXIT;
355                             }
356                         } else {
357                             if (CHECK_PORT_ENABLED(pRockchipPort)) {
358                                 omx_trace("Rockchip_OSAL_SemaphoreWait loadedResource ");
359                                 Rockchip_OSAL_SemaphoreWait(pRockchipComponent->pRockchipPort[i].loadedResource);
360                                 omx_trace("Rockchip_OSAL_SemaphoreWait loadedResource out");
361                                 if (pRockchipComponent->abendState == OMX_TRUE) {
362                                     omx_err("Rockchip_OSAL_SemaphoreWait abendState == OMX_TRUE");
363                                     Rockchip_OSAL_SignalSet(pRockchipComponent->abendStateEvent);
364                                     ret = Rockchip_OMX_Release_Resource(pOMXComponent);
365                                     goto EXIT;
366                                 }
367                                 pRockchipPort->portDefinition.bPopulated = OMX_TRUE;
368                             }
369                         }
370                     }
371 
372                     if (pRockchipComponent->bMultiThreadProcess == OMX_FALSE) {
373                         Rockchip_OSAL_SignalCreate(&pRockchipComponent->pauseEvent);
374                     } else {
375                         for (i = 0; i < ALL_PORT_NUM; i++) {
376                             Rockchip_OSAL_SignalCreate(&pRockchipComponent->pRockchipPort[i].pauseEvent);
377                             if (pRockchipComponent->pRockchipPort[i].bufferProcessType == BUFFER_SHARE)
378                                 Rockchip_OSAL_SignalCreate(&pRockchipComponent->pRockchipPort[i]. \
379                                     hAllCodecBufferReturnEvent);
380                         }
381                     }
382                     for (i = 0; i < ALL_PORT_NUM; i++) {
383                         ret = Rockchip_OSAL_SemaphoreCreate(&pRockchipComponent->pRockchipPort[i].bufferSemID);
384                         if (ret != OMX_ErrorNone) {
385                             ret = OMX_ErrorInsufficientResources;
386                             omx_err("OMX_ErrorInsufficientResources, Line:%d", __LINE__);
387                             goto EXIT;
388                         }
389                     }
390                     for (i = 0; i < ALL_PORT_NUM; i++) {
391                         if (pRockchipComponent->pRockchipPort[i].portWayType == WAY1_PORT) {
392                             ret = Rockchip_OSAL_MutexCreate(&pRockchipComponent->pRockchipPort[i].way. \
393                                 port1WayDataBuffer.dataBuffer.bufferMutex);
394                             if (ret != OMX_ErrorNone) {
395                                 ret = OMX_ErrorInsufficientResources;
396                                 omx_err("OMX_ErrorInsufficientResources, Line:%d", __LINE__);
397                                 goto EXIT;
398                             }
399                         } else if (pRockchipComponent->pRockchipPort[i].portWayType == WAY2_PORT) {
400                             ret = Rockchip_OSAL_MutexCreate(&pRockchipComponent->pRockchipPort[i].way. \
401                                 port2WayDataBuffer.inputDataBuffer.bufferMutex);
402                             if (ret != OMX_ErrorNone) {
403                                 ret = OMX_ErrorInsufficientResources;
404                                 omx_err("OMX_ErrorInsufficientResources, Line:%d", __LINE__);
405                                 goto EXIT;
406                             }
407                             ret = Rockchip_OSAL_MutexCreate(&pRockchipComponent->pRockchipPort[i].way. \
408                                 port2WayDataBuffer.outputDataBuffer.bufferMutex);
409                             if (ret != OMX_ErrorNone) {
410                                 ret = OMX_ErrorInsufficientResources;
411                                 omx_err("OMX_ErrorInsufficientResources, Line:%d", __LINE__);
412                                 goto EXIT;
413                             }
414                         }
415                         ret = Rockchip_OSAL_MutexCreate(&pRockchipComponent->pRockchipPort[i].hPortMutex);
416                         if (ret != OMX_ErrorNone) {
417                             ret = OMX_ErrorInsufficientResources;
418                             goto EXIT;
419                         }
420                         ret = Rockchip_OSAL_MutexCreate(&pRockchipComponent->pRockchipPort[i].secureBufferMutex);
421                         if (ret != OMX_ErrorNone) {
422                             ret = OMX_ErrorInsufficientResources;
423                             goto EXIT;
424                         }
425                     }
426                     omx_trace("rockchip_BufferProcessCreate");
427 
428                     ret = pRockchipComponent->rockchip_BufferProcessCreate(pOMXComponent);
429                     if (ret != OMX_ErrorNone) {
430                         if (pRockchipComponent->bMultiThreadProcess == OMX_FALSE) {
431                             Rockchip_OSAL_SignalTerminate(pRockchipComponent->pauseEvent);
432                             pRockchipComponent->pauseEvent = NULL;
433                         } else {
434                             for (i = 0; i < ALL_PORT_NUM; i++) {
435                                 Rockchip_OSAL_SignalTerminate(pRockchipComponent->pRockchipPort[i].pauseEvent);
436                                 pRockchipComponent->pRockchipPort[i].pauseEvent = NULL;
437                                 if (pRockchipComponent->pRockchipPort[i].bufferProcessType == BUFFER_SHARE) {
438                                     Rockchip_OSAL_SignalTerminate(pRockchipComponent->pRockchipPort[i]. \
439                                         hAllCodecBufferReturnEvent);
440                                     pRockchipComponent->pRockchipPort[i].hAllCodecBufferReturnEvent = NULL;
441                                 }
442                             }
443                         }
444                         for (i = 0; i < ALL_PORT_NUM; i++) {
445                             if (pRockchipComponent->pRockchipPort[i].portWayType == WAY1_PORT) {
446                                 Rockchip_OSAL_MutexTerminate(pRockchipComponent->pRockchipPort[i].way. \
447                                     port1WayDataBuffer.dataBuffer.bufferMutex);
448                                 pRockchipComponent->pRockchipPort[i].way.port1WayDataBuffer.dataBuffer. \
449                                     bufferMutex = NULL;
450                             } else if (pRockchipComponent->pRockchipPort[i].portWayType == WAY2_PORT) {
451                                 Rockchip_OSAL_MutexTerminate(pRockchipComponent->pRockchipPort[i].way. \
452                                     port2WayDataBuffer.inputDataBuffer.bufferMutex);
453                                 pRockchipComponent->pRockchipPort[i].way.port2WayDataBuffer.inputDataBuffer. \
454                                     bufferMutex = NULL;
455                                 Rockchip_OSAL_MutexTerminate(pRockchipComponent->pRockchipPort[i].way. \
456                                 port2WayDataBuffer.outputDataBuffer.bufferMutex);
457                                 pRockchipComponent->pRockchipPort[i].way.port2WayDataBuffer.outputDataBuffer. \
458                                     bufferMutex = NULL;
459                             }
460                             Rockchip_OSAL_MutexTerminate(pRockchipComponent->pRockchipPort[i].hPortMutex);
461                             pRockchipComponent->pRockchipPort[i].hPortMutex = NULL;
462                             Rockchip_OSAL_MutexTerminate(pRockchipComponent->pRockchipPort[i].secureBufferMutex);
463                             pRockchipComponent->pRockchipPort[i].secureBufferMutex = NULL;
464                         }
465                         for (i = 0; i < ALL_PORT_NUM; i++) {
466                             Rockchip_OSAL_SemaphoreTerminate(pRockchipComponent->pRockchipPort[i].bufferSemID);
467                             pRockchipComponent->pRockchipPort[i].bufferSemID = NULL;
468                         }
469 
470                         ret = OMX_ErrorInsufficientResources;
471                         goto EXIT;
472                     }
473 
474                     omx_trace(" OMX_StateIdle");
475                     pRockchipComponent->currentState = OMX_StateIdle;
476                     break;
477                 case OMX_StateExecuting:
478                 case OMX_StatePause:
479                     if (currentState == OMX_StateExecuting) {
480                         pRockchipComponent->nRkFlags |= RK_VPU_NEED_FLUSH_ON_SEEK;
481                     }
482                     Rockchip_OMX_BufferFlushProcess(pOMXComponent, ALL_PORT_INDEX, OMX_FALSE);
483                     pRockchipComponent->currentState = OMX_StateIdle;
484                     break;
485                 case OMX_StateWaitForResources:
486                     pRockchipComponent->currentState = OMX_StateIdle;
487                     break;
488                 default:
489                     ret = OMX_ErrorIncorrectStateTransition;
490                     break;
491                 }
492                 break;
493         case OMX_StateExecuting:
494             switch (currentState) {
495                 case OMX_StateLoaded:
496                     ret = OMX_ErrorIncorrectStateTransition;
497                     break;
498                 case OMX_StateIdle:
499                     omx_trace("rockchip_codec_componentInit");
500                     ret = pRockchipComponent->rockchip_codec_componentInit(pOMXComponent);
501                     if (ret != OMX_ErrorNone) {
502                         omx_err_f("rockchip_codec_componentInit failed!");
503                         Rockchip_OSAL_SignalSet(pRockchipComponent->abendStateEvent);
504                         Rockchip_OMX_Release_Resource(pOMXComponent);
505                         goto EXIT;
506                     }
507 
508                     for (i = 0; i < pRockchipComponent->portParam.nPorts; i++) {
509                         pRockchipPort = &pRockchipComponent->pRockchipPort[i];
510                         if (CHECK_PORT_TUNNELED(pRockchipPort) &&
511                             CHECK_PORT_BUFFER_SUPPLIER(pRockchipPort) &&
512                             CHECK_PORT_ENABLED(pRockchipPort)) {
513                             for (j = 0; j < pRockchipPort->tunnelBufferNum; j++) {
514                                 Rockchip_OSAL_SemaphorePost(pRockchipComponent->pRockchipPort[i].bufferSemID);
515                             }
516                         }
517                     }
518 
519                     pRockchipComponent->transientState = ROCKCHIP_OMX_TransStateMax;
520                     pRockchipComponent->currentState = OMX_StateExecuting;
521                     if (pRockchipComponent->bMultiThreadProcess == OMX_FALSE) {
522                         Rockchip_OSAL_SignalSet(pRockchipComponent->pauseEvent);
523                     } else {
524                         for (i = 0; i < ALL_PORT_NUM; i++) {
525                             Rockchip_OSAL_SignalSet(pRockchipComponent->pRockchipPort[i].pauseEvent);
526                         }
527                     }
528                     break;
529                 case OMX_StatePause:
530                     for (i = 0; i < pRockchipComponent->portParam.nPorts; i++) {
531                         pRockchipPort = &pRockchipComponent->pRockchipPort[i];
532                         if (CHECK_PORT_TUNNELED(pRockchipPort) && CHECK_PORT_BUFFER_SUPPLIER(pRockchipPort) \
533                             && CHECK_PORT_ENABLED(pRockchipPort)) {
534                             OMX_S32 semaValue = 0, cnt = 0;
535                             Rockchip_OSAL_Get_SemaphoreCount(pRockchipComponent->pRockchipPort[i]. \
536                                 bufferSemID, &semaValue);
537                             if (Rockchip_OSAL_GetElemNum(&pRockchipPort->bufferQ) > semaValue) {
538                                 cnt = Rockchip_OSAL_GetElemNum(&pRockchipPort->bufferQ) - semaValue;
539                                 for (k = 0; k < cnt; k++) {
540                                     Rockchip_OSAL_SemaphorePost(pRockchipComponent->pRockchipPort[i].bufferSemID);
541                                 }
542                             }
543                         }
544                     }
545 
546                     pRockchipComponent->currentState = OMX_StateExecuting;
547                     if (pRockchipComponent->bMultiThreadProcess == OMX_FALSE) {
548                         Rockchip_OSAL_SignalSet(pRockchipComponent->pauseEvent);
549                     } else {
550                         for (i = 0; i < ALL_PORT_NUM; i++) {
551                             Rockchip_OSAL_SignalSet(pRockchipComponent->pRockchipPort[i].pauseEvent);
552                         }
553                     }
554                     break;
555                 case OMX_StateWaitForResources:
556                     ret = OMX_ErrorIncorrectStateTransition;
557                     break;
558                 default:
559                     ret = OMX_ErrorIncorrectStateTransition;
560                     break;
561         }
562             break;
563         case OMX_StatePause:
564             switch (currentState) {
565                 case OMX_StateLoaded:
566                     ret = OMX_ErrorIncorrectStateTransition;
567                     break;
568                 case OMX_StateIdle:
569                     pRockchipComponent->currentState = OMX_StatePause;
570                     break;
571                 case OMX_StateExecuting:
572                     pRockchipComponent->currentState = OMX_StatePause;
573                     break;
574                 case OMX_StateWaitForResources:
575                     ret = OMX_ErrorIncorrectStateTransition;
576                     break;
577                 default:
578                     ret = OMX_ErrorIncorrectStateTransition;
579                     break;
580             }
581             break;
582         case OMX_StateWaitForResources:
583             switch (currentState) {
584                 case OMX_StateLoaded:
585                     ret = Rockchip_OMX_In_WaitForResource(pOMXComponent);
586                     pRockchipComponent->currentState = OMX_StateWaitForResources;
587                     break;
588                 case OMX_StateIdle:
589                 case OMX_StateExecuting:
590                 case OMX_StatePause:
591                     ret = OMX_ErrorIncorrectStateTransition;
592                     break;
593                 default:
594                     ret = OMX_ErrorIncorrectStateTransition;
595                     break;
596             }
597             break;
598         default:
599             ret = OMX_ErrorIncorrectStateTransition;
600             break;
601     }
602 
603 EXIT:
604     if (ret == OMX_ErrorNone) {
605         if (pRockchipComponent->pCallbacks != NULL) {
606             pRockchipComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent,
607                                                          pRockchipComponent->callbackData,
608                                                          OMX_EventCmdComplete, OMX_CommandStateSet,
609                                                          destState, NULL);
610         }
611     } else {
612         omx_err("ERROR");
613         if (pRockchipComponent->pCallbacks != NULL) {
614             pRockchipComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent,
615                                                          pRockchipComponent->callbackData,
616                                                          OMX_EventError, ret, 0, NULL);
617         }
618     }
619     FunctionOut();
620 
621     return ret;
622 }
623 
Rockchip_OMX_MessageHandlerThread(OMX_PTR threadData)624 static OMX_ERRORTYPE Rockchip_OMX_MessageHandlerThread(OMX_PTR threadData)
625 {
626     OMX_ERRORTYPE             ret = OMX_ErrorNone;
627     OMX_COMPONENTTYPE        *pOMXComponent = NULL;
628     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
629     ROCKCHIP_OMX_MESSAGE       *message = NULL;
630     OMX_U32                   messageType = 0, portIndex = 0;
631 
632     FunctionIn();
633 
634     if (threadData == NULL) {
635         ret = OMX_ErrorBadParameter;
636         goto EXIT;
637     }
638 
639     pOMXComponent = (OMX_COMPONENTTYPE *)threadData;
640     ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
641     if (ret != OMX_ErrorNone) {
642         goto EXIT;
643     }
644 
645     pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
646 
647     while (pRockchipComponent->bExitMessageHandlerThread == OMX_FALSE) {
648         Rockchip_OSAL_SemaphoreWait(pRockchipComponent->msgSemaphoreHandle);
649         message = (ROCKCHIP_OMX_MESSAGE *)Rockchip_OSAL_Dequeue(&pRockchipComponent->messageQ);
650         if (message != NULL) {
651             messageType = message->messageType;
652             switch (messageType) {
653                 case OMX_CommandStateSet:
654                     ret = Rockchip_OMX_ComponentStateSet(pOMXComponent, message->messageParam);
655                     break;
656                 case OMX_CommandFlush:
657                     ret = Rockchip_OMX_BufferFlushProcess(pOMXComponent, message->messageParam, OMX_TRUE);
658                     break;
659                 case OMX_CommandPortDisable:
660                     ret = Rockchip_OMX_PortDisableProcess(pOMXComponent, message->messageParam);
661                     break;
662                 case OMX_CommandPortEnable:
663                     ret = Rockchip_OMX_PortEnableProcess(pOMXComponent, message->messageParam);
664                     break;
665                 case OMX_CommandMarkBuffer:
666                     portIndex = message->messageParam;
667                     pRockchipComponent->pRockchipPort[portIndex].markType.hMarkTargetComponent =
668                         ((OMX_MARKTYPE *)message->pCmdData)->hMarkTargetComponent;
669                     pRockchipComponent->pRockchipPort[portIndex].markType.pMarkData            =
670                         ((OMX_MARKTYPE *)message->pCmdData)->pMarkData;
671                     break;
672                 case (OMX_COMMANDTYPE)ROCKCHIP_OMX_CommandComponentDeInit:
673                     pRockchipComponent->bExitMessageHandlerThread = OMX_TRUE;
674                     break;
675                 default:
676                     break;
677             }
678             Rockchip_OSAL_Free(message);
679             message = NULL;
680         }
681     }
682 
683     Rockchip_OSAL_ThreadExit(NULL);
684 
685 EXIT:
686     FunctionOut();
687 
688     return ret;
689 }
690 
Rockchip_StateSet(ROCKCHIP_OMX_BASECOMPONENT * pRockchipComponent,OMX_U32 nParam)691 static OMX_ERRORTYPE Rockchip_StateSet(ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent, OMX_U32 nParam)
692 {
693     OMX_U32 destState = nParam;
694     OMX_U32 i = 0;
695 
696     if ((destState == OMX_StateIdle) && (pRockchipComponent->currentState == OMX_StateLoaded)) {
697         pRockchipComponent->transientState = ROCKCHIP_OMX_TransStateLoadedToIdle;
698         for (i = 0; i < pRockchipComponent->portParam.nPorts; i++) {
699             pRockchipComponent->pRockchipPort[i].portState = OMX_StateIdle;
700         }
701         omx_trace("to OMX_StateIdle");
702     } else if ((destState == OMX_StateLoaded) && (pRockchipComponent->currentState == OMX_StateIdle)) {
703         pRockchipComponent->transientState = ROCKCHIP_OMX_TransStateIdleToLoaded;
704         for (i = 0; i < pRockchipComponent->portParam.nPorts; i++) {
705             pRockchipComponent->pRockchipPort[i].portState = OMX_StateLoaded;
706         }
707         omx_trace("to OMX_StateLoaded");
708     } else if ((destState == OMX_StateIdle) && (pRockchipComponent->currentState == OMX_StateExecuting)) {
709         ROCKCHIP_OMX_BASEPORT *pRockchipPort = NULL;
710 
711         pRockchipPort = &(pRockchipComponent->pRockchipPort[INPUT_PORT_INDEX]);
712         if ((pRockchipPort->portDefinition.bEnabled == OMX_FALSE) &&
713             (pRockchipPort->portState == OMX_StateIdle)) {
714             pRockchipPort->exceptionFlag = INVALID_STATE;
715             Rockchip_OSAL_SemaphorePost(pRockchipPort->loadedResource);
716         }
717 
718         pRockchipPort = &(pRockchipComponent->pRockchipPort[OUTPUT_PORT_INDEX]);
719         if ((pRockchipPort->portDefinition.bEnabled == OMX_FALSE) &&
720             (pRockchipPort->portState == OMX_StateIdle)) {
721             pRockchipPort->exceptionFlag = INVALID_STATE;
722             Rockchip_OSAL_SemaphorePost(pRockchipPort->loadedResource);
723         }
724 
725         pRockchipComponent->transientState = ROCKCHIP_OMX_TransStateExecutingToIdle;
726         omx_trace("to OMX_StateIdle");
727     } else if ((destState == OMX_StateExecuting) && (pRockchipComponent->currentState == OMX_StateIdle)) {
728         pRockchipComponent->transientState = ROCKCHIP_OMX_TransStateIdleToExecuting;
729         omx_trace("to OMX_StateExecuting");
730     } else if (destState == OMX_StateInvalid) {
731         for (i = 0; i < pRockchipComponent->portParam.nPorts; i++) {
732             pRockchipComponent->pRockchipPort[i].portState = OMX_StateInvalid;
733         }
734     }
735 
736     return OMX_ErrorNone;
737 }
738 
Rockchip_SetPortFlush(ROCKCHIP_OMX_BASECOMPONENT * pRockchipComponent,OMX_U32 nParam)739 static OMX_ERRORTYPE Rockchip_SetPortFlush(ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent, OMX_U32 nParam)
740 {
741     OMX_ERRORTYPE        ret = OMX_ErrorNone;
742     OMX_S32              portIndex = nParam;
743     OMX_U16              i = 0, cnt = 0, index = 0;
744 
745     if ((pRockchipComponent->currentState == OMX_StateExecuting) ||
746         (pRockchipComponent->currentState == OMX_StatePause)) {
747         if ((portIndex != ALL_PORT_INDEX) &&
748             ((OMX_S32)portIndex >= (OMX_S32)pRockchipComponent->portParam.nPorts)) {
749             ret = OMX_ErrorBadPortIndex;
750             goto EXIT;
751         }
752 
753         /*********************
754         *    need flush event set ?????
755         **********************/
756         cnt = (portIndex == ALL_PORT_INDEX) ? ALL_PORT_NUM : 1;
757         for (i = 0; i < cnt; i++) {
758             if (portIndex == ALL_PORT_INDEX)
759                 index = i;
760             else
761                 index = portIndex;
762             pRockchipComponent->pRockchipPort[index].bIsPortFlushed = OMX_TRUE;
763         }
764     } else {
765         ret = OMX_ErrorIncorrectStateOperation;
766         goto EXIT;
767     }
768     ret = OMX_ErrorNone;
769 
770 EXIT:
771     return ret;
772 }
773 
Rockchip_SetPortEnable(ROCKCHIP_OMX_BASECOMPONENT * pRockchipComponent,OMX_U32 nParam)774 static OMX_ERRORTYPE Rockchip_SetPortEnable(ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent, OMX_U32 nParam)
775 {
776     OMX_ERRORTYPE        ret = OMX_ErrorNone;
777     ROCKCHIP_OMX_BASEPORT *pRockchipPort = NULL;
778     OMX_S32              portIndex = nParam;
779     OMX_U16              i = 0;
780 
781     FunctionIn();
782 
783     if ((portIndex != ALL_PORT_INDEX) &&
784         ((OMX_S32)portIndex >= (OMX_S32)pRockchipComponent->portParam.nPorts)) {
785         ret = OMX_ErrorBadPortIndex;
786         goto EXIT;
787     }
788 
789     if (portIndex == ALL_PORT_INDEX) {
790         for (i = 0; i < pRockchipComponent->portParam.nPorts; i++) {
791             pRockchipPort = &pRockchipComponent->pRockchipPort[i];
792             if (CHECK_PORT_ENABLED(pRockchipPort)) {
793                 ret = OMX_ErrorIncorrectStateOperation;
794                 goto EXIT;
795             } else {
796                 pRockchipPort->portState = OMX_StateIdle;
797             }
798         }
799     } else {
800         pRockchipPort = &pRockchipComponent->pRockchipPort[portIndex];
801         if (CHECK_PORT_ENABLED(pRockchipPort)) {
802             ret = OMX_ErrorIncorrectStateOperation;
803             goto EXIT;
804         } else {
805             pRockchipPort->portState = OMX_StateIdle;
806         }
807     }
808     ret = OMX_ErrorNone;
809 
810 EXIT:
811     FunctionOut();
812 
813     return ret;
814 }
815 
Rockchip_SetPortDisable(ROCKCHIP_OMX_BASECOMPONENT * pRockchipComponent,OMX_U32 nParam)816 static OMX_ERRORTYPE Rockchip_SetPortDisable(ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent, OMX_U32 nParam)
817 {
818     OMX_ERRORTYPE        ret = OMX_ErrorNone;
819     ROCKCHIP_OMX_BASEPORT *pRockchipPort = NULL;
820     OMX_S32              portIndex = nParam;
821     OMX_U16              i = 0;
822 
823     FunctionIn();
824 
825     if ((portIndex != ALL_PORT_INDEX) &&
826         ((OMX_S32)portIndex >= (OMX_S32)pRockchipComponent->portParam.nPorts)) {
827         ret = OMX_ErrorBadPortIndex;
828         goto EXIT;
829     }
830 
831     if (portIndex == ALL_PORT_INDEX) {
832         for (i = 0; i < pRockchipComponent->portParam.nPorts; i++) {
833             pRockchipPort = &pRockchipComponent->pRockchipPort[i];
834             if (!CHECK_PORT_ENABLED(pRockchipPort)) {
835                 ret = OMX_ErrorIncorrectStateOperation;
836                 goto EXIT;
837             }
838             pRockchipPort->portState = OMX_StateLoaded;
839             pRockchipPort->bIsPortDisabled = OMX_TRUE;
840         }
841     } else {
842         pRockchipPort = &pRockchipComponent->pRockchipPort[portIndex];
843         pRockchipPort->portState = OMX_StateLoaded;
844         pRockchipPort->bIsPortDisabled = OMX_TRUE;
845     }
846     ret = OMX_ErrorNone;
847 
848 EXIT:
849     FunctionOut();
850 
851     return ret;
852 }
853 
Rockchip_SetMarkBuffer(ROCKCHIP_OMX_BASECOMPONENT * pRockchipComponent,OMX_U32 nParam)854 static OMX_ERRORTYPE Rockchip_SetMarkBuffer(ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent, OMX_U32 nParam)
855 {
856     OMX_ERRORTYPE        ret = OMX_ErrorNone;
857 
858     if (nParam >= pRockchipComponent->portParam.nPorts) {
859         ret = OMX_ErrorBadPortIndex;
860         goto EXIT;
861     }
862 
863     if ((pRockchipComponent->currentState == OMX_StateExecuting) ||
864         (pRockchipComponent->currentState == OMX_StatePause)) {
865         ret = OMX_ErrorNone;
866     } else {
867         ret = OMX_ErrorIncorrectStateOperation;
868     }
869 
870 EXIT:
871     return ret;
872 }
873 
Rockchip_OMX_CommandQueue(ROCKCHIP_OMX_BASECOMPONENT * pRockchipComponent,OMX_COMMANDTYPE Cmd,OMX_U32 nParam,OMX_PTR pCmdData)874 static OMX_ERRORTYPE Rockchip_OMX_CommandQueue(
875     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent,
876     OMX_COMMANDTYPE        Cmd,
877     OMX_U32                nParam,
878     OMX_PTR                pCmdData)
879 {
880     OMX_ERRORTYPE    ret = OMX_ErrorNone;
881     ROCKCHIP_OMX_MESSAGE *command = (ROCKCHIP_OMX_MESSAGE *)Rockchip_OSAL_Malloc(sizeof(ROCKCHIP_OMX_MESSAGE));
882 
883     if (command == NULL) {
884         ret = OMX_ErrorInsufficientResources;
885         goto EXIT;
886     }
887     command->messageType  = (OMX_U32)Cmd;
888     command->messageParam = nParam;
889     command->pCmdData     = pCmdData;
890 
891     ret = Rockchip_OSAL_Queue(&pRockchipComponent->messageQ, (void *)command);
892     if (ret != 0) {
893         ret = OMX_ErrorUndefined;
894         goto EXIT;
895     }
896     ret = Rockchip_OSAL_SemaphorePost(pRockchipComponent->msgSemaphoreHandle);
897 
898 EXIT:
899     return ret;
900 }
901 
Rockchip_OMX_SendCommand(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_COMMANDTYPE Cmd,OMX_IN OMX_U32 nParam,OMX_IN OMX_PTR pCmdData)902 OMX_ERRORTYPE Rockchip_OMX_SendCommand(
903     OMX_IN OMX_HANDLETYPE  hComponent,
904     OMX_IN OMX_COMMANDTYPE Cmd,
905     OMX_IN OMX_U32         nParam,
906     OMX_IN OMX_PTR         pCmdData)
907 {
908     OMX_ERRORTYPE             ret = OMX_ErrorNone;
909     OMX_COMPONENTTYPE        *pOMXComponent = NULL;
910     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
911 
912     FunctionIn();
913 
914     if (hComponent == NULL) {
915         ret = OMX_ErrorBadParameter;
916         goto EXIT;
917     }
918     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
919     ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
920     if (ret != OMX_ErrorNone) {
921         goto EXIT;
922     }
923 
924     if (pOMXComponent->pComponentPrivate == NULL) {
925         ret = OMX_ErrorBadParameter;
926         goto EXIT;
927     }
928     pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
929 
930     if (pRockchipComponent->currentState == OMX_StateInvalid) {
931         ret = OMX_ErrorInvalidState;
932         goto EXIT;
933     }
934 
935     switch (Cmd) {
936         case OMX_CommandStateSet :
937             omx_trace("Command: OMX_CommandStateSet");
938             Rockchip_StateSet(pRockchipComponent, nParam);
939             break;
940         case OMX_CommandFlush :
941             omx_trace("Command: OMX_CommandFlush");
942             pRockchipComponent->nRkFlags |= RK_VPU_NEED_FLUSH_ON_SEEK;
943             ret = Rockchip_SetPortFlush(pRockchipComponent, nParam);
944             if (ret != OMX_ErrorNone)
945                 goto EXIT;
946             break;
947         case OMX_CommandPortDisable :
948             omx_trace("Command: OMX_CommandPortDisable");
949             ret = Rockchip_SetPortDisable(pRockchipComponent, nParam);
950             if (ret != OMX_ErrorNone)
951                 goto EXIT;
952             break;
953         case OMX_CommandPortEnable :
954             omx_trace("Command: OMX_CommandPortEnable");
955             ret = Rockchip_SetPortEnable(pRockchipComponent, nParam);
956             if (ret != OMX_ErrorNone)
957                 goto EXIT;
958             break;
959         case OMX_CommandMarkBuffer :
960             omx_trace("Command: OMX_CommandMarkBuffer");
961             ret = Rockchip_SetMarkBuffer(pRockchipComponent, nParam);
962             if (ret != OMX_ErrorNone)
963                 goto EXIT;
964             break;
965         default:
966         break;
967     }
968 
969     ret = Rockchip_OMX_CommandQueue(pRockchipComponent, Cmd, nParam, pCmdData);
970 
971 EXIT:
972     FunctionOut();
973 
974     return ret;
975 }
976 
Rockchip_OMX_GetParameter(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nParamIndex,OMX_INOUT OMX_PTR ComponentParameterStructure)977 OMX_ERRORTYPE Rockchip_OMX_GetParameter(
978     OMX_IN OMX_HANDLETYPE hComponent,
979     OMX_IN OMX_INDEXTYPE  nParamIndex,
980     OMX_INOUT OMX_PTR     ComponentParameterStructure)
981 {
982     OMX_ERRORTYPE             ret = OMX_ErrorNone;
983     OMX_COMPONENTTYPE        *pOMXComponent = NULL;
984     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
985 
986     FunctionIn();
987 
988     if (hComponent == NULL) {
989         ret = OMX_ErrorBadParameter;
990         goto EXIT;
991     }
992     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
993     ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
994     if (ret != OMX_ErrorNone) {
995         goto EXIT;
996     }
997 
998     if (pOMXComponent->pComponentPrivate == NULL) {
999         ret = OMX_ErrorBadParameter;
1000         goto EXIT;
1001     }
1002     pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1003 
1004     if (ComponentParameterStructure == NULL) {
1005         ret = OMX_ErrorBadParameter;
1006         goto EXIT;
1007     }
1008     if (pRockchipComponent->currentState == OMX_StateInvalid) {
1009         ret = OMX_ErrorInvalidState;
1010         goto EXIT;
1011     }
1012 
1013     switch (nParamIndex) {
1014         case OMX_IndexParamAudioInit:
1015         case OMX_IndexParamVideoInit:
1016         case OMX_IndexParamImageInit:
1017         case OMX_IndexParamOtherInit: {
1018             OMX_PORT_PARAM_TYPE *portParam = (OMX_PORT_PARAM_TYPE *)ComponentParameterStructure;
1019             ret = Rockchip_OMX_Check_SizeVersion(portParam, sizeof(OMX_PORT_PARAM_TYPE));
1020             if (ret != OMX_ErrorNone) {
1021                 goto EXIT;
1022             }
1023             portParam->nPorts         = 0;
1024             portParam->nStartPortNumber     = 0;
1025         }
1026             break;
1027         case OMX_IndexParamPortDefinition: {
1028             OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure;
1029             OMX_U32                       portIndex = portDefinition->nPortIndex;
1030             ROCKCHIP_OMX_BASEPORT          *pRockchipPort;
1031 
1032             if (portIndex >= pRockchipComponent->portParam.nPorts) {
1033                 ret = OMX_ErrorBadPortIndex;
1034                 goto EXIT;
1035             }
1036             ret = Rockchip_OMX_Check_SizeVersion(portDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
1037             if (ret != OMX_ErrorNone) {
1038                 goto EXIT;
1039             }
1040 
1041             pRockchipPort = &pRockchipComponent->pRockchipPort[portIndex];
1042             Rockchip_OSAL_Memcpy(portDefinition, &pRockchipPort->portDefinition, portDefinition->nSize);
1043         }
1044             break;
1045         case OMX_IndexParamPriorityMgmt: {
1046             OMX_PRIORITYMGMTTYPE *compPriority = (OMX_PRIORITYMGMTTYPE *)ComponentParameterStructure;
1047 
1048             ret = Rockchip_OMX_Check_SizeVersion(compPriority, sizeof(OMX_PRIORITYMGMTTYPE));
1049             if (ret != OMX_ErrorNone) {
1050                 goto EXIT;
1051             }
1052 
1053             compPriority->nGroupID       = pRockchipComponent->compPriority.nGroupID;
1054             compPriority->nGroupPriority = pRockchipComponent->compPriority.nGroupPriority;
1055         }
1056             break;
1057         case OMX_IndexParamCompBufferSupplier: {
1058             OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplier = (OMX_PARAM_BUFFERSUPPLIERTYPE *)ComponentParameterStructure;
1059             OMX_U32                       portIndex = bufferSupplier->nPortIndex;
1060             ROCKCHIP_OMX_BASEPORT          *pRockchipPort;
1061 
1062             if ((pRockchipComponent->currentState == OMX_StateLoaded) ||
1063                 (pRockchipComponent->currentState == OMX_StateWaitForResources)) {
1064                 if (portIndex >= pRockchipComponent->portParam.nPorts) {
1065                     ret = OMX_ErrorBadPortIndex;
1066                     goto EXIT;
1067                 }
1068                 ret = Rockchip_OMX_Check_SizeVersion(bufferSupplier, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
1069                 if (ret != OMX_ErrorNone) {
1070                     goto EXIT;
1071                 }
1072 
1073                 pRockchipPort = &pRockchipComponent->pRockchipPort[portIndex];
1074 
1075                 if (pRockchipPort->portDefinition.eDir == OMX_DirInput) {
1076                     if (CHECK_PORT_BUFFER_SUPPLIER(pRockchipPort)) {
1077                         bufferSupplier->eBufferSupplier = OMX_BufferSupplyInput;
1078                     } else if (CHECK_PORT_TUNNELED(pRockchipPort)) {
1079                         bufferSupplier->eBufferSupplier = OMX_BufferSupplyOutput;
1080                     } else {
1081                         bufferSupplier->eBufferSupplier = OMX_BufferSupplyUnspecified;
1082                     }
1083                 } else {
1084                     if (CHECK_PORT_BUFFER_SUPPLIER(pRockchipPort)) {
1085                         bufferSupplier->eBufferSupplier = OMX_BufferSupplyOutput;
1086                     } else if (CHECK_PORT_TUNNELED(pRockchipPort)) {
1087                         bufferSupplier->eBufferSupplier = OMX_BufferSupplyInput;
1088                     } else {
1089                         bufferSupplier->eBufferSupplier = OMX_BufferSupplyUnspecified;
1090                     }
1091                 }
1092             } else {
1093                 ret = OMX_ErrorIncorrectStateOperation;
1094                 goto EXIT;
1095             }
1096         }
1097         break;
1098         default: {
1099             ret = OMX_ErrorUnsupportedIndex;
1100             goto EXIT;
1101         }
1102     break;
1103     }
1104 
1105     ret = OMX_ErrorNone;
1106 
1107 EXIT:
1108 
1109     FunctionOut();
1110 
1111     return ret;
1112 }
1113 
Rockchip_OMX_SetParameter(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nIndex,OMX_IN OMX_PTR ComponentParameterStructure)1114 OMX_ERRORTYPE Rockchip_OMX_SetParameter(
1115     OMX_IN OMX_HANDLETYPE hComponent,
1116     OMX_IN OMX_INDEXTYPE  nIndex,
1117     OMX_IN OMX_PTR        ComponentParameterStructure)
1118 {
1119     OMX_ERRORTYPE             ret = OMX_ErrorNone;
1120     OMX_COMPONENTTYPE        *pOMXComponent = NULL;
1121     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
1122 
1123     FunctionIn();
1124 
1125     if (hComponent == NULL) {
1126         ret = OMX_ErrorBadParameter;
1127         goto EXIT;
1128     }
1129     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1130     ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1131     if (ret != OMX_ErrorNone) {
1132         goto EXIT;
1133     }
1134 
1135     if (pOMXComponent->pComponentPrivate == NULL) {
1136         ret = OMX_ErrorBadParameter;
1137         goto EXIT;
1138     }
1139     pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1140 
1141     if (ComponentParameterStructure == NULL) {
1142         ret = OMX_ErrorBadParameter;
1143         goto EXIT;
1144     }
1145     if (pRockchipComponent->currentState == OMX_StateInvalid) {
1146         ret = OMX_ErrorInvalidState;
1147         goto EXIT;
1148     }
1149 
1150     switch (nIndex) {
1151         case OMX_IndexParamAudioInit:
1152         case OMX_IndexParamVideoInit:
1153         case OMX_IndexParamImageInit:
1154         case OMX_IndexParamOtherInit: {
1155             OMX_PORT_PARAM_TYPE *portParam = (OMX_PORT_PARAM_TYPE *)ComponentParameterStructure;
1156             ret = Rockchip_OMX_Check_SizeVersion(portParam, sizeof(OMX_PORT_PARAM_TYPE));
1157             if (ret != OMX_ErrorNone) {
1158                 goto EXIT;
1159             }
1160 
1161             if ((pRockchipComponent->currentState != OMX_StateLoaded) &&
1162                 (pRockchipComponent->currentState != OMX_StateWaitForResources)) {
1163                 ret = OMX_ErrorIncorrectStateOperation;
1164                 goto EXIT;
1165             }
1166             ret = OMX_ErrorUndefined;
1167         }
1168             break;
1169         case OMX_IndexParamPortDefinition: {
1170             OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure;
1171             OMX_U32                       portIndex = portDefinition->nPortIndex;
1172             ROCKCHIP_OMX_BASEPORT          *pRockchipPort;
1173 
1174             if (portIndex >= pRockchipComponent->portParam.nPorts) {
1175                 ret = OMX_ErrorBadPortIndex;
1176                 goto EXIT;
1177             }
1178             ret = Rockchip_OMX_Check_SizeVersion(portDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
1179             if (ret != OMX_ErrorNone) {
1180                 goto EXIT;
1181             }
1182 
1183             pRockchipPort = &pRockchipComponent->pRockchipPort[portIndex];
1184 
1185             if ((pRockchipComponent->currentState != OMX_StateLoaded) &&
1186                 (pRockchipComponent->currentState != OMX_StateWaitForResources)) {
1187                 if (pRockchipPort->portDefinition.bEnabled == OMX_TRUE) {
1188                     ret = OMX_ErrorIncorrectStateOperation;
1189                     goto EXIT;
1190                 }
1191             }
1192             if (portDefinition->nBufferCountActual < pRockchipPort->portDefinition.nBufferCountMin) {
1193                 ret = OMX_ErrorBadParameter;
1194                 goto EXIT;
1195             }
1196 
1197             Rockchip_OSAL_Memcpy(&pRockchipPort->portDefinition, portDefinition, portDefinition->nSize);
1198         }
1199             break;
1200         case OMX_IndexParamPriorityMgmt: {
1201             OMX_PRIORITYMGMTTYPE *compPriority = (OMX_PRIORITYMGMTTYPE *)ComponentParameterStructure;
1202 
1203             if ((pRockchipComponent->currentState != OMX_StateLoaded) &&
1204                 (pRockchipComponent->currentState != OMX_StateWaitForResources)) {
1205                 ret = OMX_ErrorIncorrectStateOperation;
1206                 goto EXIT;
1207             }
1208 
1209             ret = Rockchip_OMX_Check_SizeVersion(compPriority, sizeof(OMX_PRIORITYMGMTTYPE));
1210             if (ret != OMX_ErrorNone) {
1211                 goto EXIT;
1212             }
1213 
1214             pRockchipComponent->compPriority.nGroupID = compPriority->nGroupID;
1215             pRockchipComponent->compPriority.nGroupPriority = compPriority->nGroupPriority;
1216         }
1217             break;
1218         case OMX_IndexParamCompBufferSupplier: {
1219             OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplier = (OMX_PARAM_BUFFERSUPPLIERTYPE *)ComponentParameterStructure;
1220             OMX_U32           portIndex = bufferSupplier->nPortIndex;
1221             ROCKCHIP_OMX_BASEPORT *pRockchipPort = NULL;
1222 
1223 
1224             if (portIndex >= pRockchipComponent->portParam.nPorts) {
1225                 ret = OMX_ErrorBadPortIndex;
1226                 goto EXIT;
1227             }
1228             ret = Rockchip_OMX_Check_SizeVersion(bufferSupplier, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
1229             if (ret != OMX_ErrorNone) {
1230                 goto EXIT;
1231             }
1232 
1233             pRockchipPort = &pRockchipComponent->pRockchipPort[portIndex];
1234             if ((pRockchipComponent->currentState != OMX_StateLoaded) &&
1235                 (pRockchipComponent->currentState != OMX_StateWaitForResources)) {
1236                 if (pRockchipPort->portDefinition.bEnabled == OMX_TRUE) {
1237                     ret = OMX_ErrorIncorrectStateOperation;
1238                     goto EXIT;
1239                 }
1240             }
1241 
1242             if (bufferSupplier->eBufferSupplier == OMX_BufferSupplyUnspecified) {
1243                 ret = OMX_ErrorNone;
1244                 goto EXIT;
1245             }
1246             if (CHECK_PORT_TUNNELED(pRockchipPort) == 0) {
1247                 ret = OMX_ErrorNone; /* OMX_ErrorNone ????? */
1248                 goto EXIT;
1249             }
1250 
1251             if (pRockchipPort->portDefinition.eDir == OMX_DirInput) {
1252                 if (bufferSupplier->eBufferSupplier == OMX_BufferSupplyInput) {
1253                     pRockchipPort->tunnelFlags |= ROCKCHIP_TUNNEL_IS_SUPPLIER;
1254                     bufferSupplier->nPortIndex = pRockchipPort->tunneledPort;
1255                     ret = OMX_SetParameter(pRockchipPort->tunneledComponent,
1256                         OMX_IndexParamCompBufferSupplier, bufferSupplier);
1257                     goto EXIT;
1258                 } else if (bufferSupplier->eBufferSupplier == OMX_BufferSupplyOutput) {
1259                     ret = OMX_ErrorNone;
1260                     if (CHECK_PORT_BUFFER_SUPPLIER(pRockchipPort)) {
1261                         pRockchipPort->tunnelFlags &= ~ROCKCHIP_TUNNEL_IS_SUPPLIER;
1262                         bufferSupplier->nPortIndex = pRockchipPort->tunneledPort;
1263                         ret = OMX_SetParameter(pRockchipPort->tunneledComponent,
1264                             OMX_IndexParamCompBufferSupplier, bufferSupplier);
1265                     }
1266                     goto EXIT;
1267                 }
1268             } else if (pRockchipPort->portDefinition.eDir == OMX_DirOutput) {
1269                 if (bufferSupplier->eBufferSupplier == OMX_BufferSupplyInput) {
1270                     ret = OMX_ErrorNone;
1271                     if (CHECK_PORT_BUFFER_SUPPLIER(pRockchipPort)) {
1272                         pRockchipPort->tunnelFlags &= ~ROCKCHIP_TUNNEL_IS_SUPPLIER;
1273                         ret = OMX_ErrorNone;
1274                     }
1275                     goto EXIT;
1276                 } else if (bufferSupplier->eBufferSupplier == OMX_BufferSupplyOutput) {
1277                     pRockchipPort->tunnelFlags |= ROCKCHIP_TUNNEL_IS_SUPPLIER;
1278                     ret = OMX_ErrorNone;
1279                     goto EXIT;
1280                 }
1281             }
1282         }
1283         break;
1284         default: {
1285             ret = OMX_ErrorUnsupportedIndex;
1286             goto EXIT;
1287         }
1288     break;
1289     }
1290 
1291     ret = OMX_ErrorNone;
1292 
1293 EXIT:
1294 
1295     FunctionOut();
1296 
1297     return ret;
1298 }
1299 
Rockchip_OMX_GetConfig(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nIndex,OMX_INOUT OMX_PTR pComponentConfigStructure)1300 OMX_ERRORTYPE Rockchip_OMX_GetConfig(
1301     OMX_IN OMX_HANDLETYPE hComponent,
1302     OMX_IN OMX_INDEXTYPE  nIndex,
1303     OMX_INOUT OMX_PTR     pComponentConfigStructure)
1304 {
1305     OMX_ERRORTYPE             ret = OMX_ErrorNone;
1306     OMX_COMPONENTTYPE        *pOMXComponent = NULL;
1307     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
1308 
1309     FunctionIn();
1310 
1311     if (hComponent == NULL) {
1312         ret = OMX_ErrorBadParameter;
1313         goto EXIT;
1314     }
1315     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1316     ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1317     if (ret != OMX_ErrorNone) {
1318         goto EXIT;
1319     }
1320 
1321     if (pOMXComponent->pComponentPrivate == NULL) {
1322         ret = OMX_ErrorBadParameter;
1323         goto EXIT;
1324     }
1325     pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1326 
1327     if (pComponentConfigStructure == NULL) {
1328         ret = OMX_ErrorBadParameter;
1329         goto EXIT;
1330     }
1331     if (pRockchipComponent->currentState == OMX_StateInvalid) {
1332         ret = OMX_ErrorInvalidState;
1333         goto EXIT;
1334     }
1335 
1336     switch (nIndex) {
1337     default:
1338         ret = OMX_ErrorUnsupportedIndex;
1339         break;
1340     }
1341 
1342 EXIT:
1343     FunctionOut();
1344 
1345     return ret;
1346 }
1347 
Rockchip_OMX_SetConfig(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nIndex,OMX_IN OMX_PTR pComponentConfigStructure)1348 OMX_ERRORTYPE Rockchip_OMX_SetConfig(
1349     OMX_IN OMX_HANDLETYPE hComponent,
1350     OMX_IN OMX_INDEXTYPE  nIndex,
1351     OMX_IN OMX_PTR        pComponentConfigStructure)
1352 {
1353     OMX_ERRORTYPE             ret = OMX_ErrorNone;
1354     OMX_COMPONENTTYPE        *pOMXComponent = NULL;
1355     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
1356 
1357     FunctionIn();
1358 
1359     if (hComponent == NULL) {
1360         ret = OMX_ErrorBadParameter;
1361         goto EXIT;
1362     }
1363     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1364     ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1365     if (ret != OMX_ErrorNone) {
1366         goto EXIT;
1367     }
1368 
1369     if (pOMXComponent->pComponentPrivate == NULL) {
1370         ret = OMX_ErrorBadParameter;
1371         goto EXIT;
1372     }
1373     pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1374 
1375     if (pComponentConfigStructure == NULL) {
1376         ret = OMX_ErrorBadParameter;
1377         goto EXIT;
1378     }
1379     if (pRockchipComponent->currentState == OMX_StateInvalid) {
1380         ret = OMX_ErrorInvalidState;
1381         goto EXIT;
1382     }
1383 
1384     switch (nIndex) {
1385     default:
1386         ret = OMX_ErrorUnsupportedIndex;
1387         break;
1388     }
1389 
1390 EXIT:
1391     FunctionOut();
1392 
1393     return ret;
1394 }
1395 
Rockchip_OMX_GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_STRING cParameterName,OMX_OUT OMX_INDEXTYPE * pIndexType)1396 OMX_ERRORTYPE Rockchip_OMX_GetExtensionIndex(
1397     OMX_IN OMX_HANDLETYPE  hComponent,
1398     OMX_IN OMX_STRING      cParameterName,
1399     OMX_OUT OMX_INDEXTYPE *pIndexType)
1400 {
1401     OMX_ERRORTYPE             ret = OMX_ErrorNone;
1402     OMX_COMPONENTTYPE        *pOMXComponent = NULL;
1403     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
1404 
1405     FunctionIn();
1406 
1407     if (hComponent == NULL) {
1408         ret = OMX_ErrorBadParameter;
1409         goto EXIT;
1410     }
1411     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1412     ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1413     if (ret != OMX_ErrorNone) {
1414         goto EXIT;
1415     }
1416 
1417     if (pOMXComponent->pComponentPrivate == NULL) {
1418         ret = OMX_ErrorBadParameter;
1419         goto EXIT;
1420     }
1421     pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1422 
1423     if ((cParameterName == NULL) || (pIndexType == NULL)) {
1424         ret = OMX_ErrorBadParameter;
1425         goto EXIT;
1426     }
1427     if (pRockchipComponent->currentState == OMX_StateInvalid) {
1428         ret = OMX_ErrorInvalidState;
1429         goto EXIT;
1430     }
1431 
1432     ret = OMX_ErrorBadParameter;
1433 
1434 EXIT:
1435     FunctionOut();
1436 
1437     return ret;
1438 }
1439 
Rockchip_OMX_SetCallbacks(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_CALLBACKTYPE * pCallbacks,OMX_IN OMX_PTR pAppData)1440 OMX_ERRORTYPE Rockchip_OMX_SetCallbacks (
1441     OMX_IN OMX_HANDLETYPE    hComponent,
1442     OMX_IN OMX_CALLBACKTYPE* pCallbacks,
1443     OMX_IN OMX_PTR           pAppData)
1444 {
1445     OMX_ERRORTYPE             ret = OMX_ErrorNone;
1446     OMX_COMPONENTTYPE        *pOMXComponent = NULL;
1447     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
1448 
1449     FunctionIn();
1450 
1451     if (hComponent == NULL) {
1452         ret = OMX_ErrorBadParameter;
1453 
1454         omx_err("OMX_ErrorBadParameter :%d", __LINE__);
1455         goto EXIT;
1456     }
1457     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1458     ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1459     if (ret != OMX_ErrorNone) {
1460 
1461         omx_err("OMX_ErrorNone :%d", __LINE__);
1462         goto EXIT;
1463     }
1464 
1465     if (pOMXComponent->pComponentPrivate == NULL) {
1466 
1467         omx_err("OMX_ErrorBadParameter :%d", __LINE__);
1468         ret = OMX_ErrorBadParameter;
1469         goto EXIT;
1470     }
1471     pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1472 
1473     if (pCallbacks == NULL) {
1474         omx_err("OMX_ErrorBadParameter :%d", __LINE__);
1475         ret = OMX_ErrorBadParameter;
1476         goto EXIT;
1477     }
1478     if (pRockchipComponent->currentState == OMX_StateInvalid) {
1479 
1480         omx_err("OMX_ErrorInvalidState :%d", __LINE__);
1481         ret = OMX_ErrorInvalidState;
1482         goto EXIT;
1483     }
1484     if (pRockchipComponent->currentState != OMX_StateLoaded) {
1485         omx_err("OMX_StateLoaded :%d", __LINE__);
1486         ret = OMX_ErrorIncorrectStateOperation;
1487         goto EXIT;
1488     }
1489 
1490     pRockchipComponent->pCallbacks = pCallbacks;
1491     pRockchipComponent->callbackData = pAppData;
1492 
1493     ret = OMX_ErrorNone;
1494 
1495 EXIT:
1496     FunctionOut();
1497 
1498     return ret;
1499 }
1500 
Rockchip_OMX_UseEGLImage(OMX_IN OMX_HANDLETYPE hComponent,OMX_INOUT OMX_BUFFERHEADERTYPE ** ppBufferHdr,OMX_IN OMX_U32 nPortIndex,OMX_IN OMX_PTR pAppPrivate,OMX_IN void * eglImage)1501 OMX_ERRORTYPE Rockchip_OMX_UseEGLImage(
1502     OMX_IN OMX_HANDLETYPE            hComponent,
1503     OMX_INOUT OMX_BUFFERHEADERTYPE **ppBufferHdr,
1504     OMX_IN OMX_U32                   nPortIndex,
1505     OMX_IN OMX_PTR                   pAppPrivate,
1506     OMX_IN void                     *eglImage)
1507 {
1508     (void)hComponent;
1509     (void)ppBufferHdr;
1510     (void)nPortIndex;
1511     (void)pAppPrivate;
1512     (void)eglImage;
1513     return OMX_ErrorNotImplemented;
1514 }
1515 
Rockchip_OMX_BaseComponent_Constructor(OMX_IN OMX_HANDLETYPE hComponent)1516 OMX_ERRORTYPE Rockchip_OMX_BaseComponent_Constructor(
1517     OMX_IN OMX_HANDLETYPE hComponent)
1518 {
1519     OMX_ERRORTYPE             ret = OMX_ErrorNone;
1520     OMX_COMPONENTTYPE        *pOMXComponent;
1521     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
1522 
1523     FunctionIn();
1524 
1525     if (hComponent == NULL) {
1526         ret = OMX_ErrorBadParameter;
1527         omx_err("OMX_ErrorBadParameter, Line:%d", __LINE__);
1528         goto EXIT;
1529     }
1530     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1531     pRockchipComponent = Rockchip_OSAL_Malloc(sizeof(ROCKCHIP_OMX_BASECOMPONENT));
1532     if (pRockchipComponent == NULL) {
1533         ret = OMX_ErrorInsufficientResources;
1534         omx_err("OMX_ErrorInsufficientResources, Line:%d", __LINE__);
1535         goto EXIT;
1536     }
1537     Rockchip_OSAL_Memset(pRockchipComponent, 0, sizeof(ROCKCHIP_OMX_BASECOMPONENT));
1538     pOMXComponent->pComponentPrivate = (OMX_PTR)pRockchipComponent;
1539 
1540     ret = Rockchip_OSAL_SemaphoreCreate(&pRockchipComponent->msgSemaphoreHandle);
1541     if (ret != OMX_ErrorNone) {
1542         ret = OMX_ErrorInsufficientResources;
1543         omx_err("OMX_ErrorInsufficientResources, Line:%d", __LINE__);
1544         goto EXIT;
1545     }
1546     ret = Rockchip_OSAL_MutexCreate(&pRockchipComponent->compMutex);
1547     if (ret != OMX_ErrorNone) {
1548         ret = OMX_ErrorInsufficientResources;
1549         omx_err("OMX_ErrorInsufficientResources, Line:%d", __LINE__);
1550         goto EXIT;
1551     }
1552     ret = Rockchip_OSAL_SignalCreate(&pRockchipComponent->abendStateEvent);
1553     if (ret != OMX_ErrorNone) {
1554         ret = OMX_ErrorInsufficientResources;
1555         omx_err("OMX_ErrorInsufficientResources, Line:%d", __LINE__);
1556         goto EXIT;
1557     }
1558 
1559     pRockchipComponent->bExitMessageHandlerThread = OMX_FALSE;
1560     Rockchip_OSAL_QueueCreate(&pRockchipComponent->messageQ, MAX_QUEUE_ELEMENTS);
1561     ret = Rockchip_OSAL_ThreadCreate(&pRockchipComponent->hMessageHandler,
1562                                      Rockchip_OMX_MessageHandlerThread,
1563                                      pOMXComponent,
1564                                      "omx_msg_hdl");
1565     if (ret != OMX_ErrorNone) {
1566         ret = OMX_ErrorInsufficientResources;
1567         omx_err("OMX_ErrorInsufficientResources, Line:%d", __LINE__);
1568         goto EXIT;
1569     }
1570 
1571     pRockchipComponent->bMultiThreadProcess = OMX_FALSE;
1572 
1573     pOMXComponent->GetComponentVersion = &Rockchip_OMX_GetComponentVersion;
1574     pOMXComponent->SendCommand         = &Rockchip_OMX_SendCommand;
1575     pOMXComponent->GetState            = &Rockchip_OMX_GetState;
1576     pOMXComponent->SetCallbacks        = &Rockchip_OMX_SetCallbacks;
1577     pOMXComponent->UseEGLImage         = &Rockchip_OMX_UseEGLImage;
1578 
1579 EXIT:
1580     FunctionOut();
1581 
1582     return ret;
1583 }
1584 
Rockchip_OMX_BaseComponent_Destructor(OMX_IN OMX_HANDLETYPE hComponent)1585 OMX_ERRORTYPE Rockchip_OMX_BaseComponent_Destructor(
1586     OMX_IN OMX_HANDLETYPE hComponent)
1587 {
1588     OMX_ERRORTYPE             ret = OMX_ErrorNone;
1589     OMX_COMPONENTTYPE        *pOMXComponent = NULL;
1590     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
1591     OMX_S32                   semaValue = 0;
1592 
1593     FunctionIn();
1594 
1595     if (hComponent == NULL) {
1596         ret = OMX_ErrorBadParameter;
1597         goto EXIT;
1598     }
1599     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1600     ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1601     if (ret != OMX_ErrorNone) {
1602         goto EXIT;
1603     }
1604 
1605     if (pOMXComponent->pComponentPrivate == NULL) {
1606         ret = OMX_ErrorBadParameter;
1607         goto EXIT;
1608     }
1609     pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1610 
1611     Rockchip_OMX_CommandQueue(pRockchipComponent, (OMX_COMMANDTYPE)ROCKCHIP_OMX_CommandComponentDeInit, 0, NULL);
1612     Rockchip_OSAL_SleepMillisec(0);
1613     Rockchip_OSAL_Get_SemaphoreCount(pRockchipComponent->msgSemaphoreHandle, &semaValue);
1614     if (semaValue == 0)
1615         Rockchip_OSAL_SemaphorePost(pRockchipComponent->msgSemaphoreHandle);
1616     Rockchip_OSAL_SemaphorePost(pRockchipComponent->msgSemaphoreHandle);
1617 
1618     Rockchip_OSAL_ThreadTerminate(pRockchipComponent->hMessageHandler);
1619     pRockchipComponent->hMessageHandler = NULL;
1620 
1621     Rockchip_OSAL_SignalTerminate(pRockchipComponent->abendStateEvent);
1622     pRockchipComponent->abendStateEvent = NULL;
1623     Rockchip_OSAL_MutexTerminate(pRockchipComponent->compMutex);
1624     pRockchipComponent->compMutex = NULL;
1625     Rockchip_OSAL_SemaphoreTerminate(pRockchipComponent->msgSemaphoreHandle);
1626     pRockchipComponent->msgSemaphoreHandle = NULL;
1627     Rockchip_OSAL_QueueTerminate(&pRockchipComponent->messageQ);
1628 
1629     Rockchip_OSAL_Free(pRockchipComponent);
1630     pOMXComponent->pComponentPrivate = pRockchipComponent = NULL;
1631 
1632     ret = OMX_ErrorNone;
1633 EXIT:
1634     FunctionOut();
1635 
1636     return ret;
1637 }