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 G722EncTest.c 26 * 27 * This File contains the G722 ENCODER OMX tests 28 * 29 * @path $(OMAPSW_MPU)\linux\audio\src\openmax_il\g722_enc\tests 30 * 31 * @rev 0.1 32 */ 33/* ----------------------------------------------------------------------------- 34 *! 35 *! Revision History 36 *! =================================== 37 *! Date Author(s) Version Description 38 *! --------- ------------------- ------- --------------------------------- 39 *! 08-Mar-2007 A.Donjon 0.1 Code update for G722 ENCODER 40 *! 21-Mar-2007 A.Donjon 0.2 Test fwk change for pause and stop cmd 41 *! 42 *! 43 * ================================================================================= */ 44/*define OMX_GETTIME*/ 45 46#undef WAITFORRESOURCES 47 48 49#include <unistd.h> 50#include <stdlib.h> 51#include <sys/ioctl.h> 52#include <sys/select.h> 53#include <string.h> 54#include <stdio.h> 55#include <fcntl.h> 56#include <errno.h> 57#include <linux/vt.h> 58#include <signal.h> 59#include <sys/stat.h> 60#include <pthread.h> 61#include <stdio.h> 62#include <linux/soundcard.h> 63 64#include <OMX_Index.h> 65#include <OMX_Types.h> 66#include <OMX_Core.h> 67#include <OMX_Audio.h> 68#include <TIDspOmx.h> 69#include <OMX_Component.h> 70 71 72#ifdef OMX_GETTIME 73#include <OMX_Common_Utils.h> 74#include <OMX_GetTime.h> /*Headers for Performance & measuremet */ 75#endif 76 77FILE *fpRes = NULL; 78FILE *outputDebugFile = NULL; 79FILE *fOut= NULL, *fIn = NULL; 80#undef APP_DEBUG 81#undef APP_MEMCHECK 82 83#define USE_BUFFER 84 85#ifdef APP_DEBUG 86#define APP_DPRINT(...) fprintf(stderr,__VA_ARGS__) 87#else 88#define APP_DPRINT(...) 89#endif 90 91#ifdef APP_MEMCHECK 92#define APP_MEMPRINT(...) fprintf(stderr,__VA_ARGS__) 93#else 94#define APP_MEMPRINT(...) 95#endif 96 97#define G722ENC_NUM_INPUT_BUFFERS 1 /*Component default number of input buffers*/ 98#define G722ENC_NUM_OUTPUT_BUFFERS 1 /*Component default number of output buffers*/ 99#define G722ENC_MIN_INPUT_BUFFER_SIZE 16 /*G722ENC minimum input buffer size in bytes*/ 100#define G722ENC_MAX_INPUT_BUFFER_SIZE 320 /*G722ENC maximum input buffer size in bytes*/ 101#define G722ENC_MIN_OUTPUT_BUFFER_SIZE 4 /*G722ENC minimum output buffer size in bytes*/ 102#define G722ENC_MAX_OUTPUT_BUFFER_SIZE 80 /*G722ENC maximum output buffer size in bytes*/ 103#define SAMPLING_RATE 16000 104#define SAMPLE_SIZE 16 105#define G722ENC_CACHE_ALIGN_MALLOC 256 106#define G722ENC_CACHE_ALIGN_OFFSET 128 107#define strG722Encoder "OMX.TI.G722.encode" 108#define FIFO1 "/dev/fifo.1" 109#define FIFO2 "/dev/fifo.2" 110 111#ifdef OMX_GETTIME 112OMX_ERRORTYPE eError = OMX_ErrorNone; 113int GT_FlagE = 0; /* Fill Buffer 1 = First Buffer, 0 = Not First Buffer */ 114int GT_FlagF = 0; /*Empty Buffer 1 = First Buffer, 0 = Not First Buffer */ 115static OMX_NODE* pListHead = NULL; 116int Gt_k = 0 ; 117#endif 118 119int maxint(int a, int b); 120 121int fill_data (OMX_BUFFERHEADERTYPE *pBuf, FILE *fIn); 122 123 124int IpBuf_Pipe[2] = {0}; 125int OpBuf_Pipe[2] = {0}; 126int Event_Pipe[2] = {0}; 127int lastbuffer=0; 128int nbInCbPending=0; 129 130OMX_ERRORTYPE send_input_buffer (OMX_HANDLETYPE pHandle, OMX_BUFFERHEADERTYPE* pBuffer, FILE *fIn); 131 132fd_set rfds; 133int done = 0; 134int whileloopdone = 0; 135 136int preempted = 0; 137 138 139/* safe routine to get the maximum of 2 integers */ 140int maxint(int a, int b) 141{ 142 return (a>b) ? a : b; 143} 144 145/* This method will wait for the component to get to the state 146 * specified by the DesiredState input. */ 147static OMX_ERRORTYPE WaitForState(OMX_HANDLETYPE* pHandle, 148 OMX_STATETYPE DesiredState) 149{ 150 OMX_STATETYPE CurState = OMX_StateInvalid; 151 OMX_ERRORTYPE eError = OMX_ErrorNone; 152 int nCnt = 0; 153 /*OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;*/ 154 155 eError = OMX_GetState(pHandle, &CurState); 156 while( (eError == OMX_ErrorNone) && (CurState != DesiredState) ) { 157 sched_yield(); 158 if(nCnt++ == 10) { 159 APP_DPRINT( "Still Waiting, press CTL-C to continue\n"); 160 } 161 162 eError = OMX_GetState(pHandle, &CurState); 163 } 164 165 if( eError != OMX_ErrorNone ) return eError; 166 return OMX_ErrorNone; 167} 168 169 170/* ================================================================================= */ 171/** 172 * @fn EventHandler() description for SendCommand 173 EventHandler(). 174 App event handler 175 * 176 * @see OMX_Core.h 177 */ 178/* ================================================================================ */ 179OMX_ERRORTYPE EventHandler(OMX_HANDLETYPE hComponent,OMX_PTR pAppData,OMX_EVENTTYPE eEvent, 180 OMX_U32 nData1, OMX_U32 nData2, OMX_PTR pEventData) 181{ 182 OMX_ERRORTYPE error = OMX_ErrorNone; 183 OMX_U8 writeValue = 0; 184 185 switch (eEvent) 186 { 187 case OMX_EventCmdComplete: 188 /* State change notification. Do Nothing */ 189 break; 190 case OMX_EventError: 191 /* Error notification */ 192 if(nData1==OMX_ErrorOverflow){ 193 printf("EventHandler: Overflow Error\n"); 194#ifdef OMX_GETTIME 195 GT_START(); 196#endif 197 error = OMX_SendCommand(hComponent,OMX_CommandStateSet, OMX_StateIdle, NULL); 198 if(error != OMX_ErrorNone){ 199 APP_DPRINT ("%d :: Error from SendCommand-Idle(Stop) State function\n",__LINE__); 200 } 201 done = 1; 202 error = WaitForState(hComponent, OMX_StateIdle); 203#ifdef OMX_GETTIME 204 GT_END("Call to SendCommand <OMX_StateIdle>"); 205#endif 206 if(error != OMX_ErrorNone) { 207 APP_DPRINT( "Error: G722Encoder->WaitForState reports an error %X\n", error); 208 goto EXIT; 209 } 210 }else if(nData1 == OMX_ErrorResourcesPreempted) { 211 writeValue = 0; 212 preempted = 1; 213 write(Event_Pipe[1], &writeValue, sizeof(OMX_U8)); 214 } 215 break; 216 case OMX_EventMax: 217 case OMX_EventMark: 218 case OMX_EventPortSettingsChanged: 219 case OMX_EventComponentResumed: 220 case OMX_EventDynamicResourcesAvailable: 221 case OMX_EventPortFormatDetected: 222 case OMX_EventBufferFlag: 223 writeValue = 2; 224 write(Event_Pipe[1], &writeValue, sizeof(OMX_U8)); 225 226 case OMX_EventResourcesAcquired: 227 writeValue = 1; 228 preempted = 0; 229 write(Event_Pipe[1], &writeValue, sizeof(OMX_U8)); 230 231 break; 232 } /* end of switch */ 233 EXIT: 234 return OMX_ErrorNone; 235} 236 237 238/* ================================================================================= */ 239/** 240 * @fn FillBufferDone() description for FillBufferDone 241 FillBufferDone(). 242 Called by the component when an output buffer has been filled 243 * 244 * @see OMX_Core.h 245 */ 246/* ================================================================================ */ 247void FillBufferDone (OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer) 248{ 249 write(OpBuf_Pipe[1], &pBuffer, sizeof(pBuffer)); 250#ifdef OMX_GETTIME 251 if (GT_FlagF == 1 ) /* First Buffer Reply*/ /* 1 = First Buffer, 0 = Not First Buffer */ 252 { 253 GT_END("Call to FillBufferDone <First: FillBufferDone>"); 254 GT_FlagF = 0 ; /* 1 = First Buffer, 0 = Not First Buffer */ 255 } 256#endif 257} 258 259 260/* ================================================================================= */ 261/** 262 * @fn EmptyBufferDone() description for EmptyBufferDone 263 EmptyBufferDone(). 264 Called by the component when an input buffer has been emptied 265 * 266 * @see OMX_Core.h 267 */ 268/* ================================================================================ */ 269void EmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer) 270{ 271 if (!preempted) 272 write(IpBuf_Pipe[1], &pBuffer, sizeof(pBuffer)); 273#ifdef OMX_GETTIME 274 if (GT_FlagE == 1 ) /* First Buffer Reply*/ /* 1 = First Buffer, 0 = Not First Buffer */ 275 { 276 GT_END("Call to EmptyBufferDone <First: EmptyBufferDone>"); 277 GT_FlagE = 0; /* 1 = First Buffer, 0 = Not First Buffer */ 278 } 279#endif 280} 281 282/* ================================================================================= */ 283/** 284 * @fn main() description for main 285 main(). 286 Test app main function 287 * 288 * @see OMX_Core.h 289 */ 290/* ================================================================================ */ 291int main(int argc, char* argv[]) 292{ 293 OMX_CALLBACKTYPE PcmCaBa = {(void *)EventHandler, 294 (void*)EmptyBufferDone, 295 (void*)FillBufferDone}; 296 OMX_HANDLETYPE pHandle = NULL; 297 OMX_ERRORTYPE error = OMX_ErrorNone; 298 OMX_U32 AppData = 100; 299 OMX_PARAM_PORTDEFINITIONTYPE* pCompPrivateStruct = NULL; 300 OMX_AUDIO_PARAM_ADPCMTYPE *pG722Param = NULL; 301 OMX_COMPONENTTYPE *pComponent = NULL; 302 OMX_AUDIO_CONFIG_VOLUMETYPE* pCompPrivateStructGain = NULL; 303 /*OMX_STATETYPE state;*/ 304 OMX_BUFFERHEADERTYPE* pInputBufferHeader = NULL; 305 OMX_BUFFERHEADERTYPE* pOutputBufferHeader = NULL; 306 TI_OMX_DATAPATH dataPath; 307 308#ifdef USE_BUFFER 309 OMX_U8* pInputBuffer = NULL; 310 OMX_U8* pOutputBuffer = NULL; 311#endif 312 TI_OMX_DSP_DEFINITION *pAppPrivate = NULL; 313 int inBufSize = 0; 314 int outBufSize = 0; 315 OMX_S16 numOutputBuffers = 0; 316 OMX_S16 numInputBuffers = 0; 317 TI_OMX_STREAM_INFO *streaminfo = NULL; 318 OMX_INDEXTYPE index = 0; 319 OMX_STATETYPE testAppState = OMX_StateInvalid; 320 321 struct timeval tv; 322 int retval = 0, i = 0, j = 0; 323 int frmCount = 0; 324 int frmCount1 = 0; 325 int frmCnt = 1; 326 int testcnt = 1; 327 int testcnt1 = 1; 328 int nbDASFframes = 0; 329 int fdmax = 0; 330 int testCaseNo = 0; 331#ifdef DSP_RENDERING_ON 332 int g722encfdwrite = 0; 333 int g722encfdread = 0; 334#endif 335 336 streaminfo = malloc(sizeof(TI_OMX_STREAM_INFO)); 337 pAppPrivate = malloc(sizeof(TI_OMX_DSP_DEFINITION)); 338 339 APP_DPRINT("------------------------------------------------------\n"); 340 APP_DPRINT("This is Main Thread In G722 ENCODER Test Application:\n"); 341 APP_DPRINT("Test Core 1.5 - " __DATE__ ":" __TIME__ "\n"); 342 APP_DPRINT("------------------------------------------------------\n"); 343#ifdef OMX_GETTIME 344 printf("Line %d\n",__LINE__); 345 GTeError = OMX_ListCreate(&pListHead); 346 printf("Line %d\n",__LINE__); 347 printf("eError = %d\n",GTeError); 348 GT_START(); 349 printf("Line %d\n",__LINE__); 350#endif 351#ifdef DSP_RENDERING_ON 352 if((g722encfdwrite=open(FIFO1,O_WRONLY))<0) { 353 APP_DPRINT("[G722TEST] - failure to open WRITE pipe\n"); 354 } 355 else { 356 APP_DPRINT("[G722TEST] - opened WRITE pipe\n"); 357 } 358 359 if((g722encfdread=open(FIFO2,O_RDONLY))<0) { 360 APP_DPRINT("[G722TEST] - failure to open READ pipe\n"); 361 goto EXIT; 362 } 363 else { 364 APP_DPRINT("[G722TEST] - opened READ pipe\n"); 365 } 366#endif 367 368 APP_DPRINT("File = %s, Function = %s, Line = %d\n",__FILE__,__FUNCTION__,__LINE__); 369 if((argc != 11)) { 370 printf(" =========================================== \n"); 371 printf("Usage: TestApp inFile outFile TestCaseNo nbInSamp nbOutSamp opMode nbInBuf nbOutBuf DASF nbFramesToEncode\n"); 372 printf("Example: G722EncTest speeche.pcm output.bit 1 160 40 0 1 1 1 1000\n"); 373 printf("opMode: 0=64kps 1=56kbps 2=48kbps\n"); 374 printf("DASF mode: 1=DASF 0=file-to-file mode\n"); 375 printf("nbFramesToEncode: number of frames to encode in DASF mode\n"); 376 goto EXIT; 377 } 378 379 /* check to see that the input file exists */ 380 struct stat sb = {0}; 381 int status = stat(argv[1], &sb); 382 if( status != 0 ) { 383 APP_DPRINT( "Cannot find file %s. (%u)\n", argv[1], errno); 384 goto EXIT; 385 } 386 387 error = TIOMX_Init(); 388 if(error != OMX_ErrorNone) { 389 APP_DPRINT("%d :: Error returned by TIOMX_Init()\n",__LINE__); 390 goto EXIT; 391 } 392 393 inBufSize = atoi(argv[4])<<1; 394 outBufSize = atoi(argv[5])<<1; 395 396 numInputBuffers = atoi(argv[7]); 397 numOutputBuffers = atoi(argv[8]); 398 399 nbDASFframes = atoi(argv[10]); 400 if (atoi(argv[3]) > 0 && atoi(argv[3]) < 7) { 401 switch (atoi(argv[3])) { 402 case 1: 403 printf ("--------------------------------------------------\n"); 404 printf ("Testing Simple RECORD till EOF or predefined frame number\n"); 405 printf ("--------------------------------------------------\n"); 406 break; 407 case 2: 408 printf ("--------------------------------------------------\n"); 409 printf ("Testing RECORD and STOP at predefined frame number\n"); 410 printf ("--------------------------------------------------\n"); 411 testCaseNo = 2; 412 break; 413 case 3: 414 printf ("--------------------------------------------------\n"); 415 printf ("Testing PAUSE & RESUME Command \n"); 416 printf ("--------------------------------------------------\n"); 417 testCaseNo = 3; 418 break; 419 case 4: 420 printf ("--------------------------------------------------\n"); 421 printf ("Testing Repeated RECORD without Deleting Component\n"); 422 printf ("--------------------------------------------------\n"); 423 testcnt = 15; 424 break; 425 case 5: 426 printf ("--------------------------------------------------\n"); 427 printf ("Testing Repeated RECORD with Deleting Component \n"); 428 printf ("--------------------------------------------------\n"); 429 testcnt1 = 15; 430 break; 431 case 6: 432 printf ("--------------------------------------------------\n"); 433 printf ("Testing Set Volume for record stream \n"); 434 printf ("--------------------------------------------------\n"); 435 break; 436 } 437 } 438 else { 439 printf("Bad parameter for test case\n"); 440 goto EXIT; 441 } 442 443 for(j = 0; j < testcnt1; j++) { 444 whileloopdone = 0; 445 /* Create the handle of the G722 Encoder Component */ 446 /*pHandle = malloc(sizeof(OMX_HANDLETYPE));*/ 447 APP_MEMPRINT("%d:::[TESTAPPALLOC] %p\n",__LINE__,pHandle); 448#ifdef OMX_GETTIME 449 GT_START(); 450 error = TIOMX_GetHandle(&pHandle, strG722Encoder, &AppData, &PcmCaBa); 451 GT_END("Call to GetHandle"); 452#else 453 error = TIOMX_GetHandle(&pHandle, strG722Encoder, &AppData, &PcmCaBa); 454#endif 455 if((error != OMX_ErrorNone) || (pHandle == NULL)) { 456 APP_DPRINT ("Error in Get Handle function\n"); 457 goto EXIT; 458 } 459 460 /* Create a pipe used to queue data from the callback. */ 461 retval = pipe(IpBuf_Pipe); 462 if( retval != 0) { 463 APP_DPRINT( "Error:Fill Data Pipe failed to open\n"); 464 goto EXIT; 465 } 466 retval = pipe(OpBuf_Pipe); 467 if( retval != 0) { 468 APP_DPRINT( "Error:Empty Data Pipe failed to open\n"); 469 goto EXIT; 470 } 471 retval = pipe(Event_Pipe); 472 if( retval != 0) { 473 APP_DPRINT( "Error:Empty Data Pipe failed to open\n"); 474 goto EXIT; 475 } 476 477 /* save off the "max" of the handles for the selct statement */ 478 fdmax = maxint(IpBuf_Pipe[0], OpBuf_Pipe[0]); 479 fdmax = maxint(fdmax,Event_Pipe[0]); 480 481 if (atoi(argv[3]) == 5){ 482 printf ("%d :: Encoding the file [%d] Time\n",__LINE__, j+1); 483 } 484 485 486 if (atoi(argv[9]) == 0 || atoi(argv[9]) == 1) { 487 pAppPrivate->dasfMode = atoi(argv[9]); 488 } 489 else { 490 printf("Bad value for DASF mode\n"); 491 goto EXIT; 492 } 493 /* add to config TeeDN */ 494 pAppPrivate->teeMode = 0; 495 pCompPrivateStruct = malloc (sizeof (OMX_PARAM_PORTDEFINITIONTYPE)); 496 APP_MEMPRINT("%d:::[TESTAPPALLOC] %p\n",__LINE__,pCompPrivateStruct); 497 pCompPrivateStruct->nSize = sizeof (OMX_PARAM_PORTDEFINITIONTYPE); 498 pCompPrivateStruct->nVersion.s.nVersionMajor = 1; 499 pCompPrivateStruct->nVersion.s.nVersionMinor = 1; 500 pCompPrivateStruct->nPortIndex = OMX_DirInput; 501 OMX_GetParameter (pHandle,OMX_IndexParamPortDefinition,pCompPrivateStruct); 502 503 /* Send input port config */ 504 pCompPrivateStruct->eDir = OMX_DirInput; 505 pCompPrivateStruct->bEnabled = OMX_TRUE; 506 pCompPrivateStruct->nBufferCountMin = G722ENC_NUM_INPUT_BUFFERS; 507 pCompPrivateStruct->nBufferSize = inBufSize; 508 pCompPrivateStruct->format.audio.eEncoding = OMX_AUDIO_CodingADPCM; 509 pCompPrivateStruct->nPortIndex = 0x0; 510 pCompPrivateStruct->nBufferCountActual = G722ENC_NUM_INPUT_BUFFERS; 511 pCompPrivateStruct->bEnabled = OMX_TRUE; 512#ifdef OMX_GETTIME 513 GT_START(); 514 error = OMX_SetParameter (pHandle,OMX_IndexParamPortDefinition, pCompPrivateStruct); 515 GT_END("Set Parameter Test-SetParameter"); 516#else 517 error = OMX_SetParameter (pHandle,OMX_IndexParamPortDefinition, pCompPrivateStruct); 518#endif 519 if (error != OMX_ErrorNone) { 520 error = OMX_ErrorBadParameter; 521 APP_DPRINT ("%d :: OMX_ErrorBadParameter\n",__LINE__); 522 goto EXIT; 523 } 524 525 /* Send output port config */ 526 pCompPrivateStruct->nPortIndex = OMX_DirOutput; 527 pCompPrivateStruct->eDir = OMX_DirOutput; 528 pCompPrivateStruct->bEnabled = OMX_TRUE; 529 pCompPrivateStruct->nBufferCountMin = G722ENC_NUM_OUTPUT_BUFFERS; 530 pCompPrivateStruct->nPortIndex = 0x1; 531 pCompPrivateStruct->nBufferCountActual = G722ENC_NUM_OUTPUT_BUFFERS; 532 pCompPrivateStruct->bEnabled = OMX_TRUE; 533 pCompPrivateStruct->nBufferSize = outBufSize; 534#ifdef OMX_GETTIME 535 GT_START(); 536 error = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct); 537 GT_END("Set Parameter Test-SetParameter"); 538#else 539 error = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct); 540#endif 541 if (error != OMX_ErrorNone) { 542 error = OMX_ErrorBadParameter; 543 APP_DPRINT ("%d :: OMX_ErrorBadParameter\n",__LINE__); 544 goto EXIT; 545 } 546 547 pG722Param = malloc (sizeof (OMX_AUDIO_PARAM_ADPCMTYPE)); 548 APP_MEMPRINT("%d:::[TESTAPPALLOC] %p\n",__LINE__,pG722Param); 549 pG722Param->nSize = sizeof (OMX_AUDIO_PARAM_ADPCMTYPE); 550 pG722Param->nVersion.s.nVersionMajor = 1; 551 pG722Param->nVersion.s.nVersionMinor = 1; 552 pG722Param->nPortIndex = OMX_DirOutput; 553 pG722Param->nChannels = 1; 554 /* Codec rate selection */ 555 pG722Param->nSampleRate = atoi(argv[6]); 556 if((atoi(argv[6])<0)||(atoi(argv[6])>2)){ 557 printf("Error in input arguments\n"); 558 printf("opMode: 0=64kps 1=56kbps 2=48kbps\n"); 559 printf("opMode set to 64kbps\n"); 560 pG722Param->nSampleRate = 0; 561 } 562 pG722Param->nBitsPerSample = SAMPLE_SIZE; 563#ifdef OMX_GETTIME 564 GT_START(); 565 error = OMX_SetParameter (pHandle, OMX_IndexParamAudioAdpcm, pG722Param); 566 GT_END("Set Parameter Test-SetParameter"); 567#else 568 error = OMX_SetParameter (pHandle, OMX_IndexParamAudioAdpcm, pG722Param); 569#endif 570 if (error != OMX_ErrorNone) { 571 error = OMX_ErrorBadParameter; 572 APP_DPRINT ("%d :: OMX_ErrorBadParameter\n",__LINE__); 573 goto EXIT; 574 } 575 576 pG722Param->nPortIndex = OMX_DirInput; 577 pG722Param->nSampleRate = SAMPLING_RATE; 578#ifdef OMX_GETTIME 579 GT_START(); 580 error = OMX_SetParameter (pHandle, OMX_IndexParamAudioAdpcm, pG722Param); 581 GT_END("Set Parameter Test-SetParameter"); 582#else 583 error = OMX_SetParameter (pHandle, OMX_IndexParamAudioAdpcm, pG722Param); 584#endif 585 if (error != OMX_ErrorNone) { 586 error = OMX_ErrorBadParameter; 587 APP_DPRINT ("%d :: OMX_ErrorBadParameter\n",__LINE__); 588 goto EXIT; 589 } 590 591 /* setting for stream gain */ 592 pCompPrivateStructGain = malloc (sizeof(OMX_AUDIO_CONFIG_VOLUMETYPE)); 593 if(pCompPrivateStructGain == NULL) 594 { 595 APP_DPRINT("%d :: App: Malloc Failed\n",__LINE__); 596 goto EXIT; 597 } 598 /* default setting for gain */ 599 pCompPrivateStructGain->nSize = sizeof(OMX_AUDIO_CONFIG_VOLUMETYPE); 600 pCompPrivateStructGain->nVersion.s.nVersionMajor = 0xF1; 601 pCompPrivateStructGain->nVersion.s.nVersionMinor = 0xF2; 602 pCompPrivateStructGain->nPortIndex = OMX_DirOutput; 603 pCompPrivateStructGain->bLinear = OMX_FALSE; 604 pCompPrivateStructGain->sVolume.nValue = 50; /* actual volume */ 605 pCompPrivateStructGain->sVolume.nMin = 0; /* min volume */ 606 pCompPrivateStructGain->sVolume.nMax = 100; /* max volume */ 607 608 error = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.g722headerinfo",&index); 609 if (error != OMX_ErrorNone) { 610 printf("Error getting extension index\n"); 611 goto EXIT; 612 } 613 OMX_SetConfig(pHandle, index, pAppPrivate); 614 615#ifndef USE_BUFFER 616 /* allocate input buffer */ 617 error = OMX_AllocateBuffer(pHandle,&pInputBufferHeader,0,NULL,inBufSize); 618 if(error != OMX_ErrorNone) { 619 APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer()\n",__LINE__); 620 goto EXIT; 621 } 622 /* allocate output buffer */ 623 error = OMX_AllocateBuffer(pHandle,&pOutputBufferHeader,1,NULL,outBufSize); 624 if(error != OMX_ErrorNone) { 625 APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer()\n",__LINE__); 626 goto EXIT; 627 } 628#else 629 630 pInputBuffer = (OMX_U8*)malloc(inBufSize+G722ENC_CACHE_ALIGN_MALLOC); 631 pInputBuffer = pInputBuffer+G722ENC_CACHE_ALIGN_OFFSET; 632 APP_MEMPRINT("%d:::[TESTAPPALLOC] %p\n",__LINE__,pInputBuffer); 633 /* allocate input buffer */ 634 error = OMX_UseBuffer(pHandle,&pInputBufferHeader,0,NULL,inBufSize,pInputBuffer); 635 if(error != OMX_ErrorNone) { 636 APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n",__LINE__); 637 goto EXIT; 638 } 639 pOutputBuffer= (OMX_U8*)malloc (outBufSize+G722ENC_CACHE_ALIGN_MALLOC); 640 pOutputBuffer = pOutputBuffer+G722ENC_CACHE_ALIGN_OFFSET; 641 APP_MEMPRINT("%d:::[TESTAPPALLOC] %p\n",__LINE__,pOutputBuffer); 642 /* allocate output buffer */ 643 error = OMX_UseBuffer(pHandle,&pOutputBufferHeader,1,NULL,outBufSize,pOutputBuffer); 644 if(error != OMX_ErrorNone) { 645 APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n",__LINE__); 646 goto EXIT; 647 } 648 649#endif 650 /* get streamID back to application */ 651 error = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.g722streamIDinfo",&index); 652 if (error != OMX_ErrorNone) { 653 printf("Error getting extension index\n"); 654 goto EXIT; 655 } 656 657 error = OMX_GetConfig (pHandle, index, streaminfo); 658 if(error != OMX_ErrorNone) { 659 error = OMX_ErrorBadParameter; 660 APP_DPRINT("%d :: G722EncTest.c :: Error from OMX_GetConfig() function\n",__LINE__); 661 goto EXIT; 662 } 663 664#ifdef DSP_RENDERING_ON 665 if((write(g722encfdwrite, &cmd_data, sizeof(cmd_data)))<0) { 666 } 667 if((read(g722encfdread, &cmd_data, sizeof(cmd_data)))<0) { 668 goto EXIT; 669 } 670#endif 671 672 error = OMX_SetConfig (pHandle, index, pAppPrivate); 673 if(error != OMX_ErrorNone) { 674 error = OMX_ErrorBadParameter; 675 APP_DPRINT("%d :: Error from OMX_SetConfig() function\n",__LINE__); 676 goto EXIT; 677 } 678 679 if (pAppPrivate->dasfMode) { 680#ifdef RTM_PATH 681 dataPath = DATAPATH_APPLICATION_RTMIXER; 682#endif 683 684#ifdef ETEEDN_PATH 685 dataPath = DATAPATH_APPLICATION; 686#endif 687 } 688 689 error = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.g722.datapath",&index); 690 if (error != OMX_ErrorNone) { 691 printf("Error getting extension index\n"); 692 goto EXIT; 693 } 694 error = OMX_SetConfig (pHandle, index, &dataPath); 695 if(error != OMX_ErrorNone) { 696 error = OMX_ErrorBadParameter; 697 goto EXIT; 698 } 699#ifdef OMX_GETTIME 700 GT_START(); 701#endif 702 error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL); 703 if(error != OMX_ErrorNone) { 704 APP_DPRINT ("Error from SendCommand-Idle(Init) State function - error = %d\n",error); 705 goto EXIT; 706 } 707 /* Wait for startup to complete */ 708 error = WaitForState(pHandle, OMX_StateIdle); 709#ifdef OMX_GETTIME 710 GT_END("Call to SendCommand <OMX_StateIdle>"); 711#endif 712 if(error != OMX_ErrorNone) { 713 APP_DPRINT( "Error: G722Encoder->WaitForState reports an error %X\n", error); 714 goto EXIT; 715 } 716#ifdef OMX_GETTIME 717 Gt_k = 0 ; 718#endif 719 for(i = 0; i < testcnt; i++) { 720 whileloopdone = 0; 721 frmCount1 = 0; 722 frmCount = 0; 723 nbInCbPending = 0; 724 725 fIn = fopen(argv[1], "r"); 726 if(fIn == NULL) { 727 fprintf(stderr, "Error: failed to open the file %s for readonly access\n", argv[1]); 728 goto EXIT; 729 } 730 731 fOut = fopen(argv[2], "w"); 732 if(fOut == NULL) { 733 fprintf(stderr, "Error: failed to create the output file \n"); 734 goto EXIT; 735 } 736 737 if(atoi(argv[3]) == 4) { 738 printf ("%d :: Encoding the file [%d] Time\n",__LINE__, i+1); 739 } 740 741 done = 0; 742 743 APP_DPRINT ("%d :: Sending OMX_StateExecuting Command\n",__LINE__); 744#ifdef OMX_GETTIME 745 GT_START(); 746#endif 747 error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateExecuting, NULL); 748 if(error != OMX_ErrorNone) { 749 APP_DPRINT ("Error from SendCommand-Executing State function\n"); 750 goto EXIT; 751 } 752 pComponent = (OMX_COMPONENTTYPE *)(pHandle); 753 error = WaitForState(pHandle, OMX_StateExecuting); 754#ifdef OMX_GETTIME 755 GT_END("Call to SendCommand <OMX_StateExecuting>"); 756#endif 757 if(error != OMX_ErrorNone) { 758 APP_DPRINT( "Error: hAmrEncoder->WaitForState reports an error %X\n", error); 759 goto EXIT; 760 } 761 762#ifdef OMX_GETTIME 763 if (Gt_k==0) 764 { 765 GT_FlagE=1; /* 1 = First Buffer, 0 = Not First Buffer */ 766 GT_START(); /* Fill Buffer */ 767 } 768#endif 769 if (pAppPrivate->dasfMode == 0) { 770 send_input_buffer(pHandle, pInputBufferHeader, fIn); 771 } 772#ifdef OMX_GETTIME 773 if (Gt_k==0) 774 { 775 GT_FlagF=1; /* 1 = First Buffer, 0 = Not First Buffer */ 776 GT_START(); /* Fill Buffer */ 777 } 778#endif 779 OMX_FillThisBuffer(pComponent,pOutputBufferHeader); 780 OMX_GetState (pHandle, &testAppState); 781#ifdef OMX_GETTIME 782 Gt_k=1; 783#endif 784 785#ifdef WAITFORRESOURCES 786 if(1){ 787 while((error == OMX_ErrorNone) && (whileloopdone != 1)) { 788#else 789 while((error == OMX_ErrorNone) && (testAppState != OMX_StateIdle)) { 790 if(1){ 791 792#endif 793 if ((testAppState == OMX_StateIdle)&&(nbInCbPending==0)) { 794 whileloopdone = 1; 795 } 796 797 FD_ZERO(&rfds); 798 FD_SET(IpBuf_Pipe[0], &rfds); 799 FD_SET(OpBuf_Pipe[0], &rfds); 800 FD_SET(Event_Pipe[0], &rfds); 801 tv.tv_sec = 1; 802 tv.tv_usec = 0; 803 retval = select(fdmax+1, &rfds, NULL, NULL, &tv); 804 if(retval == -1) { 805 perror("select()"); 806 APP_DPRINT ("%d :: Error \n",__LINE__); 807 break; 808 } 809 810 if(retval == 0) { 811 APP_DPRINT ("%d :: BasicFn App Timeout !!!!!!!!!!! \n",__LINE__); 812 } 813 814 /* === input buffer === */ 815 switch (atoi(argv[3])){ 816 817 case 1: /* simple record till EOF or predefined frame number */ 818 case 4: /* repeated record without deleting component */ 819 case 5: /* repeated record with deleting component */ 820 if(pAppPrivate->dasfMode == 0) { /* file-to-file mode */ 821 if(FD_ISSET(IpBuf_Pipe[0], &rfds)){ 822 OMX_BUFFERHEADERTYPE* pBuffer = NULL; 823 read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer)); 824 nbInCbPending--; 825 frmCount++; 826 error = send_input_buffer (pHandle, pBuffer, fIn); 827 if (error != OMX_ErrorNone) { 828 APP_DPRINT ("%d :: Error While reading input pipe\n",__LINE__); 829 goto EXIT; 830 } 831 } 832 } 833 else{ /* DASF mode */ 834 if((frmCount1 == nbDASFframes) && (done == 0)){ 835 APP_DPRINT("Sending Idle Command - Line %d\n",__LINE__); 836 #ifdef OMX_GETTIME 837 GT_START(); 838 #endif 839 error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL); 840 if(error != OMX_ErrorNone){ 841 APP_DPRINT ("%d :: Error from SendCommand-Idle(Stop) State function\n",__LINE__); 842 goto EXIT; 843 } 844 error = WaitForState(pHandle, OMX_StateIdle); 845 #ifdef OMX_GETTIME 846 GT_END("Call to SendCommand <OMX_StateIdle>"); 847 #endif 848 if(error != OMX_ErrorNone) { 849 APP_DPRINT( "Error: G722Encoder->WaitForState reports an error %X\n",error); 850 goto EXIT; 851 } 852 done = 1; 853 APP_DPRINT("%d :: Shutting down ---------- \n",__LINE__); 854 } 855 856 } 857 break; 858 859 case 2: /* Stop */ 860 if(pAppPrivate->dasfMode == 0) { /* file-to-file mode */ 861 if(FD_ISSET(IpBuf_Pipe[0], &rfds)) { 862 if(frmCount1 > 149) { 863 nbInCbPending--; 864 if(nbInCbPending == 0){ 865 APP_DPRINT("Sending Idle Command - Line %d\n",__LINE__); 866 #ifdef OMX_GETTIME 867 GT_START(); 868 #endif 869 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL); 870 if(error != OMX_ErrorNone) { 871 APP_DPRINT ("%d :: Error from SendCommand-Idle(Stop) State function\n",__LINE__); 872 goto EXIT; 873 } 874 error = WaitForState(pHandle, OMX_StateIdle); 875 #ifdef OMX_GETTIME 876 GT_END("Call to SendCommand <OMX_StateIdle>"); 877 #endif 878 if(error != OMX_ErrorNone) { 879 APP_DPRINT( "Error: G722Encoder->WaitForState reports an error %X\n", error); 880 goto EXIT; 881 } 882 done = 1; 883 APP_DPRINT("%d :: Shutting down ---------- \n",__LINE__); 884 } 885 } 886 else{ 887 OMX_BUFFERHEADERTYPE* pBuffer = NULL; 888 read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer)); 889 nbInCbPending--; 890 frmCount++; 891 error = send_input_buffer (pHandle, pBuffer, fIn); 892 if (error != OMX_ErrorNone) { 893 APP_DPRINT ("%d :: Error While reading input pipe\n",__LINE__); 894 goto EXIT; 895 } 896 frmCnt++; 897 } 898 } 899 } 900 else { /* DASF mode */ 901 if(frmCount1 == 300) { 902 APP_DPRINT("Sending Idle Command - Line %d\n",__LINE__); 903 #ifdef OMX_GETTIME 904 GT_START(); 905 #endif 906 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL); 907 if(error != OMX_ErrorNone) { 908 APP_DPRINT ("%d :: Error from SendCommand-Idle(Stop) State function\n",__LINE__); 909 goto EXIT; 910 } 911 done = 1; 912 error = WaitForState(pHandle, OMX_StateIdle); 913 #ifdef OMX_GETTIME 914 GT_END("Call to SendCommand <OMX_StateIdle>"); 915 #endif 916 if(error != OMX_ErrorNone) { 917 APP_DPRINT( "Error: G722Encoder->WaitForState reports an error %X\n", error); 918 goto EXIT; 919 } 920 APP_DPRINT("%d :: Shutting down ---------- \n",__LINE__); 921 } 922 } 923 break; 924 925 case 3: /* pause and resume */ 926 /*if (frmCount == 320) { 927 APP_DPRINT ("%d :: Sending Resume command to Codec \n",__LINE__); 928 #ifdef OMX_GETTIME 929 GT_START(); 930 #endif 931 error = OMX_SendCommand(pHandle, OMX_CommandStateSet,OMX_StateExecuting, NULL); 932 if(error != OMX_ErrorNone) { 933 APP_DPRINT ("%d :: Error from SendCommand-Executing State function\n",__LINE__); 934 goto EXIT; 935 } 936 APP_DPRINT("Calling Wait For State Line %d\n",__LINE__); 937 error = WaitForState(pHandle, OMX_StateExecuting); 938 #ifdef OMX_GETTIME 939 GT_END("Call to SendCommand <OMX_StateExecuting>"); 940 #endif 941 APP_DPRINT("After Wait For State Line %d\n",__LINE__); 942 if(error != OMX_ErrorNone) { 943 APP_DPRINT("%d :: Error: hPcmEncoder->WaitForState reports an error\n",__LINE__); 944 goto EXIT; 945 } 946 }*/ 947 if(frmCount == 300) { 948 APP_DPRINT ("%d :: Sending Pause command to Codec \n",__LINE__); 949 #ifdef OMX_GETTIME 950 GT_START(); 951 #endif 952 error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StatePause, NULL); 953 if(error != OMX_ErrorNone) { 954 APP_DPRINT ("%d :: Error from SendCommand-Pasue State function\n",__LINE__); 955 goto EXIT; 956 } 957 /* Wait for state to complete */ 958 APP_DPRINT("Calling Wait For State Line %d\n",__LINE__); 959 error = WaitForState(pHandle, OMX_StatePause); 960 #ifdef OMX_GETTIME 961 GT_END("Call to SendCommand <OMX_StatePause>"); 962 #endif 963 APP_DPRINT("After Wait For State Line %d\n",__LINE__); 964 if(error != OMX_ErrorNone) { 965 APP_DPRINT("%d :: Error: hPcmEncoder->WaitForState reports an error\n", __LINE__); 966 goto EXIT; 967 } 968 969 puts("Sleeping for 3 secs..."); 970 sleep(3); 971 puts("Resuming..."); 972 error = OMX_SendCommand(pHandle, OMX_CommandStateSet,OMX_StateExecuting, NULL); 973 if(error != OMX_ErrorNone) { 974 APP_DPRINT ("%d :: Error from SendCommand-Executing State function\n",__LINE__); 975 goto EXIT; 976 } 977 APP_DPRINT("Calling Wait For State Line %d\n",__LINE__); 978 error = WaitForState(pHandle, OMX_StateExecuting); 979 #ifdef OMX_GETTIME 980 GT_END("Call to SendCommand <OMX_StateExecuting>"); 981 #endif 982 APP_DPRINT("After Wait For State Line %d\n",__LINE__); 983 if(error != OMX_ErrorNone) { 984 APP_DPRINT("%d :: Error: hPcmEncoder->WaitForState reports an error\n",__LINE__); 985 goto EXIT; 986 } 987 } 988 if(pAppPrivate->dasfMode == 0) { /* file-to-file mode */ 989 if(FD_ISSET(IpBuf_Pipe[0], &rfds)) { 990 OMX_BUFFERHEADERTYPE* pBuffer = NULL; 991 read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer)); 992 nbInCbPending--; 993 frmCount++; 994 error = send_input_buffer (pHandle, pBuffer, fIn); 995 if (error != OMX_ErrorNone) { 996 APP_DPRINT ("%d :: Error While reading input pipe\n",__LINE__); 997 goto EXIT; 998 } 999 frmCnt++; 1000 } 1001 } 1002 else { /* DASF mode */ 1003 if(frmCount1 == nbDASFframes) { 1004 APP_DPRINT("Sending Idle Command - Line %d\n",__LINE__); 1005 #ifdef OMX_GETTIME 1006 GT_START(); 1007 #endif 1008 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL); 1009 if(error != OMX_ErrorNone) { 1010 APP_DPRINT ("%d :: Error from SendCommand-Idle(Stop) State function\n",__LINE__); 1011 goto EXIT; 1012 } 1013 done = 1; 1014 error = WaitForState(pHandle, OMX_StateIdle); 1015 #ifdef OMX_GETTIME 1016 GT_END("Call to SendCommand <OMX_StateIdle>"); 1017 #endif 1018 if(error != OMX_ErrorNone) { 1019 APP_DPRINT( "Error: G722Encoder->WaitForState reports an error %X\n", error); 1020 goto EXIT; 1021 } 1022 APP_DPRINT("%d :: Shutting down ---------- \n",__LINE__); 1023 } 1024 } 1025 break; 1026 1027 case 6: /* Set Volume */ 1028 if(pAppPrivate->dasfMode == 0){ /* file-to-file mode */ 1029 APP_DPRINT("%d :: This test is not applied to file mode\n",__LINE__); 1030 goto EXIT; 1031 } 1032 else{ /* DASF mode */ 1033 if(frmCount1 == 500){ 1034 /* set high gain for record stream */ 1035 APP_DPRINT("[G722 encoder] --- will set stream gain to high\n"); 1036 pCompPrivateStructGain->sVolume.nValue = 0x8000; 1037 error = OMX_SetConfig(pHandle, OMX_IndexConfigAudioVolume, pCompPrivateStructGain); 1038 if (error != OMX_ErrorNone) 1039 { 1040 error = OMX_ErrorBadParameter; 1041 goto EXIT; 1042 } 1043 } 1044 if(frmCount1 == 800){ 1045 /* set low gain for record stream */ 1046 APP_DPRINT("[G722 encoder] --- will set stream gain to low\n"); 1047 pCompPrivateStructGain->sVolume.nValue = 0x1000; 1048 error = OMX_SetConfig(pHandle, OMX_IndexConfigAudioVolume, pCompPrivateStructGain); 1049 if (error != OMX_ErrorNone) 1050 { 1051 error = OMX_ErrorBadParameter; 1052 goto EXIT; 1053 } 1054 1055 } 1056 1057 if(frmCount1 == nbDASFframes) { 1058 printf("frmCount1 == nbDASFFrames\n\n"); 1059 APP_DPRINT("Sending Idle Command - Line %d\n",__LINE__); 1060 #ifdef OMX_GETTIME 1061 GT_START(); 1062 #endif 1063 error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL); 1064 if(error != OMX_ErrorNone) { 1065 APP_DPRINT ("%d :: Error from SendCommand-Idle(Stop) State function\n",__LINE__); 1066 goto EXIT; 1067 } 1068 done = 1; 1069 error = WaitForState(pHandle, OMX_StateIdle); 1070 #ifdef OMX_GETTIME 1071 GT_END("Call to SendCommand <OMX_StateIdle>"); 1072 #endif 1073 if(error != OMX_ErrorNone) { 1074 APP_DPRINT( "Error: G722Encoder->WaitForState reports an error %X\n", error); 1075 goto EXIT; 1076 } 1077 APP_DPRINT("%d :: Shutting down ---------- \n",__LINE__); 1078 } 1079 } 1080 break; 1081 1082 1083 default: 1084 APP_DPRINT("%d :: ### Running Simple DEFAULT Case Here ###\n",__LINE__); 1085 } 1086 1087 /* === output buffer === */ 1088 if(FD_ISSET(OpBuf_Pipe[0], &rfds)) { 1089 OMX_BUFFERHEADERTYPE* pBuf = NULL; 1090 read(OpBuf_Pipe[0], &pBuf, sizeof(pBuf)); 1091 1092 if (pBuf->nAllocLen != pBuf->nFilledLen) { 1093 APP_DPRINT("%d :: WARNING: Different Size, %ld\n", __LINE__, pBuf->nFilledLen); 1094 } 1095 1096 fwrite(pBuf->pBuffer, 1, pBuf->nFilledLen, fOut); 1097 fflush(fOut); 1098 1099 frmCount1++; 1100 OMX_FillThisBuffer(pHandle, pBuf); 1101 1102 } 1103 1104 if( FD_ISSET(Event_Pipe[0], &rfds) ) { 1105 OMX_U8 pipeContents; 1106 /*OMX_BUFFERHEADERTYPE* pBuffer;*/ 1107 1108 read(Event_Pipe[0], &pipeContents, sizeof(OMX_U8)); 1109 1110 if (pipeContents == 0) { 1111 printf("Test app received OMX_ErrorResourcesPreempted\n"); 1112 WaitForState(pHandle,OMX_StateIdle); 1113 error = OMX_FreeBuffer(pHandle,OMX_DirInput,pInputBufferHeader); 1114 if( (error != OMX_ErrorNone)) { 1115 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__); 1116 goto EXIT; 1117 } 1118 error = OMX_FreeBuffer(pHandle,OMX_DirOutput,pOutputBufferHeader); 1119 if( (error != OMX_ErrorNone)) { 1120 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__); 1121 goto EXIT; 1122 } 1123#ifdef USE_BUFFER 1124 /* free the App Allocated Buffers */ 1125 pInputBuffer = pInputBuffer-G722ENC_CACHE_ALIGN_OFFSET; 1126 pOutputBuffer = pOutputBuffer-G722ENC_CACHE_ALIGN_OFFSET; 1127 free(pOutputBuffer); 1128 free(pInputBuffer); 1129 pOutputBuffer = NULL; 1130 pInputBuffer = NULL; 1131#endif 1132 OMX_SendCommand(pHandle,OMX_CommandStateSet,OMX_StateLoaded,NULL); 1133 WaitForState(pHandle,OMX_StateLoaded); 1134 OMX_SendCommand(pHandle,OMX_CommandStateSet,OMX_StateWaitForResources,NULL); 1135 WaitForState(pHandle,OMX_StateWaitForResources); 1136 } 1137 if (pipeContents == 1) { 1138#ifdef WAITFORRESOURCES 1139 printf("Test app received OMX_ErrorResourcesAcquired\n"); 1140 OMX_SendCommand(pHandle,OMX_CommandStateSet,OMX_StateIdle,NULL); 1141 /* allocate input buffer */ 1142 error = OMX_AllocateBuffer(pHandle,&pInputBufferHeader,0,NULL,inBufSize); 1143 if(error != OMX_ErrorNone) { 1144 APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer()\n",__LINE__); 1145 goto EXIT; 1146 } 1147 1148 WaitForState(pHandle,OMX_StateIdle); 1149 OMX_SendCommand(pHandle,OMX_CommandStateSet,OMX_StateExecuting,NULL); 1150 WaitForState(pHandle,OMX_StateExecuting); 1151 rewind(fIn); 1152 send_input_buffer (pHandle, pBuffer, fIn); 1153#endif 1154 } 1155 if (pipeContents == 2) { 1156 1157 /* Send component to Idle */ 1158 OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL); 1159 WaitForState(pHandle, OMX_StateIdle); 1160 1161#ifdef WAITFORRESOURCES 1162 error = OMX_FreeBuffer(pHandle,OMX_DirInput,pInputBufferHeader); 1163 if( (error != OMX_ErrorNone)) { 1164 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__); 1165 goto EXIT; 1166 } 1167 error = OMX_FreeBuffer(pHandle,OMX_DirOutput,pOutputBufferHeader); 1168 if( (error != OMX_ErrorNone)) { 1169 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__); 1170 goto EXIT; 1171 } 1172#ifdef USE_BUFFER 1173 /* free the App Allocated Buffers */ 1174 pInputBuffer = pInputBuffer-G722ENC_CACHE_ALIGN_OFFSET; 1175 pOutputBuffer = pOutputBuffer-G722ENC_CACHE_ALIGN_OFFSET; 1176 free(pOutputBuffer); 1177 free(pInputBuffer); 1178 pOutputBuffer = NULL; 1179 pInputBuffer = NULL; 1180#endif 1181 1182 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateLoaded, NULL); 1183 if(error != OMX_ErrorNone) { 1184 APP_DPRINT ("%d Error from SendCommand-Idle State function\n",__LINE__); 1185 printf("goto EXIT %d\n",__LINE__); 1186 goto EXIT; 1187 } 1188 error = WaitForState(pHandle, OMX_StateLoaded); 1189#ifdef OMX_GETTIME 1190 GT_END("Call to SendCommand <OMX_StateLoaded>"); 1191#endif 1192 if(error != OMX_ErrorNone) { 1193 APP_DPRINT( "%d Error: WaitForState reports an error %X\n",__LINE__, error); 1194 printf("goto EXIT %d\n",__LINE__); 1195 goto EXIT; 1196 } 1197 goto SHUTDOWN; 1198#endif 1199 } 1200 } 1201 1202 /*if(done == 1) { 1203 APP_DPRINT("Calling GetState Line %d\n",__LINE__); 1204 error = OMX_GetState(pHandle, &state); 1205 if(error != OMX_ErrorNone) { 1206 APP_DPRINT("%d :: Warning: OMX_GetState has returned status %X\n", __LINE__, error); 1207 goto EXIT; 1208 } 1209 }*/ 1210 1211 OMX_GetState (pHandle, &testAppState); 1212 1213 } 1214 else if (preempted){ 1215 sched_yield(); 1216 } 1217 else{ 1218 goto SHUTDOWN; 1219 } 1220 } /* While Loop Ending Here */ 1221 1222 APP_DPRINT ("%d :: The current state of the component = %d \n",__LINE__,state); 1223 fclose(fOut); 1224 fclose(fIn); 1225 fOut = NULL; 1226 fIn = NULL; 1227 frmCnt = 1; 1228 1229 if((atoi(argv[3]) == 4) || (atoi(argv[3]) == 5)) { 1230 APP_DPRINT("Pause 6 seconds\n"); 1231 /*sleep (6);*/ 1232 } 1233 else { 1234 sleep (0); 1235 } 1236 } /*Inner for loop ends here */ 1237 1238#ifndef WAITFORRESOURCES 1239 /* free buffers */ 1240 error = OMX_FreeBuffer(pHandle,OMX_DirInput,pInputBufferHeader); 1241 if( (error != OMX_ErrorNone)) { 1242 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__); 1243 goto EXIT; 1244 } 1245 error = OMX_FreeBuffer(pHandle,OMX_DirOutput,pOutputBufferHeader); 1246 if( (error != OMX_ErrorNone)) { 1247 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__); 1248 goto EXIT; 1249 } 1250#ifdef USE_BUFFER 1251 /* free the App Allocated Buffers */ 1252 pInputBuffer = pInputBuffer-G722ENC_CACHE_ALIGN_OFFSET; 1253 pOutputBuffer = pOutputBuffer-G722ENC_CACHE_ALIGN_OFFSET; 1254 free(pOutputBuffer); 1255 free(pInputBuffer); 1256 pOutputBuffer = NULL; 1257 pInputBuffer = NULL; 1258#endif 1259#endif 1260 APP_DPRINT ("%d :: Sending the OMX_StateLoaded Command\n",__LINE__); 1261#ifdef OMX_GETTIME 1262 GT_START(); 1263#endif 1264 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateLoaded, NULL); 1265 APP_DPRINT ("%d :: Sent the OMX_StateLoaded Command\n",__LINE__); 1266 error = WaitForState(pHandle, OMX_StateLoaded); 1267#ifdef OMX_GETTIME 1268 GT_END("Call to SendCommand <OMX_StateLoaded>"); 1269#endif 1270 1271#ifdef WAITFORRESOURCES 1272 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateWaitForResources, NULL); 1273 if(error != OMX_ErrorNone) { 1274 APP_DPRINT ("%d Error from SendCommand-Idle State function\n",__LINE__); 1275 printf("goto EXIT %d\n",__LINE__); 1276 goto EXIT; 1277 } 1278 error = WaitForState(pHandle, OMX_StateWaitForResources); 1279 1280 /* temporarily put this here until I figure out what should really happen here */ 1281 sleep(10); 1282 /* temporarily put this here until I figure out what should really happen here */ 1283#endif 1284 1285 1286 APP_DPRINT("%d :: Free the Component handle\n",__LINE__); 1287SHUTDOWN: 1288 /* Unload the G722 Encoder Component */ 1289 error = TIOMX_FreeHandle(pHandle); 1290 if((error != OMX_ErrorNone)) { 1291 APP_DPRINT ("%d :: Error in Free Handle function\n",__LINE__); 1292 goto EXIT; 1293 } 1294 APP_DPRINT ("%d :: Free Handle returned Successfully \n",__LINE__); 1295 1296 APP_MEMPRINT("%d:::[TESTAPPFREE] %p\n",__LINE__,pCompPrivateStruct); 1297 if(pCompPrivateStructGain != NULL) { 1298 free(pCompPrivateStructGain); 1299 pCompPrivateStructGain = NULL; 1300 } 1301 free(pCompPrivateStruct); 1302 pCompPrivateStruct = NULL; 1303 free(pG722Param); 1304 pG722Param = NULL; 1305 1306 1307 close(IpBuf_Pipe[0]); 1308 close(IpBuf_Pipe[1]); 1309 close(OpBuf_Pipe[0]); 1310 close(OpBuf_Pipe[1]); 1311 close(Event_Pipe[0]); 1312 close(Event_Pipe[1]); 1313 } /*Outer for loop ends here */ 1314 1315EXIT: 1316 1317#ifdef DSP_RENDERING_ON 1318 if((write(g722encfdwrite, &cmd_data, sizeof(cmd_data)))<0) 1319 APP_DPRINT("%d ::- send command to audio manager\n",__LINE__); 1320 1321 close(g722encfdwrite); 1322 close(g722encfdread); 1323#endif 1324 if(streaminfo){ 1325 free(streaminfo); 1326 streaminfo = NULL; 1327 } 1328 free(pAppPrivate); 1329 pAppPrivate = NULL; 1330 1331#ifdef OMX_GETTIME 1332 GT_END("G722_ENC test <End>"); 1333 OMX_ListDestroy(pListHead); 1334#endif 1335 return error; 1336} 1337 1338 1339/* ================================================================================= */ 1340/** 1341* @fn send_input_buffer() description for send_input_buffer 1342send_input_buffer(). 1343Sends input buffer to component 1344* 1345*/ 1346/* ================================================================================ */ 1347OMX_ERRORTYPE send_input_buffer(OMX_HANDLETYPE pHandle, OMX_BUFFERHEADERTYPE* pBuffer, FILE *fIn) 1348{ 1349 OMX_ERRORTYPE error = OMX_ErrorNone; 1350/* OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;*/ 1351 int nRead = fill_data (pBuffer, fIn); 1352 if((nRead == 0) && (done == 0)){ 1353 done = 1; 1354 pBuffer->nFlags = OMX_BUFFERFLAG_EOS; 1355 pBuffer->nFilledLen = nRead; 1356 1357 OMX_EmptyThisBuffer(pHandle, pBuffer); 1358 nbInCbPending++; 1359 1360 } 1361 if(done==0){ 1362 pBuffer->nFlags = 0; 1363 pBuffer->nFilledLen = nRead; 1364 if(!preempted){ 1365 OMX_EmptyThisBuffer(pHandle, pBuffer); 1366 nbInCbPending++; 1367 } 1368 } 1369 1370 return error; 1371} 1372 1373/* ================================================================================= */ 1374/** 1375* @fn fill_data() description for fill_data 1376fill_data(). 1377Fills input buffer 1378* 1379*/ 1380/* ================================================================================ */ 1381int fill_data (OMX_BUFFERHEADERTYPE *pBuf,FILE *fIn) 1382{ 1383 int nRead = 0; 1384 static int totalRead = 0; 1385 1386 nRead = fread(pBuf->pBuffer, 1, pBuf->nAllocLen , fIn); 1387 totalRead += nRead; 1388 pBuf->nFilledLen = nRead; 1389 return nRead; 1390} 1391