3 * Copyright 2012 Samsung Electronics S.LSI Co. LTD
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file Exynos_OMX_VdecControl.c
21 * @author SeungBeom Kim (sbcrux.kim@samsung.com)
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"
42 #include "Exynos_OSAL_Platform_Specific.h"
45 #include "ExynosVideoApi.h"
48 #define EXYNOS_LOG_TAG "EXYNOS_VIDEO_DECCONTROL"
49 #define EXYNOS_LOG_OFF
50 //#define EXYNOS_TRACE_ON
51 #include "Exynos_OSAL_Log.h"
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)
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;
72 if (hComponent == NULL) {
73 ret = OMX_ErrorBadParameter;
76 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
77 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
78 if (ret != OMX_ErrorNone) {
82 if (pOMXComponent->pComponentPrivate == NULL) {
83 ret = OMX_ErrorBadParameter;
86 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
87 pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
89 pExynosPort = &pExynosComponent->pExynosPort[nPortIndex];
90 if (nPortIndex >= pExynosComponent->portParam.nPorts) {
91 ret = OMX_ErrorBadPortIndex;
94 if (pExynosPort->portState != OMX_StateIdle) {
95 ret = OMX_ErrorIncorrectStateOperation;
99 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
100 ret = OMX_ErrorBadPortIndex;
104 temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE));
105 if (temp_bufferHeader == NULL) {
106 ret = OMX_ErrorInsufficientResources;
109 Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
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;
122 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX;
124 if (nPortIndex == OUTPUT_PORT_INDEX) {
125 SCMN_IMGB * pSlpOutBuf = (SCMN_IMGB *)pBuffer;
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]);
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;
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;
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;
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); */
157 Exynos_OSAL_Free(temp_bufferHeader);
158 ret = OMX_ErrorInsufficientResources;
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)
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;
182 MEMORY_TYPE mem_type;
186 if (hComponent == NULL) {
187 ret = OMX_ErrorBadParameter;
190 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
191 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
192 if (ret != OMX_ErrorNone) {
196 if (pOMXComponent->pComponentPrivate == NULL) {
197 ret = OMX_ErrorBadParameter;
200 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
201 pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
203 pExynosPort = &pExynosComponent->pExynosPort[nPortIndex];
204 if (nPortIndex >= pExynosComponent->portParam.nPorts) {
205 ret = OMX_ErrorBadPortIndex;
209 if (pExynosPort->portState != OMX_StateIdle ) {
210 ret = OMX_ErrorIncorrectStateOperation;
214 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
215 ret = OMX_ErrorBadPortIndex;
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;
224 mem_type = SYSTEM_MEMORY;
226 temp_buffer = Exynos_OSAL_SharedMemory_Alloc(pVideoDec->hSharedMemory, nSizeBytes, mem_type);
227 if (temp_buffer == NULL) {
228 ret = OMX_ErrorInsufficientResources;
231 temp_buffer_fd = Exynos_OSAL_SharedMemory_VirtToION(pVideoDec->hSharedMemory, temp_buffer);
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;
239 Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
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;
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;
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); */
264 *ppBuffer = temp_bufferHeader;
270 Exynos_OSAL_Free(temp_bufferHeader);
271 Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, temp_buffer);
273 ret = OMX_ErrorInsufficientResources;
281 OMX_ERRORTYPE Exynos_OMX_FreeBuffer(
282 OMX_IN OMX_HANDLETYPE hComponent,
283 OMX_IN OMX_U32 nPortIndex,
284 OMX_IN OMX_BUFFERHEADERTYPE *pBufferHdr)
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;
297 if (hComponent == NULL) {
298 ret = OMX_ErrorBadParameter;
301 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
302 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
303 if (ret != OMX_ErrorNone) {
307 if (pOMXComponent->pComponentPrivate == NULL) {
308 ret = OMX_ErrorBadParameter;
311 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
312 pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
313 pExynosPort = &pExynosComponent->pExynosPort[nPortIndex];
315 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
316 ret = OMX_ErrorBadPortIndex;
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,
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);
336 Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer);
338 pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer = NULL;
339 pBufferHdr->pBuffer = NULL;
340 } else if (pExynosPort->bufferStateAllocate[i] & BUFFER_STATE_ASSIGNED) {
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;
349 pExynosPort->bufferStateAllocate[i] = BUFFER_STATE_FREE;
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;
372 OMX_ERRORTYPE Exynos_OMX_AllocateTunnelBuffer(EXYNOS_OMX_BASEPORT *pOMXBasePort, OMX_U32 nPortIndex)
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;
381 ret = OMX_ErrorTunnelingUnsupported;
386 OMX_ERRORTYPE Exynos_OMX_FreeTunnelBuffer(EXYNOS_OMX_BASEPORT *pOMXBasePort, OMX_U32 nPortIndex)
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;
394 ret = OMX_ErrorTunnelingUnsupported;
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)
406 OMX_ERRORTYPE ret = OMX_ErrorNone;
408 ret = OMX_ErrorTunnelingUnsupported;
413 OMX_ERRORTYPE Exynos_OMX_GetFlushBuffer(EXYNOS_OMX_BASEPORT *pExynosPort, EXYNOS_OMX_DATABUFFER *pDataBuffer[])
415 OMX_ERRORTYPE ret = OMX_ErrorNone;
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);
434 OMX_ERRORTYPE Exynos_OMX_FlushPort(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 portIndex)
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;
448 Exynos_OSAL_Log(EXYNOS_LOG_WARNING, "flushPort idx:%d", portIndex);
451 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
453 while (Exynos_OSAL_GetElemNum(&pExynosPort->bufferQ) > 0) {
454 Exynos_OSAL_Get_SemaphoreCount(pExynosComponent->pExynosPort[portIndex].bufferSemID, &semValue);
456 Exynos_OSAL_SemaphorePost(pExynosComponent->pExynosPort[portIndex].bufferSemID);
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;
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);
470 Exynos_OSAL_Free(message);
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]);
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);
496 Exynos_ResetCodecData(&pExynosPort->processData);
498 if (pVideoDec->bDRCProcessing == OMX_TRUE)
499 maxBufferNum = pVideoDec->nDRCSavedBufferCount;
501 maxBufferNum = pExynosPort->portDefinition.nBufferCountActual;
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);
514 Exynos_ResetCodecData(&pExynosPort->processData);
519 Exynos_OSAL_Get_SemaphoreCount(pExynosComponent->pExynosPort[portIndex].bufferSemID, &cnt);
522 Exynos_OSAL_SemaphoreWait(pExynosComponent->pExynosPort[portIndex].bufferSemID);
524 Exynos_OSAL_ResetQueue(&pExynosPort->bufferQ);
532 OMX_ERRORTYPE Exynos_OMX_BufferFlush(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex, OMX_BOOL bEvent)
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;
543 Exynos_OSAL_Log(EXYNOS_LOG_WARNING, "bufferFlush idx:%d", nPortIndex);
546 if (pOMXComponent == NULL) {
547 ret = OMX_ErrorBadParameter;
550 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
551 if (ret != OMX_ErrorNone) {
555 if (pOMXComponent->pComponentPrivate == NULL) {
556 ret = OMX_ErrorBadParameter;
559 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
560 pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
562 Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"OMX_CommandFlush start, port:%d", nPortIndex);
564 pExynosComponent->pExynosPort[nPortIndex].bIsPortFlushed = OMX_TRUE;
566 if (pExynosComponent->bMultiThreadProcess == OMX_FALSE) {
567 Exynos_OSAL_SignalSet(pExynosComponent->pauseEvent);
569 Exynos_OSAL_SignalSet(pExynosComponent->pExynosPort[nPortIndex].pauseEvent);
572 pExynosPort = &pExynosComponent->pExynosPort[nPortIndex];
573 Exynos_OMX_GetFlushBuffer(pExynosPort, flushPortBuffer);
575 if (pExynosComponent->pExynosPort[nPortIndex].bufferProcessType & BUFFER_COPY)
576 Exynos_OSAL_SemaphorePost(pExynosPort->codecSemID);
577 Exynos_OSAL_SemaphorePost(pExynosPort->bufferSemID);
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);
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);
593 Exynos_ResetCodecData(&pExynosPort->processData);
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;
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);
615 Exynos_OSAL_MutexUnlock(flushPortBuffer[1]->bufferMutex);
616 Exynos_OSAL_MutexUnlock(flushPortBuffer[0]->bufferMutex);
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,
632 OMX_ERRORTYPE Exynos_InputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent)
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;
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);
648 bufferHeader = dataBuffer->bufferHeader;
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;
658 if (bufferHeader->hMarkTargetComponent != NULL) {
659 if (bufferHeader->hMarkTargetComponent == pOMXComponent) {
660 pExynosComponent->pCallbacks->EventHandler(pOMXComponent,
661 pExynosComponent->callbackData,
663 0, 0, bufferHeader->pMarkData);
665 pExynosComponent->propagateMarkType.hMarkTargetComponent = bufferHeader->hMarkTargetComponent;
666 pExynosComponent->propagateMarkType.pMarkData = bufferHeader->pMarkData;
670 bufferHeader->nFilledLen = 0;
671 bufferHeader->nOffset = 0;
672 Exynos_OMX_InputBufferReturn(pOMXComponent, bufferHeader);
675 /* reset dataBuffer */
676 Exynos_ResetDataBuffer(dataBuffer);
684 OMX_ERRORTYPE Exynos_FlushInputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer)
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;
693 bufferHeader = dataBuffer->bufferHeader;
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;
703 if (bufferHeader->hMarkTargetComponent != NULL) {
704 if (bufferHeader->hMarkTargetComponent == pOMXComponent) {
705 pExynosComponent->pCallbacks->EventHandler(pOMXComponent,
706 pExynosComponent->callbackData,
708 0, 0, bufferHeader->pMarkData);
710 pExynosComponent->propagateMarkType.hMarkTargetComponent = bufferHeader->hMarkTargetComponent;
711 pExynosComponent->propagateMarkType.pMarkData = bufferHeader->pMarkData;
715 bufferHeader->nFilledLen = 0;
716 bufferHeader->nOffset = 0;
717 Exynos_OMX_InputBufferReturn(pOMXComponent, bufferHeader);
720 /* reset dataBuffer */
721 Exynos_ResetDataBuffer(dataBuffer);
729 OMX_ERRORTYPE Exynos_InputBufferGetQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent)
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;
738 inputUseBuffer = &(pExynosPort->way.port2WayDataBuffer.inputDataBuffer);
740 if (pExynosComponent->currentState != OMX_StateExecuting) {
741 ret = OMX_ErrorUndefined;
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;
752 if (message->messageType == EXYNOS_OMX_CommandFakeBuffer) {
753 Exynos_OSAL_Free(message);
754 ret = OMX_ErrorCodecFlush;
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;
767 Exynos_OSAL_Free(message);
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);
782 OMX_ERRORTYPE Exynos_OutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent)
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;
792 dataBuffer = &(exynosOMXOutputPort->way.port2WayDataBuffer.outputDataBuffer);
793 bufferHeader = dataBuffer->bufferHeader;
795 if (bufferHeader != NULL) {
797 bufferHeader->nFilledLen = sizeof(SCMN_IMGB);
799 bufferHeader->nFilledLen = dataBuffer->remainDataLen;
801 bufferHeader->nOffset = 0;
802 bufferHeader->nFlags = dataBuffer->nFlags;
803 bufferHeader->nTimeStamp = dataBuffer->timeStamp;
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);
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;
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,
823 bufferHeader->nFlags, NULL);
826 Exynos_OMX_OutputBufferReturn(pOMXComponent, bufferHeader);
828 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d bufferHeader is NULL! ", __FUNCTION__, __LINE__);
831 /* reset dataBuffer */
832 Exynos_ResetDataBuffer(dataBuffer);
840 OMX_ERRORTYPE Exynos_FlushOutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer)
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;
849 bufferHeader = dataBuffer->bufferHeader;
851 if (bufferHeader != NULL) {
852 bufferHeader->nFilledLen = dataBuffer->remainDataLen;
853 bufferHeader->nOffset = 0;
854 bufferHeader->nFlags = dataBuffer->nFlags;
855 bufferHeader->nTimeStamp = dataBuffer->timeStamp;
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;
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,
871 bufferHeader->nFlags, NULL);
873 Exynos_OMX_OutputBufferReturn(pOMXComponent, bufferHeader);
876 /* reset dataBuffer */
877 Exynos_ResetDataBuffer(dataBuffer);
885 OMX_ERRORTYPE Exynos_OutputBufferGetQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent)
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;
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);
900 if (pExynosComponent->currentState != OMX_StateExecuting) {
901 ret = OMX_ErrorUndefined;
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;
912 if (message->messageType == EXYNOS_OMX_CommandFakeBuffer) {
913 Exynos_OSAL_Free(message);
914 ret = OMX_ErrorCodecFlush;
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; */
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;
935 Exynos_OSAL_Free(message);
946 OMX_BUFFERHEADERTYPE *Exynos_OutputBufferGetQueue_Direct(EXYNOS_OMX_BASECOMPONENT *pExynosComponent)
948 OMX_BUFFERHEADERTYPE *retBuffer = NULL;
949 EXYNOS_OMX_BASEPORT *pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
950 EXYNOS_OMX_MESSAGE *message = NULL;
954 if (pExynosComponent->currentState != OMX_StateExecuting) {
957 } else if ((pExynosComponent->transientState != EXYNOS_OMX_TransStateExecutingToIdle) &&
958 (!CHECK_PORT_BEING_FLUSHED(pExynosPort))){
959 Exynos_OSAL_SemaphoreWait(pExynosPort->bufferSemID);
961 message = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ);
962 if (message == NULL) {
966 if (message->messageType == EXYNOS_OMX_CommandFakeBuffer) {
967 Exynos_OSAL_Free(message);
972 retBuffer = (OMX_BUFFERHEADERTYPE *)(message->pCmdData);
973 Exynos_OSAL_Free(message);
982 OMX_ERRORTYPE Exynos_CodecBufferEnQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 PortIndex, OMX_PTR data)
984 OMX_ERRORTYPE ret = OMX_ErrorNone;
985 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
989 pExynosPort= &pExynosComponent->pExynosPort[PortIndex];
992 ret = OMX_ErrorInsufficientResources;
997 if (pExynosPort == NULL) {
998 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d: pExynosPort is NULL", __FUNCTION__, __LINE__);
1002 ret = Exynos_OSAL_Queue(&pExynosPort->codecBufferQ, (void *)data);
1004 ret = OMX_ErrorUndefined;
1007 Exynos_OSAL_SemaphorePost(pExynosPort->codecSemID);
1009 ret = OMX_ErrorNone;
1017 OMX_ERRORTYPE Exynos_CodecBufferDeQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 PortIndex, OMX_PTR *data)
1019 OMX_ERRORTYPE ret = OMX_ErrorNone;
1020 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1025 pExynosPort = &pExynosComponent->pExynosPort[PortIndex];
1026 Exynos_OSAL_SemaphoreWait(pExynosPort->codecSemID);
1027 tempData = (OMX_U32)Exynos_OSAL_Dequeue(&pExynosPort->codecBufferQ);
1028 if (tempData == NULL) {
1030 ret = OMX_ErrorUndefined;
1033 *data = (OMX_PTR)tempData;
1035 ret = OMX_ErrorNone;
1043 OMX_ERRORTYPE Exynos_CodecBufferReset(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 PortIndex)
1045 OMX_ERRORTYPE ret = OMX_ErrorNone;
1046 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1050 pExynosPort= &pExynosComponent->pExynosPort[PortIndex];
1052 ret = Exynos_OSAL_ResetQueue(&pExynosPort->codecBufferQ);
1054 ret = OMX_ErrorUndefined;
1059 Exynos_OSAL_Get_SemaphoreCount(pExynosPort->codecSemID, &cnt);
1061 Exynos_OSAL_SemaphoreWait(pExynosPort->codecSemID);
1065 ret = OMX_ErrorNone;
1073 OMX_ERRORTYPE Exynos_OMX_VideoDecodeGetParameter(
1074 OMX_IN OMX_HANDLETYPE hComponent,
1075 OMX_IN OMX_INDEXTYPE nParamIndex,
1076 OMX_INOUT OMX_PTR ComponentParameterStructure)
1078 OMX_ERRORTYPE ret = OMX_ErrorNone;
1079 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1080 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1081 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1085 if (hComponent == NULL) {
1086 ret = OMX_ErrorBadParameter;
1089 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1090 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1091 if (ret != OMX_ErrorNone) {
1095 if (pOMXComponent->pComponentPrivate == NULL) {
1096 ret = OMX_ErrorBadParameter;
1099 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1101 if (pExynosComponent->currentState == OMX_StateInvalid ) {
1102 ret = OMX_ErrorInvalidState;
1106 if (ComponentParameterStructure == NULL) {
1107 ret = OMX_ErrorBadParameter;
1111 switch (nParamIndex) {
1112 case OMX_IndexParamVideoInit:
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) {
1120 portParam->nPorts = pExynosComponent->portParam.nPorts;
1121 portParam->nStartPortNumber = pExynosComponent->portParam.nStartPortNumber;
1122 ret = OMX_ErrorNone;
1125 case OMX_IndexParamVideoPortFormat:
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 */
1134 ret = Exynos_OMX_Check_SizeVersion(portFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
1135 if (ret != OMX_ErrorNone) {
1139 if ((portIndex >= pExynosComponent->portParam.nPorts)) {
1140 ret = OMX_ErrorBadPortIndex;
1145 if (portIndex == INPUT_PORT_INDEX) {
1146 supportFormatNum = INPUT_PORT_SUPPORTFORMAT_NUM_MAX - 1;
1147 if (index > supportFormatNum) {
1148 ret = OMX_ErrorNoMore;
1152 pExynosPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
1153 portDefinition = &pExynosPort->portDefinition;
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;
1163 case supportFormat_0:
1164 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
1165 portFormat->eColorFormat = OMX_COLOR_FormatYUV420Planar;
1166 portFormat->xFramerate = portDefinition->format.video.xFramerate;
1168 case supportFormat_1:
1169 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
1170 portFormat->eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
1171 portFormat->xFramerate = portDefinition->format.video.xFramerate;
1173 case supportFormat_2:
1174 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
1175 portFormat->eColorFormat = OMX_SEC_COLOR_FormatNV12Tiled;
1176 portFormat->xFramerate = portDefinition->format.video.xFramerate;
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;
1186 if (index > supportFormat_0) {
1187 ret = OMX_ErrorNoMore;
1193 ret = OMX_ErrorNone;
1197 case OMX_IndexParamGetAndroidNativeBuffer:
1199 ret = Exynos_OSAL_GetPBParameter(hComponent, nParamIndex, ComponentParameterStructure);
1205 ret = Exynos_OMX_GetParameter(hComponent, nParamIndex, ComponentParameterStructure);
1215 OMX_ERRORTYPE Exynos_OMX_VideoDecodeSetParameter(
1216 OMX_IN OMX_HANDLETYPE hComponent,
1217 OMX_IN OMX_INDEXTYPE nIndex,
1218 OMX_IN OMX_PTR ComponentParameterStructure)
1220 OMX_ERRORTYPE ret = OMX_ErrorNone;
1221 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1222 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1223 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1227 if (hComponent == NULL) {
1228 ret = OMX_ErrorBadParameter;
1231 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1232 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1233 if (ret != OMX_ErrorNone) {
1237 if (pOMXComponent->pComponentPrivate == NULL) {
1238 ret = OMX_ErrorBadParameter;
1241 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1243 if (pExynosComponent->currentState == OMX_StateInvalid ) {
1244 ret = OMX_ErrorInvalidState;
1248 if (ComponentParameterStructure == NULL) {
1249 ret = OMX_ErrorBadParameter;
1254 case OMX_IndexParamVideoPortFormat:
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;
1263 ret = Exynos_OMX_Check_SizeVersion(portFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
1264 if (ret != OMX_ErrorNone) {
1268 if ((portIndex >= pExynosComponent->portParam.nPorts)) {
1269 ret = OMX_ErrorBadPortIndex;
1272 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
1273 portDefinition = &pExynosPort->portDefinition;
1275 portDefinition->format.video.eColorFormat = portFormat->eColorFormat;
1276 portDefinition->format.video.eCompressionFormat = portFormat->eCompressionFormat;
1277 portDefinition->format.video.xFramerate = portFormat->xFramerate;
1283 case OMX_IndexParamEnablePlatformSpecificBuffers:
1285 case OMX_IndexParamEnableAndroidBuffers:
1287 case OMX_IndexParamUseAndroidNativeBuffer:
1289 ret = Exynos_OSAL_SetPBParameter(hComponent, nIndex, ComponentParameterStructure);
1295 case OMX_IndexParamEnableTimestampReorder:
1297 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
1298 pVideoDec->bNeedTimestampReorder = OMX_TRUE;
1304 ret = Exynos_OMX_SetParameter(hComponent, nIndex, ComponentParameterStructure);
1315 OMX_ERRORTYPE Exynos_OMX_VideoDecodeGetConfig(
1316 OMX_HANDLETYPE hComponent,
1317 OMX_INDEXTYPE nIndex,
1318 OMX_PTR pComponentConfigStructure)
1320 OMX_ERRORTYPE ret = OMX_ErrorNone;
1321 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1322 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1326 if (hComponent == NULL) {
1327 ret = OMX_ErrorBadParameter;
1330 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1331 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1332 if (ret != OMX_ErrorNone) {
1335 if (pOMXComponent->pComponentPrivate == NULL) {
1336 ret = OMX_ErrorBadParameter;
1339 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1340 if (pComponentConfigStructure == NULL) {
1341 ret = OMX_ErrorBadParameter;
1344 if (pExynosComponent->currentState == OMX_StateInvalid) {
1345 ret = OMX_ErrorInvalidState;
1351 ret = Exynos_OMX_GetConfig(hComponent, nIndex, pComponentConfigStructure);
1361 OMX_ERRORTYPE Exynos_OMX_VideoDecodeSetConfig(
1362 OMX_HANDLETYPE hComponent,
1363 OMX_INDEXTYPE nIndex,
1364 OMX_PTR pComponentConfigStructure)
1366 OMX_ERRORTYPE ret = OMX_ErrorNone;
1367 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1368 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1372 if (hComponent == NULL) {
1373 ret = OMX_ErrorBadParameter;
1376 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1377 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1378 if (ret != OMX_ErrorNone) {
1381 if (pOMXComponent->pComponentPrivate == NULL) {
1382 ret = OMX_ErrorBadParameter;
1385 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1386 if (pComponentConfigStructure == NULL) {
1387 ret = OMX_ErrorBadParameter;
1390 if (pExynosComponent->currentState == OMX_StateInvalid) {
1391 ret = OMX_ErrorInvalidState;
1396 case OMX_IndexVendorThumbnailMode:
1398 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
1399 pVideoDec->bThumbnailMode = *((OMX_BOOL *)pComponentConfigStructure);
1401 ret = OMX_ErrorNone;
1405 ret = Exynos_OMX_SetConfig(hComponent, nIndex, pComponentConfigStructure);
1415 OMX_ERRORTYPE Exynos_OMX_VideoDecodeGetExtensionIndex(
1416 OMX_IN OMX_HANDLETYPE hComponent,
1417 OMX_IN OMX_STRING cParameterName,
1418 OMX_OUT OMX_INDEXTYPE *pIndexType)
1420 OMX_ERRORTYPE ret = OMX_ErrorNone;
1421 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1422 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1426 if (hComponent == NULL) {
1427 ret = OMX_ErrorBadParameter;
1430 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1431 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1432 if (ret != OMX_ErrorNone) {
1436 if (pOMXComponent->pComponentPrivate == NULL) {
1437 ret = OMX_ErrorBadParameter;
1440 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1442 if ((cParameterName == NULL) || (pIndexType == NULL)) {
1443 ret = OMX_ErrorBadParameter;
1446 if (pExynosComponent->currentState == OMX_StateInvalid) {
1447 ret = OMX_ErrorInvalidState;
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;
1458 if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_ENABLE_ANB) == 0)
1459 *pIndexType = (OMX_INDEXTYPE) OMX_IndexParamEnableAndroidBuffers;
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;
1466 ret = Exynos_OMX_GetExtensionIndex(hComponent, cParameterName, pIndexType);
1468 ret = Exynos_OMX_GetExtensionIndex(hComponent, cParameterName, pIndexType);
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)
1480 OMX_ERRORTYPE ret = OMX_ErrorNone;
1481 OMX_U32 width, height;
1482 // void *pPhys[MAX_BUFFER_PLANE];
1483 ExynosVideoPlane planes[MAX_BUFFER_PLANE];
1487 memset(planes, 0, sizeof(planes));
1489 if (pExynosPort->bIsPBEnabled == OMX_TRUE) {
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 *);
1498 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__);
1499 ret = OMX_ErrorBadParameter;
1503 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__);
1504 ret = OMX_ErrorBadParameter;
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;
1513 pData->buffer.multiPlaneBuffer.fd[0] = planes[0].fd;
1514 pData->buffer.multiPlaneBuffer.fd[1] = planes[1].fd;
1517 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Can not support plane");
1518 ret = OMX_ErrorNotImplemented;
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;
1536 /* this is for Fill This Buffer Done */
1538 OMX_ERRORTYPE Exynos_Shared_DataToPlatformBuffer(EXYNOS_OMX_DATA *pData, EXYNOS_OMX_DATABUFFER *pUseBuffer, EXYNOS_OMX_BASEPORT *pExynosPort, EXYNOS_OMX_BASEPORT *pExynosInPort)
1540 OMX_ERRORTYPE Exynos_Shared_DataToPlatformBuffer(EXYNOS_OMX_DATA *pData, EXYNOS_OMX_DATABUFFER *pUseBuffer, EXYNOS_OMX_BASEPORT *pExynosPort)
1543 OMX_ERRORTYPE ret = OMX_ErrorNone;
1547 pUseBuffer->bufferHeader = pData->bufferHeader;
1548 pUseBuffer->allocSize = pData->allocSize;
1550 pUseBuffer->dataLen = sizeof(SCMN_IMGB);
1552 pUseBuffer->dataLen = pData->dataLen;
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;
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;
1567 if (pExynosPort->bIsPBEnabled == OMX_TRUE) {
1569 Exynos_OSAL_UnlockPB(pUseBuffer->bufferHeader->pBuffer, pData, pExynosPort,pExynosInPort);
1571 Exynos_OSAL_UnlockPB(pUseBuffer->bufferHeader->pBuffer, pData);
1574 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__);
1575 ret = OMX_ErrorBadParameter;