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