Home | History | Annotate | Download | only in tests
      1 
      2 /*
      3  *  Copyright 2001-2008 Texas Instruments - http://www.ti.com/
      4  *
      5  *  Licensed under the Apache License, Version 2.0 (the "License");
      6  *  you may not use this file except in compliance with the License.
      7  *  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 #ifdef UNDER_CE
     18 #include <windows.h>
     19 #include <oaf_osal.h>
     20 #else
     21 #include <unistd.h>
     22 #include <sys/ioctl.h>
     23 #include <sys/select.h>
     24 #include <fcntl.h>
     25 #include <errno.h>
     26 #include <linux/vt.h>
     27 #include <signal.h>
     28 #include <sys/stat.h>
     29 #include <sys/time.h>
     30 #include <time.h>
     31 #endif
     32 
     33 #include <stdlib.h>
     34 #include <string.h>
     35 #include <stdio.h>
     36 #include <pthread.h>
     37 #include <OMX_Index.h>
     38 #include <OMX_Types.h>
     39 #include <OMX_Core.h>
     40 #include <OMX_Audio.h>
     41 #include <OMX_VPP.h>
     42 #include <OMX_IVCommon.h>
     43 #include <OMX_Component.h>
     44 #include "VPPTest.h"
     45 #include <signal.h>
     46 
     47 /* DSP recovery includes */
     48 #include <qosregistry.h>
     49 #include <qosti.h>
     50 #include <dbapi.h>
     51 #include <DSPManager.h>
     52 #include <DSPProcessor.h>
     53 #include <DSPProcessor_OEM.h>
     54 
     55 #define KHRONOS_1_2
     56 
     57 
     58 #ifdef UNDER_CE
     59 #define sleep Sleep
     60 #define APP_DPRINT printf
     61 #else
     62 /*#define APP_DEBUG*/
     63 
     64 #ifdef  APP_DEBUG
     65         #define APP_DPRINT(...)    fprintf(stderr,__VA_ARGS__)
     66 #else
     67         #define APP_DPRINT(...)
     68 #endif
     69 #endif //#ifdef UNDER_CE
     70 
     71 #ifdef UNDER_CE
     72 int fill_data (OMX_BUFFERHEADERTYPE *pBuf, HANDLE fIn);
     73 #else
     74 int fill_data (OMX_BUFFERHEADERTYPE *pBuf, FILE *fIn);
     75 #endif
     76 
     77 #define DEFAULT_WIDTH      (176)
     78 #define DEFAULT_HEIGHT     (144)
     79 
     80 
     81 typedef struct _OMX_VPPCustomTYPE
     82 {
     83     OMX_INDEXTYPE VPPCustomSetZoomFactor;
     84     OMX_INDEXTYPE VPPCustomSetZoomLimit;
     85     OMX_INDEXTYPE VPPCustomSetZoomSpeed;
     86     OMX_INDEXTYPE VPPCustomSetZoomXoffsetFromCenter16;
     87     OMX_INDEXTYPE VPPCustomSetZoomYoffsetFromCenter16;
     88     OMX_INDEXTYPE VPPCustomSetFrostedGlassOvly;
     89     OMX_INDEXTYPE VPPCustomSetColorRange;
     90     OMX_INDEXTYPE VPP_CustomRGB4ColorFormat;
     91 } OMX_VPPCustomTYPE;
     92 
     93 typedef struct EVENT_PRIVATE {
     94     OMX_EVENTTYPE eEvent;
     95     OMX_U32 nData1;
     96     OMX_U32 nData2;
     97     OMX_PTR pAppData;
     98     OMX_PTR eInfo;
     99 } EVENT_PRIVATE;
    100 static OMX_ERRORTYPE VPP_SetZoom(OMX_HANDLETYPE pHandle, int speed, int factor, int limit, int xoff, int yoff);
    101 static OMX_ERRORTYPE VPP_SetContrast(OMX_HANDLETYPE pHandle, int Contrast);
    102 static OMX_ERRORTYPE VPP_FrostedGlassEffect(OMX_HANDLETYPE pHandle, int IsOverlay);
    103 static OMX_ERRORTYPE VPP_SetCrop(OMX_HANDLETYPE pHandle, int XStart, int XSize, int YStart, int YSize);
    104 static OMX_ERRORTYPE VPP_SetMirroring(OMX_HANDLETYPE pHandle, int IsRGBOutput);
    105 static OMX_ERRORTYPE VPP_SetRotationAngle(OMX_HANDLETYPE pHandle, int IsRGBOutput,int Angle);
    106 static OMX_ERRORTYPE VPP_SetDithering(OMX_HANDLETYPE pHandle, int IsRGBOutput);
    107 static OMX_ERRORTYPE VPP_SetColorRange(OMX_HANDLETYPE pHandle, int nColorRange);
    108 OMX_BOOL VPP_Test_Check_Frames(int YUVRGB, int inFrames, int OvlyFrames,int outRGBFrames,int outYUVFrames);
    109 
    110 #ifdef DSP_MMU_FAULT_HANDLING
    111 int LoadBaseImage();
    112 #endif
    113 
    114 #ifdef UNDER_CE
    115 OMX_STRING strAmrDecoder = "OMX.TI.IMAGE.VGPOP";
    116 #else
    117 OMX_STRING strAmrDecoder = "OMX.TI.VPP";
    118 #endif
    119 
    120 int IpBuf_Pipe[2];
    121 int OvlyBuf_Pipe[2];
    122 int OpRGBBuf_Pipe[2];
    123 int OpYUVBuf_Pipe[2];
    124 int Event_Pipe[2];
    125 int nRGBFillBufferDones=0;
    126 int nYUVFillBufferDones=0;
    127 int nInputEmptyBufferDones=0;
    128 int nOvlyEmptyBufferDones=0;
    129 
    130 /* Error flag */
    131 OMX_BOOL bError = OMX_FALSE;
    132 
    133 #ifndef UNDER_CE
    134     struct timeval base;
    135     struct timeval newer;
    136     /*struct timezone tz;*/
    137 #endif //#ifndef UNDER_CE
    138 
    139 
    140 static COMPONENT_PORTINDEX_DEF MyVppPortDef;
    141 static OMX_VPPCustomTYPE MyVPPCustomDef;
    142 
    143 static long int nTotalTime = 0;
    144 
    145 
    146 /* safe routine to get the maximum of 2 integers */
    147 int maxint(int a, int b)
    148 {
    149          return (a>b) ? a : b;
    150 }
    151 
    152 /* This method will wait for the component to get to the state
    153 * specified by the DesiredState input. */
    154 static OMX_ERRORTYPE WaitForState(OMX_HANDLETYPE* pHandle, OMX_STATETYPE DesiredState)
    155 {
    156     OMX_STATETYPE CurState = OMX_StateInvalid;
    157     OMX_ERRORTYPE eError = OMX_ErrorNone;
    158     int nCnt = 0;
    159     OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
    160 
    161     eError = pComponent->GetState(pHandle, &CurState);
    162     while( (eError == OMX_ErrorNone) &&
    163     (CurState != DesiredState) && (CurState != OMX_StateInvalid)) {
    164     sched_yield();
    165     if ( nCnt++ >= 0xFFFFFFFE ) {
    166         fprintf(stderr, "VPPTEST:: Press CTL-C to continue\n");
    167     }
    168         eError = pComponent->GetState(pHandle, &CurState);
    169     }
    170 
    171     if (CurState == OMX_StateInvalid && DesiredState != OMX_StateInvalid){
    172         eError = OMX_ErrorInvalidState;
    173     }
    174     return eError;
    175 }
    176 
    177 void EventHandler(OMX_HANDLETYPE hComponent,OMX_PTR pAppData, OMX_EVENTTYPE eEvent,
    178 OMX_U32 nData1,OMX_U32 nData2, OMX_STRING eInfo)
    179 {
    180 
    181     OMX_ERRORTYPE eError = OMX_ErrorNone;
    182     EVENT_PRIVATE MyEvent;
    183 
    184     MyEvent.eEvent = eEvent;
    185     MyEvent.nData1 = nData1;
    186     MyEvent.nData2 = nData2;
    187     MyEvent.pAppData = pAppData;
    188 
    189     switch (eEvent) {
    190         case OMX_EventCmdComplete:
    191             APP_DPRINT ("%d :: App: Component State Changed To %d\n", __LINE__,state);
    192 
    193             break;
    194         case OMX_EventError:
    195             if(nData1 == OMX_ErrorHardware){
    196                 printf("%d: App: ErrorNotofication Came: \
    197                             \nComponent Name : %d : Error Num %lx: String :%s\n",
    198                 __LINE__,*((int *)(pAppData)), nData1, eInfo);
    199                 eError = OMX_SendCommand(hComponent, OMX_CommandStateSet, OMX_StateInvalid, NULL);
    200                 if(eError != OMX_ErrorNone) {
    201                     printf ("Error from SendCommand-Invalid State function\n");
    202                 }
    203             }
    204             else{
    205                 printf("%d: App: ErrorNotofication Came: \
    206                             \nComponent Name : %d : Error Num %lx: String :%s\n",
    207                             __LINE__,*((int *)(pAppData)), nData1, eInfo);
    208             }
    209 
    210             break;
    211         case OMX_EventMax:
    212             break;
    213         case OMX_EventMark:
    214             break;
    215         default:
    216             break;
    217     }
    218 
    219     write(Event_Pipe[1], &MyEvent, sizeof(EVENT_PRIVATE));
    220 
    221 }
    222 
    223 #ifndef UNDER_CE
    224 long GetProfiletime()
    225 {
    226     long int nFrameTime = 0;
    227     /*struct timeval older;*/
    228     int nStatus ;
    229     base.tv_sec = newer.tv_sec;
    230     base.tv_usec = newer.tv_usec;
    231     nStatus = gettimeofday(&newer, NULL);
    232     /*printf("base.tv_sec = %ld, base.tv_usec %ld\n", base.tv_sec, base.tv_usec);*/
    233     nFrameTime = (newer.tv_sec-base.tv_sec) * 1000000 + (newer.tv_usec-base.tv_usec);
    234     nTotalTime = nTotalTime + nFrameTime;
    235     return nFrameTime;
    236 
    237 }
    238 #endif /*#ifndef UNDER_CE*/
    239 
    240 void FillBufferDone (OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer)
    241 {
    242 
    243     /*PROFILE POINT*/
    244 
    245 #ifndef UNDER_CE
    246     long int pftime = 0;
    247     pftime = GetProfiletime();
    248     APP_DPRINT("total time for frame %d \n", nTotalTime);
    249     APP_DPRINT("total time for each frame %d \n",pftime);
    250 #endif
    251 
    252     if(pBuffer->nOutputPortIndex==MyVppPortDef.rgboutput_port){
    253           write(OpRGBBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
    254           nRGBFillBufferDones++;
    255     }
    256     else if(pBuffer->nOutputPortIndex==MyVppPortDef.yuvoutput_port){
    257           write(OpYUVBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
    258           nYUVFillBufferDones++;
    259     }
    260     else{
    261         printf("VPPTEST:: Incorrect Output Port Index\n");
    262     }
    263 
    264 
    265 }
    266 
    267 
    268 void EmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer)
    269 {
    270     if(pBuffer->nInputPortIndex == MyVppPortDef.input_port){
    271         write(IpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
    272         nInputEmptyBufferDones++;
    273     }
    274     else if(pBuffer->nInputPortIndex == MyVppPortDef.overlay_port){
    275         write(OvlyBuf_Pipe[1], &pBuffer,sizeof(pBuffer));
    276         nOvlyEmptyBufferDones++;
    277     }
    278     else{
    279         printf("VPPTEST:: Incorrect Input Port Index\n");
    280     }
    281 }
    282 
    283 
    284 static OMX_ERRORTYPE GetComponentPortDef(OMX_HANDLETYPE pHandleVPP, COMPONENT_PORTINDEX_DEF *pVppPortDef)
    285 {
    286     OMX_PORT_PARAM_TYPE *pTempPortType = NULL;
    287     OMX_ERRORTYPE eError = OMX_ErrorNone;
    288     OMX_PARAM_PORTDEFINITIONTYPE *pTempVidPortDef = NULL;
    289     int i;
    290     OMX_BOOL found_input = OMX_FALSE;
    291 
    292     pTempPortType = calloc(1, sizeof(OMX_PORT_PARAM_TYPE));
    293     if (!pTempPortType){
    294         eError = OMX_ErrorInsufficientResources;
    295         goto EXIT;
    296     }
    297 
    298     eError = OMX_GetParameter(pHandleVPP, OMX_IndexParamVideoInit, pTempPortType);
    299     if (eError != OMX_ErrorNone) {
    300         printf("VPPTEST:: Error at %d\n",__LINE__);
    301         eError = OMX_ErrorBadParameter;
    302         goto EXIT;
    303     }
    304 
    305     APP_DPRINT("VPP_JPEG_DISPLAY:: ports of VPP %lu, start port %lu\n", pTempPortType->nPorts, pTempPortType->nStartPortNumber);
    306 
    307     pTempVidPortDef = calloc (1,sizeof (OMX_PARAM_PORTDEFINITIONTYPE));
    308     if (!pTempVidPortDef){
    309         eError = OMX_ErrorInsufficientResources;
    310         goto EXIT;
    311     }
    312 
    313     found_input = OMX_FALSE;
    314     for (i = pTempPortType->nStartPortNumber; i < pTempPortType->nPorts; i ++){
    315         pTempVidPortDef->nPortIndex = i;
    316         eError = OMX_GetParameter (pHandleVPP, OMX_IndexParamPortDefinition, pTempVidPortDef);
    317         if ( eError != OMX_ErrorNone ){
    318             printf("VPPTEST:: Error at %d\n",__LINE__);
    319             eError = OMX_ErrorBadParameter;
    320             goto EXIT;
    321         }
    322 
    323         if ((pTempVidPortDef->eDir == OMX_DirInput) &&(found_input == OMX_FALSE)){
    324             /* found input */
    325             pVppPortDef->input_port= i;
    326             found_input = OMX_TRUE;
    327             continue;
    328         }
    329         if ((pTempVidPortDef->eDir == OMX_DirInput) && (found_input == OMX_TRUE)){
    330             /* found ovelay port */
    331             pVppPortDef->overlay_port = i;
    332             continue;
    333         }
    334         if ((pTempVidPortDef->eDir == OMX_DirOutput) &&
    335             (pTempVidPortDef->format.video.eColorFormat == OMX_COLOR_Format16bitRGB565)){
    336             /* found RGB output */
    337             pVppPortDef->rgboutput_port = i;
    338             continue;
    339         }
    340         if ((pTempVidPortDef->eDir == OMX_DirOutput) &&
    341             ((pTempVidPortDef->format.video.eColorFormat == OMX_COLOR_FormatYCbYCr)||
    342             (pTempVidPortDef->format.video.eColorFormat == OMX_COLOR_FormatCbYCrY))){
    343              /* found YUV output */
    344             pVppPortDef->yuvoutput_port = i;
    345             continue;
    346         }
    347     }
    348 
    349     APP_DPRINT("VPPTEST:: input port is %d\n", pVppPortDef->input_port);
    350     APP_DPRINT("VPPTEST:: overlay port is %d\n", pVppPortDef->overlay_port);
    351     APP_DPRINT("VPPTEST:: RGB output port is %d\n", pVppPortDef->rgboutput_port);
    352     APP_DPRINT("VPPTEST:: YUV output port is %d\n", pVppPortDef->yuvoutput_port);
    353 
    354 EXIT:
    355     if (pTempPortType){
    356         free(pTempPortType);
    357         pTempPortType = NULL;
    358     }
    359 
    360     if (pTempVidPortDef){
    361         free(pTempVidPortDef);
    362         pTempVidPortDef = NULL;
    363     }
    364     return eError;
    365 }
    366 
    367 
    368 
    369 static OMX_ERRORTYPE GetVPPCustomDef(OMX_HANDLETYPE pHandleVPP)
    370 {
    371     OMX_ERRORTYPE eError = OMX_ErrorNone;
    372 
    373     eError = OMX_GetExtensionIndex(pHandleVPP, "OMX.TI.VPP.Param.ZoomFactor", &(MyVPPCustomDef.VPPCustomSetZoomFactor));
    374     if(eError != OMX_ErrorNone) {
    375         fprintf (stderr,"VPPTEST:: Error in OMX_GetExtensionIndex function\n");
    376         goto EXIT;
    377     }
    378     APP_DPRINT("OMX.TI.VPP.Param.ZoomFactor is %x\n", MyVPPCustomDef.VPPCustomSetZoomFactor);
    379 
    380     eError = OMX_GetExtensionIndex(pHandleVPP, "OMX.TI.VPP.Param.ZoomLimit", &(MyVPPCustomDef.VPPCustomSetZoomLimit));
    381     if(eError != OMX_ErrorNone) {
    382         fprintf (stderr,"VPPTEST:: Error in OMX_GetExtensionIndex function\n");
    383         goto EXIT;
    384     }
    385     APP_DPRINT("OMX.TI.VPP.Param.ZoomLimit is %x\n", MyVPPCustomDef.VPPCustomSetZoomLimit);
    386 
    387     eError = OMX_GetExtensionIndex(pHandleVPP, "OMX.TI.VPP.Param.ZoomSpeed", &(MyVPPCustomDef.VPPCustomSetZoomSpeed));
    388     if(eError != OMX_ErrorNone) {
    389         fprintf (stderr,"Error in OMX_GetExtensionIndex function\n");
    390         goto EXIT;
    391     }
    392     APP_DPRINT("OMX.TI.VPP.Param.ZoomSpeed is %x\n", MyVPPCustomDef.VPPCustomSetZoomSpeed);
    393 
    394     eError = OMX_GetExtensionIndex(pHandleVPP, "OMX.TI.VPP.Param.ZoomXoffsetFromCenter16", &(MyVPPCustomDef.VPPCustomSetZoomXoffsetFromCenter16));
    395     if(eError != OMX_ErrorNone) {
    396         fprintf (stderr,"VPPTEST:: Error in OMX_GetExtensionIndex function\n");
    397         goto EXIT;
    398     }
    399     APP_DPRINT("OMX.TI.VPP.Param.ZoomXoffsetFromCenter16 is %x\n", MyVPPCustomDef.VPPCustomSetZoomXoffsetFromCenter16);
    400 
    401     eError = OMX_GetExtensionIndex(pHandleVPP, "OMX.TI.VPP.Param.ZoomYoffsetFromCenter16", &(MyVPPCustomDef.VPPCustomSetZoomYoffsetFromCenter16));
    402     if(eError != OMX_ErrorNone) {
    403         fprintf (stderr,"Error in OMX_GetExtensionIndex function\n");
    404         goto EXIT;
    405     }
    406     APP_DPRINT("OMX.TI.VPP.Param.ZoomYoffsetFromCenter16 is %x\n", MyVPPCustomDef.VPPCustomSetZoomYoffsetFromCenter16);
    407 
    408     eError = OMX_GetExtensionIndex(pHandleVPP, "OMX.TI.VPP.Param.FrostedGlassOvly", &(MyVPPCustomDef.VPPCustomSetFrostedGlassOvly));
    409     if(eError != OMX_ErrorNone) {
    410         fprintf (stderr,"VPPTEST:: Error in OMX_GetExtensionIndex function\n");
    411         goto EXIT;
    412     }
    413     APP_DPRINT("OMX.TI.VPP.Param.FrostedGlassOvly is %x\n", (MyVPPCustomDef.VPPCustomSetFrostedGlassOvly));
    414 
    415 
    416     eError = OMX_GetExtensionIndex(pHandleVPP, "OMX.TI.VPP.Param.VideoColorRange", &(MyVPPCustomDef.VPPCustomSetColorRange));
    417     if(eError != OMX_ErrorNone) {
    418         fprintf (stderr,"VPPTEST:: Error in OMX_GetExtensionIndex function\n");
    419         goto EXIT;
    420     }
    421     APP_DPRINT("OMX.TI.VPP.Param.FrostedGlassOvly is %x\n", (MyVPPCustomDef.VPPCustomSetColorRange));
    422 
    423     eError = OMX_GetExtensionIndex(pHandleVPP, "OMX.TI.VPP.Param.RGB4ColorFormat", &(MyVPPCustomDef.VPP_CustomRGB4ColorFormat));
    424     if(eError != OMX_ErrorNone) {
    425         fprintf (stderr,"VPPTEST:: Error in OMX_GetExtensionIndex function\n");
    426         goto EXIT;
    427     }
    428     APP_DPRINT("OMX.TI.VPP.Param.ZoomFactor is %x\n", MyVPPCustomDef.VPP_CustomRGB4ColorFormat);
    429 
    430 EXIT:
    431         return eError;
    432 
    433 }
    434 
    435 
    436 
    437 #ifdef UNDER_CE
    438 int _tmain(int argc, TCHAR **argv)
    439 #else
    440 int main(int argc, char* argv[])
    441 #endif
    442 {
    443     OMX_ERRORTYPE           error = OMX_ErrorNone;
    444     OMX_CALLBACKTYPE AmrCaBa = {(void *)EventHandler,
    445                                 (void*) EmptyBufferDone,
    446                                 (void*)FillBufferDone};
    447     OMX_HANDLETYPE pHandle;
    448     OMX_U32 AppData = 100;
    449     OMX_PARAM_PORTDEFINITIONTYPE* pCompPrivateStruct = NULL;
    450     OMX_BUFFERHEADERTYPE* InputBufHeader[MAX_VPP_BUFFERS];
    451     OMX_BUFFERHEADERTYPE* OvlyBufHeader[MAX_VPP_BUFFERS];
    452     OMX_BUFFERHEADERTYPE* OutRGBBufHeader[MAX_VPP_BUFFERS];
    453     OMX_BUFFERHEADERTYPE* OutYUVBufHeader[MAX_VPP_BUFFERS];
    454 
    455     OMX_COMPONENTTYPE *pComponent;
    456     OMX_STATETYPE state;
    457     int retval;
    458 #ifdef UNDER_CE
    459     TCHAR* szInFile = NULL;
    460     TCHAR* szOutFile = NULL;
    461     HANDLE fIn = NULL;
    462     HANDLE fOut = NULL;
    463     HANDLE fYuvOut = NULL;
    464     HANDLE fInOvelay = NULL;
    465     TCHAR stringRGB[30];
    466     TCHAR stringYUV[30];
    467     TCHAR overlaystring[30];
    468     DWORD dwWritten;
    469 #else
    470     char* szInFile = NULL;
    471     char* szOutFile = NULL;
    472     FILE* fIn = NULL;
    473     FILE* fOut = NULL;
    474     FILE* fYuvOut = NULL;
    475     FILE* fInOvelay = NULL;
    476     char stringRGB[30];
    477     char stringYUV[30];
    478     char overlaystring[30];
    479 #endif
    480     OMX_U16 inputwidth=0;
    481     OMX_U16 inputheight=0;
    482     OMX_U16 outputwidth=0;
    483     OMX_U16 outputheight=0;
    484     OMX_U16 inputcolor;
    485     OMX_U16 rgboutputcolor;
    486     OMX_U16 yuvoutputcolor;
    487     int Isoverlay;
    488     int IsYUVRGB;
    489     int bitrate=0;
    490     int iCurrentFrameIn = 0;
    491     int iCurrentOvlyFrameIn=0;
    492     int iCurrentRGBFrameOut = 0;
    493     int iCurrentYUVFrameOut = 0;
    494     int DEINIT_FLAG = 0;
    495     int nTypeofAllocation;
    496     int feature_param[4]={0,0,0,0};   /*Initialize array*/
    497     int feature;  /*Feature selected, only scaling, zoom, contrast, frosted glass effect, cropping, mirror and rotation*/
    498     OMX_COLOR_FORMATTYPE nColor;        /*Used to pass Color Format for input and output ports*/
    499     fd_set rfds;
    500     int fdmax;
    501     OMX_U8 *pInBuffer = NULL;
    502     OMX_U8 *pYUVBuffer = NULL;
    503     OMX_U8 *pRGBBuffer = NULL;
    504     int nRead = 0;
    505     int done = 0;
    506     int frmCount = 0;
    507     int nCounter =0;
    508     int count_stop_restart=0;   /* Executing-->Idle-->Executing*/
    509     int count_stop_load=0;  /* Loaded-->Idle-->Executing-->Idle-->Loaded */
    510     int max_count_stop_restart=0;
    511     int max_count_stop_load=0;
    512     OMX_BUFFERHEADERTYPE* pBuffer = NULL;  /*To Hold Input Buffers*/
    513     OMX_BUFFERHEADERTYPE* pBuf = NULL;     /*To Hold Output Buffers*/
    514     OMX_PARAM_PORTDEFINITIONTYPE *portinput;
    515     int nFillThisBufferYUV=0;
    516     int nFillThisBufferRGB=0;
    517     int nTimeouts =0;
    518     int bPauseResume=OMX_FALSE;
    519     int bStopRestart=OMX_FALSE;
    520     int bStopNotFree=OMX_FALSE;
    521     int bStopExit=OMX_FALSE;
    522     int MAX_VPP_BUFFERS_IN_USE = MAX_VPP_BUFFERS;
    523     sigset_t set;
    524 
    525     /* validate command line args */
    526     if(argc < 13) {
    527 #ifdef UNDER_CE
    528         printf("usage: %S <input.yuv><file_desc><Inp. Width><Inp. Height><Inp. color><0:no overlay/1:overlay><Out. Width><Out Height><yuv color><rgb color><0 :Internal 1 :external allocation><Feature [0-8]>\n",
    529                 argv[0]);
    530         printf("./VPPTest_common patterns/qciftest.yuv qcif_qqcif  176 144 1 0 88 72 1 2 0 0\n");
    531 #else
    532         printf("usage: %s <input.yuv><file_desc><Inp. Width><Inp. Height><Inp. color><0:no overlay/1:overlay><Out. Width><Out Height><yuv color><rgb color><0 :Internal 1 :external allocation><Feature [0-8]>\n",
    533                 argv[0]);
    534         printf("./VPPTest_common patterns/qciftest.yuv qcif_qqcif  176 144 1 0 88 72 1 2 0 0\n");
    535 #endif
    536         return -1;
    537     }
    538 
    539     szInFile = argv[1];
    540     szOutFile = argv[2];
    541 #ifdef UNDER_CE
    542     inputwidth=_wtoi(argv[3]);
    543     inputheight=_wtoi(argv[4]);
    544     inputcolor=_wtoi(argv[5]);
    545     Isoverlay = _wtoi(argv[6]);
    546     outputwidth=_wtoi(argv[7]);
    547     outputheight=_wtoi(argv[8]);
    548     yuvoutputcolor= _wtoi(argv[9]);
    549     rgboutputcolor = _wtoi(argv[10]);
    550     nTypeofAllocation = _wtoi(argv[11]);
    551     feature= (_wtoi(argv[12])& (0x00FF);  /*Use only lower byte*/
    552     bPauseResume = (_wtoi(argv[12]) & (0x0100);  /*Bit 8 is PauseResumeFlag*/
    553     bStopRestart = (_wtoi(argv[12]) & (0x0200);  /*Bit 9 is StopRestart Flag*/
    554     bStopNotFree = (_wtoi(argv[12]) & (0x0400);  /*Bit 10 is Stop without freeing component Flag*/
    555     bStopExit = (_wtoi(argv[12]) & (0x0800);     /*Bit 11 is Stop without finishing the procesed image*/
    556 
    557 #else
    558     inputwidth=atoi(argv[3]);
    559     inputheight=atoi(argv[4]);
    560     inputcolor=atoi(argv[5]);
    561     Isoverlay =atoi(argv[6]);
    562     outputwidth=atoi(argv[7]);
    563     outputheight=atoi(argv[8]);
    564     yuvoutputcolor= atoi(argv[9]);
    565     rgboutputcolor = atoi(argv[10]);
    566     nTypeofAllocation = atoi(argv[11]);
    567     feature=atoi(argv[12]) & (0x00FF);  /*Use only lower byte*/
    568     bPauseResume = atoi(argv[12]) & (0x0100);  /*Bit 8 is PauseResumeFlag*/
    569     bStopRestart = atoi(argv[12]) & (0x0200);  /*Bit 9 is StopRestart Flag*/
    570     bStopNotFree = atoi(argv[12]) & (0x0400);  /*Bit 10 is Stop without freeing component Flag*/
    571     bStopExit = atoi(argv[12]) & (0x0800);     /*Bit 11 is Stop without finishing the procesed image*/
    572 #endif
    573 
    574     /* 1600 x 1200 is only a rough guess */
    575     if ((inputwidth * inputheight) >= (1600 * 1200))
    576     {
    577         MAX_VPP_BUFFERS_IN_USE = 1;
    578     }
    579 
    580     if(yuvoutputcolor == 0 && rgboutputcolor ==0)
    581     {
    582         printf("VPPTEST:: At least one output is required\n");
    583         printf("VPPTEST:: Selecting YUV420 as default.\n");
    584         yuvoutputcolor=1;
    585     }
    586     if(yuvoutputcolor && rgboutputcolor)  /*Simultaneous output*/
    587     {
    588         IsYUVRGB=2;
    589     }
    590     else if(yuvoutputcolor)  /*Only YUV output*/
    591     {
    592         IsYUVRGB=0;
    593     }
    594     else
    595     {
    596         IsYUVRGB=1;     /*Only RGB output*/
    597     }
    598 
    599     /* Assign Parameters according to feature selected*/
    600     switch (feature)  /*Assign feature selected feature parameters*/
    601     {
    602         case 0 : /*Only Scaling Needed */
    603         {
    604             if(argc>13)
    605             {
    606                 printf("VPPTEST:: Only Scaling Selected, ignoring Extra parameters\n");
    607             }
    608 
    609             break;
    610         }
    611 
    612         case 1:     /*On Demand Zoom */
    613         case 2:     /*Dynamic Zoom  */
    614         {
    615             if(argc < 15){
    616 #ifdef UNDER_CE
    617                 printf("usage: %S <input.yuv> <output desc> <Inp. width> <Inp. Height> <0:no overlay/1:overlay> <outputwidth> <outputheight> <0:YUV/1:RGB/2:BOTH>  <0 :Internal 1 :external allocation>\
    618                     <Feature 1= On Demand/2=Dynamic>    <On Demand Zoom/Dynamic Zoom> <Zoom Factor/Zoom Speed> <Zoom Limit>\n",argv[0]);
    619 #else
    620                 printf("usage: %s <input.yuv> <output desc> <Inp. width> <Inp. Height> <0:no overlay/1:overlay> <outputwidth> <outputheight> <0:YUV/1:RGB/2:BOTH>  <0 :Internal 1 :external allocation>\
    621                     <Feature 1= On Demand/2=Dynamic>    <On Demand Zoom/Dynamic Zoom> <Zoom Factor/Zoom Speed> <Zoom Limit>\n",argv[0]);
    622 #endif
    623                 return -1;
    624             }
    625             else{
    626 #ifdef UNDER_CE
    627                 feature_param[0] = _wtoi(argv[13]);  /*Zoom Factor or Zoom Speed*/
    628                 feature_param[1] = _wtoi(argv[14]); /*Zoom Limit */
    629 #else
    630                 feature_param[0] = atoi(argv[13]);  /*Zoom Factor or Zoom Speed*/
    631                 feature_param[1] = atoi(argv[14]);  /*Zoom Limit */
    632 #endif
    633             }
    634             if(argc>15){
    635                 printf("On Demand Zoom Selected, Ignoring Extra parameters\n");
    636             }
    637 
    638             break;
    639         }
    640         case 3:  /*Zoom Offset*/
    641         {
    642             if(argc<17){
    643 #ifdef UNDER_CE
    644                 printf("usage: %S <input.yuv> <output.rgb> <inputwidth> <inputheight> <0:no overlay/1:overlay>  <outputwidth> <outputheight> <0:YUV/1:RGB/2:BOTH>  <0 :Internal 1 :external allocation>\
    645                     <Feature 3=Zoom Offset> <Zoom Factor> <Zoom Limit> <X Offset> <Y Offset>\n",argv[0]);
    646 #else
    647                 printf("usage: %s <input.yuv> <output.rgb> <inputwidth> <inputheight> <0:no overlay/1:overlay>  <outputwidth> <outputheight> <0:YUV/1:RGB/2:BOTH>  <0 :Internal 1 :external allocation>\
    648                     <Feature 3=Zoom Offset> <Zoom Factor> <Zoom Limit> <X Offset> <Y Offset>\n",argv[0]);
    649 #endif
    650                 return -1;
    651             }
    652             else{
    653 #ifdef UNDER_CE
    654                 feature_param[0] = _wtoi(argv[13]); /*Zoom Factor*/
    655                 feature_param[1] = _wtoi(argv[14]); /*Zoom Limit*/
    656                 feature_param[2] = _wtoi(argv[15]); /*X Offset*/
    657                 feature_param[3] = _wtoi(argv[16]); /*Y Offset*/
    658 #else
    659                 feature_param[0] = atoi(argv[13]);  /*Zoom Factor*/
    660                 feature_param[1] = atoi(argv[14]);  /*Zoom Limit*/
    661                 feature_param[2] = atoi(argv[15]);  /*X Offset*/
    662                 feature_param[3] = atoi(argv[16]);  /*Y Offset*/
    663 #endif
    664             }
    665             if(argc>17){
    666                 printf("VPPTEST:: Zoom Offset Selected, Ignoring Extra parameters\n");
    667             }
    668 
    669             break;
    670         }
    671 
    672         case 4 : /* Contrast */
    673         {
    674             if(argc<14)
    675             {
    676 #ifdef UNDER_CE
    677                 printf("usage: %S <input.yuv> <output.rgb> <width> <height> <0:no overlay/1:overlay>  <outputwidth> <outputheight> <0:YUV/1:RGB/2:BOTH>  <0 :Internal 1 :external allocation>\
    678                     <Feature 4=Contrast> <Contrast Value [-100 100]>\n",argv[0]);
    679 #else
    680                 printf("usage: %s <input.yuv> <output.rgb> <width> <height> <0:no overlay/1:overlay>  <outputwidth> <outputheight> <0:YUV/1:RGB/2:BOTH>  <0 :Internal 1 :external allocation>\
    681                     <Feature 4=Contrast> <Contrast Value [-100 100]>\n",argv[0]);
    682 #endif
    683                 return -1;
    684             }
    685             else{
    686 #ifdef UNDER_CE
    687                 feature_param[0] = _wtoi(argv[13]);
    688 #else
    689                 feature_param[0]=atoi(argv[13]);
    690 #endif
    691             }
    692             if(argc>14){
    693                 printf("VPPTEST:: Contrast Selected, Ignoring extra parameters\n");
    694             }
    695 
    696             break;
    697         }
    698 
    699         case 5 :  /*Frosted Glass effect */
    700         {
    701             if(Isoverlay ==0){
    702                 printf("VPPTEST:: Overlay is needed for Frosted Glass effect\n");
    703                 return -1;
    704             }
    705 
    706             break;
    707         }
    708 
    709         case 6 : /*Cropping*/
    710         {
    711             if(argc<17){
    712 #ifdef UNDER_CE
    713                 printf("usage: %S <input.yuv> <output.rgb> <width> <height> <0:no overlay/1:overlay>  <outputwidth> <outputheight> <0:YUV/1:RGB/2:BOTH>  <0 :Internal 1 :external allocation>\
    714                     <Feature 6=Cropping> <Left Coord> <Width> <Top coord> <Height>\n",argv[0]);
    715 #else
    716                 printf("usage: %s <input.yuv> <output.rgb> <width> <height> <0:no overlay/1:overlay>  <outputwidth> <outputheight> <0:YUV/1:RGB/2:BOTH>  <0 :Internal 1 :external allocation>\
    717                     <Feature 6=Cropping> <Left Coord> <Width> <Top Coord> <Height>\n",argv[0]);
    718 #endif
    719                 return -1;
    720             }
    721             else{
    722 #ifdef UNDER_CE
    723                 feature_param[0] = _wtoi(argv[13]); /*Left Pixel*/
    724                 feature_param[1] = _wtoi(argv[14]); /*Width*/
    725                 feature_param[2] = _wtoi(argv[15]); /*Top Pixel*/
    726                 feature_param[3] = _wtoi(argv[16]); /*Height*/
    727 #else
    728                 feature_param[0] = atoi(argv[13]);  /*Left Pixel*/
    729                 feature_param[1] = atoi(argv[14]);  /*Width*/
    730                 feature_param[2] = atoi(argv[15]);  /*Top Pixel*/
    731                 feature_param[3] = atoi(argv[16]);  /*Height*/
    732 #endif
    733             }
    734             if(argc>17){
    735                 printf("VPPTEST:: Cropping Selected, Ignoring Extra parameters\n");
    736             }
    737 
    738             break;
    739         }
    740 
    741         case 7 : /* Mirroring */
    742         {
    743             if(!IsYUVRGB){
    744                 printf("VPPTEST:: Mirrored Image is only possible for RGB output\n");
    745                 return -1;
    746             }
    747             break;
    748         }
    749 
    750         case 8: /*Rotation*/
    751         {
    752             if(argc<14){
    753                 printf("usage: %s <input.yuv> <output descriptor> <Inp. width> <Inp. height> <Inp. Color> <0:no overlay/1:overlay>  <outputwidth> <outputheight> <YUV output format> <RGB format>  <0 :Internal 1 :external allocation>\
    754                     <Feature 8=Rotation> <Rotation Angle = 0,90,180,270>\n",argv[0]);
    755                 return -1;
    756             }
    757             else{
    758 #ifdef UNDER_CE
    759                 feature_param[0]=_wtoi(argv[13]);
    760 #else
    761                 feature_param[0]=atoi(argv[13]);
    762 #endif
    763             }
    764 
    765             break;
    766         }
    767         case 9 : /* Dithering */
    768         {
    769             if(!IsYUVRGB){
    770                 printf("VPPTEST:: Dithering is only possible for RGB output\n");
    771                 return -1;
    772             }
    773             break;
    774         }
    775         case 10: /*Video Color Range Conversion*/
    776             {
    777 
    778 #ifdef UNDER_CE
    779                 feature_param[0]=_wtoi(argv[13]);
    780 #else
    781                 feature_param[0]=atoi(argv[13]);
    782 #endif
    783                 break;
    784 
    785             }
    786 
    787 
    788         default :
    789         {
    790 #ifdef UNDER_CE
    791             printf("Not a Valid Option on Selected Feature\n");
    792             printf("usage: %S <Num><input.yuv> <output.rgb> <width> <height> <0:no overlay/1:overlay>  <outputwidth> <outputheight> <0:YUV/1:RGB/2:BOTH>  <0 :Internal 1 :external allocation>\
    793                 <Feature [0:9]> <...>\n",argv[0]);
    794 #else
    795             printf("Not a Valid Option on Selected Feature\n");
    796             printf("usage: %s <Num><input.yuv> <output.rgb> <width> <height> <0:no overlay/1:overlay>  <outputwidth> <outputheight> <0:YUV/1:RGB/2:BOTH>  <0 :Internal 1 :external allocation>\
    797                 <Feature [0:9]> <...>\n",argv[0]);
    798 #endif
    799                 return -1;
    800             break;
    801         }
    802     }  /*End switch*/
    803 
    804 
    805     printf("Test Core 1.8 - " __DATE__ ":" __TIME__ "\n");
    806     printf("------------------------------------------------\n");
    807       /*Buffer flow can happen here*/
    808     if(Isoverlay){
    809 #ifdef UNDER_CE
    810         wsprintf(overlaystring,L"play_qCIF.raw");
    811         printf("Overlay file: %S\n",overlaystring);
    812 #else
    813 
    814         sprintf(overlaystring,"/omx/patterns/play_qCIF.raw");
    815         printf("Overlay file: %s\n",overlaystring);
    816 #endif
    817     }
    818 
    819 
    820 #ifndef UNDER_CE
    821    /* check to see that the input file exists */
    822     struct stat sb = {0};
    823     int status = stat(argv[1], &sb);
    824     if( status != 0 ){
    825         fprintf(stderr, "Cannot find file %s. (%u)\n", argv[1], errno);
    826         goto EXIT;
    827     }
    828 #endif
    829 
    830     /* Create a pipe used to queue data from the callback. */
    831     retval = pipe(IpBuf_Pipe);
    832     if(retval != 0){
    833         fprintf(stderr, "Error:Fill Data Pipe failed to open\n");
    834         goto EXIT;
    835     }
    836     /* Create a pipe used to queue data from the callback. */
    837     retval = pipe(OvlyBuf_Pipe);
    838     if(retval != 0){
    839         fprintf(stderr, "Error:Fill Data Pipe failed to open\n");
    840         goto EXIT;
    841     }
    842 
    843     retval = pipe(OpRGBBuf_Pipe);
    844     if(retval != 0){
    845         fprintf(stderr, "Error:Empty Data Pipe failed to open\n");
    846         goto EXIT;
    847     }
    848     retval = pipe(OpYUVBuf_Pipe);
    849     if(retval != 0){
    850         fprintf(stderr, "Error:Empty Data Pipe failed to open\n");
    851         goto EXIT;
    852     }
    853     /* Create a pipe used to handle events from the callback. */
    854     retval = pipe(Event_Pipe);
    855     if(retval != 0){
    856         fprintf(stderr, "Error:Fill Data Pipe failed to open\n");
    857         goto EXIT;
    858     }
    859 
    860     /* save off the "max" of the handles for the selct statement */
    861     fdmax = maxint(IpBuf_Pipe[0], OvlyBuf_Pipe[0]);
    862     fdmax = maxint(fdmax, OpRGBBuf_Pipe[0]);
    863     fdmax = maxint(fdmax, OpYUVBuf_Pipe[0]);
    864     fdmax = maxint(fdmax, Event_Pipe[0]);
    865 
    866 #ifdef DSP_MMU_FAULT_HANDLING
    867 /* LOAD BASE IMAGE FIRST TIME */
    868         LoadBaseImage();
    869 #endif
    870 
    871     error = TIOMX_Init();
    872     if(error != OMX_ErrorNone) {
    873         printf("%d :: Error returned by TIOMX_init()\n",__LINE__);
    874         goto EXIT;
    875     }
    876 
    877 /********************************************************************************************************/
    878     /* Load the VPP Component */
    879     error = TIOMX_GetHandle(&pHandle,strAmrDecoder,&AppData, &AmrCaBa);
    880     if( (error != OMX_ErrorNone) || (pHandle == NULL) ){
    881         fprintf (stderr,"Error in Get Handle function\n");
    882         goto EXIT;
    883     }
    884     if(bStopNotFree){
    885         max_count_stop_load=20;
    886     }
    887     else{
    888         max_count_stop_load=1;
    889     }
    890     /********************************Component is loaded here, we can loop after this point****************************************/
    891     for(count_stop_load=0; count_stop_load<max_count_stop_load; count_stop_load++)
    892     {
    893         error = GetComponentPortDef(pHandle, &MyVppPortDef);
    894         if (error != OMX_ErrorNone){
    895             fprintf (stderr,"Error in Get Handle function\n");
    896             goto EXIT;
    897         }
    898 
    899         error = GetVPPCustomDef(pHandle);
    900         if(error != OMX_ErrorNone)
    901         {
    902             fprintf (stderr,"Error in Get Handle function\n");
    903             goto EXIT;
    904         }
    905 
    906         printf("VPPTEST:: Input Height: %d, Input Width %d\n",inputheight, inputwidth);
    907 
    908         /*Select Input Format and Buffer Size accordingly*/
    909         switch(inputcolor)
    910         {
    911             case 0:     /*YUV 420 Planar*/
    912                 nColor = OMX_COLOR_FormatYUV420PackedPlanar;
    913                 printf("VPPTEST:: Input YUV420\n");
    914                 break;
    915             case 1: /*YUV 422 Interleaved (little-endian)*/
    916                 nColor = OMX_COLOR_FormatCbYCrY/*OMX_COLOR_FormatYCbYCr*/;
    917                 printf("VPPTEST:: Input YUV422 Interleaved (little-endian)\n");
    918                 break;
    919             case 2: /*YUV 422 Interleaved (big-endian)*/
    920                 nColor = OMX_COLOR_FormatYCbYCr/*OMX_COLOR_FormatYCrYCb*/;
    921                 printf("VPPTEST:: Input YUV422 Interleaved (big-endian)\n");
    922                 break;
    923             case 3: /*RGB24 8:8:8*/
    924                 nColor = OMX_COLOR_Format24bitRGB888;
    925                 printf("VPPTEST:: Input RGB24\n");
    926                 break;
    927             case 4 : /*RGB16 5:6:5*/
    928                 nColor = OMX_COLOR_Format16bitRGB565;
    929                 printf("VPPTEST:: Input RGB16\n");
    930                 break;
    931             case 5 : /*RGB12 5:6:5*/
    932                 nColor = OMX_COLOR_Format12bitRGB444;
    933                 printf("VPPTEST:: Input RGB12\n");
    934                 break;
    935             case 6 : /*RGB8 3:3:2*/
    936                 nColor = OMX_COLOR_Format8bitRGB332;
    937                 printf("VPPTEST:: Input RGB8\n");
    938                 break;
    939             case 7 : /*RGB4  Look-Up-Table*/
    940                 nColor = MyVPPCustomDef.VPP_CustomRGB4ColorFormat;
    941                 printf("VPPTEST:: Input RGB4\n");
    942                 break;
    943             case 8 : /*GRAY8 */
    944                 nColor = OMX_COLOR_FormatL8;
    945                 printf("VPPTEST:: Input GRAY8\n");
    946                 break;
    947             case 9 : /* GRAY4 */
    948                 nColor = OMX_COLOR_FormatL4;
    949                 printf("VPPTEST:: Input GRAY4\n");
    950                 break;
    951             case 10: /* GRAY2 */
    952                 nColor = OMX_COLOR_FormatL2;
    953                 printf("VPPTEST:: Input GRAY2\n");
    954                 break;
    955             case 11 : /* Monochrome */
    956                 nColor = OMX_COLOR_FormatMonochrome;
    957                 printf("VPPTEST:: Input Monochrome\n");
    958                 break;
    959             default:
    960                 printf("VPPTEST:: Not a valid option for Input Format\n");
    961                 goto EXIT;
    962                 break;
    963         }
    964 
    965 
    966         printf("VPPTEST:: %d : GetHandle Done..........\n",__LINE__);
    967 
    968         pCompPrivateStruct = malloc (sizeof (OMX_PARAM_PORTDEFINITIONTYPE));
    969         if(!pCompPrivateStruct){
    970             printf("VPPTEST:: eError = OMX_ErrorInsufficientResources");
    971             error = OMX_ErrorInsufficientResources;
    972             goto EXIT;
    973         }
    974 
    975         pCompPrivateStruct->nSize = sizeof (OMX_PARAM_PORTDEFINITIONTYPE);
    976         pCompPrivateStruct->nVersion.s.nVersionMajor = 0x1;
    977         pCompPrivateStruct->nVersion.s.nVersionMinor = 0x0;
    978         pCompPrivateStruct->nVersion.s.nRevision = 0x0;
    979         pCompPrivateStruct->nVersion.s.nStep = 0x0;
    980         pCompPrivateStruct->nPortIndex = MyVppPortDef.input_port;
    981         pCompPrivateStruct->eDir = OMX_DirInput;
    982         pCompPrivateStruct->nBufferCountMin = 1;
    983         pCompPrivateStruct->nBufferCountActual = MAX_VPP_BUFFERS_IN_USE;
    984         pCompPrivateStruct->bEnabled = OMX_TRUE;
    985         pCompPrivateStruct->bPopulated = OMX_FALSE;
    986         pCompPrivateStruct->eDomain = OMX_PortDomainVideo;
    987         pCompPrivateStruct->format.video.nFrameHeight = inputheight;
    988         pCompPrivateStruct->format.video.nFrameWidth = inputwidth;
    989         pCompPrivateStruct->format.video.eColorFormat = nColor;
    990         pCompPrivateStruct->format.video.nBitrate = bitrate;
    991 
    992         //Send input port config
    993         error = OMX_SetParameter (pHandle,OMX_IndexParamPortDefinition,
    994                                                pCompPrivateStruct);
    995         if (error != OMX_ErrorNone) {
    996             goto EXIT;
    997         }
    998 
    999         if(Isoverlay){  /* At the moment, only qcif overlay frame is supported*/
   1000             error = OMX_GetParameter (pHandle,OMX_IndexParamPortDefinition, pCompPrivateStruct);
   1001             if(error != OMX_ErrorNone){
   1002                 goto EXIT;
   1003             }
   1004             pCompPrivateStruct->nPortIndex = MyVppPortDef.overlay_port;
   1005             pCompPrivateStruct->eDir = OMX_DirInput;
   1006             pCompPrivateStruct->nBufferCountActual = MAX_VPP_BUFFERS_IN_USE;
   1007             pCompPrivateStruct->format.video.nFrameHeight = DEFAULT_HEIGHT;
   1008             pCompPrivateStruct->format.video.nFrameWidth = DEFAULT_WIDTH;
   1009             pCompPrivateStruct->format.video.eColorFormat = OMX_COLOR_Format24bitRGB888;//OMX_COLOR_FormatYCbYCr
   1010             error = OMX_SetParameter (pHandle,OMX_IndexParamPortDefinition, pCompPrivateStruct);
   1011             if (error != OMX_ErrorNone){
   1012                 goto EXIT;
   1013             }
   1014             printf("VPPTEST:: Overlay Enabled\n");
   1015 
   1016         }
   1017         else {
   1018             OMX_SendCommand(pHandle, OMX_CommandPortDisable, MyVppPortDef.overlay_port, NULL);
   1019         }
   1020 
   1021         /**************************** FOR OUTPUT PORTS ***************************/
   1022         printf("VPPTEST:: Output height: %d, Output Width: %d\n",outputheight, outputwidth);
   1023 
   1024         if(IsYUVRGB){ /*Select output Format and Buffer Size accordingly*/
   1025             switch (rgboutputcolor) {
   1026                 case 1: /*RGB24 8:8:8*/
   1027                     nColor = OMX_COLOR_Format24bitRGB888; /* changed from BGR*/
   1028                     printf("VPPTEST:: %d::Output RGB24\n",__LINE__);
   1029                     break;
   1030                 case 2: /*RGB16 5:6:5*/
   1031                     nColor =OMX_COLOR_Format16bitRGB565;
   1032                     printf("VPPTEST:: Output RGB16\n");
   1033                     break;
   1034                 case 3:/*RGB12 4:4:4*/
   1035                     nColor=OMX_COLOR_Format12bitRGB444;
   1036                     printf("VPPTEST:: Output RGB12\n");
   1037                     break;
   1038                 case 4:/*RGB8 3:3:2*/
   1039                     nColor = OMX_COLOR_Format8bitRGB332;
   1040                     printf("VPPTEST:: Output RGB8\n");
   1041                     break;
   1042                 case 5: /*RGB4*/
   1043                     nColor = MyVPPCustomDef.VPP_CustomRGB4ColorFormat;
   1044                     printf("VPPTEST:: Output RGB4\n");
   1045                     break;
   1046                 case 6: /*GRAY8 */
   1047                     nColor=OMX_COLOR_FormatL8;
   1048                     printf("VPPTEST:: Output GRAY8\n");
   1049                     break;
   1050                 case 7:/*GRAY4*/
   1051                     nColor = OMX_COLOR_FormatL4;
   1052                     printf("VPPTEST:: Output GRAY4\n");
   1053                     break;
   1054                 case 8: /*GRAY2*/
   1055                     nColor = OMX_COLOR_FormatL2;
   1056                     printf("VPPTEST:: Output GRAY2\n");
   1057                     break;
   1058                 case 9: /*Monochrome*/
   1059                     nColor = OMX_COLOR_FormatMonochrome;
   1060                     printf("VPPTEST:: Output Monochrome\n");
   1061                     break;
   1062                 case 10: /*RGB32*/
   1063                     nColor = OMX_COLOR_Format32bitARGB8888;
   1064                     printf("VPPTEST:: Output RGB32\n");
   1065                     break;
   1066                 default:
   1067                     nColor =OMX_COLOR_Format16bitRGB565;
   1068                     printf("VPPTEST:: Not a valid option, default to RGB16\n");
   1069                     break;
   1070             }
   1071         }
   1072 
   1073         /*Send output port config for RGB port*/
   1074 
   1075         if(IsYUVRGB){
   1076             printf("VPPTEST:: configuring RGB port \n");
   1077             error = OMX_GetParameter (pHandle,OMX_IndexParamPortDefinition,
   1078                                                    pCompPrivateStruct);
   1079             if (error != OMX_ErrorNone) {
   1080                 goto EXIT;
   1081             }
   1082             pCompPrivateStruct->nPortIndex = MyVppPortDef.rgboutput_port;
   1083             pCompPrivateStruct->eDir = OMX_DirOutput;
   1084             pCompPrivateStruct->nBufferCountActual = MAX_VPP_BUFFERS_IN_USE;
   1085             pCompPrivateStruct->format.video.nFrameHeight = outputheight;
   1086             pCompPrivateStruct->format.video.nFrameWidth = outputwidth;
   1087             pCompPrivateStruct->format.video.eColorFormat = nColor ;/*OMX_COLOR_FormatUnused */
   1088             error = OMX_SetParameter (pHandle,OMX_IndexParamPortDefinition,
   1089                                                    pCompPrivateStruct);
   1090             if (error != OMX_ErrorNone) {
   1091                 goto EXIT;
   1092             }
   1093             printf("VPPTEST:: RGB port has been configured\n");
   1094         }
   1095 
   1096         else{
   1097             OMX_SendCommand(pHandle, OMX_CommandPortDisable, MyVppPortDef.rgboutput_port, NULL);
   1098         }
   1099 
   1100         /*Send output port config for YUV port*/
   1101         if(IsYUVRGB ==0 || IsYUVRGB ==2){
   1102             switch (yuvoutputcolor)
   1103             {
   1104             case 1:
   1105                 nColor=OMX_COLOR_FormatYUV420PackedPlanar;
   1106                 printf("VPPTEST:: Output YUV420 Planar\n");
   1107                 break;
   1108             case 2:
   1109                 nColor=OMX_COLOR_FormatYCbYCr;   /*YUV422 (YUYV)*/
   1110                 printf("VPPTEST:: Output YUV422 YUYV\n");
   1111                 break;
   1112             case 3:
   1113                 nColor=OMX_COLOR_FormatCbYCrY;  /*YUV422 (UYVY)*/
   1114                 printf("VPPTEST:: Output YUV422 UYVY\n");
   1115                 break;
   1116             default:
   1117                 printf("VPPTEST:: Not a valid option, default to YUV420 planar\n");
   1118                 nColor=OMX_COLOR_FormatYUV420PackedPlanar;
   1119                 break;
   1120             }
   1121 
   1122             error = OMX_GetParameter (pHandle,OMX_IndexParamPortDefinition,
   1123                         pCompPrivateStruct);
   1124             if (error != OMX_ErrorNone) {
   1125                 goto EXIT;
   1126             }
   1127             pCompPrivateStruct->nPortIndex = MyVppPortDef.yuvoutput_port;
   1128             pCompPrivateStruct->eDir = OMX_DirOutput;
   1129             pCompPrivateStruct->nBufferCountActual = MAX_VPP_BUFFERS_IN_USE;
   1130             pCompPrivateStruct->format.video.nFrameHeight = outputheight;
   1131             pCompPrivateStruct->format.video.nFrameWidth = outputwidth;
   1132             pCompPrivateStruct->format.video.eColorFormat = nColor;
   1133 
   1134             APP_DPRINT("VPPTEST:: Configuring YUV output port\n");
   1135             error = OMX_SetParameter (pHandle,OMX_IndexParamPortDefinition,
   1136                         pCompPrivateStruct);
   1137             if (error != OMX_ErrorNone) {
   1138                 goto EXIT;
   1139             }
   1140             printf("VPPTEST:: YUV output port has been configured\n");
   1141         }
   1142         else{
   1143             OMX_SendCommand(pHandle, OMX_CommandPortDisable, MyVppPortDef.yuvoutput_port, NULL);
   1144         }
   1145 
   1146         APP_DPRINT ("Basic Function:: Sending OMX_StateIdle Command\n");
   1147 
   1148 
   1149         printf("VPPTEST:: Num buffers %d\n", MAX_VPP_BUFFERS_IN_USE);
   1150 
   1151         /*Input Buffer Allocation*/
   1152         pCompPrivateStruct->nPortIndex = MyVppPortDef.input_port;
   1153        error = OMX_GetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
   1154         if (error != OMX_ErrorNone) {
   1155             goto EXIT;
   1156         }
   1157 
   1158         if(nTypeofAllocation ==0){
   1159             for(nCounter=0; nCounter<MAX_VPP_BUFFERS_IN_USE; nCounter++){  /*MultiBuffer*/
   1160                 error = OMX_AllocateBuffer(pHandle, &InputBufHeader[nCounter], MyVppPortDef.input_port, (void *)NULL, pCompPrivateStruct->nBufferSize);
   1161                 if(error != OMX_ErrorNone) {
   1162                     printf("VPPTEST:: VPPTEST:: OMX_AllocateBuffer failed !!\n");
   1163                     goto EXIT;
   1164                 }
   1165             }
   1166         }
   1167         else{
   1168             pInBuffer = malloc(pCompPrivateStruct->nBufferSize +256);
   1169             if(pInBuffer == NULL){
   1170                 error = OMX_ErrorInsufficientResources;
   1171                 goto EXIT;
   1172             }
   1173             pInBuffer += 128;
   1174             for(nCounter=0; nCounter<MAX_VPP_BUFFERS_IN_USE; nCounter++){ /*MultiBuffer*/
   1175                 error = OMX_UseBuffer(pHandle, &InputBufHeader[nCounter],
   1176                             MyVppPortDef.input_port,
   1177                             (void *)NULL,
   1178                             pCompPrivateStruct->nBufferSize,
   1179                             pInBuffer);
   1180                 if(error != OMX_ErrorNone) {
   1181                     printf("VPPTEST:: OMX_UseBuffer failed !!\n");
   1182                     goto EXIT;
   1183                 }
   1184             }
   1185         }
   1186 
   1187         /*Overlay Buffer Allocation*/
   1188         pCompPrivateStruct->nPortIndex = MyVppPortDef.overlay_port;
   1189        error = OMX_GetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
   1190         if (error != OMX_ErrorNone) {
   1191             goto EXIT;
   1192         }
   1193 
   1194         if(Isoverlay){
   1195             for(nCounter=0; nCounter<MAX_VPP_BUFFERS_IN_USE; nCounter++){  /*MultiBuffer*/
   1196                 error = OMX_AllocateBuffer(pHandle, &OvlyBufHeader[nCounter],
   1197                             MyVppPortDef.overlay_port,
   1198                             (void *)NULL,
   1199                             pCompPrivateStruct->nBufferSize);
   1200                 if(error != OMX_ErrorNone) {
   1201                     printf("VPPTEST:: OMX_AllocateBuffer failed !!\n");
   1202                     goto EXIT;
   1203                 }
   1204             }
   1205         }
   1206 
   1207         /*RGB Buffer Allocation*/
   1208         pCompPrivateStruct->nPortIndex = MyVppPortDef.rgboutput_port;
   1209        error = OMX_GetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
   1210         if (error != OMX_ErrorNone) {
   1211             goto EXIT;
   1212         }
   1213 
   1214         if(IsYUVRGB){
   1215             if(nTypeofAllocation == 0){
   1216                 for(nCounter=0; nCounter<MAX_VPP_BUFFERS_IN_USE; nCounter++){  /*MultiBuffer*/
   1217                     error = OMX_AllocateBuffer(pHandle, &OutRGBBufHeader[nCounter],
   1218                                 MyVppPortDef.rgboutput_port,
   1219                                 (void *)NULL,
   1220                                 pCompPrivateStruct->nBufferSize);
   1221                     if(error != OMX_ErrorNone) {
   1222                         printf("VPPTEST:: OMX_AllocateBuffer failed !!\n");
   1223                         goto EXIT;
   1224                     }
   1225                 }
   1226             }
   1227             else{
   1228                 pRGBBuffer = malloc(pCompPrivateStruct->nBufferSize + 256);
   1229                 if(pRGBBuffer == NULL){
   1230                     error = OMX_ErrorInsufficientResources;
   1231                     goto EXIT;
   1232                 }
   1233                 pRGBBuffer += 128;
   1234                 for(nCounter = 0; nCounter<MAX_VPP_BUFFERS_IN_USE; nCounter++){ /*MultiBuffer*/
   1235                     error = OMX_UseBuffer(pHandle, &OutRGBBufHeader[nCounter],
   1236                                 MyVppPortDef.rgboutput_port,
   1237                                 (void *)NULL,
   1238                                 pCompPrivateStruct->nBufferSize,
   1239                                 pRGBBuffer);
   1240                     if(error != OMX_ErrorNone){
   1241                         printf("VPPTEST:: OMX_UseBuffer failed !!\n");
   1242                         goto EXIT;
   1243                     }
   1244                 }
   1245             }
   1246         }
   1247 
   1248         /*YUV Buffer Allocation*/
   1249         pCompPrivateStruct->nPortIndex = MyVppPortDef.yuvoutput_port;
   1250        error = OMX_GetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
   1251         if (error != OMX_ErrorNone) {
   1252             goto EXIT;
   1253         }
   1254 
   1255         if(IsYUVRGB ==0 || IsYUVRGB ==2){
   1256             if(nTypeofAllocation ==0){
   1257                 for(nCounter=0; nCounter<MAX_VPP_BUFFERS_IN_USE; nCounter++){  /*MultiBuffer*/
   1258                     error = OMX_AllocateBuffer(pHandle, &OutYUVBufHeader[nCounter],
   1259                                 MyVppPortDef.yuvoutput_port,
   1260                                 (void *)NULL,
   1261                                 pCompPrivateStruct->nBufferSize);
   1262                     if(error != OMX_ErrorNone) {
   1263                         printf("VPPTEST:: OMX_AllocateBuffer failed !!\n");
   1264                         goto EXIT;
   1265                     }
   1266                 }
   1267             }
   1268             else{
   1269                 pYUVBuffer = malloc(pCompPrivateStruct->nBufferSize +256);
   1270                 if(pYUVBuffer == NULL){
   1271                     error = OMX_ErrorInsufficientResources;
   1272                     goto EXIT;
   1273                 }
   1274                 pYUVBuffer += 128;
   1275                 for(nCounter=0; nCounter<MAX_VPP_BUFFERS_IN_USE; nCounter++){  /*MultiBuffer*/
   1276                     error = OMX_UseBuffer(pHandle, &OutYUVBufHeader[nCounter],
   1277                                 MyVppPortDef.yuvoutput_port,
   1278                                 (void *)NULL,
   1279                                 pCompPrivateStruct->nBufferSize,
   1280                                 pYUVBuffer);
   1281                     if(error != OMX_ErrorNone) {
   1282                         printf("VPPTEST:: OMX_UseBuffer failed !!\n");
   1283                         goto EXIT;
   1284                     }
   1285                 }
   1286             }
   1287         }
   1288 
   1289         error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
   1290         if(error != OMX_ErrorNone){
   1291             fprintf (stderr,"VPPTEST:: Error from SendCommand-Idle(Init) State function\n");
   1292             goto EXIT;
   1293         }
   1294         printf("VPPTEST:: Sending component to Idle State\n");
   1295         /* Wait for startup to complete */
   1296         error = WaitForState(pHandle, OMX_StateIdle);
   1297         if(error != OMX_ErrorNone) {
   1298             fprintf(stderr, "VPPTEST:: Error:  VPP->WaitForState reports an error %X\n", error);
   1299             goto EXIT;
   1300         }
   1301         state = OMX_StateIdle;
   1302         APP_DPRINT("Component is in Idle State\n");
   1303 
   1304     /*******HERE THE COMPONENT IS ALREADY IN IDLE STATE AND BUFFERS HAVE BEEN ALLOCATED********/
   1305         if(bStopRestart) {
   1306             max_count_stop_restart=20;
   1307         }
   1308         else{
   1309             max_count_stop_restart=1;
   1310         }
   1311 
   1312         for(count_stop_restart=0; count_stop_restart<max_count_stop_restart; count_stop_restart++)  /*Executing-->Idle-->Executing*/
   1313         {
   1314             sched_yield();
   1315             iCurrentFrameIn = 0;
   1316             iCurrentOvlyFrameIn=0;
   1317             iCurrentRGBFrameOut = 0;
   1318             iCurrentYUVFrameOut = 0;
   1319             nFillThisBufferYUV=0;
   1320             nFillThisBufferRGB=0;
   1321         /***********************************OPEN THE NEEDED FILES****************************************************/
   1322 #ifdef UNDER_CE
   1323             fIn = CreateFile(argv[1], GENERIC_READ, 0,
   1324                                    NULL,OPEN_EXISTING, 0, NULL);
   1325             if (INVALID_HANDLE_VALUE == fIn){
   1326                 APP_DPRINT("Error:  failed to open the file %S for readonly" \
   1327                      "access\n", argv[1]);
   1328                 goto EXIT;
   1329             }
   1330 
   1331             if(IsYUVRGB){
   1332                 wsprintf(stringRGB, L"%s.raw",szOutFile);
   1333 
   1334                 fOut = CreateFile(stringRGB, GENERIC_WRITE, 0,
   1335                                    NULL,CREATE_ALWAYS, 0, NULL);
   1336                 if (INVALID_HANDLE_VALUE == fOut){
   1337                     APP_DPRINT("Error:  failed to create the output file %s\n",
   1338                         stringRGB);
   1339                     goto EXIT;
   1340                 }
   1341             }
   1342 
   1343             if(IsYUVRGB ==0 || IsYUVRGB ==2){
   1344                 wsprintf(stringYUV, L"%s.yuv",szOutFile);
   1345 
   1346                 fYuvOut = CreateFile(stringYUV, GENERIC_WRITE, 0,
   1347                                    NULL,CREATE_ALWAYS, 0, NULL);
   1348                 if( fYuvOut == INVALID_HANDLE_VALUE ){
   1349                     APP_DPRINT("Error:  failed to create the output file %s\n",
   1350                          stringYUV);
   1351                     goto EXIT;
   1352                 }
   1353             }
   1354 #else
   1355 
   1356             /* Open the file of data to be rendered. */
   1357             fIn = fopen(argv[1], "r");
   1358             if( fIn == NULL ){
   1359                 fprintf(stderr, "VPPTEST:: %d::Error:  failed to open the file %s for readonly access\n",__LINE__,argv[1]);
   1360                 goto EXIT;
   1361             }
   1362 
   1363             if(IsYUVRGB ){
   1364 
   1365                 sprintf(stringRGB, "%s.raw",szOutFile);
   1366 
   1367                 fOut = fopen(stringRGB, "w");
   1368                 if( fOut == NULL ){
   1369                     fprintf(stderr,
   1370                         "Error:  failed to create the output file %s\n",
   1371                         argv[2]);
   1372                     goto EXIT;
   1373                 }
   1374             }
   1375             if(IsYUVRGB ==0 || IsYUVRGB ==2){
   1376                 sprintf(stringYUV, "%s.yuv",szOutFile);
   1377                 fYuvOut = fopen(stringYUV, "w");
   1378                 if(fYuvOut == NULL){
   1379                     fprintf(stderr,
   1380                         "Error:  failed to create the output file %s\n",
   1381                         stringYUV);
   1382                     goto EXIT;
   1383                 }
   1384             }
   1385 #endif
   1386 
   1387 
   1388 
   1389             /**** ALL THE Configurables Features of VPP will happen here (Zoom, Contrast, Cropping, etc.*/
   1390             APP_DPRINT("Configurating features...\n");
   1391             if(Isoverlay){
   1392                 /*This should be enable in case of overlay */
   1393                 OMX_CONFIG_COLORKEYTYPE *color = malloc(sizeof(OMX_CONFIG_COLORKEYTYPE));
   1394                 if(color == NULL){
   1395                     error = OMX_ErrorInsufficientResources;
   1396                     goto EXIT;
   1397                 }
   1398                 /*OMX_U8  colorKey[]  = {0,250,5,3};   ARGB*/
   1399                 OMX_U8  colorKey[]  = {0,3,5,250}; /*ARGB*/
   1400                 color->nARGBMask = (int)colorKey;
   1401                 error = OMX_SetConfig (pHandle,OMX_IndexConfigCommonColorKey,
   1402                                                    color);
   1403                 free(color);
   1404                 if (error != OMX_ErrorNone) {
   1405                     error = OMX_ErrorBadParameter;
   1406                     goto EXIT;
   1407                 }
   1408             }
   1409             error=OMX_ErrorNone;
   1410             switch(feature)
   1411             {
   1412                 case 0:     /*Only Scaling Selected*/
   1413                     break;  /*No need to configure any other feature*/
   1414                 case 1:     /*On Demand Zoom*/
   1415                 {
   1416                     error = VPP_SetZoom(pHandle, 0,feature_param[0], feature_param[1],0,0);
   1417                     printf("VPPTEST:: Selected On Demand Zoom feature\n");
   1418                     break;
   1419                 }
   1420                 case 2: /*Dynamic Zoom*/
   1421                     error = VPP_SetZoom(pHandle,feature_param[0],1024,feature_param[1],0,0);
   1422                     printf("VPPTEST:: Selected Dynamic Zoom Feature\n");
   1423                     break;
   1424 
   1425                 case 3:     /*Zoom Offset*/
   1426                 {
   1427                 /*  error = VPP_SetZoom(pHandle,feature,feature_param);*/
   1428                 error = VPP_SetZoom(pHandle,0, feature_param[0], feature_param[1],feature_param[2],feature_param[3]);
   1429                 printf("VPPTEST:: Selected Zoom Offset Feature\n");
   1430                 /*VPP_SetZoom(OMX_HANDLETYPE pHandle, int speed, int factor, int limit, int xoff, int yoff);*/
   1431                     break;
   1432                 }
   1433                 case 4:  /*Contrast*/
   1434                 {
   1435                     error = VPP_SetContrast(pHandle, feature_param[0]);
   1436                     printf("VPPTEST:: Selected Contrast (Video Gain) Feature\n");
   1437                     break;
   1438                 }
   1439                 case 5: /*Frosted Glass Overlay Effect*/
   1440                 {
   1441                     error = VPP_FrostedGlassEffect(pHandle, Isoverlay);
   1442                     printf("VPPTEST:: Selected Frosted Glass Overlay Effect\n");
   1443                     break;
   1444                 }
   1445                 case 6: /*Cropping*/
   1446                 {
   1447                     error = VPP_SetCrop(pHandle, feature_param[0], feature_param[1], feature_param[2], feature_param[3]);
   1448               printf("VPPTEST:: Selected cropping Feature\n");
   1449                     break;
   1450                 }
   1451                 case 7: /*Mirroring*/
   1452                 {
   1453                     error = VPP_SetMirroring(pHandle,IsYUVRGB);
   1454                     printf("VPPTEST:: Selected Mirroring Feature\n");
   1455                     break;
   1456                 }
   1457                 case 8 : /*RotationAngle*/
   1458                 {
   1459                     error = VPP_SetRotationAngle(pHandle, IsYUVRGB,feature_param[0]);
   1460                     printf("VPPTEST:: Selected Rotation Feature\n");
   1461                     break;
   1462                 }
   1463                 case 9: /*Dithering*/
   1464                 {
   1465                     error = VPP_SetDithering(pHandle,IsYUVRGB);
   1466                     printf("VPPTEST:: Selected Dithering Feature\n");
   1467                     break;
   1468 
   1469                 }
   1470 
   1471                 case 10:  /*Color Range Conversion*/
   1472                     {
   1473                         error=VPP_SetColorRange(pHandle,feature_param[0]);
   1474                         printf("VPPTEST:: Selected Color Range\n");
   1475                         break;
   1476                     }
   1477 
   1478 
   1479                 default:
   1480                 {   error = OMX_ErrorBadParameter;
   1481                     printf("VPPTEST:: Not a valid Option on Feature Selection\n");
   1482                     break;
   1483                 }
   1484             }
   1485 
   1486             if (error != OMX_ErrorNone)
   1487             {
   1488                 error = OMX_ErrorBadParameter;
   1489                 goto EXIT;
   1490             }
   1491 
   1492             APP_DPRINT ("Basic Function:: Sending OMX_StateExecuting Command\n");
   1493             error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateExecuting, NULL);
   1494             if(error != OMX_ErrorNone) {
   1495                 fprintf (stderr,"VPPTEST:: Error from SendCommand-Executing State function\n");
   1496                 goto EXIT;
   1497             }
   1498             pComponent = (OMX_COMPONENTTYPE *)pHandle;
   1499 
   1500 
   1501             error = WaitForState(pHandle, OMX_StateExecuting);
   1502             if(error != OMX_ErrorNone) {
   1503                 fprintf(stderr, "VPPTEST:: Error:  VPP->WaitForState reports an error %X\n", error);
   1504                 goto EXIT;
   1505             }
   1506             printf("VPPTEST:: Component is now in Executing state\n");
   1507             state = OMX_StateExecuting;
   1508 
   1509             if(Isoverlay){
   1510                 fInOvelay = fopen(overlaystring, "r");
   1511                 if (!fInOvelay)
   1512                 {
   1513                     fprintf(stderr, "Error:  failed to open the file %s for readonly access\n", overlaystring);
   1514                     goto EXIT;
   1515                 }
   1516             }
   1517 #ifndef UNDER_CE
   1518                     /*PROFILE POINT */
   1519                     gettimeofday(&base, NULL);
   1520                     newer.tv_sec = base.tv_sec;
   1521                     newer.tv_usec = base.tv_usec;
   1522                     APP_DPRINT("sec: %ld, usec: %ld\n", base.tv_sec, base.tv_usec);
   1523                     /*profiletime = GetProfiletime());*/
   1524 #endif
   1525             for(nCounter=0; nCounter<MAX_VPP_BUFFERS_IN_USE; nCounter++){ /*MultiBuffer*/
   1526                 /*Send Input Buffers to the Component */
   1527                 /*Provided that at least one frame will be read*/
   1528                 nRead = fill_data (InputBufHeader[nCounter],fIn);
   1529                 if(nRead == 0){
   1530                     APP_DPRINT("There is no data on input file\n");
   1531                     break; /*If there is no data send no more buffers to the component*/
   1532                             /*Exit for loop*/
   1533                 }
   1534                 else{
   1535                     ++iCurrentFrameIn;
   1536                     error = OMX_EmptyThisBuffer(pHandle, InputBufHeader[nCounter]);  /*INPUT port*/
   1537                     if (error != OMX_ErrorNone) {
   1538                         printf ("VPPTEST:: Error from OMX_EmptyThisBuffer function 0x%X\n",error);
   1539                         goto EXIT;
   1540                     }
   1541                 }
   1542 
   1543                 if(Isoverlay)   /*OVERLAY PORT*/{
   1544 #ifdef UNDER_CE
   1545                     fInOvelay = CreateFile(overlaystring, GENERIC_READ, 0,
   1546                                           NULL,OPEN_EXISTING, 0, NULL);
   1547                     if(fInOvelay == INVALID_HANDLE_VALUE){
   1548                         APP_DPRINT("Error:  failed to open the file %s for readonly\
   1549                                 access\n", fInOvelay);
   1550                         goto EXIT;
   1551                     }
   1552 #else
   1553                     fseek(fInOvelay, 0L, SEEK_SET);
   1554                     nRead = fill_data (OvlyBufHeader[nCounter],fInOvelay);
   1555                     if (nRead < (DEFAULT_WIDTH * DEFAULT_HEIGHT)* 3){
   1556                         printf("VPPTEST:: Error in fread for overlay, not enough data\n");
   1557                     }
   1558                     ++iCurrentOvlyFrameIn;
   1559                     error = OMX_EmptyThisBuffer(pHandle, OvlyBufHeader[nCounter]);  /*OVERLAY port*/
   1560                     if (error != OMX_ErrorNone) {
   1561                         printf ("VPPTEST:: Error from OMX_EmptyThisBuffer function 0x%X\n",error);
   1562                         goto EXIT;
   1563                     }
   1564                 }
   1565         #endif
   1566                 if(IsYUVRGB){  /*Send RGB output buffers to component*/
   1567                     OutRGBBufHeader[nCounter]->nFilledLen=0;
   1568                     error = OMX_FillThisBuffer(pHandle,OutRGBBufHeader[nCounter]);
   1569                     if (error != OMX_ErrorNone){
   1570                         printf ("VPPTEST:: Error from OMX_FillThisBuffer function 0x%X\n",error);
   1571                         goto EXIT;
   1572                     }
   1573                     nFillThisBufferRGB++;
   1574                 }
   1575                 if(IsYUVRGB==0 || IsYUVRGB ==2){  /*Send YUV output buffers to component*/
   1576                     OutYUVBufHeader[nCounter]->nFilledLen=0;
   1577                     error = OMX_FillThisBuffer(pHandle,OutYUVBufHeader[nCounter]);
   1578                     if (error != OMX_ErrorNone) {
   1579                         printf ("VPPTEST:: Error from OMX_FillThisBuffer function 0x%X\n",error);
   1580                         goto EXIT;
   1581                     }
   1582                     nFillThisBufferYUV++;
   1583                 }
   1584             }  /*end of for*/
   1585 
   1586         /**************************************************************************/
   1587 
   1588             nRead = 0;
   1589             done = 0;
   1590             frmCount = 0;
   1591             OMX_STATETYPE MyState;
   1592 
   1593             MyState = OMX_StateExecuting;
   1594             DEINIT_FLAG = OMX_FALSE;
   1595             while ((error == OMX_ErrorNone ) && (MyState != OMX_StateIdle)) {
   1596                 FD_ZERO(&rfds);
   1597                 FD_SET(IpBuf_Pipe[0], &rfds);
   1598                 FD_SET(OvlyBuf_Pipe[0],&rfds);
   1599                 FD_SET(OpRGBBuf_Pipe[0], &rfds);
   1600                 FD_SET(OpYUVBuf_Pipe[0],&rfds);
   1601                 FD_SET(Event_Pipe[0],&rfds);
   1602                 sigemptyset(&set) ;
   1603                 sigaddset(&set, SIGALRM);
   1604 
   1605                 retval = pselect(fdmax+1, &rfds, NULL, NULL, NULL,&set);
   1606                 if(retval == -1) {
   1607 #ifndef UNDER_CE
   1608                     perror("select()");
   1609 #endif
   1610                     fprintf (stderr, "VPPTEST:: : Error \n");
   1611                     break;
   1612                 }
   1613 
   1614                 if(retval == 0) {
   1615                     APP_DPRINT("\n\n\n%d ::!!!!!!!     App Timeout !!!!!!!!!!! \n",__LINE__);
   1616                     APP_DPRINT("%d :: ---------------------------------------\n\n\n",__LINE__);
   1617                     if(++nTimeouts>5){
   1618                         APP_DPRINT("VPPTEST:: No more data from Component\n");
   1619                         APP_DPRINT("VPPTEST:: Inputs=%d, Ovlys=%d, OutRGBs=%d,OutYUVs=%d\n",
   1620                                     iCurrentFrameIn, iCurrentOvlyFrameIn,
   1621                                     iCurrentRGBFrameOut,iCurrentYUVFrameOut);
   1622                         error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
   1623                         if(error != OMX_ErrorNone) {
   1624                             fprintf (stderr,"VPPTEST:: Error from SendCommand-Idle(Init) State function\n");
   1625                             goto EXIT;
   1626                         }
   1627                         error = WaitForState(pHandle, OMX_StateIdle);
   1628                         if(error != OMX_ErrorNone) {
   1629                             printf("VPPTEST:: Error:  hVPP->WaitForState has timed out %X", error);
   1630                             goto EXIT;
   1631                         }
   1632                         APP_DPRINT("VPP has been set in Idle State now\n");
   1633                         APP_DPRINT("Error on %s-->%s\n",szInFile,szOutFile);
   1634                         MyState = OMX_StateIdle;
   1635                     }
   1636                 }
   1637                 /**
   1638                 * If FD_ISSET then there is data available in the pipe.
   1639                 * Read it and get the buffer data out.
   1640                 * Then re-fill the buffer and send it back.
   1641                 **/
   1642                 if ( FD_ISSET(Event_Pipe[0], &rfds)) {
   1643                     EVENT_PRIVATE EventPrivate;
   1644                     read(Event_Pipe[0], &EventPrivate, sizeof(EVENT_PRIVATE));
   1645                     switch(EventPrivate.eEvent) {
   1646                         case OMX_EventError:
   1647                             DEINIT_FLAG = OMX_TRUE;
   1648                             bError = OMX_TRUE;
   1649                             printf("APP:: Waiting for OMX_StateInvalid... \n");
   1650                             WaitForState(pHandle, OMX_StateInvalid);
   1651                             printf("APP:: At Invalid state.\n");
   1652                             goto EXIT;
   1653                             break;
   1654 
   1655                         case OMX_EventBufferFlag:
   1656                             printf("APP:: Unloading component...\n");
   1657                             break;
   1658 
   1659                         default:
   1660                             break;
   1661                     }
   1662                 }
   1663 
   1664                 if(bPauseResume && !(iCurrentFrameIn%20)){
   1665                     printf("VPPTEST:: Pausing the component at %d Frames\n",iCurrentFrameIn);
   1666                     error=OMX_SendCommand(pHandle,OMX_CommandStateSet,OMX_StatePause,NULL);
   1667                     if(error!=OMX_ErrorNone){
   1668                         fprintf(stderr,"VPPTEST:: Error from SendCommand-Pause State Function\n");
   1669                         goto EXIT;
   1670                     }
   1671                     error = WaitForState(pHandle,OMX_StatePause);
   1672                     if(error !=OMX_ErrorNone){
   1673                         printf("VPPTEST:: Error: hVPP->WaitForState has timed out %X", error);
   1674                         goto EXIT;
   1675                     }
   1676                     printf("VPPTEST:: Sleeping the component for 2 seconds in Pause\n");
   1677                     sleep(2);
   1678                     error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
   1679                     if(error != OMX_ErrorNone) {
   1680                         fprintf (stderr,"Error from SendCommand-Executing State function\n");
   1681                         goto EXIT;
   1682                     }
   1683                     error = WaitForState(pHandle, OMX_StateExecuting);
   1684                     if(error != OMX_ErrorNone) {
   1685                         printf("VPPTEST:: Error:  hVPP->WaitForState has timed out %X", error);
   1686                         goto EXIT;
   1687                     }
   1688                     printf("VPPTEST:: Component is Executing again\n");
   1689 
   1690                 }
   1691 
   1692                 if(bStopExit && !(iCurrentFrameIn%43)){ /*Stopping to get an output file of 40 frames jesa*/
   1693                     printf("VPPTEST:: Stopping at output YUV frame %d and exiting\n", iCurrentYUVFrameOut);
   1694                     if( FD_ISSET(IpBuf_Pipe[0], &rfds) ) {
   1695                         read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
   1696                     }
   1697                     if( FD_ISSET(OvlyBuf_Pipe[0], &rfds) ) {
   1698                         read(OvlyBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
   1699                     }
   1700                     if( FD_ISSET(OpRGBBuf_Pipe[0], &rfds) ) {
   1701                         read(OpRGBBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
   1702                     }
   1703                     if( FD_ISSET(OpYUVBuf_Pipe[0], &rfds) ) {
   1704                         read(OpYUVBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
   1705                     }
   1706                     fprintf(stderr, "VPPTEST:: Shutting down ---------- \n");
   1707                     APP_DPRINT("Number of Processed Frames: Input=%d, Overlay=%d, RGB=%d, YUV=%d\n",
   1708                                 iCurrentFrameIn,iCurrentOvlyFrameIn,iCurrentRGBFrameOut,iCurrentYUVFrameOut);
   1709                     APP_DPRINT("Number of frames received: Input=%d, Overlay=%d, RGB=%d, YUV=%d\n",
   1710                                 nInputEmptyBufferDones, nOvlyEmptyBufferDones, nRGBFillBufferDones, nYUVFillBufferDones);
   1711                     APP_DPRINT("Number of sent Buffers: Input=%d, Overlay=%d, RGB=%d, YUV=%d\n",
   1712                                 iCurrentFrameIn,iCurrentOvlyFrameIn, nFillThisBufferRGB, nFillThisBufferYUV);
   1713                     DEINIT_FLAG = 1;
   1714                 }
   1715 
   1716                 if( FD_ISSET(IpBuf_Pipe[0], &rfds) ) {
   1717                     read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
   1718                     portinput = pBuffer->pInputPortPrivate;
   1719                     APP_DPRINT("%d ::App: Read from IpBuf_Pipe InBufHeader %p\n",
   1720                                                                  __LINE__,pBuffer);
   1721                     frmCount++;
   1722 
   1723                     if (!done) {
   1724 
   1725                         APP_DPRINT("%d ::reading INPUT DATA file \n",
   1726                                                                    __LINE__);
   1727                         /*If buffer corresponds to Input Port*/
   1728                         nRead = fill_data (pBuffer,fIn);
   1729                         APP_DPRINT(" ::reading INPUT DATA file pBuffer->nAllocLen %d    read=%d\n",
   1730                                                                   pBuffer->nAllocLen,nRead);
   1731                         if((nRead < pBuffer->nAllocLen) && (done == 0)){
   1732                             fprintf(stderr, "VPPTEST:: Shutting down ---------- \n");
   1733                             APP_DPRINT("Number of Processed Frames: Input=%d, Overlay=%d, RGB=%d, YUV=%d\n",
   1734                                         iCurrentFrameIn,iCurrentOvlyFrameIn,iCurrentRGBFrameOut,iCurrentYUVFrameOut);
   1735                             APP_DPRINT("Number of frames received: Input=%d, Overlay=%d, RGB=%d, YUV=%d\n",
   1736                                         nInputEmptyBufferDones, nOvlyEmptyBufferDones, nRGBFillBufferDones, nYUVFillBufferDones);
   1737                             APP_DPRINT("Number of sent Buffers: Input=%d, Overlay=%d, RGB=%d, YUV=%d\n",
   1738                                     iCurrentFrameIn,iCurrentOvlyFrameIn, nFillThisBufferRGB, nFillThisBufferYUV);
   1739                             done = 1;
   1740                             DEINIT_FLAG = 1;
   1741                             pBuffer->nFlags = OMX_BUFFERFLAG_EOS;
   1742                          }
   1743                         else{
   1744                             ++iCurrentFrameIn;
   1745                             pBuffer->nFilledLen = nRead;
   1746                             pComponent->EmptyThisBuffer(pHandle,pBuffer);
   1747                             APP_DPRINT("%d :: App: Sent Filled Input Buffer to Comp\n",__LINE__);
   1748                         }
   1749                     }
   1750                 }
   1751 
   1752                 if(FD_ISSET(OvlyBuf_Pipe[0],&rfds) ){
   1753                     APP_DPRINT("%d ::reading OVERLAY DATA file \n",
   1754                                                          __LINE__);
   1755             /*Read and process Overlay Pipe, only if Input Pipe has been processed already*/
   1756                     if(iCurrentOvlyFrameIn<iCurrentFrameIn){
   1757                         read(OvlyBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
   1758 #ifdef UNDER_CE
   1759                         fInOvelay = CreateFile(overlaystring, GENERIC_READ, 0,
   1760                                                   NULL,OPEN_EXISTING, 0, NULL);
   1761                         if( fInOvelay == INVALID_HANDLE_VALUE ){
   1762                             APP_DPRINT("Error:  failed to open the file %s for readonly\
   1763                                         access\n", fInOvelay);
   1764                                         goto EXIT;
   1765                         }
   1766 #else
   1767                         fseek(fInOvelay, 0L, SEEK_SET);
   1768                         nRead = fill_data(pBuffer,fInOvelay);
   1769                         if (nRead < (DEFAULT_WIDTH * DEFAULT_HEIGHT)* 3){
   1770                                 printf("VPPTEST:: Error in fread for overlay, not enough data\n");
   1771                         }
   1772 #endif
   1773 
   1774 #ifdef UNDER_CE
   1775                         CloseHandle(fInOvelay);
   1776 #else
   1777 
   1778 #endif
   1779                         ++iCurrentOvlyFrameIn;
   1780                         pBuffer->nFilledLen = nRead;
   1781                         pComponent->EmptyThisBuffer(pHandle,pBuffer);
   1782                         APP_DPRINT("%d :: App: Sent Filled Overlay Buffer to Comp\n",__LINE__);
   1783                     }/*end if(iCurrentOvlyFrameIn<iCurrentFrameIn)*/
   1784                 } /*end if(FD_ISSET(OvlyBuf_Pipe[0],&rfds) */
   1785 
   1786                 if(FD_ISSET(OpRGBBuf_Pipe[0], &rfds) ) {
   1787                     /*Only read and process RGB Output pipe if Input Pipe
   1788                         has been processed first*/
   1789                     if(iCurrentRGBFrameOut<iCurrentFrameIn){
   1790                         read(OpRGBBuf_Pipe[0], &pBuf, sizeof(pBuf));
   1791                         APP_DPRINT("%d ::App: Read from OpBuf_Pipe OutBufHeader %p\n", __LINE__,pBuf);
   1792                         ++iCurrentRGBFrameOut;
   1793                         if (pBuf->nAllocLen != pBuf->nFilledLen ) {
   1794                             if(pBuf->nFilledLen==0) printf("* WARNING: Frame has been lost (pBuf->nFilledLen is 0)\n");
   1795                            APP_DPRINT("%d : WARNING: Different Size, %ld\n",__LINE__, pBuf->nFilledLen);
   1796                         }
   1797                         else{
   1798 #ifdef UNDER_CE
   1799                             WriteFile(fOut, pBuf->pBuffer, pBuf->nFilledLen, &dwWritten, NULL);
   1800 #else
   1801                 fwrite(pBuf->pBuffer, 1, pBuf->nFilledLen, fOut);
   1802 #endif
   1803 
   1804                             /*Send the same number of Output buffers than Input buffers*/
   1805                             if(nFillThisBufferRGB<iCurrentFrameIn){
   1806                                 pComponent->FillThisBuffer(pHandle,pBuf);
   1807                                 nFillThisBufferRGB++;
   1808                             }
   1809                         }
   1810                     }/*end if((iCurrentRGBFrameOut<iCurrentFrameIn)*/
   1811                 } /*end of FD_ISSET(OpRGBBuf_Pipe[0], &rfds)*/
   1812 
   1813                 if(FD_ISSET(OpYUVBuf_Pipe[0], &rfds) ) {
   1814                     /*Read and Process Output YUV Pipe, only if Input Pipe has
   1815                     been read and processed first */
   1816                     if(iCurrentYUVFrameOut < iCurrentFrameIn){
   1817                         read(OpYUVBuf_Pipe[0], &pBuf, sizeof(pBuf));
   1818                         APP_DPRINT("%d ::App: Read from OpYUVBuf_Pipe OutBufHeader %p\n", __LINE__,pBuf);
   1819                         ++iCurrentYUVFrameOut;
   1820                         if (pBuf->nAllocLen != pBuf->nFilledLen ) {
   1821                              if(pBuf->nFilledLen==0) printf("* WARNING: Frame has been lost (pBuf->nFilledLen is 0)\n");
   1822                             APP_DPRINT("%d : WARNING: Different Size, %ld\n",__LINE__, pBuf->nFilledLen);
   1823                         }
   1824                         else{
   1825 
   1826 #ifdef UNDER_CE
   1827                             WriteFile(fOut, pBuf->pBuffer, pBuf->nFilledLen, &dwWritten, NULL);
   1828 #else
   1829             fwrite(pBuf->pBuffer, 1, pBuf->nFilledLen, fYuvOut);
   1830 #endif
   1831 
   1832                     /*Send the same number of output buffers than input buffers
   1833                      to the component*/
   1834                             if(nFillThisBufferYUV<iCurrentFrameIn){
   1835                                 pComponent->FillThisBuffer(pHandle,pBuf);
   1836                                 nFillThisBufferYUV++;
   1837                             }
   1838                         }
   1839 
   1840                     }/*end if(iCurrentYUVFrameOut < iCurrentFrameIn)*/
   1841                     APP_DPRINT("%d :: App: %ld bytes are being written\n",__LINE__,(pBuf->nFilledLen/4));
   1842 
   1843                 }/*end if (FD_ISSET(OpYUVBuf_Pipe[0], &rfds)*/
   1844 
   1845                     if (DEINIT_FLAG &&
   1846                         ((iCurrentFrameIn == iCurrentRGBFrameOut) ||
   1847                         (iCurrentFrameIn == iCurrentYUVFrameOut) ||
   1848                         (bStopExit)
   1849                         )){
   1850                         APP_DPRINT("Read full file!!!\n");
   1851                         done = 1;
   1852                         error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);
   1853                         if(error != OMX_ErrorNone) {
   1854                             fprintf (stderr,"Error from SendCommand-Idle(Stop) State function\n");
   1855                             goto EXIT;
   1856                         }
   1857                         APP_DPRINT("Waiting for OMX_StateIdle... \n");
   1858                         error = WaitForState(pHandle, OMX_StateIdle);
   1859                         if(error != OMX_ErrorNone) {
   1860                             APP_DPRINT("Error:  VPP->WaitForState has timed out %X",
   1861                                 error);
   1862                             goto EXIT;
   1863                         }
   1864                     }/*end of if DEINIT_FLAG*/
   1865 
   1866 
   1867                 if(done == 1) {
   1868                     error = pComponent->GetState(pHandle, &state);
   1869                     if(error != OMX_ErrorNone) {
   1870                         fprintf(stderr, "Warning:  VPP->GetState has returned status %X\n", error);
   1871                         goto EXIT;
   1872                     }
   1873                 }
   1874             OMX_GetState(pHandle, &MyState);
   1875 
   1876             }
   1877             APP_DPRINT("VPPTESTDEBUG::Exiting While loop, closing all the file handles\n");
   1878             APP_DPRINT("Number of Processed Frames: Input=%d, Overlay=%d, RGB=%d, YUV=%d\n",
   1879                             iCurrentFrameIn,iCurrentOvlyFrameIn,iCurrentRGBFrameOut,iCurrentYUVFrameOut);
   1880             printf("VPPTEST:: Component is now in Idle State\n");
   1881 #ifdef UNDER_CE
   1882             CloseHandle(fIn);
   1883             if(IsYUVRGB )
   1884                 CloseHandle(fOut);
   1885             if(IsYUVRGB ==0 || IsYUVRGB ==2)
   1886                 CloseHandle(fYuvOut);
   1887 #else
   1888             fclose(fIn);
   1889             if(IsYUVRGB)
   1890                 fclose(fOut);
   1891             if (Isoverlay)
   1892                 fclose(fInOvelay);
   1893             if(IsYUVRGB ==0 || IsYUVRGB ==2)
   1894             fclose(fYuvOut);
   1895 #endif
   1896             if(MyState == OMX_StateInvalid){
   1897                 break; /*to exit the Executing-->Idle-->Executing cicle*/
   1898             }
   1899         } /* Executing-->Idle-->Executing*/
   1900 
   1901     /***************************************************************************************************/
   1902         APP_DPRINT("Total processing time = %ld\n", nTotalTime);
   1903 
   1904         OMX_STATETYPE MyState;
   1905         OMX_GetState(pHandle, &MyState);
   1906 
   1907         if(MyState != OMX_StateInvalid){
   1908             APP_DPRINT ("%d :: App: State Of Component Is Idle Now\n",__LINE__);
   1909             APP_DPRINT("Sending the StateLoaded Command\n");
   1910             error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateLoaded, NULL);
   1911             if(error != OMX_ErrorNone) {
   1912                 fprintf (stderr,"Error from SendCommand-Idle State function\n");
   1913                 goto EXIT;
   1914             }
   1915             /*Disable the ports before freeing the buffers*/
   1916 
   1917             error = OMX_SendCommand(pHandle,OMX_CommandPortDisable, MyVppPortDef.input_port, NULL);
   1918             if(error != OMX_ErrorNone){
   1919                 APP_DPRINT("VPPTEST:: %d::Error from SendCommand-->PortDisable\n",__LINE__);
   1920                 goto EXIT;
   1921             }
   1922             if(Isoverlay){
   1923                 error = OMX_SendCommand(pHandle,OMX_CommandPortDisable, MyVppPortDef.overlay_port, NULL);
   1924                 if(error != OMX_ErrorNone){
   1925                     APP_DPRINT("VPPTEST:: %d::Error from SendCommand-->PortDisable\n",__LINE__);
   1926                     goto EXIT;
   1927                 }
   1928             }
   1929             if(IsYUVRGB){
   1930                 error = OMX_SendCommand(pHandle,OMX_CommandPortDisable,MyVppPortDef.rgboutput_port, NULL);
   1931                 if(error != OMX_ErrorNone){
   1932                     APP_DPRINT("VPPTEST:: %d::Error from SendCommand-->PortDisable\n",__LINE__);
   1933                     goto EXIT;
   1934                 }
   1935             }
   1936             if(IsYUVRGB==0 || IsYUVRGB==2){
   1937                 error = OMX_SendCommand(pHandle,OMX_CommandPortDisable,MyVppPortDef.yuvoutput_port, NULL);
   1938                 if(error != OMX_ErrorNone){
   1939                     APP_DPRINT("VPPTEST:: %d::Error from SendCommand-->PortDisable\n",__LINE__);
   1940                     goto EXIT;
   1941                 }
   1942             }
   1943         }
   1944         if(nTypeofAllocation == 1){
   1945             if(pInBuffer){
   1946                 free (pInBuffer);
   1947                 pInBuffer = NULL;
   1948             }
   1949             if(pYUVBuffer){
   1950                 free(pYUVBuffer);
   1951                 pYUVBuffer = NULL;
   1952             }
   1953             if(pRGBBuffer){
   1954                 free(pRGBBuffer);
   1955                 pYUVBuffer = NULL;
   1956             }
   1957         }
   1958         for(nCounter=0; nCounter<MAX_VPP_BUFFERS_IN_USE; nCounter++){  /* MultiBuffer*/
   1959             error = OMX_FreeBuffer(pHandle, MyVppPortDef.input_port, InputBufHeader[nCounter]) ;
   1960             if(error != OMX_ErrorNone) {
   1961                 printf("VPPTEST:: free buffer failed !!\n");
   1962                 goto EXIT;
   1963             }
   1964 
   1965             if(Isoverlay){
   1966             error = OMX_FreeBuffer(pHandle, MyVppPortDef.overlay_port, OvlyBufHeader[nCounter]);
   1967                 if(error != OMX_ErrorNone) {
   1968                     printf("VPPTEST:: OMX_FreeBuffer failed !!\n");
   1969                     goto EXIT;
   1970                 }
   1971             }
   1972 
   1973             if(IsYUVRGB)
   1974             {
   1975                 error = OMX_FreeBuffer(pHandle, MyVppPortDef.rgboutput_port, OutRGBBufHeader[nCounter]);
   1976                 if(error != OMX_ErrorNone) {
   1977                     printf("VPPTEST:: OMX_FreeBuffer failed !!\n");
   1978                     goto EXIT;
   1979                 }
   1980             }
   1981 
   1982             if(IsYUVRGB ==0 || IsYUVRGB ==2){
   1983                 error = OMX_FreeBuffer(pHandle, MyVppPortDef.yuvoutput_port, OutYUVBufHeader[nCounter]);
   1984                 if(error != OMX_ErrorNone) {
   1985                     printf("VPPTEST:: OMX_FreeBuffer failed !!\n");
   1986                     goto EXIT;
   1987                 }
   1988             }
   1989         }//end of for loop
   1990 
   1991         /* Wait for startup to complete */
   1992         error = WaitForState(pHandle, OMX_StateLoaded);
   1993         if((error != OMX_ErrorNone) && (error != OMX_ErrorInvalidState)){
   1994             fprintf(stderr, "Error:  VPP->WaitForState reports an error %X\n", error);
   1995             goto EXIT;
   1996         }
   1997         free(pCompPrivateStruct);   /*Free all m(allocated) resources to avoid memory leaks*/
   1998 
   1999         printf ("VPPTEST:: App: State Of Component Is Loaded Now\n");
   2000 
   2001        if(MyState == OMX_StateInvalid){
   2002             break; /*to exit for (count_stop_load ...) */
   2003        }
   2004 
   2005     }  /*end for(count_stop_load=0; count_stop_load<2; count_stop_load++)*/
   2006 
   2007 EXIT:
   2008 
   2009     printf ("VPPTEST:: Free the Component handle\n");
   2010     error = TIOMX_FreeHandle(pHandle);
   2011     if( (error != OMX_ErrorNone)) {
   2012         fprintf (stderr,"Error in Free Handle function\n");
   2013         goto EXIT;
   2014     }
   2015     fprintf (stderr,"Free Handle returned Successfully \n");
   2016 
   2017 #ifdef DSP_MMU_FAULT_HANDLING
   2018     if(bError) {
   2019         LoadBaseImage();
   2020     }
   2021 #endif
   2022 
   2023 
   2024         /* De-Initialize OMX Core */
   2025     error = TIOMX_Deinit();
   2026     if (error != OMX_ErrorNone) {
   2027         printf("VPPTEST:: Failed to de-init OMX Core!\n");
   2028         goto EXIT;
   2029     }
   2030 
   2031     if(error != OMX_ErrorNone){
   2032         if(pCompPrivateStruct){
   2033             free(pCompPrivateStruct);
   2034             pCompPrivateStruct = NULL;
   2035         }
   2036         if(pInBuffer){
   2037             pInBuffer -= 128;
   2038             free(pInBuffer);
   2039             pInBuffer = NULL;
   2040         }
   2041         if(pRGBBuffer){
   2042             pRGBBuffer -= 128;
   2043             free(pRGBBuffer);
   2044             pRGBBuffer = NULL;
   2045         }
   2046         if(pYUVBuffer){
   2047             pYUVBuffer -= 128;
   2048             free(pYUVBuffer);
   2049             pYUVBuffer = NULL;
   2050         }
   2051     }
   2052     return error;
   2053 }
   2054 
   2055 
   2056 
   2057 #ifndef UNDER_CE
   2058 int fill_data (OMX_BUFFERHEADERTYPE *pBuf, FILE *fIn)
   2059 #else
   2060 int fill_data (OMX_BUFFERHEADERTYPE *pBuf, HANDLE fIn)
   2061 #endif
   2062 {
   2063     int nRead;
   2064     static int totalRead = 0;
   2065     OMX_U8 *pTmp = NULL;
   2066     pTmp = pBuf->pBuffer;
   2067      APP_DPRINT(" :: ------------- before File Read -------------- %p\n",pBuf);
   2068      APP_DPRINT(" :: ------------- before File Read -------------- %d\n",pBuf->nAllocLen);
   2069      APP_DPRINT(" :: ------------- before File Read -------------- %p\n",pBuf->pBuffer);
   2070 #ifndef UNDER_CE
   2071     nRead = fread(pBuf->pBuffer, 1, pBuf->nAllocLen, fIn);
   2072 #else
   2073     ReadFile(fIn, pBuf->pBuffer, pBuf->nAllocLen, &nRead, NULL);
   2074 #endif
   2075     APP_DPRINT("\n%d :: ------------- App File Read --------------\n",__LINE__);
   2076     APP_DPRINT ("App: Read %d bytes from file\n", nRead);
   2077     APP_DPRINT ("App: pBuf->nAllocLen = %ld\n",pBuf->nAllocLen);
   2078     APP_DPRINT("%d :: ------------- App File Read --------------\n\n",__LINE__);
   2079 
   2080     pBuf->nFilledLen = nRead;
   2081     totalRead += nRead;
   2082     return nRead;
   2083 }
   2084 
   2085 
   2086 
   2087 static OMX_ERRORTYPE VPP_SetZoom(OMX_HANDLETYPE pHandle, int speed, int factor, int limit, int xoff, int yoff)
   2088 {
   2089     int nZoomSpeed = speed;
   2090     int nZoomFactor = factor<<10;
   2091     int nZoomLimit = limit<<10;
   2092     int nXoff = xoff<<4;
   2093     int nYoff=yoff<<4;
   2094 
   2095     OMX_ERRORTYPE error = OMX_ErrorNone;
   2096 
   2097     error = OMX_SetConfig (pHandle, MyVPPCustomDef.VPPCustomSetZoomFactor, &nZoomFactor);
   2098     if(error != OMX_ErrorNone){
   2099         fprintf(stderr,"Error configuring Zoom Factor\n");
   2100         return error;
   2101     }
   2102     error = OMX_SetConfig (pHandle,MyVPPCustomDef.VPPCustomSetZoomSpeed,&nZoomSpeed);
   2103     if(error != OMX_ErrorNone){
   2104         fprintf(stderr,"Error configuring Zoom Factor\n");
   2105         return error;
   2106     }
   2107 
   2108     error = OMX_SetConfig (pHandle,MyVPPCustomDef.VPPCustomSetZoomLimit,&nZoomLimit);
   2109     if(error != OMX_ErrorNone){
   2110         fprintf(stderr,"Error configuring Zoom Limit/n");
   2111         return error;
   2112     }
   2113     error = OMX_SetConfig(pHandle,MyVPPCustomDef.VPPCustomSetZoomXoffsetFromCenter16,&nXoff);
   2114     if(error != OMX_ErrorNone){
   2115         fprintf(stderr,"Error Configuring Horizontal Zoom Offset\n.");
   2116         return error;
   2117     }
   2118     error = OMX_SetConfig(pHandle,MyVPPCustomDef.VPPCustomSetZoomYoffsetFromCenter16,&nYoff);
   2119     if(error != OMX_ErrorNone){
   2120         fprintf(stderr,"Error Configuring Vertical Zoom Offset");
   2121         return error;
   2122     }
   2123 
   2124     return error;
   2125 }
   2126 
   2127 
   2128 
   2129 static OMX_ERRORTYPE VPP_SetContrast(OMX_HANDLETYPE pHandle, int Contrast)
   2130 {
   2131     OMX_ERRORTYPE error = OMX_ErrorNone;
   2132     OMX_CONFIG_CONTRASTTYPE *pConfigNewContrast = malloc(sizeof(OMX_CONFIG_CONTRASTTYPE));
   2133     if(pConfigNewContrast == NULL){
   2134         error = OMX_ErrorInsufficientResources;
   2135         goto EXIT;
   2136     }
   2137     memset(pConfigNewContrast,0,sizeof(OMX_CONFIG_CONTRASTTYPE));
   2138     pConfigNewContrast->nContrast = Contrast;
   2139     error=OMX_SetConfig(pHandle,OMX_IndexConfigCommonContrast,pConfigNewContrast);
   2140     if(error != OMX_ErrorNone){
   2141         printf("VPPTEST:: VPPTest Error at %d\n",__LINE__);
   2142         error = OMX_ErrorBadParameter;
   2143         goto EXIT;
   2144     }
   2145 
   2146 EXIT:
   2147     if ( error != OMX_ErrorNone){
   2148         if(pConfigNewContrast){
   2149             free(pConfigNewContrast);
   2150             pConfigNewContrast = NULL;
   2151         }
   2152     }
   2153     return error;
   2154 }
   2155 
   2156 
   2157 
   2158 static OMX_ERRORTYPE VPP_FrostedGlassEffect(OMX_HANDLETYPE pHandle, int IsOverlay)
   2159 {
   2160     OMX_ERRORTYPE error = OMX_ErrorNone;
   2161 
   2162     if(IsOverlay){
   2163         int FrostedGlassEffect=1;
   2164         error=OMX_SetConfig(pHandle,MyVPPCustomDef.VPPCustomSetFrostedGlassOvly,&FrostedGlassEffect);
   2165         if(error != OMX_ErrorNone){
   2166             printf("VPPTEST:: VPPTest Error at %d\n",__LINE__);
   2167             error = OMX_ErrorBadParameter;
   2168             return error;
   2169         }
   2170     }
   2171     else{
   2172         printf("VPPTEST:: Frosted Glass Effect is only upon overlayed images.\n");
   2173         error=OMX_ErrorBadParameter;
   2174     }
   2175     return error;
   2176 }
   2177 
   2178 
   2179 
   2180 static OMX_ERRORTYPE VPP_SetCrop(OMX_HANDLETYPE pHandle, int XStart, int XSize, int YStart, int YSize)
   2181 {
   2182     OMX_ERRORTYPE error = OMX_ErrorNone;
   2183     OMX_CONFIG_RECTTYPE *pConfigNewCropWindow = malloc (sizeof(OMX_CONFIG_RECTTYPE));
   2184     if(pConfigNewCropWindow == NULL){
   2185         error = OMX_ErrorInsufficientResources;
   2186         goto EXIT;
   2187     }
   2188     memset(pConfigNewCropWindow, 0, sizeof(OMX_CONFIG_RECTTYPE));
   2189     pConfigNewCropWindow->nLeft   = XStart;
   2190     pConfigNewCropWindow->nTop    = YStart;
   2191     pConfigNewCropWindow->nWidth  = XSize;
   2192     pConfigNewCropWindow->nHeight = YSize;
   2193     error = OMX_SetConfig (pHandle, OMX_IndexConfigCommonInputCrop, pConfigNewCropWindow);
   2194     if (error != OMX_ErrorNone) {
   2195         printf("VPPTest Error at %d\n",__LINE__);
   2196         error = OMX_ErrorBadParameter;
   2197         goto EXIT;
   2198     }
   2199 
   2200 EXIT:
   2201     if(error != OMX_ErrorNone){
   2202         free(pConfigNewCropWindow);
   2203         pConfigNewCropWindow = NULL;
   2204     }
   2205     return error;
   2206 }
   2207 
   2208 static OMX_ERRORTYPE VPP_SetMirroring(OMX_HANDLETYPE pHandle, int IsRGBOutput)
   2209 {
   2210     OMX_ERRORTYPE error = OMX_ErrorNone;
   2211     OMX_CONFIG_MIRRORTYPE * pConfigNewMirror = NULL;
   2212     if(IsRGBOutput){
   2213         pConfigNewMirror = malloc(sizeof(OMX_CONFIG_MIRRORTYPE));
   2214         if(pConfigNewMirror == NULL){
   2215             error = OMX_ErrorInsufficientResources;
   2216             goto EXIT;
   2217         }
   2218         memset(pConfigNewMirror,0,sizeof(OMX_CONFIG_MIRRORTYPE));
   2219         pConfigNewMirror->nPortIndex = MyVppPortDef.rgboutput_port;
   2220         pConfigNewMirror->eMirror = OMX_MirrorHorizontal;
   2221         error=OMX_SetConfig(pHandle,OMX_IndexConfigCommonMirror,pConfigNewMirror);
   2222         if(error != OMX_ErrorNone){
   2223             printf("VPPTest Error at %d\n",__LINE__);
   2224             error = OMX_ErrorBadParameter;
   2225             goto EXIT;
   2226         }
   2227     }
   2228     else{
   2229         printf("VPPTEST:: Need to use RGB as Output, Mirror Setting unchanged.\n");
   2230         error=OMX_ErrorBadParameter;
   2231         goto EXIT;
   2232     }
   2233 EXIT:
   2234 
   2235     if(pConfigNewMirror){
   2236         free(pConfigNewMirror);
   2237         pConfigNewMirror = NULL;
   2238     }
   2239     return error;
   2240 }
   2241 
   2242 static OMX_ERRORTYPE VPP_SetRotationAngle(OMX_HANDLETYPE pHandle, int IsRGBOutput,int Angle)
   2243 {
   2244     OMX_ERRORTYPE error = OMX_ErrorNone;
   2245     OMX_CONFIG_ROTATIONTYPE *pConfigNewRotation = malloc(sizeof(OMX_CONFIG_ROTATIONTYPE));
   2246     if(pConfigNewRotation == NULL){
   2247         error = OMX_ErrorInsufficientResources;
   2248         goto EXIT;
   2249     }
   2250     memset(pConfigNewRotation,0,sizeof(OMX_CONFIG_ROTATIONTYPE));
   2251     if(Angle == 0 || Angle == 90 || Angle ==180 || Angle ==270){
   2252         pConfigNewRotation->nRotation = Angle;
   2253     }
   2254     else{
   2255         printf("VPPTEST:: Not a valid Rotation Angle, Working with Default Rotation Angle\n");
   2256         goto EXIT;
   2257     }
   2258 
   2259     switch(IsRGBOutput){
   2260         case 0:  /*YUV output only*/
   2261             pConfigNewRotation->nPortIndex = MyVppPortDef.yuvoutput_port;
   2262             error=OMX_SetConfig(pHandle,OMX_IndexConfigCommonRotate,pConfigNewRotation);
   2263             if(error != OMX_ErrorNone){
   2264                 printf("VPPTest Error at %d\n",__LINE__);
   2265                 error = OMX_ErrorBadParameter;
   2266                 goto EXIT;
   2267             }
   2268             break;
   2269         case 1: /*RGB output only*/
   2270             pConfigNewRotation->nPortIndex = MyVppPortDef.rgboutput_port;
   2271             error=OMX_SetConfig(pHandle,OMX_IndexConfigCommonRotate,pConfigNewRotation);
   2272             if(error != OMX_ErrorNone){
   2273                 printf("VPPTest Error at %d\n",__LINE__);
   2274                 error = OMX_ErrorBadParameter;
   2275                 goto EXIT;
   2276             }
   2277         case 2: /*Simultaneous outputs*/
   2278             pConfigNewRotation->nPortIndex = MyVppPortDef.rgboutput_port;
   2279             error=OMX_SetConfig(pHandle,OMX_IndexConfigCommonRotate,pConfigNewRotation);
   2280             if(error != OMX_ErrorNone){
   2281                 printf("VPPTest Error at %d\n",__LINE__);
   2282                 error = OMX_ErrorBadParameter;
   2283                 goto EXIT;
   2284             }
   2285             pConfigNewRotation->nPortIndex = MyVppPortDef.yuvoutput_port;
   2286             error=OMX_SetConfig(pHandle,OMX_IndexConfigCommonRotate,pConfigNewRotation);
   2287             if(error != OMX_ErrorNone){
   2288                 printf("VPPTest Error at %d\n",__LINE__);
   2289                 error = OMX_ErrorBadParameter;
   2290                 goto EXIT;
   2291             }
   2292             break;
   2293     default:
   2294         break;
   2295     }
   2296 EXIT:
   2297     if(pConfigNewRotation){
   2298         free(pConfigNewRotation);
   2299         pConfigNewRotation = NULL;
   2300     }
   2301     return error;
   2302 
   2303 }
   2304 
   2305 
   2306 
   2307 static OMX_ERRORTYPE VPP_SetDithering(OMX_HANDLETYPE pHandle, int IsRGBOutput)
   2308 {
   2309     OMX_ERRORTYPE error = OMX_ErrorNone;
   2310     OMX_CONFIG_DITHERTYPE * pConfigNewDither = NULL;
   2311 
   2312     if(IsRGBOutput){
   2313         pConfigNewDither = malloc(sizeof(OMX_CONFIG_DITHERTYPE));
   2314         if(pConfigNewDither == NULL){
   2315             error = OMX_ErrorInsufficientResources;
   2316             goto EXIT;
   2317         }
   2318         memset(pConfigNewDither,0,sizeof(OMX_CONFIG_DITHERTYPE));
   2319         pConfigNewDither->nPortIndex = MyVppPortDef.rgboutput_port;
   2320         pConfigNewDither->eDither = OMX_DitherErrorDiffusion;
   2321         error=OMX_SetConfig(pHandle,OMX_IndexConfigCommonDithering,pConfigNewDither);
   2322         if(error != OMX_ErrorNone){
   2323             printf("VPPTest Error at %d\n",__LINE__);
   2324             error = OMX_ErrorBadParameter;
   2325             goto EXIT;
   2326         }
   2327     }
   2328     else{
   2329         printf("VPPTEST:: Need to use RGB as Output, Dithering not possible.\n");
   2330         error=OMX_ErrorBadParameter;
   2331         goto EXIT;
   2332     }
   2333 
   2334 EXIT:
   2335 
   2336     if(pConfigNewDither){
   2337         free(pConfigNewDither);
   2338         pConfigNewDither = NULL;
   2339     }
   2340     return error;
   2341 }
   2342 
   2343 static OMX_ERRORTYPE VPP_SetColorRange(OMX_HANDLETYPE pHandle, int nColorRange)
   2344 {
   2345     OMX_ERRORTYPE error = OMX_ErrorNone;
   2346 
   2347     if(nColorRange<0 || nColorRange>3){
   2348         printf("VPPTEST:: Not a valid option in Color Range Conversion\n");
   2349         error = OMX_ErrorBadParameter;
   2350         return error;
   2351     }
   2352 
   2353     error=OMX_SetConfig(pHandle, MyVPPCustomDef.VPPCustomSetColorRange, &nColorRange);
   2354     if(error != OMX_ErrorNone){
   2355         printf("VPPTest Error at %d\n",__LINE__);
   2356         error = OMX_ErrorBadParameter;
   2357         return error;
   2358     }
   2359 
   2360 
   2361     return error;
   2362 }
   2363 
   2364 OMX_BOOL VPP_Test_Check_Frames(int YUVRGB, int inFrames, int OvlyFrames,int outRGBFrames,int outYUVFrames)
   2365 {
   2366     if(YUVRGB==0){
   2367         if(outYUVFrames < (inFrames-1) || outYUVFrames < (OvlyFrames-1))
   2368         {
   2369             return OMX_TRUE;
   2370         }
   2371         else{
   2372             return OMX_FALSE;
   2373             }
   2374     }
   2375     else if(YUVRGB==1){
   2376         if(outRGBFrames < (inFrames-1) || outRGBFrames < (OvlyFrames-1)){
   2377            return OMX_TRUE;
   2378         }
   2379         else{
   2380              return OMX_FALSE;
   2381              }
   2382       }
   2383       else{
   2384             if( (outRGBFrames < (inFrames-1) || outRGBFrames < (OvlyFrames-1)) ||
   2385                 (outYUVFrames < (inFrames-1) || outYUVFrames < (OvlyFrames-1))){
   2386            return OMX_TRUE;
   2387         }
   2388         else{
   2389             return OMX_FALSE;
   2390         }
   2391     }
   2392 }
   2393 
   2394 #ifdef DSP_MMU_FAULT_HANDLING
   2395 
   2396 int LoadBaseImage() {
   2397     unsigned int uProcId = 0;	/* default proc ID is 0. */
   2398     unsigned int index = 0;
   2399 
   2400     struct DSP_PROCESSORINFO dspInfo;
   2401     DSP_HPROCESSOR hProc;
   2402     DSP_STATUS status = DSP_SOK;
   2403     unsigned int numProcs;
   2404     char* argv[2];
   2405 
   2406     argv[0] = "/lib/dsp/baseimage.dof";
   2407 
   2408     status = (DBAPI)DspManager_Open(0, NULL);
   2409     if (DSP_FAILED(status)) {
   2410         printf("DSPManager_Open failed \n");
   2411         return -1;
   2412     }
   2413     while (DSP_SUCCEEDED(DSPManager_EnumProcessorInfo(index,&dspInfo,
   2414         (unsigned int)sizeof(struct DSP_PROCESSORINFO),&numProcs))) {
   2415         if ((dspInfo.uProcessorType == DSPTYPE_55) ||
   2416             (dspInfo.uProcessorType == DSPTYPE_64)) {
   2417             uProcId = index;
   2418             status = DSP_SOK;
   2419             break;
   2420         }
   2421         index++;
   2422     }
   2423     status = DSPProcessor_Attach(uProcId, NULL, &hProc);
   2424     if (DSP_SUCCEEDED(status)) {
   2425         status = DSPProcessor_Stop(hProc);
   2426         if (DSP_SUCCEEDED(status)) {
   2427             status = DSPProcessor_Load(hProc,1,(const char **)argv,NULL);
   2428             if (DSP_SUCCEEDED(status)) {
   2429                 status = DSPProcessor_Start(hProc);
   2430                 if (DSP_SUCCEEDED(status)) {
   2431                 }
   2432                 else {
   2433                 }
   2434             }
   2435 			else {
   2436             }
   2437             DSPProcessor_Detach(hProc);
   2438         }
   2439         else {
   2440         }
   2441     }
   2442     else {
   2443     }
   2444     fprintf(stderr,"Baseimage Loaded\n");
   2445 
   2446     return 0;
   2447 }
   2448 #endif
   2449 
   2450 
   2451