2 /* -----------------------------------------------------------------------------------------------------------
3 Software License for The Fraunhofer FDK AAC Codec Library for Android
5 © Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
9 The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
10 the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
11 This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
13 AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
14 audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
15 independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
16 of the MPEG specifications.
18 Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
19 may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
20 individually for the purpose of encoding or decoding bit streams in products that are compliant with
21 the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
22 these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
23 software may already be covered under those patent licenses when it is used for those licensed purposes only.
25 Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
26 are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
27 applications information and documentation.
31 Redistribution and use in source and binary forms, with or without modification, are permitted without
32 payment of copyright license fees provided that you satisfy the following conditions:
34 You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
35 your modifications thereto in source code form.
37 You must retain the complete text of this software license in the documentation and/or other materials
38 provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
39 You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
40 modifications thereto to recipients of copies in binary form.
42 The name of Fraunhofer may not be used to endorse or promote products derived from this library without
43 prior written permission.
45 You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
46 software or your modifications thereto.
48 Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
49 and the date of any change. For modified versions of the FDK AAC Codec, the term
50 "Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
51 "Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
55 NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
56 ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
57 respect to this software.
59 You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
60 by appropriate patent licenses.
64 This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
65 "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
66 of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
67 CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
68 including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
69 or business interruption, however caused and on any theory of liability, whether in contract, strict
70 liability, or tort (including negligence), arising in any way out of the use of this software, even if
71 advised of the possibility of such damage.
73 5. CONTACT INFORMATION
75 Fraunhofer Institute for Integrated Circuits IIS
76 Attention: Audio and Multimedia Departments - FDK AAC LL
78 91058 Erlangen, Germany
80 www.iis.fraunhofer.de/amm
81 amm-info@iis.fraunhofer.de
82 ----------------------------------------------------------------------------------------------------------- */
84 /************************** Fraunhofer IIS FDK SysLib **********************
87 Description: command line parser
89 ******************************************************************************/
93 #define _CRT_SECURE_NO_WARNINGS
101 #include "cmdl_parser.h"
102 #include "genericStds.h"
106 /************************ interface ************************/
108 static INT
GetArgFromString(INT argc
, TEXTCHAR
* argv
[], TEXTCHAR
* search_string
, TEXTCHAR type
, TEXTCHAR
* found_string
, INT
* switches_used
);
109 static void RemoveWhiteSpace(const TEXTCHAR
* pReqArgs
, TEXTCHAR
* Removed
);
110 static INT
CheckArg(TEXTCHAR
* arg
, TEXTCHAR
* str
, UINT numArgs
, TEXTCHAR type
, TEXTCHAR
* current_str
);
111 static INT
CheckForUnusedSwitches(INT argc
, /*TEXTCHAR* argv[],*/ INT
* switches_used
);
112 static INT
ParseString(TEXTCHAR
* str
, INT
*, TEXTCHAR
*, TEXTCHAR
*);
113 static void GetNumberOfArgs(TEXTCHAR
* str
, INT
* nArgs
);
116 void removeQuotes(char *str
)
119 FDKstrcpy(str
, str
+1);
120 str
[FDKstrlen(str
)-1] = 0;
125 /********************** implementation *********************/
127 INT
IIS_ScanCmdl(INT argc
, TEXTCHAR
* argv
[], const TEXTCHAR
* str
, ...)
130 INT found_and_set
= 0;
132 INT
* switches_used
= 0;
135 TEXTCHAR
* c_str_type
= 0;
136 TEXTCHAR
* str_clean
= 0;
140 if (argc
== 0 || argc
== 1)
142 FDKprintf("No command line arguments\n");
146 str_clean
= (TEXTCHAR
*) FDKcalloc((unsigned int)_tcslen(str
), sizeof(TEXTCHAR
));
147 if (str_clean
== NULL
) {
148 FDKprintf("Error allocating memory line %d, file %s\n", __LINE__
, __FILE__
);
152 RemoveWhiteSpace(str
, str_clean
);
153 GetNumberOfArgs(str_clean
, &nArgs
);
155 b_str_opt
= (INT
*) FDKcalloc(nArgs
, sizeof(INT
));
156 s_str
= (TEXTCHAR
*) FDKcalloc(nArgs
*CMDL_MAX_ARGC
, sizeof(TEXTCHAR
) );
157 c_str_type
= (TEXTCHAR
*) FDKcalloc(nArgs
, sizeof(TEXTCHAR
));
158 switches_used
= (INT
*) FDKcalloc(argc
, sizeof(INT
));
160 if (b_str_opt
== NULL
|| s_str
== NULL
|| c_str_type
== NULL
|| switches_used
== NULL
) {
161 FDKprintf("Error allocating memory line %d, file %s\n", __LINE__
, __FILE__
);
165 if ( ParseString( str_clean
, b_str_opt
, s_str
, c_str_type
)) {
171 for ( i
= 0; i
< nArgs
; i
++ )
173 TEXTCHAR arg
[CMDL_MAX_STRLEN
] = {L
'\0'};
174 TEXTCHAR
* p_arg
= arg
;
175 TEXTCHAR
* current_str
= &(s_str
[i
*CMDL_MAX_ARGC
]);
177 if (GetArgFromString(argc
, argv
, current_str
, c_str_type
[i
], arg
, switches_used
)
181 _ftprintf(stderr
, _TEXT("\n\nError: Parsing argument for required switch '%ls'.\n" ), current_str
);
183 _ftprintf(stderr
, _TEXT("\n\nError: Parsing argument for required switch '%s'.\n" ), current_str
);
188 if (CheckArg(p_arg
, s_str
, nArgs
, c_str_type
[i
], current_str
))
193 switch (c_str_type
[i
] )
198 tmp
= va_arg(ap
, TEXTCHAR
*);
200 if ( arg
[0] == '\0' )
203 _tcsncpy( tmp
, arg
, CMDL_MAX_STRLEN
);
204 /* Remove quotes. Windows Mobile Workaround. */
211 INT
* tmp
= va_arg(ap
, INT
*);
213 if ( arg
[0] == '\0' )
216 *tmp
= _tcstol(arg
, NULL
, 0);
222 char* tmp
= va_arg(ap
, char*);
224 if ( arg
[0] == '\0' )
233 UCHAR
* tmp
= va_arg(ap
, UCHAR
*);
235 if ( arg
[0] == '\0' )
244 float* tmp
= (float*) va_arg( ap
,double*);
246 if ( arg
[0] == '\0' )
249 *tmp
= (float) _tstof(arg
);
253 case 'y': // support 'data type double'
255 double* tmp
= (double*) va_arg( ap
,double*);
256 // use sscanf instead _tstof because of gcc
257 //_tstof(arg,"%lf",tmp); // '%lf' reads as double
258 *tmp
= _tstof(arg
); // '%lf' reads as double
265 INT
* tmp
= va_arg( ap
, INT
*);
267 if ( arg
[0] == '\0' )
276 FDKprintfErr("Bug: unsupported data identifier \"%c\"\n", c_str_type
[i
]);
285 CheckForUnusedSwitches(argc
, /*argv,*/ switches_used
);
288 if (b_str_opt
) FDKfree(b_str_opt
);
289 if (s_str
) FDKfree(s_str
);
290 if (c_str_type
) FDKfree(c_str_type
);
291 if (str_clean
) FDKfree(str_clean
);
292 if (switches_used
) FDKfree(switches_used
);
294 return found_and_set
;
298 void GetNumberOfArgs(TEXTCHAR
* str
, INT
* nArgs
)
301 for ( i
= 0; i
< _tcslen(str
); ++i
)
309 INT
ParseString(TEXTCHAR
* str
, INT
* b_str_opt
, TEXTCHAR
* s_str
, TEXTCHAR
* c_str_type
)
314 TEXTCHAR
* str_start
= 0;
315 TEXTCHAR
* str_stop
= 0;
319 str_stop
= str_start
;
321 for ( i
= 0; i
< _tcslen(str
) - 1; ++i
)
323 if ( str
[i
] == '%' ) /* We have an Argument */
327 if ( b_str_opt
[argCounter
-1] )
328 str_start
= str_stop
+ 3;
331 str_start
= str_stop
+ 2;
334 /* Save Argument type */
335 c_str_type
[argCounter
] = str
[i
+1];
337 if ( *str_start
== '(' ) /* Optional Argument */
339 b_str_opt
[argCounter
] = 1;
346 _tcsncpy(&(s_str
[argCounter
*CMDL_MAX_ARGC
]), str_start
, CMDL_MAX_ARGC
);
350 str_stop
= &(str
[i
]);
352 if ( b_str_opt
[argCounter
] )
354 if ( i
+2 > ( _tcslen(str
) -1 ))
356 _ftprintf(stderr
,_TEXT("\n\nInternal Parser Error: Strlen Problem\n") );
359 if ( str
[i
+2] != ')' )
361 _ftprintf(stderr
,_TEXT("\n\nInternal Parser Error: Missing bracket ')'\n") );
380 void RemoveWhiteSpace(const TEXTCHAR
* pReqArgs
, TEXTCHAR
* pRemoved
)
384 UINT len
= (UINT
)_tcslen(pReqArgs
);
387 for ( i
= 0; i
< len
; ++i
)
390 if ( pReqArgs
[i
] != ' ' )
392 pRemoved
[k
] = pReqArgs
[i
];
399 INT
GetArgFromString(INT argc
, TEXTCHAR
* argv
[], TEXTCHAR
* search_string
, TEXTCHAR type
, TEXTCHAR
* found_string
, INT
* sw_used
)
403 for (i
= 1; i
< argc
; ++i
) {
404 if ( !_tcscmp(search_string
, argv
[i
]) ) /* Strings are equal */
406 if ( type
== '1' ) /* Switch without argument */
408 _tcsncpy( found_string
, _TEXT("1"), 1);
414 if ( i
== (argc
- 1)) /* We have %s or %d but are finished*/
417 if ( _tcslen(argv
[i
+1]) > CMDL_MAX_STRLEN
)
420 _ftprintf (stderr
,_TEXT("Warning: Ignoring argument for switch '%ls'. "), search_string
);
422 _ftprintf (stderr
,_TEXT("Warning: Ignoring argument for switch '%s'. "), search_string
);
424 _ftprintf (stderr
,_TEXT("Argument is too LONG.\n") );
429 _tcsncpy( found_string
, argv
[i
+1], CMDL_MAX_STRLEN
);
441 INT
CheckArg(TEXTCHAR
* arg
, TEXTCHAR
* str
, UINT numArgs
, TEXTCHAR type
, TEXTCHAR
* cur_str
)
445 /* No argument given-> return */
450 /* Check if arg is switch */
451 for ( i
= 0; i
< numArgs
; ++i
)
453 if (!_tcscmp(arg
, &(str
[i
*CMDL_MAX_ARGC
])))
456 _ftprintf(stderr
, _TEXT("\n\nError: Argument '%ls' for switch '%ls' is not valid \n" ), arg
, cur_str
);
458 _ftprintf(stderr
, _TEXT("\n\nError: Argument '%s' for switch '%s' is not valid \n" ), arg
, cur_str
);
464 /* Check if type is %d but a string is given */
466 for ( i
= 0; i
< _tcslen(arg
); ++i
)
468 if ( (type
== 'd') && !_istdigit(arg
[i
]) && arg
[i
] != 'x' && arg
[i
] != '-')
471 _ftprintf(stderr
, _TEXT("\n\nError: Argument '%ls' for switch '%ls' is not a valid number.\n" ), arg
, cur_str
);
473 _ftprintf(stderr
, _TEXT("\n\nError: Argument '%s' for switch '%s' is not a valid number.\n" ), arg
, cur_str
);
484 INT
CheckForUnusedSwitches(INT argc
, /*TEXTCHAR* argv[],*/ INT
* switches_used
)
488 for( i
= 1; i
< argc
; ++i
)
490 if ( !switches_used
[i
] )
501 static char line
[CMDL_MAX_STRLEN
*CMDL_MAX_ARGC
];
502 static char *argv_ptr
[CMDL_MAX_ARGC
];
503 #ifdef CMDFILE_PREFIX
504 static char tmp
[256]; /* this array is used to store the prefix and the filepath/name */
507 int IIS_ProcessCmdlList(const char* param_filename
, int (*pFunction
)(int, TEXTCHAR
**))
509 /* static to reduce required stack size */
515 #ifdef CMDFILE_PREFIX
516 FDKstrcpy(tmp
, CMDFILE_PREFIX
);
517 FDKstrcpy(tmp
+FDKstrlen(CMDFILE_PREFIX
), param_filename
);
518 /* Open the file with command lines */
519 config_fp
= FDKfopen(tmp
, "r");
521 /* Open the file with command lines */
522 config_fp
= FDKfopen(param_filename
, "r");
525 if(config_fp
== NULL
)
527 #ifdef CMDFILE_PREFIX
528 FDKprintf("\ncould not open config file %s", tmp
);
530 FDKprintf("\ncould not open config file %s", param_filename
);
535 /* Obtain a command line from config file */
536 while (FDKfgets(line
, CMDL_MAX_STRLEN
*CMDL_MAX_ARGC
, config_fp
) != NULL
)
541 line_ptr
= (char*)FDKstrchr(line
, '\n');
542 if (line_ptr
!= NULL
)
547 /* Scan the line and put the command line params into argv */
549 /* Skip consecutive blanks. */
550 while (*line_ptr
== ' ' && line_ptr
< line
+CMDL_MAX_STRLEN
)
552 /* Assign argument. */
553 argv_ptr
[argc
] = line_ptr
;
554 /* Get pointer to next blank. */
555 line_ptr
= (char*)FDKstrchr(line_ptr
, ' ');
557 if (line_ptr
!= NULL
) {
560 /* Skip former blank (now null character) */
562 /* Advance argument counter */
565 } while ( line_ptr
!= NULL
&& argc
< CMDL_MAX_ARGC
);
567 /* call "would be main()" */
568 if (argc
> 2 && *argv_ptr
[1] != '#' && FDKstrlen(argv_ptr
[1])>1)
572 retval
= (*pFunction
)(argc
, argv_ptr
);
574 FDKprintf("main returned %d\n", retval
);
578 FDKfclose(config_fp
);