1
2 /*
3 * Copyright 2001-2008 Texas Instruments - http://www.ti.com/
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 /* =============================================================================
18 * Texas Instruments OMAP (TM) Platform Software
19 * (c) Copyright Texas Instruments, Incorporated. All Rights Reserved.
20 *
21 * Use of this software is controlled by the terms and conditions found
22 * in the license agreement under which this software has been supplied.
23 * =========================================================================== */
24 /**
25 * @file OMX_G722DecTest.c
26 *
27 * This file contains the test application code that invokes the component.
28 *
29 * @path $(CSLPATH)\OMAPSW_MPU\linux\audio\src\openmax_il\g722_dec\tests
30 *
31 * @rev 1.0
32 */
33 /* ----------------------------------------------------------------------------
34 *!
35 *! Revision History
36 *! ===================================
37 *! This is newest file
38 * =========================================================================== */
39 /* ------compilation control switches -------------------------*/
40 /*#define APP_DEBUG **/
41 /*#undef APP_DEBUG **/
42 /*undef OMX_GETTIME */
43
44 /*#define G722DEC_DEBUG*/
45 /*#define APP_DEBUG*/
46 /*#define APP_STATEDETAILS*/
47 /*#define WAITFORRESOURCES*/
48 #undef USE_BUFFER
49 /****************************************************************
50 * INCLUDE FILES
51 ****************************************************************/
52 /* ----- system and platform files ----------------------------*/
53 #include <unistd.h>
54 #include <stdlib.h>
55 #include <sys/ioctl.h>
56 #include <sys/select.h>
57 #include <string.h>
58 #include <stdio.h>
59 #include <fcntl.h>
60 #include <errno.h>
61 #include <signal.h>
62 #include <sys/stat.h>
63 #include <OMX_Index.h>
64 #include <OMX_Types.h>
65 #include <OMX_Core.h>
66 #include <OMX_Audio.h>
67 #include <TIDspOmx.h>
68 #include <pthread.h>
69 #include <linux/soundcard.h>
70 typedef enum {FALSE, TRUE} boolean;
71 #include <OMX_G722Dec_Utils.h>
72
73
74 #ifdef OMX_GETTIME
75 #include <OMX_Common_Utils.h>
76 #include <OMX_GetTime.h> /*Headers for Performance & measuremet */
77 #endif
78
79 #ifdef APP_DEBUG
80 #define APP_DPRINT(...) fprintf(stderr,__VA_ARGS__)
81 #else
82 #define APP_DPRINT(...) /*0j0 printf (__VA_ARGS__)*/
83 #endif
84
85 #ifdef APP_STATEDETAILS
86 #define APP_STATEPRINT(...) fprintf(stderr,__VA_ARGS__)
87 #else
88 #define APP_STATEPRINT(...) /*0j0 printf (__VA_ARGS__)*/
89 #endif
90
91 /* Constants */
92 #define APP_OUTPUT_FILE "output" /*.pcm"*/
93 #define SLEEP_TIME 2
94 #define G722_APP_ID 100 /* Defines G722 Dec App ID, App must use this value */
95 #define INVALID_SAMPLING_FREQ 51 /*Do not change; fixed for component!*/
96 #define MAX_NUM_OF_BUFS 10 /*Do not change; fixed for component!*/
97 #define EOS_MIN_SIZE 2
98 #define FIFO1 "/dev/fifo.1"
99 #define FIFO2 "/dev/fifo.2"
100 #define STR_G722DECODER "OMX.TI.G722.decode"
101
102 #ifdef APP_DEBUG
103 #define N_REPETITIONS 5
104 #else
105 #define N_REPETITIONS 20
106 #endif
107
108 /* undef OMX_GETTIME */
109 #ifdef OMX_GETTIME
110 /* OMX_ERRORTYPE eError = OMX_ErrorNone;*/
111 int GT_FlagE = 0; /* Fill Buffer 1 = First Buffer, 0 = Not First Buffer */
112 int GT_FlagF = 0; /*Empty Buffer 1 = First Buffer, 0 = Not First Buffer */
113 static OMX_NODE* pListHead = NULL;
114 #endif
115
116 /*typedef enum {FALSE, TRUE} boolean;*/
117
118 /* Prototypes */
119 boolean validateArguments (int, char *[], int *, char *, int *, int *, int *, int *, int *, int *);
120 int maxint (int a, int b);
121 static OMX_ERRORTYPE WaitForState (OMX_HANDLETYPE *, OMX_STATETYPE);
122 OMX_ERRORTYPE EventHandler (OMX_HANDLETYPE, OMX_PTR, OMX_EVENTTYPE, OMX_U32, OMX_U32, OMX_PTR);
123 void FillBufferDone (OMX_HANDLETYPE, OMX_PTR, OMX_BUFFERHEADERTYPE *);
124 void EmptyBufferDone (OMX_HANDLETYPE, OMX_PTR, OMX_BUFFERHEADERTYPE *);
125 OMX_ERRORTYPE send_input_buffer (OMX_HANDLETYPE, OMX_BUFFERHEADERTYPE *, FILE *);
126 int validateArg4 (char *);
127 int getNumTestCase (char *, char *);
128 boolean checkInputParameters (int);
129 boolean validateSampRate (int);
130 boolean omxSetInputPortParameter (OMX_HANDLETYPE *, int, int);
131 boolean omxSetOutputPortParameter (OMX_HANDLETYPE *, int, int, int);
132 boolean g722SetInputPort (OMX_HANDLETYPE *, int);
133 boolean g722SetOutputPort (OMX_HANDLETYPE *);
134 boolean omxSetConfigMute (OMX_HANDLETYPE *, OMX_BOOL);
135 boolean omxSetConfigVolume (OMX_HANDLETYPE *, OMX_S32);
136 OMX_ERRORTYPE omxUseBuffers (OMX_HANDLETYPE *, int, int, int, OMX_BUFFERHEADERTYPE *[], int, int, OMX_BUFFERHEADERTYPE *[]);
137 OMX_ERRORTYPE testCases (OMX_HANDLETYPE *, fd_set *,int, FILE *, FILE *, int *, int *, struct timeval *, int, int, OMX_BUFFERHEADERTYPE *[], int, OMX_BUFFERHEADERTYPE *[]);
138 OMX_ERRORTYPE testCase_2_4 (OMX_HANDLETYPE *, int, FILE *, FILE *, int, OMX_BUFFERHEADERTYPE *[]);
139 OMX_ERRORTYPE testCase_3 (OMX_HANDLETYPE *);
140
141 OMX_ERRORTYPE sendInBuffFillOutBuff (OMX_HANDLETYPE *, int, int, int, OMX_BUFFERHEADERTYPE *[], FILE *, OMX_BUFFERHEADERTYPE *[]);
142 OMX_ERRORTYPE omxFreeBuffers (OMX_HANDLETYPE *pHandle, int nBuffs, OMX_BUFFERHEADERTYPE *pBufferHeader [], char *sBuffTypeMsg);
143
144 void printTestCaseInfo (int, char *);
145 void getString_OMX_State (char *ptrString, OMX_STATETYPE state);
146
147 /* Global variables */
148 int sendlastbuffer = 0;
149 OMX_STATETYPE gState = OMX_StateExecuting;
150
151 int IpBuf_Pipe[2] = {0};
152 int OpBuf_Pipe[2] = {0};
153 int Event_Pipe[2] = {0};
154
155 int preempted = 0;
156
157 /* ================================================================================= * */
158 /**
159 * @fn main() This is the main function of application which gets called.
160 *
161 * @param argc This is the number of commandline arguments..
162 *
163 * @param argv[] This is an array of pointers to command line arguments..
164 *
165 * @pre None
166 *
167 * @post None
168 *
169 * @return An integer value.
170 *
171 * @see None
172 */
173 /* ================================================================================ * */
main(int argc,char * argv[])174 int main(int argc, char* argv[])
175 {
176 OMX_CALLBACKTYPE G722CaBa = {(void *)EventHandler,
177 (void *)EmptyBufferDone,
178 (void *)FillBufferDone
179 };
180 int nIpBuffs = 1;
181 int nOpBuffs = 1;
182 int nIpBufSize = 4096; /*default value */
183 int nOpBufSize = 320; /* default value */
184 int gDasfMode = 0;
185 OMX_HANDLETYPE *pHandle = NULL;
186 OMX_ERRORTYPE error = OMX_ErrorNone;
187 OMX_U32 AppData = G722_APP_ID;
188 TI_OMX_DSP_DEFINITION appPrivate;
189 OMX_INDEXTYPE index = 0;
190 OMX_BUFFERHEADERTYPE *pInputBufferHeader [MAX_NUM_OF_BUFS] = {NULL};
191 OMX_BUFFERHEADERTYPE *pOutputBufferHeader [MAX_NUM_OF_BUFS] = {NULL};
192 TI_OMX_DATAPATH dataPath;
193 fd_set rfds;
194 static int totalFilled = 0;
195 struct timeval tv;
196 int retval = 0;
197 int frmCnt = 1;
198 char fname [100] = APP_OUTPUT_FILE;
199 FILE* fIn = NULL;
200 FILE* fOut = NULL;
201 int tcID = 0;
202 #ifdef DSP_RENDERING_ON
203 int g722decfdwrite = 0;
204 int g722decfdread = 0;
205 #endif
206
207 #ifdef OMX_GETTIME
208 OMX_ListCreate(&pListHead);
209 #endif
210 int iSampRate = 0;
211 boolean bFlag = validateArguments (argc, argv, &iSampRate, fname, &tcID, &gDasfMode, &nIpBuffs, &nIpBufSize, &nOpBuffs, &nOpBufSize);
212 if (bFlag == FALSE) {
213 printf ("<<<<<<<<< Argument validate fault >>>>>>>>>");
214 exit (1);
215 }
216 int nIdx = 0,
217 nJdx = 0;
218 int nCntTest1 = (tcID != 6)? 1: N_REPETITIONS;
219 int nCntTest = (tcID != 5)? 1: N_REPETITIONS;
220 #ifdef APP_DEBUG
221 char strState [20] = {""};
222 #endif
223
224 error = TIOMX_Init();
225 if(error != OMX_ErrorNone) {
226 APP_DPRINT("%d :: Error returned by OMX_Init()\n",__LINE__);
227 exit (1);
228 }
229
230 for (nIdx = 0; nIdx < nCntTest1; nIdx++) {
231 pHandle = malloc(sizeof(OMX_HANDLETYPE));
232 if(pHandle == NULL){
233 printf("%d :: App: Malloc Failed\n",__LINE__);
234 exit (1);
235 }
236
237 #ifdef DSP_RENDERING_ON
238 if((g722decfdwrite = open(FIFO1,O_WRONLY))<0) {
239 printf("[G722TEST] - failure to open WRITE pipe\n");
240 exit (1);
241 }
242 printf("[G722TEST] - opened WRITE pipe\n");
243
244 if((g722decfdread = open(FIFO2,O_RDONLY))<0) {
245 printf("[G722TEST] - failure to open READ pipe\n");
246 exit (1);
247 }
248 printf("[G722TEST] - opened READ pipe\n");
249
250
251 if((write(g722decfdwrite, &cmd_data, sizeof(cmd_data)))<0) {
252 printf("%d ::G722DecTest.c ::[G722 Dec Component] - send command to audio manager\n", __LINE__);
253 }
254 if((read(g722decfdread, &cmd_data, sizeof(cmd_data)))<0) {
255 printf("%d ::G722DecTest.c ::[G722 Dec Component] - failure to get data from the audio manager\n", __LINE__);
256 exit (1);
257 }
258 #endif
259
260 #ifdef OMX_GETTIME
261 GT_START();
262 error = OMX_GetHandle(pHandle, STR_G722DECODER, &AppData, &G722CaBa);
263 GT_END("Call to GetHandle");
264 #else
265 error = TIOMX_GetHandle(pHandle, STR_G722DECODER, &AppData, &G722CaBa);
266 #endif
267
268 if((error != OMX_ErrorNone) || (*pHandle == NULL)) {
269 APP_DPRINT ("Error in Get Handle function\n");
270 exit (1);
271 }
272
273 /* Create a pipe used to queue data from the callback. */
274 retval = pipe(IpBuf_Pipe);
275 if( retval != 0) {
276 printf( "Error:Fill In Buff Pipe failed to open\n");
277 exit (1);
278 }
279
280 retval = pipe(OpBuf_Pipe);
281 if( retval != 0) {
282 printf( "Error:Empty Out Buff Pipe failed to open\n");
283 exit (1);
284 }
285
286 retval = pipe(Event_Pipe);
287 if( retval != 0) {
288 printf( "Error:Empty Event Pipe failed to open\n");
289 exit (1);
290 }
291
292 /* Send input port config */
293 bFlag = omxSetInputPortParameter (pHandle, nIpBuffs, nIpBufSize);
294 if (bFlag == FALSE) {
295 exit (1);
296 }
297
298 /* Send output port config */
299 bFlag = omxSetOutputPortParameter (pHandle, nOpBuffs, nOpBufSize, gDasfMode);
300 if (bFlag == FALSE) {
301 exit (1);
302 }
303
304 error = OMX_GetExtensionIndex(*pHandle, "OMX.TI.index.config.g722headerinfo",&index);
305 if (error != OMX_ErrorNone) {
306 printf("Error getting extension index\n");
307 exit (1);
308 }
309
310 appPrivate.dasfMode = gDasfMode;
311
312 error = OMX_SetConfig(*pHandle, index, &appPrivate);
313 if(error != OMX_ErrorNone) {
314 error = OMX_ErrorBadParameter;
315 APP_DPRINT("%d :: Error from OMX_SetConfig() function\n",__LINE__);
316 exit (1);
317 }
318 #ifdef OMX_GETTIME
319 GT_START();
320 #endif
321
322 error = omxUseBuffers (pHandle, gDasfMode, nIpBuffs, nIpBufSize, pInputBufferHeader, nOpBuffs, nOpBufSize, pOutputBufferHeader);
323 if (error != OMX_ErrorNone) {
324 exit (1);
325 }
326
327 /* Send G722 config for input */
328 bFlag = g722SetInputPort (pHandle, iSampRate);
329 if (bFlag == FALSE) {
330 exit (1);
331 }
332
333 /* Send G722 config for output */
334 bFlag = g722SetOutputPort (pHandle);
335 if (bFlag == FALSE) {
336 exit (1);
337 }
338
339 if(gDasfMode == 1) {
340 APP_DPRINT("%d :: G722 DECODER RUNNING UNDER DASF MODE\n",__LINE__);
341
342 #ifdef RTM_PATH
343 dataPath = DATAPATH_APPLICATION_RTMIXER;
344 #endif
345 #ifdef ETEEDN_PATH
346 dataPath = DATAPATH_APPLICATION;
347 #endif
348 error = OMX_GetExtensionIndex(*pHandle, "OMX.TI.index.config.g722dec.datapath",&index);
349 if (error != OMX_ErrorNone) {
350 printf("Error getting extension index\n");
351 exit (1);
352 }
353 error = OMX_SetConfig (*pHandle, index, &dataPath);
354 if(error != OMX_ErrorNone) {
355 error = OMX_ErrorBadParameter;
356 APP_DPRINT("%d :: G722DecTest.c :: Error from OMX_SetConfig() function\n",__LINE__);
357 exit (1);
358 }
359 }
360 error = OMX_SendCommand(*pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
361 if(error != OMX_ErrorNone) {
362 APP_DPRINT ("Error from SendCommand-Idle(Init) State function - error = %d\n",error);
363 exit (1);
364 }
365
366
367 APP_DPRINT("%d :: App :: About to call WaitForState to change to Idle\n",__LINE__);
368 error = WaitForState(pHandle, OMX_StateIdle);
369 APP_DPRINT("%d :: App :: state changed to Idle\n",__LINE__);
370 if(error != OMX_ErrorNone) {
371 APP_DPRINT( "Error: hAmrEncoder->WaitForState reports an error %X\n", error);
372 exit (1);
373 }
374
375 for (nJdx = 0; nJdx < nCntTest; nJdx++) {
376 if(gDasfMode == 0) {
377 APP_DPRINT("%d :: G722 DECODER RUNNING UNDER FILE MODE\n",__LINE__);
378 fOut = fopen(fname, "w");
379 if(fOut == NULL) {
380 APP_DPRINT ( "Error: failed to create the output file \n");
381 exit (1);
382 }
383 APP_DPRINT("%d :: Op File has created\n",__LINE__);
384 }
385 fIn = fopen(argv[1], "r");
386 if(fIn == NULL) {
387 fprintf(stderr, "Error: failed to open the file %s for readonly access\n", argv[1]);
388 exit (1);
389 }
390
391 if (tcID == 5) {
392 printf("*********************************************************\n");
393 printf ("App: %d time Sending OMX_StateExecuting Command: TC 5\n", nJdx);
394 printf("*********************************************************\n");
395 }
396 if (tcID == 6) {
397 printf("*********************************************************\n");
398 printf("%d :: App: Outer %d time Sending OMX_StateExecuting Command: TC6\n",__LINE__, nIdx);
399 printf("*********************************************************\n");
400 }
401 /* EOS_sent = OMX_FALSE; */
402 #ifdef OMX_GETTIME
403 GT_START();
404 #endif
405 error = OMX_SendCommand(*pHandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
406 if(error != OMX_ErrorNone) {
407 APP_DPRINT ("Error from SendCommand-Executing State function\n");
408 exit (1);
409 }
410
411 APP_DPRINT("%d :: App :: About to call WaitForState to change to Executing\n",__LINE__);
412 error = WaitForState(pHandle, OMX_StateExecuting);
413 gState = OMX_StateExecuting;
414 #ifdef OMX_GETTIME
415 GT_START();
416 #endif
417 if(error != OMX_ErrorNone) {
418 APP_DPRINT( "Error: WaitForState reports an error %X\n", error);
419 exit (1);
420 }
421 APP_DPRINT("%d :: App :: state changed to Executing\n",__LINE__);
422
423 error = sendInBuffFillOutBuff (pHandle, nIpBuffs, nOpBuffs, gDasfMode, pInputBufferHeader, fIn, pOutputBufferHeader);
424 if (error != OMX_ErrorNone) {
425 exit (1);
426 }
427
428 while (1) {
429 #ifdef APP_DEBUG
430 getString_OMX_State (strState, gState);
431 #endif
432
433 if ((error == OMX_ErrorNone) && (gState != OMX_StateIdle)) {
434 error = testCases (pHandle, &rfds, tcID, fIn, fOut, &frmCnt, &totalFilled, &tv, gDasfMode, nIpBuffs, pInputBufferHeader, nOpBuffs, pOutputBufferHeader);
435 if (error != OMX_ErrorNone) {
436 printf ("<<<<<<<<<<<<<< testCases fault exit >>>>>>>>>>>>>>\n");
437 exit (1);
438 }
439 } else if (preempted) {
440 sched_yield ();
441 } else {
442 break;
443 /* goto SHUTDOWN */
444 }
445 } /* While Loop Ending Here */
446 fclose(fIn);
447 if(0 == gDasfMode) {
448 fclose(fOut);
449 }
450
451 if(nIdx != (nCntTest - 1)) {
452 if((tcID == 5) || (tcID == 2)) {
453 printf("%d :: sleeping here for %d secs\n",__LINE__,SLEEP_TIME);
454 sleep (SLEEP_TIME);
455 }
456 }
457 }
458 #ifdef DSP_RENDERING_ON
459 cmd_data.AM_Cmd = AM_Exit;
460 if((write (g722decfdwrite, &cmd_data, sizeof(cmd_data)))<0)
461 printf("%d :: [G722 Dec Component] - send command to audio manager\n",__LINE__);
462 close(g722decfdwrite);
463 close(g722decfdread);
464 #endif
465
466
467 APP_DPRINT ("Sending the StateLoaded Command\n");
468 #ifdef OMX_GETTIME
469 GT_START();
470 #endif
471 error = OMX_SendCommand(*pHandle,OMX_CommandStateSet, OMX_StateLoaded, NULL);
472
473 error = omxFreeBuffers (pHandle, nIpBuffs, pInputBufferHeader, "Input");
474 if((error != OMX_ErrorNone)) {
475 APP_DPRINT ("%d:: Error in Free Input Buffers function\n",__LINE__);
476 exit (1);
477 }
478 if(gDasfMode == 0) {
479 error = omxFreeBuffers (pHandle, nOpBuffs, pOutputBufferHeader, "Output");
480 if((error != OMX_ErrorNone)) {
481 APP_DPRINT ("%d:: Error in Free Output Buffers function\n",__LINE__);
482 exit (1);
483 }
484 }
485 error = WaitForState(pHandle, OMX_StateLoaded);
486 #ifdef OMX_GETTIME
487 GT_END("Call to SendCommand <OMX_StateLoaded>");
488 #endif
489 if(error != OMX_ErrorNone) {
490 APP_DPRINT ("%d:: Error from SendCommand-Idle State function\n",__LINE__);
491 exit (1);
492 }
493
494 #ifdef WAITFORRESOURCES
495 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateWaitForResources, NULL);
496 if(error != OMX_ErrorNone) {
497 APP_DPRINT ("%d :: AmrDecTest.c :: Error from SendCommand-Idle State function\n",__LINE__);
498 printf("goto EXIT %d\n",__LINE__);
499
500 goto EXIT;
501 }
502 error = WaitForState(pHandle, OMX_StateWaitForResources);
503
504 /* temporarily put this here until I figure out what should really happen here */
505 sleep(10);
506 #endif
507
508 error = OMX_SendCommand(*pHandle, OMX_CommandPortDisable, -1, NULL);
509
510
511 #ifdef DSP_RENDERING_ON
512 if((write(g722decfdwrite, &cmd_data, sizeof(cmd_data)))<0)
513 APP_DPRINT ("%d [G722Dec Test] - send command to audio manager\n",__LINE__);
514 #endif
515
516 error = TIOMX_FreeHandle(*pHandle);
517 if( (error != OMX_ErrorNone)) {
518 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
519 exit (1);
520 }
521 APP_DPRINT ("%d:: Free Handle returned Successfully \n\n\n\n",__LINE__);
522 if (pHandle) {
523 free(pHandle);
524 }
525
526 close (Event_Pipe[0]);
527 close (Event_Pipe[1]);
528 close (IpBuf_Pipe[0]);
529 close (IpBuf_Pipe[1]);
530 close (OpBuf_Pipe[0]);
531 close (OpBuf_Pipe[1]);
532
533 sendlastbuffer = 0;
534 }
535
536 error = TIOMX_Deinit();
537 if( (error != OMX_ErrorNone)) {
538 APP_DPRINT("APP: Error in Deinit Core function\n");
539 }
540
541 if (gDasfMode == 0) {
542 printf("**********************************************************\n");
543 printf("NOTE: An output file %s has been created in file system\n",APP_OUTPUT_FILE);
544 printf("**********************************************************\n");
545 }
546 #ifdef OMX_GETTIME
547 GT_END("G722_DEC test <End>");
548 OMX_ListDestroy(pListHead);
549 #endif
550 exit (0);
551 } /* end main () */
552
553 /* ================================================================================= * */
554 /**
555 * @fn validateArguments() This is the main function of application which gets called.
556 *
557 */
558 /* ================================================================================ * */
validateArguments(int nArgc,char * sArgv[],int * iSampRate,char * fname,int * tcID,int * gDasfMode,int * nIpBuffs,int * nIpBufSize,int * nOpBuffs,int * nOpBufSize)559 boolean validateArguments (int nArgc, char *sArgv [], int *iSampRate, char *fname, int *tcID, int *gDasfMode, int *nIpBuffs, int *nIpBufSize, int *nOpBuffs, int *nOpBufSize)
560 {
561 APP_DPRINT("------------------------------------------------------\n");
562 APP_DPRINT("This is Main Thread In G722 DECODER Test Application:\n");
563 APP_DPRINT("Test Core 1.5 - " __DATE__ ":" __TIME__ "\n");
564 APP_DPRINT("------------------------------------------------------\n");
565
566 /* check the input parameters */
567 if (checkInputParameters (nArgc) == FALSE) {
568 return (FALSE);
569 }
570
571 /* check to see that the input file exists */
572 struct stat sb = {0};
573 int status = stat(sArgv[1], &sb);
574 if( status != 0 ) {
575 printf( "Cannot find file %s. (%u)\n", sArgv[1], errno);
576 printf ("Test not performed!!!!!!\n\n");
577 return (FALSE);
578 }
579
580 int nTmp = atoi(sArgv[2]);
581 if (validateSampRate (nTmp) == FALSE) {
582 return (FALSE);
583 }
584 *iSampRate = nTmp;
585
586 *tcID = getNumTestCase (sArgv [3], fname);
587 if (*tcID == 0) {
588 printf("Invalid Test Case ID: exiting...\n");
589 return (FALSE);
590 }
591
592 *gDasfMode = validateArg4 (sArgv [4]);
593 if (*gDasfMode == -1) {
594 return (FALSE);
595 }
596
597 *nIpBuffs = atoi(sArgv[5]);
598 APP_DPRINT("%d :: App: nIpBuf = %d\n",__LINE__, *nIpBuffs);
599 *nIpBufSize = atoi(sArgv[6]);
600 APP_DPRINT("%d :: App: nIpBufSize = %d\n",__LINE__, *nIpBufSize);
601 *nOpBuffs = atoi(sArgv[7]);
602 APP_DPRINT("%d :: App: nOpBuf = %d\n",__LINE__, *nOpBuffs);
603 *nOpBufSize = atoi(sArgv[8]);
604 APP_DPRINT("%d :: App: nOpBufSize = %d\n",__LINE__, *nOpBufSize);
605
606 printf ("Sample rate:\t\t %d\n", *iSampRate);
607 printf ("Test case ID:\t\t %d\n", *tcID);
608 printf ("DasfMode:\t\t %d\n", *gDasfMode);
609 printf ("# of Input Buffers:\t %d\n", *nIpBuffs);
610 printf ("Size of Input Buffers:\t %d\n", *nIpBufSize);
611 printf ("# of Output Buffers:\t %d\n", *nOpBuffs);
612 printf ("Size of Output Buffers:\t %d\n", *nOpBufSize);
613 return (TRUE);
614 }
615 /**/
616 /* ================================================================================= * */
617 /**
618 * @fn maxint() gives the maximum of two integers.
619 *
620 * @param a intetger a
621 *
622 * @param b integer b
623 *
624 * @pre None
625 *
626 * @post None
627 *
628 * @return bigger number
629 *
630 * @see None
631 */
632 /* ================================================================================ * */
maxint(int a,int b)633 int maxint(int a, int b)
634 {
635 return (a>b) ? a : b;
636 }
637
638 /* ================================================================================= * */
639 /**
640 * @fn WaitForState() Waits for the state to change.
641 *
642 * @param pHandle This is component handle allocated by the OMX core.
643 *
644 * @param DesiredState This is state which the app is waiting for.
645 *
646 * @pre None
647 *
648 * @post None
649 *
650 * @return Appropriate OMX Error.
651 *
652 * @see None
653 */
654 /* ================================================================================ * */
WaitForState(OMX_HANDLETYPE * pHandle,OMX_STATETYPE DesiredState)655 static OMX_ERRORTYPE WaitForState(OMX_HANDLETYPE* pHandle, OMX_STATETYPE DesiredState)
656 {
657 OMX_STATETYPE CurState = OMX_StateInvalid;
658 OMX_ERRORTYPE error = OMX_ErrorNone;
659 int nCnt = 0;
660
661 error = OMX_GetState(*pHandle, &CurState);
662 while( (error == OMX_ErrorNone) && (CurState != DesiredState)) {
663 sched_yield();
664 if(nCnt++ == 10) {
665 APP_DPRINT( "Still Waiting, press CTL-C to continue\n");
666 }
667 error = OMX_GetState(*pHandle, &CurState);
668 }
669
670 return error;
671 }
672
673
674 /* ================================================================================= * */
675 /**
676 * @fn EventHandler() This is event handle which is called by the component on
677 * any event change.
678 *
679 * @param hComponent This is component handle allocated by the OMX core.
680 *
681 * @param pAppData This is application private data.
682 *
683 * @param eEvent This is event generated from the component.
684 *
685 * @param nData1 Data1 associated with the event.
686 *
687 * @param nData2 Data2 associated with the event.
688 *
689 * @param pEventData Any other string event data from component.
690 *
691 * @pre None
692 *
693 * @post None
694 *
695 * @return Appropriate OMX error.
696 *
697 * @see None
698 */
699 /* ================================================================================ * */
EventHandler(OMX_HANDLETYPE hComponent,OMX_PTR pAppData,OMX_EVENTTYPE eEvent,OMX_U32 nData1,OMX_U32 nData2,OMX_PTR pEventData)700 OMX_ERRORTYPE EventHandler(OMX_HANDLETYPE hComponent,OMX_PTR pAppData,OMX_EVENTTYPE eEvent,
701 OMX_U32 nData1, OMX_U32 nData2, OMX_PTR pEventData)
702 {
703 OMX_U8 writeValue = 0;
704 #ifdef APP_DEBUG
705 char strState [20] = {""};
706 char strTargetState [20] = {""};
707 getString_OMX_State (strState, nData2);
708 getString_OMX_State (strTargetState, nData1);
709 #endif
710
711 switch (eEvent) {
712 case OMX_EventResourcesAcquired:
713 APP_DPRINT ("------> OMX_EventResourcesAcquired <--------\n");
714 writeValue = 1;
715 write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
716 preempted = 0;
717 break;
718 case OMX_EventCmdComplete:
719 APP_DPRINT ("------> OMX_EventCmdComplete<--------\n");
720 gState = (OMX_STATETYPE)nData2;
721 break;
722 case OMX_EventMax:
723 APP_DPRINT ("------> OMX_EventMax<--------\n");
724 case OMX_EventMark:
725 APP_DPRINT ("------> OMX_EventMark<--------\n");
726 break;
727 case OMX_EventPortSettingsChanged:
728 APP_DPRINT ("------> OMX_EventPortSettingsChanged <--------\n");
729 break;
730 case OMX_EventComponentResumed:
731 APP_DPRINT ("------> OMX_EventComponentResumed <--------\n");
732 break;
733 case OMX_EventDynamicResourcesAvailable:
734 APP_DPRINT ("------> OMX_EventDynamicResourcesAvailable <--------\n");
735 break;
736 case OMX_EventPortFormatDetected:
737 break;
738 case OMX_EventError:
739 APP_DPRINT ("------> OMX_EventError <--------\n");
740 APP_DPRINT ( "%d :: G722DecTest.c Event: OMX_EventError. Component State Changed To %s. Target %s\n", __LINE__, strState, strTargetState);
741 if (nData1 != OMX_ErrorInvalidState && nData1 == OMX_ErrorResourcesPreempted) {
742 APP_DPRINT ("------> \tprocess on OMX_ErrorResourcesPreempted<--------\n");
743 preempted=1;
744
745 writeValue = 0;
746 write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
747 } else {
748 APP_DPRINT ("------> \tnothing to process on OMX_EnentError <--------\n");
749 }
750 break;
751 case OMX_EventBufferFlag:
752 APP_DPRINT ("------> OMX_EventBufferFlag <--------\n");
753 APP_DPRINT ( "%d :: G722DecTest.c Event: OMX_EventBufferFlag. Component State Changed To %s. Target %s\n", __LINE__, strState, strTargetState);
754 /* <<<<< Process Manager <<<<< */
755 writeValue = 2;
756 write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
757 /* >>>>>>>>>> */
758 break;
759 default:
760 APP_DPRINT ("------> Unknown event <--------\n");
761 break;
762 }
763
764 return OMX_ErrorNone;
765 }
766
767 /* ================================================================================= * */
768 /**
769 * @fn FillBufferDone() Component sens the output buffer to app using this
770 * callback.
771 *
772 * @param hComponent This is component handle allocated by the OMX core.
773 *
774 * @param ptr This is another pointer.
775 *
776 * @param pBuffer This is output buffer.
777 *
778 * @pre None
779 *
780 * @post None
781 *
782 * @return None
783 *
784 * @see None
785 */
786 /* ================================================================================ * */
FillBufferDone(OMX_HANDLETYPE hComponent,OMX_PTR ptr,OMX_BUFFERHEADERTYPE * pBuffer)787 void FillBufferDone (OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer)
788 {
789 write(OpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
790 #ifdef OMX_GETTIME
791 OMX_ERRORTYPE eError = OMX_ErrorNone;
792 int GT_FlagE = 0; /* Fill Buffer 1 = First Buffer, 0 = Not First Buffer */
793 int GT_FlagF = 0; /*Empty Buffer 1 = First Buffer, 0 = Not First Buffer */
794 static OMX_NODE* pListHead = NULL;
795 #endif
796 }
797
798 /* ================================================================================= * */
799 /**
800 * @fn EmptyBufferDone() Component sends the input buffer to app using this
801 * callback.
802 *
803 * @param hComponent This is component handle allocated by the OMX core.
804 *
805 * @param ptr This is another pointer.
806 *
807 * @param pBuffer This is input buffer.
808 *
809 * @pre None
810 *
811 * @post None
812 *
813 * @return None
814 *
815 * @see None
816 */
817 /* ================================================================================ * */
EmptyBufferDone(OMX_HANDLETYPE hComponent,OMX_PTR ptr,OMX_BUFFERHEADERTYPE * pBuffer)818 void EmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer)
819 {
820 if (!preempted)
821 write(IpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
822 #ifdef OMX_GETTIME
823 if (GT_FlagF == 1 ) { /* First Buffer Reply*/ /* 1 = First Buffer, 0 = Not First Buffer */
824 GT_END("Call to FillBufferDone <First: FillBufferDone>");
825 GT_FlagF = 0 ; /* 1 = First Buffer, 0 = Not First Buffer */
826 }
827 #endif
828 }
829
830 /* ================================================================================= * */
831 /**
832 * @fn send_input_buffer() Sends the input buffer to the component.
833 *
834 * @param pHandle This is component handle allocated by the OMX core.
835 *
836 * @param pBuffer This is the buffer pointer.
837 *
838 * @fIn This is input file handle.
839 *
840 * @pre None
841 *
842 * @post None
843 *
844 * @return Appropriate OMX error.
845 *
846 * @see None
847 */
848 /* ================================================================================ * */
send_input_buffer(OMX_HANDLETYPE pHandle,OMX_BUFFERHEADERTYPE * pBufferHeader,FILE * fIn)849 OMX_ERRORTYPE send_input_buffer(OMX_HANDLETYPE pHandle, OMX_BUFFERHEADERTYPE* pBufferHeader, FILE *fIn)
850 {
851 OMX_ERRORTYPE error = OMX_ErrorNone;
852 int nRead = 0;
853 static int totalRead = 0;
854 static int fileHdrReadFlag = 0;
855 static int ccnt = 1;
856 if (!fileHdrReadFlag) {
857 fileHdrReadFlag = 1;
858 }
859 nRead = fread(pBufferHeader->pBuffer, 1, pBufferHeader->nAllocLen , fIn);
860
861 if (nRead != 0) {
862 totalRead += nRead;
863 pBufferHeader->nFilledLen = nRead;
864 ccnt++;
865
866 APP_DPRINT("\n*****************************************************\n");
867 APP_DPRINT ("%d :: App:: pBuffer->pBuffer = %p pBuffer->nAllocLen = * %ld, nRead = %d, totalread = %d\n",
868 __LINE__, pBufferHeader->pBuffer, pBufferHeader->nAllocLen, nRead, totalRead);
869 APP_DPRINT("\n*****************************************************\n");
870 }
871
872 if(sendlastbuffer){
873 sendlastbuffer = 0;
874 pBufferHeader->nFlags = 0;
875
876 return error;
877 }
878
879 if(nRead < pBufferHeader->nAllocLen) {
880 pBufferHeader->nFlags = OMX_BUFFERFLAG_EOS;
881 sendlastbuffer = 1;
882 } else {
883 pBufferHeader->nFlags = 0;
884 }
885 pBufferHeader->nFilledLen = nRead;
886 error = OMX_EmptyThisBuffer(pHandle, pBufferHeader);
887 return error;
888 }
889
890 /* ================================================================================= * */
891 /**
892 * @fn validateArg4() This is the main function of application which gets called.
893 *
894 */
895 /* ================================================================================ * */
validateArg4(char * sArg4)896 int validateArg4 (char *sArg4)
897 {
898 int gDasfMode = -1;
899
900 if (!strcmp(sArg4, "DM")) {
901 gDasfMode = 1;
902 } else if (!strcmp(sArg4, "FM")) {
903 gDasfMode = 0;
904 } else {
905 printf("\n%d :: App: Sending Bad Parameter for dasf mode\n",__LINE__);
906 printf("%d :: App: Should Be One of these Modes FM or DM\n",__LINE__);
907 gDasfMode = -1;
908 }
909
910 return (gDasfMode);
911 }
912
913 /* ================================================================================= * */
914 /**
915 * @fn getNumTestCase() This is the main function of application which gets called.
916 *
917 */
918 /* ================================================================================ * */
getNumTestCase(char * sTestCase,char * sFileName)919 int getNumTestCase (char *sTestCase, char *sFileName)
920 {
921 int iTestCase = 0;
922
923 if(!strcmp(sTestCase,"TC_1")) {
924 iTestCase = 1;
925 } else if (!strcmp(sTestCase,"TC_2")) {
926 iTestCase = 2;
927 } else if (!strcmp(sTestCase,"TC_3")) {
928 iTestCase = 3;
929 } else if (!strcmp(sTestCase,"TC_4")) {
930 iTestCase = 4;
931 } else if (!strcmp(sTestCase,"TC_5")) {
932 iTestCase = 5;
933 } else if (!strcmp(sTestCase,"TC_6")) {
934 iTestCase = 6;
935 } else if (!strcmp(sTestCase,"TC_7")) {
936 iTestCase = 7;
937 } else if (!strcmp(sTestCase,"TC_8")) {
938 iTestCase = 8;
939 } else if (!strcmp(sTestCase,"TC_9")) {
940 iTestCase = 9;
941 }
942 printTestCaseInfo (iTestCase, sFileName);
943
944 return (iTestCase);
945 }
946
947 /* ================================================================================= * */
948 /**
949 * @fn printTestCaseInfo() This is the main function of application which gets called.
950 *
951 */
952 /* ================================================================================ * */
printTestCaseInfo(int iTestCase,char * sFileName)953 void printTestCaseInfo (int iTestCase, char *sFileName)
954 {
955 switch (iTestCase) {
956 case 1:
957 case 7:
958 case 8:
959 printf ("-------------------------------------\n");
960 printf ("Testing Simple PLAY till EOF \n");
961 printf ("-------------------------------------\n");
962 strcat(sFileName, ".pcm");
963 break;
964 case 2:
965 printf ("-------------------------------------\n");
966 printf ("Testing Basic Stop \n");
967 printf ("-------------------------------------\n");
968 strcat(sFileName, "_tc2.pcm");
969 break;
970 case 3:
971 printf ("-------------------------------------\n");
972 printf ("Testing PAUSE & RESUME Command\n");
973 printf ("-------------------------------------\n");
974 strcat(sFileName, ".pcm");
975 break;
976 case 4:
977 printf ("---------------------------------------------\n");
978 printf ("Testing STOP Command by Stopping In-Between\n");
979 printf ("---------------------------------------------\n");
980 break;
981 case 5:
982 printf ("-------------------------------------------------\n");
983 printf ("Testing Repeated PLAY without Deleting Component\n");
984 printf ("-------------------------------------------------\n");
985 strcat(sFileName,"_tc5.pcm");
986 break;
987 case 6:
988 printf ("------------------------------------------------\n");
989 printf ("Testing Repeated PLAY with Deleting Component\n");
990 printf ("------------------------------------------------\n");
991 strcat(sFileName,"_tc6.pcm");
992 break;
993 case 9:
994 printf ("------------------------------------------------\n");
995 printf ("TimeStamp, TickCounts\n");
996 printf ("------------------------------------------------\n");
997 strcat(sFileName,"_tc6.pcm");
998 break;
999 }
1000
1001 return;
1002 }
1003
1004 /* ================================================================================= * */
1005 /**
1006 * @fn checkInputParameters() This is the main function of application which gets called.
1007 *
1008 */
1009 /* ================================================================================ * */
checkInputParameters(iNumParams)1010 boolean checkInputParameters (iNumParams)
1011 {
1012 if(iNumParams != 9) {
1013 printf("Wrong Arguments: See Below:\n\n");
1014 printf("%d :: Usage: [TestApp] [Input File] [Input File Bit Rate] [TC ID]\
1015 [FM/DM] [NB INPUT BUF] [INPUT BUF SIZE] [NB OUTPUT BUF] [OUTPUT BUF SIZE]\n",__LINE__);
1016 return (FALSE);
1017 }
1018 return (TRUE);
1019 }
1020
1021 /* ================================================================================= * */
1022 /**
1023 * @fn validateSampRate() This is the main function of application which gets called.
1024 *
1025 */
1026 /* ================================================================================ * */
validateSampRate(int iSampRate)1027 boolean validateSampRate (int iSampRate)
1028 {
1029 if (iSampRate == 64000) {
1030 return (TRUE);
1031 } else if(iSampRate == 56000) {
1032 return (TRUE);
1033 } else if(iSampRate == 48000) {
1034 return (TRUE);
1035 } else if (iSampRate == INVALID_SAMPLING_FREQ) {
1036 printf("***********************************************************\n");
1037 printf("%d :: App: Note: Invalid Frequency has been specified by App\n",__LINE__);
1038 printf("***********************************************************\n");
1039 return (FALSE);
1040 } else {
1041 printf ("%d :: Sample Frequency Not Supported: \n", __LINE__);
1042 printf ("Supported frequencies are: 64000 or 56000 or 48000.\n");
1043 printf ("If you want to specify invalid sampling frequency, specify %d and test the component for error.\n",
1044 INVALID_SAMPLING_FREQ);
1045 printf("%d :: Exiting...........\n",__LINE__);
1046 return (FALSE);
1047 }
1048 printf ("Unspecified error.\n");
1049 return (FALSE);
1050 }
1051
1052 /* ================================================================================= * */
1053 /**
1054 * @fn omxSetInputPortParameter() This is the main function of application which gets called.
1055 *
1056 */
1057 /* ================================================================================ * */
omxSetInputPortParameter(OMX_HANDLETYPE * pHandle,int nIpBuffs,int nIpBufSize)1058 boolean omxSetInputPortParameter (OMX_HANDLETYPE *pHandle, int nIpBuffs, int nIpBufSize)
1059 {
1060 OMX_PARAM_PORTDEFINITIONTYPE pCompPrivateStruct;
1061 OMX_ERRORTYPE error = OMX_ErrorNone;
1062
1063 pCompPrivateStruct.nSize = sizeof (OMX_PARAM_PORTDEFINITIONTYPE);
1064 pCompPrivateStruct.eDir = OMX_DirInput;
1065 pCompPrivateStruct.nBufferCountActual = nIpBuffs;
1066 pCompPrivateStruct.nBufferSize = nIpBufSize;
1067 pCompPrivateStruct.format.audio.eEncoding = OMX_AUDIO_CodingPCM;
1068 pCompPrivateStruct.bEnabled = OMX_TRUE;
1069 pCompPrivateStruct.bPopulated = OMX_FALSE;
1070 pCompPrivateStruct.nPortIndex = OMX_DirInput;
1071 #ifdef OMX_GETTIME
1072 GT_START();
1073 error = OMX_SetParameter(*pHandle,OMX_IndexParamPortDefinition, &pCompPrivateStruct);
1074 GT_END("Set Parameter Test-SetParameter");
1075 #else
1076 error = OMX_SetParameter(*pHandle,OMX_IndexParamPortDefinition, &pCompPrivateStruct);
1077 #endif
1078 if(error != OMX_ErrorNone) {
1079 error = OMX_ErrorBadParameter;
1080 printf ("%d :: OMX_ErrorBadParameter\n",__LINE__);
1081 }
1082
1083 return (TRUE);
1084 }
1085
1086 /* ================================================================================= * */
1087 /**
1088 * @fn omxSetOutputPortParameter() This is the main function of application which gets called.
1089 *
1090 */
1091 /* ================================================================================ * */
omxSetOutputPortParameter(OMX_HANDLETYPE * pHandle,int nOpBuffs,int nOpBufSize,int gDasfMode)1092 boolean omxSetOutputPortParameter (OMX_HANDLETYPE *pHandle, int nOpBuffs, int nOpBufSize, int gDasfMode)
1093 {
1094 OMX_PARAM_PORTDEFINITIONTYPE pCompPrivateStruct;
1095 OMX_ERRORTYPE error = OMX_ErrorNone;
1096
1097 pCompPrivateStruct.eDir = OMX_DirOutput;
1098 pCompPrivateStruct.nBufferCountActual = (gDasfMode == 1)? 0 : nOpBuffs;
1099 pCompPrivateStruct.nBufferSize = nOpBufSize;
1100 pCompPrivateStruct.format.audio.eEncoding = OMX_AUDIO_CodingPCM;
1101 pCompPrivateStruct.bEnabled = OMX_TRUE;
1102 pCompPrivateStruct.bPopulated = (gDasfMode == 1)? OMX_TRUE : OMX_FALSE;
1103 pCompPrivateStruct.nPortIndex = OMX_DirOutput;
1104
1105 #ifdef OMX_GETTIME
1106 GT_START();
1107 error = OMX_SetParameter(*pHandle,OMX_IndexParamPortDefinition, &pCompPrivateStruct);
1108 GT_END("Set Parameter Test-SetParameter");
1109 #else
1110 error = OMX_SetParameter(*pHandle,OMX_IndexParamPortDefinition, &pCompPrivateStruct);
1111 #endif
1112 if(error != OMX_ErrorNone) {
1113 error = OMX_ErrorBadParameter;
1114 printf ("%d :: OMX_ErrorBadParameter\n",__LINE__);
1115 }
1116
1117 return (TRUE);
1118 }
1119
1120 /* ================================================================================= * */
1121 /**
1122 * @fn g722SetInputPort() This is the main function of application which gets called.
1123 *
1124 */
1125 /* ================================================================================ * */
g722SetInputPort(OMX_HANDLETYPE * pHandle,int iSampRate)1126 boolean g722SetInputPort (OMX_HANDLETYPE *pHandle, int iSampRate)
1127 {
1128 OMX_AUDIO_PARAM_PCMMODETYPE pG722Param;
1129 OMX_ERRORTYPE error = OMX_ErrorNone;
1130
1131 pG722Param.nSize = sizeof(OMX_AUDIO_PARAM_PCMMODETYPE);
1132 pG722Param.nVersion.s.nVersionMajor = 0xF1;
1133 pG722Param.nVersion.s.nVersionMinor = 0xF2;
1134 pG722Param.nPortIndex = OMX_DirInput;
1135 pG722Param.nChannels = 1; /* mono */
1136 pG722Param.nBitPerSample = 8;
1137 pG722Param.eNumData = OMX_NumericalDataUnsigned;
1138 pG722Param.eEndian = OMX_EndianLittle;
1139 pG722Param.bInterleaved = OMX_FALSE;
1140 pG722Param.ePCMMode = OMX_AUDIO_PCMModeLinear;
1141 pG722Param.nSamplingRate = iSampRate;
1142
1143 #ifdef OMX_GETTIME
1144 GT_START();
1145 error = OMX_SetParameter (*pHandle, OMX_IndexParamAudioPcm, &pG722Param);
1146 GT_END("Set Parameter Test-SetParameter");
1147 #else
1148 error = OMX_SetParameter (*pHandle, OMX_IndexParamAudioPcm, &pG722Param);
1149 #endif
1150
1151 if (error != OMX_ErrorNone) {
1152 error = OMX_ErrorBadParameter;
1153 return (FALSE);
1154 }
1155 return (TRUE);
1156 }
1157
1158 /* ================================================================================= * */
1159 /**
1160 * @fn g722SetOutputPort() This is the main function of application which gets called.
1161 *
1162 */
1163 /* ================================================================================ * */
g722SetOutputPort(OMX_HANDLETYPE * pHandle)1164 boolean g722SetOutputPort (OMX_HANDLETYPE *pHandle)
1165 {
1166 OMX_AUDIO_PARAM_PCMMODETYPE pG722Param;
1167 OMX_ERRORTYPE error = OMX_ErrorNone;
1168
1169 pG722Param.nSize = sizeof(OMX_AUDIO_PARAM_PCMMODETYPE);
1170 pG722Param.nVersion.s.nVersionMajor = 0xF1;
1171 pG722Param.nVersion.s.nVersionMinor = 0xF2;
1172 pG722Param.nPortIndex = OMX_DirOutput;
1173 pG722Param.nChannels = 1; /* mono */
1174 pG722Param.nBitPerSample = 16;
1175 pG722Param.nSamplingRate = 16000;
1176 pG722Param.eNumData = OMX_NumericalDataUnsigned;
1177 pG722Param.eEndian = OMX_EndianLittle;
1178 pG722Param.bInterleaved = OMX_FALSE;
1179 pG722Param.ePCMMode = OMX_AUDIO_PCMModeLinear;
1180
1181 #ifdef OMX_GETTIME
1182 GT_START();
1183 error = OMX_SetParameter (*pHandle, OMX_IndexParamAudioPcm, &pG722Param);
1184 GT_END("Set Parameter Test-SetParameter");
1185 #else
1186 error = OMX_SetParameter (*pHandle, OMX_IndexParamAudioPcm, &pG722Param);
1187 #endif
1188
1189 if (error != OMX_ErrorNone) {
1190 error = OMX_ErrorBadParameter;
1191 return (FALSE);
1192 }
1193 return (TRUE);
1194 }
1195
1196 /* ================================================================================= * */
1197 /**
1198 * @fn omxSetConfigMute() This is the main function of application which gets called.
1199 *
1200 */
1201 /* ================================================================================ * */
omxSetConfigMute(OMX_HANDLETYPE * pHandle,OMX_BOOL bMute)1202 boolean omxSetConfigMute (OMX_HANDLETYPE *pHandle, OMX_BOOL bMute)
1203 {
1204 OMX_AUDIO_CONFIG_MUTETYPE pCompPrivateStructMute;
1205 OMX_ERRORTYPE error = OMX_ErrorNone;
1206
1207 /* default setting for Mute/Unmute */
1208 pCompPrivateStructMute.nSize = sizeof (OMX_AUDIO_CONFIG_MUTETYPE);
1209 pCompPrivateStructMute.nVersion.s.nVersionMajor = 0xF1;
1210 pCompPrivateStructMute.nVersion.s.nVersionMinor = 0xF2;
1211 pCompPrivateStructMute.nPortIndex = OMX_DirInput;
1212 pCompPrivateStructMute.bMute = bMute;
1213
1214 error = OMX_SetConfig(*pHandle, OMX_IndexConfigAudioMute, &pCompPrivateStructMute);
1215 if (error != OMX_ErrorNone) {
1216 error = OMX_ErrorBadParameter;
1217 return (FALSE);
1218 }
1219 return (TRUE);
1220 }
1221
1222 /* ================================================================================= * */
1223 /**
1224 * @fn omxSetConfigVolume() This is the main function of application which gets called.
1225 *
1226 */
1227 /* ================================================================================ * */
omxSetConfigVolume(OMX_HANDLETYPE * pHandle,OMX_S32 nVolume)1228 boolean omxSetConfigVolume (OMX_HANDLETYPE *pHandle, OMX_S32 nVolume)
1229 {
1230 OMX_AUDIO_CONFIG_VOLUMETYPE pCompPrivateStructVolume;
1231 OMX_ERRORTYPE error = OMX_ErrorNone;
1232
1233 /* default setting for volume */
1234 pCompPrivateStructVolume.nSize = sizeof(OMX_AUDIO_CONFIG_VOLUMETYPE);
1235 pCompPrivateStructVolume.nVersion.s.nVersionMajor = 0xF1;
1236 pCompPrivateStructVolume.nVersion.s.nVersionMinor = 0xF2;
1237 pCompPrivateStructVolume.nPortIndex = OMX_DirInput;
1238 pCompPrivateStructVolume.bLinear = OMX_FALSE;
1239 pCompPrivateStructVolume.sVolume.nValue = nVolume; /* actual volume */
1240 pCompPrivateStructVolume.sVolume.nMin = 0; /* min volume */
1241 pCompPrivateStructVolume.sVolume.nMax = 100; /* max volume */
1242
1243 error = OMX_SetConfig(*pHandle, OMX_IndexConfigAudioVolume, &pCompPrivateStructVolume);
1244 if (error != OMX_ErrorNone) {
1245 error = OMX_ErrorBadParameter;
1246 return (FALSE);
1247 }
1248 return (TRUE);
1249 }
1250
1251 /* ================================================================================= * */
1252 /**
1253 * @fn omxUseBuffers() This is the main function of application which gets called.
1254 *
1255 */
1256 /* ================================================================================ * */
omxUseBuffers(OMX_HANDLETYPE * pHandle,int gDasfMode,int nIpBuffs,int nIpBufSize,OMX_BUFFERHEADERTYPE * pInputBufferHeader[],int nOpBuffs,int nOpBufSize,OMX_BUFFERHEADERTYPE * pOutputBufferHeader[])1257 OMX_ERRORTYPE omxUseBuffers (OMX_HANDLETYPE *pHandle, int gDasfMode, int nIpBuffs, int nIpBufSize, OMX_BUFFERHEADERTYPE *pInputBufferHeader [], int nOpBuffs, int nOpBufSize, OMX_BUFFERHEADERTYPE *pOutputBufferHeader [])
1258 {
1259 OMX_ERRORTYPE error = OMX_ErrorNone;
1260 int i=0; /* 0j0 <<<<<<<<<<< */
1261
1262 #ifndef USE_BUFFER
1263 for(i=0; i < nIpBuffs; i++) {
1264 APP_DPRINT("%d :: About to call OMX_AllocateBuffer On Input\n",__LINE__);
1265 error = OMX_AllocateBuffer(*pHandle, &pInputBufferHeader[i], 0, NULL, nIpBufSize);
1266 APP_DPRINT("%d :: called OMX_AllocateBuffer\n",__LINE__);
1267 if(error != OMX_ErrorNone) {
1268 APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer()\n",__LINE__);
1269 return (error);
1270 }
1271 }
1272
1273 if (gDasfMode == 0) {
1274 for(i=0; i < nOpBuffs; i++) {
1275 error = OMX_AllocateBuffer(*pHandle,&pOutputBufferHeader[i],1,NULL,nOpBufSize);
1276 if(error != OMX_ErrorNone) {
1277 APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer()\n",__LINE__);
1278 return (error);
1279 }
1280 }
1281 }
1282 #else
1283 OMX_U8* pInputBuffer [MAX_NUM_OF_BUFS] = {NULL};
1284 OMX_U8* pOutputBuffer [MAX_NUM_OF_BUFS] = {NULL};
1285
1286 for(i=0; i<nIpBuffs; i++) {
1287 if (pInputBuffer[i] == NULL) {
1288 pInputBuffer[i] = (OMX_U8*)malloc(nIpBufSize);
1289 APP_DPRINT("%d :: About to call OMX_UseBuffer On Input\n",__LINE__);
1290 printf("%d :: About to call OMX_UseBuffer On Input\n",__LINE__);
1291 error = OMX_UseBuffer(*pHandle,&pInputBufferHeader[i],0,NULL,nIpBufSize,pInputBuffer[i]);
1292 if(error != OMX_ErrorNone) {
1293 APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n",__LINE__);
1294 return (error);
1295 }
1296 }
1297 }
1298
1299 if (gDasfMode == 0) {
1300 for(i=0; i<nOpBuffs; i++) {
1301 if (pOutputBuffer[i] == NULL) {
1302 pOutputBuffer[i] = malloc (nOpBufSize + 256);
1303 pOutputBuffer[i] = pOutputBuffer[i] + 128;
1304 /* allocate output buffer */
1305 APP_DPRINT("%d :: About to call OMX_UseBuffer On Output\n",__LINE__);
1306 printf("%d :: About to call OMX_UseBuffer On Output\n",__LINE__);
1307 error = OMX_UseBuffer(*pHandle,&pOutputBufferHeader[i],1,NULL,nOpBufSize,pOutputBuffer[i]);
1308 if(error != OMX_ErrorNone) {
1309 APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n",__LINE__);
1310 return (error);
1311 }
1312 pOutputBufferHeader[i]->nFilledLen = 0;
1313 }
1314 }
1315 }
1316 #endif
1317 return (error);
1318 }
1319
1320 /* ================================================================================= * */
1321 /**
1322 * @fn testCases() This is the main function of application which gets called.
1323 *
1324 */
1325 /* ================================================================================ * */
testCases(OMX_HANDLETYPE * pHandle,fd_set * rfds,int tcID,FILE * fIn,FILE * fOut,int * frmCnt,int * totalFilled,struct timeval * tv,int gDasfMode,int nIpBuffs,OMX_BUFFERHEADERTYPE * pInputBufferHeader[],int nOpBuffs,OMX_BUFFERHEADERTYPE * pOutputBufferHeader[])1326 OMX_ERRORTYPE testCases (OMX_HANDLETYPE *pHandle, fd_set *rfds, int tcID, FILE *fIn, FILE *fOut, int *frmCnt, int *totalFilled, struct timeval *tv, int gDasfMode, int nIpBuffs, OMX_BUFFERHEADERTYPE *pInputBufferHeader [], int nOpBuffs, OMX_BUFFERHEADERTYPE *pOutputBufferHeader [])
1327 {
1328 boolean bFlag = true;
1329 static int frmCount = 0;
1330
1331 OMX_ERRORTYPE error = OMX_ErrorNone;
1332 int fdmax = maxint(IpBuf_Pipe [0], OpBuf_Pipe [0]);
1333 fdmax = maxint (fdmax, Event_Pipe [0]);
1334
1335 FD_ZERO (rfds);
1336 FD_SET (IpBuf_Pipe[0], rfds);
1337 FD_SET (OpBuf_Pipe[0], rfds);
1338 FD_SET (Event_Pipe[0], rfds);
1339 tv->tv_sec = 1;
1340 tv->tv_usec = 0;
1341
1342 int retval = select(fdmax+1, rfds, NULL, NULL, tv);
1343 if(retval == -1) {
1344 perror("select()");
1345 APP_DPRINT ( " : Error \n");
1346 return (OMX_EventError);
1347 }
1348
1349 if(retval == 0) {
1350 APP_DPRINT ("%d :: BasicFn App Timeout !!!!!!!!!!! \n",__LINE__);
1351 }
1352 /*****/
1353 frmCount++;
1354
1355 switch (tcID) {
1356 case 1:
1357 case 5:
1358 case 6:
1359 if(FD_ISSET(IpBuf_Pipe[0], rfds)) {
1360 OMX_BUFFERHEADERTYPE* pBuffer = NULL;
1361 read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
1362 APP_DPRINT("%d :: APP: input buffer received, filled length = %d\n",__LINE__,(int)pBuffer->nFilledLen);
1363 error = send_input_buffer (*pHandle, pBuffer, fIn);
1364 if (error != OMX_ErrorNone) {
1365 return (error);
1366 }
1367 }
1368 break;
1369 case 2:
1370 case 4:
1371 if(FD_ISSET(IpBuf_Pipe[0], rfds)) {
1372 if(*frmCnt == 4) {
1373 APP_DPRINT("Shutting down ---------- \n");
1374 #ifdef OMX_GETTIME
1375 GT_START();
1376 #endif
1377 error = OMX_SendCommand(*pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);
1378 if(error != OMX_ErrorNone) {
1379 fprintf (stderr,"Error from SendCommand-Idle(Stop) State function\n");
1380 return (error);
1381 }
1382 if(tcID == 4) {
1383 error = testCase_2_4 (pHandle, gDasfMode, fIn, fOut, nIpBuffs, pInputBufferHeader);
1384 if(error != OMX_ErrorNone) {
1385 fprintf (stderr,"Error from SendCommand-Idle(Stop) State function\n");
1386 return (error);
1387 }
1388 }
1389 } else {
1390 OMX_BUFFERHEADERTYPE* pBuffer = NULL;
1391 read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
1392 error = send_input_buffer (*pHandle, pBuffer, fIn);
1393 if (error != OMX_ErrorNone) {
1394 return (error);
1395 }
1396 }
1397 (*frmCnt)++;
1398 }
1399 break;
1400 case 3:
1401 if(frmCount == 3 || frmCount == 6) {
1402 error = testCase_3 (pHandle);
1403 if(error != OMX_ErrorNone) {
1404 return (error);
1405 }
1406 }
1407
1408 if(FD_ISSET(IpBuf_Pipe[0], rfds)) {
1409
1410 OMX_BUFFERHEADERTYPE* pBuffer = NULL;
1411 read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
1412 error = send_input_buffer (*pHandle, pBuffer, fIn);
1413 if (error != OMX_ErrorNone) {
1414 return (error);
1415 }
1416
1417 (*frmCnt)++;
1418 }
1419 break;
1420 case 7:
1421 /* test mute/unmute playback stream */
1422 if(FD_ISSET(IpBuf_Pipe[0], rfds)) {
1423 OMX_BUFFERHEADERTYPE* pBuffer = NULL;
1424 read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
1425 error = send_input_buffer (*pHandle, pBuffer, fIn);
1426 if (error != OMX_ErrorNone) {
1427 return (error);
1428 }
1429 (*frmCnt)++;
1430 }
1431
1432 if(*frmCnt == 3) {
1433 printf("************Mute the playback stream*****************\n");
1434 bFlag = omxSetConfigMute (pHandle, OMX_TRUE);
1435 if (bFlag == FALSE) {
1436 return (error);
1437 }
1438 }
1439
1440 if(*frmCnt == 6) {
1441 printf("************Unmute the playback stream*****************\n");
1442 bFlag = omxSetConfigMute (pHandle, OMX_FALSE);
1443 if (bFlag == FALSE) {
1444 return (error);
1445 }
1446 }
1447 break;
1448
1449 case 8:
1450 /* test set volume for playback stream */
1451 if(FD_ISSET(IpBuf_Pipe[0], rfds)) {
1452 OMX_BUFFERHEADERTYPE* pBuffer = NULL;
1453 read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
1454 error = send_input_buffer (*pHandle, pBuffer, fIn);
1455 if (error != OMX_ErrorNone) {
1456 return (error);
1457 }
1458
1459 (*frmCnt)++;
1460 }
1461
1462 if(*frmCnt == 3) {
1463 printf("************Set stream volume to high*****************\n");
1464 bFlag = omxSetConfigVolume (pHandle, 0x8000);
1465 if (bFlag == FALSE) {
1466 return (error);
1467 }
1468 }
1469
1470 if(*frmCnt == 6) {
1471 printf("************Set stream volume to low*****************\n");
1472 bFlag = omxSetConfigVolume (pHandle, 0x1000);
1473 if (bFlag == FALSE) {
1474 return (error);
1475 }
1476 }
1477 break;
1478 case 9:
1479 if(FD_ISSET(IpBuf_Pipe[0], rfds)) {
1480 OMX_BUFFERHEADERTYPE* pBuffer= NULL;
1481 read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
1482 APP_DPRINT("%d :: APP: input buffer received, filled length = %d\n",__LINE__,(int)pBuffer->nFilledLen);
1483 error = send_input_buffer (*pHandle, pBuffer, fIn);
1484 if (error != OMX_ErrorNone) {
1485 return (error);
1486 }
1487
1488 pBuffer->nTimeStamp = (OMX_S64) rand() % 70;
1489 pBuffer->nTickCount = (OMX_S64) rand() % 70;
1490 printf("SENDING TIMESTAMP = %d\n", (int) pBuffer->nTimeStamp);
1491 printf("SENDING TICK COUNT = %ld\n", pBuffer->nTickCount);
1492 }
1493 break;
1494
1495 default:
1496 APP_DPRINT("%d :: ### Running Simple DEFAULT Case Here ###\n",__LINE__);
1497 } /* end switch */
1498 /**********************/
1499 if( FD_ISSET(OpBuf_Pipe[0], rfds) ) {
1500 OMX_BUFFERHEADERTYPE* pBuf = NULL;
1501 read(OpBuf_Pipe[0], &pBuf, sizeof(pBuf));
1502 if(pBuf->nFlags == OMX_BUFFERFLAG_EOS){
1503 printf("EOS received by App, Stopping the component\n");
1504 pBuf->nFlags = 0;
1505 /* StopComponent(pHandle);*/
1506 fseek(fIn, 0, SEEK_SET);
1507 }
1508 if(pBuf->nFilledLen == 0) {
1509 APP_DPRINT("%d :: APP: output buffer received, filled length = %d, totalfilled = %d\n",__LINE__,(int)pBuf->nFilledLen,totalFilled);
1510 } else {
1511 APP_DPRINT("%d :: APP: output buffer received, filled length = %d, totalfilled = %d\n",__LINE__,(int)pBuf->nFilledLen,totalFilled);
1512 fwrite(pBuf->pBuffer, 1, pBuf->nFilledLen, fOut);
1513 }
1514 totalFilled += pBuf->nFilledLen;
1515 fflush(fOut);
1516 OMX_FillThisBuffer(*pHandle, pBuf);
1517 }
1518 /*************/
1519 /*<<<<<<< Process Manager <<<<<<< */
1520 if ( FD_ISSET (Event_Pipe[0], rfds) ) {
1521 OMX_U8 pipeContents =0;
1522 read(Event_Pipe[0], &pipeContents, sizeof(OMX_U8));
1523
1524 if (pipeContents == 0) {
1525
1526 printf("Test app received OMX_ErrorResourcesPreempted\n");
1527 WaitForState(pHandle,OMX_StateIdle);
1528 int i;
1529 for (i=0; i < nIpBuffs; i++) {
1530 error = OMX_FreeBuffer (pHandle,OMX_DirInput,pInputBufferHeader[i]);
1531 if( (error != OMX_ErrorNone)) {
1532 APP_DPRINT ("%d :: G722DecTest.c :: Error in Free Handle function\n",__LINE__);
1533 }
1534 }
1535
1536 if (gDasfMode == 0) {
1537 for (i=0; i < nOpBuffs; i++) {
1538 error = OMX_FreeBuffer (pHandle,OMX_DirOutput,pOutputBufferHeader[i]);
1539 if( (error != OMX_ErrorNone)) {
1540 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
1541 }
1542 }
1543 }
1544
1545 #ifdef USE_BUFFER
1546 /* newfree the App Allocated Buffers */
1547 APP_DPRINT("%d :: AmrDecTest.c :: Freeing the App Allocated Buffers in TestApp\n",__LINE__);
1548 for(i=0; i < nIpBuffs; i++) {
1549 APP_MEMPRINT("%d::: [TESTAPPFREE] pInputBuffer[%d] = %p\n",__LINE__,i,pInputBuffer[i]);
1550 if(pInputBuffer[i] != NULL){
1551 pInputBuffer[i] = pInputBuffer[i] - 128;
1552 newfree(pInputBuffer[i]);
1553 pInputBuffer[i] = NULL;
1554 }
1555 }
1556 for(i=0; i < numOutputBuffers; i++) {
1557 APP_MEMPRINT("%d::: [TESTAPPFREE] pOutputBuffer[%d] = %p\n",__LINE__,i, pOutputBuffer[i]);
1558 if(pOutputBuffer[i] != NULL){
1559 pOutputBuffer[i] = pOutputBuffer[i] - 128;
1560 newfree(pOutputBuffer[i]);
1561 pOutputBuffer[i] = NULL;
1562 }
1563 }
1564 #endif
1565
1566 OMX_SendCommand(*pHandle,OMX_CommandStateSet, OMX_StateIdle/*OMX_StateLoaded*/,NULL);
1567 WaitForState(pHandle, OMX_StateIdle/*OMX_StateLoaded*/);
1568 #ifdef WAITFORRESOURCES
1569 OMX_SendCommand(*pHandle,OMX_CommandStateSet,OMX_StateWaitForResources,NULL);
1570 WaitForState(pHandle,OMX_StateWaitForResources);
1571 #endif
1572 } else if (pipeContents == 1) {
1573
1574 printf("Test app received OMX_ErrorResourcesAcquired\n");
1575
1576 OMX_SendCommand(*pHandle,OMX_CommandStateSet,OMX_StateIdle,NULL);
1577 int i = 0;
1578 for (i=0; i < nIpBuffs; i++) {
1579 /* allocate input buffer */
1580 error = OMX_AllocateBuffer (*pHandle,&pInputBufferHeader[i],0,NULL, G722D_INPUT_BUFFER_SIZE *3); /*To have enought space for */
1581 if(error != OMX_ErrorNone) {
1582 APP_DPRINT("%d :: G722DecTest.c :: Error returned by OMX_AllocateBuffer()\n",__LINE__);
1583 }
1584 }
1585 WaitForState(pHandle,OMX_StateIdle);
1586 OMX_SendCommand(*pHandle,OMX_CommandStateSet,OMX_StateExecuting,NULL);
1587 WaitForState(pHandle,OMX_StateExecuting);
1588 rewind(fIn);
1589
1590 for (i=0; i < nIpBuffs;i++) {
1591 send_input_buffer(*pHandle, pInputBufferHeader[i], fIn);
1592 }
1593 } else if (pipeContents == 2) {
1594 OMX_STATETYPE CurState = OMX_StateInvalid;
1595 char strCurrState [20] = {""};
1596
1597 error = OMX_GetState(*pHandle, &CurState);
1598 getString_OMX_State (strCurrState, CurState);
1599 error = OMX_SendCommand(*pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);
1600 error = WaitForState(pHandle, OMX_StateIdle);
1601 #ifdef OMX_GETTIME
1602 GT_END("Call to SendCommand <OMX_StateIdle>");
1603 #endif
1604 if(error != OMX_ErrorNone) {
1605 printf("\nError: WaitForState reports an error %X!!!!!!!\n", error);
1606 return error;
1607 }
1608 /*
1609 #if 1
1610 error = OMX_SendCommand(*pHandle,OMX_CommandStateSet, OMX_StateLoaded, NULL);
1611 if(error != OMX_ErrorNone) {
1612 APP_DPRINT ("%d :: G722DecTest.c :: Error from SendCommand-Idle State function\n",__LINE__);
1613 printf("goto EXIT %d\n",__LINE__);
1614
1615 *goto EXIT;*
1616 return (-1);
1617 }
1618 error = WaitForState(pHandle, OMX_StateLoaded);
1619 if(error != OMX_ErrorNone) {
1620 APP_DPRINT( "%d :: G722DecTest.c :: Error: WaitForState reports an error %X\n",__LINE__, error);
1621 printf("goto EXIT %d\n",__LINE__);
1622 *goto EXIT;*
1623 return (-1);
1624 }
1625 # ifdef OMX_GETTIME
1626 GT_END("Call to SendCommand <OMX_StateIdle>"); *<OMX_StateLoaded>");*
1627 # endif
1628
1629 #endif
1630 */
1631 /*goto SHUTDOWN;*/
1632 return (OMX_ErrorNone);
1633 /**/
1634 } else {
1635 printf ("--------> Pipe content = %d <----------\n", pipeContents);
1636 }
1637 }
1638 return (error);
1639 }
1640
1641 /* ================================================================================= * */
1642 /**
1643 * @fn testCase_2_4() This is the main function of application which gets called.
1644 *
1645 */
1646 /* ================================================================================ * */
testCase_2_4(OMX_HANDLETYPE * pHandle,int gDasfMode,FILE * fIn,FILE * fOut,int nIpBuffs,OMX_BUFFERHEADERTYPE * pInputBufferHeader[])1647 OMX_ERRORTYPE testCase_2_4 (OMX_HANDLETYPE *pHandle, int gDasfMode, FILE *fIn, FILE *fOut, int nIpBuffs, OMX_BUFFERHEADERTYPE *pInputBufferHeader [])
1648 {
1649 OMX_ERRORTYPE error = OMX_ErrorNone;
1650
1651 APP_STATEPRINT ("*********** Waiting for state to change to Idle ************\n\n");
1652
1653 #ifdef OMX_GETTIME
1654 GT_END("Call to SendCommand <OMX_StateIdle>");
1655 #endif
1656
1657 error = WaitForState(pHandle, OMX_StateIdle);
1658 if(error != OMX_ErrorNone) {
1659 fprintf(stderr, "Error: WaitForState reports an error %X\n", error);
1660 return (error);
1661 }
1662 APP_STATEPRINT("*********** State Changed to Idle ************\n\n");
1663
1664 printf("Component Has Stopped here and waiting for %d seconds before it plays further\n",SLEEP_TIME);
1665 sleep(SLEEP_TIME);
1666
1667 APP_STATEPRINT("*************** Execute command to Component *******************\n");
1668
1669 #ifdef OMX_GETTIME
1670 GT_START();
1671 #endif
1672
1673 error = OMX_SendCommand(*pHandle, OMX_CommandStateSet,OMX_StateExecuting, NULL);
1674 if(error != OMX_ErrorNone) {
1675 fprintf (stderr,"Error from SendCommand-Executing State function\n");
1676 return (error);
1677 }
1678
1679 APP_STATEPRINT("*********** Waiting for state to change to Executing ************\n\n");
1680 error = WaitForState(pHandle, OMX_StateExecuting);
1681
1682 #ifdef OMX_GETTIME
1683 GT_START();
1684 #endif
1685 if(error != OMX_ErrorNone) {
1686 fprintf(stderr, "Error: WaitForState reports an error %X\n", error);
1687 return (error);
1688 }
1689 APP_STATEPRINT("*********** State Changed to Executing ************\n\n");
1690
1691 if (gDasfMode == 0) {
1692 /*rewind input and output files*/
1693 fseek(fIn, 0L, SEEK_SET);
1694 fseek(fOut, 0L, SEEK_SET);
1695 }
1696 int k = 0;
1697 for (k=0; k < nIpBuffs; k++) {
1698 error = send_input_buffer (*pHandle, pInputBufferHeader[k], fIn);
1699 }
1700 return (error);
1701 }
1702 /* ================================================================================= * */
1703 /**
1704 * @fn testCase_3() This is the main function of application which gets called.
1705 *
1706 */
1707 /* ================================================================================ * */
testCase_3(OMX_HANDLETYPE * pHandle)1708 OMX_ERRORTYPE testCase_3 (OMX_HANDLETYPE *pHandle)
1709 {
1710 OMX_ERRORTYPE error = OMX_ErrorNone;
1711
1712 APP_STATEPRINT("\n\n*************** Pause command to Component *******************\n");
1713
1714 #ifdef OMX_GETTIME
1715 GT_END("Call to SendCommand <OMX_StateExecuting>");
1716 #endif
1717
1718 error = OMX_SendCommand (*pHandle, OMX_CommandStateSet, OMX_StatePause, NULL);
1719 if(error != OMX_ErrorNone) {
1720 fprintf (stderr,"Error from SendCommand-Pasue State function\n");
1721 return (error);
1722 }
1723 APP_STATEPRINT("*********** Waiting for state to change to Pause ************\n");
1724 #ifdef OMX_GETTIME
1725 GT_START();
1726 #endif
1727 error = WaitForState (pHandle, OMX_StatePause);
1728
1729 if(error != OMX_ErrorNone) {
1730 fprintf(stderr, "Error: WaitForState reports an error %X\n", error);
1731 return (error);
1732 }
1733 APP_STATEPRINT("*********** State Changed to Pause ************\n\n");
1734
1735 printf("Sleeping for %d secs....\n\n",SLEEP_TIME);
1736 sleep(SLEEP_TIME);
1737
1738 APP_STATEPRINT("*************** Resume command to Component *******************\n");
1739 #ifdef OMX_GETTIME
1740 GT_END("Call to SendCommand <OMX_StatePause>");
1741 #endif
1742 error = OMX_SendCommand (*pHandle, OMX_CommandStateSet,OMX_StateExecuting, NULL);
1743 if(error != OMX_ErrorNone) {
1744 fprintf (stderr,"Error from SendCommand-Executing State function\n");
1745 return (error);
1746 }
1747
1748 APP_STATEPRINT("******** Waiting for state to change to Resume ************\n");
1749
1750 #ifdef OMX_GETTIME
1751 GT_END("Call to SendCommand <OMX_StateExecuting>");
1752 #endif
1753
1754 error = WaitForState (pHandle, OMX_StateExecuting);
1755 if(error != OMX_ErrorNone) {
1756 fprintf(stderr, "Error: WaitForState reports an error %X\n", error);
1757 return (error);
1758 }
1759 APP_STATEPRINT("*********** State Changed to Resume ************\n\n");
1760
1761 return (error);
1762 }
1763 /* ================================================================================= * */
1764 /**
1765 * @fn sendInBuffFillOutBuff() This is the main function of application which gets called.
1766 *
1767 */
1768 /* ================================================================================ * */
sendInBuffFillOutBuff(OMX_HANDLETYPE * pHandle,int nIpBuffs,int nOpBuffs,int gDasfMode,OMX_BUFFERHEADERTYPE * pInputBufferHeader[],FILE * fIn,OMX_BUFFERHEADERTYPE * pOutputBufferHeader[])1769 OMX_ERRORTYPE sendInBuffFillOutBuff (OMX_HANDLETYPE *pHandle, int nIpBuffs, int nOpBuffs, int gDasfMode, OMX_BUFFERHEADERTYPE *pInputBufferHeader[], FILE *fIn, OMX_BUFFERHEADERTYPE *pOutputBufferHeader[])
1770 {
1771 int k = 0;
1772 OMX_ERRORTYPE error = OMX_ErrorNone;
1773
1774 for (k=0; k < nIpBuffs; k++) {
1775 #ifdef OMX_GETTIME
1776 if (k == 0) {
1777 GT_FlagE=1; /* 1 = First Buffer, 0 = Not First Buffer */
1778 GT_START(); /* Empty Bufffer */
1779 }
1780 #endif
1781 error = send_input_buffer (*pHandle, pInputBufferHeader[k], fIn);
1782 if(error != OMX_ErrorNone) {
1783 return (error);
1784 }
1785 }
1786 if (gDasfMode == 0) {
1787 for (k=0; k < nOpBuffs; k++) {
1788 #ifdef OMX_GETTIME
1789 if (k == 0) {
1790 GT_FlagF=1; /* 1 = First Buffer, 0 = Not First Buffer */
1791 GT_START(); /* Fill Buffer */
1792 }
1793 #endif
1794 error = OMX_FillThisBuffer (*pHandle, pOutputBufferHeader[k]);
1795 if(error != OMX_ErrorNone) {
1796 return (error);
1797 }
1798 }
1799 }
1800 return (error);
1801 }
1802 /* ================================================================================= * */
1803 /**
1804 * @fn omxFreeBuffers() This is the main function of application which gets called.
1805 *
1806 */
1807 /* ================================================================================ * */
omxFreeBuffers(OMX_HANDLETYPE * pHandle,int nBuffs,OMX_BUFFERHEADERTYPE * pBufferHeader[],char * sBuffTypeMsg)1808 OMX_ERRORTYPE omxFreeBuffers (OMX_HANDLETYPE *pHandle, int nBuffs, OMX_BUFFERHEADERTYPE *pBufferHeader [], char *sBuffTypeMsg)
1809 {
1810 int i = 0;
1811 OMX_ERRORTYPE error = OMX_ErrorNone;
1812
1813 for (i=0; i<nBuffs; i++) {
1814 APP_DPRINT("%d :: App: Freeing %p %s BufHeader\n",__LINE__,pBufferHeader[i], sBuffTypeMsg);
1815 error = OMX_FreeBuffer(*pHandle,OMX_DirInput,pBufferHeader[i]);
1816 if((error != OMX_ErrorNone)) {
1817 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
1818 return (error);
1819 }
1820 }
1821
1822 return (error);
1823 }
1824 /* ================================================================================= * */
1825 /**
1826 * @fn getString_OMX_State () This is the main function of application which gets called.
1827 *
1828 */
1829 /* ================================================================================ * */
getString_OMX_State(char * ptrString,OMX_STATETYPE state)1830 void getString_OMX_State (char *ptrString, OMX_STATETYPE state)
1831 {
1832 switch (state) {
1833 case OMX_StateInvalid:
1834 strcpy (ptrString, "OMX_StateInvalid\0");
1835 break;
1836 case OMX_StateLoaded:
1837 strcpy (ptrString, "OMX_StateLoaded\0");
1838 break;
1839 case OMX_StateIdle:
1840 strcpy (ptrString, "OMX_StateIdle\0");
1841 break;
1842 case OMX_StateExecuting:
1843 strcpy (ptrString, "OMX_StateExecuting\0");
1844 break;
1845 case OMX_StatePause:
1846 strcpy (ptrString, "OMX_StatePause\0");
1847 break;
1848 case OMX_StateWaitForResources:
1849 strcpy (ptrString, "OMX_StateWaitForResources\0");
1850 break;
1851 case OMX_StateMax:
1852 strcpy (ptrString, "OMX_StateMax\0");
1853 break;
1854 default:
1855 strcpy (ptrString, "Unknown state\0");
1856 break;
1857
1858 }
1859 return;
1860 }
1861