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)
33 #include "Exynos_OSAL_Semaphore.h"
34 #include "Exynos_OMX_Baseport.h"
35 #include "Exynos_OMX_Basecomponent.h"
36 #include "Exynos_OMX_Macros.h"
37 #include "Exynos_OMX_Vdec.h"
38 #include "Exynos_OSAL_Platform_Specific.h"
39 #include "exynos_format.h"
41 #include "ExynosVideoApi.h"
44 #define EXYNOS_LOG_TAG "Exynos_OSAL_PB"
45 #define EXYNOS_LOG_OFF
46 #include "Exynos_OSAL_Log.h"
53 OMX_ERRORTYPE Exynos_OSAL_LockPBHandle(
54 OMX_IN OMX_U32 handle,
56 OMX_IN OMX_U32 height,
57 OMX_IN OMX_COLOR_FORMATTYPE format,
58 OMX_OUT OMX_PTR planes)
62 OMX_ERRORTYPE ret = OMX_ErrorNone;
65 GraphicBufferMapper &mapper = GraphicBufferMapper::get();
66 buffer_handle_t bufferHandle = (buffer_handle_t) handle;
68 private_handle_t *priv_hnd = (private_handle_t *) bufferHandle;
70 Rect bounds(width, height);
71 ExynosVideoPlane *vplanes = (ExynosVideoPlane *) planes;
72 void *vaddr[MAX_BUFFER_PLANE];
74 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle);
79 case OMX_COLOR_FormatYUV420Planar:
80 case OMX_COLOR_FormatYUV420SemiPlanar:
81 case OMX_SEC_COLOR_FormatNV12Tiled:
82 usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_YUV_ADDR;
85 usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
89 if (mapper.lock(bufferHandle, usage, bounds, vaddr) != 0) {
90 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: mapper.lock() fail", __func__);
91 ret = OMX_ErrorUndefined;
96 vplanes[0].fd = priv_hnd->fd;
97 vplanes[0].offset = 0;
98 vplanes[1].fd = priv_hnd->u_fd;
99 vplanes[1].offset = priv_hnd->uoffset;
100 vplanes[2].fd = priv_hnd->v_fd;
101 vplanes[2].offset = priv_hnd->voffset;
103 vplanes[0].addr = vaddr[0];
104 vplanes[1].addr = vaddr[1];
105 vplanes[2].addr = vaddr[2];
107 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer locked: 0x%x", __func__, *vaddr);
116 OMX_ERRORTYPE Exynos_OSAL_UnlockPBHandle(OMX_IN OMX_U32 handle)
120 OMX_ERRORTYPE ret = OMX_ErrorNone;
123 GraphicBufferMapper &mapper = GraphicBufferMapper::get();
124 buffer_handle_t bufferHandle = (buffer_handle_t) handle;
126 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle);
128 if (mapper.unlock(bufferHandle) != 0) {
129 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: mapper.unlock() fail", __func__);
130 ret = OMX_ErrorUndefined;
134 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer unlocked: 0x%x", __func__, handle);
143 OMX_ERRORTYPE Exynos_OSAL_LockPB(
144 OMX_IN OMX_PTR pBuffer,
145 OMX_IN OMX_U32 width,
146 OMX_IN OMX_U32 height,
147 OMX_IN OMX_COLOR_FORMATTYPE format,
148 OMX_OUT OMX_U32 *pStride,
149 OMX_OUT OMX_PTR planes)
153 OMX_ERRORTYPE ret = OMX_ErrorNone;
156 ExynosVideoPlane *vplanes = (ExynosVideoPlane *) planes;
157 MMVideoBuffer *buffer = (MMVideoBuffer *) pBuffer;
160 vplanes[0].fd = buffer->handle.dmabuf_fd[0];
161 vplanes[0].offset = 0;
162 vplanes[1].fd = buffer->handle.dmabuf_fd[1];
163 vplanes[1].offset = 0; //priv_hnd->uoffset;
164 vplanes[2].fd = 0; //priv_hnd->v_fd;
165 vplanes[2].offset = 0; //priv_hnd->voffset;
167 vplanes[0].addr = buffer->data[0]; //vaddr[0];
168 vplanes[1].addr = buffer->data[1]; //vaddr[1];
169 vplanes[2].addr = NULL; //vaddr[2];
171 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "Exynos_OSAL_LockPB:fd[0](%d) fd[1](%d) a[0](%p) a[1](%p)",
172 buffer->handle.dmabuf_fd[0], buffer->handle.dmabuf_fd[1], buffer->data[0], buffer->data[1]);
174 android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
176 ret = Exynos_OSAL_LockPBHandle((OMX_U32)pANB->handle, width, height, format, planes);
177 *pStride = pANB->stride;
187 OMX_ERRORTYPE Exynos_OSAL_UnlockPB(OMX_IN OMX_PTR pBuffer, EXYNOS_OMX_DATA *pData, EXYNOS_OMX_BASEPORT *pExynosPort,EXYNOS_OMX_BASEPORT *pExynosInPort)
189 OMX_ERRORTYPE Exynos_OSAL_UnlockPB(OMX_IN OMX_PTR pBuffer, EXYNOS_OMX_DATA *pData)
194 OMX_ERRORTYPE ret = OMX_ErrorNone;
196 MMVideoBuffer *pSlpOutBuf = NULL;
197 DECODE_CODEC_EXTRA_BUFFERINFO *pBufferInfo = NULL;
199 pSlpOutBuf = (MMVideoBuffer *)pBuffer;
200 if (pSlpOutBuf == NULL) {
201 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "pBuffer is NULL!");
202 ret = OMX_ErrorInsufficientResources;
205 memset(pSlpOutBuf, 0, sizeof(MMVideoBuffer));
207 pBufferInfo = (DECODE_CODEC_EXTRA_BUFFERINFO *)pData->extInfo;
209 if (pExynosPort->cropRectangle.nWidth != 0 && pExynosPort->cropRectangle.nHeight != 0) {
210 /* modify for h264 trim */
211 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "this has cropRectangle(h264).crop.nWidth = %d, crop.nHeight = %d",
212 pExynosPort->cropRectangle.nWidth, pExynosPort->cropRectangle.nWidth);
213 pSlpOutBuf->width[0] = pExynosPort->cropRectangle.nWidth;
214 pSlpOutBuf->width[1] = pExynosPort->cropRectangle.nWidth;
215 pSlpOutBuf->height[0] = pExynosPort->cropRectangle.nHeight;
216 pSlpOutBuf->height[1] = pExynosPort->cropRectangle.nHeight/2;
219 pSlpOutBuf->stride_width[0] = ALIGN(pExynosPort->cropRectangle.nWidth, S5P_FIMV_NV12MT_HALIGN); /* need to check. stride */
220 pSlpOutBuf->stride_width[1] = ALIGN(pExynosPort->cropRectangle.nWidth, S5P_FIMV_NV12MT_HALIGN);
221 pSlpOutBuf->stride_height[0] = ALIGN(pExynosPort->cropRectangle.nHeight, S5P_FIMV_NV12MT_VALIGN); /* need to check. elevation */
222 pSlpOutBuf->stride_height[1] = ALIGN((pExynosPort->cropRectangle.nHeight/2), S5P_FIMV_NV12MT_VALIGN);
224 pSlpOutBuf->width[0] = pBufferInfo->imageWidth;
225 pSlpOutBuf->width[1] = pBufferInfo->imageWidth;
226 pSlpOutBuf->height[0] = pBufferInfo->imageHeight;
227 pSlpOutBuf->height[1] = (pBufferInfo->imageHeight/2);
229 pSlpOutBuf->stride_width[0] = ALIGN(pBufferInfo->imageWidth, S5P_FIMV_NV12MT_HALIGN); /* need to check. stride */
230 pSlpOutBuf->stride_width[1] = ALIGN(pBufferInfo->imageWidth, S5P_FIMV_NV12MT_HALIGN);
231 pSlpOutBuf->stride_height[0] = ALIGN(pBufferInfo->imageHeight, S5P_FIMV_NV12MT_VALIGN); /* need to check. elevation */
232 pSlpOutBuf->stride_height[1] = ALIGN((pBufferInfo->imageHeight/2), S5P_FIMV_NV12MT_VALIGN);
238 if (pVideoDec->bDRMPlayerMode == OMX_TRUE) {
239 pSlpOutBuf->a[0] = 0;
240 pSlpOutBuf->a[1] = 0;
243 pSlpOutBuf->data[0] = pData->buffer.multiPlaneBuffer.dataBuffer[0];
244 pSlpOutBuf->data[1] = pData->buffer.multiPlaneBuffer.dataBuffer[1];
246 pSlpOutBuf->data[2] = 0; /* omx do not use this plane */
248 pSlpOutBuf->handle.dmabuf_fd[0] = pData->buffer.multiPlaneBuffer.fd[0];
249 pSlpOutBuf->handle.dmabuf_fd[1] = pData->buffer.multiPlaneBuffer.fd[1];
250 pSlpOutBuf->handle.dmabuf_fd[2] = 0;
252 if(pExynosInPort->portDefinition.format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
254 pSlpOutBuf->size[0] = calc_plane(pBufferInfo->imageWidth,pBufferInfo->imageHeight);
255 pSlpOutBuf->size[1] = calc_plane(pBufferInfo->imageWidth,(pBufferInfo->imageHeight) / 2);
256 Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"H264 foramt and y_size=%d, uv_size=%d",pSlpOutBuf->size[0],pSlpOutBuf->size[1]);
258 pSlpOutBuf->size[0]= calc_yplane(pBufferInfo->imageWidth,pBufferInfo->imageHeight);
259 pSlpOutBuf->size[1] = calc_uvplane(pBufferInfo->imageWidth,(pBufferInfo->imageHeight) / 2);
260 Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"foramt is %d, and y_size=%d, uv_size=%d",pExynosInPort->portDefinition.format.video.eCompressionFormat ,pSlpOutBuf->size[0],pSlpOutBuf->size[1]);
264 //pSlpOutBuf->type = 1; /* use fd mode */
266 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "fd (%d, %d, %d) received from MFC", pSlpOutBuf->handle.dmabuf_fd[0], pSlpOutBuf->handle.dmabuf_fd[1], pSlpOutBuf->handle.dmabuf_fd[2]);
268 android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
270 ret = Exynos_OSAL_UnlockPBHandle((OMX_U32)pANB->handle);
279 OMX_ERRORTYPE useAndroidNativeBuffer(
280 EXYNOS_OMX_BASEPORT *pExynosPort,
281 OMX_BUFFERHEADERTYPE **ppBufferHdr,
287 OMX_ERRORTYPE ret = OMX_ErrorNone;
288 OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL;
290 OMX_U32 width, height;
292 ExynosVideoPlane planes[MAX_BUFFER_PLANE];
296 if (pExynosPort == NULL) {
297 ret = OMX_ErrorBadParameter;
300 if (pExynosPort->portState != OMX_StateIdle) {
301 ret = OMX_ErrorIncorrectStateOperation;
304 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
305 ret = OMX_ErrorBadPortIndex;
309 temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE));
310 if (temp_bufferHeader == NULL) {
311 ret = OMX_ErrorInsufficientResources;
314 Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
316 for (i = 0; i < pExynosPort->portDefinition.nBufferCountActual; i++) {
317 if (pExynosPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) {
318 pExynosPort->extendBufferHeader[i].OMXBufferHeader = temp_bufferHeader;
319 pExynosPort->bufferStateAllocate[i] = (BUFFER_STATE_ASSIGNED | HEADER_STATE_ALLOCATED);
320 INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE);
321 temp_bufferHeader->pBuffer = pBuffer;
322 temp_bufferHeader->nAllocLen = nSizeBytes;
323 temp_bufferHeader->pAppPrivate = pAppPrivate;
324 if (nPortIndex == INPUT_PORT_INDEX)
325 temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX;
327 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX;
329 width = pExynosPort->portDefinition.format.video.nFrameWidth;
330 height = pExynosPort->portDefinition.format.video.nFrameHeight;
331 Exynos_OSAL_LockPB(temp_bufferHeader->pBuffer, width, height,
332 pExynosPort->portDefinition.format.video.eColorFormat,
335 pExynosPort->extendBufferHeader[i].buf_fd[0] = planes[0].fd;
336 pExynosPort->extendBufferHeader[i].buf_fd[1] = planes[1].fd;
337 pExynosPort->extendBufferHeader[i].buf_fd[2] = planes[2].fd;
339 pExynosPort->extendBufferHeader[i].pYUVBuf[0] = planes[0].addr;
340 pExynosPort->extendBufferHeader[i].pYUVBuf[1] = planes[1].addr;
341 pExynosPort->extendBufferHeader[i].pYUVBuf[2] = planes[2].addr;
342 Exynos_OSAL_UnlockANB(temp_bufferHeader->pBuffer);
343 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "useAndroidNativeBuffer: buf %d pYUVBuf[0]:0x%x , pYUVBuf[1]:0x%x ",
344 i, pExynosPort->extendBufferHeader[i].pYUVBuf[0],
345 pExynosPort->extendBufferHeader[i].pYUVBuf[1]);
347 pExynosPort->assignedBufferNum++;
348 if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) {
349 pExynosPort->portDefinition.bPopulated = OMX_TRUE;
350 /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */
351 Exynos_OSAL_SemaphorePost(pExynosPort->loadedResource);
352 /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */
354 *ppBufferHdr = temp_bufferHeader;
361 Exynos_OSAL_Free(temp_bufferHeader);
362 ret = OMX_ErrorInsufficientResources;
371 OMX_ERRORTYPE Exynos_OSAL_GetPBParameter(
372 OMX_IN OMX_HANDLETYPE hComponent,
373 OMX_IN OMX_INDEXTYPE nIndex,
374 OMX_INOUT OMX_PTR ComponentParameterStructure)
376 OMX_ERRORTYPE ret = OMX_ErrorNone;
377 OMX_COMPONENTTYPE *pOMXComponent = NULL;
378 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
382 if (hComponent == NULL) {
383 ret = OMX_ErrorBadParameter;
387 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
388 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
389 if (ret != OMX_ErrorNone) {
393 if (pOMXComponent->pComponentPrivate == NULL) {
394 ret = OMX_ErrorBadParameter;
398 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
399 if (pExynosComponent->currentState == OMX_StateInvalid ) {
400 ret = OMX_ErrorInvalidState;
404 if (ComponentParameterStructure == NULL) {
405 ret = OMX_ErrorBadParameter;
410 #if 0 /* SLP_PLATFORM */
411 case OMX_IndexParamGetAndroidNativeBuffer:
413 GetAndroidNativeBufferUsageParams *pANBParams = (GetAndroidNativeBufferUsageParams *) ComponentParameterStructure;
414 OMX_U32 portIndex = pANBParams->nPortIndex;
416 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamGetAndroidNativeBuffer", __func__);
418 ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(GetAndroidNativeBufferUsageParams));
419 if (ret != OMX_ErrorNone) {
420 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(GetAndroidNativeBufferUsageParams) is failed", __func__);
424 if (portIndex >= pExynosComponent->portParam.nPorts) {
425 ret = OMX_ErrorBadPortIndex;
429 /* NOTE: OMX_IndexParamGetAndroidNativeBuffer returns original 'nUsage' without any
430 * modifications since currently not defined what the 'nUsage' is for.
432 pANBParams->nUsage |= (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP
433 | GRALLOC_USAGE_HW_ION | GRALLOC_USAGE_HWC_HWOVERLAY);
439 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
440 ret = OMX_ErrorUnsupportedIndex;
452 OMX_ERRORTYPE Exynos_OSAL_SetPBParameter(
453 OMX_IN OMX_HANDLETYPE hComponent,
454 OMX_IN OMX_INDEXTYPE nIndex,
455 OMX_IN OMX_PTR ComponentParameterStructure)
457 OMX_ERRORTYPE ret = OMX_ErrorNone;
458 OMX_COMPONENTTYPE *pOMXComponent = NULL;
459 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
460 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
464 if (hComponent == NULL) {
465 ret = OMX_ErrorBadParameter;
469 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
470 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
471 if (ret != OMX_ErrorNone) {
475 if (pOMXComponent->pComponentPrivate == NULL) {
476 ret = OMX_ErrorBadParameter;
480 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
481 if (pExynosComponent->currentState == OMX_StateInvalid ) {
482 ret = OMX_ErrorInvalidState;
486 if (ComponentParameterStructure == NULL) {
487 ret = OMX_ErrorBadParameter;
491 pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
495 case OMX_IndexParamEnablePlatformSpecificBuffers:
497 case OMX_IndexParamEnableAndroidBuffers:
500 EnableGemBuffersParams *pPBParams = (EnableGemBuffersParams *) ComponentParameterStructure;
501 OMX_U32 portIndex = pPBParams->nPortIndex;
502 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
504 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamEnablePlatformSpecificBuffers", __func__);
506 ret = Exynos_OMX_Check_SizeVersion(pPBParams, sizeof(EnableGemBuffersParams));
507 if (ret != OMX_ErrorNone) {
508 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(EnableGemBuffersParams) is failed", __func__);
512 if (portIndex >= pExynosComponent->portParam.nPorts) {
513 ret = OMX_ErrorBadPortIndex;
517 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
518 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
519 ret = OMX_ErrorBadPortIndex;
524 /* PB and DPB Buffer Sharing */
525 if ((portIndex == OUTPUT_PORT_INDEX) &&
526 ((pExynosPort->bufferProcessType & BUFFER_PBSHARE) == BUFFER_PBSHARE)) {
527 pExynosPort->bufferProcessType = BUFFER_SHARE;
528 pExynosPort->portDefinition.format.video.eColorFormat = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
529 Exynos_OSAL_Log(EXYNOS_LOG_INFO, "output buffer sharing mode is on");
531 Exynos_OSAL_Log(EXYNOS_LOG_INFO, "pExynosPort->portDefinition.format.video.eColorFormat: 0x%x", pExynosPort->portDefinition.format.video.eColorFormat);
533 if ((portIndex == OUTPUT_PORT_INDEX) &&
534 (pExynosPort->bufferProcessType & BUFFER_COPY)) {
535 pExynosPort->bufferProcessType = BUFFER_COPY;
536 pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
539 pExynosPort->bIsPBEnabled = pPBParams->enable;
540 Exynos_OSAL_Log(EXYNOS_LOG_INFO, "pExynosPort->bIsPBEnabled: %d", pExynosPort->bIsPBEnabled);
544 #if 0 /* SLP_PLATFORM */
545 case OMX_IndexParamUseAndroidNativeBuffer:
547 UseAndroidNativeBufferParams *pANBParams = (UseAndroidNativeBufferParams *) ComponentParameterStructure;
548 OMX_U32 portIndex = pANBParams->nPortIndex;
549 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
550 android_native_buffer_t *pANB;
553 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamUseAndroidNativeBuffer, portIndex: %d", __func__, portIndex);
555 ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(UseAndroidNativeBufferParams));
556 if (ret != OMX_ErrorNone) {
557 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(UseAndroidNativeBufferParams) is failed", __func__);
561 if (portIndex >= pExynosComponent->portParam.nPorts) {
562 ret = OMX_ErrorBadPortIndex;
566 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
567 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
568 ret = OMX_ErrorBadPortIndex;
572 if (pExynosPort->portState != OMX_StateIdle) {
573 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Port state should be IDLE", __func__);
574 ret = OMX_ErrorIncorrectStateOperation;
578 pANB = pANBParams->nativeBuffer.get();
580 /* MALI alignment restriction */
581 nSizeBytes = ALIGN(pANB->width, 16) * ALIGN(pANB->height, 16);
582 nSizeBytes += ALIGN(pANB->width / 2, 16) * ALIGN(pANB->height / 2, 16) * 2;
584 ret = useAndroidNativeBuffer(pExynosPort,
585 pANBParams->bufferHeader,
586 pANBParams->nPortIndex,
587 pANBParams->pAppPrivate,
590 if (ret != OMX_ErrorNone) {
591 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: useAndroidNativeBuffer is failed: err=0x%x", __func__,ret);
597 case OMX_IndexParamStoreMetaDataBuffer:
599 StoreMetaDataInBuffersParams *pANBParams = (StoreMetaDataInBuffersParams *) ComponentParameterStructure;
600 OMX_U32 portIndex = pANBParams->nPortIndex;
601 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
603 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamStoreMetaDataBuffer", __func__);
605 ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(StoreMetaDataInBuffersParams));
606 if (ret != OMX_ErrorNone) {
607 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(StoreMetaDataInBuffersParams) is failed", __func__);
611 if (portIndex >= pExynosComponent->portParam.nPorts) {
612 ret = OMX_ErrorBadPortIndex;
616 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
617 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
618 ret = OMX_ErrorBadPortIndex;
622 pExynosPort->bStoreMetaData = pANBParams->bStoreMetaData;
628 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
629 ret = OMX_ErrorUnsupportedIndex;
641 #if 0 // we can remove this later.
642 OMX_ERRORTYPE Exynos_OSAL_GetInfoFromMetaData(OMX_IN OMX_BYTE pBuffer,
643 OMX_OUT OMX_PTR *ppBuf)
645 OMX_ERRORTYPE ret = OMX_ErrorNone;
646 MetadataBufferType type;
651 * meta data contains the following data format.
652 * payload depends on the MetadataBufferType
653 * --------------------------------------------------------------
654 * | MetadataBufferType | payload |
655 * --------------------------------------------------------------
657 * If MetadataBufferType is kMetadataBufferTypeCameraSource, then
658 * --------------------------------------------------------------
659 * | kMetadataBufferTypeCameraSource | physical addr. of Y |physical addr. of CbCr |
660 * --------------------------------------------------------------
662 * If MetadataBufferType is kMetadataBufferTypeGrallocSource, then
663 * --------------------------------------------------------------
664 * | kMetadataBufferTypeGrallocSource | buffer_handle_t |
665 * --------------------------------------------------------------
668 /* MetadataBufferType */
669 Exynos_OSAL_Memcpy(&type, (MetadataBufferType *)pBuffer, sizeof(MetadataBufferType));
671 if (type == kMetadataBufferTypeCameraSource) {
672 void *pAddress = NULL;
675 Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType), sizeof(void *));
676 ppBuf[0] = (void *)pAddress;
678 /* Address. of CbCr */
679 Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType) + sizeof(void *), sizeof(void *));
680 ppBuf[1] = (void *)pAddress;
682 } else if (type == kMetadataBufferTypeGrallocSource) {
683 buffer_handle_t pBufHandle;
685 /* buffer_handle_t */
686 Exynos_OSAL_Memcpy(&pBufHandle, pBuffer + sizeof(MetadataBufferType), sizeof(buffer_handle_t));
687 ppBuf[0] = (OMX_PTR)pBufHandle;
696 OMX_COLOR_FORMATTYPE Exynos_OSAL_Hal2OMXPixelFormat(
697 unsigned int hal_format)
699 OMX_COLOR_FORMATTYPE omx_format;
700 switch (hal_format) {
701 case HAL_PIXEL_FORMAT_YCbCr_422_I:
702 omx_format = OMX_COLOR_FormatYCbYCr;
704 case HAL_PIXEL_FORMAT_YCbCr_420_P:
705 omx_format = OMX_COLOR_FormatYUV420Planar;
707 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
708 omx_format = OMX_COLOR_FormatYUV420SemiPlanar;
710 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
711 omx_format = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
713 case HAL_PIXEL_FORMAT_ARGB888:
714 omx_format = OMX_COLOR_Format32bitARGB8888;
717 omx_format = OMX_COLOR_FormatYUV420Planar;
723 unsigned int Exynos_OSAL_OMX2HalPixelFormat(
724 OMX_COLOR_FORMATTYPE omx_format)
726 unsigned int hal_format;
727 switch (omx_format) {
728 case OMX_COLOR_FormatYCbYCr:
729 hal_format = HAL_PIXEL_FORMAT_YCbCr_422_I;
731 case OMX_COLOR_FormatYUV420Planar:
732 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
734 case OMX_COLOR_FormatYUV420SemiPlanar:
735 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP;
737 case OMX_SEC_COLOR_FormatNV12Tiled:
738 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED;
740 case OMX_COLOR_Format32bitARGB8888:
741 hal_format = HAL_PIXEL_FORMAT_ARGB888;
744 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;