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