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 G726Enc_Test.c
     26 *
     27 * This file implements G726 Encoder Component Test Application to verify
     28 * which is fully compliant with the Khronos OpenMAX (TM) 1.0 Specification
     29 *
     30 * @path  $(CSLPATH)\OMAPSW_MPU\linux\audio\src\openmax_il\g726_enc\tests
     31 *
     32 * @rev  1.0
     33 */
     34 /* ----------------------------------------------------------------------------
     35 *!
     36 *! Revision History
     37 *! ===================================
     38 *! Gyancarlo Garcia: Initial Verision
     39 *! 05-Oct-2007
     40 *!
     41 * =========================================================================== */
     42 /* ------compilation control switches -------------------------*/
     43 /****************************************************************
     44 *  INCLUDE FILES
     45 ****************************************************************/
     46 /* ----- system and platform files ----------------------------*/
     47 
     48 #include <unistd.h>
     49 #include <sys/ioctl.h>
     50 #include <sys/select.h>
     51 #include <errno.h>
     52 #include <linux/vt.h>
     53 #include <signal.h>
     54 #include <sys/stat.h>
     55 #include <pthread.h>
     56 #include <linux/soundcard.h>
     57 
     58 #include <string.h>
     59 #include <fcntl.h>
     60 #include <stdlib.h>
     61 #include <stdio.h>
     62 
     63 #include <OMX_Index.h>
     64 #include <OMX_Types.h>
     65 #include <OMX_Core.h>
     66 #include <OMX_Audio.h>
     67 #include <TIDspOmx.h>
     68 
     69 #include <OMX_Component.h>
     70 #include <time.h>
     71 #ifdef OMX_GETTIME
     72     #include <OMX_Common_Utils.h>
     73     #include <OMX_GetTime.h>     /*Headers for Performance & measuremet    */
     74 #endif
     75 int preempted=0;
     76 
     77 #undef  WAITFORRESOURCES
     78 #define MAX_CYCLES  20
     79 #undef  FLUSHINPAUSE
     80 
     81 FILE *fpRes = NULL;
     82 
     83 /* ======================================================================= */
     84 /**
     85  * @def G726ENC_INPUT_BUFFER_SIZE        Default input buffer size
     86  */
     87 /* ======================================================================= */
     88 #define G726ENC_INPUT_BUFFER_SIZE  16
     89 /*16 = 8 input samples of 2 bytes each*/
     90 /* ======================================================================= */
     91 /**
     92  * @def G726ENC_INPUT_BUFFER_SIZE_DASF     Default input buffer size for DASF tests
     93  */
     94 /* ======================================================================= */
     95 #define G726ENC_INPUT_BUFFER_SIZE_DASF 80
     96 
     97 /* ======================================================================= */
     98 /**
     99  * @def G726ENC_OUTPUT_BUFFER_SIZE   Default output buffer size
    100  */
    101 /* ======================================================================= */
    102 #define G726ENC_OUTPUT_BUFFER_SIZE 60
    103 /*60 was choseen since is multiple of 2,3,4 and 5, that are the
    104                                          smallest frame size for 16kps, 24kbps, 32kbps and 40kbps respectively,
    105                                          so the same outputSize can be used for all the bitrates*/
    106 
    107 /* ======================================================================= */
    108 /*
    109  * @def    G726ENC_APP_ID  App ID Value setting
    110  */
    111 /* ======================================================================= */
    112 #define G726ENC_APP_ID 100
    113 
    114 #define HALF_FRAME 1
    115 #define TWO_FRAMES 2
    116 
    117 #define SLEEP_TIME 5
    118 
    119 #define FIFO1 "/dev/fifo.1"
    120 #define FIFO2 "/dev/fifo.2"
    121 #undef APP_DEBUG
    122 
    123 #undef APP_MEMCHECK
    124 
    125 /*#define USE_BUFFER*/
    126 #undef USE_BUFFER
    127 
    128 #ifdef APP_DEBUG
    129     #define APP_DPRINT(...)    fprintf(stderr,__VA_ARGS__)
    130 #else
    131     #define APP_DPRINT(...)
    132 #endif
    133 
    134 #ifdef APP_MEMCHECK
    135     #define APP_MEMPRINT(...)    fprintf(stderr,__VA_ARGS__)
    136 #else
    137     #define APP_MEMPRINT(...)
    138 #endif
    139 
    140 #ifdef OMX_GETTIME
    141   OMX_ERRORTYPE eError = OMX_ErrorNone;
    142   int GT_FlagE = 0;  /* Fill Buffer 1 = First Buffer,  0 = Not First Buffer  */
    143   int GT_FlagF = 0;  /*Empty Buffer  1 = First Buffer,  0 = Not First Buffer  */
    144   static OMX_NODE* pListHead = NULL;
    145 #endif
    146 
    147 /* ======================================================================= */
    148 /**
    149  * @def    APP_DEBUGMEM   Turns memory leaks messaging on and off.
    150  *         NBAMRENC_DEBUGMEM must be defined in OMX Comp in order to get
    151  *         this functionality On.
    152  */
    153 /* ======================================================================= */
    154 #undef APP_DEBUGMEM
    155 /*#define APP_DEBUGMEM*/
    156 
    157 #ifdef APP_DEBUGMEM
    158 void *arr[500] = {NULL};
    159 int lines[500] = {0};
    160 int bytes[500] = {0};
    161 char file[500][50]  = {""};
    162 int ind=0;
    163 
    164 #define SafeMalloc(x) DebugMalloc(__LINE__,__FILE__,x)
    165 #define SafeFree(z) DebugFree(z,__LINE__,__FILE__)
    166 
    167 void * DebugMalloc(int line, char *s, int size)
    168 {
    169    void *p = NULL;
    170    int e=0;
    171    p = calloc(1,size);
    172    if(p==NULL){
    173        printf("__ Memory not available\n");
    174        exit(1);
    175        }
    176    else{
    177          while((lines[e]!=0)&& (e<500) ){
    178               e++;
    179          }
    180          arr[e]=p;
    181          lines[e]=line;
    182          bytes[e]=size;
    183          strcpy(file[e],s);
    184          printf("__ Allocating %d bytes on address %p, line %d file %s\n", size, p, line, s);
    185          return p;
    186    }
    187 }
    188 
    189 int DebugFree(void *dp, int line, char *s){
    190     int q = 0;
    191     if(dp==NULL){
    192                  printf("__ NULL can't be deleted\n");
    193                  return 0;
    194     }
    195     for(q=0;q<500;q++){
    196         if(arr[q]==dp){
    197            printf("__ Deleting %d bytes on address %p, line %d file %s\n", bytes[q],dp, line, s);
    198            free(dp);
    199            dp = NULL;
    200            lines[q]=0;
    201            strcpy(file[q],"");
    202            break;
    203         }
    204      }
    205      if(500==q)
    206          printf("\n\__ nPointer not found. Line:%d    File%s!!\n\n",line, s);
    207 }
    208 #else
    209 #define SafeMalloc(x) calloc(1,x)
    210 #define SafeFree(z) free(z)
    211 #endif
    212 
    213 
    214 /* ======================================================================= */
    215 /**
    216  *  M A C R O S FOR MALLOC and MEMORY FREE and CLOSING PIPES
    217  */
    218 /* ======================================================================= */
    219 
    220 #define OMX_NBAPP_CONF_INIT_STRUCT(_s_, _name_)    \
    221     memset((_s_), 0x0, sizeof(_name_));    \
    222     (_s_)->nSize = sizeof(_name_);        \
    223     (_s_)->nVersion.s.nVersionMajor = 0x1;    \
    224     (_s_)->nVersion.s.nVersionMinor = 0x0;    \
    225     (_s_)->nVersion.s.nRevision = 0x0;        \
    226     (_s_)->nVersion.s.nStep = 0x0
    227 
    228 #define OMX_NBAPP_INIT_STRUCT(_s_, _name_)    \
    229     memset((_s_), 0x0, sizeof(_name_));    \
    230 
    231 #define OMX_NBAPP_MALLOC_STRUCT(_pStruct_, _sName_)   \
    232     _pStruct_ = (_sName_*)SafeMalloc(sizeof(_sName_));      \
    233     if(_pStruct_ == NULL){      \
    234         printf("***********************************\n"); \
    235         printf("%d :: Malloc Failed\n",__LINE__); \
    236         printf("***********************************\n"); \
    237         eError = OMX_ErrorInsufficientResources; \
    238         goto EXIT;      \
    239     } \
    240     APP_MEMPRINT("%d :: ALLOCATING MEMORY = %p\n",__LINE__,_pStruct_);
    241 
    242 
    243 /* ======================================================================= */
    244 /**
    245  * @def NBAPP_MAX_NUM_OF_BUFS       Maximum number of buffers
    246  * @def    NBAPP_NUM_OF_CHANNELS         Number of Channels
    247  * @def NBAPP_SAMPLING_FREQUENCY    Sampling frequency
    248  */
    249 /* ======================================================================= */
    250 #define NBAPP_MAX_NUM_OF_BUFS 10
    251 #define NBAPP_NUM_OF_CHANNELS 1
    252 #define NBAPP_SAMPLING_FREQUENCY 8000
    253 
    254 typedef struct AUDIO_INFO {
    255     OMX_U32 acdnMode;
    256     OMX_U32 dasfMode;
    257     OMX_U32 nIpBufs;
    258     OMX_U32 nIpBufSize;
    259     OMX_U32 nOpBufs;
    260     OMX_U32 nOpBufSize;
    261     OMX_U32 nMFrameMode;
    262 } AUDIO_INFO;
    263 
    264 static OMX_BOOL bInvalidState;
    265 
    266 OMX_ERRORTYPE StopComponent(OMX_HANDLETYPE *pHandle);
    267 OMX_ERRORTYPE PauseComponent(OMX_HANDLETYPE *pHandle);
    268 OMX_ERRORTYPE PlayComponent(OMX_HANDLETYPE *pHandle);
    269 OMX_ERRORTYPE send_input_buffer(OMX_HANDLETYPE pHandle, OMX_BUFFERHEADERTYPE* pBuffer, FILE *fIn);
    270 
    271 int maxint(int a, int b);
    272 
    273 int inputPortDisabled = 0;
    274 int outputPortDisabled = 0;
    275 
    276 OMX_STRING strG726Encoder = "OMX.TI.G726.encode";
    277 
    278 int IpBuf_Pipe[2] = {0};
    279 int OpBuf_Pipe[2] = {0};
    280 int Event_Pipe[2] = {0};
    281 
    282 fd_set rfds;
    283 int done = 0;
    284 int FirstTime = 1;
    285 int mframe=0;
    286 int nRead = 0;
    287 int DasfMode =0;
    288 unsigned long int vez=0;
    289 
    290 OMX_U8 NextBuffer[G726ENC_INPUT_BUFFER_SIZE*3];
    291 OMX_U32 fdwrite = 0;
    292 OMX_U32 fdread = 0;
    293 
    294 pthread_mutex_t WaitForState_mutex;
    295 pthread_cond_t  WaitForState_threshold;
    296 OMX_U8          WaitForState_flag = 0;
    297 OMX_U8		TargetedState = 0;
    298 
    299 /* safe routine to get the maximum of 2 integers */
    300 int maxint(int a, int b)
    301 {
    302    return (a>b) ? a : b;
    303 }
    304 
    305 /* This method will wait for the component to get to the state
    306  * specified by the DesiredState input. */
    307 static OMX_ERRORTYPE WaitForState(OMX_HANDLETYPE* pHandle,
    308                                   OMX_STATETYPE DesiredState)
    309 {
    310      OMX_STATETYPE CurState = OMX_StateInvalid;
    311      OMX_ERRORTYPE eError = OMX_ErrorNone;
    312      OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
    313      eError = OMX_GetState(pComponent, &CurState);
    314      if (CurState == OMX_StateInvalid && bInvalidState == OMX_TRUE)
    315 	 {
    316 		 eError = OMX_ErrorInvalidState;
    317 	 }
    318      if(CurState != DesiredState){
    319             WaitForState_flag = 1;
    320             TargetedState = DesiredState;
    321             pthread_mutex_lock(&WaitForState_mutex);
    322             pthread_cond_wait(&WaitForState_threshold, &WaitForState_mutex);/*Going to sleep till signal arrives*/
    323             pthread_mutex_unlock(&WaitForState_mutex);
    324      }
    325      return eError;
    326 }
    327 
    328 OMX_ERRORTYPE EventHandler(
    329         OMX_HANDLETYPE hComponent,
    330         OMX_PTR pAppData,
    331         OMX_EVENTTYPE eEvent,
    332         OMX_U32 nData1,
    333         OMX_U32 nData2,
    334         OMX_PTR pEventData)
    335 {
    336    APP_DPRINT( "%d :: App: Entering EventHandler \n", __LINE__);
    337    OMX_ERRORTYPE eError = OMX_ErrorNone;
    338    OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)hComponent;
    339    OMX_STATETYPE state = OMX_StateInvalid;
    340    OMX_U8 writeValue = 0;
    341 
    342    eError = OMX_GetState(pComponent, &state);
    343    if(eError != OMX_ErrorNone) {
    344        APP_DPRINT("%d :: App: Error returned from OMX_GetState\n",__LINE__);
    345        goto EXIT;
    346    }
    347    APP_DPRINT( "%d :: App: Component eEvent = %d\n", __LINE__,eEvent);
    348    switch (eEvent) {
    349        APP_DPRINT( "%d :: App: Component State Changed To %d\n", __LINE__,state);
    350        case OMX_EventResourcesAcquired:
    351             writeValue = 1;
    352             write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
    353             preempted=0;
    354        break;
    355        case OMX_EventCmdComplete:
    356            APP_DPRINT( "%d :: App: Component State Changed To %d\n", __LINE__,state);
    357         if (nData1 == OMX_CommandPortDisable) {
    358             if (nData2 == OMX_DirInput) {
    359                 inputPortDisabled = 1;
    360             }
    361             if (nData2 == OMX_DirOutput) {
    362                 outputPortDisabled = 1;
    363             }
    364         }
    365         if ((nData1 == OMX_CommandStateSet) && (TargetedState == nData2) && (WaitForState_flag)){
    366                         WaitForState_flag = 0;
    367                         pthread_mutex_lock(&WaitForState_mutex);
    368                         pthread_cond_signal(&WaitForState_threshold);/*Sending Waking Up Signal*/
    369                         pthread_mutex_unlock(&WaitForState_mutex);
    370                 }
    371         if (nData1 == OMX_CommandFlush){
    372             if (nData2 == OMX_DirInput) {
    373                 printf ("App: EventHandler - Flush completed on input port\n");
    374             }
    375             else if (nData2 == OMX_DirOutput) {
    376                 printf ("App: EventHandler - Flush completed on output port\n");
    377             }
    378         }
    379            break;
    380        case OMX_EventError:
    381 		   if (nData1 == OMX_ErrorInvalidState) {
    382 		   		bInvalidState =OMX_TRUE;
    383 		   }
    384 		   else if(nData1 == OMX_ErrorResourcesPreempted) {
    385                       preempted=1;
    386 
    387 		      writeValue = 0;
    388                     write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
    389 		   }
    390 		   else if (nData1 == OMX_ErrorResourcesLost) {
    391                     WaitForState_flag = 0;
    392                     pthread_mutex_lock(&WaitForState_mutex);
    393                     pthread_cond_signal(&WaitForState_threshold);/*Sending Waking Up Signal*/
    394                     pthread_mutex_unlock(&WaitForState_mutex);
    395            }
    396            break;
    397        case OMX_EventMax:
    398               APP_DPRINT( "%d :: App: Component OMX_EventMax = %d\n", __LINE__,eEvent);
    399            break;
    400        case OMX_EventMark:
    401               APP_DPRINT( "%d :: App: Component OMX_EventMark = %d\n", __LINE__,eEvent);
    402            break;
    403        case OMX_EventPortSettingsChanged:
    404               APP_DPRINT( "%d :: App: Component OMX_EventPortSettingsChanged = %d\n", __LINE__,eEvent);
    405               break;
    406        case OMX_EventBufferFlag:
    407               APP_DPRINT( "%d :: App: Component OMX_EventBufferFlag = %d\n", __LINE__,eEvent);
    408 #ifdef WAITFORRESOURCES
    409             writeValue = 2;
    410             write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
    411 #endif
    412            break;
    413        default:
    414            break;
    415 
    416    }
    417 EXIT:
    418     APP_DPRINT( "%d :: App: Exiting EventHandler \n", __LINE__);
    419     return eError;
    420 }
    421 
    422 void FillBufferDone (OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer)
    423 {
    424     write(OpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
    425 #ifdef OMX_GETTIME
    426 	if (GT_FlagF == 1 ) /* First Buffer Reply*/  /* 1 = First Buffer,  0 = Not First Buffer  */
    427     {
    428 		GT_END("Call to FillBufferDone  <First: FillBufferDone>");
    429         GT_FlagF = 0 ;   /* 1 = First Buffer,  0 = Not First Buffer  */
    430     }
    431 #endif
    432 }
    433 
    434 void EmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer)
    435 {
    436     if (!preempted)
    437         write(IpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
    438 #ifdef OMX_GETTIME
    439     if (GT_FlagE == 1 ) /* First Buffer Reply*/  /* 1 = First Buffer,  0 = Not First Buffer  */
    440     {
    441       GT_END("Call to EmptyBufferDone <First: EmptyBufferDone>");
    442 	  GT_FlagE = 0;   /* 1 = First Buffer,  0 = Not First Buffer  */
    443     }
    444 #endif
    445 }
    446 
    447 int main(int argc, char* argv[])
    448 {
    449     OMX_CALLBACKTYPE G726CaBa = {(void *)EventHandler,
    450                 (void*)EmptyBufferDone,
    451                                 (void*)FillBufferDone};
    452     OMX_HANDLETYPE pHandle;
    453     OMX_ERRORTYPE eError = OMX_ErrorNone;
    454     OMX_U32 AppData = G726ENC_APP_ID;
    455     OMX_PARAM_PORTDEFINITIONTYPE* pCompPrivateStruct = NULL;
    456     OMX_AUDIO_PARAM_G726TYPE *pG726Param = NULL;
    457 
    458     OMX_COMPONENTTYPE *pComponent = NULL;
    459     OMX_STATETYPE state = OMX_StateInvalid;
    460     OMX_BUFFERHEADERTYPE* pInputBufferHeader[NBAPP_MAX_NUM_OF_BUFS] = {NULL};
    461     OMX_BUFFERHEADERTYPE* pOutputBufferHeader[NBAPP_MAX_NUM_OF_BUFS] = {NULL};
    462 #ifdef USE_BUFFER
    463     OMX_U8* pInputBuffer[NBAPP_MAX_NUM_OF_BUFS] = {NULL};
    464     OMX_U8* pOutputBuffer[NBAPP_MAX_NUM_OF_BUFS] = {NULL};
    465 #endif
    466     TI_OMX_DSP_DEFINITION* audioinfo = NULL;
    467 
    468     FILE* fIn = NULL;
    469     FILE* fOut = NULL;
    470     struct timeval tv;
    471     int retval, i = 0, j = 0, k = 0, kk = 0, tcID = 0;
    472     int frmCount = 0;
    473     int frmCnt = 1;
    474     int testcnt = 0;
    475     int testcnt1 = 0;
    476     int fdmax = 0;
    477     int nFrameCount = 1;
    478     int nFrameLen = 0;
    479     int nIpBuff = 1;
    480     int nOutBuff = 1;
    481     OMX_INDEXTYPE index = 0;
    482     int status = 0;
    483     int    NoDataRead = 0;
    484     int numInputBuffers=0,numOutputBuffers=0;
    485     OMX_AUDIO_CONFIG_VOLUMETYPE* pCompPrivateStructGain = NULL;
    486     TI_OMX_DATAPATH dataPath;
    487     TI_OMX_STREAM_INFO *streaminfo=NULL;
    488 
    489     bInvalidState=OMX_FALSE;
    490 
    491     pthread_mutex_init(&WaitForState_mutex, NULL);
    492     pthread_cond_init (&WaitForState_threshold, NULL);
    493     WaitForState_flag = 0;
    494 
    495     printf("------------------------------------------------------\n");
    496     printf("This is Main Thread In G726 ENCODER Test Application:\n");
    497     printf("Test Core 1.5 - " __DATE__ ":" __TIME__ "\n");
    498     printf("------------------------------------------------------\n");
    499 
    500 #ifdef OMX_GETTIME
    501     printf("Line %d\n",__LINE__);
    502       GTeError = OMX_ListCreate(&pListHead);
    503         printf("Line %d\n",__LINE__);
    504       printf("eError = %d\n",GTeError);
    505       GT_START();
    506   printf("Line %d\n",__LINE__);
    507 #endif
    508 
    509     /* check the input parameters */
    510     if(argc < 9) {
    511         printf("%d :: Usage: [TestApp][Input File][Output File][FUNC_ID_X][FM/DM][ACDN_ON/ACDN_OFF][16/24/3240][# INPUT BUF][# OUTPUT BUF][# REP]\n",__LINE__);
    512         goto EXIT;
    513     }
    514 
    515     /* check to see that the input file exists */
    516     struct stat sb = {0};
    517     status = stat(argv[1], &sb);
    518     if( status != 0 ) {
    519         printf("Cannot find file %s (%u)\n", argv[1], errno);
    520         goto EXIT;
    521     }
    522 
    523     /* Open the file of data to be encoded. */
    524     printf("%d :: App: Input file is %s\n", __LINE__, argv[1]);
    525     fIn = fopen(argv[1], "r");
    526     if( fIn == NULL ) {
    527             APP_DPRINT("Error:  failed to open the input file %s\n", argv[1]);
    528             goto EXIT;
    529     }
    530 
    531     /* Open the file of data to be written. */
    532     printf("%d :: App: g726 output file is %s\n", __LINE__, argv[2]);
    533     fOut = fopen(argv[2], "w");
    534     if( fOut == NULL ) {
    535             APP_DPRINT("Error:  failed to open the output file %s\n", argv[2]);
    536             goto EXIT;
    537     }
    538 
    539     if(!strcmp(argv[3],"FUNC_ID_1")) {
    540         printf("%d :: ### TESTCASE 1: Playing component till EOF ###\n",__LINE__);
    541         testcnt = 1;
    542         testcnt1 = 1;
    543         tcID = 1;
    544     } else if(!strcmp(argv[3],"FUNC_ID_2")) {
    545         printf("%d :: ### TESTCASE 2: Stoping component at the middle of stream ###\n",__LINE__);
    546         testcnt = 1;
    547         testcnt1 = 1;
    548         tcID = 2;
    549     } else if(!strcmp(argv[3],"FUNC_ID_3")) {
    550         printf("%d :: ### TESTCASE 3: Runing pause & resume test ###\n",__LINE__);
    551         testcnt = 1;
    552         testcnt1 = 1;
    553         tcID = 3;
    554     } else if(!strcmp(argv[3],"FUNC_ID_4")) {
    555         printf("%d :: ### TESTCASE 4: Runing stop & resume test ###\n",__LINE__);
    556         testcnt = 2;
    557         testcnt1 = 1;
    558         tcID = 4;
    559         printf("######## testcnt = %d #########\n",testcnt);
    560     }
    561     if(!strcmp(argv[3],"FUNC_ID_5")){
    562         printf("%d :: ### TESTCASE 5: Repetitive Test without deleting the component ###\n",__LINE__);
    563         if (argc > 9)
    564         {
    565             testcnt = (int) atoi (argv[9]);
    566         }
    567         else
    568         {
    569             testcnt = MAX_CYCLES;
    570         }
    571         testcnt1 = 1;
    572         tcID = 5;
    573     }
    574 
    575     if(!strcmp(argv[3],"FUNC_ID_6")) {
    576         printf("%d :: ### TESTCASE 6: Repetitive Test with Deleting the component ###\n",__LINE__);
    577         testcnt = 1;
    578         if (argc > 9)
    579         {
    580             testcnt1 = (int) atoi( argv[9]);
    581         }
    582         else
    583         {
    584             testcnt1 = MAX_CYCLES;
    585         }
    586         tcID = 6;
    587     }
    588 
    589     if(!strcmp(argv[3],"FUNC_ID_7")) {
    590         printf("%d :: ### TESTCASE 7: Testing Component by sending 2 frames by buffer ###\n",__LINE__);
    591         testcnt = 1;
    592         testcnt1 = 1;
    593         tcID = 1;
    594         mframe = TWO_FRAMES;
    595     }
    596 
    597     if(!strcmp(argv[3],"FUNC_ID_8")) {
    598         printf("%d :: ### TESTCASE 8: Testing Component by sending 1/2 frame by buffer ###\n",__LINE__);
    599         testcnt = 1;
    600         testcnt1 = 1;
    601         tcID = 1;
    602         mframe = HALF_FRAME;
    603     }
    604 
    605     if(!strcmp(argv[3],"FUNC_ID_9")) {
    606         printf("%d :: ### TESTCASE 8: Runing Component with Volume Test ###\n",__LINE__);
    607         testcnt = 1;
    608         testcnt1 = 1;
    609         tcID = 1;
    610     }
    611 
    612 
    613     for(j = 0; j < testcnt1; j++) {
    614 
    615         /* Create a pipe used to queue data from the callback. */
    616         retval = pipe(IpBuf_Pipe);
    617         if( retval != 0) {
    618             APP_DPRINT("Error:Fill Data Pipe failed to open\n");
    619             goto EXIT;
    620         }
    621 
    622         retval = pipe(OpBuf_Pipe);
    623         if( retval != 0) {
    624             APP_DPRINT("Error:Empty Data Pipe failed to open\n");
    625             goto EXIT;
    626         }
    627 
    628         retval = pipe(Event_Pipe);
    629         if(retval != 0) {
    630             APP_DPRINT( "Error:Empty Event Pipe failed to open\n");
    631             goto EXIT;
    632         }
    633         /* save off the "max" of the handles for the selct statement */
    634         fdmax = maxint(IpBuf_Pipe[0], OpBuf_Pipe[0]);
    635         fdmax = maxint(fdmax,Event_Pipe[0]);
    636 
    637         eError = TIOMX_Init();
    638 
    639         if(eError != OMX_ErrorNone) {
    640             APP_DPRINT("%d :: Error returned by OMX_Init()\n",__LINE__);
    641             goto EXIT;
    642         }
    643 
    644         if(j >= 1) {
    645             printf ("%d :: Encoding the file in TESTCASE 6\n",__LINE__);
    646             fIn = fopen(argv[1], "r");
    647             if( fIn == NULL ) {
    648                 fprintf(stderr, "Error:  failed to open the file %s for read only access\n",argv[1]);
    649                 goto EXIT;
    650             }
    651 
    652             fOut = fopen("TC6_G7261.G726", "w");
    653             if( fOut == NULL ) {
    654                 fprintf(stderr, "Error:  failed to create the output file %s\n",argv[2]);
    655                 goto EXIT;
    656             }
    657          }
    658 
    659         /* Load the G726 Encoder Component */
    660 	#ifdef OMX_GETTIME
    661 		GT_START();
    662         eError = TIOMX_GetHandle(&pHandle, strG726Encoder, &AppData, &G726CaBa);
    663 		GT_END("Call to GetHandle");
    664 	#else
    665         eError = TIOMX_GetHandle(&pHandle, strG726Encoder, &AppData, &G726CaBa);
    666 	#endif
    667         if((eError != OMX_ErrorNone) || (pHandle == NULL)) {
    668             APP_DPRINT("Error in Get Handle function\n");
    669             printf("Error in Get Handle function\n");
    670             goto EXIT;
    671         }
    672 
    673         OMX_NBAPP_MALLOC_STRUCT(audioinfo, TI_OMX_DSP_DEFINITION);
    674         OMX_NBAPP_INIT_STRUCT(audioinfo, TI_OMX_DSP_DEFINITION);
    675 
    676         /* Setting Input and Output Buffers features for the Component */
    677         numInputBuffers = atoi(argv[7]);
    678         printf("%d :: App: number of input buffers = %d \n",__LINE__,numInputBuffers);
    679         printf("%d :: App: input buffer size = %d \n",__LINE__,G726ENC_INPUT_BUFFER_SIZE);
    680 
    681         numOutputBuffers = atoi(argv[8]);
    682         printf("%d :: App: number of output buffers = %d \n",__LINE__,numOutputBuffers);
    683         printf("%d :: App: output buffer size = %d \n",__LINE__,G726ENC_OUTPUT_BUFFER_SIZE);
    684 
    685         OMX_NBAPP_MALLOC_STRUCT(pCompPrivateStruct, OMX_PARAM_PORTDEFINITIONTYPE);
    686         OMX_NBAPP_CONF_INIT_STRUCT(pCompPrivateStruct, OMX_PARAM_PORTDEFINITIONTYPE);
    687 
    688         OMX_NBAPP_MALLOC_STRUCT(pG726Param, OMX_AUDIO_PARAM_G726TYPE);
    689         OMX_NBAPP_CONF_INIT_STRUCT(pG726Param, OMX_AUDIO_PARAM_G726TYPE);
    690 
    691         APP_DPRINT("%d :: Setting input port config\n",__LINE__);
    692         pCompPrivateStruct->nSize                              = sizeof (OMX_PARAM_PORTDEFINITIONTYPE);
    693         pCompPrivateStruct->nVersion.s.nVersionMajor           = 0xF1;
    694         pCompPrivateStruct->nVersion.s.nVersionMinor           = 0xF2;
    695         pCompPrivateStruct->nPortIndex                         = OMX_DirInput;
    696         pCompPrivateStruct->eDir                               = OMX_DirInput;
    697         pCompPrivateStruct->nBufferCountActual                 = numInputBuffers;
    698         pCompPrivateStruct->nBufferCountMin                    = numInputBuffers;
    699         pCompPrivateStruct->nBufferSize                        = G726ENC_INPUT_BUFFER_SIZE;
    700         pCompPrivateStruct->bEnabled                           = OMX_TRUE;
    701         pCompPrivateStruct->bPopulated                         = OMX_FALSE;
    702         pCompPrivateStruct->eDomain                            = OMX_PortDomainAudio;
    703         pCompPrivateStruct->format.audio.eEncoding             = OMX_AUDIO_CodingG726;
    704         pCompPrivateStruct->format.audio.pNativeRender         = NULL;
    705         pCompPrivateStruct->format.audio.bFlagErrorConcealment = OMX_FALSE;    /*Send input port config*/
    706 
    707         if(!(strcmp(argv[4],"FM"))) {
    708             audioinfo->dasfMode = 0;
    709             APP_DPRINT("\n%d :: App: audioinfo->dasfMode = %ld \n",__LINE__,audioinfo->dasfMode);
    710         } else if(!(strcmp(argv[4],"DM"))){
    711             audioinfo->dasfMode = 1;
    712             DasfMode = 1;
    713             APP_DPRINT("\n%d :: App: audioinfo->dasfMode = %ld \n",__LINE__,audioinfo->dasfMode);
    714             APP_DPRINT("%d :: G726 ENCODER RUNNING UNDER DASF MODE \n",__LINE__);
    715             pCompPrivateStruct->nBufferCountActual = 0;
    716             pCompPrivateStruct->nBufferSize = G726ENC_INPUT_BUFFER_SIZE_DASF;
    717         } else {
    718             eError = OMX_ErrorBadParameter;
    719             printf("\n%d :: App: audioinfo->dasfMode Sending Bad Parameter\n",__LINE__);
    720             printf("%d :: App: Should Be One of these Modes FM, DM\n",__LINE__);
    721             goto EXIT;
    722         }
    723 
    724 
    725         if (argc == 11)
    726         {
    727             /* Application wants to decide upon rtp */
    728             audioinfo->rtpMode = atoi (argv[10]);
    729 
    730         }
    731         else
    732         {
    733             /* if user hasn't decided, let's go linear */
    734             audioinfo->rtpMode = 0;
    735         }
    736 
    737         if(audioinfo->dasfMode) { /*Dasf Mode*/
    738             if((atoi(argv[7])) != 0) {
    739                 eError = OMX_ErrorBadParameter;
    740                 printf("%d :: App: For DASF mode argv[7] Should Be --> 0\n",__LINE__);
    741                 goto EXIT;
    742             }
    743         } else {
    744             if((atoi(argv[7])) == 0) {  /*File Mode*/
    745                 eError = OMX_ErrorBadParameter;
    746                 printf("%d :: App: For FILE mode argv[7] Should be greater than zero depends on number of buffers user want to encode\n",__LINE__);
    747                 goto EXIT;
    748             }
    749         }
    750 
    751         if(!(strcmp(argv[5],"ACDN_OFF"))) {
    752               audioinfo->acousticMode = 0;
    753               APP_DPRINT("\n%d :: App: audioinfo->acdnMode = %ld \n",__LINE__,audioinfo->acousticMode);
    754         } else if(!(strcmp(argv[5],"ACDN_ON"))) {
    755               audioinfo->acousticMode = 1;
    756               APP_DPRINT("\n%d :: App: audioinfo->acdnMode = %ld \n",__LINE__,audioinfo->acousticMode);
    757         } else {
    758               eError = OMX_ErrorBadParameter;
    759               printf("\n%d :: App: audioinfo->acdnMode Sending Bad Parameter\n",__LINE__);
    760               printf("%d :: App: Should Be One of these Modes ACDN_ON, ACDN_OFF, not %s\n",__LINE__, argv[5]);
    761               goto EXIT;
    762         }
    763 	#ifdef OMX_GETTIME
    764 		GT_START();
    765         eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
    766 		GT_END("Set Parameter Test-SetParameter");
    767 	#else
    768         eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
    769 	#endif
    770         if (eError != OMX_ErrorNone) {
    771             eError = OMX_ErrorBadParameter;
    772             APP_DPRINT("%d :: OMX_ErrorBadParameter\n",__LINE__);
    773             goto EXIT;
    774         }
    775 
    776         APP_MEMPRINT("%d :: Setting output port config\n",__LINE__);
    777         pCompPrivateStruct->nSize                              = sizeof (OMX_PARAM_PORTDEFINITIONTYPE);
    778         pCompPrivateStruct->nVersion.s.nVersionMajor           = 0xF1;
    779         pCompPrivateStruct->nVersion.s.nVersionMinor           = 0xF2;
    780         pCompPrivateStruct->nPortIndex                         = OMX_DirOutput;
    781         pCompPrivateStruct->eDir                               = OMX_DirOutput;
    782         pCompPrivateStruct->nBufferCountActual                 = numOutputBuffers;
    783         pCompPrivateStruct->nBufferCountMin                    = numOutputBuffers;
    784         pCompPrivateStruct->nBufferSize                        = G726ENC_OUTPUT_BUFFER_SIZE;
    785         pCompPrivateStruct->bEnabled                           = OMX_TRUE;
    786         pCompPrivateStruct->bPopulated                         = OMX_FALSE;
    787         pCompPrivateStruct->eDomain                            = OMX_PortDomainAudio;
    788         pCompPrivateStruct->format.audio.eEncoding             = OMX_AUDIO_CodingG726;
    789         pCompPrivateStruct->format.audio.pNativeRender         = NULL;
    790         pCompPrivateStruct->format.audio.bFlagErrorConcealment = OMX_FALSE;    /*Send output port config*/
    791 	#ifdef OMX_GETTIME
    792 		GT_START();
    793         eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
    794 		GT_END("Set Parameter Test-SetParameter");
    795 	#else
    796         eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
    797 	#endif
    798         if (eError != OMX_ErrorNone) {
    799             eError = OMX_ErrorBadParameter;
    800             APP_DPRINT("%d :: OMX_ErrorBadParameter\n",__LINE__);
    801             goto EXIT;
    802         }
    803 
    804         if(!(strcmp(argv[6],"16"))) {
    805               pG726Param->eG726Mode = OMX_AUDIO_G726Mode16;
    806               APP_DPRINT("\n%d :: App: eBitRate set to 16 kbps\n",__LINE__);
    807         }
    808         else if(!(strcmp(argv[6],"24"))) {
    809               pG726Param->eG726Mode = OMX_AUDIO_G726Mode24;
    810               APP_DPRINT("\n%d :: App: eBitRate set to 24 kbps\n",__LINE__);
    811         }
    812         else if(!(strcmp(argv[6],"32"))) {
    813               pG726Param->eG726Mode = OMX_AUDIO_G726Mode32;
    814               APP_DPRINT("\n%d :: App: eBitRate set to 32 kbps\n",__LINE__);
    815         }
    816         else if(!(strcmp(argv[6],"40"))) {
    817               pG726Param->eG726Mode = OMX_AUDIO_G726Mode40;
    818               APP_DPRINT("\n%d :: App: eBitRate set to 40 kbps\n",__LINE__);
    819         }
    820         else{
    821               pG726Param->eG726Mode = OMX_AUDIO_G726ModeUnused;
    822               APP_DPRINT("\n%d :: App: UnSuported bit Rate, setting to OMX_AUDIO_G726ModeUnused\n",__LINE__);
    823          }
    824 
    825         /* Send  G726 config for output */
    826         pG726Param->nSize                    = sizeof(OMX_AUDIO_PARAM_G726TYPE);
    827         pG726Param->nVersion.s.nVersionMajor = 0xF1;
    828         pG726Param->nVersion.s.nVersionMinor = 0xF2;
    829         pG726Param->nPortIndex               = OMX_DirOutput;
    830         pG726Param->nChannels                = NBAPP_NUM_OF_CHANNELS;
    831 	#ifdef OMX_GETTIME
    832 		GT_START();
    833         eError = OMX_SetParameter (pHandle, OMX_IndexParamAudioG726, pG726Param);
    834 		GT_END("Set Parameter Test-SetParameter");
    835 	#else
    836         eError = OMX_SetParameter (pHandle, OMX_IndexParamAudioG726, pG726Param);
    837 	#endif
    838         if (eError != OMX_ErrorNone) {
    839             eError = OMX_ErrorBadParameter;
    840             APP_DPRINT("%d :: OMX_ErrorBadParameter\n",__LINE__);
    841             goto EXIT;
    842         }
    843 
    844 #ifdef DSP_RENDERING_ON
    845     if (audioinfo->dasfMode){
    846           if((fdwrite=open(FIFO1,O_WRONLY))<0) {
    847          	   APP_DPRINT("%d :: [G726E Component] - failure to open WRITE pipe\n",__LINE__);
    848           }
    849           if((fdread=open(FIFO2,O_RDONLY))<0) {
    850       	       APP_DPRINT("%d :: [G726E Component] - failure to open READ pipe\n",__LINE__);
    851           }
    852           APP_DPRINT("%d :: OMX_ComponentInit\n", __LINE__);
    853 
    854          cmd_data.hComponent = pHandle;
    855          cmd_data.AM_Cmd = AM_CommandIsInputStreamAvailable;
    856          cmd_data.param1 = 0;
    857 
    858          if((write(fdwrite, &cmd_data, sizeof(cmd_data)))<0) {
    859              APP_DPRINT("%d :: [G726E Component] - send command to audio manager\n",__LINE__);
    860          }
    861          if((read(fdread, &cmd_data, sizeof(cmd_data)))<0) {
    862       	     printf("%d :: [G726E Component] - failure to get data from the audio manager!!! \n",__LINE__);
    863    	         goto EXIT;
    864          }
    865     	 if(cmd_data.streamID == 0) {
    866 		     printf("%d :: [G726E Component] - no input stream available!!!!!!!\n",__LINE__);
    867 		     eError = OMX_ErrorInsufficientResources;
    868 		      goto EXIT;
    869 
    870 	     } else {
    871 		       APP_DPRINT("%d :: [G726E Component] - input stream available\n",__LINE__);
    872 		       audioinfo->streamId=cmd_data.streamID;
    873 		       eError = OMX_ErrorNone;
    874     	}
    875     }
    876 #endif
    877 
    878     eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.tispecific",&index);
    879         if (eError != OMX_ErrorNone) {
    880             APP_DPRINT("Error returned from OMX_GetExtensionIndex\n");
    881             goto EXIT;
    882         }
    883 
    884     eError = OMX_SetConfig (pHandle, index, audioinfo);
    885         if(eError != OMX_ErrorNone) {
    886             eError = OMX_ErrorBadParameter;
    887             APP_DPRINT("%d :: Error from OMX_SetConfig() function\n",__LINE__);
    888             goto EXIT;
    889     }
    890     if (audioinfo->acousticMode == OMX_TRUE) {
    891         printf("Using Acoustic Device Node Path\n");
    892         dataPath = DATAPATH_ACDN;
    893     }
    894     else if (audioinfo->dasfMode) {
    895 #ifdef RTM_PATH
    896         printf("Using Real Time Mixer Path\n");
    897         dataPath = DATAPATH_APPLICATION_RTMIXER;
    898 #endif
    899 
    900 #ifdef ETEEDN_PATH
    901         printf("Using Eteeden Path\n");
    902         dataPath = DATAPATH_APPLICATION;
    903 #endif
    904     }
    905     eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.G726.datapath",&index);
    906 	if (eError != OMX_ErrorNone) {
    907 		printf("Error getting extension index\n");
    908 		goto EXIT;
    909 	}
    910 	eError = OMX_SetConfig (pHandle, index, &dataPath);
    911     if(eError != OMX_ErrorNone) {
    912         eError = OMX_ErrorBadParameter;
    913         APP_DPRINT("%d :: AmrDecTest.c :: Error from OMX_SetConfig() function\n",__LINE__);
    914         goto EXIT;
    915     }
    916 
    917         if (audioinfo->dasfMode ==  1) {
    918              /* get streamID back to application */
    919              OMX_NBAPP_MALLOC_STRUCT(streaminfo, TI_OMX_STREAM_INFO);
    920 
    921      	    eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.G726.streamIDinfo",&index);
    922           	if (eError != OMX_ErrorNone) {
    923       	     	printf("Error getting extension index\n");
    924         		goto EXIT;
    925           	}
    926 
    927            	eError = OMX_GetConfig (pHandle, index, streaminfo);
    928             if(eError != OMX_ErrorNone) {
    929                  eError = OMX_ErrorBadParameter;
    930                  APP_DPRINT("%d :: AmrEncTest.c :: Error from OMX_GetConfig() function\n",__LINE__);
    931                  goto EXIT;
    932             }
    933             printf("***************StreamId=%ld******************\n", streaminfo->streamId);
    934        }
    935 
    936         APP_DPRINT("%d Sending Component to OMX_StateIdle\n",__LINE__);
    937 	#ifdef OMX_GETTIME
    938 		GT_START();
    939 	#endif
    940         eError = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
    941         if(eError != OMX_ErrorNone) {
    942             APP_DPRINT("Error from SendCommand-Idle(Init) State function\n");
    943             goto EXIT;
    944         }
    945 
    946 #ifndef USE_BUFFER
    947         APP_DPRINT("%d :: About to call OMX_AllocateBuffer\n",__LINE__);
    948         for(i = 0; i < numInputBuffers; i++) {
    949             /* allocate input buffer */
    950             APP_DPRINT("%d :: About to call OMX_AllocateBuffer for pInputBufferHeader[%d]\n",__LINE__, i);
    951             eError = OMX_AllocateBuffer(pHandle, &pInputBufferHeader[i], 0, NULL, G726ENC_INPUT_BUFFER_SIZE);
    952             if(eError != OMX_ErrorNone) {
    953                 APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer for pInputBufferHeader[%d]\n",__LINE__, i);
    954                 goto EXIT;
    955             }
    956         }
    957 
    958         for(i = 0; i < numOutputBuffers; i++) {
    959             /* allocate output buffer */
    960             APP_DPRINT("%d :: About to call OMX_AllocateBuffer for pOutputBufferHeader[%d]\n",__LINE__, i);
    961             eError = OMX_AllocateBuffer(pHandle, &pOutputBufferHeader[i], 1, NULL, G726ENC_OUTPUT_BUFFER_SIZE);
    962             if(eError != OMX_ErrorNone) {
    963                 APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer for pOutputBufferHeader[%d]\n",__LINE__, i);
    964                 goto EXIT;
    965             }
    966         }
    967 #else
    968         for(i = 0; i < numInputBuffers; i++) {
    969             pInputBuffer[i] = (OMX_U8*)SafeMalloc(G726ENC_INPUT_BUFFER_SIZE);
    970             APP_MEMPRINT("%d :: [TESTAPP ALLOC] pInputBuffer[%d] = %p\n",__LINE__,i,pInputBuffer[i]);
    971             if(NULL == pInputBuffer[i]) {
    972                 APP_DPRINT("%d :: Malloc Failed\n",__LINE__);
    973                 eError = OMX_ErrorInsufficientResources;
    974                 goto EXIT;
    975             }
    976             /*  allocate input buffer */
    977             APP_DPRINT("%d :: About to call OMX_UseBuffer\n",__LINE__);
    978             eError = OMX_UseBuffer(pHandle, &pInputBufferHeader[i], 0, NULL, G726ENC_INPUT_BUFFER_SIZE, pInputBuffer[i]);
    979             if(eError != OMX_ErrorNone) {
    980                 APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n",__LINE__);
    981                 goto EXIT;
    982             }
    983         }
    984 
    985         for(i = 0; i < numOutputBuffers; i++) {
    986             pOutputBuffer[i] = SafeMalloc(G726ENC_OUTPUT_BUFFER_SIZE + 256);
    987             APP_MEMPRINT("%d :: [TESTAPP ALLOC] pOutputBuffer[%d] = %p\n",__LINE__,i,pOutputBuffer[i]);
    988             if(NULL == pOutputBuffer[i]) {
    989                 APP_DPRINT("%d :: Malloc Failed\n",__LINE__);
    990                 eError = OMX_ErrorInsufficientResources;
    991                 goto EXIT;
    992             }
    993             pOutputBuffer[i] = pOutputBuffer[i] + 128;
    994 
    995             /* allocate output buffer */
    996             APP_DPRINT("%d :: About to call OMX_UseBuffer\n",__LINE__);
    997             eError = OMX_UseBuffer(pHandle, &pOutputBufferHeader[i], 1, NULL, G726ENC_OUTPUT_BUFFER_SIZE, pOutputBuffer[i]);
    998             if(eError != OMX_ErrorNone) {
    999                 APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n",__LINE__);
   1000                 goto EXIT;
   1001             }
   1002         }
   1003 #endif
   1004 
   1005         /* Wait for startup to complete */
   1006         eError = WaitForState(pHandle, OMX_StateIdle);
   1007 	#ifdef OMX_GETTIME
   1008 		GT_END("Call to SendCommand <OMX_StateIdle>");
   1009 	#endif
   1010         if(eError != OMX_ErrorNone) {
   1011             APP_DPRINT( "Error:  hG726Encoder->WaitForState reports an eError %X\n", eError);
   1012             goto EXIT;
   1013         }
   1014         APP_DPRINT("%d Component on OMX_StateIdle\n",__LINE__);
   1015 
   1016         for(i = 0; i < testcnt; i++) {
   1017             frmCnt = 1;
   1018             nFrameCount = 1;
   1019             nOutBuff = 1;
   1020             nIpBuff  = 1;
   1021             if(i >= 1) {
   1022                 printf("%d :: Encoding the file in TESTCASE 5 OR TESTCSE 4\n",__LINE__);
   1023                 fIn = fopen(argv[1], "r");
   1024                 if(fIn == NULL) {
   1025                     fprintf(stderr, "Error:  failed to open the file %s for readonly access\n", argv[1]);
   1026                     goto EXIT;
   1027                 }
   1028                 fOut = fopen("TC5_G7261.G726", "w");
   1029                 if(fOut == NULL) {
   1030                     fprintf(stderr, "Error:  failed to create the output file %s\n", argv[2]);
   1031                     goto EXIT;
   1032                 }
   1033             }
   1034 
   1035             done = 0;
   1036             APP_DPRINT("%d :: App: Sending OMX_StateExecuting Command\n",__LINE__);
   1037 
   1038             APP_DPRINT("%d Sending Component to OMX_Executing\n",__LINE__);
   1039 		#ifdef OMX_GETTIME
   1040 			GT_START();
   1041 		#endif
   1042             eError = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
   1043             if(eError != OMX_ErrorNone) {
   1044                 printf("Error from SendCommand-Executing State function\n");
   1045                 goto EXIT;
   1046             }
   1047             eError = WaitForState(pHandle, OMX_StateExecuting);
   1048 		#ifdef OMX_GETTIME
   1049 			GT_END("Call to SendCommand <OMX_StateExecuting>");
   1050 		#endif
   1051             APP_DPRINT("%d Component on OMX_Executing\n",__LINE__);
   1052             if(eError != OMX_ErrorNone) {
   1053                 APP_DPRINT( "Error:  hG726Encoder->WaitForState reports an eError %X\n", eError);
   1054                 goto EXIT;
   1055             }
   1056 
   1057             if(audioinfo->dasfMode == 1) {
   1058                 printf("%d :: App: No.of Buffers Encoding = %d\n",__LINE__, atoi(argv[8]));
   1059             }
   1060 
   1061             pComponent = (OMX_COMPONENTTYPE *)pHandle;
   1062 
   1063             if(audioinfo->dasfMode == 0) {
   1064                 for (k=0; k < numInputBuffers; k++) {
   1065                     OMX_BUFFERHEADERTYPE* pBuffer = pInputBufferHeader[k];
   1066 		            pBuffer->nFlags=0;
   1067                             APP_DPRINT("%d About to call send_input_buffer\n",__LINE__);/*glen*/
   1068 						#ifdef OMX_GETTIME
   1069 					        if (k==0)
   1070 					        {
   1071 					           GT_FlagE=1;  /* 1 = First Buffer,  0 = Not First Buffer  */
   1072 					           GT_START(); /* Empty Bufffer */
   1073 							}
   1074 						#endif
   1075                             eError =  send_input_buffer(pHandle, pBuffer, fIn);
   1076                 }
   1077             }
   1078 
   1079             for (kk = 0; kk < numOutputBuffers; kk++) {
   1080                 APP_DPRINT("%d :: App: Calling FillThisBuffer \n",__LINE__);
   1081                 APP_DPRINT("%d About to call FillThisBuffern \n",__LINE__);/*glen*/
   1082 			#ifdef OMX_GETTIME
   1083 		        if (kk==0)
   1084 		        {
   1085 		           GT_FlagF=1;  /* 1 = First Buffer,  0 = Not First Buffer  */
   1086 		           GT_START(); /* Fill Buffer */
   1087 				}
   1088 			#endif
   1089                 OMX_FillThisBuffer(pHandle, pOutputBufferHeader[kk]);
   1090             }
   1091 
   1092             eError = OMX_GetState(pComponent, &state);
   1093             if(eError != OMX_ErrorNone) {
   1094                 APP_DPRINT("%d :: OMX_GetState has returned status %X\n",__LINE__, eError);
   1095                 goto EXIT;
   1096             }
   1097             retval = 1;
   1098 #ifdef WAITFORRESOURCES
   1099             while( 1 ){
   1100             if((eError == OMX_ErrorNone) && (state != OMX_StateIdle) && (state != OMX_StateInvalid) ){
   1101 #else
   1102             while((eError == OMX_ErrorNone) && (state != OMX_StateIdle) && (state != OMX_StateInvalid)){
   1103             if( 1 ){
   1104 #endif
   1105                 FD_ZERO(&rfds);
   1106                 FD_SET(IpBuf_Pipe[0], &rfds);
   1107                 FD_SET(OpBuf_Pipe[0], &rfds);
   1108                 FD_SET(Event_Pipe[0], &rfds);
   1109                 tv.tv_sec = 1;
   1110                 tv.tv_usec = 0;
   1111 
   1112                 retval = select(fdmax+1, &rfds, NULL, NULL, &tv);
   1113                 if(retval == -1) {
   1114                     perror("select()");
   1115                     APP_DPRINT( " :: Error \n");
   1116                     break;
   1117                 }
   1118 
   1119                 if(!retval){
   1120                     NoDataRead++;
   1121 #ifdef WAITFORRESOURCES
   1122                     if(NoDataRead > 2000){
   1123 #else
   1124                     if(NoDataRead > 5){
   1125 #endif
   1126                         printf("Stoping component since No data is read from the pipes\n");
   1127                         StopComponent(pHandle);
   1128                     }
   1129                 }
   1130                 else{
   1131                      NoDataRead=0;
   1132                 }
   1133 
   1134                 switch (tcID) {
   1135 		        case 1:
   1136 		        case 2:
   1137 		        case 3:
   1138                         case 4:
   1139 		        case 5:
   1140 		        case 6:
   1141                         case 7:
   1142 			if(audioinfo->dasfMode == 0) {
   1143 				if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {
   1144 					OMX_BUFFERHEADERTYPE* pBuffer = NULL;
   1145 					read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
   1146                                         frmCount++;
   1147 					if (frmCount==15 && tcID ==3){ /*Pause the component*/
   1148 						printf("App: Pausing Component for 5 Seconds....\n\n\n");
   1149 						PauseComponent(pHandle);
   1150 						sleep(3);
   1151 #ifdef FLUSHINPAUSE
   1152 						printf("App: Sending Flush to input port\n");
   1153 						eError = OMX_SendCommand(pHandle, OMX_CommandFlush, 0, NULL);
   1154                         if(eError != OMX_ErrorNone) {
   1155                             APP_DPRINT("%d:: Error from SendCommand OMX_CommandFlush\n",__LINE__);
   1156                             goto EXIT;
   1157                         }
   1158 #endif
   1159                         sleep(2);
   1160 						printf("App: Resume Component\n");
   1161 						PlayComponent(pHandle);
   1162 					}
   1163 					if (frmCount==50 && tcID ==4){ /*Stop the component*/
   1164                                                 printf("Stoping the Component And Starting Again\n");
   1165                                                 printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
   1166                                                 StopComponent(pHandle);
   1167                                                 tcID = 1;
   1168 						break;
   1169                                         }
   1170                                         if (frmCount==100 && tcID ==2){ /*Stop the component*/
   1171                                                 printf("Stoping the Component at the middle of stream\n");
   1172                                                 StopComponent(pHandle);
   1173 						break;
   1174                                         }
   1175 					eError =  send_input_buffer(pHandle, pBuffer, fIn);
   1176 				        }
   1177 			} else {
   1178                                        if (nFrameCount==15 && tcID ==3){  /*Pause the component*/
   1179                                                 tcID = 1;
   1180 						printf("App: Pausing Component for 5 Seconds....\n\n\n");
   1181 						PauseComponent(pHandle);
   1182 						sleep(3);
   1183 #ifdef FLUSHINPAUSE
   1184 						printf("App: Sending Flush to output port\n");
   1185 						eError = OMX_SendCommand(pHandle, OMX_CommandFlush, 1, NULL);
   1186                         if(eError != OMX_ErrorNone) {
   1187                             APP_DPRINT("%d:: Error from SendCommand OMX_CommandFlush\n",__LINE__);
   1188                             goto EXIT;
   1189                         }
   1190 #endif
   1191                         sleep(2);
   1192 						printf("App: Resume Component\n");
   1193 						PlayComponent(pHandle);
   1194 					}
   1195 					if (nFrameCount==50 && tcID ==4){ /*Stop the component*/
   1196 					        printf("Stoping the Component And Starting Again\n");
   1197                             printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
   1198 						StopComponent(pHandle);
   1199                                                 tcID = 1;
   1200 						nFrameCount = 0;
   1201 						break;
   1202                                         }
   1203                                         if (nFrameCount==100 && tcID ==2){ /*Stop the component*/
   1204                                                 printf("Stoping the Component at the middle of stream\n");
   1205                                                 StopComponent(pHandle);
   1206 						break;
   1207                                         }
   1208 
   1209 					if(nFrameCount == 50 && tcID == 7)												     {
   1210 							/* set high gain for record stream */
   1211 							printf("[G726 encoder] --- will set stream gain to high\n");
   1212             				                pCompPrivateStructGain->sVolume.nValue = 0x8000;
   1213 							eError = OMX_SetConfig(pHandle, OMX_IndexConfigAudioVolume, pCompPrivateStructGain);
   1214 							if (eError != OMX_ErrorNone)
   1215 							{
   1216 								eError = OMX_ErrorBadParameter;
   1217 								goto EXIT;
   1218 							}
   1219 					}
   1220 					if(nFrameCount == 250 && tcID == 7)
   1221 					{
   1222 							/* set low gain for record stream */
   1223 							printf("[G726 encoder] --- will set stream gain to low\n");
   1224             				                pCompPrivateStructGain->sVolume.nValue = 0x2000;
   1225 							eError = OMX_SetConfig(pHandle, OMX_IndexConfigAudioVolume, pCompPrivateStructGain);
   1226 							if (eError != OMX_ErrorNone)
   1227 							{
   1228 								eError = OMX_ErrorBadParameter;
   1229 								goto EXIT;
   1230 							}
   1231 					}
   1232 				}
   1233 		break;
   1234 		default:
   1235 				APP_DPRINT("%d :: ### Simple DEFAULT Case Here ###\n",__LINE__);
   1236 		}
   1237                 /*----- output buffer ----*/
   1238                 if( FD_ISSET(OpBuf_Pipe[0], &rfds) ) {
   1239                     OMX_BUFFERHEADERTYPE* pBuf = NULL;
   1240                     read(OpBuf_Pipe[0], &pBuf, sizeof(pBuf));
   1241                     APP_DPRINT("%d :: App: pBuf->nFilledLen = %ld\n",__LINE__, pBuf->nFilledLen);
   1242                     nFrameLen = pBuf->nFilledLen;
   1243                     APP_DPRINT("%d :: App: nFrameLen = %d \n",__LINE__, nFrameLen);
   1244                     if (nFrameLen != 0) {
   1245                         APP_DPRINT("%d :: Writing OutputBuffer No: %d to the file nWrite = %d \n",__LINE__, nOutBuff, nFrameLen);
   1246                         APP_DPRINT("Writing %d Bytes to the output File #%d\n", nFrameLen,nFrameCount);
   1247                         fwrite(pBuf->pBuffer, 1, nFrameLen, fOut);
   1248                         fflush(fOut);
   1249                     }
   1250                     nFrameCount++;
   1251                     APP_DPRINT("%d :: App: pBuf->nFlags = %ld\n",__LINE__, pBuf->nFlags);
   1252 
   1253                     if(pBuf->nFlags == OMX_BUFFERFLAG_EOS) {
   1254 				          printf("%d :: App: OMX_BUFFERFLAG_EOS is received\n",__LINE__);
   1255 				          printf("%d :: App: Shutting down ---------- \n",__LINE__);
   1256 				          StopComponent(pHandle);
   1257 				          pBuf->nFlags = 0;
   1258             	    }
   1259 			        else{
   1260 				          nOutBuff++;
   1261                           OMX_FillThisBuffer(pComponent, pBuf);
   1262  			              APP_DPRINT("%d :: App: pBuf->nFlags = %ld\n",__LINE__, pBuf->nFlags);
   1263         			}
   1264                     if(audioinfo->dasfMode) {
   1265      				    APP_DPRINT("%d :: NBAMR ENCODER RUNNING UNDER DASF MODE \n",__LINE__);
   1266 					    if(nFrameCount >= 400) {
   1267                                                     printf("400 Frames Reached, Stoping Component from App\n");/*glen*/
   1268 						    StopComponent(pHandle);
   1269 					    }
   1270 					    APP_DPRINT("%d :: NBAMR ENCODER READING DATA FROM DASF  \n",__LINE__);
   1271                     }
   1272                 }
   1273 /*-------*/
   1274         if( FD_ISSET(Event_Pipe[0], &rfds) ) {
   1275             OMX_U8 pipeContents = 0;
   1276             read(Event_Pipe[0], &pipeContents, sizeof(OMX_U8));
   1277             APP_DPRINT("%d :: received RM event: %d\n",__LINE__, pipeContents);
   1278             if (pipeContents == 0) {
   1279 
   1280                 printf("Test app received OMX_ErrorResourcesPreempted\n");
   1281                 WaitForState(pHandle,OMX_StateIdle);
   1282                 for (i=0; i < numInputBuffers; i++) {
   1283                     eError = OMX_FreeBuffer(pHandle,OMX_DirInput,pInputBufferHeader[i]);
   1284                     if( (eError != OMX_ErrorNone)) {
   1285                         APP_DPRINT ("Error in Free Handle function\n");
   1286                     }
   1287                 }
   1288 
   1289                 for (i=0; i < numOutputBuffers; i++) {
   1290                     eError = OMX_FreeBuffer(pHandle,OMX_DirOutput,pOutputBufferHeader[i]);
   1291                     if( (eError != OMX_ErrorNone)) {
   1292                         APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
   1293                     }
   1294                 }
   1295 
   1296 #ifdef USE_BUFFER
   1297                 /* newfree the App Allocated Buffers */
   1298                 APP_DPRINT("%d :: Freeing the App Allocated Buffers in TestApp\n",__LINE__);
   1299                 for(i=0; i < numInputBuffers; i++) {
   1300                     APP_MEMPRINT("%d::: [TESTAPPFREE] pInputBuffer[%d] = %p\n",__LINE__,i,pInputBuffer[i]);
   1301                     if(pInputBuffer[i] != NULL){
   1302                         pInputBuffer[i] = pInputBuffer[i] - 128;
   1303                         newfree(pInputBuffer[i]);
   1304                         pInputBuffer[i] = NULL;
   1305                         }
   1306                     }
   1307                     for(i=0; i < numOutputBuffers; i++) {
   1308                         APP_MEMPRINT("%d::: [TESTAPPFREE] pOutputBuffer[%d] = %p\n",__LINE__,i, pOutputBuffer[i]);
   1309                         if(pOutputBuffer[i] != NULL){
   1310                             pOutputBuffer[i] = pOutputBuffer[i] - 128;
   1311                             newfree(pOutputBuffer[i]);
   1312                             pOutputBuffer[i] = NULL;
   1313                         }
   1314                     }
   1315 #endif
   1316 
   1317                     OMX_SendCommand(pHandle,OMX_CommandStateSet,OMX_StateLoaded,NULL);
   1318                     WaitForState(pHandle,OMX_StateLoaded);
   1319                     OMX_SendCommand(pHandle,OMX_CommandStateSet,OMX_StateWaitForResources,NULL);
   1320                     WaitForState(pHandle,OMX_StateWaitForResources);
   1321                     }
   1322                     else if (pipeContents == 1) {
   1323                         printf("Test app received OMX_ErrorResourcesAcquired\n");
   1324 
   1325         OMX_SendCommand(pHandle,OMX_CommandStateSet,OMX_StateIdle,NULL);
   1326 	for (i=0; i < numInputBuffers; i++) {
   1327 		/* allocate input buffer */
   1328 		eError = OMX_AllocateBuffer(pHandle,&pInputBufferHeader[i],0,NULL,G726ENC_INPUT_BUFFER_SIZE*3); /*To have enought space for    */
   1329 		if(eError != OMX_ErrorNone) {
   1330 	        APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer()\n",__LINE__);
   1331 		}
   1332 
   1333 
   1334 	}
   1335 
   1336 		WaitForState(pHandle,OMX_StateIdle);
   1337     OMX_SendCommand(pHandle,OMX_CommandStateSet,OMX_StateExecuting,NULL);
   1338     WaitForState(pHandle,OMX_StateExecuting);
   1339     rewind(fIn);
   1340         for (i=0; i < numInputBuffers;i++) {
   1341             send_input_buffer(pHandle, pInputBufferHeader[i], fIn);
   1342         }
   1343 
   1344                     }
   1345                 if (pipeContents == 2) {
   1346 
   1347                     StopComponent(pHandle);
   1348 
   1349                 for (i=0; i < numInputBuffers; i++) {
   1350                     eError = OMX_FreeBuffer(pHandle,OMX_DirInput,pInputBufferHeader[i]);
   1351                     if( (eError != OMX_ErrorNone)) {
   1352                         APP_DPRINT ("%d :: TestAPP :: Error in Free Handle function\n",__LINE__);
   1353                     }
   1354                 }
   1355 
   1356                 for (i=0; i < numOutputBuffers; i++) {
   1357                     eError = OMX_FreeBuffer(pHandle,OMX_DirOutput,pOutputBufferHeader[i]);
   1358                     if( (eError != OMX_ErrorNone)) {
   1359                         APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
   1360                     }
   1361                 }
   1362 
   1363 #if 1
   1364     eError = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateLoaded, NULL);
   1365     if(eError != OMX_ErrorNone) {
   1366         APP_DPRINT ("%d :: Error from SendCommand-Idle State function\n",__LINE__);
   1367 				        printf("goto EXIT %d\n",__LINE__);
   1368 
   1369         goto EXIT;
   1370     }
   1371     eError = WaitForState(pHandle, OMX_StateLoaded);
   1372 #ifdef OMX_GETTIME
   1373 	GT_END("Call to SendCommand <OMX_StateLoaded>");
   1374 #endif
   1375     if(eError != OMX_ErrorNone) {
   1376         APP_DPRINT( "%d :: Error:  WaitForState reports an eError %X\n",__LINE__, error);
   1377 				        printf("goto EXIT %d\n",__LINE__);
   1378 
   1379         goto EXIT;
   1380     }
   1381 #endif
   1382 goto SHUTDOWN;
   1383                 }
   1384         }
   1385 /*-------*/
   1386 
   1387                 eError = OMX_GetState(pComponent, &state);
   1388                 if(eError != OMX_ErrorNone) {
   1389                         APP_DPRINT("%d :: OMX_GetState has returned status %X\n",__LINE__, eError);
   1390                         goto EXIT;
   1391                 }
   1392             }
   1393 else if (preempted) {
   1394     sched_yield();
   1395 }
   1396 else {
   1397     goto SHUTDOWN;
   1398 }
   1399 
   1400 } /* While Loop Ending Here */
   1401             FirstTime =1;
   1402             APP_DPRINT("%d :: App: The current state of the component = %d \n",__LINE__,state);
   1403             fclose(fOut);
   1404             fclose(fIn);
   1405 
   1406             APP_DPRINT("%d :: App: G726 Encoded = %d Frames \n",__LINE__,(nOutBuff));
   1407         } /*Test Case 4 & 5 Inner for loop ends here  */
   1408 
   1409         APP_DPRINT ("%d :: App: Sending the OMX_StateLoaded Command\n",__LINE__);
   1410 	#ifdef OMX_GETTIME
   1411 		GT_START();
   1412 	#endif
   1413         eError = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateLoaded, NULL);
   1414         if(eError != OMX_ErrorNone) {
   1415             APP_DPRINT("%d:: Error from SendCommand-Idle State function\n",__LINE__);
   1416             goto EXIT;
   1417         }
   1418 
   1419 #ifndef WAITFORRESOURCES
   1420         /* free the Allocate and Use Buffers */
   1421         APP_DPRINT("%d :: App: Freeing the Allocate OR Use Buffers in TestApp\n",__LINE__);
   1422         for(i=0; i < numInputBuffers; i++) {
   1423             APP_DPRINT("%d :: App: About to free pInputBufferHeader[%d]\n",__LINE__, i);
   1424             eError = OMX_FreeBuffer(pHandle, OMX_DirInput, pInputBufferHeader[i]);
   1425             if((eError != OMX_ErrorNone)) {
   1426                 APP_DPRINT("%d:: Error in FreeBuffer function\n",__LINE__);
   1427                 goto EXIT;
   1428             }
   1429         }
   1430         for(i=0; i < numOutputBuffers; i++) {
   1431             APP_DPRINT("%d :: App: About to free pOutputBufferHeader[%d]\n",__LINE__, i);
   1432             eError = OMX_FreeBuffer(pHandle, OMX_DirOutput, pOutputBufferHeader[i]);
   1433             if((eError != OMX_ErrorNone)) {
   1434                 APP_DPRINT("%d :: Error in Free Buffer function\n",__LINE__);
   1435                 goto EXIT;
   1436             }
   1437         }
   1438   #ifdef USE_BUFFER
   1439         /* free the App Allocated Buffers */
   1440         APP_DPRINT("%d :: App: Freeing the App Allocated Buffers in TestApp\n",__LINE__);
   1441         for(i=0; i < numInputBuffers; i++) {
   1442             APP_MEMPRINT("%d :: App: [TESTAPPFREE] pInputBuffer[%d] = %p\n",__LINE__,i,pInputBuffer[i]);
   1443             if(pInputBuffer[i] != NULL){
   1444                 SafeFree(pInputBuffer[i]);
   1445                 pInputBuffer[i] = NULL;
   1446             }
   1447         }
   1448 
   1449         for(i=0; i < numOutputBuffers; i++) {
   1450             pOutputBuffer[i] = pOutputBuffer[i] - 128;
   1451             APP_MEMPRINT("%d :: App: [TESTAPPFREE] pOutputBuffer[%d] = %p\n",__LINE__,i, pOutputBuffer[i]);
   1452             if(pOutputBuffer[i] != NULL){
   1453                 SafeFree(pOutputBuffer[i]);
   1454                 pOutputBuffer[i] = NULL;
   1455             }
   1456         }
   1457   #endif
   1458 #endif
   1459 
   1460   	eError = WaitForState(pHandle, OMX_StateLoaded);
   1461 	#ifdef OMX_GETTIME
   1462 		GT_END("Call to SendCommand <OMX_StateLoaded>, PortReset, clear buffers");
   1463 	#endif
   1464 		if(eError != OMX_ErrorNone) {
   1465 			APP_DPRINT( "Error:  G726Encoder->WaitForState reports an error %X\n", eError);
   1466 			goto EXIT;
   1467 		}
   1468 
   1469 #ifdef WAITFORRESOURCES
   1470     eError = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateWaitForResources, NULL);
   1471     if(eError != OMX_ErrorNone) {
   1472         APP_DPRINT ("%d :: Error from SendCommand-Idle State function\n",__LINE__);
   1473 				        printf("goto EXIT %d\n",__LINE__);
   1474 
   1475         goto EXIT;
   1476     }
   1477     eError = WaitForState(pHandle, OMX_StateWaitForResources);
   1478 
   1479     /* temporarily put this here until I figure out what should really happen here */
   1480     sleep(10);
   1481     /* temporarily put this here until I figure out what should really happen here */
   1482 #endif
   1483 
   1484         APP_DPRINT ("%d :: App: Sending the OMX_CommandPortDisable Command\n",__LINE__);
   1485         eError = OMX_SendCommand(pHandle, OMX_CommandPortDisable, -1, NULL);
   1486         if(eError != OMX_ErrorNone) {
   1487             APP_DPRINT("%d:: Error from SendCommand OMX_CommandPortDisable\n",__LINE__);
   1488             goto EXIT;
   1489         }
   1490 SHUTDOWN:
   1491 
   1492         if(audioinfo->dasfMode){
   1493             close(fdwrite);
   1494             close(fdread);
   1495             if (streaminfo != NULL){
   1496                SafeFree(streaminfo);
   1497             }
   1498         }
   1499 
   1500         APP_DPRINT("%d :: App: Free the Component handle\n",__LINE__);
   1501         /* Unload the G726 Encoder Component */
   1502         eError = TIOMX_FreeHandle(pHandle);
   1503         if((eError != OMX_ErrorNone)) {
   1504             APP_DPRINT("%d :: Error in Free Handle function\n",__LINE__);
   1505             goto EXIT;
   1506         }
   1507         APP_DPRINT("%d :: App: Free Handle returned Successfully\n",__LINE__);
   1508 
   1509         APP_DPRINT("%d :: App: Calling OMX_Deinit()\n",__LINE__);
   1510         eError = TIOMX_Deinit();
   1511         if(eError != OMX_ErrorNone) {
   1512             APP_DPRINT("%d :: Error returned by OMX_Deinit()\n",__LINE__);
   1513             goto EXIT;
   1514         }
   1515 
   1516         APP_DPRINT("%d :: App: Freeing the Memory Allocated in TestApp\n",__LINE__);
   1517 
   1518         APP_MEMPRINT("%d :: App: [TESTAPPFREE] %p\n",__LINE__,pG726Param);
   1519         if(pG726Param != NULL){
   1520             SafeFree(pG726Param);
   1521             pG726Param = NULL;
   1522         }
   1523         APP_MEMPRINT("%d :: App: [TESTAPPFREE] %p\n",__LINE__,pCompPrivateStruct);
   1524         if(pCompPrivateStruct != NULL){
   1525             SafeFree(pCompPrivateStruct);
   1526             pCompPrivateStruct = NULL;
   1527         }
   1528         APP_MEMPRINT("%d :: App: [TESTAPPFREE] %p\n",__LINE__,audioinfo);
   1529         if(audioinfo != NULL){
   1530             SafeFree(audioinfo);
   1531             audioinfo = NULL;
   1532         }
   1533 
   1534         APP_DPRINT("%d :: App: Closing the Input and Output Pipes\n",__LINE__);
   1535         eError = close (IpBuf_Pipe[0]);
   1536         if (0 != eError && OMX_ErrorNone == eError) {
   1537             eError = OMX_ErrorHardware;
   1538             APP_DPRINT("%d :: Error while closing IpBuf_Pipe[0]\n",__LINE__);
   1539             goto EXIT;
   1540         }
   1541         eError = close (IpBuf_Pipe[1]);
   1542         if (0 != eError && OMX_ErrorNone == eError) {
   1543             eError = OMX_ErrorHardware;
   1544             APP_DPRINT("%d :: Error while closing IpBuf_Pipe[1]\n",__LINE__);
   1545             goto EXIT;
   1546         }
   1547         eError = close (OpBuf_Pipe[0]);
   1548         if (0 != eError && OMX_ErrorNone == eError) {
   1549             eError = OMX_ErrorHardware;
   1550             APP_DPRINT("%d :: Error while closing OpBuf_Pipe[0]\n",__LINE__);
   1551             goto EXIT;
   1552         }
   1553         eError = close (OpBuf_Pipe[1]);
   1554         if (0 != eError && OMX_ErrorNone == eError) {
   1555             eError = OMX_ErrorHardware;
   1556             APP_DPRINT("%d :: Error while closing OpBuf_Pipe[1]\n",__LINE__);
   1557             goto EXIT;
   1558         }
   1559     } /*Outer for loop ends here */
   1560 
   1561     pthread_mutex_destroy(&WaitForState_mutex);
   1562     pthread_cond_destroy(&WaitForState_threshold);
   1563 
   1564     printf("%d :: *********************************************************************\n",__LINE__);
   1565     printf("%d :: NOTE: An output file %s has been created in file system\n",__LINE__,argv[2]);
   1566     printf("%d :: *********************************************************************\n",__LINE__);
   1567     if (testcnt == MAX_CYCLES) {
   1568         printf("%d :: *********************************************************************\n",__LINE__);
   1569         printf("%d :: NOTE: An output file TC5_G7261.G726 has been created in file system\n",__LINE__);
   1570         printf("%d :: *********************************************************************\n",__LINE__);
   1571     }
   1572     if (testcnt1 == MAX_CYCLES) {
   1573         printf("%d :: *********************************************************************\n",__LINE__);
   1574         printf("%d :: NOTE: An output file TC6_G7261.G726 has been created in file system\n",__LINE__);
   1575         printf("%d :: *********************************************************************\n",__LINE__);
   1576     }
   1577 EXIT:
   1578 #ifdef APP_DEBUGMEM
   1579     printf("\n__ Printing memory not deleted\n");
   1580     for(i=0;i<500;i++){
   1581         if (lines[i]!=0){
   1582              printf("__ %d Bytes allocated on [%p],   File:%s Line: %d\n",bytes[i],arr[i],file[i],lines[i]);
   1583              }
   1584     }
   1585 #endif
   1586 #ifdef OMX_GETTIME
   1587 	GT_END("G726Enc test <End>");
   1588 	OMX_ListDestroy(pListHead);
   1589 #endif
   1590     return eError;
   1591 }
   1592 
   1593 OMX_ERRORTYPE send_input_buffer(OMX_HANDLETYPE pHandle, OMX_BUFFERHEADERTYPE* pBuffer, FILE *fIn)
   1594 {
   1595 	OMX_ERRORTYPE error = OMX_ErrorNone;
   1596 	OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
   1597 
   1598 	if(FirstTime){
   1599 		if(mframe == TWO_FRAMES){
   1600 			nRead = fread(pBuffer->pBuffer, 1, G726ENC_INPUT_BUFFER_SIZE*2, fIn);
   1601 		}
   1602                 else if(mframe == HALF_FRAME){
   1603 			nRead = fread(NextBuffer, 1, G726ENC_INPUT_BUFFER_SIZE/2, fIn);
   1604 	        }
   1605 		else{
   1606 			nRead = fread(pBuffer->pBuffer, 1, G726ENC_INPUT_BUFFER_SIZE, fIn);
   1607 		}
   1608 		pBuffer->nFilledLen = nRead;
   1609 	}
   1610 	else{
   1611 		memcpy(pBuffer->pBuffer, NextBuffer,nRead);
   1612 		pBuffer->nFilledLen = nRead;
   1613 	}
   1614 
   1615 	if(mframe == TWO_FRAMES){
   1616 			nRead = fread(NextBuffer, 1, G726ENC_INPUT_BUFFER_SIZE*2, fIn);
   1617 	}
   1618         else if(mframe == HALF_FRAME){
   1619 			nRead = fread(NextBuffer, 1, G726ENC_INPUT_BUFFER_SIZE/2, fIn);
   1620 	}
   1621 	else{
   1622 			nRead = fread(NextBuffer, 1, G726ENC_INPUT_BUFFER_SIZE, fIn);
   1623 	}
   1624 
   1625 	if(nRead < G726ENC_INPUT_BUFFER_SIZE && !DasfMode && (mframe != HALF_FRAME)){
   1626 		pBuffer->nFlags = OMX_BUFFERFLAG_EOS;
   1627 	}else{
   1628           pBuffer->nFlags = 0;
   1629           }
   1630 
   1631         if( ((mframe != HALF_FRAME) && (pBuffer->nFilledLen>= G726ENC_INPUT_BUFFER_SIZE)) ||
   1632               ((mframe == HALF_FRAME) && (pBuffer->nFilledLen> 0))){
   1633 
   1634         if(pBuffer->nFlags == OMX_BUFFERFLAG_EOS){
   1635                            APP_DPRINT("Sending Last Input Buffer from App\n");
   1636         }
   1637         vez++;
   1638         APP_DPRINT("Sending %d bytes to Comp, Time: %ld\n", (int)pBuffer->nFilledLen,vez);
   1639         pBuffer->nTimeStamp = rand() % 100;
   1640         if (!preempted) {
   1641              error = OMX_EmptyThisBuffer(pComponent, pBuffer);
   1642              if (error == OMX_ErrorIncorrectStateOperation)
   1643                  error = 0;
   1644         }
   1645     }
   1646    	FirstTime=0;
   1647 	return error;
   1648 }
   1649 
   1650 OMX_ERRORTYPE StopComponent(OMX_HANDLETYPE *pHandle)
   1651 {
   1652     OMX_ERRORTYPE error = OMX_ErrorNone;
   1653 #ifdef OMX_GETTIME
   1654 	GT_START();
   1655 #endif
   1656     error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);
   1657 	if(error != OMX_ErrorNone) {
   1658                     fprintf (stderr,"\nError from SendCommand-Idle(Stop) State function!!!!!!!!\n");
   1659                     goto EXIT;
   1660 		}
   1661 	error =	WaitForState(pHandle, OMX_StateIdle);
   1662 #ifdef OMX_GETTIME
   1663 	GT_END("Call to SendCommand <OMX_StateIdle>");
   1664 #endif
   1665     if(error != OMX_ErrorNone) {
   1666 					fprintf(stderr, "\nError:  G726Encoder->WaitForState reports an error %X!!!!!!!\n", error);
   1667 					goto EXIT;
   1668 	}
   1669 EXIT:
   1670     return error;
   1671 }
   1672 
   1673 OMX_ERRORTYPE PauseComponent(OMX_HANDLETYPE *pHandle)
   1674 {
   1675     OMX_ERRORTYPE error = OMX_ErrorNone;
   1676 #ifdef OMX_GETTIME
   1677 	GT_START();
   1678 #endif
   1679     error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StatePause, NULL);
   1680 	if(error != OMX_ErrorNone) {
   1681                     fprintf (stderr,"\nError from SendCommand-Idle(Stop) State function!!!!!!!!\n");
   1682                     goto EXIT;
   1683 		}
   1684 	error =	WaitForState(pHandle, OMX_StatePause);
   1685 #ifdef OMX_GETTIME
   1686 	GT_END("Call to SendCommand <OMX_StatePause>");
   1687 #endif
   1688     if(error != OMX_ErrorNone) {
   1689 					fprintf(stderr, "\nError:  G726Encoder->WaitForState reports an error %X!!!!!!!\n", error);
   1690 					goto EXIT;
   1691 	}
   1692 EXIT:
   1693     return error;
   1694 }
   1695 
   1696 OMX_ERRORTYPE PlayComponent(OMX_HANDLETYPE *pHandle)
   1697 {
   1698     OMX_ERRORTYPE error = OMX_ErrorNone;
   1699 #ifdef OMX_GETTIME
   1700 	GT_START();
   1701 #endif
   1702     error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateExecuting, NULL);
   1703 	if(error != OMX_ErrorNone) {
   1704                     fprintf (stderr,"\nError from SendCommand-Idle(Stop) State function!!!!!!!!\n");
   1705                     goto EXIT;
   1706 		}
   1707 	error =	WaitForState(pHandle, OMX_StateExecuting);
   1708 #ifdef OMX_GETTIME
   1709 	GT_END("Call to SendCommand <OMX_StateExecuting>");
   1710 #endif
   1711     if(error != OMX_ErrorNone) {
   1712 					fprintf(stderr, "\nError:  G726Encoder->WaitForState reports an error %X!!!!!!!\n", error);
   1713 					goto EXIT;
   1714 	}
   1715 EXIT:
   1716     return error;
   1717 
   1718 }
   1719