Changed sources for compiling
[platform/adaptation/ap_samsung/libomxil-e3250-v4l2.git] / openmax / component / video / dec / Exynos_OMX_VdecControl.c
1 /*
2  *
3  * Copyright 2012 Samsung Electronics S.LSI 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        Exynos_OMX_VdecControl.c
20  * @brief
21  * @author      SeungBeom Kim (sbcrux.kim@samsung.com)
22  * @version     2.0.0
23  * @history
24  *   2012.02.20 : Create
25  */
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <mm_types.h>
31 #include "Exynos_OMX_Macros.h"
32 #include "Exynos_OSAL_Event.h"
33 #include "Exynos_OMX_Vdec.h"
34 #include "Exynos_OMX_VdecControl.h"
35 #include "Exynos_OMX_Basecomponent.h"
36 #include "Exynos_OSAL_Thread.h"
37 #include "Exynos_OSAL_Semaphore.h"
38 #include "Exynos_OSAL_Mutex.h"
39 #include "Exynos_OSAL_ETC.h"
40 #include "Exynos_OSAL_SharedMemory.h"
41
42 #ifdef USE_PB
43 #include "Exynos_OSAL_Platform_Specific.h"
44 #endif
45
46 #include "ExynosVideoApi.h"
47
48 #undef  EXYNOS_LOG_TAG
49 #define EXYNOS_LOG_TAG    "EXYNOS_VIDEO_DECCONTROL"
50 #define EXYNOS_LOG_OFF
51 //#define EXYNOS_TRACE_ON
52 #include "Exynos_OSAL_Log.h"
53
54
55 OMX_ERRORTYPE Exynos_OMX_UseBuffer(
56     OMX_IN OMX_HANDLETYPE            hComponent,
57     OMX_INOUT OMX_BUFFERHEADERTYPE **ppBufferHdr,
58     OMX_IN OMX_U32                   nPortIndex,
59     OMX_IN OMX_PTR                   pAppPrivate,
60     OMX_IN OMX_U32                   nSizeBytes,
61     OMX_IN OMX_U8                   *pBuffer)
62 {
63     OMX_ERRORTYPE          ret = OMX_ErrorNone;
64     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
65     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
66     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
67     EXYNOS_OMX_BASEPORT      *pExynosPort = NULL;
68     OMX_BUFFERHEADERTYPE  *temp_bufferHeader = NULL;
69     OMX_U32                i = 0;
70
71     FunctionIn();
72
73     if (hComponent == NULL) {
74         ret = OMX_ErrorBadParameter;
75         goto EXIT;
76     }
77     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
78     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
79     if (ret != OMX_ErrorNone) {
80         goto EXIT;
81     }
82
83     if (pOMXComponent->pComponentPrivate == NULL) {
84         ret = OMX_ErrorBadParameter;
85         goto EXIT;
86     }
87     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
88     pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
89
90     pExynosPort = &pExynosComponent->pExynosPort[nPortIndex];
91     if (nPortIndex >= pExynosComponent->portParam.nPorts) {
92         ret = OMX_ErrorBadPortIndex;
93         goto EXIT;
94     }
95     if (pExynosPort->portState != OMX_StateIdle) {
96         ret = OMX_ErrorIncorrectStateOperation;
97         goto EXIT;
98     }
99
100     if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
101         ret = OMX_ErrorBadPortIndex;
102         goto EXIT;
103     }
104
105     temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE));
106     if (temp_bufferHeader == NULL) {
107         ret = OMX_ErrorInsufficientResources;
108         goto EXIT;
109     }
110     Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
111
112     for (i = 0; i < pExynosPort->portDefinition.nBufferCountActual; i++) {
113         if (pExynosPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) {
114             pExynosPort->extendBufferHeader[i].OMXBufferHeader = temp_bufferHeader;
115             pExynosPort->bufferStateAllocate[i] = (BUFFER_STATE_ASSIGNED | HEADER_STATE_ALLOCATED);
116             INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE);
117             temp_bufferHeader->pBuffer        = pBuffer;
118             temp_bufferHeader->nAllocLen      = nSizeBytes;
119             temp_bufferHeader->pAppPrivate    = pAppPrivate;
120             if (nPortIndex == INPUT_PORT_INDEX)
121                 temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX;
122             else
123                 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX;
124 #ifdef SLP_PLATFORM
125             if (nPortIndex == OUTPUT_PORT_INDEX) {
126                 MMVideoBuffer * pSlpOutBuf = (MMVideoBuffer *)pBuffer;
127
128                 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "fd[0] =%d, fd[1] =%d, vaddr[0] =%p, vaddr[1] = %p, y_size=%d, uv_size=%d\n",
129                         pSlpOutBuf->handle.dmabuf_fd[0], pSlpOutBuf->handle.dmabuf_fd[1], pSlpOutBuf->data[0], pSlpOutBuf->data[1],
130                         pSlpOutBuf->size[0],pSlpOutBuf->size[1]);
131
132                 pExynosPort->extendBufferHeader[i].buf_fd[0] = pSlpOutBuf->handle.dmabuf_fd[0];
133                 pExynosPort->extendBufferHeader[i].buf_fd[1] = pSlpOutBuf->handle.dmabuf_fd[1];
134                 pExynosPort->extendBufferHeader[i].buf_fd[2] = 0;
135
136                 pExynosPort->extendBufferHeader[i].pYUVBuf[0] = pSlpOutBuf->data[0];
137                 pExynosPort->extendBufferHeader[i].pYUVBuf[1] = pSlpOutBuf->data[1];
138                 pExynosPort->extendBufferHeader[i].pYUVBuf[2] = NULL;
139
140                 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "PlatformBuffer: buf %d pYUVBuf[0]:0x%x , pYUVBuf[1]:0x%x ",
141                     i, pExynosPort->extendBufferHeader[i].pYUVBuf[0], pExynosPort->extendBufferHeader[i].pYUVBuf[1]);
142             } else if ((pVideoDec->bDRMPlayerMode == OMX_TRUE) && (nPortIndex == INPUT_PORT_INDEX)) {
143                 pExynosPort->extendBufferHeader[i].buf_fd[0] = pBuffer;
144             } else if(nPortIndex == INPUT_PORT_INDEX){
145                 MMVideoBuffer * pSlpOutBuf = (MMVideoBuffer *)pBuffer;
146                 temp_bufferHeader->pBuffer  = pSlpOutBuf->data[0];
147 #if 0
148                 pExynosPort->extendBufferHeader[i].buf_fd[0] = pBuffer;
149                 SCMN_IMGB * pSlpOutBuf = (SCMN_IMGB *)pBuffer;
150                 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "fd[0] =%d, vaddr[0] =%p, , length=%d",
151                         pSlpOutBuf->fd[0], pSlpOutBuf->a[0], nSizeBytes);
152
153                 pExynosPort->extendBufferHeader[i].buf_fd[0] = pSlpOutBuf->fd[0];
154                 pExynosPort->extendBufferHeader[i].buf_fd[1] = 0;
155                 pExynosPort->extendBufferHeader[i].buf_fd[2] = 0;
156
157                 pExynosPort->extendBufferHeader[i].pYUVBuf[0] = pSlpOutBuf->a[0];
158                 pExynosPort->extendBufferHeader[i].pYUVBuf[1] = NULL;
159                 pExynosPort->extendBufferHeader[i].pYUVBuf[2] = NULL;
160
161                 temp_bufferHeader->pBuffer = pSlpOutBuf->a[0];
162 #endif
163             }
164 #endif
165             *ppBufferHdr = temp_bufferHeader;
166             pExynosPort->assignedBufferNum++;
167             if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) {
168                 pExynosPort->portDefinition.bPopulated = OMX_TRUE;
169                 /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */
170                 Exynos_OSAL_SemaphorePost(pExynosPort->loadedResource);
171                 /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */
172             }
173             ret = OMX_ErrorNone;
174             goto EXIT;
175         }
176     }
177
178     Exynos_OSAL_Free(temp_bufferHeader);
179     ret = OMX_ErrorInsufficientResources;
180
181 EXIT:
182     FunctionOut();
183
184     return ret;
185 }
186
187 OMX_ERRORTYPE Exynos_OMX_AllocateBuffer(
188     OMX_IN OMX_HANDLETYPE            hComponent,
189     OMX_INOUT OMX_BUFFERHEADERTYPE **ppBuffer,
190     OMX_IN OMX_U32                   nPortIndex,
191     OMX_IN OMX_PTR                   pAppPrivate,
192     OMX_IN OMX_U32                   nSizeBytes)
193 {
194     OMX_ERRORTYPE          ret = OMX_ErrorNone;
195     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
196     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
197     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
198     EXYNOS_OMX_BASEPORT      *pExynosPort = NULL;
199     OMX_BUFFERHEADERTYPE  *temp_bufferHeader = NULL;
200     OMX_U8                *temp_buffer = NULL;
201     int                    temp_buffer_fd = -1;
202     OMX_U32                i = 0;
203     MEMORY_TYPE            mem_type;
204
205     FunctionIn();
206
207     if (hComponent == NULL) {
208         ret = OMX_ErrorBadParameter;
209         goto EXIT;
210     }
211     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
212     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
213     if (ret != OMX_ErrorNone) {
214         goto EXIT;
215     }
216
217     if (pOMXComponent->pComponentPrivate == NULL) {
218         ret = OMX_ErrorBadParameter;
219         goto EXIT;
220     }
221     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
222     pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
223
224     pExynosPort = &pExynosComponent->pExynosPort[nPortIndex];
225     if (nPortIndex >= pExynosComponent->portParam.nPorts) {
226         ret = OMX_ErrorBadPortIndex;
227         goto EXIT;
228     }
229 /*
230     if (pExynosPort->portState != OMX_StateIdle ) {
231         ret = OMX_ErrorIncorrectStateOperation;
232         goto EXIT;
233     }
234 */
235     if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
236         ret = OMX_ErrorBadPortIndex;
237         goto EXIT;
238     }
239
240     if ((pVideoDec->bDRMPlayerMode == OMX_TRUE) && (nPortIndex == INPUT_PORT_INDEX)) {
241         mem_type = SECURE_MEMORY;
242     } else if (pExynosPort->bufferProcessType & BUFFER_SHARE) {
243         mem_type = NORMAL_MEMORY;
244     } else {
245         mem_type = SYSTEM_MEMORY;
246         }
247     temp_buffer = Exynos_OSAL_SharedMemory_Alloc(pVideoDec->hSharedMemory, nSizeBytes, mem_type);
248         if (temp_buffer == NULL) {
249             ret = OMX_ErrorInsufficientResources;
250             goto EXIT;
251         }
252     temp_buffer_fd = Exynos_OSAL_SharedMemory_VirtToION(pVideoDec->hSharedMemory, temp_buffer);
253
254     temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE));
255     if (temp_bufferHeader == NULL) {
256             Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, temp_buffer);
257         ret = OMX_ErrorInsufficientResources;
258         goto EXIT;
259     }
260     Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
261
262     for (i = 0; i < pExynosPort->portDefinition.nBufferCountActual; i++) {
263         if (pExynosPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) {
264             pExynosPort->extendBufferHeader[i].OMXBufferHeader = temp_bufferHeader;
265             pExynosPort->extendBufferHeader[i].buf_fd[0] = temp_buffer_fd;
266             pExynosPort->bufferStateAllocate[i] = (BUFFER_STATE_ALLOCATED | HEADER_STATE_ALLOCATED);
267             INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE);
268             if (mem_type == SECURE_MEMORY)
269                 temp_bufferHeader->pBuffer = temp_buffer_fd;
270             else
271                 temp_bufferHeader->pBuffer        = temp_buffer;
272             temp_bufferHeader->nAllocLen      = nSizeBytes;
273             temp_bufferHeader->pAppPrivate    = pAppPrivate;
274             if (nPortIndex == INPUT_PORT_INDEX)
275                 temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX;
276             else
277                 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX;
278             pExynosPort->assignedBufferNum++;
279             if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) {
280                 pExynosPort->portDefinition.bPopulated = OMX_TRUE;
281                 /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */
282                 Exynos_OSAL_SemaphorePost(pExynosPort->loadedResource);
283                 /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */
284             }
285             *ppBuffer = temp_bufferHeader;
286             ret = OMX_ErrorNone;
287             goto EXIT;
288         }
289     }
290
291     Exynos_OSAL_Free(temp_bufferHeader);
292         Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, temp_buffer);
293
294     ret = OMX_ErrorInsufficientResources;
295
296 EXIT:
297     FunctionOut();
298
299     return ret;
300 }
301
302 OMX_ERRORTYPE Exynos_OMX_FreeBuffer(
303     OMX_IN OMX_HANDLETYPE hComponent,
304     OMX_IN OMX_U32        nPortIndex,
305     OMX_IN OMX_BUFFERHEADERTYPE *pBufferHdr)
306 {
307     OMX_ERRORTYPE          ret = OMX_ErrorNone;
308     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
309     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
310     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
311     EXYNOS_OMX_BASEPORT      *pExynosPort = NULL;
312     OMX_BUFFERHEADERTYPE  *temp_bufferHeader = NULL;
313     OMX_U8                *temp_buffer = NULL;
314     OMX_U32                i = 0;
315
316     FunctionIn();
317
318     if (hComponent == NULL) {
319         ret = OMX_ErrorBadParameter;
320         goto EXIT;
321     }
322     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
323     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
324     if (ret != OMX_ErrorNone) {
325         goto EXIT;
326     }
327
328     if (pOMXComponent->pComponentPrivate == NULL) {
329         ret = OMX_ErrorBadParameter;
330         goto EXIT;
331     }
332     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
333     pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
334     pExynosPort = &pExynosComponent->pExynosPort[nPortIndex];
335
336     if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
337         ret = OMX_ErrorBadPortIndex;
338         goto EXIT;
339     }
340
341     if ((pExynosPort->portState != OMX_StateLoaded) && (pExynosPort->portState != OMX_StateInvalid)) {
342         (*(pExynosComponent->pCallbacks->EventHandler)) (pOMXComponent,
343                         pExynosComponent->callbackData,
344                         (OMX_U32)OMX_EventError,
345                         (OMX_U32)OMX_ErrorPortUnpopulated,
346                         nPortIndex, NULL);
347     }
348
349     for (i = 0; i < /*pExynosPort->portDefinition.nBufferCountActual*/MAX_BUFFER_NUM; i++) {
350         if (((pExynosPort->bufferStateAllocate[i] | BUFFER_STATE_FREE) != 0) && (pExynosPort->extendBufferHeader[i].OMXBufferHeader != NULL)) {
351             if (pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer == pBufferHdr->pBuffer) {
352                 if (pExynosPort->bufferStateAllocate[i] & BUFFER_STATE_ALLOCATED) {
353                     if ((pVideoDec->bDRMPlayerMode == OMX_TRUE) && (nPortIndex == INPUT_PORT_INDEX)) {
354                         OMX_PTR mapBuffer = Exynos_OSAL_SharedMemory_IONToVirt(pVideoDec->hSharedMemory, (int)pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer);
355                         Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, mapBuffer);
356                     } else {
357                         Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer);
358                     }
359                     pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer = NULL;
360                     pBufferHdr->pBuffer = NULL;
361                 } else if (pExynosPort->bufferStateAllocate[i] & BUFFER_STATE_ASSIGNED) {
362                     ; /* None*/
363                 }
364                 pExynosPort->assignedBufferNum--;
365                 if (pExynosPort->bufferStateAllocate[i] & HEADER_STATE_ALLOCATED) {
366                     Exynos_OSAL_Free(pExynosPort->extendBufferHeader[i].OMXBufferHeader);
367                     pExynosPort->extendBufferHeader[i].OMXBufferHeader = NULL;
368                     pBufferHdr = NULL;
369                 }
370                 pExynosPort->bufferStateAllocate[i] = BUFFER_STATE_FREE;
371                 ret = OMX_ErrorNone;
372                 goto EXIT;
373             }
374         }
375     }
376
377 EXIT:
378     if (ret == OMX_ErrorNone) {
379         if (pExynosPort->assignedBufferNum == 0) {
380             Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pExynosPort->unloadedResource signal set");
381             /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */
382             Exynos_OSAL_SemaphorePost(pExynosPort->unloadedResource);
383             /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */
384             pExynosPort->portDefinition.bPopulated = OMX_FALSE;
385         }
386     }
387
388     FunctionOut();
389
390     return ret;
391 }
392
393 OMX_ERRORTYPE Exynos_OMX_AllocateTunnelBuffer(EXYNOS_OMX_BASEPORT *pOMXBasePort, OMX_U32 nPortIndex)
394 {
395     OMX_ERRORTYPE                 ret = OMX_ErrorNone;
396     EXYNOS_OMX_BASEPORT             *pExynosPort = NULL;
397     OMX_BUFFERHEADERTYPE         *temp_bufferHeader = NULL;
398     OMX_U8                       *temp_buffer = NULL;
399     OMX_U32                       bufferSize = 0;
400     OMX_PARAM_PORTDEFINITIONTYPE  portDefinition;
401
402     ret = OMX_ErrorTunnelingUnsupported;
403 EXIT:
404     return ret;
405 }
406
407 OMX_ERRORTYPE Exynos_OMX_FreeTunnelBuffer(EXYNOS_OMX_BASEPORT *pOMXBasePort, OMX_U32 nPortIndex)
408 {
409     OMX_ERRORTYPE ret = OMX_ErrorNone;
410     EXYNOS_OMX_BASEPORT* pExynosPort = NULL;
411     OMX_BUFFERHEADERTYPE* temp_bufferHeader = NULL;
412     OMX_U8 *temp_buffer = NULL;
413     OMX_U32 bufferSize = 0;
414
415     ret = OMX_ErrorTunnelingUnsupported;
416 EXIT:
417     return ret;
418 }
419
420 OMX_ERRORTYPE Exynos_OMX_ComponentTunnelRequest(
421     OMX_IN OMX_HANDLETYPE hComp,
422     OMX_IN OMX_U32        nPort,
423     OMX_IN OMX_HANDLETYPE hTunneledComp,
424     OMX_IN OMX_U32        nTunneledPort,
425     OMX_INOUT OMX_TUNNELSETUPTYPE *pTunnelSetup)
426 {
427     OMX_ERRORTYPE ret = OMX_ErrorNone;
428
429     ret = OMX_ErrorTunnelingUnsupported;
430 EXIT:
431     return ret;
432 }
433
434 OMX_ERRORTYPE Exynos_OMX_GetFlushBuffer(EXYNOS_OMX_BASEPORT *pExynosPort, EXYNOS_OMX_DATABUFFER *pDataBuffer[])
435 {
436     OMX_ERRORTYPE ret = OMX_ErrorNone;
437
438     FunctionIn();
439
440     *pDataBuffer = NULL;
441
442     if (pExynosPort->portWayType == WAY1_PORT) {
443         *pDataBuffer = &pExynosPort->way.port1WayDataBuffer.dataBuffer;
444     } else if (pExynosPort->portWayType == WAY2_PORT) {
445             pDataBuffer[0] = &(pExynosPort->way.port2WayDataBuffer.inputDataBuffer);
446             pDataBuffer[1] = &(pExynosPort->way.port2WayDataBuffer.outputDataBuffer);
447     }
448
449 EXIT:
450     FunctionOut();
451
452     return ret;
453 }
454
455 OMX_ERRORTYPE Exynos_OMX_FlushPort(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 portIndex)
456 {
457     OMX_ERRORTYPE          ret = OMX_ErrorNone;
458     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
459     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
460     EXYNOS_OMX_BASEPORT      *pExynosPort = NULL;
461     OMX_BUFFERHEADERTYPE     *bufferHeader = NULL;
462     EXYNOS_OMX_DATABUFFER    *pDataPortBuffer[2] = {NULL, NULL};
463     EXYNOS_OMX_MESSAGE       *message = NULL;
464     OMX_U32                flushNum = 0;
465     OMX_S32                semValue = 0;
466     int i = 0, maxBufferNum = 0;
467     FunctionIn();
468 #ifdef SLP_PLATFORM
469     Exynos_OSAL_Log(EXYNOS_LOG_WARNING, "flushPort idx:%d", portIndex);
470 #endif
471
472     pExynosPort = &pExynosComponent->pExynosPort[portIndex];
473
474     while (Exynos_OSAL_GetElemNum(&pExynosPort->bufferQ) > 0) {
475         Exynos_OSAL_Get_SemaphoreCount(pExynosComponent->pExynosPort[portIndex].bufferSemID, &semValue);
476         if (semValue == 0)
477             Exynos_OSAL_SemaphorePost(pExynosComponent->pExynosPort[portIndex].bufferSemID);
478
479         Exynos_OSAL_SemaphoreWait(pExynosComponent->pExynosPort[portIndex].bufferSemID);
480         message = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ);
481         if ((message != NULL) && (message->messageType != EXYNOS_OMX_CommandFakeBuffer)) {
482             bufferHeader = (OMX_BUFFERHEADERTYPE *)message->pCmdData;
483             bufferHeader->nFilledLen = 0;
484
485             if (portIndex == OUTPUT_PORT_INDEX) {
486                 Exynos_OMX_OutputBufferReturn(pOMXComponent, bufferHeader);
487             } else if (portIndex == INPUT_PORT_INDEX) {
488                 Exynos_OMX_InputBufferReturn(pOMXComponent, bufferHeader);
489             }
490         }
491         Exynos_OSAL_Free(message);
492         message = NULL;
493     }
494
495     Exynos_OMX_GetFlushBuffer(pExynosPort, pDataPortBuffer);
496     if (portIndex == INPUT_PORT_INDEX) {
497         if (pDataPortBuffer[0]->dataValid == OMX_TRUE)
498             Exynos_FlushInputBufferReturn(pOMXComponent, pDataPortBuffer[0]);
499         if (pDataPortBuffer[1]->dataValid == OMX_TRUE)
500             Exynos_FlushInputBufferReturn(pOMXComponent, pDataPortBuffer[1]);
501     } else if (portIndex == OUTPUT_PORT_INDEX) {
502         if (pDataPortBuffer[0]->dataValid == OMX_TRUE)
503             Exynos_FlushOutputBufferReturn(pOMXComponent, pDataPortBuffer[0]);
504         if (pDataPortBuffer[1]->dataValid == OMX_TRUE)
505             Exynos_FlushOutputBufferReturn(pOMXComponent, pDataPortBuffer[1]);
506     }
507
508     if (pExynosComponent->bMultiThreadProcess == OMX_TRUE) {
509         if (pExynosPort->bufferProcessType & BUFFER_SHARE) {
510             if (pExynosPort->processData.bufferHeader != NULL) {
511                 if (portIndex == INPUT_PORT_INDEX) {
512                     Exynos_OMX_InputBufferReturn(pOMXComponent, pExynosPort->processData.bufferHeader);
513                 } else if (portIndex == OUTPUT_PORT_INDEX) {
514                     Exynos_OMX_OutputBufferReturn(pOMXComponent, pExynosPort->processData.bufferHeader);
515                 }
516             }
517             Exynos_ResetCodecData(&pExynosPort->processData);
518
519             if (pVideoDec->bDRCProcessing == OMX_TRUE)
520                 maxBufferNum = pVideoDec->nDRCSavedBufferCount;
521             else
522                 maxBufferNum = pExynosPort->portDefinition.nBufferCountActual;
523
524             for (i = 0; i < maxBufferNum; i++) {
525                 if (pExynosPort->extendBufferHeader[i].bBufferInOMX == OMX_TRUE) {
526                     if (portIndex == OUTPUT_PORT_INDEX) {
527                         Exynos_OMX_OutputBufferReturn(pOMXComponent, pExynosPort->extendBufferHeader[i].OMXBufferHeader);
528                     } else if (portIndex == INPUT_PORT_INDEX) {
529                         Exynos_OMX_InputBufferReturn(pOMXComponent, pExynosPort->extendBufferHeader[i].OMXBufferHeader);
530                     }
531                 }
532             }
533         }
534     } else {
535         Exynos_ResetCodecData(&pExynosPort->processData);
536     }
537
538     while(1) {
539         OMX_S32 cnt = 0;
540         Exynos_OSAL_Get_SemaphoreCount(pExynosComponent->pExynosPort[portIndex].bufferSemID, &cnt);
541         if (cnt <= 0)
542             break;
543         Exynos_OSAL_SemaphoreWait(pExynosComponent->pExynosPort[portIndex].bufferSemID);
544     }
545     Exynos_OSAL_ResetQueue(&pExynosPort->bufferQ);
546
547 EXIT:
548     FunctionOut();
549
550     return ret;
551 }
552
553 OMX_ERRORTYPE Exynos_OMX_BufferFlush(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex, OMX_BOOL bEvent)
554 {
555     OMX_ERRORTYPE             ret = OMX_ErrorNone;
556     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
557     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
558     EXYNOS_OMX_BASEPORT      *pExynosPort = NULL;
559     EXYNOS_OMX_DATABUFFER    *flushPortBuffer[2] = {NULL, NULL};
560     OMX_U32                   i = 0, cnt = 0;
561
562     FunctionIn();
563 #ifdef SLP_PLATFORM
564     Exynos_OSAL_Log(EXYNOS_LOG_WARNING, "bufferFlush idx:%d", nPortIndex);
565 #endif
566
567     if (pOMXComponent == NULL) {
568         ret = OMX_ErrorBadParameter;
569         goto EXIT;
570     }
571     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
572     if (ret != OMX_ErrorNone) {
573         goto EXIT;
574     }
575
576     if (pOMXComponent->pComponentPrivate == NULL) {
577         ret = OMX_ErrorBadParameter;
578         goto EXIT;
579     }
580     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
581     pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
582
583     Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"OMX_CommandFlush start, port:%d", nPortIndex);
584
585     pExynosComponent->pExynosPort[nPortIndex].bIsPortFlushed = OMX_TRUE;
586
587     if (pExynosComponent->bMultiThreadProcess == OMX_FALSE) {
588         Exynos_OSAL_SignalSet(pExynosComponent->pauseEvent);
589     } else {
590         Exynos_OSAL_SignalSet(pExynosComponent->pExynosPort[nPortIndex].pauseEvent);
591     }
592
593     pExynosPort = &pExynosComponent->pExynosPort[nPortIndex];
594     Exynos_OMX_GetFlushBuffer(pExynosPort, flushPortBuffer);
595
596     if (pExynosComponent->pExynosPort[nPortIndex].bufferProcessType & BUFFER_COPY)
597         Exynos_OSAL_SemaphorePost(pExynosPort->codecSemID);
598     Exynos_OSAL_SemaphorePost(pExynosPort->bufferSemID);
599
600     pVideoDec->exynos_codec_bufferProcessRun(pOMXComponent, nPortIndex);
601     Exynos_OSAL_MutexLock(flushPortBuffer[0]->bufferMutex);
602     pVideoDec->exynos_codec_stop(pOMXComponent, nPortIndex);
603     Exynos_OSAL_MutexLock(flushPortBuffer[1]->bufferMutex);
604     ret = Exynos_OMX_FlushPort(pOMXComponent, nPortIndex);
605
606     if (pVideoDec->bDRCProcessing == OMX_TRUE) {
607         /* pVideoDec->bDRCProcess == OMX_TRUE
608            the case of dynamic resolution change */
609         pVideoDec->exynos_codec_resetupAllElement(pOMXComponent, nPortIndex);
610     } else if (pExynosComponent->pExynosPort[nPortIndex].bufferProcessType & BUFFER_COPY) {
611         pVideoDec->exynos_codec_enqueueAllBuffer(pOMXComponent, nPortIndex);
612     }
613
614     Exynos_ResetCodecData(&pExynosPort->processData);
615
616     if (ret == OMX_ErrorNone) {
617         if (nPortIndex == INPUT_PORT_INDEX) {
618             pExynosComponent->checkTimeStamp.needSetStartTimeStamp = OMX_TRUE;
619             pExynosComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_FALSE;
620             pExynosComponent->checkTimeStamp.bImmediateDisplay = OMX_FALSE;
621             Exynos_OSAL_Memset(pExynosComponent->timeStamp, -19771003, sizeof(OMX_TICKS) * MAX_TIMESTAMP);
622             Exynos_OSAL_Memset(pExynosComponent->nFlags, 0, sizeof(OMX_U32) * MAX_FLAGS);
623             pExynosComponent->getAllDelayBuffer = OMX_FALSE;
624             pExynosComponent->bSaveFlagEOS = OMX_FALSE;
625             pExynosComponent->reInputData = OMX_FALSE;
626         }
627
628         pExynosComponent->pExynosPort[nPortIndex].bIsPortFlushed = OMX_FALSE;
629         Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"OMX_CommandFlush EventCmdComplete, port:%d", nPortIndex);
630         if (bEvent == OMX_TRUE)
631             pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent,
632                             pExynosComponent->callbackData,
633                             OMX_EventCmdComplete,
634                             OMX_CommandFlush, nPortIndex, NULL);
635     }
636     Exynos_OSAL_MutexUnlock(flushPortBuffer[1]->bufferMutex);
637     Exynos_OSAL_MutexUnlock(flushPortBuffer[0]->bufferMutex);
638
639 EXIT:
640     if ((ret != OMX_ErrorNone) && (pOMXComponent != NULL) && (pExynosComponent != NULL)) {
641         Exynos_OSAL_Log(EXYNOS_LOG_ERROR,"%s : %d", __FUNCTION__, __LINE__);
642         pExynosComponent->pCallbacks->EventHandler(pOMXComponent,
643                         pExynosComponent->callbackData,
644                         OMX_EventError,
645                         ret, 0, NULL);
646     }
647
648     FunctionOut();
649
650     return ret;
651 }
652
653 OMX_ERRORTYPE Exynos_InputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent)
654 {
655     OMX_ERRORTYPE          ret = OMX_ErrorNone;
656     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
657     EXYNOS_OMX_BASEPORT      *exynosOMXInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
658     EXYNOS_OMX_DATABUFFER    *dataBuffer = NULL;
659     OMX_BUFFERHEADERTYPE     *bufferHeader = NULL;
660
661     FunctionIn();
662
663     if (exynosOMXInputPort->bufferProcessType & BUFFER_COPY) {
664         dataBuffer = &(exynosOMXInputPort->way.port2WayDataBuffer.inputDataBuffer);
665     } else if (exynosOMXInputPort->bufferProcessType & BUFFER_SHARE) {
666         dataBuffer = &(exynosOMXInputPort->way.port2WayDataBuffer.outputDataBuffer);
667     }
668
669     bufferHeader = dataBuffer->bufferHeader;
670
671     if (bufferHeader != NULL) {
672         if (exynosOMXInputPort->markType.hMarkTargetComponent != NULL ) {
673             bufferHeader->hMarkTargetComponent      = exynosOMXInputPort->markType.hMarkTargetComponent;
674             bufferHeader->pMarkData                 = exynosOMXInputPort->markType.pMarkData;
675             exynosOMXInputPort->markType.hMarkTargetComponent = NULL;
676             exynosOMXInputPort->markType.pMarkData = NULL;
677         }
678
679         if (bufferHeader->hMarkTargetComponent != NULL) {
680             if (bufferHeader->hMarkTargetComponent == pOMXComponent) {
681                 pExynosComponent->pCallbacks->EventHandler(pOMXComponent,
682                                 pExynosComponent->callbackData,
683                                 OMX_EventMark,
684                                 0, 0, bufferHeader->pMarkData);
685             } else {
686                 pExynosComponent->propagateMarkType.hMarkTargetComponent = bufferHeader->hMarkTargetComponent;
687                 pExynosComponent->propagateMarkType.pMarkData = bufferHeader->pMarkData;
688             }
689         }
690
691         bufferHeader->nFilledLen = 0;
692         bufferHeader->nOffset = 0;
693         Exynos_OMX_InputBufferReturn(pOMXComponent, bufferHeader);
694     }
695
696     /* reset dataBuffer */
697     Exynos_ResetDataBuffer(dataBuffer);
698
699 EXIT:
700     FunctionOut();
701
702     return ret;
703 }
704
705 OMX_ERRORTYPE Exynos_FlushInputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer)
706 {
707     OMX_ERRORTYPE          ret = OMX_ErrorNone;
708     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
709     EXYNOS_OMX_BASEPORT      *exynosOMXInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
710     OMX_BUFFERHEADERTYPE     *bufferHeader = NULL;
711
712     FunctionIn();
713
714     bufferHeader = dataBuffer->bufferHeader;
715
716     if (bufferHeader != NULL) {
717         if (exynosOMXInputPort->markType.hMarkTargetComponent != NULL ) {
718             bufferHeader->hMarkTargetComponent      = exynosOMXInputPort->markType.hMarkTargetComponent;
719             bufferHeader->pMarkData                 = exynosOMXInputPort->markType.pMarkData;
720             exynosOMXInputPort->markType.hMarkTargetComponent = NULL;
721             exynosOMXInputPort->markType.pMarkData = NULL;
722         }
723
724         if (bufferHeader->hMarkTargetComponent != NULL) {
725             if (bufferHeader->hMarkTargetComponent == pOMXComponent) {
726                 pExynosComponent->pCallbacks->EventHandler(pOMXComponent,
727                                 pExynosComponent->callbackData,
728                                 OMX_EventMark,
729                                 0, 0, bufferHeader->pMarkData);
730             } else {
731                 pExynosComponent->propagateMarkType.hMarkTargetComponent = bufferHeader->hMarkTargetComponent;
732                 pExynosComponent->propagateMarkType.pMarkData = bufferHeader->pMarkData;
733             }
734         }
735
736         bufferHeader->nFilledLen = 0;
737         bufferHeader->nOffset = 0;
738         Exynos_OMX_InputBufferReturn(pOMXComponent, bufferHeader);
739     }
740
741     /* reset dataBuffer */
742     Exynos_ResetDataBuffer(dataBuffer);
743
744 EXIT:
745     FunctionOut();
746
747     return ret;
748 }
749
750 OMX_ERRORTYPE Exynos_InputBufferGetQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent)
751 {
752     OMX_ERRORTYPE          ret = OMX_ErrorUndefined;
753     EXYNOS_OMX_BASEPORT   *pExynosPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
754     EXYNOS_OMX_MESSAGE    *message = NULL;
755     EXYNOS_OMX_DATABUFFER *inputUseBuffer = NULL;
756
757     FunctionIn();
758
759     inputUseBuffer = &(pExynosPort->way.port2WayDataBuffer.inputDataBuffer);
760
761     if (pExynosComponent->currentState != OMX_StateExecuting) {
762         ret = OMX_ErrorUndefined;
763         goto EXIT;
764     } else if ((pExynosComponent->transientState != EXYNOS_OMX_TransStateExecutingToIdle) &&
765                (!CHECK_PORT_BEING_FLUSHED(pExynosPort))) {
766         Exynos_OSAL_SemaphoreWait(pExynosPort->bufferSemID);
767         if (inputUseBuffer->dataValid != OMX_TRUE) {
768             message = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ);
769             if (message == NULL) {
770                 ret = OMX_ErrorUndefined;
771                 goto EXIT;
772             }
773             if (message->messageType == EXYNOS_OMX_CommandFakeBuffer) {
774                 Exynos_OSAL_Free(message);
775                 ret = OMX_ErrorCodecFlush;
776                 goto EXIT;
777             }
778
779             inputUseBuffer->bufferHeader  = (OMX_BUFFERHEADERTYPE *)(message->pCmdData);
780             inputUseBuffer->allocSize     = inputUseBuffer->bufferHeader->nAllocLen;
781             inputUseBuffer->dataLen       = inputUseBuffer->bufferHeader->nFilledLen;
782             inputUseBuffer->remainDataLen = inputUseBuffer->dataLen;
783             inputUseBuffer->usedDataLen   = 0;
784             inputUseBuffer->dataValid     = OMX_TRUE;
785             inputUseBuffer->nFlags        = inputUseBuffer->bufferHeader->nFlags;
786             inputUseBuffer->timeStamp     = inputUseBuffer->bufferHeader->nTimeStamp;
787
788             Exynos_OSAL_Free(message);
789
790 #ifndef SLP_PLATFORM
791             if (inputUseBuffer->allocSize <= inputUseBuffer->dataLen)
792                 Exynos_OSAL_Log(EXYNOS_LOG_WARNING, "Input Buffer Full, Check input buffer size! allocSize:%d, dataLen:%d", inputUseBuffer->allocSize, inputUseBuffer->dataLen);
793 #endif
794         }
795         ret = OMX_ErrorNone;
796     }
797 EXIT:
798     FunctionOut();
799
800     return ret;
801 }
802
803 OMX_ERRORTYPE Exynos_OutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent)
804 {
805     OMX_ERRORTYPE          ret = OMX_ErrorNone;
806     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
807     EXYNOS_OMX_BASEPORT      *exynosOMXOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
808     EXYNOS_OMX_DATABUFFER    *dataBuffer = NULL;
809     OMX_BUFFERHEADERTYPE     *bufferHeader = NULL;
810
811     FunctionIn();
812
813     dataBuffer = &(exynosOMXOutputPort->way.port2WayDataBuffer.outputDataBuffer);
814     bufferHeader = dataBuffer->bufferHeader;
815
816     if (bufferHeader != NULL) {
817 #ifdef SLP_PLATFORM
818         bufferHeader->nFilledLen = sizeof(MMVideoBuffer);
819 #else
820         bufferHeader->nFilledLen = dataBuffer->remainDataLen;
821 #endif
822         bufferHeader->nOffset    = 0;
823         bufferHeader->nFlags     = dataBuffer->nFlags;
824         bufferHeader->nTimeStamp = dataBuffer->timeStamp;
825
826         Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"Exynos_OutputBufferReturn: nFilledLen: %d", bufferHeader->nFilledLen);
827         Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"Exynos_OutputBufferReturn: nFlags: %d", bufferHeader->nFlags);
828         Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"Exynos_OutputBufferReturn: nTimeStamp: %lld", bufferHeader->nTimeStamp);
829
830         if (pExynosComponent->propagateMarkType.hMarkTargetComponent != NULL) {
831             bufferHeader->hMarkTargetComponent = pExynosComponent->propagateMarkType.hMarkTargetComponent;
832             bufferHeader->pMarkData = pExynosComponent->propagateMarkType.pMarkData;
833             pExynosComponent->propagateMarkType.hMarkTargetComponent = NULL;
834             pExynosComponent->propagateMarkType.pMarkData = NULL;
835         }
836
837         if ((bufferHeader->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) {
838             bufferHeader->nFilledLen = 0;
839             Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"event OMX_BUFFERFLAG_EOS!!!");
840             pExynosComponent->pCallbacks->EventHandler(pOMXComponent,
841                             pExynosComponent->callbackData,
842                             OMX_EventBufferFlag,
843                             OUTPUT_PORT_INDEX,
844                             bufferHeader->nFlags, NULL);
845         }
846
847         Exynos_OMX_OutputBufferReturn(pOMXComponent, bufferHeader);
848     } else {
849         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d  bufferHeader is NULL! ", __FUNCTION__, __LINE__);
850     }
851
852     /* reset dataBuffer */
853     Exynos_ResetDataBuffer(dataBuffer);
854
855 EXIT:
856     FunctionOut();
857
858     return ret;
859 }
860
861 OMX_ERRORTYPE Exynos_FlushOutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer)
862 {
863     OMX_ERRORTYPE          ret = OMX_ErrorNone;
864     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
865     EXYNOS_OMX_BASEPORT      *exynosOMXOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
866     OMX_BUFFERHEADERTYPE     *bufferHeader = NULL;
867
868     FunctionIn();
869
870     bufferHeader = dataBuffer->bufferHeader;
871
872     if (bufferHeader != NULL) {
873         bufferHeader->nFilledLen = dataBuffer->remainDataLen;
874         bufferHeader->nOffset    = 0;
875         bufferHeader->nFlags     = dataBuffer->nFlags;
876         bufferHeader->nTimeStamp = dataBuffer->timeStamp;
877
878         if (pExynosComponent->propagateMarkType.hMarkTargetComponent != NULL) {
879             bufferHeader->hMarkTargetComponent = pExynosComponent->propagateMarkType.hMarkTargetComponent;
880             bufferHeader->pMarkData = pExynosComponent->propagateMarkType.pMarkData;
881             pExynosComponent->propagateMarkType.hMarkTargetComponent = NULL;
882             pExynosComponent->propagateMarkType.pMarkData = NULL;
883         }
884
885         if ((bufferHeader->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) {
886             bufferHeader->nFilledLen = 0;
887             Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"event OMX_BUFFERFLAG_EOS!!!");
888             pExynosComponent->pCallbacks->EventHandler(pOMXComponent,
889                             pExynosComponent->callbackData,
890                             OMX_EventBufferFlag,
891                             OUTPUT_PORT_INDEX,
892                             bufferHeader->nFlags, NULL);
893         }
894         Exynos_OMX_OutputBufferReturn(pOMXComponent, bufferHeader);
895     }
896
897     /* reset dataBuffer */
898     Exynos_ResetDataBuffer(dataBuffer);
899
900 EXIT:
901     FunctionOut();
902
903     return ret;
904 }
905
906 OMX_ERRORTYPE Exynos_OutputBufferGetQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent)
907 {
908     OMX_ERRORTYPE       ret = OMX_ErrorUndefined;
909     EXYNOS_OMX_BASEPORT   *pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
910     EXYNOS_OMX_MESSAGE    *message = NULL;
911     EXYNOS_OMX_DATABUFFER *outputUseBuffer = NULL;
912
913     FunctionIn();
914
915     if (pExynosPort->bufferProcessType & BUFFER_COPY) {
916         outputUseBuffer = &(pExynosPort->way.port2WayDataBuffer.outputDataBuffer);
917     } else if (pExynosPort->bufferProcessType & BUFFER_SHARE) {
918         outputUseBuffer = &(pExynosPort->way.port2WayDataBuffer.inputDataBuffer);
919     }
920
921     if (pExynosComponent->currentState != OMX_StateExecuting) {
922         ret = OMX_ErrorUndefined;
923         goto EXIT;
924     } else if ((pExynosComponent->transientState != EXYNOS_OMX_TransStateExecutingToIdle) &&
925                (!CHECK_PORT_BEING_FLUSHED(pExynosPort))){
926         Exynos_OSAL_SemaphoreWait(pExynosPort->bufferSemID);
927         if (outputUseBuffer->dataValid != OMX_TRUE) {
928             message = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ);
929             if (message == NULL) {
930                 ret = OMX_ErrorUndefined;
931                 goto EXIT;
932             }
933             if (message->messageType == EXYNOS_OMX_CommandFakeBuffer) {
934                 Exynos_OSAL_Free(message);
935                 ret = OMX_ErrorCodecFlush;
936                 goto EXIT;
937             }
938
939             outputUseBuffer->bufferHeader  = (OMX_BUFFERHEADERTYPE *)(message->pCmdData);
940             outputUseBuffer->allocSize     = outputUseBuffer->bufferHeader->nAllocLen;
941             outputUseBuffer->dataLen       = 0; //dataBuffer->bufferHeader->nFilledLen;
942             outputUseBuffer->remainDataLen = outputUseBuffer->dataLen;
943             outputUseBuffer->usedDataLen   = 0; //dataBuffer->bufferHeader->nOffset;
944             outputUseBuffer->dataValid     = OMX_TRUE;
945             /* dataBuffer->nFlags             = dataBuffer->bufferHeader->nFlags; */
946             /* dataBuffer->nTimeStamp         = dataBuffer->bufferHeader->nTimeStamp; */
947 /*
948             if (pExynosPort->bufferProcessType & BUFFER_SHARE)
949                 outputUseBuffer->pPrivate      = outputUseBuffer->bufferHeader->pOutputPortPrivate;
950             else if (pExynosPort->bufferProcessType & BUFFER_COPY) {
951                 pExynosPort->processData.dataBuffer = outputUseBuffer->bufferHeader->pBuffer;
952                 pExynosPort->processData.allocSize  = outputUseBuffer->bufferHeader->nAllocLen;
953             }
954 */
955
956             Exynos_OSAL_Free(message);
957         }
958         ret = OMX_ErrorNone;
959     }
960 EXIT:
961     FunctionOut();
962
963     return ret;
964
965 }
966
967 OMX_BUFFERHEADERTYPE *Exynos_OutputBufferGetQueue_Direct(EXYNOS_OMX_BASECOMPONENT *pExynosComponent)
968 {
969     OMX_BUFFERHEADERTYPE  *retBuffer = NULL;
970     EXYNOS_OMX_BASEPORT   *pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
971     EXYNOS_OMX_MESSAGE    *message = NULL;
972
973     FunctionIn();
974
975     if (pExynosComponent->currentState != OMX_StateExecuting) {
976         retBuffer = NULL;
977         goto EXIT;
978     } else if ((pExynosComponent->transientState != EXYNOS_OMX_TransStateExecutingToIdle) &&
979                (!CHECK_PORT_BEING_FLUSHED(pExynosPort))){
980         Exynos_OSAL_SemaphoreWait(pExynosPort->bufferSemID);
981
982         message = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ);
983         if (message == NULL) {
984             retBuffer = NULL;
985             goto EXIT;
986         }
987         if (message->messageType == EXYNOS_OMX_CommandFakeBuffer) {
988             Exynos_OSAL_Free(message);
989             retBuffer = NULL;
990             goto EXIT;
991         }
992
993         retBuffer  = (OMX_BUFFERHEADERTYPE *)(message->pCmdData);
994         Exynos_OSAL_Free(message);
995     }
996
997 EXIT:
998     FunctionOut();
999
1000     return retBuffer;
1001 }
1002
1003 OMX_ERRORTYPE Exynos_CodecBufferEnQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 PortIndex, OMX_PTR data)
1004 {
1005     OMX_ERRORTYPE       ret = OMX_ErrorNone;
1006     EXYNOS_OMX_BASEPORT   *pExynosPort = NULL;
1007
1008     FunctionIn();
1009
1010     pExynosPort= &pExynosComponent->pExynosPort[PortIndex];
1011
1012     if (data == NULL) {
1013         ret = OMX_ErrorInsufficientResources;
1014         goto EXIT;
1015     }
1016
1017 #ifdef SLP_PLATFORM
1018     if (pExynosPort == NULL) {
1019         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d: pExynosPort is NULL", __FUNCTION__, __LINE__);
1020     }
1021 #endif
1022
1023     ret = Exynos_OSAL_Queue(&pExynosPort->codecBufferQ, (void *)data);
1024     if (ret != 0) {
1025         ret = OMX_ErrorUndefined;
1026         goto EXIT;
1027     }
1028     Exynos_OSAL_SemaphorePost(pExynosPort->codecSemID);
1029
1030     ret = OMX_ErrorNone;
1031
1032 EXIT:
1033     FunctionOut();
1034
1035     return ret;
1036 }
1037
1038 OMX_ERRORTYPE Exynos_CodecBufferDeQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 PortIndex, OMX_PTR *data)
1039 {
1040     OMX_ERRORTYPE       ret = OMX_ErrorNone;
1041     EXYNOS_OMX_BASEPORT   *pExynosPort = NULL;
1042     OMX_U32 tempData;
1043
1044     FunctionIn();
1045
1046     pExynosPort = &pExynosComponent->pExynosPort[PortIndex];
1047     Exynos_OSAL_SemaphoreWait(pExynosPort->codecSemID);
1048     tempData = (OMX_U32)Exynos_OSAL_Dequeue(&pExynosPort->codecBufferQ);
1049     if (tempData == NULL) {
1050         *data = NULL;
1051         ret = OMX_ErrorUndefined;
1052         goto EXIT;
1053     }
1054     *data = (OMX_PTR)tempData;
1055
1056     ret = OMX_ErrorNone;
1057
1058 EXIT:
1059     FunctionOut();
1060
1061     return ret;
1062 }
1063
1064 OMX_ERRORTYPE Exynos_CodecBufferReset(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 PortIndex)
1065 {
1066     OMX_ERRORTYPE       ret = OMX_ErrorNone;
1067     EXYNOS_OMX_BASEPORT   *pExynosPort = NULL;
1068
1069     FunctionIn();
1070
1071     pExynosPort= &pExynosComponent->pExynosPort[PortIndex];
1072
1073     ret = Exynos_OSAL_ResetQueue(&pExynosPort->codecBufferQ);
1074     if (ret != 0) {
1075         ret = OMX_ErrorUndefined;
1076         goto EXIT;
1077     }
1078     while (1) {
1079         int cnt = 0;
1080         Exynos_OSAL_Get_SemaphoreCount(pExynosPort->codecSemID, &cnt);
1081         if (cnt > 0)
1082             Exynos_OSAL_SemaphoreWait(pExynosPort->codecSemID);
1083         else
1084             break;
1085     }
1086     ret = OMX_ErrorNone;
1087
1088 EXIT:
1089     FunctionOut();
1090
1091     return ret;
1092 }
1093
1094 OMX_ERRORTYPE Exynos_OMX_VideoDecodeGetParameter(
1095     OMX_IN OMX_HANDLETYPE hComponent,
1096     OMX_IN OMX_INDEXTYPE  nParamIndex,
1097     OMX_INOUT OMX_PTR     ComponentParameterStructure)
1098 {
1099     OMX_ERRORTYPE          ret = OMX_ErrorNone;
1100     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
1101     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1102     EXYNOS_OMX_BASEPORT      *pExynosPort = NULL;
1103
1104     FunctionIn();
1105
1106     if (hComponent == NULL) {
1107         ret = OMX_ErrorBadParameter;
1108         goto EXIT;
1109     }
1110     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1111     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1112     if (ret != OMX_ErrorNone) {
1113         goto EXIT;
1114     }
1115
1116     if (pOMXComponent->pComponentPrivate == NULL) {
1117         ret = OMX_ErrorBadParameter;
1118         goto EXIT;
1119     }
1120     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1121
1122     if (pExynosComponent->currentState == OMX_StateInvalid ) {
1123         ret = OMX_ErrorInvalidState;
1124         goto EXIT;
1125     }
1126
1127     if (ComponentParameterStructure == NULL) {
1128         ret = OMX_ErrorBadParameter;
1129         goto EXIT;
1130     }
1131
1132     switch (nParamIndex) {
1133     case OMX_IndexParamVideoInit:
1134     {
1135         OMX_PORT_PARAM_TYPE *portParam = (OMX_PORT_PARAM_TYPE *)ComponentParameterStructure;
1136         ret = Exynos_OMX_Check_SizeVersion(portParam, sizeof(OMX_PORT_PARAM_TYPE));
1137         if (ret != OMX_ErrorNone) {
1138             goto EXIT;
1139         }
1140
1141         portParam->nPorts           = pExynosComponent->portParam.nPorts;
1142         portParam->nStartPortNumber = pExynosComponent->portParam.nStartPortNumber;
1143         ret = OMX_ErrorNone;
1144     }
1145         break;
1146     case OMX_IndexParamVideoPortFormat:
1147     {
1148         OMX_VIDEO_PARAM_PORTFORMATTYPE *portFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)ComponentParameterStructure;
1149         OMX_U32                         portIndex = portFormat->nPortIndex;
1150         OMX_U32                         index    = portFormat->nIndex;
1151         EXYNOS_OMX_BASEPORT               *pExynosPort = NULL;
1152         OMX_PARAM_PORTDEFINITIONTYPE   *portDefinition = NULL;
1153         OMX_U32                         supportFormatNum = 0; /* supportFormatNum = N-1 */
1154
1155         ret = Exynos_OMX_Check_SizeVersion(portFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
1156         if (ret != OMX_ErrorNone) {
1157             goto EXIT;
1158         }
1159
1160         if ((portIndex >= pExynosComponent->portParam.nPorts)) {
1161             ret = OMX_ErrorBadPortIndex;
1162             goto EXIT;
1163         }
1164
1165
1166         if (portIndex == INPUT_PORT_INDEX) {
1167             supportFormatNum = INPUT_PORT_SUPPORTFORMAT_NUM_MAX - 1;
1168             if (index > supportFormatNum) {
1169                 ret = OMX_ErrorNoMore;
1170                 goto EXIT;
1171             }
1172
1173             pExynosPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
1174             portDefinition = &pExynosPort->portDefinition;
1175
1176             portFormat->eCompressionFormat = portDefinition->format.video.eCompressionFormat;
1177             portFormat->eColorFormat       = portDefinition->format.video.eColorFormat;
1178             portFormat->xFramerate           = portDefinition->format.video.xFramerate;
1179         } else if (portIndex == OUTPUT_PORT_INDEX) {
1180             pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
1181             portDefinition = &pExynosPort->portDefinition;
1182
1183             switch (index) {
1184             case supportFormat_0:
1185                 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
1186                 portFormat->eColorFormat       = OMX_COLOR_FormatYUV420Planar;
1187                 portFormat->xFramerate         = portDefinition->format.video.xFramerate;
1188                 break;
1189             case supportFormat_1:
1190                 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
1191                 portFormat->eColorFormat       = OMX_COLOR_FormatYUV420SemiPlanar;
1192                 portFormat->xFramerate         = portDefinition->format.video.xFramerate;
1193                 break;
1194             case supportFormat_2:
1195                 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
1196                 portFormat->eColorFormat       = OMX_SEC_COLOR_FormatNV12Tiled;
1197                 portFormat->xFramerate         = portDefinition->format.video.xFramerate;
1198                 break;
1199 #ifdef SLP_PLATFORM
1200             case supportFormat_3:
1201                 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
1202                 portFormat->eColorFormat       = OMX_SEC_COLOR_FormatNV12T_DmaBuf_Fd;
1203                 portFormat->xFramerate         = portDefinition->format.video.xFramerate;
1204                 break;
1205 #endif
1206             default:
1207                 if (index > supportFormat_0) {
1208                     ret = OMX_ErrorNoMore;
1209                     goto EXIT;
1210                 }
1211                 break;
1212             }
1213         }
1214         ret = OMX_ErrorNone;
1215     }
1216         break;
1217 #ifdef USE_PB
1218     case OMX_IndexParamGetAndroidNativeBuffer:
1219     {
1220         ret = Exynos_OSAL_GetPBParameter(hComponent, nParamIndex, ComponentParameterStructure);
1221     }
1222         break;
1223 #endif
1224     default:
1225     {
1226         ret = Exynos_OMX_GetParameter(hComponent, nParamIndex, ComponentParameterStructure);
1227     }
1228         break;
1229     }
1230
1231 EXIT:
1232     FunctionOut();
1233
1234     return ret;
1235 }
1236 OMX_ERRORTYPE Exynos_OMX_VideoDecodeSetParameter(
1237     OMX_IN OMX_HANDLETYPE hComponent,
1238     OMX_IN OMX_INDEXTYPE  nIndex,
1239     OMX_IN OMX_PTR        ComponentParameterStructure)
1240 {
1241     OMX_ERRORTYPE          ret = OMX_ErrorNone;
1242     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
1243     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1244     EXYNOS_OMX_BASEPORT      *pExynosPort = NULL;
1245
1246     FunctionIn();
1247
1248     if (hComponent == NULL) {
1249         ret = OMX_ErrorBadParameter;
1250         goto EXIT;
1251     }
1252     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1253     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1254     if (ret != OMX_ErrorNone) {
1255         goto EXIT;
1256     }
1257
1258     if (pOMXComponent->pComponentPrivate == NULL) {
1259         ret = OMX_ErrorBadParameter;
1260         goto EXIT;
1261     }
1262     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1263
1264     if (pExynosComponent->currentState == OMX_StateInvalid ) {
1265         ret = OMX_ErrorInvalidState;
1266         goto EXIT;
1267     }
1268
1269     if (ComponentParameterStructure == NULL) {
1270         ret = OMX_ErrorBadParameter;
1271         goto EXIT;
1272     }
1273
1274     switch (nIndex) {
1275     case OMX_IndexParamVideoPortFormat:
1276     {
1277         OMX_VIDEO_PARAM_PORTFORMATTYPE *portFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)ComponentParameterStructure;
1278         OMX_U32                         portIndex = portFormat->nPortIndex;
1279         OMX_U32                         index    = portFormat->nIndex;
1280         EXYNOS_OMX_BASEPORT               *pExynosPort = NULL;
1281         OMX_PARAM_PORTDEFINITIONTYPE   *portDefinition = NULL;
1282         OMX_U32                         supportFormatNum = 0;
1283
1284         ret = Exynos_OMX_Check_SizeVersion(portFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
1285         if (ret != OMX_ErrorNone) {
1286             goto EXIT;
1287         }
1288
1289         if ((portIndex >= pExynosComponent->portParam.nPorts)) {
1290             ret = OMX_ErrorBadPortIndex;
1291             goto EXIT;
1292         } else {
1293             pExynosPort = &pExynosComponent->pExynosPort[portIndex];
1294             portDefinition = &pExynosPort->portDefinition;
1295
1296             portDefinition->format.video.eColorFormat       = portFormat->eColorFormat;
1297             portDefinition->format.video.eCompressionFormat = portFormat->eCompressionFormat;
1298             portDefinition->format.video.xFramerate         = portFormat->xFramerate;
1299         }
1300     }
1301         break;
1302 #ifdef USE_PB
1303 #ifdef SLP_PLATFORM
1304     case OMX_IndexParamEnablePlatformSpecificBuffers:
1305 #else
1306     case OMX_IndexParamEnableAndroidBuffers:
1307 #endif
1308     case OMX_IndexParamUseAndroidNativeBuffer:
1309     {
1310         ret = Exynos_OSAL_SetPBParameter(hComponent, nIndex, ComponentParameterStructure);
1311     }
1312         break;
1313 #endif
1314
1315 #ifdef SLP_PLATFORM
1316     case OMX_IndexParamEnableTimestampReorder:
1317     {
1318         EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
1319         pVideoDec->bNeedTimestampReorder = OMX_TRUE;
1320     }
1321         break;
1322 #endif
1323     default:
1324     {
1325         ret = Exynos_OMX_SetParameter(hComponent, nIndex, ComponentParameterStructure);
1326     }
1327         break;
1328     }
1329
1330 EXIT:
1331     FunctionOut();
1332
1333     return ret;
1334 }
1335
1336 OMX_ERRORTYPE Exynos_OMX_VideoDecodeGetConfig(
1337     OMX_HANDLETYPE hComponent,
1338     OMX_INDEXTYPE nIndex,
1339     OMX_PTR pComponentConfigStructure)
1340 {
1341     OMX_ERRORTYPE          ret = OMX_ErrorNone;
1342     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
1343     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1344
1345     FunctionIn();
1346
1347     if (hComponent == NULL) {
1348         ret = OMX_ErrorBadParameter;
1349         goto EXIT;
1350     }
1351     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1352     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1353     if (ret != OMX_ErrorNone) {
1354         goto EXIT;
1355     }
1356     if (pOMXComponent->pComponentPrivate == NULL) {
1357         ret = OMX_ErrorBadParameter;
1358         goto EXIT;
1359     }
1360     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1361     if (pComponentConfigStructure == NULL) {
1362         ret = OMX_ErrorBadParameter;
1363         goto EXIT;
1364     }
1365     if (pExynosComponent->currentState == OMX_StateInvalid) {
1366         ret = OMX_ErrorInvalidState;
1367         goto EXIT;
1368     }
1369
1370     switch (nIndex) {
1371     default:
1372         ret = Exynos_OMX_GetConfig(hComponent, nIndex, pComponentConfigStructure);
1373         break;
1374     }
1375
1376 EXIT:
1377     FunctionOut();
1378
1379     return ret;
1380 }
1381
1382 OMX_ERRORTYPE Exynos_OMX_VideoDecodeSetConfig(
1383     OMX_HANDLETYPE hComponent,
1384     OMX_INDEXTYPE nIndex,
1385     OMX_PTR pComponentConfigStructure)
1386 {
1387     OMX_ERRORTYPE           ret = OMX_ErrorNone;
1388     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
1389     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1390
1391     FunctionIn();
1392
1393     if (hComponent == NULL) {
1394         ret = OMX_ErrorBadParameter;
1395         goto EXIT;
1396     }
1397     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1398     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1399     if (ret != OMX_ErrorNone) {
1400         goto EXIT;
1401     }
1402     if (pOMXComponent->pComponentPrivate == NULL) {
1403         ret = OMX_ErrorBadParameter;
1404         goto EXIT;
1405     }
1406     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1407     if (pComponentConfigStructure == NULL) {
1408         ret = OMX_ErrorBadParameter;
1409         goto EXIT;
1410     }
1411     if (pExynosComponent->currentState == OMX_StateInvalid) {
1412         ret = OMX_ErrorInvalidState;
1413         goto EXIT;
1414     }
1415
1416     switch (nIndex) {
1417     case OMX_IndexVendorThumbnailMode:
1418     {
1419         EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
1420         pVideoDec->bThumbnailMode = *((OMX_BOOL *)pComponentConfigStructure);
1421
1422         ret = OMX_ErrorNone;
1423     }
1424         break;
1425     default:
1426         ret = Exynos_OMX_SetConfig(hComponent, nIndex, pComponentConfigStructure);
1427         break;
1428     }
1429
1430 EXIT:
1431     FunctionOut();
1432
1433     return ret;
1434 }
1435
1436 OMX_ERRORTYPE Exynos_OMX_VideoDecodeGetExtensionIndex(
1437     OMX_IN OMX_HANDLETYPE  hComponent,
1438     OMX_IN OMX_STRING      cParameterName,
1439     OMX_OUT OMX_INDEXTYPE *pIndexType)
1440 {
1441     OMX_ERRORTYPE           ret = OMX_ErrorNone;
1442     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
1443     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1444
1445     FunctionIn();
1446
1447     if (hComponent == NULL) {
1448         ret = OMX_ErrorBadParameter;
1449         goto EXIT;
1450     }
1451     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1452     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1453     if (ret != OMX_ErrorNone) {
1454         goto EXIT;
1455     }
1456
1457     if (pOMXComponent->pComponentPrivate == NULL) {
1458         ret = OMX_ErrorBadParameter;
1459         goto EXIT;
1460     }
1461     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1462
1463     if ((cParameterName == NULL) || (pIndexType == NULL)) {
1464         ret = OMX_ErrorBadParameter;
1465         goto EXIT;
1466     }
1467     if (pExynosComponent->currentState == OMX_StateInvalid) {
1468         ret = OMX_ErrorInvalidState;
1469         goto EXIT;
1470     }
1471
1472 #ifdef USE_PB
1473 #ifdef SLP_PLATFORM
1474     if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_ENABLE_PB) == 0)
1475         *pIndexType = (OMX_INDEXTYPE) OMX_IndexParamEnablePlatformSpecificBuffers;
1476     else if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_ENABLE_TS_REORDER) == 0)
1477         *pIndexType = (OMX_INDEXTYPE) OMX_IndexParamEnableTimestampReorder;
1478 #else
1479     if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_ENABLE_ANB) == 0)
1480         *pIndexType = (OMX_INDEXTYPE) OMX_IndexParamEnableAndroidBuffers;
1481 #endif
1482     else if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_GET_ANB) == 0)
1483         *pIndexType = (OMX_INDEXTYPE) OMX_IndexParamGetAndroidNativeBuffer;
1484     else if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_USE_ANB) == 0)
1485         *pIndexType = (OMX_INDEXTYPE) OMX_IndexParamUseAndroidNativeBuffer;
1486     else
1487         ret = Exynos_OMX_GetExtensionIndex(hComponent, cParameterName, pIndexType);
1488 #else
1489     ret = Exynos_OMX_GetExtensionIndex(hComponent, cParameterName, pIndexType);
1490 #endif
1491
1492 EXIT:
1493     FunctionOut();
1494
1495     return ret;
1496 }
1497
1498 #ifdef USE_PB /* this is from FillThisBuffer */
1499 OMX_ERRORTYPE Exynos_Shared_PlatformBufferToData(EXYNOS_OMX_DATABUFFER *pUseBuffer, EXYNOS_OMX_DATA *pData, EXYNOS_OMX_BASEPORT *pExynosPort, EXYNOS_OMX_PLANE nPlane)
1500 {
1501     OMX_ERRORTYPE ret = OMX_ErrorNone;
1502     OMX_U32 width, height;
1503 //    void *pPhys[MAX_BUFFER_PLANE];
1504     ExynosVideoPlane planes[MAX_BUFFER_PLANE];
1505
1506     FunctionIn();
1507
1508     memset(planes, 0, sizeof(planes));
1509
1510     if (pExynosPort->bIsPBEnabled == OMX_TRUE) {
1511         OMX_U32 stride;
1512
1513         width = pExynosPort->portDefinition.format.video.nFrameWidth;
1514         height = pExynosPort->portDefinition.format.video.nFrameHeight;
1515         if ((pUseBuffer->bufferHeader != NULL) && (pUseBuffer->bufferHeader->pBuffer != NULL)) {
1516             Exynos_OSAL_LockPB(pUseBuffer->bufferHeader->pBuffer, width, height, pExynosPort->portDefinition.format.video.eColorFormat, &stride, planes);
1517             pUseBuffer->dataLen = sizeof(void *);
1518         } else {
1519             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__);
1520             ret = OMX_ErrorBadParameter;
1521             goto EXIT;
1522         }
1523     } else {
1524         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__);
1525         ret = OMX_ErrorBadParameter;
1526         goto EXIT;
1527     }
1528
1529     if (nPlane == TWO_PLANE) {
1530         /* Case of Shared Buffer, Only support two PlaneBuffer */
1531         pData->buffer.multiPlaneBuffer.dataBuffer[0] = planes[0].addr;
1532         pData->buffer.multiPlaneBuffer.dataBuffer[1] = planes[1].addr;
1533 #ifdef USE_DMA_BUF
1534         pData->buffer.multiPlaneBuffer.fd[0] = planes[0].fd;
1535         pData->buffer.multiPlaneBuffer.fd[1] = planes[1].fd;
1536 #endif
1537     } else {
1538         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Can not support plane");
1539         ret = OMX_ErrorNotImplemented;
1540         goto EXIT;
1541     }
1542
1543     pData->allocSize     = pUseBuffer->allocSize;
1544     pData->dataLen       = pUseBuffer->dataLen;
1545     pData->usedDataLen   = pUseBuffer->usedDataLen;
1546     pData->remainDataLen = pUseBuffer->remainDataLen;
1547     pData->timeStamp     = pUseBuffer->timeStamp;
1548     pData->nFlags        = pUseBuffer->nFlags;
1549     pData->pPrivate      = pUseBuffer->pPrivate;
1550     pData->bufferHeader  = pUseBuffer->bufferHeader;
1551
1552 EXIT:
1553     FunctionOut();
1554     return ret;
1555 }
1556
1557 /* this is for Fill This Buffer Done */
1558 #ifdef SLP_PLATFORM
1559 OMX_ERRORTYPE Exynos_Shared_DataToPlatformBuffer(EXYNOS_OMX_DATA *pData, EXYNOS_OMX_DATABUFFER *pUseBuffer, EXYNOS_OMX_BASEPORT *pExynosPort, EXYNOS_OMX_BASEPORT *pExynosInPort)
1560 #else
1561 OMX_ERRORTYPE Exynos_Shared_DataToPlatformBuffer(EXYNOS_OMX_DATA *pData, EXYNOS_OMX_DATABUFFER *pUseBuffer, EXYNOS_OMX_BASEPORT *pExynosPort)
1562 #endif
1563 {
1564     OMX_ERRORTYPE ret = OMX_ErrorNone;
1565
1566     FunctionIn();
1567
1568     pUseBuffer->bufferHeader          = pData->bufferHeader;
1569     pUseBuffer->allocSize             = pData->allocSize;
1570 #ifdef SLP_PLATFORM
1571     pUseBuffer->dataLen               = sizeof(MMVideoBuffer);
1572 #else
1573     pUseBuffer->dataLen               = pData->dataLen;
1574 #endif
1575     pUseBuffer->usedDataLen           = pData->usedDataLen;
1576     pUseBuffer->remainDataLen         = pData->remainDataLen;
1577     pUseBuffer->timeStamp             = pData->timeStamp;
1578     pUseBuffer->nFlags                = pData->nFlags;
1579     pUseBuffer->pPrivate              = pData->pPrivate;
1580
1581     if ((pUseBuffer->bufferHeader == NULL) ||
1582         (pUseBuffer->bufferHeader->pBuffer == NULL)) {
1583         Exynos_OSAL_Log(EXYNOS_LOG_VERVOSE, "pUseBuffer->bufferHeader or pUseBuffer->bufferHeader->pBuffer is NULL");
1584         ret = OMX_ErrorUndefined;
1585         goto EXIT;
1586     }
1587
1588     if (pExynosPort->bIsPBEnabled == OMX_TRUE) {
1589 #ifdef SLP_PLATFORM
1590         Exynos_OSAL_UnlockPB(pUseBuffer->bufferHeader->pBuffer, pData, pExynosPort,pExynosInPort);
1591 #else
1592         Exynos_OSAL_UnlockPB(pUseBuffer->bufferHeader->pBuffer, pData);
1593 #endif
1594     } else {
1595         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__);
1596         ret = OMX_ErrorBadParameter;
1597         goto EXIT;
1598     }
1599
1600 EXIT:
1601     FunctionOut();
1602
1603     return ret;
1604 }
1605 #endif