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