Home | History | Annotate | Download | only in mpeg4
      1 /*
      2  *
      3  * Copyright 2012 Samsung Electronics S.LSI Co. LTD
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 /*
     19  * @file      Exynos_OMX_Mpeg4dec.c
     20  * @brief
     21  * @author    Yunji Kim (yunji.kim (at) samsung.com)
     22  * @author    SeungBeom Kim (sbcrux.kim (at) samsung.com)
     23  * @version   2.0.0
     24  * @history
     25  *   2012.02.20 : Create
     26  */
     27 
     28 #include <stdio.h>
     29 #include <stdlib.h>
     30 #include <string.h>
     31 
     32 #include "Exynos_OMX_Macros.h"
     33 #include "Exynos_OMX_Basecomponent.h"
     34 #include "Exynos_OMX_Baseport.h"
     35 #include "Exynos_OMX_Vdec.h"
     36 #include "Exynos_OSAL_ETC.h"
     37 #include "Exynos_OSAL_Semaphore.h"
     38 #include "Exynos_OSAL_Thread.h"
     39 #include "library_register.h"
     40 #include "Exynos_OMX_Mpeg4dec.h"
     41 #include "ExynosVideoApi.h"
     42 #include "Exynos_OSAL_SharedMemory.h"
     43 #include "Exynos_OSAL_Event.h"
     44 
     45 #ifdef USE_ANB
     46 #include "Exynos_OSAL_Android.h"
     47 #endif
     48 
     49 /* To use CSC_METHOD_HW in EXYNOS OMX, gralloc should allocate physical memory using FIMC */
     50 /* It means GRALLOC_USAGE_HW_FIMC1 should be set on Native Window usage */
     51 #include "csc.h"
     52 
     53 #undef  EXYNOS_LOG_TAG
     54 #define EXYNOS_LOG_TAG    "EXYNOS_MPEG4_DEC"
     55 #define EXYNOS_LOG_OFF
     56 //#define EXYNOS_TRACE_ON
     57 #include "Exynos_OSAL_Log.h"
     58 
     59 #define MPEG4_DEC_NUM_OF_EXTRA_BUFFERS 7
     60 
     61 //#define FULL_FRAME_SEARCH
     62 
     63 /* MPEG4 Decoder Supported Levels & profiles */
     64 EXYNOS_OMX_VIDEO_PROFILELEVEL supportedMPEG4ProfileLevels[] ={
     65     {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level0},
     66     {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level0b},
     67     {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level1},
     68     {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level2},
     69     {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level3},
     70     {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level4},
     71     {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level4a},
     72     {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level5},
     73     {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level0},
     74     {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level0b},
     75     {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level1},
     76     {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level2},
     77     {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level3},
     78     {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level4},
     79     {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level4a},
     80     {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level5}};
     81 
     82 /* H.263 Decoder Supported Levels & profiles */
     83 EXYNOS_OMX_VIDEO_PROFILELEVEL supportedH263ProfileLevels[] = {
     84     /* Baseline (Profile 0) */
     85     {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level10},
     86     {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level20},
     87     {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level30},
     88     {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level40},
     89     {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level45},
     90     {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level50},
     91     {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level60},
     92     {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level70},
     93     /* Profile 1 */
     94     {OMX_VIDEO_H263ProfileH320Coding, OMX_VIDEO_H263Level10},
     95     {OMX_VIDEO_H263ProfileH320Coding, OMX_VIDEO_H263Level20},
     96     {OMX_VIDEO_H263ProfileH320Coding, OMX_VIDEO_H263Level30},
     97     {OMX_VIDEO_H263ProfileH320Coding, OMX_VIDEO_H263Level40},
     98     {OMX_VIDEO_H263ProfileH320Coding, OMX_VIDEO_H263Level45},
     99     {OMX_VIDEO_H263ProfileH320Coding, OMX_VIDEO_H263Level50},
    100     {OMX_VIDEO_H263ProfileH320Coding, OMX_VIDEO_H263Level60},
    101     {OMX_VIDEO_H263ProfileH320Coding, OMX_VIDEO_H263Level70},
    102     /* Profile 2 */
    103     {OMX_VIDEO_H263ProfileBackwardCompatible, OMX_VIDEO_H263Level10},
    104     {OMX_VIDEO_H263ProfileBackwardCompatible, OMX_VIDEO_H263Level20},
    105     {OMX_VIDEO_H263ProfileBackwardCompatible, OMX_VIDEO_H263Level30},
    106     {OMX_VIDEO_H263ProfileBackwardCompatible, OMX_VIDEO_H263Level40},
    107     {OMX_VIDEO_H263ProfileBackwardCompatible, OMX_VIDEO_H263Level45},
    108     {OMX_VIDEO_H263ProfileBackwardCompatible, OMX_VIDEO_H263Level50},
    109     {OMX_VIDEO_H263ProfileBackwardCompatible, OMX_VIDEO_H263Level60},
    110     {OMX_VIDEO_H263ProfileBackwardCompatible, OMX_VIDEO_H263Level70},
    111     /* Profile 3, restricted up to SD resolution */
    112     {OMX_VIDEO_H263ProfileISWV2, OMX_VIDEO_H263Level10},
    113     {OMX_VIDEO_H263ProfileISWV2, OMX_VIDEO_H263Level20},
    114     {OMX_VIDEO_H263ProfileISWV2, OMX_VIDEO_H263Level30},
    115     {OMX_VIDEO_H263ProfileISWV2, OMX_VIDEO_H263Level40},
    116     {OMX_VIDEO_H263ProfileISWV2, OMX_VIDEO_H263Level45},
    117     {OMX_VIDEO_H263ProfileISWV2, OMX_VIDEO_H263Level50},
    118     {OMX_VIDEO_H263ProfileISWV2, OMX_VIDEO_H263Level60},
    119     {OMX_VIDEO_H263ProfileISWV2, OMX_VIDEO_H263Level70}};
    120 
    121 
    122 static OMX_ERRORTYPE GetCodecInputPrivateData(OMX_PTR codecBuffer, void *pVirtAddr, OMX_U32 *dataSize)
    123 {
    124     OMX_ERRORTYPE       ret = OMX_ErrorNone;
    125 
    126 EXIT:
    127     return ret;
    128 }
    129 
    130 static OMX_ERRORTYPE GetCodecOutputPrivateData(OMX_PTR codecBuffer, void *addr[], int size[])
    131 {
    132     OMX_ERRORTYPE       ret = OMX_ErrorNone;
    133     ExynosVideoBuffer  *pCodecBuffer;
    134 
    135     if (codecBuffer == NULL) {
    136         ret = OMX_ErrorBadParameter;
    137         goto EXIT;
    138     }
    139 
    140     pCodecBuffer = (ExynosVideoBuffer *)codecBuffer;
    141 
    142     if (addr != NULL) {
    143         addr[0] = pCodecBuffer->planes[0].addr;
    144         addr[1] = pCodecBuffer->planes[1].addr;
    145         addr[2] = pCodecBuffer->planes[2].addr;
    146     }
    147 
    148     if (size != NULL) {
    149         size[0] = pCodecBuffer->planes[0].allocSize;
    150         size[1] = pCodecBuffer->planes[1].allocSize;
    151         size[2] = pCodecBuffer->planes[2].allocSize;
    152     }
    153 
    154 EXIT:
    155     return ret;
    156 }
    157 
    158 static OMX_BOOL gbFIMV1 = OMX_FALSE;
    159 
    160 static int Check_Mpeg4_Frame(
    161     OMX_U8   *pInputStream,
    162     OMX_U32   buffSize,
    163     OMX_U32   flag,
    164     OMX_BOOL  bPreviousFrameEOF,
    165     OMX_BOOL *pbEndOfFrame)
    166 {
    167     OMX_U32  len;
    168     int      readStream;
    169     unsigned startCode;
    170     OMX_BOOL bFrameStart;
    171 
    172     len = 0;
    173     bFrameStart = OMX_FALSE;
    174 
    175     if (flag & OMX_BUFFERFLAG_CODECCONFIG) {
    176         if (*pInputStream == 0x03) { /* FIMV1 */
    177             BitmapInfoHhr *pInfoHeader;
    178 
    179             pInfoHeader = (BitmapInfoHhr *)(pInputStream + 1);
    180             /* FIXME */
    181             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "############## NOT SUPPORTED #################");
    182             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "width(%d), height(%d)", pInfoHeader->BiWidth, pInfoHeader->BiHeight);
    183             gbFIMV1 = OMX_TRUE;
    184             *pbEndOfFrame = OMX_TRUE;
    185             return buffSize;
    186         }
    187     }
    188 
    189     if (gbFIMV1) {
    190         *pbEndOfFrame = OMX_TRUE;
    191         return buffSize;
    192     }
    193 
    194     if (bPreviousFrameEOF == OMX_FALSE)
    195         bFrameStart = OMX_TRUE;
    196 
    197     startCode = 0xFFFFFFFF;
    198     if (bFrameStart == OMX_FALSE) {
    199         /* find VOP start code */
    200         while(startCode != 0x1B6) {
    201             readStream = *(pInputStream + len);
    202             startCode = (startCode << 8) | readStream;
    203             len++;
    204             if (len > buffSize)
    205                 goto EXIT;
    206         }
    207     }
    208 
    209     /* find next VOP start code */
    210     startCode = 0xFFFFFFFF;
    211     while ((startCode != 0x1B6)) {
    212         readStream = *(pInputStream + len);
    213         startCode = (startCode << 8) | readStream;
    214         len++;
    215         if (len > buffSize)
    216             goto EXIT;
    217     }
    218 
    219     *pbEndOfFrame = OMX_TRUE;
    220 
    221     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "1. Check_Mpeg4_Frame returned EOF = %d, len = %d, buffSize = %d", *pbEndOfFrame, len - 4, buffSize);
    222 
    223     return len - 4;
    224 
    225 EXIT :
    226     *pbEndOfFrame = OMX_FALSE;
    227 
    228     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "2. Check_Mpeg4_Frame returned EOF = %d, len = %d, buffSize = %d", *pbEndOfFrame, len - 1, buffSize);
    229 
    230     return --len;
    231 }
    232 
    233 static int Check_H263_Frame(
    234     OMX_U8   *pInputStream,
    235     OMX_U32   buffSize,
    236     OMX_U32   flag,
    237     OMX_BOOL  bPreviousFrameEOF,
    238     OMX_BOOL *pbEndOfFrame)
    239 {
    240     OMX_U32  len;
    241     int      readStream;
    242     unsigned startCode;
    243     OMX_BOOL bFrameStart = 0;
    244     unsigned pTypeMask   = 0x03;
    245     unsigned pType       = 0;
    246 
    247     len = 0;
    248     bFrameStart = OMX_FALSE;
    249 
    250     if (bPreviousFrameEOF == OMX_FALSE)
    251         bFrameStart = OMX_TRUE;
    252 
    253     startCode = 0xFFFFFFFF;
    254     if (bFrameStart == OMX_FALSE) {
    255         /* find PSC(Picture Start Code) : 0000 0000 0000 0000 1000 00 */
    256         while (((startCode << 8 >> 10) != 0x20) || (pType != 0x02)) {
    257             readStream = *(pInputStream + len);
    258             startCode = (startCode << 8) | readStream;
    259 
    260             readStream = *(pInputStream + len + 1);
    261             pType = readStream & pTypeMask;
    262 
    263             len++;
    264             if (len > buffSize)
    265                 goto EXIT;
    266         }
    267     }
    268 
    269     /* find next PSC */
    270     startCode = 0xFFFFFFFF;
    271     pType = 0;
    272     while (((startCode << 8 >> 10) != 0x20) || (pType != 0x02)) {
    273         readStream = *(pInputStream + len);
    274         startCode = (startCode << 8) | readStream;
    275 
    276         readStream = *(pInputStream + len + 1);
    277         pType = readStream & pTypeMask;
    278 
    279         len++;
    280         if (len > buffSize)
    281             goto EXIT;
    282     }
    283 
    284     *pbEndOfFrame = OMX_TRUE;
    285 
    286     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "1. Check_H263_Frame returned EOF = %d, len = %d, iBuffSize = %d", *pbEndOfFrame, len - 3, buffSize);
    287 
    288     return len - 3;
    289 
    290 EXIT :
    291 
    292     *pbEndOfFrame = OMX_FALSE;
    293 
    294     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "2. Check_H263_Frame returned EOF = %d, len = %d, iBuffSize = %d", *pbEndOfFrame, len - 1, buffSize);
    295 
    296     return --len;
    297 }
    298 
    299 static OMX_BOOL Check_Stream_StartCode(
    300     OMX_U8    *pInputStream,
    301     OMX_U32    streamSize,
    302     CODEC_TYPE codecType)
    303 {
    304     switch (codecType) {
    305     case CODEC_TYPE_MPEG4:
    306         if (gbFIMV1) {
    307             return OMX_TRUE;
    308         } else {
    309             if (streamSize < 3) {
    310                 return OMX_FALSE;
    311             } else if ((pInputStream[0] == 0x00) &&
    312                        (pInputStream[1] == 0x00) &&
    313                        (pInputStream[2] == 0x01)) {
    314                 return OMX_TRUE;
    315             } else {
    316                 return OMX_FALSE;
    317             }
    318         }
    319         break;
    320     case CODEC_TYPE_H263:
    321         if (streamSize > 0) {
    322             unsigned startCode = 0xFFFFFFFF;
    323             unsigned pTypeMask = 0x03;
    324             unsigned pType     = 0;
    325             OMX_U32  len       = 0;
    326             int      readStream;
    327             /* Check PSC(Picture Start Code) : 0000 0000 0000 0000 1000 00 */
    328             while (((startCode << 8 >> 10) != 0x20) || (pType != 0x02)) {
    329                 readStream = *(pInputStream + len);
    330                 startCode = (startCode << 8) | readStream;
    331 
    332                 readStream = *(pInputStream + len + 1);
    333                 pType = readStream & pTypeMask;
    334 
    335                 len++;
    336                 if (len > 0x3)
    337                     break;
    338             }
    339 
    340             if (len > 0x3) {
    341                 Exynos_OSAL_Log(EXYNOS_LOG_WARNING, "[%s] Picture Start Code Missing", __FUNCTION__);
    342                 return OMX_FALSE;
    343             } else {
    344                 return OMX_TRUE;
    345             }
    346         } else {
    347             return OMX_FALSE;
    348         }
    349     default:
    350         Exynos_OSAL_Log(EXYNOS_LOG_WARNING, "%s: undefined codec type (%d)", __FUNCTION__, codecType);
    351         return OMX_FALSE;
    352     }
    353 }
    354 
    355 OMX_ERRORTYPE Mpeg4CodecOpen(EXYNOS_MPEG4DEC_HANDLE *pMpeg4Dec)
    356 {
    357     OMX_ERRORTYPE            ret        = OMX_ErrorNone;
    358     ExynosVideoDecOps       *pDecOps    = NULL;
    359     ExynosVideoDecBufferOps *pInbufOps  = NULL;
    360     ExynosVideoDecBufferOps *pOutbufOps = NULL;
    361 
    362     FunctionIn();
    363 
    364     if (pMpeg4Dec == NULL) {
    365         ret = OMX_ErrorBadParameter;
    366         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorBadParameter, Line:%d", __LINE__);
    367         goto EXIT;
    368     }
    369 
    370     /* alloc ops structure */
    371     pDecOps    = (ExynosVideoDecOps *)Exynos_OSAL_Malloc(sizeof(ExynosVideoDecOps));
    372     pInbufOps  = (ExynosVideoDecBufferOps *)Exynos_OSAL_Malloc(sizeof(ExynosVideoDecBufferOps));
    373     pOutbufOps = (ExynosVideoDecBufferOps *)Exynos_OSAL_Malloc(sizeof(ExynosVideoDecBufferOps));
    374 
    375     if ((pDecOps == NULL) || (pInbufOps == NULL) || (pOutbufOps == NULL)) {
    376         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to allocate decoder ops buffer");
    377         ret = OMX_ErrorInsufficientResources;
    378         goto EXIT;
    379     }
    380 
    381     pMpeg4Dec->hMFCMpeg4Handle.pDecOps    = pDecOps;
    382     pMpeg4Dec->hMFCMpeg4Handle.pInbufOps  = pInbufOps;
    383     pMpeg4Dec->hMFCMpeg4Handle.pOutbufOps = pOutbufOps;
    384 
    385     /* function pointer mapping */
    386     pDecOps->nSize    = sizeof(ExynosVideoDecOps);
    387     pInbufOps->nSize  = sizeof(ExynosVideoDecBufferOps);
    388     pOutbufOps->nSize = sizeof(ExynosVideoDecBufferOps);
    389 
    390     Exynos_Video_Register_Decoder(pDecOps, pInbufOps, pOutbufOps);
    391 
    392     /* check mandatory functions for decoder ops */
    393     if ((pDecOps->Init == NULL) || (pDecOps->Finalize == NULL) ||
    394         (pDecOps->Get_ActualBufferCount == NULL) || (pDecOps->Set_FrameTag == NULL) ||
    395         (pDecOps->Get_FrameTag == NULL)) {
    396         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Mandatory functions must be supplied");
    397         ret = OMX_ErrorInsufficientResources;
    398         goto EXIT;
    399     }
    400 
    401     /* check mandatory functions for buffer ops */
    402     if ((pInbufOps->Setup == NULL) || (pOutbufOps->Setup == NULL) ||
    403         (pInbufOps->Run == NULL) || (pOutbufOps->Run == NULL) ||
    404         (pInbufOps->Stop == NULL) || (pOutbufOps->Stop == NULL) ||
    405         (pInbufOps->Enqueue == NULL) || (pOutbufOps->Enqueue == NULL) ||
    406         (pInbufOps->Dequeue == NULL) || (pOutbufOps->Dequeue == NULL)) {
    407         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Mandatory functions must be supplied");
    408         ret = OMX_ErrorInsufficientResources;
    409         goto EXIT;
    410     }
    411 
    412     /* alloc context, open, querycap */
    413     pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle = pMpeg4Dec->hMFCMpeg4Handle.pDecOps->Init(V4L2_MEMORY_DMABUF);
    414     if (pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle == NULL) {
    415         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to allocate context buffer");
    416         ret = OMX_ErrorInsufficientResources;
    417         goto EXIT;
    418     }
    419 
    420     ret = OMX_ErrorNone;
    421 
    422 EXIT:
    423     if (ret != OMX_ErrorNone) {
    424         if (pDecOps != NULL) {
    425             Exynos_OSAL_Free(pDecOps);
    426             pMpeg4Dec->hMFCMpeg4Handle.pDecOps = NULL;
    427         }
    428         if (pInbufOps != NULL) {
    429             Exynos_OSAL_Free(pInbufOps);
    430             pMpeg4Dec->hMFCMpeg4Handle.pInbufOps = NULL;
    431         }
    432         if (pOutbufOps != NULL) {
    433             Exynos_OSAL_Free(pOutbufOps);
    434             pMpeg4Dec->hMFCMpeg4Handle.pOutbufOps = NULL;
    435         }
    436     }
    437 
    438     FunctionOut();
    439 
    440     return ret;
    441 }
    442 
    443 OMX_ERRORTYPE Mpeg4CodecClose(EXYNOS_MPEG4DEC_HANDLE *pMpeg4Dec)
    444 {
    445     OMX_ERRORTYPE            ret        = OMX_ErrorNone;
    446     void                    *hMFCHandle = NULL;
    447     ExynosVideoDecOps       *pDecOps    = NULL;
    448     ExynosVideoDecBufferOps *pInbufOps  = NULL;
    449     ExynosVideoDecBufferOps *pOutbufOps = NULL;
    450 
    451     FunctionIn();
    452 
    453     if (pMpeg4Dec == NULL) {
    454         ret = OMX_ErrorBadParameter;
    455         goto EXIT;
    456     }
    457 
    458     hMFCHandle = pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle;
    459     pDecOps    = pMpeg4Dec->hMFCMpeg4Handle.pDecOps;
    460     pInbufOps  = pMpeg4Dec->hMFCMpeg4Handle.pInbufOps;
    461     pOutbufOps = pMpeg4Dec->hMFCMpeg4Handle.pOutbufOps;
    462 
    463     if (hMFCHandle != NULL) {
    464         pDecOps->Finalize(hMFCHandle);
    465         pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle = NULL;
    466     }
    467     if (pOutbufOps != NULL) {
    468         Exynos_OSAL_Free(pOutbufOps);
    469         pMpeg4Dec->hMFCMpeg4Handle.pOutbufOps = NULL;
    470     }
    471     if (pInbufOps != NULL) {
    472         Exynos_OSAL_Free(pInbufOps);
    473         pMpeg4Dec->hMFCMpeg4Handle.pInbufOps = NULL;
    474     }
    475     if (pDecOps != NULL) {
    476         Exynos_OSAL_Free(pDecOps);
    477         pMpeg4Dec->hMFCMpeg4Handle.pDecOps = NULL;
    478     }
    479 
    480     ret = OMX_ErrorNone;
    481 
    482 EXIT:
    483     FunctionOut();
    484 
    485     return ret;
    486 }
    487 
    488 OMX_ERRORTYPE Mpeg4CodecStart(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 nPortIndex)
    489 {
    490     OMX_ERRORTYPE            ret = OMX_ErrorNone;
    491     void                    *hMFCHandle = NULL;
    492     ExynosVideoDecOps       *pDecOps    = NULL;
    493     ExynosVideoDecBufferOps *pInbufOps  = NULL;
    494     ExynosVideoDecBufferOps *pOutbufOps = NULL;
    495     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
    496     EXYNOS_MPEG4DEC_HANDLE   *pMpeg4Dec = NULL;
    497 
    498     FunctionIn();
    499 
    500     if (pOMXComponent == NULL) {
    501         ret = OMX_ErrorBadParameter;
    502         goto EXIT;
    503     }
    504 
    505     pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)((EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate)->hComponentHandle;
    506     if (pVideoDec == NULL) {
    507         ret = OMX_ErrorBadParameter;
    508         goto EXIT;
    509     }
    510 
    511     pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)pVideoDec->hCodecHandle;
    512     if (pMpeg4Dec == NULL) {
    513         ret = OMX_ErrorBadParameter;
    514         goto EXIT;
    515     }
    516 
    517     hMFCHandle = pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle;
    518     pDecOps    = pMpeg4Dec->hMFCMpeg4Handle.pDecOps;
    519     pInbufOps  = pMpeg4Dec->hMFCMpeg4Handle.pInbufOps;
    520     pOutbufOps = pMpeg4Dec->hMFCMpeg4Handle.pOutbufOps;
    521 
    522     if (nPortIndex == INPUT_PORT_INDEX)
    523         pInbufOps->Run(hMFCHandle);
    524     else if (nPortIndex == OUTPUT_PORT_INDEX)
    525         pOutbufOps->Run(hMFCHandle);
    526 
    527     ret = OMX_ErrorNone;
    528 
    529 EXIT:
    530     FunctionOut();
    531 
    532     return ret;
    533 }
    534 
    535 OMX_ERRORTYPE Mpeg4CodecStop(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 nPortIndex)
    536 {
    537     OMX_ERRORTYPE            ret = OMX_ErrorNone;
    538     void                    *hMFCHandle = NULL;
    539     ExynosVideoDecOps       *pDecOps    = NULL;
    540     ExynosVideoDecBufferOps *pInbufOps  = NULL;
    541     ExynosVideoDecBufferOps *pOutbufOps = NULL;
    542     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
    543     EXYNOS_MPEG4DEC_HANDLE   *pMpeg4Dec = NULL;
    544 
    545     FunctionIn();
    546 
    547     if (pOMXComponent == NULL) {
    548         ret = OMX_ErrorBadParameter;
    549         goto EXIT;
    550     }
    551 
    552     pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)((EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate)->hComponentHandle;
    553     if (pVideoDec == NULL) {
    554         ret = OMX_ErrorBadParameter;
    555         goto EXIT;
    556     }
    557     pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)pVideoDec->hCodecHandle;
    558     if (pMpeg4Dec == NULL) {
    559         ret = OMX_ErrorBadParameter;
    560         goto EXIT;
    561     }
    562 
    563     hMFCHandle = pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle;
    564     pDecOps    = pMpeg4Dec->hMFCMpeg4Handle.pDecOps;
    565     pInbufOps  = pMpeg4Dec->hMFCMpeg4Handle.pInbufOps;
    566     pOutbufOps = pMpeg4Dec->hMFCMpeg4Handle.pOutbufOps;
    567 
    568     if ((nPortIndex == INPUT_PORT_INDEX) && (pInbufOps != NULL))
    569         pInbufOps->Stop(hMFCHandle);
    570     else if ((nPortIndex == OUTPUT_PORT_INDEX) && (pOutbufOps != NULL))
    571         pOutbufOps->Stop(hMFCHandle);
    572 
    573     ret = OMX_ErrorNone;
    574 
    575 EXIT:
    576     FunctionOut();
    577 
    578     return ret;
    579 }
    580 
    581 OMX_ERRORTYPE Mpeg4CodecOutputBufferProcessRun(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 nPortIndex)
    582 {
    583     OMX_ERRORTYPE            ret = OMX_ErrorNone;
    584     void                    *hMFCHandle = NULL;
    585     ExynosVideoDecOps       *pDecOps    = NULL;
    586     ExynosVideoDecBufferOps *pInbufOps  = NULL;
    587     ExynosVideoDecBufferOps *pOutbufOps = NULL;
    588     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
    589     EXYNOS_MPEG4DEC_HANDLE   *pMpeg4Dec = NULL;
    590 
    591     FunctionIn();
    592 
    593     if (pOMXComponent == NULL) {
    594         ret = OMX_ErrorBadParameter;
    595         goto EXIT;
    596     }
    597 
    598     pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)((EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate)->hComponentHandle;
    599     if (pVideoDec == NULL) {
    600         ret = OMX_ErrorBadParameter;
    601         goto EXIT;
    602     }
    603     pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)pVideoDec->hCodecHandle;
    604     if (pMpeg4Dec == NULL) {
    605         ret = OMX_ErrorBadParameter;
    606         goto EXIT;
    607     }
    608 
    609     hMFCHandle = pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle;
    610     pDecOps    = pMpeg4Dec->hMFCMpeg4Handle.pDecOps;
    611     pInbufOps  = pMpeg4Dec->hMFCMpeg4Handle.pInbufOps;
    612     pOutbufOps = pMpeg4Dec->hMFCMpeg4Handle.pOutbufOps;
    613 
    614     if (nPortIndex == INPUT_PORT_INDEX) {
    615         if (pMpeg4Dec->bSourceStart == OMX_FALSE) {
    616             Exynos_OSAL_SignalSet(pMpeg4Dec->hSourceStartEvent);
    617             Exynos_OSAL_SleepMillisec(0);
    618         }
    619     }
    620 
    621     if (nPortIndex == OUTPUT_PORT_INDEX) {
    622         if (pMpeg4Dec->bDestinationStart == OMX_FALSE) {
    623             Exynos_OSAL_SignalSet(pMpeg4Dec->hDestinationStartEvent);
    624             Exynos_OSAL_SleepMillisec(0);
    625         }
    626     }
    627 
    628     ret = OMX_ErrorNone;
    629 
    630 EXIT:
    631     FunctionOut();
    632 
    633     return ret;
    634 }
    635 
    636 OMX_ERRORTYPE Mpeg4CodecRegistCodecBuffers(
    637     OMX_COMPONENTTYPE   *pOMXComponent,
    638     OMX_U32              nPortIndex,
    639     OMX_U32              nBufferCnt)
    640 {
    641     OMX_ERRORTYPE                    ret                = OMX_ErrorNone;
    642     EXYNOS_OMX_BASECOMPONENT        *pExynosComponent   = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    643     EXYNOS_OMX_VIDEODEC_COMPONENT   *pVideoDec          = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
    644     EXYNOS_MPEG4DEC_HANDLE          *pMpeg4Dec          = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
    645     void                            *hMFCHandle         = pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle;
    646     CODEC_DEC_BUFFER               **ppCodecBuffer      = NULL;
    647     ExynosVideoDecBufferOps         *pBufOps            = NULL;
    648     ExynosVideoPlane                *pPlanes            = NULL;
    649 
    650     OMX_U32 nPlaneCnt = 0;
    651     int i, j;
    652 
    653     FunctionIn();
    654 
    655     if (nPortIndex == INPUT_PORT_INDEX) {
    656         ppCodecBuffer   = &(pVideoDec->pMFCDecInputBuffer[0]);
    657         nPlaneCnt       = MFC_INPUT_BUFFER_PLANE;
    658         pBufOps         = pMpeg4Dec->hMFCMpeg4Handle.pInbufOps;
    659     } else {
    660         ppCodecBuffer   = &(pVideoDec->pMFCDecOutputBuffer[0]);
    661         nPlaneCnt       = MFC_OUTPUT_BUFFER_PLANE;
    662         pBufOps         = pMpeg4Dec->hMFCMpeg4Handle.pOutbufOps;
    663     }
    664 
    665     pPlanes = (ExynosVideoPlane *)Exynos_OSAL_Malloc(sizeof(ExynosVideoPlane) * nPlaneCnt);
    666     if (pPlanes == NULL) {
    667         ret = OMX_ErrorInsufficientResources;
    668         goto EXIT;
    669     }
    670 
    671     /* Register buffer */
    672     for (i = 0; i < nBufferCnt; i++) {
    673         for (j = 0; j < nPlaneCnt; j++) {
    674             pPlanes[j].addr         = ppCodecBuffer[i]->pVirAddr[j];
    675             pPlanes[j].fd           = ppCodecBuffer[i]->fd[j];
    676             pPlanes[j].allocSize    = ppCodecBuffer[i]->bufferSize[j];
    677         }
    678 
    679         if (pBufOps->Register(hMFCHandle, pPlanes, nPlaneCnt) != VIDEO_ERROR_NONE) {
    680             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "PORT[%d]: Failed to Register buffer", nPortIndex);
    681             ret = OMX_ErrorInsufficientResources;
    682             Exynos_OSAL_Free(pPlanes);
    683             goto EXIT;
    684         }
    685     }
    686 
    687     Exynos_OSAL_Free(pPlanes);
    688 
    689     ret = OMX_ErrorNone;
    690 
    691 EXIT:
    692     FunctionOut();
    693 
    694     return ret;
    695 }
    696 
    697 OMX_ERRORTYPE Mpeg4CodecEnQueueAllBuffer(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 nPortIndex)
    698 {
    699     OMX_ERRORTYPE                  ret = OMX_ErrorNone;
    700     EXYNOS_OMX_BASECOMPONENT      *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    701     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
    702     EXYNOS_MPEG4DEC_HANDLE         *pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)pVideoDec->hCodecHandle;
    703     void                          *hMFCHandle = pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle;
    704     EXYNOS_OMX_BASEPORT           *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
    705     EXYNOS_OMX_BASEPORT           *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
    706     int i, nOutbufs;
    707 
    708     ExynosVideoDecOps       *pDecOps    = pMpeg4Dec->hMFCMpeg4Handle.pDecOps;
    709     ExynosVideoDecBufferOps *pInbufOps  = pMpeg4Dec->hMFCMpeg4Handle.pInbufOps;
    710     ExynosVideoDecBufferOps *pOutbufOps = pMpeg4Dec->hMFCMpeg4Handle.pOutbufOps;
    711 
    712     FunctionIn();
    713 
    714     if ((nPortIndex != INPUT_PORT_INDEX) && (nPortIndex != OUTPUT_PORT_INDEX)) {
    715         ret = OMX_ErrorBadPortIndex;
    716         goto EXIT;
    717     }
    718 
    719     if ((nPortIndex == INPUT_PORT_INDEX) &&
    720         (pMpeg4Dec->bSourceStart == OMX_TRUE)) {
    721         Exynos_CodecBufferReset(pExynosComponent, INPUT_PORT_INDEX);
    722 
    723         for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) {
    724             Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoDec->pMFCDecInputBuffer[%d]: 0x%x", i, pVideoDec->pMFCDecInputBuffer[i]);
    725             Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoDec->pMFCDecInputBuffer[%d]->pVirAddr[0]: 0x%x", i, pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[0]);
    726 
    727             Exynos_CodecBufferEnQueue(pExynosComponent, INPUT_PORT_INDEX, pVideoDec->pMFCDecInputBuffer[i]);
    728         }
    729 
    730         pInbufOps->Clear_Queue(hMFCHandle);
    731     } else if ((nPortIndex == OUTPUT_PORT_INDEX) &&
    732                (pMpeg4Dec->bDestinationStart == OMX_TRUE)) {
    733         OMX_U32 dataLen[MFC_OUTPUT_BUFFER_PLANE] = {0, 0};
    734         ExynosVideoBuffer *pBuffer = NULL;
    735 
    736         Exynos_CodecBufferReset(pExynosComponent, OUTPUT_PORT_INDEX);
    737 
    738         nOutbufs = pDecOps->Get_ActualBufferCount(hMFCHandle);
    739         nOutbufs += EXTRA_DPB_NUM;
    740         for (i = 0; i < nOutbufs; i++) {
    741             Exynos_CodecBufferEnQueue(pExynosComponent, OUTPUT_PORT_INDEX, pVideoDec->pMFCDecOutputBuffer[i]);
    742         }
    743         pOutbufOps->Clear_Queue(hMFCHandle);
    744     } else {
    745         ret = OMX_ErrorBadParameter;
    746         goto EXIT;
    747     }
    748 
    749 EXIT:
    750     FunctionOut();
    751 
    752     return ret;
    753 }
    754 
    755 OMX_ERRORTYPE Mpeg4CodecSrcSetup(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcInputData)
    756 {
    757     OMX_ERRORTYPE                  ret = OMX_ErrorNone;
    758     EXYNOS_OMX_BASECOMPONENT      *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    759     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
    760     EXYNOS_MPEG4DEC_HANDLE         *pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
    761     void                          *hMFCHandle = pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle;
    762     EXYNOS_OMX_BASEPORT           *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
    763     EXYNOS_OMX_BASEPORT           *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
    764     OMX_U32                     oneFrameSize = pSrcInputData->dataLen;
    765 
    766     ExynosVideoDecOps       *pDecOps    = pMpeg4Dec->hMFCMpeg4Handle.pDecOps;
    767     ExynosVideoDecBufferOps *pInbufOps  = pMpeg4Dec->hMFCMpeg4Handle.pInbufOps;
    768     ExynosVideoDecBufferOps *pOutbufOps = pMpeg4Dec->hMFCMpeg4Handle.pOutbufOps;
    769     ExynosVideoGeometry      bufferConf;
    770     OMX_U32                  inputBufferNumber = 0;
    771     int i;
    772 
    773     FunctionIn();
    774 
    775     if ((oneFrameSize <= 0) && (pSrcInputData->nFlags & OMX_BUFFERFLAG_EOS)) {
    776         OMX_BUFFERHEADERTYPE *OMXBuffer = NULL;
    777         OMXBuffer = Exynos_OutputBufferGetQueue_Direct(pExynosComponent);
    778         if (OMXBuffer == NULL) {
    779             ret = OMX_ErrorUndefined;
    780             goto EXIT;
    781         }
    782 
    783         OMXBuffer->nTimeStamp = pSrcInputData->timeStamp;
    784         OMXBuffer->nFlags = pSrcInputData->nFlags;
    785         Exynos_OMX_OutputBufferReturn(pOMXComponent, OMXBuffer);
    786 
    787         ret = OMX_ErrorNone;
    788         goto EXIT;
    789     }
    790 
    791     if (pVideoDec->bThumbnailMode == OMX_TRUE)
    792         pDecOps->Set_IFrameDecoding(hMFCHandle);
    793 
    794     /* input buffer info */
    795     Exynos_OSAL_Memset(&bufferConf, 0, sizeof(bufferConf));
    796     if (pMpeg4Dec->hMFCMpeg4Handle.codecType == CODEC_TYPE_MPEG4)
    797         bufferConf.eCompressionFormat = VIDEO_CODING_MPEG4;
    798     else
    799         bufferConf.eCompressionFormat = VIDEO_CODING_H263;
    800 
    801     pInbufOps->Set_Shareable(hMFCHandle);
    802     if (pExynosInputPort->bufferProcessType == BUFFER_SHARE) {
    803         bufferConf.nSizeImage = pExynosInputPort->portDefinition.format.video.nFrameWidth
    804                                 * pExynosInputPort->portDefinition.format.video.nFrameHeight * 3 / 2;
    805         inputBufferNumber = MAX_VIDEO_INPUTBUFFER_NUM;
    806     } else if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) {
    807         bufferConf.nSizeImage = DEFAULT_MFC_INPUT_BUFFER_SIZE;
    808         inputBufferNumber = MFC_INPUT_BUFFER_NUM_MAX;
    809     }
    810 
    811     /* should be done before prepare input buffer */
    812     if (pInbufOps->Enable_Cacheable(hMFCHandle) != VIDEO_ERROR_NONE) {
    813         ret = OMX_ErrorInsufficientResources;
    814         goto EXIT;
    815     }
    816 
    817     /* set input buffer geometry */
    818     if (pInbufOps->Set_Geometry(hMFCHandle, &bufferConf) != VIDEO_ERROR_NONE) {
    819         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to set geometry for input buffer");
    820         ret = OMX_ErrorInsufficientResources;
    821         goto EXIT;
    822     }
    823 
    824     /* setup input buffer */
    825     if (pInbufOps->Setup(hMFCHandle, inputBufferNumber) != VIDEO_ERROR_NONE) {
    826         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to setup input buffer");
    827         ret = OMX_ErrorInsufficientResources;
    828         goto EXIT;
    829     }
    830 
    831     if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) {
    832         ret = Mpeg4CodecRegistCodecBuffers(pOMXComponent, INPUT_PORT_INDEX, MFC_INPUT_BUFFER_NUM_MAX);
    833         if (ret != OMX_ErrorNone)
    834             goto EXIT;
    835     } else if (pExynosInputPort->bufferProcessType == BUFFER_SHARE) {
    836         /* Register input buffer */
    837         for (i = 0; i < pExynosInputPort->portDefinition.nBufferCountActual; i++) {
    838             ExynosVideoPlane plane;
    839             plane.addr = pExynosInputPort->extendBufferHeader[i].OMXBufferHeader->pBuffer;
    840             plane.allocSize = pExynosInputPort->extendBufferHeader[i].OMXBufferHeader->nAllocLen;
    841             plane.fd = pExynosInputPort->extendBufferHeader[i].buf_fd[0];
    842             if (pInbufOps->Register(hMFCHandle, &plane, MFC_INPUT_BUFFER_PLANE) != VIDEO_ERROR_NONE) {
    843                 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Register input buffer");
    844                 ret = OMX_ErrorInsufficientResources;
    845                 goto EXIT;
    846             }
    847         }
    848     }
    849 
    850     /* set output geometry */
    851     Exynos_OSAL_Memset(&bufferConf, 0, sizeof(bufferConf));
    852     pMpeg4Dec->hMFCMpeg4Handle.MFCOutputColorType = bufferConf.eColorFormat = VIDEO_COLORFORMAT_NV12_TILED;
    853     if (pOutbufOps->Set_Geometry(hMFCHandle, &bufferConf) != VIDEO_ERROR_NONE) {
    854         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to set geometry for output buffer");
    855         ret = OMX_ErrorInsufficientResources;
    856         goto EXIT;
    857     }
    858 
    859     /* input buffer enqueue for header parsing */
    860     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "oneFrameSize: %d", oneFrameSize);
    861     if (pInbufOps->Enqueue(hMFCHandle, (unsigned char **)&pSrcInputData->buffer.singlePlaneBuffer.dataBuffer,
    862                         (unsigned int *)&oneFrameSize, MFC_INPUT_BUFFER_PLANE, pSrcInputData->bufferHeader) != VIDEO_ERROR_NONE) {
    863         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to enqueue input buffer for header parsing");
    864 //        ret = OMX_ErrorInsufficientResources;
    865         ret = (OMX_ERRORTYPE)OMX_ErrorCodecInit;
    866         goto EXIT;
    867     }
    868 
    869     /* start header parsing */
    870     if (pInbufOps->Run(hMFCHandle) != VIDEO_ERROR_NONE) {
    871         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to run input buffer for header parsing");
    872         ret = OMX_ErrorCodecInit;
    873         goto EXIT;
    874     }
    875 
    876     /* get geometry for output */
    877     Exynos_OSAL_Memset(&pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf, 0, sizeof(ExynosVideoGeometry));
    878     if (pOutbufOps->Get_Geometry(hMFCHandle, &pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf) != VIDEO_ERROR_NONE) {
    879         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to get geometry for parsed header info");
    880         ret = OMX_ErrorInsufficientResources;
    881         goto EXIT;
    882     }
    883 
    884     /* get dpb count */
    885     pMpeg4Dec->hMFCMpeg4Handle.maxDPBNum = pDecOps->Get_ActualBufferCount(hMFCHandle);
    886     if (pVideoDec->bThumbnailMode == OMX_FALSE)
    887         pMpeg4Dec->hMFCMpeg4Handle.maxDPBNum += EXTRA_DPB_NUM;
    888     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "Mpeg4CodecSetup nOutbufs: %d", pMpeg4Dec->hMFCMpeg4Handle.maxDPBNum);
    889 
    890     pMpeg4Dec->hMFCMpeg4Handle.bConfiguredMFCSrc = OMX_TRUE;
    891 
    892     if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) {
    893         if ((pExynosInputPort->portDefinition.format.video.nFrameWidth != pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf.nFrameWidth) ||
    894             (pExynosInputPort->portDefinition.format.video.nFrameHeight != pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf.nFrameHeight)) {
    895             pExynosInputPort->portDefinition.format.video.nFrameWidth = pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf.nFrameWidth;
    896             pExynosInputPort->portDefinition.format.video.nFrameHeight = pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf.nFrameHeight;
    897             pExynosInputPort->portDefinition.format.video.nStride = ((pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf.nFrameWidth + 15) & (~15));
    898             pExynosInputPort->portDefinition.format.video.nSliceHeight = ((pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf.nFrameHeight + 15) & (~15));
    899 
    900             Exynos_UpdateFrameSize(pOMXComponent);
    901             pExynosOutputPort->exceptionFlag = NEED_PORT_DISABLE;
    902 
    903             /** Send Port Settings changed call back **/
    904             (*(pExynosComponent->pCallbacks->EventHandler))
    905                 (pOMXComponent,
    906                  pExynosComponent->callbackData,
    907                  OMX_EventPortSettingsChanged, /* The command was completed */
    908                  OMX_DirOutput, /* This is the port index */
    909                  0,
    910                  NULL);
    911         }
    912     } else if (pExynosOutputPort->bufferProcessType == BUFFER_SHARE) {
    913         if ((pExynosInputPort->portDefinition.format.video.nFrameWidth != pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf.nFrameWidth) ||
    914             (pExynosInputPort->portDefinition.format.video.nFrameHeight != pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf.nFrameHeight) ||
    915             (pExynosOutputPort->portDefinition.nBufferCountActual != pMpeg4Dec->hMFCMpeg4Handle.maxDPBNum)) {
    916             pExynosInputPort->portDefinition.format.video.nFrameWidth = pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf.nFrameWidth;
    917             pExynosInputPort->portDefinition.format.video.nFrameHeight = pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf.nFrameHeight;
    918             pExynosInputPort->portDefinition.format.video.nStride = ((pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf.nFrameWidth + 15) & (~15));
    919             pExynosInputPort->portDefinition.format.video.nSliceHeight = ((pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf.nFrameHeight + 15) & (~15));
    920 
    921             pExynosOutputPort->portDefinition.nBufferCountActual = pMpeg4Dec->hMFCMpeg4Handle.maxDPBNum;
    922             pExynosOutputPort->portDefinition.nBufferCountMin = pMpeg4Dec->hMFCMpeg4Handle.maxDPBNum;
    923 
    924             Exynos_UpdateFrameSize(pOMXComponent);
    925             pExynosOutputPort->exceptionFlag = NEED_PORT_DISABLE;
    926 
    927             /** Send Port Settings changed call back **/
    928             (*(pExynosComponent->pCallbacks->EventHandler))
    929                 (pOMXComponent,
    930                  pExynosComponent->callbackData,
    931                  OMX_EventPortSettingsChanged, /* The command was completed */
    932                  OMX_DirOutput, /* This is the port index */
    933                  0,
    934                  NULL);
    935         }
    936     }
    937     Exynos_OSAL_SleepMillisec(0);
    938     ret = OMX_ErrorInputDataDecodeYet;
    939     Mpeg4CodecStop(pOMXComponent, INPUT_PORT_INDEX);
    940 
    941 EXIT:
    942     FunctionOut();
    943 
    944     return ret;
    945 }
    946 
    947 OMX_ERRORTYPE Mpeg4CodecDstSetup(OMX_COMPONENTTYPE *pOMXComponent)
    948 {
    949     OMX_ERRORTYPE                  ret = OMX_ErrorNone;
    950     EXYNOS_OMX_BASECOMPONENT      *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    951     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
    952     EXYNOS_MPEG4DEC_HANDLE         *pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
    953     void                          *hMFCHandle = pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle;
    954     EXYNOS_OMX_BASEPORT           *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
    955     EXYNOS_OMX_BASEPORT           *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
    956 
    957     ExynosVideoDecOps       *pDecOps    = pMpeg4Dec->hMFCMpeg4Handle.pDecOps;
    958     ExynosVideoDecBufferOps *pInbufOps  = pMpeg4Dec->hMFCMpeg4Handle.pInbufOps;
    959     ExynosVideoDecBufferOps *pOutbufOps = pMpeg4Dec->hMFCMpeg4Handle.pOutbufOps;
    960 
    961     int i, nOutbufs;
    962 
    963     FunctionIn();
    964 
    965     if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) {
    966         /* BUFFER_COPY case, get dpb count */
    967         nOutbufs = pMpeg4Dec->hMFCMpeg4Handle.maxDPBNum;
    968 
    969         /* should be done before prepare output buffer */
    970         if (pOutbufOps->Enable_Cacheable(hMFCHandle) != VIDEO_ERROR_NONE) {
    971             ret = OMX_ErrorInsufficientResources;
    972             goto EXIT;
    973         }
    974     } else {
    975         /*BUFFER_SHERE case, get dpb count */
    976         nOutbufs = pExynosOutputPort->portDefinition.nBufferCountActual;
    977     }
    978 
    979     if (pOutbufOps->Enable_DynamicDPB(hMFCHandle) != VIDEO_ERROR_NONE) {
    980         ret = OMX_ErrorUndefined;
    981         goto EXIT;
    982     }
    983 
    984     pOutbufOps->Set_Shareable(hMFCHandle);
    985     if (pOutbufOps->Setup(hMFCHandle, MAX_OUTPUTBUFFER_NUM_DYNAMIC) != VIDEO_ERROR_NONE) {
    986         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to setup output buffer");
    987         ret = OMX_ErrorInsufficientResources;
    988         goto EXIT;
    989     }
    990 
    991     ExynosVideoPlane planes[MFC_OUTPUT_BUFFER_PLANE];
    992     OMX_U32 nAllocLen[MFC_OUTPUT_BUFFER_PLANE] = {0, 0};
    993     OMX_U32 dataLen[MFC_OUTPUT_BUFFER_PLANE] = {0, 0};
    994     int plane;
    995 
    996     nAllocLen[0] = calc_plane(pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf.nFrameWidth,
    997                         pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf.nFrameHeight);
    998     nAllocLen[1] = calc_plane(pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf.nFrameWidth,
    999                         pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf.nFrameHeight >> 1);
   1000 
   1001     if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) {
   1002         ret = Exynos_Allocate_CodecBuffers(pOMXComponent, OUTPUT_PORT_INDEX, nOutbufs, nAllocLen);
   1003         if (ret != OMX_ErrorNone)
   1004             goto EXIT;
   1005 
   1006         for (i = 0; i < nOutbufs; i++) {
   1007             /* Enqueue output buffer */
   1008             pOutbufOps->ExtensionEnqueue(hMFCHandle,
   1009                             (unsigned char **)pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr,
   1010                             (unsigned char **)pVideoDec->pMFCDecOutputBuffer[i]->fd,
   1011                             (unsigned int *)pVideoDec->pMFCDecOutputBuffer[i]->bufferSize,
   1012                             (unsigned int *)dataLen, MFC_OUTPUT_BUFFER_PLANE, NULL);
   1013         }
   1014 
   1015         if (pOutbufOps->Run(hMFCHandle) != VIDEO_ERROR_NONE) {
   1016             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to run output buffer");
   1017             ret = OMX_ErrorInsufficientResources;
   1018             goto EXIT;
   1019         }
   1020     } else if (pExynosOutputPort->bufferProcessType == BUFFER_SHARE) {
   1021         /*************/
   1022         /*    TBD    */
   1023         /*************/
   1024 #ifdef USE_ANB
   1025         if ((pExynosOutputPort->bIsANBEnabled == OMX_FALSE) &&
   1026             (pExynosOutputPort->bStoreMetaData == OMX_FALSE)) {
   1027             ret = OMX_ErrorNotImplemented;
   1028             goto EXIT;
   1029         }
   1030 #else
   1031         ret = OMX_ErrorNotImplemented;
   1032         goto EXIT;
   1033 #endif
   1034     }
   1035 
   1036     pMpeg4Dec->hMFCMpeg4Handle.bConfiguredMFCDst = OMX_TRUE;
   1037 
   1038     ret = OMX_ErrorNone;
   1039 
   1040 EXIT:
   1041     FunctionOut();
   1042 
   1043     return ret;
   1044 }
   1045 
   1046 OMX_ERRORTYPE Exynos_Mpeg4Dec_GetParameter(
   1047     OMX_IN OMX_HANDLETYPE hComponent,
   1048     OMX_IN OMX_INDEXTYPE  nParamIndex,
   1049     OMX_INOUT OMX_PTR     pComponentParameterStructure)
   1050 {
   1051     OMX_ERRORTYPE             ret              = OMX_ErrorNone;
   1052     OMX_COMPONENTTYPE        *pOMXComponent    = NULL;
   1053     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
   1054 
   1055     FunctionIn();
   1056 
   1057     if (hComponent == NULL || pComponentParameterStructure == NULL) {
   1058         ret = OMX_ErrorBadParameter;
   1059         goto EXIT;
   1060     }
   1061     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
   1062     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
   1063     if (ret != OMX_ErrorNone) {
   1064         goto EXIT;
   1065     }
   1066     if (pOMXComponent->pComponentPrivate == NULL) {
   1067         ret = OMX_ErrorBadParameter;
   1068         goto EXIT;
   1069     }
   1070 
   1071     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   1072     if (pExynosComponent->currentState == OMX_StateInvalid ) {
   1073         ret = OMX_ErrorInvalidState;
   1074         goto EXIT;
   1075     }
   1076 
   1077     switch (nParamIndex) {
   1078     case OMX_IndexParamVideoMpeg4:
   1079     {
   1080         OMX_VIDEO_PARAM_MPEG4TYPE *pDstMpeg4Param = (OMX_VIDEO_PARAM_MPEG4TYPE *)pComponentParameterStructure;
   1081         OMX_VIDEO_PARAM_MPEG4TYPE *pSrcMpeg4Param = NULL;
   1082         EXYNOS_MPEG4DEC_HANDLE    *pMpeg4Dec      = NULL;
   1083 
   1084         ret = Exynos_OMX_Check_SizeVersion(pDstMpeg4Param, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE));
   1085         if (ret != OMX_ErrorNone) {
   1086             goto EXIT;
   1087         }
   1088 
   1089         if (pDstMpeg4Param->nPortIndex >= ALL_PORT_NUM) {
   1090             ret = OMX_ErrorBadPortIndex;
   1091             goto EXIT;
   1092         }
   1093 
   1094         pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
   1095         pSrcMpeg4Param = &pMpeg4Dec->mpeg4Component[pDstMpeg4Param->nPortIndex];
   1096 
   1097         Exynos_OSAL_Memcpy(pDstMpeg4Param, pSrcMpeg4Param, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE));
   1098     }
   1099         break;
   1100     case OMX_IndexParamVideoH263:
   1101     {
   1102         OMX_VIDEO_PARAM_H263TYPE *pDstH263Param = (OMX_VIDEO_PARAM_H263TYPE *)pComponentParameterStructure;
   1103         OMX_VIDEO_PARAM_H263TYPE *pSrcH263Param = NULL;
   1104         EXYNOS_MPEG4DEC_HANDLE   *pMpeg4Dec     = NULL;
   1105 
   1106         ret = Exynos_OMX_Check_SizeVersion(pDstH263Param, sizeof(OMX_VIDEO_PARAM_H263TYPE));
   1107         if (ret != OMX_ErrorNone) {
   1108             goto EXIT;
   1109         }
   1110 
   1111         if (pDstH263Param->nPortIndex >= ALL_PORT_NUM) {
   1112             ret = OMX_ErrorBadPortIndex;
   1113             goto EXIT;
   1114         }
   1115 
   1116         pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
   1117         pSrcH263Param = &pMpeg4Dec->h263Component[pDstH263Param->nPortIndex];
   1118 
   1119         Exynos_OSAL_Memcpy(pDstH263Param, pSrcH263Param, sizeof(OMX_VIDEO_PARAM_H263TYPE));
   1120     }
   1121         break;
   1122     case OMX_IndexParamStandardComponentRole:
   1123     {
   1124         OMX_S32                      codecType;
   1125         OMX_PARAM_COMPONENTROLETYPE *pComponentRole = (OMX_PARAM_COMPONENTROLETYPE *)pComponentParameterStructure;
   1126 
   1127         ret = Exynos_OMX_Check_SizeVersion(pComponentRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
   1128         if (ret != OMX_ErrorNone) {
   1129             goto EXIT;
   1130         }
   1131 
   1132         codecType = ((EXYNOS_MPEG4DEC_HANDLE *)(((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle))->hMFCMpeg4Handle.codecType;
   1133         if (codecType == CODEC_TYPE_MPEG4)
   1134             Exynos_OSAL_Strcpy((char *)pComponentRole->cRole, EXYNOS_OMX_COMPONENT_MPEG4_DEC_ROLE);
   1135         else
   1136             Exynos_OSAL_Strcpy((char *)pComponentRole->cRole, EXYNOS_OMX_COMPONENT_H263_DEC_ROLE);
   1137     }
   1138         break;
   1139     case OMX_IndexParamVideoProfileLevelQuerySupported:
   1140     {
   1141         OMX_VIDEO_PARAM_PROFILELEVELTYPE *pDstProfileLevel   = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pComponentParameterStructure;
   1142         EXYNOS_OMX_VIDEO_PROFILELEVEL    *pProfileLevel      = NULL;
   1143         OMX_U32                           maxProfileLevelNum = 0;
   1144         OMX_S32                           codecType;
   1145 
   1146         ret = Exynos_OMX_Check_SizeVersion(pDstProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE));
   1147         if (ret != OMX_ErrorNone) {
   1148             goto EXIT;
   1149         }
   1150 
   1151         if (pDstProfileLevel->nPortIndex >= ALL_PORT_NUM) {
   1152             ret = OMX_ErrorBadPortIndex;
   1153             goto EXIT;
   1154         }
   1155 
   1156         codecType = ((EXYNOS_MPEG4DEC_HANDLE *)(((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle))->hMFCMpeg4Handle.codecType;
   1157         if (codecType == CODEC_TYPE_MPEG4) {
   1158             pProfileLevel = supportedMPEG4ProfileLevels;
   1159             maxProfileLevelNum = sizeof(supportedMPEG4ProfileLevels) / sizeof(EXYNOS_OMX_VIDEO_PROFILELEVEL);
   1160         } else {
   1161             pProfileLevel = supportedH263ProfileLevels;
   1162             maxProfileLevelNum = sizeof(supportedH263ProfileLevels) / sizeof(EXYNOS_OMX_VIDEO_PROFILELEVEL);
   1163         }
   1164 
   1165         if (pDstProfileLevel->nProfileIndex >= maxProfileLevelNum) {
   1166             ret = OMX_ErrorNoMore;
   1167             goto EXIT;
   1168         }
   1169 
   1170         pProfileLevel += pDstProfileLevel->nProfileIndex;
   1171         pDstProfileLevel->eProfile = pProfileLevel->profile;
   1172         pDstProfileLevel->eLevel = pProfileLevel->level;
   1173     }
   1174         break;
   1175     case OMX_IndexParamVideoProfileLevelCurrent:
   1176     {
   1177         OMX_VIDEO_PARAM_PROFILELEVELTYPE *pDstProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pComponentParameterStructure;
   1178         OMX_VIDEO_PARAM_MPEG4TYPE        *pSrcMpeg4Param   = NULL;
   1179         OMX_VIDEO_PARAM_H263TYPE         *pSrcH263Param    = NULL;
   1180         EXYNOS_MPEG4DEC_HANDLE           *pMpeg4Dec        = NULL;
   1181         OMX_S32                           codecType;
   1182 
   1183         ret = Exynos_OMX_Check_SizeVersion(pDstProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE));
   1184         if (ret != OMX_ErrorNone) {
   1185             goto EXIT;
   1186         }
   1187 
   1188         if (pDstProfileLevel->nPortIndex >= ALL_PORT_NUM) {
   1189             ret = OMX_ErrorBadPortIndex;
   1190             goto EXIT;
   1191         }
   1192 
   1193         pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
   1194         codecType = pMpeg4Dec->hMFCMpeg4Handle.codecType;
   1195         if (codecType == CODEC_TYPE_MPEG4) {
   1196             pSrcMpeg4Param = &pMpeg4Dec->mpeg4Component[pDstProfileLevel->nPortIndex];
   1197             pDstProfileLevel->eProfile = pSrcMpeg4Param->eProfile;
   1198             pDstProfileLevel->eLevel = pSrcMpeg4Param->eLevel;
   1199         } else {
   1200             pSrcH263Param = &pMpeg4Dec->h263Component[pDstProfileLevel->nPortIndex];
   1201             pDstProfileLevel->eProfile = pSrcH263Param->eProfile;
   1202             pDstProfileLevel->eLevel = pSrcH263Param->eLevel;
   1203         }
   1204     }
   1205         break;
   1206     case OMX_IndexParamVideoErrorCorrection:
   1207     {
   1208         OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pDstErrorCorrectionType = (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *)pComponentParameterStructure;
   1209         OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pSrcErrorCorrectionType = NULL;
   1210         EXYNOS_MPEG4DEC_HANDLE              *pMpeg4Dec               = NULL;
   1211 
   1212         ret = Exynos_OMX_Check_SizeVersion(pDstErrorCorrectionType, sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE));
   1213         if (ret != OMX_ErrorNone) {
   1214             goto EXIT;
   1215         }
   1216 
   1217         if (pDstErrorCorrectionType->nPortIndex != INPUT_PORT_INDEX) {
   1218             ret = OMX_ErrorBadPortIndex;
   1219             goto EXIT;
   1220         }
   1221 
   1222         pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
   1223         pSrcErrorCorrectionType = &pMpeg4Dec->errorCorrectionType[INPUT_PORT_INDEX];
   1224 
   1225         pDstErrorCorrectionType->bEnableHEC = pSrcErrorCorrectionType->bEnableHEC;
   1226         pDstErrorCorrectionType->bEnableResync = pSrcErrorCorrectionType->bEnableResync;
   1227         pDstErrorCorrectionType->nResynchMarkerSpacing = pSrcErrorCorrectionType->nResynchMarkerSpacing;
   1228         pDstErrorCorrectionType->bEnableDataPartitioning = pSrcErrorCorrectionType->bEnableDataPartitioning;
   1229         pDstErrorCorrectionType->bEnableRVLC = pSrcErrorCorrectionType->bEnableRVLC;
   1230     }
   1231         break;
   1232     default:
   1233         ret = Exynos_OMX_VideoDecodeGetParameter(hComponent, nParamIndex, pComponentParameterStructure);
   1234         break;
   1235     }
   1236 EXIT:
   1237     FunctionOut();
   1238 
   1239     return ret;
   1240 }
   1241 
   1242 OMX_ERRORTYPE Exynos_Mpeg4Dec_SetParameter(
   1243     OMX_IN OMX_HANDLETYPE hComponent,
   1244     OMX_IN OMX_INDEXTYPE  nIndex,
   1245     OMX_IN OMX_PTR        pComponentParameterStructure)
   1246 {
   1247     OMX_ERRORTYPE             ret              = OMX_ErrorNone;
   1248     OMX_COMPONENTTYPE        *pOMXComponent    = NULL;
   1249     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
   1250 
   1251     FunctionIn();
   1252 
   1253     if (hComponent == NULL || pComponentParameterStructure == NULL) {
   1254         ret = OMX_ErrorBadParameter;
   1255         goto EXIT;
   1256     }
   1257     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
   1258     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
   1259     if (ret != OMX_ErrorNone) {
   1260         goto EXIT;
   1261     }
   1262     if (pOMXComponent->pComponentPrivate == NULL) {
   1263         ret = OMX_ErrorBadParameter;
   1264         goto EXIT;
   1265     }
   1266 
   1267     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   1268     if (pExynosComponent->currentState == OMX_StateInvalid ) {
   1269         ret = OMX_ErrorInvalidState;
   1270         goto EXIT;
   1271     }
   1272 
   1273     switch (nIndex) {
   1274     case OMX_IndexParamVideoMpeg4:
   1275     {
   1276         OMX_VIDEO_PARAM_MPEG4TYPE *pDstMpeg4Param = NULL;
   1277         OMX_VIDEO_PARAM_MPEG4TYPE *pSrcMpeg4Param = (OMX_VIDEO_PARAM_MPEG4TYPE *)pComponentParameterStructure;
   1278         EXYNOS_MPEG4DEC_HANDLE    *pMpeg4Dec      = NULL;
   1279 
   1280         ret = Exynos_OMX_Check_SizeVersion(pSrcMpeg4Param, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE));
   1281         if (ret != OMX_ErrorNone) {
   1282             goto EXIT;
   1283         }
   1284 
   1285         if (pSrcMpeg4Param->nPortIndex >= ALL_PORT_NUM) {
   1286             ret = OMX_ErrorBadPortIndex;
   1287             goto EXIT;
   1288         }
   1289 
   1290         pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
   1291         pDstMpeg4Param = &pMpeg4Dec->mpeg4Component[pSrcMpeg4Param->nPortIndex];
   1292 
   1293         Exynos_OSAL_Memcpy(pDstMpeg4Param, pSrcMpeg4Param, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE));
   1294     }
   1295         break;
   1296     case OMX_IndexParamVideoH263:
   1297     {
   1298         OMX_VIDEO_PARAM_H263TYPE *pDstH263Param = NULL;
   1299         OMX_VIDEO_PARAM_H263TYPE *pSrcH263Param = (OMX_VIDEO_PARAM_H263TYPE *)pComponentParameterStructure;
   1300         EXYNOS_MPEG4DEC_HANDLE   *pMpeg4Dec     = NULL;
   1301 
   1302         ret = Exynos_OMX_Check_SizeVersion(pSrcH263Param, sizeof(OMX_VIDEO_PARAM_H263TYPE));
   1303         if (ret != OMX_ErrorNone) {
   1304             goto EXIT;
   1305         }
   1306 
   1307         if (pSrcH263Param->nPortIndex >= ALL_PORT_NUM) {
   1308             ret = OMX_ErrorBadPortIndex;
   1309             goto EXIT;
   1310         }
   1311 
   1312         pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
   1313         pDstH263Param = &pMpeg4Dec->h263Component[pSrcH263Param->nPortIndex];
   1314 
   1315         Exynos_OSAL_Memcpy(pDstH263Param, pSrcH263Param, sizeof(OMX_VIDEO_PARAM_H263TYPE));
   1316     }
   1317         break;
   1318     case OMX_IndexParamStandardComponentRole:
   1319     {
   1320         OMX_PARAM_COMPONENTROLETYPE *pComponentRole = (OMX_PARAM_COMPONENTROLETYPE*)pComponentParameterStructure;
   1321 
   1322         ret = Exynos_OMX_Check_SizeVersion(pComponentRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
   1323         if (ret != OMX_ErrorNone) {
   1324             goto EXIT;
   1325         }
   1326 
   1327         if ((pExynosComponent->currentState != OMX_StateLoaded) && (pExynosComponent->currentState != OMX_StateWaitForResources)) {
   1328             ret = OMX_ErrorIncorrectStateOperation;
   1329             goto EXIT;
   1330         }
   1331 
   1332         if (!Exynos_OSAL_Strcmp((char*)pComponentRole->cRole, EXYNOS_OMX_COMPONENT_MPEG4_DEC_ROLE)) {
   1333             pExynosComponent->pExynosPort[INPUT_PORT_INDEX].portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4;
   1334         } else if (!Exynos_OSAL_Strcmp((char*)pComponentRole->cRole, EXYNOS_OMX_COMPONENT_H263_DEC_ROLE)) {
   1335             pExynosComponent->pExynosPort[INPUT_PORT_INDEX].portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingH263;
   1336         } else {
   1337             ret = OMX_ErrorBadParameter;
   1338             goto EXIT;
   1339         }
   1340     }
   1341         break;
   1342     case OMX_IndexParamVideoProfileLevelCurrent:
   1343     {
   1344         OMX_VIDEO_PARAM_PROFILELEVELTYPE *pSrcProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pComponentParameterStructure;
   1345         OMX_VIDEO_PARAM_MPEG4TYPE        *pDstMpeg4Param   = NULL;
   1346         OMX_VIDEO_PARAM_H263TYPE         *pDstH263Param    = NULL;
   1347         EXYNOS_MPEG4DEC_HANDLE           *pMpeg4Dec        = NULL;
   1348         OMX_S32                           codecType;
   1349 
   1350         ret = Exynos_OMX_Check_SizeVersion(pSrcProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE));
   1351         if (ret != OMX_ErrorNone)
   1352             goto EXIT;
   1353 
   1354         if (pSrcProfileLevel->nPortIndex >= ALL_PORT_NUM) {
   1355             ret = OMX_ErrorBadPortIndex;
   1356             goto EXIT;
   1357         }
   1358 
   1359         pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
   1360         codecType = pMpeg4Dec->hMFCMpeg4Handle.codecType;
   1361         if (codecType == CODEC_TYPE_MPEG4) {
   1362             /*
   1363              * To do: Check validity of profile & level parameters
   1364              */
   1365 
   1366             pDstMpeg4Param = &pMpeg4Dec->mpeg4Component[pSrcProfileLevel->nPortIndex];
   1367             pDstMpeg4Param->eProfile = pSrcProfileLevel->eProfile;
   1368             pDstMpeg4Param->eLevel = pSrcProfileLevel->eLevel;
   1369         } else {
   1370             /*
   1371              * To do: Check validity of profile & level parameters
   1372              */
   1373 
   1374             pDstH263Param = &pMpeg4Dec->h263Component[pSrcProfileLevel->nPortIndex];
   1375             pDstH263Param->eProfile = pSrcProfileLevel->eProfile;
   1376             pDstH263Param->eLevel = pSrcProfileLevel->eLevel;
   1377         }
   1378     }
   1379         break;
   1380     case OMX_IndexParamVideoErrorCorrection:
   1381     {
   1382         OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pSrcErrorCorrectionType = (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *)pComponentParameterStructure;
   1383         OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pDstErrorCorrectionType = NULL;
   1384         EXYNOS_MPEG4DEC_HANDLE              *pMpeg4Dec               = NULL;
   1385 
   1386         ret = Exynos_OMX_Check_SizeVersion(pSrcErrorCorrectionType, sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE));
   1387         if (ret != OMX_ErrorNone) {
   1388             goto EXIT;
   1389         }
   1390 
   1391         if (pSrcErrorCorrectionType->nPortIndex != INPUT_PORT_INDEX) {
   1392             ret = OMX_ErrorBadPortIndex;
   1393             goto EXIT;
   1394         }
   1395 
   1396         pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
   1397         pDstErrorCorrectionType = &pMpeg4Dec->errorCorrectionType[INPUT_PORT_INDEX];
   1398 
   1399         pDstErrorCorrectionType->bEnableHEC = pSrcErrorCorrectionType->bEnableHEC;
   1400         pDstErrorCorrectionType->bEnableResync = pSrcErrorCorrectionType->bEnableResync;
   1401         pDstErrorCorrectionType->nResynchMarkerSpacing = pSrcErrorCorrectionType->nResynchMarkerSpacing;
   1402         pDstErrorCorrectionType->bEnableDataPartitioning = pSrcErrorCorrectionType->bEnableDataPartitioning;
   1403         pDstErrorCorrectionType->bEnableRVLC = pSrcErrorCorrectionType->bEnableRVLC;
   1404     }
   1405         break;
   1406     default:
   1407         ret = Exynos_OMX_VideoDecodeSetParameter(hComponent, nIndex, pComponentParameterStructure);
   1408         break;
   1409     }
   1410 EXIT:
   1411     FunctionOut();
   1412 
   1413     return ret;
   1414 }
   1415 
   1416 OMX_ERRORTYPE Exynos_Mpeg4Dec_GetConfig(
   1417     OMX_IN OMX_HANDLETYPE hComponent,
   1418     OMX_IN OMX_INDEXTYPE  nIndex,
   1419     OMX_IN OMX_PTR        pComponentConfigStructure)
   1420 {
   1421     OMX_ERRORTYPE             ret              = OMX_ErrorNone;
   1422     OMX_COMPONENTTYPE        *pOMXComponent    = NULL;
   1423     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
   1424 
   1425     FunctionIn();
   1426 
   1427     if (hComponent == NULL || pComponentConfigStructure == NULL) {
   1428         ret = OMX_ErrorBadParameter;
   1429         goto EXIT;
   1430     }
   1431     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
   1432     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
   1433     if (ret != OMX_ErrorNone) {
   1434         goto EXIT;
   1435     }
   1436     if (pOMXComponent->pComponentPrivate == NULL) {
   1437         ret = OMX_ErrorBadParameter;
   1438         goto EXIT;
   1439     }
   1440     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   1441     if (pExynosComponent->currentState == OMX_StateInvalid) {
   1442         ret = OMX_ErrorInvalidState;
   1443         goto EXIT;
   1444     }
   1445 
   1446     switch (nIndex) {
   1447     default:
   1448         ret = Exynos_OMX_VideoDecodeGetConfig(hComponent, nIndex, pComponentConfigStructure);
   1449         break;
   1450     }
   1451 
   1452 EXIT:
   1453     FunctionOut();
   1454 
   1455     return ret;
   1456 }
   1457 
   1458 OMX_ERRORTYPE Exynos_Mpeg4Dec_SetConfig(
   1459     OMX_IN OMX_HANDLETYPE hComponent,
   1460     OMX_IN OMX_INDEXTYPE  nIndex,
   1461     OMX_IN OMX_PTR        pComponentConfigStructure)
   1462 {
   1463     OMX_ERRORTYPE             ret              = OMX_ErrorNone;
   1464     OMX_COMPONENTTYPE        *pOMXComponent    = NULL;
   1465     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
   1466 
   1467     FunctionIn();
   1468 
   1469     if (hComponent == NULL || pComponentConfigStructure == NULL) {
   1470         ret = OMX_ErrorBadParameter;
   1471         goto EXIT;
   1472     }
   1473     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
   1474     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
   1475     if (ret != OMX_ErrorNone) {
   1476         goto EXIT;
   1477     }
   1478     if (pOMXComponent->pComponentPrivate == NULL) {
   1479         ret = OMX_ErrorBadParameter;
   1480         goto EXIT;
   1481     }
   1482     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   1483     if (pExynosComponent->currentState == OMX_StateInvalid) {
   1484         ret = OMX_ErrorInvalidState;
   1485         goto EXIT;
   1486     }
   1487 
   1488     switch (nIndex) {
   1489     default:
   1490         ret = Exynos_OMX_VideoDecodeSetConfig(hComponent, nIndex, pComponentConfigStructure);
   1491         break;
   1492     }
   1493 
   1494 EXIT:
   1495     FunctionOut();
   1496 
   1497     return ret;
   1498 }
   1499 
   1500 OMX_ERRORTYPE Exynos_Mpeg4Dec_GetExtensionIndex(
   1501     OMX_IN  OMX_HANDLETYPE  hComponent,
   1502     OMX_IN  OMX_STRING      cParameterName,
   1503     OMX_OUT OMX_INDEXTYPE  *pIndexType)
   1504 {
   1505     OMX_ERRORTYPE             ret              = OMX_ErrorNone;
   1506     OMX_COMPONENTTYPE        *pOMXComponent    = NULL;
   1507     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
   1508 
   1509     FunctionIn();
   1510 
   1511     if (hComponent == NULL) {
   1512         ret = OMX_ErrorBadParameter;
   1513         goto EXIT;
   1514     }
   1515     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
   1516     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
   1517     if (ret != OMX_ErrorNone) {
   1518         goto EXIT;
   1519     }
   1520     if (pOMXComponent->pComponentPrivate == NULL) {
   1521         ret = OMX_ErrorBadParameter;
   1522         goto EXIT;
   1523     }
   1524     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   1525     if ((cParameterName == NULL) || (pIndexType == NULL)) {
   1526         ret = OMX_ErrorBadParameter;
   1527         goto EXIT;
   1528     }
   1529     if (pExynosComponent->currentState == OMX_StateInvalid) {
   1530         ret = OMX_ErrorInvalidState;
   1531         goto EXIT;
   1532     }
   1533 
   1534     ret = Exynos_OMX_VideoDecodeGetExtensionIndex(hComponent, cParameterName, pIndexType);
   1535 
   1536 EXIT:
   1537     FunctionOut();
   1538 
   1539     return ret;
   1540 }
   1541 
   1542 OMX_ERRORTYPE Exynos_Mpeg4Dec_ComponentRoleEnum(
   1543     OMX_IN  OMX_HANDLETYPE hComponent,
   1544     OMX_OUT OMX_U8        *cRole,
   1545     OMX_IN  OMX_U32        nIndex)
   1546 {
   1547     OMX_ERRORTYPE             ret              = OMX_ErrorNone;
   1548     OMX_COMPONENTTYPE        *pOMXComponent    = NULL;
   1549     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
   1550     OMX_S32                   codecType;
   1551 
   1552     FunctionIn();
   1553 
   1554     if ((hComponent == NULL) || (cRole == NULL)) {
   1555         ret = OMX_ErrorBadParameter;
   1556         goto EXIT;
   1557     }
   1558     if (nIndex != (MAX_COMPONENT_ROLE_NUM - 1)) {
   1559         ret = OMX_ErrorNoMore;
   1560         goto EXIT;
   1561     }
   1562     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
   1563     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
   1564     if (ret != OMX_ErrorNone) {
   1565         goto EXIT;
   1566     }
   1567     if (pOMXComponent->pComponentPrivate == NULL) {
   1568         ret = OMX_ErrorBadParameter;
   1569         goto EXIT;
   1570     }
   1571     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   1572     if (pExynosComponent->currentState == OMX_StateInvalid ) {
   1573         ret = OMX_ErrorInvalidState;
   1574         goto EXIT;
   1575     }
   1576 
   1577     codecType = ((EXYNOS_MPEG4DEC_HANDLE *)(((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle))->hMFCMpeg4Handle.codecType;
   1578     if (codecType == CODEC_TYPE_MPEG4)
   1579         Exynos_OSAL_Strcpy((char *)cRole, EXYNOS_OMX_COMPONENT_MPEG4_DEC_ROLE);
   1580     else
   1581         Exynos_OSAL_Strcpy((char *)cRole, EXYNOS_OMX_COMPONENT_H263_DEC_ROLE);
   1582 
   1583 EXIT:
   1584     FunctionOut();
   1585 
   1586     return ret;
   1587 }
   1588 
   1589 /* MFC Init */
   1590 OMX_ERRORTYPE Exynos_Mpeg4Dec_Init(OMX_COMPONENTTYPE *pOMXComponent)
   1591 {
   1592     OMX_ERRORTYPE                  ret               = OMX_ErrorNone;
   1593     EXYNOS_OMX_BASECOMPONENT      *pExynosComponent  = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   1594     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec         = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
   1595     EXYNOS_OMX_BASEPORT           *pExynosInputPort  = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
   1596     EXYNOS_OMX_BASEPORT           *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
   1597     EXYNOS_MPEG4DEC_HANDLE        *pMpeg4Dec         = (EXYNOS_MPEG4DEC_HANDLE *)pVideoDec->hCodecHandle;
   1598     OMX_PTR                        hMFCHandle        = pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle;
   1599 
   1600     ExynosVideoDecOps       *pDecOps    = NULL;
   1601     ExynosVideoDecBufferOps *pInbufOps  = NULL;
   1602     ExynosVideoDecBufferOps *pOutbufOps = NULL;
   1603 
   1604     CSC_METHOD csc_method = CSC_METHOD_SW;
   1605     int i, plane;
   1606 
   1607     FunctionIn();
   1608 
   1609     pMpeg4Dec->hMFCMpeg4Handle.bConfiguredMFCSrc = OMX_FALSE;
   1610     pMpeg4Dec->hMFCMpeg4Handle.bConfiguredMFCDst = OMX_FALSE;
   1611     pExynosComponent->bUseFlagEOF = OMX_TRUE;
   1612     pExynosComponent->bSaveFlagEOS = OMX_FALSE;
   1613     pExynosComponent->bBehaviorEOS = OMX_FALSE;
   1614 
   1615     /* H.264 Codec Open */
   1616     ret = Mpeg4CodecOpen(pMpeg4Dec);
   1617     if (ret != OMX_ErrorNone) {
   1618         goto EXIT;
   1619     }
   1620 
   1621     pDecOps    = pMpeg4Dec->hMFCMpeg4Handle.pDecOps;
   1622     pInbufOps  = pMpeg4Dec->hMFCMpeg4Handle.pInbufOps;
   1623     pOutbufOps = pMpeg4Dec->hMFCMpeg4Handle.pOutbufOps;
   1624 
   1625     if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) {
   1626         OMX_U32 nPlaneSize[MFC_INPUT_BUFFER_PLANE] = {DEFAULT_MFC_INPUT_BUFFER_SIZE};
   1627         Exynos_OSAL_SemaphoreCreate(&pExynosInputPort->codecSemID);
   1628         Exynos_OSAL_QueueCreate(&pExynosInputPort->codecBufferQ, MAX_QUEUE_ELEMENTS);
   1629         ret = Exynos_Allocate_CodecBuffers(pOMXComponent, INPUT_PORT_INDEX, MFC_INPUT_BUFFER_NUM_MAX, nPlaneSize);
   1630         if (ret != OMX_ErrorNone)
   1631             goto EXIT;
   1632 
   1633         for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++)
   1634             Exynos_CodecBufferEnQueue(pExynosComponent, INPUT_PORT_INDEX, pVideoDec->pMFCDecInputBuffer[i]);
   1635     } else if (pExynosInputPort->bufferProcessType == BUFFER_SHARE) {
   1636         /*************/
   1637         /*    TBD    */
   1638         /*************/
   1639         /* Does not require any actions. */
   1640     }
   1641 
   1642     if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) {
   1643         Exynos_OSAL_SemaphoreCreate(&pExynosOutputPort->codecSemID);
   1644         Exynos_OSAL_QueueCreate(&pExynosOutputPort->codecBufferQ, MAX_QUEUE_ELEMENTS);
   1645     } else if (pExynosOutputPort->bufferProcessType == BUFFER_SHARE) {
   1646         /*************/
   1647         /*    TBD    */
   1648         /*************/
   1649         /* Does not require any actions. */
   1650     }
   1651 
   1652     pMpeg4Dec->bSourceStart = OMX_FALSE;
   1653     Exynos_OSAL_SignalCreate(&pMpeg4Dec->hSourceStartEvent);
   1654     pMpeg4Dec->bDestinationStart = OMX_FALSE;
   1655     Exynos_OSAL_SignalCreate(&pMpeg4Dec->hDestinationStartEvent);
   1656 
   1657     Exynos_OSAL_Memset(pExynosComponent->timeStamp, -19771003, sizeof(OMX_TICKS) * MAX_TIMESTAMP);
   1658     Exynos_OSAL_Memset(pExynosComponent->nFlags, 0, sizeof(OMX_U32) * MAX_FLAGS);
   1659     pMpeg4Dec->hMFCMpeg4Handle.indexTimestamp = 0;
   1660     pMpeg4Dec->hMFCMpeg4Handle.outputIndexTimestamp = 0;
   1661 
   1662     pExynosComponent->getAllDelayBuffer = OMX_FALSE;
   1663 
   1664 #if 0//defined(USE_CSC_GSCALER)
   1665     csc_method = CSC_METHOD_HW; //in case of Use ION buffer.
   1666 #endif
   1667     pVideoDec->csc_handle = csc_init(csc_method);
   1668     if (pVideoDec->csc_handle == NULL) {
   1669         ret = OMX_ErrorInsufficientResources;
   1670         goto EXIT;
   1671     }
   1672     pVideoDec->csc_set_format = OMX_FALSE;
   1673 
   1674 EXIT:
   1675     FunctionOut();
   1676 
   1677     return ret;
   1678 }
   1679 
   1680 /* MFC Terminate */
   1681 OMX_ERRORTYPE Exynos_Mpeg4Dec_Terminate(OMX_COMPONENTTYPE *pOMXComponent)
   1682 {
   1683     OMX_ERRORTYPE          ret = OMX_ErrorNone;
   1684     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   1685     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
   1686     EXYNOS_OMX_BASEPORT      *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
   1687     EXYNOS_OMX_BASEPORT      *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
   1688     EXYNOS_MPEG4DEC_HANDLE    *pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
   1689     OMX_PTR                hMFCHandle = pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle;
   1690 
   1691     ExynosVideoDecOps       *pDecOps    = pMpeg4Dec->hMFCMpeg4Handle.pDecOps;
   1692     ExynosVideoDecBufferOps *pInbufOps  = pMpeg4Dec->hMFCMpeg4Handle.pInbufOps;
   1693     ExynosVideoDecBufferOps *pOutbufOps = pMpeg4Dec->hMFCMpeg4Handle.pOutbufOps;
   1694 
   1695     int i, plane;
   1696 
   1697     FunctionIn();
   1698 
   1699     if (pVideoDec->csc_handle != NULL) {
   1700         csc_deinit(pVideoDec->csc_handle);
   1701         pVideoDec->csc_handle = NULL;
   1702     }
   1703 
   1704     Exynos_OSAL_SignalTerminate(pMpeg4Dec->hDestinationStartEvent);
   1705     pMpeg4Dec->hDestinationStartEvent = NULL;
   1706     pMpeg4Dec->bDestinationStart = OMX_FALSE;
   1707     Exynos_OSAL_SignalTerminate(pMpeg4Dec->hSourceStartEvent);
   1708     pMpeg4Dec->hSourceStartEvent = NULL;
   1709     pMpeg4Dec->bSourceStart = OMX_FALSE;
   1710 
   1711     if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) {
   1712         Exynos_Free_CodecBuffers(pOMXComponent, OUTPUT_PORT_INDEX);
   1713         Exynos_OSAL_QueueTerminate(&pExynosOutputPort->codecBufferQ);
   1714         Exynos_OSAL_SemaphoreTerminate(pExynosOutputPort->codecSemID);
   1715     } else if (pExynosOutputPort->bufferProcessType == BUFFER_SHARE) {
   1716         /*************/
   1717         /*    TBD    */
   1718         /*************/
   1719         /* Does not require any actions. */
   1720     }
   1721 
   1722     if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) {
   1723         Exynos_Free_CodecBuffers(pOMXComponent, INPUT_PORT_INDEX);
   1724         Exynos_OSAL_QueueTerminate(&pExynosInputPort->codecBufferQ);
   1725         Exynos_OSAL_SemaphoreTerminate(pExynosInputPort->codecSemID);
   1726     } else if (pExynosInputPort->bufferProcessType == BUFFER_SHARE) {
   1727         /*************/
   1728         /*    TBD    */
   1729         /*************/
   1730         /* Does not require any actions. */
   1731     }
   1732     Mpeg4CodecClose(pMpeg4Dec);
   1733 
   1734     Exynos_ResetAllPortConfig(pOMXComponent);
   1735 
   1736 EXIT:
   1737     FunctionOut();
   1738 
   1739     return ret;
   1740 }
   1741 
   1742 OMX_ERRORTYPE Exynos_Mpeg4Dec_SrcIn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcInputData)
   1743 {
   1744     OMX_ERRORTYPE               ret = OMX_ErrorNone;
   1745     EXYNOS_OMX_BASECOMPONENT      *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   1746     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
   1747     EXYNOS_MPEG4DEC_HANDLE         *pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
   1748     void                          *hMFCHandle = pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle;
   1749     EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
   1750     EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
   1751     OMX_U32  oneFrameSize = pSrcInputData->dataLen;
   1752     ExynosVideoDecOps       *pDecOps    = pMpeg4Dec->hMFCMpeg4Handle.pDecOps;
   1753     ExynosVideoDecBufferOps *pInbufOps  = pMpeg4Dec->hMFCMpeg4Handle.pInbufOps;
   1754     ExynosVideoDecBufferOps *pOutbufOps = pMpeg4Dec->hMFCMpeg4Handle.pOutbufOps;
   1755     ExynosVideoErrorType codecReturn = VIDEO_ERROR_NONE;
   1756     int i;
   1757 
   1758     FunctionIn();
   1759 
   1760     if (pMpeg4Dec->hMFCMpeg4Handle.bConfiguredMFCSrc == OMX_FALSE) {
   1761         ret = Mpeg4CodecSrcSetup(pOMXComponent, pSrcInputData);
   1762         goto EXIT;
   1763     }
   1764     if (pMpeg4Dec->hMFCMpeg4Handle.bConfiguredMFCDst == OMX_FALSE) {
   1765         ret = Mpeg4CodecDstSetup(pOMXComponent);
   1766     }
   1767 
   1768     if ((Check_Stream_StartCode(pSrcInputData->buffer.singlePlaneBuffer.dataBuffer, oneFrameSize, pMpeg4Dec->hMFCMpeg4Handle.codecType) == OMX_TRUE) ||
   1769         ((pSrcInputData->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS)) {
   1770         pExynosComponent->timeStamp[pMpeg4Dec->hMFCMpeg4Handle.indexTimestamp] = pSrcInputData->timeStamp;
   1771         pExynosComponent->nFlags[pMpeg4Dec->hMFCMpeg4Handle.indexTimestamp] = pSrcInputData->nFlags;
   1772         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "input timestamp %lld us (%.2f secs), Tag: %d, nFlags: 0x%x", pSrcInputData->timeStamp, pSrcInputData->timeStamp / 1E6, pMpeg4Dec->hMFCMpeg4Handle.indexTimestamp, pSrcInputData->nFlags);
   1773         pDecOps->Set_FrameTag(hMFCHandle, pMpeg4Dec->hMFCMpeg4Handle.indexTimestamp);
   1774         pMpeg4Dec->hMFCMpeg4Handle.indexTimestamp++;
   1775         pMpeg4Dec->hMFCMpeg4Handle.indexTimestamp %= MAX_TIMESTAMP;
   1776 
   1777         /* queue work for input buffer */
   1778         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "oneFrameSize: %d, bufferHeader: 0x%x, dataBuffer: 0x%x", oneFrameSize, pSrcInputData->bufferHeader, pSrcInputData->buffer.singlePlaneBuffer.dataBuffer);
   1779         codecReturn = pInbufOps->Enqueue(hMFCHandle, (unsigned char **)&pSrcInputData->buffer.singlePlaneBuffer.dataBuffer,
   1780                                     (unsigned int *)&oneFrameSize, MFC_INPUT_BUFFER_PLANE, pSrcInputData->bufferHeader);
   1781         if (codecReturn != VIDEO_ERROR_NONE) {
   1782             ret = (OMX_ERRORTYPE)OMX_ErrorCodecDecode;
   1783             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__);
   1784             goto EXIT;
   1785         }
   1786         Mpeg4CodecStart(pOMXComponent, INPUT_PORT_INDEX);
   1787         if (pMpeg4Dec->bSourceStart == OMX_FALSE) {
   1788             pMpeg4Dec->bSourceStart = OMX_TRUE;
   1789             Exynos_OSAL_SignalSet(pMpeg4Dec->hSourceStartEvent);
   1790             Exynos_OSAL_SleepMillisec(0);
   1791         }
   1792         if (pMpeg4Dec->bDestinationStart == OMX_FALSE) {
   1793             pMpeg4Dec->bDestinationStart = OMX_TRUE;
   1794             Exynos_OSAL_SignalSet(pMpeg4Dec->hDestinationStartEvent);
   1795             Exynos_OSAL_SleepMillisec(0);
   1796         }
   1797     }
   1798 
   1799     ret = OMX_ErrorNone;
   1800 
   1801 EXIT:
   1802     FunctionOut();
   1803 
   1804     return ret;
   1805 }
   1806 
   1807 OMX_ERRORTYPE Exynos_Mpeg4Dec_SrcOut(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcOutputData)
   1808 {
   1809     OMX_ERRORTYPE                  ret = OMX_ErrorNone;
   1810     EXYNOS_OMX_BASECOMPONENT      *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   1811     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
   1812     EXYNOS_MPEG4DEC_HANDLE         *pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
   1813     void                          *hMFCHandle = pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle;
   1814     EXYNOS_OMX_BASEPORT     *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
   1815     ExynosVideoDecOps       *pDecOps    = pMpeg4Dec->hMFCMpeg4Handle.pDecOps;
   1816     ExynosVideoDecBufferOps *pInbufOps  = pMpeg4Dec->hMFCMpeg4Handle.pInbufOps;
   1817     ExynosVideoBuffer       *pVideoBuffer;
   1818 
   1819     FunctionIn();
   1820 
   1821     pVideoBuffer = pInbufOps->Dequeue(hMFCHandle);
   1822 
   1823     pSrcOutputData->dataLen       = 0;
   1824     pSrcOutputData->usedDataLen   = 0;
   1825     pSrcOutputData->remainDataLen = 0;
   1826     pSrcOutputData->nFlags    = 0;
   1827     pSrcOutputData->timeStamp = 0;
   1828 
   1829     if (pVideoBuffer == NULL) {
   1830         pSrcOutputData->buffer.singlePlaneBuffer.dataBuffer = NULL;
   1831         pSrcOutputData->allocSize  = 0;
   1832         pSrcOutputData->pPrivate = NULL;
   1833         pSrcOutputData->bufferHeader = NULL;
   1834     } else {
   1835         pSrcOutputData->buffer.singlePlaneBuffer.dataBuffer = pVideoBuffer->planes[0].addr;
   1836         pSrcOutputData->buffer.singlePlaneBuffer.fd = pVideoBuffer->planes[0].fd;
   1837         pSrcOutputData->allocSize  = pVideoBuffer->planes[0].allocSize;
   1838 
   1839         if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) {
   1840             int i = 0;
   1841             while (pSrcOutputData->buffer.singlePlaneBuffer.dataBuffer != pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[0]) {
   1842                 if (i >= MFC_INPUT_BUFFER_NUM_MAX) {
   1843                     Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Can not find buffer");
   1844                     ret = (OMX_ERRORTYPE)OMX_ErrorCodecDecode;
   1845                     goto EXIT;
   1846                 }
   1847                 i++;
   1848             }
   1849             pVideoDec->pMFCDecInputBuffer[i]->dataSize = 0;
   1850             pSrcOutputData->pPrivate = pVideoDec->pMFCDecInputBuffer[i];
   1851         }
   1852 
   1853         /* For Share Buffer */
   1854         pSrcOutputData->bufferHeader = (OMX_BUFFERHEADERTYPE*)pVideoBuffer->pPrivate;
   1855     }
   1856 
   1857     ret = OMX_ErrorNone;
   1858 
   1859 EXIT:
   1860     FunctionOut();
   1861 
   1862     return ret;
   1863 }
   1864 
   1865 OMX_ERRORTYPE Exynos_Mpeg4Dec_DstIn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pDstInputData)
   1866 {
   1867     OMX_ERRORTYPE                  ret = OMX_ErrorNone;
   1868     EXYNOS_OMX_BASECOMPONENT      *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   1869     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
   1870     EXYNOS_MPEG4DEC_HANDLE         *pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
   1871     void                          *hMFCHandle = pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle;
   1872     EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
   1873     ExynosVideoDecOps       *pDecOps    = pMpeg4Dec->hMFCMpeg4Handle.pDecOps;
   1874     ExynosVideoDecBufferOps *pOutbufOps = pMpeg4Dec->hMFCMpeg4Handle.pOutbufOps;
   1875     OMX_U32 dataLen[MFC_OUTPUT_BUFFER_PLANE] = {0,};
   1876     ExynosVideoErrorType codecReturn = VIDEO_ERROR_NONE;
   1877 
   1878     FunctionIn();
   1879 
   1880     if (pDstInputData->buffer.multiPlaneBuffer.dataBuffer[0] == NULL) {
   1881         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to find input buffer");
   1882         ret = OMX_ErrorBadParameter;
   1883         goto EXIT;
   1884     }
   1885 
   1886     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s : %d => ADDR[0]: 0x%x, ADDR[1]: 0x%x, FD[0]:%d, FD[1]:%d", __FUNCTION__, __LINE__,
   1887                                         pDstInputData->buffer.multiPlaneBuffer.dataBuffer[0],
   1888                                         pDstInputData->buffer.multiPlaneBuffer.dataBuffer[1],
   1889                                         pDstInputData->buffer.multiPlaneBuffer.fd[0],
   1890                                         pDstInputData->buffer.multiPlaneBuffer.fd[1]);
   1891 
   1892     OMX_U32 nAllocLen[VIDEO_BUFFER_MAX_PLANES] = {0, 0, 0};
   1893     nAllocLen[0] = pExynosOutputPort->portDefinition.format.video.nFrameWidth * pExynosOutputPort->portDefinition.format.video.nFrameHeight;
   1894     nAllocLen[1] = pExynosOutputPort->portDefinition.format.video.nFrameWidth * pExynosOutputPort->portDefinition.format.video.nFrameHeight / 2;
   1895 
   1896     codecReturn = pOutbufOps->ExtensionEnqueue(hMFCHandle,
   1897                                 (unsigned char **)pDstInputData->buffer.multiPlaneBuffer.dataBuffer,
   1898                                 (unsigned int **)pDstInputData->buffer.multiPlaneBuffer.fd,
   1899                                 (unsigned int *)nAllocLen, (unsigned int *)dataLen,
   1900                                 MFC_OUTPUT_BUFFER_PLANE, pDstInputData->bufferHeader);
   1901     if (codecReturn != VIDEO_ERROR_NONE) {
   1902         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__);
   1903         ret = (OMX_ERRORTYPE)OMX_ErrorCodecDecode;
   1904         goto EXIT;
   1905     }
   1906     Mpeg4CodecStart(pOMXComponent, OUTPUT_PORT_INDEX);
   1907 
   1908     ret = OMX_ErrorNone;
   1909 
   1910 EXIT:
   1911     FunctionOut();
   1912 
   1913     return ret;
   1914 }
   1915 
   1916 OMX_ERRORTYPE Exynos_Mpeg4Dec_DstOut(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pDstOutputData)
   1917 {
   1918     OMX_ERRORTYPE                  ret = OMX_ErrorNone;
   1919     EXYNOS_OMX_BASECOMPONENT      *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   1920     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
   1921     EXYNOS_MPEG4DEC_HANDLE         *pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
   1922     void                          *hMFCHandle = pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle;
   1923     EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
   1924     EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
   1925     ExynosVideoDecOps       *pDecOps    = pMpeg4Dec->hMFCMpeg4Handle.pDecOps;
   1926     ExynosVideoDecBufferOps *pOutbufOps = pMpeg4Dec->hMFCMpeg4Handle.pOutbufOps;
   1927     ExynosVideoBuffer       *pVideoBuffer;
   1928     ExynosVideoBuffer        videoBuffer;
   1929     ExynosVideoFrameStatusType displayStatus = VIDEO_FRAME_STATUS_UNKNOWN;
   1930     ExynosVideoGeometry *bufferGeometry;
   1931     DECODE_CODEC_EXTRA_BUFFERINFO *pBufferInfo = NULL;
   1932     OMX_S32 indexTimestamp = 0;
   1933     int plane;
   1934 
   1935     FunctionIn();
   1936 
   1937     if (pMpeg4Dec->bDestinationStart == OMX_FALSE) {
   1938         ret = OMX_ErrorNone;
   1939         goto EXIT;
   1940     }
   1941 
   1942     while (1) {
   1943         Exynos_OSAL_Memset(&videoBuffer, 0, sizeof(ExynosVideoBuffer));
   1944         if (pOutbufOps->ExtensionDequeue(hMFCHandle, &videoBuffer) == VIDEO_ERROR_NONE) {
   1945             pVideoBuffer = &videoBuffer;
   1946         } else {
   1947             pVideoBuffer = NULL;
   1948             ret = OMX_ErrorNone;
   1949             goto EXIT;
   1950         }
   1951         displayStatus = pVideoBuffer->displayStatus;
   1952         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "displayStatus: 0x%x", displayStatus);
   1953 
   1954         if ((displayStatus == VIDEO_FRAME_STATUS_DISPLAY_DECODING) ||
   1955             (displayStatus == VIDEO_FRAME_STATUS_DISPLAY_ONLY) ||
   1956             (displayStatus == VIDEO_FRAME_STATUS_CHANGE_RESOL) ||
   1957             (displayStatus == VIDEO_FRAME_STATUS_DECODING_FINISHED) ||
   1958             (CHECK_PORT_BEING_FLUSHED(pExynosOutputPort))) {
   1959             if (pVideoBuffer != NULL) {
   1960                 ret = OMX_ErrorNone;
   1961                 break;
   1962             } else {
   1963                 ret = OMX_ErrorUndefined;
   1964                 break;
   1965             }
   1966         }
   1967     }
   1968 
   1969     if (ret != OMX_ErrorNone)
   1970         goto EXIT;
   1971 
   1972     pMpeg4Dec->hMFCMpeg4Handle.outputIndexTimestamp++;
   1973     pMpeg4Dec->hMFCMpeg4Handle.outputIndexTimestamp %= MAX_TIMESTAMP;
   1974 
   1975     pDstOutputData->allocSize = pDstOutputData->dataLen = 0;
   1976     for (plane = 0; plane < MFC_OUTPUT_BUFFER_PLANE; plane++) {
   1977         pDstOutputData->buffer.multiPlaneBuffer.dataBuffer[plane] = pVideoBuffer->planes[plane].addr;
   1978         pDstOutputData->buffer.multiPlaneBuffer.fd[plane] = pVideoBuffer->planes[plane].fd;
   1979         pDstOutputData->allocSize += pVideoBuffer->planes[plane].allocSize;
   1980         pDstOutputData->dataLen +=  pVideoBuffer->planes[plane].dataSize;
   1981     }
   1982     pDstOutputData->usedDataLen = 0;
   1983     pDstOutputData->pPrivate = pVideoBuffer;
   1984     if (pExynosOutputPort->bufferProcessType & BUFFER_COPY) {
   1985         int i = 0;
   1986         pDstOutputData->pPrivate = NULL;
   1987         for (i = 0; i < MFC_OUTPUT_BUFFER_NUM_MAX; i++) {
   1988             if (pDstOutputData->buffer.multiPlaneBuffer.dataBuffer[0] ==
   1989                 pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[0]) {
   1990                 pDstOutputData->pPrivate = pVideoDec->pMFCDecOutputBuffer[i];
   1991                 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s : %d => ADDR[0]: 0x%x, ADDR[1]: 0x%x, FD[0]:%d, FD[1]:%d", __FUNCTION__, __LINE__,
   1992                                     pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[0],
   1993                                     pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[1],
   1994                                     pVideoDec->pMFCDecOutputBuffer[i]->fd[0],
   1995                                     pVideoDec->pMFCDecOutputBuffer[i]->fd[1]);
   1996                 break;
   1997             }
   1998         }
   1999 
   2000         if (pDstOutputData->pPrivate == NULL) {
   2001             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Can not find buffer");
   2002             ret = (OMX_ERRORTYPE)OMX_ErrorCodecDecode;
   2003             goto EXIT;
   2004         }
   2005     }
   2006     /* For Share Buffer */
   2007     pDstOutputData->bufferHeader = (OMX_BUFFERHEADERTYPE *)pVideoBuffer->pPrivate;
   2008 
   2009     pBufferInfo = (DECODE_CODEC_EXTRA_BUFFERINFO *)pDstOutputData->extInfo;
   2010     bufferGeometry = &pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf;
   2011     pBufferInfo->imageWidth = bufferGeometry->nFrameWidth;
   2012     pBufferInfo->imageHeight = bufferGeometry->nFrameHeight;
   2013     Exynos_OSAL_Memcpy(&pBufferInfo->PDSB, &pVideoBuffer->PDSB, sizeof(PrivateDataShareBuffer));
   2014     switch (bufferGeometry->eColorFormat) {
   2015     case VIDEO_COLORFORMAT_NV12:
   2016         pBufferInfo->ColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
   2017         break;
   2018     case VIDEO_COLORFORMAT_NV12_TILED:
   2019     default:
   2020         pBufferInfo->ColorFormat = OMX_SEC_COLOR_FormatNV12Tiled;
   2021         break;
   2022     }
   2023 
   2024     indexTimestamp = pDecOps->Get_FrameTag(hMFCHandle);
   2025     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "out indexTimestamp: %d", indexTimestamp);
   2026     if ((indexTimestamp < 0) || (indexTimestamp >= MAX_TIMESTAMP)) {
   2027         if ((pExynosComponent->checkTimeStamp.needSetStartTimeStamp != OMX_TRUE) &&
   2028             (pExynosComponent->checkTimeStamp.needCheckStartTimeStamp != OMX_TRUE)) {
   2029             pDstOutputData->timeStamp = pExynosComponent->timeStamp[pMpeg4Dec->hMFCMpeg4Handle.outputIndexTimestamp];
   2030             pDstOutputData->nFlags = pExynosComponent->nFlags[pMpeg4Dec->hMFCMpeg4Handle.outputIndexTimestamp];
   2031             Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "missing out indexTimestamp: %d", indexTimestamp);
   2032         } else {
   2033             pDstOutputData->timeStamp = 0x00;
   2034             pDstOutputData->nFlags = 0x00;
   2035         }
   2036     } else {
   2037         /* For timestamp correction. if mfc support frametype detect */
   2038         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "disp_pic_frame_type: %d", pVideoBuffer->frameType);
   2039 #ifdef NEED_TIMESTAMP_REORDER
   2040         if ((pVideoBuffer->frameType == VIDEO_FRAME_I)) {
   2041             pDstOutputData->timeStamp = pExynosComponent->timeStamp[indexTimestamp];
   2042             pDstOutputData->nFlags = pExynosComponent->nFlags[indexTimestamp];
   2043             pMpeg4Dec->hMFCMpeg4Handle.outputIndexTimestamp = indexTimestamp;
   2044         } else {
   2045             pDstOutputData->timeStamp = pExynosComponent->timeStamp[pMpeg4Dec->hMFCMpeg4Handle.outputIndexTimestamp];
   2046             pDstOutputData->nFlags = pExynosComponent->nFlags[pMpeg4Dec->hMFCMpeg4Handle.outputIndexTimestamp];
   2047         }
   2048 #else
   2049         pDstOutputData->timeStamp = pExynosComponent->timeStamp[indexTimestamp];
   2050         pDstOutputData->nFlags = pExynosComponent->nFlags[indexTimestamp];
   2051 #endif
   2052         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "timestamp %lld us (%.2f secs), indexTimestamp: %d, nFlags: 0x%x", pDstOutputData->timeStamp, pDstOutputData->timeStamp / 1E6, indexTimestamp, pDstOutputData->nFlags);
   2053     }
   2054 
   2055     if ((displayStatus == VIDEO_FRAME_STATUS_CHANGE_RESOL) ||
   2056         (displayStatus == VIDEO_FRAME_STATUS_DECODING_FINISHED) ||
   2057         ((pDstOutputData->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS)) {
   2058         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "displayStatus:%d, nFlags0x%x", displayStatus, pDstOutputData->nFlags);
   2059         pDstOutputData->remainDataLen = 0;
   2060         if (((pDstOutputData->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) &&
   2061             (pExynosComponent->bBehaviorEOS == OMX_TRUE)) {
   2062             pDstOutputData->remainDataLen = bufferGeometry->nFrameWidth * bufferGeometry->nFrameHeight * 3 / 2;
   2063             pExynosComponent->bBehaviorEOS = OMX_FALSE;
   2064         }
   2065     } else {
   2066         pDstOutputData->remainDataLen = bufferGeometry->nFrameWidth * bufferGeometry->nFrameHeight * 3 / 2;
   2067     }
   2068 
   2069     ret = OMX_ErrorNone;
   2070 
   2071 EXIT:
   2072     FunctionOut();
   2073 
   2074     return ret;
   2075 }
   2076 
   2077 OMX_ERRORTYPE Exynos_Mpeg4Dec_srcInputBufferProcess(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcInputData)
   2078 {
   2079     OMX_ERRORTYPE             ret = OMX_ErrorNone;
   2080     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   2081     EXYNOS_MPEG4DEC_HANDLE    *pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
   2082     EXYNOS_OMX_BASEPORT      *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
   2083 
   2084     FunctionIn();
   2085 
   2086     if ((!CHECK_PORT_ENABLED(pExynosInputPort)) || (!CHECK_PORT_POPULATED(pExynosInputPort))) {
   2087         ret = OMX_ErrorNone;
   2088         goto EXIT;
   2089     }
   2090     if (OMX_FALSE == Exynos_Check_BufferProcess_State(pExynosComponent, INPUT_PORT_INDEX)) {
   2091         ret = OMX_ErrorNone;
   2092         goto EXIT;
   2093     }
   2094 
   2095     ret = Exynos_Mpeg4Dec_SrcIn(pOMXComponent, pSrcInputData);
   2096     if ((ret != OMX_ErrorNone) && (ret != OMX_ErrorInputDataDecodeYet)) {
   2097         pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent,
   2098                                                 pExynosComponent->callbackData,
   2099                                                 OMX_EventError, ret, 0, NULL);
   2100     }
   2101 
   2102 EXIT:
   2103     FunctionOut();
   2104 
   2105     return ret;
   2106 }
   2107 
   2108 OMX_ERRORTYPE Exynos_Mpeg4Dec_srcOutputBufferProcess(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcOutputData)
   2109 {
   2110     OMX_ERRORTYPE             ret = OMX_ErrorNone;
   2111     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   2112     EXYNOS_MPEG4DEC_HANDLE   *pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
   2113     EXYNOS_OMX_BASEPORT     *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
   2114 
   2115     FunctionIn();
   2116 
   2117     if ((!CHECK_PORT_ENABLED(pExynosInputPort)) || (!CHECK_PORT_POPULATED(pExynosInputPort))) {
   2118         ret = OMX_ErrorNone;
   2119         goto EXIT;
   2120     }
   2121 
   2122     if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) {
   2123         if (OMX_FALSE == Exynos_Check_BufferProcess_State(pExynosComponent, INPUT_PORT_INDEX)) {
   2124             ret = OMX_ErrorNone;
   2125             goto EXIT;
   2126         }
   2127     }
   2128     if ((pMpeg4Dec->bSourceStart == OMX_FALSE) &&
   2129        (!CHECK_PORT_BEING_FLUSHED(pExynosInputPort))) {
   2130         Exynos_OSAL_SignalWait(pMpeg4Dec->hSourceStartEvent, DEF_MAX_WAIT_TIME);
   2131         Exynos_OSAL_SignalReset(pMpeg4Dec->hSourceStartEvent);
   2132     }
   2133 
   2134     ret = Exynos_Mpeg4Dec_SrcOut(pOMXComponent, pSrcOutputData);
   2135     if ((ret != OMX_ErrorNone) &&
   2136         (pExynosComponent->currentState == OMX_StateExecuting)) {
   2137         pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent,
   2138                                                 pExynosComponent->callbackData,
   2139                                                 OMX_EventError, ret, 0, NULL);
   2140     }
   2141 
   2142 EXIT:
   2143     FunctionOut();
   2144 
   2145     return ret;
   2146 }
   2147 
   2148 OMX_ERRORTYPE Exynos_Mpeg4Dec_dstInputBufferProcess(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pDstInputData)
   2149 {
   2150     OMX_ERRORTYPE             ret = OMX_ErrorNone;
   2151     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   2152     EXYNOS_MPEG4DEC_HANDLE    *pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
   2153     EXYNOS_OMX_BASEPORT      *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
   2154 
   2155     FunctionIn();
   2156 
   2157     if ((!CHECK_PORT_ENABLED(pExynosOutputPort)) || (!CHECK_PORT_POPULATED(pExynosOutputPort))) {
   2158         ret = OMX_ErrorNone;
   2159         goto EXIT;
   2160     }
   2161     if (OMX_FALSE == Exynos_Check_BufferProcess_State(pExynosComponent, OUTPUT_PORT_INDEX)) {
   2162         ret = OMX_ErrorNone;
   2163         goto EXIT;
   2164     }
   2165     if (pExynosOutputPort->bufferProcessType == BUFFER_SHARE) {
   2166         if ((pMpeg4Dec->bDestinationStart == OMX_FALSE) &&
   2167            (!CHECK_PORT_BEING_FLUSHED(pExynosOutputPort))) {
   2168             Exynos_OSAL_SignalWait(pMpeg4Dec->hDestinationStartEvent, DEF_MAX_WAIT_TIME);
   2169             Exynos_OSAL_SignalReset(pMpeg4Dec->hDestinationStartEvent);
   2170         }
   2171     }
   2172     if (pMpeg4Dec->hMFCMpeg4Handle.bConfiguredMFCDst == OMX_TRUE) {
   2173         ret = Exynos_Mpeg4Dec_DstIn(pOMXComponent, pDstInputData);
   2174         if (ret != OMX_ErrorNone) {
   2175             pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent,
   2176                                                 pExynosComponent->callbackData,
   2177                                                 OMX_EventError, ret, 0, NULL);
   2178         }
   2179     }
   2180 
   2181 EXIT:
   2182     FunctionOut();
   2183 
   2184     return ret;
   2185 }
   2186 
   2187 OMX_ERRORTYPE Exynos_Mpeg4Dec_dstOutputBufferProcess(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pDstOutputData)
   2188 {
   2189     OMX_ERRORTYPE             ret = OMX_ErrorNone;
   2190     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   2191     EXYNOS_MPEG4DEC_HANDLE   *pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
   2192     EXYNOS_OMX_BASEPORT     *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
   2193 
   2194     FunctionIn();
   2195 
   2196     if ((!CHECK_PORT_ENABLED(pExynosOutputPort)) || (!CHECK_PORT_POPULATED(pExynosOutputPort))) {
   2197         ret = OMX_ErrorNone;
   2198         goto EXIT;
   2199     }
   2200     if (OMX_FALSE == Exynos_Check_BufferProcess_State(pExynosComponent, OUTPUT_PORT_INDEX)) {
   2201         ret = OMX_ErrorNone;
   2202         goto EXIT;
   2203     }
   2204 
   2205     if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) {
   2206         if ((pMpeg4Dec->bDestinationStart == OMX_FALSE) &&
   2207             (!CHECK_PORT_BEING_FLUSHED(pExynosOutputPort))) {
   2208             Exynos_OSAL_SignalWait(pMpeg4Dec->hDestinationStartEvent, DEF_MAX_WAIT_TIME);
   2209             Exynos_OSAL_SignalReset(pMpeg4Dec->hDestinationStartEvent);
   2210         }
   2211     }
   2212     ret = Exynos_Mpeg4Dec_DstOut(pOMXComponent, pDstOutputData);
   2213     if ((ret != OMX_ErrorNone) &&
   2214         (pExynosComponent->currentState == OMX_StateExecuting)) {
   2215         pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent,
   2216                                                 pExynosComponent->callbackData,
   2217                                                 OMX_EventError, ret, 0, NULL);
   2218     }
   2219 
   2220 EXIT:
   2221     FunctionOut();
   2222 
   2223     return ret;
   2224 }
   2225 
   2226 OSCL_EXPORT_REF OMX_ERRORTYPE Exynos_OMX_ComponentInit(OMX_HANDLETYPE hComponent, OMX_STRING componentName)
   2227 {
   2228     OMX_ERRORTYPE                  ret              = OMX_ErrorNone;
   2229     OMX_COMPONENTTYPE             *pOMXComponent    = NULL;
   2230     EXYNOS_OMX_BASECOMPONENT      *pExynosComponent = NULL;
   2231     EXYNOS_OMX_BASEPORT           *pExynosPort      = NULL;
   2232     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec        = NULL;
   2233     EXYNOS_MPEG4DEC_HANDLE        *pMpeg4Dec        = NULL;
   2234     int i = 0;
   2235     OMX_S32 codecType = -1;
   2236 
   2237     FunctionIn();
   2238 
   2239     if ((hComponent == NULL) || (componentName == NULL)) {
   2240         ret = OMX_ErrorBadParameter;
   2241         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorBadParameter, Line:%d", __LINE__);
   2242         goto EXIT;
   2243     }
   2244     if (Exynos_OSAL_Strcmp(EXYNOS_OMX_COMPONENT_MPEG4_DEC, componentName) == 0) {
   2245         codecType = CODEC_TYPE_MPEG4;
   2246     } else if (Exynos_OSAL_Strcmp(EXYNOS_OMX_COMPONENT_H263_DEC, componentName) == 0) {
   2247         codecType = CODEC_TYPE_H263;
   2248     } else {
   2249         ret = OMX_ErrorBadParameter;
   2250         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorBadParameter, componentName:%s, Line:%d", componentName, __LINE__);
   2251         goto EXIT;
   2252     }
   2253 
   2254     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
   2255     ret = Exynos_OMX_VideoDecodeComponentInit(pOMXComponent);
   2256     if (ret != OMX_ErrorNone) {
   2257         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_Error, Line:%d", __LINE__);
   2258         goto EXIT;
   2259     }
   2260     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   2261     pExynosComponent->codecType = HW_VIDEO_DEC_CODEC;
   2262 
   2263     pExynosComponent->componentName = (OMX_STRING)Exynos_OSAL_Malloc(MAX_OMX_COMPONENT_NAME_SIZE);
   2264     if (pExynosComponent->componentName == NULL) {
   2265         Exynos_OMX_VideoDecodeComponentDeinit(pOMXComponent);
   2266         ret = OMX_ErrorInsufficientResources;
   2267         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__);
   2268         goto EXIT;
   2269     }
   2270     Exynos_OSAL_Memset(pExynosComponent->componentName, 0, MAX_OMX_COMPONENT_NAME_SIZE);
   2271 
   2272     pMpeg4Dec = Exynos_OSAL_Malloc(sizeof(EXYNOS_MPEG4DEC_HANDLE));
   2273     if (pMpeg4Dec == NULL) {
   2274         Exynos_OMX_VideoDecodeComponentDeinit(pOMXComponent);
   2275         ret = OMX_ErrorInsufficientResources;
   2276         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__);
   2277         goto EXIT;
   2278     }
   2279     Exynos_OSAL_Memset(pMpeg4Dec, 0, sizeof(EXYNOS_MPEG4DEC_HANDLE));
   2280     pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
   2281     pVideoDec->hCodecHandle = (OMX_HANDLETYPE)pMpeg4Dec;
   2282     pMpeg4Dec->hMFCMpeg4Handle.codecType = codecType;
   2283 
   2284     if (codecType == CODEC_TYPE_MPEG4)
   2285         Exynos_OSAL_Strcpy(pExynosComponent->componentName, EXYNOS_OMX_COMPONENT_MPEG4_DEC);
   2286     else
   2287         Exynos_OSAL_Strcpy(pExynosComponent->componentName, EXYNOS_OMX_COMPONENT_H263_DEC);
   2288 
   2289     /* Set componentVersion */
   2290     pExynosComponent->componentVersion.s.nVersionMajor = VERSIONMAJOR_NUMBER;
   2291     pExynosComponent->componentVersion.s.nVersionMinor = VERSIONMINOR_NUMBER;
   2292     pExynosComponent->componentVersion.s.nRevision     = REVISION_NUMBER;
   2293     pExynosComponent->componentVersion.s.nStep         = STEP_NUMBER;
   2294     /* Set specVersion */
   2295     pExynosComponent->specVersion.s.nVersionMajor = VERSIONMAJOR_NUMBER;
   2296     pExynosComponent->specVersion.s.nVersionMinor = VERSIONMINOR_NUMBER;
   2297     pExynosComponent->specVersion.s.nRevision     = REVISION_NUMBER;
   2298     pExynosComponent->specVersion.s.nStep         = STEP_NUMBER;
   2299 
   2300     /* Input port */
   2301     pExynosPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
   2302     pExynosPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH;
   2303     pExynosPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT;
   2304     pExynosPort->portDefinition.format.video.nStride = 0; /*DEFAULT_FRAME_WIDTH;*/
   2305     pExynosPort->portDefinition.format.video.nSliceHeight = 0;
   2306     pExynosPort->portDefinition.nBufferSize = DEFAULT_VIDEO_INPUT_BUFFER_SIZE;
   2307     if (codecType == CODEC_TYPE_MPEG4) {
   2308         pExynosPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4;
   2309         Exynos_OSAL_Memset(pExynosPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE);
   2310         Exynos_OSAL_Strcpy(pExynosPort->portDefinition.format.video.cMIMEType, "video/mpeg4");
   2311     } else {
   2312         pExynosPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingH263;
   2313         Exynos_OSAL_Memset(pExynosPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE);
   2314         Exynos_OSAL_Strcpy(pExynosPort->portDefinition.format.video.cMIMEType, "video/h263");
   2315     }
   2316     pExynosPort->portDefinition.format.video.pNativeRender = 0;
   2317     pExynosPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE;
   2318     pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatUnused;
   2319     pExynosPort->portDefinition.bEnabled = OMX_TRUE;
   2320     pExynosPort->bufferProcessType = BUFFER_SHARE;
   2321     pExynosPort->portWayType = WAY2_PORT;
   2322 
   2323     /* Output port */
   2324     pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
   2325     pExynosPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH;
   2326     pExynosPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT;
   2327     pExynosPort->portDefinition.format.video.nStride = 0; /*DEFAULT_FRAME_WIDTH;*/
   2328     pExynosPort->portDefinition.format.video.nSliceHeight = 0;
   2329     pExynosPort->portDefinition.nBufferSize = DEFAULT_VIDEO_OUTPUT_BUFFER_SIZE;
   2330     pExynosPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
   2331     Exynos_OSAL_Memset(pExynosPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE);
   2332     Exynos_OSAL_Strcpy(pExynosPort->portDefinition.format.video.cMIMEType, "raw/video");
   2333     pExynosPort->portDefinition.format.video.pNativeRender = 0;
   2334     pExynosPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE;
   2335     pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420Planar;
   2336     pExynosPort->portDefinition.bEnabled = OMX_TRUE;
   2337     pExynosPort->bufferProcessType = BUFFER_COPY | BUFFER_ANBSHARE;
   2338     pExynosPort->portWayType = WAY2_PORT;
   2339 
   2340     if (codecType == CODEC_TYPE_MPEG4) {
   2341         for(i = 0; i < ALL_PORT_NUM; i++) {
   2342             INIT_SET_SIZE_VERSION(&pMpeg4Dec->mpeg4Component[i], OMX_VIDEO_PARAM_MPEG4TYPE);
   2343             pMpeg4Dec->mpeg4Component[i].nPortIndex = i;
   2344             pMpeg4Dec->mpeg4Component[i].eProfile   = OMX_VIDEO_MPEG4ProfileSimple;
   2345             pMpeg4Dec->mpeg4Component[i].eLevel     = OMX_VIDEO_MPEG4Level3;
   2346         }
   2347     } else {
   2348         for(i = 0; i < ALL_PORT_NUM; i++) {
   2349             INIT_SET_SIZE_VERSION(&pMpeg4Dec->h263Component[i], OMX_VIDEO_PARAM_H263TYPE);
   2350             pMpeg4Dec->h263Component[i].nPortIndex = i;
   2351             pMpeg4Dec->h263Component[i].eProfile   = OMX_VIDEO_H263ProfileBaseline | OMX_VIDEO_H263ProfileISWV2;
   2352             pMpeg4Dec->h263Component[i].eLevel     = OMX_VIDEO_H263Level45;
   2353         }
   2354     }
   2355 
   2356     pOMXComponent->GetParameter      = &Exynos_Mpeg4Dec_GetParameter;
   2357     pOMXComponent->SetParameter      = &Exynos_Mpeg4Dec_SetParameter;
   2358     pOMXComponent->GetConfig         = &Exynos_Mpeg4Dec_GetConfig;
   2359     pOMXComponent->SetConfig         = &Exynos_Mpeg4Dec_SetConfig;
   2360     pOMXComponent->GetExtensionIndex = &Exynos_Mpeg4Dec_GetExtensionIndex;
   2361     pOMXComponent->ComponentRoleEnum = &Exynos_Mpeg4Dec_ComponentRoleEnum;
   2362     pOMXComponent->ComponentDeInit   = &Exynos_OMX_ComponentDeinit;
   2363 
   2364     pExynosComponent->exynos_codec_componentInit      = &Exynos_Mpeg4Dec_Init;
   2365     pExynosComponent->exynos_codec_componentTerminate = &Exynos_Mpeg4Dec_Terminate;
   2366 
   2367     pVideoDec->exynos_codec_srcInputProcess  = &Exynos_Mpeg4Dec_srcInputBufferProcess;
   2368     pVideoDec->exynos_codec_srcOutputProcess = &Exynos_Mpeg4Dec_srcOutputBufferProcess;
   2369     pVideoDec->exynos_codec_dstInputProcess  = &Exynos_Mpeg4Dec_dstInputBufferProcess;
   2370     pVideoDec->exynos_codec_dstOutputProcess = &Exynos_Mpeg4Dec_dstOutputBufferProcess;
   2371 
   2372     pVideoDec->exynos_codec_start            = &Mpeg4CodecStart;
   2373     pVideoDec->exynos_codec_stop             = &Mpeg4CodecStop;
   2374     pVideoDec->exynos_codec_bufferProcessRun = &Mpeg4CodecOutputBufferProcessRun;
   2375     pVideoDec->exynos_codec_enqueueAllBuffer = &Mpeg4CodecEnQueueAllBuffer;
   2376 
   2377     if (codecType == CODEC_TYPE_MPEG4)
   2378         pVideoDec->exynos_checkInputFrame = &Check_Mpeg4_Frame;
   2379     else
   2380         pVideoDec->exynos_checkInputFrame = &Check_H263_Frame;
   2381 
   2382     pVideoDec->exynos_codec_getCodecInputPrivateData  = &GetCodecInputPrivateData;
   2383     pVideoDec->exynos_codec_getCodecOutputPrivateData = &GetCodecOutputPrivateData;
   2384 
   2385     pVideoDec->hSharedMemory = Exynos_OSAL_SharedMemory_Open();
   2386     if (pVideoDec->hSharedMemory == NULL) {
   2387         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__);
   2388         Exynos_OSAL_Free(pMpeg4Dec);
   2389         pMpeg4Dec = ((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle = NULL;
   2390         Exynos_OMX_VideoDecodeComponentDeinit(pOMXComponent);
   2391         ret = OMX_ErrorInsufficientResources;
   2392         goto EXIT;
   2393     }
   2394 
   2395     pExynosComponent->currentState = OMX_StateLoaded;
   2396 
   2397     ret = OMX_ErrorNone;
   2398 
   2399 EXIT:
   2400     FunctionOut();
   2401 
   2402     return ret;
   2403 }
   2404 
   2405 OMX_ERRORTYPE Exynos_OMX_ComponentDeinit(OMX_HANDLETYPE hComponent)
   2406 {
   2407     OMX_ERRORTYPE            ret = OMX_ErrorNone;
   2408     OMX_COMPONENTTYPE       *pOMXComponent = NULL;
   2409     EXYNOS_OMX_BASECOMPONENT   *pExynosComponent = NULL;
   2410     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
   2411     EXYNOS_MPEG4DEC_HANDLE      *pMpeg4Dec = NULL;
   2412 
   2413     FunctionIn();
   2414 
   2415     if (hComponent == NULL) {
   2416         ret = OMX_ErrorBadParameter;
   2417         goto EXIT;
   2418     }
   2419     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
   2420     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   2421     pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
   2422 
   2423     Exynos_OSAL_SharedMemory_Close(pVideoDec->hSharedMemory);
   2424 
   2425     Exynos_OSAL_Free(pExynosComponent->componentName);
   2426     pExynosComponent->componentName = NULL;
   2427 
   2428     pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)pVideoDec->hCodecHandle;
   2429     if (pMpeg4Dec != NULL) {
   2430         Exynos_OSAL_Free(pMpeg4Dec);
   2431         pMpeg4Dec = pVideoDec->hCodecHandle = NULL;
   2432     }
   2433 
   2434     ret = Exynos_OMX_VideoDecodeComponentDeinit(pOMXComponent);
   2435     if (ret != OMX_ErrorNone) {
   2436         goto EXIT;
   2437     }
   2438 
   2439     ret = OMX_ErrorNone;
   2440 
   2441 EXIT:
   2442     FunctionOut();
   2443 
   2444     return ret;
   2445 }
   2446