Home | History | Annotate | Download | only in src
      1 
      2 /*
      3  * Copyright (C) Texas Instruments - http://www.ti.com/
      4  *
      5  * This library is free software; you can redistribute it and/or
      6  * modify it under the terms of the GNU Lesser General Public
      7  * License as published by the Free Software Foundation; either
      8  * version 2.1 of the License, or (at your option) any later version.
      9  *
     10  *
     11  * This library is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14  * Lesser General Public License for more details.
     15  *
     16  *
     17  * You should have received a copy of the GNU Lesser General Public
     18  * License along with this library; if not, write to the Free Software
     19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
     20  */
     21 /* =============================================================================
     22 *             Texas Instruments OMAP (TM) Platform Software
     23 *  (c) Copyright Texas Instruments, Incorporated.  All Rights Reserved.
     24 *
     25 *  Use of this software is controlled by the terms and conditions found
     26 *  in the license agreement under which this software has been supplied.
     27 * ============================================================================*/
     28 /**
     29 * @file OMX_Video_Decoder.c
     30 *
     31 * This file implements OMX Component for video decoder that
     32 * is fully compliant with the OMX specification 1.0
     33 *
     34 * @path  $(CSLPATH)\
     35 *
     36 * @rev  0.1
     37 */
     38 /* ----------------------------------------------------------------------------
     39 *!
     40 *! Revision History
     41 *! ===================================
     42 *! 24-July-2005 mf:  Initial Version. Change required per OMAPSWxxxxxxxxx
     43 *! to provide _________________.
     44 *!
     45 * ============================================================================*/
     46 
     47 /* ------compilation control switches ----------------------------------------*/
     48 /*******************************************************************************
     49 *  INCLUDE FILES
     50 *******************************************************************************/
     51 /* ----- system and platform files -------------------------------------------*/
     52 #ifdef UNDER_CE
     53 #include <windows.h>
     54 #include <oaf_osal.h>
     55 #include <omx_core.h>
     56 #else
     57 #include <wchar.h>
     58 #include <unistd.h>
     59 #include <sys/time.h>
     60 #include <sys/types.h>
     61 #include <sys/ioctl.h>
     62 #include <sys/select.h>
     63 #include <errno.h>
     64 #include <pthread.h>
     65 #endif
     66 
     67 #include <string.h>
     68 #include <fcntl.h>
     69 #include <stdlib.h>
     70 #include <stdio.h>
     71 #include <dbapi.h>
     72 #include <OMX_Component.h>
     73 #include "OMX_VideoDecoder.h"
     74 #include "OMX_VideoDec_Utils.h"
     75 #include "OMX_VideoDec_DSP.h"
     76 #include "OMX_VideoDec_Thread.h"
     77 #include "OMX_VidDec_CustomCmd.h"
     78 
     79 /* For PPM fps measurements */
     80 static int mDebugFps = 0;
     81 
     82 #ifdef RESOURCE_MANAGER_ENABLED
     83 /*#ifndef UNDER_CE*/
     84 #include <ResourceManagerProxyAPI.h>
     85 /*#endif*/
     86 #endif
     87 
     88 /*******************************************************************************
     89 *  EXTERNAL REFERENCES NOTE : only use if not found in header file
     90 *******************************************************************************/
     91 /*--------data declarations --------------------------------------------------*/
     92 
     93 /*--------function prototypes ------------------------------------------------*/
     94 extern OMX_ERRORTYPE VIDDEC_Start_ComponentThread(OMX_HANDLETYPE pHandle);
     95 extern OMX_ERRORTYPE VIDDEC_Stop_ComponentThread(OMX_HANDLETYPE pComponent);
     96 /*extern OMX_ERRORTYPE VIDDEC_HandleCommandMarkBuffer(VIDDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 nParam1, OMX_PTR pCmdData);
     97 extern OMX_ERRORTYPE VIDDEC_HandleCommandFlush(VIDDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 nParam1, OMX_PTR pCmdData);*/
     98 extern OMX_ERRORTYPE VIDDEC_Load_Defaults (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_S32 nPassing);
     99 extern OMX_ERRORTYPE IncrementCount (OMX_U8 * pCounter, pthread_mutex_t *pMutex);
    100 extern OMX_ERRORTYPE DecrementCount (OMX_U8 * pCounter, pthread_mutex_t *pMutex);
    101 
    102 /*******************************************************************************
    103 *  PUBLIC DECLARATIONS Defined here, used elsewhere
    104 *******************************************************************************/
    105 /*--------data declarations --------------------------------------------------*/
    106 OMX_STRING cVideoDecodeName = "OMX.TI.Video.Decoder";
    107 
    108 VIDDEC_CUSTOM_PARAM sVideoDecCustomParams[] =                                {{VIDDEC_CUSTOMPARAM_PROCESSMODE, VideoDecodeCustomParamProcessMode},
    109                                                                              {VIDDEC_CUSTOMPARAM_H264BITSTREAMFORMAT, VideoDecodeCustomParamH264BitStreamFormat},
    110                                                                              {VIDDEC_CUSTOMPARAM_WMVPROFILE, VideoDecodeCustomParamWMVProfile},
    111                                                                              {VIDDEC_CUSTOMPARAM_WMVFILETYPE, VideoDecodeCustomParamWMVFileType},
    112                                                                              {VIDDEC_CUSTOMPARAM_PARSERENABLED, VideoDecodeCustomParamParserEnabled},
    113                                                                              {VIDDEC_CUSTOMCONFIG_DEBUG, VideoDecodeCustomConfigDebug},
    114 #ifdef VIDDEC_SPARK_CODE
    115                                                                              {VIDDEC_CUSTOMPARAM_ISNALBIGENDIAN, VideoDecodeCustomParamIsNALBigEndian},
    116                                                                              {VIDDEC_CUSTOMPARAM_ISSPARKINPUT, VideoDecodeCustomParamIsSparkInput}};
    117 #else
    118                                                                              {VIDDEC_CUSTOMPARAM_ISNALBIGENDIAN, VideoDecodeCustomParamIsNALBigEndian}};
    119 #endif
    120 /* H.263 Supported Levels & profiles */
    121 VIDEO_PROFILE_LEVEL_TYPE SupportedH263ProfileLevels[] = {
    122   {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level10},
    123   {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level20},
    124   {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level30},
    125   {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level40},
    126   {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level45},
    127   {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level50},
    128   {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level60},
    129   {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level70},
    130   {-1, -1}};
    131 
    132 /* MPEG4 Supported Levels & profiles */
    133 VIDEO_PROFILE_LEVEL_TYPE SupportedMPEG4ProfileLevels[] ={
    134   {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level0},
    135   {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level0b},
    136   {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level1},
    137   {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level2},
    138   {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level3},
    139   {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level4},
    140   {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level4a},
    141   {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level5},
    142   {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level0},
    143   {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level0b},
    144   {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level1},
    145   {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level2},
    146   {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level3},
    147   {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level4},
    148   {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level5},
    149   {-1,-1}};
    150 
    151 /* AVC Supported Levels & profiles */
    152 VIDEO_PROFILE_LEVEL_TYPE SupportedAVCProfileLevels[] ={
    153   {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel1},
    154   {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel1b},
    155   {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel11},
    156   {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel12},
    157   {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel13},
    158   {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel2},
    159   {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel21},
    160   {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel22},
    161   {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel3},
    162   {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel31},
    163   {-1,-1}};
    164 /*--------function prototypes ------------------------------------------------*/
    165 
    166 /*******************************************************************************
    167 *  PRIVATE DECLARATIONS Defined here, used only here
    168 *******************************************************************************/
    169 /*--------data declarations --------------------------------------------------*/
    170 /*SetConfig defines*/
    171 #define SET_CONFIG_MUTEX_BASE           0x0000FF00
    172 #define SET_CONFIG_ONMUTEX              0x0000FF01
    173 #define SET_CONFIG_OFFMUTEX             0x0000FF00
    174 
    175 /*--------macro definitions --------------------------------------------------*/
    176 
    177 /*-------function prototypes -------------------------------------------------*/
    178 static OMX_ERRORTYPE VIDDEC_SetCallbacks (OMX_HANDLETYPE hComp,
    179                                           OMX_CALLBACKTYPE* pCallBacks,
    180                                           OMX_PTR pAppData);
    181 
    182 static OMX_ERRORTYPE VIDDEC_GetComponentVersion (OMX_HANDLETYPE hComp,
    183                                                  OMX_STRING pComponentName,
    184                                                  OMX_VERSIONTYPE* pComponent,
    185                                                  OMX_VERSIONTYPE* pSpecVersion,
    186                                                  OMX_UUIDTYPE* pComponentUUID);
    187 
    188 static OMX_ERRORTYPE VIDDEC_SendCommand (OMX_HANDLETYPE hComponent,
    189                                          OMX_COMMANDTYPE Cmd,
    190                                          OMX_U32 nParam1,
    191                                          OMX_PTR pCmdData);
    192 
    193 static OMX_ERRORTYPE VIDDEC_GetParameter (OMX_HANDLETYPE hComponent,
    194                                           OMX_INDEXTYPE nParamIndex,
    195                                           OMX_PTR ComponentParamStruct);
    196 
    197 static OMX_ERRORTYPE VIDDEC_SetParameter (OMX_HANDLETYPE hComp,
    198                                           OMX_INDEXTYPE nParamIndex,
    199                                           OMX_PTR ComponentParamStruct);
    200 
    201 static OMX_ERRORTYPE VIDDEC_GetConfig (OMX_HANDLETYPE hComp,
    202                                        OMX_INDEXTYPE nConfigIndex,
    203                                        OMX_PTR pComponentConfigStructure);
    204 
    205 static OMX_ERRORTYPE VIDDEC_SetConfig (OMX_HANDLETYPE hComp,
    206                                        OMX_INDEXTYPE nConfigIndex,
    207                                        OMX_PTR pComponentConfigStructure);
    208 
    209 static OMX_ERRORTYPE VIDDEC_EmptyThisBuffer (OMX_HANDLETYPE hComp,
    210                                              OMX_BUFFERHEADERTYPE* pBuffer);
    211 
    212 static OMX_ERRORTYPE VIDDEC_FillThisBuffer (OMX_HANDLETYPE hComp,
    213                                             OMX_BUFFERHEADERTYPE* pBuffer);
    214 
    215 static OMX_ERRORTYPE VIDDEC_GetState (OMX_HANDLETYPE hComp, OMX_STATETYPE* pState);
    216 
    217 static OMX_ERRORTYPE VIDDEC_ComponentTunnelRequest (OMX_IN OMX_HANDLETYPE hComp,
    218                                                     OMX_IN OMX_U32 nPort,
    219                                                     OMX_IN OMX_HANDLETYPE hTunneledComp,
    220                                                     OMX_IN OMX_U32 nTunneledPort,
    221                                                     OMX_INOUT OMX_TUNNELSETUPTYPE* pTunnelSetup);
    222 
    223 static OMX_ERRORTYPE VIDDEC_UseBuffer (OMX_IN OMX_HANDLETYPE hComponent,
    224                                 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
    225                                 OMX_IN OMX_U32 nPortIndex,
    226                                 OMX_IN OMX_PTR pAppPrivate,
    227                                 OMX_IN OMX_U32 nSizeBytes,
    228                                 OMX_IN OMX_U8* pBuffer);
    229 
    230 static OMX_ERRORTYPE VIDDEC_AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent,
    231                                      OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
    232                                      OMX_IN OMX_U32 nPortIndex,
    233                                      OMX_IN OMX_PTR pAppPrivate,
    234                                      OMX_IN OMX_U32 nSizeBytes);
    235 
    236 static OMX_ERRORTYPE VIDDEC_FreeBuffer (OMX_IN OMX_HANDLETYPE hComponent,
    237                                         OMX_IN OMX_U32 nPortIndex,
    238                                         OMX_IN OMX_BUFFERHEADERTYPE* pBuffer);
    239 
    240 static OMX_ERRORTYPE VIDDEC_ComponentDeInit (OMX_HANDLETYPE hComponent);
    241 
    242 static OMX_ERRORTYPE VIDDEC_VerifyTunnelConnection (VIDDEC_PORT_TYPE *pPort,
    243                                                     OMX_HANDLETYPE hTunneledComp,
    244                                                     OMX_PARAM_PORTDEFINITIONTYPE* pPortDef);
    245 
    246 static OMX_ERRORTYPE VIDDEC_Allocate_DSPResources (OMX_IN VIDDEC_COMPONENT_PRIVATE *pComponentPrivate,
    247                                                    OMX_IN OMX_U32 nPortIndex);
    248 
    249 static OMX_ERRORTYPE VIDDEC_GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent,
    250                                               OMX_IN OMX_STRING cParameterName,
    251                                               OMX_OUT OMX_INDEXTYPE* pIndexType);
    252 
    253 #ifdef KHRONOS_1_1
    254 static OMX_ERRORTYPE ComponentRoleEnum(
    255                 OMX_IN OMX_HANDLETYPE hComponent,
    256                 OMX_OUT OMX_U8 *cRole,
    257                 OMX_IN OMX_U32 nIndex);
    258 #endif
    259 
    260 /*----------------------------------------------------------------------------*/
    261 /**
    262   * OMX_ComponentInit() Set the all the function pointers of component
    263   *
    264   * This method will update the component function pointer to the handle
    265   *
    266   * @param hComp         handle for this instance of the component
    267   *
    268   * @retval OMX_NoError              Success, ready to roll
    269   *         OMX_ErrorInsufficientResources If the malloc fails
    270   **/
    271 /*----------------------------------------------------------------------------*/
    272 
    273 OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComponent)
    274 {
    275     OMX_ERRORTYPE eError = OMX_ErrorNone;
    276     OMX_COMPONENTTYPE *pHandle = NULL;
    277     VIDDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
    278     OMX_U32 nMemUsage = 0;
    279 #ifdef __ENV_CHANGE__
    280     char EnvChangeValue[VIDDEC_MAX_NAMESIZE];
    281     char* EnvChangeValueu = NULL;
    282 #endif
    283 #ifdef ANDROID
    284     /* print to logcat to verify that we are running a TI OMX codec*/
    285     ALOGI("TI Video Decoder \n");
    286 #endif
    287 
    288     OMX_CONF_CHECK_CMD(hComponent, OMX_TRUE, OMX_TRUE);
    289     pHandle = (OMX_COMPONENTTYPE *)hComponent;
    290 
    291     OMX_MALLOC_STRUCT(pHandle->pComponentPrivate, VIDDEC_COMPONENT_PRIVATE, nMemUsage);
    292     if (pHandle->pComponentPrivate == NULL) {
    293         eError = OMX_ErrorInsufficientResources;
    294         goto EXIT;
    295     }
    296     pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
    297     pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0] += nMemUsage;
    298 
    299 #ifdef __PERF_INSTRUMENTATION__
    300     pComponentPrivate->pPERF = PERF_Create(PERF_FOURS("VD  "),
    301                                            PERF_ModuleLLMM | PERF_ModuleVideoDecode);
    302 #endif
    303     OMX_DBG_INIT(pComponentPrivate->dbg, "OMX_DBG_VIDDEC");
    304     ((VIDDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->pHandle = pHandle;
    305 
    306     pHandle->SetCallbacks                   = VIDDEC_SetCallbacks;
    307     pHandle->GetComponentVersion            = VIDDEC_GetComponentVersion;
    308     pHandle->SendCommand                    = VIDDEC_SendCommand;
    309     pHandle->GetParameter                   = VIDDEC_GetParameter;
    310     pHandle->SetParameter                   = VIDDEC_SetParameter;
    311     pHandle->GetConfig                      = VIDDEC_GetConfig;
    312     pHandle->SetConfig                      = VIDDEC_SetConfig;
    313     pHandle->GetState                       = VIDDEC_GetState;
    314     pHandle->ComponentTunnelRequest         = VIDDEC_ComponentTunnelRequest;
    315     pHandle->UseBuffer                      = VIDDEC_UseBuffer;
    316     pHandle->AllocateBuffer                 = VIDDEC_AllocateBuffer;
    317     pHandle->FreeBuffer                     = VIDDEC_FreeBuffer;
    318     pHandle->EmptyThisBuffer                = VIDDEC_EmptyThisBuffer;
    319     pHandle->FillThisBuffer                 = VIDDEC_FillThisBuffer;
    320     pHandle->ComponentDeInit                = VIDDEC_ComponentDeInit;
    321     pHandle->GetExtensionIndex              = VIDDEC_GetExtensionIndex;
    322 #ifdef KHRONOS_1_1
    323     pHandle->ComponentRoleEnum              = ComponentRoleEnum;
    324 #endif
    325 
    326     /*mutex protection*/
    327     if (pthread_mutex_init(&(pComponentPrivate->mutexInputBFromApp), NULL) != 0) {
    328         eError = OMX_ErrorUndefined;
    329         return eError;
    330     }
    331     if (pthread_mutex_init(&(pComponentPrivate->mutexOutputBFromApp), NULL) != 0) {
    332         eError = OMX_ErrorUndefined;
    333         return eError;
    334     }
    335     if (pthread_mutex_init(&(pComponentPrivate->mutexInputBFromDSP), NULL) != 0) {
    336         eError = OMX_ErrorUndefined;
    337         return eError;
    338     }
    339     if (pthread_mutex_init(&(pComponentPrivate->mutexOutputBFromDSP), NULL) != 0) {
    340         eError = OMX_ErrorUndefined;
    341         return eError;
    342     }
    343     VIDDEC_PTHREAD_MUTEX_INIT(pComponentPrivate->outputFlushCompletionMutex);
    344     pComponentPrivate->bIsOutputFlushPending = OMX_FALSE;
    345     VIDDEC_PTHREAD_MUTEX_INIT(pComponentPrivate->inputFlushCompletionMutex);
    346     pComponentPrivate->bIsInputFlushPending = OMX_FALSE;
    347     OMX_MALLOC_STRUCT(pComponentPrivate->pPortParamType, OMX_PORT_PARAM_TYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    348 #ifdef __STD_COMPONENT__
    349     OMX_MALLOC_STRUCT(pComponentPrivate->pPortParamTypeAudio, OMX_PORT_PARAM_TYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    350     OMX_MALLOC_STRUCT(pComponentPrivate->pPortParamTypeImage, OMX_PORT_PARAM_TYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    351     OMX_MALLOC_STRUCT(pComponentPrivate->pPortParamTypeOthers, OMX_PORT_PARAM_TYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    352 #endif
    353     OMX_MALLOC_STRUCT(pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT], VIDDEC_PORT_TYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    354     OMX_MALLOC_STRUCT(pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT], VIDDEC_PORT_TYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    355     OMX_MALLOC_STRUCT(pComponentPrivate->pInPortDef, OMX_PARAM_PORTDEFINITIONTYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    356     OMX_MALLOC_STRUCT(pComponentPrivate->pOutPortDef, OMX_PARAM_PORTDEFINITIONTYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    357     OMX_MALLOC_STRUCT(pComponentPrivate->pInPortFormat, OMX_VIDEO_PARAM_PORTFORMATTYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    358     OMX_MALLOC_STRUCT(pComponentPrivate->pOutPortFormat, OMX_VIDEO_PARAM_PORTFORMATTYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    359     OMX_MALLOC_STRUCT(pComponentPrivate->pPriorityMgmt, OMX_PRIORITYMGMTTYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    360     OMX_MALLOC_STRUCT(pComponentPrivate->pInBufSupplier, OMX_PARAM_BUFFERSUPPLIERTYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    361     OMX_MALLOC_STRUCT(pComponentPrivate->pOutBufSupplier, OMX_PARAM_BUFFERSUPPLIERTYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    362     OMX_MALLOC_STRUCT(pComponentPrivate->pMpeg4, OMX_VIDEO_PARAM_MPEG4TYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    363     OMX_MALLOC_STRUCT(pComponentPrivate->pMpeg2, OMX_VIDEO_PARAM_MPEG2TYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    364     OMX_MALLOC_STRUCT(pComponentPrivate->pH264, OMX_VIDEO_PARAM_AVCTYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    365     OMX_MALLOC_STRUCT(pComponentPrivate->pH263, OMX_VIDEO_PARAM_H263TYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    366     OMX_MALLOC_STRUCT(pComponentPrivate->pWMV, OMX_VIDEO_PARAM_WMVTYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    367     OMX_MALLOC_STRUCT(pComponentPrivate->pDeblockingParamType, OMX_PARAM_DEBLOCKINGTYPE, pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    368     OMX_MALLOC_STRUCT(pComponentPrivate->pPVCapabilityFlags, PV_OMXComponentCapabilityFlagsType, pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    369 
    370     OMX_MALLOC_STRUCT_SIZED(pComponentPrivate->cComponentName, char, VIDDEC_MAX_NAMESIZE + 1,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
    371     if (pComponentPrivate->cComponentName == NULL) {
    372         OMX_TRACE4(pComponentPrivate->dbg, "Error: Malloc failed\n");
    373         eError = OMX_ErrorInsufficientResources;
    374         goto EXIT;
    375     }
    376     strncpy(pComponentPrivate->cComponentName, cVideoDecodeName, VIDDEC_MAX_NAMESIZE);
    377     OMX_CONF_INIT_STRUCT( &pComponentPrivate->componentRole, OMX_PARAM_COMPONENTROLETYPE, pComponentPrivate->dbg);
    378     VIDDEC_Load_Defaults( pComponentPrivate, VIDDEC_INIT_ALL);
    379 #ifdef __ENV_CHANGE__
    380 #ifdef KHRONOS_1_1
    381     EnvChangeValueu = getenv(ENV_CHANGE_NAME_VALUE);
    382     if(EnvChangeValueu != NULL) {
    383         strcpy( EnvChangeValue, EnvChangeValueu);
    384         if( strcmp( EnvChangeValueu, ENV_CHANGE_SET_H263) == 0) {
    385             eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_H263);
    386             if( pComponentPrivate->pOutPortFormat->eColorFormat != VIDDEC_COLORFORMAT420) {
    387                 eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_PLANAR420);
    388             }
    389             strcpy((char*)pComponentPrivate->componentRole.cRole, VIDDEC_COMPONENTROLES_H263);
    390         }
    391         else if( strcmp( EnvChangeValueu, ENV_CHANGE_SET_H264) == 0 ||  strcmp( EnvChangeValueu, ENV_CHANGE_SET_AVC) == 0) {
    392             eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_H264);
    393             if( pComponentPrivate->pOutPortFormat->eColorFormat != VIDDEC_COLORFORMAT420) {
    394                 eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_PLANAR420);
    395             }
    396             strcpy((char*)pComponentPrivate->componentRole.cRole, VIDDEC_COMPONENTROLES_H264);
    397         }
    398         else if( strcmp( EnvChangeValueu, ENV_CHANGE_SET_MPEG2) == 0) {
    399             eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_MPEG2);
    400             if( pComponentPrivate->pOutPortFormat->eColorFormat != VIDDEC_COLORFORMAT420) {
    401                 eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_PLANAR420);
    402             }
    403             strcpy((char*)pComponentPrivate->componentRole.cRole, VIDDEC_COMPONENTROLES_MPEG2);
    404         }
    405         else if( strcmp( EnvChangeValueu, ENV_CHANGE_SET_WMV9) == 0) {
    406             eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_WMV9);
    407             if( pComponentPrivate->pOutPortFormat->eColorFormat != VIDDEC_COLORFORMAT420) {
    408                 eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_PLANAR420);
    409             }
    410             strcpy((char*)pComponentPrivate->componentRole.cRole, VIDDEC_COMPONENTROLES_MPEG4);
    411         }
    412 #ifdef VIDDEC_SPARK_CODE
    413         else if( strcmp( EnvChangeValueu, ENV_CHANGE_SET_SPARK) == 0) {
    414             eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_SPARK);
    415             if( pComponentPrivate->pOutPortFormat->eColorFormat != VIDDEC_COLORFORMAT420) {
    416                 eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_PLANAR420);
    417             }
    418             strcpy((char*)pComponentPrivate->componentRole.cRole, VIDDEC_COMPONENTROLES_H263);
    419         }
    420 #endif
    421         else {
    422             eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_MPEG4);
    423             if( pComponentPrivate->pOutPortFormat->eColorFormat != VIDDEC_COLORFORMAT420) {
    424                 eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_PLANAR420);
    425             }
    426             strcpy((char*)pComponentPrivate->componentRole.cRole, VIDDEC_COMPONENTROLES_WMV9);
    427         }
    428     }
    429     else
    430     {
    431         if( pComponentPrivate->pOutPortFormat->eColorFormat != VIDDEC_COLORFORMAT420) {
    432             eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_PLANAR420);
    433         }
    434         strcpy((char*)pComponentPrivate->componentRole.cRole, VIDDEC_COMPONENTROLES_MPEG4);
    435     }
    436 #else
    437     EnvChangeValueu = getenv(ENV_CHANGE_NAME_VALUE);
    438     if(EnvChangeValueu != NULL) {
    439         strcpy( EnvChangeValue, EnvChangeValueu);
    440         if( strcmp( EnvChangeValueu, ENV_CHANGE_SET_H263) == 0) {
    441             VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_H263);
    442         }
    443         else if( strcmp( EnvChangeValueu, ENV_CHANGE_SET_H264) == 0) {
    444             VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_H264);
    445         }
    446         else if( strcmp( EnvChangeValueu, ENV_CHANGE_SET_MPEG2) == 0) {
    447             VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_MPEG2);
    448         }
    449         else if( strcmp( EnvChangeValueu, ENV_CHANGE_SET_WMV9) == 0) {
    450             VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_WMV9);
    451         }
    452 #ifdef VIDDEC_SPARK_CODE
    453         else if( strcmp( EnvChangeValueu, ENV_CHANGE_SET_SPARK) == 0) {
    454             VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_SPARK);
    455         }
    456 #endif
    457         else {
    458             VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_MPEG4);
    459         }
    460         if( pComponentPrivate->pOutPortFormat->eColorFormat != VIDDEC_COLORFORMAT420) {
    461             eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_PLANAR420);
    462         }
    463     }
    464 #endif
    465 #endif
    466 
    467 #ifdef RESOURCE_MANAGER_ENABLED
    468 /*#ifndef UNDER_CE*/
    469     /* load the ResourceManagerProxy thread */
    470     eError = RMProxy_NewInitalizeEx(OMX_COMPONENTTYPE_VIDEO);
    471     if (eError != OMX_ErrorNone) {
    472         pComponentPrivate->eRMProxyState = VidDec_RMPROXY_State_Unload;
    473         OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from loading ResourceManagerProxy thread\n");
    474         goto EXIT;
    475     }
    476     else{
    477         pComponentPrivate->eRMProxyState = VidDec_RMPROXY_State_Load;
    478     }
    479 /*#endif*/
    480 #endif
    481 
    482     /* Start the component thread */
    483     eError = VIDDEC_Start_ComponentThread(pHandle);
    484     if (eError != OMX_ErrorNone) {
    485         OMX_ERROR4(pComponentPrivate->dbg, "Error returned from the Component\n");
    486         goto EXIT;
    487     }
    488 
    489 EXIT:
    490     return eError;
    491 }
    492 
    493 /*----------------------------------------------------------------------------*/
    494 /**
    495   *  VIDDEC_SetCallbacks() Sets application callbacks to the component
    496   *
    497   * This method will update application callbacks
    498   * the application.
    499   *
    500   * @param pComp         handle for this instance of the component
    501   * @param pCallBacks    application callbacks
    502   * @param ptr           pointer to the appdata structure
    503   *
    504   * @retval OMX_NoError              Success, ready to roll
    505   *         OMX_Error_BadParameter   The input parameter pointer is null
    506   **/
    507 /*----------------------------------------------------------------------------*/
    508 
    509 static OMX_ERRORTYPE VIDDEC_SetCallbacks (OMX_HANDLETYPE pComponent,
    510                                           OMX_CALLBACKTYPE* pCallBacks,
    511                                           OMX_PTR pAppData)
    512 {
    513     OMX_ERRORTYPE eError = OMX_ErrorNone;
    514     OMX_COMPONENTTYPE *pHandle = NULL;
    515     VIDDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
    516 
    517     OMX_CONF_CHECK_CMD(pComponent, pCallBacks, OMX_TRUE);
    518 
    519     pHandle = (OMX_COMPONENTTYPE*)pComponent;
    520     pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
    521 
    522     /* Copy the callbacks of the application to the component private  */
    523     memcpy (&(pComponentPrivate->cbInfo), pCallBacks, sizeof(OMX_CALLBACKTYPE));
    524 
    525     /* copy the application private data to component memory */
    526     pHandle->pApplicationPrivate = pAppData;
    527 
    528     pComponentPrivate->eState = OMX_StateLoaded;
    529 
    530 EXIT:
    531     return eError;
    532 }
    533 
    534 /*----------------------------------------------------------------------------*/
    535 /**
    536   *  VIDDEC_GetComponentVersion() Sets application callbacks to the component
    537   *
    538   * This method will update application callbacks
    539   * the application.
    540   *
    541   * @param pComp         handle for this instance of the component
    542   * @param pCallBacks    application callbacks
    543   * @param ptr
    544   *
    545   * @retval OMX_NoError              Success, ready to roll
    546   *         OMX_Error_BadParameter   The input parameter pointer is null
    547   **/
    548 /*----------------------------------------------------------------------------*/
    549 
    550 static OMX_ERRORTYPE VIDDEC_GetComponentVersion (OMX_HANDLETYPE hComp,
    551                                                  OMX_STRING pComponentName,
    552                                                  OMX_VERSIONTYPE* pComponentVersion,
    553                                                  OMX_VERSIONTYPE* pSpecVersion,
    554                                                  OMX_UUIDTYPE* pComponentUUID)
    555 {
    556     OMX_ERRORTYPE eError = OMX_ErrorNone;
    557     OMX_COMPONENTTYPE* pHandle = NULL;
    558     VIDDEC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
    559 
    560     if (!hComp || !pComponentName || !pComponentVersion || !pSpecVersion) {
    561         eError = OMX_ErrorBadParameter;
    562         goto EXIT;
    563     }
    564     pHandle = (OMX_COMPONENTTYPE*)hComp;
    565     pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
    566 
    567     strcpy(pComponentName, pComponentPrivate->cComponentName);
    568     memcpy(pComponentVersion, &(pComponentPrivate->pComponentVersion.s), sizeof(pComponentPrivate->pComponentVersion.s));
    569     memcpy(pSpecVersion, &(pComponentPrivate->pSpecVersion.s), sizeof(pComponentPrivate->pSpecVersion.s));
    570 
    571     if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
    572         memcpy(pComponentUUID, (OMX_UUIDTYPE *)&STRING_H264VDSOCKET_TI_UUID, STRING_UUID_LENGHT);
    573     }
    574     else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) {
    575         memcpy(pComponentUUID, (OMX_UUIDTYPE *)&STRING_WMVDSOCKET_TI_UUID, STRING_UUID_LENGHT);
    576     }
    577     else if ((pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4) ||
    578              (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)) {
    579         memcpy(pComponentUUID, (OMX_UUIDTYPE *)&STRING_MP4DSOCKET_TI_UUID, STRING_UUID_LENGHT);
    580     }
    581     else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) {
    582         memcpy(pComponentUUID, (OMX_UUIDTYPE *)&STRING_MP2DSOCKET_TI_UUID, STRING_UUID_LENGHT);
    583     }
    584 #ifdef VIDDEC_SPARK_CODE
    585     else if (VIDDEC_SPARKCHECK) {
    586             memcpy(pComponentUUID, (OMX_UUIDTYPE *)&STRING_SPARKDSOCKET_TI_UUID, STRING_UUID_LENGHT);
    587     }
    588 #endif
    589     else {
    590         memcpy(pComponentUUID, (OMX_UUIDTYPE *)&STRING_MP4DSOCKET_TI_UUID, STRING_UUID_LENGHT);
    591     }
    592 EXIT:
    593     return eError;
    594 }
    595 
    596 /*----------------------------------------------------------------------------*/
    597 /**
    598   *  VIDDEC_SendCommand() Sets application callbacks to the component
    599   *
    600   * This method will update application callbacks
    601   * the application.
    602   *
    603   * @param pComp         handle for this instance of the component
    604   * @param pCallBacks    application callbacks
    605   * @param ptr
    606   *
    607   * @retval OMX_NoError              Success, ready to roll
    608   *         OMX_Error_BadParameter   The input parameter pointer is null
    609   **/
    610 /*----------------------------------------------------------------------------*/
    611 static OMX_ERRORTYPE VIDDEC_SendCommand (OMX_HANDLETYPE hComponent,
    612                                          OMX_COMMANDTYPE Cmd,
    613                                          OMX_U32 nParam1,
    614                                          OMX_PTR pCmdData)
    615 {
    616     OMX_ERRORTYPE eError = OMX_ErrorNone;
    617     OMX_S32 nRet;
    618     OMX_COMPONENTTYPE* pHandle = NULL;
    619     VIDDEC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
    620     OMX_CONF_CHECK_CMD(hComponent, OMX_TRUE, OMX_TRUE);
    621 
    622     pHandle = (OMX_COMPONENTTYPE*)hComponent;
    623     pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
    624 
    625     if (pComponentPrivate->eState == OMX_StateInvalid) {
    626         eError = OMX_ErrorInvalidState;
    627         goto EXIT;
    628     }
    629 
    630 #ifdef __PERF_INSTRUMENTATION__
    631     PERF_SendingCommand(pComponentPrivate->pPERF,
    632                         Cmd, (Cmd == OMX_CommandMarkBuffer) ? (OMX_U32) pCmdData : nParam1,
    633                         PERF_ModuleComponent);
    634 #endif
    635 
    636     switch (Cmd) {
    637         case OMX_CommandStateSet:
    638             ALOGD("VIDDEC_SendCommand: Received request from omx client to change state to %d", nParam1);
    639             /* Add a pending transition */
    640             if(AddStateTransition(pComponentPrivate) != OMX_ErrorNone) {
    641                 return OMX_ErrorUndefined;
    642             }
    643             pComponentPrivate->eIdleToLoad = nParam1;
    644             pComponentPrivate->eExecuteToIdle = nParam1;
    645             nRet = write(pComponentPrivate->cmdPipe[VIDDEC_PIPE_WRITE], &Cmd, sizeof(Cmd));
    646             if (nRet == -1) {
    647                 if(RemoveStateTransition(pComponentPrivate, OMX_FALSE) != OMX_ErrorNone) {
    648                    return OMX_ErrorUndefined;
    649                 }
    650                 return OMX_ErrorUndefined;
    651             }
    652             nRet = write(pComponentPrivate->cmdDataPipe[VIDDEC_PIPE_WRITE], &nParam1, sizeof(nParam1));
    653             if (nRet == -1) {
    654                 if(RemoveStateTransition(pComponentPrivate, OMX_FALSE) != OMX_ErrorNone) {
    655                    return OMX_ErrorUndefined;
    656                 }
    657                 return OMX_ErrorUndefined;
    658             }
    659             break;
    660         case OMX_CommandPortDisable:
    661             if (nParam1 == VIDDEC_INPUT_PORT) {
    662                 pComponentPrivate->pInPortDef->bEnabled = OMX_FALSE;
    663                 OMX_PRBUFFER2(pComponentPrivate->dbg, "Disabling VIDDEC_INPUT_PORT 0x%x\n",pComponentPrivate->pInPortDef->bEnabled);
    664                 VIDDEC_HandleCommandFlush(pComponentPrivate, 0, OMX_FALSE);
    665             }
    666             else if (nParam1 == VIDDEC_OUTPUT_PORT) {
    667                 pComponentPrivate->pOutPortDef->bEnabled = OMX_FALSE;
    668                 OMX_PRBUFFER2(pComponentPrivate->dbg, "Disabling VIDDEC_OUTPUT_PORT 0x%x\n",pComponentPrivate->pOutPortDef->bEnabled);
    669                 VIDDEC_HandleCommandFlush(pComponentPrivate, 1, OMX_FALSE);
    670             }
    671             else if (nParam1 == OMX_ALL) {
    672                 pComponentPrivate->pInPortDef->bEnabled = OMX_FALSE;
    673                 pComponentPrivate->pOutPortDef->bEnabled = OMX_FALSE;
    674                 OMX_PRBUFFER2(pComponentPrivate->dbg, "Disabling OMX_ALL IN 0x%x OUT 0x%x\n",pComponentPrivate->pInPortDef->bEnabled,
    675                     pComponentPrivate->pOutPortDef->bEnabled);
    676                 VIDDEC_HandleCommandFlush(pComponentPrivate, -1, OMX_FALSE);
    677             }
    678             else {
    679                 eError = OMX_ErrorBadParameter;
    680                 goto EXIT;
    681             }
    682             nRet = write(pComponentPrivate->cmdPipe[VIDDEC_PIPE_WRITE], &Cmd, sizeof(Cmd));
    683             if (nRet == -1) {
    684                 eError = OMX_ErrorUndefined;
    685                 goto EXIT;
    686             }
    687             nRet = write(pComponentPrivate->cmdDataPipe[VIDDEC_PIPE_WRITE], &nParam1, sizeof(nParam1));
    688             if (nRet == -1) {
    689                 eError = OMX_ErrorUndefined;
    690                 goto EXIT;
    691             }
    692 #ifdef ANDROID
    693             /*Workaround version to handle pv app */
    694             /*After ports is been flush*/
    695 
    696             if (nParam1 == VIDDEC_INPUT_PORT &&
    697                     pComponentPrivate->bDynamicConfigurationInProgress == OMX_TRUE &&
    698                     pComponentPrivate->bInPortSettingsChanged == OMX_TRUE) {
    699                 VIDDEC_PTHREAD_MUTEX_SIGNAL(pComponentPrivate->sDynConfigMutex);
    700             }
    701 #endif
    702             break;
    703         case OMX_CommandPortEnable:
    704             if (nParam1 == VIDDEC_INPUT_PORT) {
    705                 pComponentPrivate->pInPortDef->bEnabled = OMX_TRUE;
    706                 OMX_PRBUFFER2(pComponentPrivate->dbg, "Enabling VIDDEC_INPUT_PORT 0x%x\n",pComponentPrivate->pInPortDef->bEnabled);
    707             }
    708             else if (nParam1 == VIDDEC_OUTPUT_PORT) {
    709                 pComponentPrivate->pOutPortDef->bEnabled = OMX_TRUE;
    710                 OMX_PRBUFFER2(pComponentPrivate->dbg, "Enabling VIDDEC_OUTPUT_PORT 0x%x\n",pComponentPrivate->pOutPortDef->bEnabled);
    711             }
    712             else if (nParam1 == OMX_ALL) {
    713                 pComponentPrivate->pInPortDef->bEnabled = OMX_TRUE;
    714                 pComponentPrivate->pOutPortDef->bEnabled = OMX_TRUE;
    715                 OMX_PRBUFFER2(pComponentPrivate->dbg, "Enabling VIDDEC_INPUT_PORT 0x%x\n",pComponentPrivate->pInPortDef->bEnabled);
    716             }
    717             nRet = write(pComponentPrivate->cmdPipe[VIDDEC_PIPE_WRITE], &Cmd, sizeof(Cmd));
    718             if (nRet == -1) {
    719                 eError = OMX_ErrorUndefined;
    720                 goto EXIT;
    721             }
    722             nRet = write(pComponentPrivate->cmdDataPipe[VIDDEC_PIPE_WRITE], &nParam1, sizeof(nParam1));
    723             if (nRet == -1) {
    724                 eError = OMX_ErrorUndefined;
    725                 goto EXIT;
    726             }
    727             break;
    728         case OMX_CommandFlush:
    729             if ( nParam1 > 1 && nParam1 != -1 ) {
    730                 eError = OMX_ErrorBadPortIndex;
    731                 goto EXIT;
    732             }
    733             nRet = write(pComponentPrivate->cmdPipe[VIDDEC_PIPE_WRITE], &Cmd, sizeof(Cmd));
    734             if (nRet == -1) {
    735                 eError = OMX_ErrorUndefined;
    736                 goto EXIT;
    737             }
    738             nRet = write(pComponentPrivate->cmdDataPipe[VIDDEC_PIPE_WRITE], &nParam1, sizeof(nParam1));
    739             if (nRet == -1) {
    740                 eError = OMX_ErrorUndefined;
    741                 goto EXIT;
    742             }
    743             break;
    744         case OMX_CommandMarkBuffer:
    745             if ( nParam1 > VIDDEC_OUTPUT_PORT ){
    746                 eError = OMX_ErrorBadPortIndex;
    747                 goto EXIT;
    748             }
    749             nRet = write(pComponentPrivate->cmdPipe[VIDDEC_PIPE_WRITE], &Cmd, sizeof(Cmd));
    750             if (nRet == -1) {
    751                 eError = OMX_ErrorUndefined;
    752                 goto EXIT;
    753             }
    754             nRet = write(pComponentPrivate->cmdDataPipe[VIDDEC_PIPE_WRITE], &nParam1, sizeof(nParam1));
    755             if (nRet == -1) {
    756                 eError = OMX_ErrorUndefined;
    757                 goto EXIT;
    758             }
    759             nRet = write(pComponentPrivate->cmdDataPipe[VIDDEC_PIPE_WRITE], &pCmdData, sizeof(pCmdData));
    760             if (nRet == -1) {
    761                 eError = OMX_ErrorUndefined;
    762                 goto EXIT;
    763             }
    764             break;
    765         case OMX_CommandMax:
    766             break;
    767         default:
    768             eError = OMX_ErrorUndefined;
    769     }
    770 
    771 EXIT:
    772     return eError;
    773 }
    774 
    775 /*----------------------------------------------------------------------------*/
    776 /**
    777   *  VIDDEC_GetParameter() Sets application callbacks to the component
    778   *
    779   * This method will update application callbacks
    780   * the application.
    781   *
    782   * @param pComp         handle for this instance of the component
    783   * @param pCallBacks    application callbacks
    784   * @param ptr
    785   *
    786   * @retval OMX_NoError              Success, ready to roll
    787   *         OMX_Error_BadParameter   The input parameter pointer is null
    788   **/
    789 /*----------------------------------------------------------------------------*/
    790 
    791 static OMX_ERRORTYPE VIDDEC_GetParameter (OMX_IN OMX_HANDLETYPE hComponent,
    792                                           OMX_IN  OMX_INDEXTYPE nParamIndex,
    793                                           OMX_INOUT OMX_PTR ComponentParameterStructure)
    794 {
    795     OMX_COMPONENTTYPE* pComp = NULL;
    796     VIDDEC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
    797     OMX_ERRORTYPE eError = OMX_ErrorNone;
    798 #ifdef KHRONOS_1_1
    799     OMX_PARAM_COMPONENTROLETYPE *pRole = NULL;
    800 #endif
    801     OMX_CONF_CHECK_CMD(hComponent, ComponentParameterStructure, OMX_TRUE);
    802 
    803     pComp = (OMX_COMPONENTTYPE*)hComponent;
    804     pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE*)pComp->pComponentPrivate;
    805 
    806     if (pComponentPrivate->eState == OMX_StateInvalid) {
    807         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation);
    808     }
    809 
    810     switch (nParamIndex) {
    811         case OMX_IndexConfigVideoMBErrorReporting: /**< reference: OMX_CONFIG_MBERRORREPORTINGTYPE */
    812         {
    813             if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
    814                 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263 ||
    815                 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
    816                 OMX_CONFIG_MBERRORREPORTINGTYPE* pMBErrorReportTo = ComponentParameterStructure;
    817                 /*OMX_CONF_CHK_VERSION( pMBErrorReportTo, OMX_CONFIG_MBERRORREPORTINGTYPE, eError, pComponentPrivate->dbg);*/
    818                 pMBErrorReportTo->bEnabled = pComponentPrivate->eMBErrorReport.bEnabled;
    819             }
    820             else {
    821                 eError = OMX_ErrorUnsupportedIndex;
    822             }
    823             break;
    824         }
    825         case OMX_IndexParamVideoInit:
    826             memcpy(ComponentParameterStructure, pComponentPrivate->pPortParamType, sizeof(OMX_PORT_PARAM_TYPE));
    827             break;
    828 #ifdef __STD_COMPONENT__
    829         case OMX_IndexParamAudioInit:
    830             memcpy(ComponentParameterStructure, pComponentPrivate->pPortParamTypeAudio, sizeof(OMX_PORT_PARAM_TYPE));
    831             break;
    832         case OMX_IndexParamImageInit:
    833             memcpy(ComponentParameterStructure, pComponentPrivate->pPortParamTypeImage, sizeof(OMX_PORT_PARAM_TYPE));
    834             break;
    835         case OMX_IndexParamOtherInit:
    836             memcpy(ComponentParameterStructure, pComponentPrivate->pPortParamTypeOthers, sizeof(OMX_PORT_PARAM_TYPE));
    837             break;
    838 #ifdef KHRONOS_1_1
    839         case OMX_IndexParamVideoMacroblocksPerFrame:/**< reference: OMX_PARAM_MACROBLOCKSTYPE */
    840         {
    841             OMX_PARAM_MACROBLOCKSTYPE* pMBBlocksTypeTo = ComponentParameterStructure;
    842             /*OMX_CONF_CHK_VERSION( pMBBlocksTypeTo, OMX_PARAM_MACROBLOCKSTYPE, eError, pComponentPrivate->dbg);*/
    843             pMBBlocksTypeTo->nMacroblocks = pComponentPrivate->pOutPortDef->format.video.nFrameWidth *
    844                                             pComponentPrivate->pOutPortDef->format.video.nFrameHeight / 256;
    845             break;
    846         }
    847         case OMX_IndexParamVideoProfileLevelQuerySupported:
    848             {
    849                 VIDEO_PROFILE_LEVEL_TYPE* pProfileLevel = NULL;
    850                 OMX_U32 nNumberOfProfiles = 0;
    851                 OMX_VIDEO_PARAM_PROFILELEVELTYPE *pParamProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)ComponentParameterStructure;
    852                 pParamProfileLevel->nPortIndex = pComponentPrivate->pInPortDef->nPortIndex;
    853 
    854                 /* Choose table based on compression format */
    855                 switch(pComponentPrivate->pInPortDef->format.video.eCompressionFormat)
    856                 {
    857                    case OMX_VIDEO_CodingH263:
    858 					    pProfileLevel = SupportedH263ProfileLevels;
    859 	                    nNumberOfProfiles = sizeof(SupportedH263ProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
    860                       break;
    861                    case OMX_VIDEO_CodingMPEG4:
    862 					    pProfileLevel = SupportedMPEG4ProfileLevels;
    863 	                    nNumberOfProfiles = sizeof(SupportedMPEG4ProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
    864                       break;
    865                    case OMX_VIDEO_CodingAVC:
    866 					    pProfileLevel = SupportedAVCProfileLevels;
    867                         nNumberOfProfiles = sizeof(SupportedAVCProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
    868                       break;
    869                     default:
    870                         return OMX_ErrorBadParameter;
    871                   }
    872 
    873                 if((pParamProfileLevel->nProfileIndex < 0) || (pParamProfileLevel->nProfileIndex >= (nNumberOfProfiles - 1)))
    874                     return OMX_ErrorBadParameter;
    875                   /* Point to table entry based on index */
    876                   pProfileLevel += pParamProfileLevel->nProfileIndex;
    877 
    878                   /* -1 indicates end of table */
    879                   if(pProfileLevel->nProfile != -1) {
    880                      pParamProfileLevel->eProfile = pProfileLevel->nProfile;
    881                      pParamProfileLevel->eLevel = pProfileLevel->nLevel;
    882                      eError = OMX_ErrorNone;
    883                   }
    884                   else {
    885                      eError = OMX_ErrorNoMore;
    886                   }
    887                   break;
    888                   }
    889         case OMX_IndexParamVideoProfileLevelCurrent:
    890         {
    891            OMX_VIDEO_PARAM_PROFILELEVELTYPE *pParamProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)ComponentParameterStructure;
    892            if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
    893            ALOGW("Getparameter OMX_IndexParamVideoProfileLevelCurrent AVC");
    894            pParamProfileLevel->eProfile = pComponentPrivate->pH264->eProfile;
    895            pParamProfileLevel->eLevel = pComponentPrivate->pH264->eLevel;
    896         }
    897         else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4) {
    898            ALOGW("Getparameter OMX_IndexParamVideoProfileLevelCurrent MPEG4");
    899            pParamProfileLevel->eProfile = pComponentPrivate->pMpeg4->eProfile;
    900            pParamProfileLevel->eLevel = pComponentPrivate->pMpeg4->eLevel;
    901         }
    902         else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) {
    903            ALOGW("Getparameter OMX_IndexParamVideoProfileLevelCurrent H.263");
    904            pParamProfileLevel->eProfile = pComponentPrivate->pH263->eProfile;
    905            pParamProfileLevel->eLevel = pComponentPrivate->pH263->eLevel;
    906         }
    907         else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) {
    908            pParamProfileLevel->eProfile = pComponentPrivate->pMpeg2->eProfile;
    909            pParamProfileLevel->eLevel = pComponentPrivate->pMpeg2->eLevel;
    910         }
    911         else {
    912            ALOGD("Error in Getparameter OMX_IndexParamVideoProfileLevelCurrent");
    913            eError = OMX_ErrorBadParameter;
    914          }
    915       }
    916       break;
    917         case OMX_IndexParamStandardComponentRole:
    918             if (ComponentParameterStructure != NULL) {
    919                 pRole = (OMX_PARAM_COMPONENTROLETYPE *)ComponentParameterStructure;
    920                 /*OMX_CONF_CHK_VERSION( pRole, OMX_PARAM_COMPONENTROLETYPE, eError, pComponentPrivate->dbg);*/
    921                 memcpy( pRole, &pComponentPrivate->componentRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
    922             }
    923             else {
    924                 eError = OMX_ErrorBadParameter;
    925             }
    926             break;
    927 #endif
    928 #endif
    929         case OMX_IndexParamPortDefinition:
    930             {
    931                 if (((OMX_PARAM_PORTDEFINITIONTYPE*)(ComponentParameterStructure))->nPortIndex ==
    932                         pComponentPrivate->pInPortDef->nPortIndex) {
    933                     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = pComponentPrivate->pInPortDef;
    934                     OMX_PARAM_PORTDEFINITIONTYPE *pPortDefParam = (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure;
    935                     memcpy(pPortDefParam, pPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
    936                 }
    937                 else if (((OMX_PARAM_PORTDEFINITIONTYPE*)(ComponentParameterStructure))->nPortIndex ==
    938                         pComponentPrivate->pOutPortDef->nPortIndex) {
    939                     OMX_PARAM_PORTDEFINITIONTYPE *pPortDefParam = (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure;
    940                     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = pComponentPrivate->pOutPortDef;
    941                     memcpy(pPortDefParam, pPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
    942                 }
    943                 else {
    944                     eError = OMX_ErrorBadPortIndex;
    945                 }
    946 
    947                 OMX_PRBUFFER1(pComponentPrivate->dbg, "CountActual 0x%x CountMin 0x%x Size %d bEnabled %x bPopulated %x compression %x %x-%x\n",
    948                                 (int )((OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure)->nBufferCountActual,
    949                                 (int )((OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure)->nBufferCountMin,
    950                                 (int )((OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure)->nBufferSize,
    951                                 (int )((OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure)->bEnabled,
    952                                 (int )((OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure)->bPopulated,
    953                                 (int )((OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure)->format.video.nFrameWidth,
    954                                 (int )((OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure)->format.video.nFrameHeight,
    955                                 (int )((OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure)->format.video.eCompressionFormat);
    956             }
    957             break;
    958         case OMX_IndexParamVideoPortFormat:
    959             {
    960                 OMX_VIDEO_PARAM_PORTFORMATTYPE* pPortFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
    961                 if (pPortFormat->nPortIndex == pComponentPrivate->pInPortFormat->nPortIndex) {
    962                     switch (pPortFormat->nIndex) {
    963                         case VIDDEC_DEFAULT_INPUT_INDEX_H263:
    964                             OMX_PRINT1(pComponentPrivate->dbg, "eCompressionFormat = OMX_VIDEO_CodingH263\n");
    965                             pComponentPrivate->pInPortFormat->nIndex                        = VIDDEC_DEFAULT_INPUT_INDEX_H263;
    966                             pComponentPrivate->pInPortFormat->eCompressionFormat            = OMX_VIDEO_CodingH263;
    967                             pComponentPrivate->pInPortDef->format.video.eCompressionFormat  = OMX_VIDEO_CodingH263;
    968                             break;
    969                         case VIDDEC_DEFAULT_INPUT_INDEX_H264:
    970                             OMX_PRINT1(pComponentPrivate->dbg, "eCompressionFormat = OMX_VIDEO_CodingAVC\n");
    971                             pComponentPrivate->pInPortFormat->nIndex                        = VIDDEC_DEFAULT_INPUT_INDEX_H264;
    972                             pComponentPrivate->pInPortFormat->eCompressionFormat            = OMX_VIDEO_CodingAVC;
    973                             pComponentPrivate->pInPortDef->format.video.eCompressionFormat  = OMX_VIDEO_CodingAVC;
    974                             break;
    975                         case VIDDEC_DEFAULT_INPUT_INDEX_MPEG2:
    976                             pComponentPrivate->pInPortFormat->nIndex                        = VIDDEC_DEFAULT_INPUT_INDEX_MPEG2;
    977                             pComponentPrivate->pInPortFormat->eCompressionFormat            = OMX_VIDEO_CodingMPEG2;
    978                             pComponentPrivate->pInPortDef->format.video.eCompressionFormat  = OMX_VIDEO_CodingMPEG2;
    979                             break;
    980                         case VIDDEC_DEFAULT_INPUT_INDEX_MPEG4:
    981                             OMX_PRINT1(pComponentPrivate->dbg, "eCompressionFormat = VIDDEC_DEFAULT_INPUT_INDEX_MPEG4\n");
    982                             pComponentPrivate->pInPortFormat->nIndex                        = VIDDEC_DEFAULT_INPUT_INDEX_MPEG4;
    983                             pComponentPrivate->pInPortFormat->eCompressionFormat            = OMX_VIDEO_CodingMPEG4;
    984                             pComponentPrivate->pInPortDef->format.video.eCompressionFormat  = OMX_VIDEO_CodingMPEG4;
    985                             break;
    986                         case VIDDEC_DEFAULT_INPUT_INDEX_WMV9:
    987                             pComponentPrivate->pInPortFormat->nIndex                        = VIDDEC_DEFAULT_INPUT_INDEX_WMV9;
    988                             pComponentPrivate->pInPortFormat->eCompressionFormat            = OMX_VIDEO_CodingWMV;
    989                             pComponentPrivate->pInPortDef->format.video.eCompressionFormat  = OMX_VIDEO_CodingWMV;
    990                             break;
    991 #ifdef VIDDEC_SPARK_CODE
    992                         case VIDDEC_DEFAULT_INPUT_INDEX_SPARK:
    993                             pComponentPrivate->pInPortFormat->nIndex                        = VIDDEC_DEFAULT_INPUT_INDEX_SPARK;
    994                             pComponentPrivate->pInPortFormat->eCompressionFormat            = OMX_VIDEO_CodingUnused;
    995                             pComponentPrivate->pInPortDef->format.video.eCompressionFormat  = OMX_VIDEO_CodingUnused;
    996                             break;
    997 #endif
    998                         default:
    999                             OMX_PRINT1(pComponentPrivate->dbg, "Input Index= %lu; OMX_ErrorNoMore\n", pPortFormat->nIndex);
   1000                             eError = OMX_ErrorNoMore;
   1001                             break;
   1002                     }
   1003                     if(eError == OMX_ErrorNone) {
   1004                         memcpy(ComponentParameterStructure, pComponentPrivate->pInPortFormat,
   1005                                 sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
   1006                     }
   1007                 }
   1008                 else if (pPortFormat->nPortIndex == pComponentPrivate->pOutPortFormat->nPortIndex) {
   1009                     if(eError == OMX_ErrorNone) {
   1010                         memcpy(ComponentParameterStructure, pComponentPrivate->pOutPortFormat,
   1011                             sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
   1012                     }
   1013                 }
   1014                 else {
   1015                     eError = OMX_ErrorBadPortIndex;
   1016                 }
   1017             }
   1018             break;
   1019         case OMX_IndexParamPriorityMgmt:
   1020             memcpy(ComponentParameterStructure, pComponentPrivate->pPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
   1021             break;
   1022         case  OMX_IndexParamVideoWmv:
   1023             {
   1024                 if (((OMX_VIDEO_PARAM_WMVTYPE*)(ComponentParameterStructure))->nPortIndex ==
   1025                         pComponentPrivate->pWMV->nPortIndex) {
   1026                     memcpy(ComponentParameterStructure, pComponentPrivate->pWMV, sizeof(OMX_VIDEO_PARAM_WMVTYPE));
   1027                 }
   1028                 else {
   1029                     eError = OMX_ErrorBadPortIndex;
   1030                 }
   1031             }
   1032             break;
   1033         case  OMX_IndexParamVideoMpeg4:
   1034             {
   1035                 if (((OMX_VIDEO_PARAM_MPEG4TYPE*)(ComponentParameterStructure))->nPortIndex ==
   1036                         pComponentPrivate->pMpeg4->nPortIndex) {
   1037                     memcpy(ComponentParameterStructure, pComponentPrivate->pMpeg4, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE));
   1038                 }
   1039                 else {
   1040                     eError = OMX_ErrorBadPortIndex;
   1041                 }
   1042             }
   1043             break;
   1044         case  OMX_IndexParamVideoMpeg2:
   1045             {
   1046                 if (((OMX_VIDEO_PARAM_MPEG2TYPE*)(ComponentParameterStructure))->nPortIndex ==
   1047                         pComponentPrivate->pMpeg2->nPortIndex) {
   1048                     memcpy(ComponentParameterStructure, pComponentPrivate->pMpeg2, sizeof(OMX_VIDEO_PARAM_MPEG2TYPE));
   1049                 }
   1050                 else {
   1051                     eError = OMX_ErrorBadPortIndex;
   1052                 }
   1053             }
   1054             break;
   1055         case OMX_IndexParamVideoAvc:
   1056             {
   1057 
   1058                 if (((OMX_VIDEO_PARAM_AVCTYPE*)(ComponentParameterStructure))->nPortIndex ==
   1059                         pComponentPrivate->pH264->nPortIndex) {
   1060                     memcpy(ComponentParameterStructure, pComponentPrivate->pH264, sizeof(OMX_VIDEO_PARAM_AVCTYPE));
   1061                 }
   1062                 else {
   1063                     eError = OMX_ErrorBadPortIndex;
   1064                 }
   1065             }
   1066             break;
   1067         case OMX_IndexParamVideoH263:
   1068             {
   1069 
   1070                 if (((OMX_VIDEO_PARAM_H263TYPE*)(ComponentParameterStructure))->nPortIndex ==
   1071                         pComponentPrivate->pH263->nPortIndex) {
   1072                     memcpy(ComponentParameterStructure, pComponentPrivate->pH263, sizeof(OMX_VIDEO_PARAM_H263TYPE));
   1073                 }
   1074                 else {
   1075                     eError = OMX_ErrorBadPortIndex;
   1076                 }
   1077             }
   1078             break;
   1079         case OMX_IndexParamCompBufferSupplier:
   1080             {
   1081                 OMX_PARAM_BUFFERSUPPLIERTYPE* pBuffSupplierParam = (OMX_PARAM_BUFFERSUPPLIERTYPE*)ComponentParameterStructure;
   1082 
   1083                 if (pBuffSupplierParam->nPortIndex == 1) {
   1084                     pBuffSupplierParam->eBufferSupplier = pComponentPrivate->pCompPort[pBuffSupplierParam->nPortIndex]->eSupplierSetting;
   1085                 }
   1086                 else if (pBuffSupplierParam->nPortIndex == 0) {
   1087                     pBuffSupplierParam->eBufferSupplier = pComponentPrivate->pCompPort[pBuffSupplierParam->nPortIndex]->eSupplierSetting;
   1088                 }
   1089                 else {
   1090                     eError = OMX_ErrorBadPortIndex;
   1091                     break;
   1092                 }
   1093             }
   1094             break;
   1095         case VideoDecodeCustomParamProcessMode:
   1096             *((OMX_U32 *)ComponentParameterStructure) = pComponentPrivate->ProcessMode;
   1097             break;
   1098         case VideoDecodeCustomParamParserEnabled:
   1099             *((OMX_BOOL *)ComponentParameterStructure) = pComponentPrivate->bParserEnabled;
   1100             break;
   1101         case VideoDecodeCustomParamH264BitStreamFormat:
   1102             *((OMX_U32 *)ComponentParameterStructure) = pComponentPrivate->H264BitStreamFormat;
   1103             break;
   1104         case VideoDecodeCustomParamWMVProfile:
   1105             {
   1106                 *((VIDDEC_WMV_PROFILES *)ComponentParameterStructure) = pComponentPrivate->wmvProfile;
   1107             }
   1108             break;
   1109         case VideoDecodeCustomParamWMVFileType:
   1110             *((OMX_U32 *)ComponentParameterStructure) = pComponentPrivate->nWMVFileType;
   1111             break;
   1112         case VideoDecodeCustomParamIsNALBigEndian:
   1113             *((OMX_BOOL *)ComponentParameterStructure) = pComponentPrivate->bIsNALBigEndian;
   1114 
   1115             break;
   1116 #ifdef VIDDEC_SPARK_CODE
   1117         case VideoDecodeCustomParamIsSparkInput:
   1118             *((OMX_U32 *)ComponentParameterStructure) = pComponentPrivate->bIsSparkInput;
   1119 
   1120             break;
   1121 #endif
   1122         case OMX_IndexParamCommonDeblocking: /**< reference: OMX_PARAM_DEBLOCKINGTYPE */
   1123         {
   1124             memcpy(ComponentParameterStructure, pComponentPrivate->pDeblockingParamType, sizeof(OMX_PARAM_DEBLOCKINGTYPE));
   1125             break;
   1126         }
   1127 #ifdef ANDROID
   1128         /* Opencore specific */
   1129         case (OMX_INDEXTYPE) PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX: /** Obtain the capabilities of the OMX component **/
   1130                 memcpy(ComponentParameterStructure, pComponentPrivate->pPVCapabilityFlags,
   1131                         sizeof(PV_OMXComponentCapabilityFlagsType));
   1132                 eError = OMX_ErrorNone;
   1133             break;
   1134 #endif
   1135         default:
   1136             eError = OMX_ErrorUnsupportedIndex;
   1137             break;
   1138         }
   1139 
   1140 EXIT:
   1141     return eError;
   1142 }
   1143 
   1144 /*----------------------------------------------------------------------------*/
   1145 /**
   1146   *  VIDDEC_CheckSetParameter() checks when it is valid calling OMX_SetParameter
   1147   *
   1148   * This method will update application callbacks
   1149   * the application.
   1150   *
   1151   * @param pComponentPrivate         handle for this instance of the component
   1152   * @param pCompParam                pointer to the parameter structure
   1153   * @param nParamIndex               parameter index
   1154   *
   1155   * @retval OMX_NoError              Success, ready to roll
   1156   *         OMX_ErrorIncorrectStateOperation   if the checks fails
   1157   **/
   1158 /*----------------------------------------------------------------------------*/
   1159 
   1160 OMX_ERRORTYPE VIDDEC_CheckSetParameter(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_PTR pCompParam, OMX_INDEXTYPE nParamIndex) {
   1161     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1162 
   1163     if (pComponentPrivate->eState == OMX_StateInvalid) {
   1164         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation);
   1165     }
   1166 
   1167     if (pComponentPrivate->eState != OMX_StateLoaded && pComponentPrivate->eState != OMX_StateWaitForResources) {
   1168         /*using OMX_CONFIG_ROTATIONTYPE because it is smallest structure that contains nPortIndex;*/
   1169         OMX_CONFIG_ROTATIONTYPE* pTempFormat = (OMX_CONFIG_ROTATIONTYPE*)pCompParam;
   1170 
   1171         switch (nParamIndex) {
   1172             /*the indices corresponding to the parameter structures containing the field "nPortIndex"*/
   1173             case OMX_IndexParamCompBufferSupplier:
   1174             case OMX_IndexParamVideoPortFormat:
   1175             case OMX_IndexParamPortDefinition:
   1176             case OMX_IndexParamVideoWmv:
   1177             case OMX_IndexParamVideoMpeg4:
   1178             case OMX_IndexParamVideoMpeg2:
   1179             case OMX_IndexParamVideoAvc:
   1180             case OMX_IndexParamVideoH263:
   1181             case OMX_IndexConfigVideoMBErrorReporting:
   1182             case OMX_IndexParamCommonDeblocking:
   1183                 if (pTempFormat->nPortIndex ==  pComponentPrivate->pInPortDef->nPortIndex) {
   1184                     if (pComponentPrivate->pInPortDef->bEnabled){
   1185                         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation);
   1186                     }
   1187                 }
   1188                 else if (pTempFormat->nPortIndex == pComponentPrivate->pOutPortDef->nPortIndex) {
   1189                     if (pComponentPrivate->pOutPortDef->bEnabled){
   1190                         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation);
   1191                     }
   1192                 }/*it cannot be -1 because structure assignment will happen on one port*/
   1193                 else {
   1194                     eError = OMX_ErrorBadPortIndex;
   1195                 }
   1196                 break;
   1197             default:
   1198                 /*all other cases where pCompParam is integer or it doesn't support nPortIndex*/
   1199                 if (!(pComponentPrivate->pInPortDef->bEnabled == OMX_FALSE ||
   1200                     pComponentPrivate->pOutPortDef->bEnabled == OMX_FALSE)) {
   1201                     OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation);
   1202                 }
   1203         }
   1204     }
   1205 EXIT:
   1206     return eError;
   1207 }
   1208 
   1209 /*----------------------------------------------------------------------------*/
   1210 /**
   1211   *  VIDDEC_SetParameter() Sets application callbacks to the component
   1212   *
   1213   * This method will update application callbacks
   1214   * the application.
   1215   *
   1216   * @param pComp         handle for this instance of the component
   1217   * @param pCallBacks    application callbacks
   1218   * @param ptr
   1219   *
   1220   * @retval OMX_NoError              Success, ready to roll
   1221   *         OMX_Error_BadParameter   The input parameter pointer is null
   1222   **/
   1223 /*----------------------------------------------------------------------------*/
   1224 
   1225 static OMX_ERRORTYPE VIDDEC_SetParameter (OMX_HANDLETYPE hComp,
   1226                                           OMX_INDEXTYPE nParamIndex,
   1227                                           OMX_PTR pCompParam)
   1228 {
   1229     OMX_COMPONENTTYPE* pHandle= NULL;
   1230     VIDDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
   1231     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1232 
   1233 #ifdef KHRONOS_1_1
   1234     OMX_PARAM_COMPONENTROLETYPE *pRole = NULL;
   1235 #endif
   1236     OMX_CONF_CHECK_CMD(hComp, pCompParam, OMX_TRUE);
   1237     pHandle= (OMX_COMPONENTTYPE*)hComp;
   1238     pComponentPrivate = pHandle->pComponentPrivate;
   1239 
   1240     eError = VIDDEC_CheckSetParameter(pComponentPrivate, pCompParam, nParamIndex);
   1241 
   1242     if (eError != OMX_ErrorNone)
   1243         OMX_CONF_SET_ERROR_BAIL(eError , OMX_ErrorIncorrectStateOperation);
   1244 
   1245     switch (nParamIndex) {
   1246         case OMX_IndexParamVideoPortFormat:
   1247             {
   1248                 OMX_VIDEO_PARAM_PORTFORMATTYPE* pPortFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE*)pCompParam;
   1249                 if (pPortFormat->nPortIndex == pComponentPrivate->pInPortFormat->nPortIndex) {
   1250                     if(pPortFormat->eColorFormat == OMX_COLOR_FormatUnused) {
   1251                         switch (pPortFormat->eCompressionFormat) {
   1252                             case OMX_VIDEO_CodingH263:
   1253                                 pComponentPrivate->pInPortDef->format.video.eCompressionFormat  = OMX_VIDEO_CodingH263;
   1254                                 break;
   1255                             case OMX_VIDEO_CodingAVC:
   1256                                 pComponentPrivate->pInPortDef->format.video.eCompressionFormat  = OMX_VIDEO_CodingAVC;
   1257                                 OMX_PRINT1(pComponentPrivate->dbg, "eCompressionFormat = OMX_VIDEO_CodingAVC\n");
   1258                                 break;
   1259                             case OMX_VIDEO_CodingMPEG2:
   1260                                 pComponentPrivate->pInPortDef->format.video.eCompressionFormat  = OMX_VIDEO_CodingMPEG2;
   1261                                 break;
   1262                             case OMX_VIDEO_CodingMPEG4:
   1263                                 OMX_PRINT1(pComponentPrivate->dbg, "eCompressionFormat = OMX_VIDEO_CodingMPEG4\n");
   1264                                 pComponentPrivate->pInPortDef->format.video.eCompressionFormat  = OMX_VIDEO_CodingMPEG4;
   1265                                 break;
   1266                             case OMX_VIDEO_CodingWMV:
   1267                                 OMX_PRINT1(pComponentPrivate->dbg, "eCompressionFormat = OMX_VIDEO_CodingWMV\n");
   1268                                 pComponentPrivate->pInPortDef->format.video.eCompressionFormat  = OMX_VIDEO_CodingWMV;
   1269                                 break;
   1270 
   1271 #ifdef VIDDEC_SPARK_CODE
   1272                             case OMX_VIDEO_CodingUnused:
   1273                                 if (pComponentPrivate->bIsSparkInput) {
   1274                                     pComponentPrivate->pInPortDef->format.video.eCompressionFormat  = OMX_VIDEO_CodingUnused;
   1275                                 }
   1276                                 else {
   1277                                     eError = OMX_ErrorNoMore;
   1278                                 }
   1279                                 break;
   1280 #endif
   1281                             default:
   1282                                 eError = OMX_ErrorNoMore;
   1283                                 break;
   1284                         }
   1285                     }
   1286                     else {
   1287                         eError = OMX_ErrorBadParameter;
   1288                     }
   1289                     if(eError == OMX_ErrorNone) {
   1290                         memcpy(pComponentPrivate->pInPortFormat, pPortFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
   1291                     }
   1292                 }
   1293                 else if (pPortFormat->nPortIndex == pComponentPrivate->pOutPortFormat->nPortIndex) {
   1294                     if(pPortFormat->eCompressionFormat == OMX_VIDEO_CodingUnused) {
   1295                         switch (pPortFormat->eColorFormat) {
   1296                             case OMX_COLOR_FormatYUV420Planar:
   1297                                 pComponentPrivate->pOutPortDef->format.video.eColorFormat = VIDDEC_COLORFORMAT420;
   1298                                 break;
   1299                             case OMX_COLOR_FormatCbYCrY:
   1300                                 pComponentPrivate->pOutPortDef->format.video.eColorFormat = VIDDEC_COLORFORMAT422;
   1301                                 break;
   1302                             default:
   1303                                 eError = OMX_ErrorNoMore;
   1304                                 break;
   1305                         }
   1306                     }
   1307                     else {
   1308                         eError = OMX_ErrorBadParameter;
   1309                     }
   1310                     if(eError == OMX_ErrorNone) {
   1311                         memcpy(pComponentPrivate->pOutPortFormat, pPortFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
   1312                     }
   1313                 }
   1314                 else {
   1315                     eError = OMX_ErrorBadPortIndex;
   1316                 }
   1317             }
   1318             break;
   1319         case OMX_IndexParamVideoInit:
   1320             memcpy(pComponentPrivate->pPortParamType, (OMX_PORT_PARAM_TYPE*)pCompParam, sizeof(OMX_PORT_PARAM_TYPE));
   1321             break;
   1322 #ifdef __STD_COMPONENT__
   1323         case OMX_IndexParamAudioInit:
   1324             memcpy(pComponentPrivate->pPortParamTypeAudio, (OMX_PORT_PARAM_TYPE*)pCompParam, sizeof(OMX_PORT_PARAM_TYPE));
   1325             break;
   1326         case OMX_IndexParamImageInit:
   1327             memcpy(pComponentPrivate->pPortParamTypeImage, (OMX_PORT_PARAM_TYPE*)pCompParam, sizeof(OMX_PORT_PARAM_TYPE));
   1328             break;
   1329         case OMX_IndexParamOtherInit:
   1330             memcpy(pComponentPrivate->pPortParamTypeOthers, (OMX_PORT_PARAM_TYPE*)pCompParam, sizeof(OMX_PORT_PARAM_TYPE));
   1331             break;
   1332 #endif
   1333         case OMX_IndexParamPortDefinition:
   1334             {
   1335                 OMX_PARAM_PORTDEFINITIONTYPE* pComponentParam = (OMX_PARAM_PORTDEFINITIONTYPE*)pCompParam;
   1336                 if (pComponentParam->nPortIndex == pComponentPrivate->pInPortDef->nPortIndex) {
   1337                     OMX_PARAM_PORTDEFINITIONTYPE *pPortDefParam = (OMX_PARAM_PORTDEFINITIONTYPE *)pComponentParam;
   1338                     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = pComponentPrivate->pInPortDef;
   1339                     memcpy(pPortDef, pPortDefParam, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
   1340                     if ( pPortDef->nBufferSize == 0 )
   1341                     {
   1342                         pPortDef->nBufferSize = pPortDef->format.video.nFrameWidth *
   1343                                                 pPortDef->format.video.nFrameHeight;
   1344                     }
   1345 
   1346                     OMX_PRINT1(pComponentPrivate->dbg, "Set i/p size: %dx%d", pPortDefParam->format.video.nFrameWidth, pPortDefParam->format.video.nFrameHeight);
   1347                 }
   1348                 else if (pComponentParam->nPortIndex == pComponentPrivate->pOutPortDef->nPortIndex) {
   1349                     OMX_PARAM_PORTDEFINITIONTYPE *pPortDefParam = (OMX_PARAM_PORTDEFINITIONTYPE *)pComponentParam;
   1350                     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = pComponentPrivate->pOutPortDef;
   1351                     memcpy(pPortDef, pPortDefParam, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
   1352                     pPortDef->nBufferSize = pPortDef->format.video.nFrameWidth *
   1353                                             pPortDef->format.video.nFrameHeight *
   1354                                             ((pComponentPrivate->pOutPortFormat->eColorFormat == VIDDEC_COLORFORMAT420) ? VIDDEC_FACTORFORMAT420 : VIDDEC_FACTORFORMAT422);
   1355 
   1356                     OMX_PRINT1(pComponentPrivate->dbg, "Set OUT/p size: %dx%d", pPortDefParam->format.video.nFrameWidth, pPortDefParam->format.video.nFrameHeight);
   1357                 }
   1358                 else {
   1359                     eError = OMX_ErrorBadPortIndex;
   1360                 }
   1361                 OMX_PRBUFFER1(pComponentPrivate->dbg, "CountActual 0x%x CountMin 0x%x Size %d bEnabled %x bPopulated %x\n",
   1362                                 (int )pComponentParam->nBufferCountActual,
   1363                                 (int )pComponentParam->nBufferCountMin,
   1364                                 (int )pComponentParam->nBufferSize,
   1365                                 (int )pComponentParam->bEnabled,
   1366                                 (int )pComponentParam->bPopulated);
   1367             }
   1368             break;
   1369         case OMX_IndexParamVideoWmv:
   1370             {
   1371                 OMX_VIDEO_PARAM_WMVTYPE* pComponentParam = (OMX_VIDEO_PARAM_WMVTYPE*)pCompParam;
   1372                 if (pComponentParam->nPortIndex == pComponentPrivate->pWMV->nPortIndex) {
   1373                     memcpy(pComponentPrivate->pWMV, pCompParam, sizeof(OMX_VIDEO_PARAM_WMVTYPE));
   1374                 }
   1375                 else {
   1376                     eError = OMX_ErrorBadPortIndex;
   1377                 }
   1378             }
   1379             break;
   1380         case OMX_IndexParamVideoMpeg4:
   1381             {
   1382                 OMX_VIDEO_PARAM_MPEG4TYPE* pComponentParam = (OMX_VIDEO_PARAM_MPEG4TYPE*)pCompParam;
   1383                 if (pComponentParam->nPortIndex == pComponentPrivate->pMpeg4->nPortIndex) {
   1384                     memcpy(pComponentPrivate->pMpeg4, pCompParam, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE));
   1385                 }
   1386                 else {
   1387                     eError = OMX_ErrorBadPortIndex;
   1388                 }
   1389             }
   1390             break;
   1391         case OMX_IndexParamVideoMpeg2:
   1392             {
   1393                 OMX_VIDEO_PARAM_MPEG2TYPE* pComponentParam = (OMX_VIDEO_PARAM_MPEG2TYPE*)pCompParam;
   1394                 if (pComponentParam->nPortIndex == pComponentPrivate->pMpeg2->nPortIndex) {
   1395                     memcpy(pComponentPrivate->pMpeg2, pCompParam, sizeof(OMX_VIDEO_PARAM_MPEG2TYPE));
   1396                 }
   1397                 else {
   1398                     eError = OMX_ErrorBadPortIndex;
   1399                 }
   1400             }
   1401             break;
   1402         case OMX_IndexParamVideoAvc:
   1403             {
   1404                 OMX_VIDEO_PARAM_AVCTYPE* pComponentParam = (OMX_VIDEO_PARAM_AVCTYPE *)pCompParam;
   1405                 if (pComponentParam->nPortIndex == pComponentPrivate->pH264->nPortIndex) {
   1406                     memcpy(pComponentPrivate->pH264, pCompParam, sizeof(OMX_VIDEO_PARAM_AVCTYPE));
   1407                 }
   1408                 else {
   1409                     eError = OMX_ErrorBadPortIndex;
   1410                 }
   1411             }
   1412             break;
   1413         case OMX_IndexParamVideoH263:
   1414             {
   1415                 OMX_VIDEO_PARAM_H263TYPE* pComponentParam = (OMX_VIDEO_PARAM_H263TYPE *)pCompParam;
   1416                 if (pComponentParam->nPortIndex == pComponentPrivate->pH263->nPortIndex) {
   1417                     memcpy(pComponentPrivate->pH263, pCompParam, sizeof(OMX_VIDEO_PARAM_H263TYPE));
   1418                 }
   1419                 else {
   1420                     eError = OMX_ErrorBadPortIndex;
   1421                 }
   1422             }
   1423             break;
   1424         case OMX_IndexParamPriorityMgmt:
   1425             memcpy(pComponentPrivate->pPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, sizeof(OMX_PRIORITYMGMTTYPE));
   1426             break;
   1427         case OMX_IndexParamCompBufferSupplier:
   1428             {
   1429                 OMX_PARAM_BUFFERSUPPLIERTYPE* pBuffSupplierParam = (OMX_PARAM_BUFFERSUPPLIERTYPE*)pCompParam;
   1430 
   1431                 if (pBuffSupplierParam->nPortIndex == 1) {
   1432                     pComponentPrivate->pCompPort[pBuffSupplierParam->nPortIndex]->eSupplierSetting = pBuffSupplierParam->eBufferSupplier;
   1433                 }
   1434                 else if (pBuffSupplierParam->nPortIndex == 0) {
   1435                     pComponentPrivate->pCompPort[pBuffSupplierParam->nPortIndex]->eSupplierSetting = pBuffSupplierParam->eBufferSupplier;
   1436                 }
   1437                 else {
   1438                     eError = OMX_ErrorBadPortIndex;
   1439                     break;
   1440                 }
   1441             }
   1442             break;
   1443         /* Video decode custom parameters */
   1444         case VideoDecodeCustomParamProcessMode:
   1445             pComponentPrivate->ProcessMode = (OMX_U32)(*((OMX_U32 *)pCompParam));
   1446             break;
   1447         case VideoDecodeCustomParamParserEnabled:
   1448             pComponentPrivate->bParserEnabled = (OMX_BOOL)(*((OMX_BOOL *)pCompParam));
   1449             break;
   1450         case VideoDecodeCustomParamH264BitStreamFormat:
   1451             pComponentPrivate->H264BitStreamFormat = (OMX_U32)(*((OMX_U32 *)pCompParam));
   1452             break;
   1453         case VideoDecodeCustomParamWMVProfile:
   1454             {
   1455                 pComponentPrivate->wmvProfile = *((VIDDEC_WMV_PROFILES *)pCompParam);
   1456             }
   1457             break;
   1458 #ifdef KHRONOS_1_1
   1459         case OMX_IndexParamStandardComponentRole:
   1460             if (pCompParam != NULL) {
   1461                 OMX_U8* cTempRole = NULL;
   1462                 cTempRole = (OMX_U8*)pComponentPrivate->componentRole.cRole;
   1463                 pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam;
   1464                 /*OMX_CONF_CHK_VERSION( pRole, OMX_PARAM_COMPONENTROLETYPE, eError, pComponentPrivate->dbg);*/
   1465                 if(strcmp( (char*)pRole->cRole, VIDDEC_COMPONENTROLES_H263) == 0) {
   1466                     eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_H263);
   1467                 }
   1468                 else if(strcmp( (char*)pRole->cRole, VIDDEC_COMPONENTROLES_H264) == 0) {
   1469                     eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_H264);
   1470                 }
   1471                 else if(strcmp( (char*)pRole->cRole, VIDDEC_COMPONENTROLES_MPEG2) == 0) {
   1472                     eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_MPEG2);
   1473                 }
   1474                 else if(strcmp( (char*)pRole->cRole, VIDDEC_COMPONENTROLES_MPEG4) == 0) {
   1475                     eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_MPEG4);
   1476                 }
   1477                 else if(strcmp( (char*)pRole->cRole, VIDDEC_COMPONENTROLES_WMV9) == 0) {
   1478                     eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_WMV9);
   1479                 }
   1480 #ifdef VIDDEC_SPARK_CODE
   1481                 else if(strcmp( (char*)pRole->cRole, VIDDEC_COMPONENTROLES_SPARK) == 0) {
   1482                     eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_SPARK);
   1483                 }
   1484 #endif
   1485                 else {
   1486                     eError = OMX_ErrorBadParameter;
   1487                 }
   1488                 if(eError != OMX_ErrorNone) {
   1489                     goto EXIT;
   1490                 }
   1491 #ifdef ANDROID
   1492                 /* Set format according with hw accelerated rendering */
   1493                 if( pComponentPrivate->pOutPortFormat->eColorFormat != VIDDEC_COLORFORMAT422) {
   1494                     eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_INTERLEAVED422);
   1495                 }
   1496 #else
   1497                 if( pComponentPrivate->pOutPortFormat->eColorFormat != VIDDEC_COLORFORMAT420) {
   1498                     eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_PLANAR420);
   1499                 }
   1500 #endif
   1501                 memcpy( (void *)&pComponentPrivate->componentRole, (void *)pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
   1502             }
   1503             else {
   1504                 eError = OMX_ErrorBadParameter;
   1505             }
   1506             break;
   1507 #endif
   1508         case VideoDecodeCustomParamWMVFileType:
   1509             pComponentPrivate->nWMVFileType = (OMX_U32)(*((OMX_U32 *)pCompParam));
   1510 
   1511             break;
   1512         case VideoDecodeCustomParamIsNALBigEndian:
   1513             pComponentPrivate->bIsNALBigEndian = (OMX_BOOL)(*((OMX_BOOL *)pCompParam));
   1514             break;
   1515 #ifdef VIDDEC_SPARK_CODE
   1516         case VideoDecodeCustomParamIsSparkInput:
   1517             pComponentPrivate->bIsSparkInput = (OMX_BOOL)(*((OMX_BOOL *)pCompParam));
   1518             break;
   1519 #endif
   1520 #ifdef KHRONOS_1_1
   1521         case OMX_IndexConfigVideoMBErrorReporting:/**< reference: OMX_CONFIG_MBERRORREPORTINGTYPE */
   1522         {
   1523             if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
   1524                 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263 ||
   1525                 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
   1526                 OMX_CONFIG_MBERRORREPORTINGTYPE* pMBErrorReportFrom = pCompParam;
   1527                 /*OMX_CONF_CHK_VERSION( pMBErrorReportFrom, OMX_CONFIG_MBERRORREPORTINGTYPE, eError, pComponentPrivate->dbg);*/
   1528                 pComponentPrivate->eMBErrorReport.bEnabled = pMBErrorReportFrom->bEnabled;
   1529             }
   1530             else {
   1531                 eError = OMX_ErrorUnsupportedIndex;
   1532             }
   1533             break;
   1534         }
   1535         case OMX_IndexParamCommonDeblocking: /**< reference: OMX_PARAM_DEBLOCKINGTYPE */
   1536         {
   1537             char value[PROPERTY_VALUE_MAX];
   1538             property_get("debug.video.showfps", value, "0");
   1539             mDebugFps = atoi(value);
   1540             ALOGD_IF(mDebugFps, "Not setting deblocking to measure fps");
   1541             if (mDebugFps == OMX_FALSE) {
   1542                 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
   1543                         pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263){
   1544                         /*pComponentPrivate->pDeblockingParamType->bDeblocking =
   1545                             ((OMX_PARAM_DEBLOCKINGTYPE*)pCompParam)->bDeblocking;*/
   1546                         /*codec is not supporting deblocking by now*/
   1547                         pComponentPrivate->pDeblockingParamType->bDeblocking = OMX_FALSE;
   1548                         eError = OMX_ErrorUnsupportedIndex;
   1549                     break;
   1550                 }
   1551             }
   1552             else {
   1553                 eError = OMX_ErrorUnsupportedIndex;
   1554                 break;
   1555             }
   1556         }
   1557 
   1558         case OMX_IndexParamVideoMacroblocksPerFrame:
   1559         case OMX_IndexParamNumAvailableStreams:
   1560         case OMX_IndexParamActiveStream:
   1561         case OMX_IndexParamSuspensionPolicy:
   1562         case OMX_IndexParamComponentSuspended:
   1563         case OMX_IndexAutoPauseAfterCapture:
   1564         case OMX_IndexParamCustomContentPipe:
   1565         case OMX_IndexParamDisableResourceConcealment:
   1566 #ifdef KHRONOS_1_2
   1567             case OMX_IndexConfigMetadataItemCount:
   1568             case OMX_IndexConfigContainerNodeCount:
   1569             case OMX_IndexConfigMetadataItem:
   1570             case OMX_IndexConfigCounterNodeID:
   1571             case OMX_IndexParamMetadataFilterType:
   1572             case OMX_IndexConfigCommonTransitionEffect:
   1573             case OMX_IndexKhronosExtensions:
   1574 #else
   1575             case OMX_IndexConfigMetaDataSize:
   1576             case OMX_IndexConfigMetaDataAtIndex:
   1577             case OMX_IndexConfigMetaDataAtKey:
   1578             case OMX_IndexConfigMetaDataNodeCount:
   1579             case OMX_IndexConfigMetaDataNode:
   1580             case OMX_IndexConfigMetaDataItemCount:
   1581 #endif
   1582         case OMX_IndexParamMetadataKeyFilter:
   1583         case OMX_IndexConfigPriorityMgmt:
   1584         case OMX_IndexConfigAudioChannelVolume:
   1585         case OMX_IndexConfigFlashControl:
   1586         case OMX_IndexParamVideoProfileLevelQuerySupported:
   1587            break;
   1588         case OMX_IndexParamVideoProfileLevelCurrent:
   1589         {
   1590            VIDEO_PROFILE_LEVEL_TYPE* pProfileLevel = NULL;
   1591            OMX_VIDEO_PARAM_PROFILELEVELTYPE *pParamProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pCompParam;
   1592 
   1593            /* Choose table based on compression format */
   1594            switch(pComponentPrivate->pInPortDef->format.video.eCompressionFormat)
   1595            {
   1596               case OMX_VIDEO_CodingH263:
   1597                  pProfileLevel = SupportedH263ProfileLevels;
   1598                  break;
   1599               case OMX_VIDEO_CodingMPEG4:
   1600                  pProfileLevel = SupportedMPEG4ProfileLevels;
   1601                  break;
   1602               case OMX_VIDEO_CodingAVC:
   1603                  pProfileLevel = SupportedAVCProfileLevels;
   1604                  break;
   1605              default:
   1606                  return OMX_ErrorBadParameter;
   1607             }
   1608 
   1609             /* Check validity of profile & level parameters */
   1610             while((pProfileLevel->nProfile != (OMX_S32)pParamProfileLevel->eProfile) ||
   1611                  (pProfileLevel->nLevel != (OMX_S32)pParamProfileLevel->eLevel)) {
   1612                pProfileLevel++;
   1613                if(pProfileLevel->nProfile == -1) break;
   1614              }
   1615 
   1616             if(pProfileLevel->nProfile != -1) {
   1617             /* Update profile & level values in the compression format specific structure */
   1618                switch(pComponentPrivate->pInPortDef->format.video.eCompressionFormat) {
   1619                   case OMX_VIDEO_CodingH263:
   1620                      pComponentPrivate->pH263->eProfile = pParamProfileLevel->eProfile;
   1621                      pComponentPrivate->pH263->eLevel = pParamProfileLevel->eLevel;
   1622                      break;
   1623                   case OMX_VIDEO_CodingMPEG4:
   1624                      pComponentPrivate->pMpeg4->eProfile = pParamProfileLevel->eProfile;
   1625                      pComponentPrivate->pMpeg4->eLevel = pParamProfileLevel->eLevel;
   1626                      break;
   1627                   case OMX_VIDEO_CodingAVC:
   1628                      pComponentPrivate->pH264->eProfile = pParamProfileLevel->eProfile;
   1629                      pComponentPrivate->pH264->eLevel = pParamProfileLevel->eLevel;
   1630                  default:
   1631                      return OMX_ErrorBadParameter;
   1632                }
   1633                eError = OMX_ErrorNone;
   1634             }
   1635             else {
   1636                eError = OMX_ErrorBadParameter;
   1637             }
   1638             break;
   1639             }
   1640 
   1641         case OMX_IndexConfigVideoBitrate:
   1642         case OMX_IndexConfigVideoFramerate:
   1643         case OMX_IndexConfigVideoIntraVOPRefresh:
   1644         case OMX_IndexConfigVideoIntraMBRefresh:
   1645         case OMX_IndexConfigVideoMacroBlockErrorMap:
   1646         case OMX_IndexParamVideoSliceFMO:
   1647         case OMX_IndexConfigVideoAVCIntraPeriod:
   1648         case OMX_IndexConfigVideoNalSize:
   1649         case OMX_IndexConfigCommonExposureValue:
   1650         case OMX_IndexConfigCommonOutputSize:
   1651         case OMX_IndexParamCommonExtraQuantData:
   1652         case OMX_IndexConfigCommonFocusRegion:
   1653         case OMX_IndexConfigCommonFocusStatus:
   1654         case OMX_IndexParamContentURI:
   1655         case OMX_IndexConfigCaptureMode:
   1656         case OMX_IndexConfigCapturing:
   1657 #endif
   1658         default:
   1659             eError = OMX_ErrorUnsupportedIndex;
   1660             break;
   1661     }
   1662 EXIT:
   1663     return eError;
   1664 }
   1665 
   1666 /*----------------------------------------------------------------------------*/
   1667 /**
   1668   *  VIDDEC_GetConfig() Sets application callbacks to the component
   1669   *
   1670   * This method will update application callbacks
   1671   * the application.
   1672   *
   1673   * @param pComp         handle for this instance of the component
   1674   * @param pCallBacks    application callbacks
   1675   * @param ptr
   1676   *
   1677   * @retval OMX_NoError              Success, ready to roll
   1678   *         OMX_Error_BadParameter   The input parameter pointer is null
   1679   **/
   1680 /*----------------------------------------------------------------------------*/
   1681 
   1682 static OMX_ERRORTYPE VIDDEC_GetConfig (OMX_HANDLETYPE hComp,
   1683                                        OMX_INDEXTYPE nConfigIndex,
   1684                                        OMX_PTR ComponentConfigStructure)
   1685 {
   1686     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1687     OMX_COMPONENTTYPE* pHandle = NULL;
   1688     VIDDEC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
   1689 
   1690     OMX_CONF_CHECK_CMD(hComp, ComponentConfigStructure, OMX_TRUE);
   1691 
   1692     pHandle = (OMX_COMPONENTTYPE*)hComp;
   1693     pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
   1694 
   1695     if (pComponentPrivate->eState == OMX_StateInvalid) {
   1696         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation);
   1697     }
   1698     else {
   1699         switch ((OMX_S32) nConfigIndex)
   1700         {
   1701             case OMX_IndexParamPortDefinition:
   1702                 {
   1703                     OMX_PARAM_PORTDEFINITIONTYPE *pPortDefParam = (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentConfigStructure;
   1704                     if (((OMX_PARAM_PORTDEFINITIONTYPE*)(ComponentConfigStructure))->nPortIndex ==
   1705                             pComponentPrivate->pInPortDef->nPortIndex) {
   1706                         OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = pComponentPrivate->pInPortDef;
   1707                         memcpy(pPortDefParam, pPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
   1708                     }
   1709                     else if (((OMX_PARAM_PORTDEFINITIONTYPE*)(ComponentConfigStructure))->nPortIndex ==
   1710                             pComponentPrivate->pOutPortDef->nPortIndex) {
   1711                         OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = pComponentPrivate->pOutPortDef;
   1712                         memcpy(pPortDefParam, pPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
   1713                     }
   1714                     else {
   1715                         eError = OMX_ErrorBadPortIndex;
   1716                     }
   1717                 }
   1718                 break;
   1719             case VideoDecodeCustomConfigDebug:/**< reference: struct OMX_TI_Debug */
   1720                 OMX_DBG_GETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
   1721                 break;
   1722 #ifdef KHRONOS_1_1
   1723             case OMX_IndexConfigVideoMBErrorReporting:/**< reference: OMX_CONFIG_MBERRORREPORTINGTYPE */
   1724             {
   1725                 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
   1726                     pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263 ||
   1727                     pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
   1728                     OMX_CONFIG_MBERRORREPORTINGTYPE* pMBErrorReportTo = ComponentConfigStructure;
   1729                     /*OMX_CONF_CHK_VERSION( pMBErrorReportTo, OMX_CONFIG_MBERRORREPORTINGTYPE, eError, pComponentPrivate->dbg);*/
   1730                     pMBErrorReportTo->bEnabled = pComponentPrivate->eMBErrorReport.bEnabled;
   1731                 }
   1732                 else {
   1733                     eError = OMX_ErrorUnsupportedIndex;
   1734                 }
   1735                 break;
   1736             }
   1737             case OMX_IndexConfigVideoMacroBlockErrorMap: /**< reference: OMX_CONFIG_MACROBLOCKERRORMAPTYPE */
   1738             {
   1739                 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
   1740                     pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263 ||
   1741                     pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
   1742                     OMX_CONFIG_MACROBLOCKERRORMAPTYPE_TI* pMBErrorMapTypeFrom = &pComponentPrivate->eMBErrorMapType[pComponentPrivate->cMBErrorIndexOut];
   1743                     OMX_CONFIG_MACROBLOCKERRORMAPTYPE_TI* pMBErrorMapTypeTo = ComponentConfigStructure;
   1744                     OMX_U8* ErrMapFrom = pMBErrorMapTypeFrom->ErrMap;
   1745                     OMX_U8* ErrMapTo = pMBErrorMapTypeTo->ErrMap;
   1746                     /*OMX_CONF_CHK_VERSION( pRole, OMX_CONFIG_MBERRORREPORTINGTYPE, eError, pComponentPrivate->dbg);*/
   1747                     pMBErrorMapTypeTo->nErrMapSize = pMBErrorMapTypeFrom->nErrMapSize;
   1748                     memcpy(ErrMapTo, ErrMapFrom, pMBErrorMapTypeFrom->nErrMapSize);
   1749                     pComponentPrivate->cMBErrorIndexOut++;
   1750                     pComponentPrivate->cMBErrorIndexOut %= pComponentPrivate->pOutPortDef->nBufferCountActual;
   1751                 }
   1752                 else {
   1753                     eError = OMX_ErrorUnsupportedIndex;
   1754                 }
   1755                 break;
   1756             }
   1757             case OMX_IndexParamVideoMacroblocksPerFrame:/**< reference: OMX_PARAM_MACROBLOCKSTYPE */
   1758             {
   1759                 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
   1760                     pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263 ||
   1761                     pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
   1762                     OMX_PARAM_MACROBLOCKSTYPE* pMBBlocksTypeTo = ComponentConfigStructure;
   1763                     /*OMX_CONF_CHK_VERSION( pMBBlocksTypeTo, OMX_PARAM_MACROBLOCKSTYPE, eError, pComponentPrivate->dbg);*/
   1764                     pMBBlocksTypeTo->nMacroblocks = pComponentPrivate->pOutPortDef->format.video.nFrameWidth *
   1765                                                     pComponentPrivate->pOutPortDef->format.video.nFrameHeight / 256;
   1766                 }
   1767                 else {
   1768                     eError = OMX_ErrorUnsupportedIndex;
   1769                 }
   1770                 break;
   1771             }
   1772             case OMX_IndexParamNumAvailableStreams:
   1773             case OMX_IndexParamActiveStream:
   1774             case OMX_IndexParamSuspensionPolicy:
   1775             case OMX_IndexParamComponentSuspended:
   1776             case OMX_IndexAutoPauseAfterCapture:
   1777             case OMX_IndexParamCustomContentPipe:
   1778             case OMX_IndexParamDisableResourceConcealment:
   1779 #ifdef KHRONOS_1_2
   1780             case OMX_IndexConfigMetadataItemCount:
   1781             case OMX_IndexConfigContainerNodeCount:
   1782             case OMX_IndexConfigMetadataItem:
   1783             case OMX_IndexConfigCounterNodeID:
   1784             case OMX_IndexParamMetadataFilterType:
   1785             case OMX_IndexConfigCommonTransitionEffect:
   1786             case OMX_IndexKhronosExtensions:
   1787 #else
   1788             case OMX_IndexConfigMetaDataSize:
   1789             case OMX_IndexConfigMetaDataAtIndex:
   1790             case OMX_IndexConfigMetaDataAtKey:
   1791             case OMX_IndexConfigMetaDataNodeCount:
   1792             case OMX_IndexConfigMetaDataNode:
   1793             case OMX_IndexConfigMetaDataItemCount:
   1794 #endif
   1795             case OMX_IndexParamMetadataKeyFilter:
   1796             case OMX_IndexConfigPriorityMgmt:
   1797             case OMX_IndexParamStandardComponentRole:
   1798             case OMX_IndexConfigAudioChannelVolume:
   1799             case OMX_IndexConfigFlashControl:
   1800             case OMX_IndexParamVideoProfileLevelQuerySupported:
   1801             case OMX_IndexParamVideoProfileLevelCurrent:
   1802             case OMX_IndexConfigVideoBitrate:
   1803             case OMX_IndexConfigVideoFramerate:
   1804             case OMX_IndexConfigVideoIntraVOPRefresh:
   1805             case OMX_IndexConfigVideoIntraMBRefresh:
   1806             case OMX_IndexParamVideoSliceFMO:
   1807             case OMX_IndexConfigVideoAVCIntraPeriod:
   1808             case OMX_IndexConfigVideoNalSize:
   1809             case OMX_IndexConfigCommonExposureValue:
   1810             case OMX_IndexConfigCommonOutputSize:
   1811             case OMX_IndexParamCommonExtraQuantData:
   1812             case OMX_IndexConfigCommonFocusRegion:
   1813             case OMX_IndexConfigCommonFocusStatus:
   1814             case OMX_IndexParamContentURI:
   1815             case OMX_IndexConfigCaptureMode:
   1816             case OMX_IndexConfigCapturing:
   1817 #endif
   1818             case OMX_IndexComponentStartUnused:
   1819             case OMX_IndexParamPriorityMgmt:    /**< reference: OMX_PRIORITYMGMTTYPE */
   1820             case OMX_IndexParamAudioInit:       /**< reference: OMX_PORT_PARAM_TYPE  */
   1821             case OMX_IndexParamImageInit:       /**< reference: OMX_PORT_PARAM_TYPE  */
   1822             case OMX_IndexParamVideoInit:       /**< reference: OMX_PORT_PARAM_TYPE  */
   1823             case OMX_IndexParamOtherInit:       /**< reference: OMX_PORT_PARAM_TYPE  */
   1824 
   1825             case OMX_IndexPortStartUnused:
   1826             case OMX_IndexParamCompBufferSupplier: /**< reference: OMX_PARAM_BUFFERSUPPLIERTYPE (*/
   1827             case OMX_IndexReservedStartUnused:
   1828 
   1829             /* Audio parameters and configurations */
   1830             case OMX_IndexAudioStartUnused:
   1831             case OMX_IndexParamAudioPortFormat: /**< reference: OMX_AUDIO_PARAM_PORTFORMATTYPE */
   1832             case OMX_IndexParamAudioPcm:        /**< reference: OMX_AUDIO_PARAM_PCMMODETYPE */
   1833             case OMX_IndexParamAudioAac:        /**< reference: OMX_AUDIO_PARAM_AACPROFILETYPE */
   1834             case OMX_IndexParamAudioRa:         /**< reference: OMX_AUDIO_PARAM_RATYPE */
   1835             case OMX_IndexParamAudioMp3:        /**< reference: OMX_AUDIO_PARAM_MP3TYPE */
   1836             case OMX_IndexParamAudioAdpcm:      /**< reference: OMX_AUDIO_PARAM_ADPCMTYPE */
   1837             case OMX_IndexParamAudioG723:       /**< reference: OMX_AUDIO_PARAM_G723TYPE */
   1838             case OMX_IndexParamAudioG729:       /**< reference: OMX_AUDIO_PARAM_G729TYPE */
   1839             case OMX_IndexParamAudioAmr:        /**< reference: OMX_AUDIO_PARAM_AMRTYPE */
   1840             case OMX_IndexParamAudioWma:        /**< reference: OMX_AUDIO_PARAM_WMATYPE */
   1841             case OMX_IndexParamAudioSbc:        /**< reference: OMX_AUDIO_PARAM_SBCTYPE */
   1842             case OMX_IndexParamAudioMidi:       /**< reference: OMX_AUDIO_PARAM_MIDITYPE */
   1843             case OMX_IndexParamAudioGsm_FR:     /**< reference: OMX_AUDIO_PARAM__GSMFRTYPE */
   1844             case OMX_IndexParamAudioMidiLoadUserSound: /**< reference: OMX_AUDIO_PARAM_MIDILOADUSERSOUNDTYPE */
   1845             case OMX_IndexParamAudioG726:       /**< reference: OMX_AUDIO_PARAM_G726TYPE */
   1846             case OMX_IndexParamAudioGsm_EFR:    /**< reference: OMX_AUDIO_PARAM__GSMEFRTYPE */
   1847             case OMX_IndexParamAudioGsm_HR:     /**< reference: OMX_AUDIO_PARAM__GSMHRTYPE */
   1848             case OMX_IndexParamAudioPdc_FR:     /**< reference: OMX_AUDIO_PARAM__PDCFRTYPE */
   1849             case OMX_IndexParamAudioPdc_EFR:    /**< reference: OMX_AUDIO_PARAM__PDCEFRTYPE */
   1850             case OMX_IndexParamAudioPdc_HR:     /**< reference: OMX_AUDIO_PARAM__PDCHRTYPE */
   1851             case OMX_IndexParamAudioTdma_FR:    /**< reference: OMX_AUDIO_PARAM__TDMAFRTYPE */
   1852             case OMX_IndexParamAudioTdma_EFR:   /**< reference: OMX_AUDIO_PARAM__TDMAEFRTYPE */
   1853             case OMX_IndexParamAudioQcelp8:     /**< reference: OMX_AUDIO_PARAM__QCELP8TYPE */
   1854             case OMX_IndexParamAudioQcelp13:    /**< reference: OMX_AUDIO_PARAM__QCELP13TYPE */
   1855             case OMX_IndexParamAudioEvrc:       /**< reference: OMX_AUDIO_PARAM__EVRCTYPE */
   1856             case OMX_IndexParamAudioSmv:        /**< reference: OMX_AUDIO_PARAM__SMVTYPE */
   1857             case OMX_IndexParamAudioVorbis:     /**< reference: OMX_AUDIO_PARAM__VORBISTYPE */
   1858 
   1859             case OMX_IndexConfigAudioMidiImmediateEvent:   /**< OMX_AUDIO_CONFIG_MIDIIMMEDIATEEVENTTYPE */
   1860             case OMX_IndexConfigAudioMidiControl:          /**< reference: OMX_AUDIO_CONFIG_MIDICONTROLTYPE */
   1861             case OMX_IndexConfigAudioMidiSoundBankProgram: /**< reference: OMX_AUDIO_CONFIG_MIDISOUNDBANKPROGRAMTYPE */
   1862             case OMX_IndexConfigAudioMidiStatus:           /**< reference: OMX_AUDIO_CONFIG_MIDISTATUSTYPE */
   1863             case OMX_IndexConfigAudioMidiMetaEvent:        /**< reference: OMX_AUDIO_CONFIG_MIDIMETAEVENTTYPE */
   1864             case OMX_IndexConfigAudioMidiMetaEventData:    /**< reference: OMX_AUDIO_CONFIG_MIDIMETAEVENTDATATYPE */
   1865             case OMX_IndexConfigAudioVolume:               /**< reference: OMX_AUDIO_CONFIG_VOLUMETYPE */
   1866             case OMX_IndexConfigAudioBalance:              /**< reference: OMX_AUDIO_CONFIG_BALANCETYPE */
   1867             case OMX_IndexConfigAudioChannelMute:          /**< reference: OMX_AUDIO_CONFIG_CHANNELMUTETYPE */
   1868             case OMX_IndexConfigAudioMute:                 /**< reference: OMX_AUDIO_CONFIG_MUTETYPE */
   1869             case OMX_IndexConfigAudioLoudness:             /**< reference: OMX_AUDIO_CONFIG_LOUDNESSTYPE */
   1870             case OMX_IndexConfigAudioEchoCancelation:      /**< reference: OMX_AUDIO_CONFIG_ECHOCANCELATIONTYPE */
   1871             case OMX_IndexConfigAudioNoiseReduction:       /**< reference: OMX_AUDIO_CONFIG_NOISEREDUCTIONTYPE */
   1872             case OMX_IndexConfigAudioBass:                 /**< reference: OMX_AUDIO_CONFIG_BASSTYPE */
   1873             case OMX_IndexConfigAudioTreble:               /**< reference: OMX_AUDIO_CONFIG_TREBLETYPE */
   1874             case OMX_IndexConfigAudioStereoWidening:       /**< reference: OMX_AUDIO_CONFIG_STEREOWIDENINGTYPE */
   1875             case OMX_IndexConfigAudioChorus:               /**< reference: OMX_AUDIO_CONFIG_CHORUSTYPE */
   1876             case OMX_IndexConfigAudioEqualizer:            /**< reference: OMX_AUDIO_CONFIG_EQUALIZERTYPE */
   1877             case OMX_IndexConfigAudioReverberation:        /**< reference: OMX_AUDIO_CONFIG_REVERBERATIONTYPE */
   1878 
   1879             /* Image specific parameters and configurations */
   1880             case OMX_IndexImageStartUnused:
   1881             case OMX_IndexParamImagePortFormat:   /**< reference: OMX_IMAGE_PARAM_PORTFORMATTYPE */
   1882             case OMX_IndexParamFlashControl:      /**< refer to OMX_IMAGE_PARAM_FLASHCONTROLTYPE */
   1883             case OMX_IndexConfigFocusControl:     /**< refer to OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE */
   1884             case OMX_IndexParamQFactor:           /**< refer to OMX_IMAGE_PARAM_QFACTORTYPE */
   1885             case OMX_IndexParamQuantizationTable: /**< refer to OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE */
   1886             case OMX_IndexParamHuffmanTable:      /**< For jpeg, refer to OMX_IMAGE_PARAM_HUFFMANTTABLETYPE */
   1887 
   1888             /* Video specific parameters and configurations */
   1889             case OMX_IndexVideoStartUnused:
   1890             case OMX_IndexParamVideoPortFormat:   /**< reference: OMX_VIDEO_PARAM_PORTFORMATTYPE */
   1891             case OMX_IndexParamVideoQuantization: /**< reference: OMX_VIDEO_PARAM_QUANTIZATIONPARAMTYPE */
   1892             case OMX_IndexParamVideoFastUpdate:   /**< reference: OMX_VIDEO_PARAM_VIDEOFASTUPDATETYPE */
   1893             case OMX_IndexParamVideoBitrate:      /**< reference: OMX_VIDEO_PARAM_BITRATETYPE */
   1894             case OMX_IndexParamVideoMotionVector: /**< reference: OMX_VIDEO_PARAM_MOTIONVECTORTYPE */
   1895             case OMX_IndexParamVideoIntraRefresh: /**< reference: OMX_VIDEO_PARAM_INTRAREFRESHTYPE */
   1896             case OMX_IndexParamVideoErrorCorrection: /**< reference: OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE */
   1897             case OMX_IndexParamVideoVBSMC: /**< reference:OMX_VIDEO_PARAM_VBSMCTYPE */
   1898             case OMX_IndexParamVideoMpeg2: /**< reference:OMX_VIDEO_PARAM_MPEG2TYPE */
   1899             case OMX_IndexParamVideoMpeg4: /**< reference: OMX_VIDEO_CONFIG_MPEG4TYPE */
   1900             case OMX_IndexParamVideoWmv:   /**< reference:OMX_VIDEO_PARAM_WMVTYPE */
   1901             case OMX_IndexParamVideoRv:    /**< reference:OMX_VIDEO_PARAM_RVTYPE */
   1902             case OMX_IndexParamVideoAvc:   /**< reference:OMX_VIDEO_PARAM_AVCTYPE */
   1903             case OMX_IndexParamVideoH263:  /**< reference:OMX_VIDEO_PARAM_H263TYPE */
   1904 
   1905             /* Image & Video common Configurations */
   1906             case OMX_IndexCommonStartUnused:
   1907             case OMX_IndexParamCommonDeblocking: /**< reference: OMX_PARAM_DEBLOCKINGTYPE */
   1908             case OMX_IndexParamCommonSensorMode: /**< reference: OMX_PARAM_SENSORMODETYPE */
   1909             case OMX_IndexParamCommonInterleave: /** reference: OMX_PARAM_INTERLEAVETYPE */
   1910             case OMX_IndexConfigCommonColorFormatConversion: /**< reference: OMX_CONFIG_COLORCONVERSIONTYPE */
   1911             case OMX_IndexConfigCommonScale:            /**< reference: OMX_CONFIG_SCALEFACTORTYPE */
   1912             case OMX_IndexConfigCommonImageFilter:      /**< reference: OMX_CONFIG_IMAGEFILTERTYPE */
   1913             case OMX_IndexConfigCommonColorEnhancement: /**< reference: OMX_CONFIG_COLORENHANCEMENTTYPE */
   1914             case OMX_IndexConfigCommonColorKey:         /**< reference: OMX_CONFIG_COLORKEYTYPE */
   1915             case OMX_IndexConfigCommonColorBlend:       /**< reference: OMX_CONFIG_COLORBLENDTYPE */
   1916             case OMX_IndexConfigCommonFrameStabilisation: /**< reference: OMX_CONFIG_FRAMESTABTYPE */
   1917             case OMX_IndexConfigCommonRotate:         /**< reference: OMX_CONFIG_ROTATIONTYPE */
   1918             case OMX_IndexConfigCommonMirror:         /**< reference: OMX_CONFIG_MIRRORTYPE */
   1919             case OMX_IndexConfigCommonOutputPosition: /**< reference: OMX_CONFIG_POINTTYPE */
   1920             case OMX_IndexConfigCommonInputCrop:      /**< reference: OMX_CONFIG_RECTTYPE */
   1921             case OMX_IndexConfigCommonOutputCrop:     /**< reference: OMX_CONFIG_RECTTYPE */
   1922             case OMX_IndexConfigCommonDigitalZoom:    /**< reference: OMX_SCALEFACTORTYPE */
   1923             case OMX_IndexConfigCommonOpticalZoom:    /**< reference: OMX_SCALEFACTORTYPE*/
   1924             case OMX_IndexConfigCommonWhiteBalance:   /**< reference: OMX_CONFIG_WHITEBALCONTROLTYPE */
   1925             case OMX_IndexConfigCommonExposure:       /**< reference: OMX_CONFIG_EXPOSURECONTROLTYPE */
   1926             case OMX_IndexConfigCommonContrast:       /**< reference to OMX_CONFIG_CONTRASTTYPE */
   1927             case OMX_IndexConfigCommonBrightness:     /**< reference to OMX_CONFIG_BRIGHTNESSTYPE */
   1928             case OMX_IndexConfigCommonBacklight:      /**< reference to OMX_CONFIG_BACKLIGHTTYPE */
   1929             case OMX_IndexConfigCommonGamma:          /**< reference to OMX_CONFIG_GAMMATYPE */
   1930             case OMX_IndexConfigCommonSaturation:     /**< reference to OMX_CONFIG_SATURATIONTYPE */
   1931             case OMX_IndexConfigCommonLightness:      /**< reference to OMX_CONFIG_LIGHTNESSTYPE */
   1932             case OMX_IndexConfigCommonExclusionRect:  /** reference: OMX_CONFIG_RECTTYPE */
   1933             case OMX_IndexConfigCommonDithering:      /**< reference: OMX_TIME_CONFIG_DITHERTYPE */
   1934             case OMX_IndexConfigCommonPlaneBlend:     /** reference: OMX_CONFIG_PLANEBLENDTYPE */
   1935 
   1936             /* Reserved Configuration range */
   1937             case OMX_IndexOtherStartUnused:
   1938             case OMX_IndexParamOtherPortFormat: /**< reference: OMX_OTHER_PARAM_PORTFORMATTYPE */
   1939             case OMX_IndexConfigOtherPower:     /**< reference: OMX_OTHER_CONFIG_POWERTYPE */
   1940             case OMX_IndexConfigOtherStats:     /**< reference: OMX_OTHER_CONFIG_STATSTYPE */
   1941 
   1942             /* Reserved Time range */
   1943             case OMX_IndexTimeStartUnused:
   1944             case OMX_IndexConfigTimeScale:      /**< reference: OMX_TIME_CONFIG_SCALETYPE */
   1945             case OMX_IndexConfigTimeClockState: /**< reference: OMX_TIME_CONFIG_CLOCKSTATETYPE */
   1946             case OMX_IndexConfigTimeActiveRefClock:   /**< reference: OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE */
   1947             case OMX_IndexConfigTimeCurrentMediaTime: /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE (read only)*/
   1948             case OMX_IndexConfigTimeCurrentWallTime:  /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE (read only)*/
   1949             case OMX_IndexConfigTimeCurrentAudioReference: /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE (write only) */
   1950             case OMX_IndexConfigTimeCurrentVideoReference: /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE (write only) */
   1951             case OMX_IndexConfigTimeMediaTimeRequest:      /**< reference: OMX_TIME_CONFIG_MEDIATIMEREQUESTTYPE (write only) */
   1952             case OMX_IndexConfigTimeClientStartTime:       /**<reference:  OMX_TIME_CONFIG_TIMESTAMPTYPE (write only) */
   1953             case OMX_IndexConfigTimePosition:              /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE */
   1954             case OMX_IndexConfigTimeSeekMode:              /**< reference: OMX_TIME_CONFIG_SEEKMODETYPE */
   1955 
   1956             /* Vendor specific area */
   1957 #ifdef KHRONOS_1_2
   1958             case OMX_IndexVendorStartUnused:
   1959 #else
   1960             case OMX_IndexIndexVendorStartUnused:
   1961 #endif
   1962             /* Vendor specific structures should be in the range of 0xFF000000
   1963                to 0xFFFFFFFF.  This range is not broken out by vendor, so
   1964                private indexes are not guaranteed unique and therefore should
   1965                only be sent to the appropriate component. */
   1966 
   1967             case OMX_IndexMax:
   1968                 eError = OMX_ErrorUnsupportedIndex;
   1969             break;
   1970         }
   1971     }
   1972 EXIT:
   1973     return eError;
   1974 }
   1975 /*----------------------------------------------------------------------------*/
   1976 /**
   1977   *  VIDDEC_SetConfig() Sets application callbacks to the component
   1978   *
   1979   * This method will update application callbacks
   1980   * the application.
   1981   *
   1982   * @param pComp         handle for this instance of the component
   1983   * @param pCallBacks    application callbacks
   1984   * @param ptr
   1985   *
   1986   * @retval OMX_NoError              Success, ready to roll
   1987   *         OMX_Error_BadParameter   The input parameter pointer is null
   1988   **/
   1989 /*----------------------------------------------------------------------------*/
   1990 
   1991 static OMX_ERRORTYPE VIDDEC_SetConfig (OMX_HANDLETYPE hComp,
   1992                                        OMX_INDEXTYPE nConfigIndex,
   1993                                        OMX_PTR ComponentConfigStructure)
   1994 {
   1995     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1996     OMX_PARAM_PORTDEFINITIONTYPE* pComponentConfig = NULL;
   1997     OMX_COMPONENTTYPE* pHandle = NULL;
   1998     VIDDEC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
   1999     OMX_S32 nConfigIndexTemp = 0;
   2000 
   2001     OMX_CONF_CHECK_CMD(hComp, ComponentConfigStructure, OMX_TRUE);
   2002 
   2003     pComponentConfig = (OMX_PARAM_PORTDEFINITIONTYPE*)ComponentConfigStructure;
   2004     pHandle = (OMX_COMPONENTTYPE*)hComp;
   2005     pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
   2006 
   2007     if (pComponentPrivate->eState == OMX_StateInvalid) {
   2008         eError = OMX_ErrorInvalidState;
   2009         OMX_PRSTATE4(pComponentPrivate->dbg, "state invalid for SetConfig...............\n");
   2010         goto EXIT;
   2011     }
   2012     else {
   2013         nConfigIndexTemp = nConfigIndex;
   2014         switch (nConfigIndexTemp) {
   2015             case OMX_IndexParamPortDefinition:
   2016             {
   2017                 OMX_PARAM_PORTDEFINITIONTYPE* pPortDef = NULL;
   2018                 if (pComponentConfig->nPortIndex == VIDDEC_INPUT_PORT) {
   2019                     OMX_MALLOC_STRUCT(pPortDef, OMX_PARAM_PORTDEFINITIONTYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel4]);
   2020                     if (pPortDef == NULL) {
   2021                         OMX_TRACE4(pComponentPrivate->dbg, "malloc failed\n");
   2022                         eError = OMX_ErrorInsufficientResources;
   2023                         goto EXIT;
   2024                     }
   2025                     ((VIDDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->pPortDef[VIDDEC_INPUT_PORT] = pPortDef;
   2026                     memcpy(pPortDef, pComponentConfig, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
   2027                     free(pPortDef);
   2028                 }
   2029                 else if (pComponentConfig->nPortIndex == VIDDEC_OUTPUT_PORT) {
   2030                     OMX_MALLOC_STRUCT(pPortDef, OMX_PARAM_PORTDEFINITIONTYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel4]);
   2031                     if (pPortDef == NULL) {
   2032                         OMX_TRACE4(pComponentPrivate->dbg, "malloc failed\n");
   2033                         eError = OMX_ErrorInsufficientResources;
   2034                         goto EXIT;
   2035                     }
   2036                     ((VIDDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->pPortDef[VIDDEC_OUTPUT_PORT] = pPortDef;
   2037                     memcpy(pPortDef, pComponentConfig, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
   2038                     free(pPortDef);
   2039                 }
   2040                 break;
   2041             }
   2042             case VideoDecodeCustomConfigDebug:/**< reference: struct OMX_TI_Debug */
   2043                 OMX_DBG_SETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
   2044                 break;
   2045 #ifdef KHRONOS_1_1
   2046             case OMX_IndexConfigVideoMBErrorReporting:/**< reference: OMX_CONFIG_MBERRORREPORTINGTYPE */
   2047             {
   2048                 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
   2049                     pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263 ||
   2050                     pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
   2051                     OMX_CONFIG_MBERRORREPORTINGTYPE* pMBErrorReportFrom = ComponentConfigStructure;
   2052                     /*OMX_CONF_CHK_VERSION( pMBErrorReportFrom, OMX_CONFIG_MBERRORREPORTINGTYPE, eError, pComponentPrivate->dbg);*/
   2053                     pComponentPrivate->eMBErrorReport.bEnabled = pMBErrorReportFrom->bEnabled;
   2054                 }
   2055                 else {
   2056                     eError = OMX_ErrorUnsupportedIndex;
   2057                 }
   2058                 break;
   2059             }
   2060             case OMX_IndexParamVideoMacroblocksPerFrame:
   2061             case OMX_IndexParamNumAvailableStreams:
   2062             case OMX_IndexParamActiveStream:
   2063             case OMX_IndexParamSuspensionPolicy:
   2064             case OMX_IndexParamComponentSuspended:
   2065             case OMX_IndexAutoPauseAfterCapture:
   2066             case OMX_IndexParamCustomContentPipe:
   2067             case OMX_IndexParamDisableResourceConcealment:
   2068 #ifdef KHRONOS_1_2
   2069             case OMX_IndexConfigMetadataItemCount:
   2070             case OMX_IndexConfigContainerNodeCount:
   2071             case OMX_IndexConfigMetadataItem:
   2072             case OMX_IndexConfigCounterNodeID:
   2073             case OMX_IndexParamMetadataFilterType:
   2074             case OMX_IndexConfigCommonTransitionEffect:
   2075             case OMX_IndexKhronosExtensions:
   2076 #else
   2077             case OMX_IndexConfigMetaDataSize:
   2078             case OMX_IndexConfigMetaDataAtIndex:
   2079             case OMX_IndexConfigMetaDataAtKey:
   2080             case OMX_IndexConfigMetaDataNodeCount:
   2081             case OMX_IndexConfigMetaDataNode:
   2082             case OMX_IndexConfigMetaDataItemCount:
   2083 #endif
   2084             case OMX_IndexParamMetadataKeyFilter:
   2085             case OMX_IndexConfigPriorityMgmt:
   2086             case OMX_IndexParamStandardComponentRole:
   2087             case OMX_IndexConfigAudioChannelVolume:
   2088             case OMX_IndexConfigFlashControl:
   2089             case OMX_IndexParamVideoProfileLevelQuerySupported:
   2090             case OMX_IndexParamVideoProfileLevelCurrent:
   2091             case OMX_IndexConfigVideoBitrate:
   2092             case OMX_IndexConfigVideoFramerate:
   2093             case OMX_IndexConfigVideoIntraVOPRefresh:
   2094             case OMX_IndexConfigVideoIntraMBRefresh:
   2095             case OMX_IndexParamVideoSliceFMO:
   2096             case OMX_IndexConfigVideoAVCIntraPeriod:
   2097             case OMX_IndexConfigVideoNalSize:
   2098             case OMX_IndexConfigVideoMacroBlockErrorMap:
   2099             case OMX_IndexConfigCommonExposureValue:
   2100             case OMX_IndexConfigCommonOutputSize:
   2101             case OMX_IndexParamCommonExtraQuantData:
   2102             case OMX_IndexConfigCommonFocusRegion:
   2103             case OMX_IndexConfigCommonFocusStatus:
   2104             case OMX_IndexParamContentURI:
   2105             case OMX_IndexConfigCaptureMode:
   2106             case OMX_IndexConfigCapturing:
   2107 #endif
   2108             case OMX_IndexComponentStartUnused:
   2109             case OMX_IndexParamPriorityMgmt:    /**< reference: OMX_PRIORITYMGMTTYPE */
   2110             case OMX_IndexParamAudioInit:       /**< reference: OMX_PORT_PARAM_TYPE  */
   2111             case OMX_IndexParamImageInit:       /**< reference: OMX_PORT_PARAM_TYPE  */
   2112             case OMX_IndexParamVideoInit:       /**< reference: OMX_PORT_PARAM_TYPE  */
   2113             case OMX_IndexParamOtherInit:       /**< reference: OMX_PORT_PARAM_TYPE  */
   2114 
   2115             case OMX_IndexPortStartUnused:
   2116             case OMX_IndexParamCompBufferSupplier: /**< reference: OMX_PARAM_BUFFERSUPPLIERTYPE (*/
   2117             case OMX_IndexReservedStartUnused:
   2118 
   2119             /* Audio parameters and configurations */
   2120             case OMX_IndexAudioStartUnused:
   2121             case OMX_IndexParamAudioPortFormat: /**< reference: OMX_AUDIO_PARAM_PORTFORMATTYPE */
   2122             case OMX_IndexParamAudioPcm:        /**< reference: OMX_AUDIO_PARAM_PCMMODETYPE */
   2123             case OMX_IndexParamAudioAac:        /**< reference: OMX_AUDIO_PARAM_AACPROFILETYPE */
   2124             case OMX_IndexParamAudioRa:         /**< reference: OMX_AUDIO_PARAM_RATYPE */
   2125             case OMX_IndexParamAudioMp3:        /**< reference: OMX_AUDIO_PARAM_MP3TYPE */
   2126             case OMX_IndexParamAudioAdpcm:      /**< reference: OMX_AUDIO_PARAM_ADPCMTYPE */
   2127             case OMX_IndexParamAudioG723:       /**< reference: OMX_AUDIO_PARAM_G723TYPE */
   2128             case OMX_IndexParamAudioG729:       /**< reference: OMX_AUDIO_PARAM_G729TYPE */
   2129             case OMX_IndexParamAudioAmr:        /**< reference: OMX_AUDIO_PARAM_AMRTYPE */
   2130             case OMX_IndexParamAudioWma:        /**< reference: OMX_AUDIO_PARAM_WMATYPE */
   2131             case OMX_IndexParamAudioSbc:        /**< reference: OMX_AUDIO_PARAM_SBCTYPE */
   2132             case OMX_IndexParamAudioMidi:       /**< reference: OMX_AUDIO_PARAM_MIDITYPE */
   2133             case OMX_IndexParamAudioGsm_FR:     /**< reference: OMX_AUDIO_PARAM__GSMFRTYPE */
   2134             case OMX_IndexParamAudioMidiLoadUserSound: /**< reference: OMX_AUDIO_PARAM_MIDILOADUSERSOUNDTYPE */
   2135             case OMX_IndexParamAudioG726:       /**< reference: OMX_AUDIO_PARAM_G726TYPE */
   2136             case OMX_IndexParamAudioGsm_EFR:    /**< reference: OMX_AUDIO_PARAM__GSMEFRTYPE */
   2137             case OMX_IndexParamAudioGsm_HR:     /**< reference: OMX_AUDIO_PARAM__GSMHRTYPE */
   2138             case OMX_IndexParamAudioPdc_FR:     /**< reference: OMX_AUDIO_PARAM__PDCFRTYPE */
   2139             case OMX_IndexParamAudioPdc_EFR:    /**< reference: OMX_AUDIO_PARAM__PDCEFRTYPE */
   2140             case OMX_IndexParamAudioPdc_HR:     /**< reference: OMX_AUDIO_PARAM__PDCHRTYPE */
   2141             case OMX_IndexParamAudioTdma_FR:    /**< reference: OMX_AUDIO_PARAM__TDMAFRTYPE */
   2142             case OMX_IndexParamAudioTdma_EFR:   /**< reference: OMX_AUDIO_PARAM__TDMAEFRTYPE */
   2143             case OMX_IndexParamAudioQcelp8:     /**< reference: OMX_AUDIO_PARAM__QCELP8TYPE */
   2144             case OMX_IndexParamAudioQcelp13:    /**< reference: OMX_AUDIO_PARAM__QCELP13TYPE */
   2145             case OMX_IndexParamAudioEvrc:       /**< reference: OMX_AUDIO_PARAM__EVRCTYPE */
   2146             case OMX_IndexParamAudioSmv:        /**< reference: OMX_AUDIO_PARAM__SMVTYPE */
   2147             case OMX_IndexParamAudioVorbis:     /**< reference: OMX_AUDIO_PARAM__VORBISTYPE */
   2148 
   2149             case OMX_IndexConfigAudioMidiImmediateEvent:   /**< OMX_AUDIO_CONFIG_MIDIIMMEDIATEEVENTTYPE */
   2150             case OMX_IndexConfigAudioMidiControl:          /**< reference: OMX_AUDIO_CONFIG_MIDICONTROLTYPE */
   2151             case OMX_IndexConfigAudioMidiSoundBankProgram: /**< reference: OMX_AUDIO_CONFIG_MIDISOUNDBANKPROGRAMTYPE */
   2152             case OMX_IndexConfigAudioMidiStatus:           /**< reference: OMX_AUDIO_CONFIG_MIDISTATUSTYPE */
   2153             case OMX_IndexConfigAudioMidiMetaEvent:        /**< reference: OMX_AUDIO_CONFIG_MIDIMETAEVENTTYPE */
   2154             case OMX_IndexConfigAudioMidiMetaEventData:    /**< reference: OMX_AUDIO_CONFIG_MIDIMETAEVENTDATATYPE */
   2155             case OMX_IndexConfigAudioVolume:               /**< reference: OMX_AUDIO_CONFIG_VOLUMETYPE */
   2156             case OMX_IndexConfigAudioBalance:              /**< reference: OMX_AUDIO_CONFIG_BALANCETYPE */
   2157             case OMX_IndexConfigAudioChannelMute:          /**< reference: OMX_AUDIO_CONFIG_CHANNELMUTETYPE */
   2158             case OMX_IndexConfigAudioMute:                 /**< reference: OMX_AUDIO_CONFIG_MUTETYPE */
   2159             case OMX_IndexConfigAudioLoudness:             /**< reference: OMX_AUDIO_CONFIG_LOUDNESSTYPE */
   2160             case OMX_IndexConfigAudioEchoCancelation:      /**< reference: OMX_AUDIO_CONFIG_ECHOCANCELATIONTYPE */
   2161             case OMX_IndexConfigAudioNoiseReduction:       /**< reference: OMX_AUDIO_CONFIG_NOISEREDUCTIONTYPE */
   2162             case OMX_IndexConfigAudioBass:                 /**< reference: OMX_AUDIO_CONFIG_BASSTYPE */
   2163             case OMX_IndexConfigAudioTreble:               /**< reference: OMX_AUDIO_CONFIG_TREBLETYPE */
   2164             case OMX_IndexConfigAudioStereoWidening:       /**< reference: OMX_AUDIO_CONFIG_STEREOWIDENINGTYPE */
   2165             case OMX_IndexConfigAudioChorus:               /**< reference: OMX_AUDIO_CONFIG_CHORUSTYPE */
   2166             case OMX_IndexConfigAudioEqualizer:            /**< reference: OMX_AUDIO_CONFIG_EQUALIZERTYPE */
   2167             case OMX_IndexConfigAudioReverberation:        /**< reference: OMX_AUDIO_CONFIG_REVERBERATIONTYPE */
   2168 
   2169             /* Image specific parameters and configurations */
   2170             case OMX_IndexImageStartUnused:
   2171             case OMX_IndexParamImagePortFormat:   /**< reference: OMX_IMAGE_PARAM_PORTFORMATTYPE */
   2172             case OMX_IndexParamFlashControl:      /**< refer to OMX_IMAGE_PARAM_FLASHCONTROLTYPE */
   2173             case OMX_IndexConfigFocusControl:     /**< refer to OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE */
   2174             case OMX_IndexParamQFactor:           /**< refer to OMX_IMAGE_PARAM_QFACTORTYPE */
   2175             case OMX_IndexParamQuantizationTable: /**< refer to OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE */
   2176             case OMX_IndexParamHuffmanTable:      /**< For jpeg, refer to OMX_IMAGE_PARAM_HUFFMANTTABLETYPE */
   2177 
   2178             /* Video specific parameters and configurations */
   2179             case OMX_IndexVideoStartUnused:
   2180             case OMX_IndexParamVideoPortFormat:   /**< reference: OMX_VIDEO_PARAM_PORTFORMATTYPE */
   2181             case OMX_IndexParamVideoQuantization: /**< reference: OMX_VIDEO_PARAM_QUANTIZATIONPARAMTYPE */
   2182             case OMX_IndexParamVideoFastUpdate:   /**< reference: OMX_VIDEO_PARAM_VIDEOFASTUPDATETYPE */
   2183             case OMX_IndexParamVideoBitrate:      /**< reference: OMX_VIDEO_PARAM_BITRATETYPE */
   2184             case OMX_IndexParamVideoMotionVector: /**< reference: OMX_VIDEO_PARAM_MOTIONVECTORTYPE */
   2185             case OMX_IndexParamVideoIntraRefresh: /**< reference: OMX_VIDEO_PARAM_INTRAREFRESHTYPE */
   2186             case OMX_IndexParamVideoErrorCorrection: /**< reference: OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE */
   2187             case OMX_IndexParamVideoVBSMC: /**< reference:OMX_VIDEO_PARAM_VBSMCTYPE */
   2188             case OMX_IndexParamVideoMpeg2: /**< reference:OMX_VIDEO_PARAM_MPEG2TYPE */
   2189             case OMX_IndexParamVideoMpeg4: /**< reference: OMX_VIDEO_CONFIG_MPEG4TYPE */
   2190             case OMX_IndexParamVideoWmv:   /**< reference:OMX_VIDEO_PARAM_WMVTYPE */
   2191             case OMX_IndexParamVideoRv:    /**< reference:OMX_VIDEO_PARAM_RVTYPE */
   2192             case OMX_IndexParamVideoAvc:   /**< reference:OMX_VIDEO_PARAM_AVCTYPE */
   2193             case OMX_IndexParamVideoH263:  /**< reference:OMX_VIDEO_PARAM_H263TYPE */
   2194 
   2195             /* Image & Video common Configurations */
   2196             case OMX_IndexCommonStartUnused:
   2197             case OMX_IndexParamCommonDeblocking: /**< reference: OMX_PARAM_DEBLOCKINGTYPE */
   2198             case OMX_IndexParamCommonSensorMode: /**< reference: OMX_PARAM_SENSORMODETYPE */
   2199             case OMX_IndexParamCommonInterleave: /** reference: OMX_PARAM_INTERLEAVETYPE */
   2200             case OMX_IndexConfigCommonColorFormatConversion: /**< reference: OMX_CONFIG_COLORCONVERSIONTYPE */
   2201             case OMX_IndexConfigCommonScale:            /**< reference: OMX_CONFIG_SCALEFACTORTYPE */
   2202             case OMX_IndexConfigCommonImageFilter:      /**< reference: OMX_CONFIG_IMAGEFILTERTYPE */
   2203             case OMX_IndexConfigCommonColorEnhancement: /**< reference: OMX_CONFIG_COLORENHANCEMENTTYPE */
   2204             case OMX_IndexConfigCommonColorKey:         /**< reference: OMX_CONFIG_COLORKEYTYPE */
   2205             case OMX_IndexConfigCommonColorBlend:       /**< reference: OMX_CONFIG_COLORBLENDTYPE */
   2206             case OMX_IndexConfigCommonFrameStabilisation: /**< reference: OMX_CONFIG_FRAMESTABTYPE */
   2207             case OMX_IndexConfigCommonRotate:         /**< reference: OMX_CONFIG_ROTATIONTYPE */
   2208             case OMX_IndexConfigCommonMirror:         /**< reference: OMX_CONFIG_MIRRORTYPE */
   2209             case OMX_IndexConfigCommonOutputPosition: /**< reference: OMX_CONFIG_POINTTYPE */
   2210             case OMX_IndexConfigCommonInputCrop:      /**< reference: OMX_CONFIG_RECTTYPE */
   2211             case OMX_IndexConfigCommonOutputCrop:     /**< reference: OMX_CONFIG_RECTTYPE */
   2212             case OMX_IndexConfigCommonDigitalZoom:    /**< reference: OMX_SCALEFACTORTYPE */
   2213             case OMX_IndexConfigCommonOpticalZoom:    /**< reference: OMX_SCALEFACTORTYPE*/
   2214             case OMX_IndexConfigCommonWhiteBalance:   /**< reference: OMX_CONFIG_WHITEBALCONTROLTYPE */
   2215             case OMX_IndexConfigCommonExposure:       /**< reference: OMX_CONFIG_EXPOSURECONTROLTYPE */
   2216             case OMX_IndexConfigCommonContrast:       /**< reference to OMX_CONFIG_CONTRASTTYPE */
   2217             case OMX_IndexConfigCommonBrightness:     /**< reference to OMX_CONFIG_BRIGHTNESSTYPE */
   2218             case OMX_IndexConfigCommonBacklight:      /**< reference to OMX_CONFIG_BACKLIGHTTYPE */
   2219             case OMX_IndexConfigCommonGamma:          /**< reference to OMX_CONFIG_GAMMATYPE */
   2220             case OMX_IndexConfigCommonSaturation:     /**< reference to OMX_CONFIG_SATURATIONTYPE */
   2221             case OMX_IndexConfigCommonLightness:      /**< reference to OMX_CONFIG_LIGHTNESSTYPE */
   2222             case OMX_IndexConfigCommonExclusionRect:  /** reference: OMX_CONFIG_RECTTYPE */
   2223             case OMX_IndexConfigCommonDithering:      /**< reference: OMX_TIME_CONFIG_DITHERTYPE */
   2224             case OMX_IndexConfigCommonPlaneBlend:     /** reference: OMX_CONFIG_PLANEBLENDTYPE */
   2225 
   2226             /* Reserved Configuration range */
   2227             case OMX_IndexOtherStartUnused:
   2228             case OMX_IndexParamOtherPortFormat: /**< reference: OMX_OTHER_PARAM_PORTFORMATTYPE */
   2229             case OMX_IndexConfigOtherPower:     /**< reference: OMX_OTHER_CONFIG_POWERTYPE */
   2230             case OMX_IndexConfigOtherStats:     /**< reference: OMX_OTHER_CONFIG_STATSTYPE */
   2231 
   2232             /* Reserved Time range */
   2233             case OMX_IndexTimeStartUnused:
   2234             case OMX_IndexConfigTimeScale:      /**< reference: OMX_TIME_CONFIG_SCALETYPE */
   2235             case OMX_IndexConfigTimeClockState: /**< reference: OMX_TIME_CONFIG_CLOCKSTATETYPE */
   2236             case OMX_IndexConfigTimeActiveRefClock:   /**< reference: OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE */
   2237             case OMX_IndexConfigTimeCurrentMediaTime: /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE (read only)*/
   2238             case OMX_IndexConfigTimeCurrentWallTime:  /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE (read only)*/
   2239             case OMX_IndexConfigTimeCurrentAudioReference: /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE (write only) */
   2240             case OMX_IndexConfigTimeCurrentVideoReference: /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE (write only) */
   2241             case OMX_IndexConfigTimeMediaTimeRequest:      /**< reference: OMX_TIME_CONFIG_MEDIATIMEREQUESTTYPE (write only) */
   2242             case OMX_IndexConfigTimeClientStartTime:       /**<reference:  OMX_TIME_CONFIG_TIMESTAMPTYPE (write only) */
   2243             case OMX_IndexConfigTimePosition:              /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE */
   2244             case OMX_IndexConfigTimeSeekMode:              /**< reference: OMX_TIME_CONFIG_SEEKMODETYPE */
   2245 
   2246             /* Vendor specific area */
   2247 #ifdef KHRONOS_1_2
   2248             case OMX_IndexVendorStartUnused:
   2249 #else
   2250             case OMX_IndexIndexVendorStartUnused:
   2251 #endif            /* Vendor specific structures should be in the range of 0xFF000000
   2252                to 0xFFFFFFFF.  This range is not broken out by vendor, so
   2253                private indexes are not guaranteed unique and therefore should
   2254                only be sent to the appropriate component. */
   2255 
   2256             case OMX_IndexMax:
   2257                 eError = OMX_ErrorUnsupportedIndex;
   2258             break;
   2259         }
   2260     }
   2261 
   2262 EXIT:
   2263     return eError;
   2264 }
   2265 
   2266 /*----------------------------------------------------------------------------*/
   2267 /**
   2268   *  VIDDEC_GetState() Sets application callbacks to the component
   2269   *
   2270   * This method will update application callbacks
   2271   * the application.
   2272   *
   2273   * @param pComp         handle for this instance of the component
   2274   * @param pCallBacks    application callbacks
   2275   * @param ptr
   2276   *
   2277   * @retval OMX_NoError              Success, ready to roll
   2278   *         OMX_Error_BadParameter   The input parameter pointer is null
   2279   **/
   2280 /*----------------------------------------------------------------------------*/
   2281 
   2282 static OMX_ERRORTYPE VIDDEC_GetState (OMX_HANDLETYPE hComponent,
   2283                                       OMX_STATETYPE* pState)
   2284 {
   2285     OMX_ERRORTYPE eError                        = OMX_ErrorNone;
   2286     OMX_COMPONENTTYPE* pHandle = NULL;
   2287 
   2288     VIDDEC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
   2289     struct timespec abs_time = {0,0};
   2290     int nPendingStateChangeRequests = 0;
   2291     int ret = 0;
   2292     /* Set to sufficiently high value */
   2293     int mutex_timeout = 3;
   2294 
   2295     if(hComponent == NULL || pState == NULL) {
   2296         return OMX_ErrorBadParameter;
   2297     }
   2298 
   2299     pHandle = (OMX_COMPONENTTYPE*)hComponent;
   2300     pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
   2301 
   2302     /* Retrieve current state */
   2303     if (pHandle && pHandle->pComponentPrivate) {
   2304         /* Check for any pending state transition requests */
   2305         if(pthread_mutex_lock(&pComponentPrivate->mutexStateChangeRequest)) {
   2306             return OMX_ErrorUndefined;
   2307         }
   2308         nPendingStateChangeRequests = pComponentPrivate->nPendingStateChangeRequests;
   2309         if(!nPendingStateChangeRequests) {
   2310            if(pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest)) {
   2311                return OMX_ErrorUndefined;
   2312            }
   2313 
   2314            /* No pending state transitions */
   2315           *pState = ((VIDDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->eState;
   2316             eError = OMX_ErrorNone;
   2317         }
   2318         else {
   2319                   /* Wait for component to complete state transition */
   2320            clock_gettime(CLOCK_REALTIME, &abs_time);
   2321            abs_time.tv_sec += mutex_timeout;
   2322            abs_time.tv_nsec = 0;
   2323           ret = pthread_cond_timedwait(&(pComponentPrivate->StateChangeCondition), &(pComponentPrivate->mutexStateChangeRequest), &abs_time);
   2324            if (!ret) {
   2325               /* Component has completed state transitions*/
   2326               *pState = ((VIDDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->eState;
   2327               if(pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest)) {
   2328                   return OMX_ErrorUndefined;
   2329               }
   2330               eError = OMX_ErrorNone;
   2331            }
   2332            else if(ret == ETIMEDOUT) {
   2333               /* Unlock mutex in case of timeout */
   2334               OMX_ERROR4(pComponentPrivate->dbg, "VIDDEC_GetState timed out\n");
   2335               pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest);
   2336               *pState = OMX_StateInvalid;
   2337               return OMX_ErrorNone;
   2338            }
   2339         }
   2340      }
   2341      else {
   2342         eError = OMX_ErrorInvalidComponent;
   2343         *pState = OMX_StateInvalid;
   2344      }
   2345 
   2346     return eError;
   2347 }
   2348 
   2349 /*----------------------------------------------------------------------------*/
   2350 /**
   2351   *  VIDDEC_EmptyThisBuffer() Sets application callbacks to the component
   2352   *
   2353   * This method will update application callbacks
   2354   * the application.
   2355   *
   2356   * @param pComp         handle for this instance of the component
   2357   * @param pCallBacks    application callbacks
   2358   * @param ptr
   2359   *
   2360   * @retval OMX_NoError              Success, ready to roll
   2361   *         OMX_Error_BadParameter   The input parameter pointer is null
   2362   **/
   2363 /*----------------------------------------------------------------------------*/
   2364 
   2365 static OMX_ERRORTYPE VIDDEC_EmptyThisBuffer (OMX_HANDLETYPE pComponent,
   2366                                              OMX_BUFFERHEADERTYPE* pBuffHead)
   2367 {
   2368     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2369     OMX_COMPONENTTYPE *pHandle = NULL;
   2370     VIDDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
   2371     VIDDEC_BUFFER_PRIVATE* pBufferPrivate = NULL;
   2372     OMX_S32 ret = 0;
   2373 
   2374     OMX_CONF_CHECK_CMD(pComponent, OMX_TRUE, OMX_TRUE);
   2375 
   2376     pHandle = (OMX_COMPONENTTYPE *)pComponent;
   2377     pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
   2378 
   2379     OMX_PRBUFFER1(pComponentPrivate->dbg, "+++Entering pHandle 0x%p pBuffer 0x%p Index %lu  state %x  nflags  %x  isfirst %x\n",pComponent,
   2380             pBuffHead, pBuffHead->nInputPortIndex,pComponentPrivate->eState,pBuffHead->nFlags,pComponentPrivate->bFirstHeader);
   2381 
   2382     OMX_BOOL bIsInputFlushPending = OMX_FALSE;
   2383     VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->inputFlushCompletionMutex);
   2384     bIsInputFlushPending = pComponentPrivate->bIsInputFlushPending;
   2385     VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->inputFlushCompletionMutex);
   2386     if (bIsInputFlushPending) {
   2387         ALOGE("Unable to process any OMX_EmptyThisBuffer requsts with input flush pending");
   2388         return OMX_ErrorIncorrectStateOperation;
   2389     }
   2390 #ifdef __PERF_INSTRUMENTATION__
   2391     PERF_ReceivedFrame(pComponentPrivate->pPERF,
   2392                        pBuffHead->pBuffer,
   2393                        pBuffHead->nFilledLen,
   2394                        PERF_ModuleHLMM);
   2395 #endif
   2396 
   2397     OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate->pInPortDef->bEnabled %d\n",
   2398         pComponentPrivate->pInPortDef->bEnabled);
   2399     if(!pComponentPrivate->pInPortDef->bEnabled)
   2400         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation);
   2401 
   2402     if(pBuffHead->nInputPortIndex != VIDDEC_INPUT_PORT)
   2403         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorBadPortIndex);
   2404 
   2405     if(pComponentPrivate->eState != OMX_StateExecuting &&
   2406         pComponentPrivate->eState != OMX_StatePause &&
   2407         pComponentPrivate->eState != OMX_StateIdle)
   2408         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation);
   2409 
   2410     OMX_CONF_CHK_VERSION(pBuffHead, OMX_BUFFERHEADERTYPE, eError, pComponentPrivate->dbg);
   2411 
   2412     if ((pComponentPrivate->bParserEnabled == OMX_FALSE) &&
   2413         (pComponentPrivate->bFirstHeader == OMX_FALSE) &&
   2414         (pBuffHead->nFilledLen > pBuffHead->nAllocLen)) {
   2415         pBuffHead->nFilledLen = pBuffHead->nAllocLen;
   2416     }
   2417 
   2418     pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate;
   2419     ret = pBufferPrivate->eBufferOwner;
   2420     pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT;
   2421     eError = IncrementCount (&(pComponentPrivate->nCountInputBFromApp), &(pComponentPrivate->mutexInputBFromApp));
   2422     if (eError != OMX_ErrorNone) {
   2423         return eError;
   2424     }
   2425 
   2426     OMX_PRBUFFER1(pComponentPrivate->dbg, "Writing pBuffer 0x%p OldeBufferOwner %ld nAllocLen %lu nFilledLen %lu eBufferOwner %d\n",
   2427         pBuffHead, ret,pBuffHead->nAllocLen,pBuffHead->nFilledLen,pBufferPrivate->eBufferOwner);
   2428 
   2429     ret = write (pComponentPrivate->filled_inpBuf_Q[VIDDEC_PIPE_WRITE], &(pBuffHead), sizeof(pBuffHead));
   2430     if (ret == -1) {
   2431         /*like function returns error buffer still with Client IL*/
   2432         pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
   2433         OMX_PRCOMM4(pComponentPrivate->dbg, "Error in Writing to the Data pipe\n");
   2434         DecrementCount (&(pComponentPrivate->nCountInputBFromApp), &(pComponentPrivate->mutexInputBFromApp));
   2435         eError = OMX_ErrorHardware;
   2436         goto EXIT;
   2437     }
   2438 
   2439 EXIT:
   2440     if (pComponentPrivate)
   2441         OMX_PRBUFFER1(pComponentPrivate->dbg, "---Exiting 0x%x\n", eError);
   2442     return eError;
   2443 }
   2444 
   2445 /*----------------------------------------------------------------------------*/
   2446 /**
   2447   *  VIDDEC_FillThisBuffer() Sets application callbacks to the component
   2448   *
   2449   * This method will update application callbacks
   2450   * the application.
   2451   *
   2452   * @param pComp         handle for this instance of the component
   2453   * @param pCallBacks    application callbacks
   2454   * @param ptr
   2455   *
   2456   * @retval OMX_NoError              Success, ready to roll
   2457   *         OMX_Error_BadParameter   The input parameter pointer is null
   2458   **/
   2459 /*----------------------------------------------------------------------------*/
   2460 
   2461 static OMX_ERRORTYPE VIDDEC_FillThisBuffer (OMX_HANDLETYPE pComponent,
   2462                                             OMX_BUFFERHEADERTYPE* pBuffHead)
   2463 {
   2464     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2465     OMX_COMPONENTTYPE *pHandle = NULL;
   2466     VIDDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
   2467     VIDDEC_BUFFER_PRIVATE* pBufferPrivate = NULL;
   2468     int ret = 0;
   2469     OMX_CONF_CHECK_CMD(pComponent, pBuffHead, OMX_TRUE);
   2470     pHandle = (OMX_COMPONENTTYPE *)pComponent;
   2471     pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
   2472 
   2473     OMX_PRBUFFER1(pComponentPrivate->dbg, "+++Entering pHandle 0x%p pBuffer 0x%p Index %lu\n",pComponent,
   2474             pBuffHead, pBuffHead->nOutputPortIndex);
   2475 
   2476     OMX_BOOL bIsOutputFlushPending = OMX_FALSE;
   2477     VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->outputFlushCompletionMutex);
   2478     bIsOutputFlushPending = pComponentPrivate->bIsOutputFlushPending;
   2479     VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->outputFlushCompletionMutex);
   2480     if (bIsOutputFlushPending) {
   2481         ALOGE("Unable to process any OMX_FillThisBuffer requsts with flush pending");
   2482         return OMX_ErrorIncorrectStateOperation;
   2483     }
   2484 
   2485 #ifdef __PERF_INSTRUMENTATION__
   2486     PERF_ReceivedFrame(pComponentPrivate->pPERF,
   2487                        pBuffHead->pBuffer,
   2488                        0,
   2489                        PERF_ModuleHLMM);
   2490 #endif
   2491 
   2492     OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate->pOutPortDef->bEnabled %d\n",
   2493         pComponentPrivate->pOutPortDef->bEnabled);
   2494     if(!pComponentPrivate->pOutPortDef->bEnabled)
   2495         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation);
   2496 
   2497     if(pBuffHead->nOutputPortIndex != 0x1)
   2498         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorBadPortIndex);
   2499 
   2500     if(pComponentPrivate->eState != OMX_StateExecuting &&
   2501         pComponentPrivate->eState != OMX_StatePause &&
   2502         pComponentPrivate->eState != OMX_StateIdle)
   2503         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation);
   2504 
   2505     OMX_CONF_CHK_VERSION(pBuffHead, OMX_BUFFERHEADERTYPE, eError, pComponentPrivate->dbg);
   2506 
   2507     if ((pComponentPrivate->bParserEnabled == OMX_FALSE) &&
   2508         (pComponentPrivate->bFirstHeader == OMX_FALSE) &&
   2509         (pBuffHead->nFilledLen > pBuffHead->nAllocLen)) {
   2510         OMX_PRINT1(pComponentPrivate->dbg, "bFirstHeader: nFilledLen= %lu <- nAllocLen= %lu\n", pBuffHead->nFilledLen, pBuffHead->nAllocLen);
   2511 
   2512         pBuffHead->nFilledLen = pBuffHead->nAllocLen;
   2513     }
   2514 
   2515     pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pOutputPortPrivate;
   2516     ret = pBufferPrivate->eBufferOwner;
   2517     pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT;
   2518     eError = IncrementCount (&(pComponentPrivate->nCountOutputBFromApp), &(pComponentPrivate->mutexOutputBFromApp));
   2519     if (eError != OMX_ErrorNone) {
   2520         return eError;
   2521     }
   2522     pBuffHead->nFilledLen = 0;
   2523     pBuffHead->nFlags = 0;
   2524     OMX_PRBUFFER1(pComponentPrivate->dbg, "Writing pBuffer 0x%p OldeBufferOwner %d eBufferOwner %d nFilledLen %lu\n",
   2525         pBuffHead, ret,pBufferPrivate->eBufferOwner,pBuffHead->nFilledLen);
   2526     ret = write (pComponentPrivate->free_outBuf_Q[1], &(pBuffHead), sizeof (pBuffHead));
   2527     if (ret == -1) {
   2528         /*like function returns error buffer still with Client IL*/
   2529         pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
   2530         OMX_PRCOMM4(pComponentPrivate->dbg, "Error in Writing to the Data pipe\n");
   2531         DecrementCount (&(pComponentPrivate->nCountOutputBFromApp), &(pComponentPrivate->mutexOutputBFromApp));
   2532         eError = OMX_ErrorHardware;
   2533         goto EXIT;
   2534     }
   2535 
   2536 EXIT:
   2537     if (pComponentPrivate)
   2538         OMX_PRBUFFER1(pComponentPrivate->dbg, "---Exiting 0x%x\n", eError);
   2539     return eError;
   2540 }
   2541 
   2542 /*----------------------------------------------------------------------------*/
   2543 /**
   2544   * VIDDEC_ComponentDeinit() Sets application callbacks to the component
   2545   *
   2546   * This method will update application callbacks
   2547   * the application.
   2548   *
   2549   * @param pComp         handle for this instance of the component
   2550   * @param pCallBacks    application callbacks
   2551   * @param ptr
   2552   *
   2553   * @retval OMX_NoError              Success, ready to roll
   2554   *         OMX_Error_BadParameter   The input parameter pointer is null
   2555   **/
   2556 /*----------------------------------------------------------------------------*/
   2557 
   2558 static OMX_ERRORTYPE VIDDEC_ComponentDeInit(OMX_HANDLETYPE hComponent)
   2559 {
   2560     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2561     OMX_COMPONENTTYPE* pHandle = NULL;
   2562     VIDDEC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
   2563     OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
   2564     OMX_U32 nParam1 = -1;
   2565     OMX_U32 buffcount = 0;
   2566     OMX_U32 i = 0;
   2567     OMX_U32 iCount = 0;
   2568 
   2569     OMX_CONF_CHECK_CMD(hComponent, OMX_TRUE, OMX_TRUE);
   2570 
   2571     pHandle = (OMX_COMPONENTTYPE*)hComponent;
   2572     pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
   2573 
   2574 #ifdef __PERF_INSTRUMENTATION__
   2575     PERF_Boundary(pComponentPrivate->pPERF,
   2576                   PERF_BoundaryStart | PERF_BoundaryCleanup);
   2577     PERF_SendingCommand(pComponentPrivate->pPERF,
   2578                         Cmd, nParam1, PERF_ModuleComponent);
   2579 #endif
   2580     if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload &&
   2581         pComponentPrivate->pModLCML != NULL &&
   2582         pComponentPrivate->pLCML != NULL){
   2583         LCML_DSP_INTERFACE *pLcmlHandle = NULL;
   2584         pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
   2585         LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, EMMCodecControlDestroy, NULL);
   2586         pComponentPrivate->eLCMLState = VidDec_LCML_State_Destroy;
   2587     }
   2588     if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload &&
   2589         pComponentPrivate->pModLCML != NULL){
   2590         if(pComponentPrivate->pModLCML != NULL){
   2591             dlclose(pComponentPrivate->pModLCML);
   2592             pComponentPrivate->pModLCML = NULL;
   2593             pComponentPrivate->pLCML = NULL;
   2594             pComponentPrivate->eLCMLState = VidDec_LCML_State_Unload;
   2595         }
   2596     }
   2597     eError = write(pComponentPrivate->cmdPipe[VIDDEC_PIPE_WRITE], &Cmd, sizeof(Cmd));
   2598     if (eError == -1) {
   2599         eError = OMX_ErrorUndefined;
   2600         goto EXIT;
   2601     }
   2602     eError = write(pComponentPrivate->cmdDataPipe[VIDDEC_PIPE_WRITE], &nParam1, sizeof(nParam1));
   2603     if (eError == -1) {
   2604        eError = OMX_ErrorUndefined;
   2605        goto EXIT;
   2606     }
   2607 
   2608     eError = VIDDEC_Stop_ComponentThread(pHandle);
   2609     if (eError != OMX_ErrorNone) {
   2610         OMX_ERROR4(pComponentPrivate->dbg, "Error returned from the Component\n");
   2611     }
   2612 
   2613     if (pComponentPrivate->pInternalConfigBufferAVC != NULL)
   2614       free(pComponentPrivate->pInternalConfigBufferAVC);
   2615     for (iCount = 0; iCount < MAX_PRIVATE_BUFFERS; iCount++) {
   2616         if(pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[iCount]->pBufferHdr != NULL) {
   2617             OMX_BUFFERHEADERTYPE* pBuffHead = NULL;
   2618             pBuffHead = pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[iCount]->pBufferHdr;
   2619             if(pBuffHead != NULL){
   2620                 if(pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[iCount]->bAllocByComponent == OMX_TRUE){
   2621                     OMX_MEMFREE_STRUCT_DSPALIGN(pBuffHead->pBuffer,OMX_U8);
   2622                 }
   2623                 free(pBuffHead);
   2624                 pBuffHead = NULL;
   2625                 pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[iCount]->pBufferHdr = NULL;
   2626             }
   2627         }
   2628     }
   2629 
   2630     for (iCount = 0; iCount < MAX_PRIVATE_BUFFERS; iCount++) {
   2631         if(pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[iCount]->pBufferHdr != NULL) {
   2632             OMX_BUFFERHEADERTYPE* pBuffHead = NULL;
   2633             pBuffHead = pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[iCount]->pBufferHdr;
   2634             if(pBuffHead != NULL){
   2635 	         if(pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[iCount]->bAllocByComponent == OMX_TRUE){
   2636                     OMX_MEMFREE_STRUCT_DSPALIGN(pBuffHead->pBuffer,OMX_U8);
   2637 	         }
   2638                 free(pBuffHead);
   2639                 pBuffHead = NULL;
   2640                 pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[iCount]->pBufferHdr = NULL;
   2641             }
   2642         }
   2643     }
   2644 
   2645 #ifdef RESOURCE_MANAGER_ENABLED
   2646     if(pComponentPrivate->eRMProxyState == VidDec_RMPROXY_State_Registered){
   2647         OMX_PRMGR2(pComponentPrivate->dbg, "memory usage 0 %d : %d bytes\n",(unsigned int)pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0],(unsigned int)VIDDEC_MEMUSAGE);
   2648         if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
   2649             eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_FreeResource, OMX_H264_Decode_COMPONENT, 0, VIDDEC_MEMUSAGE, NULL);
   2650             if (eError != OMX_ErrorNone) {
   2651                  OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n");
   2652             }
   2653         }
   2654         else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) {
   2655             eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_FreeResource, OMX_WMV_Decode_COMPONENT, 0, VIDDEC_MEMUSAGE, NULL);
   2656             if (eError != OMX_ErrorNone) {
   2657                  OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n");
   2658             }
   2659         }
   2660         else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4) {
   2661             eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_FreeResource, OMX_MPEG4_Decode_COMPONENT, 0, VIDDEC_MEMUSAGE, NULL);
   2662             if (eError != OMX_ErrorNone) {
   2663                  OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n");
   2664             }
   2665         }
   2666         else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) {
   2667             eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_FreeResource, OMX_H263_Decode_COMPONENT, 0, VIDDEC_MEMUSAGE, NULL);
   2668             if (eError != OMX_ErrorNone) {
   2669                  OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n");
   2670             }
   2671         }
   2672         else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) {
   2673             eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_FreeResource, OMX_MPEG2_Decode_COMPONENT, 0, VIDDEC_MEMUSAGE, NULL);
   2674             if (eError != OMX_ErrorNone) {
   2675                  OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n");
   2676             }
   2677         }
   2678 #ifdef VIDDEC_SPARK_CODE
   2679         else if (VIDDEC_SPARKCHECK) {
   2680             eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_FreeResource, OMX_MPEG4_Decode_COMPONENT, 0, VIDDEC_MEMUSAGE, NULL);
   2681             if (eError != OMX_ErrorNone) {
   2682                  OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n");
   2683             }
   2684         }
   2685 #endif
   2686         else {
   2687             eError = OMX_ErrorUnsupportedSetting;
   2688             goto EXIT;
   2689         }
   2690         pComponentPrivate->eRMProxyState = VidDec_RMPROXY_State_Load;
   2691     }
   2692     if(pComponentPrivate->eRMProxyState != VidDec_RMPROXY_State_Unload){
   2693         eError = RMProxy_DeinitalizeEx(OMX_COMPONENTTYPE_VIDEO);
   2694         if (eError != OMX_ErrorNone) {
   2695             OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n");
   2696         }
   2697         pComponentPrivate->eRMProxyState = VidDec_RMPROXY_State_Unload;
   2698     }
   2699 #endif
   2700 
   2701     VIDDEC_CircBuf_DeInit(pComponentPrivate, VIDDEC_CBUFFER_TIMESTAMP, VIDDEC_INPUT_PORT);
   2702     VIDDEC_Queue_Free(&pComponentPrivate->qBuffMark);
   2703     VIDDEC_Queue_Free(&pComponentPrivate->qCmdMarkData);
   2704     VIDDEC_Queue_Free(&pComponentPrivate->qBytesSent);
   2705     /* Free Resources */
   2706     if(pComponentPrivate->pPortParamType) {
   2707         free(pComponentPrivate->pPortParamType);
   2708         pComponentPrivate->pPortParamType = NULL;
   2709     }
   2710 #ifdef __STD_COMPONENT__
   2711     if(pComponentPrivate->pPortParamTypeAudio) {
   2712         free(pComponentPrivate->pPortParamTypeAudio);
   2713         pComponentPrivate->pPortParamTypeAudio = NULL;
   2714     }
   2715     if(pComponentPrivate->pPortParamTypeImage) {
   2716         free(pComponentPrivate->pPortParamTypeImage);
   2717         pComponentPrivate->pPortParamTypeImage = NULL;
   2718     }
   2719     if(pComponentPrivate->pPortParamTypeOthers) {
   2720         free(pComponentPrivate->pPortParamTypeOthers);
   2721         pComponentPrivate->pPortParamTypeOthers = NULL;
   2722     }
   2723 #endif
   2724 
   2725     buffcount = MAX_PRIVATE_BUFFERS;
   2726     for (i = 0; i < buffcount; i++) {
   2727         if(pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[i]) {
   2728             OMX_PRBUFFER1(pComponentPrivate->dbg, "BufferPrivate cleared 0x%p\n",
   2729                     pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[i]);
   2730             free(pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[i]);
   2731             pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[i] = NULL;
   2732         }
   2733     }
   2734 
   2735     buffcount = MAX_PRIVATE_BUFFERS;
   2736     for (i = 0; i < buffcount; i++) {
   2737         if(pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]) {
   2738             OMX_PRBUFFER1(pComponentPrivate->dbg, "BufferPrivate cleared 0x%p\n",
   2739                     pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]);
   2740             free(pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]);
   2741             pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i] = NULL;
   2742         }
   2743     }
   2744     if(pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]) {
   2745         free(pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]);
   2746         pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT] = NULL;
   2747     }
   2748 
   2749     if(pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]) {
   2750         free(pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]);
   2751         pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT] = NULL;
   2752     }
   2753 
   2754     if(pComponentPrivate->pInPortDef) {
   2755         free(pComponentPrivate->pInPortDef);
   2756         pComponentPrivate->pInPortDef = NULL;
   2757     }
   2758     if(pComponentPrivate->pOutPortDef) {
   2759         free(pComponentPrivate->pOutPortDef);
   2760         pComponentPrivate->pOutPortDef = NULL;
   2761     }
   2762     if(pComponentPrivate->pInPortFormat) {
   2763         free(pComponentPrivate->pInPortFormat);
   2764         pComponentPrivate->pInPortFormat = NULL;
   2765     }
   2766     if(pComponentPrivate->pOutPortFormat) {
   2767         free(pComponentPrivate->pOutPortFormat);
   2768         pComponentPrivate->pOutPortFormat = NULL;
   2769     }
   2770     if(pComponentPrivate->pPriorityMgmt) {
   2771         free(pComponentPrivate->pPriorityMgmt);
   2772         pComponentPrivate->pPriorityMgmt = NULL;
   2773     }
   2774     if(pComponentPrivate->pInBufSupplier) {
   2775         free(pComponentPrivate->pInBufSupplier);
   2776         pComponentPrivate->pInBufSupplier = NULL;
   2777     }
   2778     if(pComponentPrivate->pOutBufSupplier) {
   2779         free(pComponentPrivate->pOutBufSupplier);
   2780         pComponentPrivate->pOutBufSupplier = NULL;
   2781     }
   2782     if(pComponentPrivate->pMpeg4 != NULL) {
   2783         free(pComponentPrivate->pMpeg4);
   2784         pComponentPrivate->pMpeg4 = NULL;
   2785     }
   2786     if(pComponentPrivate->pMpeg2 != NULL) {
   2787         free(pComponentPrivate->pMpeg2);
   2788         pComponentPrivate->pMpeg2 = NULL;
   2789     }
   2790     if(pComponentPrivate->pH264 != NULL) {
   2791         free(pComponentPrivate->pH264);
   2792         pComponentPrivate->pH264 = NULL;
   2793     }
   2794     if(pComponentPrivate->pH263 != NULL) {
   2795         free(pComponentPrivate->pH263);
   2796         pComponentPrivate->pH263 = NULL;
   2797     }
   2798     if(pComponentPrivate->pWMV != NULL) {
   2799         free(pComponentPrivate->pWMV);
   2800         pComponentPrivate->pWMV = NULL;
   2801     }
   2802     if(pComponentPrivate->pDeblockingParamType != NULL) {
   2803         free(pComponentPrivate->pDeblockingParamType);
   2804         pComponentPrivate->pDeblockingParamType = NULL;
   2805     }
   2806 #ifdef ANDROID
   2807     if(pComponentPrivate->pPVCapabilityFlags != NULL) {
   2808         free(pComponentPrivate->pPVCapabilityFlags);
   2809         pComponentPrivate->pPVCapabilityFlags = NULL;
   2810     }
   2811 #endif
   2812     if(pComponentPrivate->cComponentName != NULL) {
   2813         free(pComponentPrivate->cComponentName);
   2814         pComponentPrivate->cComponentName = NULL;
   2815     }
   2816 
   2817     pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]  = 0;
   2818     pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]  = 0;
   2819     pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel2]  = 0;
   2820     pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel3]  = 0;
   2821     pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel4]  = 0;
   2822 
   2823 #ifdef __PERF_INSTRUMENTATION__
   2824     PERF_Boundary(pComponentPrivate->pPERF,
   2825                   PERF_BoundaryComplete | PERF_BoundaryCleanup);
   2826     PERF_Done(pComponentPrivate->pPERF);
   2827 #endif
   2828 
   2829     OMX_DBG_CLOSE(pComponentPrivate->dbg);
   2830 
   2831 #ifndef UNDER_CE
   2832     if(pComponentPrivate->eFirstBuffer.pFirstBufferSaved){
   2833         free(pComponentPrivate->eFirstBuffer.pFirstBufferSaved);
   2834         pComponentPrivate->eFirstBuffer.pFirstBufferSaved = NULL;
   2835         pComponentPrivate->eFirstBuffer.bSaveFirstBuffer = OMX_FALSE;
   2836         pComponentPrivate->eFirstBuffer.nFilledLen = 0;
   2837     }
   2838     if(pComponentPrivate->pCodecData){
   2839         free(pComponentPrivate->pCodecData);
   2840         pComponentPrivate->pCodecData = NULL;
   2841         pComponentPrivate->nCodecDataSize = 0;
   2842     }
   2843     VIDDEC_PTHREAD_MUTEX_DESTROY(pComponentPrivate->sMutex);
   2844     VIDDEC_PTHREAD_SEMAPHORE_DESTROY(pComponentPrivate->sInSemaphore);
   2845     VIDDEC_PTHREAD_SEMAPHORE_DESTROY(pComponentPrivate->sOutSemaphore);
   2846     VIDDEC_PTHREAD_MUTEX_DESTROY(pComponentPrivate->inputFlushCompletionMutex);
   2847     VIDDEC_PTHREAD_MUTEX_DESTROY(pComponentPrivate->outputFlushCompletionMutex);
   2848 #endif
   2849     pthread_mutex_destroy(&(pComponentPrivate->mutexInputBFromApp));
   2850     pthread_mutex_destroy(&(pComponentPrivate->mutexOutputBFromApp));
   2851     pthread_mutex_destroy(&(pComponentPrivate->mutexInputBFromDSP));
   2852     pthread_mutex_destroy(&(pComponentPrivate->mutexOutputBFromDSP));
   2853 
   2854     pthread_mutex_destroy(&pComponentPrivate->mutexStateChangeRequest);
   2855     pthread_cond_destroy(&pComponentPrivate->StateChangeCondition);
   2856 
   2857     if(pComponentPrivate->pUalgParams != NULL){
   2858         OMX_U8* pTemp = NULL;
   2859         pTemp = (OMX_U8*)(pComponentPrivate->pUalgParams);
   2860         pTemp -= VIDDEC_PADDING_HALF;
   2861         pComponentPrivate->pUalgParams = (OMX_PTR*)pTemp;
   2862         free(pComponentPrivate->pUalgParams);
   2863         pComponentPrivate->pUalgParams = NULL;
   2864     }
   2865     if(pHandle->pComponentPrivate != NULL) {
   2866         free(pHandle->pComponentPrivate);
   2867         pHandle->pComponentPrivate = NULL;
   2868         pComponentPrivate = NULL;
   2869     }
   2870 EXIT:
   2871     return eError;
   2872 }
   2873 
   2874 /*----------------------------------------------------------------------------*/
   2875 /**
   2876   *  VIDDEC_UseBuffer()
   2877   *
   2878   *
   2879   *
   2880   *
   2881   * @param
   2882   * @param
   2883   * @param
   2884   *
   2885   * @retval OMX_NoError              Success, ready to roll
   2886   *         OMX_Error_BadParameter   The input parameter pointer is null
   2887   **/
   2888 /*----------------------------------------------------------------------------*/
   2889 
   2890 static OMX_ERRORTYPE VIDDEC_UseBuffer(OMX_IN OMX_HANDLETYPE hComponent,
   2891                                OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
   2892                                OMX_IN OMX_U32 nPortIndex,
   2893                                OMX_IN OMX_PTR pAppPrivate,
   2894                                OMX_IN OMX_U32 nSizeBytes,
   2895                                OMX_IN OMX_U8* pBuffer)
   2896 {
   2897     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2898     OMX_COMPONENTTYPE* pHandle = NULL;
   2899     VIDDEC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
   2900     OMX_PARAM_PORTDEFINITIONTYPE* pPortDef = NULL;
   2901     VIDDEC_PORT_TYPE* pCompPort = NULL;
   2902     OMX_U8 pBufferCnt = 0;
   2903 
   2904     OMX_CONF_CHECK_CMD(hComponent, pBuffer, OMX_TRUE);
   2905 
   2906     pHandle = (OMX_COMPONENTTYPE*)hComponent;
   2907     pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
   2908 
   2909     OMX_PRBUFFER1(pComponentPrivate->dbg, "+++Entering pHandle 0x%p ppBufferHdr 0x%p pBuffer 0x%p nPortIndex 0x%lx nSizeBytes 0x%lx\n",
   2910         hComponent, *ppBufferHdr, pBuffer, nPortIndex, nSizeBytes);
   2911 
   2912 #ifdef __PERF_INSTRUMENTATION__
   2913     PERF_ReceivedFrame(pComponentPrivate->pPERF,
   2914                        pBuffer,
   2915                        nSizeBytes,
   2916                        PERF_ModuleHLMM);
   2917 #endif
   2918 
   2919     if (nPortIndex == pComponentPrivate->pInPortFormat->nPortIndex) {
   2920         pCompPort = pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT];
   2921         pBufferCnt = pCompPort->nBufferCnt;
   2922         pPortDef = pComponentPrivate->pInPortDef;
   2923     }
   2924     else if (nPortIndex == pComponentPrivate->pOutPortFormat->nPortIndex) {
   2925         pCompPort = pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT];
   2926         pBufferCnt = pCompPort->nBufferCnt;
   2927         pPortDef = pComponentPrivate->pOutPortDef;
   2928     }
   2929     else {
   2930         eError = OMX_ErrorBadPortIndex;
   2931         goto EXIT;
   2932     }
   2933 
   2934     if(!pPortDef->bEnabled){
   2935         OMX_ERROR4(pComponentPrivate->dbg, "Error: port disabled\n");
   2936         eError = OMX_ErrorIncorrectStateOperation;
   2937         goto EXIT;
   2938     }
   2939 
   2940     OMX_PRBUFFER1(pComponentPrivate->dbg, "pPortDef->nBufferSize %d nSizeBytes %d %d\n", (int )pPortDef->nBufferSize,
   2941         (int )nSizeBytes,(int )(pPortDef->nBufferSize > nSizeBytes));
   2942     pPortDef->nBufferSize = nSizeBytes;
   2943     if(nSizeBytes != pPortDef->nBufferSize || pPortDef->bPopulated){
   2944         OMX_PRBUFFER4(pComponentPrivate->dbg, "Error: badparameter\n");
   2945         eError = OMX_ErrorBadParameter;
   2946         goto EXIT;
   2947     }
   2948 
   2949     OMX_MALLOC_STRUCT(pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr, OMX_BUFFERHEADERTYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
   2950     if (!pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr) {
   2951         OMX_TRACE4(pComponentPrivate->dbg, "Error: Malloc failed\n");
   2952         eError = OMX_ErrorInsufficientResources;
   2953         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   2954                                                pComponentPrivate->pHandle->pApplicationPrivate,
   2955                                                OMX_EventError,
   2956                                                eError,
   2957                                                OMX_TI_ErrorMajor,
   2958                                                NULL);
   2959         goto EXIT;
   2960     }
   2961 
   2962     *ppBufferHdr = pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr;
   2963     memset(*ppBufferHdr, 0, sizeof(OMX_BUFFERHEADERTYPE));
   2964     OMX_CONF_INIT_STRUCT(pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr, OMX_BUFFERHEADERTYPE, pComponentPrivate->dbg);
   2965 
   2966     (*ppBufferHdr)->pBuffer = pBuffer;
   2967     (*ppBufferHdr)->nAllocLen = nSizeBytes;
   2968     (*ppBufferHdr)->pAppPrivate = pAppPrivate;
   2969     (*ppBufferHdr)->pMarkData = NULL;
   2970 #ifndef VIDDEC_WMVPOINTERFIXED
   2971     if (pComponentPrivate->nWMVFileType == VIDDEC_WMV_ELEMSTREAM &&
   2972         pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV &&
   2973         pComponentPrivate->ProcessMode == 0 &&
   2974         nPortIndex == VIDDEC_INPUT_PORT) {
   2975         /* vc-1 fix */
   2976         (*ppBufferHdr)->nOffset = VIDDEC_WMV_BUFFER_OFFSET;
   2977     }
   2978 #endif
   2979     if (pCompPort->hTunnelComponent != NULL) {
   2980         if (pPortDef->eDir == OMX_DirInput) {
   2981             (*ppBufferHdr)->nInputPortIndex  = nPortIndex;
   2982             (*ppBufferHdr)->nOutputPortIndex = pComponentPrivate->pCompPort[nPortIndex]->nTunnelPort;
   2983         }
   2984         else {
   2985             (*ppBufferHdr)->nInputPortIndex  = pComponentPrivate->pCompPort[nPortIndex]->nTunnelPort;
   2986             (*ppBufferHdr)->nOutputPortIndex = nPortIndex;
   2987         }
   2988     }
   2989     else {
   2990         if (nPortIndex == VIDDEC_INPUT_PORT) {
   2991             (*ppBufferHdr)->nInputPortIndex  = VIDDEC_INPUT_PORT;
   2992             (*ppBufferHdr)->nOutputPortIndex = VIDDEC_NOPORT;
   2993         }
   2994         else {
   2995             (*ppBufferHdr)->nInputPortIndex  = VIDDEC_NOPORT;
   2996             (*ppBufferHdr)->nOutputPortIndex = VIDDEC_OUTPUT_PORT;
   2997         }
   2998     }
   2999 
   3000     if (nPortIndex == VIDDEC_INPUT_PORT) {
   3001         (*ppBufferHdr)->pInputPortPrivate = pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[pBufferCnt];
   3002     }
   3003     else {
   3004         (*ppBufferHdr)->pOutputPortPrivate = pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[pBufferCnt];
   3005     }
   3006     pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[pBufferCnt]->bAllocByComponent = OMX_FALSE;
   3007 
   3008     if (pCompPort->hTunnelComponent != NULL) {
   3009         pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[pBufferCnt]->eBufferOwner = VIDDEC_BUFFER_WITH_TUNNELEDCOMP;
   3010     }
   3011     else {
   3012         pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[pBufferCnt]->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
   3013     }
   3014 
   3015     OMX_PRBUFFER1(pComponentPrivate->dbg, "ppBufferHdr 0x%p pBuffer 0x%p nAllocLen %lu eBufferOwner %d\n",
   3016         *ppBufferHdr, pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr->pBuffer, (*ppBufferHdr)->nAllocLen,
   3017         pCompPort->pBufferPrivate[pBufferCnt]->eBufferOwner);
   3018 
   3019     eError = VIDDEC_Allocate_DSPResources(pComponentPrivate, nPortIndex);
   3020     if (eError != OMX_ErrorNone) {
   3021         eError = OMX_ErrorInsufficientResources;
   3022         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   3023                                                pComponentPrivate->pHandle->pApplicationPrivate,
   3024                                                OMX_EventError,
   3025                                                eError,
   3026                                                OMX_TI_ErrorMajor,
   3027                                                NULL);
   3028         goto EXIT;
   3029     }
   3030 
   3031     pCompPort->nBufferCnt++;
   3032 
   3033     if (pCompPort->nBufferCnt == pPortDef->nBufferCountActual) {
   3034         pPortDef->bPopulated = OMX_TRUE;
   3035 #ifndef UNDER_CE
   3036         if (nPortIndex == VIDDEC_INPUT_PORT) {
   3037             VIDDEC_PTHREAD_SEMAPHORE_POST(pComponentPrivate->sInSemaphore);
   3038         }
   3039         else {
   3040             VIDDEC_PTHREAD_SEMAPHORE_POST(pComponentPrivate->sOutSemaphore);
   3041         }
   3042 #endif
   3043     }
   3044 EXIT:
   3045     if (pComponentPrivate)
   3046         OMX_PRBUFFER1(pComponentPrivate->dbg, "---Exiting eError 0x%x\n", \
   3047                                                          eError);
   3048     return eError;
   3049 }
   3050 
   3051 /*----------------------------------------------------------------------------*/
   3052 /**
   3053   *  VIDDEC_FreeBuffer()
   3054   *
   3055   *
   3056   *
   3057   *
   3058   * @param
   3059   * @param
   3060   * @param
   3061   *
   3062   * @retval OMX_NoError              Success, ready to roll
   3063   *         OMX_Error_BadParameter   The input parameter pointer is null
   3064   **/
   3065 /*----------------------------------------------------------------------------*/
   3066 
   3067 static OMX_ERRORTYPE VIDDEC_FreeBuffer (OMX_IN OMX_HANDLETYPE hComponent,
   3068                                  OMX_IN OMX_U32 nPortIndex,
   3069                                  OMX_IN OMX_BUFFERHEADERTYPE* pBuffHead)
   3070 {
   3071     OMX_ERRORTYPE eError = OMX_ErrorNone;
   3072     OMX_COMPONENTTYPE* pHandle = NULL;
   3073     VIDDEC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
   3074     VIDDEC_BUFFER_PRIVATE* pBufferPrivate = NULL;
   3075     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
   3076     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
   3077     VIDDEC_PORT_TYPE* pCompPort = NULL;
   3078     OMX_PARAM_PORTDEFINITIONTYPE* pPortDef = NULL;
   3079     OMX_U8* pTemp = NULL;
   3080     OMX_U32 i = 0;
   3081     VIDDEC_PORT_TYPE* pInCompPort = NULL;
   3082     OMX_U8 pInBufferCnt = 0;
   3083     VIDDEC_PORT_TYPE* pOutCompPort = NULL;
   3084     OMX_U8 pOutBufferCnt = 0;
   3085     OMX_U32 buffcount = 0;
   3086     OMX_STATETYPE TunnelState = OMX_StateInvalid;
   3087     OMX_BOOL bTransIdle = OMX_FALSE;
   3088 
   3089     OMX_CONF_CHECK_CMD(hComponent, pBuffHead, OMX_TRUE);
   3090 
   3091     pHandle = (OMX_COMPONENTTYPE*)hComponent;
   3092     pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
   3093 
   3094     OMX_PRBUFFER1(pComponentPrivate->dbg, "+++Entering pHandle 0x%p pBuffHead 0x%p nPortIndex %lu nFilledLen %lx nAllocLen %lx\n",
   3095         hComponent, pBuffHead, nPortIndex,pBuffHead->nFilledLen,pBuffHead->nAllocLen);
   3096 
   3097     pPortDefIn = pComponentPrivate->pInPortDef;
   3098     pPortDefOut = pComponentPrivate->pOutPortDef;
   3099 
   3100     pInCompPort = pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT];
   3101     pInBufferCnt = pInCompPort->nBufferCnt;
   3102     pOutCompPort = pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT];
   3103     pOutBufferCnt = pOutCompPort->nBufferCnt;
   3104 
   3105     if (nPortIndex == pComponentPrivate->pInPortFormat->nPortIndex) {
   3106         pPortDef = pComponentPrivate->pInPortDef;
   3107         pCompPort = pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT];
   3108         pBufferPrivate = pBuffHead->pInputPortPrivate;
   3109     }
   3110     else if (nPortIndex == pComponentPrivate->pOutPortFormat->nPortIndex) {
   3111         pPortDef = pComponentPrivate->pOutPortDef;
   3112         pCompPort = pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT];
   3113         pBufferPrivate = pBuffHead->pOutputPortPrivate;
   3114     }
   3115     else {
   3116         eError = OMX_ErrorBadPortIndex;
   3117         goto EXIT;
   3118     }
   3119 
   3120     /*if(pPortDef->bEnabled && pComponentPrivate->eState != OMX_StateIdle){
   3121         OMX_ERROR4(pComponentPrivate->dbg, "Error: port disabled\n");
   3122         eError = OMX_ErrorIncorrectStateOperation;
   3123         goto EXIT;
   3124     }*/
   3125 
   3126     if (pPortDefIn->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
   3127         pPortDefIn->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) {
   3128         if (nPortIndex == pComponentPrivate->pInPortFormat->nPortIndex) {
   3129             OMX_MEMFREE_STRUCT_DSPALIGN(pBufferPrivate->pUalgParam,OMX_PTR);
   3130             pBufferPrivate->nUalgParamSize = 0;
   3131         }
   3132         else if (nPortIndex == pComponentPrivate->pOutPortFormat->nPortIndex) {
   3133             OMX_MEMFREE_STRUCT_DSPALIGN(pBufferPrivate->pUalgParam,OMX_PTR);
   3134             pBufferPrivate->nUalgParamSize = 0;
   3135         }
   3136         else {
   3137             eError = OMX_ErrorBadPortIndex;
   3138             goto EXIT;
   3139         }
   3140     }
   3141 #ifdef VIDDEC_SPARK_CODE
   3142     else if (VIDDEC_SPARKCHECK) {
   3143         if (nPortIndex == pComponentPrivate->pInPortFormat->nPortIndex) {
   3144             OMX_MEMFREE_STRUCT_DSPALIGN(pBufferPrivate->pUalgParam,OMX_PTR);
   3145             pBufferPrivate->nUalgParamSize = 0;
   3146         }
   3147         else if (nPortIndex == pComponentPrivate->pOutPortFormat->nPortIndex) {
   3148             OMX_MEMFREE_STRUCT_DSPALIGN(pBufferPrivate->pUalgParam,OMX_PTR);
   3149             pBufferPrivate->nUalgParamSize = 0;
   3150         }
   3151         else {
   3152             eError = OMX_ErrorBadPortIndex;
   3153             goto EXIT;
   3154         }
   3155     }
   3156 #endif
   3157     else if (pPortDefIn->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) {
   3158         if (nPortIndex == pComponentPrivate->pInPortFormat->nPortIndex) {
   3159             OMX_MEMFREE_STRUCT_DSPALIGN(pBufferPrivate->pUalgParam,OMX_PTR);
   3160             pBufferPrivate->nUalgParamSize = 0;
   3161         }
   3162         else if (nPortIndex == pComponentPrivate->pOutPortFormat->nPortIndex) {
   3163             OMX_MEMFREE_STRUCT_DSPALIGN(pBufferPrivate->pUalgParam,OMX_PTR);
   3164             pBufferPrivate->nUalgParamSize = 0;
   3165         }
   3166         else {
   3167             eError = OMX_ErrorBadPortIndex;
   3168             goto EXIT;
   3169         }
   3170     }
   3171     else if (pPortDefIn->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
   3172         if (nPortIndex == pComponentPrivate->pInPortFormat->nPortIndex) {
   3173             OMX_MEMFREE_STRUCT_DSPALIGN(pBufferPrivate->pUalgParam,OMX_PTR);
   3174             pBufferPrivate->nUalgParamSize = 0;
   3175         }
   3176         else if (nPortIndex == pComponentPrivate->pOutPortFormat->nPortIndex) {
   3177             OMX_MEMFREE_STRUCT_DSPALIGN(pBufferPrivate->pUalgParam,OMX_PTR);
   3178             pBufferPrivate->nUalgParamSize = 0;
   3179         }
   3180         else {
   3181             eError = OMX_ErrorBadPortIndex;
   3182             goto EXIT;
   3183         }
   3184     }
   3185     else if (pPortDefIn->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) {
   3186         if (nPortIndex == pComponentPrivate->pInPortFormat->nPortIndex) {
   3187             OMX_MEMFREE_STRUCT_DSPALIGN(pBufferPrivate->pUalgParam,OMX_PTR);
   3188             pBufferPrivate->nUalgParamSize = 0;
   3189         }
   3190         else if (nPortIndex == pComponentPrivate->pOutPortFormat->nPortIndex) {
   3191             OMX_MEMFREE_STRUCT_DSPALIGN(pBufferPrivate->pUalgParam,OMX_PTR);
   3192             pBufferPrivate->nUalgParamSize = 0;
   3193         }
   3194         else {
   3195             eError = OMX_ErrorBadPortIndex;
   3196             goto EXIT;
   3197         }
   3198     }
   3199     else {
   3200         OMX_ERROR4(pComponentPrivate->dbg, "Error: Invalid Compression Type\n");
   3201         goto EXIT;
   3202     }
   3203     OMX_PRBUFFER1(pComponentPrivate->dbg, "bAllocByComponent 0x%x pBuffer 0x%p\n", (int )pBufferPrivate->bAllocByComponent,
   3204         pBuffHead->pBuffer);
   3205     if (pBufferPrivate->bAllocByComponent == OMX_TRUE) {
   3206         if(pBuffHead->pBuffer != NULL){
   3207 #ifdef __PERF_INSTRUMENTATION__
   3208            PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   3209                              pBuffHead->pBuffer,
   3210                              pBuffHead->nAllocLen,
   3211                              PERF_ModuleMemory);
   3212 #endif
   3213 
   3214       /* Freeing the original buffer position were data buffer was allocated */
   3215            if(pBufferPrivate->pOriginalBuffer != NULL){
   3216               pBuffHead->pBuffer = pBufferPrivate->pOriginalBuffer;
   3217               pBufferPrivate->pOriginalBuffer = NULL;
   3218               OMX_FREE_VIDDEC(pBuffHead->pBuffer);
   3219            } else{
   3220                OMX_FREE_BUFFER_VIDDEC(pBuffHead, pCompPort);
   3221            }
   3222         }
   3223     }
   3224 
   3225     buffcount = pPortDef->nBufferCountActual;
   3226     for(i = 0; i < buffcount; i++){
   3227         if (pCompPort->pBufferPrivate[i]->pBufferHdr == pBuffHead){
   3228             OMX_PRBUFFER1(pComponentPrivate->dbg, "buffcount %lu eBufferOwner 0x%x\n", i, pCompPort->pBufferPrivate[i]->eBufferOwner);
   3229             free(pCompPort->pBufferPrivate[i]->pBufferHdr);
   3230             pCompPort->pBufferPrivate[i]->pBufferHdr = NULL;
   3231             pBuffHead = NULL;
   3232         }
   3233     }
   3234     if(pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->hTunnelComponent != NULL){
   3235         eError = OMX_GetState(pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->hTunnelComponent,&TunnelState);
   3236         if(eError != OMX_ErrorNone) {
   3237             OMX_ERROR4(pComponentPrivate->dbg, "GetState Invalid return\n");
   3238             goto EXIT;
   3239         }
   3240         OMX_PRCOMM2(pComponentPrivate->dbg, "TunnelState %d\n", TunnelState);
   3241     }
   3242     if((pComponentPrivate->eState == OMX_StateIdle) && (pComponentPrivate->eIdleToLoad == OMX_StateLoaded)){
   3243         bTransIdle = OMX_TRUE;
   3244     }
   3245     else {
   3246         bTransIdle = OMX_FALSE;
   3247     }
   3248     if (nPortIndex == pComponentPrivate->pInPortFormat->nPortIndex) {
   3249         pInBufferCnt--;
   3250         pInCompPort->nBufferCnt--;
   3251         if (pInBufferCnt == 0) {
   3252             pPortDefIn->bPopulated = OMX_FALSE;
   3253 #ifndef UNDER_CE
   3254             if (nPortIndex == VIDDEC_INPUT_PORT) {
   3255                 VIDDEC_PTHREAD_SEMAPHORE_POST(pComponentPrivate->sInSemaphore);
   3256             }
   3257             else {
   3258                 VIDDEC_PTHREAD_SEMAPHORE_POST(pComponentPrivate->sOutSemaphore);
   3259             }
   3260 #endif
   3261             if (bTransIdle) {
   3262                 i = 0;
   3263             }
   3264             else if ((!pPortDef->bEnabled && (pComponentPrivate->eState == OMX_StateIdle ||
   3265                       pComponentPrivate->eState == OMX_StateExecuting
   3266                       || pComponentPrivate->eState == OMX_StatePause))) {
   3267                 i = 0;
   3268             }
   3269             else {
   3270                 if (pComponentPrivate->eState != OMX_StateInvalid) {
   3271                 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle,
   3272                                                         pComponentPrivate->pHandle->pApplicationPrivate,
   3273                                                         OMX_EventError,
   3274                                                         OMX_ErrorPortUnpopulated,
   3275                                                         OMX_TI_ErrorMinor,
   3276                                                         "Input Port Unpopulated");
   3277                 }
   3278             }
   3279         }
   3280     }
   3281 
   3282     else if (nPortIndex == pComponentPrivate->pOutPortFormat->nPortIndex) {
   3283         pOutBufferCnt--;
   3284         pOutCompPort->nBufferCnt--;
   3285         if (pOutBufferCnt == 0) {
   3286             pPortDefOut->bPopulated = OMX_FALSE;
   3287 #ifndef UNDER_CE
   3288             if (nPortIndex == VIDDEC_INPUT_PORT) {
   3289                 VIDDEC_PTHREAD_SEMAPHORE_POST(pComponentPrivate->sInSemaphore);
   3290             }
   3291             else {
   3292                 VIDDEC_PTHREAD_SEMAPHORE_POST(pComponentPrivate->sOutSemaphore);
   3293             }
   3294 #endif
   3295             if ((pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->hTunnelComponent == NULL) &&  bTransIdle) {
   3296                 i = 0;
   3297             }
   3298             else if ((pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->hTunnelComponent != NULL) &&  (TunnelState == OMX_StateIdle)) {
   3299                 i = 0;
   3300             }
   3301             else if ((!pPortDef->bEnabled && (pComponentPrivate->eState == OMX_StateIdle ||
   3302                       pComponentPrivate->eState == OMX_StateExecuting
   3303                       || pComponentPrivate->eState == OMX_StatePause))) {
   3304                 i = 0;
   3305             }
   3306             else {
   3307                 if (pComponentPrivate->eState != OMX_StateInvalid) {
   3308                 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle,
   3309                                                         pComponentPrivate->pHandle->pApplicationPrivate,
   3310                                                         OMX_EventError,
   3311                                                         OMX_ErrorPortUnpopulated,
   3312                                                         OMX_TI_ErrorMinor,
   3313                                                         "Output Port Unpopulated");
   3314                 }
   3315             }
   3316         }
   3317     }
   3318 
   3319 EXIT:
   3320     if (pComponentPrivate)
   3321         OMX_PRBUFFER1(pComponentPrivate->dbg, "---Exiting eError 0x%x\n", \
   3322                                                         eError);
   3323     return eError;
   3324 }
   3325 
   3326 /*----------------------------------------------------------------------------*/
   3327 /**
   3328   *  VIDDEC_AllocateBuffer()
   3329   *
   3330   *
   3331   *
   3332   *
   3333   * @param
   3334   * @param
   3335   * @param
   3336   *
   3337   * @retval OMX_NoError              Success, ready to roll
   3338   *         OMX_Error_BadParameter   The input parameter pointer is null
   3339   **/
   3340 /*----------------------------------------------------------------------------*/
   3341 
   3342 static OMX_ERRORTYPE VIDDEC_AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent,
   3343                                      OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffHead,
   3344                                      OMX_IN OMX_U32 nPortIndex,
   3345                                      OMX_IN OMX_PTR pAppPrivate,
   3346                                      OMX_IN OMX_U32 nSizeBytes)
   3347 {
   3348     OMX_ERRORTYPE eError = OMX_ErrorNone;
   3349     OMX_COMPONENTTYPE* pHandle = NULL;
   3350     VIDDEC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
   3351     OMX_PARAM_PORTDEFINITIONTYPE* pPortDef = NULL;
   3352     VIDDEC_PORT_TYPE* pCompPort = NULL;
   3353     OMX_U8 pBufferCnt = 0;
   3354 
   3355     OMX_CONF_CHECK_CMD(hComponent, OMX_TRUE, OMX_TRUE);
   3356 
   3357     pHandle = (OMX_COMPONENTTYPE*)hComponent;
   3358     pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
   3359 
   3360     OMX_PRBUFFER1(pComponentPrivate->dbg, "+++Entering pHandle 0x%p pBuffHead 0x%p nPortIndex 0x%lx nSizeBytes 0x%lx\n",
   3361         hComponent, *pBuffHead, nPortIndex, nSizeBytes);
   3362 
   3363 
   3364     if (nPortIndex == pComponentPrivate->pInPortFormat->nPortIndex) {
   3365         pCompPort = pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT];
   3366         pBufferCnt = pCompPort->nBufferCnt;
   3367         pPortDef = pComponentPrivate->pInPortDef;
   3368     }
   3369     else if (nPortIndex == pComponentPrivate->pOutPortFormat->nPortIndex) {
   3370         pCompPort = pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT];
   3371         pBufferCnt = pCompPort->nBufferCnt;
   3372         pPortDef = pComponentPrivate->pOutPortDef;
   3373     }
   3374     else {
   3375         eError = OMX_ErrorBadPortIndex;
   3376         goto EXIT;
   3377     }
   3378 
   3379     OMX_MALLOC_STRUCT(pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr, OMX_BUFFERHEADERTYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
   3380     if (!pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr) {
   3381         eError = OMX_ErrorInsufficientResources;
   3382         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   3383                                                pComponentPrivate->pHandle->pApplicationPrivate,
   3384                                                OMX_EventError,
   3385                                                eError,
   3386                                                OMX_TI_ErrorMajor,
   3387                                                NULL);
   3388         goto EXIT;
   3389     }
   3390 
   3391     *pBuffHead = pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr;
   3392     memset(*pBuffHead, 0, sizeof(OMX_BUFFERHEADERTYPE));
   3393     OMX_CONF_INIT_STRUCT(pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr, OMX_BUFFERHEADERTYPE, pComponentPrivate->dbg);
   3394     /* Allocate Video Decoder buffer */
   3395     OMX_MALLOC_STRUCT_SIZED((*pBuffHead)->pBuffer, OMX_U8, OMX_GET_DATABUFF_SIZE(nSizeBytes), NULL);
   3396     if (!((*pBuffHead)->pBuffer)) {
   3397         eError = OMX_ErrorInsufficientResources;
   3398         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   3399                                                pComponentPrivate->pHandle->pApplicationPrivate,
   3400                                                OMX_EventError,
   3401                                                eError,
   3402                                                OMX_TI_ErrorMajor,
   3403                                                NULL);
   3404         goto EXIT;
   3405     }
   3406     /* Align and add padding for data buffer */
   3407     pCompPort->pBufferPrivate[pBufferCnt]->pOriginalBuffer = (*pBuffHead)->pBuffer;
   3408     (*pBuffHead)->pBuffer += VIDDEC_PADDING_HALF;
   3409     OMX_ALIGN_BUFFER((*pBuffHead)->pBuffer, VIDDEC_ALIGNMENT);
   3410 #ifdef VIDDEC_WMVPOINTERFIXED
   3411     pCompPort->pBufferPrivate[pBufferCnt]->pTempBuffer = (*pBuffHead)->pBuffer;
   3412     (*pBuffHead)->nOffset = 0;
   3413 #endif
   3414 
   3415     (*pBuffHead)->pBuffer = (pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr->pBuffer);
   3416     (*pBuffHead)->nAllocLen = nSizeBytes;
   3417     (*pBuffHead)->pAppPrivate = pAppPrivate;
   3418     (*pBuffHead)->pPlatformPrivate = NULL;
   3419     (*pBuffHead)->pInputPortPrivate = NULL;
   3420     (*pBuffHead)->pOutputPortPrivate = NULL;
   3421     (*pBuffHead)->nFlags = VIDDEC_CLEARFLAGS;
   3422     (*pBuffHead)->pMarkData = NULL;
   3423 
   3424 #ifdef __PERF_INSTRUMENTATION__
   3425     PERF_ReceivedFrame(pComponentPrivate->pPERFcomp,
   3426                        (*pBuffHead)->pBuffer,
   3427                        (*pBuffHead)->nAllocLen,
   3428                        PERF_ModuleMemory);
   3429 #endif
   3430 
   3431 
   3432     if (pCompPort->hTunnelComponent != NULL) {
   3433         if (pPortDef->eDir == OMX_DirInput) {
   3434             (*pBuffHead)->nInputPortIndex  = nPortIndex;
   3435             (*pBuffHead)->nOutputPortIndex = pCompPort->nTunnelPort;
   3436         }
   3437         else {
   3438             (*pBuffHead)->nInputPortIndex  = pCompPort->nTunnelPort;
   3439             (*pBuffHead)->nOutputPortIndex = nPortIndex;
   3440         }
   3441     }
   3442     else {
   3443         if (nPortIndex == VIDDEC_INPUT_PORT) {
   3444             (*pBuffHead)->nInputPortIndex  = VIDDEC_INPUT_PORT;
   3445             (*pBuffHead)->nOutputPortIndex = VIDDEC_NOPORT;
   3446         }
   3447         else {
   3448             (*pBuffHead)->nInputPortIndex  = VIDDEC_NOPORT;
   3449             (*pBuffHead)->nOutputPortIndex = VIDDEC_OUTPUT_PORT;
   3450         }
   3451     }
   3452 
   3453     if (nPortIndex == VIDDEC_INPUT_PORT) {
   3454         (*pBuffHead)->pInputPortPrivate = pCompPort->pBufferPrivate[pBufferCnt];
   3455         (*pBuffHead)->pOutputPortPrivate = NULL;
   3456     }
   3457     else {
   3458         (*pBuffHead)->pOutputPortPrivate = pCompPort->pBufferPrivate[pBufferCnt];
   3459         (*pBuffHead)->pInputPortPrivate = NULL;
   3460     }
   3461     pCompPort->pBufferPrivate[pBufferCnt]->bAllocByComponent = OMX_TRUE;
   3462 
   3463     if (pCompPort->hTunnelComponent != NULL) {
   3464         pCompPort->pBufferPrivate[pBufferCnt]->eBufferOwner = VIDDEC_BUFFER_WITH_TUNNELEDCOMP;
   3465     }
   3466     else {
   3467         pCompPort->pBufferPrivate[pBufferCnt]->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
   3468     }
   3469 
   3470     pPortDef->nBufferSize = nSizeBytes;
   3471     OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead 0x%p nAllocLen 0x%lx pBuffer %p eBufferOwner %d\n",
   3472         *pBuffHead, (*pBuffHead)->nAllocLen, pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr->pBuffer,
   3473         pCompPort->pBufferPrivate[pBufferCnt]->eBufferOwner);
   3474 
   3475     eError = VIDDEC_Allocate_DSPResources(pComponentPrivate, nPortIndex);
   3476     if (eError != OMX_ErrorNone) {
   3477         OMX_PRDSP4(pComponentPrivate->dbg, "Error: Allocating DSP resources\n");
   3478         eError = OMX_ErrorInsufficientResources;
   3479         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   3480                                                pComponentPrivate->pHandle->pApplicationPrivate,
   3481                                                OMX_EventError,
   3482                                                eError,
   3483                                                OMX_TI_ErrorMajor,
   3484                                                NULL);
   3485         goto EXIT;
   3486     }
   3487 
   3488     pCompPort->nBufferCnt++;
   3489     pCompPort->pBufferPrivate[pBufferCnt]->nNumber = pCompPort->nBufferCnt;
   3490 
   3491     OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x nBufferCountActual %lu nBufferCnt %u nnumber %lu\n",
   3492         pCompPort->pBufferPrivate[pBufferCnt]->eBufferOwner, pPortDef->nBufferCountActual,
   3493         pCompPort->nBufferCnt,pCompPort->pBufferPrivate[pBufferCnt]->nNumber);
   3494     if (pCompPort->nBufferCnt == pPortDef->nBufferCountActual) {
   3495         pPortDef->bPopulated = OMX_TRUE;
   3496 #ifndef UNDER_CE
   3497             if (nPortIndex == VIDDEC_INPUT_PORT) {
   3498                 VIDDEC_PTHREAD_SEMAPHORE_POST(pComponentPrivate->sInSemaphore);
   3499             }
   3500             else {
   3501                 VIDDEC_PTHREAD_SEMAPHORE_POST(pComponentPrivate->sOutSemaphore);
   3502             }
   3503 #endif
   3504     }
   3505 
   3506 EXIT:
   3507     if (pComponentPrivate)
   3508         OMX_PRBUFFER1(pComponentPrivate->dbg, "---Exiting eError 0x%x\n", \
   3509                                                          eError);
   3510     return eError;
   3511 }
   3512 
   3513 #ifdef KHRONOS_1_1
   3514 /*-------------------------------------------------------------------*/
   3515 /**
   3516   * IsTIOMXComponent()
   3517   *
   3518   * Check if the component is TI component.
   3519   *
   3520   * @param hTunneledComp Component Tunnel Pipe
   3521   *
   3522   * @retval OMX_TRUE   Input is a TI component.
   3523   *         OMX_FALSE  Input is a not a TI component.
   3524   *
   3525   **/
   3526 /*-------------------------------------------------------------------*/
   3527 static OMX_BOOL IsTIOMXComponent(OMX_HANDLETYPE hComp, struct OMX_TI_Debug *dbg)
   3528 {
   3529     OMX_ERRORTYPE eError = OMX_ErrorNone;
   3530     /*OMX_PARAM_BUFFERSUPPLIERTYPE sBufferSupplier;*/
   3531     OMX_STRING pTunnelcComponentName = NULL;
   3532     OMX_VERSIONTYPE* pTunnelComponentVersion = NULL;
   3533     OMX_VERSIONTYPE* pSpecVersion = NULL;
   3534     OMX_UUIDTYPE* pComponentUUID = NULL;
   3535     char *pSubstring = NULL;
   3536     OMX_BOOL bResult = OMX_TRUE;
   3537 
   3538     pTunnelcComponentName = malloc(128);
   3539     if (pTunnelcComponentName == NULL) {
   3540         eError = OMX_ErrorInsufficientResources;
   3541         OMX_TRACE4(*dbg, "Error in Video Decoder OMX_ErrorInsufficientResources\n");
   3542         goto EXIT;
   3543     }
   3544 
   3545     pTunnelComponentVersion = malloc(sizeof(OMX_VERSIONTYPE));
   3546     if (pTunnelComponentVersion == NULL) {
   3547         OMX_TRACE4(*dbg, "Error in Video Decoder OMX_ErrorInsufficientResources\n");
   3548         eError = OMX_ErrorInsufficientResources;
   3549         goto EXIT;
   3550     }
   3551 
   3552     pSpecVersion = malloc(sizeof(OMX_VERSIONTYPE));
   3553     if (pSpecVersion == NULL) {
   3554         OMX_TRACE4(*dbg, "Error in Video Decoder OMX_ErrorInsufficientResources\n");
   3555         eError = OMX_ErrorInsufficientResources;
   3556         goto EXIT;
   3557     }
   3558 
   3559     pComponentUUID = malloc(sizeof(OMX_UUIDTYPE));
   3560     if (pComponentUUID == NULL) {
   3561         OMX_TRACE4(*dbg, "Error in Video Decoder OMX_ErrorInsufficientResources\n");
   3562         eError = OMX_ErrorInsufficientResources;
   3563         goto EXIT;
   3564     }
   3565 
   3566     eError = OMX_GetComponentVersion (hComp, pTunnelcComponentName, pTunnelComponentVersion, pSpecVersion, pComponentUUID);
   3567 
   3568     /* Check if tunneled component is a TI component */
   3569     pSubstring = strstr(pTunnelcComponentName, "OMX.TI.");
   3570     if(pSubstring == NULL) {
   3571                 bResult = OMX_FALSE;
   3572     }
   3573 
   3574 EXIT:
   3575     free(pTunnelcComponentName);
   3576     free(pTunnelComponentVersion);
   3577     free(pSpecVersion);
   3578     free(pComponentUUID);
   3579 
   3580     return bResult;
   3581 } /* End of IsTIOMXComponent */
   3582 #endif
   3583 
   3584 /*----------------------------------------------------------------------------*/
   3585 /**
   3586   *  VIDDEC_VerifyTunnelConnection()
   3587   *
   3588   *
   3589   *
   3590   *
   3591   * @param
   3592   * @param
   3593   * @param
   3594   *
   3595   * @retval OMX_NoError              Success, ready to roll
   3596   *         OMX_Error_BadParameter   The input parameter pointer is null
   3597   **/
   3598 /*----------------------------------------------------------------------------*/
   3599 
   3600 static OMX_ERRORTYPE VIDDEC_VerifyTunnelConnection (VIDDEC_PORT_TYPE *pPort,
   3601                                              OMX_HANDLETYPE hTunneledComp,
   3602                                              OMX_PARAM_PORTDEFINITIONTYPE* pPortDef)
   3603 {
   3604     OMX_PARAM_PORTDEFINITIONTYPE sPortDef;
   3605     OMX_ERRORTYPE eError = OMX_ErrorNone;
   3606 
   3607     sPortDef.nSize                    = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
   3608     sPortDef.nVersion.s.nVersionMajor = VERSION_MAJOR;
   3609     sPortDef.nVersion.s.nVersionMinor = VERSION_MINOR;
   3610     sPortDef.nVersion.s.nRevision     = VERSION_REVISION;
   3611     sPortDef.nVersion.s.nStep         = VERSION_STEP;
   3612     sPortDef.nPortIndex               = pPort->nTunnelPort;
   3613 
   3614     eError = OMX_GetParameter(hTunneledComp, OMX_IndexParamPortDefinition, &sPortDef);
   3615     if (eError != OMX_ErrorNone) {
   3616         return eError;
   3617     }
   3618 
   3619     switch (pPortDef->eDomain) {
   3620         case OMX_PortDomainOther:
   3621             if (sPortDef.format.other.eFormat != pPortDef->format.other.eFormat) {
   3622                 pPort->hTunnelComponent = 0;
   3623                 pPort->nTunnelPort      = 0;
   3624                 return OMX_ErrorPortsNotCompatible;
   3625             }
   3626             break;
   3627         case OMX_PortDomainAudio:
   3628             if (sPortDef.format.audio.eEncoding != pPortDef->format.audio.eEncoding) {
   3629                 pPort->hTunnelComponent = 0;
   3630                 pPort->nTunnelPort      = 0;
   3631                 return OMX_ErrorPortsNotCompatible;
   3632             }
   3633             break;
   3634         case OMX_PortDomainVideo:
   3635             if (sPortDef.format.video.eCompressionFormat != pPortDef->format.video.eCompressionFormat) {
   3636                 pPort->hTunnelComponent = 0;
   3637                 pPort->nTunnelPort      = 0;
   3638                 return OMX_ErrorPortsNotCompatible;
   3639             }
   3640             break;
   3641         case OMX_PortDomainImage:
   3642             if (sPortDef.format.image.eCompressionFormat != pPortDef->format.image.eCompressionFormat) {
   3643                 pPort->hTunnelComponent = 0;
   3644                 pPort->nTunnelPort      = 0;
   3645                 return OMX_ErrorPortsNotCompatible;
   3646             }
   3647             break;
   3648         default:
   3649             pPort->hTunnelComponent = 0;
   3650             pPort->nTunnelPort      = 0;
   3651             return OMX_ErrorPortsNotCompatible;     /* Our current port is not set up correctly */
   3652     }
   3653     return eError;
   3654 }
   3655 
   3656 /*----------------------------------------------------------------------------*/
   3657 /**
   3658   *  VIDDEC_ComponentTunnelRequest() Sets application callbacks to the component
   3659   *
   3660   * This method will update application callbacks
   3661   * the application.
   3662   *
   3663   * @param pComp         handle for this instance of the component
   3664   * @param pCallBacks    application callbacks
   3665   * @param ptr
   3666   *
   3667   * @retval OMX_NoError              Success, ready to roll
   3668   *         OMX_Error_BadParameter   The input parameter pointer is null
   3669   **/
   3670 /*----------------------------------------------------------------------------*/
   3671 
   3672 static OMX_ERRORTYPE VIDDEC_ComponentTunnelRequest (OMX_IN OMX_HANDLETYPE hComponent,
   3673                                              OMX_IN OMX_U32 nPort,
   3674                                              OMX_IN OMX_HANDLETYPE hTunneledComp,
   3675                                              OMX_IN OMX_U32 nTunneledPort,
   3676                                              OMX_INOUT OMX_TUNNELSETUPTYPE* pTunnelSetup)
   3677 {
   3678     OMX_ERRORTYPE eError = OMX_ErrorNone;
   3679     OMX_COMPONENTTYPE* pHandle = NULL;
   3680     VIDDEC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
   3681     OMX_PARAM_BUFFERSUPPLIERTYPE sBufferSupplier;
   3682     VIDDEC_PORT_TYPE *pPort = NULL;
   3683     OMX_PARAM_PORTDEFINITIONTYPE* pPortDef = NULL;
   3684 
   3685     OMX_CONF_CHECK_CMD(hComponent, OMX_TRUE, OMX_TRUE);
   3686 
   3687     pHandle = (OMX_COMPONENTTYPE*)hComponent;
   3688     pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
   3689 
   3690     pPort = pComponentPrivate->pCompPort[nPort];
   3691     pPortDef = pComponentPrivate->pInPortDef;
   3692 
   3693     if (nPort == pComponentPrivate->pInPortFormat->nPortIndex) {
   3694         pPortDef = pComponentPrivate->pInPortDef;
   3695     }
   3696     else if (nPort == pComponentPrivate->pOutPortFormat->nPortIndex) {
   3697         pPortDef = pComponentPrivate->pOutPortDef;
   3698     }
   3699 
   3700     if (pTunnelSetup == NULL || hTunneledComp == 0) {
   3701         pPort->hTunnelComponent = NULL;
   3702         pPort->nTunnelPort = 0;
   3703         pPort->eSupplierSetting = OMX_BufferSupplyUnspecified;
   3704     }
   3705     else {
   3706         if (pPortDef->eDir != OMX_DirInput && pPortDef->eDir != OMX_DirOutput) {
   3707             return OMX_ErrorBadParameter;
   3708         }
   3709 
   3710 #ifdef KHRONOS_1_1
   3711         /* Check if the other component is developed by TI */
   3712         if(IsTIOMXComponent(hTunneledComp, &pComponentPrivate->dbg) != OMX_TRUE) {
   3713             eError = OMX_ErrorTunnelingUnsupported;
   3714             goto EXIT;
   3715         }
   3716 #endif
   3717         pPort->hTunnelComponent = hTunneledComp;
   3718         pPort->nTunnelPort = nTunneledPort;
   3719 
   3720         if (pPortDef->eDir == OMX_DirOutput) {
   3721             pTunnelSetup->eSupplier = pPort->eSupplierSetting;
   3722         }
   3723         else {
   3724             /* Component is the input (sink of data) */
   3725             eError = VIDDEC_VerifyTunnelConnection(pPort, hTunneledComp, pPortDef);
   3726             if (OMX_ErrorNone != eError) {
   3727                 OMX_ERROR4(pComponentPrivate->dbg, "Error: PP VerifyTunnelConnection failed\n");
   3728                 /* Invalid connection formats. Return eError */
   3729                 return OMX_ErrorPortsNotCompatible;
   3730             }
   3731 
   3732             /* If specified, obey output port's preferences. Otherwise choose output */
   3733             pPort->eSupplierSetting = pTunnelSetup->eSupplier;
   3734             if (OMX_BufferSupplyUnspecified == pPort->eSupplierSetting) {
   3735                 pPort->eSupplierSetting = pTunnelSetup->eSupplier = OMX_BufferSupplyOutput;
   3736             }
   3737 
   3738             /* Tell the output port who the supplier is */
   3739             sBufferSupplier.nSize                    = sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE);
   3740             sBufferSupplier.nVersion.s.nVersionMajor = VERSION_MAJOR;
   3741             sBufferSupplier.nVersion.s.nVersionMinor = VERSION_MAJOR;
   3742             sBufferSupplier.nVersion.s.nRevision     = VERSION_REVISION;
   3743             sBufferSupplier.nVersion.s.nStep         = VERSION_STEP;
   3744             sBufferSupplier.nPortIndex               = nTunneledPort;
   3745             sBufferSupplier.eBufferSupplier          = pPort->eSupplierSetting;
   3746 
   3747             eError = OMX_SetParameter(hTunneledComp, OMX_IndexParamCompBufferSupplier, &sBufferSupplier);
   3748 
   3749             eError = OMX_GetParameter(hTunneledComp, OMX_IndexParamCompBufferSupplier, &sBufferSupplier);
   3750 
   3751             if (sBufferSupplier.eBufferSupplier != pPort->eSupplierSetting) {
   3752                 OMX_ERROR4(pComponentPrivate->dbg, "SetParameter: OMX_IndexParamCompBufferSupplier failed to change setting\n" );
   3753                 return OMX_ErrorUndefined;
   3754             }
   3755         }
   3756     }
   3757 
   3758 EXIT:
   3759     return eError;
   3760 }
   3761 
   3762 /*----------------------------------------------------------------------------*/
   3763 /**
   3764   *  VIDDEC_Allocate_DSPResources()
   3765   *
   3766   *
   3767   *
   3768   *
   3769   * @param
   3770   * @param
   3771   * @param
   3772   *
   3773   * @retval OMX_NoError              Success, ready to roll
   3774   *         OMX_Error_BadParameter   The input parameter pointer is null
   3775   **/
   3776 /*----------------------------------------------------------------------------*/
   3777 
   3778 static OMX_ERRORTYPE VIDDEC_Allocate_DSPResources(VIDDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_IN OMX_U32 nPortIndex)
   3779 {
   3780     OMX_ERRORTYPE eError = OMX_ErrorNone;
   3781     /*todo remove array, fix it to variable,
   3782     it means just one variable for both index*/
   3783     void *pUalgOutParams[1];
   3784     void *pUalgInpParams[1];
   3785     OMX_U8* pTemp = NULL;
   3786     OMX_U8 nBufferCnt = pComponentPrivate->pCompPort[nPortIndex]->nBufferCnt;
   3787     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = pComponentPrivate->pInPortDef;
   3788     VIDDEC_BUFFER_PRIVATE* pBufferPrivate = NULL;
   3789 
   3790     pBufferPrivate =
   3791          (VIDDEC_BUFFER_PRIVATE*)(pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[nBufferCnt]);
   3792 
   3793     if (nPortIndex == pComponentPrivate->pInPortFormat->nPortIndex) {
   3794         if (pPortDefIn->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
   3795             pPortDefIn->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) {
   3796             OMX_MALLOC_STRUCT_SIZED(pUalgInpParams[0], MP4VD_GPP_SN_UALGInputParams, sizeof(MP4VD_GPP_SN_UALGInputParams) + VIDDEC_PADDING_FULL,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
   3797             /*pUalgInpParams[0] = (MP4VD_GPP_SN_UALGInputParams*)malloc(sizeof(MP4VD_GPP_SN_UALGInputParams) + VIDDEC_PADDING_FULL);*/
   3798             if ((MP4VD_GPP_SN_UALGInputParams*)(!pUalgInpParams[0])) {
   3799                 OMX_TRACE4(pComponentPrivate->dbg, "Error: Malloc failed\n");
   3800                 eError = OMX_ErrorInsufficientResources;
   3801                 goto EXIT;
   3802             }
   3803             pTemp = (OMX_U8*)pUalgInpParams[0];
   3804             pTemp += VIDDEC_PADDING_HALF;
   3805             pUalgInpParams[0] = pTemp;
   3806             pBufferPrivate->pUalgParam = (MP4VD_GPP_SN_UALGInputParams*)(pUalgInpParams[0]);
   3807             pBufferPrivate->nUalgParamSize = sizeof(MP4VD_GPP_SN_UALGInputParams);
   3808         }
   3809 #ifdef VIDDEC_SPARK_CODE
   3810         else if (VIDDEC_SPARKCHECK) {
   3811             OMX_MALLOC_STRUCT_SIZED(pUalgInpParams[0], SPARKVD_GPP_SN_UALGInputParams, sizeof(SPARKVD_GPP_SN_UALGInputParams) + VIDDEC_PADDING_FULL,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
   3812             /*pUalgInpParams[0] = (SPARKVD_GPP_SN_UALGInputParams*)malloc(sizeof(SPARKVD_GPP_SN_UALGInputParams) + VIDDEC_PADDING_FULL);*/
   3813             if ((SPARKVD_GPP_SN_UALGInputParams*)(!pUalgInpParams[0])) {
   3814                 OMX_TRACE4(pComponentPrivate->dbg, "Error: Malloc failed\n");
   3815                 eError = OMX_ErrorInsufficientResources;
   3816                 goto EXIT;
   3817             }
   3818             pTemp = (OMX_U8*)pUalgInpParams[0];
   3819             pTemp += VIDDEC_PADDING_HALF;
   3820             pUalgInpParams[0] = pTemp;
   3821             pBufferPrivate->pUalgParam = (SPARKVD_GPP_SN_UALGInputParams*)(pUalgInpParams[0]);
   3822             pBufferPrivate->nUalgParamSize = sizeof(SPARKVD_GPP_SN_UALGInputParams);
   3823         }
   3824 #endif
   3825         else if (pPortDefIn->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) {
   3826             OMX_MALLOC_STRUCT_SIZED(pUalgInpParams[0], MP2VDEC_UALGInputParam, sizeof(MP2VDEC_UALGInputParam) + VIDDEC_PADDING_FULL,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
   3827             /*pUalgInpParams[0] = (MP2VDEC_UALGInputParam*)malloc(sizeof(MP2VDEC_UALGInputParam) + VIDDEC_PADDING_FULL);*/
   3828             if ((MP2VDEC_UALGInputParam*)(!pUalgInpParams[0])) {
   3829                 OMX_TRACE4(pComponentPrivate->dbg, "Error: Malloc failed\n");
   3830                 eError = OMX_ErrorInsufficientResources;
   3831                 goto EXIT;
   3832             }
   3833             pTemp = (OMX_U8*)pUalgInpParams[0];
   3834             pTemp += VIDDEC_PADDING_HALF;
   3835             pUalgInpParams[0] = pTemp;
   3836             pBufferPrivate->pUalgParam = (MP2VDEC_UALGInputParam*)(pUalgInpParams[0]);
   3837             pBufferPrivate->nUalgParamSize = sizeof(MP2VDEC_UALGInputParam);
   3838         }
   3839         else if (pPortDefIn->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
   3840             OMX_MALLOC_STRUCT_SIZED(pUalgInpParams[0], H264VDEC_UALGInputParam, sizeof(H264VDEC_UALGInputParam) + VIDDEC_PADDING_FULL,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
   3841             /*pUalgInpParams[0] = (H264VDEC_UALGInputParam*)malloc(sizeof(H264VDEC_UALGInputParam) + VIDDEC_PADDING_FULL);*/
   3842             if ((H264VDEC_UALGInputParam*)(!pUalgInpParams[0])) {
   3843                 OMX_TRACE4(pComponentPrivate->dbg, "Error: Malloc failed\n");
   3844                 eError = OMX_ErrorInsufficientResources;
   3845                 goto EXIT;
   3846             }
   3847             pTemp = (OMX_U8*)pUalgInpParams[0];
   3848             pTemp += VIDDEC_PADDING_HALF;
   3849             pUalgInpParams[0] = pTemp;
   3850             pBufferPrivate->pUalgParam = (H264VDEC_UALGInputParam*)(pUalgInpParams[0]);
   3851             pBufferPrivate->nUalgParamSize = sizeof(H264VDEC_UALGInputParam);
   3852         }
   3853         else if (pPortDefIn->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) {
   3854             OMX_MALLOC_STRUCT_SIZED(pUalgInpParams[0], WMV9DEC_UALGInputParam, sizeof(WMV9DEC_UALGInputParam) + VIDDEC_PADDING_FULL,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
   3855             /*pUalgInpParams[0] = (WMV9DEC_UALGInputParam*)malloc(sizeof(WMV9DEC_UALGInputParam) + VIDDEC_PADDING_FULL);*/
   3856             if ((WMV9DEC_UALGInputParam*)(!pUalgInpParams[0])) {
   3857                 OMX_TRACE4(pComponentPrivate->dbg, "Error: Malloc failed\n");
   3858                 eError = OMX_ErrorInsufficientResources;
   3859                 goto EXIT;
   3860             }
   3861             pTemp = (OMX_U8*)pUalgInpParams[0];
   3862             pTemp += VIDDEC_PADDING_HALF;
   3863             pUalgInpParams[0] = pTemp;
   3864             pBufferPrivate->pUalgParam = (WMV9DEC_UALGInputParam*)(pUalgInpParams[0]);
   3865             pBufferPrivate->nUalgParamSize = sizeof(WMV9DEC_UALGInputParam);
   3866         }
   3867         else {
   3868             OMX_ERROR4(pComponentPrivate->dbg, "Error: Invalid Compression Type\n");
   3869             goto EXIT;
   3870         }
   3871     }
   3872     else if (nPortIndex == pComponentPrivate->pOutPortFormat->nPortIndex) {
   3873         if (pPortDefIn->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
   3874             pPortDefIn->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) {
   3875             OMX_MALLOC_STRUCT_SIZED(pUalgOutParams[0], MP4VD_GPP_SN_UALGOutputParams, sizeof(MP4VD_GPP_SN_UALGOutputParams) + VIDDEC_PADDING_FULL,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
   3876             /*pUalgOutParams[0] = (MP4VD_GPP_SN_UALGOutputParams*)malloc(sizeof(MP4VD_GPP_SN_UALGOutputParams) + VIDDEC_PADDING_FULL);*/
   3877             if ((MP4VD_GPP_SN_UALGOutputParams*)(!pUalgOutParams[0])) {
   3878                 OMX_TRACE4(pComponentPrivate->dbg, "Error: Malloc failed\n");
   3879                 eError = OMX_ErrorInsufficientResources;
   3880                 goto EXIT;
   3881             }
   3882             pTemp = (OMX_U8*)pUalgOutParams[0];
   3883             pTemp += VIDDEC_PADDING_HALF;
   3884             pUalgOutParams[0] = pTemp;
   3885             pBufferPrivate->pUalgParam = (MP4VD_GPP_SN_UALGOutputParams*)(pUalgOutParams[0]);
   3886             pBufferPrivate->nUalgParamSize = sizeof(MP4VD_GPP_SN_UALGOutputParams);
   3887         }
   3888 #ifdef VIDDEC_SPARK_CODE
   3889         else if (VIDDEC_SPARKCHECK) {
   3890             OMX_MALLOC_STRUCT_SIZED(pUalgOutParams[0], SPARKVD_GPP_SN_UALGOutputParams, sizeof(SPARKVD_GPP_SN_UALGOutputParams) + VIDDEC_PADDING_FULL,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
   3891             /*pUalgOutParams[0] = (SPARKVD_GPP_SN_UALGOutputParams*)malloc(sizeof(SPARKVD_GPP_SN_UALGOutputParams) + VIDDEC_PADDING_FULL);*/
   3892             if ((SPARKVD_GPP_SN_UALGOutputParams*)(!pUalgOutParams[0])) {
   3893                 OMX_TRACE4(pComponentPrivate->dbg, "Error: Malloc failed\n");
   3894                 eError = OMX_ErrorInsufficientResources;
   3895                 goto EXIT;
   3896             }
   3897             pTemp = (OMX_U8*)pUalgOutParams[0];
   3898             pTemp += VIDDEC_PADDING_HALF;
   3899             pUalgOutParams[0] = pTemp;
   3900             pBufferPrivate->pUalgParam = (SPARKVD_GPP_SN_UALGOutputParams*)(pUalgOutParams[0]);
   3901             pBufferPrivate->nUalgParamSize = sizeof(SPARKVD_GPP_SN_UALGOutputParams);
   3902         }
   3903 #endif
   3904         else if (pPortDefIn->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) {
   3905             OMX_MALLOC_STRUCT_SIZED(pUalgOutParams[0], MP2VDEC_UALGOutputParam, sizeof(MP2VDEC_UALGOutputParam) + VIDDEC_PADDING_FULL,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
   3906             /*pUalgOutParams[0] = (MP2VDEC_UALGOutputParam*)malloc(sizeof(MP2VDEC_UALGOutputParam) + VIDDEC_PADDING_FULL);*/
   3907             if ((MP2VDEC_UALGOutputParam*)(!pUalgOutParams[0])) {
   3908                 OMX_TRACE4(pComponentPrivate->dbg, "Error: Malloc failed\n");
   3909                 eError = OMX_ErrorInsufficientResources;
   3910                 goto EXIT;
   3911             }
   3912             pTemp = (OMX_U8*)pUalgOutParams[0];
   3913             pTemp += VIDDEC_PADDING_HALF;
   3914             pUalgOutParams[0] = pTemp;
   3915             pBufferPrivate->pUalgParam = (MP2VDEC_UALGOutputParam*)(pUalgOutParams[0]);
   3916             pBufferPrivate->nUalgParamSize = sizeof(MP2VDEC_UALGOutputParam);
   3917         }
   3918         else if (pPortDefIn->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
   3919             OMX_MALLOC_STRUCT_SIZED(pUalgOutParams[0], H264VDEC_UALGOutputParam, sizeof(H264VDEC_UALGOutputParam) + VIDDEC_PADDING_FULL,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
   3920             /*pUalgOutParams[0] = (H264VDEC_UALGOutputParam*)malloc(sizeof(H264VDEC_UALGOutputParam) + VIDDEC_PADDING_FULL);*/
   3921             if ((H264VDEC_UALGOutputParam*)(!pUalgOutParams[0])) {
   3922                 OMX_TRACE4(pComponentPrivate->dbg, "Error: Malloc failed\n");
   3923                 eError = OMX_ErrorInsufficientResources;
   3924                 goto EXIT;
   3925             }
   3926             pTemp = (OMX_U8*)pUalgOutParams[0];
   3927             pTemp += VIDDEC_PADDING_HALF;
   3928             pUalgOutParams[0] = pTemp;
   3929             pBufferPrivate->pUalgParam = (H264VDEC_UALGOutputParam*)(pUalgOutParams[0]);
   3930             pBufferPrivate->nUalgParamSize = sizeof(H264VDEC_UALGOutputParam);
   3931         }
   3932         else if (pPortDefIn->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) {
   3933             OMX_MALLOC_STRUCT_SIZED(pUalgOutParams[0], WMV9DEC_UALGOutputParam, sizeof(WMV9DEC_UALGOutputParam) + VIDDEC_PADDING_FULL,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
   3934             /*pUalgOutParams[0] = (WMV9DEC_UALGOutputParam*)malloc(sizeof(WMV9DEC_UALGOutputParam) + VIDDEC_PADDING_FULL);*/
   3935             if ((WMV9DEC_UALGOutputParam*)(!pUalgOutParams[0])) {
   3936                 OMX_TRACE4(pComponentPrivate->dbg, "Error: Malloc failed\n");
   3937                 eError = OMX_ErrorInsufficientResources;
   3938                 goto EXIT;
   3939             }
   3940             pTemp = (OMX_U8*)pUalgOutParams[0];
   3941             pTemp += VIDDEC_PADDING_HALF;
   3942             pUalgOutParams[0] = pTemp;
   3943             pBufferPrivate->pUalgParam = (WMV9DEC_UALGOutputParam*)(pUalgOutParams[0]);
   3944             pBufferPrivate->nUalgParamSize = sizeof(WMV9DEC_UALGOutputParam);
   3945         }
   3946         else {
   3947             OMX_ERROR4(pComponentPrivate->dbg, "Error: Invalid Compression Type\n");
   3948             eError = OMX_ErrorUnsupportedSetting;
   3949             goto EXIT;
   3950         }
   3951     }
   3952     else {
   3953         eError = OMX_ErrorBadPortIndex;
   3954         goto EXIT;
   3955     }
   3956 
   3957 EXIT:
   3958     return eError;
   3959 }
   3960 
   3961 /*-------------------------------------------------------------------*/
   3962 /**
   3963   * VIDDEC_GetExtensionIndex()
   3964   *
   3965   *
   3966   *
   3967   * @retval OMX_ErrorNone                    Successful operation.
   3968   *         OMX_ErrorBadParameter            Invalid operation.
   3969   *         OMX_ErrorIncorrectStateOperation If called when port is disabled.
   3970   **/
   3971 /*-------------------------------------------------------------------*/
   3972 static OMX_ERRORTYPE VIDDEC_GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent, OMX_IN OMX_STRING cParameterName, OMX_OUT OMX_INDEXTYPE* pIndexType)
   3973 {
   3974     int nIndex;
   3975     OMX_ERRORTYPE eError = OMX_ErrorUndefined;
   3976 
   3977     OMX_CONF_CHECK_CMD(hComponent, OMX_TRUE, OMX_TRUE);
   3978     for(nIndex = 0; nIndex < sizeof(sVideoDecCustomParams)/sizeof(VIDDEC_CUSTOM_PARAM); nIndex++) {
   3979         if(strcmp((char *)cParameterName, (char *)&(sVideoDecCustomParams[nIndex].cCustomParamName)) == 0) {
   3980             *pIndexType = sVideoDecCustomParams[nIndex].nCustomParamIndex;
   3981             eError = OMX_ErrorNone;
   3982             break;
   3983         }
   3984     }
   3985 EXIT:
   3986     return eError;
   3987 }
   3988 
   3989 #ifdef KHRONOS_1_1
   3990 /*-------------------------------------------------------------------*/
   3991 /**
   3992   * ComponentRoleEnum()
   3993   *
   3994   *
   3995   *
   3996   * @retval OMX_ErrorNone                    Successful operation.
   3997   *         OMX_ErrorBadParameter            Invalid operation.
   3998   *         OMX_ErrorIncorrectStateOperation If called when port is disabled.
   3999   **/
   4000 /*-------------------------------------------------------------------*/
   4001 
   4002 static OMX_ERRORTYPE ComponentRoleEnum(
   4003         OMX_IN OMX_HANDLETYPE hComponent,
   4004                 OMX_OUT OMX_U8 *cRole,
   4005                 OMX_IN OMX_U32 nIndex)
   4006 {
   4007     VIDDEC_COMPONENT_PRIVATE *pComponentPrivate;
   4008 
   4009     OMX_ERRORTYPE eError = OMX_ErrorNone;
   4010     pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
   4011 
   4012     memset(cRole, 0x0, OMX_MAX_STRINGNAME_SIZE);
   4013     switch (nIndex) {
   4014         case VIDDEC_DEFAULT_INPUT_INDEX_H263:
   4015             eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_H263);
   4016             if( pComponentPrivate->pOutPortFormat->eColorFormat != VIDDEC_COLORFORMAT420) {
   4017                 eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_PLANAR420);
   4018             }
   4019             strcpy((char*)cRole, VIDDEC_COMPONENTROLES_H263);
   4020             break;
   4021         case VIDDEC_DEFAULT_INPUT_INDEX_H264:
   4022             eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_H264);
   4023             if( pComponentPrivate->pOutPortFormat->eColorFormat != VIDDEC_COLORFORMAT420) {
   4024                 eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_PLANAR420);
   4025             }
   4026             strcpy((char*)cRole, VIDDEC_COMPONENTROLES_H264);
   4027             break;
   4028         case VIDDEC_DEFAULT_INPUT_INDEX_MPEG2:
   4029             eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_MPEG2);
   4030             if( pComponentPrivate->pOutPortFormat->eColorFormat != VIDDEC_COLORFORMAT420) {
   4031                 eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_PLANAR420);
   4032             }
   4033             strcpy((char*)cRole, VIDDEC_COMPONENTROLES_MPEG2);
   4034             break;
   4035         case VIDDEC_DEFAULT_INPUT_INDEX_MPEG4:
   4036             eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_MPEG4);
   4037             if( pComponentPrivate->pOutPortFormat->eColorFormat != VIDDEC_COLORFORMAT420) {
   4038                 eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_PLANAR420);
   4039             }
   4040             strcpy((char*)cRole, VIDDEC_COMPONENTROLES_MPEG4);
   4041             break;
   4042         case VIDDEC_DEFAULT_INPUT_INDEX_WMV9:
   4043             eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_WMV9);
   4044             if( pComponentPrivate->pOutPortFormat->eColorFormat != VIDDEC_COLORFORMAT420) {
   4045                 eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_PLANAR420);
   4046             }
   4047             strcpy((char*)cRole, VIDDEC_COMPONENTROLES_WMV9);
   4048             break;
   4049         /*todo add spark, it was not added because it is not in khronos spec, yet*/
   4050         default:
   4051             eError = OMX_ErrorNoMore;
   4052             break;
   4053     }
   4054     if(eError != OMX_ErrorNone) {
   4055         goto EXIT;
   4056     }
   4057 
   4058 EXIT:
   4059     return eError;
   4060 }
   4061 #endif
   4062 
   4063