• 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_Baseport.c
20  * @brief
21  * @author     csy (csy@rock-chips.com)
22  * @version    1.0.0
23  * @history
24  *    2013.11.26 : Create
25  */
26 
27 #undef  ROCKCHIP_LOG_TAG
28 #define ROCKCHIP_LOG_TAG    "omx_base_port"
29 
30 #include "Rockchip_OMX_Baseport.h"
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include "Rockchip_OMX_Macros.h"
35 #include "Rockchip_OSAL_Event.h"
36 #include "Rockchip_OSAL_Semaphore.h"
37 #include "Rockchip_OSAL_Mutex.h"
38 #include "Rockchip_OMX_Basecomponent.h"
39 #include "Rockchip_OSAL_OHOS.h"
40 #include "Rockchip_OSAL_Log.h"
41 #include "omx_video_global.h"
42 
43 OMX_U32 omx_vdec_debug = 0;
44 OMX_U32 omx_venc_debug = 0;
45 
46 
Rkvpu_OMX_InputBufferReturn(OMX_COMPONENTTYPE * pOMXComponent,OMX_BUFFERHEADERTYPE * bufferHeader)47 OMX_ERRORTYPE Rkvpu_OMX_InputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, OMX_BUFFERHEADERTYPE* bufferHeader)
48 {
49     OMX_ERRORTYPE             ret = OMX_ErrorNone;
50     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
51     ROCKCHIP_OMX_BASEPORT      *pRockchipPort = &pRockchipComponent->pRockchipPort[INPUT_PORT_INDEX];
52     OMX_U32                   i = 0;
53 
54     Rockchip_OSAL_MutexLock(pRockchipPort->hPortMutex);
55     for (i = 0; i < pRockchipPort->portDefinition.nBufferCountActual; i++) {
56         if (bufferHeader == pRockchipPort->extendBufferHeader[i].OMXBufferHeader) {
57             pRockchipPort->extendBufferHeader[i].bBufferInOMX = OMX_FALSE;
58             break;
59         }
60     }
61 
62     VIDEO_DBG(VIDEO_DBG_LOG_PORT, "[%s]: empty buffer done(%p) timeus: %lld us, flags: 0x%lx",
63               pRockchipComponent->componentName,
64               bufferHeader->pBuffer,
65               bufferHeader->nTimeStamp,
66               bufferHeader->nFlags);
67 
68     Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
69     pRockchipComponent->pCallbacks->EmptyBufferDone(pOMXComponent, pRockchipComponent->callbackData, bufferHeader);
70 
71     return ret;
72 }
73 
Rockchip_OMX_OutputBufferReturn(OMX_COMPONENTTYPE * pOMXComponent,OMX_BUFFERHEADERTYPE * bufferHeader)74 OMX_ERRORTYPE Rockchip_OMX_OutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, OMX_BUFFERHEADERTYPE* bufferHeader)
75 {
76     OMX_ERRORTYPE             ret = OMX_ErrorNone;
77     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
78     ROCKCHIP_OMX_BASEPORT      *pRockchipPort = &pRockchipComponent->pRockchipPort[OUTPUT_PORT_INDEX];
79     OMX_U32                   i = 0;
80 
81     Rockchip_OSAL_MutexLock(pRockchipPort->hPortMutex);
82     for (i = 0; i < MAX_BUFFER_NUM; i++) {
83         if (bufferHeader == pRockchipPort->extendBufferHeader[i].OMXBufferHeader) {
84             pRockchipPort->extendBufferHeader[i].bBufferInOMX = OMX_FALSE;
85             break;
86         }
87     }
88 
89     if (bufferHeader->nFlags & OMX_BUFFERFLAG_EOS) {
90         VIDEO_DBG(VIDEO_DBG_LOG_PORT, "[%s]: fill EOS buffer done(%p) timeus: %lld us, flags: 0x%lx",
91                   pRockchipComponent->componentName,
92                   bufferHeader->pBuffer,
93                   bufferHeader->nTimeStamp,
94                   bufferHeader->nFlags);
95     } else {
96         VIDEO_DBG(VIDEO_DBG_LOG_PORT, "[%s]: fill buffer done(%p) timeus: %lld us, flags: 0x%lx",
97                   pRockchipComponent->componentName,
98                   bufferHeader->pBuffer,
99                   bufferHeader->nTimeStamp,
100                   bufferHeader->nFlags);
101     }
102 
103     Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
104     pRockchipComponent->pCallbacks->FillBufferDone(pOMXComponent, pRockchipComponent->callbackData, bufferHeader);
105 
106     goto EXIT;
107 EXIT:
108     omx_trace("bufferHeader:0x%p", bufferHeader);
109     return ret;
110 }
111 
Rockchip_OMX_BufferFlushProcess(OMX_COMPONENTTYPE * pOMXComponent,OMX_S32 nPortIndex,OMX_BOOL bEvent)112 OMX_ERRORTYPE Rockchip_OMX_BufferFlushProcess(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex, OMX_BOOL bEvent)
113 {
114     OMX_ERRORTYPE             ret = OMX_ErrorNone;
115     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
116     OMX_S32                   portIndex = 0;
117     OMX_U32                   i = 0, cnt = 0;
118 
119     FunctionIn();
120 
121     if (pOMXComponent == NULL) {
122         ret = OMX_ErrorBadParameter;
123         goto EXIT;
124     }
125     ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
126     if (ret != OMX_ErrorNone) {
127         goto EXIT;
128     }
129 
130     if (pOMXComponent->pComponentPrivate == NULL) {
131         ret = OMX_ErrorBadParameter;
132         goto EXIT;
133     }
134     pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
135 
136     cnt = (nPortIndex == ALL_PORT_INDEX) ? ALL_PORT_NUM : 1;
137 
138     for (i = 0; i < cnt; i++) {
139         if (nPortIndex == ALL_PORT_INDEX)
140             portIndex = i;
141         else
142             portIndex = nPortIndex;
143 
144         pRockchipComponent->rockchip_BufferFlush(pOMXComponent, portIndex, bEvent);
145     }
146 
147     VIDEO_DBG(VIDEO_DBG_LOG_PORT, "[%s]: buffer flush.", pRockchipComponent->componentName);
148 
149 EXIT:
150     if ((ret != OMX_ErrorNone) && (pOMXComponent != NULL) && (pRockchipComponent != NULL)) {
151         omx_err("ERROR");
152         pRockchipComponent->pCallbacks->EventHandler(pOMXComponent,
153                                                      pRockchipComponent->callbackData,
154                                                      OMX_EventError,
155                                                      ret, 0, NULL);
156     }
157 
158     FunctionOut();
159 
160     return ret;
161 }
162 
Rockchip_OMX_EnablePort(OMX_COMPONENTTYPE * pOMXComponent,OMX_S32 portIndex)163 OMX_ERRORTYPE Rockchip_OMX_EnablePort(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 portIndex)
164 {
165     OMX_ERRORTYPE          ret = OMX_ErrorNone;
166     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
167     ROCKCHIP_OMX_BASEPORT      *pRockchipPort = NULL;
168 
169     FunctionIn();
170 
171     pRockchipPort = &pRockchipComponent->pRockchipPort[portIndex];
172 
173     if ((pRockchipComponent->currentState != OMX_StateLoaded) &&
174         (pRockchipComponent->currentState != OMX_StateWaitForResources)) {
175         Rockchip_OSAL_SemaphoreWait(pRockchipPort->loadedResource);
176 
177         if (pRockchipPort->exceptionFlag == INVALID_STATE) {
178             pRockchipPort->exceptionFlag = NEED_PORT_DISABLE;
179             goto EXIT;
180         }
181         pRockchipPort->portDefinition.bPopulated = OMX_TRUE;
182     }
183     pRockchipPort->exceptionFlag = GENERAL_STATE;
184     pRockchipPort->portDefinition.bEnabled = OMX_TRUE;
185     VIDEO_DBG(VIDEO_DBG_LOG_PORT, "[%s]: now enable %s port.",
186               pRockchipComponent->componentName,
187               portIndex == INPUT_PORT_INDEX ? "input" : "output");
188 
189     ret = OMX_ErrorNone;
190 
191 EXIT:
192     FunctionOut();
193 
194     return ret;
195 }
196 
Rockchip_OMX_PortEnableProcess(OMX_COMPONENTTYPE * pOMXComponent,OMX_S32 nPortIndex)197 OMX_ERRORTYPE Rockchip_OMX_PortEnableProcess(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex)
198 {
199     OMX_ERRORTYPE          ret = OMX_ErrorNone;
200     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
201     OMX_S32                portIndex = 0;
202     OMX_U32                i = 0, cnt = 0;
203 
204     FunctionIn();
205 
206     if (pOMXComponent == NULL) {
207         ret = OMX_ErrorBadParameter;
208         goto EXIT;
209     }
210     ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
211     if (ret != OMX_ErrorNone) {
212         goto EXIT;
213     }
214 
215     if (pOMXComponent->pComponentPrivate == NULL) {
216         ret = OMX_ErrorBadParameter;
217         goto EXIT;
218     }
219     pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
220 
221     cnt = (nPortIndex == ALL_PORT_INDEX) ? ALL_PORT_NUM : 1;
222 
223     for (i = 0; i < cnt; i++) {
224         if (nPortIndex == ALL_PORT_INDEX)
225             portIndex = i;
226         else
227             portIndex = nPortIndex;
228 
229         ret = Rockchip_OMX_EnablePort(pOMXComponent, portIndex);
230         if (ret == OMX_ErrorNone) {
231             pRockchipComponent->pCallbacks->EventHandler(pOMXComponent,
232                                                          pRockchipComponent->callbackData,
233                                                          OMX_EventCmdComplete,
234                                                          OMX_CommandPortEnable, portIndex, NULL);
235         }
236     }
237 
238 EXIT:
239     if ((ret != OMX_ErrorNone) && (pOMXComponent != NULL) && (pRockchipComponent != NULL)) {
240         pRockchipComponent->pCallbacks->EventHandler(pOMXComponent,
241                                                      pRockchipComponent->callbackData,
242                                                      OMX_EventError,
243                                                      ret, 0, NULL);
244     }
245 
246     FunctionOut();
247 
248     return ret;
249 }
250 
Rockchip_OMX_DisablePort(OMX_COMPONENTTYPE * pOMXComponent,OMX_S32 portIndex)251 OMX_ERRORTYPE Rockchip_OMX_DisablePort(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 portIndex)
252 {
253     OMX_ERRORTYPE          ret = OMX_ErrorNone;
254     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
255     ROCKCHIP_OMX_BASEPORT      *pRockchipPort = NULL;
256     ROCKCHIP_OMX_MESSAGE       *message;
257 
258     FunctionIn();
259 
260     pRockchipPort = &pRockchipComponent->pRockchipPort[portIndex];
261 
262     if (!CHECK_PORT_ENABLED(pRockchipPort)) {
263         ret = OMX_ErrorNone;
264         goto EXIT;
265     }
266 
267     if (pRockchipComponent->currentState != OMX_StateLoaded) {
268         if (CHECK_PORT_BUFFER_SUPPLIER(pRockchipPort)) {
269             while (Rockchip_OSAL_GetElemNum(&pRockchipPort->bufferQ) > 0) {
270                 message = (ROCKCHIP_OMX_MESSAGE*)Rockchip_OSAL_Dequeue(&pRockchipPort->bufferQ);
271                 Rockchip_OSAL_Free(message);
272             }
273         }
274         pRockchipPort->portDefinition.bPopulated = OMX_FALSE;
275         Rockchip_OSAL_SemaphoreWait(pRockchipPort->unloadedResource);
276     }
277 
278     if (pRockchipComponent->codecType == HW_VIDEO_DEC_CODEC
279         && portIndex == OUTPUT_PORT_INDEX) {
280         ret = Rkvpu_ComputeDecBufferCount((OMX_HANDLETYPE)pOMXComponent);
281         if (ret != OMX_ErrorNone) {
282             omx_err("compute decoder buffer count failed!");
283             goto EXIT;
284         }
285     }
286     pRockchipPort->portDefinition.bEnabled = OMX_FALSE;
287     VIDEO_DBG(VIDEO_DBG_LOG_PORT, "[%s]: now disable %s port.",
288               pRockchipComponent->componentName,
289               portIndex == INPUT_PORT_INDEX ? "input" : "output");
290 
291     ret = OMX_ErrorNone;
292 
293 EXIT:
294     FunctionOut();
295 
296     return ret;
297 }
298 
Rockchip_OMX_PortDisableProcess(OMX_COMPONENTTYPE * pOMXComponent,OMX_S32 nPortIndex)299 OMX_ERRORTYPE Rockchip_OMX_PortDisableProcess(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex)
300 {
301     OMX_ERRORTYPE          ret = OMX_ErrorNone;
302     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
303     OMX_S32                portIndex = 0;
304     OMX_U32                i = 0, cnt = 0;
305 
306     FunctionIn();
307 
308     if (pOMXComponent == NULL) {
309         ret = OMX_ErrorBadParameter;
310         goto EXIT;
311     }
312     ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
313     if (ret != OMX_ErrorNone) {
314         goto EXIT;
315     }
316 
317     if (pOMXComponent->pComponentPrivate == NULL) {
318         ret = OMX_ErrorBadParameter;
319         goto EXIT;
320     }
321     pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
322 
323     cnt = (nPortIndex == ALL_PORT_INDEX) ? ALL_PORT_NUM : 1;
324 
325     /* port flush */
326     for (i = 0; i < cnt; i++) {
327         if (nPortIndex == ALL_PORT_INDEX)
328             portIndex = i;
329         else
330             portIndex = nPortIndex;
331 
332         Rockchip_OMX_BufferFlushProcess(pOMXComponent, portIndex, OMX_FALSE);
333     }
334 
335     for (i = 0; i < cnt; i++) {
336         if (nPortIndex == ALL_PORT_INDEX)
337             portIndex = i;
338         else
339             portIndex = nPortIndex;
340 
341         ret = Rockchip_OMX_DisablePort(pOMXComponent, portIndex);
342         pRockchipComponent->pRockchipPort[portIndex].bIsPortDisabled = OMX_FALSE;
343         if (ret == OMX_ErrorNone) {
344             pRockchipComponent->pCallbacks->EventHandler(pOMXComponent,
345                                                          pRockchipComponent->callbackData,
346                                                          OMX_EventCmdComplete,
347                                                          OMX_CommandPortDisable, portIndex, NULL);
348         }
349     }
350 
351 EXIT:
352     if ((ret != OMX_ErrorNone) && (pOMXComponent != NULL) && (pRockchipComponent != NULL)) {
353         pRockchipComponent->pCallbacks->EventHandler(pOMXComponent,
354                                                      pRockchipComponent->callbackData,
355                                                      OMX_EventError,
356                                                      ret, 0, NULL);
357     }
358 
359     FunctionOut();
360 
361     return ret;
362 }
363 
Rockchip_OMX_EmptyThisBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_BUFFERHEADERTYPE * pBuffer)364 OMX_ERRORTYPE Rockchip_OMX_EmptyThisBuffer(
365     OMX_IN OMX_HANDLETYPE        hComponent,
366     OMX_IN OMX_BUFFERHEADERTYPE *pBuffer)
367 {
368     OMX_ERRORTYPE           ret = OMX_ErrorNone;
369     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
370     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
371     ROCKCHIP_OMX_BASEPORT      *pRockchipPort = NULL;
372     OMX_BOOL               findBuffer = OMX_FALSE;
373     ROCKCHIP_OMX_MESSAGE       *message;
374     OMX_U32                i = 0;
375 
376     FunctionIn();
377 
378     if (hComponent == NULL) {
379         ret = OMX_ErrorBadParameter;
380         goto EXIT;
381     }
382     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
383     ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
384     if (ret != OMX_ErrorNone) {
385         goto EXIT;
386     }
387 
388     if (pOMXComponent->pComponentPrivate == NULL) {
389         ret = OMX_ErrorBadParameter;
390         goto EXIT;
391     }
392     pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
393     if (pRockchipComponent->currentState == OMX_StateInvalid) {
394         ret = OMX_ErrorInvalidState;
395         goto EXIT;
396     }
397 
398     if (pBuffer == NULL) {
399         ret = OMX_ErrorBadParameter;
400         goto EXIT;
401     }
402     if (pBuffer->nInputPortIndex != INPUT_PORT_INDEX) {
403         ret = OMX_ErrorBadPortIndex;
404         goto EXIT;
405     }
406 
407     ret = Rockchip_OMX_Check_SizeVersion(pBuffer, sizeof(OMX_BUFFERHEADERTYPE));
408     if (ret != OMX_ErrorNone) {
409         goto EXIT;
410     }
411 
412     if ((pRockchipComponent->currentState != OMX_StateIdle) &&
413         (pRockchipComponent->currentState != OMX_StateExecuting) &&
414         (pRockchipComponent->currentState != OMX_StatePause)) {
415         ret = OMX_ErrorIncorrectStateOperation;
416         goto EXIT;
417     }
418 
419     pRockchipPort = &pRockchipComponent->pRockchipPort[INPUT_PORT_INDEX];
420     if ((!CHECK_PORT_ENABLED(pRockchipPort)) ||
421         (CHECK_PORT_BEING_FLUSHED(pRockchipPort) &&
422          (!CHECK_PORT_TUNNELED(pRockchipPort) || !CHECK_PORT_BUFFER_SUPPLIER(pRockchipPort))) ||
423         ((pRockchipComponent->transientState == ROCKCHIP_OMX_TransStateExecutingToIdle) &&
424          (CHECK_PORT_TUNNELED(pRockchipPort) && !CHECK_PORT_BUFFER_SUPPLIER(pRockchipPort)))) {
425         ret = OMX_ErrorIncorrectStateOperation;
426         goto EXIT;
427     }
428 
429     Rockchip_OSAL_MutexLock(pRockchipPort->hPortMutex);
430     for (i = 0; i < pRockchipPort->portDefinition.nBufferCountActual; i++) {
431         if (pBuffer == pRockchipPort->extendBufferHeader[i].OMXBufferHeader) {
432             pRockchipPort->extendBufferHeader[i].bBufferInOMX = OMX_TRUE;
433             findBuffer = OMX_TRUE;
434             break;
435         }
436     }
437 
438     if (findBuffer == OMX_FALSE) {
439         ret = OMX_ErrorBadParameter;
440         Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
441         goto EXIT;
442     }
443 
444     if (pBuffer->nFlags & OMX_BUFFERFLAG_EXTRADATA) {
445         omx_trace("[%s]: empty this extradata buffer(%p) timeus: %lld us, size: %ld, flags: 0x%lx",
446                   pRockchipComponent->componentName,
447                   pBuffer->pBuffer,
448                   pBuffer->nTimeStamp,
449                   pBuffer->nFilledLen,
450                   pBuffer->nFlags);
451 
452     } else if (pBuffer->nFlags & OMX_BUFFERFLAG_EOS) {
453         omx_trace("[%s]: empty this EOS buffer(%p) timeus: %lld us, size: %ld, flags: 0x%lx",
454                   pRockchipComponent->componentName,
455                   pBuffer->pBuffer,
456                   pBuffer->nTimeStamp,
457                   pBuffer->nFilledLen,
458                   pBuffer->nFlags);
459     } else {
460         omx_trace("[%s]: empty this buffer(%p) timeus: %lld us, size: %ld, flags: 0x%lx",
461                   pRockchipComponent->componentName,
462                   pBuffer->pBuffer,
463                   pBuffer->nTimeStamp,
464                   pBuffer->nFilledLen,
465                   pBuffer->nFlags);
466     }
467 
468     message = Rockchip_OSAL_Malloc(sizeof(ROCKCHIP_OMX_MESSAGE));
469     if (message == NULL) {
470         ret = OMX_ErrorInsufficientResources;
471         Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
472         goto EXIT;
473     }
474     message->messageType = ROCKCHIP_OMX_CommandEmptyBuffer;
475     message->messageParam = (OMX_U32) i;
476     message->pCmdData = (OMX_PTR)pBuffer;
477 
478     ret = Rockchip_OSAL_Queue(&pRockchipPort->bufferQ, (void *)message);
479 
480     if (ret != 0) {
481         ret = OMX_ErrorUndefined;
482         Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
483         goto EXIT;
484     }
485     ret = Rockchip_OSAL_SemaphorePost(pRockchipPort->bufferSemID);
486     Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
487 
488 EXIT:
489     FunctionOut();
490 
491     return ret;
492 }
493 
Rockchip_OMX_FillThisBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_BUFFERHEADERTYPE * pBuffer)494 OMX_ERRORTYPE Rockchip_OMX_FillThisBuffer(
495     OMX_IN OMX_HANDLETYPE        hComponent,
496     OMX_IN OMX_BUFFERHEADERTYPE *pBuffer)
497 {
498     OMX_ERRORTYPE           ret = OMX_ErrorNone;
499     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
500     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
501     ROCKCHIP_OMX_BASEPORT      *pRockchipPort = NULL;
502     OMX_BOOL               findBuffer = OMX_FALSE;
503     ROCKCHIP_OMX_MESSAGE       *message;
504     OMX_U32                i = 0;
505 
506     FunctionIn();
507 
508     if (hComponent == NULL) {
509         ret = OMX_ErrorBadParameter;
510         goto EXIT;
511     }
512     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
513     ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
514     if (ret != OMX_ErrorNone) {
515         goto EXIT;
516     }
517 
518     if (pOMXComponent->pComponentPrivate == NULL) {
519         ret = OMX_ErrorBadParameter;
520         goto EXIT;
521     }
522     pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
523     if (pRockchipComponent->currentState == OMX_StateInvalid) {
524         ret = OMX_ErrorInvalidState;
525         goto EXIT;
526     }
527 
528     if (pBuffer == NULL) {
529         ret = OMX_ErrorBadParameter;
530         goto EXIT;
531     }
532     if (pBuffer->nOutputPortIndex != OUTPUT_PORT_INDEX) {
533         ret = OMX_ErrorBadPortIndex;
534         goto EXIT;
535     }
536 
537     ret = Rockchip_OMX_Check_SizeVersion(pBuffer, sizeof(OMX_BUFFERHEADERTYPE));
538     if (ret != OMX_ErrorNone) {
539         goto EXIT;
540     }
541 
542     if ((pRockchipComponent->currentState != OMX_StateIdle) &&
543         (pRockchipComponent->currentState != OMX_StateExecuting) &&
544         (pRockchipComponent->currentState != OMX_StatePause)) {
545         ret = OMX_ErrorIncorrectStateOperation;
546         goto EXIT;
547     }
548 
549     pRockchipPort = &pRockchipComponent->pRockchipPort[OUTPUT_PORT_INDEX];
550 
551     if ((!CHECK_PORT_ENABLED(pRockchipPort)) ||
552         (CHECK_PORT_BEING_FLUSHED(pRockchipPort) && (!CHECK_PORT_TUNNELED(pRockchipPort) ||
553             !CHECK_PORT_BUFFER_SUPPLIER(pRockchipPort))) ||
554         ((pRockchipComponent->transientState == ROCKCHIP_OMX_TransStateExecutingToIdle) &&
555             (CHECK_PORT_TUNNELED(pRockchipPort) && !CHECK_PORT_BUFFER_SUPPLIER(pRockchipPort)))) {
556         ret = OMX_ErrorIncorrectStateOperation;
557         goto EXIT;
558     }
559 
560     Rockchip_OSAL_MutexLock(pRockchipPort->hPortMutex);
561     for (i = 0; i < MAX_BUFFER_NUM; i++) {
562         if (pBuffer == pRockchipPort->extendBufferHeader[i].OMXBufferHeader) {
563             pRockchipPort->extendBufferHeader[i].bBufferInOMX = OMX_TRUE;
564             findBuffer = OMX_TRUE;
565             break;
566         }
567     }
568 
569     if (findBuffer == OMX_FALSE) {
570         ret = OMX_ErrorBadParameter;
571         Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
572         goto EXIT;
573     }
574 
575     omx_trace("[%s]: fill this buffer(%p) flags: 0x%lx",
576               pRockchipComponent->componentName,
577               pBuffer->pBuffer,
578               pBuffer->nFlags);
579 
580     if (pRockchipPort->bufferProcessType == BUFFER_SHARE) {
581         Rockchip_OSAL_Fd2VpumemPool(pRockchipComponent, pRockchipPort->extendBufferHeader[i].OMXBufferHeader);
582     } else {
583         message = Rockchip_OSAL_Malloc(sizeof(ROCKCHIP_OMX_MESSAGE));
584         if (message == NULL) {
585             ret = OMX_ErrorInsufficientResources;
586             Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
587             goto EXIT;
588         }
589         message->messageType = ROCKCHIP_OMX_CommandFillBuffer;
590         message->messageParam = (OMX_U32) i;
591         message->pCmdData = (OMX_PTR)pBuffer;
592 
593         ret = Rockchip_OSAL_Queue(&pRockchipPort->bufferQ, (void *)message);
594         if (ret != 0) {
595             ret = OMX_ErrorUndefined;
596             Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
597             goto EXIT;
598         }
599     }
600 
601     ret = Rockchip_OSAL_SemaphorePost(pRockchipPort->bufferSemID);
602     Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
603 
604 EXIT:
605     FunctionOut();
606 
607     return ret;
608 }
609 
Rockchip_OMX_Port_Constructor(OMX_HANDLETYPE hComponent)610 OMX_ERRORTYPE Rockchip_OMX_Port_Constructor(OMX_HANDLETYPE hComponent)
611 {
612     OMX_ERRORTYPE          ret = OMX_ErrorNone;
613     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
614     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
615     ROCKCHIP_OMX_BASEPORT      *pRockchipPort = NULL;
616     ROCKCHIP_OMX_BASEPORT      *pRockchipInputPort = NULL;
617     ROCKCHIP_OMX_BASEPORT      *pRockchipOutputPort = NULL;
618 
619     FunctionIn();
620 
621     if (hComponent == NULL) {
622         ret = OMX_ErrorBadParameter;
623         omx_err("OMX_ErrorBadParameter, Line:%d", __LINE__);
624         goto EXIT;
625     }
626     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
627     ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
628     if (ret != OMX_ErrorNone) {
629         goto EXIT;
630     }
631 
632     if (pOMXComponent->pComponentPrivate == NULL) {
633         ret = OMX_ErrorBadParameter;
634         omx_err("OMX_ErrorBadParameter, Line:%d", __LINE__);
635         goto EXIT;
636     }
637     pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
638 
639     INIT_SET_SIZE_VERSION(&pRockchipComponent->portParam, OMX_PORT_PARAM_TYPE);
640     pRockchipComponent->portParam.nPorts = ALL_PORT_NUM;
641     pRockchipComponent->portParam.nStartPortNumber = INPUT_PORT_INDEX;
642 
643     pRockchipPort = Rockchip_OSAL_Malloc(sizeof(ROCKCHIP_OMX_BASEPORT) * ALL_PORT_NUM);
644     if (pRockchipPort == NULL) {
645         ret = OMX_ErrorInsufficientResources;
646         omx_err("OMX_ErrorInsufficientResources, Line:%d", __LINE__);
647         goto EXIT;
648     }
649     Rockchip_OSAL_Memset(pRockchipPort, 0, sizeof(ROCKCHIP_OMX_BASEPORT) * ALL_PORT_NUM);
650     pRockchipComponent->pRockchipPort = pRockchipPort;
651 
652     /* Input Port */
653     pRockchipInputPort = &pRockchipPort[INPUT_PORT_INDEX];
654 
655     Rockchip_OSAL_QueueCreate(&pRockchipInputPort->bufferQ, MAX_QUEUE_ELEMENTS);
656     Rockchip_OSAL_QueueCreate(&pRockchipInputPort->securebufferQ, MAX_QUEUE_ELEMENTS);
657 
658     pRockchipInputPort->extendBufferHeader =
659         Rockchip_OSAL_Malloc(sizeof(ROCKCHIP_OMX_BUFFERHEADERTYPE) * MAX_BUFFER_NUM);
660     if (pRockchipInputPort->extendBufferHeader == NULL) {
661         Rockchip_OSAL_Free(pRockchipPort);
662         pRockchipPort = NULL;
663         ret = OMX_ErrorInsufficientResources;
664         omx_err("OMX_ErrorInsufficientResources, Line:%d", __LINE__);
665         goto EXIT;
666     }
667     Rockchip_OSAL_Memset(pRockchipInputPort->extendBufferHeader, 0,
668         sizeof(ROCKCHIP_OMX_BUFFERHEADERTYPE) * MAX_BUFFER_NUM);
669 
670     pRockchipInputPort->bufferStateAllocate = Rockchip_OSAL_Malloc(sizeof(OMX_U32) * MAX_BUFFER_NUM);
671     if (pRockchipInputPort->bufferStateAllocate == NULL) {
672         Rockchip_OSAL_Free(pRockchipInputPort->extendBufferHeader);
673         pRockchipInputPort->extendBufferHeader = NULL;
674         Rockchip_OSAL_Free(pRockchipPort);
675         pRockchipPort = NULL;
676         ret = OMX_ErrorInsufficientResources;
677         omx_err("OMX_ErrorInsufficientResources, Line:%d", __LINE__);
678         goto EXIT;
679     }
680     Rockchip_OSAL_Memset(pRockchipInputPort->bufferStateAllocate, 0, sizeof(OMX_U32) * MAX_BUFFER_NUM);
681 
682     pRockchipInputPort->bufferSemID = NULL;
683     pRockchipInputPort->assignedBufferNum = 0;
684     pRockchipInputPort->portState = OMX_StateMax;
685     pRockchipInputPort->bIsPortFlushed = OMX_FALSE;
686     pRockchipInputPort->bIsPortDisabled = OMX_FALSE;
687     pRockchipInputPort->tunneledComponent = NULL;
688     pRockchipInputPort->tunneledPort = 0;
689     pRockchipInputPort->tunnelBufferNum = 0;
690     pRockchipInputPort->bufferSupplier = OMX_BufferSupplyUnspecified;
691     pRockchipInputPort->tunnelFlags = 0;
692     ret = Rockchip_OSAL_SemaphoreCreate(&pRockchipInputPort->loadedResource);
693     if (ret != OMX_ErrorNone) {
694         Rockchip_OSAL_Free(pRockchipInputPort->bufferStateAllocate);
695         pRockchipInputPort->bufferStateAllocate = NULL;
696         Rockchip_OSAL_Free(pRockchipInputPort->extendBufferHeader);
697         pRockchipInputPort->extendBufferHeader = NULL;
698         Rockchip_OSAL_Free(pRockchipPort);
699         pRockchipPort = NULL;
700         goto EXIT;
701     }
702     ret = Rockchip_OSAL_SemaphoreCreate(&pRockchipInputPort->unloadedResource);
703     if (ret != OMX_ErrorNone) {
704         Rockchip_OSAL_SemaphoreTerminate(pRockchipInputPort->loadedResource);
705         pRockchipInputPort->loadedResource = NULL;
706         Rockchip_OSAL_Free(pRockchipInputPort->bufferStateAllocate);
707         pRockchipInputPort->bufferStateAllocate = NULL;
708         Rockchip_OSAL_Free(pRockchipInputPort->extendBufferHeader);
709         pRockchipInputPort->extendBufferHeader = NULL;
710         Rockchip_OSAL_Free(pRockchipPort);
711         pRockchipPort = NULL;
712         goto EXIT;
713     }
714 
715     INIT_SET_SIZE_VERSION(&pRockchipInputPort->portDefinition, OMX_PARAM_PORTDEFINITIONTYPE);
716     pRockchipInputPort->portDefinition.nPortIndex = INPUT_PORT_INDEX;
717     pRockchipInputPort->portDefinition.eDir = OMX_DirInput;
718     pRockchipInputPort->portDefinition.nBufferCountActual = 0;
719     pRockchipInputPort->portDefinition.nBufferCountMin = 0;
720     pRockchipInputPort->portDefinition.nBufferSize = 0;
721     pRockchipInputPort->portDefinition.bEnabled = OMX_FALSE;
722     pRockchipInputPort->portDefinition.bPopulated = OMX_FALSE;
723     pRockchipInputPort->portDefinition.eDomain = OMX_PortDomainMax;
724     pRockchipInputPort->portDefinition.bBuffersContiguous = OMX_FALSE;
725     pRockchipInputPort->portDefinition.nBufferAlignment = 0;
726     pRockchipInputPort->markType.hMarkTargetComponent = NULL;
727     pRockchipInputPort->markType.pMarkData = NULL;
728     pRockchipInputPort->exceptionFlag = GENERAL_STATE;
729 
730     /* Output Port */
731     pRockchipOutputPort = &pRockchipPort[OUTPUT_PORT_INDEX];
732      /* For in case of "Output Buffer Share", MAX ELEMENTS(DPB + EDPB) */
733     Rockchip_OSAL_QueueCreate(&pRockchipOutputPort->bufferQ, MAX_QUEUE_ELEMENTS);
734 
735     pRockchipOutputPort->extendBufferHeader =
736         Rockchip_OSAL_Malloc(sizeof(ROCKCHIP_OMX_BUFFERHEADERTYPE) * MAX_BUFFER_NUM);
737     if (pRockchipOutputPort->extendBufferHeader == NULL) {
738         Rockchip_OSAL_SemaphoreTerminate(pRockchipInputPort->unloadedResource);
739         pRockchipInputPort->unloadedResource = NULL;
740         Rockchip_OSAL_SemaphoreTerminate(pRockchipInputPort->loadedResource);
741         pRockchipInputPort->loadedResource = NULL;
742         Rockchip_OSAL_Free(pRockchipInputPort->bufferStateAllocate);
743         pRockchipInputPort->bufferStateAllocate = NULL;
744         Rockchip_OSAL_Free(pRockchipInputPort->extendBufferHeader);
745         pRockchipInputPort->extendBufferHeader = NULL;
746         Rockchip_OSAL_Free(pRockchipPort);
747         pRockchipPort = NULL;
748         ret = OMX_ErrorInsufficientResources;
749         goto EXIT;
750     }
751     Rockchip_OSAL_Memset(pRockchipOutputPort->extendBufferHeader, 0,
752         sizeof(ROCKCHIP_OMX_BUFFERHEADERTYPE) * MAX_BUFFER_NUM);
753 
754     pRockchipOutputPort->bufferStateAllocate = Rockchip_OSAL_Malloc(sizeof(OMX_U32) * MAX_BUFFER_NUM);
755     if (pRockchipOutputPort->bufferStateAllocate == NULL) {
756         Rockchip_OSAL_Free(pRockchipOutputPort->extendBufferHeader);
757         pRockchipOutputPort->extendBufferHeader = NULL;
758 
759         Rockchip_OSAL_SemaphoreTerminate(pRockchipInputPort->unloadedResource);
760         pRockchipInputPort->unloadedResource = NULL;
761         Rockchip_OSAL_SemaphoreTerminate(pRockchipInputPort->loadedResource);
762         pRockchipInputPort->loadedResource = NULL;
763         Rockchip_OSAL_Free(pRockchipInputPort->bufferStateAllocate);
764         pRockchipInputPort->bufferStateAllocate = NULL;
765         Rockchip_OSAL_Free(pRockchipInputPort->extendBufferHeader);
766         pRockchipInputPort->extendBufferHeader = NULL;
767         Rockchip_OSAL_Free(pRockchipPort);
768         pRockchipPort = NULL;
769         ret = OMX_ErrorInsufficientResources;
770         goto EXIT;
771     }
772     Rockchip_OSAL_Memset(pRockchipOutputPort->bufferStateAllocate, 0, sizeof(OMX_U32) * MAX_BUFFER_NUM);
773 
774     pRockchipOutputPort->bufferSemID = NULL;
775     pRockchipOutputPort->assignedBufferNum = 0;
776     pRockchipOutputPort->portState = OMX_StateMax;
777     pRockchipOutputPort->bIsPortFlushed = OMX_FALSE;
778     pRockchipOutputPort->bIsPortDisabled = OMX_FALSE;
779     pRockchipOutputPort->tunneledComponent = NULL;
780     pRockchipOutputPort->tunneledPort = 0;
781     pRockchipOutputPort->tunnelBufferNum = 0;
782     pRockchipOutputPort->bufferSupplier = OMX_BufferSupplyUnspecified;
783     pRockchipOutputPort->tunnelFlags = 0;
784     ret = Rockchip_OSAL_SemaphoreCreate(&pRockchipOutputPort->loadedResource);
785     if (ret != OMX_ErrorNone) {
786         Rockchip_OSAL_Free(pRockchipOutputPort->bufferStateAllocate);
787         pRockchipOutputPort->bufferStateAllocate = NULL;
788         Rockchip_OSAL_Free(pRockchipOutputPort->extendBufferHeader);
789         pRockchipOutputPort->extendBufferHeader = NULL;
790 
791         Rockchip_OSAL_SemaphoreTerminate(pRockchipInputPort->unloadedResource);
792         pRockchipInputPort->unloadedResource = NULL;
793         Rockchip_OSAL_SemaphoreTerminate(pRockchipInputPort->loadedResource);
794         pRockchipInputPort->loadedResource = NULL;
795         Rockchip_OSAL_Free(pRockchipInputPort->bufferStateAllocate);
796         pRockchipInputPort->bufferStateAllocate = NULL;
797         Rockchip_OSAL_Free(pRockchipInputPort->extendBufferHeader);
798         pRockchipInputPort->extendBufferHeader = NULL;
799         Rockchip_OSAL_Free(pRockchipPort);
800         pRockchipPort = NULL;
801         goto EXIT;
802     }
803     ret = Rockchip_OSAL_SemaphoreCreate(&pRockchipOutputPort->unloadedResource);
804     if (ret != OMX_ErrorNone) {
805         Rockchip_OSAL_SemaphoreTerminate(pRockchipOutputPort->loadedResource);
806         pRockchipOutputPort->loadedResource = NULL;
807         Rockchip_OSAL_Free(pRockchipOutputPort->bufferStateAllocate);
808         pRockchipOutputPort->bufferStateAllocate = NULL;
809         Rockchip_OSAL_Free(pRockchipOutputPort->extendBufferHeader);
810         pRockchipOutputPort->extendBufferHeader = NULL;
811 
812         Rockchip_OSAL_SemaphoreTerminate(pRockchipInputPort->unloadedResource);
813         pRockchipInputPort->unloadedResource = NULL;
814         Rockchip_OSAL_SemaphoreTerminate(pRockchipInputPort->loadedResource);
815         pRockchipInputPort->loadedResource = NULL;
816         Rockchip_OSAL_Free(pRockchipInputPort->bufferStateAllocate);
817         pRockchipInputPort->bufferStateAllocate = NULL;
818         Rockchip_OSAL_Free(pRockchipInputPort->extendBufferHeader);
819         pRockchipInputPort->extendBufferHeader = NULL;
820         Rockchip_OSAL_Free(pRockchipPort);
821         pRockchipPort = NULL;
822         goto EXIT;
823     }
824 
825     INIT_SET_SIZE_VERSION(&pRockchipOutputPort->portDefinition, OMX_PARAM_PORTDEFINITIONTYPE);
826     pRockchipOutputPort->portDefinition.nPortIndex = OUTPUT_PORT_INDEX;
827     pRockchipOutputPort->portDefinition.eDir = OMX_DirOutput;
828     pRockchipOutputPort->portDefinition.nBufferCountActual = 0;
829     pRockchipOutputPort->portDefinition.nBufferCountMin = 0;
830     pRockchipOutputPort->portDefinition.nBufferSize = 0;
831     pRockchipOutputPort->portDefinition.bEnabled = OMX_FALSE;
832 
833     pRockchipOutputPort->portDefinition.bPopulated = OMX_FALSE;
834     pRockchipOutputPort->portDefinition.eDomain = OMX_PortDomainMax;
835     pRockchipOutputPort->portDefinition.bBuffersContiguous = OMX_FALSE;
836     pRockchipOutputPort->portDefinition.nBufferAlignment = 0;
837     pRockchipOutputPort->markType.hMarkTargetComponent = NULL;
838     pRockchipOutputPort->markType.pMarkData = NULL;
839     pRockchipOutputPort->exceptionFlag = GENERAL_STATE;
840 
841     pRockchipComponent->checkTimeStamp.needSetStartTimeStamp = OMX_FALSE;
842     pRockchipComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_FALSE;
843     pRockchipComponent->checkTimeStamp.startTimeStamp = 0;
844     pRockchipComponent->checkTimeStamp.nStartFlags = 0x0;
845 
846     pOMXComponent->EmptyThisBuffer = &Rockchip_OMX_EmptyThisBuffer;
847     pOMXComponent->FillThisBuffer  = &Rockchip_OMX_FillThisBuffer;
848 
849     ret = OMX_ErrorNone;
850 EXIT:
851     FunctionOut();
852 
853     return ret;
854 }
855 
Rockchip_OMX_Port_Destructor(OMX_HANDLETYPE hComponent)856 OMX_ERRORTYPE Rockchip_OMX_Port_Destructor(OMX_HANDLETYPE hComponent)
857 {
858     OMX_ERRORTYPE             ret = OMX_ErrorNone;
859     OMX_COMPONENTTYPE        *pOMXComponent = NULL;
860     ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
861     ROCKCHIP_OMX_BASEPORT      *pRockchipPort = NULL;
862     int i = 0;
863 
864     FunctionIn();
865 
866     if (hComponent == NULL) {
867         ret = OMX_ErrorBadParameter;
868         goto EXIT;
869     }
870     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
871     ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
872     if (ret != OMX_ErrorNone) {
873         goto EXIT;
874     }
875     if (pOMXComponent->pComponentPrivate == NULL) {
876         ret = OMX_ErrorBadParameter;
877         goto EXIT;
878     }
879     pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
880 
881     if (pRockchipComponent->transientState == ROCKCHIP_OMX_TransStateLoadedToIdle) {
882         pRockchipComponent->abendState = OMX_TRUE;
883         for (i = 0; i < ALL_PORT_NUM; i++) {
884             pRockchipPort = &pRockchipComponent->pRockchipPort[i];
885             Rockchip_OSAL_SemaphorePost(pRockchipPort->loadedResource);
886         }
887         Rockchip_OSAL_SignalWait(pRockchipComponent->abendStateEvent, DEF_MAX_WAIT_TIME);
888         Rockchip_OSAL_SignalReset(pRockchipComponent->abendStateEvent);
889     }
890 
891     for (i = 0; i < ALL_PORT_NUM; i++) {
892         pRockchipPort = &pRockchipComponent->pRockchipPort[i];
893 
894         Rockchip_OSAL_SemaphoreTerminate(pRockchipPort->loadedResource);
895         pRockchipPort->loadedResource = NULL;
896         Rockchip_OSAL_SemaphoreTerminate(pRockchipPort->unloadedResource);
897         pRockchipPort->unloadedResource = NULL;
898         Rockchip_OSAL_Free(pRockchipPort->bufferStateAllocate);
899         pRockchipPort->bufferStateAllocate = NULL;
900         Rockchip_OSAL_Free(pRockchipPort->extendBufferHeader);
901         pRockchipPort->extendBufferHeader = NULL;
902 
903         Rockchip_OSAL_QueueTerminate(&pRockchipPort->bufferQ);
904         Rockchip_OSAL_QueueTerminate(&pRockchipPort->securebufferQ);
905     }
906     Rockchip_OSAL_Free(pRockchipComponent->pRockchipPort);
907     pRockchipComponent->pRockchipPort = NULL;
908     ret = OMX_ErrorNone;
909 EXIT:
910     FunctionOut();
911 
912     return ret;
913 }
914 
Rockchip_ResetDataBuffer(ROCKCHIP_OMX_DATABUFFER * pDataBuffer)915 OMX_ERRORTYPE Rockchip_ResetDataBuffer(ROCKCHIP_OMX_DATABUFFER *pDataBuffer)
916 {
917     OMX_ERRORTYPE ret = OMX_ErrorNone;
918 
919     if (pDataBuffer == NULL) {
920         ret = OMX_ErrorBadParameter;
921         goto EXIT;
922     }
923 
924     pDataBuffer->dataValid     = OMX_FALSE;
925     pDataBuffer->dataLen       = 0;
926     pDataBuffer->remainDataLen = 0;
927     pDataBuffer->usedDataLen   = 0;
928     pDataBuffer->bufferHeader  = NULL;
929     pDataBuffer->nFlags        = 0;
930     pDataBuffer->timeStamp     = 0;
931     pDataBuffer->pPrivate      = NULL;
932 
933 EXIT:
934     return ret;
935 }
936 
Rockchip_ResetCodecData(ROCKCHIP_OMX_DATA * pData)937 OMX_ERRORTYPE Rockchip_ResetCodecData(ROCKCHIP_OMX_DATA *pData)
938 {
939     OMX_ERRORTYPE ret = OMX_ErrorNone;
940 
941     if (pData == NULL) {
942         ret = OMX_ErrorBadParameter;
943         goto EXIT;
944     }
945 
946     pData->dataLen       = 0;
947     pData->usedDataLen   = 0;
948     pData->remainDataLen = 0;
949     pData->nFlags        = 0;
950     pData->timeStamp     = 0;
951     pData->pPrivate      = NULL;
952     pData->bufferHeader  = NULL;
953     pData->allocSize     = 0;
954 
955 EXIT:
956     return ret;
957 }
958 
Rockchip_Shared_BufferToData(ROCKCHIP_OMX_DATABUFFER * pUseBuffer,ROCKCHIP_OMX_DATA * pData,ROCKCHIP_OMX_PLANE nPlane)959 OMX_ERRORTYPE Rockchip_Shared_BufferToData(
960     ROCKCHIP_OMX_DATABUFFER *pUseBuffer,
961     ROCKCHIP_OMX_DATA *pData,
962     ROCKCHIP_OMX_PLANE nPlane)
963 {
964     OMX_ERRORTYPE ret = OMX_ErrorNone;
965 
966     if (nPlane == ONE_PLANE) {
967         /* Case of Shared Buffer, Only support singlePlaneBuffer */
968         pData->buffer.singlePlaneBuffer.dataBuffer = pUseBuffer->bufferHeader->pBuffer;
969     } else {
970         omx_err("Can not support plane");
971         ret = OMX_ErrorNotImplemented;
972         goto EXIT;
973     }
974 
975     pData->allocSize     = pUseBuffer->allocSize;
976     pData->dataLen       = pUseBuffer->dataLen;
977     pData->usedDataLen   = pUseBuffer->usedDataLen;
978     pData->remainDataLen = pUseBuffer->remainDataLen;
979     pData->timeStamp     = pUseBuffer->timeStamp;
980     pData->nFlags        = pUseBuffer->nFlags;
981     pData->pPrivate      = pUseBuffer->pPrivate;
982     pData->bufferHeader  = pUseBuffer->bufferHeader;
983 
984 EXIT:
985     return ret;
986 }
987 
Rockchip_Shared_DataToBuffer(ROCKCHIP_OMX_DATA * pData,ROCKCHIP_OMX_DATABUFFER * pUseBuffer)988 OMX_ERRORTYPE Rockchip_Shared_DataToBuffer(ROCKCHIP_OMX_DATA *pData, ROCKCHIP_OMX_DATABUFFER *pUseBuffer)
989 {
990     OMX_ERRORTYPE ret = OMX_ErrorNone;
991 
992     pUseBuffer->bufferHeader          = pData->bufferHeader;
993     pUseBuffer->allocSize             = pData->allocSize;
994     pUseBuffer->dataLen               = pData->dataLen;
995     pUseBuffer->usedDataLen           = pData->usedDataLen;
996     pUseBuffer->remainDataLen         = pData->remainDataLen;
997     pUseBuffer->timeStamp             = pData->timeStamp;
998     pUseBuffer->nFlags                = pData->nFlags;
999     pUseBuffer->pPrivate              = pData->pPrivate;
1000 
1001     return ret;
1002 }