Home | History | Annotate | Download | only in osal
      1 /*
      2  * Copyright 2012 Samsung Electronics S.LSI Co. LTD
      3  *
      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
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     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.
     15  */
     16 
     17 /*
     18  * @file        Exynos_OSAL_Android.cpp
     19  * @brief
     20  * @author      Seungbeom Kim (sbcrux.kim (at) samsung.com)
     21  * @author      Hyeyeon Chung (hyeon.chung (at) samsung.com)
     22  * @author      Yunji Kim (yunji.kim (at) samsung.com)
     23  * @author      Jinsung Yang (jsgood.yang (at) samsung.com)
     24  * @version     2.0.0
     25  * @history
     26  *   2012.02.20 : Create
     27  */
     28 
     29 #include <stdio.h>
     30 #include <stdlib.h>
     31 
     32 #include <system/window.h>
     33 #include <ui/GraphicBuffer.h>
     34 #include <ui/GraphicBufferMapper.h>
     35 #include <ui/Rect.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>
     41 
     42 #include "Exynos_OSAL_Semaphore.h"
     43 #include "Exynos_OMX_Baseport.h"
     44 #include "Exynos_OMX_Basecomponent.h"
     45 #include "Exynos_OMX_Macros.h"
     46 #include "Exynos_OMX_Vdec.h"
     47 #include "Exynos_OMX_Venc.h"
     48 #include "Exynos_OSAL_Android.h"
     49 #include "exynos_format.h"
     50 
     51 #undef  EXYNOS_LOG_TAG
     52 #define EXYNOS_LOG_TAG    "Exynos_OSAL_Android"
     53 #define EXYNOS_LOG_OFF
     54 #include "Exynos_OSAL_Log.h"
     55 
     56 using namespace android;
     57 
     58 #ifdef __cplusplus
     59 extern "C" {
     60 #endif
     61 
     62 
     63 OMX_ERRORTYPE Exynos_OSAL_LockANBHandle(
     64     OMX_IN OMX_U32 handle,
     65     OMX_IN OMX_U32 width,
     66     OMX_IN OMX_U32 height,
     67     OMX_IN OMX_COLOR_FORMATTYPE format,
     68     OMX_OUT OMX_PTR planes)
     69 {
     70     FunctionIn();
     71 
     72     OMX_ERRORTYPE ret = OMX_ErrorNone;
     73     GraphicBufferMapper &mapper = GraphicBufferMapper::get();
     74     buffer_handle_t bufferHandle = (buffer_handle_t) handle;
     75     private_handle_t *priv_hnd = (private_handle_t *) bufferHandle;
     76     Rect bounds(width, height);
     77     ExynosVideoPlane *vplanes = (ExynosVideoPlane *) planes;
     78     void *vaddr[MAX_BUFFER_PLANE];
     79 
     80     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle);
     81 
     82     int usage = 0;
     83 
     84     switch (format) {
     85     case OMX_COLOR_FormatYUV420Planar:
     86     case OMX_COLOR_FormatYUV420SemiPlanar:
     87     case OMX_SEC_COLOR_FormatNV12Tiled:
     88         usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
     89         break;
     90     default:
     91         usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
     92         break;
     93     }
     94 
     95     if (mapper.lock(bufferHandle, usage, bounds, vaddr) != 0) {
     96         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: mapper.lock() fail", __func__);
     97         ret = OMX_ErrorUndefined;
     98         goto EXIT;
     99     }
    100 
    101     vplanes[0].fd = priv_hnd->fd;
    102     vplanes[0].offset = 0;
    103     vplanes[0].addr = vaddr[0];
    104     vplanes[1].fd = priv_hnd->fd1;
    105     vplanes[1].offset = 0;
    106     vplanes[1].addr = vaddr[1];
    107     vplanes[2].fd = priv_hnd->fd2;
    108     vplanes[2].offset = 0;
    109     vplanes[2].addr = vaddr[2];
    110 
    111     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer locked: 0x%x", __func__, *vaddr);
    112 
    113 EXIT:
    114     FunctionOut();
    115 
    116     return ret;
    117 }
    118 
    119 OMX_ERRORTYPE Exynos_OSAL_UnlockANBHandle(OMX_IN OMX_U32 handle)
    120 {
    121     FunctionIn();
    122 
    123     OMX_ERRORTYPE ret = OMX_ErrorNone;
    124     GraphicBufferMapper &mapper = GraphicBufferMapper::get();
    125     buffer_handle_t bufferHandle = (buffer_handle_t) handle;
    126 
    127     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle);
    128 
    129     if (mapper.unlock(bufferHandle) != 0) {
    130         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: mapper.unlock() fail", __func__);
    131         ret = OMX_ErrorUndefined;
    132         goto EXIT;
    133     }
    134 
    135     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer unlocked: 0x%x", __func__, handle);
    136 
    137 EXIT:
    138     FunctionOut();
    139 
    140     return ret;
    141 }
    142 
    143 OMX_COLOR_FORMATTYPE Exynos_OSAL_GetANBColorFormat(OMX_IN OMX_U32 handle)
    144 {
    145     FunctionIn();
    146 
    147     OMX_COLOR_FORMATTYPE ret = OMX_COLOR_FormatUnused;
    148     private_handle_t *priv_hnd = (private_handle_t *) handle;
    149 
    150     ret = Exynos_OSAL_Hal2OMXPixelFormat(priv_hnd->format);
    151     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "ColorFormat: 0x%x", ret);
    152 
    153 EXIT:
    154     FunctionOut();
    155 
    156     return ret;
    157 }
    158 
    159 OMX_ERRORTYPE Exynos_OSAL_LockANB(
    160     OMX_IN OMX_PTR pBuffer,
    161     OMX_IN OMX_U32 width,
    162     OMX_IN OMX_U32 height,
    163     OMX_IN OMX_COLOR_FORMATTYPE format,
    164     OMX_OUT OMX_U32 *pStride,
    165     OMX_OUT OMX_PTR planes)
    166 {
    167     FunctionIn();
    168 
    169     OMX_ERRORTYPE ret = OMX_ErrorNone;
    170     android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
    171 
    172     ret = Exynos_OSAL_LockANBHandle((OMX_U32)pANB->handle, width, height, format, planes);
    173     *pStride = pANB->stride;
    174 
    175 EXIT:
    176     FunctionOut();
    177 
    178     return ret;
    179 }
    180 
    181 OMX_ERRORTYPE Exynos_OSAL_UnlockANB(OMX_IN OMX_PTR pBuffer)
    182 {
    183     FunctionIn();
    184 
    185     OMX_ERRORTYPE ret = OMX_ErrorNone;
    186     android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
    187 
    188     ret = Exynos_OSAL_UnlockANBHandle((OMX_U32)pANB->handle);
    189 
    190 EXIT:
    191     FunctionOut();
    192 
    193     return ret;
    194 }
    195 
    196 OMX_ERRORTYPE useAndroidNativeBuffer(
    197     EXYNOS_OMX_BASEPORT      *pExynosPort,
    198     OMX_BUFFERHEADERTYPE **ppBufferHdr,
    199     OMX_U32                nPortIndex,
    200     OMX_PTR                pAppPrivate,
    201     OMX_U32                nSizeBytes,
    202     OMX_U8                *pBuffer)
    203 {
    204     OMX_ERRORTYPE         ret = OMX_ErrorNone;
    205     OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL;
    206     unsigned int          i = 0;
    207     OMX_U32               width, height;
    208     OMX_U32               stride;
    209     ExynosVideoPlane      planes[MAX_BUFFER_PLANE];
    210 
    211     FunctionIn();
    212 
    213     if (pExynosPort == NULL) {
    214         ret = OMX_ErrorBadParameter;
    215         goto EXIT;
    216     }
    217     if (pExynosPort->portState != OMX_StateIdle) {
    218         ret = OMX_ErrorIncorrectStateOperation;
    219         goto EXIT;
    220     }
    221     if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
    222         ret = OMX_ErrorBadPortIndex;
    223         goto EXIT;
    224     }
    225 
    226     temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE));
    227     if (temp_bufferHeader == NULL) {
    228         ret = OMX_ErrorInsufficientResources;
    229         goto EXIT;
    230     }
    231     Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
    232 
    233     for (i = 0; i < pExynosPort->portDefinition.nBufferCountActual; i++) {
    234         if (pExynosPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) {
    235             pExynosPort->extendBufferHeader[i].OMXBufferHeader = temp_bufferHeader;
    236             pExynosPort->bufferStateAllocate[i] = (BUFFER_STATE_ASSIGNED | HEADER_STATE_ALLOCATED);
    237             INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE);
    238             temp_bufferHeader->pBuffer        = pBuffer;
    239             temp_bufferHeader->nAllocLen      = nSizeBytes;
    240             temp_bufferHeader->pAppPrivate    = pAppPrivate;
    241             if (nPortIndex == INPUT_PORT_INDEX)
    242                 temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX;
    243             else
    244                 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX;
    245 
    246             width = pExynosPort->portDefinition.format.video.nFrameWidth;
    247             height = pExynosPort->portDefinition.format.video.nFrameHeight;
    248             Exynos_OSAL_LockANB(temp_bufferHeader->pBuffer, width, height,
    249                                 pExynosPort->portDefinition.format.video.eColorFormat,
    250                                 &stride, planes);
    251             pExynosPort->extendBufferHeader[i].buf_fd[0] = planes[0].fd;
    252             pExynosPort->extendBufferHeader[i].pYUVBuf[0] = planes[0].addr;
    253             pExynosPort->extendBufferHeader[i].buf_fd[1] = planes[1].fd;
    254             pExynosPort->extendBufferHeader[i].pYUVBuf[1] = planes[1].addr;
    255             pExynosPort->extendBufferHeader[i].buf_fd[2] = planes[2].fd;
    256             pExynosPort->extendBufferHeader[i].pYUVBuf[2] = planes[2].addr;
    257             Exynos_OSAL_UnlockANB(temp_bufferHeader->pBuffer);
    258             Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "useAndroidNativeBuffer: buf %d pYUVBuf[0]:0x%x (fd:%d), pYUVBuf[1]:0x%x (fd:%d)",
    259                             i, pExynosPort->extendBufferHeader[i].pYUVBuf[0], planes[0].fd,
    260                             pExynosPort->extendBufferHeader[i].pYUVBuf[1], planes[1].fd);
    261 
    262             pExynosPort->assignedBufferNum++;
    263             if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) {
    264                 pExynosPort->portDefinition.bPopulated = OMX_TRUE;
    265                 /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */
    266                 Exynos_OSAL_SemaphorePost(pExynosPort->loadedResource);
    267                 /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */
    268             }
    269             *ppBufferHdr = temp_bufferHeader;
    270             ret = OMX_ErrorNone;
    271 
    272             goto EXIT;
    273         }
    274     }
    275 
    276     Exynos_OSAL_Free(temp_bufferHeader);
    277     ret = OMX_ErrorInsufficientResources;
    278 
    279 EXIT:
    280     FunctionOut();
    281 
    282     return ret;
    283 }
    284 
    285 OMX_ERRORTYPE Exynos_OSAL_GetANBParameter(
    286     OMX_IN OMX_HANDLETYPE hComponent,
    287     OMX_IN OMX_INDEXTYPE  nIndex,
    288     OMX_INOUT OMX_PTR     ComponentParameterStructure)
    289 {
    290     OMX_ERRORTYPE          ret = OMX_ErrorNone;
    291     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
    292     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
    293 
    294     FunctionIn();
    295 
    296     if (hComponent == NULL) {
    297         ret = OMX_ErrorBadParameter;
    298         goto EXIT;
    299     }
    300 
    301     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
    302     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
    303     if (ret != OMX_ErrorNone) {
    304         goto EXIT;
    305     }
    306 
    307     if (pOMXComponent->pComponentPrivate == NULL) {
    308         ret = OMX_ErrorBadParameter;
    309         goto EXIT;
    310     }
    311 
    312     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    313     if (pExynosComponent->currentState == OMX_StateInvalid ) {
    314         ret = OMX_ErrorInvalidState;
    315         goto EXIT;
    316     }
    317 
    318     if (ComponentParameterStructure == NULL) {
    319         ret = OMX_ErrorBadParameter;
    320         goto EXIT;
    321     }
    322 
    323     switch (nIndex) {
    324     case OMX_IndexParamGetAndroidNativeBuffer:
    325     {
    326         GetAndroidNativeBufferUsageParams *pANBParams = (GetAndroidNativeBufferUsageParams *) ComponentParameterStructure;
    327         OMX_U32 portIndex = pANBParams->nPortIndex;
    328 
    329         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamGetAndroidNativeBuffer", __func__);
    330 
    331         ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(GetAndroidNativeBufferUsageParams));
    332         if (ret != OMX_ErrorNone) {
    333             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(GetAndroidNativeBufferUsageParams) is failed", __func__);
    334             goto EXIT;
    335         }
    336 
    337         if (portIndex >= pExynosComponent->portParam.nPorts) {
    338             ret = OMX_ErrorBadPortIndex;
    339             goto EXIT;
    340         }
    341 
    342         /* NOTE: OMX_IndexParamGetAndroidNativeBuffer returns original 'nUsage' without any
    343          * modifications since currently not defined what the 'nUsage' is for.
    344          */
    345         pANBParams->nUsage |= (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP);
    346     }
    347         break;
    348 
    349     default:
    350     {
    351         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
    352         ret = OMX_ErrorUnsupportedIndex;
    353         goto EXIT;
    354     }
    355         break;
    356     }
    357 
    358 EXIT:
    359     FunctionOut();
    360 
    361     return ret;
    362 }
    363 
    364 OMX_ERRORTYPE Exynos_OSAL_SetANBParameter(
    365     OMX_IN OMX_HANDLETYPE hComponent,
    366     OMX_IN OMX_INDEXTYPE  nIndex,
    367     OMX_IN OMX_PTR        ComponentParameterStructure)
    368 {
    369     OMX_ERRORTYPE          ret = OMX_ErrorNone;
    370     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
    371     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
    372 
    373     FunctionIn();
    374 
    375     if (hComponent == NULL) {
    376         ret = OMX_ErrorBadParameter;
    377         goto EXIT;
    378     }
    379 
    380     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
    381     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
    382     if (ret != OMX_ErrorNone) {
    383         goto EXIT;
    384     }
    385 
    386     if (pOMXComponent->pComponentPrivate == NULL) {
    387         ret = OMX_ErrorBadParameter;
    388         goto EXIT;
    389     }
    390 
    391     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    392     if (pExynosComponent->currentState == OMX_StateInvalid ) {
    393         ret = OMX_ErrorInvalidState;
    394         goto EXIT;
    395     }
    396 
    397     if (ComponentParameterStructure == NULL) {
    398         ret = OMX_ErrorBadParameter;
    399         goto EXIT;
    400     }
    401 
    402 
    403     switch (nIndex) {
    404     case OMX_IndexParamEnableAndroidBuffers:
    405     {
    406         EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
    407         EnableAndroidNativeBuffersParams *pANBParams = (EnableAndroidNativeBuffersParams *) ComponentParameterStructure;
    408         OMX_U32 portIndex = pANBParams->nPortIndex;
    409         EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
    410 
    411         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamEnableAndroidNativeBuffers", __func__);
    412 
    413         ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(EnableAndroidNativeBuffersParams));
    414         if (ret != OMX_ErrorNone) {
    415             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(EnableAndroidNativeBuffersParams) is failed", __func__);
    416             goto EXIT;
    417         }
    418 
    419         if (portIndex >= pExynosComponent->portParam.nPorts) {
    420             ret = OMX_ErrorBadPortIndex;
    421             goto EXIT;
    422         }
    423 
    424         pExynosPort = &pExynosComponent->pExynosPort[portIndex];
    425         if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
    426             ret = OMX_ErrorBadPortIndex;
    427             goto EXIT;
    428         }
    429 
    430         /* ANB and DPB Buffer Sharing */
    431         pExynosPort->bIsANBEnabled = pANBParams->enable;
    432         if ((portIndex == OUTPUT_PORT_INDEX) &&
    433             (pExynosPort->bIsANBEnabled == OMX_TRUE) &&
    434             ((pExynosPort->bufferProcessType & BUFFER_ANBSHARE) == BUFFER_ANBSHARE)) {
    435             pExynosPort->bufferProcessType = BUFFER_SHARE;
    436             pExynosPort->portDefinition.format.video.eColorFormat = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
    437             Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "OMX_IndexParamEnableAndroidBuffers & bufferProcessType change to BUFFER_SHARE");
    438         }
    439     }
    440         break;
    441 
    442     case OMX_IndexParamUseAndroidNativeBuffer:
    443     {
    444         EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
    445         UseAndroidNativeBufferParams *pANBParams = (UseAndroidNativeBufferParams *) ComponentParameterStructure;
    446         OMX_U32 portIndex = pANBParams->nPortIndex;
    447         EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
    448         android_native_buffer_t *pANB;
    449         OMX_U32 nSizeBytes;
    450 
    451         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamUseAndroidNativeBuffer, portIndex: %d", __func__, portIndex);
    452 
    453         ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(UseAndroidNativeBufferParams));
    454         if (ret != OMX_ErrorNone) {
    455             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(UseAndroidNativeBufferParams) is failed", __func__);
    456             goto EXIT;
    457         }
    458 
    459         if (portIndex >= pExynosComponent->portParam.nPorts) {
    460             ret = OMX_ErrorBadPortIndex;
    461             goto EXIT;
    462         }
    463 
    464         pExynosPort = &pExynosComponent->pExynosPort[portIndex];
    465         if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
    466             ret = OMX_ErrorBadPortIndex;
    467             goto EXIT;
    468         }
    469 
    470         if (pExynosPort->portState != OMX_StateIdle) {
    471             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Port state should be IDLE", __func__);
    472             ret = OMX_ErrorIncorrectStateOperation;
    473             goto EXIT;
    474         }
    475 
    476         pANB = pANBParams->nativeBuffer.get();
    477 
    478         /* MALI alignment restriction */
    479         nSizeBytes = ALIGN(pANB->width, 16) * ALIGN(pANB->height, 16);
    480         nSizeBytes += ALIGN(pANB->width / 2, 16) * ALIGN(pANB->height / 2, 16) * 2;
    481 
    482         ret = useAndroidNativeBuffer(pExynosPort,
    483                                      pANBParams->bufferHeader,
    484                                      pANBParams->nPortIndex,
    485                                      pANBParams->pAppPrivate,
    486                                      nSizeBytes,
    487                                      (OMX_U8 *) pANB);
    488         if (ret != OMX_ErrorNone) {
    489             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: useAndroidNativeBuffer is failed: err=0x%x", __func__,ret);
    490             goto EXIT;
    491         }
    492     }
    493         break;
    494 
    495     case OMX_IndexParamStoreMetaDataBuffer:
    496     {
    497         EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle;;
    498         StoreMetaDataInBuffersParams *pANBParams = (StoreMetaDataInBuffersParams *) ComponentParameterStructure;
    499         OMX_U32 portIndex = pANBParams->nPortIndex;
    500         EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
    501 
    502         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamStoreMetaDataBuffer", __func__);
    503 
    504         ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(StoreMetaDataInBuffersParams));
    505         if (ret != OMX_ErrorNone) {
    506             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(StoreMetaDataInBuffersParams) is failed", __func__);
    507             goto EXIT;
    508         }
    509 
    510         if (portIndex >= pExynosComponent->portParam.nPorts) {
    511             ret = OMX_ErrorBadPortIndex;
    512             goto EXIT;
    513         }
    514 
    515         pExynosPort = &pExynosComponent->pExynosPort[portIndex];
    516         if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
    517             ret = OMX_ErrorBadPortIndex;
    518             goto EXIT;
    519         }
    520 
    521         pExynosPort->bStoreMetaData = pANBParams->bStoreMetaData;
    522         pVideoEnc->bFirstInput = OMX_TRUE;
    523     }
    524         break;
    525 
    526     default:
    527     {
    528         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
    529         ret = OMX_ErrorUnsupportedIndex;
    530         goto EXIT;
    531     }
    532         break;
    533     }
    534 
    535 EXIT:
    536     FunctionOut();
    537 
    538     return ret;
    539 }
    540 
    541 OMX_ERRORTYPE Exynos_OSAL_GetInfoFromMetaData(OMX_IN OMX_BYTE pBuffer,
    542                                            OMX_OUT OMX_PTR *ppBuf)
    543 {
    544     OMX_ERRORTYPE      ret = OMX_ErrorNone;
    545     MetadataBufferType type;
    546 
    547     FunctionIn();
    548 
    549 /*
    550  * meta data contains the following data format.
    551  * payload depends on the MetadataBufferType
    552  * --------------------------------------------------------------
    553  * | MetadataBufferType                         |          payload                           |
    554  * --------------------------------------------------------------
    555  *
    556  * If MetadataBufferType is kMetadataBufferTypeCameraSource, then
    557  * --------------------------------------------------------------
    558  * | kMetadataBufferTypeCameraSource  | physical addr. of Y |physical addr. of CbCr |
    559  * --------------------------------------------------------------
    560  *
    561  * If MetadataBufferType is kMetadataBufferTypeGrallocSource, then
    562  * --------------------------------------------------------------
    563  * | kMetadataBufferTypeGrallocSource    | buffer_handle_t |
    564  * --------------------------------------------------------------
    565  */
    566 
    567     /* MetadataBufferType */
    568     Exynos_OSAL_Memcpy(&type, (MetadataBufferType *)pBuffer, sizeof(MetadataBufferType));
    569 
    570     if (type == kMetadataBufferTypeCameraSource) {
    571         void *pAddress = NULL;
    572 
    573         /* Address. of Y */
    574         Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType), sizeof(void *));
    575         ppBuf[0] = (void *)pAddress;
    576 
    577         /* Address. of CbCr */
    578         Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType) + sizeof(void *), sizeof(void *));
    579         ppBuf[1] = (void *)pAddress;
    580 
    581     } else if (type == kMetadataBufferTypeGrallocSource) {
    582         buffer_handle_t    pBufHandle;
    583 
    584         /* buffer_handle_t */
    585         Exynos_OSAL_Memcpy(&pBufHandle, pBuffer + sizeof(MetadataBufferType), sizeof(buffer_handle_t));
    586         ppBuf[0] = (OMX_PTR)pBufHandle;
    587     }
    588 
    589 EXIT:
    590     FunctionOut();
    591 
    592     return ret;
    593 }
    594 
    595 OMX_COLOR_FORMATTYPE Exynos_OSAL_Hal2OMXPixelFormat(
    596     unsigned int hal_format)
    597 {
    598     OMX_COLOR_FORMATTYPE omx_format;
    599     switch (hal_format) {
    600     case HAL_PIXEL_FORMAT_YCbCr_422_I:
    601         omx_format = OMX_COLOR_FormatYCbYCr;
    602         break;
    603     case HAL_PIXEL_FORMAT_YCbCr_420_P:
    604         omx_format = OMX_COLOR_FormatYUV420Planar;
    605         break;
    606     case HAL_PIXEL_FORMAT_YCbCr_420_SP:
    607         omx_format = OMX_COLOR_FormatYUV420SemiPlanar;
    608         break;
    609     case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP_TILED:
    610         omx_format = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12TPhysicalAddress;
    611         break;
    612     case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
    613         omx_format = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
    614         break;
    615     case HAL_PIXEL_FORMAT_BGRA_8888:
    616     case HAL_PIXEL_FORMAT_CUSTOM_ARGB_8888:
    617         omx_format = OMX_COLOR_Format32bitARGB8888;
    618         break;
    619     default:
    620         omx_format = OMX_COLOR_FormatYUV420Planar;
    621         break;
    622     }
    623     return omx_format;
    624 }
    625 
    626 unsigned int Exynos_OSAL_OMX2HalPixelFormat(
    627     OMX_COLOR_FORMATTYPE omx_format)
    628 {
    629     unsigned int hal_format;
    630     switch (omx_format) {
    631     case OMX_COLOR_FormatYCbYCr:
    632         hal_format = HAL_PIXEL_FORMAT_YCbCr_422_I;
    633         break;
    634     case OMX_COLOR_FormatYUV420Planar:
    635         hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
    636         break;
    637     case OMX_COLOR_FormatYUV420SemiPlanar:
    638         hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP;
    639         break;
    640     case OMX_SEC_COLOR_FormatNV12TPhysicalAddress:
    641         hal_format = HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP_TILED;
    642         break;
    643     case OMX_SEC_COLOR_FormatNV12Tiled:
    644         hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED;
    645         break;
    646     case OMX_COLOR_Format32bitARGB8888:
    647         hal_format = HAL_PIXEL_FORMAT_CUSTOM_ARGB_8888;
    648         break;
    649     default:
    650         hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
    651         break;
    652     }
    653     return hal_format;
    654 }
    655 
    656 
    657 #ifdef __cplusplus
    658 }
    659 #endif
    660