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