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 /* =============================================================================
     18  *             Texas Instruments OMAP (TM) Platform Software
     19  *  (c) Copyright Texas Instruments, Incorporated.  All Rights Reserved.
     20  *
     21  *  Use of this software is controlled by the terms and conditions found
     22  *  in the license agreement under which this software has been supplied.
     23  * =========================================================================== */
     24 /**
     25  * @file G711DecTest.c
     26  *
     27  * This file contains the test application code that invokes the component.
     28  *
     29  * @path  $(CSLPATH)\OMAPSW_MPU\linux\audio\src\openmax_il\g711\tests
     30  *
     31  * @rev  1.0
     32  */
     33 /* ----------------------------------------------------------------------------
     34  *!
     35  *! Revision History
     36  *! ===================================
     37  *! 14-dec-2006 sc: creation
     38  * =========================================================================== */
     39 
     40 
     41 /* standard header files */
     42 #include <unistd.h>
     43 #include <stdlib.h>
     44 #include <sys/ioctl.h>
     45 #include <sys/select.h>
     46 #include <string.h>
     47 #include <stdio.h>
     48 #include <fcntl.h>
     49 #include <errno.h>
     50 #include <linux/vt.h>
     51 #include <signal.h>
     52 #include <sys/stat.h>
     53 #include <pthread.h>
     54 #include <stdio.h>
     55 #include <linux/soundcard.h>
     56 
     57 /* OMX header files */
     58 #include <OMX_Index.h>
     59 #include <OMX_Types.h>
     60 #include <OMX_Component.h>
     61 #include <OMX_Core.h>
     62 #include <OMX_Audio.h>
     63 #include <TIDspOmx.h>
     64 
     65 
     66 #ifdef OMX_GETTIME
     67 #include <OMX_Common_Utils.h>
     68 #include <OMX_GetTime.h>     /*Headers for Performance & measuremet    */
     69 #endif
     70 
     71 /* ======================================================================= */
     72 /**
     73  * @def APP_DEBUG Configure Debug traces
     74  */
     75 /* ======================================================================= */
     76 #undef APP_DEBUG
     77 /*For timestamp and tickcount*/
     78 #undef APP_TIME_TIC_DEBUG
     79 /* ======================================================================= */
     80 /**
     81  * @def APP_DEBUG Configure Debug traces
     82  */
     83 /* ======================================================================= */
     84 #undef APP_MEMCHECK
     85 /* ======================================================================= */
     86 /**
     87  * @def    APP_MEMDEBUG    This Macro turns On the logic to detec memory
     88  *                         leaks on the App. To debug the component,
     89  *                         WMADEC_MEMDEBUG must be defined.
     90  */
     91 /* ======================================================================= */
     92 #undef APP_MEMDEBUG
     93 
     94 void *arr[500] = {NULL};
     95 int lines[500]= {0};
     96 int bytes[500]= {0};
     97 char file[500][50]= {""};
     98 
     99 #ifdef APP_MEMDEBUG
    100 int r;
    101 #define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
    102 #define newfree(z) myfree(z,__LINE__,__FILE__)
    103 void * mymalloc(int line, char *s, int size);
    104 int myfree(void *dp, int line, char *s);
    105 #else
    106 #define newmalloc(x) malloc(x)
    107 #define newfree(z) free(z)
    108 #endif
    109 
    110 /* ======================================================================= */
    111 /**
    112  * @def  DASF                           Define a Value for DASF mode
    113  */
    114 /* ======================================================================= */
    115 #define DASF 1
    116 /* ======================================================================= */
    117 /**
    118  * @def  USE_BUFFER                 Buffer allocation method (app vs OMX)
    119  */
    120 /* ======================================================================= */
    121 #undef USE_BUFFER
    122 /* ======================================================================= */
    123 /**
    124  * @def  FIFO1, FIFO2                 FIFO
    125  */
    126 /* ======================================================================= */
    127 #define FIFO1 "/dev/fifo.1"
    128 #define FIFO2 "/dev/fifo.2"
    129 /* ======================================================================= */
    130 /**
    131  * @def  GAIN                      Define a GAIN value for Configure Audio
    132  */
    133 /* ======================================================================= */
    134 #define GAIN 95
    135 /* ======================================================================= */
    136 /**
    137  * @def    INPUT_G711DEC_BUFFER_SIZE             Standart Input Buffer Size
    138  *                                                (1 frame)
    139  */
    140 /* ======================================================================= */
    141 #define INPUT_G711DEC_BUFFER_SIZE 80
    142 /* ======================================================================= */
    143 /**
    144  * @def    OUTPUT_G711DEC_BUFFER_SIZE           Standart Output Buffer Size
    145  */
    146 /* ======================================================================= */
    147 #define OUTPUT_G711DEC_BUFFER_SIZE 160
    148 /* ======================================================================= */
    149 /**
    150  * @def    G711DEC_SAMPLING_FREQUENCY          Sampling Frequency
    151  */
    152 /* ======================================================================= */
    153 #define G711DEC_SAMPLING_FREQUENCY 8000
    154 /* ======================================================================= */
    155 /**
    156  * @def    G711_APP_ID          Application Id
    157  */
    158 /* ======================================================================= */
    159 #define G711_APP_ID 100
    160 /* ======================================================================= */
    161 /**
    162  * @def    G711_MAX_NUM_BUFS    Number of buffer
    163  */
    164 /* ======================================================================= */
    165 #define G711_MAX_NUM_BUFS 10
    166 /* ======================================================================= */
    167 /**
    168  *  MACROS used for debug
    169  */
    170 /* ======================================================================= */
    171 #ifdef APP_DEBUG
    172 #define APP_DPRINT(...)    fprintf(stderr,__VA_ARGS__)
    173 #else
    174 #define APP_DPRINT(...)
    175 #endif
    176 
    177 #ifdef APP_MEMCHECK
    178 #define APP_MEMPRINT(...)    fprintf(stderr,__VA_ARGS__)
    179 #else
    180 #define APP_MEMPRINT(...)
    181 #endif
    182 
    183 #ifdef APP_TIME_TIC_DEBUG
    184 #define TIME_PRINT(...)     fprintf(stderr,__VA_ARGS__)
    185 #define TICK_PRINT(...)     fprintf(stderr,__VA_ARGS__)
    186 #else
    187 #define TIME_PRINT(...)
    188 #define TICK_PRINT(...)
    189 #endif
    190 
    191 #ifdef OMX_GETTIME
    192 OMX_ERRORTYPE eError = OMX_ErrorNone;
    193 int GT_FlagE = 0;  /* Fill Buffer 1 = First Buffer,  0 = Not First Buffer  */
    194 int GT_FlagF = 0;  /*Empty Buffer  1 = First Buffer,  0 = Not First Buffer  */
    195 static OMX_NODE* pListHead = NULL;
    196 #endif
    197 
    198 /* ======================================================================= */
    199 /**
    200  *  PRIVATE functions
    201  */
    202 /* ======================================================================= */
    203 OMX_S16 GetInfoFromBufferHeader(OMX_U8 **pBufPtr, OMX_S16 *pCurBitRate,OMX_S16 *pNextBitRateFlag);
    204 void ResetBufferPointers(OMX_U8 **pBuffer);
    205 OMX_S16 maxint(OMX_S16 a, OMX_S16 b);
    206 OMX_S16 fill_data (OMX_BUFFERHEADERTYPE *pBuf, FILE *fIn);
    207 OMX_ERRORTYPE send_input_buffer (OMX_HANDLETYPE pHandle, OMX_BUFFERHEADERTYPE* pBuffer, FILE *fIn);
    208 void ConfigureAudio();
    209 
    210 /* ======================================================================= */
    211 /**
    212  *  GLOBAL variables
    213  */
    214 /* ======================================================================= */
    215 FILE *inputToSN = NULL;
    216 OMX_S16 inputPortDisabled = 0;
    217 OMX_S16 outputPortDisabled = 0;
    218 OMX_S16 alternate = 0;
    219 OMX_S16 numRead = 0;
    220 OMX_S16 testCaseNo = 0;
    221 OMX_STRING strG711Decoder = "OMX.TI.G711.decode";
    222 
    223 pthread_mutex_t WaitForState_mutex;
    224 pthread_cond_t  WaitForState_threshold;
    225 OMX_U8          WaitForState_flag = 0;
    226 OMX_U8          TargetedState = 0;
    227 
    228 /* pipe management */
    229 int IpBuf_Pipe[2] = {0};
    230 int OpBuf_Pipe[2] = {0};
    231 int Event_Pipe[2] = {0};
    232 fd_set rfds;
    233 static OMX_BOOL bInvalidState;
    234 OMX_S16 done = 0;
    235 OMX_S16 dasfmode = 0;
    236 OMX_S16 fsizemode = 0;
    237 /******************************************************************************/
    238 OMX_S16 numInputBuffers = 0;
    239 OMX_S16 numOutputBuffers = 0;
    240 #ifdef USE_BUFFER
    241 OMX_U8* pInputBuffer[10] = {NULL};
    242 OMX_U8* pOutputBuffer[10] = {NULL};
    243 #endif
    244 
    245 OMX_BUFFERHEADERTYPE* pInputBufferHeader[10]  = {NULL};
    246 OMX_BUFFERHEADERTYPE* pOutputBufferHeader[10] = {NULL};
    247 
    248 int timeToExit = 0;
    249 /* RM control */
    250 int preempted = 0;
    251 /******************************************************************************/
    252 
    253 
    254 /* ----------------------------------------------------------------------------
    255  * maxint()
    256  *
    257  * safe routine to get the maximum of 2 integers
    258  * ---------------------------------------------------------------------------- */
    259 OMX_S16 maxint(OMX_S16 a, OMX_S16 b)
    260 {
    261     return (a>b) ? a : b;
    262 }
    263 
    264 /* ----------------------------------------------------------------------------
    265  * WaitForState()
    266  *
    267  * This function is called by the application.
    268  * It blocks until the OMX component is not in the DesiredState
    269  * ---------------------------------------------------------------------------- */
    270 static OMX_ERRORTYPE WaitForState(OMX_HANDLETYPE* pHandle, OMX_STATETYPE DesiredState)
    271 {
    272     OMX_STATETYPE CurState = OMX_StateInvalid;
    273     OMX_ERRORTYPE eError = OMX_ErrorNone;
    274     OMX_S16 nCnt = 0;
    275     OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
    276     eError = pComponent->GetState(pHandle, &CurState);
    277 
    278     while( (eError == OMX_ErrorNone) && (CurState != DesiredState) && (eError == OMX_ErrorNone) ) {
    279         // sleep(1);
    280         if(nCnt++ == 10) {
    281             APP_DPRINT( "Still Waiting, press CTL-C to continue\n");
    282         }
    283         eError = pComponent->GetState(pHandle, &CurState);
    284     }
    285 
    286     if( eError != OMX_ErrorNone ) return eError;
    287     return OMX_ErrorNone;
    288 }
    289 
    290 /* ----------------------------------------------------------------------------
    291  * EventHandler()
    292  *
    293  * This function is called by OMX component as
    294  * a callback when one of the following OMX_EVENTS
    295  * occurs:
    296  *
    297  * OMX_EventCmdComplete,         component has sucessfully completed a command
    298  * OMX_EventError,               component has detected an error condition
    299  * OMX_EventMark,                component has detected a buffer mark
    300  * OMX_EventPortSettingsChanged, component is reported a port settings change
    301  * OMX_EventBufferFlag,          component has detected an EOS
    302  * OMX_EventResourcesAcquired,   component has been granted resources and is
    303  *                               automatically starting the state change from
    304  *                               OMX_StateWaitForResources to OMX_StateIdle.
    305  * ---------------------------------------------------------------------------- */
    306 OMX_ERRORTYPE EventHandler(OMX_HANDLETYPE hComponent,OMX_PTR pAppData,OMX_EVENTTYPE eEvent,
    307                            OMX_U32 nData1,OMX_U32 nData2,OMX_PTR pEventData)
    308 {
    309     OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)hComponent;
    310     OMX_STATETYPE state = OMX_StateInvalid;
    311     OMX_ERRORTYPE eError = OMX_ErrorNone;
    312     OMX_U8 writeValue = 0;
    313 
    314     eError = pComponent->GetState (hComponent, &state);
    315     APP_DPRINT("%d Error returned from GetState\n",__LINE__);
    316     if(eError != OMX_ErrorNone) {
    317         APP_DPRINT("%d :: App: Error returned from GetState\n",__LINE__);
    318     }
    319 
    320     switch (eEvent) {
    321     case OMX_EventResourcesAcquired:
    322         writeValue = 1;
    323         preempted = 0;
    324         write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
    325         APP_DPRINT( "%d :: App: Component OMX_EventResourcesAquired = %d\n", __LINE__,eEvent);
    326         break;
    327     case OMX_EventBufferFlag:
    328         writeValue = 2;
    329         write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
    330         printf( "%d :: App: Component OMX_EventBufferFlag = %d\n", __LINE__,eEvent);
    331         break;
    332     case OMX_EventCmdComplete:
    333         APP_DPRINT ( "%d :: App: Component State Changed To %d\n", __LINE__,state);
    334         if (nData1 == OMX_CommandPortDisable) {
    335             if (nData2 == OMX_DirInput) {
    336                 inputPortDisabled = 1;
    337             }
    338             APP_DPRINT( "%d :: App: Component OMX_EventCmdComplete = %d\n", __LINE__,eEvent);
    339             if (nData2 == OMX_DirOutput) {
    340                 outputPortDisabled = 1;
    341             }
    342             APP_DPRINT( "%d :: App: Component OMX_EventCmdComplete = %d\n", __LINE__,eEvent);
    343         }
    344         if ((nData1 == OMX_CommandStateSet) && (TargetedState == nData2) &&
    345             (WaitForState_flag)){
    346             WaitForState_flag = 0;
    347             pthread_mutex_lock(&WaitForState_mutex);
    348             pthread_cond_signal(&WaitForState_threshold);
    349             pthread_mutex_unlock(&WaitForState_mutex);
    350         }
    351         APP_DPRINT( "%d :: App: Component OMX_EventCmdComplete = %d\n", __LINE__,(int)nData2);
    352         break;
    353 
    354     case OMX_EventError:
    355         if (nData1 == OMX_ErrorInvalidState) {
    356             bInvalidState = OMX_TRUE;
    357         }
    358         else if(nData1 == OMX_ErrorResourcesPreempted) {
    359             writeValue = 0;
    360             preempted = 1;
    361             write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
    362         }
    363         else if (nData1 == OMX_ErrorResourcesLost) {
    364             WaitForState_flag = 0;
    365             pthread_mutex_lock(&WaitForState_mutex);
    366             pthread_cond_signal(&WaitForState_threshold);
    367             pthread_mutex_unlock(&WaitForState_mutex);
    368         }
    369         else if(nData1 == OMX_ErrorResourcesPreempted) {
    370             writeValue = 0;
    371             preempted = 1;
    372             write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
    373         }
    374         APP_DPRINT( "%d :: App: Component OMX_EventError = %d\n", __LINE__,eEvent);
    375         break;
    376 
    377     case OMX_EventMax:
    378     case OMX_EventMark:
    379         break;
    380 
    381     default:
    382         break;
    383     }
    384 
    385     return eError;
    386 }
    387 
    388 /* ----------------------------------------------------------------------------
    389  * FillBufferDone()
    390  *
    391  * This function is called by OMX component as
    392  * a callback when a Buffer has been filled
    393  * ---------------------------------------------------------------------------- */
    394 void FillBufferDone (OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer)
    395 {
    396     APP_DPRINT ("APP:::: OUTPUT BUFFER = %p && %p\n",pBuffer, pBuffer->pBuffer);
    397     APP_DPRINT ("APP:::: pBuffer->nFilledLen = %d\n",(int)pBuffer->nFilledLen);
    398     /*add on: TimeStamp & TickCount EmptyBufferDone*/
    399     TIME_PRINT("TimeStamp Output: %lld\n",pBuffer->nTimeStamp);
    400     TICK_PRINT("TickCount Output: %ld\n\n",pBuffer->nTickCount);
    401     write(OpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
    402 #ifdef OMX_GETTIME
    403     if (GT_FlagF == 1 ) /* First Buffer Reply*/  /* 1 = First Buffer,  0 = Not First Buffer  */
    404     {
    405         GT_END("Call to FillBufferDone  <First: FillBufferDone>");
    406         GT_FlagF = 0 ;   /* 1 = First Buffer,  0 = Not First Buffer  */
    407     }
    408 #endif
    409 }
    410 
    411 /* ----------------------------------------------------------------------------
    412  * EmptyBufferDone()
    413  *
    414  * This function is called by OMX component as
    415  * a callback when a Buffer has been emptied
    416  * ---------------------------------------------------------------------------- */
    417 void EmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer)
    418 {
    419     APP_DPRINT ("APP:::: INPUT BUFFER = %p && %p\n",pBuffer, pBuffer->pBuffer);
    420     if (!preempted) {
    421         write(IpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
    422     }
    423 #ifdef OMX_GETTIME
    424     if (GT_FlagE == 1 ) /* First Buffer Reply*/  /* 1 = First Buffer,  0 = Not First Buffer  */
    425     {
    426         GT_END("Call to EmptyBufferDone <First: EmptyBufferDone>");
    427         GT_FlagE = 0;   /* 1 = First Buffer,  0 = Not First Buffer  */
    428     }
    429 #endif
    430 }
    431 typedef struct G711DEC_FTYPES{
    432     unsigned short FrameSizeType;
    433     unsigned short NmuNLvl;
    434     unsigned short NoiseLp;
    435     unsigned long  dBmNoise;
    436     unsigned short plc;
    437 }G711DEC_FTYPES;
    438 /* ----------------------------------------------------------------------------
    439  * main()
    440  *
    441  * This function is called at application startup
    442  * and drives the G711 Decoder OMX component
    443  * ---------------------------------------------------------------------------- */
    444 int main(int argc, char* argv[])
    445 {
    446     OMX_CALLBACKTYPE G711CaBa = {(void *)EventHandler,
    447                                  (void*)EmptyBufferDone,
    448                                  (void*)FillBufferDone};
    449 
    450     OMX_HANDLETYPE                pHandle;
    451     OMX_PARAM_PORTDEFINITIONTYPE* pCompPrivateStruct    = NULL;
    452     OMX_AUDIO_CONFIG_MUTETYPE*    pCompPrivateStructMute = NULL;
    453     OMX_AUDIO_CONFIG_VOLUMETYPE*  pCompPrivateStructVolume = NULL;
    454     OMX_AUDIO_PARAM_PCMMODETYPE*  pG711Param = NULL;
    455     OMX_COMPONENTTYPE*            pComponent,*pComponent_dasf = NULL;
    456     OMX_BUFFERHEADERTYPE*         pInputBufferHeader[G711_MAX_NUM_BUFS] = {NULL};
    457     OMX_BUFFERHEADERTYPE*         pOutputBufferHeader[G711_MAX_NUM_BUFS] = {NULL};
    458 
    459     OMX_ERRORTYPE error = OMX_ErrorNone;
    460     OMX_U32 AppData = G711_APP_ID;
    461     TI_OMX_DSP_DEFINITION* audioinfo = malloc(sizeof(TI_OMX_DSP_DEFINITION));
    462     G711DEC_FTYPES* frameinfo = malloc(sizeof(G711DEC_FTYPES));
    463     TI_OMX_DATAPATH dataPath;
    464     struct timeval tv   ;
    465     OMX_S16 retval = 0, i = 0, j = 0,k = 0;
    466     OMX_S16 frmCount = 0;
    467     OMX_S16 frmCnt = 1;
    468     OMX_S16 testcnt = 1;
    469     OMX_S16 testcnt1 = 1;
    470 
    471     OMX_BUFFERHEADERTYPE* pBuf = NULL;
    472 
    473     bInvalidState = OMX_FALSE;
    474 
    475     OMX_STATETYPE         state = OMX_StateInvalid;
    476     OMX_INDEXTYPE         index = 0;
    477 /*    int g711decfdwrite = 0;
    478     int g711decfdread = 0;*/
    479 
    480     APP_DPRINT("------------------------------------------------------\n");
    481     APP_DPRINT("This is Main Thread In G711 DECODER Test Application:\n");
    482     APP_DPRINT("Test Core 1.5 - " __DATE__ ":" __TIME__ "\n");
    483     APP_DPRINT("------------------------------------------------------\n");
    484 #ifdef OMX_GETTIME
    485     printf("Line %d\n",__LINE__);
    486     GTeError = OMX_ListCreate(&pListHead);
    487     printf("Line %d\n",__LINE__);
    488     printf("eError = %d\n",GTeError);
    489     GT_START();
    490     printf("Line %d\n",__LINE__);
    491 #endif
    492     /* check the input parameters */
    493     if(argc != 17) {
    494         printf( "Usage: G711DecTest_common [infile] [outfile] [1-ALaw 2-MuLaw]\
    495                 [sampling freq] [testcase] [dasf mode] [accoustic mode] [nbInputBuf]\
    496                 [Input Buf Size] [nbOutputBuf] [Output Buf size] [Frame Size Type]\
    497                 [NMU Lvl] [Noise LP] [Noise in dBm] [PLC index]\n");
    498         goto EXIT;
    499     }
    500 
    501     OMX_S16 numInputBuffers = 0;
    502     OMX_S16 inputBufferSize = 0;
    503     OMX_S16 numOutputBuffers = 0;
    504     OMX_S16 outputBufferSize = 0;
    505     OMX_S8  fParam1 = 0;
    506     numInputBuffers = atoi(argv[8]);
    507     inputBufferSize = atoi(argv[9]);
    508     numOutputBuffers = atoi(argv[10]);
    509     outputBufferSize = atoi(argv[11]);
    510     fParam1 = atoi(argv[12]);
    511 
    512     if(numInputBuffers > 4 && numInputBuffers < 1)
    513     {
    514         APP_DPRINT( "Cannot support %u Input buffers\n", numInputBuffers);
    515         goto EXIT;
    516     }
    517     if(numOutputBuffers > 4 && numOutputBuffers < 0)
    518     {
    519         APP_DPRINT( "Cannot support %u Output buffers\n", numOutputBuffers);
    520         goto EXIT;
    521     }
    522     if(fParam1 > 3 && fParam1 < 0)
    523     {
    524         APP_DPRINT( "Cannot support %u such frame size type \n", fParam1);
    525         printf( "Cannot support %u such frame size type \n", fParam1);
    526 
    527         goto EXIT;
    528     }
    529 
    530     printf("%d :: App: number of Input buffers = %d \n",__LINE__,numInputBuffers);
    531     printf("%d :: App: size of input buffers = %d \n",__LINE__,inputBufferSize);
    532     printf("%d :: App: number of output buffers = %d \n",__LINE__,numOutputBuffers);
    533     printf("%d :: App: size of Output buffers = %d \n",__LINE__,outputBufferSize);
    534 
    535     /* check to see that the input file exists */
    536     struct stat sb = {0};
    537     OMX_S16 status = stat(argv[1], &sb);
    538     if( status != 0 ) {
    539         APP_DPRINT( "Cannot find file %s. (%u)\n", argv[1], errno);
    540         goto EXIT;
    541     }
    542 
    543     /* Open the file of data to be rendered. */
    544     FILE* fIn = fopen(argv[1], "r");
    545     if( fIn == NULL ) {
    546         APP_DPRINT( "Error:  failed to open the file %s for readonly\access\n", argv[1]);
    547         goto EXIT;
    548     }
    549 
    550     FILE* fOut = NULL;
    551     fOut = fopen(argv[2], "w");
    552     if( fOut == NULL ) {
    553         APP_DPRINT( "Error:  failed to create the output file %s\n", argv[2]);
    554         goto EXIT;
    555     }
    556 
    557     /* Create a pipe used to queue data from the callback. */
    558     retval = pipe(IpBuf_Pipe);
    559     if( retval != 0) {
    560         APP_DPRINT( "Error:Fill Data Pipe failed to open\n");
    561         goto EXIT;
    562     }
    563 
    564     retval = pipe(OpBuf_Pipe);
    565     if( retval != 0) {
    566         APP_DPRINT( "Error:Empty Data Pipe failed to open\n");
    567         goto EXIT;
    568     }
    569     retval = pipe(Event_Pipe);
    570     if( retval != 0) {
    571         APP_DPRINT( "%d %s Error: Empty Data Pipe failed to open\n",__LINE__, __FUNCTION__);
    572         goto EXIT;
    573     }
    574 
    575     /* save off the "max" of the handles for the selct statement */
    576     OMX_S16 fdmax = maxint(IpBuf_Pipe[0], OpBuf_Pipe[0]);
    577     fdmax = maxint(fdmax,Event_Pipe[0]);
    578     APP_DPRINT("%d :: G711Test\n",__LINE__);
    579 
    580     error = TIOMX_Init();
    581 
    582     if(error != OMX_ErrorNone) {
    583         APP_DPRINT("%d :: Error returned by TIOMX_Init()\n",__LINE__);
    584         goto EXIT;
    585     }
    586 
    587     APP_DPRINT("%d :: G711Test\n",__LINE__);
    588 
    589     int command = atoi(argv[5]);
    590     switch (command ) {
    591     case 1:
    592         printf ("-------------------------------------\n");
    593         printf ("Testing Simple PLAY till EOF \n");
    594         printf ("-------------------------------------\n");
    595         break;
    596     case 2:
    597         printf ("-------------------------------------\n");
    598         printf ("Testing Stop and Play \n");
    599         printf ("-------------------------------------\n");
    600         testcnt = 2;
    601         break;
    602     case 3:
    603         printf ("-------------------------------------\n");
    604         printf ("Testing PAUSE & RESUME Command\n");
    605         printf ("-------------------------------------\n");
    606         break;
    607     case 4:
    608         printf ("---------------------------------------------\n");
    609         printf ("Testing STOP Command by Stopping In-Between\n");
    610         printf ("---------------------------------------------\n");
    611         break;
    612     case 5:
    613         printf ("-------------------------------------------------\n");
    614         printf ("Testing Repeated PLAY without Deleting Component\n");
    615         printf ("-------------------------------------------------\n");
    616         testcnt = 20;
    617         break;
    618     case 6:
    619         printf ("------------------------------------------------\n");
    620         printf ("Testing Repeated PLAY with Deleting Component\n");
    621         printf ("------------------------------------------------\n");
    622         testcnt1 = 20;
    623         break;
    624     case 7:
    625         printf ("----------------------------------------------------------\n");
    626         printf ("Testing Multiframe with each buffer size = 2 x frameLength\n");
    627         printf ("----------------------------------------------------------\n");
    628         testCaseNo = 7;
    629         break;
    630     case 8:
    631         printf ("------------------------------------------------------------\n");
    632         printf ("Testing Multiframe with each buffer size = 1/2 x frameLength\n");
    633         printf ("------------------------------------------------------------\n");
    634         testCaseNo = 8;
    635         break;
    636     case 9:
    637         printf ("------------------------------------------------------------\n");
    638         printf ("Testing Multiframe with alternating buffer sizes\n");
    639         printf ("------------------------------------------------------------\n");
    640         testCaseNo = 9;
    641         break;
    642     case 10:
    643         printf ("------------------------------------------------------------\n");
    644         printf ("Testing Mute/Unmute for Playback Stream\n");
    645         printf ("------------------------------------------------------------\n");
    646         break;
    647     case 11:
    648         printf ("------------------------------------------------------------\n");
    649         printf ("Testing Set Volume for Playback Stream\n");
    650         printf ("------------------------------------------------------------\n");
    651         break;
    652 
    653     case 12:
    654         printf ("------------------------------------------------------------\n");
    655         printf ("Testing Simple PLAY  \n");
    656         printf ("------------------------------------------------------------\n");
    657         break;
    658 
    659     }
    660 
    661     APP_DPRINT("%d :: G711Test\n",__LINE__);
    662     fsizemode = atoi(argv[12]);
    663     dasfmode = atoi(argv[6]);
    664     if(dasfmode == 1){
    665         printf("DASF MODE\n");
    666 #if STATE_TRANSITION_STATE
    667         ConfigureAudio();
    668 #endif
    669     }
    670     else if(dasfmode == 0){
    671         printf("NON DASF MODE\n");
    672     }
    673     else {
    674         printf("Enter proper DASF mode\n");
    675         printf("DASF:1\n");
    676         printf("NON DASF:0\n");
    677         goto EXIT;
    678     }
    679 
    680     APP_DPRINT("%d :: G711Test\n",__LINE__);
    681 
    682     for(j = 0; j < testcnt1; j++) {
    683         if(j >= 1) {
    684             printf ("\n****** Decoding the file %i Time ******* \n", j+1);
    685 
    686             /* Create a pipe used to queue data from the callback. */
    687             retval = pipe( IpBuf_Pipe);
    688             if( retval != 0) {
    689                 APP_DPRINT( "Error:Fill Data Pipe failed to open\n");
    690                 goto EXIT;
    691             }
    692 
    693             retval = pipe( OpBuf_Pipe);
    694             if( retval != 0) {
    695                 APP_DPRINT( "Error:Empty Data Pipe failed to open\n");
    696                 goto EXIT;
    697             }
    698             fIn = fopen(argv[1], "r");
    699             if( fIn == NULL ) {
    700                 fprintf(stderr, "Error:  failed to open the file %s for readonly\
    701                                                                    access\n", argv[1]);
    702                 goto EXIT;
    703             }
    704 
    705             fOut = fopen(argv[2], "w");
    706             if( fOut == NULL ) {
    707                 fprintf(stderr, "Error:  failed to create the output file \n");
    708                 goto EXIT;
    709             }
    710             error = TIOMX_Init();
    711             inputToSN = fopen("outputSecondTime.log","w");
    712 
    713         }
    714         else {
    715             inputToSN = fopen("outputFirstTime.log","w");
    716         }
    717 #ifdef DSP_RENDERING_ON
    718         if((g711decfdwrite=open(FIFO1,O_WRONLY))<0)
    719         {
    720             printf("[G711TEST] - failure to open WRITE pipe\n");
    721         }
    722         else
    723         {
    724             printf("[G711TEST] - opened WRITE pipe\n");
    725         }
    726         if((g711decfdread=open(FIFO2,O_RDONLY))<0)
    727         {
    728             printf("[G711TEST] - failure to open READ pipe\n");
    729             goto EXIT;
    730         }
    731         else
    732         {
    733             printf("[G711TEST] - opened READ pipe\n");
    734         }
    735 #endif
    736         /* Load the G711 Encoder Component */
    737         APP_DPRINT("%d :: G711Test\n",__LINE__);
    738 #ifdef OMX_GETTIME
    739         GT_START();
    740         error = OMX_GetHandle(&pHandle, strG711Decoder, &AppData, &G711CaBa);
    741         GT_END("Call to OMX_GetHandle");
    742 #else
    743         error = TIOMX_GetHandle(&pHandle, strG711Decoder, &AppData, &G711CaBa);
    744 #endif
    745         APP_DPRINT("%d :: G711Test\n",__LINE__);
    746         if((error != OMX_ErrorNone) || (pHandle == NULL)) {
    747             APP_DPRINT ("Error in Get Handle function\n");
    748             goto EXIT;
    749         }
    750 
    751         APP_DPRINT("%d :: G711Test\n",__LINE__);
    752 
    753         pCompPrivateStruct = malloc (sizeof (OMX_PARAM_PORTDEFINITIONTYPE));
    754         if (pCompPrivateStruct == 0) {
    755             printf("Malloc failed\n");
    756             error = -1;
    757             goto EXIT;
    758         }
    759 
    760         if (dasfmode)
    761         {
    762 #ifdef RTM_PATH
    763             dataPath = DATAPATH_APPLICATION_RTMIXER;
    764 #endif
    765 
    766 #ifdef ETEEDN_PATH
    767             dataPath = DATAPATH_APPLICATION;
    768 #endif
    769         }
    770         /* set playback stream mute/unmute */
    771         pCompPrivateStructMute = malloc (sizeof(OMX_AUDIO_CONFIG_MUTETYPE));
    772         if(pCompPrivateStructMute == NULL) {
    773             printf("%d :: App: Malloc Failed\n",__LINE__);
    774             goto EXIT;
    775         }
    776         pCompPrivateStructVolume = malloc (sizeof(OMX_AUDIO_CONFIG_VOLUMETYPE));
    777         if(pCompPrivateStructVolume == NULL) {
    778             printf("%d :: App: Malloc Failed\n",__LINE__);
    779             goto EXIT;
    780         }
    781 
    782         APP_MEMPRINT("%d:::[TESTAPPALLOC] %p\n",__LINE__,pCompPrivateStruct);
    783         APP_DPRINT("%d :: G711Test\n",__LINE__);
    784         pCompPrivateStruct->nSize = sizeof (OMX_PARAM_PORTDEFINITIONTYPE);
    785         pCompPrivateStruct->nVersion.s.nVersionMajor = 0xF1;
    786         pCompPrivateStruct->nVersion.s.nVersionMinor = 0xF2;
    787         APP_DPRINT("%d :: G711Test\n",__LINE__);
    788         /* Send input port config */
    789         pCompPrivateStruct->nPortIndex = OMX_DirInput;
    790         pCompPrivateStruct->format.audio.cMIMEType = malloc(20);
    791         strcpy(pCompPrivateStruct->format.audio.cMIMEType,"NONMIME");
    792         pCompPrivateStruct->eDir = OMX_DirInput;
    793         pCompPrivateStruct->nPortIndex = OMX_DirInput;
    794         pCompPrivateStruct->nBufferCountActual = numInputBuffers;
    795         pCompPrivateStruct->nBufferSize = inputBufferSize;
    796         pCompPrivateStruct->format.audio.eEncoding = OMX_AUDIO_CodingG711;
    797         pCompPrivateStruct->bEnabled = 1;
    798         pCompPrivateStruct->bPopulated = 0;
    799 
    800 #ifdef OMX_GETTIME
    801         GT_START();
    802         error = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
    803         GT_END("Set Parameter Test-SetParameter");
    804 #else
    805         error = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
    806 #endif
    807         if (error != OMX_ErrorNone) {
    808             error = OMX_ErrorBadParameter;
    809             printf ("%d:: OMX_ErrorBadParameter\n",__LINE__);
    810             goto EXIT;
    811         }
    812         /* Send output port config */
    813         pCompPrivateStruct->nPortIndex = OMX_DirOutput;
    814         pCompPrivateStruct->eDir = OMX_DirOutput;
    815         pCompPrivateStruct->nPortIndex = OMX_DirOutput;
    816         pCompPrivateStruct->nBufferCountActual = numOutputBuffers;
    817         pCompPrivateStruct->nBufferSize = outputBufferSize;
    818 
    819         if(dasfmode == 1) {
    820             pCompPrivateStruct->nBufferCountActual = 0;
    821         }
    822 #ifdef OMX_GETTIME
    823         GT_START();
    824         error = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
    825         GT_END("Set Parameter Test-SetParameter");
    826 #else
    827         error = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
    828 #endif
    829         if (error != OMX_ErrorNone) {
    830             error = OMX_ErrorBadParameter;
    831             printf ("%d:: OMX_ErrorBadParameter\n",__LINE__);
    832             goto EXIT;
    833         }
    834         /* default setting for Mute/Unmute */
    835         pCompPrivateStructMute->nSize = sizeof (OMX_AUDIO_CONFIG_MUTETYPE);
    836         pCompPrivateStructMute->nVersion.s.nVersionMajor    = 0xF1;
    837         pCompPrivateStructMute->nVersion.s.nVersionMinor    = 0xF2;
    838         pCompPrivateStructMute->nPortIndex                  = OMX_DirInput;
    839         pCompPrivateStructMute->bMute                       = OMX_FALSE;
    840 
    841         /* default setting for volume */
    842         pCompPrivateStructVolume->nSize = sizeof(OMX_AUDIO_CONFIG_VOLUMETYPE);
    843         pCompPrivateStructVolume->nVersion.s.nVersionMajor  = 0xF1;
    844         pCompPrivateStructVolume->nVersion.s.nVersionMinor  = 0xF2;
    845         pCompPrivateStructVolume->nPortIndex                = OMX_DirInput;
    846         pCompPrivateStructVolume->bLinear                   = OMX_FALSE;
    847         pCompPrivateStructVolume->sVolume.nValue            = 50;               /* actual volume */
    848         pCompPrivateStructVolume->sVolume.nMin              = 0;                /* min volume */
    849         pCompPrivateStructVolume->sVolume.nMax              = 100;              /* max volume */
    850 
    851 #ifndef USE_BUFFER
    852         /* Allocate Input buffers with OMX_AllocateBuffer() API */
    853         for (i=0; i < numInputBuffers; i++) {
    854             /* allocate input buffer */
    855             APP_DPRINT("%d :: About to call OMX_AllocateBuffer\n",__LINE__);
    856             error = OMX_AllocateBuffer(pHandle,&pInputBufferHeader[i],0,NULL,inputBufferSize);
    857             APP_DPRINT("%d :: called OMX_AllocateBuffer\n",__LINE__);
    858             if(error != OMX_ErrorNone) {
    859                 APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer()\n",__LINE__);
    860                 goto EXIT;
    861             }
    862 
    863         }
    864         /* Allocate Output buffers with OMX_AllocateBuffer() API */
    865         for (i=0; i < numOutputBuffers; i++) {
    866             /* allocate output buffer */
    867             APP_DPRINT("%d :: About to call OMX_AllocateBuffer\n",__LINE__);
    868             error = OMX_AllocateBuffer(pHandle,&pOutputBufferHeader[i],1,NULL,outputBufferSize);
    869             APP_DPRINT("%d :: called OMX_AllocateBuffer\n",__LINE__);
    870             if(error != OMX_ErrorNone) {
    871                 APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer()\n",__LINE__);
    872                 goto EXIT;
    873             }
    874         }
    875 #else
    876         /* Allocate Input buffers with OMX_UseBuffer() API */
    877         for (i=0; i < numInputBuffers; i++)
    878         {
    879             pInputBuffer[i] = (OMX_U8*)malloc(inputBufferSize + EXTRA_BUFFBYTES);
    880             APP_MEMPRINT("%d:::[TESTAPPALLOC] %p\n",__LINE__,pInputBuffer[i]);
    881             pInputBuffer[i] = pInputBuffer[i] + CACHE_ALIGNMENT;
    882 
    883             /* allocate input buffer */
    884             APP_DPRINT("%d :: About to call OMX_UseBuffer\n",__LINE__);
    885             error = OMX_UseBuffer(pHandle,&pInputBufferHeader[i],0,NULL,inputBufferSize,pInputBuffer[i]);
    886             APP_DPRINT("%d :: called OMX_UseBuffer\n",__LINE__);
    887             if(error != OMX_ErrorNone)
    888             {
    889                 APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n",__LINE__);
    890                 goto EXIT;
    891             }
    892 
    893         }
    894         /* Allocate Output buffers with OMX_UseBuffer() API */
    895         for ( i = 0 ; i < numOutputBuffers ; i++ )
    896         {
    897             pOutputBuffer[i] = (OMX_U8*)malloc (outputBufferSize + EXTRA_BUFFBYTES);
    898             APP_MEMPRINT("%d:::[TESTAPPALLOC] %p\n",__LINE__,pOutputBuffer);
    899             pOutputBuffer[i] = pOutputBuffer[i] + CACHE_ALIGNMENT;
    900 
    901             /* allocate output buffer */
    902             APP_DPRINT("%d :: About to call OMX_UseBuffer\n",__LINE__);
    903             error = OMX_UseBuffer(pHandle,&pOutputBufferHeader[i],1,NULL,outputBufferSize,pOutputBuffer[i]);
    904             APP_DPRINT("%d :: called OMX_UseBuffer\n",__LINE__);
    905             if(error != OMX_ErrorNone)
    906             {
    907                 APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n",__LINE__);
    908                 goto EXIT;
    909             }
    910 
    911         }
    912 #endif
    913 
    914         /* Send  G711 config for input */
    915         pG711Param = malloc (sizeof (OMX_AUDIO_PARAM_PCMMODETYPE));
    916         APP_MEMPRINT("%d:::[TESTAPPALLOC] %p\n",__LINE__,pG711Param);
    917         if(pG711Param == NULL) {
    918             printf("%d :: App: Malloc Failed\n",__LINE__);
    919             goto EXIT;
    920         }
    921 
    922         pG711Param->nPortIndex = OMX_DirInput;
    923         OMX_GetParameter(pHandle, OMX_IndexParamAudioPcm, pG711Param);
    924         pG711Param->nSize = sizeof (OMX_AUDIO_PARAM_PCMMODETYPE);
    925         pG711Param->nVersion.s.nVersionMajor = 0xF1;
    926         pG711Param->nVersion.s.nVersionMinor = 0xF2;
    927 
    928         pG711Param->nChannels = 1; /* mono */
    929         pG711Param->eNumData = OMX_NumericalDataUnsigned;
    930         pG711Param->eEndian = OMX_EndianLittle;
    931         pG711Param->bInterleaved = OMX_FALSE;
    932         pG711Param->nBitPerSample = 8;
    933         pG711Param->nSamplingRate = 0; /* means undefined in the OMX standard */
    934 
    935         for ( i = 0 ; i < OMX_AUDIO_MAXCHANNELS ; i++ )
    936             pG711Param->eChannelMapping[0] = OMX_AUDIO_ChannelNone;
    937 
    938         /* extract compression format from command line */
    939         if (atoi(argv[3]) == OMX_AUDIO_PCMModeALaw)
    940             pG711Param->ePCMMode = OMX_AUDIO_PCMModeALaw;
    941         else if (atoi(argv[3]) == OMX_AUDIO_PCMModeMULaw)
    942             pG711Param->ePCMMode = OMX_AUDIO_PCMModeMULaw;
    943 
    944         else {
    945             printf("Enter proper G711 mode\n");
    946             printf("A-Law:1\n");
    947             printf("MU-Law:2\n");
    948             goto EXIT;
    949         }
    950 #ifdef OMX_GETTIME
    951         GT_START();
    952         error = OMX_SetParameter (pHandle, OMX_IndexParamAudioPcm, pG711Param);
    953         GT_END("Set Parameter Test-SetParameter");
    954 #else
    955         error = OMX_SetParameter (pHandle, OMX_IndexParamAudioPcm, pG711Param);
    956 #endif
    957         if (error != OMX_ErrorNone) {
    958             error = OMX_ErrorBadParameter;
    959             printf ("%d:: OMX_ErrorBadParameter\n",__LINE__);
    960             goto EXIT;
    961         }
    962         /* Send  G711 config for output */
    963         pG711Param->nPortIndex = OMX_DirOutput;
    964         pG711Param->nBitPerSample = 16;
    965         pG711Param->ePCMMode = OMX_AUDIO_PCMModeLinear;
    966 
    967         /* extract sampling rate from command line */
    968         pG711Param->nSamplingRate = atoi(argv[4]);
    969 #ifdef OMX_GETTIME
    970         GT_START();
    971         error = OMX_SetParameter (pHandle,OMX_IndexParamAudioPcm, pG711Param);
    972         GT_END("Set Parameter Test-SetParameter");
    973 #else
    974         error = OMX_SetParameter (pHandle,OMX_IndexParamAudioPcm, pG711Param);
    975 #endif
    976         if (error != OMX_ErrorNone) {
    977             error = OMX_ErrorBadParameter;
    978             printf ("%d:: OMX_ErrorBadParameter\n",__LINE__);
    979             goto EXIT;
    980         }
    981 
    982         pComponent_dasf = (OMX_COMPONENTTYPE *)pHandle;
    983 
    984         /** Getting the frame params */
    985         frameinfo->FrameSizeType = atoi(argv[12]);
    986         frameinfo->NmuNLvl = atoi(argv[13]);
    987         frameinfo->NoiseLp = atoi(argv[14]);
    988         frameinfo->dBmNoise = atoi(argv[15]);
    989         frameinfo->plc = atoi(argv[16]);
    990 
    991         error = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.g711dec.frameparams",&index);
    992         if (error != OMX_ErrorNone) {
    993             printf("Error getting extension index\n");
    994             goto EXIT;
    995         }
    996 
    997         error = OMX_SetConfig (pHandle, index, frameinfo);
    998         if(error != OMX_ErrorNone) {
    999             error = OMX_ErrorBadParameter;
   1000             APP_DPRINT("%d :: Error from OMX_SetConfig() function\n",__LINE__);
   1001             goto EXIT;
   1002         }
   1003 
   1004         /* get TeeDN or ACDN mode */
   1005         audioinfo->acousticMode = atoi(argv[7]);
   1006 
   1007         /* Process DASF mode */
   1008         if(dasfmode == 1){
   1009             audioinfo->dasfMode = 1;
   1010         }
   1011         else if(dasfmode == 0){
   1012             audioinfo->dasfMode = 0;
   1013 
   1014         }
   1015         else {
   1016             printf("Enter proper DASF mode\n");
   1017             printf("DASF:1\n");
   1018             printf("NON DASF:0\n");
   1019             goto EXIT;
   1020         }
   1021 
   1022         /* get extension index to define proprietary DASF settings */
   1023         error = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.g711headerinfo",&index);
   1024         if (error != OMX_ErrorNone) {
   1025             printf("Error getting extension index\n");
   1026             goto EXIT;
   1027         }
   1028 
   1029 /*        cmd_data.hComponent = pHandle;
   1030         cmd_data.AM_Cmd = AM_CommandIsOutputStreamAvailable;*/
   1031 
   1032         /* for decoder, using AM_CommandIsInputStreamAvailable */
   1033 /*        cmd_data.param1 = 0;*/
   1034 #ifdef DSP_RENDERING_ON
   1035         if((write(g711decfdwrite, &cmd_data, sizeof(cmd_data)))<0) {
   1036             printf("%d [G711 Dec Component] - send command to audio manager\n", __LINE__);
   1037             goto EXIT;
   1038         }
   1039         if((read(g711decfdread, &cmd_data, sizeof(cmd_data)))<0) {
   1040             printf("%d [G711 Dec Component] - failure to get data from the audio manager\n", __LINE__);
   1041             goto EXIT;
   1042         }
   1043 #endif
   1044 
   1045 /*        audioinfo->streamId = cmd_data.streamID;*/
   1046         if(audioinfo->dasfMode)
   1047             printf("***************StreamId=%d******************\n", (int)audioinfo->streamId );
   1048         APP_DPRINT("%d :: TestApp: Set Config, pHandle %p\n", __LINE__, pHandle);
   1049         error = OMX_SetConfig(pHandle,index,audioinfo);
   1050         if (error != OMX_ErrorNone) {
   1051             printf("Error in SetConfig\n");
   1052             goto EXIT;
   1053         }
   1054         APP_DPRINT("%d :: TestApp: Get Extension Index, pHandle %p\n", __LINE__, pHandle);
   1055         error = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.g711dec.datapath",&index);
   1056         if (error != OMX_ErrorNone) {
   1057             printf("Error getting extension index\n");
   1058             goto EXIT;
   1059         }
   1060         APP_DPRINT("%d :: TestApp: Set Config, pHandle %p\n", __LINE__, pHandle);
   1061         error = OMX_SetConfig (pHandle, index, &dataPath);
   1062         if(error != OMX_ErrorNone) {
   1063             error = OMX_ErrorBadParameter;
   1064             APP_DPRINT("%d :: WmaDecTest.c :: Error from OMX_SetConfig() function\n",__LINE__);
   1065             goto EXIT;
   1066         }
   1067 
   1068         /* start the OMX component */
   1069         APP_DPRINT("%d :: TestApp: Change state to Idle, pHandle %p\n", __LINE__, pHandle);
   1070 #ifdef OMX_GETTIME
   1071         GT_START();
   1072 #endif
   1073         error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
   1074         if(error != OMX_ErrorNone) {
   1075             APP_DPRINT ("Error from SendCommand-Idle(Init) State function\n");
   1076             goto EXIT;
   1077         }
   1078 
   1079         /* Wait for startup to complete */
   1080         error = WaitForState(pHandle, OMX_StateIdle);
   1081 #ifdef OMX_GETTIME
   1082         GT_END("Call to SendCommand <OMX_StateIdle>");
   1083 #endif
   1084         if(error != OMX_ErrorNone) {
   1085             APP_DPRINT( "Error:  hG711Encoder->WaitForState reports an error %X\n", error);
   1086             goto EXIT;
   1087         }
   1088         APP_DPRINT("%d :: TestApp: State Changed to Idle\n", __LINE__);
   1089         for(i = 0; i < testcnt; i++)
   1090         {
   1091             if(i > 0)
   1092             {
   1093                 printf ("\n***** Decoding the file for %i Time ***** \n",i+1);
   1094 
   1095                 close(IpBuf_Pipe[0]);
   1096                 close(IpBuf_Pipe[1]);
   1097                 close(OpBuf_Pipe[0]);
   1098                 close(OpBuf_Pipe[1]);
   1099                 close(Event_Pipe[0]);
   1100                 close(Event_Pipe[1]);
   1101 
   1102                 /* Create a pipe used to queue data from the callback. */
   1103                 retval = pipe(IpBuf_Pipe);
   1104                 if( retval != 0)
   1105                 {
   1106                     APP_DPRINT( "Error:Fill Data Pipe failed to open\n");
   1107                     goto EXIT;
   1108                 }
   1109 
   1110                 retval = pipe(OpBuf_Pipe);
   1111                 if( retval != 0)
   1112                 {
   1113                     APP_DPRINT( "Error:Empty Data Pipe failed to open\n");
   1114                     goto EXIT;
   1115                 }
   1116 
   1117                 retval = pipe(Event_Pipe);
   1118                 if( retval != 0) {
   1119                     APP_DPRINT( "%d Error: Empty Event Pipe failed to open\n",__LINE__);
   1120                     goto EXIT;
   1121                 }
   1122 
   1123                 fIn = fopen(argv[1], "r");
   1124                 if(fIn == NULL)
   1125                 {
   1126                     fprintf(stderr, "Error:  failed to open the file %s for readonly access\n", argv[1]);
   1127                     goto EXIT;
   1128                 }
   1129 
   1130                 fOut = fopen(argv[2], "w");
   1131                 if(fOut == NULL)
   1132                 {
   1133                     fprintf(stderr, "Error:  failed to create the output file \n");
   1134                     goto EXIT;
   1135                 }
   1136             }
   1137 
   1138             done = 0;
   1139 
   1140             printf ("Basic Function:: Sending OMX_StateExecuting Command\n");
   1141 #ifdef OMX_GETTIME
   1142             GT_START();
   1143 #endif
   1144             error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
   1145             if(error != OMX_ErrorNone)
   1146             {
   1147                 APP_DPRINT ("Error from SendCommand-Executing State function\n");
   1148                 goto EXIT;
   1149             }
   1150             pComponent = (OMX_COMPONENTTYPE *)pHandle;
   1151             error = WaitForState(pHandle, OMX_StateExecuting);
   1152 #ifdef OMX_GETTIME
   1153             GT_END("Call to SendCommand <OMX_StateExecuting>");
   1154 #endif
   1155             if(error != OMX_ErrorNone)
   1156             {
   1157                 APP_DPRINT( "Error:  hG711Decoder->WaitForState reports an error %X\n", error);
   1158                 goto EXIT;
   1159             }
   1160 
   1161             for (k=0; k < numInputBuffers; k++)
   1162             {
   1163 #ifdef OMX_GETTIME
   1164                 if (k==0)
   1165                 {
   1166                     GT_FlagE=1;  /* 1 = First Buffer,  0 = Not First Buffer  */
   1167                     GT_START(); /* Empty Bufffer */
   1168                 }
   1169 #endif
   1170                 error = send_input_buffer (pHandle, pInputBufferHeader[k], fIn);
   1171             }
   1172 
   1173             if (dasfmode == 0)
   1174             {
   1175                 for (k=0; k < numOutputBuffers; k++)
   1176                 {
   1177 #ifdef OMX_GETTIME
   1178                     if (k==0)
   1179                     {
   1180                         GT_FlagF=1;  /* 1 = First Buffer,  0 = Not First Buffer  */
   1181                         GT_START(); /* Fill Buffer */
   1182                     }
   1183 #endif
   1184                     OMX_FillThisBuffer(pHandle,  pOutputBufferHeader[k]);
   1185                 }
   1186             }
   1187 
   1188             error = OMX_GetState(pHandle, &state);
   1189 
   1190             while( (error == OMX_ErrorNone) && (state != OMX_StateIdle) &&
   1191                    (state != OMX_StateInvalid)) {
   1192 
   1193                 FD_ZERO(&rfds);
   1194                 FD_SET(IpBuf_Pipe[0], &rfds);
   1195                 FD_SET(OpBuf_Pipe[0], &rfds);
   1196                 FD_SET(Event_Pipe[0], &rfds);
   1197                 tv.tv_sec = 1;
   1198                 tv.tv_usec = 0;
   1199                 frmCount++;
   1200 
   1201                 retval = select(fdmax+1, &rfds, NULL, NULL, &tv);
   1202                 if(retval == -1)
   1203                 {
   1204                     perror("select()");
   1205                     APP_DPRINT ( " : Error \n");
   1206                     break;
   1207                 }
   1208 
   1209                 if(retval == 0) {
   1210                     APP_DPRINT ("%d :: BasicFn App Timeout !!!!!!!!!!! \n",__LINE__);
   1211                 }
   1212 
   1213                 switch (command)
   1214                 {
   1215                 case 1: /* Testing Simple PLAY till EOF */
   1216                 case 5: /* Testing Repeated PLAY without Deleting Component */
   1217                 case 6: /* Testing Repeated PLAY with Deleting Component */
   1218                 case 7: /* Testing Multiframe with each buffer size = 2 x frameLength */
   1219                 case 8: /* Testing Multiframe with each buffer size = 1/2 x frameLength */
   1220                 case 9: /* Testing Multiframe with alternating buffer sizes */
   1221                     if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {
   1222                         OMX_BUFFERHEADERTYPE* pBuffer;
   1223                         read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
   1224                         error = send_input_buffer (pHandle, pBuffer, fIn);
   1225 
   1226                         if (error != OMX_ErrorNone) {
   1227                             printf ("Error While reading input pipe\n");
   1228                             goto EXIT;
   1229                         }
   1230                         frmCnt++;
   1231                         pBuffer->nFlags = 0;
   1232                     }
   1233                     break;
   1234 
   1235                 case 2: /* Testing Stop and Play */
   1236                 case 4: /* Testing STOP Command by Stopping In-Between */
   1237                     if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {
   1238                         OMX_BUFFERHEADERTYPE* pBuffer;
   1239                         read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
   1240                         frmCnt++;
   1241                         pBuffer->nFlags = 0;
   1242                         if(frmCnt == 50) { /*100 Frames processed */
   1243                             fprintf(stderr, "Shutting down since 100 frames were sent---------- \n");
   1244 #ifdef OMX_GETTIME
   1245                             GT_START();
   1246 #endif
   1247                             error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);
   1248                             if(error != OMX_ErrorNone) {
   1249                                 fprintf (stderr,"Error from SendCommand-Idle(Stop) State function\n");
   1250                                 goto EXIT;
   1251                             }
   1252                             error = WaitForState(pHandle, OMX_StateIdle);
   1253 #ifdef OMX_GETTIME
   1254                             GT_END("Call to SendCommand <OMX_StateIdle>");
   1255 #endif
   1256                             if(error != OMX_ErrorNone) {
   1257                                 fprintf(stderr, "Error:  hPcmDecoder->WaitForState reports an error %X\n", error);
   1258                                 goto EXIT;
   1259                             }
   1260                             done = 1;
   1261                         }
   1262                         error = send_input_buffer (pHandle, pBuffer, fIn);
   1263                         if (error != OMX_ErrorNone) {
   1264                             printf ("Error While reading input pipe\n");
   1265                             goto EXIT;
   1266                         }
   1267                     }
   1268                     break;
   1269 
   1270                 case 3: /* Testing PAUSE & RESUME Command */
   1271                     if (frmCount == 16) {  /*100 Frames processed */
   1272                         printf (" Sending Resume command to Codec \n");
   1273 #ifdef OMX_GETTIME
   1274                         GT_START();
   1275 #endif
   1276                         error = OMX_SendCommand(pHandle, OMX_CommandStateSet,OMX_StateExecuting, NULL);
   1277                         if(error != OMX_ErrorNone) {
   1278                             fprintf (stderr,"Error from SendCommand-Executing State function\n");
   1279                             goto EXIT;
   1280                         }
   1281                         /* Wait for startup to complete */
   1282                         error = WaitForState(pHandle, OMX_StateExecuting);
   1283 #ifdef OMX_GETTIME
   1284                         GT_END("Call to SendCommand <OMX_StateExecuting>");
   1285 #endif
   1286                         if(error != OMX_ErrorNone) {
   1287                             fprintf(stderr, "Error:  hPcmDecoder->WaitForState reports an error %X\n", error);
   1288                             goto EXIT;
   1289                         }
   1290                     }
   1291                     if(frmCount == 6) {   /*6 Frames processed */
   1292                         printf (" Sending Pause command to Codec \n");
   1293 #ifdef OMX_GETTIME
   1294                         GT_START();
   1295 #endif
   1296                         error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StatePause, NULL);
   1297                         if(error != OMX_ErrorNone) {
   1298                             fprintf (stderr,"Error from SendCommand-Pasue State function\n");
   1299                             goto EXIT;
   1300                         }
   1301                         /* Wait for startup to complete */
   1302                         error = WaitForState(pHandle, OMX_StatePause);
   1303 #ifdef OMX_GETTIME
   1304                         GT_END("Call to SendCommand <OMX_StatePause>");
   1305 #endif
   1306                         if(error != OMX_ErrorNone) {
   1307                             fprintf(stderr, "Error:  hPcmDecoder->WaitForState reports an error %X\n", error);
   1308                             goto EXIT;
   1309                         }
   1310                     }
   1311 
   1312                     if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {
   1313                         OMX_BUFFERHEADERTYPE* pBuffer;
   1314                         read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
   1315                         error = send_input_buffer (pHandle, pBuffer, fIn);
   1316                         if (error != OMX_ErrorNone) {
   1317                             printf ("Error While reading input pipe\n");
   1318                             goto EXIT;
   1319                         }
   1320                         frmCnt++;
   1321                     }
   1322                     break;
   1323 
   1324                 case 10: /* Testing Mute/Unmute for Playback Stream */
   1325                     if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {
   1326                         OMX_BUFFERHEADERTYPE* pBuffer;
   1327 
   1328                         read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
   1329                         pBuffer->nFlags = 0;
   1330                         error = send_input_buffer (pHandle, pBuffer, fIn);
   1331                         if (error != OMX_ErrorNone) {
   1332                             goto EXIT;
   1333                         }
   1334                         frmCnt++;
   1335                     }
   1336                     if(frmCnt == 50) {
   1337                         printf("************Mute the playback stream*****************\n");
   1338                         pCompPrivateStructMute->bMute = OMX_TRUE;
   1339                         error = OMX_SetConfig(pHandle, OMX_IndexConfigAudioMute, pCompPrivateStructMute);
   1340                         if (error != OMX_ErrorNone) {
   1341                             error = OMX_ErrorBadParameter;
   1342                             goto EXIT;
   1343                         }
   1344                     }
   1345                     if(frmCnt == 120) {
   1346                         printf("************Unmute the playback stream*****************\n");
   1347                         pCompPrivateStructMute->bMute = OMX_FALSE;
   1348                         error = OMX_SetConfig(pHandle, OMX_IndexConfigAudioMute, pCompPrivateStructMute);
   1349                         if (error != OMX_ErrorNone) {
   1350                             error = OMX_ErrorBadParameter;
   1351                             goto EXIT;
   1352                         }
   1353                     }
   1354                     break;
   1355 
   1356                 case 11: /* test set volume for playback stream */
   1357                     if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {
   1358                         OMX_BUFFERHEADERTYPE* pBuffer;
   1359 
   1360                         read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
   1361                         pBuffer->nFlags = 0;
   1362                         error = send_input_buffer (pHandle, pBuffer, fIn);
   1363                         if (error != OMX_ErrorNone) {
   1364                             goto EXIT;
   1365                         }
   1366                         frmCnt++;
   1367                     }
   1368                     if(frmCnt == 10) {
   1369                         printf("************Set stream volume to high*****************\n");
   1370                         pCompPrivateStructVolume->sVolume.nValue = 0x8000;
   1371                         error = OMX_SetConfig(pHandle, OMX_IndexConfigAudioVolume, pCompPrivateStructVolume);
   1372                         if (error != OMX_ErrorNone) {
   1373                             error = OMX_ErrorBadParameter;
   1374                             goto EXIT;
   1375                         }
   1376                     }
   1377                     if(frmCnt == 85) {
   1378                         printf("************Set stream volume to low*****************\n");
   1379                         pCompPrivateStructVolume->sVolume.nValue = 0x1000;
   1380                         error = OMX_SetConfig(pHandle, OMX_IndexConfigAudioVolume, pCompPrivateStructVolume);
   1381                         if (error != OMX_ErrorNone) {
   1382                             error = OMX_ErrorBadParameter;
   1383                             goto EXIT;
   1384                         }
   1385                     }
   1386                     break;
   1387 
   1388                 case 12: /* test unsupported content*/
   1389                     if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {
   1390                         int a, b;
   1391                         a = (int)argv[4];
   1392                         b = (int)argv[7];
   1393                         OMX_BUFFERHEADERTYPE* pBuffer;
   1394                         read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
   1395                         error = send_input_buffer (pHandle, pBuffer, fIn);
   1396                         if(((a != 8000)) || ((b <= 0) || (b >= 3))){
   1397                             printf("************ Unsupported content ****************\n ");
   1398                             goto EXIT;
   1399                         }
   1400                         if (error != OMX_ErrorNone) {
   1401                             printf ("Error While reading input pipe\n");
   1402                             goto EXIT;
   1403                         }
   1404                         frmCnt++;
   1405                     }
   1406                 default:
   1407                     APP_DPRINT("%d :: ### Running Simple DEFAULT Case Here ###\n",__LINE__);
   1408 
   1409                 } /* Switch Command Ending Here */
   1410 
   1411                 if( FD_ISSET(OpBuf_Pipe[0], &rfds) ) {
   1412                     read(OpBuf_Pipe[0], &pBuf, sizeof(pBuf));
   1413                     if (OUTPUT_G711DEC_BUFFER_SIZE != pBuf->nFilledLen ) {
   1414                         APP_DPRINT ("%d : WARNING: Different Size, %d\n",__LINE__,(int)pBuf->nFilledLen);
   1415                     }
   1416                     if ((state != OMX_StateExecuting) && (pBuf->nFilledLen > 0))
   1417                         printf("Writing remaining output buffer\n");
   1418                     fwrite(pBuf->pBuffer, 1, pBuf->nFilledLen, fOut);
   1419                     fflush(fOut);
   1420                     if (state == OMX_StateExecuting ) {
   1421                         OMX_FillThisBuffer(pHandle, pBuf);
   1422                     }
   1423                 }
   1424 
   1425                 error = pComponent->GetState(pHandle, &state);
   1426                 if(error != OMX_ErrorNone) {
   1427                     APP_DPRINT("%d:: Warning:  hG711Encoder->GetState has returned status %X\n",__LINE__, error);
   1428                     goto EXIT;
   1429                 }
   1430                 else if (preempted){
   1431                     sched_yield();
   1432                 }
   1433             } /* While Loop Ending Here */
   1434 
   1435             printf ("The current state of the component = %d \n",state);
   1436             fclose(fOut);
   1437             fclose(fIn);
   1438             if(( command == 5) || (command == 2)) { /*If test is Stop & Play or Repeated*/
   1439                 sleep (3);                                     /*play without deleting the component*/
   1440             }
   1441         } /* For loop on testcnt ends here */
   1442 
   1443 /*        cmd_data.hComponent = pHandle;
   1444         cmd_data.AM_Cmd = AM_Exit;*/
   1445 #ifdef DSP_RENDERING_ON
   1446         if((write(g711decfdwrite, &cmd_data, sizeof(cmd_data)))<0)
   1447             printf("%d ::TestApp :: [G711 Dec Component] - send command to audio manager\n",__LINE__);
   1448         close(g711decfdwrite);
   1449         close(g711decfdread);
   1450 #endif
   1451         printf ("Sending the StateLoaded Command\n");
   1452 #ifdef OMX_GETTIME
   1453         GT_START();
   1454 #endif
   1455         error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateLoaded, NULL);
   1456         if(error != OMX_ErrorNone) {
   1457             APP_DPRINT ("%d:: Error from SendCommand-Idle State function\n",__LINE__);
   1458             goto EXIT;
   1459         }
   1460 
   1461         error = OMX_SendCommand(pHandle, OMX_CommandPortDisable, -1, NULL);
   1462 
   1463 
   1464         if(error != OMX_ErrorNone) {
   1465             APP_DPRINT( "Error:  hG711Encoder->WaitForState reports an error %X\n", error);
   1466             goto EXIT;
   1467         }
   1468 
   1469         /* free buffers */
   1470         for (i=0; i < numInputBuffers; i++) {
   1471             error = OMX_FreeBuffer(pHandle,OMX_DirInput,pInputBufferHeader[i]);
   1472             if( (error != OMX_ErrorNone)) {
   1473                 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
   1474                 goto EXIT;
   1475             }
   1476         }
   1477 
   1478         for (i=0; i < numOutputBuffers; i++) {
   1479             error = OMX_FreeBuffer(pHandle,OMX_DirOutput,pOutputBufferHeader[i]);
   1480             if( (error != OMX_ErrorNone)) {
   1481                 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
   1482                 goto EXIT;
   1483             }
   1484         }
   1485 
   1486 #ifdef USE_BUFFER
   1487         /* free the App Allocated Buffers */
   1488         printf("%d :: App: Freeing the App Allocated Buffers in TestApp\n",__LINE__);
   1489         for(i=0; i < numInputBuffers; i++) {
   1490             pInputBuffer[i] = pInputBuffer[i] - 128;
   1491             APP_MEMPRINT("%d :: App: [TESTAPPFREE] pInputBuffer[%d] = %p\n",__LINE__,i,pInputBuffer[i]);
   1492             if(pInputBuffer[i] != NULL){
   1493                 free(pInputBuffer[i]);
   1494                 pInputBuffer[i] = NULL;
   1495             }
   1496         }
   1497 
   1498         for(i=0; i < numOutputBuffers; i++) {
   1499             pOutputBuffer[i] = pOutputBuffer[i] - 128;
   1500             APP_MEMPRINT("%d :: App: [TESTAPPFREE] pOutputBuffer[%d] = %p\n",__LINE__,i, pOutputBuffer[i]);
   1501             if(pOutputBuffer[i] != NULL){
   1502                 free(pOutputBuffer[i]);
   1503                 pOutputBuffer[i] = NULL;
   1504             }
   1505         }
   1506 #endif
   1507 
   1508         error = WaitForState(pHandle, OMX_StateLoaded);
   1509 #ifdef OMX_GETTIME
   1510         GT_END("Call to SendCommand <OMX_StateLoaded After freeing input/output BUFFERS & OMX_CommandPortDisable>");
   1511 #endif
   1512 
   1513         /* Unload the G711 Encoder Component */
   1514         printf ("Free the Component handle\n");
   1515         error = TIOMX_FreeHandle(pHandle);
   1516         APP_MEMPRINT("%d:::[TESTAPPFREE] %p\n",__LINE__,pG711Param);
   1517         free(pG711Param);
   1518         APP_MEMPRINT("%d:::[TESTAPPFREE] %p\n",__LINE__,pCompPrivateStruct->format.audio.cMIMEType);
   1519         free(pCompPrivateStruct->format.audio.cMIMEType);
   1520         APP_MEMPRINT("%d:::[TESTAPPFREE] %p\n",__LINE__,pCompPrivateStruct);
   1521         free(pCompPrivateStruct);
   1522         if( (error != OMX_ErrorNone)) {
   1523             APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
   1524             goto EXIT;
   1525         }
   1526 
   1527         close(IpBuf_Pipe[0]);
   1528         close(IpBuf_Pipe[1]);
   1529         close(OpBuf_Pipe[0]);
   1530         close(OpBuf_Pipe[1]);
   1531 
   1532         close(Event_Pipe[0]);
   1533         close(Event_Pipe[1]);
   1534         APP_DPRINT ("%d Free Handle returned Successfully\n",__LINE__);
   1535 
   1536         fclose(inputToSN);
   1537         APP_DPRINT ("%d:: Free Handle returned Successfully \n\n\n\n",__LINE__);
   1538 
   1539     } /* For loop on testcnt1 ends here */
   1540 
   1541  EXIT:
   1542 
   1543 #ifdef OMX_GETTIME
   1544     GT_END("G711_DEC test <End>");
   1545     OMX_ListDestroy(pListHead);
   1546 #endif
   1547 
   1548     error = TIOMX_Deinit();
   1549     if( (error != OMX_ErrorNone)) {
   1550         APP_DPRINT("APP: Error in Deinit Core function\n");
   1551         goto EXIT;
   1552     }
   1553     return error;
   1554 }
   1555 
   1556 /***************************************************
   1557  *
   1558  *   Send_input_Buffer send input buffer to OMX_COMPONENT
   1559  *
   1560  *****************************************************/
   1561 OMX_ERRORTYPE send_input_buffer(OMX_HANDLETYPE pHandle, OMX_BUFFERHEADERTYPE* pBuffer, FILE *fIn)
   1562 {
   1563     OMX_ERRORTYPE error = OMX_ErrorNone;
   1564     OMX_S16 nRead = fill_data (pBuffer, fIn);
   1565     OMX_S16 i = 0;
   1566     APP_DPRINT ("%%%%%%%%%%%%%%%%%%%%%%%%%\n");
   1567     APP_DPRINT ("%d :: pBuffer = %p nRead = %d\n",__LINE__,pBuffer,nRead);
   1568     APP_DPRINT ("%%%%%%%%%%%%%%%%%%%%%%%%%\n");
   1569 
   1570     if((nRead < numRead) && (done == 0)) {
   1571         fprintf(stderr, "Shutting down Since last buffer was sent---------- \n");
   1572 #ifdef OMX_GETTIME
   1573         GT_START();
   1574 #endif
   1575         error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);
   1576         if(error != OMX_ErrorNone) {
   1577             fprintf (stderr,"Error from SendCommand-Idle(Stop) State function\n");
   1578             goto EXIT;
   1579         }
   1580         WaitForState(pHandle, OMX_StateIdle);
   1581 #ifdef OMX_GETTIME
   1582         GT_END("Call to SendCommand <OMX_StateIdle>");
   1583 #endif
   1584         done = 1;
   1585         pBuffer->nFlags = OMX_BUFFERFLAG_EOS;
   1586         printf("%i %s - EOS Has been ocurred \n",__LINE__,__FUNCTION__);
   1587     }
   1588 
   1589     else {
   1590         pBuffer->nFilledLen = nRead;
   1591         for (i=0; i < nRead; i++) {
   1592             fprintf(inputToSN,"pBuffer->pBuffer[%d] = %x\n",i,pBuffer->pBuffer[i]);
   1593         }
   1594         pBuffer->nTimeStamp = rand()%100;
   1595         pBuffer->nTickCount = rand() % 70;
   1596         TIME_PRINT("TimeStamp Input: %lld\n",pBuffer->nTimeStamp);
   1597         TICK_PRINT("TickCount Input: %ld\n",pBuffer->nTickCount);
   1598         error = OMX_EmptyThisBuffer(pHandle, pBuffer);
   1599         if (error == OMX_ErrorIncorrectStateOperation) error = 0;
   1600     }
   1601 
   1602  EXIT:
   1603     return error;
   1604 }
   1605 
   1606 
   1607 OMX_S16 fill_data (OMX_BUFFERHEADERTYPE *pBuf, FILE *fIn)
   1608 {
   1609     OMX_S16 nRead = 0;
   1610     static OMX_S16 totalRead = 0;
   1611     static OMX_S16 fileHdrReadFlag = 0;
   1612 
   1613     if (!fileHdrReadFlag) {
   1614         fprintf (stderr, "Reading the file\n");
   1615         fileHdrReadFlag = 1;
   1616     }
   1617 
   1618     if (testCaseNo == 7) { /* Multiframe with each buffer size = 2* framelenght */
   1619         numRead = 2*pBuf->nAllocLen;
   1620     }
   1621     else if (testCaseNo == 8) { /* Multiframe with each buffer size = 2/framelenght */
   1622         numRead = pBuf->nAllocLen/2;
   1623     }
   1624     else if (testCaseNo == 9) { /* Multiframe with alternating buffer size */
   1625         if (alternate == 0) {
   1626             numRead = 2*pBuf->nAllocLen;
   1627             alternate = 1;
   1628         }
   1629         else {
   1630             numRead = pBuf->nAllocLen/2;
   1631             alternate = 0;
   1632         }
   1633     }
   1634     else {
   1635         numRead = pBuf->nAllocLen;
   1636     }
   1637     nRead = fread(pBuf->pBuffer, 1, numRead , fIn);
   1638     totalRead += nRead;
   1639 
   1640     pBuf->nFilledLen = nRead;
   1641     return nRead;
   1642 }
   1643 
   1644 void ConfigureAudio()
   1645 {
   1646     int Mixer = 0, arg = 0, status = 0;
   1647 
   1648     Mixer = open("/dev/sound/mixer", O_WRONLY);
   1649     if (Mixer < 0) {
   1650         perror("open of /dev/sound/mixer failed");
   1651         exit(1);
   1652     }
   1653 
   1654     arg = G711DEC_SAMPLING_FREQUENCY;      /* sampling rate */
   1655     printf("Sampling freq set to:%d\n",arg);
   1656     status = ioctl(Mixer, SOUND_PCM_WRITE_RATE, &arg);
   1657     if (status == -1) {
   1658         perror("SOUND_PCM_WRITE_RATE ioctl failed");
   1659         printf("sample rate set to %u\n", arg);
   1660     }
   1661     arg = AFMT_S16_LE;          /* AFMT_S16_LE or AFMT_S32_LE */
   1662     status = ioctl(Mixer, SOUND_PCM_SETFMT, &arg);
   1663     if (status == -1) {
   1664         perror("SOUND_PCM_SETFMT ioctl failed");
   1665         printf("Bitsize set to %u\n", arg);
   1666     }
   1667     arg = 2;            /* Channels mono 1 stereo 2 */
   1668     status = ioctl(Mixer, SOUND_PCM_WRITE_CHANNELS, &arg);
   1669     if (status == -1) {
   1670         perror("SOUND_PCM_WRITE_CHANNELS ioctl failed");
   1671         printf("Channels set to %u\n", arg);
   1672     }
   1673     /* MIN 0 MAX 100 */
   1674 
   1675     arg = GAIN<<8|GAIN;
   1676     status = ioctl(Mixer, SOUND_MIXER_WRITE_VOLUME, &arg);
   1677     if (status == -1) {
   1678         perror("SOUND_MIXER_WRITE_VOLUME ioctl failed");
   1679         printf("Volume set to %u\n", arg);
   1680     }
   1681 }
   1682 
   1683 #ifdef APP_MEMDEBUG
   1684 void * mymalloc(int line, char *s, int size)
   1685 {
   1686     void *p;
   1687     int e=0;
   1688     p = malloc(size);
   1689     if(p==NULL){
   1690         printf("Memory not available\n");
   1691         exit(1);
   1692     }
   1693     else{
   1694         while((lines[e]!=0)&& (e<500) ){
   1695             e++;
   1696         }
   1697         arr[e]=p;
   1698         lines[e]=line;
   1699         bytes[e]=size;
   1700         strcpy(file[e],s);
   1701         printf("Allocating %d bytes on address %p, line %d file %s pos %d\n", size, p, line, s, e);
   1702         return p;
   1703     }
   1704 }
   1705 
   1706 int myfree(void *dp, int line, char *s)
   1707 {
   1708     int q = 0;
   1709     for(q=0;q<500;q++){
   1710         if(arr[q]==dp){
   1711             printf("Deleting %d bytes on address %p, line %d file %s\n", bytes[q],dp, line, s);
   1712             free(dp);
   1713             dp = NULL;
   1714             lines[q]=0;
   1715             strcpy(file[q],"");
   1716             break;
   1717         }
   1718     }
   1719     if(500==q)
   1720         printf("\n\nPointer not found. Line:%d    File%s!!\n\n",line, s);
   1721 
   1722     return 0;
   1723 }
   1724 #endif
   1725