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 G729DecTest.c
26 *
27 * This File contains the G729 DECODER OMX tests
28 *
29 * @path $(OMAPSW_MPU)\linux\audio\src\openmax_il\g729_dec\tests
30 *
31 * @rev 0.5
32 */
33 /* -----------------------------------------------------------------------------
34 *!
35 *! Revision History
36 *! ===================================
37 *! Date Author(s) Version Description
38 *! --------- ------------------- ------- ---------------------------------
39 *! 03-Jan-2007 A.Donjon 0.1 Code update for G729 DECODER
40 *! 19-Feb-2007 A.Donjon 0.2 Update for SN change for last frame
41 *! 06-Apr-2007 A.Donjon 0.3 USE_BUFFER
42 *! 08-Jun-2007 A.Donjon 0.4 Variable input buffer size
43 *! 04-Jul-2007 A.Donjon 0.5 Improved test app.
44 *!
45 *!
46 * ================================================================================= */
47 /****************************************************************
48 * INCLUDE FILES
49 ****************************************************************/
50
51 /* ----- system and platform files ----------------------------*/
52 #include <unistd.h>
53 #include <stdlib.h>
54 #include <sys/ioctl.h>
55 #include <sys/select.h>
56 #include <string.h>
57 #include <stdio.h>
58 #include <fcntl.h>
59 #include <errno.h>
60 #include <linux/vt.h>
61 #include <signal.h>
62 #include <sys/stat.h>
63 #include <pthread.h>
64 #include <linux/soundcard.h>
65 #include <time.h>
66
67 /*-------program files ----------------------------------------*/
68 #include <OMX_Index.h>
69 #include <OMX_Types.h>
70 #include <TIDspOmx.h>
71 #include <OMX_Core.h>
72 #include <OMX_Audio.h>
73 #include <G729DecTest.h>
74 #include <OMX_G729Decoder.h>
75
76 #ifdef OMX_GETTIME
77 #include <OMX_Common_Utils.h>
78 #include <OMX_GetTime.h> /*Headers for Performance & measuremet */
79 #endif
80
81 /* ------compilation control switches -------------------------*/
82 #undef APP_DEBUG
83 #undef APP_MEMCHECK
84 #undef APP_INFO
85 #undef USE_BUFFER
86
87 /* ======================================================================= */
88 /**
89 * @def DASF Define a Value for DASF mode
90 */
91 /* ======================================================================= */
92 #define DASF 1
93 /* ======================================================================= */
94 /**
95 * @def GAIN Define a GAIN value for Configure Audio
96 */
97 /* ======================================================================= */
98 #define GAIN 95
99 /* ======================================================================= */
100 /**
101 * @def G729DEC_SAMPLING_FREQUENCY Sampling Frequency
102 */
103 /* ======================================================================= */
104 #define G729DEC_SAMPLING_FREQUENCY 8000
105 /* ======================================================================= */
106 /**
107 * @def EXTRA_BUFFBYTES Num of Extra Bytes to be allocated
108 */
109 /* ======================================================================= */
110 #define EXTRA_BUFFBYTES (256)
111
112 /* ======================================================================= */
113 /**
114 * @def CACHE_ALIGNMENT Buffer Cache Alignment
115 */
116 /* ======================================================================= */
117 #define CACHE_ALIGNMENT 128
118
119
120
121
122 #define FIFO1 "/dev/fifo.1"
123 #define FIFO2 "/dev/fifo.2"
124
125 /****************************************************************
126 * EXTERNAL REFERENCES NOTE : only use if not found in header file
127 ****************************************************************/
128 /*--------data declarations -----------------------------------*/
129 /*--------function prototypes ---------------------------------*/
130
131 /****************************************************************
132 * PUBLIC DECLARATIONS Defined here, used elsewhere
133 ****************************************************************/
134 /*--------data declarations -----------------------------------*/
135
136 /*--------function prototypes ---------------------------------*/
137
138 /****************************************************************
139 * PRIVATE DECLARATIONS Defined here, used only here
140 ****************************************************************/
141 /*--------data declarations -----------------------------------*/
142
143 #ifdef OMX_GETTIME
144 OMX_ERRORTYPE eError = OMX_ErrorNone;
145 int GT_FlagE = 0; /* Fill Buffer 1 = First Buffer, 0 = Not First Buffer */
146 int GT_FlagF = 0; /*Empty Buffer 1 = First Buffer, 0 = Not First Buffer */
147 static OMX_NODE* pListHead = NULL;
148 #endif
149
150
151 OMX_S16 inputPortDisabled = 0;
152 OMX_S16 outputPortDisabled = 0;
153 OMX_S8 InputCallbacksPending = 0;
154 OMX_S8 OutputLastPending = 0;
155
156 typedef enum COMPONENTS {
157 COMP_1,
158 COMP_2
159 }COMPONENTS;
160
161 OMX_STRING strG729Decoder = "OMX.TI.G729.decode";
162 int IpBuf_Pipe[2] = {0};
163 int OpBuf_Pipe[2] = {0};
164 fd_set rfds;
165 OMX_S16 dasfMode = 0;
166 OMX_S16 packetsPerBuffer = 0;
167 OMX_S16 EOFevent = 0;
168 OMX_BOOL bExitOnError = OMX_FALSE;
169 int command = 0;
170
171 #ifdef DSP_RENDERING_ON
172 AM_COMMANDDATATYPE cmd_data;
173 #endif
174
175 /*--------function prototypes ---------------------------------*/
176 OMX_S16 maxint(OMX_S16 a, OMX_S16 b);
177 OMX_ERRORTYPE StopComponent(OMX_HANDLETYPE *pHandle);
178 OMX_ERRORTYPE PauseComponent(OMX_HANDLETYPE *pHandle);
179 OMX_ERRORTYPE PlayComponent(OMX_HANDLETYPE *pHandle);
180 OMX_S16 fill_data_fromFile (OMX_BUFFERHEADERTYPE *pBuf, FILE *fIn, OMX_HANDLETYPE pHandle);
181 void ConfigureAudio();
182 OMX_ERRORTYPE send_input_buffer (OMX_HANDLETYPE pHandle, OMX_BUFFERHEADERTYPE* pBuffer, FILE *fIn);
183
184 #ifdef USE_BUFFER
185 OMX_ERRORTYPE FreeResources(OMX_AUDIO_PARAM_G729TYPE* pG729Param,
186 OMX_AUDIO_PARAM_PCMMODETYPE* pPcmParam,
187 OMX_PARAM_PORTDEFINITIONTYPE* pCompPrivateStruct,
188 OMX_AUDIO_CONFIG_MUTETYPE* pCompPrivateStructMute,
189 OMX_AUDIO_CONFIG_VOLUMETYPE* pCompPrivateStructVolume,
190 TI_OMX_DSP_DEFINITION* audioinfo,
191 OMX_U8* pInputBuffer[10],
192 OMX_U8* pOutputBuffer[10],
193 G729DEC_BufParamStruct* pInBufferParam[10],
194 OMX_HANDLETYPE* pHandle);
195 #else
196 OMX_ERRORTYPE FreeResources(OMX_AUDIO_PARAM_G729TYPE* pG729Param,
197 OMX_AUDIO_PARAM_PCMMODETYPE* pPcmParam,
198 OMX_PARAM_PORTDEFINITIONTYPE* pCompPrivateStruct,
199 OMX_AUDIO_CONFIG_MUTETYPE* pCompPrivateStructMute,
200 OMX_AUDIO_CONFIG_VOLUMETYPE* pCompPrivateStructVolume,
201 TI_OMX_DSP_DEFINITION* audioinfo,
202 OMX_BUFFERHEADERTYPE* pInputBufferHeader[10],
203 OMX_BUFFERHEADERTYPE* pOutputBufferHeader[10],
204 G729DEC_BufParamStruct* pInBufferParam[10],
205 OMX_HANDLETYPE* pHandle);
206 #endif
207
208
209 /*--------macros ----------------------------------------------*/
210 #ifdef APP_DEBUG
211 #define APP_DPRINT(...) fprintf(stderr,__VA_ARGS__)
212 #else
213 #define APP_DPRINT(...)
214 #endif
215
216 #ifdef APP_INFO
217 #define DPRINT(...) fprintf(stderr,__VA_ARGS__)
218 #else
219 #define DPRINT(...)
220 #endif
221
222 #ifdef APP_MEMCHECK
223 #define APP_MEMPRINT(...) fprintf(stderr,__VA_ARGS__)
224 #else
225 #define APP_MEMPRINT(...)
226 #endif
227
228
229 /* safe routine to get the maximum of 2 integers */
maxint(OMX_S16 a,OMX_S16 b)230 OMX_S16 maxint(OMX_S16 a, OMX_S16 b)
231 {
232 return (a>b) ? a : b;
233 }
234
235 #define OMX_G729APP_INIT_STRUCT(_s_, _name_) \
236 memset((_s_), 0x0, sizeof(_name_)); \
237
238 #define OMX_G729APP_MALLOC_STRUCT(_pStruct_, _sName_) \
239 _pStruct_ = (_sName_*)malloc(sizeof(_sName_)); \
240 if(_pStruct_ == NULL){ \
241 printf("***********************************\n"); \
242 printf("%d :: Malloc Failed\n",__LINE__); \
243 printf("***********************************\n"); \
244 error = OMX_ErrorInsufficientResources; \
245 goto EXIT; \
246 } \
247 APP_MEMPRINT("%d :: ALLOCATING MEMORY = %p\n",__LINE__,_pStruct_);
248
249 /* This method will wait for the component to get to the state
250 * specified by the DesiredState input. */
WaitForState(OMX_HANDLETYPE * pHandle,OMX_STATETYPE DesiredState)251 static OMX_ERRORTYPE WaitForState(OMX_HANDLETYPE* pHandle,
252 OMX_STATETYPE DesiredState)
253 {
254 OMX_STATETYPE CurState = OMX_StateInvalid;
255 OMX_ERRORTYPE eError = OMX_ErrorNone;
256 OMX_S16 nCnt = 0;
257 OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
258 eError = pComponent->GetState(pHandle, &CurState);
259
260 while((eError == OMX_ErrorNone) && (CurState != DesiredState) && (eError == OMX_ErrorNone) ) {
261 sleep(1);
262 if(nCnt++ == 10) {
263 APP_DPRINT( "Still Waiting, press CTL-C to continue\n");
264 }
265 eError = pComponent->GetState(pHandle, &CurState);
266
267 }
268 return eError;
269 }
270
271
EventHandler(OMX_HANDLETYPE hComponent,OMX_PTR pAppData,OMX_EVENTTYPE eEvent,OMX_U32 nData1,OMX_U32 nData2,OMX_PTR pEventData)272 OMX_ERRORTYPE EventHandler(
273 OMX_HANDLETYPE hComponent,
274 OMX_PTR pAppData,
275 OMX_EVENTTYPE eEvent,
276 OMX_U32 nData1,
277 OMX_U32 nData2,
278 OMX_PTR pEventData)
279 {
280
281 OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)hComponent;
282 OMX_STATETYPE state = OMX_StateInvalid;
283 OMX_ERRORTYPE eError = OMX_ErrorNone;
284
285 #ifdef APP_DEBUG
286 int iComp = *((int *)(pAppData));
287 #endif
288
289 eError = pComponent->GetState (hComponent, &state);
290 if(eError != OMX_ErrorNone) {
291 APP_DPRINT("%d :: App: Error returned from GetState\n",__LINE__);
292 }
293 switch (eEvent) {
294 case OMX_EventCmdComplete:
295
296 if(nData1 == OMX_CommandPortDisable){
297 if (nData2 == OMX_DirInput) {
298 inputPortDisabled = 1;
299 }
300 if (nData2 == OMX_DirOutput) {
301 outputPortDisabled = 1;
302 }
303 }
304 else if(nData1 == OMX_CommandStateSet){
305
306
307 }
308 break;
309
310 case OMX_EventError:
311 /* Error notification */
312 if(nData1==OMX_ErrorOverflow){
313 APP_DPRINT("EventHandler: WARNING: Overflow ERROR\n");
314 /* Output buffer with sufficient allocated size must be sent to SN */
315 }
316 if(nData1==OMX_ErrorStreamCorrupt){
317 APP_DPRINT("EventHandler: ERROR: Data corrupt ERROR\n");
318 /* Corrupted input buffer parameters, component must be reseted or stopped */
319 }
320 break;
321 break;
322 case OMX_EventMax:
323 break;
324 case OMX_EventMark:
325 break;
326
327 default:
328 break;
329 }
330 return eError;
331 }
332
FillBufferDone(OMX_HANDLETYPE hComponent,OMX_PTR ptr,OMX_BUFFERHEADERTYPE * pBufferO)333 void FillBufferDone (OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBufferO)
334 {
335 APP_DPRINT ("APP:::: OUTPUT BUFFER = %p && %p\n",pBufferO, pBufferO->pBuffer);
336 APP_DPRINT ("APP:::: pBuffer->nFilledLen = %d\n",pBufferO->nFilledLen);
337 write(OpBuf_Pipe[1], &pBufferO, sizeof(pBufferO));
338
339 #ifdef OMX_GETTIME
340 if (GT_FlagF == 1 ) /* First Buffer Reply*/ /* 1 = First Buffer, 0 = Not First Buffer */
341 {
342 GT_END("Call to FillBufferDone <First: FillBufferDone>");
343 GT_FlagF = 0 ; /* 1 = First Buffer, 0 = Not First Buffer */
344 }
345 #endif
346
347 }
348
349
EmptyBufferDone(OMX_HANDLETYPE hComponent,OMX_PTR ptr,OMX_BUFFERHEADERTYPE * pBufferI)350 void EmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBufferI)
351 {
352 OMX_S16 ret = 0;
353 APP_DPRINT ("APP:::: INPUT BUFFER = %p && %p\n",pBufferI, pBufferI->pBuffer);
354 if (command == 0){
355 APP_DPRINT("output: pBuffer->nTimeStamp = %d\n", (int)pBufferI->nTimeStamp);
356 APP_DPRINT("output: pBuffer->nTickCount = %ld\n", pBufferI->nTickCount);
357 }
358 ret = write(IpBuf_Pipe[1], &pBufferI, sizeof(pBufferI));
359
360 #ifdef OMX_GETTIME
361 if (GT_FlagE == 1 ) /* First Buffer Reply*/ /* 1 = First Buffer, 0 = Not First Buffer */
362 {
363 GT_END("Call to EmptyBufferDone <First: EmptyBufferDone>");
364 GT_FlagE = 0; /* 1 = First Buffer, 0 = Not First Buffer */
365 }
366 #endif
367 }
368
369
370
371 OMX_S16 SendInputBuffer = 0;
372 OMX_S16 numInputBuffers = 0;
373 OMX_S16 numOutputBuffers = 0;
374 FILE *fp;
375
main(int argc,char * argv[])376 int main(int argc, char* argv[])
377 {
378 OMX_CALLBACKTYPE G729CaBa = {(void *)EventHandler,
379 (void*)EmptyBufferDone,
380 (void*)FillBufferDone};
381 OMX_HANDLETYPE pHandle;
382 OMX_ERRORTYPE error = OMX_ErrorNone;
383 OMX_U32 AppData = 100;
384 OMX_PARAM_PORTDEFINITIONTYPE* pCompPrivateStruct = NULL;
385 OMX_AUDIO_PARAM_G729TYPE *pG729Param = NULL;
386 OMX_AUDIO_PARAM_PCMMODETYPE *pPcmParam = NULL;
387 OMX_COMPONENTTYPE *pComponent = NULL;
388 OMX_STATETYPE state = OMX_StateInvalid;
389 OMX_BUFFERHEADERTYPE* pInputBufferHeader[10] = {NULL};
390 OMX_BUFFERHEADERTYPE* pOutputBufferHeader[10] = {NULL};
391 TI_OMX_DSP_DEFINITION *audioinfo = NULL;
392 G729DEC_BufParamStruct* pInBufferParam[10] = {NULL};
393
394 #ifdef USE_BUFFER
395 OMX_U8* pInputBuffer[10] = {NULL};
396 OMX_U8* pOutputBuffer[10]= {NULL};
397 #endif
398
399 struct timeval tv;
400 OMX_S16 retval = 0, i = 0, j = 0,k = 0;
401 OMX_S16 frmCount = 0;
402 OMX_S16 OutBufCount = 0;
403 OMX_S16 InBufCount = 0;
404 OMX_S16 testcnt = 1;
405 OMX_S16 testcnt1 = 1;
406 OMX_BUFFERHEADERTYPE* pBuffer = NULL;
407 OMX_BUFFERHEADERTYPE* pBuf = NULL;
408 OMX_INDEXTYPE index = 0;
409 TI_OMX_DATAPATH dataPath;
410 int g729decfdwrite = 0;
411 int g729decfdread = 0;
412 OMX_AUDIO_CONFIG_MUTETYPE* pCompPrivateStructMute = NULL;
413 OMX_AUDIO_CONFIG_VOLUMETYPE* pCompPrivateStructVolume = NULL;
414
415 #ifdef MTRACE
416 mtrace();
417 #endif
418
419 bExitOnError = OMX_FALSE;
420 OMX_G729APP_MALLOC_STRUCT(audioinfo, TI_OMX_DSP_DEFINITION);
421 OMX_G729APP_INIT_STRUCT(audioinfo, TI_OMX_DSP_DEFINITION);
422 APP_DPRINT("------------------------------------------------------\n");
423 APP_DPRINT("This is Main Thread In G729 DECODER Test Application:\n");
424 APP_DPRINT("Test Core 1.5 - " __DATE__ ":" __TIME__ "\n");
425 APP_DPRINT("------------------------------------------------------\n");
426
427 #ifdef OMX_GETTIME
428 GTeError = OMX_ListCreate(&pListHead);
429 printf("eError = %d\n",GTeError);
430 GT_START();
431 #endif
432
433 #ifdef DSP_RENDERING_ON
434 if((g729decfdwrite=open(FIFO1,O_WRONLY))<0) {
435 printf("[G729TEST] - failure to open WRITE pipe\n");
436 }
437 else {
438 printf("[G729TEST] - opened WRITE pipe\n");
439 }
440
441 if((g729decfdread=open(FIFO2,O_RDONLY))<0) {
442 printf("[G729TEST] - failure to open READ pipe\n");
443 bExitOnError = OMX_TRUE;
444 goto EXIT;
445 }
446 else {
447 printf("[G729TEST] - opened READ pipe\n");
448 }
449 #endif
450
451 /* check the input parameters */
452 if(argc != 8) {
453 printf( "Usage: testApp infile outfile TestCaseNo DASFmode nbinbuf nboutbuf nbPacketsPerBuffer\n");
454 printf(" DASFmode: FM or DM for File Mode or DASF Mode\n");
455 bExitOnError = OMX_TRUE;
456 goto EXIT;
457 }
458
459 numInputBuffers = atoi(argv[5]);
460 numOutputBuffers = atoi(argv[6]);
461
462 /* validate number of buffers input from command */
463 if(numInputBuffers < 1 || numInputBuffers > 4)
464 {
465 printf("Please use between at least 1 but no more than 4 input buffers\n");
466 bExitOnError = OMX_TRUE;
467 goto EXIT;
468 }
469 if(numOutputBuffers < 1 || numOutputBuffers > 4)
470 {
471 printf("Please use between at least 1 but no more than 4 output buffers\n");
472 bExitOnError = OMX_TRUE;
473 goto EXIT;
474 }
475 APP_DPRINT( "Nb input buffers: %d, Nb output buffers: %d\n", numInputBuffers, numOutputBuffers);
476 packetsPerBuffer = atoi(argv[7]);
477 if((packetsPerBuffer>0)&&(packetsPerBuffer<7)){
478 APP_DPRINT( "Nb packets per buffer: %d\n", packetsPerBuffer);
479 }
480 else{
481 printf("Number of packets per buffer should be between 1 and 6\n");
482 bExitOnError = OMX_TRUE;
483 goto EXIT;
484 }
485
486 /* check to see that the input file exists */
487 struct stat sb = {0};
488 OMX_S16 status = stat(argv[1], &sb);
489 if( status != 0 ) {
490 APP_DPRINT( "Cannot find file %s. (%u)\n", argv[1], errno);
491 bExitOnError = OMX_TRUE;
492 goto EXIT;
493 }
494
495 /* Open the file of data to be decoded */
496 FILE* fIn = fopen(argv[1], "r");
497 fp =fopen(argv[1], "r");
498 if( fIn == NULL ) {
499 APP_DPRINT( "Error: failed to open the file %s for readonly\access\n", argv[1]);
500 bExitOnError = OMX_TRUE;
501 goto EXIT;
502 }
503
504 FILE* fOut = NULL;
505 /* Open the output file only in no DASF mode*/
506 if(!(strcmp(argv[4],"FM"))){
507 fOut = fopen(argv[2], "w");
508 APP_DPRINT( "NO DASF MODE, created output file \n");
509 if( fOut == NULL ) {
510 APP_DPRINT( "Error: failed to create the output file %s\n", argv[2]);
511 bExitOnError = OMX_TRUE;
512 goto EXIT;
513 }
514 }
515
516 /* Create a pipe used to queue data from the callback. */
517 retval = pipe(IpBuf_Pipe);
518 if( retval != 0) {
519 APP_DPRINT( "Error:Fill Data Pipe failed to open\n");
520 bExitOnError = OMX_TRUE;
521 goto EXIT;
522 }
523
524 retval = pipe(OpBuf_Pipe);
525 if( retval != 0) {
526 APP_DPRINT( "Error:Empty Data Pipe failed to open\n");
527 bExitOnError = OMX_TRUE;
528 goto EXIT;
529 }
530
531 /* save off the "max" of the handles for the selct statement */
532 OMX_S16 fdmax = maxint(IpBuf_Pipe[0], OpBuf_Pipe[0]);
533
534 APP_DPRINT("%d :: G729Test\n",__LINE__);
535 error = TIOMX_Init();
536 APP_DPRINT("%d :: G729Test\n",__LINE__);
537 if(error != OMX_ErrorNone) {
538 APP_DPRINT("%d :: Error returned by OMX_Init()\n",__LINE__);
539 bExitOnError = OMX_TRUE;
540 goto EXIT;
541 }
542
543 /* Test case number */
544 command = atoi(argv[3]);
545 APP_DPRINT("%d :: G729Test\n",__LINE__);
546 switch (command ) {
547 case 0:
548 printf ("-------------------------------------\n");
549 printf ("Testing Time stamp and Tick count \n");
550 printf ("-------------------------------------\n");
551 break;
552 case 1:
553 printf ("-------------------------------------\n");
554 printf ("Testing Simple PLAY till EOF \n");
555 printf ("-------------------------------------\n");
556 break;
557 case 2:
558 printf ("-------------------------------------\n");
559 printf ("Testing Stop and Play \n");
560 printf ("-------------------------------------\n");
561 break;
562 case 3:
563 printf ("-------------------------------------\n");
564 printf ("Testing PAUSE & RESUME Command\n");
565 printf ("-------------------------------------\n");
566 break;
567 case 4:
568 printf ("---------------------------------------------\n");
569 printf ("Testing STOP Command by Stopping In-Between\n");
570 printf ("---------------------------------------------\n");
571 break;
572 case 5:
573 printf ("-------------------------------------------------\n");
574 printf ("Testing Repeated PLAY without Deleting Component\n");
575 printf ("-------------------------------------------------\n");
576 testcnt = 15;
577 break;
578 case 6:
579 printf ("------------------------------------------------\n");
580 printf ("Testing Repeated PLAY with Deleting Component\n");
581 printf ("------------------------------------------------\n");
582 testcnt1 = 15;
583 break;
584 case 7:
585 printf ("------------------------------------------------------------\n");
586 printf ("Testing Mute/Unmute for Playback Stream\n");
587 printf ("------------------------------------------------------------\n");
588 break;
589 case 8:
590 printf ("------------------------------------------------------------\n");
591 printf ("Testing Set Volume for Playback Stream\n");
592 printf ("------------------------------------------------------------\n");
593 break;
594 default:
595 printf("------------------------------------------------------------\n");
596 printf("Wrong test case number. Valid test number from 1 to 8\n");
597 bExitOnError = OMX_TRUE;
598 goto EXIT;
599 }
600
601 if(!(strcmp(argv[4],"FM"))) {
602 audioinfo->dasfMode = 0;
603 dasfMode = 0;
604 printf("NON DASF MODE\n");
605 }
606 else if(!(strcmp(argv[4],"DM"))){
607 audioinfo->dasfMode = 1;
608 dasfMode = 1;
609 printf("DASF MODE\n");
610
611 #if STATE_TRANSITION_STATE
612 ConfigureAudio();
613 #endif
614
615 }
616 else {
617 printf("Enter proper DASF mode: \n");
618 printf("Should be one of these modes: FM or DM for File Mode or DASF Mode\n");
619 bExitOnError = OMX_TRUE;
620 goto EXIT;
621 }
622
623
624 APP_DPRINT("%d :: G729Test\n",__LINE__);
625 for(j = 0; j < testcnt1; j++) {
626 if(j >= 1) {
627 printf ("Decoding the file for %d Time\n",j+1);
628 close(IpBuf_Pipe[0]);
629 close(IpBuf_Pipe[1]);
630 close(OpBuf_Pipe[0]);
631 close(OpBuf_Pipe[1]);
632
633
634 /* Create a pipe used to queue data from the callback. */
635 retval = pipe( IpBuf_Pipe);
636 if( retval != 0) {
637 APP_DPRINT( "Error:Fill Data Pipe failed to open\n");
638 bExitOnError = OMX_TRUE;
639 goto EXIT;
640 }
641
642 retval = pipe( OpBuf_Pipe);
643 if( retval != 0) {
644 APP_DPRINT( "Error:Empty Data Pipe failed to open\n");
645 bExitOnError = OMX_TRUE;
646 goto EXIT;
647 }
648
649 /* Open the input file to be decoded */
650 fIn = fopen(argv[1], "r");
651 fp= fopen(argv[1], "r");
652 if( fIn == NULL ) {
653 fprintf(stderr, "Error: failed to open the file %s for readonly\
654 access\n", argv[1]);
655 bExitOnError = OMX_TRUE;
656 goto EXIT;
657 }
658
659 /* Open the output file only in non DASF mode */
660 if(audioinfo->dasfMode == 0){
661 fOut = fopen(argv[2], "w");
662 if( fOut == NULL ) {
663 fprintf(stderr, "Error: failed to create the output file \n");
664 bExitOnError = OMX_TRUE;
665 goto EXIT;
666 }
667 error = TIOMX_Init();
668 }
669
670 }
671
672 /* Load the G729 Decoder Component */
673 APP_DPRINT("%d :: G729Test\n",__LINE__);
674
675 #ifdef OMX_GETTIME
676 GT_START();
677 error = OMX_GetHandle(&pHandle, strG729Decoder, &AppData, &G729CaBa);
678 GT_END("Call to GetHandle");
679 #else
680 error = TIOMX_GetHandle(&pHandle, strG729Decoder, &AppData, &G729CaBa);
681 #endif
682
683 APP_DPRINT("%d :: G729Test\n",__LINE__);
684 if((error != OMX_ErrorNone) || (pHandle == NULL)) {
685 APP_DPRINT ("Error in Get Handle function\n");
686 bExitOnError = OMX_TRUE;
687 goto EXIT;
688 }
689
690 APP_DPRINT("%d :: G729Test\n",__LINE__);
691 OMX_G729APP_MALLOC_STRUCT(pCompPrivateStruct, OMX_PARAM_PORTDEFINITIONTYPE);
692 OMX_G729APP_INIT_STRUCT(pCompPrivateStruct, OMX_PARAM_PORTDEFINITIONTYPE);
693 /* set playback stream mute/unmute */
694 OMX_G729APP_MALLOC_STRUCT(pCompPrivateStructMute, OMX_AUDIO_CONFIG_MUTETYPE);
695 OMX_G729APP_INIT_STRUCT(pCompPrivateStructMute, OMX_AUDIO_CONFIG_MUTETYPE);
696 OMX_G729APP_MALLOC_STRUCT(pCompPrivateStructVolume, OMX_AUDIO_CONFIG_VOLUMETYPE);
697 OMX_G729APP_INIT_STRUCT(pCompPrivateStructVolume, OMX_AUDIO_CONFIG_VOLUMETYPE);
698
699
700
701 pCompPrivateStruct->nSize = sizeof (OMX_PARAM_PORTDEFINITIONTYPE);
702 pCompPrivateStruct->nVersion.s.nVersionMajor = 0x1;
703 pCompPrivateStruct->nVersion.s.nVersionMinor = 0x2;
704 APP_DPRINT("%d :: G729Test\n",__LINE__);
705
706 /* Send input port config */
707 pCompPrivateStruct->eDir = OMX_DirInput;
708 pCompPrivateStruct->nPortIndex = OMX_DirInput;
709 pCompPrivateStruct->nBufferCountActual = numInputBuffers;
710 pCompPrivateStruct->nBufferSize = INPUT_G729DEC_BUFFER_SIZE*packetsPerBuffer;
711 pCompPrivateStruct->format.audio.eEncoding = OMX_AUDIO_CodingG729;
712 pCompPrivateStruct->bEnabled = 1;
713 pCompPrivateStruct->bPopulated = 0;
714 #ifdef OMX_GETTIME
715 GT_START();
716 error = OMX_SetParameter (pHandle,OMX_IndexParamPortDefinition,
717 pCompPrivateStruct);
718 GT_END("Set Parameter Test-SetParameter");
719 #else
720 error = OMX_SetParameter (pHandle,OMX_IndexParamPortDefinition,
721 pCompPrivateStruct);
722 #endif
723 if (error != OMX_ErrorNone) {
724 error = OMX_ErrorBadParameter;
725 printf ("%d:: OMX_ErrorBadParameter\n",__LINE__);
726 bExitOnError = OMX_TRUE;
727 goto EXIT;
728 }
729
730 /* Send output port config */
731 pCompPrivateStruct->nPortIndex = OMX_DirOutput;
732 pCompPrivateStruct->eDir = OMX_DirOutput;
733 pCompPrivateStruct->format.audio.eEncoding = OMX_AUDIO_CodingPCM;
734 pCompPrivateStruct->nBufferCountActual = numOutputBuffers;
735 pCompPrivateStruct->nBufferSize = (OUTPUT_G729DEC_BUFFER_SIZE)*packetsPerBuffer;
736 if(audioinfo->dasfMode == 1) {
737 pCompPrivateStruct->nBufferCountActual = 0;
738 }
739
740 #ifdef OMX_GETTIME
741 GT_START();
742 error = OMX_SetParameter (pHandle,OMX_IndexParamPortDefinition,
743 pCompPrivateStruct);
744 GT_END("Set Parameter Test-SetParameter");
745 #else
746 error = OMX_SetParameter (pHandle,OMX_IndexParamPortDefinition,
747 pCompPrivateStruct);
748 #endif
749
750 if (error != OMX_ErrorNone) {
751 error = OMX_ErrorBadParameter;
752 printf ("%d:: OMX_ErrorBadParameter\n",__LINE__);
753 bExitOnError = OMX_TRUE;
754 goto EXIT;
755 }
756
757 /* default setting for Mute/Unmute */
758 pCompPrivateStructMute->nSize = sizeof (OMX_AUDIO_CONFIG_MUTETYPE);
759 pCompPrivateStructMute->nVersion.s.nVersionMajor = 0x1;
760 pCompPrivateStructMute->nVersion.s.nVersionMinor = 0x1;
761 pCompPrivateStructMute->nPortIndex = OMX_DirInput;
762 pCompPrivateStructMute->bMute = OMX_FALSE;
763
764 /* default setting for volume */
765 pCompPrivateStructVolume->nSize = sizeof(OMX_AUDIO_CONFIG_VOLUMETYPE);
766 pCompPrivateStructVolume->nVersion.s.nVersionMajor = 0x1;
767 pCompPrivateStructVolume->nVersion.s.nVersionMinor = 0x1;
768 pCompPrivateStructVolume->nPortIndex = OMX_DirInput;
769 pCompPrivateStructVolume->bLinear = OMX_FALSE;
770 pCompPrivateStructVolume->sVolume.nValue = 0x4000; /*actual volume */
771 pCompPrivateStructVolume->sVolume.nMin = 0; /* min volume */
772 pCompPrivateStructVolume->sVolume.nMax = 100; /* max volume */
773
774 #ifndef USE_BUFFER
775
776 for (i=0; i < numInputBuffers; i++) {
777 OMX_G729APP_MALLOC_STRUCT(pInBufferParam[i], G729DEC_BufParamStruct);
778 OMX_G729APP_INIT_STRUCT(pInBufferParam[i], G729DEC_BufParamStruct);
779 /* allocate input buffer */
780 APP_DPRINT("%d :: About to call OMX_AllocateBuffer\n",__LINE__);
781 error = OMX_AllocateBuffer(pHandle,
782 &pInputBufferHeader[i], 0,
783 pInBufferParam[i],
784 INPUT_G729DEC_BUFFER_SIZE*packetsPerBuffer);
785 APP_DPRINT("%d :: called OMX_AllocateBuffer\n",__LINE__);
786 if(error != OMX_ErrorNone) {
787 APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer()\n",__LINE__);
788 bExitOnError = OMX_TRUE;
789 goto EXIT;
790 }
791 }
792 for (i=0; i < numOutputBuffers; i++) {
793 /* allocate output buffer */
794 APP_DPRINT("%d :: About to call OMX_AllocateBuffer\n",__LINE__);
795 error = OMX_AllocateBuffer(pHandle,&pOutputBufferHeader[i],1,NULL,(OUTPUT_G729DEC_BUFFER_SIZE)*packetsPerBuffer);
796 APP_DPRINT("%d :: called OMX_AllocateBuffer\n",__LINE__);
797 if(error != OMX_ErrorNone) {
798 APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer()\n",__LINE__);
799 bExitOnError = OMX_TRUE;
800 goto EXIT;
801 }
802 }
803
804 #else
805
806 APP_DPRINT("%d :: About to call OMX_UseBuffer\n",__LINE__);
807 /* numInputBuffers validated above to resolve Klockworks error */
808 for (i=0; i < numInputBuffers; i++){
809 OMX_G729APP_MALLOC_STRUCT(pInBufferParam[i], G729DEC_BufParamStruct);
810 OMX_G729APP_INIT_STRUCT(pInBufferParam[i], G729DEC_BufParamStruct);
811 pInputBuffer[i] = (OMX_U8*)malloc((INPUT_G729DEC_BUFFER_SIZE*packetsPerBuffer) + EXTRA_BUFFBYTES);
812 memset(pInputBuffer[i] , 0x0, (INPUT_G729DEC_BUFFER_SIZE*packetsPerBuffer) + EXTRA_BUFFBYTES);
813 APP_MEMPRINT("%d:::[TESTAPPALLOC] %p\n",__LINE__,pInputBuffer[i]);
814 pInputBuffer[i] = pInputBuffer[i] + CACHE_ALIGNMENT;
815
816 /* allocate input buffer */
817 APP_DPRINT("%d :: About to call OMX_UseBuffer\n",__LINE__);
818 error = OMX_UseBuffer(pHandle,&pInputBufferHeader[i],0,pInBufferParam[i],INPUT_G729DEC_BUFFER_SIZE*packetsPerBuffer,pInputBuffer[i]);
819 APP_DPRINT("%d :: called OMX_UseBuffer\n",__LINE__);
820 if(error != OMX_ErrorNone){
821 APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n",__LINE__);
822 bExitOnError = OMX_TRUE;
823 goto EXIT;
824 }
825 }
826 /* numInputBuffers validated above to resolve Klockworks error */
827 for ( i = 0 ; i < numOutputBuffers ; i++ ){
828 pOutputBuffer[i] = (OMX_U8*)malloc(((OUTPUT_G729DEC_BUFFER_SIZE)*packetsPerBuffer)+EXTRA_BUFFBYTES);
829 memset(pOutputBuffer[i] , 0x0, (OUTPUT_G729DEC_BUFFER_SIZE*packetsPerBuffer) + EXTRA_BUFFBYTES);
830 APP_MEMPRINT("%d:::[TESTAPPALLOC] %p\n",__LINE__,pOutputBuffer);
831 pOutputBuffer[i] = pOutputBuffer[i] + CACHE_ALIGNMENT;
832 /* allocate output buffer */
833 APP_DPRINT("%d :: About to call OMX_UseBuffer\n",__LINE__);
834 error = OMX_UseBuffer(pHandle,&pOutputBufferHeader[i],1,NULL,(OUTPUT_G729DEC_BUFFER_SIZE)*packetsPerBuffer,pOutputBuffer[i]);
835 APP_DPRINT("%d :: called OMX_UseBuffer\n",__LINE__);
836 if(error != OMX_ErrorNone){
837 APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n",__LINE__);
838 bExitOnError = OMX_TRUE;
839 goto EXIT;
840 }
841 }
842 #endif
843
844 OMX_G729APP_MALLOC_STRUCT(pG729Param, OMX_AUDIO_PARAM_G729TYPE);
845 OMX_G729APP_INIT_STRUCT(pG729Param, OMX_AUDIO_PARAM_G729TYPE);
846 pG729Param->nSize = sizeof (OMX_AUDIO_PARAM_G729TYPE);
847 pG729Param->nVersion.s.nVersionMajor = 0xF1;
848 pG729Param->nVersion.s.nVersionMinor = 0xF2;
849 pG729Param->nPortIndex = OMX_DirInput;
850 pG729Param->nChannels = 1;
851 pG729Param->eBitType = OMX_AUDIO_G729AB;
852
853 #ifdef OMX_GETTIME
854 GT_START();
855 error = OMX_SetParameter (pHandle,OMX_IndexParamAudioG729,
856 pG729Param);
857 GT_END("Set Parameter Test-SetParameter");
858 #else
859 error = OMX_SetParameter (pHandle,OMX_IndexParamAudioG729,
860 pG729Param);
861 #endif
862
863 if (error != OMX_ErrorNone) {
864 error = OMX_ErrorBadParameter;
865 printf ("%d:: OMX_ErrorBadParameter\n",__LINE__);
866 bExitOnError = OMX_TRUE;
867 goto EXIT;
868 }
869 OMX_G729APP_MALLOC_STRUCT(pPcmParam, OMX_AUDIO_PARAM_PCMMODETYPE);
870 OMX_G729APP_INIT_STRUCT(pPcmParam, OMX_AUDIO_PARAM_PCMMODETYPE);
871 pPcmParam->nPortIndex = OMX_DirOutput;
872 pPcmParam->nChannels = 1;
873 #ifdef OMX_GETTIME
874 GT_START();
875 error = OMX_SetParameter (pHandle,OMX_IndexParamAudioPcm,
876 pPcmParam);
877 GT_END("Set Parameter Test-SetParameter");
878 #else
879 error = OMX_SetParameter (pHandle,OMX_IndexParamAudioPcm,
880 pPcmParam);
881 #endif
882 if (error != OMX_ErrorNone) {
883 error = OMX_ErrorBadParameter;
884 printf ("%d:: OMX_ErrorBadParameter\n",__LINE__);
885 bExitOnError = OMX_TRUE;
886 goto EXIT;
887 }
888
889 /* get TeeDN or ACDN mode */
890 audioinfo->acousticMode = OMX_FALSE;
891
892 if (dasfMode) {
893 #ifdef RTM_PATH
894 dataPath = DATAPATH_APPLICATION_RTMIXER;
895 #endif
896
897 #ifdef ETEEDN_PATH
898 dataPath = DATAPATH_APPLICATION;
899 #endif
900 }
901
902 error = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.g729headerinfo",&index);
903 if (error != OMX_ErrorNone) {
904 printf("Error getting extension index\n");
905 bExitOnError = OMX_TRUE;
906 goto EXIT;
907 }
908
909 #ifdef DSP_RENDERING_ON
910 cmd_data.hComponent = pHandle;
911 cmd_data.AM_Cmd = AM_CommandIsOutputStreamAvailable;
912 cmd_data.param1 = 0;
913 if((write(g729decfdwrite, &cmd_data, sizeof(cmd_data)))<0) {
914 printf("%d ::OMX_G729Decoder.c ::[G729 Dec Component] - send command to audio manager\n", __LINE__);
915 }
916 if((read(g729decfdread, &cmd_data, sizeof(cmd_data)))<0) {
917 printf("%d ::OMX_G729Decoder.c ::[G729 Dec Component] - failure to get data from the audio manager\n", __LINE__);
918 bExitOnError = OMX_TRUE;
919 goto EXIT;
920 }
921 audioinfo->streamId = cmd_data.streamID;
922 #endif
923
924 error = OMX_SetConfig (pHandle, index, audioinfo);
925 if(error != OMX_ErrorNone) {
926 error = OMX_ErrorBadParameter;
927 APP_DPRINT("%d :: Error from OMX_SetConfig() function\n",__LINE__);
928 bExitOnError = OMX_TRUE;
929 goto EXIT;
930 /* TODO: should be sure resources are cleaned up at any of the goto EXIT statements */
931 }
932
933 error = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.g729.datapath",&index);
934 if (error != OMX_ErrorNone) {
935 printf("Error getting extension index\n");
936 bExitOnError = OMX_TRUE;
937 goto EXIT;
938 }
939
940
941 error = OMX_SetConfig (pHandle, index, &dataPath);
942 if(error != OMX_ErrorNone) {
943 error = OMX_ErrorBadParameter;
944 APP_DPRINT("%d :: G729DecTest.c :: Error from OMX_SetConfig() function\n",__LINE__);
945 bExitOnError = OMX_TRUE;
946 goto EXIT;
947 }
948
949 #ifdef OMX_GETTIME
950 GT_START();
951 #endif
952
953 error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
954 if(error != OMX_ErrorNone) {
955 APP_DPRINT ("Error from SendCommand-Idle(Init) State function\n");
956 bExitOnError = OMX_TRUE;
957 goto EXIT;
958 }
959 /* Wait for startup to complete */
960 error = WaitForState(pHandle, OMX_StateIdle);
961 #ifdef OMX_GETTIME
962 GT_END("Call to SendCommand <OMX_StateIdle>");
963 #endif
964 if(error != OMX_ErrorNone) {
965 APP_DPRINT( "Error: hG729Decoder->WaitForState reports an error %X\n", error);
966 bExitOnError = OMX_TRUE;
967 goto EXIT;
968 }
969 for(i = 0; i < testcnt; i++) { /* PROCESS LOOP */
970 if(i > 0) {
971 printf ("Decoding the file for %d Time\n",i+1);
972 close(IpBuf_Pipe[0]);
973 close(IpBuf_Pipe[1]);
974 close(OpBuf_Pipe[0]);
975 close(OpBuf_Pipe[1]);
976
977 /* Create a pipe used to queue data from the callback. */
978 retval = pipe(IpBuf_Pipe);
979 if( retval != 0) {
980 APP_DPRINT( "Error:Fill Data Pipe failed to open\n");
981 bExitOnError = OMX_TRUE;
982 goto EXIT;
983 }
984
985 retval = pipe(OpBuf_Pipe);
986 if( retval != 0) {
987 APP_DPRINT( "Error:Empty Data Pipe failed to open\n");
988 bExitOnError = OMX_TRUE;
989 goto EXIT;
990 }
991
992 /* Open the input file for decoding */
993 fIn = fopen(argv[1], "r");
994 fp= fopen(argv[1], "r");
995 if(fIn == NULL) {
996 fprintf(stderr, "Error: failed to open the file %s for readonly access\n", argv[1]);
997 bExitOnError = OMX_TRUE;
998 goto EXIT;
999 }
1000
1001 /* Open the output file only in non DASF mode */
1002 if(audioinfo->dasfMode == 0){
1003 fOut = fopen(argv[2], "w");
1004 if(fOut == NULL) {
1005 fprintf(stderr, "Error: failed to create the output file \n");
1006 bExitOnError = OMX_TRUE;
1007 goto EXIT;
1008 }
1009 }
1010 }
1011 printf ("Basic Function:: Sending OMX_StateExecuting Command\n");
1012 #ifdef OMX_GETTIME
1013 GT_START();
1014 #endif
1015 error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
1016 if(error != OMX_ErrorNone) {
1017 APP_DPRINT ("Error from SendCommand-Executing State function\n");
1018 bExitOnError = OMX_TRUE;
1019 goto EXIT;
1020 }
1021 pComponent = (OMX_COMPONENTTYPE *)pHandle;
1022 error = pComponent->GetState(pHandle, &state);
1023 error = WaitForState(pHandle, OMX_StateExecuting);
1024 #ifdef OMX_GETTIME
1025 GT_END("Call to SendCommand <OMX_StateExecuting>");
1026 #endif
1027 if(error != OMX_ErrorNone) {
1028 APP_DPRINT( "Error: hG729Decoder->WaitForState reports an error %X\n", error);
1029 bExitOnError = OMX_TRUE;
1030 goto EXIT;
1031 }
1032
1033 InputCallbacksPending = 0;
1034 for (k=0; k < numInputBuffers; k++) {
1035 pInputBufferHeader[k]->nFlags = 0;
1036
1037 #ifdef OMX_GETTIME
1038 if (k==0)
1039 {
1040 GT_FlagE=1; /* 1 = First Buffer, 0 = Not First Buffer */
1041 GT_START(); /* Empty Bufffer */
1042 }
1043 #endif
1044
1045 error = send_input_buffer (pHandle, pInputBufferHeader[k], fIn);
1046 }
1047
1048 if (audioinfo->dasfMode == 0) {
1049 for (k=0; k < numOutputBuffers; k++) {
1050 pOutputBufferHeader[k]->nFlags = 0;
1051
1052 #ifdef OMX_GETTIME
1053 if (k==0)
1054 {
1055 GT_FlagF=1; /* 1 = First Buffer, 0 = Not First Buffer */
1056 GT_START(); /* Fill Buffer */
1057 }
1058 #endif
1059
1060 pComponent->FillThisBuffer(pHandle, pOutputBufferHeader[k]);
1061 }
1062 }
1063 error = pComponent->GetState(pHandle, &state);
1064 retval = 1;
1065 SendInputBuffer = 0;
1066 EOFevent = 0;
1067 frmCount = 0;
1068 OutBufCount = 0;
1069 InBufCount = 0;
1070 while( (error == OMX_ErrorNone) && ((state != OMX_StateIdle) || (retval>0)) ) {
1071 FD_ZERO(&rfds);
1072 FD_SET(IpBuf_Pipe[0], &rfds);
1073 FD_SET(OpBuf_Pipe[0], &rfds);
1074 tv.tv_sec = 1;
1075 tv.tv_usec = 0;
1076
1077 retval = select(fdmax+1, &rfds, NULL, NULL, &tv);
1078 if(retval == -1) {
1079 perror("select()");
1080 printf ( " : Error \n");
1081 break;
1082 }
1083 APP_DPRINT("Input Callbacks pending = %d, Output Last Pending = %d\n", InputCallbacksPending, OutputLastPending);
1084 if( (retval == 0) && (InputCallbacksPending < 1) && (!OutputLastPending) ) {
1085 APP_DPRINT ("%d :: BasicFn App Timeout !!!!!!!!!!! \n",__LINE__);
1086 fprintf(stderr, "Shutting down Since there is nothing else to send nor read---------- \n");
1087 StopComponent(pHandle);
1088 }
1089
1090 /* FREE input buffer */
1091 if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {
1092 read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
1093 InputCallbacksPending--;
1094 InBufCount++;
1095 frmCount+=packetsPerBuffer;
1096 APP_DPRINT("frame count = %d\n", frmCount);
1097 if(pBuffer->nFlags==1){ /* Last input buffer received by App */
1098 InputCallbacksPending = 0;
1099 }
1100 if( ((2==command) || (4==command)) && (600 == frmCount)){ /*Stop Tests*/
1101 fprintf(stderr, "Send STOP Command to component ---------- \n");
1102 StopComponent(pHandle);
1103 }
1104
1105 pBuffer->nFlags = 0;
1106
1107 if (state == OMX_StateExecuting){
1108 if(!EOFevent){
1109 error = send_input_buffer (pHandle, pBuffer, fIn);
1110 }
1111 else{
1112 printf("EOF, not sending input\n");
1113 }
1114 if (error != OMX_ErrorNone) {
1115 bExitOnError = OMX_TRUE;
1116 goto EXIT;
1117 }
1118 }
1119
1120 if(3 == command){ /*Pause Test*/
1121 if(frmCount == 100) { /*100 Frames processed */
1122 printf (" Sending Pause command to Codec \n");
1123 PauseComponent(pHandle);
1124 printf("5 secs sleep...\n");
1125 sleep(5);
1126 printf (" Sending Resume command to Codec \n");
1127 PlayComponent(pHandle);
1128 }
1129 }
1130 else if ( 7 == command ){ /*Mute and UnMuteTest*/
1131 if(frmCount == 100){
1132 printf("************Mute the playback stream*****************\n");
1133 pCompPrivateStructMute->bMute = OMX_TRUE;
1134 error = OMX_SetConfig(pHandle, OMX_IndexConfigAudioMute, pCompPrivateStructMute);
1135 if (error != OMX_ErrorNone)
1136 {
1137 error = OMX_ErrorBadParameter;
1138 bExitOnError = OMX_TRUE;
1139 goto EXIT;
1140 }
1141 }
1142 else if(frmCount == 400) {
1143 printf("************Unmute the playback stream*****************\n");
1144 pCompPrivateStructMute->bMute = OMX_FALSE;
1145 error = OMX_SetConfig(pHandle, OMX_IndexConfigAudioMute, pCompPrivateStructMute);
1146 if (error != OMX_ErrorNone) {
1147 error = OMX_ErrorBadParameter;
1148 bExitOnError = OMX_TRUE;
1149 goto EXIT;
1150 }
1151 }
1152 }
1153 else if ( 8 == command ) { /*Set Volume Test*/
1154 if(frmCount == 600){
1155 printf("************Set stream volume to high*****************\n");
1156 pCompPrivateStructVolume->sVolume.nValue = 0x7500;
1157 error = OMX_SetConfig(pHandle, OMX_IndexConfigAudioVolume, pCompPrivateStructVolume);
1158 if (error != OMX_ErrorNone) {
1159 error = OMX_ErrorBadParameter;
1160 bExitOnError = OMX_TRUE;
1161 goto EXIT;
1162 }
1163 }
1164 else if(frmCount == 1200) {
1165 printf("************Set stream volume to low*****************\n");
1166 pCompPrivateStructVolume->sVolume.nValue = 0x2500;
1167 error = OMX_SetConfig(pHandle, OMX_IndexConfigAudioVolume, pCompPrivateStructVolume);
1168 if (error != OMX_ErrorNone) {
1169 error = OMX_ErrorBadParameter;
1170 bExitOnError = OMX_TRUE;
1171 goto EXIT;
1172 }
1173 }
1174 }
1175 }
1176
1177 if( FD_ISSET(OpBuf_Pipe[0], &rfds)) {
1178 read(OpBuf_Pipe[0], &pBuf, sizeof(pBuf));
1179 APP_DPRINT("reading from output buffer pipe\n");
1180 OutBufCount++;
1181 if ((state != OMX_StateExecuting) && (pBuf->nFilledLen > 0)){
1182 printf("Writing remaining output buffer\n");
1183 }
1184 APP_DPRINT ("FWRITE output buffer of size %d\n",pBuf->nFilledLen);
1185 if(pBuf->nFlags!=1){
1186 fwrite(pBuf->pBuffer, 1, pBuf->nFilledLen, fOut);
1187 fflush(fOut);
1188 if (state == OMX_StateExecuting ) {
1189 pComponent->FillThisBuffer(pHandle, pBuf);
1190 }
1191 }
1192 else{/* Last output frame = dummy frame from DSP */
1193 OutputLastPending = 0;
1194 InputCallbacksPending = 0;
1195 pBuf->nFlags = 0;
1196 }
1197 }
1198 error = pComponent->GetState(pHandle, &state);
1199 if(error != OMX_ErrorNone) {
1200 printf("%d:: Warning: hG729Decoder->GetState has returned status %X\n", __LINE__, error);
1201 bExitOnError = OMX_TRUE;
1202 goto EXIT;
1203 }
1204 } /* While Loop Ending Here */
1205 if(audioinfo->dasfMode == 0){
1206 fclose(fOut);
1207 }
1208 fclose(fIn);
1209 fclose(fp);
1210 printf("Number of free input buffers received by test app. : %d\n",InBufCount);
1211 printf("Number of free output buffers received by test app. : %d\n",OutBufCount);
1212 if((command == 2) || (( command == 5)&&(audioinfo->dasfMode == 0)) || (( command == 6)&&(audioinfo->dasfMode == 0))) {
1213 sleep (2);
1214 }
1215 } /*Inner for loop ends here */
1216
1217
1218 printf("Free buffers\n");
1219 /* free buffers */
1220 for (i=0; i < numInputBuffers; i++) {
1221 error = OMX_FreeBuffer(pHandle,OMX_DirInput,pInputBufferHeader[i]);
1222 if( (error != OMX_ErrorNone)) {
1223 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
1224 bExitOnError = OMX_TRUE;
1225 goto EXIT;
1226 }
1227 if(pInBufferParam[i] != NULL){
1228 free(pInBufferParam[i]);
1229 pInBufferParam[i] = NULL;
1230 }
1231 }
1232 for (i=0; i < numOutputBuffers; i++) {
1233 error = OMX_FreeBuffer(pHandle,OMX_DirOutput,pOutputBufferHeader[i]);
1234 if( (error != OMX_ErrorNone)) {
1235 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
1236 bExitOnError = OMX_TRUE;
1237 goto EXIT;
1238 }
1239 }
1240
1241 #ifdef USE_BUFFER
1242 /* free the App Allocated Buffers */
1243 printf("%d :: App: Freeing the App Allocated Buffers in TestApp\n",__LINE__);
1244 for(i=0; i < numInputBuffers; i++) {
1245 pInputBuffer[i] = pInputBuffer[i] - CACHE_ALIGNMENT;
1246 APP_MEMPRINT("%d :: App: [TESTAPPFREE] pInputBuffer[%d] = %p\n",__LINE__,i,pInputBuffer[i]);
1247 if(pInputBuffer[i] != NULL){
1248 free(pInputBuffer[i]);
1249 pInputBuffer[i] = NULL;;
1250 }
1251
1252 }
1253
1254 for(i=0; i < numOutputBuffers; i++) {
1255 pOutputBuffer[i] = pOutputBuffer[i] - 128;
1256 APP_MEMPRINT("%d :: App: [TESTAPPFREE] pOutputBuffer[%d] = %p\n",__LINE__,i, pOutputBuffer[i]);
1257 if(pOutputBuffer[i] != NULL){
1258 free(pOutputBuffer[i]);
1259 pOutputBuffer[i] = NULL;
1260 }
1261 }
1262 #endif
1263 printf ("Sending the StateLoaded Command\n");
1264
1265 #ifdef OMX_GETTIME
1266 GT_START();
1267 #endif
1268
1269 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateLoaded, NULL);
1270 error = WaitForState(pHandle, OMX_StateLoaded);
1271 #ifdef OMX_GETTIME
1272 GT_END("Call to SendCommand <OMX_StateLoaded>");
1273 #endif
1274
1275 if(error != OMX_ErrorNone) {
1276 APP_DPRINT ("%d:: Error from SendCommand-Idle State function\n",__LINE__);
1277 bExitOnError = OMX_TRUE;
1278 goto EXIT;
1279 }
1280
1281 error = OMX_SendCommand(pHandle, OMX_CommandPortDisable, -1, NULL);
1282
1283 printf ("Free the Component handle\n");
1284 /* Unload the G729 Decoder Component */
1285 error = TIOMX_FreeHandle(pHandle);
1286 if( (error != OMX_ErrorNone)) {
1287 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
1288 goto EXIT;
1289 }
1290 APP_DPRINT ("%d:: Free Handle returned Successfully \n\n\n\n",__LINE__);
1291 free(pG729Param);
1292 free(pPcmParam);
1293 free(pCompPrivateStruct);
1294 free(pCompPrivateStructMute);
1295 free(pCompPrivateStructVolume);
1296 close(IpBuf_Pipe[0]);
1297 close(IpBuf_Pipe[1]);
1298 close(OpBuf_Pipe[0]);
1299 close(OpBuf_Pipe[1]);
1300 APP_DPRINT("Freed resources successfully\n");
1301 } /*Outer for loop ends here */
1302 free(audioinfo);
1303
1304 /* De-Initialize OMX Core */
1305 error = TIOMX_Deinit();
1306 if (error != OMX_ErrorNone) {
1307 printf("APP::Failed to de-init OMX Core!\n");
1308 }
1309
1310 #ifdef DSP_RENDERING_ON
1311 cmd_data.hComponent = pHandle;
1312 cmd_data.AM_Cmd = AM_Exit;
1313 if((write(g729decfdwrite, &cmd_data, sizeof(cmd_data)))<0)
1314 {
1315 printf("%d ::OMX_G729Decoder.c :: [G729 Dec Component] - send command to audio manager\n",__LINE__);
1316 }
1317 close(g729decfdwrite);
1318 close(g729decfdread);
1319 #endif
1320
1321 EXIT:
1322
1323 if (bExitOnError){
1324 #ifdef USE_BUFFER
1325 FreeResources(pG729Param, pPcmParam, pCompPrivateStruct,
1326 pCompPrivateStructMute, pCompPrivateStructVolume,
1327 audioinfo, pInputBuffer, pOutputBuffer, pInBufferParam, pHandle);
1328 #else
1329
1330 FreeResources(pG729Param, pPcmParam, pCompPrivateStruct,
1331 pCompPrivateStructMute, pCompPrivateStructVolume,
1332 audioinfo, pInputBufferHeader, pOutputBufferHeader, pInBufferParam, pHandle);
1333 #endif
1334 error = TIOMX_FreeHandle(pHandle);
1335 if( (error != OMX_ErrorNone)) {
1336 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
1337 goto EXIT;
1338 }
1339 }
1340
1341 #ifdef OMX_GETTIME
1342 GT_END("G729_DEC test <End>");
1343 OMX_ListDestroy(pListHead);
1344 #endif
1345
1346 #ifdef MTRACE
1347 muntrace();
1348 #endif
1349
1350 return error;
1351 }
1352
send_input_buffer(OMX_HANDLETYPE pHandle,OMX_BUFFERHEADERTYPE * pBuffer,FILE * fIn)1353 OMX_ERRORTYPE send_input_buffer(OMX_HANDLETYPE pHandle, OMX_BUFFERHEADERTYPE* pBuffer, FILE *fIn)
1354 {
1355 OMX_ERRORTYPE error = OMX_ErrorNone;
1356 OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
1357 OMX_S16 status = 0;
1358
1359 status = fill_data_fromFile (pBuffer, fIn, pHandle);
1360 pBuffer->nTimeStamp = (OMX_S64) rand() % 70;
1361 pBuffer->nTickCount = (OMX_S64) rand() % 70;
1362 if (command == 0){
1363 APP_DPRINT("SENDING TIMESTAMP = %d\n", (int) pBuffer->nTimeStamp);
1364 APP_DPRINT("SENDING TICK COUNT = %ld\n", pBuffer->nTickCount);
1365 }
1366 if(status>=0){
1367 SendInputBuffer++;
1368 InputCallbacksPending++;
1369 pComponent->EmptyThisBuffer(pHandle, pBuffer);
1370 }
1371 else{
1372 error = OMX_ErrorStreamCorrupt;
1373 }
1374 return error;
1375 }
1376
1377
1378 /* ===========================================================================*/
1379 /**
1380 * @fn fill_data_fromFile fills input buffer with 1 G729 frame from input test file
1381 * Conversion from ITU format to frame type header + G729 packet
1382 *
1383 */
1384 /* ===========================================================================*/
fill_data_fromFile(OMX_BUFFERHEADERTYPE * pBuf,FILE * fIn,OMX_HANDLETYPE pHandle)1385 OMX_S16 fill_data_fromFile (OMX_BUFFERHEADERTYPE *pBuf, FILE *fIn, OMX_HANDLETYPE pHandle)
1386 {
1387 OMX_S16 nRead = 0;
1388 OMX_S16 nRead2 = 0;
1389 OMX_S16 dRead = 0;
1390 OMX_S16 j = 0, n = 0, k = 0, m = 0;
1391 /* BFI + number of bit in frame + serial bitstream */
1392 OMX_S16 serial[ITU_INPUT_SIZE];
1393 /* G729 frame type */
1394 OMX_S16 frame_type = 0;
1395 /* Number of data bytes in packet */
1396 OMX_U32 nBytes = 0;
1397 /* G729 packet */
1398 OMX_U8 *packet = NULL;
1399 /* Offset in bytes in input buffer */
1400 OMX_U8 offset = 0;
1401 G729DEC_BufParamStruct* pBufStructTemp = (G729DEC_BufParamStruct*)pBuf->pInputPortPrivate;
1402
1403
1404 pBufStructTemp->frameLost = 0;
1405 pBufStructTemp->numPackets = packetsPerBuffer;
1406 pBufStructTemp->bNoUseDefaults = OMX_TRUE;
1407 pBuf->nFilledLen = 0;
1408 pBuf->nFlags = 0;
1409 for(j = 0; j < packetsPerBuffer; j++){ /* nb packets in input buffer */
1410
1411 nRead2=fread(serial, sizeof(OMX_S16), 2 , fp); //this is temporary
1412 /* read BFI and number of bits in frame */
1413 nRead = fread(serial, sizeof(OMX_S16), 2 , fIn);
1414 if(nRead != 0){
1415 /* Number of data bytes in packet */
1416 nBytes = serial[1]>>3;
1417 pBufStructTemp->packetLength[j] = nBytes + 1;
1418 pBuf->nFilledLen += pBufStructTemp->packetLength[j];
1419 /* read ITU serial bitstream */
1420 dRead = fread(&serial[2], sizeof(OMX_S16), serial[1], fIn);
1421 if(dRead != serial[1]){
1422 printf("WARN: Error in input file\n");
1423 dRead = -1; /*error flag */
1424 }
1425 /* set frame type */
1426 switch(nBytes){
1427 case G729SPEECHPACKETSIZE:
1428 frame_type = SPEECH_FRAME_TYPE;
1429 break;
1430 case G729SIDPACKETSIZE:
1431 frame_type = SID_FRAME_TYPE;
1432 break;
1433 case NO_TX_FRAME_TYPE:
1434 frame_type = NO_TX_FRAME_TYPE;
1435 break;
1436 default:
1437 frame_type = ERASURE_FRAME;
1438 }
1439 if(serial[0]!= SYNC_WORD){ /* Untransmitted frame => Frame erasure flag */
1440 frame_type = ERASURE_FRAME;
1441 }
1442 /* Add G729 frame type header to G729 input packet */
1443 *((OMX_U8 *)(&pBuf->pBuffer[0]+offset)) = frame_type;
1444
1445 /* Convert ITU format to bitstream */
1446 packet = (OMX_U8 *)(&pBuf->pBuffer[0]+offset+1);
1447 if(frame_type == SPEECH_FRAME_TYPE){
1448 n = 2;
1449 k = 0;
1450 while(n<SPEECH_FRAME_SIZE){
1451 packet[k] = 0;
1452 for(m=7;m>=0;m--){
1453 serial[n] = (~(serial[n]) & 0x2)>>1;
1454 packet[k] = packet[k] + (serial[n]<<m);
1455 n++;
1456 }
1457 k++;
1458 }
1459 }
1460 if(frame_type == SID_FRAME_TYPE){
1461 n = 2;
1462 k = 0;
1463 while(n<SID_OCTET_FRAME_SIZE){
1464 packet[k] = 0;
1465 for(m=7;m>=0;m--){
1466 serial[n] = (~(serial[n]) & 0x2)>>1;
1467 packet[k] = packet[k] + (serial[n]<<m);
1468 n++;
1469 }
1470 k++;
1471 }
1472 }
1473 offset = offset + nBytes + 1;
1474 }
1475 else{
1476 if(offset == 0){/* End of file on a dummy frame */
1477 /* Set flag on input buffer to indicate Last Frame */
1478 pBuf->nFlags=OMX_BUFFERFLAG_EOS;
1479 /* Dummy buffer (no data) */
1480 pBuf->nFilledLen = 0;
1481 EOFevent = 1;
1482 printf("End of file on a dummy frame \n");
1483 }
1484 else{/* End of file on valid frame */
1485 pBuf->nFlags=OMX_BUFFERFLAG_EOS;
1486 EOFevent = 1;
1487 printf("End of file on a valid frame \n");
1488 }
1489 if(dasfMode==0){
1490 OutputLastPending = 1;
1491 }
1492 j = packetsPerBuffer; /* break */
1493 }
1494 }
1495 return dRead;
1496 }
1497
ConfigureAudio()1498 void ConfigureAudio()
1499 {
1500 int Mixer = 0, arg = 0, status = 0;
1501
1502 Mixer = open("/dev/sound/mixer", O_WRONLY);
1503 if (Mixer < 0) {
1504 perror("open of /dev/sound/mixer failed");
1505 exit(1);
1506 }
1507 arg = G729DEC_SAMPLING_FREQUENCY; /* sampling rate */
1508 printf("Sampling freq set to:%d\n",arg);
1509 status = ioctl(Mixer, SOUND_PCM_WRITE_RATE, &arg);
1510 if (status == -1) {
1511 perror("SOUND_PCM_WRITE_RATE ioctl failed");
1512 printf("sample rate set to %u\n", arg);
1513 }
1514 arg = AFMT_S16_LE; /* AFMT_S16_LE or AFMT_S32_LE */
1515 status = ioctl(Mixer, SOUND_PCM_SETFMT, &arg);
1516 if (status == -1) {
1517 perror("SOUND_PCM_SETFMT ioctl failed");
1518 printf("Bitsize set to %u\n", arg);
1519 }
1520 arg = 2; /* Channels mono 1 stereo 2 */
1521 status = ioctl(Mixer, SOUND_PCM_WRITE_CHANNELS, &arg);
1522 if (status == -1) {
1523 perror("SOUND_PCM_WRITE_CHANNELS ioctl failed");
1524 printf("Channels set to %u\n", arg);
1525 }
1526 arg = GAIN<<8|GAIN;
1527 status = ioctl(Mixer, SOUND_MIXER_WRITE_VOLUME, &arg);
1528 if (status == -1) {
1529 perror("SOUND_MIXER_WRITE_VOLUME ioctl failed");
1530 printf("Volume set to %u\n", arg);
1531 }
1532 }
1533
StopComponent(OMX_HANDLETYPE * pHandle)1534 OMX_ERRORTYPE StopComponent(OMX_HANDLETYPE *pHandle)
1535 {
1536 OMX_ERRORTYPE error = OMX_ErrorNone;
1537
1538 #ifdef OMX_GETTIME
1539 GT_START();
1540 #endif
1541
1542 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);
1543 if(error != OMX_ErrorNone) {
1544 fprintf (stderr,"\nError from SendCommand-Idle(Stop) State function!!!!!!!!\n");
1545 goto EXIT;
1546 }
1547 error = WaitForState(pHandle, OMX_StateIdle);
1548
1549 #ifdef OMX_GETTIME
1550 GT_END("Call to SendCommand <OMX_StateIdle>");
1551 #endif
1552
1553 if(error != OMX_ErrorNone) {
1554 fprintf(stderr, "\nError: hG729Decoder->WaitForState reports an error %X!!!!!!!\n", error);
1555 goto EXIT;
1556 }
1557 EXIT:
1558 return error;
1559 }
1560
PauseComponent(OMX_HANDLETYPE * pHandle)1561 OMX_ERRORTYPE PauseComponent(OMX_HANDLETYPE *pHandle)
1562 {
1563 OMX_ERRORTYPE error = OMX_ErrorNone;
1564
1565 #ifdef OMX_GETTIME
1566 GT_START();
1567 #endif
1568
1569 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StatePause, NULL);
1570 if(error != OMX_ErrorNone) {
1571 fprintf (stderr,"\nError from SendCommand-Pasue State function!!!!!!\n");
1572 goto EXIT;
1573 }
1574 error = WaitForState(pHandle, OMX_StatePause);
1575
1576 #ifdef OMX_GETTIME
1577 GT_END("Call to SendCommand <OMX_StatePause>");
1578 #endif
1579
1580 if(error != OMX_ErrorNone) {
1581 fprintf(stderr, "\nError: hG729Decoder->WaitForState reports an error %X!!!!!!!\n", error);
1582 goto EXIT;
1583 }
1584 EXIT:
1585 return error;
1586 }
1587
PlayComponent(OMX_HANDLETYPE * pHandle)1588 OMX_ERRORTYPE PlayComponent(OMX_HANDLETYPE *pHandle)
1589 {
1590 OMX_ERRORTYPE error = OMX_ErrorNone;
1591 #ifdef OMX_GETTIME
1592 GT_START();
1593 #endif
1594 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateExecuting, NULL);
1595 if(error != OMX_ErrorNone) {
1596 fprintf (stderr,"\nError from SendCommand-Executing State function!!!!!!!\n");
1597 goto EXIT;
1598 }
1599 error = WaitForState(pHandle, OMX_StateExecuting);
1600 #ifdef OMX_GETTIME
1601 GT_END("Call to SendCommand <OMX_StateExecuting>");
1602 #endif
1603 if(error != OMX_ErrorNone) {
1604 fprintf(stderr, "\nError: hG729Decoder->WaitForState reports an error %X!!!!!!!\n", error);
1605 goto EXIT;
1606 }
1607 EXIT:
1608 return error;
1609 }
1610
1611 #ifdef USE_BUFFER
FreeResources(OMX_AUDIO_PARAM_G729TYPE * pG729Param,OMX_AUDIO_PARAM_PCMMODETYPE * pPcmParam,OMX_PARAM_PORTDEFINITIONTYPE * pCompPrivateStruct,OMX_AUDIO_CONFIG_MUTETYPE * pCompPrivateStructMute,OMX_AUDIO_CONFIG_VOLUMETYPE * pCompPrivateStructVolume,TI_OMX_DSP_DEFINITION * audioinfo,OMX_U8 * pInputBuffer[10],OMX_U8 * pOutputBuffer[10],G729DEC_BufParamStruct * pInBufferParam[10],OMX_HANDLETYPE * pHandle)1612 OMX_ERRORTYPE FreeResources(OMX_AUDIO_PARAM_G729TYPE* pG729Param,
1613 OMX_AUDIO_PARAM_PCMMODETYPE* pPcmParam,
1614 OMX_PARAM_PORTDEFINITIONTYPE* pCompPrivateStruct,
1615 OMX_AUDIO_CONFIG_MUTETYPE* pCompPrivateStructMute,
1616 OMX_AUDIO_CONFIG_VOLUMETYPE* pCompPrivateStructVolume,
1617 TI_OMX_DSP_DEFINITION* audioinfo,
1618 OMX_U8* pInputBuffer[10],
1619 OMX_U8* pOutputBuffer[10],
1620 G729DEC_BufParamStruct* pInBufferParam[10],
1621 OMX_HANDLETYPE* pHandle)
1622 {
1623 OMX_ERRORTYPE eError = OMX_ErrorNone;
1624 int i = 0;
1625
1626 printf("Free buffers\n");
1627 /* free buffers */
1628 for (i=0; i < numInputBuffers; i++) {
1629 eError = OMX_FreeBuffer(pHandle,OMX_DirInput,pInputBufferHeader[i]);
1630 if( (eError != OMX_ErrorNone)) {
1631 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
1632 goto EXIT;
1633 }
1634 if(pInBufferParam[i] != NULL){
1635 free(pInBufferParam[i]);
1636 pInBufferParam[i] = NULL;
1637 }
1638 }
1639
1640 for (i=0; i < numOutputBuffers; i++) {
1641 eError = OMX_FreeBuffer(pHandle,OMX_DirOutput,pOutputBufferHeader[i]);
1642 if( (eError != OMX_ErrorNone)) {
1643 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
1644 printf("%d:: Error in Free Handle function\n",__LINE__);
1645 goto EXIT;
1646 }
1647 }
1648 free(pG729Param);
1649 free(pPcmParam);
1650 free(pCompPrivateStruct);
1651 free(pCompPrivateStructMute);
1652 free(pCompPrivateStructVolume);
1653
1654 close(IpBuf_Pipe[0]);
1655 close(IpBuf_Pipe[1]);
1656 close(OpBuf_Pipe[0]);
1657 close(OpBuf_Pipe[1]);
1658 free(audioinfo);
1659
1660 EXIT:
1661 return eError;
1662 }
1663
1664 #else
1665
FreeResources(OMX_AUDIO_PARAM_G729TYPE * pG729Param,OMX_AUDIO_PARAM_PCMMODETYPE * pPcmParam,OMX_PARAM_PORTDEFINITIONTYPE * pCompPrivateStruct,OMX_AUDIO_CONFIG_MUTETYPE * pCompPrivateStructMute,OMX_AUDIO_CONFIG_VOLUMETYPE * pCompPrivateStructVolume,TI_OMX_DSP_DEFINITION * audioinfo,OMX_BUFFERHEADERTYPE * pInputBufferHeader[10],OMX_BUFFERHEADERTYPE * pOutputBufferHeader[10],G729DEC_BufParamStruct * pInBufferParam[10],OMX_HANDLETYPE * pHandle)1666 OMX_ERRORTYPE FreeResources(OMX_AUDIO_PARAM_G729TYPE* pG729Param,
1667 OMX_AUDIO_PARAM_PCMMODETYPE* pPcmParam,
1668 OMX_PARAM_PORTDEFINITIONTYPE* pCompPrivateStruct,
1669 OMX_AUDIO_CONFIG_MUTETYPE* pCompPrivateStructMute,
1670 OMX_AUDIO_CONFIG_VOLUMETYPE* pCompPrivateStructVolume,
1671 TI_OMX_DSP_DEFINITION* audioinfo,
1672 OMX_BUFFERHEADERTYPE* pInputBufferHeader[10],
1673 OMX_BUFFERHEADERTYPE* pOutputBufferHeader[10],
1674 G729DEC_BufParamStruct* pInBufferParam[10],
1675 OMX_HANDLETYPE* pHandle)
1676 {
1677 OMX_ERRORTYPE eError = OMX_ErrorNone;
1678 int i = 0;
1679
1680 printf("Free buffers\n");
1681 /* free buffers */
1682 for (i=0; i < numInputBuffers; i++) {
1683 eError = OMX_FreeBuffer(pHandle,OMX_DirInput,pInputBufferHeader[i]);
1684 if( (eError != OMX_ErrorNone)) {
1685 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
1686 goto EXIT;
1687 }
1688 if(pInBufferParam[i] != NULL){
1689 free(pInBufferParam[i]);
1690 pInBufferParam[i] = NULL;
1691 }
1692 }
1693 for (i=0; i < numOutputBuffers; i++) {
1694 eError = OMX_FreeBuffer(pHandle,OMX_DirOutput,pOutputBufferHeader[i]);
1695 if( (eError != OMX_ErrorNone)) {
1696 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
1697 printf("%d:: Error in Free Handle function\n",__LINE__);
1698 goto EXIT;
1699 }
1700 }
1701 free(pG729Param);
1702 free(pPcmParam);
1703 free(pCompPrivateStruct);
1704 free(pCompPrivateStructMute);
1705 free(pCompPrivateStructVolume);
1706 close(IpBuf_Pipe[0]);
1707 close(IpBuf_Pipe[1]);
1708 close(OpBuf_Pipe[0]);
1709 close(OpBuf_Pipe[1]);
1710 free(audioinfo);
1711
1712 EXIT:
1713 return eError;
1714 }
1715 #endif
1716