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 pExynosPort->extendBufferHeader[i].tbm_bo[0] = pSlpOutBuf->handle.bo[0];
141 pExynosPort->extendBufferHeader[i].tbm_bo[1] = pSlpOutBuf->handle.bo[1];
142 pExynosPort->extendBufferHeader[i].tbm_bo[2] = NULL;
144 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "\nPlatformBuffer: buf %d pYUVBuf[0]:0x%x , pYUVBuf[1]:0x%x ",
145 i, pExynosPort->extendBufferHeader[i].pYUVBuf[0], pExynosPort->extendBufferHeader[i].pYUVBuf[1]);
146 } else if ((pVideoDec->bDRMPlayerMode == OMX_TRUE) && (nPortIndex == INPUT_PORT_INDEX)) {
147 pExynosPort->extendBufferHeader[i].buf_fd[0] = pBuffer;
148 } else if(nPortIndex == INPUT_PORT_INDEX){
149 MMVideoBuffer * pSlpOutBuf = (MMVideoBuffer *)pBuffer;
150 temp_bufferHeader->pBuffer = pSlpOutBuf->data[0];
152 pExynosPort->extendBufferHeader[i].buf_fd[0] = pBuffer;
153 SCMN_IMGB * pSlpOutBuf = (SCMN_IMGB *)pBuffer;
154 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "fd[0] =%d, vaddr[0] =%p, , length=%d",
155 pSlpOutBuf->fd[0], pSlpOutBuf->a[0], nSizeBytes);
157 pExynosPort->extendBufferHeader[i].buf_fd[0] = pSlpOutBuf->fd[0];
158 pExynosPort->extendBufferHeader[i].buf_fd[1] = 0;
159 pExynosPort->extendBufferHeader[i].buf_fd[2] = 0;
161 pExynosPort->extendBufferHeader[i].pYUVBuf[0] = pSlpOutBuf->a[0];
162 pExynosPort->extendBufferHeader[i].pYUVBuf[1] = NULL;
163 pExynosPort->extendBufferHeader[i].pYUVBuf[2] = NULL;
165 temp_bufferHeader->pBuffer = pSlpOutBuf->a[0];
169 *ppBufferHdr = temp_bufferHeader;
170 pExynosPort->assignedBufferNum++;
171 if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) {
172 pExynosPort->portDefinition.bPopulated = OMX_TRUE;
173 /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */
174 Exynos_OSAL_SemaphorePost(pExynosPort->loadedResource);
175 /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */
182 Exynos_OSAL_Free(temp_bufferHeader);
183 ret = OMX_ErrorInsufficientResources;
191 OMX_ERRORTYPE Exynos_OMX_AllocateBuffer(
192 OMX_IN OMX_HANDLETYPE hComponent,
193 OMX_INOUT OMX_BUFFERHEADERTYPE **ppBuffer,
194 OMX_IN OMX_U32 nPortIndex,
195 OMX_IN OMX_PTR pAppPrivate,
196 OMX_IN OMX_U32 nSizeBytes)
198 OMX_ERRORTYPE ret = OMX_ErrorNone;
199 OMX_COMPONENTTYPE *pOMXComponent = NULL;
200 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
201 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
202 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
203 OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL;
204 OMX_U8 *temp_buffer = NULL;
205 int temp_buffer_fd = -1;
207 MEMORY_TYPE mem_type;
211 if (hComponent == NULL) {
212 ret = OMX_ErrorBadParameter;
215 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
216 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
217 if (ret != OMX_ErrorNone) {
221 if (pOMXComponent->pComponentPrivate == NULL) {
222 ret = OMX_ErrorBadParameter;
225 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
226 pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
228 pExynosPort = &pExynosComponent->pExynosPort[nPortIndex];
229 if (nPortIndex >= pExynosComponent->portParam.nPorts) {
230 ret = OMX_ErrorBadPortIndex;
234 if (pExynosPort->portState != OMX_StateIdle ) {
235 ret = OMX_ErrorIncorrectStateOperation;
239 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
240 ret = OMX_ErrorBadPortIndex;
244 if ((pVideoDec->bDRMPlayerMode == OMX_TRUE) && (nPortIndex == INPUT_PORT_INDEX)) {
245 mem_type = SECURE_MEMORY;
246 } else if (pExynosPort->bufferProcessType & BUFFER_SHARE) {
247 mem_type = NORMAL_MEMORY;
249 mem_type = SYSTEM_MEMORY;
251 temp_buffer = Exynos_OSAL_SharedMemory_Alloc(pVideoDec->hSharedMemory, nSizeBytes, mem_type);
252 if (temp_buffer == NULL) {
253 ret = OMX_ErrorInsufficientResources;
256 temp_buffer_fd = Exynos_OSAL_SharedMemory_VirtToION(pVideoDec->hSharedMemory, temp_buffer);
258 temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE));
259 if (temp_bufferHeader == NULL) {
260 Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, temp_buffer);
261 ret = OMX_ErrorInsufficientResources;
264 Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
266 for (i = 0; i < pExynosPort->portDefinition.nBufferCountActual; i++) {
267 if (pExynosPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) {
268 pExynosPort->extendBufferHeader[i].OMXBufferHeader = temp_bufferHeader;
269 pExynosPort->extendBufferHeader[i].buf_fd[0] = temp_buffer_fd;
270 pExynosPort->bufferStateAllocate[i] = (BUFFER_STATE_ALLOCATED | HEADER_STATE_ALLOCATED);
271 INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE);
272 if (mem_type == SECURE_MEMORY)
273 temp_bufferHeader->pBuffer = temp_buffer_fd;
275 temp_bufferHeader->pBuffer = temp_buffer;
276 temp_bufferHeader->nAllocLen = nSizeBytes;
277 temp_bufferHeader->pAppPrivate = pAppPrivate;
278 if (nPortIndex == INPUT_PORT_INDEX)
279 temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX;
281 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX;
282 pExynosPort->assignedBufferNum++;
283 if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) {
284 pExynosPort->portDefinition.bPopulated = OMX_TRUE;
285 /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */
286 Exynos_OSAL_SemaphorePost(pExynosPort->loadedResource);
287 /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */
289 *ppBuffer = temp_bufferHeader;
295 Exynos_OSAL_Free(temp_bufferHeader);
296 Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, temp_buffer);
298 ret = OMX_ErrorInsufficientResources;
306 OMX_ERRORTYPE Exynos_OMX_FreeBuffer(
307 OMX_IN OMX_HANDLETYPE hComponent,
308 OMX_IN OMX_U32 nPortIndex,
309 OMX_IN OMX_BUFFERHEADERTYPE *pBufferHdr)
311 OMX_ERRORTYPE ret = OMX_ErrorNone;
312 OMX_COMPONENTTYPE *pOMXComponent = NULL;
313 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
314 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
315 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
316 OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL;
317 OMX_U8 *temp_buffer = NULL;
322 if (hComponent == NULL) {
323 ret = OMX_ErrorBadParameter;
326 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
327 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
328 if (ret != OMX_ErrorNone) {
332 if (pOMXComponent->pComponentPrivate == NULL) {
333 ret = OMX_ErrorBadParameter;
336 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
337 pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
338 pExynosPort = &pExynosComponent->pExynosPort[nPortIndex];
340 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
341 ret = OMX_ErrorBadPortIndex;
345 if ((pExynosPort->portState != OMX_StateLoaded) && (pExynosPort->portState != OMX_StateInvalid)) {
346 (*(pExynosComponent->pCallbacks->EventHandler)) (pOMXComponent,
347 pExynosComponent->callbackData,
348 (OMX_U32)OMX_EventError,
349 (OMX_U32)OMX_ErrorPortUnpopulated,
353 for (i = 0; i < /*pExynosPort->portDefinition.nBufferCountActual*/MAX_BUFFER_NUM; i++) {
354 if (((pExynosPort->bufferStateAllocate[i] | BUFFER_STATE_FREE) != 0) && (pExynosPort->extendBufferHeader[i].OMXBufferHeader != NULL)) {
355 if (pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer == pBufferHdr->pBuffer) {
356 if (pExynosPort->bufferStateAllocate[i] & BUFFER_STATE_ALLOCATED) {
357 if ((pVideoDec->bDRMPlayerMode == OMX_TRUE) && (nPortIndex == INPUT_PORT_INDEX)) {
358 OMX_PTR mapBuffer = Exynos_OSAL_SharedMemory_IONToVirt(pVideoDec->hSharedMemory, (int)pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer);
359 Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, mapBuffer);
361 Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer);
363 pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer = NULL;
364 pBufferHdr->pBuffer = NULL;
365 } else if (pExynosPort->bufferStateAllocate[i] & BUFFER_STATE_ASSIGNED) {
368 pExynosPort->assignedBufferNum--;
369 if (pExynosPort->bufferStateAllocate[i] & HEADER_STATE_ALLOCATED) {
370 Exynos_OSAL_Free(pExynosPort->extendBufferHeader[i].OMXBufferHeader);
371 pExynosPort->extendBufferHeader[i].OMXBufferHeader = NULL;
374 pExynosPort->bufferStateAllocate[i] = BUFFER_STATE_FREE;
382 if (ret == OMX_ErrorNone) {
383 if (pExynosPort->assignedBufferNum == 0) {
384 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pExynosPort->unloadedResource signal set");
385 /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */
386 Exynos_OSAL_SemaphorePost(pExynosPort->unloadedResource);
387 /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */
388 pExynosPort->portDefinition.bPopulated = OMX_FALSE;
397 OMX_ERRORTYPE Exynos_OMX_AllocateTunnelBuffer(EXYNOS_OMX_BASEPORT *pOMXBasePort, OMX_U32 nPortIndex)
399 OMX_ERRORTYPE ret = OMX_ErrorNone;
400 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
401 OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL;
402 OMX_U8 *temp_buffer = NULL;
403 OMX_U32 bufferSize = 0;
404 OMX_PARAM_PORTDEFINITIONTYPE portDefinition;
406 ret = OMX_ErrorTunnelingUnsupported;
411 OMX_ERRORTYPE Exynos_OMX_FreeTunnelBuffer(EXYNOS_OMX_BASEPORT *pOMXBasePort, OMX_U32 nPortIndex)
413 OMX_ERRORTYPE ret = OMX_ErrorNone;
414 EXYNOS_OMX_BASEPORT* pExynosPort = NULL;
415 OMX_BUFFERHEADERTYPE* temp_bufferHeader = NULL;
416 OMX_U8 *temp_buffer = NULL;
417 OMX_U32 bufferSize = 0;
419 ret = OMX_ErrorTunnelingUnsupported;
424 OMX_ERRORTYPE Exynos_OMX_ComponentTunnelRequest(
425 OMX_IN OMX_HANDLETYPE hComp,
426 OMX_IN OMX_U32 nPort,
427 OMX_IN OMX_HANDLETYPE hTunneledComp,
428 OMX_IN OMX_U32 nTunneledPort,
429 OMX_INOUT OMX_TUNNELSETUPTYPE *pTunnelSetup)
431 OMX_ERRORTYPE ret = OMX_ErrorNone;
433 ret = OMX_ErrorTunnelingUnsupported;
438 OMX_ERRORTYPE Exynos_OMX_GetFlushBuffer(EXYNOS_OMX_BASEPORT *pExynosPort, EXYNOS_OMX_DATABUFFER *pDataBuffer[])
440 OMX_ERRORTYPE ret = OMX_ErrorNone;
446 if (pExynosPort->portWayType == WAY1_PORT) {
447 *pDataBuffer = &pExynosPort->way.port1WayDataBuffer.dataBuffer;
448 } else if (pExynosPort->portWayType == WAY2_PORT) {
449 pDataBuffer[0] = &(pExynosPort->way.port2WayDataBuffer.inputDataBuffer);
450 pDataBuffer[1] = &(pExynosPort->way.port2WayDataBuffer.outputDataBuffer);
459 OMX_ERRORTYPE Exynos_OMX_FlushPort(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 portIndex)
461 OMX_ERRORTYPE ret = OMX_ErrorNone;
462 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
463 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
464 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
465 OMX_BUFFERHEADERTYPE *bufferHeader = NULL;
466 EXYNOS_OMX_DATABUFFER *pDataPortBuffer[2] = {NULL, NULL};
467 EXYNOS_OMX_MESSAGE *message = NULL;
468 OMX_U32 flushNum = 0;
469 OMX_S32 semValue = 0;
470 int i = 0, maxBufferNum = 0;
473 Exynos_OSAL_Log(EXYNOS_LOG_WARNING, "flushPort idx:%d", portIndex);
476 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
478 while (Exynos_OSAL_GetElemNum(&pExynosPort->bufferQ) > 0) {
479 Exynos_OSAL_Get_SemaphoreCount(pExynosComponent->pExynosPort[portIndex].bufferSemID, &semValue);
481 Exynos_OSAL_SemaphorePost(pExynosComponent->pExynosPort[portIndex].bufferSemID);
483 Exynos_OSAL_SemaphoreWait(pExynosComponent->pExynosPort[portIndex].bufferSemID);
484 message = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ);
485 if ((message != NULL) && (message->messageType != EXYNOS_OMX_CommandFakeBuffer)) {
486 bufferHeader = (OMX_BUFFERHEADERTYPE *)message->pCmdData;
487 bufferHeader->nFilledLen = 0;
489 if (portIndex == OUTPUT_PORT_INDEX) {
490 Exynos_OMX_OutputBufferReturn(pOMXComponent, bufferHeader);
491 } else if (portIndex == INPUT_PORT_INDEX) {
492 Exynos_OMX_InputBufferReturn(pOMXComponent, bufferHeader);
495 Exynos_OSAL_Free(message);
499 Exynos_OMX_GetFlushBuffer(pExynosPort, pDataPortBuffer);
500 if (portIndex == INPUT_PORT_INDEX) {
501 if (pDataPortBuffer[0]->dataValid == OMX_TRUE)
502 Exynos_FlushInputBufferReturn(pOMXComponent, pDataPortBuffer[0]);
503 if (pDataPortBuffer[1]->dataValid == OMX_TRUE)
504 Exynos_FlushInputBufferReturn(pOMXComponent, pDataPortBuffer[1]);
505 } else if (portIndex == OUTPUT_PORT_INDEX) {
506 if (pDataPortBuffer[0]->dataValid == OMX_TRUE)
507 Exynos_FlushOutputBufferReturn(pOMXComponent, pDataPortBuffer[0]);
508 if (pDataPortBuffer[1]->dataValid == OMX_TRUE)
509 Exynos_FlushOutputBufferReturn(pOMXComponent, pDataPortBuffer[1]);
512 if (pExynosComponent->bMultiThreadProcess == OMX_TRUE) {
513 if (pExynosPort->bufferProcessType & BUFFER_SHARE) {
514 if (pExynosPort->processData.bufferHeader != NULL) {
515 if (portIndex == INPUT_PORT_INDEX) {
516 Exynos_OMX_InputBufferReturn(pOMXComponent, pExynosPort->processData.bufferHeader);
517 } else if (portIndex == OUTPUT_PORT_INDEX) {
518 Exynos_OMX_OutputBufferReturn(pOMXComponent, pExynosPort->processData.bufferHeader);
521 Exynos_ResetCodecData(&pExynosPort->processData);
523 if (pVideoDec->bDRCProcessing == OMX_TRUE)
524 maxBufferNum = pVideoDec->nDRCSavedBufferCount;
526 maxBufferNum = pExynosPort->portDefinition.nBufferCountActual;
528 for (i = 0; i < maxBufferNum; i++) {
529 if (pExynosPort->extendBufferHeader[i].bBufferInOMX == OMX_TRUE) {
530 if (portIndex == OUTPUT_PORT_INDEX) {
531 Exynos_OMX_OutputBufferReturn(pOMXComponent, pExynosPort->extendBufferHeader[i].OMXBufferHeader);
532 } else if (portIndex == INPUT_PORT_INDEX) {
533 Exynos_OMX_InputBufferReturn(pOMXComponent, pExynosPort->extendBufferHeader[i].OMXBufferHeader);
539 Exynos_ResetCodecData(&pExynosPort->processData);
544 Exynos_OSAL_Get_SemaphoreCount(pExynosComponent->pExynosPort[portIndex].bufferSemID, &cnt);
547 Exynos_OSAL_SemaphoreWait(pExynosComponent->pExynosPort[portIndex].bufferSemID);
549 Exynos_OSAL_ResetQueue(&pExynosPort->bufferQ);
557 OMX_ERRORTYPE Exynos_OMX_BufferFlush(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex, OMX_BOOL bEvent)
559 OMX_ERRORTYPE ret = OMX_ErrorNone;
560 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
561 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
562 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
563 EXYNOS_OMX_DATABUFFER *flushPortBuffer[2] = {NULL, NULL};
564 OMX_U32 i = 0, cnt = 0;
568 Exynos_OSAL_Log(EXYNOS_LOG_WARNING, "bufferFlush idx:%d", nPortIndex);
571 if (pOMXComponent == NULL) {
572 ret = OMX_ErrorBadParameter;
575 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
576 if (ret != OMX_ErrorNone) {
580 if (pOMXComponent->pComponentPrivate == NULL) {
581 ret = OMX_ErrorBadParameter;
584 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
585 pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
587 Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"OMX_CommandFlush start, port:%d", nPortIndex);
589 pExynosComponent->pExynosPort[nPortIndex].bIsPortFlushed = OMX_TRUE;
591 if (pExynosComponent->bMultiThreadProcess == OMX_FALSE) {
592 Exynos_OSAL_SignalSet(pExynosComponent->pauseEvent);
594 Exynos_OSAL_SignalSet(pExynosComponent->pExynosPort[nPortIndex].pauseEvent);
597 pExynosPort = &pExynosComponent->pExynosPort[nPortIndex];
598 Exynos_OMX_GetFlushBuffer(pExynosPort, flushPortBuffer);
600 if (pExynosComponent->pExynosPort[nPortIndex].bufferProcessType & BUFFER_COPY)
601 Exynos_OSAL_SemaphorePost(pExynosPort->codecSemID);
602 Exynos_OSAL_SemaphorePost(pExynosPort->bufferSemID);
604 pVideoDec->exynos_codec_bufferProcessRun(pOMXComponent, nPortIndex);
605 Exynos_OSAL_MutexLock(flushPortBuffer[0]->bufferMutex);
606 pVideoDec->exynos_codec_stop(pOMXComponent, nPortIndex);
607 Exynos_OSAL_MutexLock(flushPortBuffer[1]->bufferMutex);
608 ret = Exynos_OMX_FlushPort(pOMXComponent, nPortIndex);
610 if (pVideoDec->bDRCProcessing == OMX_TRUE) {
611 /* pVideoDec->bDRCProcess == OMX_TRUE
612 the case of dynamic resolution change */
613 pVideoDec->exynos_codec_resetupAllElement(pOMXComponent, nPortIndex);
614 } else if (pExynosComponent->pExynosPort[nPortIndex].bufferProcessType & BUFFER_COPY) {
615 pVideoDec->exynos_codec_enqueueAllBuffer(pOMXComponent, nPortIndex);
618 Exynos_ResetCodecData(&pExynosPort->processData);
620 if (ret == OMX_ErrorNone) {
621 if (nPortIndex == INPUT_PORT_INDEX) {
622 pExynosComponent->checkTimeStamp.needSetStartTimeStamp = OMX_TRUE;
623 pExynosComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_FALSE;
624 pExynosComponent->checkTimeStamp.bImmediateDisplay = OMX_FALSE;
625 Exynos_OSAL_Memset(pExynosComponent->timeStamp, -19771003, sizeof(OMX_TICKS) * MAX_TIMESTAMP);
626 Exynos_OSAL_Memset(pExynosComponent->nFlags, 0, sizeof(OMX_U32) * MAX_FLAGS);
627 pExynosComponent->getAllDelayBuffer = OMX_FALSE;
628 pExynosComponent->bSaveFlagEOS = OMX_FALSE;
629 pExynosComponent->reInputData = OMX_FALSE;
632 pExynosComponent->pExynosPort[nPortIndex].bIsPortFlushed = OMX_FALSE;
633 Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"OMX_CommandFlush EventCmdComplete, port:%d", nPortIndex);
634 if (bEvent == OMX_TRUE)
635 pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent,
636 pExynosComponent->callbackData,
637 OMX_EventCmdComplete,
638 OMX_CommandFlush, nPortIndex, NULL);
640 Exynos_OSAL_MutexUnlock(flushPortBuffer[1]->bufferMutex);
641 Exynos_OSAL_MutexUnlock(flushPortBuffer[0]->bufferMutex);
644 if ((ret != OMX_ErrorNone) && (pOMXComponent != NULL) && (pExynosComponent != NULL)) {
645 Exynos_OSAL_Log(EXYNOS_LOG_ERROR,"%s : %d", __FUNCTION__, __LINE__);
646 pExynosComponent->pCallbacks->EventHandler(pOMXComponent,
647 pExynosComponent->callbackData,
657 OMX_ERRORTYPE Exynos_InputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent)
659 OMX_ERRORTYPE ret = OMX_ErrorNone;
660 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
661 EXYNOS_OMX_BASEPORT *exynosOMXInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
662 EXYNOS_OMX_DATABUFFER *dataBuffer = NULL;
663 OMX_BUFFERHEADERTYPE *bufferHeader = NULL;
667 if (exynosOMXInputPort->bufferProcessType & BUFFER_COPY) {
668 dataBuffer = &(exynosOMXInputPort->way.port2WayDataBuffer.inputDataBuffer);
669 } else if (exynosOMXInputPort->bufferProcessType & BUFFER_SHARE) {
670 dataBuffer = &(exynosOMXInputPort->way.port2WayDataBuffer.outputDataBuffer);
673 bufferHeader = dataBuffer->bufferHeader;
675 if (bufferHeader != NULL) {
676 if (exynosOMXInputPort->markType.hMarkTargetComponent != NULL ) {
677 bufferHeader->hMarkTargetComponent = exynosOMXInputPort->markType.hMarkTargetComponent;
678 bufferHeader->pMarkData = exynosOMXInputPort->markType.pMarkData;
679 exynosOMXInputPort->markType.hMarkTargetComponent = NULL;
680 exynosOMXInputPort->markType.pMarkData = NULL;
683 if (bufferHeader->hMarkTargetComponent != NULL) {
684 if (bufferHeader->hMarkTargetComponent == pOMXComponent) {
685 pExynosComponent->pCallbacks->EventHandler(pOMXComponent,
686 pExynosComponent->callbackData,
688 0, 0, bufferHeader->pMarkData);
690 pExynosComponent->propagateMarkType.hMarkTargetComponent = bufferHeader->hMarkTargetComponent;
691 pExynosComponent->propagateMarkType.pMarkData = bufferHeader->pMarkData;
695 bufferHeader->nFilledLen = 0;
696 bufferHeader->nOffset = 0;
697 Exynos_OMX_InputBufferReturn(pOMXComponent, bufferHeader);
700 /* reset dataBuffer */
701 Exynos_ResetDataBuffer(dataBuffer);
709 OMX_ERRORTYPE Exynos_FlushInputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer)
711 OMX_ERRORTYPE ret = OMX_ErrorNone;
712 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
713 EXYNOS_OMX_BASEPORT *exynosOMXInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
714 OMX_BUFFERHEADERTYPE *bufferHeader = NULL;
718 bufferHeader = dataBuffer->bufferHeader;
720 if (bufferHeader != NULL) {
721 if (exynosOMXInputPort->markType.hMarkTargetComponent != NULL ) {
722 bufferHeader->hMarkTargetComponent = exynosOMXInputPort->markType.hMarkTargetComponent;
723 bufferHeader->pMarkData = exynosOMXInputPort->markType.pMarkData;
724 exynosOMXInputPort->markType.hMarkTargetComponent = NULL;
725 exynosOMXInputPort->markType.pMarkData = NULL;
728 if (bufferHeader->hMarkTargetComponent != NULL) {
729 if (bufferHeader->hMarkTargetComponent == pOMXComponent) {
730 pExynosComponent->pCallbacks->EventHandler(pOMXComponent,
731 pExynosComponent->callbackData,
733 0, 0, bufferHeader->pMarkData);
735 pExynosComponent->propagateMarkType.hMarkTargetComponent = bufferHeader->hMarkTargetComponent;
736 pExynosComponent->propagateMarkType.pMarkData = bufferHeader->pMarkData;
740 bufferHeader->nFilledLen = 0;
741 bufferHeader->nOffset = 0;
742 Exynos_OMX_InputBufferReturn(pOMXComponent, bufferHeader);
745 /* reset dataBuffer */
746 Exynos_ResetDataBuffer(dataBuffer);
754 OMX_ERRORTYPE Exynos_InputBufferGetQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent)
756 OMX_ERRORTYPE ret = OMX_ErrorUndefined;
757 EXYNOS_OMX_BASEPORT *pExynosPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
758 EXYNOS_OMX_MESSAGE *message = NULL;
759 EXYNOS_OMX_DATABUFFER *inputUseBuffer = NULL;
763 inputUseBuffer = &(pExynosPort->way.port2WayDataBuffer.inputDataBuffer);
765 if (pExynosComponent->currentState != OMX_StateExecuting) {
766 ret = OMX_ErrorUndefined;
768 } else if ((pExynosComponent->transientState != EXYNOS_OMX_TransStateExecutingToIdle) &&
769 (!CHECK_PORT_BEING_FLUSHED(pExynosPort))) {
770 Exynos_OSAL_SemaphoreWait(pExynosPort->bufferSemID);
771 if (inputUseBuffer->dataValid != OMX_TRUE) {
772 message = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ);
773 if (message == NULL) {
774 ret = OMX_ErrorUndefined;
777 if (message->messageType == EXYNOS_OMX_CommandFakeBuffer) {
778 Exynos_OSAL_Free(message);
779 ret = OMX_ErrorCodecFlush;
783 inputUseBuffer->bufferHeader = (OMX_BUFFERHEADERTYPE *)(message->pCmdData);
784 inputUseBuffer->allocSize = inputUseBuffer->bufferHeader->nAllocLen;
785 inputUseBuffer->dataLen = inputUseBuffer->bufferHeader->nFilledLen;
786 inputUseBuffer->remainDataLen = inputUseBuffer->dataLen;
787 inputUseBuffer->usedDataLen = 0;
788 inputUseBuffer->dataValid = OMX_TRUE;
789 inputUseBuffer->nFlags = inputUseBuffer->bufferHeader->nFlags;
790 inputUseBuffer->timeStamp = inputUseBuffer->bufferHeader->nTimeStamp;
792 Exynos_OSAL_Free(message);
795 if (inputUseBuffer->allocSize <= inputUseBuffer->dataLen)
796 Exynos_OSAL_Log(EXYNOS_LOG_WARNING, "Input Buffer Full, Check input buffer size! allocSize:%d, dataLen:%d", inputUseBuffer->allocSize, inputUseBuffer->dataLen);
807 OMX_ERRORTYPE Exynos_OutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent)
809 OMX_ERRORTYPE ret = OMX_ErrorNone;
810 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
811 EXYNOS_OMX_BASEPORT *exynosOMXOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
812 EXYNOS_OMX_DATABUFFER *dataBuffer = NULL;
813 OMX_BUFFERHEADERTYPE *bufferHeader = NULL;
817 dataBuffer = &(exynosOMXOutputPort->way.port2WayDataBuffer.outputDataBuffer);
818 bufferHeader = dataBuffer->bufferHeader;
820 if (bufferHeader != NULL) {
822 bufferHeader->nFilledLen = sizeof(MMVideoBuffer);
824 bufferHeader->nFilledLen = dataBuffer->remainDataLen;
826 bufferHeader->nOffset = 0;
827 bufferHeader->nFlags = dataBuffer->nFlags;
828 bufferHeader->nTimeStamp = dataBuffer->timeStamp;
830 Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"Exynos_OutputBufferReturn: nFilledLen: %d", bufferHeader->nFilledLen);
831 Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"Exynos_OutputBufferReturn: nFlags: %d", bufferHeader->nFlags);
832 Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"Exynos_OutputBufferReturn: nTimeStamp: %lld", bufferHeader->nTimeStamp);
834 if (pExynosComponent->propagateMarkType.hMarkTargetComponent != NULL) {
835 bufferHeader->hMarkTargetComponent = pExynosComponent->propagateMarkType.hMarkTargetComponent;
836 bufferHeader->pMarkData = pExynosComponent->propagateMarkType.pMarkData;
837 pExynosComponent->propagateMarkType.hMarkTargetComponent = NULL;
838 pExynosComponent->propagateMarkType.pMarkData = NULL;
841 if ((bufferHeader->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) {
842 bufferHeader->nFilledLen = 0;
843 Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"event OMX_BUFFERFLAG_EOS!!!");
844 pExynosComponent->pCallbacks->EventHandler(pOMXComponent,
845 pExynosComponent->callbackData,
848 bufferHeader->nFlags, NULL);
851 Exynos_OMX_OutputBufferReturn(pOMXComponent, bufferHeader);
853 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d bufferHeader is NULL! ", __FUNCTION__, __LINE__);
856 /* reset dataBuffer */
857 Exynos_ResetDataBuffer(dataBuffer);
865 OMX_ERRORTYPE Exynos_FlushOutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer)
867 OMX_ERRORTYPE ret = OMX_ErrorNone;
868 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
869 EXYNOS_OMX_BASEPORT *exynosOMXOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
870 OMX_BUFFERHEADERTYPE *bufferHeader = NULL;
874 bufferHeader = dataBuffer->bufferHeader;
876 if (bufferHeader != NULL) {
877 bufferHeader->nFilledLen = dataBuffer->remainDataLen;
878 bufferHeader->nOffset = 0;
879 bufferHeader->nFlags = dataBuffer->nFlags;
880 bufferHeader->nTimeStamp = dataBuffer->timeStamp;
882 if (pExynosComponent->propagateMarkType.hMarkTargetComponent != NULL) {
883 bufferHeader->hMarkTargetComponent = pExynosComponent->propagateMarkType.hMarkTargetComponent;
884 bufferHeader->pMarkData = pExynosComponent->propagateMarkType.pMarkData;
885 pExynosComponent->propagateMarkType.hMarkTargetComponent = NULL;
886 pExynosComponent->propagateMarkType.pMarkData = NULL;
889 if ((bufferHeader->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) {
890 bufferHeader->nFilledLen = 0;
891 Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"event OMX_BUFFERFLAG_EOS!!!");
892 pExynosComponent->pCallbacks->EventHandler(pOMXComponent,
893 pExynosComponent->callbackData,
896 bufferHeader->nFlags, NULL);
898 Exynos_OMX_OutputBufferReturn(pOMXComponent, bufferHeader);
901 /* reset dataBuffer */
902 Exynos_ResetDataBuffer(dataBuffer);
910 OMX_ERRORTYPE Exynos_OutputBufferGetQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent)
912 OMX_ERRORTYPE ret = OMX_ErrorUndefined;
913 EXYNOS_OMX_BASEPORT *pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
914 EXYNOS_OMX_MESSAGE *message = NULL;
915 EXYNOS_OMX_DATABUFFER *outputUseBuffer = NULL;
919 if (pExynosPort->bufferProcessType & BUFFER_COPY) {
920 outputUseBuffer = &(pExynosPort->way.port2WayDataBuffer.outputDataBuffer);
921 } else if (pExynosPort->bufferProcessType & BUFFER_SHARE) {
922 outputUseBuffer = &(pExynosPort->way.port2WayDataBuffer.inputDataBuffer);
925 if (pExynosComponent->currentState != OMX_StateExecuting) {
926 ret = OMX_ErrorUndefined;
928 } else if ((pExynosComponent->transientState != EXYNOS_OMX_TransStateExecutingToIdle) &&
929 (!CHECK_PORT_BEING_FLUSHED(pExynosPort))){
930 Exynos_OSAL_SemaphoreWait(pExynosPort->bufferSemID);
931 if (outputUseBuffer->dataValid != OMX_TRUE) {
932 message = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ);
933 if (message == NULL) {
934 ret = OMX_ErrorUndefined;
937 if (message->messageType == EXYNOS_OMX_CommandFakeBuffer) {
938 Exynos_OSAL_Free(message);
939 ret = OMX_ErrorCodecFlush;
943 outputUseBuffer->bufferHeader = (OMX_BUFFERHEADERTYPE *)(message->pCmdData);
944 outputUseBuffer->allocSize = outputUseBuffer->bufferHeader->nAllocLen;
945 outputUseBuffer->dataLen = 0; //dataBuffer->bufferHeader->nFilledLen;
946 outputUseBuffer->remainDataLen = outputUseBuffer->dataLen;
947 outputUseBuffer->usedDataLen = 0; //dataBuffer->bufferHeader->nOffset;
948 outputUseBuffer->dataValid = OMX_TRUE;
949 /* dataBuffer->nFlags = dataBuffer->bufferHeader->nFlags; */
950 /* dataBuffer->nTimeStamp = dataBuffer->bufferHeader->nTimeStamp; */
952 if (pExynosPort->bufferProcessType & BUFFER_SHARE)
953 outputUseBuffer->pPrivate = outputUseBuffer->bufferHeader->pOutputPortPrivate;
954 else if (pExynosPort->bufferProcessType & BUFFER_COPY) {
955 pExynosPort->processData.dataBuffer = outputUseBuffer->bufferHeader->pBuffer;
956 pExynosPort->processData.allocSize = outputUseBuffer->bufferHeader->nAllocLen;
960 Exynos_OSAL_Free(message);
971 OMX_BUFFERHEADERTYPE *Exynos_OutputBufferGetQueue_Direct(EXYNOS_OMX_BASECOMPONENT *pExynosComponent)
973 OMX_BUFFERHEADERTYPE *retBuffer = NULL;
974 EXYNOS_OMX_BASEPORT *pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
975 EXYNOS_OMX_MESSAGE *message = NULL;
979 if (pExynosComponent->currentState != OMX_StateExecuting) {
982 } else if ((pExynosComponent->transientState != EXYNOS_OMX_TransStateExecutingToIdle) &&
983 (!CHECK_PORT_BEING_FLUSHED(pExynosPort))){
984 Exynos_OSAL_SemaphoreWait(pExynosPort->bufferSemID);
986 message = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ);
987 if (message == NULL) {
991 if (message->messageType == EXYNOS_OMX_CommandFakeBuffer) {
992 Exynos_OSAL_Free(message);
997 retBuffer = (OMX_BUFFERHEADERTYPE *)(message->pCmdData);
998 Exynos_OSAL_Free(message);
1007 OMX_ERRORTYPE Exynos_CodecBufferEnQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 PortIndex, OMX_PTR data)
1009 OMX_ERRORTYPE ret = OMX_ErrorNone;
1010 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1014 pExynosPort= &pExynosComponent->pExynosPort[PortIndex];
1017 ret = OMX_ErrorInsufficientResources;
1022 if (pExynosPort == NULL) {
1023 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d: pExynosPort is NULL", __FUNCTION__, __LINE__);
1027 ret = Exynos_OSAL_Queue(&pExynosPort->codecBufferQ, (void *)data);
1029 ret = OMX_ErrorUndefined;
1032 Exynos_OSAL_SemaphorePost(pExynosPort->codecSemID);
1034 ret = OMX_ErrorNone;
1042 OMX_ERRORTYPE Exynos_CodecBufferDeQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 PortIndex, OMX_PTR *data)
1044 OMX_ERRORTYPE ret = OMX_ErrorNone;
1045 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1050 pExynosPort = &pExynosComponent->pExynosPort[PortIndex];
1051 Exynos_OSAL_SemaphoreWait(pExynosPort->codecSemID);
1052 tempData = (OMX_U32)Exynos_OSAL_Dequeue(&pExynosPort->codecBufferQ);
1053 if (tempData == NULL) {
1055 ret = OMX_ErrorUndefined;
1058 *data = (OMX_PTR)tempData;
1060 ret = OMX_ErrorNone;
1068 OMX_ERRORTYPE Exynos_CodecBufferReset(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 PortIndex)
1070 OMX_ERRORTYPE ret = OMX_ErrorNone;
1071 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1075 pExynosPort= &pExynosComponent->pExynosPort[PortIndex];
1077 ret = Exynos_OSAL_ResetQueue(&pExynosPort->codecBufferQ);
1079 ret = OMX_ErrorUndefined;
1084 Exynos_OSAL_Get_SemaphoreCount(pExynosPort->codecSemID, &cnt);
1086 Exynos_OSAL_SemaphoreWait(pExynosPort->codecSemID);
1090 ret = OMX_ErrorNone;
1098 OMX_ERRORTYPE Exynos_OMX_VideoDecodeGetParameter(
1099 OMX_IN OMX_HANDLETYPE hComponent,
1100 OMX_IN OMX_INDEXTYPE nParamIndex,
1101 OMX_INOUT OMX_PTR ComponentParameterStructure)
1103 OMX_ERRORTYPE ret = OMX_ErrorNone;
1104 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1105 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1106 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1110 if (hComponent == NULL) {
1111 ret = OMX_ErrorBadParameter;
1114 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1115 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1116 if (ret != OMX_ErrorNone) {
1120 if (pOMXComponent->pComponentPrivate == NULL) {
1121 ret = OMX_ErrorBadParameter;
1124 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1126 if (pExynosComponent->currentState == OMX_StateInvalid ) {
1127 ret = OMX_ErrorInvalidState;
1131 if (ComponentParameterStructure == NULL) {
1132 ret = OMX_ErrorBadParameter;
1136 switch (nParamIndex) {
1137 case OMX_IndexParamVideoInit:
1139 OMX_PORT_PARAM_TYPE *portParam = (OMX_PORT_PARAM_TYPE *)ComponentParameterStructure;
1140 ret = Exynos_OMX_Check_SizeVersion(portParam, sizeof(OMX_PORT_PARAM_TYPE));
1141 if (ret != OMX_ErrorNone) {
1145 portParam->nPorts = pExynosComponent->portParam.nPorts;
1146 portParam->nStartPortNumber = pExynosComponent->portParam.nStartPortNumber;
1147 ret = OMX_ErrorNone;
1150 case OMX_IndexParamVideoPortFormat:
1152 OMX_VIDEO_PARAM_PORTFORMATTYPE *portFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)ComponentParameterStructure;
1153 OMX_U32 portIndex = portFormat->nPortIndex;
1154 OMX_U32 index = portFormat->nIndex;
1155 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1156 OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = NULL;
1157 OMX_U32 supportFormatNum = 0; /* supportFormatNum = N-1 */
1159 ret = Exynos_OMX_Check_SizeVersion(portFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
1160 if (ret != OMX_ErrorNone) {
1164 if ((portIndex >= pExynosComponent->portParam.nPorts)) {
1165 ret = OMX_ErrorBadPortIndex;
1170 if (portIndex == INPUT_PORT_INDEX) {
1171 supportFormatNum = INPUT_PORT_SUPPORTFORMAT_NUM_MAX - 1;
1172 if (index > supportFormatNum) {
1173 ret = OMX_ErrorNoMore;
1177 pExynosPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
1178 portDefinition = &pExynosPort->portDefinition;
1180 portFormat->eCompressionFormat = portDefinition->format.video.eCompressionFormat;
1181 portFormat->eColorFormat = portDefinition->format.video.eColorFormat;
1182 portFormat->xFramerate = portDefinition->format.video.xFramerate;
1183 } else if (portIndex == OUTPUT_PORT_INDEX) {
1184 pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
1185 portDefinition = &pExynosPort->portDefinition;
1188 case supportFormat_0:
1189 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
1190 portFormat->eColorFormat = OMX_COLOR_FormatYUV420Planar;
1191 portFormat->xFramerate = portDefinition->format.video.xFramerate;
1193 case supportFormat_1:
1194 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
1195 portFormat->eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
1196 portFormat->xFramerate = portDefinition->format.video.xFramerate;
1198 case supportFormat_2:
1199 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
1200 portFormat->eColorFormat = OMX_SEC_COLOR_FormatNV12L_DmaBuf_Fd;
1201 portFormat->xFramerate = portDefinition->format.video.xFramerate;
1204 case supportFormat_3:
1205 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
1206 portFormat->eColorFormat = OMX_SEC_COLOR_FormatNV12T_DmaBuf_Fd;
1207 portFormat->xFramerate = portDefinition->format.video.xFramerate;
1211 if (index > supportFormat_0) {
1212 ret = OMX_ErrorNoMore;
1218 ret = OMX_ErrorNone;
1222 case OMX_IndexParamGetAndroidNativeBuffer:
1224 ret = Exynos_OSAL_GetPBParameter(hComponent, nParamIndex, ComponentParameterStructure);
1230 ret = Exynos_OMX_GetParameter(hComponent, nParamIndex, ComponentParameterStructure);
1240 OMX_ERRORTYPE Exynos_OMX_VideoDecodeSetParameter(
1241 OMX_IN OMX_HANDLETYPE hComponent,
1242 OMX_IN OMX_INDEXTYPE nIndex,
1243 OMX_IN OMX_PTR ComponentParameterStructure)
1245 OMX_ERRORTYPE ret = OMX_ErrorNone;
1246 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1247 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1248 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1252 if (hComponent == NULL) {
1253 ret = OMX_ErrorBadParameter;
1256 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1257 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1258 if (ret != OMX_ErrorNone) {
1262 if (pOMXComponent->pComponentPrivate == NULL) {
1263 ret = OMX_ErrorBadParameter;
1266 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1268 if (pExynosComponent->currentState == OMX_StateInvalid ) {
1269 ret = OMX_ErrorInvalidState;
1273 if (ComponentParameterStructure == NULL) {
1274 ret = OMX_ErrorBadParameter;
1279 case OMX_IndexParamVideoPortFormat:
1281 OMX_VIDEO_PARAM_PORTFORMATTYPE *portFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)ComponentParameterStructure;
1282 OMX_U32 portIndex = portFormat->nPortIndex;
1283 OMX_U32 index = portFormat->nIndex;
1284 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1285 OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = NULL;
1286 OMX_U32 supportFormatNum = 0;
1288 ret = Exynos_OMX_Check_SizeVersion(portFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
1289 if (ret != OMX_ErrorNone) {
1293 if ((portIndex >= pExynosComponent->portParam.nPorts)) {
1294 ret = OMX_ErrorBadPortIndex;
1297 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
1298 portDefinition = &pExynosPort->portDefinition;
1300 portDefinition->format.video.eColorFormat = portFormat->eColorFormat;
1301 portDefinition->format.video.eCompressionFormat = portFormat->eCompressionFormat;
1302 portDefinition->format.video.xFramerate = portFormat->xFramerate;
1308 case OMX_IndexParamEnablePlatformSpecificBuffers:
1310 case OMX_IndexParamEnableAndroidBuffers:
1312 case OMX_IndexParamUseAndroidNativeBuffer:
1314 ret = Exynos_OSAL_SetPBParameter(hComponent, nIndex, ComponentParameterStructure);
1320 case OMX_IndexParamEnableTimestampReorder:
1322 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
1323 pVideoDec->bNeedTimestampReorder = OMX_TRUE;
1329 ret = Exynos_OMX_SetParameter(hComponent, nIndex, ComponentParameterStructure);
1340 OMX_ERRORTYPE Exynos_OMX_VideoDecodeGetConfig(
1341 OMX_HANDLETYPE hComponent,
1342 OMX_INDEXTYPE nIndex,
1343 OMX_PTR pComponentConfigStructure)
1345 OMX_ERRORTYPE ret = OMX_ErrorNone;
1346 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1347 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1351 if (hComponent == NULL) {
1352 ret = OMX_ErrorBadParameter;
1355 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1356 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1357 if (ret != OMX_ErrorNone) {
1360 if (pOMXComponent->pComponentPrivate == NULL) {
1361 ret = OMX_ErrorBadParameter;
1364 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1365 if (pComponentConfigStructure == NULL) {
1366 ret = OMX_ErrorBadParameter;
1369 if (pExynosComponent->currentState == OMX_StateInvalid) {
1370 ret = OMX_ErrorInvalidState;
1376 ret = Exynos_OMX_GetConfig(hComponent, nIndex, pComponentConfigStructure);
1386 OMX_ERRORTYPE Exynos_OMX_VideoDecodeSetConfig(
1387 OMX_HANDLETYPE hComponent,
1388 OMX_INDEXTYPE nIndex,
1389 OMX_PTR pComponentConfigStructure)
1391 OMX_ERRORTYPE ret = OMX_ErrorNone;
1392 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1393 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1397 if (hComponent == NULL) {
1398 ret = OMX_ErrorBadParameter;
1401 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1402 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1403 if (ret != OMX_ErrorNone) {
1406 if (pOMXComponent->pComponentPrivate == NULL) {
1407 ret = OMX_ErrorBadParameter;
1410 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1411 if (pComponentConfigStructure == NULL) {
1412 ret = OMX_ErrorBadParameter;
1415 if (pExynosComponent->currentState == OMX_StateInvalid) {
1416 ret = OMX_ErrorInvalidState;
1421 case OMX_IndexVendorThumbnailMode:
1423 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
1424 pVideoDec->bThumbnailMode = *((OMX_BOOL *)pComponentConfigStructure);
1426 ret = OMX_ErrorNone;
1430 ret = Exynos_OMX_SetConfig(hComponent, nIndex, pComponentConfigStructure);
1440 OMX_ERRORTYPE Exynos_OMX_VideoDecodeGetExtensionIndex(
1441 OMX_IN OMX_HANDLETYPE hComponent,
1442 OMX_IN OMX_STRING cParameterName,
1443 OMX_OUT OMX_INDEXTYPE *pIndexType)
1445 OMX_ERRORTYPE ret = OMX_ErrorNone;
1446 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1447 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1451 if (hComponent == NULL) {
1452 ret = OMX_ErrorBadParameter;
1455 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1456 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1457 if (ret != OMX_ErrorNone) {
1461 if (pOMXComponent->pComponentPrivate == NULL) {
1462 ret = OMX_ErrorBadParameter;
1465 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1467 if ((cParameterName == NULL) || (pIndexType == NULL)) {
1468 ret = OMX_ErrorBadParameter;
1471 if (pExynosComponent->currentState == OMX_StateInvalid) {
1472 ret = OMX_ErrorInvalidState;
1478 if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_ENABLE_PB) == 0)
1479 *pIndexType = (OMX_INDEXTYPE) OMX_IndexParamEnablePlatformSpecificBuffers;
1480 else if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_ENABLE_TS_REORDER) == 0)
1481 *pIndexType = (OMX_INDEXTYPE) OMX_IndexParamEnableTimestampReorder;
1483 if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_ENABLE_ANB) == 0)
1484 *pIndexType = (OMX_INDEXTYPE) OMX_IndexParamEnableAndroidBuffers;
1486 else if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_GET_ANB) == 0)
1487 *pIndexType = (OMX_INDEXTYPE) OMX_IndexParamGetAndroidNativeBuffer;
1488 else if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_USE_ANB) == 0)
1489 *pIndexType = (OMX_INDEXTYPE) OMX_IndexParamUseAndroidNativeBuffer;
1491 ret = Exynos_OMX_GetExtensionIndex(hComponent, cParameterName, pIndexType);
1493 ret = Exynos_OMX_GetExtensionIndex(hComponent, cParameterName, pIndexType);
1502 #ifdef USE_PB /* this is from FillThisBuffer */
1503 OMX_ERRORTYPE Exynos_Shared_PlatformBufferToData(EXYNOS_OMX_DATABUFFER *pUseBuffer, EXYNOS_OMX_DATA *pData, EXYNOS_OMX_BASEPORT *pExynosPort, EXYNOS_OMX_PLANE nPlane)
1505 OMX_ERRORTYPE ret = OMX_ErrorNone;
1506 OMX_U32 width, height;
1507 // void *pPhys[MAX_BUFFER_PLANE];
1508 ExynosVideoPlane planes[MAX_BUFFER_PLANE];
1512 memset(planes, 0, sizeof(planes));
1514 if (pExynosPort->bIsPBEnabled == OMX_TRUE) {
1517 width = pExynosPort->portDefinition.format.video.nFrameWidth;
1518 height = pExynosPort->portDefinition.format.video.nFrameHeight;
1519 if ((pUseBuffer->bufferHeader != NULL) && (pUseBuffer->bufferHeader->pBuffer != NULL)) {
1520 Exynos_OSAL_LockPB(pUseBuffer->bufferHeader->pBuffer, width, height, pExynosPort->portDefinition.format.video.eColorFormat, &stride, planes);
1521 pUseBuffer->dataLen = sizeof(void *);
1523 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__);
1524 ret = OMX_ErrorBadParameter;
1528 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__);
1529 ret = OMX_ErrorBadParameter;
1533 if (nPlane == TWO_PLANE) {
1534 /* Case of Shared Buffer, Only support two PlaneBuffer */
1535 pData->buffer.multiPlaneBuffer.dataBuffer[0] = planes[0].addr;
1536 pData->buffer.multiPlaneBuffer.dataBuffer[1] = planes[1].addr;
1538 pData->buffer.multiPlaneBuffer.fd[0] = planes[0].fd;
1539 pData->buffer.multiPlaneBuffer.fd[1] = planes[1].fd;
1542 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Can not support plane");
1543 ret = OMX_ErrorNotImplemented;
1547 pData->allocSize = pUseBuffer->allocSize;
1548 pData->dataLen = pUseBuffer->dataLen;
1549 pData->usedDataLen = pUseBuffer->usedDataLen;
1550 pData->remainDataLen = pUseBuffer->remainDataLen;
1551 pData->timeStamp = pUseBuffer->timeStamp;
1552 pData->nFlags = pUseBuffer->nFlags;
1553 pData->pPrivate = pUseBuffer->pPrivate;
1554 pData->bufferHeader = pUseBuffer->bufferHeader;
1561 /* this is for Fill This Buffer Done */
1563 OMX_ERRORTYPE Exynos_Shared_DataToPlatformBuffer(EXYNOS_OMX_DATA *pData, EXYNOS_OMX_DATABUFFER *pUseBuffer, EXYNOS_OMX_BASEPORT *pExynosPort, EXYNOS_OMX_BASEPORT *pExynosInPort)
1565 OMX_ERRORTYPE Exynos_Shared_DataToPlatformBuffer(EXYNOS_OMX_DATA *pData, EXYNOS_OMX_DATABUFFER *pUseBuffer, EXYNOS_OMX_BASEPORT *pExynosPort)
1568 OMX_ERRORTYPE ret = OMX_ErrorNone;
1572 pUseBuffer->bufferHeader = pData->bufferHeader;
1573 pUseBuffer->allocSize = pData->allocSize;
1575 pUseBuffer->dataLen = sizeof(MMVideoBuffer);
1577 pUseBuffer->dataLen = pData->dataLen;
1579 pUseBuffer->usedDataLen = pData->usedDataLen;
1580 pUseBuffer->remainDataLen = pData->remainDataLen;
1581 pUseBuffer->timeStamp = pData->timeStamp;
1582 pUseBuffer->nFlags = pData->nFlags;
1583 pUseBuffer->pPrivate = pData->pPrivate;
1585 if ((pUseBuffer->bufferHeader == NULL) ||
1586 (pUseBuffer->bufferHeader->pBuffer == NULL)) {
1587 Exynos_OSAL_Log(EXYNOS_LOG_VERVOSE, "pUseBuffer->bufferHeader or pUseBuffer->bufferHeader->pBuffer is NULL");
1588 ret = OMX_ErrorUndefined;
1592 if (pExynosPort->bIsPBEnabled == OMX_TRUE) {
1594 Exynos_OSAL_UnlockPB(pUseBuffer->bufferHeader->pBuffer, pData, pExynosPort,pExynosInPort);
1596 Exynos_OSAL_UnlockPB(pUseBuffer->bufferHeader->pBuffer, pData);
1599 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__);
1600 ret = OMX_ErrorBadParameter;