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