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)
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"
43 #include "Exynos_OSAL_Platform_Specific.h"
46 #include "ExynosVideoApi.h"
49 #define EXYNOS_LOG_TAG "EXYNOS_VIDEO_DECCONTROL"
50 #define EXYNOS_LOG_OFF
51 //#define EXYNOS_TRACE_ON
52 #include "Exynos_OSAL_Log.h"
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)
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;
73 if (hComponent == NULL) {
74 ret = OMX_ErrorBadParameter;
77 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
78 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
79 if (ret != OMX_ErrorNone) {
83 if (pOMXComponent->pComponentPrivate == NULL) {
84 ret = OMX_ErrorBadParameter;
87 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
88 pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
90 pExynosPort = &pExynosComponent->pExynosPort[nPortIndex];
91 if (nPortIndex >= pExynosComponent->portParam.nPorts) {
92 ret = OMX_ErrorBadPortIndex;
95 if (pExynosPort->portState != OMX_StateIdle) {
96 ret = OMX_ErrorIncorrectStateOperation;
100 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
101 ret = OMX_ErrorBadPortIndex;
105 temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE));
106 if (temp_bufferHeader == NULL) {
107 ret = OMX_ErrorInsufficientResources;
110 Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
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;
123 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX;
125 if (nPortIndex == OUTPUT_PORT_INDEX) {
126 MMVideoBuffer * pSlpOutBuf = (MMVideoBuffer *)pBuffer;
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]);
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;
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;
140 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "PlatformBuffer: buf %d pYUVBuf[0]:0x%x , pYUVBuf[1]:0x%x ",
141 i, pExynosPort->extendBufferHeader[i].pYUVBuf[0], pExynosPort->extendBufferHeader[i].pYUVBuf[1]);
142 } else if ((pVideoDec->bDRMPlayerMode == OMX_TRUE) && (nPortIndex == INPUT_PORT_INDEX)) {
143 pExynosPort->extendBufferHeader[i].buf_fd[0] = pBuffer;
144 } else if(nPortIndex == INPUT_PORT_INDEX){
145 MMVideoBuffer * pSlpOutBuf = (MMVideoBuffer *)pBuffer;
146 temp_bufferHeader->pBuffer = pSlpOutBuf->data[0];
148 pExynosPort->extendBufferHeader[i].buf_fd[0] = pBuffer;
149 SCMN_IMGB * pSlpOutBuf = (SCMN_IMGB *)pBuffer;
150 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "fd[0] =%d, vaddr[0] =%p, , length=%d",
151 pSlpOutBuf->fd[0], pSlpOutBuf->a[0], nSizeBytes);
153 pExynosPort->extendBufferHeader[i].buf_fd[0] = pSlpOutBuf->fd[0];
154 pExynosPort->extendBufferHeader[i].buf_fd[1] = 0;
155 pExynosPort->extendBufferHeader[i].buf_fd[2] = 0;
157 pExynosPort->extendBufferHeader[i].pYUVBuf[0] = pSlpOutBuf->a[0];
158 pExynosPort->extendBufferHeader[i].pYUVBuf[1] = NULL;
159 pExynosPort->extendBufferHeader[i].pYUVBuf[2] = NULL;
161 temp_bufferHeader->pBuffer = pSlpOutBuf->a[0];
165 *ppBufferHdr = temp_bufferHeader;
166 pExynosPort->assignedBufferNum++;
167 if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) {
168 pExynosPort->portDefinition.bPopulated = OMX_TRUE;
169 /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */
170 Exynos_OSAL_SemaphorePost(pExynosPort->loadedResource);
171 /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */
178 Exynos_OSAL_Free(temp_bufferHeader);
179 ret = OMX_ErrorInsufficientResources;
187 OMX_ERRORTYPE Exynos_OMX_AllocateBuffer(
188 OMX_IN OMX_HANDLETYPE hComponent,
189 OMX_INOUT OMX_BUFFERHEADERTYPE **ppBuffer,
190 OMX_IN OMX_U32 nPortIndex,
191 OMX_IN OMX_PTR pAppPrivate,
192 OMX_IN OMX_U32 nSizeBytes)
194 OMX_ERRORTYPE ret = OMX_ErrorNone;
195 OMX_COMPONENTTYPE *pOMXComponent = NULL;
196 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
197 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
198 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
199 OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL;
200 OMX_U8 *temp_buffer = NULL;
201 int temp_buffer_fd = -1;
203 MEMORY_TYPE mem_type;
207 if (hComponent == NULL) {
208 ret = OMX_ErrorBadParameter;
211 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
212 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
213 if (ret != OMX_ErrorNone) {
217 if (pOMXComponent->pComponentPrivate == NULL) {
218 ret = OMX_ErrorBadParameter;
221 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
222 pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
224 pExynosPort = &pExynosComponent->pExynosPort[nPortIndex];
225 if (nPortIndex >= pExynosComponent->portParam.nPorts) {
226 ret = OMX_ErrorBadPortIndex;
230 if (pExynosPort->portState != OMX_StateIdle ) {
231 ret = OMX_ErrorIncorrectStateOperation;
235 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
236 ret = OMX_ErrorBadPortIndex;
240 if ((pVideoDec->bDRMPlayerMode == OMX_TRUE) && (nPortIndex == INPUT_PORT_INDEX)) {
241 mem_type = SECURE_MEMORY;
242 } else if (pExynosPort->bufferProcessType & BUFFER_SHARE) {
243 mem_type = NORMAL_MEMORY;
245 mem_type = SYSTEM_MEMORY;
247 temp_buffer = Exynos_OSAL_SharedMemory_Alloc(pVideoDec->hSharedMemory, nSizeBytes, mem_type);
248 if (temp_buffer == NULL) {
249 ret = OMX_ErrorInsufficientResources;
252 temp_buffer_fd = Exynos_OSAL_SharedMemory_VirtToION(pVideoDec->hSharedMemory, temp_buffer);
254 temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE));
255 if (temp_bufferHeader == NULL) {
256 Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, temp_buffer);
257 ret = OMX_ErrorInsufficientResources;
260 Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
262 for (i = 0; i < pExynosPort->portDefinition.nBufferCountActual; i++) {
263 if (pExynosPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) {
264 pExynosPort->extendBufferHeader[i].OMXBufferHeader = temp_bufferHeader;
265 pExynosPort->extendBufferHeader[i].buf_fd[0] = temp_buffer_fd;
266 pExynosPort->bufferStateAllocate[i] = (BUFFER_STATE_ALLOCATED | HEADER_STATE_ALLOCATED);
267 INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE);
268 if (mem_type == SECURE_MEMORY)
269 temp_bufferHeader->pBuffer = temp_buffer_fd;
271 temp_bufferHeader->pBuffer = temp_buffer;
272 temp_bufferHeader->nAllocLen = nSizeBytes;
273 temp_bufferHeader->pAppPrivate = pAppPrivate;
274 if (nPortIndex == INPUT_PORT_INDEX)
275 temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX;
277 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX;
278 pExynosPort->assignedBufferNum++;
279 if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) {
280 pExynosPort->portDefinition.bPopulated = OMX_TRUE;
281 /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */
282 Exynos_OSAL_SemaphorePost(pExynosPort->loadedResource);
283 /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */
285 *ppBuffer = temp_bufferHeader;
291 Exynos_OSAL_Free(temp_bufferHeader);
292 Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, temp_buffer);
294 ret = OMX_ErrorInsufficientResources;
302 OMX_ERRORTYPE Exynos_OMX_FreeBuffer(
303 OMX_IN OMX_HANDLETYPE hComponent,
304 OMX_IN OMX_U32 nPortIndex,
305 OMX_IN OMX_BUFFERHEADERTYPE *pBufferHdr)
307 OMX_ERRORTYPE ret = OMX_ErrorNone;
308 OMX_COMPONENTTYPE *pOMXComponent = NULL;
309 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
310 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
311 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
312 OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL;
313 OMX_U8 *temp_buffer = NULL;
318 if (hComponent == NULL) {
319 ret = OMX_ErrorBadParameter;
322 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
323 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
324 if (ret != OMX_ErrorNone) {
328 if (pOMXComponent->pComponentPrivate == NULL) {
329 ret = OMX_ErrorBadParameter;
332 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
333 pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
334 pExynosPort = &pExynosComponent->pExynosPort[nPortIndex];
336 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
337 ret = OMX_ErrorBadPortIndex;
341 if ((pExynosPort->portState != OMX_StateLoaded) && (pExynosPort->portState != OMX_StateInvalid)) {
342 (*(pExynosComponent->pCallbacks->EventHandler)) (pOMXComponent,
343 pExynosComponent->callbackData,
344 (OMX_U32)OMX_EventError,
345 (OMX_U32)OMX_ErrorPortUnpopulated,
349 for (i = 0; i < /*pExynosPort->portDefinition.nBufferCountActual*/MAX_BUFFER_NUM; i++) {
350 if (((pExynosPort->bufferStateAllocate[i] | BUFFER_STATE_FREE) != 0) && (pExynosPort->extendBufferHeader[i].OMXBufferHeader != NULL)) {
351 if (pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer == pBufferHdr->pBuffer) {
352 if (pExynosPort->bufferStateAllocate[i] & BUFFER_STATE_ALLOCATED) {
353 if ((pVideoDec->bDRMPlayerMode == OMX_TRUE) && (nPortIndex == INPUT_PORT_INDEX)) {
354 OMX_PTR mapBuffer = Exynos_OSAL_SharedMemory_IONToVirt(pVideoDec->hSharedMemory, (int)pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer);
355 Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, mapBuffer);
357 Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer);
359 pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer = NULL;
360 pBufferHdr->pBuffer = NULL;
361 } else if (pExynosPort->bufferStateAllocate[i] & BUFFER_STATE_ASSIGNED) {
364 pExynosPort->assignedBufferNum--;
365 if (pExynosPort->bufferStateAllocate[i] & HEADER_STATE_ALLOCATED) {
366 Exynos_OSAL_Free(pExynosPort->extendBufferHeader[i].OMXBufferHeader);
367 pExynosPort->extendBufferHeader[i].OMXBufferHeader = NULL;
370 pExynosPort->bufferStateAllocate[i] = BUFFER_STATE_FREE;
378 if (ret == OMX_ErrorNone) {
379 if (pExynosPort->assignedBufferNum == 0) {
380 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pExynosPort->unloadedResource signal set");
381 /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */
382 Exynos_OSAL_SemaphorePost(pExynosPort->unloadedResource);
383 /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */
384 pExynosPort->portDefinition.bPopulated = OMX_FALSE;
393 OMX_ERRORTYPE Exynos_OMX_AllocateTunnelBuffer(EXYNOS_OMX_BASEPORT *pOMXBasePort, OMX_U32 nPortIndex)
395 OMX_ERRORTYPE ret = OMX_ErrorNone;
396 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
397 OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL;
398 OMX_U8 *temp_buffer = NULL;
399 OMX_U32 bufferSize = 0;
400 OMX_PARAM_PORTDEFINITIONTYPE portDefinition;
402 ret = OMX_ErrorTunnelingUnsupported;
407 OMX_ERRORTYPE Exynos_OMX_FreeTunnelBuffer(EXYNOS_OMX_BASEPORT *pOMXBasePort, OMX_U32 nPortIndex)
409 OMX_ERRORTYPE ret = OMX_ErrorNone;
410 EXYNOS_OMX_BASEPORT* pExynosPort = NULL;
411 OMX_BUFFERHEADERTYPE* temp_bufferHeader = NULL;
412 OMX_U8 *temp_buffer = NULL;
413 OMX_U32 bufferSize = 0;
415 ret = OMX_ErrorTunnelingUnsupported;
420 OMX_ERRORTYPE Exynos_OMX_ComponentTunnelRequest(
421 OMX_IN OMX_HANDLETYPE hComp,
422 OMX_IN OMX_U32 nPort,
423 OMX_IN OMX_HANDLETYPE hTunneledComp,
424 OMX_IN OMX_U32 nTunneledPort,
425 OMX_INOUT OMX_TUNNELSETUPTYPE *pTunnelSetup)
427 OMX_ERRORTYPE ret = OMX_ErrorNone;
429 ret = OMX_ErrorTunnelingUnsupported;
434 OMX_ERRORTYPE Exynos_OMX_GetFlushBuffer(EXYNOS_OMX_BASEPORT *pExynosPort, EXYNOS_OMX_DATABUFFER *pDataBuffer[])
436 OMX_ERRORTYPE ret = OMX_ErrorNone;
442 if (pExynosPort->portWayType == WAY1_PORT) {
443 *pDataBuffer = &pExynosPort->way.port1WayDataBuffer.dataBuffer;
444 } else if (pExynosPort->portWayType == WAY2_PORT) {
445 pDataBuffer[0] = &(pExynosPort->way.port2WayDataBuffer.inputDataBuffer);
446 pDataBuffer[1] = &(pExynosPort->way.port2WayDataBuffer.outputDataBuffer);
455 OMX_ERRORTYPE Exynos_OMX_FlushPort(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 portIndex)
457 OMX_ERRORTYPE ret = OMX_ErrorNone;
458 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
459 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
460 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
461 OMX_BUFFERHEADERTYPE *bufferHeader = NULL;
462 EXYNOS_OMX_DATABUFFER *pDataPortBuffer[2] = {NULL, NULL};
463 EXYNOS_OMX_MESSAGE *message = NULL;
464 OMX_U32 flushNum = 0;
465 OMX_S32 semValue = 0;
466 int i = 0, maxBufferNum = 0;
469 Exynos_OSAL_Log(EXYNOS_LOG_WARNING, "flushPort idx:%d", portIndex);
472 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
474 while (Exynos_OSAL_GetElemNum(&pExynosPort->bufferQ) > 0) {
475 Exynos_OSAL_Get_SemaphoreCount(pExynosComponent->pExynosPort[portIndex].bufferSemID, &semValue);
477 Exynos_OSAL_SemaphorePost(pExynosComponent->pExynosPort[portIndex].bufferSemID);
479 Exynos_OSAL_SemaphoreWait(pExynosComponent->pExynosPort[portIndex].bufferSemID);
480 message = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ);
481 if ((message != NULL) && (message->messageType != EXYNOS_OMX_CommandFakeBuffer)) {
482 bufferHeader = (OMX_BUFFERHEADERTYPE *)message->pCmdData;
483 bufferHeader->nFilledLen = 0;
485 if (portIndex == OUTPUT_PORT_INDEX) {
486 Exynos_OMX_OutputBufferReturn(pOMXComponent, bufferHeader);
487 } else if (portIndex == INPUT_PORT_INDEX) {
488 Exynos_OMX_InputBufferReturn(pOMXComponent, bufferHeader);
491 Exynos_OSAL_Free(message);
495 Exynos_OMX_GetFlushBuffer(pExynosPort, pDataPortBuffer);
496 if (portIndex == INPUT_PORT_INDEX) {
497 if (pDataPortBuffer[0]->dataValid == OMX_TRUE)
498 Exynos_FlushInputBufferReturn(pOMXComponent, pDataPortBuffer[0]);
499 if (pDataPortBuffer[1]->dataValid == OMX_TRUE)
500 Exynos_FlushInputBufferReturn(pOMXComponent, pDataPortBuffer[1]);
501 } else if (portIndex == OUTPUT_PORT_INDEX) {
502 if (pDataPortBuffer[0]->dataValid == OMX_TRUE)
503 Exynos_FlushOutputBufferReturn(pOMXComponent, pDataPortBuffer[0]);
504 if (pDataPortBuffer[1]->dataValid == OMX_TRUE)
505 Exynos_FlushOutputBufferReturn(pOMXComponent, pDataPortBuffer[1]);
508 if (pExynosComponent->bMultiThreadProcess == OMX_TRUE) {
509 if (pExynosPort->bufferProcessType & BUFFER_SHARE) {
510 if (pExynosPort->processData.bufferHeader != NULL) {
511 if (portIndex == INPUT_PORT_INDEX) {
512 Exynos_OMX_InputBufferReturn(pOMXComponent, pExynosPort->processData.bufferHeader);
513 } else if (portIndex == OUTPUT_PORT_INDEX) {
514 Exynos_OMX_OutputBufferReturn(pOMXComponent, pExynosPort->processData.bufferHeader);
517 Exynos_ResetCodecData(&pExynosPort->processData);
519 if (pVideoDec->bDRCProcessing == OMX_TRUE)
520 maxBufferNum = pVideoDec->nDRCSavedBufferCount;
522 maxBufferNum = pExynosPort->portDefinition.nBufferCountActual;
524 for (i = 0; i < maxBufferNum; i++) {
525 if (pExynosPort->extendBufferHeader[i].bBufferInOMX == OMX_TRUE) {
526 if (portIndex == OUTPUT_PORT_INDEX) {
527 Exynos_OMX_OutputBufferReturn(pOMXComponent, pExynosPort->extendBufferHeader[i].OMXBufferHeader);
528 } else if (portIndex == INPUT_PORT_INDEX) {
529 Exynos_OMX_InputBufferReturn(pOMXComponent, pExynosPort->extendBufferHeader[i].OMXBufferHeader);
535 Exynos_ResetCodecData(&pExynosPort->processData);
540 Exynos_OSAL_Get_SemaphoreCount(pExynosComponent->pExynosPort[portIndex].bufferSemID, &cnt);
543 Exynos_OSAL_SemaphoreWait(pExynosComponent->pExynosPort[portIndex].bufferSemID);
545 Exynos_OSAL_ResetQueue(&pExynosPort->bufferQ);
553 OMX_ERRORTYPE Exynos_OMX_BufferFlush(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex, OMX_BOOL bEvent)
555 OMX_ERRORTYPE ret = OMX_ErrorNone;
556 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
557 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
558 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
559 EXYNOS_OMX_DATABUFFER *flushPortBuffer[2] = {NULL, NULL};
560 OMX_U32 i = 0, cnt = 0;
564 Exynos_OSAL_Log(EXYNOS_LOG_WARNING, "bufferFlush idx:%d", nPortIndex);
567 if (pOMXComponent == NULL) {
568 ret = OMX_ErrorBadParameter;
571 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
572 if (ret != OMX_ErrorNone) {
576 if (pOMXComponent->pComponentPrivate == NULL) {
577 ret = OMX_ErrorBadParameter;
580 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
581 pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
583 Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"OMX_CommandFlush start, port:%d", nPortIndex);
585 pExynosComponent->pExynosPort[nPortIndex].bIsPortFlushed = OMX_TRUE;
587 if (pExynosComponent->bMultiThreadProcess == OMX_FALSE) {
588 Exynos_OSAL_SignalSet(pExynosComponent->pauseEvent);
590 Exynos_OSAL_SignalSet(pExynosComponent->pExynosPort[nPortIndex].pauseEvent);
593 pExynosPort = &pExynosComponent->pExynosPort[nPortIndex];
594 Exynos_OMX_GetFlushBuffer(pExynosPort, flushPortBuffer);
596 if (pExynosComponent->pExynosPort[nPortIndex].bufferProcessType & BUFFER_COPY)
597 Exynos_OSAL_SemaphorePost(pExynosPort->codecSemID);
598 Exynos_OSAL_SemaphorePost(pExynosPort->bufferSemID);
600 pVideoDec->exynos_codec_bufferProcessRun(pOMXComponent, nPortIndex);
601 Exynos_OSAL_MutexLock(flushPortBuffer[0]->bufferMutex);
602 pVideoDec->exynos_codec_stop(pOMXComponent, nPortIndex);
603 Exynos_OSAL_MutexLock(flushPortBuffer[1]->bufferMutex);
604 ret = Exynos_OMX_FlushPort(pOMXComponent, nPortIndex);
606 if (pVideoDec->bDRCProcessing == OMX_TRUE) {
607 /* pVideoDec->bDRCProcess == OMX_TRUE
608 the case of dynamic resolution change */
609 pVideoDec->exynos_codec_resetupAllElement(pOMXComponent, nPortIndex);
610 } else if (pExynosComponent->pExynosPort[nPortIndex].bufferProcessType & BUFFER_COPY) {
611 pVideoDec->exynos_codec_enqueueAllBuffer(pOMXComponent, nPortIndex);
614 Exynos_ResetCodecData(&pExynosPort->processData);
616 if (ret == OMX_ErrorNone) {
617 if (nPortIndex == INPUT_PORT_INDEX) {
618 pExynosComponent->checkTimeStamp.needSetStartTimeStamp = OMX_TRUE;
619 pExynosComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_FALSE;
620 pExynosComponent->checkTimeStamp.bImmediateDisplay = OMX_FALSE;
621 Exynos_OSAL_Memset(pExynosComponent->timeStamp, -19771003, sizeof(OMX_TICKS) * MAX_TIMESTAMP);
622 Exynos_OSAL_Memset(pExynosComponent->nFlags, 0, sizeof(OMX_U32) * MAX_FLAGS);
623 pExynosComponent->getAllDelayBuffer = OMX_FALSE;
624 pExynosComponent->bSaveFlagEOS = OMX_FALSE;
625 pExynosComponent->reInputData = OMX_FALSE;
628 pExynosComponent->pExynosPort[nPortIndex].bIsPortFlushed = OMX_FALSE;
629 Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"OMX_CommandFlush EventCmdComplete, port:%d", nPortIndex);
630 if (bEvent == OMX_TRUE)
631 pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent,
632 pExynosComponent->callbackData,
633 OMX_EventCmdComplete,
634 OMX_CommandFlush, nPortIndex, NULL);
636 Exynos_OSAL_MutexUnlock(flushPortBuffer[1]->bufferMutex);
637 Exynos_OSAL_MutexUnlock(flushPortBuffer[0]->bufferMutex);
640 if ((ret != OMX_ErrorNone) && (pOMXComponent != NULL) && (pExynosComponent != NULL)) {
641 Exynos_OSAL_Log(EXYNOS_LOG_ERROR,"%s : %d", __FUNCTION__, __LINE__);
642 pExynosComponent->pCallbacks->EventHandler(pOMXComponent,
643 pExynosComponent->callbackData,
653 OMX_ERRORTYPE Exynos_InputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent)
655 OMX_ERRORTYPE ret = OMX_ErrorNone;
656 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
657 EXYNOS_OMX_BASEPORT *exynosOMXInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
658 EXYNOS_OMX_DATABUFFER *dataBuffer = NULL;
659 OMX_BUFFERHEADERTYPE *bufferHeader = NULL;
663 if (exynosOMXInputPort->bufferProcessType & BUFFER_COPY) {
664 dataBuffer = &(exynosOMXInputPort->way.port2WayDataBuffer.inputDataBuffer);
665 } else if (exynosOMXInputPort->bufferProcessType & BUFFER_SHARE) {
666 dataBuffer = &(exynosOMXInputPort->way.port2WayDataBuffer.outputDataBuffer);
669 bufferHeader = dataBuffer->bufferHeader;
671 if (bufferHeader != NULL) {
672 if (exynosOMXInputPort->markType.hMarkTargetComponent != NULL ) {
673 bufferHeader->hMarkTargetComponent = exynosOMXInputPort->markType.hMarkTargetComponent;
674 bufferHeader->pMarkData = exynosOMXInputPort->markType.pMarkData;
675 exynosOMXInputPort->markType.hMarkTargetComponent = NULL;
676 exynosOMXInputPort->markType.pMarkData = NULL;
679 if (bufferHeader->hMarkTargetComponent != NULL) {
680 if (bufferHeader->hMarkTargetComponent == pOMXComponent) {
681 pExynosComponent->pCallbacks->EventHandler(pOMXComponent,
682 pExynosComponent->callbackData,
684 0, 0, bufferHeader->pMarkData);
686 pExynosComponent->propagateMarkType.hMarkTargetComponent = bufferHeader->hMarkTargetComponent;
687 pExynosComponent->propagateMarkType.pMarkData = bufferHeader->pMarkData;
691 bufferHeader->nFilledLen = 0;
692 bufferHeader->nOffset = 0;
693 Exynos_OMX_InputBufferReturn(pOMXComponent, bufferHeader);
696 /* reset dataBuffer */
697 Exynos_ResetDataBuffer(dataBuffer);
705 OMX_ERRORTYPE Exynos_FlushInputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer)
707 OMX_ERRORTYPE ret = OMX_ErrorNone;
708 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
709 EXYNOS_OMX_BASEPORT *exynosOMXInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
710 OMX_BUFFERHEADERTYPE *bufferHeader = NULL;
714 bufferHeader = dataBuffer->bufferHeader;
716 if (bufferHeader != NULL) {
717 if (exynosOMXInputPort->markType.hMarkTargetComponent != NULL ) {
718 bufferHeader->hMarkTargetComponent = exynosOMXInputPort->markType.hMarkTargetComponent;
719 bufferHeader->pMarkData = exynosOMXInputPort->markType.pMarkData;
720 exynosOMXInputPort->markType.hMarkTargetComponent = NULL;
721 exynosOMXInputPort->markType.pMarkData = NULL;
724 if (bufferHeader->hMarkTargetComponent != NULL) {
725 if (bufferHeader->hMarkTargetComponent == pOMXComponent) {
726 pExynosComponent->pCallbacks->EventHandler(pOMXComponent,
727 pExynosComponent->callbackData,
729 0, 0, bufferHeader->pMarkData);
731 pExynosComponent->propagateMarkType.hMarkTargetComponent = bufferHeader->hMarkTargetComponent;
732 pExynosComponent->propagateMarkType.pMarkData = bufferHeader->pMarkData;
736 bufferHeader->nFilledLen = 0;
737 bufferHeader->nOffset = 0;
738 Exynos_OMX_InputBufferReturn(pOMXComponent, bufferHeader);
741 /* reset dataBuffer */
742 Exynos_ResetDataBuffer(dataBuffer);
750 OMX_ERRORTYPE Exynos_InputBufferGetQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent)
752 OMX_ERRORTYPE ret = OMX_ErrorUndefined;
753 EXYNOS_OMX_BASEPORT *pExynosPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
754 EXYNOS_OMX_MESSAGE *message = NULL;
755 EXYNOS_OMX_DATABUFFER *inputUseBuffer = NULL;
759 inputUseBuffer = &(pExynosPort->way.port2WayDataBuffer.inputDataBuffer);
761 if (pExynosComponent->currentState != OMX_StateExecuting) {
762 ret = OMX_ErrorUndefined;
764 } else if ((pExynosComponent->transientState != EXYNOS_OMX_TransStateExecutingToIdle) &&
765 (!CHECK_PORT_BEING_FLUSHED(pExynosPort))) {
766 Exynos_OSAL_SemaphoreWait(pExynosPort->bufferSemID);
767 if (inputUseBuffer->dataValid != OMX_TRUE) {
768 message = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ);
769 if (message == NULL) {
770 ret = OMX_ErrorUndefined;
773 if (message->messageType == EXYNOS_OMX_CommandFakeBuffer) {
774 Exynos_OSAL_Free(message);
775 ret = OMX_ErrorCodecFlush;
779 inputUseBuffer->bufferHeader = (OMX_BUFFERHEADERTYPE *)(message->pCmdData);
780 inputUseBuffer->allocSize = inputUseBuffer->bufferHeader->nAllocLen;
781 inputUseBuffer->dataLen = inputUseBuffer->bufferHeader->nFilledLen;
782 inputUseBuffer->remainDataLen = inputUseBuffer->dataLen;
783 inputUseBuffer->usedDataLen = 0;
784 inputUseBuffer->dataValid = OMX_TRUE;
785 inputUseBuffer->nFlags = inputUseBuffer->bufferHeader->nFlags;
786 inputUseBuffer->timeStamp = inputUseBuffer->bufferHeader->nTimeStamp;
788 Exynos_OSAL_Free(message);
791 if (inputUseBuffer->allocSize <= inputUseBuffer->dataLen)
792 Exynos_OSAL_Log(EXYNOS_LOG_WARNING, "Input Buffer Full, Check input buffer size! allocSize:%d, dataLen:%d", inputUseBuffer->allocSize, inputUseBuffer->dataLen);
803 OMX_ERRORTYPE Exynos_OutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent)
805 OMX_ERRORTYPE ret = OMX_ErrorNone;
806 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
807 EXYNOS_OMX_BASEPORT *exynosOMXOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
808 EXYNOS_OMX_DATABUFFER *dataBuffer = NULL;
809 OMX_BUFFERHEADERTYPE *bufferHeader = NULL;
813 dataBuffer = &(exynosOMXOutputPort->way.port2WayDataBuffer.outputDataBuffer);
814 bufferHeader = dataBuffer->bufferHeader;
816 if (bufferHeader != NULL) {
818 bufferHeader->nFilledLen = sizeof(MMVideoBuffer);
820 bufferHeader->nFilledLen = dataBuffer->remainDataLen;
822 bufferHeader->nOffset = 0;
823 bufferHeader->nFlags = dataBuffer->nFlags;
824 bufferHeader->nTimeStamp = dataBuffer->timeStamp;
826 Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"Exynos_OutputBufferReturn: nFilledLen: %d", bufferHeader->nFilledLen);
827 Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"Exynos_OutputBufferReturn: nFlags: %d", bufferHeader->nFlags);
828 Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"Exynos_OutputBufferReturn: nTimeStamp: %lld", bufferHeader->nTimeStamp);
830 if (pExynosComponent->propagateMarkType.hMarkTargetComponent != NULL) {
831 bufferHeader->hMarkTargetComponent = pExynosComponent->propagateMarkType.hMarkTargetComponent;
832 bufferHeader->pMarkData = pExynosComponent->propagateMarkType.pMarkData;
833 pExynosComponent->propagateMarkType.hMarkTargetComponent = NULL;
834 pExynosComponent->propagateMarkType.pMarkData = NULL;
837 if ((bufferHeader->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) {
838 bufferHeader->nFilledLen = 0;
839 Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"event OMX_BUFFERFLAG_EOS!!!");
840 pExynosComponent->pCallbacks->EventHandler(pOMXComponent,
841 pExynosComponent->callbackData,
844 bufferHeader->nFlags, NULL);
847 Exynos_OMX_OutputBufferReturn(pOMXComponent, bufferHeader);
849 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d bufferHeader is NULL! ", __FUNCTION__, __LINE__);
852 /* reset dataBuffer */
853 Exynos_ResetDataBuffer(dataBuffer);
861 OMX_ERRORTYPE Exynos_FlushOutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer)
863 OMX_ERRORTYPE ret = OMX_ErrorNone;
864 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
865 EXYNOS_OMX_BASEPORT *exynosOMXOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
866 OMX_BUFFERHEADERTYPE *bufferHeader = NULL;
870 bufferHeader = dataBuffer->bufferHeader;
872 if (bufferHeader != NULL) {
873 bufferHeader->nFilledLen = dataBuffer->remainDataLen;
874 bufferHeader->nOffset = 0;
875 bufferHeader->nFlags = dataBuffer->nFlags;
876 bufferHeader->nTimeStamp = dataBuffer->timeStamp;
878 if (pExynosComponent->propagateMarkType.hMarkTargetComponent != NULL) {
879 bufferHeader->hMarkTargetComponent = pExynosComponent->propagateMarkType.hMarkTargetComponent;
880 bufferHeader->pMarkData = pExynosComponent->propagateMarkType.pMarkData;
881 pExynosComponent->propagateMarkType.hMarkTargetComponent = NULL;
882 pExynosComponent->propagateMarkType.pMarkData = NULL;
885 if ((bufferHeader->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) {
886 bufferHeader->nFilledLen = 0;
887 Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"event OMX_BUFFERFLAG_EOS!!!");
888 pExynosComponent->pCallbacks->EventHandler(pOMXComponent,
889 pExynosComponent->callbackData,
892 bufferHeader->nFlags, NULL);
894 Exynos_OMX_OutputBufferReturn(pOMXComponent, bufferHeader);
897 /* reset dataBuffer */
898 Exynos_ResetDataBuffer(dataBuffer);
906 OMX_ERRORTYPE Exynos_OutputBufferGetQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent)
908 OMX_ERRORTYPE ret = OMX_ErrorUndefined;
909 EXYNOS_OMX_BASEPORT *pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
910 EXYNOS_OMX_MESSAGE *message = NULL;
911 EXYNOS_OMX_DATABUFFER *outputUseBuffer = NULL;
915 if (pExynosPort->bufferProcessType & BUFFER_COPY) {
916 outputUseBuffer = &(pExynosPort->way.port2WayDataBuffer.outputDataBuffer);
917 } else if (pExynosPort->bufferProcessType & BUFFER_SHARE) {
918 outputUseBuffer = &(pExynosPort->way.port2WayDataBuffer.inputDataBuffer);
921 if (pExynosComponent->currentState != OMX_StateExecuting) {
922 ret = OMX_ErrorUndefined;
924 } else if ((pExynosComponent->transientState != EXYNOS_OMX_TransStateExecutingToIdle) &&
925 (!CHECK_PORT_BEING_FLUSHED(pExynosPort))){
926 Exynos_OSAL_SemaphoreWait(pExynosPort->bufferSemID);
927 if (outputUseBuffer->dataValid != OMX_TRUE) {
928 message = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ);
929 if (message == NULL) {
930 ret = OMX_ErrorUndefined;
933 if (message->messageType == EXYNOS_OMX_CommandFakeBuffer) {
934 Exynos_OSAL_Free(message);
935 ret = OMX_ErrorCodecFlush;
939 outputUseBuffer->bufferHeader = (OMX_BUFFERHEADERTYPE *)(message->pCmdData);
940 outputUseBuffer->allocSize = outputUseBuffer->bufferHeader->nAllocLen;
941 outputUseBuffer->dataLen = 0; //dataBuffer->bufferHeader->nFilledLen;
942 outputUseBuffer->remainDataLen = outputUseBuffer->dataLen;
943 outputUseBuffer->usedDataLen = 0; //dataBuffer->bufferHeader->nOffset;
944 outputUseBuffer->dataValid = OMX_TRUE;
945 /* dataBuffer->nFlags = dataBuffer->bufferHeader->nFlags; */
946 /* dataBuffer->nTimeStamp = dataBuffer->bufferHeader->nTimeStamp; */
948 if (pExynosPort->bufferProcessType & BUFFER_SHARE)
949 outputUseBuffer->pPrivate = outputUseBuffer->bufferHeader->pOutputPortPrivate;
950 else if (pExynosPort->bufferProcessType & BUFFER_COPY) {
951 pExynosPort->processData.dataBuffer = outputUseBuffer->bufferHeader->pBuffer;
952 pExynosPort->processData.allocSize = outputUseBuffer->bufferHeader->nAllocLen;
956 Exynos_OSAL_Free(message);
967 OMX_BUFFERHEADERTYPE *Exynos_OutputBufferGetQueue_Direct(EXYNOS_OMX_BASECOMPONENT *pExynosComponent)
969 OMX_BUFFERHEADERTYPE *retBuffer = NULL;
970 EXYNOS_OMX_BASEPORT *pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
971 EXYNOS_OMX_MESSAGE *message = NULL;
975 if (pExynosComponent->currentState != OMX_StateExecuting) {
978 } else if ((pExynosComponent->transientState != EXYNOS_OMX_TransStateExecutingToIdle) &&
979 (!CHECK_PORT_BEING_FLUSHED(pExynosPort))){
980 Exynos_OSAL_SemaphoreWait(pExynosPort->bufferSemID);
982 message = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ);
983 if (message == NULL) {
987 if (message->messageType == EXYNOS_OMX_CommandFakeBuffer) {
988 Exynos_OSAL_Free(message);
993 retBuffer = (OMX_BUFFERHEADERTYPE *)(message->pCmdData);
994 Exynos_OSAL_Free(message);
1003 OMX_ERRORTYPE Exynos_CodecBufferEnQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 PortIndex, OMX_PTR data)
1005 OMX_ERRORTYPE ret = OMX_ErrorNone;
1006 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1010 pExynosPort= &pExynosComponent->pExynosPort[PortIndex];
1013 ret = OMX_ErrorInsufficientResources;
1018 if (pExynosPort == NULL) {
1019 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d: pExynosPort is NULL", __FUNCTION__, __LINE__);
1023 ret = Exynos_OSAL_Queue(&pExynosPort->codecBufferQ, (void *)data);
1025 ret = OMX_ErrorUndefined;
1028 Exynos_OSAL_SemaphorePost(pExynosPort->codecSemID);
1030 ret = OMX_ErrorNone;
1038 OMX_ERRORTYPE Exynos_CodecBufferDeQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 PortIndex, OMX_PTR *data)
1040 OMX_ERRORTYPE ret = OMX_ErrorNone;
1041 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1046 pExynosPort = &pExynosComponent->pExynosPort[PortIndex];
1047 Exynos_OSAL_SemaphoreWait(pExynosPort->codecSemID);
1048 tempData = (OMX_U32)Exynos_OSAL_Dequeue(&pExynosPort->codecBufferQ);
1049 if (tempData == NULL) {
1051 ret = OMX_ErrorUndefined;
1054 *data = (OMX_PTR)tempData;
1056 ret = OMX_ErrorNone;
1064 OMX_ERRORTYPE Exynos_CodecBufferReset(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 PortIndex)
1066 OMX_ERRORTYPE ret = OMX_ErrorNone;
1067 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1071 pExynosPort= &pExynosComponent->pExynosPort[PortIndex];
1073 ret = Exynos_OSAL_ResetQueue(&pExynosPort->codecBufferQ);
1075 ret = OMX_ErrorUndefined;
1080 Exynos_OSAL_Get_SemaphoreCount(pExynosPort->codecSemID, &cnt);
1082 Exynos_OSAL_SemaphoreWait(pExynosPort->codecSemID);
1086 ret = OMX_ErrorNone;
1094 OMX_ERRORTYPE Exynos_OMX_VideoDecodeGetParameter(
1095 OMX_IN OMX_HANDLETYPE hComponent,
1096 OMX_IN OMX_INDEXTYPE nParamIndex,
1097 OMX_INOUT OMX_PTR ComponentParameterStructure)
1099 OMX_ERRORTYPE ret = OMX_ErrorNone;
1100 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1101 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1102 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1106 if (hComponent == NULL) {
1107 ret = OMX_ErrorBadParameter;
1110 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1111 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1112 if (ret != OMX_ErrorNone) {
1116 if (pOMXComponent->pComponentPrivate == NULL) {
1117 ret = OMX_ErrorBadParameter;
1120 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1122 if (pExynosComponent->currentState == OMX_StateInvalid ) {
1123 ret = OMX_ErrorInvalidState;
1127 if (ComponentParameterStructure == NULL) {
1128 ret = OMX_ErrorBadParameter;
1132 switch (nParamIndex) {
1133 case OMX_IndexParamVideoInit:
1135 OMX_PORT_PARAM_TYPE *portParam = (OMX_PORT_PARAM_TYPE *)ComponentParameterStructure;
1136 ret = Exynos_OMX_Check_SizeVersion(portParam, sizeof(OMX_PORT_PARAM_TYPE));
1137 if (ret != OMX_ErrorNone) {
1141 portParam->nPorts = pExynosComponent->portParam.nPorts;
1142 portParam->nStartPortNumber = pExynosComponent->portParam.nStartPortNumber;
1143 ret = OMX_ErrorNone;
1146 case OMX_IndexParamVideoPortFormat:
1148 OMX_VIDEO_PARAM_PORTFORMATTYPE *portFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)ComponentParameterStructure;
1149 OMX_U32 portIndex = portFormat->nPortIndex;
1150 OMX_U32 index = portFormat->nIndex;
1151 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1152 OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = NULL;
1153 OMX_U32 supportFormatNum = 0; /* supportFormatNum = N-1 */
1155 ret = Exynos_OMX_Check_SizeVersion(portFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
1156 if (ret != OMX_ErrorNone) {
1160 if ((portIndex >= pExynosComponent->portParam.nPorts)) {
1161 ret = OMX_ErrorBadPortIndex;
1166 if (portIndex == INPUT_PORT_INDEX) {
1167 supportFormatNum = INPUT_PORT_SUPPORTFORMAT_NUM_MAX - 1;
1168 if (index > supportFormatNum) {
1169 ret = OMX_ErrorNoMore;
1173 pExynosPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
1174 portDefinition = &pExynosPort->portDefinition;
1176 portFormat->eCompressionFormat = portDefinition->format.video.eCompressionFormat;
1177 portFormat->eColorFormat = portDefinition->format.video.eColorFormat;
1178 portFormat->xFramerate = portDefinition->format.video.xFramerate;
1179 } else if (portIndex == OUTPUT_PORT_INDEX) {
1180 pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
1181 portDefinition = &pExynosPort->portDefinition;
1184 case supportFormat_0:
1185 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
1186 portFormat->eColorFormat = OMX_COLOR_FormatYUV420Planar;
1187 portFormat->xFramerate = portDefinition->format.video.xFramerate;
1189 case supportFormat_1:
1190 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
1191 portFormat->eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
1192 portFormat->xFramerate = portDefinition->format.video.xFramerate;
1194 case supportFormat_2:
1195 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
1196 portFormat->eColorFormat = OMX_SEC_COLOR_FormatNV12Tiled;
1197 portFormat->xFramerate = portDefinition->format.video.xFramerate;
1200 case supportFormat_3:
1201 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
1202 portFormat->eColorFormat = OMX_SEC_COLOR_FormatNV12T_DmaBuf_Fd;
1203 portFormat->xFramerate = portDefinition->format.video.xFramerate;
1207 if (index > supportFormat_0) {
1208 ret = OMX_ErrorNoMore;
1214 ret = OMX_ErrorNone;
1218 case OMX_IndexParamGetAndroidNativeBuffer:
1220 ret = Exynos_OSAL_GetPBParameter(hComponent, nParamIndex, ComponentParameterStructure);
1226 ret = Exynos_OMX_GetParameter(hComponent, nParamIndex, ComponentParameterStructure);
1236 OMX_ERRORTYPE Exynos_OMX_VideoDecodeSetParameter(
1237 OMX_IN OMX_HANDLETYPE hComponent,
1238 OMX_IN OMX_INDEXTYPE nIndex,
1239 OMX_IN OMX_PTR ComponentParameterStructure)
1241 OMX_ERRORTYPE ret = OMX_ErrorNone;
1242 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1243 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1244 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1248 if (hComponent == NULL) {
1249 ret = OMX_ErrorBadParameter;
1252 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1253 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1254 if (ret != OMX_ErrorNone) {
1258 if (pOMXComponent->pComponentPrivate == NULL) {
1259 ret = OMX_ErrorBadParameter;
1262 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1264 if (pExynosComponent->currentState == OMX_StateInvalid ) {
1265 ret = OMX_ErrorInvalidState;
1269 if (ComponentParameterStructure == NULL) {
1270 ret = OMX_ErrorBadParameter;
1275 case OMX_IndexParamVideoPortFormat:
1277 OMX_VIDEO_PARAM_PORTFORMATTYPE *portFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)ComponentParameterStructure;
1278 OMX_U32 portIndex = portFormat->nPortIndex;
1279 OMX_U32 index = portFormat->nIndex;
1280 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1281 OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = NULL;
1282 OMX_U32 supportFormatNum = 0;
1284 ret = Exynos_OMX_Check_SizeVersion(portFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
1285 if (ret != OMX_ErrorNone) {
1289 if ((portIndex >= pExynosComponent->portParam.nPorts)) {
1290 ret = OMX_ErrorBadPortIndex;
1293 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
1294 portDefinition = &pExynosPort->portDefinition;
1296 portDefinition->format.video.eColorFormat = portFormat->eColorFormat;
1297 portDefinition->format.video.eCompressionFormat = portFormat->eCompressionFormat;
1298 portDefinition->format.video.xFramerate = portFormat->xFramerate;
1304 case OMX_IndexParamEnablePlatformSpecificBuffers:
1306 case OMX_IndexParamEnableAndroidBuffers:
1308 case OMX_IndexParamUseAndroidNativeBuffer:
1310 ret = Exynos_OSAL_SetPBParameter(hComponent, nIndex, ComponentParameterStructure);
1316 case OMX_IndexParamEnableTimestampReorder:
1318 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
1319 pVideoDec->bNeedTimestampReorder = OMX_TRUE;
1325 ret = Exynos_OMX_SetParameter(hComponent, nIndex, ComponentParameterStructure);
1336 OMX_ERRORTYPE Exynos_OMX_VideoDecodeGetConfig(
1337 OMX_HANDLETYPE hComponent,
1338 OMX_INDEXTYPE nIndex,
1339 OMX_PTR pComponentConfigStructure)
1341 OMX_ERRORTYPE ret = OMX_ErrorNone;
1342 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1343 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1347 if (hComponent == NULL) {
1348 ret = OMX_ErrorBadParameter;
1351 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1352 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1353 if (ret != OMX_ErrorNone) {
1356 if (pOMXComponent->pComponentPrivate == NULL) {
1357 ret = OMX_ErrorBadParameter;
1360 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1361 if (pComponentConfigStructure == NULL) {
1362 ret = OMX_ErrorBadParameter;
1365 if (pExynosComponent->currentState == OMX_StateInvalid) {
1366 ret = OMX_ErrorInvalidState;
1372 ret = Exynos_OMX_GetConfig(hComponent, nIndex, pComponentConfigStructure);
1382 OMX_ERRORTYPE Exynos_OMX_VideoDecodeSetConfig(
1383 OMX_HANDLETYPE hComponent,
1384 OMX_INDEXTYPE nIndex,
1385 OMX_PTR pComponentConfigStructure)
1387 OMX_ERRORTYPE ret = OMX_ErrorNone;
1388 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1389 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1393 if (hComponent == NULL) {
1394 ret = OMX_ErrorBadParameter;
1397 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1398 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1399 if (ret != OMX_ErrorNone) {
1402 if (pOMXComponent->pComponentPrivate == NULL) {
1403 ret = OMX_ErrorBadParameter;
1406 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1407 if (pComponentConfigStructure == NULL) {
1408 ret = OMX_ErrorBadParameter;
1411 if (pExynosComponent->currentState == OMX_StateInvalid) {
1412 ret = OMX_ErrorInvalidState;
1417 case OMX_IndexVendorThumbnailMode:
1419 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
1420 pVideoDec->bThumbnailMode = *((OMX_BOOL *)pComponentConfigStructure);
1422 ret = OMX_ErrorNone;
1426 ret = Exynos_OMX_SetConfig(hComponent, nIndex, pComponentConfigStructure);
1436 OMX_ERRORTYPE Exynos_OMX_VideoDecodeGetExtensionIndex(
1437 OMX_IN OMX_HANDLETYPE hComponent,
1438 OMX_IN OMX_STRING cParameterName,
1439 OMX_OUT OMX_INDEXTYPE *pIndexType)
1441 OMX_ERRORTYPE ret = OMX_ErrorNone;
1442 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1443 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1447 if (hComponent == NULL) {
1448 ret = OMX_ErrorBadParameter;
1451 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1452 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1453 if (ret != OMX_ErrorNone) {
1457 if (pOMXComponent->pComponentPrivate == NULL) {
1458 ret = OMX_ErrorBadParameter;
1461 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1463 if ((cParameterName == NULL) || (pIndexType == NULL)) {
1464 ret = OMX_ErrorBadParameter;
1467 if (pExynosComponent->currentState == OMX_StateInvalid) {
1468 ret = OMX_ErrorInvalidState;
1474 if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_ENABLE_PB) == 0)
1475 *pIndexType = (OMX_INDEXTYPE) OMX_IndexParamEnablePlatformSpecificBuffers;
1476 else if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_ENABLE_TS_REORDER) == 0)
1477 *pIndexType = (OMX_INDEXTYPE) OMX_IndexParamEnableTimestampReorder;
1479 if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_ENABLE_ANB) == 0)
1480 *pIndexType = (OMX_INDEXTYPE) OMX_IndexParamEnableAndroidBuffers;
1482 else if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_GET_ANB) == 0)
1483 *pIndexType = (OMX_INDEXTYPE) OMX_IndexParamGetAndroidNativeBuffer;
1484 else if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_USE_ANB) == 0)
1485 *pIndexType = (OMX_INDEXTYPE) OMX_IndexParamUseAndroidNativeBuffer;
1487 ret = Exynos_OMX_GetExtensionIndex(hComponent, cParameterName, pIndexType);
1489 ret = Exynos_OMX_GetExtensionIndex(hComponent, cParameterName, pIndexType);
1498 #ifdef USE_PB /* this is from FillThisBuffer */
1499 OMX_ERRORTYPE Exynos_Shared_PlatformBufferToData(EXYNOS_OMX_DATABUFFER *pUseBuffer, EXYNOS_OMX_DATA *pData, EXYNOS_OMX_BASEPORT *pExynosPort, EXYNOS_OMX_PLANE nPlane)
1501 OMX_ERRORTYPE ret = OMX_ErrorNone;
1502 OMX_U32 width, height;
1503 // void *pPhys[MAX_BUFFER_PLANE];
1504 ExynosVideoPlane planes[MAX_BUFFER_PLANE];
1508 memset(planes, 0, sizeof(planes));
1510 if (pExynosPort->bIsPBEnabled == OMX_TRUE) {
1513 width = pExynosPort->portDefinition.format.video.nFrameWidth;
1514 height = pExynosPort->portDefinition.format.video.nFrameHeight;
1515 if ((pUseBuffer->bufferHeader != NULL) && (pUseBuffer->bufferHeader->pBuffer != NULL)) {
1516 Exynos_OSAL_LockPB(pUseBuffer->bufferHeader->pBuffer, width, height, pExynosPort->portDefinition.format.video.eColorFormat, &stride, planes);
1517 pUseBuffer->dataLen = sizeof(void *);
1519 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__);
1520 ret = OMX_ErrorBadParameter;
1524 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__);
1525 ret = OMX_ErrorBadParameter;
1529 if (nPlane == TWO_PLANE) {
1530 /* Case of Shared Buffer, Only support two PlaneBuffer */
1531 pData->buffer.multiPlaneBuffer.dataBuffer[0] = planes[0].addr;
1532 pData->buffer.multiPlaneBuffer.dataBuffer[1] = planes[1].addr;
1534 pData->buffer.multiPlaneBuffer.fd[0] = planes[0].fd;
1535 pData->buffer.multiPlaneBuffer.fd[1] = planes[1].fd;
1538 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Can not support plane");
1539 ret = OMX_ErrorNotImplemented;
1543 pData->allocSize = pUseBuffer->allocSize;
1544 pData->dataLen = pUseBuffer->dataLen;
1545 pData->usedDataLen = pUseBuffer->usedDataLen;
1546 pData->remainDataLen = pUseBuffer->remainDataLen;
1547 pData->timeStamp = pUseBuffer->timeStamp;
1548 pData->nFlags = pUseBuffer->nFlags;
1549 pData->pPrivate = pUseBuffer->pPrivate;
1550 pData->bufferHeader = pUseBuffer->bufferHeader;
1557 /* this is for Fill This Buffer Done */
1559 OMX_ERRORTYPE Exynos_Shared_DataToPlatformBuffer(EXYNOS_OMX_DATA *pData, EXYNOS_OMX_DATABUFFER *pUseBuffer, EXYNOS_OMX_BASEPORT *pExynosPort, EXYNOS_OMX_BASEPORT *pExynosInPort)
1561 OMX_ERRORTYPE Exynos_Shared_DataToPlatformBuffer(EXYNOS_OMX_DATA *pData, EXYNOS_OMX_DATABUFFER *pUseBuffer, EXYNOS_OMX_BASEPORT *pExynosPort)
1564 OMX_ERRORTYPE ret = OMX_ErrorNone;
1568 pUseBuffer->bufferHeader = pData->bufferHeader;
1569 pUseBuffer->allocSize = pData->allocSize;
1571 pUseBuffer->dataLen = sizeof(MMVideoBuffer);
1573 pUseBuffer->dataLen = pData->dataLen;
1575 pUseBuffer->usedDataLen = pData->usedDataLen;
1576 pUseBuffer->remainDataLen = pData->remainDataLen;
1577 pUseBuffer->timeStamp = pData->timeStamp;
1578 pUseBuffer->nFlags = pData->nFlags;
1579 pUseBuffer->pPrivate = pData->pPrivate;
1581 if ((pUseBuffer->bufferHeader == NULL) ||
1582 (pUseBuffer->bufferHeader->pBuffer == NULL)) {
1583 Exynos_OSAL_Log(EXYNOS_LOG_VERVOSE, "pUseBuffer->bufferHeader or pUseBuffer->bufferHeader->pBuffer is NULL");
1584 ret = OMX_ErrorUndefined;
1588 if (pExynosPort->bIsPBEnabled == OMX_TRUE) {
1590 Exynos_OSAL_UnlockPB(pUseBuffer->bufferHeader->pBuffer, pData, pExynosPort,pExynosInPort);
1592 Exynos_OSAL_UnlockPB(pUseBuffer->bufferHeader->pBuffer, pData);
1595 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__);
1596 ret = OMX_ErrorBadParameter;