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 PcmEncTest.c
26 *
27 * This file implements Test for PCM encoder OMX Component, which is fully
28 * compliant with the Khronos 1.0 specification.
29 *
30 * @path $(CSLPATH)\
31 *
32 * @rev 1.0
33 */
34 /* ----------------------------------------------------------------------------
35 *!
36 *! Revision History
37 *! ===================================
38 *! 24-Jan-2006 rg: Initial Version. Change required per OMAPSWxxxxxxxxx
39 *! to provide _________________.
40 *!
41 * ============================================================================= */
42
43 #include <unistd.h>
44 #include <stdlib.h>
45 #include <sys/ioctl.h>
46 #include <sys/select.h>
47 #include <string.h>
48 #include <stdio.h>
49 #include <fcntl.h>
50 #include <errno.h>
51 #include <linux/vt.h>
52 #include <signal.h>
53 #include <sys/stat.h>
54 #include <OMX_Index.h>
55 #include <OMX_Types.h>
56 #include <OMX_Component.h>
57 #include <OMX_Core.h>
58 #include <OMX_Audio.h>
59 #include <TIDspOmx.h>
60 #include <pthread.h>
61 #include <stdio.h>
62 #include <linux/soundcard.h>
63
64
65 #ifdef OMX_GETTIME
66 #include "OMX_Common_Utils.h"
67 #include "OMX_GetTime.h" /*Headers for Performance & measuremet */
68 #endif
69
70 #define INPUT_WMADEC_BUFFER_SIZE 4096 * 4
71 #define OUTPUT_WMADEC_BUFFER_SIZE 4096 * 10
72 #define NUM_WMADEC_INPUT_BUFFERS 1
73 #define NUM_WMADEC_OUTPUT_BUFFERS 1
74 #define STRESS_TEST_INTERATIONS 20
75
76 #define FIFO1 "/dev/fifo.1"
77 #define FIFO2 "/dev/fifo.2"
78
79 #define OMX_WMADEC_NonMIME 1
80 #define MIME_HEADER_LEN 6
81 #define WINDOW_PLAY_OFFSET 2
82 #undef APP_DEBUG
83 #undef APP_MEMCHECK
84 #undef TWOINPUTBUFFERS
85 #undef USE_BUFFER
86 /*For timestamp and tickcount*/
87 #undef APP_TIME_TIC_DEBUG
88 /* This Macro turns On the logic to detec memory
89 leaks on the App. To debug the component,
90 WMADEC_MEMDEBUG must be defined.*/
91 #undef APP_MEMDEBUG
92
93 #ifdef APP_DEBUG
94 #define APP_DPRINT(...) fprintf(stderr,__VA_ARGS__)
95 #else
96 #define APP_DPRINT(...)
97 #endif
98
99 #ifdef APP_TIME_TIC_DEBUG
100 #define TIME_PRINT(...) fprintf(stderr,__VA_ARGS__)
101 #define TICK_PRINT(...) fprintf(stderr,__VA_ARGS__)
102 #else
103 #define TIME_PRINT(...) if(frameMode)fprintf(stderr,__VA_ARGS__)
104 #define TICK_PRINT(...) if(frameMode)fprintf(stderr,__VA_ARGS__)
105 #endif
106
107 #ifdef APP_MEMDEBUG
108 void *arr[500];
109 int lines[500];
110 int bytes[500];
111 char file[500][50];
112 int r;
113 #define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
114 #define newfree(z) myfree(z,__LINE__,__FILE__)
115 void * mymalloc(int line, char *s, int size);
116 int myfree(void *dp, int line, char *s);
117 #else
118 #define newmalloc(x) malloc(x)
119 #define newfree(z) free(z)
120 #endif
121
122 #ifdef APP_MEMCHECK
123 #define APP_MEMPRINT(...) fprintf(stderr,__VA_ARGS__)
124 #else
125 #define APP_MEMPRINT(...)
126 #endif
127
128 /* Borrowed from http://www.dtek.chalmers.se/groups/dvd/dist/oss_audio.c */
129 /* AFMT_AC3 is really IEC61937 / IEC60958, mpeg/ac3/dts over spdif */
130 #ifndef AFMT_AC3
131 #define AFMT_AC3 0x00000400 /* Dolby Digital AC3 */
132 #endif
133 #ifndef AFMT_S32_LE
134 #define AFMT_S32_LE 0x00001000 /* 32/24-bits, in 24bit use the msbs */
135 #endif
136 #ifndef AFMT_S32_BE
137 #define AFMT_S32_BE 0x00002000 /* 32/24-bits, in 24bit use the msbs */
138 #endif
139
140 /* ======================================================================= */
141 /**
142 * Global variales declaration
143 */
144 /* ======================================================================= */
145 #ifdef OMX_GETTIME
146 OMX_ERRORTYPE eError = OMX_ErrorNone;
147 int GT_FlagE = 0; /* Fill Buffer 1 = First Buffer, 0 = Not First Buffer */
148 int GT_FlagF = 0; /*Empty Buffer 1 = First Buffer, 0 = Not First Buffer */
149 static OMX_NODE* pListHead = NULL;
150 #endif
151
152 FILE *fpRes;
153 static OMX_BOOL bInvalidState;
154 void* ArrayOfPointers[6];
155
156 pthread_mutex_t WaitForState_mutex;
157 pthread_cond_t WaitForState_threshold;
158 OMX_U8 WaitForState_flag;
159 OMX_U8 TargetedState;
160
161 int wmadecfdwrite;
162 int wmadecfdread;
163
164 /*AM_COMMANDDATATYPE cmd_data;*/
165
166 int gMimeFlag = 0;
167 int gStateNotifi = 0;
168 int gState;
169 int lastBufferSent = 0;
170 static int playCompleted = 0;
171 int sampleRateChange = 0;
172
173 fd_set rfds;
174 int done = 0;
175 int whileloopdone = 0;
176 int frameMode = 0;
177 /******************************************************************************/
178 OMX_S16 numInputBuffers = 0;
179 OMX_S16 numOutputBuffers = 0;
180 #ifdef USE_BUFFER
181 OMX_U8* pInputBuffer[10];
182 OMX_U8* pOutputBuffer[10];
183 #endif
184
185 OMX_BUFFERHEADERTYPE* pInputBufferHeader[10];
186 OMX_BUFFERHEADERTYPE* pOutputBufferHeader[10];
187
188 /*FILE *fIn=NULL;
189 int timeToExit = 0;*/
190 /* RM control */
191 int preempted = 0;
192 int Event_Pipe[2];
193 /******************************************************************************/
194
195 /* ======================================================================= */
196 /**
197 * Enumered Types
198 */
199 /* ======================================================================= */
200 typedef enum COMPONENTS {
201 COMP_1,
202 COMP_2
203 }COMPONENTS;
204
205 enum
206 {
207 NEXT_BITRATE_UNCHANGED = 0,
208 NEXT_BITRATE_CHANGED
209 };
210
211 typedef enum
212 {
213 MIME_NO_SUPPORT = 0,
214 MIME_SUPPORTED
215 }MIME_Settings;
216
217
218 /* ======================================================================= */
219 /**
220 * Function Declaration
221 */
222 /* ======================================================================= */
223
224 int GetInfoFromBufferHeader(unsigned char **pBufPtr, int *pCurBitRate,
225 int *pNextBitRateFlag);
226
227 void ResetBufferPointers(unsigned char **pBuffer);
228 int maxint(int a, int b);
229
230 int fill_data (OMX_BUFFERHEADERTYPE *pBuf, FILE *fIn);
231 int fill_data_tc7 (OMX_BUFFERHEADERTYPE *pBuf, FILE *fIn);
232 int unParse_Header (OMX_U8* pBuffer, FILE *fIn, int * payload);
233 void ConfigureAudio();
234
235 OMX_STRING strWmaEncoder = "OMX.TI.WMA.decode";
236 int IpBuf_Pipe[2];
237 int OpBuf_Pipe[2];
238 OMX_ERRORTYPE StopComponent(OMX_HANDLETYPE *pHandle);
239 OMX_ERRORTYPE send_input_buffer (OMX_HANDLETYPE pHandle, OMX_BUFFERHEADERTYPE* pBuffer, FILE *fIn);
240 OMX_ERRORTYPE send_input_buffer_tc7 (OMX_HANDLETYPE pHandle, OMX_BUFFERHEADERTYPE* pBuffer, FILE *fIn);
241 void fill_init_params(OMX_HANDLETYPE pHandle,const char * filename, int dasfmode, TI_OMX_DATAPATH * dataPath);
242 float calc_buff_size(FILE *fIn);
243 int FreeAllResources( OMX_HANDLETYPE pHandle,
244 OMX_BUFFERHEADERTYPE* pBufferIn,
245 OMX_BUFFERHEADERTYPE* pBufferOut,
246 int NIB, int NOB,
247 FILE* fIn, FILE* fOut);
248
249 #ifdef USE_BUFFER
250 int freeAllUseResources(OMX_HANDLETYPE pHandle,
251 OMX_U8* UseInpBuf[],
252 OMX_U8* UseOutBuf[],
253 int NIB, int NOB,
254 FILE* fIn, FILE* fOut);
255
256 #endif
257
258 /* safe routine to get the maximum of 2 integers */
maxint(int a,int b)259 int maxint(int a, int b)
260 {
261 return (a>b) ? a : b;
262 }
263
264 /* This method will wait for the component to get to the state
265 * specified by the DesiredState input. */
WaitForState(OMX_HANDLETYPE * pHandle,OMX_STATETYPE DesiredState)266 static OMX_ERRORTYPE WaitForState(OMX_HANDLETYPE* pHandle,
267 OMX_STATETYPE DesiredState)
268 {
269 OMX_STATETYPE CurState = OMX_StateInvalid;
270 OMX_ERRORTYPE eError1 = OMX_ErrorNone;
271 /*int nCnt = 0;*/
272 OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
273 eError1 = pComponent->GetState(pHandle, &CurState);
274 if (CurState == OMX_StateInvalid && bInvalidState == OMX_TRUE)
275 {
276 eError1 = OMX_ErrorInvalidState;
277 }
278 if( (eError1 == OMX_ErrorNone) &&
279 (CurState != DesiredState) )
280 {
281 APP_DPRINT( "%d :: App: WaitForState\n", __LINE__);
282 WaitForState_flag = 1;
283 TargetedState = DesiredState;
284 pthread_mutex_lock(&WaitForState_mutex);
285 pthread_cond_wait(&WaitForState_threshold, &WaitForState_mutex);/*Going to sleep till signal arrives*/
286 pthread_mutex_unlock(&WaitForState_mutex);
287 APP_DPRINT( "%d :: App: WaitForState\n", __LINE__);
288
289 }
290 if( eError1 != OMX_ErrorNone ) return eError1;
291 return OMX_ErrorNone;
292 }
293
294
295 /* ================================================================================= */
296 /**
297 * @fn EventHandler() description for SendCommand
298 EventHandler().
299 App event handler
300 *
301 * @see OMX_Core.h
302 */
303 /* ================================================================================ */
EventHandler(OMX_HANDLETYPE hComponent,OMX_PTR pAppData,OMX_EVENTTYPE eEvent,OMX_U32 nData1,OMX_U32 nData2,OMX_PTR pEventData)304 OMX_ERRORTYPE EventHandler(OMX_HANDLETYPE hComponent, OMX_PTR pAppData,
305 OMX_EVENTTYPE eEvent, OMX_U32 nData1, OMX_U32 nData2,
306 OMX_PTR pEventData)
307 {
308 OMX_U8 writeValue;
309
310 OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)hComponent;
311 OMX_STATETYPE state;
312 OMX_ERRORTYPE eError1;
313
314 #ifdef APP_DEBUG
315 int iComp = *((int *)(pAppData));
316 #endif
317 eError1 = pComponent->GetState (hComponent, &state);
318
319 if(eError1 != OMX_ErrorNone) {
320 APP_DPRINT("%d :: App: Error returned from GetState\n",__LINE__);
321 }
322
323 switch (eEvent) {
324 case OMX_EventCmdComplete:
325 if (nData1 == OMX_CommandPortDisable) {
326 if (nData2 == OMX_DirInput) {
327 APP_DPRINT ( "%d Component State Changed To %d\n", __LINE__,state);
328 }
329 if (nData2 == OMX_DirOutput) {
330 APP_DPRINT ( "%d Component State Changed To %d\n", __LINE__,state);
331 }
332 }
333
334 if ((nData1 == OMX_CommandStateSet) &&
335 (TargetedState == nData2) && (WaitForState_flag))
336 {
337 APP_DPRINT( "%d :: App: Component State Changed To %d\n", __LINE__,state);
338 WaitForState_flag = 0;
339 pthread_mutex_lock(&WaitForState_mutex);
340 /*Sending Waking Up Signal*/
341 pthread_cond_signal(&WaitForState_threshold);
342 pthread_mutex_unlock(&WaitForState_mutex);
343 }
344 APP_DPRINT( "%d :: App: Component State Changed To %d\n", __LINE__,state);
345 break;
346 case OMX_EventResourcesAcquired:
347 writeValue = 1;
348 preempted = 0;
349 write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
350 break;
351
352 case OMX_EventError:
353 if (nData1 != OMX_ErrorNone) {
354
355 }
356 else if(nData1 == OMX_ErrorResourcesPreempted) {
357 writeValue = 0;
358 preempted = 1;
359 write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
360 }
361 else if (nData1 == OMX_ErrorResourcesLost) {
362 WaitForState_flag = 0;
363 pthread_mutex_lock(&WaitForState_mutex);
364 pthread_cond_signal(&WaitForState_threshold);
365 pthread_mutex_unlock(&WaitForState_mutex);
366
367 }
368 if (nData1 == OMX_ErrorInvalidState) {
369 bInvalidState =OMX_TRUE;
370 }
371 break;
372 case OMX_EventMax:
373 break;
374 case OMX_EventMark:
375 break;
376 case OMX_EventBufferFlag:
377 APP_DPRINT( "%d :: App: EOS Event Received\n", __LINE__);
378 if((int)pEventData == OMX_BUFFERFLAG_EOS)
379 {
380 playCompleted = 1;
381 writeValue = 2;
382 write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
383 }
384 if(nData2 == (OMX_U32)OMX_BUFFERFLAG_EOS) {
385 if(nData1 == (OMX_U32)NULL)
386 puts("IN Buffer flag received!");
387 else if(nData1 == (OMX_U32)NULL)
388 puts("OUT Buffer flag received!");
389 }
390 break;
391 default:
392 break;
393 }
394 return eError1;
395 }
396
397
398 /* ================================================================================= */
399 /**
400 * @fn FillBufferDone() description for FillBufferDone
401 FillBufferDone().
402 Called by the component when an output buffer has been filled
403 *
404 * @see OMX_Core.h
405 */
406 /* ================================================================================ */
FillBufferDone(OMX_HANDLETYPE hComponent,OMX_PTR ptr,OMX_BUFFERHEADERTYPE * pBuffer)407 void FillBufferDone (OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer)
408 {
409 APP_DPRINT("APP:::: OUTPUT BUFFER = %p && %p, pBuffer->nFilledLen = %d\n",
410 pBuffer, pBuffer->pBuffer, pBuffer->nFilledLen);
411 /*add on: TimeStamp & TickCount EmptyBufferDone*/
412 TIME_PRINT("TimeStamp Output: %lld\n",pBuffer->nTimeStamp);
413 TICK_PRINT("TickCount Output: %ld\n\n",pBuffer->nTickCount);
414 write(OpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
415 #ifdef OMX_GETTIME
416 if (GT_FlagF == 1 ) /* First Buffer Reply*/ /* 1 = First Buffer, 0 = Not First Buffer */
417 {
418 GT_END("Call to FillBufferDone <First: FillBufferDone>");
419 GT_FlagF = 0 ; /* 1 = First Buffer, 0 = Not First Buffer */
420 }
421 #endif
422 }
423
424 /* ================================================================================= */
425 /**
426 * @fn EmptyBufferDone() description for EmptyBufferDone
427 EmptyBufferDone().
428 Called by the component when an input buffer has been emptied
429 *
430 * @see OMX_Core.h
431 */
432 /* ================================================================================ */
EmptyBufferDone(OMX_HANDLETYPE hComponent,OMX_PTR ptr,OMX_BUFFERHEADERTYPE * pBuffer)433 void EmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer)
434 {
435 APP_DPRINT ("APP:::: INPUT BUFFER = %p && %p\n",pBuffer, pBuffer->pBuffer);
436 APP_DPRINT("EmptyBufferDone\n");
437 if (!preempted)
438 write(IpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
439 #ifdef OMX_GETTIME
440 if (GT_FlagE == 1 ) /* First Buffer Reply*/ /* 1 = First Buffer, 0 = Not First Buffer */
441 {
442 GT_END("Call to EmptyBufferDone <First: EmptyBufferDone>");
443 GT_FlagE = 0; /* 1 = First Buffer, 0 = Not First Buffer */
444 }
445 #endif
446
447 }
448
449 /* ================================================================================= */
450 /**
451 * @fn main() description for main
452 main().
453 Test app main function
454 *
455 * @see OMX_Core.h
456 */
457 /* ================================================================================ */
main(int argc,char * argv[])458 int main(int argc, char* argv[])
459 {
460
461 printf("\n************************************************************************* \n*********** Entering to the WMA DEC TEST APP\n **************************************************************************\n");
462 OMX_CALLBACKTYPE WmaCaBa = {(void *)EventHandler,
463 (void*)EmptyBufferDone,
464 (void*)FillBufferDone};
465 OMX_HANDLETYPE pHandle;
466 OMX_ERRORTYPE error = OMX_ErrorNone;
467 OMX_U32 AppData = 100;
468 OMX_PARAM_PORTDEFINITIONTYPE* pCompPrivateStruct;
469 OMX_AUDIO_PARAM_WMATYPE *pWmaParam;
470 OMX_COMPONENTTYPE *pComponent_dasf;
471 OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
472 OMX_STATETYPE state;
473 /* TODO: Set a max number of buffers */
474 OMX_BUFFERHEADERTYPE* pInputBufferHeader[10];
475 /* TODO: Set a max number of buffers */
476 OMX_BUFFERHEADERTYPE* pOutputBufferHeader[10];
477 /*OMX_U32 count = 0;*/
478 /*OMX_U32 fdmax = 0;*/
479
480 FILE *fOut = NULL, *fIn = NULL;
481
482 bInvalidState=OMX_FALSE;
483 TI_OMX_DATAPATH dataPath;
484 OMX_INDEXTYPE index;
485
486 int k;
487 OMX_STATETYPE curState;
488
489 int numInputBuffers = 0;
490 int numOutputBuffers = 0;
491 struct timeval tv;
492 int retval, i, j;
493 int frmCount = 0;
494 int frmCnt = 1;
495 int testcnt = 1;
496 int testcnt1 = 1;
497 int dasfmode = 0;
498 int stress = 0;
499 OMX_U64 outBuffSize;
500 char fname[15] = "output";
501
502 pthread_mutex_init(&WaitForState_mutex, NULL);
503 pthread_cond_init (&WaitForState_threshold, NULL);
504 WaitForState_flag = 0;
505
506 APP_DPRINT("------------------------------------------------------\n");
507 APP_DPRINT("This is Main Thread In WMA DECODER Test Application:\n");
508 APP_DPRINT("Test Core 1.5 - " __DATE__ ":" __TIME__ "\n");
509 APP_DPRINT("------------------------------------------------------\n");
510
511 #ifdef OMX_GETTIME
512 printf("Line %d\n",__LINE__);
513 eError = OMX_ListCreate(&pListHead);
514 printf("Line %d\n",__LINE__);
515 printf("eError = %d\n",eError);
516 GT_START();
517 printf("Line %d\n",__LINE__);
518 #endif
519
520 /* check the input parameters */
521 if(!(argc == 7 || argc == 8)) {
522 printf( "Usage: test infile [outfile] args. Wrong Arguments: See Example Below\n");
523 printf( "./WmaDecTest_common test1_wma_v8_5kbps_8khz_1.rca test1_wma_v8_5kbps_8khz_1.WMA 1 0 1 1\n");
524 goto EXIT;
525 }
526 numInputBuffers = atoi(argv[5]);
527 numOutputBuffers = atoi(argv[6]);
528 if(numInputBuffers > 4 && numInputBuffers < 1)
529 {
530 APP_DPRINT( "Cannot support %u Input buffers\n", numInputBuffers);
531 goto EXIT;
532 }
533 if(numOutputBuffers > 4 && numOutputBuffers < 0)
534 {
535 APP_DPRINT( "Cannot support %u Output buffers\n", numOutputBuffers);
536 goto EXIT;
537 }
538
539 if( argv[7] != NULL )
540 {
541 if(!strcmp(argv[7], "FRAME"))
542 {
543 frameMode = 1;
544 printf("******** Frame mode selected *********\n");
545 }
546 else
547 {
548 stress = atoi(argv[7]);
549 }
550 }
551
552 /* check to see that the input file exists */
553 struct stat sb = {0};
554 int status = stat(argv[1], &sb);
555 if( status != 0 ) {
556 APP_DPRINT( "Cannot find file %s. (%u)\n", argv[1], errno);
557 goto EXIT;
558 }
559 APP_DPRINT("%d :: WmaTest\n",__LINE__);
560 dasfmode = atoi(argv[4]);
561 if(dasfmode == 1){
562 printf("DASF MODE\n");
563 }
564 else if(dasfmode == 0){
565 printf("NON DASF MODE\n");
566 }
567 else {
568 printf("Enter proper DASF mode\n");
569 printf("DASF:1\n");
570 printf("NON DASF:0\n");
571 goto EXIT;
572 }
573 /* Open the file of data to be rendered. */
574 fIn = fopen(argv[1], "r");
575 if( fIn == NULL ) {
576 APP_DPRINT( "Error: failed to open the file %s for readonly\access\n", argv[1]);
577 goto EXIT;
578 }
579
580 fOut = fopen(argv[2], "w");
581 if( fOut == NULL ) {
582 APP_DPRINT( "Error: failed to create the output file %s\n", argv[2]);
583 goto EXIT;
584 }
585
586 /* Create a pipe used to queue data from the callback. */
587 retval = pipe(IpBuf_Pipe);
588 if( retval != 0) {
589 APP_DPRINT( "Error:Fill Data Pipe failed to open\n");
590 goto EXIT;
591 }
592
593 retval = pipe(OpBuf_Pipe);
594 if( retval != 0) {
595 APP_DPRINT( "Error:Empty Data Pipe failed to open\n");
596 goto EXIT;
597 }
598 retval = pipe(Event_Pipe);
599 if( retval != 0) {
600 APP_DPRINT( "%d [WMADECTEST] Error: Empty Data Pipe failed to open\n",__LINE__);
601 goto EXIT;
602 }
603
604 /* save off the "max" of the handles for the selct statement */
605 int fdmax = maxint(IpBuf_Pipe[0], OpBuf_Pipe[0]);
606
607 APP_DPRINT("%d :: WmaTest\n",__LINE__);
608 error = TIOMX_Init();
609 APP_DPRINT("%d :: WmaTest\n",__LINE__);
610 if(error != OMX_ErrorNone) {
611 APP_DPRINT("%d :: Error returned by TIOMX_Init()\n",__LINE__);
612 goto EXIT;
613 }
614
615 APP_DPRINT("%d :: WmaTest\n",__LINE__);
616 switch (atoi(argv[3])) {
617 case 1:
618 printf ("-------------------------------------\n");
619 printf ("Testing Simple PLAY till EOF \n");
620 printf ("-------------------------------------\n");
621 break;
622 case 2:
623 printf ("-------------------------------------\n");
624 printf ("Testing Stop and Play \n");
625 printf ("-------------------------------------\n");
626 strcat(fname,"_tc2.pcm");
627 testcnt = 2;
628 break;
629 case 3:
630 printf ("-------------------------------------\n");
631 printf ("Testing PAUSE & RESUME Command\n");
632 printf ("-------------------------------------\n");
633 break;
634 case 4:
635 printf ("---------------------------------------------\n");
636 printf ("Testing STOP Command by Stopping In-Between\n");
637 printf ("---------------------------------------------\n");
638 break;
639 case 5:
640 printf ("-------------------------------------------------\n");
641 printf ("Testing Repeated PLAY without Deleting Component\n");
642 printf ("-------------------------------------------------\n");
643 strcat(fname,"_tc5.pcm");
644 if (stress)
645 {
646 testcnt = 100;
647 printf("****** Stress testing selected, running 100 iterations ******\n");
648 }
649 else
650 {
651 testcnt = STRESS_TEST_INTERATIONS;
652 }
653 break;
654 case 6:
655 printf ("------------------------------------------------\n");
656 printf ("Testing Repeated PLAY with Deleting Component\n");
657 printf ("------------------------------------------------\n");
658 strcat(fname,"_tc6.pcm");
659 if (stress)
660 {
661 testcnt1 = 100;
662 printf("****** Stress testing selected, running 100 iterations ******\n");
663 }
664 else
665 {
666 testcnt1 = STRESS_TEST_INTERATIONS;
667 }
668 break;
669 case 7:
670 printf ("------------------------------------------------\n");
671 printf ("Testing Window Play\n");
672 printf ("------------------------------------------------\n");
673 strcat(fname,"_tc6.pcm");
674 break;
675 case 8:
676 printf ("------------------------------------------------\n");
677 printf ("Testing Power Management\n");
678 printf ("------------------------------------------------\n");
679 sampleRateChange = 1;
680 break;
681 case 9:
682 printf ("------------------------------------------------------------\n");
683 printf ("Testing Ringtone test\n");
684 printf ("------------------------------------------------------------\n");
685 strcat(fname,"_tc9.pcm");
686 testcnt = 10;
687 break;
688 }
689
690 APP_DPRINT("%d :: WmaTest\n",__LINE__);
691 dasfmode = atoi(argv[4]);
692 if(dasfmode == 1){
693 printf("DASF MODE\n");
694 }
695 else if(dasfmode == 0){
696 printf("NON DASF MODE\n");
697 }
698 else {
699 printf("Enter proper DASF mode\n");
700 printf("DASF:1\n");
701 printf("NON DASF:0\n");
702 goto EXIT;
703 }
704
705 APP_DPRINT("%d :: WmaTest\n",__LINE__);
706 for(j = 0; j < testcnt1; j++) {
707 whileloopdone = 0;
708 if(j > 0) {
709 printf ("=Decoding the file %d Time\n",j+1);
710 close(IpBuf_Pipe[0]);
711 close(IpBuf_Pipe[1]);
712 close(OpBuf_Pipe[0]);
713 close(OpBuf_Pipe[1]);
714 close(Event_Pipe[0]);
715 close(Event_Pipe[1]);
716
717 /* Create a pipe used to queue data from the callback. */
718 retval = pipe(IpBuf_Pipe);
719 if( retval != 0) {
720 APP_DPRINT( "Error:Fill Data Pipe failed to open\n");
721 goto EXIT;
722 }
723 retval = pipe(OpBuf_Pipe);
724 if( retval != 0) {
725 APP_DPRINT( "Error:Empty Data Pipe failed to open\n");
726 goto EXIT;
727 }
728 retval = pipe(Event_Pipe);
729 if( retval != 0) {
730 APP_DPRINT( "%d [GSMFRTEST] Error:Empty Data Pipe failed to open\n",__LINE__);
731 goto EXIT;
732 }
733 fIn = fopen(argv[1], "r");
734 if( fIn == NULL ) {
735 fprintf(stderr, "Error: failed to open the file %s for readonly\
736 access\n", argv[1]);
737 goto EXIT;
738 }
739 fOut = fopen(fname, "w");
740 if( fOut == NULL ) {
741 fprintf(stderr, "Error: failed to create the output file \n");
742 goto EXIT;
743 }
744 error = TIOMX_Init();
745 if(error != OMX_ErrorNone) {
746 APP_DPRINT("%d [GSMFRTEST] Error returned by OMX_Init()\n",__LINE__);
747 goto EXIT;
748 }
749 }
750
751 #ifdef DSP_RENDERING_ON
752 if((wmadecfdwrite=open(FIFO1,O_WRONLY))<0)
753 {
754 printf("[WmaTEST] - failure to open WRITE pipe\n");
755 }
756 else
757 {
758 printf("[WmaTEST] - opened WRITE pipe\n");
759 }
760 if((wmadecfdread=open(FIFO2,O_RDONLY))<0)
761 {
762 printf("[WmaTEST] - failure to open READ pipe\n");
763 goto EXIT;
764 }
765 else
766 {
767 printf("[WmaTEST] - opened READ pipe\n");
768 }
769 #endif
770 /* Load the WMA Encoder Component */
771 APP_DPRINT("%d :: WmaTest\n",__LINE__);
772 #ifdef OMX_GETTIME
773 GT_START();
774 error = TIOMX_GetHandle(&pHandle, strWmaEncoder, &AppData, &WmaCaBa);
775 GT_END("Call to GetHandle");
776 #else
777 error = TIOMX_GetHandle(&pHandle, strWmaEncoder, &AppData, &WmaCaBa);
778 #endif
779
780 APP_DPRINT("%d :: WmaTest\n",__LINE__);
781 if((error != OMX_ErrorNone) || (pHandle == NULL)) {
782 APP_DPRINT ("Error in Get Handle function\n");
783 goto EXIT;
784 }
785
786 APP_DPRINT("%d :: WmaTest\n",__LINE__);
787 pCompPrivateStruct = newmalloc (sizeof (OMX_PARAM_PORTDEFINITIONTYPE));
788 ArrayOfPointers[0]=(OMX_PARAM_PORTDEFINITIONTYPE*)pCompPrivateStruct;
789 APP_MEMPRINT("%d:::[TESTAPPALLOC] %p\n",__LINE__,pCompPrivateStruct);
790
791 APP_DPRINT("%d :: WmaTest\n",__LINE__);
792 pCompPrivateStruct->nSize = sizeof (OMX_PARAM_PORTDEFINITIONTYPE);
793 pCompPrivateStruct->nVersion.s.nVersionMajor = 0xF1;
794 pCompPrivateStruct->nVersion.s.nVersionMinor = 0xF2;
795 APP_DPRINT("%d :: WmaTest\n",__LINE__);
796
797 /* Send input port config */
798 pCompPrivateStruct->nPortIndex = OMX_DirInput;
799 pCompPrivateStruct->format.audio.cMIMEType = newmalloc(20);
800 ArrayOfPointers[1]=pCompPrivateStruct->format.audio.cMIMEType;
801 APP_MEMPRINT("%d:::[TESTAPPALLOC] %p\n",__LINE__,pCompPrivateStruct->format.audio.cMIMEType);
802
803 #ifndef USE_BUFFER
804 APP_DPRINT("%d :: About to call OMX_AllocateBuffer\n",__LINE__);
805 for (i=0; i < numInputBuffers; i++) {
806 /* allocate input buffer */
807 APP_DPRINT("%d :: About to call OMX_AllocateBuffer\n",__LINE__);
808 error = OMX_AllocateBuffer(pHandle,&pInputBufferHeader[i],0,NULL,INPUT_WMADEC_BUFFER_SIZE);
809 APP_DPRINT("%d :: called OMX_AllocateBuffer\n",__LINE__);
810 if(error != OMX_ErrorNone) {
811 APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer()\n",__LINE__);
812 goto EXIT;
813 }
814
815 }
816
817 if (frameMode)
818 {
819 outBuffSize = calc_buff_size(fIn);
820 APP_DPRINT("%d :: outBuffSize %lld\n", outBuffSize, __LINE__);
821 fclose(fIn);
822 fIn = fopen(argv[1], "r");
823 if(fIn == NULL) {
824 fprintf(stderr, "Error: failed to open the file %s for readonly access\n", argv[1]);
825 goto EXIT;
826 }
827 }
828 else if (dasfmode == 1)
829 {
830 outBuffSize = 4096 * 2 * 2;
831 }
832 else
833 {
834 outBuffSize = OUTPUT_WMADEC_BUFFER_SIZE;
835 }
836 for (i=0; i < numOutputBuffers; i++) {
837 /* allocate output buffer */
838 APP_DPRINT("%d :: About to call OMX_AllocateBuffer\n",__LINE__);
839 error = OMX_AllocateBuffer(pHandle,&pOutputBufferHeader[i],1,NULL,outBuffSize);
840 APP_DPRINT("%d :: called OMX_AllocateBuffer\n",__LINE__);
841 if(error != OMX_ErrorNone) {
842 APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer()\n",__LINE__);
843 goto EXIT;
844 }
845 }
846 #else
847 OMX_U8* pInputBuffer;
848 OMX_U8* pOutputBuffer;
849
850
851 APP_DPRINT("%d :: About to call OMX_UseBuffer\n",__LINE__);
852
853
854 pOutputBuffer= newmalloc (OUTPUT_WMADEC_BUFFER_SIZE + 256);
855 APP_MEMPRINT("%d:::[TESTAPPALLOC] %p\n",__LINE__,pOutputBuffer);
856 pOutputBuffer = pOutputBuffer + 128;
857 pInputBuffer = (OMX_U8*)newmalloc(INPUT_WMADEC_BUFFER_SIZE);
858 APP_MEMPRINT("%d:::[TESTAPPALLOC] %p\n",__LINE__,pInputBuffer);
859
860 /* allocate input buffer */
861 APP_DPRINT("%d :: About to call OMX_UseBuffer\n",__LINE__);
862 error = OMX_UseBuffer(pHandle,&pInputBufferHeader,0,NULL,INPUT_WMADEC_BUFFER_SIZE,pInputBuffer);
863 APP_DPRINT("%d :: called OMX_UseBuffer\n",__LINE__);
864 if(error != OMX_ErrorNone) {
865 APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n",__LINE__);
866 goto EXIT;
867 }
868
869 if (frameMode)
870 {
871 outBuffSize = calc_buff_size(fIn);
872 printf("%d :: outBuffSize %d\n", outBuffSize, __LINE__);
873 fclose(fIn);
874 fIn = fopen(argv[1], "r");
875 if(fIn == NULL) {
876 fprintf(stderr, "Error: failed to open the file %s for readonly access\n", argv[1]);
877 goto EXIT;
878 }
879 }
880 else
881 {
882 outBuffSize = OUTPUT_WMADEC_BUFFER_SIZE;
883 }
884
885 /* allocate output buffer */
886 APP_DPRINT("%d :: About to call OMX_UseBuffer\n",__LINE__);
887 error = OMX_UseBuffer(pHandle,&pOutputBufferHeader,1,NULL,outBuffSize,pOutputBuffer);
888 APP_DPRINT("%d :: called OMX_UseBuffer\n",__LINE__);
889 if(error != OMX_ErrorNone) {
890 APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n",__LINE__);
891 goto EXIT;
892 }
893
894 #endif
895 pCompPrivateStruct->nPortIndex = OMX_DirInput;
896 pCompPrivateStruct->eDir = OMX_DirInput;
897 pCompPrivateStruct->nBufferCountActual = NUM_WMADEC_INPUT_BUFFERS;
898 pCompPrivateStruct->nBufferSize = INPUT_WMADEC_BUFFER_SIZE;
899 pCompPrivateStruct->format.audio.eEncoding = OMX_AUDIO_CodingWMA;
900
901
902
903 #ifdef OMX_GETTIME
904 GT_START();
905 error = OMX_SetParameter (pHandle,OMX_IndexParamAudioPortFormat, pCompPrivateStruct);
906 GT_END("Set Parameter Test-SetParameter");
907 #else
908 error = OMX_SetParameter (pHandle,OMX_IndexParamAudioPortFormat, pCompPrivateStruct);
909 #endif
910
911 if (error != OMX_ErrorNone) {
912 error = OMX_ErrorBadParameter;
913 printf ("%d:: OMX_ErrorBadParameter\n",__LINE__);
914 goto EXIT;
915 }
916
917 /* Send output port config */
918 pCompPrivateStruct->nPortIndex = OMX_DirOutput;
919 pCompPrivateStruct->eDir = OMX_DirOutput;
920 pCompPrivateStruct->nBufferCountActual = NUM_WMADEC_OUTPUT_BUFFERS;
921 pCompPrivateStruct->nBufferSize = outBuffSize;
922 pCompPrivateStruct->format.audio.eEncoding = OMX_AUDIO_CodingPCM;
923
924 if(dasfmode)
925 {
926 pCompPrivateStruct->nBufferCountActual = 0;
927 }
928
929 #ifdef OMX_GETTIME
930 GT_START();
931 error = OMX_SetParameter (pHandle,OMX_IndexParamAudioPortFormat, pCompPrivateStruct);
932 GT_END("Set Parameter Test-SetParameter");
933 #else
934 error = OMX_SetParameter (pHandle,OMX_IndexParamAudioPortFormat, pCompPrivateStruct);
935 #endif
936
937 if (error != OMX_ErrorNone) {
938 error = OMX_ErrorBadParameter;
939 printf ("%d:: OMX_ErrorBadParameter\n",__LINE__);
940 goto EXIT;
941 }
942
943 pWmaParam = newmalloc (sizeof (OMX_AUDIO_PARAM_WMATYPE));
944 ArrayOfPointers[2]=(OMX_AUDIO_PARAM_WMATYPE*)pWmaParam;
945 APP_MEMPRINT("%d:::[TESTAPPALLOC] %p\n",__LINE__,pWmaParam);
946 pWmaParam->nSize = sizeof (OMX_AUDIO_PARAM_WMATYPE);
947 pWmaParam->nVersion.s.nVersionMajor = 0xF1;
948 pWmaParam->nVersion.s.nVersionMinor = 0xF2;
949 pWmaParam->nPortIndex = OMX_DirInput;
950 pWmaParam->nChannels = 1;
951 pWmaParam->nBitRate = 8000;
952 pWmaParam->eFormat = OMX_AUDIO_WMAFormat9;
953
954 #ifdef OMX_GETTIME
955 GT_START();
956 error = OMX_SetParameter (pHandle,OMX_IndexParamAudioWma,pWmaParam);
957 GT_END("Set Parameter Test-SetParameter");
958 #else
959 error = OMX_SetParameter (pHandle,OMX_IndexParamAudioWma,pWmaParam);
960 #endif
961
962 if (error != OMX_ErrorNone) {
963 error = OMX_ErrorBadParameter;
964 printf ("%d:: OMX_ErrorBadParameter\n",__LINE__);
965 goto EXIT;
966 }
967
968 pWmaParam->nPortIndex = OMX_DirOutput;
969 pWmaParam->nChannels = 1;
970 pWmaParam->nBitRate = 8000;
971
972 #ifdef OMX_GETTIME
973 GT_START();
974 error = OMX_SetParameter (pHandle,OMX_IndexParamAudioWma,pWmaParam);
975 GT_END("Set Parameter Test--SetParameter");
976 #else
977 error = OMX_SetParameter (pHandle,OMX_IndexParamAudioWma,pWmaParam);
978 #endif
979
980 if (error != OMX_ErrorNone) {
981 error = OMX_ErrorBadParameter;
982 printf ("%d:: OMX_ErrorBadParameter\n",__LINE__);
983 goto EXIT;
984 }
985
986 pComponent_dasf = (OMX_COMPONENTTYPE *)pHandle;
987
988 if (dasfmode)
989 {
990 #ifdef RTM_PATH
991 dataPath = DATAPATH_APPLICATION_RTMIXER;
992 #endif
993
994 #ifdef ETEEDN_PATH
995 dataPath = DATAPATH_APPLICATION;
996 #endif
997 }
998
999 fill_init_params(pHandle,argv[1],dasfmode,&dataPath);
1000
1001 #ifdef OMX_GETTIME
1002 GT_START();
1003 error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
1004 GT_END("Call to SendCommand <OMX_StateIdle>");
1005 #else
1006 error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
1007 #endif
1008
1009 if(error != OMX_ErrorNone) {
1010 APP_DPRINT ("Error from SendCommand-Idle(Init) State function\n");
1011 goto EXIT;
1012 }
1013
1014 /* Wait for startup to complete */
1015 error = WaitForState(pHandle, OMX_StateIdle);
1016 if(error != OMX_ErrorNone) {
1017 APP_DPRINT( "Error: hWmaEncoder->WaitForState reports an error %X\n", error);
1018 goto EXIT;
1019 }
1020
1021 if(dasfmode)
1022 {
1023 /* get streamID back to application */
1024 error = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.wmastreamIDinfo",&index);
1025 if (error != OMX_ErrorNone) {
1026 printf("Error getting extension index\n");
1027 goto EXIT;
1028 }
1029 }
1030
1031 for(i = 0; i < testcnt; i++) {
1032 whileloopdone = 0;
1033 if(i > 0) {
1034 printf ("Decoding the file %d Time\n",i+1);
1035
1036 close(IpBuf_Pipe[0]);
1037 close(IpBuf_Pipe[1]);
1038 close(OpBuf_Pipe[0]);
1039 close(OpBuf_Pipe[1]);
1040
1041
1042 /* Create a pipe used to queue data from the callback. */
1043 retval = pipe(IpBuf_Pipe);
1044 if( retval != 0) {
1045 APP_DPRINT( "Error:Fill Data Pipe failed to open\n");
1046 goto EXIT;
1047 }
1048
1049 retval = pipe(OpBuf_Pipe);
1050 if( retval != 0) {
1051 APP_DPRINT( "Error:Empty Data Pipe failed to open\n");
1052 goto EXIT;
1053 }
1054 fIn = fopen(argv[1], "r");
1055 if(fIn == NULL) {
1056 fprintf(stderr, "Error: failed to open the file %s for readonly access\n", argv[1]);
1057 goto EXIT;
1058 }
1059 fOut = fopen(fname, "w");
1060 if(fOut == NULL) {
1061 fprintf(stderr, "Error: failed to create the output file \n");
1062 goto EXIT;
1063 }
1064 }
1065
1066 done = 0;
1067
1068 if (atoi(argv[3]) == 9){
1069 if(i==0){
1070 printf ("Basic Function:: Sending OMX_StateExecuting Command\n");
1071 #ifdef OMX_GETTIME
1072 GT_START();
1073 #endif
1074 error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
1075 if(error != OMX_ErrorNone) {
1076 APP_DPRINT ("Error from SendCommand-Executing State function\n");
1077 goto EXIT;
1078 }
1079 pComponent = (OMX_COMPONENTTYPE *)pHandle;
1080 error = WaitForState(pHandle, OMX_StateExecuting);
1081 #ifdef OMX_GETTIME
1082 GT_END("Call to SendCommand <OMX_StateExecuting>");
1083 #endif
1084 if(error != OMX_ErrorNone) {
1085 APP_DPRINT( "Error: hWmaEncoder->WaitForState reports an error %X\n", error);
1086 goto EXIT;
1087 }
1088 }
1089 }else{
1090 printf ("Basic Function (else):: Sending OMX_StateExecuting Command\n");
1091 #ifdef OMX_GETTIME
1092 GT_START();
1093 #endif
1094 error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
1095 if(error != OMX_ErrorNone) {
1096 APP_DPRINT ("Error from SendCommand-Executing State function\n");
1097 goto EXIT;
1098 }
1099 pComponent = (OMX_COMPONENTTYPE *)pHandle;
1100 error = WaitForState(pHandle, OMX_StateExecuting);
1101 #ifdef OMX_GETTIME
1102 GT_END("Call to SendCommand <OMX_StateExecuting>");
1103 #endif
1104 if(error != OMX_ErrorNone) {
1105 APP_DPRINT( "Error: hWmaEncoder->WaitForState reports an error %X\n", error);
1106 goto EXIT;
1107 }
1108 }
1109
1110 if (atoi(argv[3]) == 7) {
1111 for (k=0; k < numInputBuffers; k++) {
1112 #ifdef OMX_GETTIME
1113 if (k==0)
1114 {
1115 GT_FlagE=1; /* 1 = First Buffer, 0 = Not First Buffer */
1116 GT_START(); /* Empty Bufffer */
1117 }
1118 #endif
1119 error = send_input_buffer_tc7 (pHandle, pInputBufferHeader[k], fIn);
1120 }
1121 }
1122 else {
1123 for (k=0; k < numInputBuffers; k++) {
1124 #ifdef OMX_GETTIME
1125 if (k==0)
1126 {
1127 GT_FlagE=1; /* 1 = First Buffer, 0 = Not First Buffer */
1128 GT_START(); /* Empty Bufffer */
1129 }
1130 #endif
1131 error = send_input_buffer (pHandle, pInputBufferHeader[k], fIn);
1132 }
1133 }
1134 if (dasfmode == 0)
1135 {
1136 for (k=0; k < numOutputBuffers; k++) {
1137 #ifdef OMX_GETTIME
1138 if (k==0)
1139 {
1140 GT_FlagF=1; /* 1 = First Buffer, 0 = Not First Buffer */
1141 GT_START(); /* Fill Buffer */
1142 }
1143 #endif
1144 pComponent->FillThisBuffer(pHandle, pOutputBufferHeader[k]);
1145 }
1146 }
1147
1148 if(sampleRateChange) {
1149 /*
1150 cmd_data.hComponent = pHandle;
1151 cmd_data.AM_Cmd = AM_CommandWarnSampleFreqChange;
1152 cmd_data.param1 = 44100;*/
1153 #ifdef DSP_RENDERING_ON
1154 if((write(wmadecfdwrite, &cmd_data, sizeof(cmd_data)))<0) {
1155 printf("send command to audio manager\n");
1156 }
1157 #endif
1158 }
1159 OMX_GetState(pHandle,&curState);
1160
1161 while((error == OMX_ErrorNone && curState != OMX_StateIdle )
1162 && curState != OMX_StateInvalid) {
1163
1164 FD_ZERO(&rfds);
1165 FD_SET(IpBuf_Pipe[0], &rfds);
1166 FD_SET(OpBuf_Pipe[0], &rfds);
1167 tv.tv_sec = 1;
1168 tv.tv_usec = 0;
1169 frmCount++;
1170 retval = select(fdmax+1, &rfds, NULL, NULL, &tv);
1171
1172 if(retval == -1) {
1173 perror("select()");
1174 APP_DPRINT ( " : Error \n");
1175 break;
1176 }
1177
1178 if(retval == 0) {
1179 APP_DPRINT ("%d :: BasicFn App Timeout !!!!!!!!!!! \n",__LINE__);
1180 }
1181
1182 switch (atoi(argv[3])) {
1183 case 1:
1184 case 5:
1185 case 6:
1186 case 8:
1187 if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {
1188 OMX_BUFFERHEADERTYPE* pBuffer;
1189 read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
1190 pBuffer->nTimeStamp = rand() % 100;
1191 pBuffer->nTickCount = rand() % 70;
1192 TIME_PRINT("TimeStamp Input: %lld\n",pBuffer->nTimeStamp);
1193 TICK_PRINT("TickCount Input: %ld\n",pBuffer->nTickCount);
1194 if(!playCompleted)
1195 {
1196 APP_DPRINT("APP:: %d send_input_buffer (pHandle, pBuffer, fIn)\n", __LINE__);
1197 error = send_input_buffer (pHandle, pBuffer, fIn);
1198 }
1199 if (error != OMX_ErrorNone) {
1200 printf ("Error While reading input pipe\n");
1201 goto EXIT;
1202 }
1203 frmCnt++;
1204 }
1205 break;
1206
1207 case 7:
1208 if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {
1209 OMX_BUFFERHEADERTYPE* pBuffer;
1210 read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
1211 error = send_input_buffer_tc7 (pHandle, pBuffer, fIn);
1212 if (error != OMX_ErrorNone) {
1213 printf ("Error While reading input pipe\n");
1214 goto EXIT;
1215 }
1216 frmCnt++;
1217 }
1218 break;
1219
1220 case 2:
1221 if(frmCount == 10) {
1222 printf (" Sending Stop command to Codec \n");
1223
1224 #ifdef OMX_GETTIME
1225 GT_START();
1226 error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
1227 GT_END("Call to SendCommand <OMX_StateIdle> ");
1228 #else
1229 error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
1230 #endif
1231 if(error != OMX_ErrorNone) {
1232 fprintf (stderr,"Error from SendCommand-Pasue State function\n");
1233 goto EXIT;
1234 }
1235 }
1236 if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {
1237 OMX_BUFFERHEADERTYPE* pBuffer;
1238 read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
1239
1240 error = send_input_buffer (pHandle, pBuffer, fIn);
1241 if (error != OMX_ErrorNone) {
1242 printf ("Error While reading input pipe\n");
1243 goto EXIT;
1244 }
1245 frmCnt++;
1246 }
1247 break;
1248
1249 case 4:
1250 if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {
1251
1252 OMX_BUFFERHEADERTYPE* pBuffer;
1253 read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
1254
1255 if(frmCount >= 5) {
1256 fprintf(stderr, "Shutting down ---------- \n");
1257 #ifdef OMX_GETTIME
1258 GT_START();
1259 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);
1260 GT_END("Call to SendCommand <OMX_StateIdle>");
1261 #else
1262 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);;
1263 #endif
1264
1265 if(error != OMX_ErrorNone) {
1266 fprintf (stderr,"Error from SendCommand-Idle(Stop) State function\n");
1267 goto EXIT;
1268 }
1269 done = 1;
1270 }
1271 else {
1272 error = send_input_buffer (pHandle, pBuffer, fIn);
1273 if (error != OMX_ErrorNone) {
1274 printf ("Error While reading input pipe\n");
1275 goto EXIT;
1276 }
1277 }
1278 frmCnt++;
1279 }
1280 break;
1281
1282 case 3:
1283 if (frmCount == 8) {
1284 printf (" Sending Resume command to Codec \n");
1285 #ifdef OMX_GETTIME
1286 GT_START();
1287 error = OMX_SendCommand(pHandle, OMX_CommandStateSet,OMX_StateExecuting, NULL);
1288 GT_END("Call to SendCommand <OMX_StateExecuting>");
1289 #else
1290 error = OMX_SendCommand(pHandle, OMX_CommandStateSet,OMX_StateExecuting, NULL);
1291 #endif
1292 if(error != OMX_ErrorNone) {
1293 fprintf (stderr,"Error from SendCommand-Executing State function\n");
1294 goto EXIT;
1295 }
1296 /* Wait for startup to complete */
1297 error = WaitForState(pHandle, OMX_StateExecuting);
1298
1299 if(error != OMX_ErrorNone) {
1300 fprintf(stderr, "Error: hPcmDecoder->WaitForState reports an error %X\n", error);
1301 goto EXIT;
1302 }
1303 }
1304 if(frmCount == 6) {
1305 printf (" Sending Pause command to Codec \n");
1306
1307 #ifdef OMX_GETTIME
1308 GT_START();
1309 error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StatePause, NULL);
1310 GT_END("Call to SendCommand <OMX_StatePause> ");
1311 #else
1312 error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StatePause, NULL);
1313 #endif
1314 if(error != OMX_ErrorNone) {
1315 fprintf (stderr,"Error from SendCommand-Pasue State function\n");
1316 goto EXIT;
1317 }
1318 /* Wait for startup to complete */
1319 error = WaitForState(pHandle, OMX_StatePause);
1320 if(error != OMX_ErrorNone) {
1321 fprintf(stderr, "Error: hPcmDecoder->WaitForState reports an error %X\n", error);
1322 goto EXIT;
1323 }
1324 }
1325
1326 if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {
1327 OMX_BUFFERHEADERTYPE* pBuffer;
1328 read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
1329
1330 error = send_input_buffer (pHandle, pBuffer, fIn);
1331 if (error != OMX_ErrorNone) {
1332 printf ("Error While reading input pipe\n");
1333 goto EXIT;
1334 }
1335 frmCnt++;
1336 }
1337 break;
1338 case 9:
1339 if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {
1340 OMX_BUFFERHEADERTYPE* pBuffer;
1341 read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
1342 if(!playCompleted && pBuffer->nFlags!=OMX_BUFFERFLAG_EOS){
1343 pBuffer->nFlags = 0;
1344 error = send_input_buffer (pHandle, pBuffer, fIn);
1345 }
1346
1347 if (error != OMX_ErrorNone) {
1348 goto EXIT;
1349 }
1350 frmCnt++;
1351 }
1352 break;
1353
1354 default:
1355 APP_DPRINT("%d :: ### Running Simple DEFAULT Case Here ###\n",__LINE__);
1356 }
1357 if( FD_ISSET(OpBuf_Pipe[0], &rfds) ) {
1358 OMX_BUFFERHEADERTYPE* pBuf;
1359 read(OpBuf_Pipe[0], &pBuf, sizeof(pBuf));
1360 fwrite(pBuf->pBuffer, 1, pBuf->nFilledLen, fOut);
1361 fflush(fOut);
1362 APP_DPRINT("Writing %d bytes to file\n",pBuf->nFilledLen);
1363 if (curState == OMX_StateExecuting && !playCompleted)
1364 {
1365 pComponent->FillThisBuffer(pHandle, pBuf);
1366 }
1367 if (atoi(argv[3]) == 7) {
1368 pComponent->FillThisBuffer(pHandle, pBuf);
1369 }
1370
1371 if(pBuf->nFlags == OMX_BUFFERFLAG_EOS){
1372 APP_DPRINT("State to Idle :: pBuf->nFlags == OMX_BUFFERFLAG_EOS\n");
1373 pBuf->nFlags = 0;
1374 }
1375 }
1376
1377
1378 if(done == 1) {
1379 error = pComponent->GetState(pHandle, &state);
1380 printf("done\n");
1381 if(error != OMX_ErrorNone) {
1382 APP_DPRINT("%d:: Warning: hWmaEncoder->GetState has returned status %X\n",
1383 __LINE__, error);
1384 goto EXIT;
1385 }
1386 }
1387 if (playCompleted){
1388 if((atoi(argv[3]) == 9) && (i != 9)){
1389 puts("*RING_TONE: Lets play again!");
1390 playCompleted = 0;
1391 goto my_exit;
1392 }else{
1393 printf ("APP :: Play Completed. Stop component \n");
1394 StopComponent(pHandle);
1395 playCompleted = 0;
1396 }
1397 }
1398 OMX_GetState(pHandle,&curState);
1399 } /* While Loop Ending Here */
1400
1401 printf ("The current state of the component = %d \n",curState);
1402 my_exit:
1403 fclose(fOut);
1404 fclose(fIn);
1405
1406 } /*Inner for loop ends here */
1407
1408 if(sampleRateChange) {
1409 /*cmd_data.hComponent = pHandle;
1410 cmd_data.AM_Cmd = AM_CommandWarnSampleFreqChange;
1411 cmd_data.param1 = 48000;*/
1412
1413 #ifdef DSP_RENDERING_ON
1414 if((write(wmadecfdwrite, &cmd_data, sizeof(cmd_data)))<0) {
1415 printf("send command to audio manager\n");
1416 }
1417 #endif
1418 }
1419 /*
1420 cmd_data.hComponent = pHandle;
1421 cmd_data.AM_Cmd = AM_Exit;
1422 */
1423
1424 #ifdef DSP_RENDERING_ON
1425 if((write(wmadecfdwrite, &cmd_data, sizeof(cmd_data)))<0)
1426 printf("%d ::OMX_WMADecoder.c :: [WMA Dec Component] - send command to audio manager\n",__LINE__);
1427 close(wmadecfdwrite);
1428 close(wmadecfdread);
1429 #endif
1430
1431 printf ("Sending the StateLoaded Command\n");
1432
1433 #ifdef OMX_GETTIME
1434 GT_START();
1435 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateLoaded, NULL);
1436 GT_END("Call to SendCommand <OMX_StateLoaded>");
1437 #else
1438 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateLoaded, NULL);
1439 #endif
1440 if(error != OMX_ErrorNone) {
1441 APP_DPRINT ("%d:: Error from SendCommand-Idle State function\n",__LINE__);
1442 goto EXIT;
1443 }
1444
1445 /* free buffers */
1446 for (i=0; i < numInputBuffers; i++) {
1447 error = OMX_FreeBuffer(pHandle,OMX_DirInput,pInputBufferHeader[i]);
1448 if( (error != OMX_ErrorNone)) {
1449 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
1450 goto EXIT;
1451 }
1452 }
1453
1454 for (i=0; i < numOutputBuffers; i++) {
1455 error = OMX_FreeBuffer(pHandle,OMX_DirOutput,pOutputBufferHeader[i]);
1456 if( (error != OMX_ErrorNone)) {
1457 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
1458 goto EXIT;
1459 }
1460 }
1461
1462 #ifdef OMX_GETTIME
1463 GT_START();
1464 error = OMX_SendCommand(pHandle, OMX_CommandPortDisable, -1, NULL);
1465 GT_END("Call to SendCommand <OMX_CommandPortDisable>");
1466 #else
1467 error = OMX_SendCommand(pHandle, OMX_CommandPortDisable, -1, NULL);
1468 #endif
1469 /* Wait for startup to complete */
1470 error = WaitForState(pHandle, OMX_StateLoaded);
1471 if(error != OMX_ErrorNone) {
1472 APP_DPRINT( "Error: hWmaEncoder->WaitForState reports an error %X\n", error);
1473 goto EXIT;
1474 }
1475
1476 #ifdef USE_BUFFER
1477 APP_MEMPRINT("%d:::[TESTAPPFREE] %p\n",__LINE__,pInputBuffer);
1478 newfree(pInputBuffer);
1479 pOutputBuffer -= 128;
1480 APP_MEMPRINT("%d:::[TESTAPPFREE] %p\n",__LINE__,pOutputBuffer);
1481 newfree(pOutputBuffer);
1482 #endif
1483 printf ("Free the Component handle\n");
1484 /* Unload the WMA Encoder Component */
1485 error = TIOMX_FreeHandle(pHandle);
1486 APP_MEMPRINT("%d:::[TESTAPPFREE] %p\n",__LINE__,pWmaParam);
1487 newfree(pWmaParam);
1488 APP_MEMPRINT("%d:::[TESTAPPFREE] %p\n",__LINE__,pCompPrivateStruct->format.audio.cMIMEType);
1489 newfree(pCompPrivateStruct->format.audio.cMIMEType);
1490 APP_MEMPRINT("%d:::[TESTAPPFREE] %p\n",__LINE__,pCompPrivateStruct);
1491 newfree(pCompPrivateStruct);
1492 if( (error != OMX_ErrorNone)) {
1493 APP_DPRINT ("%d:: Error in Free Handle function\n",__LINE__);
1494 goto EXIT;
1495 }
1496 close(IpBuf_Pipe[0]);
1497 close(IpBuf_Pipe[1]);
1498 close(OpBuf_Pipe[0]);
1499 close(OpBuf_Pipe[1]);
1500 APP_DPRINT ("%d:: Free Handle returned Successfully \n\n\n\n",__LINE__);
1501
1502 } /*Outer for loop ends here */
1503
1504 pthread_mutex_destroy(&WaitForState_mutex);
1505 pthread_cond_destroy(&WaitForState_threshold);
1506 error = TIOMX_Deinit();
1507 if( (error != OMX_ErrorNone)) {
1508 APP_DPRINT("APP: Error in Deinit Core function\n");
1509 goto EXIT;
1510 }
1511 #ifdef APP_MEMDEBUG
1512 printf("\n-Printing memory not deleted-\n");
1513
1514 for(r=0;r<500;r++){
1515
1516 if (lines[r]!=0){
1517
1518 printf(" --->%d Bytes allocated on %p File:%s Line: %d\n",bytes[r],arr[r],file[r],lines[r]);
1519
1520 }
1521
1522 }
1523 #endif
1524
1525 EXIT:
1526 if(bInvalidState==OMX_TRUE)
1527 {
1528
1529 #ifndef USE_BUFFER
1530 error = FreeAllResources(pHandle,
1531 pInputBufferHeader[0],
1532 pOutputBufferHeader[0],
1533 numInputBuffers,
1534 numOutputBuffers,
1535 fIn,fOut);
1536 #else
1537 error = freeAllUseResources(pHandle,
1538 pInputBuffer,
1539 pOutputBuffer,
1540 numInputBuffers,,
1541 numOutputBuffers,
1542 fIn,fOut);
1543 #endif
1544 }else{
1545 }
1546 #ifdef OMX_GETTIME
1547 GT_END("WMA_DEC test <End>");
1548 OMX_ListDestroy(pListHead);
1549 #endif
1550 return error;
1551 }
1552
1553 /* ================================================================================= */
1554 /**
1555 * @fn send_input_buffer() description for send_input_buffer
1556 send_input_buffer().
1557 Sends input buffer to component
1558 *
1559 */
1560 /* ================================================================================ */
send_input_buffer(OMX_HANDLETYPE pHandle,OMX_BUFFERHEADERTYPE * pBuffer,FILE * fIn)1561 OMX_ERRORTYPE send_input_buffer(OMX_HANDLETYPE pHandle, OMX_BUFFERHEADERTYPE* pBuffer, FILE *fIn)
1562 {
1563
1564 OMX_ERRORTYPE error = OMX_ErrorNone;
1565 OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
1566 int nRead = fill_data (pBuffer, fIn);
1567
1568
1569 if(nRead <= 0) {
1570 APP_DPRINT("Sending EOS\n");
1571 pBuffer->nFlags = OMX_BUFFERFLAG_EOS;
1572 pBuffer->nFilledLen = nRead;
1573 APP_DPRINT("nRead = %d\n",nRead);
1574 APP_DPRINT("Last EmptyThisBuffer\n");
1575 pComponent->EmptyThisBuffer(pHandle, pBuffer);
1576 lastBufferSent = 1;
1577 }
1578 else {
1579 APP_DPRINT("Send input buffer nRead = %d\n",nRead);
1580 pBuffer->nFilledLen = nRead;
1581 if(!(pBuffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)){
1582 pBuffer->nFlags = 0;
1583 }
1584 pComponent->EmptyThisBuffer(pHandle, pBuffer);
1585 }
1586 return error;
1587 }
1588 /* ================================================================================= */
1589 /**
1590 * @fn send_input_buffer() description for send_input_buffer
1591 send_input_buffer().
1592 Sends input buffer to component
1593 *
1594 */
1595 /* ================================================================================ */
send_input_buffer_tc7(OMX_HANDLETYPE pHandle,OMX_BUFFERHEADERTYPE * pBuffer,FILE * fIn)1596 OMX_ERRORTYPE send_input_buffer_tc7(OMX_HANDLETYPE pHandle, OMX_BUFFERHEADERTYPE* pBuffer, FILE *fIn)
1597 {
1598 OMX_ERRORTYPE error = OMX_ErrorNone;
1599 OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
1600 int nRead = fill_data_tc7 (pBuffer, fIn);
1601 if(nRead < pBuffer->nAllocLen) {
1602 pBuffer->nFlags = OMX_BUFFERFLAG_EOS;
1603 #ifdef OMX_GETTIME
1604 GT_START();
1605 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);
1606 GT_END("Call to SendCommand <OMX_StateIdle> ");
1607 #else
1608 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);
1609 #endif
1610
1611 }
1612 else {
1613 pBuffer->nFilledLen = nRead;
1614 pComponent->EmptyThisBuffer(pHandle, pBuffer);
1615 }
1616 return error;
1617 }
1618
1619 /* ================================================================================= */
1620 /**
1621 * @fn fill_data() description for fill_data
1622 fill_data().
1623 Fills input buffer
1624 *
1625 */
1626 /* ================================================================================ */
fill_data(OMX_BUFFERHEADERTYPE * pBuf,FILE * fIn)1627 int fill_data (OMX_BUFFERHEADERTYPE *pBuf,FILE *fIn)
1628 {
1629 int nRead;
1630 OMX_U32 packetSize;
1631 OMX_U8 byteOffset;
1632 static OMX_U8 first_cap = 0;
1633 static OMX_U8 first_buff = 0;
1634 static int totalRead = 0;
1635 static int fileHdrReadFlag = 0;
1636 static int ccnt = 1;
1637 static int payload=0;
1638 OMX_U8 temp = 0;
1639 nRead = 0;
1640 byteOffset = 0;
1641 if(frameMode)
1642 {
1643 /* TODO: Update framemode TC to match component */
1644 if (!fileHdrReadFlag) {
1645 /*The first input buffer readed have the .rca header information*/
1646 nRead = fread(pBuf->pBuffer, 1, 70, fIn);
1647 byteOffset = 70;
1648 fileHdrReadFlag = 1;
1649 }
1650 /*Read packet header, buffer begins at the offset*/
1651 nRead += fread(pBuf->pBuffer + byteOffset, 1, 5, fIn);
1652 /*Extract Packet size*/
1653 packetSize = *((OMX_U32 *)(pBuf->pBuffer + byteOffset + 1));
1654 /*Read the rest of the packet, buffer begins at the end of the packet header*/
1655 byteOffset += 5;
1656 nRead += fread(pBuf->pBuffer + byteOffset, 1, packetSize, fIn);
1657 }
1658 else
1659 {
1660 if(first_buff){
1661 if (first_cap){
1662 fread(&temp,5,1,fIn); // moving file 5 bytes
1663 }
1664 first_cap =1;
1665 nRead = fread(pBuf->pBuffer, 1, payload, fIn);
1666 if(pBuf->nFlags & OMX_BUFFERFLAG_CODECCONFIG)
1667 {
1668 pBuf->nFlags = 0;
1669 }
1670 }
1671 else{
1672 nRead = unParse_Header(pBuf->pBuffer,fIn, &payload);
1673 pBuf->nFlags = OMX_BUFFERFLAG_CODECCONFIG;
1674 first_buff=1;
1675 }
1676 }
1677 totalRead += nRead;
1678 pBuf->nFilledLen = nRead;
1679 APP_DPRINT("\n*****************************************************\n");
1680 APP_DPRINT("%d :: App:: Read IpBuff = %p pBuf->nAllocLen = * %ld, nRead = %ld\n",
1681 __LINE__, pBuf->pBuffer, pBuf->nAllocLen, nRead);
1682 APP_DPRINT("\n*****************************************************\n");
1683 ccnt++;
1684 return nRead;
1685 }
1686
1687 /* ================================================================================= */
1688 /**
1689 * @fn fill_data() description for fill_data
1690 fill_data().
1691 Fills input buffer
1692 *
1693 */
1694 /* ================================================================================ */
fill_data_tc7(OMX_BUFFERHEADERTYPE * pBuf,FILE * fIn)1695 int fill_data_tc7 (OMX_BUFFERHEADERTYPE *pBuf,FILE *fIn)
1696 {
1697 int nRead;
1698 static int totalRead = 0;
1699 static int fileHdrReadFlag = 0;
1700 static int ccnt = 1;
1701 OMX_U8* tempBuffer;
1702 OMX_U8* pBufferOffset;
1703
1704 if (!fileHdrReadFlag) {
1705 nRead = fread(pBuf->pBuffer, 1,75 , fIn);
1706 tempBuffer = newmalloc(19500*sizeof(OMX_U8));
1707 fread(tempBuffer, 1, 19500, fIn);
1708 newfree(tempBuffer);
1709 pBufferOffset = pBuf->pBuffer;
1710 pBufferOffset += 75;
1711 nRead += fread(pBufferOffset, 1, pBuf->nAllocLen-75, fIn);
1712 fileHdrReadFlag = 1;
1713 }
1714 else {
1715 nRead = fread(pBuf->pBuffer, 1, pBuf->nAllocLen , fIn);
1716 }
1717
1718 APP_DPRINT("\n*****************************************************\n");
1719 APP_DPRINT ("%d :: App:: pBuf->pBuffer = %p pBuf->nAllocLen = * %ld, nRead = %ld\n",__LINE__, pBuf->pBuffer, pBuf->nAllocLen, nRead);
1720 APP_DPRINT("\n*****************************************************\n");
1721
1722 totalRead += nRead;
1723 pBuf->nFilledLen = nRead;
1724 ccnt++;
1725 return nRead;
1726 }
1727
calc_buff_size(FILE * fIn)1728 float calc_buff_size(FILE *fIn)
1729 {
1730 int nRead;
1731 OMX_U64 playDuration;
1732 OMX_U64 numPackets;
1733 OMX_U16 sampleRate;
1734 OMX_U16 channelNum;
1735 long double pcmBytesPerPacket;
1736 float outBuffSize;
1737 OMX_U8* pBuffer;
1738 pBuffer = newmalloc((OMX_U8) 100);
1739
1740 /*Read first 70 bytes header + 5 bytes first packet header*/
1741 nRead = fread(pBuffer, 1, 70, fIn);
1742 /*for(i = 0; i < 70; i++)
1743 {
1744 printf("pBuffer[%d] = 0x%x\n", i, pBuffer[i]);
1745 }*/
1746 numPackets = *((OMX_U64 *)pBuffer);
1747 playDuration = *((OMX_U64 *)(pBuffer + 8));
1748 /*playDuration = 906880000;*/
1749 sampleRate = *((OMX_U16 *)(pBuffer + 46));
1750 channelNum = *((OMX_U16 *)(pBuffer + 44));
1751 APP_DPRINT("numPackets %lld\n", numPackets);
1752 APP_DPRINT("playDuration %lld\n", playDuration);
1753 APP_DPRINT("sampleRate %d\n", sampleRate);
1754 APP_DPRINT("channelNum %d\n", channelNum);
1755 pcmBytesPerPacket = (long double)playDuration * (long double) sampleRate / (10000000 * (long double) numPackets);
1756 APP_DPRINT("pcmBytesPerPacket %f\n", pcmBytesPerPacket);
1757 outBuffSize = OUTPUT_WMADEC_BUFFER_SIZE + pcmBytesPerPacket * channelNum * 2;
1758 APP_DPRINT("outBuffSize %f\n", outBuffSize);
1759 newfree(pBuffer);
1760 return outBuffSize;
1761 }
1762
fill_init_params(OMX_HANDLETYPE pHandle,const char * filename,int dasfmode,TI_OMX_DATAPATH * dataPath)1763 void fill_init_params(OMX_HANDLETYPE pHandle,const char * filename,int dasfmode, TI_OMX_DATAPATH * dataPath)
1764 {
1765 OMX_ERRORTYPE error = OMX_ErrorNone;
1766 WMA_HeadInfo* pHeaderInfo;
1767 OMX_INDEXTYPE index;
1768 OMX_ERRORTYPE eError1 = OMX_ErrorNone;
1769 TI_OMX_DSP_DEFINITION dspDefinition;
1770 OMX_U32 samplerate;
1771 OMX_U8 i;
1772 OMX_U8 temp;
1773 OMX_U16 arr[50];
1774 FILE *parameterFile;
1775 pHeaderInfo = newmalloc(sizeof(WMA_HeadInfo));
1776 if (pHeaderInfo == NULL)
1777 {
1778 printf("Could not allocate pHeaderInfo\n");
1779 goto EXIT;
1780 }
1781
1782 parameterFile = fopen(filename,"r");
1783 if (parameterFile == NULL)
1784 {
1785 printf("Could not open file\n");
1786 goto EXIT;
1787 }
1788 memset(arr,(int) NULL, 50);
1789 /*Read first 50 bytes of input file*/
1790 for (i = 0 ; i< 50 ; i++)
1791 {
1792 fscanf(parameterFile, "%c", &temp);
1793 arr[i] = temp;
1794 }
1795 fclose(parameterFile);
1796 /*Obtain sample rate from 46th and 48th bytes*/
1797 samplerate = arr[47] << 8 | arr[46];
1798
1799 dspDefinition.wmaHeaderInfo = pHeaderInfo;
1800 pHeaderInfo->iSamplePerSec = samplerate;
1801 pHeaderInfo->iChannel = arr[44];
1802
1803 dspDefinition.dasfMode = dasfmode;
1804
1805 eError1 = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.wmaheaderinfo",&index);
1806 if (eError1 != OMX_ErrorNone) {
1807 printf("Error getting extension index\n");
1808 goto EXIT;
1809 }
1810
1811 /*OMX_SetConfig(pHandle,index,&dspDefinition);*/
1812 /*cmd_data.hComponent = pHandle;
1813 cmd_data.AM_Cmd = AM_CommandIsOutputStreamAvailable;
1814 */
1815 /* for decoder, using AM_CommandIsInputStreamAvailable */
1816 /*cmd_data.param1 = 0;*/
1817 #ifdef DSP_RENDERING_ON
1818 if((write(wmadecfdwrite, &cmd_data, sizeof(cmd_data)))<0) {
1819 printf("%d [WMA Dec Component] - send command to audio manager\n", __LINE__);
1820 goto EXIT;
1821 }
1822 if((read(wmadecfdread, &cmd_data, sizeof(cmd_data)))<0) {
1823 printf("%d [WMA Dec Component] - failure to get data from the audio manager\n", __LINE__);
1824 goto EXIT;
1825 }
1826 #endif
1827 /*dspDefinition.streamId = cmd_data.streamID; */
1828 if(dspDefinition.dasfMode)
1829 printf("***************StreamId=%d******************\n", (int)dspDefinition.streamId);
1830
1831 error = OMX_SetConfig(pHandle,index,&dspDefinition);
1832 if (error != OMX_ErrorNone) {
1833 printf("Error in SetConfig\n");
1834 goto EXIT;
1835 }
1836
1837 error = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.wmadec.datapath",&index);
1838 if (error != OMX_ErrorNone) {
1839 printf("Error getting extension index\n");
1840 goto EXIT;
1841 }
1842
1843 error = OMX_SetConfig (pHandle, index, dataPath);
1844 if(error != OMX_ErrorNone) {
1845 error = OMX_ErrorBadParameter;
1846 APP_DPRINT("%d :: WmaDecTest.c :: Error from OMX_SetConfig() function\n",__LINE__);
1847 goto EXIT;
1848 }
1849
1850 EXIT:
1851 if(pHeaderInfo != NULL)
1852 {
1853 newfree(pHeaderInfo);
1854 }
1855
1856 printf("Exiting fill_init_params()\n");
1857 }
1858
StopComponent(OMX_HANDLETYPE * pHandle)1859 OMX_ERRORTYPE StopComponent(OMX_HANDLETYPE *pHandle)
1860 {
1861 OMX_ERRORTYPE error = OMX_ErrorNone;
1862
1863 #ifdef OMX_GETTIME
1864 GT_START();
1865 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);
1866 GT_END("Call to SendCommand <OMX_StateIdle>");
1867 #else
1868 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);
1869 #endif
1870 if(error != OMX_ErrorNone) {
1871 fprintf (stderr,"\nError from SendCommand-Idle(Stop) State function!!!!!!!!\n");
1872 goto EXIT;
1873 }
1874 error = WaitForState(pHandle, OMX_StateIdle);
1875 if(error != OMX_ErrorNone) {
1876 fprintf(stderr, "\nError: WaitForState reports an error %X!!!!!!!\n", error);
1877 goto EXIT;
1878 }
1879 EXIT:
1880 return error;
1881 }
1882
1883
1884 #ifdef APP_MEMDEBUG
mymalloc(int line,char * s,int size)1885 void * mymalloc(int line, char *s, int size)
1886 {
1887 void *p;
1888 int e=0;
1889 p = malloc(size);
1890 if(p==NULL){
1891 printf("Memory not available\n");
1892 exit(1);
1893 }
1894 else{
1895 while((lines[e]!=0)&& (e<500) ){
1896 e++;
1897 }
1898 arr[e]=p;
1899 lines[e]=line;
1900 bytes[e]=size;
1901 strcpy(file[e],s);
1902 printf("Allocating %d bytes on address %p, line %d file %s pos %d\n", size, p, line, s, e);
1903 return p;
1904 }
1905 }
1906
myfree(void * dp,int line,char * s)1907 int myfree(void *dp, int line, char *s)
1908 {
1909 int q;
1910 for(q=0;q<500;q++){
1911 if(arr[q]==dp){
1912 printf("Deleting %d bytes on address %p, line %d file %s\n", bytes[q],dp, line, s);
1913 free(dp);
1914 dp = NULL;
1915 lines[q]=0;
1916 strcpy(file[q],"");
1917 break;
1918 }
1919 }
1920 if(500==q)
1921 printf("\n\nPointer not found. Line:%d File%s!!\n\n",line, s);
1922
1923 return 0;
1924 }
1925 #endif
1926
1927
1928 /*=================================================================
1929
1930 Freeing All allocated resources
1931
1932 ==================================================================*/
1933
FreeAllResources(OMX_HANDLETYPE pHandle,OMX_BUFFERHEADERTYPE * pBufferIn,OMX_BUFFERHEADERTYPE * pBufferOut,int NIB,int NOB,FILE * fIn,FILE * fOut)1934 int FreeAllResources( OMX_HANDLETYPE pHandle,
1935 OMX_BUFFERHEADERTYPE* pBufferIn,
1936 OMX_BUFFERHEADERTYPE* pBufferOut,
1937 int NIB, int NOB,
1938 FILE* fIn, FILE* fOut)
1939 {
1940 /* show_meminfo(&mem1); */
1941 printf("%d::Freeing all resources by state invalid \n",__LINE__);
1942 OMX_ERRORTYPE eError1 = OMX_ErrorNone;
1943 OMX_U16 i;
1944 for(i=0; i < NIB; i++) {
1945 printf("%d :: APP: About to free pInputBufferHeader[%d]\n",__LINE__, i);
1946 eError1 = OMX_FreeBuffer(pHandle, OMX_DirInput, pBufferIn+i);
1947
1948 }
1949
1950
1951 for(i=0; i < NOB; i++) {
1952 printf("%d :: APP: About to free pOutputBufferHeader[%d]\n",__LINE__, i);
1953 eError1 = OMX_FreeBuffer(pHandle, OMX_DirOutput, pBufferOut+i);
1954 }
1955
1956 /*i value is fixed by the number calls to malloc in the App */
1957 for(i=0; i<6;i++)
1958 {
1959 if (ArrayOfPointers[i] != NULL){
1960 printf("%d :: APP: About to free ArrayOfPointers[%d]\n",__LINE__, i);
1961 newfree(ArrayOfPointers[i]);
1962 }
1963 }
1964
1965
1966 eError1 = close (IpBuf_Pipe[0]);
1967 eError1 = close (IpBuf_Pipe[1]);
1968 eError1 = close (OpBuf_Pipe[0]);
1969 eError1 = close (OpBuf_Pipe[1]);
1970 if(fOut != NULL) /* Could have been closed previously */
1971 {
1972 fclose(fOut);
1973 fOut=NULL;
1974 }
1975
1976 if(fIn != NULL)
1977 { fclose(fIn);
1978 fIn=NULL;
1979 }
1980 /* show_meminfo(&mem2); */
1981
1982 TIOMX_FreeHandle(pHandle);
1983
1984 /* show_meminfo(&mem2); */
1985 /* show_memcomp(&mem1,&mem2);*/
1986
1987 return eError1;
1988 }
1989
1990 /*=================================================================
1991 Freeing the resources with USE_BUFFER define
1992 ==================================================================*/
1993 #ifdef USE_BUFFER
1994
freeAllUseResources(OMX_HANDLETYPE pHandle,OMX_U8 * UseInpBuf[],OMX_U8 * UseOutBuf[],int NIB,int NOB,FILE * fIn,FILE * fOut)1995 int freeAllUseResources(OMX_HANDLETYPE pHandle,
1996 OMX_U8* UseInpBuf[],
1997 OMX_U8* UseOutBuf[],
1998 int NIB,int NOB,
1999 FILE* fIn, FILE* fOut)
2000 {
2001 OMX_ERRORTYPE eError1 = OMX_ErrorNone;
2002 OMX_U16 i;
2003 printf("%d::Freeing all resources by state invalid \n",__LINE__);
2004 /* free the UseBuffers */
2005 for(i=0; i < NIB; i++) {
2006 UseInpBuf[i] = UseInpBuf[i] - 128;
2007 printf("%d :: [TESTAPPFREE] pInputBuffer[%d] = %p\n",__LINE__,i,(UseInpBuf[i]));
2008 if(UseInpBuf[i] != NULL){
2009 newfree(UseInpBuf[i]);
2010 UseInpBuf[i] = NULL;
2011 }
2012 }
2013
2014 for(i=0; i < NOB; i++) {
2015 UseOutBuf[i] = UseOutBuf[i] - 128;
2016 printf("%d :: [TESTAPPFREE] pOutputBuffer[%d] = %p\n",__LINE__,i, UseOutBuf[i]);
2017 if(UseOutBuf[i] != NULL){
2018 newfree(UseOutBuf[i]);
2019 UseOutBuf[i] = NULL;
2020 }
2021 }
2022
2023 /*i value is fixed by the number calls to malloc in the App */
2024 for(i=0; i<6;i++)
2025 {
2026 if (ArrayOfPointers[i] != NULL)
2027 newfree(ArrayOfPointers[i]);
2028 }
2029 eError1 = close (IpBuf_Pipe[0]);
2030 eError1 = close (IpBuf_Pipe[1]);
2031 eError1 = close (OpBuf_Pipe[0]);
2032 eError1 = close (OpBuf_Pipe[1]);
2033
2034 if (fOut != NULL) /* Could have been closed previously */ */
2035 {
2036 fclose(fOut);
2037 fOut=NULL;
2038 }
2039 if (fIn != NULL)
2040 { fclose(fIn);
2041 fIn=NULL;
2042 }
2043 OMX_FreeHandle(pHandle);
2044
2045 return eError1;
2046 }
2047
2048 #endif
2049 /* ================================================================================= */
2050 /**
2051 * @fn unParse_Header
2052 * To match Android OMX Component, wee need to extract the info from the rca pattern
2053 * to build the config buffer.
2054 */
2055 /* ================================================================================ */
unParse_Header(OMX_U8 * pBuffer,FILE * fIn,int * payload)2056 int unParse_Header (OMX_U8* pBuffer, FILE *fIn, int * payload){
2057
2058 OMX_U8* tempBuffer= malloc(75);
2059 memset(pBuffer,0x00,75);
2060 memset(tempBuffer,0x00,75);
2061 fread(tempBuffer,75,1,fIn);
2062 tempBuffer+=42;
2063 memcpy(pBuffer,tempBuffer,sizeof(OMX_U16));
2064 tempBuffer+=2;
2065 memcpy(pBuffer+2,tempBuffer,sizeof(OMX_U16));
2066 tempBuffer+=2;
2067 memcpy(pBuffer+4,tempBuffer,sizeof(OMX_U32));
2068 tempBuffer+=4;
2069 memcpy(pBuffer+8,tempBuffer,sizeof(OMX_U32));
2070 tempBuffer+=4;
2071 memcpy(pBuffer+12,tempBuffer,sizeof(OMX_U16));
2072 tempBuffer+=2;
2073 memcpy(pBuffer+14,tempBuffer,sizeof(OMX_U16));
2074 tempBuffer+=8;
2075 memcpy(pBuffer+22,tempBuffer,sizeof(OMX_U16));
2076 tempBuffer += 7;
2077 *payload = *((OMX_U16*)tempBuffer);
2078 return 28;
2079 }
2080