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 WbAmrEnc_Test.c
     26 *
     27 * This file implements WBAMR Encoder Component Specific APIs and its functionality
     28 * that is fully compliant with the Khronos OpenMAX (TM) 1.0 Specification
     29 *
     30 * @path  $(CSLPATH)\OMAPSW_MPU\linux\audio\src\openmax_il\wbamr_enc\tests
     31 *
     32 * @rev  1.0
     33 */
     34 /* ----------------------------------------------------------------------------
     35 *!
     36 *! Revision History
     37 *! ===================================
     38 *! 21-sept-2006 bk: updated review findings for alpha release
     39 *! 24-Aug-2006 bk: Khronos OpenMAX (TM) 1.0 Conformance tests some more
     40 *! 18-July-2006 bk: Khronos OpenMAX (TM) 1.0 Conformance tests validated for few cases
     41 *! This is newest file
     42 * =========================================================================== */
     43 /* ------compilation control switches -------------------------*/
     44 /****************************************************************
     45 *  INCLUDE FILES
     46 ****************************************************************/
     47 /* ----- system and platform files ----------------------------*/
     48 
     49 #include <unistd.h>
     50 #include <sys/ioctl.h>
     51 #include <sys/select.h>
     52 #include <errno.h>
     53 #include <linux/vt.h>
     54 #include <signal.h>
     55 #include <sys/stat.h>
     56 #include <pthread.h>
     57 #include <linux/soundcard.h>
     58 
     59 #include <string.h>
     60 #include <fcntl.h>
     61 #include <stdlib.h>
     62 #include <stdio.h>
     63 #include <OMX_Index.h>
     64 #include <OMX_Types.h>
     65 #include <OMX_Component.h>
     66 #include <OMX_Core.h>
     67 #include <OMX_Audio.h>
     68 #include <TIDspOmx.h>
     69 
     70 #ifdef DSP_RENDERING_ON
     71 #include <AudioManagerAPI.h>
     72 #endif
     73 #include <time.h>
     74 
     75 #ifdef OMX_GETTIME
     76 #include <OMX_Common_Utils.h>
     77 #include <OMX_GetTime.h>     /*Headers for Performance & measuremet    */
     78 #endif
     79 FILE *fpRes;
     80 
     81 /* ======================================================================= */
     82 /**
     83  * @def WBAPP_NUM_INPUT_BUFFERS   Default number of input buffers
     84  */
     85 /* ======================================================================= */
     86 #define WBAPP_NUM_INPUT_BUFFERS 1
     87 /* ======================================================================= */
     88 /**
     89  * @def WBAPP_NUM_INPUT_BUFFERS_DASF  Default No.of input buffers DASF
     90  */
     91 /* ======================================================================= */
     92 #define WBAPP_NUM_INPUT_BUFFERS_DASF 2
     93 /* ======================================================================= */
     94 /**
     95  * @def WBAPP_NUM_OUTPUT_BUFFERS   Default number of output buffers
     96  */
     97 /* ======================================================================= */
     98 #define WBAPP_NUM_OUTPUT_BUFFERS 1
     99 /* ======================================================================= */
    100 /**
    101  * @def WBAPP_INPUT_BUFFER_SIZE       Default input buffer size
    102  *      WBAPP_INPUT_BUFFER_SIZE_DASF  Default input buffer size DASF
    103  */
    104 /* ======================================================================= */
    105 #define WBAPP_INPUT_BUFFER_SIZE 640
    106 #define WBAPP_INPUT_BUFFER_SIZE_DASF 640
    107 /* ======================================================================= */
    108 /**
    109  * @def WBAPP_OUTPUT_BUFFER_SIZE   Default output buffer size
    110  */
    111 /* ======================================================================= */
    112 #define WBAPP_OUTPUT_BUFFER_SIZE 116
    113 /* ======================================================================= */
    114 /**
    115  * @def WBAPP_OUTPUT_BUFFER_SIZE_MIME  Default input buffer size MIME
    116  */
    117 /* ======================================================================= */
    118 #define WBAPP_OUTPUT_BUFFER_SIZE_MIME 61
    119 
    120 /* ======================================================================= */
    121 /*
    122  * @def WBAMRENC_APP_ID  App ID Value setting
    123  */
    124 /* ======================================================================= */
    125 #define WBAMRENC_APP_ID 100
    126 
    127 #define SLEEP_TIME 5
    128 
    129 #define WBAMRENC_MIME_HEADER_LEN 9
    130 
    131 #define FIFO1 "/dev/fifo.1"
    132 #define FIFO2 "/dev/fifo.2"
    133 
    134 #define APP_INFO
    135 
    136 #undef APP_DEBUG
    137 
    138 #undef USE_BUFFER
    139 
    140 #undef APP_MEMCHECK
    141 
    142 
    143 #ifdef  APP_INFO
    144 #define APP_IPRINT(...)    fprintf(stderr,__VA_ARGS__)          /* Information prints */
    145 #else
    146 #define APP_IPRINT(...)
    147 #endif
    148 
    149 
    150 #ifdef APP_DEBUG
    151 #define APP_DPRINT(...)    fprintf(stderr,__VA_ARGS__)
    152 #else
    153 #define APP_DPRINT(...)
    154 #endif
    155 
    156 #ifdef APP_MEMCHECK
    157 #define APP_MEMPRINT(...)    fprintf(stderr,__VA_ARGS__)
    158 #else
    159 #define APP_MEMPRINT(...)
    160 #endif
    161 
    162 #undef APP_DEBUGMEM
    163 
    164 #ifdef OMX_GETTIME
    165 OMX_ERRORTYPE eError = OMX_ErrorNone;
    166 int GT_FlagE = 0;  /* Fill Buffer 1 = First Buffer,  0 = Not First Buffer  */
    167 int GT_FlagF = 0;  /*Empty Buffer  1 = First Buffer,  0 = Not First Buffer  */
    168 static OMX_NODE* pListHead = NULL;
    169 #endif
    170 
    171 #ifdef APP_DEBUGMEM
    172 void *arr[500];
    173 int lines[500];
    174 int bytes[500];
    175 char file[500][50];
    176 int ind = 0;
    177 
    178 #define newmalloc(x) mynewmalloc(__LINE__,__FILE__,x)
    179 #define newfree(z) mynewfree(z,__LINE__,__FILE__)
    180 
    181 void * mynewmalloc(int line, char *s, int size) {
    182     void *p;
    183     int e = 0;
    184     p = calloc(1, size);
    185 
    186     if (p == NULL) {
    187         APP_IPRINT("Memory not available\n");
    188         exit(1);
    189     } else {
    190         while ((lines[e] != 0) && (e < 500) ) {
    191             e++;
    192         }
    193 
    194         arr[e] = p;
    195         lines[e] = line;
    196         bytes[e] = size;
    197         strcpy(file[e], s);
    198         APP_IPRINT("Allocating %d bytes on address %p, line %d file %s pos %d\n", size, p, line, s, e);
    199         return p;
    200     }
    201 }
    202 
    203 int mynewfree(void *dp, int line, char *s) {
    204     int q;
    205 
    206     if (dp == NULL) {
    207         APP_IPRINT("NULL can't be deleted\n");
    208         return 0;
    209     }
    210 
    211     for (q = 0; q < 500; q++) {
    212         if (arr[q] == dp) {
    213             APP_IPRINT("Deleting %d bytes on address %p, line %d file %s\n", bytes[q], dp, line, s);
    214             free(dp);
    215             dp = NULL;
    216             lines[q] = 0;
    217             strcpy(file[q], "");
    218             break;
    219         }
    220     }
    221 
    222     if (500 == q)
    223         APP_IPRINT("\n\nPointer not found. Line:%d    File%s!!\n\n", line, s);
    224 
    225     return 1;
    226 }
    227 #else
    228 #define newmalloc(x) malloc(x)
    229 #define newfree(z) free(z)
    230 #endif
    231 
    232 typedef struct WBAMRENC_BUFDATA {
    233     OMX_U8 nFrames;
    234 } WBAMRENC_BUFDATA;
    235 
    236 /* ======================================================================= */
    237 /**
    238  *  M A C R O S FOR MALLOC and MEMORY FREE and CLOSING PIPES
    239  */
    240 /* ======================================================================= */
    241 
    242 #define OMX_WBAPP_CONF_INIT_STRUCT(_s_, _name_) \
    243     memset((_s_), 0x0, sizeof(_name_)); \
    244     (_s_)->nSize = sizeof(_name_);      \
    245     (_s_)->nVersion.s.nVersionMajor = 0x1;  \
    246     (_s_)->nVersion.s.nVersionMinor = 0x0;  \
    247     (_s_)->nVersion.s.nRevision = 0x0;      \
    248     (_s_)->nVersion.s.nStep = 0x0
    249 
    250 #define OMX_WBAPP_INIT_STRUCT(_s_, _name_)  \
    251     memset((_s_), 0x0, sizeof(_name_)); \
    252 
    253 #define OMX_WBAPP_MALLOC_STRUCT(_pStruct_, _sName_)   \
    254     _pStruct_ = (_sName_*)newmalloc(sizeof(_sName_));      \
    255     if(_pStruct_ == NULL){      \
    256         APP_IPRINT("***********************************\n"); \
    257         APP_IPRINT("%d :: Malloc Failed\n",__LINE__); \
    258         APP_IPRINT("***********************************\n"); \
    259         eError = OMX_ErrorInsufficientResources; \
    260         goto EXIT;      \
    261     } \
    262     APP_MEMPRINT("%d :: ALLOCATING MEMORY = %p\n",__LINE__,_pStruct_);
    263 
    264 /* ======================================================================= */
    265 /** WBAPP_COMP_PORT_TYPE  Port types
    266  *
    267  *  @param  WBAPP_INPUT_PORT            Input port
    268  *
    269  *  @param  WBAPP_OUTPUT_PORT           Output port
    270  */
    271 /*  ====================================================================== */
    272 /*This enum must not be changed. */
    273 typedef enum WBAPP_COMP_PORT_TYPE {
    274     WBAPP_INPUT_PORT = 0,
    275     WBAPP_OUTPUT_PORT
    276 } WBAPP_COMP_PORT_TYPE;
    277 
    278 /* ======================================================================= */
    279 /**
    280  * @def WBAPP_MAX_NUM_OF_BUFS      Maximum number of buffers
    281  * @def WBAPP_NUM_CHANNELS         Number of Channels
    282  * @def WBAPP_SAMPLING_FREQUENCY   Sampling frequency
    283  */
    284 /* ======================================================================= */
    285 #define WBAPP_MAX_NUM_OF_BUFS 10
    286 #define WBAPP_NUM_OF_CHANNELS 1
    287 #define WBAPP_SAMPLING_FREQUENCY 16000
    288 
    289 #undef  WAITFORRESOURCES
    290 pthread_mutex_t WaitForState_mutex;
    291 pthread_cond_t  WaitForState_threshold;
    292 OMX_U8          WaitForState_flag;
    293 OMX_U8      TargetedState;
    294 
    295 static OMX_BOOL bInvalidState;
    296 void* ArrayOfPointers[6];
    297 OMX_ERRORTYPE StopComponent(OMX_HANDLETYPE *pHandle);
    298 OMX_ERRORTYPE PauseComponent(OMX_HANDLETYPE *pHandle);
    299 OMX_ERRORTYPE PlayComponent(OMX_HANDLETYPE *pHandle);
    300 OMX_ERRORTYPE send_input_buffer(OMX_HANDLETYPE pHandle, OMX_BUFFERHEADERTYPE* pBuffer, FILE *fIn);
    301 int maxint(int a, int b);
    302 
    303 int inputPortDisabled = 0;
    304 int outputPortDisabled = 0;
    305 OMX_U8 NextBuffer[WBAPP_INPUT_BUFFER_SIZE*3];
    306 int FirstTime = 1;
    307 int nRead;
    308 WBAMRENC_BUFDATA* OutputFrames;
    309 
    310 #ifdef DSP_RENDERING_ON
    311 AM_COMMANDDATATYPE cmd_data;
    312 #endif
    313 
    314 OMX_STRING strWbAmrEncoder = "OMX.TI.WBAMR.encode";
    315 
    316 #ifndef USE_BUFFER
    317 int FreeAllResources( OMX_HANDLETYPE *pHandle,
    318                       OMX_BUFFERHEADERTYPE* pBufferIn,
    319                       OMX_BUFFERHEADERTYPE* pBufferOut,
    320                       int NIB, int NOB,
    321                       FILE* fIn, FILE* fOut);
    322 #else
    323 int  FreeAllResources(OMX_HANDLETYPE *pHandle,
    324                       OMX_U8* UseInpBuf[],
    325                       OMX_U8* UseOutBuf[],
    326                       int NIB, int NOB,
    327                       FILE* fIn, FILE* fOut);
    328 #endif
    329 int IpBuf_Pipe[2];
    330 int OpBuf_Pipe[2];
    331 int Event_Pipe[2];
    332 
    333 fd_set rfds;
    334 int done = 0;
    335 int DasfMode = 0;
    336 int mframe = 0;
    337 
    338 int preempted = 0;
    339 
    340 /* safe routine to get the maximum of 2 integers */
    341 int maxint(int a, int b) {
    342     return (a > b) ? a : b;
    343 }
    344 
    345 /* This method will wait for the component to get to the state
    346  * specified by the DesiredState input. */
    347 static OMX_ERRORTYPE WaitForState(OMX_HANDLETYPE* pHandle,
    348                                   OMX_STATETYPE DesiredState) {
    349     OMX_STATETYPE CurState = OMX_StateInvalid;
    350     OMX_ERRORTYPE eError = OMX_ErrorNone;
    351     OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
    352 
    353     eError = pComponent->GetState(pHandle, &CurState);
    354 
    355     if (CurState == OMX_StateInvalid && bInvalidState == OMX_TRUE) {
    356         eError = OMX_ErrorInvalidState;
    357     }
    358 
    359     if (CurState != DesiredState) {
    360         WaitForState_flag = 1;
    361         TargetedState = DesiredState;
    362         pthread_mutex_lock(&WaitForState_mutex);
    363         pthread_cond_wait(&WaitForState_threshold, &WaitForState_mutex);/*Going to sleep till signal arrives*/
    364         pthread_mutex_unlock(&WaitForState_mutex);
    365     }
    366 
    367     return eError;
    368 
    369 }
    370 
    371 OMX_ERRORTYPE EventHandler(
    372     OMX_HANDLETYPE hComponent,
    373     OMX_PTR pAppData,
    374     OMX_EVENTTYPE eEvent,
    375     OMX_U32 nData1,
    376     OMX_U32 nData2,
    377     OMX_PTR pEventData) {
    378     APP_DPRINT( "%d :: App: Entering EventHandler \n", __LINE__);
    379     OMX_ERRORTYPE eError = OMX_ErrorNone;
    380     OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)hComponent;
    381     OMX_STATETYPE state;
    382 
    383     OMX_U8 writeValue;
    384 
    385     eError = pComponent->GetState (hComponent, &state);
    386 
    387     if (eError != OMX_ErrorNone) {
    388         APP_DPRINT("%d :: App: Error returned from GetState\n", __LINE__);
    389         goto EXIT;
    390     }
    391 
    392     APP_DPRINT( "%d :: App: Component eEvent = %d\n", __LINE__, eEvent);
    393 
    394     switch (eEvent) {
    395             APP_DPRINT( "%d :: App: Component State Changed To %d\n", __LINE__, state);
    396         case OMX_EventCmdComplete:
    397             APP_DPRINT( "%d :: App: Component State Changed To %d\n", __LINE__, state);
    398 
    399             if (nData1 == OMX_CommandPortDisable) {
    400                 if (nData2 == WBAPP_INPUT_PORT) {
    401                     inputPortDisabled = 1;
    402                 }
    403 
    404                 if (nData2 == WBAPP_OUTPUT_PORT) {
    405                     outputPortDisabled = 1;
    406                 }
    407             }
    408 
    409             if ((nData1 == OMX_CommandStateSet) && (TargetedState == nData2) &&
    410                     (WaitForState_flag)) {
    411                 WaitForState_flag = 0;
    412                 pthread_mutex_lock(&WaitForState_mutex);
    413                 pthread_cond_signal(&WaitForState_threshold);
    414                 pthread_mutex_unlock(&WaitForState_mutex);
    415             }
    416 
    417             break;
    418         case OMX_EventError:
    419 
    420             if (nData1 == OMX_ErrorInvalidState) {
    421                 APP_IPRINT("Event Handler Invalid!!!\n\n");
    422                 bInvalidState = OMX_TRUE;
    423             } else if (nData1 == OMX_ErrorResourcesPreempted) {
    424                 preempted = 1;
    425                 writeValue = 0;
    426                 write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
    427             } else if (nData1 == OMX_ErrorResourcesLost) {
    428                 WaitForState_flag = 0;
    429                 pthread_mutex_lock(&WaitForState_mutex);
    430                 pthread_cond_signal(&WaitForState_threshold);/*Sending Waking Up Signal*/
    431                 pthread_mutex_unlock(&WaitForState_mutex);
    432             }
    433 
    434             break;
    435         case OMX_EventMax:
    436             APP_DPRINT( "%d :: App: Component OMX_EventMax = %d\n", __LINE__, eEvent);
    437             break;
    438         case OMX_EventMark:
    439             APP_DPRINT( "%d :: App: Component OMX_EventMark = %d\n", __LINE__, eEvent);
    440             break;
    441         case OMX_EventPortSettingsChanged:
    442             APP_DPRINT( "%d :: App: Component OMX_EventPortSettingsChanged = %d\n", __LINE__, eEvent);
    443             break;
    444         case OMX_EventBufferFlag:
    445             APP_DPRINT( "%d :: App: Component OMX_EventBufferFlag = %d\n", __LINE__, eEvent);
    446             writeValue = 2;
    447             write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
    448             break;
    449         case OMX_EventResourcesAcquired:
    450             APP_DPRINT( "%d :: App: Component OMX_EventResourcesAcquired = %d\n", __LINE__, eEvent);
    451             writeValue = 1;
    452             write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
    453             preempted = 0;
    454 
    455             break;
    456         default:
    457             break;
    458 
    459     }
    460 
    461 EXIT:
    462     APP_DPRINT( "%d :: App: Exiting EventHandler \n", __LINE__);
    463     return eError;
    464 }
    465 
    466 void FillBufferDone (OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer) {
    467     if (!preempted)
    468         write(OpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
    469 
    470 #ifdef OMX_GETTIME
    471 
    472     if (GT_FlagF == 1 ) /* First Buffer Reply*/ { /* 1 = First Buffer,  0 = Not First Buffer  */
    473         GT_END("Call to FillBufferDone  <First: FillBufferDone>");
    474         GT_FlagF = 0 ;   /* 1 = First Buffer,  0 = Not First Buffer  */
    475     }
    476 
    477 #endif
    478 }
    479 
    480 void EmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer) {
    481     write(IpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
    482 #ifdef OMX_GETTIME
    483 
    484     if (GT_FlagE == 1 ) /* First Buffer Reply*/ { /* 1 = First Buffer,  0 = Not First Buffer  */
    485         GT_END("Call to EmptyBufferDone <First: EmptyBufferDone>");
    486         GT_FlagE = 0;   /* 1 = First Buffer,  0 = Not First Buffer  */
    487     }
    488 
    489 #endif
    490 }
    491 
    492 int main(int argc, char* argv[]) {
    493     OMX_CALLBACKTYPE AmrCaBa = {(void *)EventHandler,
    494                                 (void*)EmptyBufferDone,
    495                                 (void*)FillBufferDone
    496                                };
    497     OMX_HANDLETYPE pHandle;
    498     OMX_ERRORTYPE eError = OMX_ErrorNone;
    499     OMX_U32 AppData = WBAMRENC_APP_ID;
    500     OMX_PARAM_PORTDEFINITIONTYPE* pCompPrivateStruct;
    501     OMX_AUDIO_PARAM_AMRTYPE *pAmrParam;
    502     OMX_COMPONENTTYPE *pComponent;
    503     OMX_STATETYPE state;
    504     OMX_BUFFERHEADERTYPE* pInputBufferHeader[WBAPP_MAX_NUM_OF_BUFS];
    505     OMX_BUFFERHEADERTYPE* pOutputBufferHeader[WBAPP_MAX_NUM_OF_BUFS];
    506     bInvalidState = OMX_FALSE;
    507 #ifdef USE_BUFFER
    508     OMX_U8* pInputBuffer[WBAPP_MAX_NUM_OF_BUFS];
    509     OMX_U8* pOutputBuffer[WBAPP_MAX_NUM_OF_BUFS];
    510 #endif
    511     FILE* fIn = NULL;
    512     FILE* fOut = NULL;
    513     struct timeval tv;
    514     int retval, i, j, k, kk, tcID = 0;
    515     int frmCount = 0;
    516     int frmCnt = 1;
    517     int testcnt = 0;
    518     int testcnt1 = 0;
    519     int status = 0;
    520     int fdmax = 0;
    521 
    522     int nFrameCount = 1;
    523     int nFrameLen = 0;
    524     int nIpBuff = 1;
    525     int nOutBuff = 1;
    526     int numOfInputBuffer = 0;
    527     int numOfOutputBuffer = 0;
    528     OMX_INDEXTYPE index;
    529     int NoDataRead = 0;
    530     OMX_U32 streamId;
    531     TI_OMX_DATAPATH dataPath;
    532     TI_OMX_DSP_DEFINITION *audioinfo;
    533     OMX_AUDIO_CONFIG_VOLUMETYPE* pCompPrivateStructGain = NULL;
    534     int wbamrencfdwrite;
    535     int wbamrencfdread;
    536 
    537     pthread_mutex_init(&WaitForState_mutex, NULL);
    538     pthread_cond_init (&WaitForState_threshold, NULL);
    539     WaitForState_flag = 0;
    540 
    541     srand ( time(NULL) );
    542     APP_IPRINT("------------------------------------------------------\n");
    543     APP_IPRINT("This is Main Thread In WBAMR ENCODER Test Application:\n");
    544     APP_IPRINT("Test Core 1.5 - " __DATE__ ":" __TIME__ "\n");
    545     APP_IPRINT("------------------------------------------------------\n");
    546 
    547 #ifdef OMX_GETTIME
    548     APP_IPRINT("Line %d\n", __LINE__);
    549     GTeError = OMX_ListCreate(&pListHead);
    550     APP_IPRINT("Line %d\n", __LINE__);
    551     APP_IPRINT("eError = %d\n", GTeError);
    552     GT_START();
    553     APP_IPRINT("Line %d\n", __LINE__);
    554 #endif
    555 
    556 
    557     /* check the input parameters */
    558     if ((argc < 14) || (argc > 15)) {
    559         APP_IPRINT("%d :: Usage: [TestApp] [O/P] [FUNC_ID_X] [FM/DM] [WBAMR/EFR] [BITRATE] [DTXON/OFF] [NONMIME/MIME/IF2] [ACDNON/OFF] [FRAMES] [1 to N] [1 to N] [MFON]\n", __LINE__);
    560         goto EXIT;
    561     }
    562 
    563     /* check to see that the input file exists */
    564     struct stat sb = {0};
    565     status = stat(argv[1], &sb);
    566 
    567     if ( status != 0 ) {
    568         APP_IPRINT("Cannot find file %s. (%u)\n", argv[1], errno);
    569         goto EXIT;
    570     }
    571 
    572     /* Open the file of data to be encoded. */
    573     fIn = fopen(argv[1], "r");
    574 
    575     if ( fIn == NULL ) {
    576         APP_IPRINT("Error:  failed to open the input file %s\n", argv[1]);
    577         goto EXIT;
    578     }
    579 
    580     /* Open the file of data to be written. */
    581     fOut = fopen(argv[2], "w");
    582 
    583     if ( fOut == NULL ) {
    584         APP_IPRINT("Error:  failed to open the output file %s\n", argv[2]);
    585         goto EXIT;
    586     }
    587 
    588     if (!strcmp(argv[3], "FUNC_ID_1")) {
    589         APP_IPRINT("%d :: ### Testing TESTCASE 1 PLAY TILL END ###\n", __LINE__);
    590         testcnt = 1;
    591         testcnt1 = 1;
    592         tcID = 1;
    593     } else if (!strcmp(argv[3], "FUNC_ID_2")) {
    594         APP_IPRINT("%d :: ### Testing TESTCASE 2 STOP IN THE END ###\n", __LINE__);
    595         testcnt = 1;
    596         testcnt1 = 1;
    597         tcID = 2;
    598     } else if (!strcmp(argv[3], "FUNC_ID_3")) {
    599         APP_IPRINT("%d :: ### Testing TESTCASE 3 PAUSE - RESUME IN BETWEEN ###\n", __LINE__);
    600         testcnt = 1;
    601         testcnt1 = 1;
    602         tcID = 3;
    603     } else if (!strcmp(argv[3], "FUNC_ID_4")) {
    604         APP_IPRINT("%d :: ### Testing TESTCASE 4 STOP IN BETWEEN ###\n", __LINE__);
    605         testcnt = 2;
    606         testcnt1 = 1;
    607         tcID = 4;
    608         APP_IPRINT("######## testcnt = %d #########\n", testcnt);
    609     } else if (!strcmp(argv[3], "FUNC_ID_5")) {
    610         APP_IPRINT("%d :: ### Testing TESTCASE 5 ENCODE without Deleting component Here ###\n", __LINE__);
    611 
    612         if (argc == 15) {
    613             testcnt = atoi(argv[14]);
    614         } else {
    615             testcnt = 20;  /*20 cycles by default*/
    616         }
    617 
    618         testcnt1 = 1;
    619         tcID = 5;
    620     } else if (!strcmp(argv[3], "FUNC_ID_6")) {
    621         APP_IPRINT("%d :: ### Testing TESTCASE 6 ENCODE with Deleting component Here ###\n", __LINE__);
    622 
    623         if (argc == 15) {
    624             testcnt1 = atoi(argv[14]);
    625         } else {
    626             testcnt1 = 20;  /*20 cycles by default*/
    627         }
    628 
    629         testcnt = 1;
    630         tcID = 6;
    631     } else if (!strcmp(argv[3], "FUNC_ID_7")) {
    632         APP_IPRINT("%d :: ### Testing TESTCASE 7 ENCODE with Volume Control ###\n", __LINE__);
    633         testcnt = 1;
    634         testcnt1 = 1;
    635         tcID = 7;
    636     } else if (!strcmp(argv[3], "FUNC_ID_8")) {
    637         APP_IPRINT("%d :: ### Testing PLAY TILL END  WITH TWO FRAMES BY BUFFER###\n", __LINE__);
    638         testcnt = 1;
    639         testcnt1 = 1;
    640         tcID = 1;
    641         mframe = 1;
    642     } else {
    643         APP_IPRINT("%d :: ### Invalid test case###\n", __LINE__);
    644         goto EXIT;
    645     }
    646 
    647     for (j = 0; j < testcnt1; j++) {
    648 
    649 #ifdef DSP_RENDERING_ON
    650 
    651         if ((wbamrencfdwrite = open(FIFO1, O_WRONLY)) < 0) {
    652             APP_IPRINT("[AMRTEST] - failure to open WRITE pipe\n");
    653         } else {
    654             APP_IPRINT("[AMRTEST] - opened WRITE pipe\n");
    655         }
    656 
    657         if ((wbamrencfdread = open(FIFO2, O_RDONLY)) < 0) {
    658             APP_IPRINT("[AMRTEST] - failure to open READ pipe\n");
    659             goto EXIT;
    660         } else {
    661             APP_IPRINT("[AMRTEST] - opened READ pipe\n");
    662         }
    663 
    664 #endif
    665 
    666         /* Create a pipe used to queue data from the callback. */
    667         retval = pipe(IpBuf_Pipe);
    668 
    669         if ( retval != 0) {
    670             APP_DPRINT("Error:Fill Data Pipe failed to open\n");
    671             goto EXIT;
    672         }
    673 
    674         retval = pipe(OpBuf_Pipe);
    675 
    676         if ( retval != 0) {
    677             APP_DPRINT("Error:Empty Data Pipe failed to open\n");
    678             goto EXIT;
    679         }
    680 
    681         retval = pipe(Event_Pipe);
    682 
    683         if ( retval != 0) {
    684             APP_DPRINT( "Error:Empty Data Pipe failed to open\n");
    685             goto EXIT;
    686         }
    687 
    688         /* save off the "max" of the handles for the selct statement */
    689         fdmax = maxint(IpBuf_Pipe[0], OpBuf_Pipe[0]);
    690         fdmax = maxint(fdmax, Event_Pipe[0]);
    691 
    692         eError = TIOMX_Init();
    693 
    694         if (eError != OMX_ErrorNone) {
    695             APP_DPRINT("%d :: Error returned by OMX_Init()\n", __LINE__);
    696             goto EXIT;
    697         }
    698 
    699         TI_OMX_STREAM_INFO *streaminfo;
    700 
    701         OMX_WBAPP_MALLOC_STRUCT(streaminfo, TI_OMX_STREAM_INFO);
    702         OMX_WBAPP_MALLOC_STRUCT(audioinfo, TI_OMX_DSP_DEFINITION);
    703         OMX_WBAPP_INIT_STRUCT(audioinfo, TI_OMX_DSP_DEFINITION);
    704 
    705         ArrayOfPointers[0] = (TI_OMX_STREAM_INFO*)streaminfo;
    706         ArrayOfPointers[1] = (TI_OMX_DSP_DEFINITION*)audioinfo;
    707 
    708         if (j > 0) {
    709             APP_IPRINT ("%d :: Encoding the file for %d Time in TESTCASE 6\n", __LINE__, j + 1);
    710             fIn = fopen(argv[1], "r");
    711 
    712             if ( fIn == NULL ) {
    713                 fprintf(stderr, "Error:  failed to open the file %s for read only access\n", argv[1]);
    714                 goto EXIT;
    715             }
    716 
    717             fOut = fopen("TC6_WbAmr1.amr", "w");
    718 
    719             if ( fOut == NULL ) {
    720                 fprintf(stderr, "Error:  failed to create the output file %s\n", argv[2]);
    721                 goto EXIT;
    722             }
    723         }
    724 
    725         /* Load the WBAMR Encoder Component */
    726 
    727 #ifdef OMX_GETTIME
    728         GT_START();
    729         eError = OMX_GetHandle(&pHandle, strWbAmrEncoder, &AppData, &AmrCaBa);
    730         GT_END("Call to GetHandle");
    731 #else
    732         eError = TIOMX_GetHandle(&pHandle, strWbAmrEncoder, &AppData, &AmrCaBa);
    733 #endif
    734 
    735         if ((eError != OMX_ErrorNone) || (pHandle == NULL)) {
    736             APP_DPRINT("Error in Get Handle function\n");
    737             goto EXIT;
    738         }
    739 
    740         /* Setting No.Of Input and Output Buffers for the Component */
    741         numOfInputBuffer = atoi(argv[11]);
    742         APP_IPRINT("\n%d :: App: audioinfo->nIpBufs = %d \n", __LINE__, numOfInputBuffer);
    743 
    744         numOfOutputBuffer = atoi(argv[12]);
    745         APP_IPRINT("\n%d :: App: audioinfo->numOfOutputBuffer = %d \n", __LINE__, numOfOutputBuffer);
    746 
    747 
    748         OMX_WBAPP_MALLOC_STRUCT(pCompPrivateStruct, OMX_PARAM_PORTDEFINITIONTYPE);
    749         OMX_WBAPP_CONF_INIT_STRUCT(pCompPrivateStruct, OMX_PARAM_PORTDEFINITIONTYPE);
    750 
    751         ArrayOfPointers[2] = (OMX_PARAM_PORTDEFINITIONTYPE*)pCompPrivateStruct;
    752         APP_DPRINT("%d :: Setting input port config\n", __LINE__);
    753         pCompPrivateStruct->nSize                              = sizeof (OMX_PARAM_PORTDEFINITIONTYPE);
    754         pCompPrivateStruct->nVersion.s.nVersionMajor           = 0xF1;
    755         pCompPrivateStruct->nVersion.s.nVersionMinor           = 0xF2;
    756         pCompPrivateStruct->nPortIndex                         = WBAPP_INPUT_PORT;
    757         pCompPrivateStruct->eDir                               = OMX_DirInput;
    758         pCompPrivateStruct->nBufferCountActual                 = numOfInputBuffer;
    759         pCompPrivateStruct->nBufferCountMin                    = numOfInputBuffer;
    760         pCompPrivateStruct->nBufferSize                        = WBAPP_INPUT_BUFFER_SIZE;
    761         pCompPrivateStruct->bEnabled                           = OMX_TRUE;
    762         pCompPrivateStruct->bPopulated                         = OMX_FALSE;
    763         pCompPrivateStruct->eDomain                            = OMX_PortDomainAudio;
    764         pCompPrivateStruct->format.audio.eEncoding             = OMX_AUDIO_CodingAMR;
    765         pCompPrivateStruct->format.audio.cMIMEType             = NULL;
    766         pCompPrivateStruct->format.audio.pNativeRender         = NULL;
    767         pCompPrivateStruct->format.audio.bFlagErrorConcealment = OMX_FALSE;    /*Send input port config*/
    768         APP_DPRINT("%d :: Setting input port config\n", __LINE__);
    769 
    770         if (!(strcmp(argv[8], "NONMIME"))) {
    771             pCompPrivateStruct->format.audio.cMIMEType = "NONMIME";
    772             APP_DPRINT("\n%d :: App: pCompPrivateStruct->format.audio.cMIMEType --> %s \n",
    773                        __LINE__, pCompPrivateStruct->format.audio.cMIMEType);
    774         } else if (!(strcmp(argv[8], "MIME"))) {
    775             pCompPrivateStruct->format.audio.cMIMEType = "MIME";
    776             APP_DPRINT("\n%d :: App: pCompPrivateStruct->format.audio.cMIMEType --> %s \n",
    777                        __LINE__, pCompPrivateStruct->format.audio.cMIMEType);
    778         } else if (!(strcmp(argv[8], "IF2"))) {
    779             pCompPrivateStruct->format.audio.cMIMEType = "IF2";
    780             APP_DPRINT("\n%d :: App: pCompPrivateStruct->format.audio.cMIMEType --> %s \n",
    781                        __LINE__, pCompPrivateStruct->format.audio.cMIMEType);
    782 
    783         } else {
    784             eError = OMX_ErrorBadParameter;
    785             APP_IPRINT("\n%d :: App: audioinfo->amrMIMEMode Sending Bad Parameter\n", __LINE__);
    786             APP_IPRINT("%d :: App: Should Be One of these Modes MIME, NONMIME, IF2\n", __LINE__);
    787             goto EXIT;
    788         }
    789 
    790 
    791         if (!(strcmp(argv[4], "FM"))) {
    792             audioinfo->dasfMode = 0;
    793             DasfMode = 0;
    794             APP_DPRINT("\n%d :: App: audioinfo->dasfMode = %x \n", __LINE__, audioinfo->dasfMode);
    795         } else if (!(strcmp(argv[4], "DM"))) {
    796             audioinfo->dasfMode = 1;
    797             DasfMode = 1;
    798             APP_DPRINT("\n%d :: App: audioinfo->dasfMode = %x \n", __LINE__, audioinfo->dasfMode);
    799             APP_DPRINT("%d :: WBAMR ENCODER RUNNING UNDER DASF MODE \n", __LINE__);
    800             pCompPrivateStruct->nBufferCountActual = 0;
    801         } else {
    802             eError = OMX_ErrorBadParameter;
    803             APP_IPRINT("\n%d :: App: audioinfo->dasfMode Sending Bad Parameter\n", __LINE__);
    804             APP_IPRINT("%d :: App: Should Be One of these Modes FM, DM\n", __LINE__);
    805             goto EXIT;
    806         }
    807 
    808 
    809         if (audioinfo->dasfMode == 0) {
    810             if ((atoi(argv[10])) != 0) {
    811                 eError = OMX_ErrorBadParameter;
    812                 APP_IPRINT("\n%d :: App: No. of Frames Sending Bad Parameter\n", __LINE__);
    813                 APP_IPRINT("%d :: App: For FILE mode argv[10] Should Be --> 0\n", __LINE__);
    814                 APP_IPRINT("%d :: App: For DASF mode argv[10] Should be greater than zero depends on number of frames user want to encode\n", __LINE__);
    815                 goto EXIT;
    816             }
    817         } else {
    818             if ((atoi(argv[10])) == 0) {
    819                 eError = OMX_ErrorBadParameter;
    820                 APP_IPRINT("\n%d :: App: No. of Frames Sending Bad Parameter\n", __LINE__);
    821                 APP_IPRINT("%d :: App: For DASF mode argv[10] Should be greater than zero depends on number of frames user want to encode\n", __LINE__);
    822                 APP_IPRINT("%d :: App: For FILE mode argv[10] Should Be --> 0\n", __LINE__);
    823                 goto EXIT;
    824             }
    825         }
    826 
    827         if (!(strcmp(argv[9], "ACDNOFF"))) {
    828             audioinfo->acousticMode = 0;
    829             APP_DPRINT("\n%d :: App: audioinfo->acousticMode = %x \n", __LINE__, audioinfo->acousticMode);
    830         } else if (!(strcmp(argv[9], "ACDNON"))) {
    831             audioinfo->acousticMode = 1;
    832             APP_DPRINT("\n%d :: App: audioinfo->acousticMode = %x \n", __LINE__, audioinfo->acousticMode);
    833         } else {
    834             eError = OMX_ErrorBadParameter;
    835             APP_IPRINT("\n%d :: App: audioinfo->acousticMode Sending Bad Parameter\n", __LINE__);
    836             APP_IPRINT("%d :: App: Should Be One of these Modes ACDNON, ACDNOFF\n", __LINE__);
    837             goto EXIT;
    838         }
    839 
    840 #ifdef OMX_GETTIME
    841         GT_START();
    842         eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
    843         GT_END("Set Parameter Test-SetParameter");
    844 #else
    845         eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
    846 #endif
    847 
    848         if (eError != OMX_ErrorNone) {
    849             eError = OMX_ErrorBadParameter;
    850             APP_DPRINT("%d :: OMX_ErrorBadParameter\n", __LINE__);
    851             goto EXIT;
    852         }
    853 
    854         APP_MEMPRINT("%d :: Setting output port config\n", __LINE__);
    855         pCompPrivateStruct->nSize                              = sizeof (OMX_PARAM_PORTDEFINITIONTYPE);
    856         pCompPrivateStruct->nVersion.s.nVersionMajor           = 0xF1;
    857         pCompPrivateStruct->nVersion.s.nVersionMinor           = 0xF2;
    858         pCompPrivateStruct->nPortIndex                         = WBAPP_OUTPUT_PORT;
    859         pCompPrivateStruct->eDir                               = OMX_DirOutput;
    860         pCompPrivateStruct->nBufferCountActual                 = numOfOutputBuffer;
    861         pCompPrivateStruct->nBufferCountMin                    = numOfOutputBuffer;
    862         pCompPrivateStruct->nBufferSize                        = WBAPP_OUTPUT_BUFFER_SIZE;
    863         pCompPrivateStruct->bEnabled                           = OMX_TRUE;
    864         pCompPrivateStruct->bPopulated                         = OMX_FALSE;
    865         pCompPrivateStruct->eDomain                            = OMX_PortDomainAudio;
    866         pCompPrivateStruct->format.audio.eEncoding             = OMX_AUDIO_CodingAMR;
    867         pCompPrivateStruct->format.audio.cMIMEType             = NULL;
    868         pCompPrivateStruct->format.audio.pNativeRender         = NULL;
    869         pCompPrivateStruct->format.audio.bFlagErrorConcealment = OMX_FALSE;    /*Send input port config*/
    870 
    871         OMX_WBAPP_MALLOC_STRUCT(pAmrParam, OMX_AUDIO_PARAM_AMRTYPE);
    872         OMX_WBAPP_CONF_INIT_STRUCT(pAmrParam, OMX_AUDIO_PARAM_AMRTYPE);
    873         ArrayOfPointers[3] = (OMX_AUDIO_PARAM_AMRTYPE *)pAmrParam;
    874 
    875         if (!(strcmp(argv[8], "NONMIME"))) {
    876             pCompPrivateStruct->format.audio.cMIMEType = "NONMIME";
    877             pAmrParam->eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatConformance;
    878             APP_DPRINT("\n%d :: App: pCompPrivateStruct->cMIMEType --> %s \n", __LINE__, argv[3]);
    879             /**< Codec Configuring to WBAMR Mode Buffer Size to 116 */
    880             pCompPrivateStruct->nBufferSize = WBAPP_OUTPUT_BUFFER_SIZE;
    881         }
    882 
    883         if (!(strcmp(argv[8], "MIME"))) {
    884             pCompPrivateStruct->format.audio.cMIMEType = "MIME";
    885             pAmrParam->eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatFSF;
    886             APP_DPRINT("\n%d :: App: pCompPrivateStruct->format.audio.cMIMEType --> %s \n",
    887                        __LINE__, pCompPrivateStruct->format.audio.cMIMEType);
    888             /**< Codec Configuring to MIME Mode Buffer Size to 61 */
    889             pCompPrivateStruct->nBufferSize = WBAPP_OUTPUT_BUFFER_SIZE_MIME;
    890         } else if (!(strcmp(argv[8], "IF2"))) {
    891             pCompPrivateStruct->format.audio.cMIMEType = "IF2";
    892             pAmrParam->eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatIF2;
    893             APP_DPRINT("\n%d :: App: pCompPrivateStruct->format.audio.cMIMEType --> %s \n",
    894                        __LINE__, pCompPrivateStruct->format.audio.cMIMEType);
    895         }
    896 
    897         APP_DPRINT("\n%d :: App: pCompPrivateStruct->nBufferSize --> %ld \n", __LINE__, pCompPrivateStruct->nBufferSize);
    898 #ifdef OMX_GETTIME
    899         GT_START();
    900         eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
    901         GT_END("Set Parameter Test-SetParameter");
    902 #else
    903         eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
    904 #endif
    905 
    906         if (eError != OMX_ErrorNone) {
    907             eError = OMX_ErrorBadParameter;
    908             APP_DPRINT("%d :: OMX_ErrorBadParameter\n", __LINE__);
    909             goto EXIT;
    910         }
    911 
    912         pAmrParam->nSize                    = sizeof(OMX_AUDIO_PARAM_AMRTYPE);
    913         pAmrParam->nVersion.s.nVersionMajor = 0xF1;
    914         pAmrParam->nVersion.s.nVersionMinor = 0xF2;
    915         pAmrParam->nPortIndex               = WBAPP_INPUT_PORT;
    916         pAmrParam->nChannels                = WBAPP_NUM_OF_CHANNELS;
    917 #ifdef OMX_GETTIME
    918         GT_START();
    919         eError = OMX_SetParameter (pHandle, OMX_IndexParamAudioAmr, pAmrParam);
    920         GT_END("Set Parameter Test-SetParameter");
    921 #else
    922         eError = OMX_SetParameter (pHandle, OMX_IndexParamAudioAmr, pAmrParam);
    923 #endif
    924 
    925         if (eError != OMX_ErrorNone) {
    926             eError = OMX_ErrorBadParameter;
    927             APP_DPRINT("%d :: OMX_ErrorBadParameter\n", __LINE__);
    928             goto EXIT;
    929         }
    930 
    931         pAmrParam->nSize                    = sizeof(OMX_AUDIO_PARAM_AMRTYPE);
    932         pAmrParam->nVersion.s.nVersionMajor = 0xF1;
    933         pAmrParam->nVersion.s.nVersionMinor = 0xF2;
    934         pAmrParam->nPortIndex               = WBAPP_OUTPUT_PORT;
    935         pAmrParam->nChannels                = WBAPP_NUM_OF_CHANNELS;
    936         pAmrParam->eAMRBandMode             = OMX_AUDIO_AMRBandModeUnused;
    937         pAmrParam->eAMRDTXMode              = OMX_AUDIO_AMRDTXModeOff;
    938 
    939         if (!(strcmp(argv[6], "BR2385"))) {
    940             pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB8;
    941             APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n", __LINE__, pAmrParam->eAMRBandMode);
    942         } else if (!(strcmp(argv[6], "BR2305"))) {
    943             pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB7;
    944             APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n", __LINE__, pAmrParam->eAMRBandMode);
    945         } else if (!(strcmp(argv[6], "BR1985"))) {
    946             pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB6;
    947             APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n", __LINE__, pAmrParam->eAMRBandMode);
    948         } else if (!(strcmp(argv[6], "BR1825"))) {
    949             pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB5;
    950             APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n", __LINE__, pAmrParam->eAMRBandMode);
    951         } else if (!(strcmp(argv[6], "BR1585"))) {
    952             pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB4;
    953             APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n", __LINE__, pAmrParam->eAMRBandMode);
    954         } else if (!(strcmp(argv[6], "BR1425"))) {
    955             pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB3;
    956             APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n", __LINE__, pAmrParam->eAMRBandMode);
    957         } else if (!(strcmp(argv[6], "BR1265"))) {
    958             pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB2;
    959             APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n", __LINE__, pAmrParam->eAMRBandMode);
    960         } else if (!(strcmp(argv[6], "BR885"))) {
    961             pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB1;
    962             APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n", __LINE__, pAmrParam->eAMRBandMode);
    963         } else if (!(strcmp(argv[6], "BR660"))) {
    964             pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB0;
    965             APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n", __LINE__, pAmrParam->eAMRBandMode);
    966         } else {
    967             eError = OMX_ErrorBadParameter;
    968             APP_IPRINT("\n%d :: App: pAmrParam->eAMRBandMode Sending Bad Parameter\n", __LINE__);
    969             APP_IPRINT("%d :: App: Should Be One of these BitRates BR2385, BR2305, BR1985, BR1825, BR1585, BR1425, BR1265, BR885, BR660\n", __LINE__);
    970             goto EXIT;
    971         }
    972 
    973         APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode --> %d \n", __LINE__, pAmrParam->eAMRBandMode);
    974 
    975         if (!(strcmp(argv[7], "DTXON"))) {
    976             /**< AMR Discontinuous Transmission Mode is enabled  */
    977             pAmrParam->eAMRDTXMode = OMX_AUDIO_AMRDTXModeOnVAD1;
    978             APP_DPRINT("\n%d :: App: pAmrParam->eAMRDTXMode --> %s \n", __LINE__, argv[7]);
    979         } else if (!(strcmp(argv[7], "DTXOFF"))) {
    980             /**< AMR Discontinuous Transmission Mode is disabled */
    981             pAmrParam->eAMRDTXMode = OMX_AUDIO_AMRDTXModeOff;
    982             APP_DPRINT("\n%d :: App: pAmrParam->eAMRDTXMode --> %s \n", __LINE__, argv[7]);
    983         } else {
    984             eError = OMX_ErrorBadParameter;
    985             APP_IPRINT("\n%d :: App: pAmrParam->eAMRDTXMode Sending Bad Parameter\n", __LINE__);
    986             APP_IPRINT("%d :: App: Should Be One of these Modes DTXON, DTXOFF\n", __LINE__);
    987             goto EXIT;
    988         }
    989 
    990 #ifdef OMX_GETTIME
    991         GT_START();
    992         eError = OMX_SetParameter (pHandle, OMX_IndexParamAudioAmr, pAmrParam);
    993         GT_END("Set Parameter Test-SetParameter");
    994 #else
    995         eError = OMX_SetParameter (pHandle, OMX_IndexParamAudioAmr, pAmrParam);
    996 #endif
    997 
    998         if (eError != OMX_ErrorNone) {
    999             eError = OMX_ErrorBadParameter;
   1000             APP_DPRINT("%d :: OMX_ErrorBadParameter\n", __LINE__);
   1001             goto EXIT;
   1002         }
   1003 
   1004 
   1005         /* setting for stream gain */
   1006         pCompPrivateStructGain = newmalloc (sizeof(OMX_AUDIO_CONFIG_VOLUMETYPE));
   1007 
   1008         if (pCompPrivateStructGain == NULL) {
   1009             APP_DPRINT("%d :: App: Malloc Failed\n", __LINE__);
   1010             goto EXIT;
   1011         }
   1012 
   1013         ArrayOfPointers[4] = (OMX_AUDIO_CONFIG_VOLUMETYPE*) pCompPrivateStructGain;
   1014 
   1015         /* default setting for gain */
   1016         pCompPrivateStructGain->nSize = sizeof(OMX_AUDIO_CONFIG_VOLUMETYPE);
   1017         pCompPrivateStructGain->nVersion.s.nVersionMajor    = 0xF1;
   1018         pCompPrivateStructGain->nVersion.s.nVersionMinor    = 0xF2;
   1019         pCompPrivateStructGain->nPortIndex                  = OMX_DirOutput;
   1020         pCompPrivateStructGain->bLinear                     = OMX_FALSE;
   1021         pCompPrivateStructGain->sVolume.nValue              = 50;               /* actual volume */
   1022         pCompPrivateStructGain->sVolume.nMin                = 0;                /* min volume */
   1023         pCompPrivateStructGain->sVolume.nMax                = 100;              /* max volume */
   1024 
   1025 
   1026         if (audioinfo->acousticMode == OMX_TRUE) {
   1027             APP_IPRINT("Using Acoustic Devide Node Path\n");
   1028             dataPath = DATAPATH_ACDN;
   1029             fprintf("HERE %d \n", __LINE__);
   1030         } else if (audioinfo->dasfMode) {
   1031 #ifdef RTM_PATH
   1032             APP_IPRINT("Using Real Time Mixer Path\n");
   1033             dataPath = DATAPATH_APPLICATION_RTMIXER;
   1034             fprintf("HERE %d \n", __LINE__);
   1035 #endif
   1036 
   1037 #ifdef ETEEDN_PATH
   1038             APP_IPRINT("Using Eteedn Path\n");
   1039             dataPath = DATAPATH_APPLICATION;
   1040             fprintf("HERE %d \n", __LINE__);
   1041 #endif
   1042         }
   1043 
   1044         eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.wbamrheaderinfo", &index);
   1045 
   1046         if (eError != OMX_ErrorNone) {
   1047             APP_IPRINT("Error getting extension index\n");
   1048             goto EXIT;
   1049         }
   1050 
   1051 #ifdef DSP_RENDERING_ON
   1052         cmd_data.hComponent = pHandle;
   1053         cmd_data.AM_Cmd = AM_CommandIsInputStreamAvailable;
   1054 
   1055         cmd_data.param1 = 0;
   1056 
   1057         if ((write(wbamrencfdwrite, &cmd_data, sizeof(cmd_data))) < 0) {
   1058             APP_IPRINT("%d ::WbAmrEncTest.c ::[WBAMR Enc Component] - send command to audio manager\n", __LINE__);
   1059         }
   1060 
   1061         if ((read(wbamrencfdread, &cmd_data, sizeof(cmd_data))) < 0) {
   1062             APP_IPRINT("%d ::WbAmrEncTest.c ::[WBAMR Enc Component] - failure to get data from the audio manager\n", __LINE__);
   1063             goto EXIT;
   1064         }
   1065 
   1066         audioinfo->streamId = cmd_data.streamID;
   1067         streamId = audioinfo->streamId;
   1068 #endif
   1069 
   1070         eError = OMX_SetConfig (pHandle, index, audioinfo);
   1071 
   1072         if (eError != OMX_ErrorNone) {
   1073             eError = OMX_ErrorBadParameter;
   1074             APP_DPRINT("%d :: Error from OMX_SetConfig() function\n", __LINE__);
   1075             goto EXIT;
   1076         }
   1077 
   1078         eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.wbamr.datapath", &index);
   1079 
   1080         if (eError != OMX_ErrorNone) {
   1081             APP_IPRINT("Error getting extension index\n");
   1082             goto EXIT;
   1083         }
   1084 
   1085         eError = OMX_SetConfig (pHandle, index, &dataPath);
   1086 
   1087         if (eError != OMX_ErrorNone) {
   1088             eError = OMX_ErrorBadParameter;
   1089             APP_DPRINT("%d :: AmrDecTest.c :: Error from OMX_SetConfig() function\n", __LINE__);
   1090             goto EXIT;
   1091         }
   1092 
   1093 #ifdef OMX_GETTIME
   1094         GT_START();
   1095 #endif
   1096         eError = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
   1097 
   1098         if (eError != OMX_ErrorNone) {
   1099             APP_DPRINT("Error from SendCommand-Idle(Init) State function\n");
   1100             goto EXIT;
   1101         }
   1102 
   1103         sleep(1);
   1104 
   1105 
   1106 #ifndef USE_BUFFER
   1107         APP_DPRINT("%d :: About to call OMX_AllocateBuffer\n", __LINE__);
   1108 
   1109         if (!DasfMode) {
   1110             /* allocate input buffer */
   1111             for (i = 0; i < numOfInputBuffer; i++) {
   1112                 APP_DPRINT("%d :: About to call OMX_AllocateBuffer for pInputBufferHeader[%d]\n", __LINE__, i);
   1113                 eError = OMX_AllocateBuffer(pHandle, &pInputBufferHeader[i], 0, NULL, WBAPP_INPUT_BUFFER_SIZE * 2);
   1114 
   1115                 if (eError != OMX_ErrorNone) {
   1116                     APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer for pInputBufferHeader[%d]\n", __LINE__, i);
   1117                     goto EXIT;
   1118                 }
   1119             }
   1120         }
   1121 
   1122         APP_DPRINT("\n%d :: App: pCompPrivateStruct->nBufferSize --> %ld \n", __LINE__, pCompPrivateStruct->nBufferSize);
   1123 
   1124         for (i = 0; i < numOfOutputBuffer; i++) {
   1125             /* allocate output buffer */
   1126             APP_DPRINT("%d :: About to call OMX_AllocateBuffer for pOutputBufferHeader[%d]\n", __LINE__, i);
   1127             eError = OMX_AllocateBuffer(pHandle, &pOutputBufferHeader[i], 1, NULL, pCompPrivateStruct->nBufferSize * 2);
   1128 
   1129             if (eError != OMX_ErrorNone) {
   1130                 APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer for pOutputBufferHeader[%d]\n", __LINE__, i);
   1131                 goto EXIT;
   1132             }
   1133         }
   1134 
   1135 #else
   1136 
   1137         if (!DasfMode) {
   1138             for (i = 0; i < numOfInputBuffer; i++) {
   1139                 pInputBuffer[i] = (OMX_U8*)newmalloc(WBAPP_INPUT_BUFFER_SIZE * 2 + 256);
   1140                 APP_MEMPRINT("%d :: [TESTAPP ALLOC] pInputBuffer[%d] = %p\n", __LINE__, i, pInputBuffer[i]);
   1141 
   1142                 if (NULL == pInputBuffer[i]) {
   1143                     APP_DPRINT("%d :: Malloc Failed\n", __LINE__);
   1144                     eError = OMX_ErrorInsufficientResources;
   1145                     goto EXIT;
   1146                 }
   1147 
   1148                 pInputBuffer[i] = pInputBuffer[i] + 128;
   1149 
   1150                 /*  allocate input buffer */
   1151                 APP_DPRINT("%d :: About to call OMX_UseBuffer\n", __LINE__);
   1152                 eError = OMX_UseBuffer(pHandle, &pInputBufferHeader[i], 0, NULL, WBAPP_INPUT_BUFFER_SIZE * 2, pInputBuffer[i]);
   1153 
   1154                 if (eError != OMX_ErrorNone) {
   1155                     APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n", __LINE__);
   1156                     goto EXIT;
   1157                 }
   1158             }
   1159         }
   1160 
   1161         for (i = 0; i < numOfOutputBuffer; i++) {
   1162             pOutputBuffer[i] = newmalloc (pCompPrivateStruct->nBufferSize * 2 + 256);
   1163             APP_MEMPRINT("%d :: [TESTAPP ALLOC] pOutputBuffer[%d] = %p\n", __LINE__, i, pOutputBuffer[i]);
   1164 
   1165             if (NULL == pOutputBuffer[i]) {
   1166                 APP_DPRINT("%d :: Malloc Failed\n", __LINE__);
   1167                 eError = OMX_ErrorInsufficientResources;
   1168                 goto EXIT;
   1169             }
   1170 
   1171             pOutputBuffer[i] = pOutputBuffer[i] + 128;
   1172 
   1173             /* allocate output buffer */
   1174             APP_DPRINT("%d :: About to call OMX_UseBuffer\n", __LINE__);
   1175             eError = OMX_UseBuffer(pHandle, &pOutputBufferHeader[i], 1, NULL, pCompPrivateStruct->nBufferSize * 2, pOutputBuffer[i]);
   1176 
   1177             if (eError != OMX_ErrorNone) {
   1178                 APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n", __LINE__);
   1179                 goto EXIT;
   1180             }
   1181         }
   1182 
   1183 #endif
   1184         /* Wait for startup to complete */
   1185         eError = WaitForState(pHandle, OMX_StateIdle);
   1186 #ifdef OMX_GETTIME
   1187         GT_END("Call to SendCommand <OMX_StateIdle & Allocated the buffers & Cleared it>");
   1188 #endif
   1189 
   1190         if (eError != OMX_ErrorNone) {
   1191             APP_DPRINT( "Error:  WaitForState reports an eError %X\n", eError);
   1192             goto EXIT;
   1193         }
   1194 
   1195         if (audioinfo->dasfMode) {
   1196             /* get streamID back to application */
   1197             eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.wbamrstreamIDinfo", &index);
   1198 
   1199             if (eError != OMX_ErrorNone) {
   1200                 APP_IPRINT("Error getting extension index\n");
   1201                 goto EXIT;
   1202             }
   1203 
   1204             eError = OMX_GetConfig (pHandle, index, streaminfo);
   1205 
   1206             if (eError != OMX_ErrorNone) {
   1207                 eError = OMX_ErrorBadParameter;
   1208                 APP_DPRINT("%d :: PcmDecTest.c :: Error from OMX_GetConfig() function\n", __LINE__);
   1209                 goto EXIT;
   1210             }
   1211 
   1212             streamId = streaminfo->streamId;
   1213             APP_IPRINT("***************StreamId=%d******************\n", (int)streamId);
   1214         }
   1215 
   1216         for (i = 0; i < testcnt; i++) {
   1217             frmCnt = 1;
   1218             nFrameCount = 1;
   1219             nOutBuff = 1;
   1220             nIpBuff  = 1;
   1221 
   1222             if (i > 0) {
   1223                 APP_IPRINT ("%d :: Encoding the file for %d Time\n", __LINE__, i + 1);
   1224                 fIn = fopen(argv[1], "r");
   1225 
   1226                 if (fIn == NULL) {
   1227                     fprintf(stderr, "Error:  failed to open the file %s for readonly access\n", argv[1]);
   1228                     goto EXIT;
   1229                 }
   1230 
   1231                 fOut = fopen("TC5_WbAmr1.amr", "w");
   1232 
   1233                 if (fOut == NULL) {
   1234                     fprintf(stderr, "Error:  failed to create the output file %s\n", argv[2]);
   1235                     goto EXIT;
   1236                 }
   1237             }
   1238 
   1239             APP_IPRINT("%d :: App: pAmrParam->eAMRBandMode --> %d \n", __LINE__, pAmrParam->eAMRBandMode);
   1240             APP_IPRINT("%d :: App: pAmrParam->eAMRDTXMode --> %s \n", __LINE__, argv[4]);
   1241             APP_IPRINT("%d :: App: pCompPrivateStruct->format.audio.cMIMEType --> %s \n", __LINE__, pCompPrivateStruct->format.audio.cMIMEType);
   1242 
   1243             APP_IPRINT("%d :: App: Sending OMX_StateExecuting Command\n", __LINE__);
   1244 #ifdef OMX_GETTIME
   1245             GT_START()
   1246 #endif
   1247             eError = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
   1248 
   1249             if (eError != OMX_ErrorNone) {
   1250                 APP_DPRINT("Error from SendCommand-Executing State function\n");
   1251                 goto EXIT;
   1252             }
   1253 
   1254             eError = WaitForState(pHandle, OMX_StateExecuting);
   1255 #ifdef OMX_GETTIME
   1256             GT_END("Call to SendCommand <OMX_StateExecuting>");
   1257 #endif
   1258 
   1259             if (eError != OMX_ErrorNone) {
   1260                 APP_DPRINT( "Error:  WaitForState reports an eError %X\n", eError);
   1261                 goto EXIT;
   1262             }
   1263 
   1264             if (audioinfo->dasfMode ) {
   1265                 APP_IPRINT("%d :: App: No.of Frames Encoding = %d\n", __LINE__, atoi(argv[10]));
   1266             }
   1267 
   1268             pComponent = (OMX_COMPONENTTYPE *)pHandle;
   1269 
   1270             if (audioinfo->dasfMode == 0) {
   1271                 for (k = 0; k < numOfInputBuffer; k++) {
   1272                     OMX_BUFFERHEADERTYPE* pBuffer = pInputBufferHeader[k];
   1273                     pBuffer->nFlags = 0;
   1274 #ifdef OMX_GETTIME
   1275 
   1276                     if (k == 0) {
   1277                         GT_FlagE = 1;  /* 1 = First Buffer,  0 = Not First Buffer  */
   1278                         GT_START(); /* Empty Bufffer */
   1279                     }
   1280 
   1281 #endif
   1282                     eError =  send_input_buffer(pHandle, pBuffer, fIn);
   1283                 }
   1284             }
   1285 
   1286             for (kk = 0; kk < numOfOutputBuffer; kk++) {
   1287                 APP_DPRINT("%d :: App: Calling FillThisBuffer \n", __LINE__);
   1288 #ifdef OMX_GETTIME
   1289 
   1290                 if (kk == 0) {
   1291                     GT_FlagF = 1;  /* 1 = First Buffer,  0 = Not First Buffer  */
   1292                     GT_START(); /* Fill Buffer */
   1293                 }
   1294 
   1295 #endif
   1296 
   1297                 pComponent->FillThisBuffer(pHandle, pOutputBufferHeader[kk]);
   1298 
   1299             }
   1300 
   1301             eError = pComponent->GetState(pHandle, &state);
   1302 
   1303             if (eError != OMX_ErrorNone) {
   1304                 APP_DPRINT("%d :: pComponent->GetState has returned status %X\n", __LINE__, eError);
   1305                 goto EXIT;
   1306             }
   1307 
   1308             retval = 1;
   1309 
   1310 
   1311 #ifndef WAITFORRESOURCES
   1312 
   1313             while ( (eError == OMX_ErrorNone) && (state != OMX_StateIdle)  && (state != OMX_StateInvalid) ) {
   1314                 if (1) {
   1315 #else
   1316 
   1317             while (1) {
   1318                 if ((eError == OMX_ErrorNone) && (state != OMX_StateIdle) && (state != OMX_StateInvalid) ) {
   1319 #endif
   1320                     FD_ZERO(&rfds);
   1321                     FD_SET(IpBuf_Pipe[0], &rfds);
   1322                     FD_SET(OpBuf_Pipe[0], &rfds);
   1323                     FD_SET(Event_Pipe[0], &rfds);
   1324 
   1325                     tv.tv_sec = 1;
   1326                     tv.tv_usec = 0;
   1327                     frmCount++;
   1328                     retval = select(fdmax + 1, &rfds, NULL, NULL, &tv);
   1329 
   1330                     if (retval == -1) {
   1331                         perror("select()");
   1332                         APP_DPRINT( " :: Error \n");
   1333                         break;
   1334                     }
   1335 
   1336                     if (!retval) {
   1337                         NoDataRead++;
   1338 
   1339                         if (NoDataRead == 2) {
   1340                             APP_IPRINT("Stoping component since No data is read from the pipes\n");
   1341                             StopComponent(pHandle);
   1342                         }
   1343                     } else {
   1344                         NoDataRead = 0;
   1345                     }
   1346 
   1347                     switch (tcID) {
   1348                         case 1:
   1349                         case 2:
   1350                         case 3:
   1351                         case 4:
   1352                         case 5:
   1353                         case 6:
   1354                         case 7:
   1355 
   1356                             if (audioinfo->dasfMode == 0) {
   1357                                 if (FD_ISSET(IpBuf_Pipe[0], &rfds)) {
   1358                                     OMX_BUFFERHEADERTYPE* pBuffer;
   1359                                     read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
   1360 
   1361                                     if ((frmCount == 14 || frmCount == 15) && tcID == 3) { /*Pause the component*/
   1362                                         APP_IPRINT("App: Pausing Component for 2 Seconds\n");
   1363                                         PauseComponent(pHandle);
   1364                                         sleep(2);
   1365                                         APP_IPRINT("App: Resume Component\n");
   1366                                         PlayComponent(pHandle);
   1367                                     }
   1368 
   1369                                     if (frmCount == 20 && tcID == 4) { /*Stop the component*/
   1370                                         tcID = 1;
   1371                                         StopComponent(pHandle);
   1372                                         break;
   1373                                     }
   1374 
   1375                                     eError =  send_input_buffer(pHandle, pBuffer, fIn);
   1376                                 }
   1377                             } else {
   1378                                 if (frmCount == 15 && tcID == 3) { /*Pause the component*/
   1379                                     tcID = 1;
   1380                                     APP_IPRINT("App: Pausing Component for 2 Seconds\n");
   1381                                     PauseComponent(pHandle);
   1382                                     sleep(2);
   1383                                     APP_IPRINT("App: Resume Component\n");
   1384                                     PlayComponent(pHandle);
   1385                                 }
   1386 
   1387                                 if (frmCount == 20 && tcID == 4) { /*Stop the component*/
   1388                                     StopComponent(pHandle);
   1389                                     break;
   1390                                 }
   1391 
   1392                                 APP_DPRINT("%d :: WBAMR ENCODER RUNNING UNDER DASF MODE \n", __LINE__);
   1393 
   1394                                 if (nFrameCount == 10 && tcID == 7) {
   1395                                     /* set high gain for record stream */
   1396                                     APP_IPRINT("[WBAMR encoder] --- will set stream gain to high\n");
   1397                                     pCompPrivateStructGain->sVolume.nValue = 0x8000;
   1398                                     eError = OMX_SetConfig(pHandle, OMX_IndexConfigAudioVolume, pCompPrivateStructGain);
   1399 
   1400                                     if (eError != OMX_ErrorNone) {
   1401                                         eError = OMX_ErrorBadParameter;
   1402                                         goto EXIT;
   1403                                     }
   1404                                 }
   1405 
   1406                                 if (nFrameCount == 250 && tcID == 7) {
   1407                                     /* set low gain for record stream */
   1408                                     APP_IPRINT("[WBAMR encoder] --- will set stream gain to low\n");
   1409                                     pCompPrivateStructGain->sVolume.nValue = 0x2000;
   1410                                     eError = OMX_SetConfig(pHandle, OMX_IndexConfigAudioVolume, pCompPrivateStructGain);
   1411 
   1412                                     if (eError != OMX_ErrorNone) {
   1413                                         eError = OMX_ErrorBadParameter;
   1414                                         goto EXIT;
   1415                                     }
   1416                                 }
   1417 
   1418                                 if (nFrameCount == atoi(argv[10])) {
   1419                                     StopComponent(pHandle);
   1420                                 }
   1421 
   1422                                 APP_DPRINT("%d :: WBAMR ENCODER READING DATA FROM DASF  \n", __LINE__);
   1423                             }
   1424 
   1425                             break;
   1426                         default:
   1427                             APP_DPRINT("%d :: ### Simple DEFAULT Case Here ###\n", __LINE__);
   1428                     }
   1429 
   1430                     if ( FD_ISSET(OpBuf_Pipe[0], &rfds) ) {
   1431                         OMX_BUFFERHEADERTYPE* pBuf;
   1432                         read(OpBuf_Pipe[0], &pBuf, sizeof(pBuf));
   1433                         APP_DPRINT("%d :: App: pBuf->nFilledLen = %ld\n", __LINE__, pBuf->nFilledLen);
   1434                         nFrameLen = pBuf->nFilledLen;
   1435 
   1436                         if (!(strcmp(pCompPrivateStruct->format.audio.cMIMEType, "MIME"))) {
   1437                             if (1 == nFrameCount) {
   1438                                 char MimeHeader[] = {0x23, 0x21, 0x41, 0x4d, 0x52, 0x2d, 0x57, 0x42, 0x0a};
   1439                                 fwrite(MimeHeader, 1, WBAMRENC_MIME_HEADER_LEN, fOut);
   1440                                 fflush(fOut);
   1441                                 APP_IPRINT("%d :: App: MIME Supported:: FrameLen = %d\n", __LINE__, nFrameLen);
   1442                             }
   1443                         }
   1444 
   1445                         APP_DPRINT("%d :: App: nFrameLen = %d \n", __LINE__, nFrameLen);
   1446 
   1447                         if (nFrameLen != 0) {
   1448                             APP_DPRINT("%d :: Writing OutputBuffer No: %d to the file nWrite = %d \n", __LINE__, nOutBuff, nFrameLen);
   1449                             fwrite(pBuf->pBuffer, 1, nFrameLen, fOut);
   1450                             fflush(fOut);
   1451                         }
   1452 
   1453                         if (pBuf->nFlags == OMX_BUFFERFLAG_EOS) {
   1454                             APP_IPRINT("%d :: App: OMX_BUFFERFLAG_EOS is received\n", __LINE__);
   1455                             APP_IPRINT("%d :: App: Shutting down ---------- \n", __LINE__);
   1456                             StopComponent(pHandle);
   1457                             pBuf->nFlags = 0;
   1458                         } else {
   1459                             nFrameCount++;
   1460                             nOutBuff++;
   1461                             pComponent->FillThisBuffer(pHandle, pBuf);
   1462                             APP_DPRINT("%d :: App: pBuf->nFlags = %ld\n", __LINE__, pBuf->nFlags);
   1463                         }
   1464                     }
   1465 
   1466                     if ( FD_ISSET(Event_Pipe[0], &rfds) ) {
   1467                         OMX_U8 pipeContents;
   1468                         read(Event_Pipe[0], &pipeContents, sizeof(OMX_U8));
   1469 
   1470                         if (pipeContents == 0) {
   1471                             APP_IPRINT("Test app received OMX_ErrorResourcesPreempted\n");
   1472                             WaitForState(pHandle, OMX_StateIdle);
   1473 
   1474                             for (i = 0; i < numOfInputBuffer; i++) {
   1475                                 APP_DPRINT("%d :: App: About to newfree pInputBufferHeader[%d]\n", __LINE__, i);
   1476                                 eError = OMX_FreeBuffer(pHandle, WBAPP_INPUT_PORT, pInputBufferHeader[i]);
   1477 
   1478                                 if ((eError != OMX_ErrorNone)) {
   1479                                     APP_DPRINT("%d:: Error in FreeBuffer function\n", __LINE__);
   1480                                     goto EXIT;
   1481                                 }
   1482 
   1483                             }
   1484 
   1485                             for (i = 0; i < numOfOutputBuffer; i++) {
   1486                                 APP_DPRINT("%d :: App: About to newfree pOutputBufferHeader[%d]\n", __LINE__, i);
   1487                                 eError = OMX_FreeBuffer(pHandle, WBAPP_OUTPUT_PORT, pOutputBufferHeader[i]);
   1488 
   1489                                 if ((eError != OMX_ErrorNone)) {
   1490                                     APP_DPRINT("%d :: Error in Free Buffer function\n", __LINE__);
   1491                                     goto EXIT;
   1492                                 }
   1493 
   1494                             }
   1495 
   1496 #ifdef USE_BUFFER
   1497 
   1498                             for (i = 0; i < numOfInputBuffer; i++) {
   1499                                 if (pInputBuffer[i] != NULL) {
   1500                                     APP_MEMPRINT("%d :: App: [TESTAPPFREE] pInputBuffer[%d] = %p\n", __LINE__, i, pInputBuffer[i]);
   1501                                     pInputBuffer[i] = pInputBuffer[i] - 128;
   1502                                     newfree(pInputBuffer[i]);
   1503                                     pInputBuffer[i] = NULL;
   1504                                 }
   1505                             }
   1506 
   1507 #endif
   1508 
   1509                             OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
   1510                             WaitForState(pHandle, OMX_StateLoaded);
   1511 
   1512                             OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateWaitForResources, NULL);
   1513                             WaitForState(pHandle, OMX_StateWaitForResources);
   1514                         } else if (pipeContents == 1) {
   1515                             APP_IPRINT("Test app received OMX_ErrorResourcesAcquired\n");
   1516 
   1517                             OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
   1518 
   1519                             for (i = 0; i < numOfOutputBuffer; i++) {
   1520                                 /* allocate output buffer */
   1521                                 APP_DPRINT("%d :: About to call OMX_AllocateBuffer for pOutputBufferHeader[%d]\n", __LINE__, i);
   1522                                 eError = OMX_AllocateBuffer(pHandle, &pOutputBufferHeader[i], 1, NULL, pCompPrivateStruct->nBufferSize * 2);
   1523 
   1524                                 if (eError != OMX_ErrorNone) {
   1525                                     APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer for pOutputBufferHeader[%d]\n", __LINE__, i);
   1526                                     goto EXIT;
   1527                                 }
   1528                             }
   1529 
   1530                             WaitForState(pHandle, OMX_StateIdle);
   1531 
   1532                             OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
   1533                             WaitForState(pHandle, OMX_StateExecuting);
   1534 
   1535                             rewind(fIn);
   1536 
   1537                             for (i = 0; i < numOfInputBuffer; i++) {
   1538                                 send_input_buffer (pHandle, pOutputBufferHeader[i], fIn);
   1539                             }
   1540                         }
   1541 
   1542                         if (pipeContents == 2) {
   1543 
   1544 #ifdef OMX_GETTIME
   1545                             GT_START();
   1546 #endif
   1547 
   1548                             OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
   1549                             WaitForState(pHandle, OMX_StateIdle);
   1550 
   1551 #ifdef OMX_GETTIME
   1552                             GT_END("Call to SendCommand <OMX_StateIdle>");
   1553 #endif
   1554 
   1555 #ifdef WAITFORRESOURCES
   1556 
   1557                             for (i = 0; i < numOfInputBuffer; i++) {
   1558                                 APP_DPRINT("%d :: App: About to newfree pInputBufferHeader[%d]\n", __LINE__, i);
   1559                                 eError = OMX_FreeBuffer(pHandle, WBAPP_INPUT_PORT, pInputBufferHeader[i]);
   1560 
   1561                                 if ((eError != OMX_ErrorNone)) {
   1562                                     APP_DPRINT("%d:: Error in FreeBuffer function\n", __LINE__);
   1563                                     goto EXIT;
   1564                                 }
   1565 
   1566                             }
   1567 
   1568                             for (i = 0; i < numOfOutputBuffer; i++) {
   1569                                 APP_DPRINT("%d :: App: About to newfree pOutputBufferHeader[%d]\n", __LINE__, i);
   1570                                 eError = OMX_FreeBuffer(pHandle, WBAPP_OUTPUT_PORT, pOutputBufferHeader[i]);
   1571 
   1572                                 if ((eError != OMX_ErrorNone)) {
   1573                                     APP_DPRINT("%d :: Error in Free Buffer function\n", __LINE__);
   1574                                     goto EXIT;
   1575                                 }
   1576 
   1577                             }
   1578 
   1579                             OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
   1580                             WaitForState(pHandle, OMX_StateLoaded);
   1581 
   1582                             goto SHUTDOWN;
   1583 #endif
   1584                         }
   1585                     }
   1586 
   1587 
   1588                     eError = pComponent->GetState(pHandle, &state);
   1589 
   1590                     if (eError != OMX_ErrorNone) {
   1591                         APP_DPRINT("%d :: pComponent->GetState has returned status %X\n", __LINE__, eError);
   1592                         goto EXIT;
   1593                     }
   1594 
   1595                 } else if (preempted) {
   1596                     sched_yield();
   1597                 } else {
   1598                     goto SHUTDOWN;
   1599                 }
   1600 
   1601             } /* While Loop Ending Here */
   1602 
   1603             APP_IPRINT("%d :: App: The current state of the component = %d \n", __LINE__, state);
   1604             fclose(fOut);
   1605             fclose(fIn);
   1606             FirstTime = 1;
   1607             NoDataRead = 0;
   1608 
   1609             if (tcID == 4)
   1610                 tcID = 1;
   1611 
   1612             APP_IPRINT("%d :: App: WBAMR Encoded = %d Frames \n", __LINE__, (nOutBuff));
   1613         } /*Test Case 4 & 5 Inner for loop ends here  */
   1614 
   1615         /* newfree the Allocate and Use Buffers */
   1616         APP_IPRINT("%d :: App: Freeing the Allocate OR Use Buffers in TestApp\n", __LINE__);
   1617 
   1618         if (!DasfMode) {
   1619             for (i = 0; i < numOfInputBuffer; i++) {
   1620                 APP_DPRINT("%d :: App: About to newfree pInputBufferHeader[%d]\n", __LINE__, i);
   1621                 eError = OMX_FreeBuffer(pHandle, WBAPP_INPUT_PORT, pInputBufferHeader[i]);
   1622 
   1623                 if ((eError != OMX_ErrorNone)) {
   1624                     APP_DPRINT("%d:: Error in FreeBuffer function\n", __LINE__);
   1625                     goto EXIT;
   1626                 }
   1627             }
   1628         }
   1629 
   1630         for (i = 0; i < numOfOutputBuffer; i++) {
   1631             APP_DPRINT("%d :: App: About to newfree pOutputBufferHeader[%d]\n", __LINE__, i);
   1632             eError = OMX_FreeBuffer(pHandle, WBAPP_OUTPUT_PORT, pOutputBufferHeader[i]);
   1633 
   1634             if ((eError != OMX_ErrorNone)) {
   1635                 APP_DPRINT("%d :: Error in Free Buffer function\n", __LINE__);
   1636                 goto EXIT;
   1637             }
   1638         }
   1639 
   1640 #ifdef USE_BUFFER
   1641         /* newfree the App Allocated Buffers */
   1642         APP_IPRINT("%d :: App: Freeing the App Allocated Buffers in TestApp\n", __LINE__);
   1643 
   1644         if (!DasfMode) {
   1645             for (i = 0; i < numOfInputBuffer; i++) {
   1646                 if (pInputBuffer[i] != NULL) {
   1647                     APP_MEMPRINT("%d :: App: [TESTAPPFREE] pInputBuffer[%d] = %p\n", __LINE__, i, pInputBuffer[i]);
   1648                     pInputBuffer[i] = pInputBuffer[i] - 128;
   1649                     newfree(pInputBuffer[i]);
   1650                     pInputBuffer[i] = NULL;
   1651                 }
   1652             }
   1653         }
   1654 
   1655         for (i = 0; i < numOfOutputBuffer; i++) {
   1656             if (pOutputBuffer[i] != NULL) {
   1657                 APP_MEMPRINT("%d :: App: [TESTAPPFREE] pOutputBuffer[%d] = %p\n", __LINE__, i, pOutputBuffer[i]);
   1658                 pOutputBuffer[i] = pOutputBuffer[i] - 128;
   1659                 newfree(pOutputBuffer[i]);
   1660                 pOutputBuffer[i] = NULL;
   1661             }
   1662         }
   1663 
   1664 #endif
   1665         APP_IPRINT ("%d :: App: Sending the OMX_StateLoaded Command\n", __LINE__);
   1666 #ifdef OMX_GETTIME
   1667         GT_START();
   1668 #endif
   1669         eError = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
   1670 
   1671         if (eError != OMX_ErrorNone) {
   1672             APP_DPRINT("%d:: Error from SendCommand-Idle State function\n", __LINE__);
   1673             goto EXIT;
   1674         }
   1675 
   1676         eError = WaitForState(pHandle, OMX_StateLoaded);
   1677 #ifdef OMX_GETTIME
   1678         GT_END("Call to SendCommand <OMX_StateLoaded>");
   1679 #endif
   1680 
   1681         if (eError != OMX_ErrorNone) {
   1682             APP_DPRINT( "Error:  WaitForState reports an eError %X\n", eError);
   1683             goto EXIT;
   1684         }
   1685 
   1686         APP_IPRINT ("%d :: App: Sending the OMX_CommandPortDisable Command\n", __LINE__);
   1687         eError = OMX_SendCommand(pHandle, OMX_CommandPortDisable, -1, NULL);
   1688 
   1689         if (eError != OMX_ErrorNone) {
   1690             APP_DPRINT("%d:: Error from SendCommand OMX_CommandPortDisable\n", __LINE__);
   1691             goto EXIT;
   1692         }
   1693 
   1694 
   1695 #ifdef WAITFORRESOURCES
   1696         eError = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateWaitForResources, NULL);
   1697 
   1698         if (eError != OMX_ErrorNone) {
   1699             APP_DPRINT ("%d Error from SendCommand-Idle State function\n", __LINE__);
   1700             goto EXIT;
   1701         }
   1702 
   1703         eError = WaitForState(pHandle, OMX_StateWaitForResources);
   1704 
   1705         /* temporarily put this here until I figure out what should really happen here */
   1706         sleep(10);
   1707         /* temporarily put this here until I figure out what should really happen here */
   1708 #endif
   1709 SHUTDOWN:
   1710 
   1711 
   1712         APP_IPRINT("%d :: App: Freeing the Memory Allocated in TestApp\n", __LINE__);
   1713 
   1714         APP_MEMPRINT("%d :: App: [TESTAPPFREE] %p\n", __LINE__, pAmrParam);
   1715 
   1716         if (pAmrParam != NULL) {
   1717             newfree(pAmrParam);
   1718             pAmrParam = NULL;
   1719         }
   1720 
   1721         APP_MEMPRINT("%d :: App: [TESTAPPFREE] %p\n", __LINE__, pCompPrivateStruct);
   1722 
   1723         if (pCompPrivateStruct != NULL) {
   1724             newfree(pCompPrivateStruct);
   1725             pCompPrivateStruct = NULL;
   1726         }
   1727 
   1728         APP_MEMPRINT("%d :: App: [TESTAPPFREE] %p\n", __LINE__, audioinfo);
   1729 
   1730         if (audioinfo != NULL) {
   1731             newfree(audioinfo);
   1732             audioinfo = NULL;
   1733         }
   1734 
   1735         if (streaminfo != NULL) {
   1736             newfree(streaminfo);
   1737             streaminfo = NULL;
   1738         }
   1739 
   1740         APP_IPRINT("%d :: App: Closing the Input and Output Pipes\n", __LINE__);
   1741         eError = close (IpBuf_Pipe[0]);
   1742 
   1743         if (0 != eError && OMX_ErrorNone == eError) {
   1744             eError = OMX_ErrorHardware;
   1745             APP_DPRINT("%d :: Error while closing IpBuf_Pipe[0]\n", __LINE__);
   1746             goto EXIT;
   1747         }
   1748 
   1749         eError = close (IpBuf_Pipe[1]);
   1750 
   1751         if (0 != eError && OMX_ErrorNone == eError) {
   1752             eError = OMX_ErrorHardware;
   1753             APP_DPRINT("%d :: Error while closing IpBuf_Pipe[1]\n", __LINE__);
   1754             goto EXIT;
   1755         }
   1756 
   1757         eError = close (OpBuf_Pipe[0]);
   1758 
   1759         if (0 != eError && OMX_ErrorNone == eError) {
   1760             eError = OMX_ErrorHardware;
   1761             APP_DPRINT("%d :: Error while closing OpBuf_Pipe[0]\n", __LINE__);
   1762             goto EXIT;
   1763         }
   1764 
   1765         eError = close (OpBuf_Pipe[1]);
   1766 
   1767         if (0 != eError && OMX_ErrorNone == eError) {
   1768             eError = OMX_ErrorHardware;
   1769             APP_DPRINT("%d :: Error while closing OpBuf_Pipe[1]\n", __LINE__);
   1770             goto EXIT;
   1771         }
   1772 
   1773 
   1774         eError = close(Event_Pipe[0]);
   1775 
   1776         if (0 != eError && OMX_ErrorNone == eError) {
   1777             eError = OMX_ErrorHardware;
   1778             APP_DPRINT("%d :: Error while closing Event_Pipe[0]\n", __LINE__);
   1779             goto EXIT;
   1780         }
   1781 
   1782         eError = close(Event_Pipe[1]);
   1783 
   1784         if (0 != eError && OMX_ErrorNone == eError) {
   1785             eError = OMX_ErrorHardware;
   1786             APP_DPRINT("%d :: Error while closing Event_Pipe[1]\n", __LINE__);
   1787             goto EXIT;
   1788         }
   1789 
   1790 
   1791         APP_IPRINT("%d :: App: Free the Component handle\n", __LINE__);
   1792         /* Unload the WBAMR Encoder Component */
   1793         eError = TIOMX_FreeHandle(pHandle);
   1794 
   1795         if ((eError != OMX_ErrorNone)) {
   1796             APP_DPRINT("%d :: Error in Free Handle function\n", __LINE__);
   1797             goto EXIT;
   1798         }
   1799 
   1800 
   1801 
   1802 
   1803         APP_IPRINT("%d :: App: Free Handle returned Successfully\n", __LINE__);
   1804 
   1805         APP_DPRINT("%d :: Deleting %p\n", __LINE__, pCompPrivateStructGain);
   1806         newfree(pCompPrivateStructGain);
   1807 
   1808 #ifdef DSP_RENDERING_ON
   1809         cmd_data.hComponent = pHandle;
   1810         cmd_data.AM_Cmd = AM_Exit;
   1811 
   1812         if ((write(wbamrencfdwrite, &cmd_data, sizeof(cmd_data))) < 0)
   1813             APP_IPRINT("%d ::- send command to audio manager\n", __LINE__);
   1814 
   1815         close(wbamrencfdwrite);
   1816         close(wbamrencfdread);
   1817 #endif
   1818 
   1819 
   1820 
   1821     } /*Outer for loop ends here */
   1822 
   1823 
   1824 
   1825     APP_IPRINT("%d :: *********************************************************************\n", __LINE__);
   1826     APP_IPRINT("%d :: NOTE: An output file %s has been created in file system\n", __LINE__, argv[2]);
   1827     APP_IPRINT("%d :: *********************************************************************\n", __LINE__);
   1828 
   1829     eError = TIOMX_Deinit();
   1830 
   1831     if ( (eError != OMX_ErrorNone)) {
   1832         APP_DPRINT("APP: Error in Deinit Core function\n");
   1833         goto EXIT;
   1834     }
   1835 
   1836     pthread_mutex_destroy(&WaitForState_mutex);
   1837     pthread_cond_destroy(&WaitForState_threshold);
   1838 
   1839 EXIT:
   1840 
   1841     if (bInvalidState == OMX_TRUE) {
   1842 #ifndef USE_BUFFER
   1843         eError = FreeAllResources(pHandle,
   1844                                   pInputBufferHeader[0],
   1845                                   pOutputBufferHeader[0],
   1846                                   numOfInputBuffer,
   1847                                   numOfOutputBuffer,
   1848                                   fIn,
   1849                                   fOut);
   1850 #else
   1851         eError = FreeAllResources(pHandle,
   1852                                   pInputBuffer,
   1853                                   pOutputBuffer,
   1854                                   numOfInputBuffer,
   1855                                   numOfOutputBuffer,
   1856                                   fIn,
   1857                                   fOut);
   1858 #endif
   1859     }
   1860 
   1861 #ifdef APP_DEBUGMEM
   1862     APP_IPRINT("\n-Printing memory not deleted-\n");
   1863 
   1864     for (i = 0; i < 500; i++) {
   1865         if (lines[i] != 0) {
   1866             APP_IPRINT(" --->%d Bytes allocated on File:%s Line: %d\n", bytes[i], file[i], lines[i]);
   1867         }
   1868     }
   1869 
   1870 #endif
   1871 
   1872 #ifdef OMX_GETTIME
   1873     GT_END("WBAMR_ENC test <End>");
   1874     OMX_ListDestroy(pListHead);
   1875 #endif
   1876     return eError;
   1877 }
   1878 
   1879 
   1880 OMX_ERRORTYPE send_input_buffer(OMX_HANDLETYPE pHandle, OMX_BUFFERHEADERTYPE* pBuffer, FILE *fIn) {
   1881     OMX_ERRORTYPE error = OMX_ErrorNone;
   1882     OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
   1883 
   1884     if (FirstTime) {
   1885         if (mframe) {
   1886             nRead = fread(pBuffer->pBuffer, 1, WBAPP_INPUT_BUFFER_SIZE * 2, fIn);
   1887         } else {
   1888             nRead = fread(pBuffer->pBuffer, 1, WBAPP_INPUT_BUFFER_SIZE, fIn);
   1889         }
   1890 
   1891         pBuffer->nFilledLen = nRead;
   1892     } else {
   1893         memcpy(pBuffer->pBuffer, NextBuffer, nRead);
   1894         pBuffer->nFilledLen = nRead;
   1895     }
   1896 
   1897     if (mframe) {
   1898         nRead = fread(NextBuffer, 1, WBAPP_INPUT_BUFFER_SIZE * 2, fIn);
   1899     } else {
   1900         nRead = fread(NextBuffer, 1, WBAPP_INPUT_BUFFER_SIZE, fIn);
   1901     }
   1902 
   1903     if (nRead < WBAPP_INPUT_BUFFER_SIZE && !DasfMode) {
   1904 
   1905 #ifdef OMX_GETTIME
   1906         GT_START();
   1907 #endif
   1908         error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
   1909         error = WaitForState(pHandle, OMX_StateIdle);
   1910 #ifdef OMX_GETTIME
   1911         GT_END("Call to SendCommand <OMX_StateIdle>");
   1912 #endif
   1913 
   1914         if (error != OMX_ErrorNone) {
   1915             APP_DPRINT ("%d :: Error from SendCommand-Idle(Stop) State function\n", __LINE__);
   1916             goto EXIT;
   1917         }
   1918 
   1919         pBuffer->nFlags = OMX_BUFFERFLAG_EOS;
   1920     } else {
   1921         pBuffer->nFlags = 0;
   1922     }
   1923 
   1924     if (pBuffer->nFilledLen != 0) {
   1925         if (pBuffer->nFlags == OMX_BUFFERFLAG_EOS) {
   1926             APP_IPRINT("Sending Last Input Buffer from App\n");
   1927         }
   1928 
   1929         pBuffer->nTimeStamp = rand() % 100;
   1930 
   1931         if (!preempted) {
   1932             error = pComponent->EmptyThisBuffer(pHandle, pBuffer);
   1933 
   1934             if (error == OMX_ErrorIncorrectStateOperation)
   1935                 error = 0;
   1936         }
   1937     }
   1938 
   1939     FirstTime = 0;
   1940 EXIT:
   1941     return error;
   1942 }
   1943 OMX_ERRORTYPE StopComponent(OMX_HANDLETYPE *pHandle) {
   1944     OMX_ERRORTYPE error = OMX_ErrorNone;
   1945 #ifdef OMX_GETTIME
   1946     GT_START();
   1947 #endif
   1948 
   1949     APP_IPRINT("%d :: APP: Sending Stop.........From APP \n", __LINE__);
   1950 
   1951     error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
   1952 
   1953     if (error != OMX_ErrorNone) {
   1954         fprintf(stderr, "\nError from SendCommand-Idle(Stop) State function!!!!!!!!\n");
   1955         goto EXIT;
   1956     }
   1957 
   1958     error = WaitForState(pHandle, OMX_StateIdle);
   1959 #ifdef OMX_GETTIME
   1960     GT_END("Call to SendCommand <OMX_StateIdle>");
   1961 #endif
   1962 
   1963     if (error != OMX_ErrorNone) {
   1964         fprintf(stderr, "\nError:  WaitForState reports an error %X!!!!!!!\n", error);
   1965         goto EXIT;
   1966     }
   1967 
   1968 EXIT:
   1969     return error;
   1970 }
   1971 
   1972 OMX_ERRORTYPE PauseComponent(OMX_HANDLETYPE *pHandle) {
   1973     OMX_ERRORTYPE error = OMX_ErrorNone;
   1974 #ifdef OMX_GETTIME
   1975     GT_START();
   1976 #endif
   1977     error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StatePause, NULL);
   1978 
   1979     if (error != OMX_ErrorNone) {
   1980         fprintf (stderr, "\nError from SendCommand-Pause State function!!!!!!\n");
   1981         goto EXIT;
   1982     }
   1983 
   1984     error = WaitForState(pHandle, OMX_StatePause);
   1985 
   1986 #ifdef OMX_GETTIME
   1987     GT_END("Call to SendCommand <OMX_StatePause>");
   1988 #endif
   1989 
   1990     if (error != OMX_ErrorNone) {
   1991         fprintf(stderr, "\nError:  WaitForState reports an error %X!!!!!!!\n", error);
   1992         goto EXIT;
   1993     }
   1994 
   1995 EXIT:
   1996     return error;
   1997 }
   1998 
   1999 OMX_ERRORTYPE PlayComponent(OMX_HANDLETYPE *pHandle) {
   2000     OMX_ERRORTYPE error = OMX_ErrorNone;
   2001 #ifdef OMX_GETTIME
   2002     GT_START();
   2003 #endif
   2004     error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
   2005 
   2006     if (error != OMX_ErrorNone) {
   2007         fprintf (stderr, "\nError from SendCommand-Executing State function!!!!!!!\n");
   2008         goto EXIT;
   2009     }
   2010 
   2011     error = WaitForState(pHandle, OMX_StateExecuting);
   2012 #ifdef OMX_GETTIME
   2013     GT_END("Call to SendCommand <OMX_StateExecuting>");
   2014 #endif
   2015 
   2016     if (error != OMX_ErrorNone) {
   2017         fprintf(stderr, "\nError:  WaitForState reports an error %X!!!!!!!\n", error);
   2018         goto EXIT;
   2019     }
   2020 
   2021 EXIT:
   2022     return error;
   2023 }
   2024 /*=================================================================
   2025 
   2026                             Freeing All allocated resources
   2027 
   2028 ==================================================================*/
   2029 #ifndef USE_BUFFER
   2030 int FreeAllResources( OMX_HANDLETYPE *pHandle,
   2031                       OMX_BUFFERHEADERTYPE* pBufferIn,
   2032                       OMX_BUFFERHEADERTYPE* pBufferOut,
   2033                       int NIB, int NOB,
   2034                       FILE* fileIn, FILE* fileOut) {
   2035     APP_IPRINT("%d::Freeing all resources by state invalid \n", __LINE__);
   2036     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2037     OMX_U16 i;
   2038 
   2039     if (!DasfMode) {
   2040         for (i = 0; i < NIB; i++) {
   2041             APP_IPRINT("%d :: APP: About to free pInputBufferHeader[%d]\n", __LINE__, i);
   2042             eError = OMX_FreeBuffer(pHandle, OMX_DirInput, pBufferIn + i);
   2043 
   2044         }
   2045     }
   2046 
   2047     for (i = 0; i < NOB; i++) {
   2048         APP_IPRINT("%d :: APP: About to free pOutputBufferHeader[%d]\n", __LINE__, i);
   2049         eError = OMX_FreeBuffer(pHandle, OMX_DirOutput, pBufferOut + i);
   2050     }
   2051 
   2052     /*i value is fixed by the number calls to malloc in the App */
   2053     for (i = 0; i < 5; i++) {
   2054         if (ArrayOfPointers[i] != NULL)
   2055             free(ArrayOfPointers[i]);
   2056     }
   2057 
   2058     TIOMX_FreeHandle(pHandle);
   2059 
   2060     return eError;
   2061 }
   2062 
   2063 
   2064 /*=================================================================
   2065 
   2066                             Freeing the resources with USE_BUFFER define
   2067 
   2068 ==================================================================*/
   2069 #else
   2070 
   2071 int FreeAllResources(OMX_HANDLETYPE *pHandle,
   2072                      OMX_U8* UseInpBuf[],
   2073                      OMX_U8* UseOutBuf[],
   2074                      int NIB, int NOB,
   2075                      FILE* fileIn, FILE* fileOut) {
   2076 
   2077     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2078     OMX_U16 i;
   2079     APP_IPRINT("%d::Freeing all resources by state invalid \n", __LINE__);
   2080 
   2081     /* free the UseBuffers */
   2082     for (i = 0; i < NIB; i++) {
   2083         UseInpBuf[i] = UseInpBuf[i] - 128;
   2084         APP_IPRINT("%d :: [TESTAPPFREE] pInputBuffer[%d] = %p\n", __LINE__, i, (UseInpBuf[i]));
   2085 
   2086         if (UseInpBuf[i] != NULL) {
   2087             newfree(UseInpBuf[i]);
   2088             UseInpBuf[i] = NULL;
   2089         }
   2090     }
   2091 
   2092     for (i = 0; i < NOB; i++) {
   2093         UseOutBuf[i] = UseOutBuf[i] - 128;
   2094         APP_IPRINT("%d :: [TESTAPPFREE] pOutputBuffer[%d] = %p\n", __LINE__, i, UseOutBuf[i]);
   2095 
   2096         if (UseOutBuf[i] != NULL) {
   2097             newfree(UseOutBuf[i]);
   2098             UseOutBuf[i] = NULL;
   2099         }
   2100     }
   2101 
   2102     /*i value is fixed by the number calls to malloc in the App */
   2103     for (i = 0; i < 5; i++) {
   2104         if (ArrayOfPointers[i] != NULL)
   2105             free(ArrayOfPointers[i]);
   2106     }
   2107 
   2108     OMX_FreeHandle(pHandle);
   2109 
   2110     return eError;
   2111 }
   2112 
   2113 #endif
   2114