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 OMX_G726DecTest.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\g726_dec\tests
     30  *
     31  * @rev  1.0
     32  */
     33 /* ----------------------------------------------------------------------------
     34  *!
     35  *! Revision History
     36  *! ===================================
     37  *! This is newest file
     38  * =========================================================================== */
     39 /* ------compilation control switches -------------------------*/
     40 /****************************************************************
     41  *  INCLUDE FILES
     42  ****************************************************************/
     43 /* ----- system and platform files ----------------------------*/
     44 #include <unistd.h>
     45 #include <stdlib.h>
     46 #include <sys/ioctl.h>
     47 #include <sys/select.h>
     48 #include <string.h>
     49 #include <stdio.h>
     50 #include <fcntl.h>
     51 #include <errno.h>
     52 #include <linux/vt.h>
     53 #include <signal.h>
     54 #include <sys/stat.h>
     55 #include <OMX_Index.h>
     56 #include <OMX_Types.h>
     57 #include <OMX_Core.h>
     58 #include <OMX_Audio.h>
     59 #include <OMX_Component.h>
     60 #include <TIDspOmx.h>
     61 #include <pthread.h>
     62 #include <stdio.h>
     63 #include <linux/soundcard.h>
     64 
     65 #ifdef OMX_GETTIME
     66 #include <OMX_Common_Utils.h>
     67 #include <OMX_GetTime.h>     /*Headers for Performance & measuremet */d
     68 #endif
     69 
     70 #undef MTRACE
     71 #ifdef MTRACE
     72 #include <mcheck.h>
     73 #endif
     74 
     75 #undef APP_DEBUG
     76 #undef APP_STATEDETAILS
     77 
     78 #undef USE_BUFFER
     79 
     80 #ifdef APP_DEBUG
     81 #define APP_DPRINT(...)    fprintf(stderr,__VA_ARGS__)
     82 #else
     83 #define APP_DPRINT(...)
     84 #endif
     85 
     86 
     87 #ifdef APP_STATEDETAILS
     88 #define APP_STATEPRINT(...)    fprintf(stderr,__VA_ARGS__)
     89 #else
     90 #define APP_STATEPRINT(...)
     91 #endif
     92 
     93 #define APP_OUTPUT_FILE "output.pcm"
     94 #define SLEEP_TIME 2
     95 
     96 #define G726_APP_ID  100 /* Defines G726 Dec App ID, App must use this value */
     97 #define INVALID_SAMPLING_FREQ  51 /*Do not change; fixed for component!*/
     98 #define MAX_NUM_OF_BUFS 10         /*Do not change; fixed for component!*/
     99 #define EOS_MIN_SIZE 2
    100 
    101 #ifdef OMX_GETTIME
    102 OMX_ERRORTYPE eError = OMX_ErrorNone;
    103 int GT_FlagE = 0;  /* Fill Buffer 1 = First Buffer,  0 = Not First Buffer  */
    104 int GT_FlagF = 0;  /*Empty Buffer  1 = First Buffer,  0 = Not First Buffer  */
    105 static OMX_NODE* pListHead = NULL;
    106 #endif
    107 
    108 
    109 int nIpBuffs = 1;
    110 int nOpBuffs = 1;
    111 int tcID = 0;
    112 
    113 int nIpBufSize = 20; /*default value */
    114 int nOpBufSize = 160; /* default value */
    115 
    116 int gDasfMode = 0;
    117 unsigned short packingType = 0;
    118 int bitRate = 0;
    119 int playcompleted = 0;
    120 
    121 OMX_STATETYPE gState = OMX_StateExecuting;
    122 
    123 #define FIFO1 "/dev/fifo.1"
    124 #define FIFO2 "/dev/fifo.2"
    125 
    126 #define LINEAR_PACKING 0
    127 #define RTP_PACKING 1
    128 
    129 int fdwrite = 0;
    130 int fdread = 0;
    131 
    132 
    133 int maxint(int a, int b);
    134 
    135 int fill_data (OMX_BUFFERHEADERTYPE *pBuf, FILE *fIn);
    136 
    137 OMX_STRING strG726Decoder = "OMX.TI.G726.decode";
    138 
    139 int IpBuf_Pipe[2] = {0};
    140 int OpBuf_Pipe[2] = {0};
    141 
    142 
    143 OMX_ERRORTYPE send_input_buffer (OMX_HANDLETYPE pHandle, OMX_BUFFERHEADERTYPE* pBuffer, FILE *fIn);
    144 
    145 fd_set rfds;
    146 
    147 
    148 /* ================================================================================= * */
    149 /**
    150  * @fn maxint() gives the maximum of two integers.
    151  *
    152  * @param a intetger a
    153  *
    154  * @param b integer b
    155  *
    156  * @pre          None
    157  *
    158  * @post         None
    159  *
    160  *  @return      bigger number
    161  *
    162  *  @see         None
    163  */
    164 /* ================================================================================ * */
    165 int maxint(int a, int b)
    166 {
    167     return (a>b) ? a : b;
    168 }
    169 
    170 /* ================================================================================= * */
    171 /**
    172  * @fn WaitForState() Waits for the state to change.
    173  *
    174  * @param pHandle This is component handle allocated by the OMX core.
    175  *
    176  * @param DesiredState This is state which the app is waiting for.
    177  *
    178  * @pre          None
    179  *
    180  * @post         None
    181  *
    182  *  @return      Appropriate OMX Error.
    183  *
    184  *  @see         None
    185  */
    186 /* ================================================================================ * */
    187 static OMX_ERRORTYPE WaitForState(OMX_HANDLETYPE* pHandle,
    188                                   OMX_STATETYPE DesiredState)
    189 {
    190     OMX_STATETYPE CurState = OMX_StateInvalid;
    191     OMX_ERRORTYPE eError = OMX_ErrorNone;
    192     int nCnt = 0;
    193 
    194     eError = OMX_GetState(*pHandle, &CurState);
    195     while( (eError == OMX_ErrorNone) &&
    196            (CurState != DesiredState) && (eError == OMX_ErrorNone) ) {
    197         sched_yield();
    198         if(nCnt++ == 10) {
    199             APP_DPRINT( "Still Waiting, press CTL-C to continue\n");
    200         }
    201         eError = OMX_GetState(*pHandle, &CurState);
    202     }
    203 
    204     return eError;
    205 }
    206 
    207 
    208 /* ================================================================================= * */
    209 /**
    210  * @fn EventHandler() This is event handle which is called by the component on
    211  * any event change.
    212  *
    213  * @param hComponent This is component handle allocated by the OMX core.
    214  *
    215  * @param pAppData This is application private data.
    216  *
    217  * @param eEvent  This is event generated from the component.
    218  *
    219  * @param nData1  Data1 associated with the event.
    220  *
    221  * @param nData2  Data2 associated with the event.
    222  *
    223  * @param pEventData Any other string event data from component.
    224  *
    225  * @pre          None
    226  *
    227  * @post         None
    228  *
    229  *  @return      Appropriate OMX error.
    230  *
    231  *  @see         None
    232  */
    233 /* ================================================================================ * */
    234 OMX_ERRORTYPE EventHandler(OMX_HANDLETYPE hComponent,OMX_PTR pAppData,OMX_EVENTTYPE eEvent,
    235                            OMX_U32 nData1, OMX_U32 nData2, OMX_PTR pEventData)
    236 {
    237     switch (eEvent)
    238     {
    239     case OMX_EventCmdComplete:
    240         gState = (OMX_STATETYPE)nData2;
    241         break;
    242     case OMX_EventError:
    243     case OMX_EventMax:
    244     case OMX_EventMark:
    245     case OMX_EventPortSettingsChanged:
    246     case OMX_EventBufferFlag:
    247         if(nData2 == (OMX_U32)OMX_BUFFERFLAG_EOS){
    248             /*                playcompleted = 1;
    249                               printf("playcomplted set true:: %d\n", __LINE__); */
    250         }
    251         break;
    252     case OMX_EventResourcesAcquired:
    253     case OMX_EventComponentResumed:
    254     case OMX_EventDynamicResourcesAvailable:
    255     case OMX_EventPortFormatDetected:
    256         break;
    257     }
    258 
    259     return OMX_ErrorNone;
    260 }
    261 
    262 /* ================================================================================= * */
    263 /**
    264  * @fn FillBufferDone() Component sens the output buffer to app using this
    265  * callback.
    266  *
    267  * @param hComponent This is component handle allocated by the OMX core.
    268  *
    269  * @param ptr This is another pointer.
    270  *
    271  * @param pBuffer This is output buffer.
    272  *
    273  * @pre          None
    274  *
    275  * @post         None
    276  *
    277  *  @return      None
    278  *
    279  *  @see         None
    280  */
    281 /* ================================================================================ * */
    282 void FillBufferDone (OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer)
    283 {
    284     write(OpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
    285 
    286 #ifdef OMX_GETTIME
    287     if (GT_FlagF == 1 ) /* First Buffer Reply*/  /* 1 = First Buffer,  0 = Not First Buffer  */
    288     {
    289         GT_END("Call to FillBufferDone  <First: FillBufferDone>");
    290         GT_FlagF = 0 ;   /* 1 = First Buffer,  0 = Not First Buffer  */
    291     }
    292 #endif
    293 }
    294 
    295 
    296 /* ================================================================================= * */
    297 /**
    298  * @fn EmptyBufferDone() Component sends the input buffer to app using this
    299  * callback.
    300  *
    301  * @param hComponent This is component handle allocated by the OMX core.
    302  *
    303  * @param ptr This is another pointer.
    304  *
    305  * @param pBuffer This is input buffer.
    306  *
    307  * @pre          None
    308  *
    309  * @post         None
    310  *
    311  *  @return      None
    312  *
    313  *  @see         None
    314  */
    315 /* ================================================================================ * */
    316 void EmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer)
    317 {
    318     write(IpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
    319 
    320 #ifdef OMX_GETTIME
    321     if (GT_FlagE == 1 ) /* First Buffer Reply*/  /* 1 = First Buffer,  0 = Not First Buffer  */
    322     {
    323         GT_END("Call to EmptyBufferDone <First: EmptyBufferDone>");
    324         GT_FlagE = 0;   /* 1 = First Buffer,  0 = Not First Buffer  */
    325     }
    326 #endif
    327 
    328 }
    329 
    330 /* ================================================================================= * */
    331 /**
    332  * @fn main() This is the main function of application which gets called.
    333  *
    334  * @param argc This is the number of commandline arguments..
    335  *
    336  * @param argv[] This is an array of pointers to command line arguments..
    337  *
    338  * @pre          None
    339  *
    340  * @post         None
    341  *
    342  *  @return      An integer value.
    343  *
    344  *  @see         None
    345  */
    346 /* ================================================================================ * */
    347 int main(int argc, char* argv[])
    348 {
    349     OMX_CALLBACKTYPE G726CaBa = {(void *)EventHandler,
    350                                  (void*)EmptyBufferDone,
    351                                  (void*)FillBufferDone};
    352     OMX_HANDLETYPE *pHandle = NULL;
    353     OMX_ERRORTYPE error = OMX_ErrorNone;
    354     OMX_U32 AppData = G726_APP_ID;
    355     OMX_PARAM_PORTDEFINITIONTYPE* pCompPrivateStruct = NULL;
    356     OMX_AUDIO_CONFIG_MUTETYPE* pCompPrivateStructMute = NULL;
    357     OMX_AUDIO_CONFIG_VOLUMETYPE* pCompPrivateStructVolume = NULL;
    358     OMX_AUDIO_PARAM_PCMMODETYPE *pPcmParam = NULL;
    359     OMX_AUDIO_PARAM_G726TYPE *pG726Param = NULL;
    360     TI_OMX_DSP_DEFINITION  *pAppPrivate = NULL;
    361     OMX_INDEXTYPE index = 0;
    362     OMX_COMPONENTTYPE *pComponent = NULL;
    363     OMX_BUFFERHEADERTYPE* pInputBufferHeader[MAX_NUM_OF_BUFS] = {NULL};
    364     OMX_BUFFERHEADERTYPE* pOutputBufferHeader[MAX_NUM_OF_BUFS] = {NULL};
    365 
    366     TI_OMX_DATAPATH dataPath;
    367     static int totalFilled = 0;
    368     int k=0;
    369     struct timeval tv;
    370     int retval = 0, j = 0;
    371     int frmCount = 0;
    372     int frmCnt = 1;
    373     int testcnt = 1;
    374     int testcnt1 = 1;
    375     char fname[100] = APP_OUTPUT_FILE;
    376     FILE* fIn = NULL;
    377     FILE* fOut = NULL;
    378 
    379 #ifdef MTRACE
    380     mtrace();
    381 #endif
    382 
    383 
    384     APP_DPRINT("------------------------------------------------------\n");
    385     APP_DPRINT("This is Main Thread In G726 DECODER Test Application:\n");
    386     APP_DPRINT("Test Core 1.5 - " __DATE__ ":" __TIME__ "\n");
    387     APP_DPRINT("------------------------------------------------------\n");
    388 #ifdef OMX_GETTIME
    389     GTeError = OMX_ListCreate(&pListHead);
    390     printf("eError = %d\n",GTeError);
    391     GT_START();
    392 #endif
    393     /* check the input parameters */
    394     if(argc != 10) {
    395         printf("Wrong Arguments: See Below:\n\n");
    396         printf("%d :: Usage: [TestApp] [Input File] [Input File Bit Rate] [TC ID]\
    397 [FM/DM] [NB INPUT BUF] [INPUT BUF SIZE] [NB OUTPUT BUF] [OUTPUT BUF SIZE] [PACKING TYPE]\n",__LINE__);
    398         goto EXIT;
    399     }
    400 
    401     /* check to see that the input file exists */
    402     struct stat sb = {0};
    403     int status = stat(argv[1], &sb);
    404     if( status != 0 ) {
    405         printf( "Cannot find file %s. (%u)\n", argv[1], errno);
    406         goto EXIT;
    407     }
    408 
    409     error = TIOMX_Init();
    410     if(error != OMX_ErrorNone) {
    411         APP_DPRINT("%d :: Error returned by OMX_Init()\n",__LINE__);
    412         goto EXIT;
    413     }
    414 
    415     if(!strcmp(argv[4],"DM")) {
    416         gDasfMode = 1;
    417     } else if(!strcmp(argv[4],"FM")) {
    418         gDasfMode = 0;
    419     } else {
    420         error = OMX_ErrorBadParameter;
    421         printf("\n%d :: App: Sending Bad Parameter for dasf mode\n",__LINE__);
    422         printf("%d :: App: Should Be One of these Modes FM or DM\n",__LINE__);
    423         goto EXIT;
    424     }
    425 
    426     nIpBuffs = atoi(argv[5]);
    427     APP_DPRINT("%d :: App: nIpBuf = %d\n",__LINE__, nIpBuffs);
    428     nIpBufSize = atoi(argv[6]);
    429     APP_DPRINT("%d :: App: nIpBufSize = %d\n",__LINE__, nIpBufSize);
    430     nOpBuffs = atoi(argv[7]);
    431     APP_DPRINT("%d :: App: nOpBuf = %d\n",__LINE__, nOpBuffs);
    432     nOpBufSize = atoi(argv[8]);
    433     APP_DPRINT("%d :: App: nOpBufSize = %d\n",__LINE__, nOpBufSize);
    434     packingType = atoi(argv[9]);
    435     APP_DPRINT("%d :: App: packingType = %d\n",__LINE__, packingType);
    436     bitRate = atoi(argv[2]);
    437     APP_DPRINT("%d :: App: bit rate = %d\n",__LINE__, bitRate);
    438 
    439     if(!strcmp(argv[3],"0")) {
    440         tcID = 0;
    441     }
    442     else if(!strcmp(argv[3],"1")) {
    443         tcID = 1;
    444     } else if (!strcmp(argv[3],"2")) {
    445         tcID = 2;
    446     } else if (!strcmp(argv[3],"3")) {
    447         tcID = 3;
    448     } else if (!strcmp(argv[3],"4")) {
    449         tcID = 4;
    450     } else if (!strcmp(argv[3],"5")) {
    451         tcID = 5;
    452     } else if (!strcmp(argv[3],"6")) {
    453         tcID = 6;
    454     } else if (!strcmp(argv[3],"7")) {
    455         tcID = 7;
    456     } else if (!strcmp(argv[3],"8")) {
    457         tcID = 8;
    458     } else {
    459         printf("Invalid Test Case ID: exiting...\n");
    460         exit(1);
    461     }
    462 
    463 
    464 
    465     switch (tcID) {
    466     case 1:
    467     case 7:
    468     case 8:
    469         printf ("-------------------------------------\n");
    470         printf ("Testing Simple PLAY till EOF \n");
    471         printf ("-------------------------------------\n");
    472         break;
    473     case 2:
    474         printf ("-------------------------------------\n");
    475         printf ("Testing Basic Stop \n");
    476         printf ("-------------------------------------\n");
    477         strcat(fname,"_tc2.pcm");
    478         break;
    479     case 3:
    480         printf ("-------------------------------------\n");
    481         printf ("Testing PAUSE & RESUME Command\n");
    482         printf ("-------------------------------------\n");
    483         break;
    484     case 4:
    485         printf ("---------------------------------------------\n");
    486         printf ("Testing STOP Command by Stopping In-Between\n");
    487         printf ("---------------------------------------------\n");
    488         break;
    489     case 5:
    490         printf ("-------------------------------------------------\n");
    491         printf ("Testing Repeated PLAY without Deleting Component\n");
    492         printf ("-------------------------------------------------\n");
    493         strcat(fname,"_tc5.pcm");
    494         testcnt = 20;
    495         break;
    496     case 6:
    497         printf ("------------------------------------------------\n");
    498         printf ("Testing Repeated PLAY with Deleting Component\n");
    499         printf ("------------------------------------------------\n");
    500         strcat(fname,"_tc6.pcm");
    501         testcnt1 = 20;
    502         break;
    503     }
    504 
    505     /**********************************************************
    506                 OUTER LOOP STARTS HERE
    507     **********************************************************/
    508     for(j = 0; j < testcnt1; j++) {
    509 
    510 #ifdef DSP_RENDERING_ON
    511         if((fdwrite=open(FIFO1,O_WRONLY))<0) {
    512             printf("[G726TEST] - failure to open WRITE pipe\n");
    513         }
    514         else {
    515             printf("[G726TEST] - opened WRITE pipe\n");
    516         }
    517 
    518         if((fdread=open(FIFO2,O_RDONLY))<0) {
    519             printf("[G726TEST] - failure to open READ pipe\n");
    520             goto EXIT;
    521         }
    522         else {
    523             printf("[G726TEST] - opened READ pipe\n");
    524         }
    525 #endif
    526 
    527         pHandle = malloc(sizeof(OMX_HANDLETYPE));
    528         if(pHandle == NULL){
    529             printf("%d :: App: Malloc Failed\n",__LINE__);
    530             goto EXIT;
    531         }
    532 #ifdef OMX_GETTIME
    533         GT_START();
    534         error = OMX_GetHandle(pHandle, strG726Decoder, &AppData, &G726CaBa);
    535         GT_END("Call to GetHandle");
    536 #else
    537         error = TIOMX_GetHandle(pHandle, strG726Decoder, &AppData, &G726CaBa);
    538 #endif
    539         if((error != OMX_ErrorNone) || (*pHandle == NULL))
    540         {
    541             APP_DPRINT ("Error in Get Handle function\n");
    542             goto EXIT;
    543         }
    544         /* Create a pipe used to queue data from the callback. */
    545         retval = pipe(IpBuf_Pipe);
    546         if( retval != 0) {
    547             printf( "Error:Fill Data Pipe failed to open\n");
    548             goto EXIT;
    549         }
    550 
    551         retval = pipe(OpBuf_Pipe);
    552         if( retval != 0) {
    553             printf( "Error:Empty Data Pipe failed to open\n");
    554             goto EXIT;
    555         }
    556 
    557         /* save off the "max" of the handles for the selct statement */
    558         int fdmax = maxint(IpBuf_Pipe[0], OpBuf_Pipe[0]);
    559 
    560         if (tcID == 6) {
    561             printf("*********************************************************\n");
    562             printf("%d :: Decoding for %d time\n",__LINE__, j);
    563             printf("*********************************************************\n");
    564         }
    565 
    566         /* Send  G726 config for input */
    567         pG726Param = malloc (sizeof(OMX_AUDIO_PARAM_G726TYPE));
    568         pG726Param->nSize                    = sizeof(OMX_AUDIO_PARAM_G726TYPE);
    569         pG726Param->nVersion.s.nVersionMajor = 1;
    570         pG726Param->nVersion.s.nVersionMinor = 1;
    571         pG726Param->nPortIndex               = OMX_DirInput;
    572         pG726Param->nChannels                = 1; /* mono */
    573         if (bitRate == 16){
    574             pG726Param->eG726Mode = OMX_AUDIO_G726Mode16;
    575         }
    576         else if(bitRate == 24){
    577             pG726Param->eG726Mode = OMX_AUDIO_G726Mode24;
    578         }
    579         else if(bitRate == 32){
    580             pG726Param->eG726Mode = OMX_AUDIO_G726Mode32;
    581         }
    582         else if(bitRate == 40){
    583             pG726Param->eG726Mode = OMX_AUDIO_G726Mode40;
    584         }
    585         else {
    586             printf("Invalid bit rate, please choose from 16, 24, 32, 40 kbps\n");
    587             goto EXIT;
    588         }
    589 #ifdef OMX_GETTIME
    590         GT_START();
    591         error = OMX_SetParameter (*pHandle, OMX_IndexParamAudioG726, pG726Param);
    592         GT_END("Set Parameter Test-SetParameter");
    593 #else
    594         error = OMX_SetParameter (*pHandle, OMX_IndexParamAudioG726, pG726Param);
    595 #endif
    596 
    597         if (error != OMX_ErrorNone)
    598         {
    599             error = OMX_ErrorBadParameter;
    600             goto EXIT;
    601         }
    602 
    603         pComponent =(OMX_COMPONENTTYPE *)(*pHandle);
    604         pCompPrivateStruct = malloc (sizeof (OMX_PARAM_PORTDEFINITIONTYPE));
    605         if(NULL == pCompPrivateStruct) {
    606             printf("%d :: App: Malloc Failed\n",__LINE__);
    607             goto EXIT;
    608         }
    609         /* set playback stream mute/unmute */
    610         pCompPrivateStructMute = malloc (sizeof(OMX_AUDIO_CONFIG_MUTETYPE));
    611         if(pCompPrivateStructMute == NULL) {
    612             printf("%d :: App: Malloc Failed\n",__LINE__);
    613             goto EXIT;
    614         }
    615         pCompPrivateStructVolume = malloc (sizeof(OMX_AUDIO_CONFIG_VOLUMETYPE));
    616         if(pCompPrivateStructVolume == NULL) {
    617             printf("%d :: App: Malloc Failed\n",__LINE__);
    618             goto EXIT;
    619         }
    620 
    621         pCompPrivateStruct->nSize = sizeof (OMX_PARAM_PORTDEFINITIONTYPE);
    622         pAppPrivate = malloc(sizeof(TI_OMX_DSP_DEFINITION));
    623         if (NULL == pAppPrivate) {
    624             printf("%d :: App: Error: Malloc Failed\n",__LINE__);
    625             goto EXIT;
    626         }
    627         pAppPrivate->dasfMode = gDasfMode;
    628         pAppPrivate->packingType = packingType;
    629         /* Send input port config */
    630         pCompPrivateStruct->eDir = OMX_DirInput;
    631         pCompPrivateStruct->nBufferCountActual = nIpBuffs;
    632         pCompPrivateStruct->nBufferSize = nIpBufSize;
    633         pCompPrivateStruct->format.audio.eEncoding = OMX_AUDIO_CodingG726;
    634         pCompPrivateStruct->bEnabled = OMX_TRUE;
    635         pCompPrivateStruct->bPopulated = OMX_FALSE;
    636         pCompPrivateStruct->nPortIndex = OMX_DirInput;
    637 #ifdef OMX_GETTIME
    638         GT_START();
    639         error = OMX_SetParameter(*pHandle,OMX_IndexParamPortDefinition, pCompPrivateStruct);
    640         GT_END("Set Parameter Test-SetParameter");
    641 #else
    642         error = OMX_SetParameter(*pHandle,OMX_IndexParamPortDefinition, pCompPrivateStruct);
    643 #endif
    644 
    645         if (error != OMX_ErrorNone)
    646         {
    647             error = OMX_ErrorBadParameter;
    648             printf ("%d :: OMX_ErrorBadParameter\n",__LINE__);
    649             goto EXIT;
    650         }
    651 
    652         /* Send output port config */
    653         pCompPrivateStruct->eDir = OMX_DirOutput;
    654         pCompPrivateStruct->nBufferCountActual = nOpBuffs;
    655         pCompPrivateStruct->nBufferSize = nOpBufSize;
    656         pCompPrivateStruct->format.audio.eEncoding = OMX_AUDIO_CodingPCM;
    657         pCompPrivateStruct->bEnabled = OMX_TRUE;
    658         pCompPrivateStruct->bPopulated = OMX_FALSE;
    659         pCompPrivateStruct->nPortIndex = OMX_DirOutput;
    660 
    661         if(gDasfMode == 1) {
    662             pCompPrivateStruct->bPopulated = OMX_TRUE;
    663         }
    664 
    665 #ifdef OMX_GETTIME
    666         GT_START();
    667         error = OMX_SetParameter(*pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
    668         GT_END("Set Parameter Test-SetParameter");
    669 #else
    670         error = OMX_SetParameter(*pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
    671 #endif
    672 
    673         if (error != OMX_ErrorNone)
    674         {
    675             error = OMX_ErrorBadParameter;
    676             printf ("%d :: OMX_ErrorBadParameter\n",__LINE__);
    677             goto EXIT;
    678         }
    679 
    680         error = OMX_GetExtensionIndex(*pHandle, "OMX.TI.index.config.g726headerinfo",&index);
    681         if (error != OMX_ErrorNone) {
    682             printf("Error getting extension index\n");
    683             goto EXIT;
    684         }
    685 
    686 
    687 #ifdef DSP_RENDERING_ON
    688         cmd_data.hComponent = *pHandle;
    689         cmd_data.AM_Cmd = AM_CommandIsOutputStreamAvailable;
    690 
    691         /* for decoder, using AM_CommandIsInputStreamAvailable */
    692         cmd_data.param1 = 0;
    693         if((write(fdwrite, &cmd_data, sizeof(cmd_data)))<0) {
    694             printf("%d ::G726DecTest.c ::[G726 Dec Component] - send command to audio manager\n", __LINE__);
    695         }
    696         if((read(fdread, &cmd_data, sizeof(cmd_data)))<0) {
    697             printf("%d ::G726DecTest.c ::[G726 Dec Component] - failure to get data from the audio manager\n", __LINE__);
    698             goto EXIT;
    699         }
    700         pAppPrivate->streamId = cmd_data.streamID;
    701 #endif
    702 
    703         OMX_SetConfig(*pHandle, index, pAppPrivate);
    704         if(error != OMX_ErrorNone) {
    705             error = OMX_ErrorBadParameter;
    706             APP_DPRINT("%d :: Error from OMX_SetConfig() function\n",__LINE__);
    707             goto EXIT;
    708         }
    709         APP_DPRINT("sending component to Idle state from loaded state\n");
    710 
    711 #ifdef OMX_GETTIME
    712         GT_START();
    713 #endif
    714 
    715         error = OMX_SendCommand(*pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
    716         if(error != OMX_ErrorNone) {
    717             APP_DPRINT ("Error from SendCommand-Idle(Init) State function - error = %d\n",error);
    718             goto EXIT;
    719         }
    720         int i = 0;
    721 
    722 #ifndef USE_BUFFER
    723         for(i=0; i<nIpBuffs; i++) {
    724             APP_DPRINT("%d :: About to call OMX_AllocateBuffer On Input\n",__LINE__);
    725             error = OMX_AllocateBuffer(*pHandle, &pInputBufferHeader[i], 0, NULL, nIpBufSize);
    726             APP_DPRINT("%d :: called OMX_AllocateBuffer\n",__LINE__);
    727             if(error != OMX_ErrorNone) {
    728                 APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer()\n",__LINE__);
    729                 goto EXIT;
    730             }
    731         }
    732 
    733         if (pAppPrivate->dasfMode == 0) {
    734             for(i=0; i<nOpBuffs; i++) {
    735                 error = OMX_AllocateBuffer(*pHandle,&pOutputBufferHeader[i],1,NULL,nOpBufSize);
    736                 if(error != OMX_ErrorNone) {
    737                     APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer()\n",__LINE__);
    738                     goto EXIT;
    739                 }
    740             }
    741         }
    742 
    743 #else
    744 
    745         OMX_U8* pInputBuffer[MAX_NUM_OF_BUFS] = {NULL};
    746         OMX_U8* pOutputBuffer[MAX_NUM_OF_BUFS] = {NULL};
    747         for(i=0; i<nIpBuffs; i++) {
    748             pInputBuffer[i] = (OMX_U8*)malloc(nIpBufSize);
    749             pInputBuffer[i] = pInputBuffer[i] + 128;
    750             APP_DPRINT("%d :: About to call OMX_UseBuffer On Input\n",__LINE__);
    751             error = OMX_UseBuffer(*pHandle,&pInputBufferHeader[i],0,NULL,nIpBufSize,pInputBuffer[i]);
    752             if(error != OMX_ErrorNone) {
    753                 APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n",__LINE__);
    754                 goto EXIT;
    755             }
    756         }
    757 
    758         if (pAppPrivate->dasfMode == 0) {
    759             for(i=0; i<nOpBuffs; i++) {
    760                 pOutputBuffer[i] = malloc (nOpBufSize + 256);
    761                 pOutputBuffer[i] = pOutputBuffer[i] + 128;
    762                 /* allocate output buffer */
    763                 APP_DPRINT("%d :: About to call OMX_UseBuffer On Output\n",__LINE__);
    764                 error = OMX_UseBuffer(*pHandle,&pOutputBufferHeader[i],1,NULL,nOpBufSize,pOutputBuffer[i]);
    765                 if(error != OMX_ErrorNone) {
    766                     APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n",__LINE__);
    767                     goto EXIT;
    768                 }
    769                 pOutputBufferHeader[i]->nFilledLen = 0;
    770             }
    771         }
    772 #endif
    773 
    774         /* g726 params for input was here */
    775 
    776         /* Send  G726 config for output */
    777         pPcmParam = malloc (sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
    778         pPcmParam->nSize                    = sizeof(OMX_AUDIO_PARAM_PCMMODETYPE);
    779         pPcmParam->nVersion.s.nVersionMajor = 1;
    780         pPcmParam->nVersion.s.nVersionMinor = 1;
    781         pPcmParam->nPortIndex               = OMX_DirOutput;
    782         pPcmParam->nChannels                = 1; /* mono */
    783         pPcmParam->nBitPerSample            = 16;
    784         pPcmParam->nSamplingRate            = 8000;
    785         pPcmParam->eNumData                 = OMX_NumericalDataUnsigned;
    786         pPcmParam->eEndian                  = OMX_EndianLittle;
    787         pPcmParam->bInterleaved             = OMX_FALSE;
    788         pPcmParam->ePCMMode                 = OMX_AUDIO_PCMModeLinear;
    789 
    790 #ifdef OMX_GETTIME
    791         GT_START();
    792         error = OMX_SetParameter (*pHandle, OMX_IndexParamAudioPcm, pPcmParam);
    793         GT_END("Set Parameter Test-SetParameter");
    794 #else
    795         error = OMX_SetParameter (*pHandle, OMX_IndexParamAudioPcm, pPcmParam);
    796 #endif
    797 
    798         if (error != OMX_ErrorNone) {
    799             error = OMX_ErrorBadParameter;
    800             goto EXIT;
    801         }
    802 
    803         /* default setting for Mute/Unmute */
    804         pCompPrivateStructMute->nSize                    = sizeof (OMX_AUDIO_CONFIG_MUTETYPE);
    805         pCompPrivateStructMute->nVersion.s.nVersionMajor = 0x1;
    806         pCompPrivateStructMute->nVersion.s.nVersionMinor = 0x1;
    807         pCompPrivateStructMute->nPortIndex               = OMX_DirInput;
    808         pCompPrivateStructMute->bMute                    = OMX_FALSE;
    809 
    810         /* default setting for volume */
    811         pCompPrivateStructVolume->nSize                    = sizeof(OMX_AUDIO_CONFIG_VOLUMETYPE);
    812         pCompPrivateStructVolume->nVersion.s.nVersionMajor = 0x1;
    813         pCompPrivateStructVolume->nVersion.s.nVersionMinor = 0x1;
    814         pCompPrivateStructVolume->nPortIndex               = OMX_DirInput;
    815         pCompPrivateStructVolume->bLinear                  = OMX_FALSE;
    816         pCompPrivateStructVolume->sVolume.nValue           = 50;  /* actual volume */
    817         pCompPrivateStructVolume->sVolume.nMin             = 0;   /* min volume */
    818         pCompPrivateStructVolume->sVolume.nMax             = 100; /* max volume */
    819 
    820         if(pAppPrivate->dasfMode == 1) {
    821             APP_DPRINT("%d :: G726 DECODER RUNNING UNDER DASF MODE\n",__LINE__);
    822         } else if(pAppPrivate->dasfMode == 0) {
    823             APP_DPRINT("%d :: G726 DECODER RUNNING UNDER FILE MODE\n",__LINE__);
    824         } else {
    825             printf("%d :: IMPROPER SETTING OF DASF/FILE MODE \n",__LINE__);
    826         }
    827 
    828         if (gDasfMode) {
    829             APP_DPRINT("***************StreamId=%d******************\n", (int)pAppPrivate->streamId);
    830 #ifdef RTM_PATH
    831             dataPath = DATAPATH_APPLICATION_RTMIXER;
    832 #endif
    833 #ifdef ETEEDN_PATH
    834             dataPath = DATAPATH_APPLICATION;
    835 #endif
    836             error = OMX_GetExtensionIndex(*pHandle, "OMX.TI.index.config.g726dec.datapath",&index);
    837             if (error != OMX_ErrorNone) {
    838                 printf("Error getting extension index\n");
    839                 goto EXIT;
    840             }
    841             error = OMX_SetConfig (*pHandle, index, &dataPath);
    842             if(error != OMX_ErrorNone) {
    843                 error = OMX_ErrorBadParameter;
    844                 APP_DPRINT("%d :: G726DecTest.c :: Error from OMX_SetConfig() function\n",__LINE__);
    845                 goto EXIT;
    846             }
    847         }
    848 
    849         APP_DPRINT("%d :: App :: About to call WaitForState to change to Idle\n",__LINE__);
    850         error = WaitForState(pHandle, OMX_StateIdle);
    851 #ifdef OMX_GETTIME
    852         GT_END("Call to SendCommand <OMX_StateIdle> After Init & Clearing Buffers");
    853 #endif
    854         APP_DPRINT("%d :: App :: state changed to Idle\n",__LINE__);
    855         if(error != OMX_ErrorNone) {
    856             APP_DPRINT( "Error:  hG726Decoder->WaitForState reports an error %X\n", error);
    857             goto EXIT;
    858         }
    859 
    860         /*****************************************************
    861                     INNER LOOP STARTS
    862         *****************************************************/
    863         for(i = 0; i < testcnt; i++) {
    864             fIn = fopen(argv[1], "r");
    865             if(fIn == NULL) {
    866                 fprintf(stderr, "Error:  failed to open the file %s for readonly access\n", argv[1]);
    867                 goto EXIT;
    868             }
    869 
    870             if(gDasfMode == 0) {
    871                 fOut = fopen(fname, "w");
    872                 if(fOut == NULL) {
    873                     fprintf(stderr, "Error:  failed to create the output file \n");
    874                     goto EXIT;
    875                 }
    876                 APP_DPRINT("%d :: Op File has created\n",__LINE__);
    877             }
    878 
    879             if (tcID == 5) {
    880                 printf("*********************************************************\n");
    881                 printf ("App: Decoding for %d time\n",i);
    882                 printf("*********************************************************\n");
    883             }
    884 #ifdef OMX_GETTIME
    885             GT_START();
    886 #endif
    887             error = OMX_SendCommand(*pHandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
    888             if(error != OMX_ErrorNone) {
    889                 APP_DPRINT ("Error from SendCommand-Executing State function\n");
    890                 goto EXIT;
    891             }
    892 
    893             APP_DPRINT("%d :: App :: About to call WaitForState to change to Executing\n",__LINE__);
    894             error = WaitForState(pHandle, OMX_StateExecuting);
    895             gState = OMX_StateExecuting;
    896 #ifdef OMX_GETTIME
    897             GT_END("Call to SendCommand <OMX_StateExecuting>");
    898 #endif
    899             APP_DPRINT("%d :: App :: state changed to Executing\n",__LINE__);
    900             if(error != OMX_ErrorNone) {
    901                 APP_DPRINT( "Error:  WaitForState reports an error %X\n", error);
    902                 goto EXIT;
    903             }
    904 
    905             for (k=0; k < nIpBuffs; k++) {
    906 #ifdef OMX_GETTIME
    907                 if (k==0)
    908                 {
    909                     GT_FlagE=1;  /* 1 = First Buffer,  0 = Not First Buffer  */
    910                     GT_START(); /* Empty Bufffer */
    911                 }
    912 #endif
    913                 error = send_input_buffer (*pHandle, pInputBufferHeader[k], fIn);
    914                 if (error != OMX_ErrorNone){
    915                     printf("error from send input buffer!\n");
    916                     goto EXIT;
    917                 }
    918             }
    919 
    920             if (gDasfMode == 0) {
    921                 for (k=0; k < nOpBuffs; k++) {
    922 #ifdef OMX_GETTIME
    923                     if (k==0)
    924                     {
    925                         GT_FlagF=1;  /* 1 = First Buffer,  0 = Not First Buffer  */
    926                         GT_START(); /* Fill Buffer */
    927                     }
    928 #endif
    929                     OMX_FillThisBuffer(*pHandle, pOutputBufferHeader[k]);
    930                 }
    931             }
    932 
    933             while((error == OMX_ErrorNone) && (gState != OMX_StateIdle)) {
    934                 FD_ZERO(&rfds);
    935                 FD_SET(IpBuf_Pipe[0], &rfds);
    936                 FD_SET(OpBuf_Pipe[0], &rfds);
    937                 tv.tv_sec = 1;
    938                 tv.tv_usec = 0;
    939                 frmCount++;
    940 
    941                 retval = select(fdmax+1, &rfds, NULL, NULL, &tv);
    942                 if(retval == -1) {
    943                     perror("select()");
    944                     APP_DPRINT ( " : Error \n");
    945                     break;
    946                 }
    947 
    948                 if(retval == 0) {
    949                     APP_DPRINT ("%d :: Basic App Timeout !!!!!!!!!!! \n",__LINE__);
    950                 }
    951 
    952                 switch (tcID) {
    953                 case 0:
    954                 case 1:
    955                 case 5:
    956                 case 6:
    957                     if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {
    958                         OMX_BUFFERHEADERTYPE* pBuffer = NULL;
    959                         read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
    960                         error = send_input_buffer (*pHandle, pBuffer, fIn);
    961                         if (error != OMX_ErrorNone) {
    962                             printf("error from send buffer!\n");
    963                             goto EXIT;
    964                         }
    965                         frmCnt++;
    966                     }
    967                     break;
    968                 case 2:
    969                 case 4:
    970                     if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {
    971                         OMX_BUFFERHEADERTYPE* pBuffer = NULL;
    972                         read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
    973                         if(frmCnt == 40) {
    974                             APP_DPRINT("Shutting down ---------- \n");
    975 #ifdef OMX_GETTIME
    976                             GT_START();
    977 #endif
    978                             error = OMX_SendCommand(*pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);
    979                             if(error != OMX_ErrorNone) {
    980                                 fprintf (stderr,"Error from SendCommand-Idle(Stop) State function\n");
    981                                 goto EXIT;
    982                             }
    983                             /*pBuffer->nFilledLen = 0;
    984                               pComponent->EmptyThisBuffer(*pHandle, pBuffer);*/
    985                         } else {
    986                             error = send_input_buffer (*pHandle, pBuffer, fIn);
    987                             if (error != OMX_ErrorNone) {
    988                                 printf ("Error While reading input pipe\n");
    989                                 goto EXIT;
    990                             }
    991                         }
    992                         if(frmCnt == 40 && tcID == 4) {
    993                             APP_STATEPRINT ("*********** Waiting for state to change to Idle ************\n\n");
    994                             error = WaitForState(pHandle, OMX_StateIdle);
    995 #ifdef OMX_GETTIME
    996                             GT_END("Call to SendCommand <OMX_StateIdle>");
    997 #endif
    998                             if(error != OMX_ErrorNone) {
    999                                 fprintf(stderr, "Error:  WaitForState reports an error %X\n", error);
   1000                                 goto EXIT;
   1001                             }
   1002                             APP_STATEPRINT("*********** State Changed to Idle ************\n\n");
   1003 
   1004                             printf("Component Has Stopped here and waiting for %d seconds before it plays further\n",SLEEP_TIME);
   1005                             sleep(SLEEP_TIME);
   1006 
   1007                             APP_STATEPRINT("*************** Execute command to Component *******************\n");
   1008 #ifdef OMX_GETTIME
   1009                             GT_START();
   1010 #endif
   1011                             error = OMX_SendCommand(*pHandle, OMX_CommandStateSet,OMX_StateExecuting, NULL);
   1012                             if(error != OMX_ErrorNone) {
   1013                                 fprintf (stderr,"Error from SendCommand-Executing State function\n");
   1014                                 goto EXIT;
   1015                             }
   1016 
   1017                             APP_STATEPRINT("*********** Waiting for state to change to Executing ************\n\n");
   1018                             error = WaitForState(pHandle, OMX_StateExecuting);
   1019 #ifdef OMX_GETTIME
   1020                             GT_END("Call to SendCommand <OMX_StateExecuting>");
   1021 #endif
   1022                             if(error != OMX_ErrorNone) {
   1023                                 fprintf(stderr, "Error:  WaitForState reports an error %X\n", error);
   1024                                 goto EXIT;
   1025                             }
   1026                             gState = OMX_StateExecuting;
   1027                             APP_STATEPRINT("*********** State Changed to Executing ************\n\n");
   1028 
   1029                             if (gDasfMode == 0) {
   1030                                 /*rewind input and output files*/
   1031                                 fseek(fIn, 0L, SEEK_SET);
   1032                                 fseek(fOut, 0L, SEEK_SET);
   1033                             }
   1034 
   1035                             for (k=0; k < nIpBuffs; k++) {
   1036                                 /* memset(pInputBufferHeader[k],0,nIpBufSize); */
   1037                                 error = send_input_buffer (*pHandle, pInputBufferHeader[k], fIn);
   1038                             }
   1039                         }
   1040                         frmCnt++;
   1041                     }
   1042                     break;
   1043                 case 3:
   1044                     if(frmCount == 30 || frmCount == 60) {
   1045                         APP_STATEPRINT("\n\n*************** Pause command to Component *******************\n");
   1046 #ifdef OMX_GETTIME
   1047                         GT_START();
   1048 #endif
   1049                         error = OMX_SendCommand(*pHandle, OMX_CommandStateSet, OMX_StatePause, NULL);
   1050                         if(error != OMX_ErrorNone) {
   1051                             fprintf (stderr,"Error from SendCommand-Pasue State function\n");
   1052                             goto EXIT;
   1053                         }
   1054                         APP_STATEPRINT("*********** Waiting for state to change to Pause ************\n");
   1055 
   1056                         error = WaitForState(pHandle, OMX_StatePause);
   1057 #ifdef OMX_GETTIME
   1058                         GT_END("Call to SendCommand <OMX_StatePause>");
   1059 #endif
   1060                         if(error != OMX_ErrorNone) {
   1061                             fprintf(stderr, "Error:  WaitForState reports an error %X\n", error);
   1062                             goto EXIT;
   1063                         }
   1064                         APP_STATEPRINT("*********** State Changed to Pause ************\n\n");
   1065 
   1066                         printf("Sleeping for %d secs....\n\n",SLEEP_TIME);
   1067                         sleep(SLEEP_TIME);
   1068 
   1069                         APP_STATEPRINT("*************** Resume command to Component *******************\n");
   1070 #ifdef OMX_GETTIME
   1071                         GT_START();
   1072 #endif
   1073                         error = OMX_SendCommand(*pHandle, OMX_CommandStateSet,OMX_StateExecuting, NULL);
   1074                         if(error != OMX_ErrorNone) {
   1075                             fprintf (stderr,"Error from SendCommand-Executing State function\n");
   1076                             goto EXIT;
   1077                         }
   1078 
   1079                         APP_STATEPRINT("******** Waiting for state to change to Resume ************\n");
   1080 
   1081                         error = WaitForState(pHandle, OMX_StateExecuting);
   1082 #ifdef OMX_GETTIME
   1083                         GT_END("Call to SendCommand <OMX_StateExecuting>");
   1084 #endif
   1085                         if(error != OMX_ErrorNone) {
   1086                             fprintf(stderr, "Error:  WaitForState reports an error %X\n", error);
   1087                             goto EXIT;
   1088                         }
   1089                         APP_STATEPRINT("*********** State Changed to Resume ************\n\n");
   1090                     }
   1091 
   1092                     if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {
   1093                         OMX_BUFFERHEADERTYPE* pBuffer = NULL;
   1094                         read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
   1095                         error = send_input_buffer (*pHandle, pBuffer, fIn);
   1096                         if (error != OMX_ErrorNone) {
   1097                             printf ("Error While reading input pipe\n");
   1098                             goto EXIT;
   1099                         }
   1100                         frmCnt++;
   1101                     }
   1102                     break;
   1103                 case 7:
   1104                     /* test mute/unmute playback stream */
   1105                     if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {
   1106                         OMX_BUFFERHEADERTYPE* pBuffer = NULL;
   1107                         read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
   1108                         error = send_input_buffer (*pHandle, pBuffer, fIn);
   1109                         if (error != OMX_ErrorNone) {
   1110                             goto EXIT;
   1111                         }
   1112                         frmCnt++;
   1113                     }
   1114 
   1115                     if(frmCnt == 3) {
   1116                         printf("************Mute the playback stream*****************\n");
   1117                         pCompPrivateStructMute->bMute = OMX_TRUE;
   1118                         error = OMX_SetConfig(*pHandle, OMX_IndexConfigAudioMute, pCompPrivateStructMute);
   1119                         if (error != OMX_ErrorNone) {
   1120                             error = OMX_ErrorBadParameter;
   1121                             goto EXIT;
   1122                         }
   1123                     }
   1124 
   1125                     if(frmCnt == 6) {
   1126                         printf("************Unmute the playback stream*****************\n");
   1127                         pCompPrivateStructMute->bMute = OMX_FALSE;
   1128                         error = OMX_SetConfig(*pHandle, OMX_IndexConfigAudioMute, pCompPrivateStructMute);
   1129                         if (error != OMX_ErrorNone) {
   1130                             error = OMX_ErrorBadParameter;
   1131                             goto EXIT;
   1132                         }
   1133                     }
   1134                     break;
   1135                 case 8:
   1136                     /* test set volume for playback stream */
   1137                     if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {
   1138                         OMX_BUFFERHEADERTYPE* pBuffer = NULL;
   1139                         read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
   1140                         error = send_input_buffer (*pHandle, pBuffer, fIn);
   1141                         if (error != OMX_ErrorNone) {
   1142                             goto EXIT;
   1143                         }
   1144                         frmCnt++;
   1145                     }
   1146 
   1147                     if(frmCnt == 3) {
   1148                         printf("************Set stream volume to high*****************\n");
   1149                         pCompPrivateStructVolume->sVolume.nValue = 0x8000;
   1150                         error = OMX_SetConfig(*pHandle, OMX_IndexConfigAudioVolume, pCompPrivateStructVolume);
   1151                         if (error != OMX_ErrorNone) {
   1152                             error = OMX_ErrorBadParameter;
   1153                             goto EXIT;
   1154                         }
   1155                     }
   1156 
   1157                     if(frmCnt == 6) {
   1158                         printf("************Set stream volume to low*****************\n");
   1159                         pCompPrivateStructVolume->sVolume.nValue = 0x1000;
   1160                         error = OMX_SetConfig(*pHandle, OMX_IndexConfigAudioVolume, pCompPrivateStructVolume);
   1161                         if (error != OMX_ErrorNone) {
   1162                             error = OMX_ErrorBadParameter;
   1163                             goto EXIT;
   1164                         }
   1165                     }
   1166                     break;
   1167                 default:
   1168                     APP_DPRINT("%d :: ### Running Simple DEFAULT Case Here ###\n",__LINE__);
   1169                 }
   1170 
   1171                 if( FD_ISSET(OpBuf_Pipe[0], &rfds) ) {
   1172                     OMX_BUFFERHEADERTYPE* pBuf = NULL;
   1173                     read(OpBuf_Pipe[0], &pBuf, sizeof(pBuf));
   1174                     if(pBuf->nFilledLen == 0){
   1175                         APP_DPRINT("%d :: APP: output buffer received, filled length = %d, totalfilled = %d\n",__LINE__,(int)pBuf->nFilledLen,totalFilled);
   1176                     }else {
   1177                         APP_DPRINT("%d :: APP: output buffer received, filled length = %d, totalfilled = %d\n",__LINE__,(int)pBuf->nFilledLen,totalFilled);
   1178                         fwrite(pBuf->pBuffer, 1, pBuf->nFilledLen, fOut);
   1179                         if (tcID == 0){
   1180                             APP_DPRINT("-----------------------------------------\n");
   1181                             APP_DPRINT("Output time stamp = %d\n", (int)pBuf->nTimeStamp);
   1182                             APP_DPRINT("Output tick count = %ld\n", pBuf->nTickCount);
   1183                             APP_DPRINT("-----------------------------------------\n");
   1184                         }
   1185 
   1186                     }
   1187                     totalFilled ++;
   1188                     fflush(fOut);
   1189                     OMX_FillThisBuffer(*pHandle, pBuf);
   1190 
   1191                 }
   1192                 if(playcompleted){
   1193                     printf("play completed, stopping component\n");
   1194 
   1195 #ifdef OMX_GETTIME
   1196                     GT_START();
   1197 #endif
   1198                     error = OMX_SendCommand(*pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);
   1199                     if(error != OMX_ErrorNone) {
   1200                         fprintf (stderr,"Error from SendCommand-Idle(Stop) State function\n");
   1201                         goto EXIT;
   1202                     }
   1203                     error = WaitForState(pHandle, OMX_StateIdle);
   1204 #ifdef OMX_GETTIME
   1205                     GT_END("Call to SendCommand <OMX_StateIdle>");
   1206 #endif
   1207                     if(error != OMX_ErrorNone) {
   1208                         fprintf(stderr, "Error:  hG726Decoder->WaitForState reports an error %X\n", error);
   1209                         goto EXIT;
   1210                     }
   1211                     playcompleted = 0;
   1212 
   1213                 }
   1214             } /* While Loop Ending Here */
   1215 
   1216             if(0 == gDasfMode) {
   1217                 fclose(fOut);
   1218             }
   1219 
   1220             fclose(fIn);
   1221             if(i != (testcnt-1)) {
   1222                 if((tcID == 5) || (tcID == 2)) {
   1223                     printf("%d :: sleeping here for %d secs\n",__LINE__,SLEEP_TIME);
   1224                     sleep (SLEEP_TIME);
   1225                 } else {
   1226                     sleep (0);
   1227                 }
   1228             }
   1229 
   1230         }
   1231 
   1232         /*******************************************************
   1233                 END INNER LOOP
   1234         *******************************************************/
   1235 
   1236 #ifdef DSP_RENDERING_ON
   1237         cmd_data.hComponent = *pHandle;
   1238         cmd_data.AM_Cmd = AM_Exit;
   1239         if((write(fdwrite, &cmd_data, sizeof(cmd_data)))<0)
   1240             printf("%d :: [G726 Dec Component] - send command to audio manager\n",__LINE__);
   1241         close(fdwrite);
   1242         close(fdread);
   1243 #endif
   1244 
   1245         for(i=0; i<nIpBuffs; i++) {
   1246             APP_DPRINT("%d :: App: Freeing %p IP BufHeader\n",__LINE__,pInputBufferHeader[i]);
   1247             error = OMX_FreeBuffer(*pHandle,OMX_DirInput,pInputBufferHeader[i]);
   1248             if((error != OMX_ErrorNone)) {
   1249                 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
   1250                 goto EXIT;
   1251             }
   1252         }
   1253 
   1254         if(pAppPrivate->dasfMode == 0) {
   1255             for(i=0; i<nOpBuffs; i++) {
   1256                 APP_DPRINT("%d :: App: Freeing %p OP BufHeader\n",__LINE__,pOutputBufferHeader[i]);
   1257                 error = OMX_FreeBuffer(*pHandle,OMX_DirOutput,pOutputBufferHeader[i]);
   1258                 if((error != OMX_ErrorNone)) {
   1259                     APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
   1260                     goto EXIT;
   1261                 }
   1262             }
   1263         }
   1264 
   1265         APP_DPRINT ("Sending the StateLoaded Command\n");
   1266 
   1267 #ifdef OMX_GETTIME
   1268         GT_START();
   1269 #endif
   1270 
   1271         error = OMX_SendCommand(*pHandle,OMX_CommandStateSet, OMX_StateLoaded, NULL);
   1272         error = WaitForState(pHandle, OMX_StateLoaded);
   1273 
   1274 #ifdef OMX_GETTIME
   1275         GT_END("Call to SendCommand <OMX_StateLoaded>");
   1276 #endif
   1277 
   1278         if(error != OMX_ErrorNone) {
   1279             APP_DPRINT ("%d:: Error from SendCommand-Idle State function\n",__LINE__);
   1280             goto EXIT;
   1281         }
   1282 
   1283         error = TIOMX_FreeHandle(*pHandle);
   1284         if( (error != OMX_ErrorNone)) {
   1285             APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
   1286             goto EXIT;
   1287         }
   1288         APP_DPRINT ("%d:: Free Handle returned Successfully \n\n\n\n",__LINE__);
   1289         if (pHandle) {
   1290             free(pHandle);
   1291             pHandle = NULL;
   1292         }
   1293 
   1294         if(pCompPrivateStruct != NULL){
   1295             free(pCompPrivateStruct);
   1296             pCompPrivateStruct = NULL;
   1297         }
   1298         if(pG726Param != NULL){
   1299             free(pG726Param);
   1300             pG726Param = NULL;
   1301         }
   1302         if(pPcmParam != NULL){
   1303             free(pPcmParam);
   1304             pPcmParam = NULL;
   1305         }
   1306         if(pCompPrivateStructMute != NULL){
   1307             free(pCompPrivateStructMute);
   1308             pCompPrivateStructMute = NULL;
   1309         }
   1310         if(pCompPrivateStructVolume != NULL){
   1311             free(pCompPrivateStructVolume);
   1312             pCompPrivateStructVolume = NULL;
   1313         }
   1314         if(pAppPrivate != NULL){
   1315             free(pAppPrivate);
   1316             pAppPrivate = NULL;
   1317         }
   1318 
   1319         close(IpBuf_Pipe[0]);
   1320         close(IpBuf_Pipe[1]);
   1321         close(OpBuf_Pipe[0]);
   1322         close(OpBuf_Pipe[1]);
   1323     }
   1324     /**************************************************
   1325             END OUTER LOOP
   1326     **************************************************/
   1327     if (gDasfMode == 0) {
   1328         printf("**********************************************************\n");
   1329         printf("NOTE: An output file has been created in file system\n");
   1330         printf("**********************************************************\n");
   1331     }
   1332  EXIT:
   1333 
   1334 #ifdef MTRACE
   1335     muntrace();
   1336 #endif
   1337 
   1338 #ifdef OMX_GETTIME
   1339     GT_END("G726_DEC test <End>");
   1340     OMX_ListDestroy(pListHead);
   1341 #endif
   1342     return error;
   1343 }
   1344 
   1345 
   1346 /* ================================================================================= * */
   1347 /**
   1348  * @fn send_input_buffer() Sends the input buffer to the component.
   1349  *
   1350  * @param pHandle This is component handle allocated by the OMX core.
   1351  *
   1352  * @param pBuffer This is the buffer pointer.
   1353  *
   1354  * @fIn This is input file handle.
   1355  *
   1356  * @pre          None
   1357  *
   1358  * @post         None
   1359  *
   1360  *  @return      Appropriate OMX error.
   1361  *
   1362  *  @see         None
   1363  */
   1364 /* ================================================================================ * */
   1365 OMX_ERRORTYPE send_input_buffer(OMX_HANDLETYPE pHandle, OMX_BUFFERHEADERTYPE* pBuffer, FILE *fIn)
   1366 {
   1367     OMX_ERRORTYPE error = OMX_ErrorNone;
   1368     int nRead = 0;
   1369 
   1370     nRead = fill_data (pBuffer, fIn);
   1371 
   1372     if (tcID == 0){
   1373         pBuffer->nTimeStamp = (OMX_S64) rand() % 2;
   1374         pBuffer->nTickCount = rand() % 70;
   1375         APP_DPRINT("Input time stamp = %d\n", (int)pBuffer->nTimeStamp);
   1376         APP_DPRINT("Input tick count = %ld\n", pBuffer->nTickCount);
   1377     }
   1378     if(nRead < nIpBufSize)
   1379     {
   1380         pBuffer->nFlags = OMX_BUFFERFLAG_EOS;
   1381     }
   1382     else {
   1383         pBuffer->nFlags = 0;
   1384     }
   1385 
   1386     OMX_EmptyThisBuffer(pHandle, pBuffer);
   1387 
   1388     return error;
   1389 
   1390 }
   1391 
   1392 /* ================================================================================= * */
   1393 /**
   1394  * @fn fill_data() Reads the data from the input file.
   1395  *
   1396  * @param pBuffer This is the buffer pointer.
   1397  *
   1398  * @fIn This is input file handle.
   1399  *
   1400  * @pre          None
   1401  *
   1402  * @post         None
   1403  *
   1404  *  @return      Number of bytes that have been read.
   1405  *
   1406  *  @see         None
   1407  */
   1408 /* ================================================================================ * */
   1409 int fill_data (OMX_BUFFERHEADERTYPE *pBuf,FILE *fIn)
   1410 {
   1411     int nRead = 0;
   1412     static int totalRead = 0;
   1413     static int fileHdrReadFlag = 0;
   1414     static int ccnt = 1;
   1415 
   1416     playcompleted = 0;
   1417     if (!fileHdrReadFlag) {
   1418         fileHdrReadFlag = 1;
   1419     }
   1420     nRead = fread(pBuf->pBuffer, 1, pBuf->nAllocLen , fIn);
   1421     pBuf->nFlags = 0;
   1422     if (nRead != 0) {
   1423         totalRead += nRead;
   1424         pBuf->nFilledLen = nRead;
   1425         pBuf->nAllocLen = nIpBufSize;
   1426         ccnt++;
   1427 
   1428         APP_DPRINT("\n*****************************************************\n");
   1429         APP_DPRINT ("%d :: App:: pBuf->pBuffer = %p pBuf->nAllocLen = * %ld, nRead = %d, totalread = %d\n",
   1430                     __LINE__, pBuf->pBuffer, pBuf->nAllocLen, nRead, totalRead);
   1431         APP_DPRINT("\n*****************************************************\n");
   1432 
   1433         if (nRead < pBuf->nAllocLen){
   1434             pBuf->nFlags = OMX_BUFFERFLAG_EOS;
   1435             playcompleted = 1;
   1436             printf("End of file on partially filled buffer\n");
   1437         }
   1438     }
   1439     else{
   1440         pBuf->nFlags = OMX_BUFFERFLAG_EOS;
   1441         pBuf->nFilledLen = 0;
   1442         playcompleted = 1;
   1443         printf("End of file on a empty buffer \n");
   1444     }
   1445 
   1446     return nRead;
   1447 }
   1448