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_Platform_Specific.c
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 "Exynos_OSAL_Semaphore.h"
33 #include "Exynos_OMX_Baseport.h"
34 #include "Exynos_OMX_Basecomponent.h"
35 #include "Exynos_OMX_Macros.h"
36 #include "Exynos_OMX_Vdec.h"
37 #include "Exynos_OSAL_Platform_Specific.h"
38 #include "exynos_format.h"
40 #include "ExynosVideoApi.h"
43 #define EXYNOS_LOG_TAG "Exynos_OSAL_PB"
44 #define EXYNOS_LOG_OFF
45 #include "Exynos_OSAL_Log.h"
52 OMX_ERRORTYPE Exynos_OSAL_LockPBHandle(
53 OMX_IN OMX_U32 handle,
55 OMX_IN OMX_U32 height,
56 OMX_IN OMX_COLOR_FORMATTYPE format,
57 OMX_OUT OMX_PTR planes)
61 OMX_ERRORTYPE ret = OMX_ErrorNone;
64 GraphicBufferMapper &mapper = GraphicBufferMapper::get();
65 buffer_handle_t bufferHandle = (buffer_handle_t) handle;
67 private_handle_t *priv_hnd = (private_handle_t *) bufferHandle;
69 Rect bounds(width, height);
70 ExynosVideoPlane *vplanes = (ExynosVideoPlane *) planes;
71 void *vaddr[MAX_BUFFER_PLANE];
73 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle);
78 case OMX_COLOR_FormatYUV420Planar:
79 case OMX_COLOR_FormatYUV420SemiPlanar:
80 case OMX_SEC_COLOR_FormatNV12Tiled:
81 usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_YUV_ADDR;
84 usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
88 if (mapper.lock(bufferHandle, usage, bounds, vaddr) != 0) {
89 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: mapper.lock() fail", __func__);
90 ret = OMX_ErrorUndefined;
95 vplanes[0].fd = priv_hnd->fd;
96 vplanes[0].offset = 0;
97 vplanes[1].fd = priv_hnd->u_fd;
98 vplanes[1].offset = priv_hnd->uoffset;
99 vplanes[2].fd = priv_hnd->v_fd;
100 vplanes[2].offset = priv_hnd->voffset;
102 vplanes[0].addr = vaddr[0];
103 vplanes[1].addr = vaddr[1];
104 vplanes[2].addr = vaddr[2];
106 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer locked: 0x%x", __func__, *vaddr);
115 OMX_ERRORTYPE Exynos_OSAL_UnlockPBHandle(OMX_IN OMX_U32 handle)
119 OMX_ERRORTYPE ret = OMX_ErrorNone;
122 GraphicBufferMapper &mapper = GraphicBufferMapper::get();
123 buffer_handle_t bufferHandle = (buffer_handle_t) handle;
125 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle);
127 if (mapper.unlock(bufferHandle) != 0) {
128 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: mapper.unlock() fail", __func__);
129 ret = OMX_ErrorUndefined;
133 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer unlocked: 0x%x", __func__, handle);
142 OMX_ERRORTYPE Exynos_OSAL_LockPB(
143 OMX_IN OMX_PTR pBuffer,
144 OMX_IN OMX_U32 width,
145 OMX_IN OMX_U32 height,
146 OMX_IN OMX_COLOR_FORMATTYPE format,
147 OMX_OUT OMX_U32 *pStride,
148 OMX_OUT OMX_PTR planes)
152 OMX_ERRORTYPE ret = OMX_ErrorNone;
155 ExynosVideoPlane *vplanes = (ExynosVideoPlane *) planes;
156 SCMN_IMGB *buffer = (SCMN_IMGB *) pBuffer;
159 vplanes[0].fd = buffer->fd[0];
160 vplanes[0].offset = 0;
161 vplanes[1].fd = buffer->fd[1];
162 vplanes[1].offset = 0; //priv_hnd->uoffset;
163 vplanes[2].fd = 0; //priv_hnd->v_fd;
164 vplanes[2].offset = 0; //priv_hnd->voffset;
166 vplanes[0].addr = buffer->a[0]; //vaddr[0];
167 vplanes[1].addr = buffer->a[1]; //vaddr[1];
168 vplanes[2].addr = NULL; //vaddr[2];
170 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "Exynos_OSAL_LockPB:fd[0](%d) fd[1](%d) a[0](%p) a[1](%p)",
171 buffer->fd[0], buffer->fd[1], buffer->a[0], buffer->a[1]);
173 android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
175 ret = Exynos_OSAL_LockPBHandle((OMX_U32)pANB->handle, width, height, format, planes);
176 *pStride = pANB->stride;
186 OMX_ERRORTYPE Exynos_OSAL_UnlockPB(OMX_IN OMX_PTR pBuffer, EXYNOS_OMX_DATA *pData, EXYNOS_OMX_BASEPORT *pExynosPort,EXYNOS_OMX_BASEPORT *pExynosInPort)
188 OMX_ERRORTYPE Exynos_OSAL_UnlockPB(OMX_IN OMX_PTR pBuffer, EXYNOS_OMX_DATA *pData)
193 OMX_ERRORTYPE ret = OMX_ErrorNone;
195 SCMN_IMGB *pSlpOutBuf = NULL;
196 DECODE_CODEC_EXTRA_BUFFERINFO *pBufferInfo = NULL;
198 pSlpOutBuf = (SCMN_IMGB *)pBuffer;
199 if (pSlpOutBuf == NULL) {
200 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "pBuffer is NULL!");
201 ret = OMX_ErrorInsufficientResources;
204 memset(pSlpOutBuf, 0, sizeof(SCMN_IMGB));
206 pBufferInfo = (DECODE_CODEC_EXTRA_BUFFERINFO *)pData->extInfo;
208 if (pExynosPort->cropRectangle.nWidth != 0 && pExynosPort->cropRectangle.nHeight != 0) {
209 /* modify for h264 trim */
210 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "this has cropRectangle(h264).crop.nWidth = %d, crop.nHeight = %d",
211 pExynosPort->cropRectangle.nWidth, pExynosPort->cropRectangle.nHeight);
212 pSlpOutBuf->w[0] = pExynosPort->cropRectangle.nWidth;
213 pSlpOutBuf->w[1] = pExynosPort->cropRectangle.nWidth;
214 pSlpOutBuf->h[0] = pExynosPort->cropRectangle.nHeight;
215 pSlpOutBuf->h[1] = (pExynosPort->cropRectangle.nHeight/2);
217 pSlpOutBuf->s[0] = ALIGN(pExynosPort->cropRectangle.nWidth, S5P_FIMV_NV12MT_HALIGN); /* need to check. stride */
218 pSlpOutBuf->s[1] = ALIGN(pExynosPort->cropRectangle.nWidth, S5P_FIMV_NV12MT_HALIGN);
219 pSlpOutBuf->e[0] = ALIGN(pExynosPort->cropRectangle.nHeight, S5P_FIMV_NV12MT_VALIGN); /* need to check. elevation */
220 pSlpOutBuf->e[1] = ALIGN((pExynosPort->cropRectangle.nHeight/2), S5P_FIMV_NV12MT_VALIGN);
222 pSlpOutBuf->w[0] = pBufferInfo->imageWidth;
223 pSlpOutBuf->w[1] = pBufferInfo->imageWidth;
224 pSlpOutBuf->h[0] = pBufferInfo->imageHeight;
225 pSlpOutBuf->h[1] = (pBufferInfo->imageHeight/2);
227 pSlpOutBuf->s[0] = ALIGN(pBufferInfo->imageWidth, S5P_FIMV_NV12MT_HALIGN); /* need to check. stride */
228 pSlpOutBuf->s[1] = ALIGN(pBufferInfo->imageWidth, S5P_FIMV_NV12MT_HALIGN);
229 pSlpOutBuf->e[0] = ALIGN(pBufferInfo->imageHeight, S5P_FIMV_NV12MT_VALIGN); /* need to check. elevation */
230 pSlpOutBuf->e[1] = ALIGN((pBufferInfo->imageHeight/2), S5P_FIMV_NV12MT_VALIGN);
236 if (pVideoDec->bDRMPlayerMode == OMX_TRUE) {
237 pSlpOutBuf->a[0] = 0;
238 pSlpOutBuf->a[1] = 0;
241 pSlpOutBuf->a[0] = pData->buffer.multiPlaneBuffer.dataBuffer[0];
242 pSlpOutBuf->a[1] = pData->buffer.multiPlaneBuffer.dataBuffer[1];
244 pSlpOutBuf->a[2] = 0; /* omx do not use this plane */
246 pSlpOutBuf->fd[0] = pData->buffer.multiPlaneBuffer.fd[0];
247 pSlpOutBuf->fd[1] = pData->buffer.multiPlaneBuffer.fd[1];
248 pSlpOutBuf->fd[2] = 0;
250 if(pExynosInPort->portDefinition.format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
252 pSlpOutBuf->y_size = calc_plane(pBufferInfo->imageWidth,pBufferInfo->imageHeight);
253 pSlpOutBuf->uv_size = calc_plane(pBufferInfo->imageWidth,(pBufferInfo->imageHeight) / 2);
254 Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"H264 foramt and y_size=%d, uv_size=%d",pSlpOutBuf->y_size,pSlpOutBuf->uv_size);
256 pSlpOutBuf->y_size= calc_yplane(pBufferInfo->imageWidth,pBufferInfo->imageHeight);
257 pSlpOutBuf->uv_size = calc_uvplane(pBufferInfo->imageWidth,(pBufferInfo->imageHeight) / 2);
258 Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"foramt is %d, and y_size=%d, uv_size=%d",pExynosInPort->portDefinition.format.video.eCompressionFormat ,pSlpOutBuf->y_size,pSlpOutBuf->uv_size);
262 pSlpOutBuf->buf_share_method = 1; /* use fd mode */
264 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "fd (%d, %d, %d) received from MFC", pSlpOutBuf->fd[0], pSlpOutBuf->fd[1], pSlpOutBuf->fd[2]);
266 android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
268 ret = Exynos_OSAL_UnlockPBHandle((OMX_U32)pANB->handle);
277 OMX_ERRORTYPE useAndroidNativeBuffer(
278 EXYNOS_OMX_BASEPORT *pExynosPort,
279 OMX_BUFFERHEADERTYPE **ppBufferHdr,
285 OMX_ERRORTYPE ret = OMX_ErrorNone;
286 OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL;
288 OMX_U32 width, height;
290 ExynosVideoPlane planes[MAX_BUFFER_PLANE];
294 if (pExynosPort == NULL) {
295 ret = OMX_ErrorBadParameter;
298 if (pExynosPort->portState != OMX_StateIdle) {
299 ret = OMX_ErrorIncorrectStateOperation;
302 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
303 ret = OMX_ErrorBadPortIndex;
307 temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE));
308 if (temp_bufferHeader == NULL) {
309 ret = OMX_ErrorInsufficientResources;
312 Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
314 for (i = 0; i < pExynosPort->portDefinition.nBufferCountActual; i++) {
315 if (pExynosPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) {
316 pExynosPort->extendBufferHeader[i].OMXBufferHeader = temp_bufferHeader;
317 pExynosPort->bufferStateAllocate[i] = (BUFFER_STATE_ASSIGNED | HEADER_STATE_ALLOCATED);
318 INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE);
319 temp_bufferHeader->pBuffer = pBuffer;
320 temp_bufferHeader->nAllocLen = nSizeBytes;
321 temp_bufferHeader->pAppPrivate = pAppPrivate;
322 if (nPortIndex == INPUT_PORT_INDEX)
323 temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX;
325 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX;
327 width = pExynosPort->portDefinition.format.video.nFrameWidth;
328 height = pExynosPort->portDefinition.format.video.nFrameHeight;
329 Exynos_OSAL_LockPB(temp_bufferHeader->pBuffer, width, height,
330 pExynosPort->portDefinition.format.video.eColorFormat,
333 pExynosPort->extendBufferHeader[i].buf_fd[0] = planes[0].fd;
334 pExynosPort->extendBufferHeader[i].buf_fd[1] = planes[1].fd;
335 pExynosPort->extendBufferHeader[i].buf_fd[2] = planes[2].fd;
337 pExynosPort->extendBufferHeader[i].pYUVBuf[0] = planes[0].addr;
338 pExynosPort->extendBufferHeader[i].pYUVBuf[1] = planes[1].addr;
339 pExynosPort->extendBufferHeader[i].pYUVBuf[2] = planes[2].addr;
340 Exynos_OSAL_UnlockANB(temp_bufferHeader->pBuffer);
341 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "useAndroidNativeBuffer: buf %d pYUVBuf[0]:0x%x , pYUVBuf[1]:0x%x ",
342 i, pExynosPort->extendBufferHeader[i].pYUVBuf[0],
343 pExynosPort->extendBufferHeader[i].pYUVBuf[1]);
345 pExynosPort->assignedBufferNum++;
346 if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) {
347 pExynosPort->portDefinition.bPopulated = OMX_TRUE;
348 /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */
349 Exynos_OSAL_SemaphorePost(pExynosPort->loadedResource);
350 /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */
352 *ppBufferHdr = temp_bufferHeader;
359 Exynos_OSAL_Free(temp_bufferHeader);
360 ret = OMX_ErrorInsufficientResources;
369 OMX_ERRORTYPE Exynos_OSAL_GetPBParameter(
370 OMX_IN OMX_HANDLETYPE hComponent,
371 OMX_IN OMX_INDEXTYPE nIndex,
372 OMX_INOUT OMX_PTR ComponentParameterStructure)
374 OMX_ERRORTYPE ret = OMX_ErrorNone;
375 OMX_COMPONENTTYPE *pOMXComponent = NULL;
376 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
380 if (hComponent == NULL) {
381 ret = OMX_ErrorBadParameter;
385 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
386 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
387 if (ret != OMX_ErrorNone) {
391 if (pOMXComponent->pComponentPrivate == NULL) {
392 ret = OMX_ErrorBadParameter;
396 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
397 if (pExynosComponent->currentState == OMX_StateInvalid ) {
398 ret = OMX_ErrorInvalidState;
402 if (ComponentParameterStructure == NULL) {
403 ret = OMX_ErrorBadParameter;
408 #if 0 /* SLP_PLATFORM */
409 case OMX_IndexParamGetAndroidNativeBuffer:
411 GetAndroidNativeBufferUsageParams *pANBParams = (GetAndroidNativeBufferUsageParams *) ComponentParameterStructure;
412 OMX_U32 portIndex = pANBParams->nPortIndex;
414 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamGetAndroidNativeBuffer", __func__);
416 ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(GetAndroidNativeBufferUsageParams));
417 if (ret != OMX_ErrorNone) {
418 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(GetAndroidNativeBufferUsageParams) is failed", __func__);
422 if (portIndex >= pExynosComponent->portParam.nPorts) {
423 ret = OMX_ErrorBadPortIndex;
427 /* NOTE: OMX_IndexParamGetAndroidNativeBuffer returns original 'nUsage' without any
428 * modifications since currently not defined what the 'nUsage' is for.
430 pANBParams->nUsage |= (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP
431 | GRALLOC_USAGE_HW_ION | GRALLOC_USAGE_HWC_HWOVERLAY);
437 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
438 ret = OMX_ErrorUnsupportedIndex;
450 OMX_ERRORTYPE Exynos_OSAL_SetPBParameter(
451 OMX_IN OMX_HANDLETYPE hComponent,
452 OMX_IN OMX_INDEXTYPE nIndex,
453 OMX_IN OMX_PTR ComponentParameterStructure)
455 OMX_ERRORTYPE ret = OMX_ErrorNone;
456 OMX_COMPONENTTYPE *pOMXComponent = NULL;
457 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
458 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
462 if (hComponent == NULL) {
463 ret = OMX_ErrorBadParameter;
467 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
468 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
469 if (ret != OMX_ErrorNone) {
473 if (pOMXComponent->pComponentPrivate == NULL) {
474 ret = OMX_ErrorBadParameter;
478 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
479 if (pExynosComponent->currentState == OMX_StateInvalid ) {
480 ret = OMX_ErrorInvalidState;
484 if (ComponentParameterStructure == NULL) {
485 ret = OMX_ErrorBadParameter;
489 pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
493 case OMX_IndexParamEnablePlatformSpecificBuffers:
495 case OMX_IndexParamEnableAndroidBuffers:
498 EnableGemBuffersParams *pPBParams = (EnableGemBuffersParams *) ComponentParameterStructure;
499 OMX_U32 portIndex = pPBParams->nPortIndex;
500 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
502 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamEnablePlatformSpecificBuffers", __func__);
504 ret = Exynos_OMX_Check_SizeVersion(pPBParams, sizeof(EnableGemBuffersParams));
505 if (ret != OMX_ErrorNone) {
506 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(EnableGemBuffersParams) is failed", __func__);
510 if (portIndex >= pExynosComponent->portParam.nPorts) {
511 ret = OMX_ErrorBadPortIndex;
515 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
516 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
517 ret = OMX_ErrorBadPortIndex;
522 /* PB and DPB Buffer Sharing */
523 if ((portIndex == OUTPUT_PORT_INDEX) &&
524 ((pExynosPort->bufferProcessType & BUFFER_PBSHARE) == BUFFER_PBSHARE)) {
525 pExynosPort->bufferProcessType = BUFFER_SHARE;
526 pExynosPort->portDefinition.format.video.eColorFormat = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
527 Exynos_OSAL_Log(EXYNOS_LOG_INFO, "output buffer sharing mode is on");
529 Exynos_OSAL_Log(EXYNOS_LOG_INFO, "pExynosPort->portDefinition.format.video.eColorFormat: 0x%x", pExynosPort->portDefinition.format.video.eColorFormat);
531 if ((portIndex == OUTPUT_PORT_INDEX) &&
532 (pExynosPort->bufferProcessType & BUFFER_COPY)) {
533 pExynosPort->bufferProcessType = BUFFER_COPY;
534 pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
537 pExynosPort->bIsPBEnabled = pPBParams->enable;
538 Exynos_OSAL_Log(EXYNOS_LOG_INFO, "pExynosPort->bIsPBEnabled: %d", pExynosPort->bIsPBEnabled);
542 #if 0 /* SLP_PLATFORM */
543 case OMX_IndexParamUseAndroidNativeBuffer:
545 UseAndroidNativeBufferParams *pANBParams = (UseAndroidNativeBufferParams *) ComponentParameterStructure;
546 OMX_U32 portIndex = pANBParams->nPortIndex;
547 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
548 android_native_buffer_t *pANB;
551 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamUseAndroidNativeBuffer, portIndex: %d", __func__, portIndex);
553 ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(UseAndroidNativeBufferParams));
554 if (ret != OMX_ErrorNone) {
555 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(UseAndroidNativeBufferParams) is failed", __func__);
559 if (portIndex >= pExynosComponent->portParam.nPorts) {
560 ret = OMX_ErrorBadPortIndex;
564 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
565 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
566 ret = OMX_ErrorBadPortIndex;
570 if (pExynosPort->portState != OMX_StateIdle) {
571 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Port state should be IDLE", __func__);
572 ret = OMX_ErrorIncorrectStateOperation;
576 pANB = pANBParams->nativeBuffer.get();
578 /* MALI alignment restriction */
579 nSizeBytes = ALIGN(pANB->width, 16) * ALIGN(pANB->height, 16);
580 nSizeBytes += ALIGN(pANB->width / 2, 16) * ALIGN(pANB->height / 2, 16) * 2;
582 ret = useAndroidNativeBuffer(pExynosPort,
583 pANBParams->bufferHeader,
584 pANBParams->nPortIndex,
585 pANBParams->pAppPrivate,
588 if (ret != OMX_ErrorNone) {
589 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: useAndroidNativeBuffer is failed: err=0x%x", __func__,ret);
595 case OMX_IndexParamStoreMetaDataBuffer:
597 StoreMetaDataInBuffersParams *pANBParams = (StoreMetaDataInBuffersParams *) ComponentParameterStructure;
598 OMX_U32 portIndex = pANBParams->nPortIndex;
599 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
601 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamStoreMetaDataBuffer", __func__);
603 ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(StoreMetaDataInBuffersParams));
604 if (ret != OMX_ErrorNone) {
605 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(StoreMetaDataInBuffersParams) is failed", __func__);
609 if (portIndex >= pExynosComponent->portParam.nPorts) {
610 ret = OMX_ErrorBadPortIndex;
614 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
615 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
616 ret = OMX_ErrorBadPortIndex;
620 pExynosPort->bStoreMetaData = pANBParams->bStoreMetaData;
626 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
627 ret = OMX_ErrorUnsupportedIndex;
639 #if 0 // we can remove this later.
640 OMX_ERRORTYPE Exynos_OSAL_GetInfoFromMetaData(OMX_IN OMX_BYTE pBuffer,
641 OMX_OUT OMX_PTR *ppBuf)
643 OMX_ERRORTYPE ret = OMX_ErrorNone;
644 MetadataBufferType type;
649 * meta data contains the following data format.
650 * payload depends on the MetadataBufferType
651 * --------------------------------------------------------------
652 * | MetadataBufferType | payload |
653 * --------------------------------------------------------------
655 * If MetadataBufferType is kMetadataBufferTypeCameraSource, then
656 * --------------------------------------------------------------
657 * | kMetadataBufferTypeCameraSource | physical addr. of Y |physical addr. of CbCr |
658 * --------------------------------------------------------------
660 * If MetadataBufferType is kMetadataBufferTypeGrallocSource, then
661 * --------------------------------------------------------------
662 * | kMetadataBufferTypeGrallocSource | buffer_handle_t |
663 * --------------------------------------------------------------
666 /* MetadataBufferType */
667 Exynos_OSAL_Memcpy(&type, (MetadataBufferType *)pBuffer, sizeof(MetadataBufferType));
669 if (type == kMetadataBufferTypeCameraSource) {
670 void *pAddress = NULL;
673 Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType), sizeof(void *));
674 ppBuf[0] = (void *)pAddress;
676 /* Address. of CbCr */
677 Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType) + sizeof(void *), sizeof(void *));
678 ppBuf[1] = (void *)pAddress;
680 } else if (type == kMetadataBufferTypeGrallocSource) {
681 buffer_handle_t pBufHandle;
683 /* buffer_handle_t */
684 Exynos_OSAL_Memcpy(&pBufHandle, pBuffer + sizeof(MetadataBufferType), sizeof(buffer_handle_t));
685 ppBuf[0] = (OMX_PTR)pBufHandle;
694 OMX_COLOR_FORMATTYPE Exynos_OSAL_Hal2OMXPixelFormat(
695 unsigned int hal_format)
697 OMX_COLOR_FORMATTYPE omx_format;
698 switch (hal_format) {
699 case HAL_PIXEL_FORMAT_YCbCr_422_I:
700 omx_format = OMX_COLOR_FormatYCbYCr;
702 case HAL_PIXEL_FORMAT_YCbCr_420_P:
703 omx_format = OMX_COLOR_FormatYUV420Planar;
705 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
706 omx_format = OMX_COLOR_FormatYUV420SemiPlanar;
708 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
709 omx_format = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
711 case HAL_PIXEL_FORMAT_ARGB888:
712 omx_format = OMX_COLOR_Format32bitARGB8888;
715 omx_format = OMX_COLOR_FormatYUV420Planar;
721 unsigned int Exynos_OSAL_OMX2HalPixelFormat(
722 OMX_COLOR_FORMATTYPE omx_format)
724 unsigned int hal_format;
725 switch (omx_format) {
726 case OMX_COLOR_FormatYCbYCr:
727 hal_format = HAL_PIXEL_FORMAT_YCbCr_422_I;
729 case OMX_COLOR_FormatYUV420Planar:
730 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
732 case OMX_COLOR_FormatYUV420SemiPlanar:
733 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP;
735 case OMX_SEC_COLOR_FormatNV12Tiled:
736 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED;
738 case OMX_COLOR_Format32bitARGB8888:
739 hal_format = HAL_PIXEL_FORMAT_ARGB888;
742 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;