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