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_VPP.c
     30 *
     31 * This file implements OMX Component for VPP that
     32 * is  compliant with the OMX khronos 1.0.
     33 *
     34 * @path  $(CSLPATH)\
     35 *
     36 * @rev  1.0
     37 */
     38 /* ----------------------------------------------------------------------------
     39 *!
     40 *! Revision History
     41 *! ===================================
     42 *! 17-april-2005 mf:  Initial Version. Change required per OMAPSWxxxxxxxxx
     43 *! to provide _________________.
     44 *!
     45 * ============================================================================= */
     46 
     47 
     48 /* ------compilation control switches -------------------------*/
     49 /****************************************************************
     50 *  INCLUDE FILES
     51 ****************************************************************/
     52 /* ----- system and platform files ----------------------------*/
     53 #ifdef UNDER_CE
     54 #include <windows.h>
     55 #include <oaf_osal.h>
     56 #include <omx_core.h>
     57 #else
     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 <pthread.h>
     64 #include <errno.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 
     73 
     74 /*-------program files ----------------------------------------*/
     75 #include <OMX_Component.h>
     76 
     77 #include "LCML_DspCodec.h"
     78 #include "OMX_VPP.h"
     79 #include "OMX_VPP_Utils.h"
     80 #include "OMX_VPP_CompThread.h"
     81 
     82 #ifdef __PERF_INSTRUMENTATION__
     83 #include "perf.h"
     84 #endif
     85 
     86 #ifdef RESOURCE_MANAGER_ENABLED
     87 #include <ResourceManagerProxyAPI.h>
     88 #endif
     89 
     90 #define VPP_CONTRAST_MIN     -100
     91 #define VPP_CONTRAST_MAX     100
     92 #define VPP_CONTRAST_OFFSET  100
     93 #define VPP_CONTRAST_FACTOR  64/100
     94 #define VPP_MAX_NAMESIZE     127
     95 
     96 
     97 #define VPP_NUM_CUSTOM_PARAMS 9
     98 
     99 
    100 
    101 /****************************************************************
    102 *  EXTERNAL REFERENCES NOTE : only use if not found in header file
    103 ****************************************************************/
    104 /*--------data declarations -----------------------------------*/
    105 
    106 
    107 /****************************************************************
    108 *  PUBLIC DECLARATIONS Defined here, used elsewhere
    109 ****************************************************************/
    110 /*--------data declarations -----------------------------------*/
    111 
    112 /*--------function prototypes ---------------------------------*/
    113 
    114 /****************************************************************
    115 *  PRIVATE DECLARATIONS Defined here, used only here
    116 ****************************************************************/
    117 /*--------data declarations -----------------------------------*/
    118 /*--------function prototypes ---------------------------------*/
    119 
    120 /* --------- Globals ------------ */
    121 OMX_STRING cVPPName = "OMX.TI.VPP";
    122 
    123 static VPP_CUSTOM_PARAM_DEFINITION sVPPCustomParams[VPP_NUM_CUSTOM_PARAMS] = {
    124     {"OMX.TI.VPP.Param.ZoomFactor", OMX_IndexCustomSetZoomFactor},
    125     {"OMX.TI.VPP.Param.ZoomLimit", OMX_IndexCustomSetZoomLimit},
    126     {"OMX.TI.VPP.Param.ZoomSpeed", OMX_IndexCustomSetZoomSpeed},
    127     {"OMX.TI.VPP.Param.ZoomXoffsetFromCenter16", OMX_IndexCustomSetZoomXoffsetFromCenter16},
    128     {"OMX.TI.VPP.Param.ZoomYoffsetFromCenter16", OMX_IndexCustomSetZoomYoffsetFromCenter16},
    129     {"OMX.TI.VPP.Param.FrostedGlassOvly", OMX_IndexCustomSetFrostedGlassOvly},
    130     {"OMX.TI.VPP.Param.VideoColorRange", OMX_IndexCustomVideoColorRange},
    131     {"OMX.TI.VPP.Param.RGB4ColorFormat", OMX_IndexCustomRGB4ColorFormat},
    132     {"OMX.TI.VPP.Config.InputSize",OMX_IndexCustomConfigInputSize}
    133     };
    134 
    135 /*--------function prototypes ---------------------------------*/
    136 static OMX_ERRORTYPE VPP_SetCallbacks (OMX_HANDLETYPE hComp,
    137                                        OMX_CALLBACKTYPE* pCallBacks,
    138                                        OMX_PTR pAppData);
    139 
    140 static OMX_ERRORTYPE VPP_GetComponentVersion (OMX_HANDLETYPE   hComp,
    141                                               OMX_STRING       szComponentName,
    142                                               OMX_VERSIONTYPE* pComponentVersion,
    143                                               OMX_VERSIONTYPE* pSpecVersion,
    144                                               OMX_UUIDTYPE*    pComponentUUID
    145                                               );
    146 
    147 static OMX_ERRORTYPE VPP_SendCommand (OMX_IN OMX_HANDLETYPE  hComponent,
    148                                       OMX_IN OMX_COMMANDTYPE Cmd,
    149                                       OMX_IN OMX_U32         nParam,
    150                                       OMX_IN OMX_PTR         pCmdData
    151                                       );
    152 
    153 static OMX_ERRORTYPE VPP_GetParameter(OMX_HANDLETYPE hComp,
    154                                       OMX_INDEXTYPE nParamIndex,
    155                                       OMX_PTR pComponentParameterStructure);
    156 
    157 static OMX_ERRORTYPE VPP_SetParameter (OMX_HANDLETYPE hComp,
    158                                        OMX_INDEXTYPE nParamIndex,
    159                                        OMX_PTR ComponentParameterStructure);
    160 
    161 static OMX_ERRORTYPE VPP_GetConfig (OMX_HANDLETYPE hComp,
    162                                     OMX_INDEXTYPE nConfigIndex,
    163                                     OMX_PTR ComponentConfigStructure);
    164 
    165 static OMX_ERRORTYPE VPP_SetConfig (OMX_HANDLETYPE hComp,
    166                                     OMX_INDEXTYPE nConfigIndex,
    167                                     OMX_PTR ComponentConfigStructure);
    168 
    169 static OMX_ERRORTYPE VPP_EmptyThisBuffer (OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBufHdr);
    170 
    171 static OMX_ERRORTYPE VPP_FillThisBuffer (OMX_HANDLETYPE hComp,OMX_BUFFERHEADERTYPE* pBufferHdr);
    172 
    173 static OMX_ERRORTYPE VPP_GetState (OMX_HANDLETYPE hComp, OMX_STATETYPE* pState);
    174 
    175 static OMX_ERRORTYPE VPP_ComponentTunnelRequest (OMX_HANDLETYPE hComp,
    176                                                  OMX_U32 nPort,
    177                                                  OMX_HANDLETYPE hTunneledComp,
    178                                                  OMX_U32 nTunneledPort,
    179                                                  OMX_INOUT  OMX_TUNNELSETUPTYPE* pTunnelSetup);
    180 
    181 static OMX_ERRORTYPE VPP_ComponentDeInit(OMX_HANDLETYPE pHandle);
    182 
    183 static OMX_ERRORTYPE VPP_UseBuffer(OMX_IN OMX_HANDLETYPE hComponent,
    184                                    OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
    185                                    OMX_IN OMX_U32 nPortIndex,
    186                                    OMX_IN OMX_PTR pAppPrivate,
    187                                    OMX_IN OMX_U32 nSizeBytes,
    188                                    OMX_IN OMX_U8* pBuffer);
    189 
    190 
    191 static OMX_ERRORTYPE VPP_AllocateBuffer(OMX_IN OMX_HANDLETYPE hComponent,
    192                                         OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
    193                                         OMX_IN OMX_U32 nPortIndex,
    194                                         OMX_IN OMX_PTR pAppPrivate,
    195                                         OMX_IN OMX_U32 nSizeBytes);
    196 
    197 static OMX_ERRORTYPE VPP_FreeBuffer(OMX_IN  OMX_HANDLETYPE hComponent,
    198                                     OMX_IN  OMX_U32 nPortIndex,
    199                                     OMX_IN  OMX_BUFFERHEADERTYPE* pBufHeader);
    200 
    201 static OMX_ERRORTYPE VPP_GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent,
    202                                                 OMX_IN OMX_STRING cParameterName,
    203                                                 OMX_OUT OMX_INDEXTYPE* pIndexType);
    204 
    205 
    206 #ifdef KHRONOS_1_1
    207 static OMX_ERRORTYPE ComponentRoleEnum(
    208                 OMX_IN OMX_HANDLETYPE hComponent,
    209                 OMX_OUT OMX_U8 *cRole,
    210                 OMX_IN OMX_U32 nIndex);
    211 #endif
    212 
    213 /*-------------------------------------------------------------------*/
    214 /**
    215   * AllocateBuffer()
    216   *
    217   * Allocate a video driver buffer.
    218   *
    219   * @retval OMX_ErrorNone                    Successful operation.
    220   *         OMX_ErrorBadParameter            Invalid operation.
    221   *         OMX_ErrorIncorrectStateOperation If called when port is disabled.
    222   **/
    223 /*-------------------------------------------------------------------*/
    224 OMX_ERRORTYPE VPP_AllocateBuffer(OMX_IN OMX_HANDLETYPE hComponent,
    225                                 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
    226                                 OMX_IN OMX_U32 nPortIndex,
    227                                 OMX_IN OMX_PTR pAppPrivate,
    228                                 OMX_IN OMX_U32 nSizeBytes)
    229 {
    230     OMX_ERRORTYPE eError = OMX_ErrorNone;
    231     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComponent;
    232     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
    233     VPP_COMPONENT_PRIVATE* pComponentPrivate = NULL;
    234     OMX_BUFFERHEADERTYPE *pBufferHdr = NULL;
    235     OMX_U8  *pBufferAligned = NULL;
    236     OMX_U8  *pBufferStart = NULL;
    237     OMX_U32 nCount = 0;
    238     OMX_DIRTYPE nDirection = OMX_DirMax;
    239     OMX_U32 nBufSize;
    240 
    241 
    242     OMX_CHECK_CMD(hComponent, ppBufferHdr, OMX_TRUE);
    243 
    244     pComponentPrivate = (VPP_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
    245 
    246     VPP_DPRINT("VPP::Inside the AllocateBuffer portindex =%ld\n",nPortIndex);
    247 
    248     if (nPortIndex == pComponentPrivate->sCompPorts[nPortIndex].pPortDef.nPortIndex) {
    249         pPortDef = &(pComponentPrivate->sCompPorts[nPortIndex].pPortDef);
    250     }
    251     else {
    252         VPP_DPRINT("OMX_ErrorBadparameter AllocateBuffer!!\n");
    253         eError = OMX_ErrorBadParameter;
    254         goto EXIT;
    255     }
    256 
    257     if (pComponentPrivate->sCompPorts[nPortIndex].pPortDef.nBufferSize > nSizeBytes) {
    258         nBufSize   = pComponentPrivate->sCompPorts[nPortIndex].pPortDef.nBufferSize;
    259     } else {
    260         nBufSize = nSizeBytes;
    261     }
    262     nDirection = pComponentPrivate->sCompPorts[nPortIndex].pPortDef.eDir;
    263 
    264     nCount  = pComponentPrivate->sCompPorts[nPortIndex].nBufferCount;
    265     /* Allocate memory for all input buffer headers..
    266     * This memory pointer will be sent to LCML */
    267     OMX_MALLOC (pBufferHdr, sizeof(OMX_BUFFERHEADERTYPE));
    268 
    269     pComponentPrivate->sCompPorts[nPortIndex].pVPPBufHeader[nCount].pBufHeader     = pBufferHdr;
    270     pComponentPrivate->sCompPorts[nPortIndex].pVPPBufHeader[nCount].bSelfAllocated = OMX_TRUE;
    271 
    272 
    273     VPP_DPRINT("VPP::%d :: --------- Inside Ip Loop\n",__LINE__);
    274     VPP_DPRINT ("VPP::Inside the AllocateBuffer --.5   pBufferHdr =%p\n" ,  pBufferHdr);
    275     pBufferHdr->nSize      = sizeof(OMX_BUFFERHEADERTYPE);
    276 
    277 
    278     pBufferHdr->nAllocLen  = nBufSize;
    279     pBufferHdr->nFilledLen = 0;
    280     pBufferHdr->nVersion.s.nVersionMajor = VPP_MAJOR_VER;
    281     pBufferHdr->nVersion.s.nVersionMinor = VPP_MINOR_VER;
    282 
    283     /* TO CONDITION FOR INPUT AND OUTPUT PORT */
    284     VPP_DPRINT ("VPP::Inside the AllocateBuffer --1   pBufferHdr =%p\n" ,  pBufferHdr);
    285     if (nDirection == OMX_DirInput) {
    286         pBufferHdr->pInputPortPrivate  = &(pComponentPrivate->sCompPorts[nPortIndex].pPortDef);
    287         pBufferHdr->pOutputPortPrivate = NULL;
    288         pBufferHdr->nOutputPortIndex   = OMX_NOPORT;
    289         pBufferHdr->nInputPortIndex    = nPortIndex;
    290         if(nPortIndex == OMX_VPP_INPUT_OVERLAY_PORT){
    291             /* Allocate buffer for overlay process only one buffer*/
    292             if(pComponentPrivate->RGBbuffer == NULL){
    293                 OMX_MALLOC(pComponentPrivate->RGBbuffer, nBufSize);
    294             }
    295         }
    296     }
    297     else {
    298         pBufferHdr->pOutputPortPrivate = &(pComponentPrivate->sCompPorts[nPortIndex].pPortDef);
    299         pBufferHdr->pInputPortPrivate  = NULL;
    300         pBufferHdr->nOutputPortIndex   = nPortIndex;
    301         pBufferHdr->nInputPortIndex    = OMX_NOPORT;
    302     }
    303     VPP_DPRINT ("VPP::Inside the AllocateBuffer --2  pBufferHdr =%p\n" ,  pBufferHdr);
    304 
    305     pBufferHdr->pPlatformPrivate = pHandle->pComponentPrivate;
    306     pBufferHdr->pAppPrivate      = pAppPrivate;
    307     pBufferHdr->pMarkData        = NULL;
    308     pBufferHdr->nTickCount       = 0;
    309     pBufferHdr->nTimeStamp     = 0;
    310 
    311     OMX_MALLOC(pBufferStart, nBufSize + 32 + 256);
    312 
    313     pBufferAligned = pBufferStart;
    314     while ((((int)pBufferAligned) & 0x1f) != 0)
    315     {
    316         pBufferAligned++;
    317     }
    318 
    319     VPP_DPRINT ("VPP::Inside the AllocateBuffer pBuffer =%p\n",pBufferHdr);
    320     VPP_DPRINT ("VPP:: Inside the AllocateBuffer   pBuffer->pBuffer =%p\n" ,  pBufferHdr->pBuffer);
    321     VPP_DPRINT ("VPP::Inside the AllocateBuffer --3  pBuffer =%p\n",pBufferHdr);
    322 
    323     pBufferAligned            = ((OMX_U8*)pBufferAligned) +128;
    324     pBufferHdr->pBuffer            = pBufferAligned;
    325     pComponentPrivate->sCompPorts[nPortIndex].pVPPBufHeader[nCount].pBufferStart = pBufferStart;
    326     pComponentPrivate->sCompPorts[nPortIndex].nBufferCount++;
    327 
    328 #ifdef __PERF_INSTRUMENTATION__
    329     PERF_ReceivedFrame(pComponentPrivate->pPERF,
    330                     pBufferHdr->pBuffer,
    331                     pBufferHdr->nAllocLen,
    332                     PERF_ModuleMemory);
    333 #endif
    334 
    335     VPP_DPRINT ("VPP::Inside the AllocateBuffer ( nBufferCountActual  =%ld nBufferCount =%ld " ,
    336     pComponentPrivate->sCompPorts[nPortIndex].pPortDef.nBufferCountActual,
    337     pComponentPrivate->sCompPorts[nPortIndex].nBufferCount);
    338     if (pComponentPrivate->sCompPorts[nPortIndex].pPortDef.nBufferCountActual ==
    339             pComponentPrivate->sCompPorts[nPortIndex].nBufferCount) {
    340         pPortDef->bPopulated = OMX_TRUE;
    341         VPP_InitBufferDataPropagation(pComponentPrivate, nPortIndex);
    342         VPP_DPRINT ("VPP::Inside the AllocateBuffer PORT populated\n" );
    343     }
    344 
    345     pComponentPrivate->sCompPorts[nPortIndex].pVPPBufHeader[nCount].eBufferOwner = VPP_BUFFER_CLIENT;
    346     * ppBufferHdr =  pComponentPrivate->sCompPorts[nPortIndex].pVPPBufHeader[nCount].pBufHeader;
    347 EXIT:
    348     if(eError != OMX_ErrorNone){
    349         OMX_FREE(pComponentPrivate->RGBbuffer);
    350     }
    351     return eError;
    352 }
    353 
    354 /*-------------------------------------------------------------------*/
    355 /**
    356   * FreeBuffer()
    357   *
    358   * Free buffer allocated for VPP.
    359   *
    360   * @retval OMX_ErrorNone                    Successful operation.
    361   *         OMX_ErrorBadParameter            Invalid operation.
    362   *         OMX_ErrorIncorrectStateOperation If called when port is disabled.
    363   **/
    364 /*-------------------------------------------------------------------*/
    365 OMX_ERRORTYPE VPP_FreeBuffer(OMX_IN  OMX_HANDLETYPE hComponent,
    366 OMX_IN  OMX_U32 nPortIndex,
    367 OMX_IN  OMX_BUFFERHEADERTYPE* pBufHeader)
    368 {
    369     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)hComponent;
    370     VPP_COMPONENT_PRIVATE *pMyData = NULL;
    371     OMX_U8  *pBufferStart = NULL;
    372     OMX_ERRORTYPE eError = OMX_ErrorNone;
    373     OMX_U32 nCount = 0;
    374 
    375     OMX_CHECK_CMD(hComponent, pBufHeader, OMX_TRUE);
    376 
    377     pMyData = (VPP_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
    378 
    379     OMX_CHECK_CMD(pMyData, OMX_TRUE, OMX_TRUE);
    380     if(!((nPortIndex == OMX_VPP_INPUT_PORT) ||
    381             (nPortIndex == OMX_VPP_INPUT_OVERLAY_PORT) ||
    382             (nPortIndex == OMX_VPP_RGB_OUTPUT_PORT)||
    383             (nPortIndex == OMX_VPP_YUV_OUTPUT_PORT))){
    384         OMX_SET_ERROR_BAIL(eError, OMX_ErrorBadParameter);
    385     }
    386 
    387     VPP_DPRINT("VPP.c: VPP_FreeBuffer port %d\n", nPortIndex);
    388     VPP_DPRINT("VPP:: # allocated buffers = %d\n", pMyData->sCompPorts[nPortIndex].nBufferCount);
    389     eError = VPP_IsValidBuffer(pBufHeader, pMyData, nPortIndex, &nCount);
    390     if(eError != OMX_ErrorNone){
    391         goto EXIT;
    392     }
    393 
    394     pBufferStart = pMyData->sCompPorts[nPortIndex].pVPPBufHeader[nCount].pBufferStart;
    395 
    396     VPP_DPRINT(" Free_ComponentResources --nPortIndex= %d, Header = %p \n", nPortIndex,
    397         pMyData->sCompPorts[nPortIndex].pVPPBufHeader[nCount].pBufHeader);
    398 
    399     if(pMyData->sCompPorts[nPortIndex].pVPPBufHeader[nCount].bSelfAllocated == OMX_TRUE) {
    400         VPP_DPRINT ("VPP::%d :: FreeBuffer --1\n",__LINE__);
    401 
    402         if (pBufHeader) {
    403             if (pBufHeader->pBuffer) {
    404 
    405 #ifdef __PERF_INSTRUMENTATION__
    406                 PERF_SendingFrame(pMyData->pPERF,
    407                                 pBufHeader->pBuffer,
    408                                 pBufHeader->nAllocLen,
    409                                 PERF_ModuleMemory);
    410 #endif
    411                VPP_DPRINT ("VPP::%d :: FreeBuffer --1.5\n",__LINE__);
    412                 OMX_FREE(pBufferStart);
    413                 pBufferStart = NULL;
    414                 pBufHeader->pBuffer = NULL;
    415                 VPP_DPRINT ("VPP::%d :: FreeBuffer --1.6\n",__LINE__);
    416             }
    417             OMX_FREE(pBufHeader);
    418             pBufHeader = NULL;
    419         }
    420     }
    421     else {
    422         if (pBufHeader) {
    423 
    424 #ifdef __PERF_INSTRUMENTATION__
    425             PERF_SendingFrame(pMyData->pPERF,
    426                             pBufHeader->pBuffer,
    427                             pBufHeader->nAllocLen,
    428                             PERF_ModuleHLMM);
    429 #endif
    430 
    431             OMX_FREE(pBufHeader);
    432             pBufHeader = NULL;
    433         }
    434     }
    435 
    436     pMyData->sCompPorts[nPortIndex].nBufferCount--;
    437 	VPP_DPRINT("nBufferCount %d\n", pMyData->sCompPorts[nPortIndex].nBufferCount);
    438     if (pMyData->sCompPorts[nPortIndex].nBufferCount == 0) {
    439 		VPP_DPRINT("port %d is unpopulated\n", nPortIndex);
    440         pMyData->sCompPorts[nPortIndex].pPortDef.bPopulated = OMX_FALSE;
    441 
    442     if (pMyData->sCompPorts[nPortIndex].pPortDef.bEnabled &&
    443             ((pMyData->curState == OMX_StateIdle && pMyData->toState != OMX_StateLoaded) ||
    444                 pMyData->curState == OMX_StateExecuting ||
    445                 pMyData->curState == OMX_StatePause)) {
    446 					VPP_DPRINT("FreeBuf: cur state %d to %d\n", pMyData->curState, pMyData->toState);
    447         pMyData->cbInfo.EventHandler (pMyData->pHandle,
    448                     pMyData->pHandle->pApplicationPrivate,
    449                     OMX_EventError,
    450                     OMX_ErrorPortUnpopulated,
    451                     OMX_TI_ErrorMinor,
    452                     "port unpopulated");
    453     }
    454 
    455     }
    456 
    457 	VPP_DPRINT("nPortIndex %d\n", nPortIndex);
    458 	VPP_DPRINT("pPortDef->bEnabled %d pPortDef->bPopulated %d pMyData->bDisableIncomplete[nPortIndex] %d (%d)\n",
    459 			pMyData->sCompPorts[nPortIndex].pPortDef.bEnabled,
    460 			pMyData->sCompPorts[nPortIndex].pPortDef.bPopulated,
    461 			pMyData->bDisableIncomplete[nPortIndex],
    462 			nPortIndex);
    463 
    464 
    465       if ((!pMyData->sCompPorts[nPortIndex].pPortDef.bEnabled) &&
    466 		  (pMyData->sCompPorts[nPortIndex].pPortDef.bPopulated == OMX_FALSE)) {
    467 			  VPP_DPRINT("VPP: %d\n", __LINE__);
    468 		if (pMyData->bDisableIncomplete[nPortIndex] == OMX_TRUE) {
    469             pMyData->sCompPorts[nPortIndex].pPortDef.bEnabled = OMX_FALSE;
    470 			pMyData->bDisableIncomplete[nPortIndex] = OMX_FALSE;
    471 			VPP_DPRINT("send OMX_CommandPortDisable for port %d\n", nPortIndex);
    472 		    pMyData->cbInfo.EventHandler (pMyData->pHandle,
    473 												pMyData->pHandle->pApplicationPrivate,
    474 												OMX_EventCmdComplete,
    475 												OMX_CommandPortDisable,
    476 												nPortIndex,
    477 												NULL);
    478       	}
    479       }
    480 
    481 
    482 EXIT:
    483     return eError;
    484 }
    485 
    486 /*----------------------------------------------------------------------------*/
    487 /**
    488   *  UseBuffer()
    489   *
    490   *
    491   *
    492   *
    493   * @param
    494   * @param
    495   * @param
    496   *
    497   * @retval OMX_NoError              Success, ready to roll
    498   *         OMX_Error_BadParameter   The input parameter pointer is null
    499   **/
    500 /*----------------------------------------------------------------------------*/
    501 OMX_ERRORTYPE VPP_UseBuffer(OMX_IN OMX_HANDLETYPE hComponent,
    502                             OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
    503                             OMX_IN OMX_U32 nPortIndex,
    504                             OMX_IN OMX_PTR pAppPrivate,
    505                             OMX_IN OMX_U32 nSizeBytes,
    506                             OMX_IN OMX_U8* pBuffer)
    507 {
    508 
    509     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)hComponent;
    510     VPP_COMPONENT_PRIVATE *pMyData = NULL;
    511     OMX_ERRORTYPE eError = OMX_ErrorNone;
    512     OMX_U32 nCount = 0;
    513     OMX_BUFFERHEADERTYPE* pBufListObj = NULL;
    514     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
    515 
    516 
    517     OMX_CHECK_CMD(hComponent, ppBufferHdr, pBuffer);
    518 
    519     VPP_DPRINT("VPP::UseBuffer nPortIndex= %lu\n",nPortIndex);
    520 
    521     pMyData = (VPP_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
    522 
    523     OMX_CHECK_CMD(pMyData, OMX_TRUE, OMX_TRUE);
    524 
    525     if (nPortIndex == pMyData->pInPortFormat->nPortIndex) {
    526         pPortDef = &(pMyData->sCompPorts[nPortIndex].pPortDef);
    527     }
    528     else if (nPortIndex == pMyData->pInPortOverlayFormat->nPortIndex) {
    529         pPortDef = &(pMyData->sCompPorts[nPortIndex].pPortDef);
    530     }
    531     else if (nPortIndex == pMyData->pOutPortRGBFormat->nPortIndex) {
    532         pPortDef = &(pMyData->sCompPorts[nPortIndex].pPortDef);
    533     }
    534     else if (nPortIndex == pMyData->pOutPortYUVFormat->nPortIndex) {
    535         pPortDef = &(pMyData->sCompPorts[nPortIndex].pPortDef);
    536     }
    537     else {
    538         OMX_SET_ERROR_BAIL(eError, OMX_ErrorBadParameter);
    539     }
    540 
    541     if (!pPortDef->bEnabled) {
    542         OMX_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation);
    543     }
    544 
    545     OMX_MALLOC(pBufListObj, sizeof(OMX_BUFFERHEADERTYPE));
    546 
    547     OMX_INIT_STRUCT((pBufListObj), OMX_BUFFERHEADERTYPE);
    548     pBufListObj->pBuffer          = pBuffer;
    549     pBufListObj->pPlatformPrivate = NULL;
    550     pBufListObj->nAllocLen        = nSizeBytes;
    551     if ((nPortIndex == pMyData->pInPortFormat->nPortIndex) ||
    552             (nPortIndex == pMyData->pInPortOverlayFormat->nPortIndex)) {
    553         pBufListObj->nInputPortIndex = nPortIndex;
    554         if (!pMyData->sCompPorts[nPortIndex].hTunnelComponent) {
    555             pBufListObj->nOutputPortIndex = OMX_NOPORT;
    556         }
    557         else {
    558             pBufListObj->nOutputPortIndex = pMyData->sCompPorts[nPortIndex].nTunnelPort;
    559         }
    560         pBufListObj->pInputPortPrivate  = &(pMyData->sCompPorts[nPortIndex].pPortDef);
    561         pBufListObj->pOutputPortPrivate = NULL;
    562 
    563         if(nPortIndex == OMX_VPP_INPUT_OVERLAY_PORT){
    564             /* Allocate buffer for overlay process only one buffer*/
    565             if(pMyData->RGBbuffer == NULL){
    566                 OMX_MALLOC(pMyData->RGBbuffer, nSizeBytes);
    567             }
    568         }
    569     }
    570     else if (( nPortIndex == pMyData->pOutPortRGBFormat->nPortIndex) ||
    571             ( nPortIndex == pMyData->pOutPortYUVFormat->nPortIndex)) {
    572         pBufListObj->nOutputPortIndex = nPortIndex;
    573         if (!pMyData->sCompPorts[nPortIndex].hTunnelComponent) {
    574             pBufListObj->nInputPortIndex = OMX_NOPORT;
    575         }
    576         else {
    577             pBufListObj->nInputPortIndex = pMyData->sCompPorts[nPortIndex].nTunnelPort;
    578         }
    579         pBufListObj->pInputPortPrivate = NULL;
    580         pBufListObj->pOutputPortPrivate = &(pMyData->sCompPorts[nPortIndex].pPortDef);
    581     }
    582     nCount = pMyData->sCompPorts[nPortIndex].nBufferCount;
    583     pMyData->sCompPorts[nPortIndex].pVPPBufHeader[nCount].pBufHeader = pBufListObj;
    584     pMyData->sCompPorts[nPortIndex].pVPPBufHeader[nCount].bSelfAllocated = OMX_FALSE;
    585 
    586     if (!pMyData->sCompPorts[nPortIndex].hTunnelComponent) {
    587         pMyData->sCompPorts[nPortIndex].pVPPBufHeader[nCount].eBufferOwner = VPP_BUFFER_CLIENT;
    588     }
    589     else{
    590          pMyData->sCompPorts[nPortIndex].pVPPBufHeader[nCount].eBufferOwner = VPP_BUFFER_CLIENT;
    591     }
    592 
    593     pMyData->sCompPorts[nPortIndex].nBufferCount++;
    594     if (pMyData->sCompPorts[nPortIndex].nBufferCount == pPortDef->nBufferCountActual) {
    595         pPortDef->bPopulated = OMX_TRUE;
    596         VPP_InitBufferDataPropagation(pMyData, nPortIndex);
    597     }
    598     *ppBufferHdr = pBufListObj;
    599 
    600     VPP_DPRINT("In UseBuffer: pBufferHdr is %p, (int) %p, (out)%p \n",
    601         *ppBufferHdr,
    602         (pBufListObj->pInputPortPrivate),
    603         (pBufListObj->pOutputPortPrivate));
    604 
    605     VPP_DPRINT("VPP::Exit UseBuffer with Error=0x%X",eError);
    606 
    607 #ifdef __PERF_INSTRUMENTATION__
    608     PERF_ReceivedFrame(pMyData->pPERF,
    609                     pBufListObj->pBuffer,
    610                     pBufListObj->nAllocLen,
    611                     PERF_ModuleHLMM);
    612 #endif
    613 
    614 EXIT:
    615     return eError;
    616 }
    617 
    618 /*-------------------------------------------------------------------*/
    619 /**
    620   * OMX_ComponentInit() Set the all the function pointers of component
    621   *
    622   * This method will update the component function pointer to the handle
    623   *
    624   * @param hComp         handle for this instance of the component
    625   *
    626   * @retval OMX_NoError              Success, ready to roll
    627   *         OMX_ErrorInsufficientResources If the malloc fails
    628   **/
    629 /*-------------------------------------------------------------------*/
    630 OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp)
    631 {
    632     OMX_ERRORTYPE eError       = OMX_ErrorUndefined;
    633     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp;
    634     OMX_U8  colorKey[3]  = {3,5,250}; /*RGB*/
    635     VPP_COMPONENT_PRIVATE *pComponentPrivate = NULL;
    636     OMX_U8* pTemp = NULL;
    637 
    638     OMX_CHECK_CMD(hComp, OMX_TRUE, OMX_TRUE);
    639 
    640     LinkedList_Create(&AllocList);
    641 
    642     /*Set the all component function pointer to the handle*/
    643     pHandle->SetCallbacks           = VPP_SetCallbacks;
    644     pHandle->GetComponentVersion    = VPP_GetComponentVersion;
    645     pHandle->SendCommand            = VPP_SendCommand;
    646     pHandle->GetParameter           = VPP_GetParameter;
    647     pHandle->SetParameter           = VPP_SetParameter;
    648     pHandle->GetConfig              = VPP_GetConfig;
    649     pHandle->SetConfig              = VPP_SetConfig;
    650     pHandle->GetState               = VPP_GetState;
    651     pHandle->EmptyThisBuffer        = VPP_EmptyThisBuffer;
    652     pHandle->FillThisBuffer         = VPP_FillThisBuffer;
    653     pHandle->ComponentTunnelRequest = VPP_ComponentTunnelRequest;
    654     pHandle->ComponentDeInit        = VPP_ComponentDeInit;
    655     pHandle->AllocateBuffer         = VPP_AllocateBuffer;
    656     pHandle->UseBuffer              = VPP_UseBuffer;
    657     pHandle->FreeBuffer             = VPP_FreeBuffer;
    658     pHandle->GetExtensionIndex      = VPP_GetExtensionIndex;
    659 #ifdef KHRONOS_1_1
    660     pHandle->ComponentRoleEnum      = ComponentRoleEnum;
    661 #endif
    662 
    663     /*Allocate the memory for Component private data area*/
    664    OMX_MALLOC(pHandle->pComponentPrivate, sizeof(VPP_COMPONENT_PRIVATE));
    665 
    666     ((VPP_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->pHandle = pHandle;
    667 
    668     pComponentPrivate = (VPP_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
    669 
    670     /*Allcocating FrameStatus*/
    671     OMX_MALLOC(pComponentPrivate->pIpFrameStatus, sizeof(GPPToVPPInputFrameStatus) + 256);
    672     pTemp = ((OMX_U8*)(pComponentPrivate->pIpFrameStatus))+128;
    673     pComponentPrivate->pIpFrameStatus =  (GPPToVPPInputFrameStatus *)pTemp;
    674     OMX_MALLOC(pComponentPrivate->pOpYUVFrameStatus, sizeof(GPPToVPPOutputFrameStatus) + 256);
    675     pTemp = ((OMX_U8*)(pComponentPrivate->pOpYUVFrameStatus))+128;
    676     pComponentPrivate->pOpYUVFrameStatus = (GPPToVPPOutputFrameStatus *)pTemp;
    677     OMX_MALLOC(pComponentPrivate->pOpRGBFrameStatus, sizeof(GPPToVPPOutputFrameStatus) + 256);
    678     pTemp = ((OMX_U8*)(pComponentPrivate->pOpRGBFrameStatus))+128;
    679     pComponentPrivate->pOpRGBFrameStatus = (GPPToVPPOutputFrameStatus *)pTemp;
    680 
    681 #ifdef KHRONOS_1_1
    682     strcpy((char *)pComponentPrivate->componentRole.cRole,"iv_renderer.yuv.overlay");
    683 #endif
    684 
    685     /*Init pIpFrameStatus*/
    686     /*Frame Width and Height*/
    687     pComponentPrivate->pIpFrameStatus->ulInWidth             = DEFAULT_WIDTH;
    688     pComponentPrivate->pIpFrameStatus->ulInHeight            = 220; /*Default value for StdCompRoleTest*/
    689     pComponentPrivate->pIpFrameStatus->ulCInOffset           = DEFAULT_WIDTH * 220;  /* offset of the C frame in the   *
    690                                                                     * buffer (equal to zero if there *
    691                                                                     * is no C frame)                 */
    692     /* crop */
    693     pComponentPrivate->pIpFrameStatus->ulInXstart            = 0;
    694     pComponentPrivate->pIpFrameStatus->ulInXsize             = 0; /*176 Default value for StdCompRoleTest */
    695     pComponentPrivate->pIpFrameStatus->ulInYstart            = 0;
    696     pComponentPrivate->pIpFrameStatus->ulInYsize             = 0; /* 220 Default value for StdCompRoleTest*/
    697 
    698     /* zoom*/
    699     pComponentPrivate->pIpFrameStatus->ulZoomFactor          = 1 << 10;
    700     pComponentPrivate->pIpFrameStatus->ulZoomLimit           = 1 << 10;
    701     pComponentPrivate->pIpFrameStatus->ulZoomSpeed           = 0;
    702 
    703     pComponentPrivate->pIpFrameStatus->ulFrostedGlassOvly    = OMX_FALSE;
    704     pComponentPrivate->pIpFrameStatus->ulLightChroma         = OMX_TRUE;
    705     pComponentPrivate->pIpFrameStatus->ulLockedRatio         = OMX_FALSE;
    706     pComponentPrivate->pIpFrameStatus->ulMirror              = OMX_FALSE;
    707     pComponentPrivate->pIpFrameStatus->ulRGBRotation         = 0;
    708     pComponentPrivate->pIpFrameStatus->ulYUVRotation         = 0;
    709 
    710     pComponentPrivate->pIpFrameStatus->ulContrastType        = 0;
    711     pComponentPrivate->pIpFrameStatus->ulVideoGain           = 1 << 6;   /*Video Gain (contrast) in VGPOP ranges from 0 to 127, being 64 = Gain 1 (no contrast)*/
    712 
    713     pComponentPrivate->pIpFrameStatus->ulXoffsetFromCenter16 = 0;
    714     pComponentPrivate->pIpFrameStatus->ulYoffsetFromCenter16 = 0;
    715     pComponentPrivate->pIpFrameStatus->ulOutPitch = 0;  /*Not supported at OMX level*/
    716     pComponentPrivate->pIpFrameStatus->ulAlphaRGB = 0; /*Not supported at OMX level*/
    717 
    718     /*Init pComponentPrivate->pOpYUVFrameStatus */
    719     pComponentPrivate->pOpYUVFrameStatus->ulOutWidth            = DEFAULT_WIDTH;
    720     pComponentPrivate->pOpYUVFrameStatus->ulOutHeight           = DEFAULT_HEIGHT;
    721     pComponentPrivate->pOpYUVFrameStatus->ulCOutOffset          = 0;/*  Offset of the C frame in the buffer *
    722                                                                 *   (equal to 0 if there is no C frame)*/
    723 
    724     /*Init pComponentPrivate->pOpRGBFrameStatus */
    725     pComponentPrivate->pOpRGBFrameStatus->ulOutWidth            = DEFAULT_WIDTH;
    726     pComponentPrivate->pOpRGBFrameStatus->ulOutHeight           = DEFAULT_HEIGHT;
    727     pComponentPrivate->pOpRGBFrameStatus->ulCOutOffset          = 0;/*  Offset of the C frame in the buffer *
    728                                                                 *   (equal to 0 if there is no C frame)*/
    729 
    730 #ifdef __PERF_INSTRUMENTATION__
    731     pComponentPrivate->pPERF = PERF_Create(PERF_FOURCC('V','P','P',' '),
    732                                 PERF_ModuleLLMM |
    733                                 PERF_ModuleVideoEncode | PERF_ModuleImageEncode |
    734                                 PERF_ModuleVideoDecode | PERF_ModuleImageDecode);
    735 #endif
    736 
    737     OMX_MALLOC(pComponentPrivate->pInPortFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
    738     OMX_MALLOC(pComponentPrivate->pInPortOverlayFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
    739     OMX_MALLOC(pComponentPrivate->pOutPortRGBFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
    740     OMX_MALLOC(pComponentPrivate->pOutPortYUVFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
    741     OMX_MALLOC(pComponentPrivate->pPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
    742     OMX_MALLOC(pComponentPrivate->pPortParamTypeImage, sizeof(OMX_PORT_PARAM_TYPE));
    743     OMX_MALLOC(pComponentPrivate->pPortParamTypeAudio, sizeof(OMX_PORT_PARAM_TYPE));
    744     OMX_MALLOC(pComponentPrivate->pPortParamTypeVideo, sizeof(OMX_PORT_PARAM_TYPE));
    745     OMX_MALLOC(pComponentPrivate->pPortParamTypeOthers, sizeof(OMX_PORT_PARAM_TYPE));
    746     OMX_MALLOC(pComponentPrivate->pCrop, sizeof(OMX_CONFIG_RECTTYPE));
    747 
    748     OMX_MALLOC(pComponentPrivate->cComponentName,  VPP_MAX_NAMESIZE + 1);
    749     strncpy(pComponentPrivate->cComponentName, cVPPName, VPP_MAX_NAMESIZE);
    750 
    751     OMX_MALLOC(pComponentPrivate->colorKey, 3 * sizeof(OMX_U8));
    752     pTemp = memcpy (pComponentPrivate->colorKey, (OMX_U8 *)colorKey,(3 * sizeof(OMX_U8)));
    753     if(pTemp == NULL){
    754         eError = OMX_ErrorUndefined;
    755         goto EXIT;
    756     }
    757 
    758     OMX_MALLOC(pComponentPrivate->tVPPIOConf, sizeof(VPPIOConf));
    759 
    760     eError=VPP_Initialize_PrivateStruct(pComponentPrivate);
    761     if (eError != OMX_ErrorNone) {
    762         VPP_DPRINT ("VPP::Error=0x%X returned from VPP_Initialize_PrivateStruct\n",eError);
    763         goto EXIT;
    764     }
    765 
    766     /* load the ResourceManagerProxy thread*/
    767 #ifdef RESOURCE_MANAGER_ENABLED
    768     eError = RMProxy_NewInitalizeEx(OMX_COMPONENTTYPE_VPP);
    769     if (eError != OMX_ErrorNone) {
    770         VPP_DPRINT ("VPP::%d::Error 0x%X returned from loading ResourceManagerProxy thread\n", __LINE__,eError);
    771         goto EXIT;
    772     }
    773 #endif
    774 
    775     /* start the component thread */
    776     eError = VPP_Start_ComponentThread(pHandle);
    777     if (eError != OMX_ErrorNone) {
    778         VPP_DPRINT ("VPP::Error=0x%X returned from Start_ComponentThread\n",eError);
    779         goto EXIT;
    780     }
    781 
    782     eError = OMX_ErrorNone;
    783 
    784 EXIT:
    785     if(eError != OMX_ErrorNone){
    786         /* LinkedList_DisplayAll(&AllocList); */
    787         OMX_FREEALL();
    788         LinkedList_Destroy(&AllocList);
    789     }
    790     return eError;
    791 }
    792 
    793 /*-------------------------------------------------------------------*/
    794 /**
    795   *  SetCallbacks() Sets application callbacks to the component
    796   *
    797   * This method will update application callbacks
    798   * the application.
    799   *
    800   * @param pComp         handle for this instance of the component
    801   * @param pCallBacks    application callbacks
    802   * @param ptr
    803   *
    804   * @retval OMX_NoError              Success, ready to roll
    805   *         OMX_Error_BadParameter   The input parameter pointer is null
    806   **/
    807 /*-------------------------------------------------------------------*/
    808 static OMX_ERRORTYPE VPP_SetCallbacks (OMX_HANDLETYPE pComponent,
    809                                         OMX_CALLBACKTYPE* pCallBacks,
    810                                         OMX_PTR pAppData)
    811 {
    812     OMX_ERRORTYPE eError = OMX_ErrorNone;
    813     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*)pComponent;
    814     VPP_COMPONENT_PRIVATE *pComponentPrivate = NULL;
    815     OMX_U8 *pTemp = NULL;
    816 
    817     OMX_CHECK_CMD(pComponent, pCallBacks, OMX_TRUE);
    818 
    819     pComponentPrivate = (VPP_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
    820 
    821     /*Copy the callbacks of the application to the component private */
    822     pTemp = memcpy (&(pComponentPrivate->cbInfo), pCallBacks, sizeof(OMX_CALLBACKTYPE));
    823     if(pTemp == NULL){
    824         eError = OMX_ErrorUndefined;
    825         goto EXIT;
    826     }
    827     /*copy the application private data to component memory*/
    828     pHandle->pApplicationPrivate = pAppData;
    829     pComponentPrivate->curState = OMX_StateLoaded;
    830 
    831 EXIT:
    832     return eError;
    833 }
    834 
    835 /*-------------------------------------------------------------------*/
    836 /**
    837   *  GetComponentVersion() Sets application callbacks to the component
    838   *
    839   * This method will update application callbacks
    840   * the application.
    841   *
    842   * @param pComp         handle for this instance of the component
    843   * @param pCallBacks    application callbacks
    844   * @param ptr
    845   *
    846   * @retval OMX_NoError              Success, ready to roll
    847   *         OMX_Error_BadParameter   The input parameter pointer is null
    848   **/
    849 /*-------------------------------------------------------------------*/
    850 static OMX_ERRORTYPE VPP_GetComponentVersion (OMX_HANDLETYPE   hComp,
    851                                               OMX_STRING       szComponentName,
    852                                               OMX_VERSIONTYPE* pComponentVersion,
    853                                               OMX_VERSIONTYPE* pSpecVersion,
    854                                               OMX_UUIDTYPE*    pComponentUUID)
    855 {
    856     OMX_ERRORTYPE          eError            = OMX_ErrorNone;
    857     OMX_COMPONENTTYPE    * pHandle           = NULL;
    858     VPP_COMPONENT_PRIVATE* pComponentPrivate = NULL;
    859     OMX_U8 *pTemp = NULL;
    860     if (!hComp || !szComponentName || !pComponentVersion || !pSpecVersion || !pComponentUUID) {
    861         eError = OMX_ErrorBadParameter;
    862         goto EXIT;
    863     }
    864     pHandle = (OMX_COMPONENTTYPE*)hComp;
    865     if (!pHandle->pComponentPrivate) {
    866         eError = OMX_ErrorBadParameter;
    867         goto EXIT;
    868     }
    869     pComponentPrivate = (VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
    870 
    871     strncpy(szComponentName, pComponentPrivate->cComponentName, VPP_MAX_NAMESIZE);
    872     pTemp = memcpy(pComponentVersion, &(pComponentPrivate->ComponentVersion.s), sizeof(pComponentPrivate->ComponentVersion.s));
    873     if(pTemp == NULL){
    874         eError = OMX_ErrorUndefined;
    875         goto EXIT;
    876     }
    877     pTemp = memcpy(pSpecVersion, &(pComponentPrivate->SpecVersion.s), sizeof(pComponentPrivate->SpecVersion.s));
    878     if(pTemp == NULL){
    879         eError = OMX_ErrorUndefined;
    880         goto EXIT;
    881     }
    882 
    883 EXIT:
    884     return eError;
    885 
    886 }
    887 
    888 /*-------------------------------------------------------------------*/
    889 /**
    890   *  SendCommand() used to send the commands to the component
    891   *
    892   * This method will be used by the application.
    893   *
    894   * @param phandle         handle for this instance of the component
    895   * @param Cmd             Command to be sent to the component
    896   * @param nParam          indicates commmad is sent using this method
    897   *
    898   * @retval OMX_NoError              Success, ready to roll
    899   *         OMX_Error_BadParameter   The input parameter pointer is null
    900   **/
    901 /*-------------------------------------------------------------------*/
    902 static OMX_ERRORTYPE VPP_SendCommand (OMX_IN OMX_HANDLETYPE phandle,
    903                                       OMX_IN OMX_COMMANDTYPE Cmd,
    904                                       OMX_IN OMX_U32 nParam,
    905                                       OMX_IN OMX_PTR pCmdData)
    906 {
    907     OMX_ERRORTYPE eError = OMX_ErrorNone;
    908     int nRet;
    909     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)phandle;
    910     VPP_COMPONENT_PRIVATE *pComponentPrivate = NULL;
    911     OMX_MARKTYPE *pMarkType = NULL;
    912 
    913 
    914     OMX_CHECK_CMD(phandle, OMX_TRUE, OMX_TRUE);
    915     pComponentPrivate = (VPP_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
    916 
    917     if ( pComponentPrivate->curState == OMX_StateInvalid ) {
    918         VPP_DPRINT("VPP::%d :: INVALID ALREADY",__LINE__);
    919         eError = OMX_ErrorInvalidState;
    920         goto EXIT;
    921     }
    922 
    923     switch(Cmd)
    924     {
    925     case OMX_CommandStateSet:
    926 		  pComponentPrivate->toState = nParam;
    927 		VPP_DPRINT("VPP:: OMX_CommandStateSet: tostate %d\n", nParam);
    928 		if (nParam == OMX_StateIdle && pComponentPrivate->curState == OMX_StateExecuting) {
    929 			pComponentPrivate->bIsStopping = OMX_TRUE;
    930 			VPP_DPRINT("VPP:: Is stopping!!\n");
    931 		}
    932         break;
    933     case OMX_CommandPortDisable:
    934 
    935         if ((nParam >= NUM_OF_VPP_PORTS) && (nParam != OMX_ALL)) {
    936             eError = OMX_ErrorBadPortIndex;
    937             break;
    938         }
    939         else if(nParam != OMX_ALL) {  /*If only one port is requested might come from the application, then disable from here to avoid race condition*/
    940             VPP_DPRINT("set port %d as diabled\n", nParam);
    941 			pComponentPrivate->sCompPorts[nParam].pPortDef.bEnabled=OMX_FALSE;
    942 			if (pComponentPrivate->sCompPorts[nParam].pPortDef.bPopulated) {
    943 			    pComponentPrivate->bDisableIncomplete[nParam] = OMX_TRUE;
    944 			} else {
    945                 pComponentPrivate->bDisableIncomplete[nParam] = OMX_FALSE;
    946 		        pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle,
    947 												pComponentPrivate->pHandle->pApplicationPrivate,
    948 												OMX_EventCmdComplete,
    949 												OMX_CommandPortDisable,
    950 												nParam,
    951 												NULL);
    952 			}
    953 		} else { /* nParam == 0xFFFFFFFF */
    954 			int i;
    955 			for (i = 0; i < NUM_OF_VPP_PORTS; i ++) {
    956 				VPP_DPRINT("set port %d as disabled\n", i);
    957 			    pComponentPrivate->sCompPorts[i].pPortDef.bEnabled=OMX_FALSE;
    958 				if (pComponentPrivate->sCompPorts[i].pPortDef.bPopulated) {
    959 				    pComponentPrivate->bDisableIncomplete[i] = OMX_TRUE;
    960 				} else {
    961                     pComponentPrivate->bDisableIncomplete[i] = OMX_FALSE;
    962 		            pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle,
    963 												pComponentPrivate->pHandle->pApplicationPrivate,
    964 												OMX_EventCmdComplete,
    965 												OMX_CommandPortDisable,
    966 												i,
    967 												NULL);
    968 				}
    969 			}
    970 		}
    971         break;
    972 
    973     case OMX_CommandPortEnable:
    974     case OMX_CommandFlush:
    975         /*if invalid port, send error, and don't write to any pipe*/
    976         if ((nParam >= NUM_OF_VPP_PORTS) && (nParam != OMX_ALL)) {
    977             eError = OMX_ErrorBadPortIndex;
    978             break;
    979         }
    980         break;
    981     case OMX_CommandMarkBuffer:
    982         /* we can only mark buffers on input port */
    983         if (nParam > 1) {
    984             eError = OMX_ErrorBadPortIndex;
    985             break;
    986         }
    987         VPP_DPRINT("VPP:: OMX_CommandMarkBuffer\n");
    988         pMarkType = (OMX_MARKTYPE *)pCmdData;
    989         pComponentPrivate->pMarkData = pMarkType->pMarkData;
    990         pComponentPrivate->hMarkTargetComponent = pMarkType->hMarkTargetComponent;
    991         goto EXIT;
    992 
    993 
    994         break;
    995     case OMX_CommandMax:
    996         break;
    997     default:
    998         eError = OMX_ErrorUndefined;
    999         break;
   1000     }
   1001     if(eError != OMX_ErrorNone){
   1002         goto EXIT;
   1003     }
   1004     /*Write to the command pipe*/
   1005     nRet = write (pComponentPrivate->cmdPipe[1], &Cmd, sizeof(OMX_COMMANDTYPE));
   1006     if (nRet == -1) {
   1007         eError = OMX_ErrorHardware;
   1008         goto EXIT;
   1009     }
   1010 
   1011 #ifdef __PERF_INSTRUMENTATION__
   1012     PERF_SendingCommand(pComponentPrivate->pPERF,
   1013         Cmd,
   1014         Cmd == OMX_CommandMarkBuffer ? ((OMX_U32) pCmdData) : nParam,
   1015         PERF_ModuleComponent);
   1016 #endif
   1017 
   1018         nRet = write (pComponentPrivate->nCmdDataPipe[1], &nParam, sizeof(OMX_U32));
   1019         if (nRet == -1) {
   1020             eError = OMX_ErrorHardware;
   1021             goto EXIT;
   1022         }
   1023 
   1024 EXIT:
   1025     return eError;
   1026 }
   1027 
   1028 /*-------------------------------------------------------------------*/
   1029 /**
   1030   *  GetParameter() Gets the current configurations of the component
   1031   *
   1032   * @param hComp         handle for this instance of the component
   1033   * @param nParamIndex
   1034   * @param ComponentParameterStructure
   1035   *
   1036   * @retval OMX_NoError              Success, ready to roll
   1037   *         OMX_Error_BadParameter   The input parameter pointer is null
   1038   **/
   1039 /*-------------------------------------------------------------------*/
   1040 static OMX_ERRORTYPE VPP_GetParameter (OMX_HANDLETYPE hComp,
   1041                                        OMX_INDEXTYPE nParamIndex,
   1042                                        OMX_PTR pComponentParameterStructure)
   1043 {
   1044     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1045     OMX_COMPONENTTYPE* pHandle= (OMX_COMPONENTTYPE*)hComp;
   1046     VPP_COMPONENT_PRIVATE *pComponentPrivate = NULL;
   1047     OMX_U8 *pTemp = NULL;
   1048     OMX_CHECK_CMD(hComp, pComponentParameterStructure, OMX_TRUE);
   1049     pComponentPrivate = (VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
   1050     OMX_CHECK_CMD(pComponentPrivate, OMX_TRUE, OMX_TRUE);
   1051 
   1052     VPP_DPRINT ("VPP::Inside the GetParameter %lu\n",(OMX_U32)nParamIndex);
   1053     if ( pComponentPrivate->curState == OMX_StateInvalid ) {
   1054         OMX_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation);
   1055     }
   1056 
   1057     switch(nParamIndex)
   1058     {
   1059     case OMX_IndexParamImageInit:
   1060         pTemp = memcpy(pComponentParameterStructure,
   1061                         ((VPP_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pPortParamTypeImage,
   1062                         sizeof(OMX_PORT_PARAM_TYPE));
   1063         if(pTemp == NULL){
   1064             eError = OMX_ErrorUndefined;
   1065             break;
   1066         }
   1067         break;
   1068     case OMX_IndexParamAudioInit:
   1069         pTemp = memcpy(pComponentParameterStructure,
   1070                         ((VPP_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pPortParamTypeAudio,
   1071                         sizeof(OMX_PORT_PARAM_TYPE));
   1072         if(pTemp == NULL){
   1073             eError = OMX_ErrorUndefined;
   1074             break;
   1075         }
   1076         break;
   1077     case OMX_IndexParamVideoInit:
   1078         pTemp = memcpy(pComponentParameterStructure,
   1079                         ((VPP_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pPortParamTypeVideo,
   1080                         sizeof(OMX_PORT_PARAM_TYPE));
   1081         if(pTemp == NULL){
   1082             eError = OMX_ErrorUndefined;
   1083             break;
   1084         }
   1085         break;
   1086     case OMX_IndexParamOtherInit:
   1087         pTemp = memcpy(pComponentParameterStructure,
   1088                         ((VPP_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pPortParamTypeOthers,
   1089                         sizeof(OMX_PORT_PARAM_TYPE));
   1090         if(pTemp == NULL){
   1091             eError = OMX_ErrorUndefined;
   1092             break;
   1093         }
   1094         break;
   1095     case OMX_IndexParamPortDefinition:
   1096         {
   1097             OMX_PARAM_PORTDEFINITIONTYPE *pComponentParam =(OMX_PARAM_PORTDEFINITIONTYPE *)pComponentParameterStructure;
   1098             OMX_U32 portindex = pComponentParam->nPortIndex;
   1099             if(portindex >= 0 && portindex < NUM_OF_VPP_PORTS){ /*The validation  should be done in two parts, if the portindex is a wrong number the next validation could generate a segmentation fault*/
   1100 				VPP_DPRINT ("VPP::Inside the GetParameter portindex = %d (%d)\n",(int)portindex, pComponentPrivate->sCompPorts[portindex].pPortDef.nPortIndex);
   1101 				if(portindex == pComponentPrivate->sCompPorts[portindex].pPortDef.nPortIndex){
   1102 	                pTemp = memcpy(pComponentParameterStructure,
   1103 	                    &pComponentPrivate->sCompPorts[portindex].pPortDef,
   1104 	                    sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
   1105 	                if(pTemp == NULL){
   1106 	                    eError = OMX_ErrorUndefined;
   1107 	                    break;
   1108 	                }
   1109 				}
   1110 				else{
   1111 					eError = OMX_ErrorBadPortIndex;
   1112 				}
   1113             }
   1114             else{
   1115                 eError = OMX_ErrorBadPortIndex;
   1116             }
   1117             break;
   1118         }
   1119     case OMX_IndexParamVideoPortFormat:
   1120         {
   1121             OMX_VIDEO_PARAM_PORTFORMATTYPE * pVidFmt = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)pComponentParameterStructure;
   1122             if (pVidFmt->nPortIndex == pComponentPrivate->pInPortFormat->nPortIndex) {
   1123                 if(pVidFmt->nIndex > pComponentPrivate->pInPortFormat->nIndex) {
   1124                     eError = OMX_ErrorNoMore;
   1125                 }
   1126                 else {
   1127                     pTemp = memcpy(pComponentParameterStructure,
   1128                         pComponentPrivate->pInPortFormat,
   1129                         sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
   1130                     if(pTemp == NULL){
   1131                         eError = OMX_ErrorUndefined;
   1132                         break;
   1133                     }
   1134                 }
   1135             }
   1136             else if(pVidFmt->nPortIndex == pComponentPrivate->pInPortOverlayFormat->nPortIndex) {
   1137                 if (pVidFmt->nIndex > pComponentPrivate->pInPortOverlayFormat->nIndex) {
   1138                     eError = OMX_ErrorNoMore;
   1139                 }
   1140                 else {
   1141                     pTemp = memcpy(pComponentParameterStructure,
   1142                         pComponentPrivate->pInPortOverlayFormat,
   1143                         sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
   1144                     if(pTemp == NULL){
   1145                         eError = OMX_ErrorUndefined;
   1146                         break;
   1147                     }
   1148                 }
   1149             }
   1150             else if (pVidFmt->nPortIndex == pComponentPrivate->pOutPortRGBFormat->nPortIndex) {
   1151                 if (pVidFmt->nIndex > pComponentPrivate->pOutPortRGBFormat->nIndex) {
   1152                     eError = OMX_ErrorNoMore;
   1153                 }
   1154                 else {
   1155                     pTemp = memcpy(pComponentParameterStructure,
   1156                         pComponentPrivate->pOutPortRGBFormat,
   1157                         sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
   1158                     if(pTemp == NULL){
   1159                         eError = OMX_ErrorUndefined;
   1160                         break;
   1161                     }
   1162                 }
   1163             }
   1164             else if (pVidFmt->nPortIndex == pComponentPrivate->pOutPortYUVFormat->nPortIndex) {
   1165                 if (pVidFmt->nIndex > pComponentPrivate->pOutPortYUVFormat->nIndex) {
   1166                     eError = OMX_ErrorNoMore;
   1167                 }
   1168                 else {
   1169                     pTemp = memcpy(pComponentParameterStructure,
   1170                         pComponentPrivate->pOutPortYUVFormat,
   1171                         sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
   1172                     if(pTemp == NULL){
   1173                         eError = OMX_ErrorUndefined;
   1174                         break;
   1175                     }
   1176                 }
   1177             }
   1178             else {
   1179                 eError = OMX_ErrorBadPortIndex;
   1180             }
   1181             break;
   1182         }
   1183     case OMX_IndexParamCompBufferSupplier:
   1184         {
   1185             OMX_PARAM_BUFFERSUPPLIERTYPE *pBuffSupplierParam = (OMX_PARAM_BUFFERSUPPLIERTYPE *)pComponentParameterStructure;
   1186             VPP_DPRINT ("VPP::Inside the GetParameter portindex =%d\n" , (int)pBuffSupplierParam->nPortIndex);
   1187             if (pBuffSupplierParam->nPortIndex == OMX_VPP_INPUT_PORT ||
   1188                     pBuffSupplierParam->nPortIndex == OMX_VPP_INPUT_OVERLAY_PORT ||
   1189                     pBuffSupplierParam->nPortIndex == OMX_VPP_RGB_OUTPUT_PORT ||
   1190                     pBuffSupplierParam->nPortIndex == OMX_VPP_YUV_OUTPUT_PORT ) {
   1191 
   1192                 pBuffSupplierParam->eBufferSupplier = pComponentPrivate->sCompPorts[pBuffSupplierParam->nPortIndex].eSupplierSetting;
   1193             }
   1194             else {
   1195                 eError = OMX_ErrorBadPortIndex;
   1196             }
   1197             break;
   1198         }
   1199     case OMX_IndexParamPriorityMgmt:
   1200         pTemp = memcpy(pComponentParameterStructure,
   1201                 pComponentPrivate->pPriorityMgmt,
   1202                 sizeof(OMX_PRIORITYMGMTTYPE));
   1203         if(pTemp == NULL){
   1204             eError = OMX_ErrorUndefined;
   1205             break;
   1206         }
   1207         break;
   1208 
   1209     default:
   1210         eError = OMX_ErrorUnsupportedIndex;
   1211         break;
   1212     }
   1213 EXIT:
   1214     return eError;
   1215 
   1216 }
   1217 
   1218 /*-------------------------------------------------------------------*/
   1219 /**
   1220   *  SetParameter() Sets configuration paramets to the component
   1221   *
   1222   * @param hComp         handle for this instance of the component
   1223   * @param nParamIndex
   1224   * @param pCompParam
   1225   *
   1226   * @retval OMX_NoError              Success, ready to roll
   1227   *         OMX_Error_BadParameter   The input parameter pointer is null
   1228   **/
   1229 /*-------------------------------------------------------------------*/
   1230 static OMX_ERRORTYPE VPP_SetParameter (OMX_HANDLETYPE hComp,
   1231                                        OMX_INDEXTYPE nParamIndex,
   1232                                        OMX_PTR pCompParam)
   1233 {
   1234     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1235     OMX_COMPONENTTYPE* pHandle= (OMX_COMPONENTTYPE*)hComp;
   1236     VPP_COMPONENT_PRIVATE *pComponentPrivate = NULL;
   1237     OMX_VIDEO_PORTDEFINITIONTYPE *pVidDef = NULL;
   1238     OMX_U8 *pTemp = NULL;
   1239 #ifdef KHRONOS_1_1
   1240     OMX_PARAM_COMPONENTROLETYPE  *pRole = NULL;
   1241 #endif
   1242     OMX_CHECK_CMD(hComp, pCompParam, OMX_TRUE);
   1243 
   1244     pComponentPrivate = (VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
   1245 
   1246     OMX_CHECK_CMD(pComponentPrivate, OMX_TRUE, OMX_TRUE);
   1247 
   1248     if (pComponentPrivate->curState != OMX_StateLoaded) {
   1249         OMX_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation);
   1250     }
   1251     switch (nParamIndex)
   1252     {
   1253     case OMX_IndexParamVideoPortFormat:
   1254         {
   1255             OMX_VIDEO_PARAM_PORTFORMATTYPE* pComponentParam = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)pCompParam;
   1256             if (pComponentParam->nPortIndex == pComponentPrivate->pInPortFormat->nPortIndex) {
   1257                 pTemp = memcpy(pComponentPrivate->pInPortFormat,
   1258                                             pComponentParam,
   1259                                             sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
   1260                 if(pTemp == NULL){
   1261                     eError = OMX_ErrorUndefined;
   1262                     break;
   1263                 }
   1264 
   1265             }
   1266             else if (pComponentParam->nPortIndex == pComponentPrivate->pInPortOverlayFormat->nPortIndex) {
   1267                 pTemp = memcpy(pComponentPrivate->pInPortOverlayFormat,
   1268                                             pComponentParam,
   1269                                             sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
   1270                 if(pTemp == NULL){
   1271                     eError = OMX_ErrorUndefined;
   1272                     break;
   1273                 }
   1274             }
   1275             else if (pComponentParam->nPortIndex == pComponentPrivate->pOutPortRGBFormat->nPortIndex) {
   1276                 pTemp = memcpy(pComponentPrivate->pOutPortRGBFormat,
   1277                                             pComponentParam,
   1278                                             sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
   1279                 if(pTemp == NULL){
   1280                     eError = OMX_ErrorUndefined;
   1281                     goto EXIT;
   1282                 }
   1283             }
   1284             else if (pComponentParam->nPortIndex == pComponentPrivate->pOutPortYUVFormat->nPortIndex) {
   1285                 pTemp = memcpy(pComponentPrivate->pOutPortYUVFormat,
   1286                                             pComponentParam,
   1287                                             sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
   1288                 if(pTemp == NULL){
   1289                     eError = OMX_ErrorUndefined;
   1290                     break;
   1291                 }
   1292             }
   1293             else {
   1294                 eError = OMX_ErrorBadPortIndex;
   1295             }
   1296             break;
   1297         }
   1298     case OMX_IndexParamVideoInit:
   1299         pTemp = memcpy(((VPP_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pPortParamTypeVideo,
   1300                 pCompParam,
   1301                 sizeof(OMX_PORT_PARAM_TYPE));
   1302         if(pTemp == NULL){
   1303             eError = OMX_ErrorUndefined;
   1304             break;
   1305         }
   1306         break;
   1307     case OMX_IndexParamPortDefinition:
   1308         {
   1309             OMX_PARAM_PORTDEFINITIONTYPE *pComponentParam = (OMX_PARAM_PORTDEFINITIONTYPE *)pCompParam;
   1310             OMX_U32 portIndex = pComponentParam->nPortIndex;
   1311             if ((portIndex == OMX_VPP_INPUT_PORT) || (portIndex == OMX_VPP_INPUT_OVERLAY_PORT)) {
   1312                 if (pComponentParam->eDir != OMX_DirInput) {
   1313                     VPP_DPRINT ("%d :: Invalid input buffer Direction\n", __LINE__);
   1314                     eError = OMX_ErrorBadParameter;
   1315                     break;
   1316                 }
   1317                 if (portIndex == OMX_VPP_INPUT_OVERLAY_PORT) {
   1318                     if ((OMX_COLOR_Format24bitRGB888 != pComponentParam->format.video.eColorFormat) &&
   1319                             (OMX_COLOR_FormatUnused != pComponentParam->format.video.eColorFormat)) {
   1320                         eError = OMX_ErrorUnsupportedSetting;
   1321                         break;
   1322                     }
   1323                 }
   1324                 if (portIndex == OMX_VPP_INPUT_PORT) {
   1325                     pComponentPrivate->pIpFrameStatus->ulInWidth = pComponentParam->format.video.nFrameWidth;
   1326                     pComponentPrivate->pIpFrameStatus->ulInHeight = pComponentParam->format.video.nFrameHeight;
   1327                     pComponentPrivate->pIpFrameStatus->ulCInOffset = 0;
   1328                 }
   1329             }
   1330             else if (portIndex == OMX_VPP_YUV_OUTPUT_PORT){
   1331                 if (pComponentParam->eDir != OMX_DirOutput) {
   1332                     VPP_DPRINT ("VPP::%d :: Invalid Output buffer Direction\n", __LINE__);
   1333                     eError = OMX_ErrorBadParameter;
   1334                     break;
   1335                 }
   1336                 pComponentPrivate->pOpYUVFrameStatus->ulOutWidth  = pComponentParam->format.video.nFrameWidth;
   1337                 pComponentPrivate->pOpYUVFrameStatus->ulOutHeight = pComponentParam->format.video.nFrameHeight;
   1338             }
   1339             else if(portIndex == OMX_VPP_RGB_OUTPUT_PORT){
   1340                 if (pComponentParam->eDir != OMX_DirOutput) {
   1341                     VPP_DPRINT ("VPP::%d :: Invalid Output buffer Direction\n", __LINE__);
   1342                     eError = OMX_ErrorBadParameter;
   1343                     break;
   1344                 }
   1345                 pComponentPrivate->pOpRGBFrameStatus->ulOutWidth  = pComponentParam->format.video.nFrameWidth;
   1346                 pComponentPrivate->pOpRGBFrameStatus->ulOutHeight = pComponentParam->format.video.nFrameHeight;
   1347             }
   1348             else {
   1349                 VPP_DPRINT ("VPP::%d :: Wrong Port Index Parameter\n", __LINE__);
   1350                 eError = OMX_ErrorBadPortIndex;
   1351                 break;
   1352             }
   1353             pTemp = memcpy (&(((VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->sCompPorts[portIndex].pPortDef),
   1354                     pComponentParam,
   1355                     sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
   1356             if(pTemp == NULL){
   1357                 eError = OMX_ErrorUndefined;
   1358                 break;
   1359             }
   1360 
   1361             /* update nBufferSize */
   1362             pComponentPrivate->sCompPorts[portIndex].pPortDef.nBufferSize =
   1363                 pComponentParam->format.video.nFrameWidth * pComponentParam->format.video.nFrameHeight;
   1364 
   1365             switch(pComponentPrivate->sCompPorts[portIndex].pPortDef.format.video.eColorFormat) {
   1366                 case OMX_COLOR_FormatYUV420PackedPlanar:
   1367                     pComponentPrivate->sCompPorts[portIndex].pPortDef.nBufferSize*= 3;
   1368                     pComponentPrivate->sCompPorts[portIndex].pPortDef.nBufferSize/= 2;
   1369                     break;
   1370                 case OMX_COLOR_FormatCbYCrY:
   1371                     pComponentPrivate->sCompPorts[portIndex].pPortDef.nBufferSize*= 2;
   1372                     break;
   1373                 case OMX_COLOR_FormatYCbYCr:
   1374                     pComponentPrivate->sCompPorts[portIndex].pPortDef.nBufferSize*= 2;
   1375                     break;
   1376                 case OMX_COLOR_Format32bitARGB8888:
   1377                     pComponentPrivate->sCompPorts[portIndex].pPortDef.nBufferSize*= 4;
   1378                     break;
   1379                 case OMX_COLOR_Format24bitRGB888:
   1380                     pComponentPrivate->sCompPorts[portIndex].pPortDef.nBufferSize*= 3;
   1381                     break;
   1382                 case OMX_COLOR_Format16bitRGB565:
   1383                     pComponentPrivate->sCompPorts[portIndex].pPortDef.nBufferSize*= 2;
   1384                     break;
   1385                 case OMX_COLOR_Format12bitRGB444:
   1386                     pComponentPrivate->sCompPorts[portIndex].pPortDef.nBufferSize*= 2;
   1387                     break;
   1388                 case OMX_COLOR_Format8bitRGB332:
   1389                     pComponentPrivate->sCompPorts[portIndex].pPortDef.nBufferSize*= 2;
   1390                     break;
   1391                 case OMX_COLOR_FormatL8:
   1392                     break;
   1393                 case OMX_COLOR_FormatL4:
   1394                     pComponentPrivate->sCompPorts[portIndex].pPortDef.nBufferSize/= 2;
   1395                     break;
   1396                 case OMX_COLOR_FormatL2:
   1397                     pComponentPrivate->sCompPorts[portIndex].pPortDef.nBufferSize/= 4;
   1398                     break;
   1399                 case  OMX_COLOR_FormatMonochrome:
   1400                     pComponentPrivate->sCompPorts[portIndex].pPortDef.nBufferSize/= 8;
   1401                     break;
   1402                 default:
   1403                     pComponentPrivate->sCompPorts[portIndex].pPortDef.nBufferSize/= 2;
   1404                     break;
   1405             }
   1406 
   1407             VPP_DPRINT("after setparam: %d\n",
   1408                 ((VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->sCompPorts[portIndex].pPortDef.nPortIndex);
   1409 
   1410             if (portIndex == OMX_VPP_YUV_OUTPUT_PORT) {
   1411                 pVidDef     = &(pComponentPrivate->sCompPorts[OMX_VPP_YUV_OUTPUT_PORT].pPortDef.format.video);
   1412                 if (pVidDef->eColorFormat == OMX_COLOR_FormatYUV420PackedPlanar) {
   1413                     pComponentPrivate->pOpYUVFrameStatus->ulCOutOffset =
   1414                     pComponentPrivate->pOpYUVFrameStatus->ulOutWidth * pComponentPrivate->pOpYUVFrameStatus->ulOutHeight;
   1415                 }
   1416                 else {
   1417                     pComponentPrivate->pOpYUVFrameStatus->ulCOutOffset = 0;
   1418                 }
   1419             }
   1420             else if (portIndex == OMX_VPP_INPUT_PORT) {
   1421                 pVidDef     = &(pComponentPrivate->sCompPorts[OMX_VPP_INPUT_PORT].pPortDef.format.video);
   1422                 if (pVidDef->eColorFormat == OMX_COLOR_FormatYUV420PackedPlanar) {
   1423                     pComponentPrivate->pIpFrameStatus->ulCInOffset =
   1424                     pComponentPrivate->pIpFrameStatus->ulInWidth * pComponentPrivate->pIpFrameStatus->ulInHeight;
   1425                 }
   1426                 else {
   1427                     pComponentPrivate->pIpFrameStatus->ulCInOffset = 0;
   1428                 }
   1429             }
   1430             break;
   1431         }
   1432     case OMX_IndexParamPriorityMgmt:
   1433         pTemp = memcpy(pComponentPrivate->pPriorityMgmt,
   1434             (OMX_PRIORITYMGMTTYPE*)pCompParam,
   1435             sizeof(OMX_PRIORITYMGMTTYPE));
   1436         if(pTemp == NULL){
   1437             eError = OMX_ErrorUndefined;
   1438             break;
   1439         }
   1440         break;
   1441     case OMX_IndexParamCompBufferSupplier:
   1442         {
   1443             OMX_PARAM_BUFFERSUPPLIERTYPE *pBuffSupplierParam = (OMX_PARAM_BUFFERSUPPLIERTYPE *)pCompParam;
   1444             /*Verify if it's a correct port index*/
   1445             if ( pBuffSupplierParam->nPortIndex == OMX_VPP_INPUT_PORT ||
   1446                     pBuffSupplierParam->nPortIndex == OMX_VPP_INPUT_OVERLAY_PORT ||
   1447                     pBuffSupplierParam->nPortIndex == OMX_VPP_RGB_OUTPUT_PORT ||
   1448                     pBuffSupplierParam->nPortIndex == OMX_VPP_YUV_OUTPUT_PORT ) {
   1449                 /* Copy parameters to input port buffer supplier type */
   1450                 pComponentPrivate->sCompPorts[pBuffSupplierParam->nPortIndex].eSupplierSetting =
   1451                     pBuffSupplierParam->eBufferSupplier;
   1452             }
   1453             else {
   1454                 eError = OMX_ErrorBadPortIndex;
   1455                 break;
   1456             }
   1457             break;
   1458         }
   1459 #ifdef KHRONOS_1_1
   1460     case OMX_IndexParamStandardComponentRole:
   1461         if (pCompParam) {
   1462             pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam;
   1463             memcpy(&(pComponentPrivate->componentRole), (void *)pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
   1464         } else {
   1465             eError = OMX_ErrorBadParameter;
   1466         }
   1467         break;
   1468 #endif
   1469     default:
   1470         eError = OMX_ErrorUnsupportedIndex;
   1471         break;
   1472     }
   1473 EXIT:
   1474     return eError;
   1475 
   1476 }
   1477 
   1478 /*-------------------------------------------------------------------*/
   1479 /**
   1480   *  GetConfig() Gets the current configuration of to the component
   1481   *
   1482   * @param hComp         handle for this instance of the component
   1483   * @param nConfigIndex
   1484   * @param ComponentConfigStructure
   1485   *
   1486   * @retval OMX_NoError              Success, ready to roll
   1487   *         OMX_Error_BadParameter   The input parameter pointer is null
   1488   **/
   1489 /*-------------------------------------------------------------------*/
   1490 static OMX_ERRORTYPE VPP_GetConfig (OMX_HANDLETYPE hComp,
   1491 OMX_INDEXTYPE nConfigIndex,
   1492 OMX_PTR ComponentConfigStructure)
   1493 {
   1494     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1495     OMX_COMPONENTTYPE* pHandle= (OMX_COMPONENTTYPE*)hComp;
   1496     VPP_COMPONENT_PRIVATE *pComponentPrivate = NULL;
   1497 
   1498     VPP_DPRINT ("VPP::Inside the GetConfig\n");
   1499 
   1500     OMX_CHECK_CMD(hComp, ComponentConfigStructure, OMX_TRUE);
   1501     pComponentPrivate = (VPP_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
   1502 
   1503     switch(nConfigIndex)
   1504     {
   1505     case OMX_IndexConfigCommonInputCrop :
   1506         {
   1507             OMX_CONFIG_RECTTYPE *crop = (OMX_CONFIG_RECTTYPE*)ComponentConfigStructure;
   1508             crop->nLeft   = pComponentPrivate->pCrop->nLeft;
   1509             crop->nWidth  = pComponentPrivate->pCrop->nWidth;
   1510             crop->nTop    = pComponentPrivate->pCrop->nTop;
   1511             crop->nHeight = pComponentPrivate->pCrop->nHeight;
   1512 
   1513             break;
   1514         }
   1515     case OMX_IndexConfigCommonRotate :/*On Rotation, the OMX_CONFIG_ROTATIONTYPE must indicate the port index, since VPP supports independent rotation on each port*/
   1516         {
   1517             OMX_CONFIG_ROTATIONTYPE *Rotate = (OMX_CONFIG_ROTATIONTYPE*)ComponentConfigStructure;
   1518             if (Rotate->nPortIndex==OMX_VPP_RGB_OUTPUT_PORT) {
   1519                 Rotate->nRotation = pComponentPrivate->pIpFrameStatus->ulRGBRotation;
   1520             }
   1521             else if (Rotate->nPortIndex==OMX_VPP_YUV_OUTPUT_PORT) {
   1522                 Rotate->nRotation = pComponentPrivate->pIpFrameStatus->ulYUVRotation;
   1523             }
   1524             else if (Rotate->nPortIndex==OMX_VPP_INPUT_PORT ||Rotate->nPortIndex==OMX_VPP_INPUT_OVERLAY_PORT){
   1525                 Rotate->nRotation = pComponentPrivate->pIpFrameStatus->ulYUVRotation;
   1526             }
   1527             else {
   1528                 eError = OMX_ErrorBadParameter;
   1529                 break;
   1530             }
   1531             break;
   1532         }
   1533     case OMX_IndexConfigCommonMirror:
   1534         {
   1535             OMX_CONFIG_MIRRORTYPE *nMirror = (OMX_CONFIG_MIRRORTYPE*)ComponentConfigStructure;
   1536             if(nMirror->nPortIndex > OMX_VPP_MAXPORT_NUM){
   1537                 eError = OMX_ErrorBadPortIndex;
   1538                 goto EXIT;
   1539             }
   1540             nMirror->eMirror = ((VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->sCompPorts[nMirror->nPortIndex].eMirror;
   1541             break;
   1542         }
   1543     case OMX_IndexConfigCommonScale:
   1544         {
   1545             OMX_CONFIG_SCALEFACTORTYPE *sScale = (OMX_CONFIG_SCALEFACTORTYPE*)ComponentConfigStructure;
   1546             if(sScale->nPortIndex > OMX_VPP_MAXPORT_NUM){
   1547                 eError = OMX_ErrorBadPortIndex;
   1548                 goto EXIT;
   1549             }
   1550 
   1551             sScale->xWidth = ((VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->sScale.xWidth;
   1552             sScale->xHeight = ((VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->sScale.xHeight;
   1553             break;
   1554         }
   1555     case OMX_IndexCustomConfigInputSize:
   1556         {
   1557             OMX_FRAMESIZETYPE *pInputSize = (OMX_FRAMESIZETYPE *)ComponentConfigStructure;
   1558             VPP_COMPONENT_PRIVATE *pComponentPrivate = (VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
   1559             if((pInputSize->nPortIndex != OMX_VPP_INPUT_PORT) && (pInputSize->nPortIndex != OMX_VPP_INPUT_OVERLAY_PORT)){
   1560                 eError = OMX_ErrorBadParameter;
   1561                 goto EXIT;
   1562             }
   1563 
   1564             if(pInputSize->nPortIndex == OMX_VPP_INPUT_PORT){
   1565                 pInputSize->nWidth = pComponentPrivate->pIpFrameStatus->ulInWidth;
   1566                 pInputSize->nHeight = pComponentPrivate->pIpFrameStatus->ulInHeight;
   1567             }
   1568             else if(pInputSize->nPortIndex == OMX_VPP_INPUT_OVERLAY_PORT){
   1569                 pInputSize->nWidth = pComponentPrivate->pIpFrameStatus->ulInWidth;
   1570                 pInputSize->nHeight = pComponentPrivate->pIpFrameStatus->ulInHeight;
   1571             }
   1572             break;
   1573         }
   1574     case OMX_IndexConfigCommonOutputSize:
   1575         {
   1576             OMX_FRAMESIZETYPE *pOutputSize = (OMX_FRAMESIZETYPE *)ComponentConfigStructure;
   1577             VPP_COMPONENT_PRIVATE *pComponentPrivate = (VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
   1578             if((pOutputSize->nPortIndex != OMX_VPP_YUV_OUTPUT_PORT) && (pOutputSize->nPortIndex != OMX_VPP_RGB_OUTPUT_PORT)){
   1579                 eError = OMX_ErrorBadParameter;
   1580                 goto EXIT;
   1581             }
   1582 
   1583             if(pOutputSize->nPortIndex == OMX_VPP_YUV_OUTPUT_PORT){
   1584                 pOutputSize->nWidth = pComponentPrivate->pOpYUVFrameStatus->ulOutWidth;
   1585                 pOutputSize->nHeight = pComponentPrivate->pOpYUVFrameStatus->ulOutHeight;
   1586             }
   1587             else if(pOutputSize->nPortIndex == OMX_VPP_RGB_OUTPUT_PORT){
   1588                 pOutputSize->nWidth = pComponentPrivate->pOpRGBFrameStatus->ulOutWidth;
   1589                 pOutputSize->nHeight = pComponentPrivate->pOpRGBFrameStatus->ulOutHeight;
   1590             }
   1591 
   1592             break;
   1593         }
   1594     default:
   1595         eError = OMX_ErrorUnsupportedIndex;
   1596         break;
   1597     }
   1598 EXIT:
   1599     return eError;
   1600 }
   1601 
   1602 /*-------------------------------------------------------------------*/
   1603 /**
   1604   *  SetConfig() Sets the configraiton to the component
   1605   *
   1606   * @param hComp         handle for this instance of the component
   1607   * @param nConfigIndex
   1608   * @param ComponentConfigStructure
   1609   *
   1610   * @retval OMX_NoError              Success, ready to roll
   1611   *         OMX_Error_BadParameter   The input parameter pointer is null
   1612   **/
   1613 /*-------------------------------------------------------------------*/
   1614 static OMX_ERRORTYPE VPP_SetConfig (OMX_HANDLETYPE hComp,
   1615 OMX_INDEXTYPE nConfigIndex,
   1616 OMX_PTR ComponentConfigStructure)
   1617 {
   1618     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1619     OMX_COMPONENTTYPE* pHandle= (OMX_COMPONENTTYPE*)hComp;
   1620     OMX_U8 *pTemp = NULL;
   1621 
   1622     OMX_CHECK_CMD(hComp, ComponentConfigStructure, OMX_TRUE);
   1623 
   1624     VPP_DPRINT ("VPP::Inside the SetConfig\n");
   1625 
   1626     switch(nConfigIndex)
   1627     {
   1628     case OMX_IndexConfigCommonColorKey:
   1629         {
   1630             /*Already allocated in ComponentInit*/
   1631             OMX_CONFIG_COLORKEYTYPE *transcolorkey = (OMX_CONFIG_COLORKEYTYPE*)ComponentConfigStructure;
   1632             pTemp = memcpy (((VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)-> colorKey,
   1633                 ((OMX_U8 *) transcolorkey ->nARGBMask )+1,
   1634                 3 * sizeof(OMX_U8));
   1635             if(pTemp == NULL){
   1636                 eError = OMX_ErrorUndefined;
   1637                 goto EXIT;
   1638             }
   1639             break;
   1640         }
   1641     case OMX_IndexConfigCommonInputCrop :
   1642         {
   1643             OMX_CONFIG_RECTTYPE *crop = (OMX_CONFIG_RECTTYPE*)ComponentConfigStructure;
   1644             ((VPP_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pIpFrameStatus->ulInXstart = crop->nLeft;
   1645             ((VPP_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pIpFrameStatus->ulInXsize  = crop->nWidth;
   1646             ((VPP_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pIpFrameStatus->ulInYstart = crop->nTop;
   1647             ((VPP_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pIpFrameStatus->ulInYsize  = crop->nHeight;
   1648             /*StdcomponentRoleTest*/
   1649             ((VPP_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pCrop->nLeft = crop->nLeft;
   1650             ((VPP_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pCrop->nWidth = crop->nWidth;
   1651             ((VPP_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pCrop->nTop = crop->nTop;
   1652             ((VPP_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pCrop->nHeight = crop->nHeight;
   1653             break;
   1654         }
   1655     case OMX_IndexConfigCommonContrast :
   1656         {
   1657             OMX_U32 nContrast;
   1658             OMX_CONFIG_CONTRASTTYPE *contrast = (OMX_CONFIG_CONTRASTTYPE*)ComponentConfigStructure;
   1659 
   1660             if (contrast->nContrast < VPP_CONTRAST_MIN) {  VPP_DPRINT("Out of range value, setting Contrast to Minimum\n");
   1661                 contrast->nContrast = VPP_CONTRAST_MIN;
   1662             }
   1663             else if(contrast->nContrast > VPP_CONTRAST_MAX)
   1664             {
   1665                 VPP_DPRINT("Out of range value, setting Contrast to Maximum\n");
   1666                 contrast->nContrast = VPP_CONTRAST_MAX;
   1667             }
   1668 
   1669             /*Normalize for VGPOP range*/
   1670             nContrast = (OMX_U32) ((contrast->nContrast+VPP_CONTRAST_OFFSET)*VPP_CONTRAST_FACTOR);
   1671 
   1672             ((VPP_COMPONENT_PRIVATE*)
   1673                 pHandle->pComponentPrivate)->pIpFrameStatus->ulVideoGain = nContrast;
   1674             break;
   1675         }
   1676     case OMX_IndexConfigCommonRotate :
   1677         {
   1678             OMX_CONFIG_ROTATIONTYPE *Rotate = (OMX_CONFIG_ROTATIONTYPE*)ComponentConfigStructure;
   1679             VPP_DPRINT ("VPP::Inside the SetConfig in OMX_IndexConfigCommonRotate  \n");
   1680 
   1681             if (((Rotate->nPortIndex == OMX_VPP_RGB_OUTPUT_PORT) || (Rotate->nPortIndex == OMX_VPP_YUV_OUTPUT_PORT)) &&
   1682                     (Rotate->nRotation == 0 ||
   1683                         Rotate->nRotation == 90 ||
   1684                         Rotate->nRotation == 180 ||
   1685                         Rotate->nRotation == 270)) {
   1686                 if(Rotate->nPortIndex == OMX_VPP_RGB_OUTPUT_PORT){
   1687                     ((VPP_COMPONENT_PRIVATE*)
   1688                     pHandle->pComponentPrivate)->pIpFrameStatus->ulRGBRotation = Rotate->nRotation;
   1689                 }
   1690                 else if (Rotate->nPortIndex == OMX_VPP_YUV_OUTPUT_PORT) {
   1691                     ((VPP_COMPONENT_PRIVATE*)
   1692                         pHandle->pComponentPrivate)->pIpFrameStatus->ulYUVRotation = Rotate->nRotation;
   1693                 }
   1694             }
   1695             else if (((Rotate->nPortIndex == OMX_VPP_INPUT_PORT) || (Rotate->nPortIndex == OMX_VPP_INPUT_OVERLAY_PORT)) &&
   1696                         (Rotate->nRotation == 0 ||
   1697                         Rotate->nRotation == 90 ||
   1698                         Rotate->nRotation == 180 ||
   1699                         Rotate->nRotation == 270)) {
   1700                     ((VPP_COMPONENT_PRIVATE*)
   1701                         pHandle->pComponentPrivate)->pIpFrameStatus->ulYUVRotation = Rotate->nRotation;
   1702                 }
   1703             else{
   1704                 eError = OMX_ErrorBadParameter;
   1705                 goto EXIT;
   1706             }
   1707             break;
   1708         }
   1709     case OMX_IndexCustomSetZoomFactor :
   1710         {
   1711             OMX_U32 *nZoomfactor = (OMX_U32*)ComponentConfigStructure;
   1712 
   1713             ((VPP_COMPONENT_PRIVATE*)
   1714                 pHandle->pComponentPrivate)->pIpFrameStatus->ulZoomFactor = *nZoomfactor;
   1715             break;
   1716         }
   1717     case OMX_IndexCustomSetZoomLimit :
   1718         {
   1719             OMX_U32 *nZoomlimit = (OMX_U32*)ComponentConfigStructure;
   1720             ((VPP_COMPONENT_PRIVATE*)
   1721                 pHandle->pComponentPrivate)->pIpFrameStatus->ulZoomLimit = *nZoomlimit;
   1722 
   1723             break;
   1724         }
   1725     case OMX_IndexCustomSetZoomSpeed :
   1726         {
   1727             OMX_U32 *nZoomspeed = (OMX_U32*)ComponentConfigStructure;
   1728             ((VPP_COMPONENT_PRIVATE*)
   1729                 pHandle->pComponentPrivate)->pIpFrameStatus->ulZoomSpeed = *nZoomspeed;
   1730 
   1731             break;
   1732         }
   1733     case OMX_IndexCustomSetFrostedGlassOvly :
   1734         {
   1735             OMX_U32 *FrostedGlassOvly = (OMX_U32*)ComponentConfigStructure;
   1736             ((VPP_COMPONENT_PRIVATE*)
   1737                 pHandle->pComponentPrivate)->pIpFrameStatus->ulFrostedGlassOvly = *FrostedGlassOvly;
   1738 
   1739             break;
   1740         }
   1741     case OMX_IndexCustomSetZoomXoffsetFromCenter16 :
   1742         {
   1743             OMX_U32 *XoffsetFromCenter16 = (OMX_U32*)ComponentConfigStructure;
   1744             ((VPP_COMPONENT_PRIVATE*)
   1745                 pHandle->pComponentPrivate)->pIpFrameStatus->ulXoffsetFromCenter16 = *XoffsetFromCenter16;
   1746 
   1747             break;
   1748         }
   1749     case OMX_IndexCustomSetZoomYoffsetFromCenter16 :
   1750         {
   1751             OMX_U32 *YoffsetFromCenter16 = (OMX_U32*)ComponentConfigStructure;
   1752             ((VPP_COMPONENT_PRIVATE*)
   1753                 pHandle->pComponentPrivate)->pIpFrameStatus->ulYoffsetFromCenter16 = *YoffsetFromCenter16;
   1754 
   1755             break;
   1756         }
   1757     case OMX_IndexConfigCommonMirror:
   1758         {
   1759             /*Only RGB output mirroring supported*/
   1760             OMX_CONFIG_MIRRORTYPE *nMirror = (OMX_CONFIG_MIRRORTYPE*)ComponentConfigStructure;
   1761             OMX_S32 nMirrorRotation = 0;
   1762             OMX_MIRRORTYPE eMirrorPrev = OMX_MirrorNone;
   1763 
   1764             if(nMirror->nPortIndex > OMX_VPP_MAXPORT_NUM){
   1765                 eError = OMX_ErrorBadParameter;
   1766                 goto EXIT;
   1767             }
   1768 
   1769             eMirrorPrev = ((VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->sCompPorts[nMirror->nPortIndex].eMirror;
   1770             if(eMirrorPrev != OMX_MirrorNone){
   1771                 ((VPP_COMPONENT_PRIVATE*)
   1772                     pHandle->pComponentPrivate)->pIpFrameStatus->ulMirror = OMX_FALSE;
   1773                 if(eMirrorPrev == OMX_MirrorVertical|| eMirrorPrev == OMX_MirrorBoth){
   1774                     nMirrorRotation = ((VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->pIpFrameStatus->ulRGBRotation;
   1775                     if(nMirrorRotation <= 90){
   1776                         nMirrorRotation += 180;
   1777                     }
   1778                     else{
   1779                         nMirrorRotation -= 180;
   1780                     }
   1781                     ((VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->pIpFrameStatus->ulRGBRotation = nMirrorRotation;
   1782                 }
   1783             }
   1784 
   1785             if (nMirror->eMirror == OMX_MirrorHorizontal){
   1786                 ((VPP_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)
   1787                     ->pIpFrameStatus->ulMirror = OMX_TRUE;
   1788                 ((VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)
   1789                     ->sCompPorts[nMirror->nPortIndex].eMirror = OMX_MirrorHorizontal;
   1790             }
   1791             else if (nMirror->eMirror == OMX_MirrorVertical){
   1792                 nMirrorRotation = 180;
   1793                 ((VPP_COMPONENT_PRIVATE*)
   1794                     pHandle->pComponentPrivate)->pIpFrameStatus->ulMirror = OMX_TRUE;
   1795                 ((VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)
   1796                     ->sCompPorts[nMirror->nPortIndex].eMirror = OMX_MirrorVertical;
   1797                 nMirrorRotation += ((VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->pIpFrameStatus->ulRGBRotation;
   1798                 if (nMirrorRotation >= 360){
   1799                     nMirrorRotation -= 180;
   1800                 }
   1801                 ((VPP_COMPONENT_PRIVATE*)
   1802                     pHandle->pComponentPrivate)->pIpFrameStatus->ulRGBRotation = nMirrorRotation;
   1803             }
   1804             else if (nMirror->eMirror == OMX_MirrorBoth) {
   1805                 ((VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)
   1806                     ->sCompPorts[nMirror->nPortIndex].eMirror = OMX_MirrorBoth;
   1807                 nMirrorRotation = 180;
   1808                 nMirrorRotation += ((VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->pIpFrameStatus->ulRGBRotation;
   1809                 if (nMirrorRotation >= 360){
   1810                     nMirrorRotation -= 180;
   1811                 }
   1812                 ((VPP_COMPONENT_PRIVATE*)
   1813                     pHandle->pComponentPrivate)->pIpFrameStatus->ulRGBRotation = nMirrorRotation;
   1814             }
   1815             else if(nMirror->eMirror == OMX_MirrorNone){
   1816                 ((VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)
   1817                     ->sCompPorts[nMirror->nPortIndex].eMirror = OMX_MirrorNone;
   1818                 }
   1819             else {
   1820                 eError = OMX_ErrorUnsupportedSetting;
   1821                 goto EXIT;
   1822             }
   1823 
   1824             break;
   1825         }
   1826     case OMX_IndexConfigCommonDithering:
   1827         {
   1828             OMX_CONFIG_DITHERTYPE *nDither = (OMX_CONFIG_DITHERTYPE *)ComponentConfigStructure;
   1829             if (nDither->eDither == OMX_DitherErrorDiffusion && nDither->nPortIndex == OMX_VPP_RGB_OUTPUT_PORT) {
   1830                 ((VPP_COMPONENT_PRIVATE*)
   1831                     pHandle->pComponentPrivate)->pIpFrameStatus->ulDithering = OMX_TRUE;
   1832             }
   1833             else {
   1834                 eError = OMX_ErrorUnsupportedSetting;
   1835                 goto EXIT;
   1836             }
   1837             break;
   1838         }
   1839     case OMX_IndexCustomVideoColorRange:
   1840         {
   1841             OMX_U32 *nColorRange = (OMX_U32*)ComponentConfigStructure;
   1842             VPP_DPRINT ("VPP::Inside the SetConfig in OMX_IndexConfigCommonColorRange  \n");
   1843             if ((*nColorRange == VGPOP_IN_16_235_OUT_16_235 ||
   1844                     *nColorRange == VGPOP_IN_00_255_OUT_00_255 ||
   1845                     *nColorRange == VGPOP_IN_00_255_OUT_16_235 ||
   1846                     *nColorRange == VGPOP_IN_16_235_OUT_00_255)) {
   1847                 ((VPP_COMPONENT_PRIVATE*)
   1848                     pHandle->pComponentPrivate)->pIpFrameStatus->eIORange = *nColorRange;
   1849             }
   1850             else {
   1851                 eError = OMX_ErrorBadParameter;
   1852                 goto EXIT;
   1853             }
   1854 
   1855             break;
   1856         }
   1857     case OMX_IndexConfigCommonScale:
   1858         {
   1859             OMX_CONFIG_SCALEFACTORTYPE *sScale = (OMX_CONFIG_SCALEFACTORTYPE*)ComponentConfigStructure;
   1860             if(sScale->nPortIndex > OMX_VPP_MAXPORT_NUM){
   1861                 eError = OMX_ErrorBadParameter;
   1862                 goto EXIT;
   1863             }
   1864 
   1865             ((VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->sScale.xWidth = sScale->xWidth;
   1866             ((VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->sScale.xHeight = sScale->xHeight;
   1867 
   1868             break;
   1869         }
   1870     case OMX_IndexCustomConfigInputSize:
   1871         {
   1872             OMX_FRAMESIZETYPE *pInputSize = (OMX_FRAMESIZETYPE *)ComponentConfigStructure;
   1873             VPP_COMPONENT_PRIVATE *pComponentPrivate = (VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
   1874             if((pInputSize->nPortIndex != OMX_VPP_INPUT_PORT) && (pInputSize->nPortIndex != OMX_VPP_INPUT_OVERLAY_PORT)){
   1875                 eError = OMX_ErrorBadParameter;
   1876                 goto EXIT;
   1877             }
   1878 
   1879             if(pInputSize->nPortIndex == OMX_VPP_INPUT_PORT){
   1880                 pComponentPrivate->pIpFrameStatus->ulInWidth = pInputSize->nWidth;
   1881                 pComponentPrivate->pIpFrameStatus->ulInHeight = pInputSize->nHeight;
   1882                 if(pComponentPrivate->sCompPorts[OMX_VPP_INPUT_PORT].pPortDef.format.video.eColorFormat == OMX_COLOR_FormatYUV420PackedPlanar){
   1883                      pComponentPrivate->pIpFrameStatus->ulCInOffset =
   1884                         pComponentPrivate->pIpFrameStatus->ulInWidth * pComponentPrivate->pIpFrameStatus->ulInHeight;
   1885                 }
   1886                 else{
   1887                     pComponentPrivate->pIpFrameStatus->ulCInOffset = 0;
   1888                 }
   1889             }
   1890             else if(pInputSize->nPortIndex == OMX_VPP_INPUT_OVERLAY_PORT){
   1891                 eError = OMX_ErrorUnsupportedSetting;
   1892                 goto EXIT;
   1893             }
   1894             break;
   1895         }
   1896     case OMX_IndexConfigCommonOutputSize:
   1897         {
   1898             OMX_FRAMESIZETYPE *pOutputSize = (OMX_FRAMESIZETYPE *)ComponentConfigStructure;
   1899             VPP_COMPONENT_PRIVATE *pComponentPrivate = (VPP_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
   1900             if((pOutputSize->nPortIndex != OMX_VPP_YUV_OUTPUT_PORT) && (pOutputSize->nPortIndex != OMX_VPP_RGB_OUTPUT_PORT)){
   1901                 eError = OMX_ErrorBadParameter;
   1902                 goto EXIT;
   1903             }
   1904 
   1905             if(pOutputSize->nPortIndex == OMX_VPP_YUV_OUTPUT_PORT){
   1906                 pComponentPrivate->pOpYUVFrameStatus->ulOutWidth = pOutputSize->nWidth;
   1907                 pComponentPrivate->pOpYUVFrameStatus->ulOutHeight = pOutputSize->nHeight;
   1908                 if(pComponentPrivate->sCompPorts[OMX_VPP_YUV_OUTPUT_PORT].pPortDef.format.video.eColorFormat == OMX_COLOR_FormatYUV420PackedPlanar){
   1909                      pComponentPrivate->pOpYUVFrameStatus->ulCOutOffset =
   1910                         pComponentPrivate->pOpYUVFrameStatus->ulOutWidth * pComponentPrivate->pOpYUVFrameStatus->ulOutHeight;
   1911                 }
   1912                 else{
   1913                     pComponentPrivate->pOpYUVFrameStatus->ulCOutOffset = 0;
   1914                 }
   1915             }
   1916             else if(pOutputSize->nPortIndex == OMX_VPP_RGB_OUTPUT_PORT){
   1917                 pComponentPrivate->pOpRGBFrameStatus->ulOutWidth            = pOutputSize->nWidth;
   1918                 pComponentPrivate->pOpRGBFrameStatus->ulOutHeight           = pOutputSize->nHeight;
   1919                 pComponentPrivate->pOpRGBFrameStatus->ulCOutOffset          = 0;
   1920             }
   1921             break;
   1922         }
   1923     default:
   1924         eError = OMX_ErrorUnsupportedIndex;
   1925         break;
   1926     }
   1927 EXIT:
   1928     return eError;
   1929 }
   1930 
   1931 /*-------------------------------------------------------------------*/
   1932 /**
   1933   *  GetState() Gets the current state of the component
   1934   *
   1935   * @param pCompomponent handle for this instance of the component
   1936   * @param pState
   1937   *
   1938   * @retval OMX_NoError              Success, ready to roll
   1939   *         OMX_Error_BadParameter   The input parameter pointer is null
   1940   **/
   1941 /*-------------------------------------------------------------------*/
   1942 static OMX_ERRORTYPE VPP_GetState (OMX_HANDLETYPE pComponent, OMX_STATETYPE* pState)
   1943 {
   1944     OMX_ERRORTYPE eError = OMX_ErrorUndefined;
   1945     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
   1946 
   1947     OMX_CHECK_CMD(pComponent, pState, OMX_TRUE);
   1948 
   1949     if (pHandle->pComponentPrivate) {
   1950         *pState = ((VPP_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->curState;
   1951     }
   1952     else {
   1953         eError = OMX_ErrorUndefined;
   1954         goto EXIT;
   1955     }
   1956     eError = OMX_ErrorNone;
   1957 
   1958 EXIT:
   1959     return eError;
   1960 }
   1961 
   1962 /*-------------------------------------------------------------------*/
   1963 /**
   1964   *  EmptyThisBuffer() This callback is used to send the input buffer to
   1965   *  component
   1966   *
   1967   * @param pComponent       handle for this instance of the component
   1968 
   1969   * @param pBuffer          buffer to be sent to codec
   1970   *
   1971   * @retval OMX_NoError              Success, ready to roll
   1972   *         OMX_Error_BadParameter   The input parameter pointer is null
   1973   **/
   1974 /*-------------------------------------------------------------------*/
   1975 static OMX_ERRORTYPE VPP_EmptyThisBuffer (OMX_HANDLETYPE pComponent, OMX_BUFFERHEADERTYPE* pBufHdr)
   1976 {
   1977     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1978     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
   1979     VPP_COMPONENT_PRIVATE *pComponentPrivate = NULL;
   1980     OMX_PARAM_PORTDEFINITIONTYPE *portDef = NULL;
   1981     VPP_BUFFERDATA_PROPAGATION* pDataProp = NULL;
   1982     OMX_S16 nRet = 0;
   1983     OMX_U32 nCount = 0;
   1984     OMX_U16 i = 0;
   1985 
   1986     OMX_CHECK_CMD(pComponent, pBufHdr, OMX_TRUE);
   1987 
   1988 
   1989     pComponentPrivate = (VPP_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
   1990 
   1991 #ifdef __PERF_INSTRUMENTATION__
   1992     PERF_ReceivedFrame(pComponentPrivate->pPERF,
   1993         pBufHdr->pBuffer,
   1994         pBufHdr->nFilledLen,
   1995         PERF_ModuleHLMM);
   1996 #endif
   1997 
   1998     VPP_DPRINT("VPP: EmptyThisBuffer() %p\n", pBufHdr);
   1999 
   2000     portDef = pBufHdr->pInputPortPrivate;
   2001 
   2002     if (pBufHdr->nInputPortIndex != OMX_VPP_INPUT_PORT &&
   2003             pBufHdr->nInputPortIndex != OMX_VPP_INPUT_OVERLAY_PORT) {
   2004         VPP_DPRINT("Error ! Incorrect input port index\n");
   2005         eError = OMX_ErrorBadPortIndex;
   2006         goto EXIT;
   2007     }
   2008 
   2009     if (pComponentPrivate->curState != OMX_StateExecuting && pComponentPrivate->curState != OMX_StatePause) {
   2010         eError = OMX_ErrorIncorrectStateOperation;
   2011         VPP_DPRINT("VPP: Incorrect state. state = %d\n", pComponentPrivate->curState);
   2012         goto EXIT;
   2013     }
   2014     if(pBufHdr->nInputPortIndex == OMX_VPP_INPUT_PORT &&
   2015             !pComponentPrivate->sCompPorts[OMX_VPP_INPUT_PORT].pPortDef.bEnabled){
   2016         VPP_DPRINT("Error (in VPP)! OMX_ErrorIncorrectStateOperation, %d\n", pComponentPrivate->curState);
   2017         eError = OMX_ErrorIncorrectStateOperation;
   2018         goto EXIT;
   2019     }
   2020     else if(pBufHdr->nInputPortIndex == OMX_VPP_INPUT_OVERLAY_PORT &&
   2021             !pComponentPrivate->sCompPorts[OMX_VPP_INPUT_OVERLAY_PORT].pPortDef.bEnabled){
   2022         VPP_DPRINT("Error (in VPP)! OMX_ErrorIncorrectStateOperation, %d\n", pComponentPrivate->curState);
   2023         eError = OMX_ErrorIncorrectStateOperation;
   2024         goto EXIT;
   2025     }
   2026 
   2027     if (pBufHdr->nSize != sizeof(OMX_BUFFERHEADERTYPE)) {
   2028         eError = OMX_ErrorBadParameter;
   2029         goto EXIT;
   2030     }
   2031     if ((pBufHdr->nVersion.s.nVersionMajor != VPP_MAJOR_VER) ||
   2032             (pBufHdr->nVersion.s.nVersionMinor != VPP_MINOR_VER) ||
   2033             (pBufHdr->nVersion.s.nRevision != VPP_REVISION) ||
   2034             (pBufHdr->nVersion.s.nStep != VPP_STEP)) {
   2035         eError = OMX_ErrorVersionMismatch;
   2036         goto EXIT;
   2037     }
   2038 
   2039     eError = VPP_IsValidBuffer(pBufHdr, pComponentPrivate, portDef->nPortIndex, &nCount);
   2040     if (eError !=OMX_ErrorNone) {
   2041         goto EXIT;
   2042     }
   2043 
   2044 	if (pComponentPrivate->toState == OMX_StateIdle && pComponentPrivate->curState == OMX_StateExecuting) {
   2045 		if(pComponentPrivate->sCompPorts[pBufHdr->nInputPortIndex].hTunnelComponent == NULL){
   2046 			VPP_DPRINT("Not right state, return buf %p\n", pBufHdr);
   2047 		        pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
   2048 	                                    pComponentPrivate->pHandle->pApplicationPrivate,
   2049 	                                    pBufHdr
   2050 	                                    );
   2051 			goto EXIT;
   2052 		}
   2053 		else{
   2054           if(pComponentPrivate->sCompPorts[portDef->nPortIndex].eSupplierSetting == OMX_BufferSupplyOutput){
   2055             pComponentPrivate->sCompPorts[portDef->nPortIndex].pVPPBufHeader[nCount].eBufferOwner = VPP_BUFFER_TUNNEL_COMPONENT;
   2056             VPP_DPRINT("VPP:: call to OMX_FillThisBuffer():: %d\n", __LINE__);
   2057 			eError = OMX_FillThisBuffer(
   2058 				pComponentPrivate->sCompPorts[pBufHdr->nInputPortIndex].hTunnelComponent,
   2059                             pBufHdr);
   2060         }
   2061         else{
   2062             pComponentPrivate->sCompPorts[portDef->nPortIndex].pVPPBufHeader[nCount].eBufferOwner = VPP_BUFFER_COMPONENT_IN;
   2063         }
   2064 			goto EXIT;
   2065 		}
   2066 	}
   2067 
   2068         /*usmc  VPP-JPEG TUNNELING*/
   2069     if((pComponentPrivate->bIsStopping == OMX_TRUE) &&
   2070             (!pComponentPrivate->sCompPorts[OMX_VPP_INPUT_PORT].hTunnelComponent)) {
   2071         pComponentPrivate->sCompPorts[OMX_VPP_INPUT_PORT].nReturnedBufferCount--;
   2072         goto EXIT;
   2073     }/*USMC VPP-JPEG TUNNELING*/
   2074 
   2075 
   2076     if(pBufHdr->nInputPortIndex == OMX_VPP_INPUT_PORT){
   2077         pComponentPrivate->nInputFrame ++;
   2078     }
   2079     else{
   2080         pComponentPrivate->nOverlayFrame ++;
   2081     }
   2082 
   2083     if(pComponentPrivate->nInputFrame != pComponentPrivate->nOverlayFrame){
   2084         if(pComponentPrivate->IsYUVdataout){
   2085             pComponentPrivate->nInYUVBufferCount ++;
   2086         }
   2087         if(pComponentPrivate->IsRGBdataout){
   2088             pComponentPrivate->nInRGBBufferCount ++;
   2089         }
   2090     }
   2091 
   2092 
   2093     VPP_DPRINT("nInBufferCount %d, nInRGBBufferCount %d:: InputCount= %d, OverlayCount= %d\n ", pComponentPrivate->nInYUVBufferCount, pComponentPrivate->nInRGBBufferCount, pComponentPrivate->nInputFrame, pComponentPrivate->nOverlayFrame);
   2094    if(pBufHdr->pMarkData == NULL){
   2095         pBufHdr->pMarkData = pComponentPrivate->pMarkData;
   2096         pBufHdr->hMarkTargetComponent = pComponentPrivate->hMarkTargetComponent;
   2097         pComponentPrivate->pMarkData = NULL;
   2098         pComponentPrivate->hMarkTargetComponent = NULL;
   2099     }
   2100 
   2101     if ((pBufHdr->nFlags) || (pBufHdr->pMarkData) || (pBufHdr->nTickCount) || (pBufHdr->nTimeStamp)){
   2102 #ifdef  VPP_DEBUG
   2103         if(pBufHdr->nInputPortIndex == OMX_VPP_INPUT_PORT){
   2104             VPP_DPRINT("OMX_VPP_INPUT_PORT\n");
   2105         }
   2106         else{
   2107             VPP_DPRINT("OMX_VPP_OVERLAY_PORT\n");
   2108         }
   2109         if(pBufHdr->nFlags & OMX_BUFFERFLAG_EOS){
   2110             VPP_DPRINT("END OF STREAM DETECTED EmptyThis buffer\n");
   2111         }
   2112         if(pBufHdr->pMarkData){
   2113             VPP_DPRINT("\nMarkDataDetected\n");
   2114         }
   2115         if((pBufHdr->nTickCount) || (pBufHdr->nTimeStamp)){
   2116             VPP_DPRINT("\n nTickCount= %d,   nTimeStamp = %d\n\n", pBufHdr->nTickCount, pBufHdr->nTimeStamp);
   2117         }
   2118 #endif
   2119 
   2120         for (i = 0; i < pComponentPrivate->sCompPorts[pBufHdr->nInputPortIndex].pPortDef.nBufferCountActual; i ++) {
   2121             pDataProp = &(pComponentPrivate->sCompPorts[pBufHdr->nInputPortIndex].sBufferDataProp[i]);
   2122             if (pDataProp->buffer_idYUV == 0xFFFFFFFF && pDataProp->buffer_idRGB == 0xFFFFFFFF) {
   2123                 pDataProp->flag = pBufHdr->nFlags;
   2124                 if(pComponentPrivate->IsYUVdataout){
   2125                     pDataProp->buffer_idYUV= pComponentPrivate->nInYUVBufferCount;
   2126                 }
   2127                 if(pComponentPrivate->IsRGBdataout){
   2128                     pDataProp->buffer_idRGB= pComponentPrivate->nInRGBBufferCount;
   2129                 }
   2130                 VPP_DPRINT("Record buff in array[%d] buffer_idYUV = %d, buffer_idRGB = %d\n, nFlags= %x", i, pDataProp->buffer_idYUV, pComponentPrivate->nInRGBBufferCount, pDataProp->flag);
   2131                  /* mark the first buffer from input port after receiving mark buffer command */
   2132                  if (pBufHdr->pMarkData) {
   2133                     VPP_DPRINT("Get mark buffer command, mark buffer %p\n", pBufHdr);
   2134                     pDataProp->pMarkData = pBufHdr->pMarkData;
   2135                     pDataProp->hMarkTargetComponent = pBufHdr->hMarkTargetComponent;
   2136                 }
   2137                  if((pBufHdr->nTickCount) || (pBufHdr->nTimeStamp)){
   2138                     printf("Record TimeStamp= %Ld & nTickCount =%ld\n", pBufHdr->nTimeStamp, pBufHdr->nTickCount);
   2139                     pDataProp->nTickCount = pBufHdr->nTickCount;
   2140                     pDataProp->nTimeStamp = pBufHdr->nTimeStamp;
   2141                  }
   2142                 break;
   2143             }
   2144         }
   2145     }
   2146 
   2147     pComponentPrivate->sCompPorts[portDef->nPortIndex].pVPPBufHeader[nCount].pBufHeader->pBuffer = pBufHdr->pBuffer; /*Updating pBuffer*/
   2148     pComponentPrivate->sCompPorts[portDef->nPortIndex].pVPPBufHeader[nCount].bHolding = OMX_TRUE;
   2149 
   2150     VPP_DPRINT("\n------------------------------------------\n\n");
   2151     VPP_DPRINT ("%d :: Component Sending Filled ip buff %p \
   2152                         to Component Thread\n",pBufHdr->nInputPortIndex, pBufHdr);
   2153     VPP_DPRINT("\n------------------------------------------\n\n");
   2154 
   2155 #if 0
   2156     FILE *fp;
   2157 
   2158     fp = fopen("mytestcvnew.raw", "w");
   2159     fwrite(pBufHdr->pBuffer, 1, pBufHdr->nFilledLen, fp);
   2160     fclose(fp);
   2161 #endif
   2162 
   2163     VPP_DPRINT("VPP get %d bytes of data from %p\n", pBufHdr->nFilledLen, pBufHdr->pBuffer);
   2164 
   2165     pComponentPrivate->sCompPorts[portDef->nPortIndex].pVPPBufHeader[nCount].eBufferOwner = VPP_BUFFER_COMPONENT_IN;
   2166     nRet = write(pComponentPrivate->nFilled_iPipe[1],&pBufHdr, sizeof(OMX_BUFFERHEADERTYPE*));
   2167 
   2168     if (nRet == -1) {
   2169         eError = OMX_ErrorHardware;
   2170         goto EXIT;
   2171     }
   2172 
   2173 EXIT:
   2174     return eError;
   2175 }
   2176 
   2177 /*-------------------------------------------------------------------*/
   2178 /**
   2179   *  FillThisBuffer() This callback is used to send the output buffer to
   2180   *  the component
   2181   *
   2182   * @param pComponent    handle for this instance of the component
   2183   * @param nPortIndex    output port number
   2184   * @param pBufferHdr       buffer to be sent to codec
   2185   *
   2186   * @retval OMX_NoError              Success, ready to roll
   2187   *         OMX_Error_BadParameter   The input parameter pointer is null
   2188   **/
   2189 /*-------------------------------------------------------------------*/
   2190 static OMX_ERRORTYPE VPP_FillThisBuffer (OMX_HANDLETYPE pComponent,
   2191                                          OMX_BUFFERHEADERTYPE* pBufferHdr)
   2192 {
   2193     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2194     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
   2195     VPP_COMPONENT_PRIVATE *pComponentPrivate = NULL;
   2196     OMX_PARAM_PORTDEFINITIONTYPE *portDef = NULL;
   2197     int nRet = 0;
   2198     OMX_U32 nCount = 0;
   2199 
   2200 
   2201     OMX_CHECK_CMD(pComponent, pBufferHdr, OMX_TRUE);
   2202 
   2203     VPP_DPRINT("\n------------------------------------------\n\n");
   2204     VPP_DPRINT ("%d :: Component Sending Emptied op buff %p \
   2205                             to Component Thread\n",__LINE__,pBufferHdr);
   2206     VPP_DPRINT("\n------------------------------------------\n\n");
   2207 
   2208 	VPP_DPRINT("get output buffer %p (%p %p)\n", pBufferHdr, pBufferHdr->hMarkTargetComponent, pBufferHdr->pMarkData);
   2209 
   2210     pComponentPrivate = (VPP_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
   2211     portDef = pBufferHdr->pOutputPortPrivate;
   2212 
   2213 #ifdef __PERF_INSTRUMENTATION__
   2214     PERF_ReceivedFrame(pComponentPrivate->pPERF,
   2215         pBufferHdr->pBuffer,
   2216         0,
   2217         PERF_ModuleHLMM);
   2218 #endif
   2219 
   2220     if (pBufferHdr->nOutputPortIndex != OMX_VPP_YUV_OUTPUT_PORT &&
   2221             pBufferHdr->nOutputPortIndex != OMX_VPP_RGB_OUTPUT_PORT) {
   2222         VPP_DPRINT("Error ! Incorrect output port index\n");
   2223         eError = OMX_ErrorBadPortIndex;
   2224         goto EXIT;
   2225     }
   2226 
   2227     if (pComponentPrivate->curState != OMX_StateExecuting &&
   2228                 pComponentPrivate->curState != OMX_StatePause &&
   2229                 pComponentPrivate->curState != OMX_StateIdle) {
   2230         VPP_DPRINT("Error (in VPP)! OMX_ErrorIncorrectStateOperation, %d\n", pComponentPrivate->curState);
   2231         eError = OMX_ErrorIncorrectStateOperation;
   2232         goto EXIT;
   2233     }
   2234 
   2235     if(pBufferHdr->nOutputPortIndex == OMX_VPP_YUV_OUTPUT_PORT &&
   2236             !pComponentPrivate->sCompPorts[OMX_VPP_YUV_OUTPUT_PORT].pPortDef.bEnabled){
   2237         VPP_DPRINT("Error (in VPP)! OMX_ErrorIncorrectStateOperation, %d\n", pComponentPrivate->curState);
   2238         eError = OMX_ErrorIncorrectStateOperation;
   2239         goto EXIT;
   2240     }
   2241     else if(pBufferHdr->nOutputPortIndex == OMX_VPP_RGB_OUTPUT_PORT &&
   2242             !pComponentPrivate->sCompPorts[OMX_VPP_RGB_OUTPUT_PORT].pPortDef.bEnabled){
   2243         VPP_DPRINT("Error (in VPP)! OMX_ErrorIncorrectStateOperation, %d\n", pComponentPrivate->curState);
   2244         eError = OMX_ErrorIncorrectStateOperation;
   2245         goto EXIT;
   2246     }
   2247 
   2248 
   2249     if (pBufferHdr->nSize != sizeof(OMX_BUFFERHEADERTYPE)) {
   2250         VPP_DPRINT("Error ! OMX_ErrorBadParameter\n");
   2251         eError = OMX_ErrorBadParameter;
   2252         goto EXIT;
   2253     }
   2254 
   2255     if ((pBufferHdr->nVersion.s.nVersionMajor != VPP_MAJOR_VER) ||
   2256             (pBufferHdr->nVersion.s.nVersionMinor != VPP_MINOR_VER) ||
   2257             (pBufferHdr->nVersion.s.nRevision != VPP_REVISION) ||
   2258             (pBufferHdr->nVersion.s.nStep != VPP_STEP)) {
   2259         eError = OMX_ErrorVersionMismatch;
   2260         goto EXIT;
   2261     }
   2262 
   2263     if ((pComponentPrivate->toState == OMX_StateIdle) && (pComponentPrivate->curState == OMX_StateExecuting || pComponentPrivate->curState == OMX_StatePause)) {
   2264         VPP_DPRINT("VPP::to state is IDLE, return buf %p\n", pBufferHdr);
   2265         if(pComponentPrivate->sCompPorts[portDef->nPortIndex].eSupplierSetting == OMX_BufferSupplyOutput){
   2266                 pComponentPrivate->sCompPorts[portDef->nPortIndex].pVPPBufHeader[nCount].eBufferOwner = VPP_BUFFER_COMPONENT_IN;
   2267         }
   2268         else{
   2269             pComponentPrivate->sCompPorts[portDef->nPortIndex].pVPPBufHeader[nCount].eBufferOwner = VPP_BUFFER_CLIENT;
   2270             pComponentPrivate->cbInfo.FillBufferDone(pComponentPrivate->pHandle,
   2271                     pComponentPrivate->pHandle->pApplicationPrivate,
   2272                     pBufferHdr);
   2273         }
   2274         goto EXIT;
   2275     }
   2276 
   2277     pBufferHdr->nFilledLen = 0;
   2278 
   2279     eError = VPP_IsValidBuffer(pBufferHdr,pComponentPrivate,portDef->nPortIndex, &nCount);
   2280     if ( eError !=OMX_ErrorNone) {
   2281         goto EXIT;
   2282     }
   2283 
   2284     pComponentPrivate->sCompPorts[portDef->nPortIndex].pVPPBufHeader[nCount].pBufHeader->pBuffer = pBufferHdr->pBuffer; /*Updating pBuffer*/
   2285     pComponentPrivate->sCompPorts[portDef->nPortIndex].pVPPBufHeader[nCount].bHolding = OMX_TRUE;
   2286     VPP_DPRINT("VPP: fillthisbuffer: (%p) %d %d %d\n", pBufferHdr, portDef->nPortIndex, nCount, pComponentPrivate->sCompPorts[portDef->nPortIndex].pVPPBufHeader[nCount].bHolding);
   2287 
   2288     pBufferHdr->nFilledLen = 0;
   2289     VPP_DPRINT ("%d :: Component Sending Emptied op buff  with index %d \
   2290                             to Component Thread\n",__LINE__,pBufferHdr->nOutputPortIndex);
   2291 
   2292     pthread_mutex_lock(&pComponentPrivate->buf_mutex);
   2293     pComponentPrivate->sCompPorts[portDef->nPortIndex].pVPPBufHeader[nCount].eBufferOwner = VPP_BUFFER_COMPONENT_IN;
   2294     pthread_mutex_unlock(&pComponentPrivate->buf_mutex);
   2295     nRet = write(pComponentPrivate->nFree_oPipe[1],&pBufferHdr,sizeof(OMX_BUFFERHEADERTYPE*));
   2296 
   2297     if (nRet == -1) {
   2298         VPP_DPRINT ("VPP::%d :: Error in Writing to the Data pipe\n", __LINE__);
   2299         eError = OMX_ErrorHardware;
   2300         goto EXIT;
   2301     }
   2302 
   2303 EXIT:
   2304      return eError;
   2305 }
   2306 
   2307 
   2308 /*-------------------------------------------------------------------*/
   2309 /**
   2310   * OMX_ComponentDeinit() this methold will de init the component
   2311   *
   2312   * @param pComp         handle for this instance of the component
   2313   *
   2314   * @retval OMX_NoError              Success, ready to roll
   2315   *
   2316   **/
   2317 /*-------------------------------------------------------------------*/
   2318 
   2319 static OMX_ERRORTYPE VPP_ComponentDeInit(OMX_HANDLETYPE pHandle)
   2320 {
   2321     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2322 
   2323     OMX_CHECK_CMD(pHandle, OMX_TRUE, OMX_TRUE);
   2324 
   2325     VPP_DPRINT (" IN ComponentDeInit \n");
   2326 
   2327     VPP_DPRINT ("VPP::Freeing OMX pComponentPrivate \n");
   2328     eError = VPP_Free_ComponentResources(pHandle);
   2329     if (eError != OMX_ErrorNone) {
   2330         VPP_DPRINT ("VPP::Error While Stoping the Component Thread\n");
   2331         goto EXIT;
   2332     }
   2333     VPP_DPRINT ("\n");
   2334 
   2335     /* load the ResourceManagerProxy thread*/
   2336 #ifdef RESOURCE_MANAGER_ENABLED
   2337     eError = RMProxy_NewSendCommand(pHandle, RMProxy_FreeResource, OMX_VPP_COMPONENT, 0, 3456, NULL);
   2338     if (eError != OMX_ErrorNone) {
   2339         VPP_DPRINT ("%d ::Error returned from destroy ResourceManagerProxy thread\n",
   2340         __LINE__);
   2341     }
   2342     eError = RMProxy_DeinitalizeEx(OMX_COMPONENTTYPE_VPP);
   2343     if (eError != OMX_ErrorNone) {
   2344         VPP_DPRINT ("VPP::%d ::Error returned from destroy ResourceManagerProxy thread\n",
   2345         __LINE__);
   2346     }
   2347 #endif
   2348 
   2349 EXIT:
   2350     return eError;
   2351 }
   2352 
   2353 /*-------------------------------------------------------------------*/
   2354 /**
   2355   *  VerifyTunnelConnection()
   2356   *
   2357   *
   2358   *
   2359   *
   2360   * @param
   2361   * @param
   2362   * @param
   2363   *
   2364   * @retval OMX_NoError              Success, ready to roll
   2365   *         OMX_Error_BadParameter   The input parameter pointer is null
   2366   **/
   2367 /*-------------------------------------------------------------------*/
   2368 OMX_ERRORTYPE VPP_VerifyTunnelConnection(VPP_PORT_TYPE *pPort,
   2369                                          OMX_HANDLETYPE hTunneledComp,
   2370                                          OMX_PARAM_PORTDEFINITIONTYPE* pPortDef)
   2371 {
   2372     /* 1.4 Check if input port is compatible with output port */
   2373     OMX_PARAM_PORTDEFINITIONTYPE MyPortDef ;
   2374     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2375 
   2376     OMX_CHECK_CMD(pPort, hTunneledComp, pPortDef);
   2377 
   2378     MyPortDef.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
   2379 
   2380     MyPortDef.nVersion.s.nVersionMajor = VPP_MAJOR_VER;
   2381     MyPortDef.nVersion.s.nVersionMinor = VPP_MINOR_VER;
   2382 
   2383     MyPortDef.nPortIndex = pPort->nTunnelPort;
   2384     eError = OMX_GetParameter(hTunneledComp, OMX_IndexParamPortDefinition, &MyPortDef);
   2385     if (eError != OMX_ErrorNone) {
   2386         VPP_DPRINT("VPP::Error 0x%X\n",eError);
   2387         return eError;
   2388     }
   2389 
   2390     switch(pPortDef->eDomain)
   2391     {
   2392     case OMX_PortDomainOther:
   2393         if (MyPortDef.format.other.eFormat!= pPortDef->format.other.eFormat) {
   2394             pPort->hTunnelComponent  = 0;
   2395             pPort->nTunnelPort       = 0;
   2396             return OMX_ErrorPortsNotCompatible;
   2397         }
   2398         break;
   2399     case OMX_PortDomainAudio:
   2400         if (MyPortDef.format.audio.eEncoding != pPortDef->format.audio.eEncoding) {
   2401             pPort->hTunnelComponent = 0;
   2402             pPort->nTunnelPort      = 0;
   2403             return OMX_ErrorPortsNotCompatible;
   2404         }
   2405         break;
   2406     case OMX_PortDomainVideo:
   2407         VPP_DPRINT("my eColorFormat is %d, partner is %d\n",
   2408         MyPortDef.format.video.eColorFormat,
   2409         pPortDef->format.video.eColorFormat);
   2410         /* The program should check the colorformat for tunneled components as the code shown here.
   2411         * However, because of big-endian/little-endian issue, we just ignore the format checking
   2412         * as this moment
   2413         if (MyPortDef.format.video.eColorFormat != pPortDef->format.video.eColorFormat)
   2414         {
   2415             pPort->hTunnelComponent = 0;
   2416             pPort->nTunnelPort      = 0;
   2417             return OMX_ErrorPortsNotCompatible;
   2418         }
   2419         */
   2420         break;
   2421     case OMX_PortDomainImage:
   2422         if (MyPortDef.format.image.eCompressionFormat != pPortDef->format.image.eCompressionFormat) {
   2423             pPort->hTunnelComponent = 0;
   2424             pPort->nTunnelPort      = 0;
   2425             return OMX_ErrorPortsNotCompatible;
   2426         }
   2427         break;
   2428     default:
   2429         pPort->hTunnelComponent     = 0;
   2430         pPort->nTunnelPort          = 0;
   2431         return OMX_ErrorPortsNotCompatible; /* Our current port is not set up correctly */
   2432     }
   2433 EXIT:
   2434     return eError;
   2435 }
   2436 
   2437 /*-------------------------------------------------------------------*/
   2438 /**
   2439   *  ComponentTunnelRequest() this method is not implemented in 1.5
   2440   *
   2441   * This method will update application callbacks
   2442   * the application.
   2443   *
   2444   * @param pComp         handle for this instance of the component
   2445   * @param pCallBacks    application callbacks
   2446   * @param ptr
   2447   *
   2448   * @retval OMX_NoError              Success, ready to roll
   2449   *         OMX_ErrorNotImplemented
   2450   **/
   2451 /*-------------------------------------------------------------------*/
   2452 static OMX_ERRORTYPE VPP_ComponentTunnelRequest (OMX_HANDLETYPE hComponent,
   2453                                                  OMX_U32 nPort,
   2454                                                  OMX_HANDLETYPE hTunneledComp,
   2455                                                  OMX_U32 nTunneledPort,
   2456                                                  OMX_INOUT  OMX_TUNNELSETUPTYPE* pTunnelSetup)
   2457 {
   2458     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2459     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)hComponent;
   2460     VPP_COMPONENT_PRIVATE *pComponentPrivate = NULL;
   2461     OMX_PARAM_BUFFERSUPPLIERTYPE sBufferSupplier;
   2462     VPP_PORT_TYPE *pPort = NULL;
   2463 
   2464     OMX_CHECK_CMD(hComponent, OMX_TRUE, OMX_TRUE);
   2465 
   2466     pComponentPrivate = (VPP_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
   2467     pPort = &(pComponentPrivate->sCompPorts[nPort]);
   2468 
   2469     if (pTunnelSetup == NULL || hTunneledComp == 0) {
   2470         /* cancel previous tunnel */
   2471         pPort->hTunnelComponent = 0;
   2472         pPort->nTunnelPort = 0;
   2473         pPort->eSupplierSetting = OMX_BufferSupplyUnspecified;
   2474         eError = OMX_ErrorNone;
   2475         goto EXIT;
   2476     }
   2477 
   2478     if (pComponentPrivate->sCompPorts[nPort].pPortDef.eDir != OMX_DirInput &&
   2479             pComponentPrivate->sCompPorts[nPort].pPortDef.eDir != OMX_DirOutput) {
   2480         eError = OMX_ErrorBadParameter;
   2481         goto EXIT;
   2482     }
   2483 
   2484     /* Check if the other component is developed by TI */
   2485     if(IsTIOMXComponent(hTunneledComp) != OMX_TRUE) {
   2486         VPP_DPRINT("OMX_ErrorTunnelingUnsupported\n");
   2487         eError = OMX_ErrorTunnelingUnsupported;
   2488         goto EXIT;
   2489     }
   2490 
   2491     pPort->hTunnelComponent = hTunneledComp;
   2492     pPort->nTunnelPort      = nTunneledPort;
   2493     VPP_DPRINT("VPP comp = %x, tunneled comp = %x\n",(int)hComponent, (int)pPort->hTunnelComponent);
   2494 
   2495     if (pComponentPrivate->sCompPorts[nPort].pPortDef.eDir == OMX_DirOutput) {
   2496         /* Component is the output (source of data) */
   2497         pTunnelSetup->eSupplier = pPort->eSupplierSetting;
   2498         VPP_DPRINT("VPP:: set output port supplier as OMX_BufferSupplyInput\n");
   2499     }
   2500     else { /* Component is the input (sink of data) */
   2501         eError = VPP_VerifyTunnelConnection(pPort, hTunneledComp, &pComponentPrivate->sCompPorts[nPort].pPortDef);
   2502         if (OMX_ErrorNone != eError) {
   2503             VPP_DPRINT(" Error !! VPP VerifyTunnelConnection failed\n");
   2504             /* Invalid connection formats. Return eError */
   2505             return OMX_ErrorPortsNotCompatible;
   2506         }
   2507         /* If specified obey output port's preferences. Otherwise choose output */
   2508         pPort->eSupplierSetting = pTunnelSetup->eSupplier;
   2509         if (OMX_BufferSupplyUnspecified == pPort->eSupplierSetting) {
   2510             pPort->eSupplierSetting = pTunnelSetup->eSupplier = OMX_BufferSupplyOutput;
   2511         }
   2512 
   2513         /* Tell the output port who the supplier is */
   2514         sBufferSupplier.nSize = sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE);
   2515 
   2516         sBufferSupplier.nVersion.s.nVersionMajor = VPP_MAJOR_VER;
   2517         sBufferSupplier.nVersion.s.nVersionMinor = VPP_MINOR_VER ;
   2518 
   2519         sBufferSupplier.nPortIndex      = nTunneledPort;
   2520         sBufferSupplier.eBufferSupplier = pPort->eSupplierSetting;
   2521         eError = OMX_SetParameter(hTunneledComp, OMX_IndexParamCompBufferSupplier, &sBufferSupplier);
   2522         if(eError != OMX_ErrorNone){
   2523             goto EXIT;
   2524         }
   2525     }
   2526 EXIT:
   2527     return eError;
   2528 }
   2529 
   2530 /*-------------------------------------------------------------------*/
   2531 /**
   2532   * VPP_GetExtensionIndex()
   2533   *
   2534   * Free a video driver buffer.
   2535   *
   2536   * @retval OMX_ErrorNone                    Successful operation.
   2537   *         OMX_ErrorBadParameter            Invalid operation.
   2538   *         OMX_ErrorIncorrectStateOperation If called when port is disabled.
   2539   **/
   2540 /*-------------------------------------------------------------------*/
   2541 OMX_ERRORTYPE VPP_GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent, OMX_IN OMX_STRING cParameterName, OMX_OUT OMX_INDEXTYPE* pIndexType)
   2542 {
   2543     int nIndex;
   2544     OMX_ERRORTYPE eError = OMX_ErrorUndefined;
   2545     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComponent;
   2546     VPP_COMPONENT_PRIVATE* pComponentPrivate = NULL;
   2547 
   2548     /* Check parameter validity */
   2549     if (!pHandle) {
   2550         eError = OMX_ErrorBadParameter;
   2551         goto EXIT;
   2552     }
   2553 
   2554     pComponentPrivate = (VPP_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
   2555 
   2556     if (!pComponentPrivate) {
   2557         eError = OMX_ErrorBadParameter;
   2558         goto EXIT;
   2559     }
   2560 
   2561     for (nIndex = 0; nIndex < VPP_NUM_CUSTOM_PARAMS; nIndex++) {
   2562         if (!strcmp((const char *)cParameterName, (const char *)(&(sVPPCustomParams[nIndex].cCustomParamName)))) {
   2563             *pIndexType = sVPPCustomParams[nIndex].nCustomParamIndex;
   2564             eError = OMX_ErrorNone;
   2565             break;
   2566         }
   2567     }
   2568 EXIT:
   2569     return eError;
   2570 }
   2571 
   2572 /*-------------------------------------------------------------------*/
   2573 /**
   2574   *  ComponentRoleEnum()
   2575   *
   2576   *
   2577   *
   2578   *
   2579   * @param
   2580   * @param
   2581   * @param
   2582   *
   2583   * @retval OMX_NoError              Success, ready to roll
   2584   *
   2585   **/
   2586 /*-------------------------------------------------------------------*/
   2587 #ifdef KHRONOS_1_1
   2588 
   2589 static OMX_ERRORTYPE ComponentRoleEnum(
   2590         OMX_IN OMX_HANDLETYPE hComponent,
   2591                 OMX_OUT OMX_U8 *cRole,
   2592                 OMX_IN OMX_U32 nIndex)
   2593 {
   2594     VPP_COMPONENT_PRIVATE *pComponentPrivate = NULL;
   2595     OMX_U8 *pTemp = NULL;
   2596     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2597     pComponentPrivate = (VPP_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
   2598 
   2599     if(nIndex == 0){
   2600         pTemp = memcpy(cRole, &(pComponentPrivate->componentRole.cRole), sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE - 1);
   2601         if(pTemp == NULL){
   2602             eError = OMX_ErrorUndefined;
   2603             goto EXIT;
   2604         }
   2605     }
   2606     else {
   2607       eError = OMX_ErrorNoMore;
   2608         }
   2609 
   2610 EXIT:
   2611     return eError;
   2612 }
   2613 #endif
   2614 
   2615