2 * Copyright 2012 Samsung Electronics S.LSI Co. LTD
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file Exynos_OSAL_Android.cpp
20 * @author Seungbeom Kim (sbcrux.kim@samsung.com)
21 * @author Hyeyeon Chung (hyeon.chung@samsung.com)
22 * @author Yunji Kim (yunji.kim@samsung.com)
23 * @author Jinsung Yang (jsgood.yang@samsung.com)
32 #include <system/window.h>
33 #include <ui/GraphicBuffer.h>
34 #include <ui/GraphicBufferMapper.h>
36 #include <media/hardware/HardwareAPI.h>
37 #include <hardware/hardware.h>
38 #include <media/hardware/OMXPluginBase.h>
39 #include <media/hardware/MetadataBufferType.h>
40 #include <gralloc_priv.h>
42 #include "Exynos_OSAL_Mutex.h"
43 #include "Exynos_OSAL_Semaphore.h"
44 #include "Exynos_OMX_Baseport.h"
45 #include "Exynos_OMX_Basecomponent.h"
46 #include "Exynos_OMX_Macros.h"
47 #include "Exynos_OMX_Vdec.h"
48 #include "Exynos_OMX_Venc.h"
49 #include "Exynos_OSAL_Android.h"
50 #include "exynos_format.h"
54 #define EXYNOS_LOG_TAG "Exynos_OSAL_Android"
55 #define EXYNOS_LOG_OFF
56 #include "Exynos_OSAL_Log.h"
58 using namespace android
;
64 int getIonFd(gralloc_module_t
const *module
)
66 private_module_t
* m
= const_cast<private_module_t
*>(reinterpret_cast<const private_module_t
*>(module
));
70 OMX_ERRORTYPE
Exynos_OSAL_LockANBHandle(
71 OMX_IN OMX_U32 handle
,
73 OMX_IN OMX_U32 height
,
74 OMX_IN OMX_COLOR_FORMATTYPE format
,
75 OMX_OUT OMX_U32
*pStride
,
76 OMX_OUT OMX_PTR planes
)
80 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
81 GraphicBufferMapper
&mapper
= GraphicBufferMapper::get();
82 buffer_handle_t bufferHandle
= (buffer_handle_t
) handle
;
83 private_handle_t
*priv_hnd
= (private_handle_t
*) bufferHandle
;
84 Rect
bounds((uint32_t)width
, (uint32_t)height
);
85 ExynosVideoPlane
*vplanes
= (ExynosVideoPlane
*) planes
;
86 void *vaddr
[MAX_BUFFER_PLANE
];
88 Exynos_OSAL_Log(EXYNOS_LOG_TRACE
, "%s: handle: 0x%x", __func__
, handle
);
93 case OMX_COLOR_FormatYUV420Planar
:
94 case OMX_COLOR_FormatYUV420SemiPlanar
:
95 case OMX_SEC_COLOR_FormatNV12Tiled
:
96 usage
= GRALLOC_USAGE_SW_READ_OFTEN
| GRALLOC_USAGE_SW_WRITE_OFTEN
;
99 usage
= GRALLOC_USAGE_SW_READ_OFTEN
| GRALLOC_USAGE_SW_WRITE_OFTEN
;
103 if (mapper
.lock(bufferHandle
, usage
, bounds
, vaddr
) != 0) {
104 Exynos_OSAL_Log(EXYNOS_LOG_ERROR
, "%s: mapper.lock() fail", __func__
);
105 ret
= OMX_ErrorUndefined
;
109 vplanes
[0].fd
= priv_hnd
->fd
;
110 vplanes
[0].offset
= 0;
111 vplanes
[0].addr
= vaddr
[0];
112 vplanes
[1].fd
= priv_hnd
->fd1
;
113 vplanes
[1].offset
= 0;
114 vplanes
[1].addr
= vaddr
[1];
115 vplanes
[2].fd
= priv_hnd
->fd2
;
116 vplanes
[2].offset
= 0;
117 vplanes
[2].addr
= vaddr
[2];
119 *pStride
= priv_hnd
->stride
;
121 Exynos_OSAL_Log(EXYNOS_LOG_TRACE
, "%s: buffer locked: 0x%x", __func__
, *vaddr
);
129 OMX_ERRORTYPE
Exynos_OSAL_UnlockANBHandle(OMX_IN OMX_U32 handle
)
133 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
134 GraphicBufferMapper
&mapper
= GraphicBufferMapper::get();
135 buffer_handle_t bufferHandle
= (buffer_handle_t
) handle
;
137 Exynos_OSAL_Log(EXYNOS_LOG_TRACE
, "%s: handle: 0x%x", __func__
, handle
);
139 if (mapper
.unlock(bufferHandle
) != 0) {
140 Exynos_OSAL_Log(EXYNOS_LOG_ERROR
, "%s: mapper.unlock() fail", __func__
);
141 ret
= OMX_ErrorUndefined
;
145 Exynos_OSAL_Log(EXYNOS_LOG_TRACE
, "%s: buffer unlocked: 0x%x", __func__
, handle
);
153 OMX_COLOR_FORMATTYPE
Exynos_OSAL_GetANBColorFormat(OMX_IN OMX_U32 handle
)
157 OMX_COLOR_FORMATTYPE ret
= OMX_COLOR_FormatUnused
;
158 private_handle_t
*priv_hnd
= (private_handle_t
*) handle
;
160 ret
= Exynos_OSAL_Hal2OMXPixelFormat(priv_hnd
->format
);
161 Exynos_OSAL_Log(EXYNOS_LOG_TRACE
, "ColorFormat: 0x%x", ret
);
169 OMX_U32
Exynos_OSAL_GetANBStride(OMX_IN OMX_U32 handle
)
174 private_handle_t
*priv_hnd
= (private_handle_t
*) handle
;
176 nStride
= priv_hnd
->stride
;
184 OMX_ERRORTYPE
Exynos_OSAL_LockMetaData(
185 OMX_IN OMX_PTR pBuffer
,
186 OMX_IN OMX_U32 width
,
187 OMX_IN OMX_U32 height
,
188 OMX_IN OMX_COLOR_FORMATTYPE format
,
189 OMX_OUT OMX_U32
*pStride
,
190 OMX_OUT OMX_PTR planes
)
194 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
197 ret
= Exynos_OSAL_GetInfoFromMetaData((OMX_BYTE
)pBuffer
, &pBuf
);
198 if (ret
== OMX_ErrorNone
) {
199 ret
= Exynos_OSAL_LockANBHandle((OMX_U32
)pBuf
, width
, height
, format
, pStride
, planes
);
208 OMX_ERRORTYPE
Exynos_OSAL_UnlockMetaData(OMX_IN OMX_PTR pBuffer
)
212 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
215 ret
= Exynos_OSAL_GetInfoFromMetaData((OMX_BYTE
)pBuffer
, &pBuf
);
216 if (ret
== OMX_ErrorNone
)
217 ret
= Exynos_OSAL_UnlockANBHandle((OMX_U32
)pBuf
);
225 OMX_HANDLETYPE
Exynos_OSAL_RefANB_Create()
228 EXYNOS_OMX_REF_HANDLE
*phREF
= NULL
;
229 gralloc_module_t
*module
= NULL
;
231 OMX_ERRORTYPE err
= OMX_ErrorNone
;
235 phREF
= (EXYNOS_OMX_REF_HANDLE
*) Exynos_OSAL_Malloc(sizeof(EXYNOS_OMX_REF_HANDLE
));
239 Exynos_OSAL_Memset(phREF
, 0, sizeof(EXYNOS_OMX_REF_HANDLE
));
240 for (i
= 0; i
< MAX_BUFFER_REF
; i
++) {
241 phREF
->SharedBuffer
[i
].BufferFd
= -1;
242 phREF
->SharedBuffer
[i
].BufferFd1
= -1;
243 phREF
->SharedBuffer
[i
].BufferFd2
= -1;
246 hw_get_module(GRALLOC_HARDWARE_MODULE_ID
, (const hw_module_t
**)&module
);
247 phREF
->pGrallocModule
= (OMX_PTR
)module
;
249 err
= Exynos_OSAL_MutexCreate(&phREF
->hMutex
);
250 if (err
!= OMX_ErrorNone
) {
251 Exynos_OSAL_Free(phREF
);
258 return ((OMX_HANDLETYPE
)phREF
);
261 OMX_ERRORTYPE
Exynos_OSAL_RefANB_Reset(OMX_HANDLETYPE hREF
)
264 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
265 EXYNOS_OMX_REF_HANDLE
*phREF
= (EXYNOS_OMX_REF_HANDLE
*)hREF
;
266 gralloc_module_t
* module
= NULL
;
271 ret
= OMX_ErrorBadParameter
;
275 module
= (gralloc_module_t
*)phREF
->pGrallocModule
;
277 Exynos_OSAL_MutexLock(phREF
->hMutex
);
278 for (i
= 0; i
< MAX_BUFFER_REF
; i
++) {
279 if (phREF
->SharedBuffer
[i
].BufferFd
> -1) {
280 while(phREF
->SharedBuffer
[i
].cnt
> 0) {
281 if (phREF
->SharedBuffer
[i
].BufferFd
> -1)
282 ion_decRef(getIonFd(module
), phREF
->SharedBuffer
[i
].pIonHandle
);
283 if (phREF
->SharedBuffer
[i
].BufferFd1
> -1)
284 ion_decRef(getIonFd(module
), phREF
->SharedBuffer
[i
].pIonHandle1
);
285 if (phREF
->SharedBuffer
[i
].BufferFd2
> -1)
286 ion_decRef(getIonFd(module
), phREF
->SharedBuffer
[i
].pIonHandle2
);
287 phREF
->SharedBuffer
[i
].cnt
--;
289 phREF
->SharedBuffer
[i
].BufferFd
= -1;
290 phREF
->SharedBuffer
[i
].BufferFd1
= -1;
291 phREF
->SharedBuffer
[i
].BufferFd2
= -1;
292 phREF
->SharedBuffer
[i
].pIonHandle
= NULL
;
293 phREF
->SharedBuffer
[i
].pIonHandle1
= NULL
;
294 phREF
->SharedBuffer
[i
].pIonHandle2
= NULL
;
297 Exynos_OSAL_MutexUnlock(phREF
->hMutex
);
305 OMX_ERRORTYPE
Exynos_OSAL_RefANB_Terminate(OMX_HANDLETYPE hREF
)
307 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
308 EXYNOS_OMX_REF_HANDLE
*phREF
= (EXYNOS_OMX_REF_HANDLE
*)hREF
;
312 ret
= OMX_ErrorBadParameter
;
316 Exynos_OSAL_RefANB_Reset(phREF
);
318 phREF
->pGrallocModule
= NULL
;
320 ret
= Exynos_OSAL_MutexTerminate(phREF
->hMutex
);
321 if (ret
!= OMX_ErrorNone
)
324 Exynos_OSAL_Free(phREF
);
333 OMX_ERRORTYPE
Exynos_OSAL_RefANB_Increase(OMX_HANDLETYPE hREF
, OMX_PTR pBuffer
)
336 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
337 buffer_handle_t bufferHandle
= (buffer_handle_t
) pBuffer
; //pANB->handle
338 private_handle_t
*priv_hnd
= (private_handle_t
*) bufferHandle
;
339 EXYNOS_OMX_REF_HANDLE
*phREF
= (EXYNOS_OMX_REF_HANDLE
*)hREF
;
340 gralloc_module_t
* module
= NULL
;
342 unsigned long *pIonHandle
;
343 unsigned long *pIonHandle1
;
344 unsigned long *pIonHandle2
;
349 ret
= OMX_ErrorBadParameter
;
353 module
= (gralloc_module_t
*)phREF
->pGrallocModule
;
355 Exynos_OSAL_MutexLock(phREF
->hMutex
);
357 if (priv_hnd
->fd
>= 0) {
358 ion_incRef(getIonFd(module
), priv_hnd
->fd
, &pIonHandle
);
360 if (priv_hnd
->fd1
>= 0) {
361 ion_incRef(getIonFd(module
), priv_hnd
->fd1
, &pIonHandle1
);
363 if (priv_hnd
->fd2
>= 0) {
364 ion_incRef(getIonFd(module
), priv_hnd
->fd2
, &pIonHandle2
);
367 for (i
= 0; i
< MAX_BUFFER_REF
; i
++) {
368 if (phREF
->SharedBuffer
[i
].BufferFd
== priv_hnd
->fd
) {
369 phREF
->SharedBuffer
[i
].cnt
++;
374 if (i
>= MAX_BUFFER_REF
) {
375 for (i
= 0; i
< MAX_BUFFER_REF
; i
++) {
376 if (phREF
->SharedBuffer
[i
].BufferFd
== -1) {
377 phREF
->SharedBuffer
[i
].BufferFd
= priv_hnd
->fd
;
378 phREF
->SharedBuffer
[i
].BufferFd1
= priv_hnd
->fd1
;
379 phREF
->SharedBuffer
[i
].BufferFd2
= priv_hnd
->fd2
;
380 phREF
->SharedBuffer
[i
].pIonHandle
= pIonHandle
;
381 phREF
->SharedBuffer
[i
].pIonHandle1
= pIonHandle1
;
382 phREF
->SharedBuffer
[i
].pIonHandle2
= pIonHandle2
;
383 phREF
->SharedBuffer
[i
].cnt
++;
389 Exynos_OSAL_Log(EXYNOS_LOG_TRACE
, "inc fd:%d cnt:%d", phREF
->SharedBuffer
[i
].BufferFd
, phREF
->SharedBuffer
[i
].cnt
);
391 Exynos_OSAL_MutexUnlock(phREF
->hMutex
);
393 if (i
>= MAX_BUFFER_REF
) {
394 ret
= OMX_ErrorUndefined
;
403 OMX_ERRORTYPE
Exynos_OSAL_RefANB_Decrease(OMX_HANDLETYPE hREF
, OMX_U32 BufferFd
)
406 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
407 EXYNOS_OMX_REF_HANDLE
*phREF
= (EXYNOS_OMX_REF_HANDLE
*)hREF
;
408 gralloc_module_t
* module
= NULL
;
412 if ((phREF
== NULL
) || (BufferFd
< 0)) {
413 ret
= OMX_ErrorBadParameter
;
417 module
= (gralloc_module_t
*)phREF
->pGrallocModule
;
419 Exynos_OSAL_MutexLock(phREF
->hMutex
);
421 for (i
= 0; i
< MAX_BUFFER_REF
; i
++) {
422 if (phREF
->SharedBuffer
[i
].BufferFd
== BufferFd
) {
423 if (phREF
->SharedBuffer
[i
].BufferFd
> -1)
424 ion_decRef(getIonFd(module
), phREF
->SharedBuffer
[i
].pIonHandle
);
425 if (phREF
->SharedBuffer
[i
].BufferFd1
> -1)
426 ion_decRef(getIonFd(module
), phREF
->SharedBuffer
[i
].pIonHandle1
);
427 if (phREF
->SharedBuffer
[i
].BufferFd2
> -1)
428 ion_decRef(getIonFd(module
), phREF
->SharedBuffer
[i
].pIonHandle2
);
429 phREF
->SharedBuffer
[i
].cnt
--;
430 if (phREF
->SharedBuffer
[i
].cnt
== 0) {
431 phREF
->SharedBuffer
[i
].BufferFd
= -1;
432 phREF
->SharedBuffer
[i
].BufferFd1
= -1;
433 phREF
->SharedBuffer
[i
].BufferFd2
= -1;
434 phREF
->SharedBuffer
[i
].pIonHandle
= NULL
;
435 phREF
->SharedBuffer
[i
].pIonHandle1
= NULL
;
436 phREF
->SharedBuffer
[i
].pIonHandle2
= NULL
;
441 Exynos_OSAL_Log(EXYNOS_LOG_TRACE
, "dec fd:%d cnt:%d", phREF
->SharedBuffer
[i
].BufferFd
, phREF
->SharedBuffer
[i
].cnt
);
443 Exynos_OSAL_MutexUnlock(phREF
->hMutex
);
445 if (i
>= MAX_BUFFER_REF
) {
446 ret
= OMX_ErrorUndefined
;
456 OMX_ERRORTYPE
useAndroidNativeBuffer(
457 EXYNOS_OMX_BASEPORT
*pExynosPort
,
458 OMX_BUFFERHEADERTYPE
**ppBufferHdr
,
464 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
465 OMX_BUFFERHEADERTYPE
*temp_bufferHeader
= NULL
;
467 OMX_U32 width
, height
;
469 ExynosVideoPlane planes
[MAX_BUFFER_PLANE
];
473 if (pExynosPort
== NULL
) {
474 ret
= OMX_ErrorBadParameter
;
477 if (pExynosPort
->portState
!= OMX_StateIdle
) {
478 ret
= OMX_ErrorIncorrectStateOperation
;
481 if (CHECK_PORT_TUNNELED(pExynosPort
) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort
)) {
482 ret
= OMX_ErrorBadPortIndex
;
486 temp_bufferHeader
= (OMX_BUFFERHEADERTYPE
*)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE
));
487 if (temp_bufferHeader
== NULL
) {
488 ret
= OMX_ErrorInsufficientResources
;
491 Exynos_OSAL_Memset(temp_bufferHeader
, 0, sizeof(OMX_BUFFERHEADERTYPE
));
493 for (i
= 0; i
< pExynosPort
->portDefinition
.nBufferCountActual
; i
++) {
494 if (pExynosPort
->bufferStateAllocate
[i
] == BUFFER_STATE_FREE
) {
495 pExynosPort
->extendBufferHeader
[i
].OMXBufferHeader
= temp_bufferHeader
;
496 pExynosPort
->bufferStateAllocate
[i
] = (BUFFER_STATE_ASSIGNED
| HEADER_STATE_ALLOCATED
);
497 INIT_SET_SIZE_VERSION(temp_bufferHeader
, OMX_BUFFERHEADERTYPE
);
498 android_native_buffer_t
*pANB
= (android_native_buffer_t
*) pBuffer
;
499 temp_bufferHeader
->pBuffer
= (OMX_U8
*)pANB
->handle
;
500 temp_bufferHeader
->nAllocLen
= nSizeBytes
;
501 temp_bufferHeader
->pAppPrivate
= pAppPrivate
;
502 if (nPortIndex
== INPUT_PORT_INDEX
)
503 temp_bufferHeader
->nInputPortIndex
= INPUT_PORT_INDEX
;
505 temp_bufferHeader
->nOutputPortIndex
= OUTPUT_PORT_INDEX
;
507 width
= pExynosPort
->portDefinition
.format
.video
.nFrameWidth
;
508 height
= pExynosPort
->portDefinition
.format
.video
.nFrameHeight
;
509 Exynos_OSAL_LockANBHandle((OMX_U32
)temp_bufferHeader
->pBuffer
, width
, height
,
510 pExynosPort
->portDefinition
.format
.video
.eColorFormat
,
512 pExynosPort
->extendBufferHeader
[i
].buf_fd
[0] = planes
[0].fd
;
513 pExynosPort
->extendBufferHeader
[i
].pYUVBuf
[0] = planes
[0].addr
;
514 pExynosPort
->extendBufferHeader
[i
].buf_fd
[1] = planes
[1].fd
;
515 pExynosPort
->extendBufferHeader
[i
].pYUVBuf
[1] = planes
[1].addr
;
516 pExynosPort
->extendBufferHeader
[i
].buf_fd
[2] = planes
[2].fd
;
517 pExynosPort
->extendBufferHeader
[i
].pYUVBuf
[2] = planes
[2].addr
;
518 Exynos_OSAL_UnlockANBHandle((OMX_U32
)temp_bufferHeader
->pBuffer
);
519 Exynos_OSAL_Log(EXYNOS_LOG_TRACE
, "useAndroidNativeBuffer: buf %d pYUVBuf[0]:0x%x (fd:%d), pYUVBuf[1]:0x%x (fd:%d)",
520 i
, pExynosPort
->extendBufferHeader
[i
].pYUVBuf
[0], planes
[0].fd
,
521 pExynosPort
->extendBufferHeader
[i
].pYUVBuf
[1], planes
[1].fd
);
523 pExynosPort
->assignedBufferNum
++;
524 if (pExynosPort
->assignedBufferNum
== pExynosPort
->portDefinition
.nBufferCountActual
) {
525 pExynosPort
->portDefinition
.bPopulated
= OMX_TRUE
;
526 /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */
527 Exynos_OSAL_SemaphorePost(pExynosPort
->loadedResource
);
528 /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */
530 *ppBufferHdr
= temp_bufferHeader
;
537 Exynos_OSAL_Free(temp_bufferHeader
);
538 ret
= OMX_ErrorInsufficientResources
;
546 OMX_ERRORTYPE
Exynos_OSAL_GetANBParameter(
547 OMX_IN OMX_HANDLETYPE hComponent
,
548 OMX_IN OMX_INDEXTYPE nIndex
,
549 OMX_INOUT OMX_PTR ComponentParameterStructure
)
551 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
552 OMX_COMPONENTTYPE
*pOMXComponent
= NULL
;
553 EXYNOS_OMX_BASECOMPONENT
*pExynosComponent
= NULL
;
557 if (hComponent
== NULL
) {
558 ret
= OMX_ErrorBadParameter
;
562 pOMXComponent
= (OMX_COMPONENTTYPE
*)hComponent
;
563 ret
= Exynos_OMX_Check_SizeVersion(pOMXComponent
, sizeof(OMX_COMPONENTTYPE
));
564 if (ret
!= OMX_ErrorNone
) {
568 if (pOMXComponent
->pComponentPrivate
== NULL
) {
569 ret
= OMX_ErrorBadParameter
;
573 pExynosComponent
= (EXYNOS_OMX_BASECOMPONENT
*)pOMXComponent
->pComponentPrivate
;
574 if (pExynosComponent
->currentState
== OMX_StateInvalid
) {
575 ret
= OMX_ErrorInvalidState
;
579 if (ComponentParameterStructure
== NULL
) {
580 ret
= OMX_ErrorBadParameter
;
585 case OMX_IndexParamGetAndroidNativeBuffer
:
587 GetAndroidNativeBufferUsageParams
*pANBParams
= (GetAndroidNativeBufferUsageParams
*) ComponentParameterStructure
;
588 OMX_U32 portIndex
= pANBParams
->nPortIndex
;
590 Exynos_OSAL_Log(EXYNOS_LOG_TRACE
, "%s: OMX_IndexParamGetAndroidNativeBuffer", __func__
);
592 ret
= Exynos_OMX_Check_SizeVersion(pANBParams
, sizeof(GetAndroidNativeBufferUsageParams
));
593 if (ret
!= OMX_ErrorNone
) {
594 Exynos_OSAL_Log(EXYNOS_LOG_ERROR
, "%s: Exynos_OMX_Check_SizeVersion(GetAndroidNativeBufferUsageParams) is failed", __func__
);
598 if (portIndex
>= pExynosComponent
->portParam
.nPorts
) {
599 ret
= OMX_ErrorBadPortIndex
;
603 /* NOTE: OMX_IndexParamGetAndroidNativeBuffer returns original 'nUsage' without any
604 * modifications since currently not defined what the 'nUsage' is for.
606 pANBParams
->nUsage
|= (GRALLOC_USAGE_HW_TEXTURE
| GRALLOC_USAGE_EXTERNAL_DISP
);
612 Exynos_OSAL_Log(EXYNOS_LOG_ERROR
, "%s: Unsupported index (%d)", __func__
, nIndex
);
613 ret
= OMX_ErrorUnsupportedIndex
;
625 OMX_ERRORTYPE
Exynos_OSAL_SetANBParameter(
626 OMX_IN OMX_HANDLETYPE hComponent
,
627 OMX_IN OMX_INDEXTYPE nIndex
,
628 OMX_IN OMX_PTR ComponentParameterStructure
)
630 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
631 OMX_COMPONENTTYPE
*pOMXComponent
= NULL
;
632 EXYNOS_OMX_BASECOMPONENT
*pExynosComponent
= NULL
;
636 if (hComponent
== NULL
) {
637 ret
= OMX_ErrorBadParameter
;
641 pOMXComponent
= (OMX_COMPONENTTYPE
*)hComponent
;
642 ret
= Exynos_OMX_Check_SizeVersion(pOMXComponent
, sizeof(OMX_COMPONENTTYPE
));
643 if (ret
!= OMX_ErrorNone
) {
647 if (pOMXComponent
->pComponentPrivate
== NULL
) {
648 ret
= OMX_ErrorBadParameter
;
652 pExynosComponent
= (EXYNOS_OMX_BASECOMPONENT
*)pOMXComponent
->pComponentPrivate
;
653 if (pExynosComponent
->currentState
== OMX_StateInvalid
) {
654 ret
= OMX_ErrorInvalidState
;
658 if (ComponentParameterStructure
== NULL
) {
659 ret
= OMX_ErrorBadParameter
;
664 case OMX_IndexParamEnableAndroidBuffers
:
666 EXYNOS_OMX_VIDEODEC_COMPONENT
*pVideoDec
= (EXYNOS_OMX_VIDEODEC_COMPONENT
*)pExynosComponent
->hComponentHandle
;
667 EnableAndroidNativeBuffersParams
*pANBParams
= (EnableAndroidNativeBuffersParams
*) ComponentParameterStructure
;
668 OMX_U32 portIndex
= pANBParams
->nPortIndex
;
669 EXYNOS_OMX_BASEPORT
*pExynosPort
= NULL
;
671 Exynos_OSAL_Log(EXYNOS_LOG_TRACE
, "%s: OMX_IndexParamEnableAndroidNativeBuffers", __func__
);
673 ret
= Exynos_OMX_Check_SizeVersion(pANBParams
, sizeof(EnableAndroidNativeBuffersParams
));
674 if (ret
!= OMX_ErrorNone
) {
675 Exynos_OSAL_Log(EXYNOS_LOG_ERROR
, "%s: Exynos_OMX_Check_SizeVersion(EnableAndroidNativeBuffersParams) is failed", __func__
);
679 if (portIndex
>= pExynosComponent
->portParam
.nPorts
) {
680 ret
= OMX_ErrorBadPortIndex
;
684 pExynosPort
= &pExynosComponent
->pExynosPort
[portIndex
];
685 if (CHECK_PORT_TUNNELED(pExynosPort
) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort
)) {
686 ret
= OMX_ErrorBadPortIndex
;
690 /* ANB and DPB Buffer Sharing */
691 if (pExynosPort
->bStoreMetaData
!= OMX_TRUE
)
692 pExynosPort
->bIsANBEnabled
= pANBParams
->enable
;
693 if ((portIndex
== OUTPUT_PORT_INDEX
) &&
694 (pExynosPort
->bIsANBEnabled
== OMX_TRUE
) &&
695 ((pExynosPort
->bufferProcessType
& BUFFER_ANBSHARE
) == BUFFER_ANBSHARE
)) {
696 pExynosPort
->bufferProcessType
= BUFFER_SHARE
;
697 pExynosPort
->portDefinition
.format
.video
.eColorFormat
= (OMX_COLOR_FORMATTYPE
)OMX_SEC_COLOR_FormatNV12Tiled
;
698 Exynos_OSAL_Log(EXYNOS_LOG_TRACE
, "OMX_IndexParamEnableAndroidBuffers & bufferProcessType change to BUFFER_SHARE");
699 } else if ((portIndex
== OUTPUT_PORT_INDEX
) &&
700 (pExynosPort
->bStoreMetaData
== OMX_FALSE
&& pExynosPort
->bIsANBEnabled
== OMX_FALSE
) &&
701 pExynosPort
->bufferProcessType
== BUFFER_SHARE
) {
702 pExynosPort
->bufferProcessType
= (EXYNOS_OMX_BUFFERPROCESS_TYPE
)(BUFFER_COPY
| BUFFER_ANBSHARE
);
703 pExynosPort
->portDefinition
.format
.video
.eColorFormat
= OMX_COLOR_FormatYUV420Planar
;
704 Exynos_OSAL_Log(EXYNOS_LOG_TRACE
, "No OMX_IndexParamEnableAndroidBuffers => reset bufferProcessType");
709 case OMX_IndexParamUseAndroidNativeBuffer
:
711 EXYNOS_OMX_VIDEODEC_COMPONENT
*pVideoDec
= (EXYNOS_OMX_VIDEODEC_COMPONENT
*)pExynosComponent
->hComponentHandle
;
712 UseAndroidNativeBufferParams
*pANBParams
= (UseAndroidNativeBufferParams
*) ComponentParameterStructure
;
713 OMX_U32 portIndex
= pANBParams
->nPortIndex
;
714 EXYNOS_OMX_BASEPORT
*pExynosPort
= NULL
;
715 android_native_buffer_t
*pANB
;
718 Exynos_OSAL_Log(EXYNOS_LOG_TRACE
, "%s: OMX_IndexParamUseAndroidNativeBuffer, portIndex: %d", __func__
, portIndex
);
720 ret
= Exynos_OMX_Check_SizeVersion(pANBParams
, sizeof(UseAndroidNativeBufferParams
));
721 if (ret
!= OMX_ErrorNone
) {
722 Exynos_OSAL_Log(EXYNOS_LOG_ERROR
, "%s: Exynos_OMX_Check_SizeVersion(UseAndroidNativeBufferParams) is failed", __func__
);
726 if (portIndex
>= pExynosComponent
->portParam
.nPorts
) {
727 ret
= OMX_ErrorBadPortIndex
;
731 pExynosPort
= &pExynosComponent
->pExynosPort
[portIndex
];
732 if (CHECK_PORT_TUNNELED(pExynosPort
) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort
)) {
733 ret
= OMX_ErrorBadPortIndex
;
737 if (pExynosPort
->portState
!= OMX_StateIdle
) {
738 Exynos_OSAL_Log(EXYNOS_LOG_ERROR
, "%s: Port state should be IDLE", __func__
);
739 ret
= OMX_ErrorIncorrectStateOperation
;
743 pANB
= pANBParams
->nativeBuffer
.get();
745 /* MALI alignment restriction */
746 nSizeBytes
= ALIGN(pANB
->width
, 16) * ALIGN(pANB
->height
, 16);
747 nSizeBytes
+= ALIGN(pANB
->width
/ 2, 16) * ALIGN(pANB
->height
/ 2, 16) * 2;
749 ret
= useAndroidNativeBuffer(pExynosPort
,
750 pANBParams
->bufferHeader
,
751 pANBParams
->nPortIndex
,
752 pANBParams
->pAppPrivate
,
755 if (ret
!= OMX_ErrorNone
) {
756 Exynos_OSAL_Log(EXYNOS_LOG_ERROR
, "%s: useAndroidNativeBuffer is failed: err=0x%x", __func__
,ret
);
762 case OMX_IndexParamStoreMetaDataBuffer
:
764 StoreMetaDataInBuffersParams
*pANBParams
= (StoreMetaDataInBuffersParams
*) ComponentParameterStructure
;
765 OMX_U32 portIndex
= pANBParams
->nPortIndex
;
766 EXYNOS_OMX_BASEPORT
*pExynosPort
= NULL
;
768 Exynos_OSAL_Log(EXYNOS_LOG_TRACE
, "%s: OMX_IndexParamStoreMetaDataBuffer", __func__
);
770 ret
= Exynos_OMX_Check_SizeVersion(pANBParams
, sizeof(StoreMetaDataInBuffersParams
));
771 if (ret
!= OMX_ErrorNone
) {
772 Exynos_OSAL_Log(EXYNOS_LOG_ERROR
, "%s: Exynos_OMX_Check_SizeVersion(StoreMetaDataInBuffersParams) is failed", __func__
);
776 if (portIndex
>= pExynosComponent
->portParam
.nPorts
) {
777 ret
= OMX_ErrorBadPortIndex
;
781 pExynosPort
= &pExynosComponent
->pExynosPort
[portIndex
];
782 if (CHECK_PORT_TUNNELED(pExynosPort
) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort
)) {
783 ret
= OMX_ErrorBadPortIndex
;
787 pExynosPort
->bStoreMetaData
= pANBParams
->bStoreMetaData
;
788 if (pExynosComponent
->codecType
== HW_VIDEO_ENC_CODEC
) {
789 EXYNOS_OMX_VIDEOENC_COMPONENT
*pVideoEnc
= (EXYNOS_OMX_VIDEOENC_COMPONENT
*)pExynosComponent
->hComponentHandle
;;
790 } else if (pExynosComponent
->codecType
== HW_VIDEO_DEC_CODEC
) {
791 EXYNOS_OMX_VIDEODEC_COMPONENT
*pVideoDec
= (EXYNOS_OMX_VIDEODEC_COMPONENT
*)pExynosComponent
->hComponentHandle
;;
792 if ((portIndex
== OUTPUT_PORT_INDEX
) &&
793 (pExynosPort
->bStoreMetaData
== OMX_TRUE
) &&
794 ((pExynosPort
->bufferProcessType
& BUFFER_ANBSHARE
) == BUFFER_ANBSHARE
)) {
795 pExynosPort
->bufferProcessType
= BUFFER_SHARE
;
796 pExynosPort
->portDefinition
.format
.video
.eColorFormat
= (OMX_COLOR_FORMATTYPE
)OMX_SEC_COLOR_FormatNV12Tiled
;
797 Exynos_OSAL_Log(EXYNOS_LOG_TRACE
, "OMX_IndexParamStoreMetaDataBuffer & bufferProcessType change to BUFFER_SHARE");
798 } else if ((portIndex
== OUTPUT_PORT_INDEX
) &&
799 (pExynosPort
->bStoreMetaData
== OMX_FALSE
&& pExynosPort
->bIsANBEnabled
== OMX_FALSE
) &&
800 pExynosPort
->bufferProcessType
== BUFFER_SHARE
) {
801 pExynosPort
->bufferProcessType
= (EXYNOS_OMX_BUFFERPROCESS_TYPE
)(BUFFER_COPY
| BUFFER_ANBSHARE
);
802 pExynosPort
->portDefinition
.format
.video
.eColorFormat
= OMX_COLOR_FormatYUV420Planar
;
803 Exynos_OSAL_Log(EXYNOS_LOG_TRACE
, "No OMX_IndexParamStoreMetaDataBuffer => reset bufferProcessType");
812 Exynos_OSAL_Log(EXYNOS_LOG_ERROR
, "%s: Unsupported index (%d)", __func__
, nIndex
);
813 ret
= OMX_ErrorUnsupportedIndex
;
825 OMX_ERRORTYPE
Exynos_OSAL_GetInfoFromMetaData(OMX_IN OMX_BYTE pBuffer
,
826 OMX_OUT OMX_PTR
*ppBuf
)
828 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
829 MetadataBufferType type
;
834 * meta data contains the following data format.
835 * payload depends on the MetadataBufferType
836 * --------------------------------------------------------------
837 * | MetadataBufferType | payload |
838 * --------------------------------------------------------------
840 * If MetadataBufferType is kMetadataBufferTypeCameraSource, then
841 * --------------------------------------------------------------
842 * | kMetadataBufferTypeCameraSource | physical addr. of Y |physical addr. of CbCr |
843 * --------------------------------------------------------------
845 * If MetadataBufferType is kMetadataBufferTypeGrallocSource, then
846 * --------------------------------------------------------------
847 * | kMetadataBufferTypeGrallocSource | buffer_handle_t |
848 * --------------------------------------------------------------
851 /* MetadataBufferType */
852 Exynos_OSAL_Memcpy(&type
, (MetadataBufferType
*)pBuffer
, sizeof(MetadataBufferType
));
854 if (type
== kMetadataBufferTypeCameraSource
) {
855 void *pAddress
= NULL
;
858 Exynos_OSAL_Memcpy(&pAddress
, pBuffer
+ sizeof(MetadataBufferType
), sizeof(void *));
859 ppBuf
[0] = (void *)pAddress
;
861 /* Address. of CbCr */
862 Exynos_OSAL_Memcpy(&pAddress
, pBuffer
+ sizeof(MetadataBufferType
) + sizeof(void *), sizeof(void *));
863 ppBuf
[1] = (void *)pAddress
;
865 } else if (type
== kMetadataBufferTypeGrallocSource
) {
866 buffer_handle_t pBufHandle
;
868 /* buffer_handle_t */
869 Exynos_OSAL_Memcpy(&pBufHandle
, pBuffer
+ sizeof(MetadataBufferType
), sizeof(buffer_handle_t
));
870 ppBuf
[0] = (OMX_PTR
)pBufHandle
;
879 OMX_ERRORTYPE
Exynos_OSAL_SetPrependSPSPPSToIDR(
880 OMX_PTR pComponentParameterStructure
,
881 OMX_PTR pbPrependSpsPpsToIdr
)
883 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
884 PrependSPSPPSToIDRFramesParams
*pANBParams
= (PrependSPSPPSToIDRFramesParams
*)pComponentParameterStructure
;
886 ret
= Exynos_OMX_Check_SizeVersion(pANBParams
, sizeof(PrependSPSPPSToIDRFramesParams
));
887 if (ret
!= OMX_ErrorNone
) {
888 Exynos_OSAL_Log(EXYNOS_LOG_ERROR
, "%s: Exynos_OMX_Check_SizeVersion(PrependSPSPPSToIDRFrames) is failed", __func__
);
892 (*((OMX_BOOL
*)pbPrependSpsPpsToIdr
)) = pANBParams
->bEnable
;
898 OMX_COLOR_FORMATTYPE
Exynos_OSAL_Hal2OMXPixelFormat(
899 unsigned int hal_format
)
901 OMX_COLOR_FORMATTYPE omx_format
;
902 switch (hal_format
) {
903 case HAL_PIXEL_FORMAT_YCbCr_422_I
:
904 omx_format
= OMX_COLOR_FormatYCbYCr
;
906 case HAL_PIXEL_FORMAT_YCbCr_420_P
:
907 omx_format
= OMX_COLOR_FormatYUV420Planar
;
909 case HAL_PIXEL_FORMAT_YCbCr_420_SP
:
910 omx_format
= OMX_COLOR_FormatYUV420SemiPlanar
;
912 case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP_TILED
:
913 omx_format
= (OMX_COLOR_FORMATTYPE
)OMX_SEC_COLOR_FormatNV12TPhysicalAddress
;
915 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED
:
916 omx_format
= (OMX_COLOR_FORMATTYPE
)OMX_SEC_COLOR_FormatNV12Tiled
;
918 case HAL_PIXEL_FORMAT_BGRA_8888
:
919 case HAL_PIXEL_FORMAT_CUSTOM_ARGB_8888
:
920 omx_format
= OMX_COLOR_Format32bitARGB8888
;
923 omx_format
= OMX_COLOR_FormatYUV420Planar
;
929 unsigned int Exynos_OSAL_OMX2HalPixelFormat(
930 OMX_COLOR_FORMATTYPE omx_format
)
932 unsigned int hal_format
;
933 switch (omx_format
) {
934 case OMX_COLOR_FormatYCbYCr
:
935 hal_format
= HAL_PIXEL_FORMAT_YCbCr_422_I
;
937 case OMX_COLOR_FormatYUV420Planar
:
938 hal_format
= HAL_PIXEL_FORMAT_YCbCr_420_P
;
940 case OMX_COLOR_FormatYUV420SemiPlanar
:
941 hal_format
= HAL_PIXEL_FORMAT_YCbCr_420_SP
;
943 case OMX_SEC_COLOR_FormatNV12TPhysicalAddress
:
944 hal_format
= HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP_TILED
;
946 case OMX_SEC_COLOR_FormatNV12Tiled
:
947 hal_format
= HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED
;
949 case OMX_COLOR_Format32bitARGB8888
:
950 hal_format
= HAL_PIXEL_FORMAT_CUSTOM_ARGB_8888
;
953 hal_format
= HAL_PIXEL_FORMAT_YCbCr_420_P
;