/src/aac/libSYS/src/genericStds.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* ----------------------------------------------------------------------------- |
2 | | Software License for The Fraunhofer FDK AAC Codec Library for Android |
3 | | |
4 | | © Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten |
5 | | Forschung e.V. All rights reserved. |
6 | | |
7 | | 1. INTRODUCTION |
8 | | The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software |
9 | | that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding |
10 | | scheme for digital audio. This FDK AAC Codec software is intended to be used on |
11 | | a wide variety of Android devices. |
12 | | |
13 | | AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient |
14 | | general perceptual audio codecs. AAC-ELD is considered the best-performing |
15 | | full-bandwidth communications codec by independent studies and is widely |
16 | | deployed. AAC has been standardized by ISO and IEC as part of the MPEG |
17 | | specifications. |
18 | | |
19 | | Patent licenses for necessary patent claims for the FDK AAC Codec (including |
20 | | those of Fraunhofer) may be obtained through Via Licensing |
21 | | (www.vialicensing.com) or through the respective patent owners individually for |
22 | | the purpose of encoding or decoding bit streams in products that are compliant |
23 | | with the ISO/IEC MPEG audio standards. Please note that most manufacturers of |
24 | | Android devices already license these patent claims through Via Licensing or |
25 | | directly from the patent owners, and therefore FDK AAC Codec software may |
26 | | already be covered under those patent licenses when it is used for those |
27 | | licensed purposes only. |
28 | | |
29 | | Commercially-licensed AAC software libraries, including floating-point versions |
30 | | with enhanced sound quality, are also available from Fraunhofer. Users are |
31 | | encouraged to check the Fraunhofer website for additional applications |
32 | | information and documentation. |
33 | | |
34 | | 2. COPYRIGHT LICENSE |
35 | | |
36 | | Redistribution and use in source and binary forms, with or without modification, |
37 | | are permitted without payment of copyright license fees provided that you |
38 | | satisfy the following conditions: |
39 | | |
40 | | You must retain the complete text of this software license in redistributions of |
41 | | the FDK AAC Codec or your modifications thereto in source code form. |
42 | | |
43 | | You must retain the complete text of this software license in the documentation |
44 | | and/or other materials provided with redistributions of the FDK AAC Codec or |
45 | | your modifications thereto in binary form. You must make available free of |
46 | | charge copies of the complete source code of the FDK AAC Codec and your |
47 | | modifications thereto to recipients of copies in binary form. |
48 | | |
49 | | The name of Fraunhofer may not be used to endorse or promote products derived |
50 | | from this library without prior written permission. |
51 | | |
52 | | You may not charge copyright license fees for anyone to use, copy or distribute |
53 | | the FDK AAC Codec software or your modifications thereto. |
54 | | |
55 | | Your modified versions of the FDK AAC Codec must carry prominent notices stating |
56 | | that you changed the software and the date of any change. For modified versions |
57 | | of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android" |
58 | | must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK |
59 | | AAC Codec Library for Android." |
60 | | |
61 | | 3. NO PATENT LICENSE |
62 | | |
63 | | NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without |
64 | | limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE. |
65 | | Fraunhofer provides no warranty of patent non-infringement with respect to this |
66 | | software. |
67 | | |
68 | | You may use this FDK AAC Codec software or modifications thereto only for |
69 | | purposes that are authorized by appropriate patent licenses. |
70 | | |
71 | | 4. DISCLAIMER |
72 | | |
73 | | This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright |
74 | | holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, |
75 | | including but not limited to the implied warranties of merchantability and |
76 | | fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
77 | | CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, |
78 | | or consequential damages, including but not limited to procurement of substitute |
79 | | goods or services; loss of use, data, or profits, or business interruption, |
80 | | however caused and on any theory of liability, whether in contract, strict |
81 | | liability, or tort (including negligence), arising in any way out of the use of |
82 | | this software, even if advised of the possibility of such damage. |
83 | | |
84 | | 5. CONTACT INFORMATION |
85 | | |
86 | | Fraunhofer Institute for Integrated Circuits IIS |
87 | | Attention: Audio and Multimedia Departments - FDK AAC LL |
88 | | Am Wolfsmantel 33 |
89 | | 91058 Erlangen, Germany |
90 | | |
91 | | www.iis.fraunhofer.de/amm |
92 | | amm-info@iis.fraunhofer.de |
93 | | ----------------------------------------------------------------------------- */ |
94 | | |
95 | | /************************* System integration library ************************** |
96 | | |
97 | | Author(s): |
98 | | |
99 | | Description: - Generic memory, stdio, string, etc. function wrappers or |
100 | | builtins. |
101 | | - OS dependant function wrappers. |
102 | | |
103 | | *******************************************************************************/ |
104 | | |
105 | | #ifndef _CRT_SECURE_NO_WARNINGS |
106 | | #define _CRT_SECURE_NO_WARNINGS |
107 | | #endif |
108 | | |
109 | | #define __GENERICSTDS_CPP__ |
110 | | |
111 | | #include "genericStds.h" |
112 | | |
113 | | /* library info */ |
114 | | #define SYS_LIB_VL0 2 |
115 | | #define SYS_LIB_VL1 0 |
116 | | #define SYS_LIB_VL2 0 |
117 | | #define SYS_LIB_TITLE "System Integration Library" |
118 | | #ifdef __ANDROID__ |
119 | | #define SYS_LIB_BUILD_DATE "" |
120 | | #define SYS_LIB_BUILD_TIME "" |
121 | | #else |
122 | | #define SYS_LIB_BUILD_DATE __DATE__ |
123 | | #define SYS_LIB_BUILD_TIME __TIME__ |
124 | | #endif |
125 | | |
126 | | #include <stdlib.h> |
127 | | #include <stdio.h> |
128 | | #include <string.h> |
129 | | #include <stdarg.h> |
130 | | |
131 | | /*************************************************************** |
132 | | * memory allocation monitoring variables |
133 | | ***************************************************************/ |
134 | | |
135 | | /* Include OS/System specific implementations. */ |
136 | | |
137 | | #include <string.h> |
138 | | #include <stdlib.h> |
139 | | #include <stdio.h> |
140 | | |
141 | 0 | void FDKprintf(const char *szFmt, ...) { |
142 | 0 | va_list ap; |
143 | 0 | va_start(ap, szFmt); |
144 | 0 | vprintf(szFmt, ap); |
145 | 0 | va_end(ap); |
146 | 0 | } |
147 | | |
148 | 0 | void FDKprintfErr(const char *szFmt, ...) { |
149 | 0 | va_list ap; |
150 | 0 | va_start(ap, szFmt); |
151 | 0 | vfprintf(stderr, szFmt, ap); |
152 | 0 | va_end(ap); |
153 | 0 | } |
154 | | |
155 | 0 | int FDKgetchar(void) { return getchar(); } |
156 | | |
157 | 0 | INT FDKfprintf(FDKFILE *stream, const char *format, ...) { |
158 | 0 | INT chars = 0; |
159 | 0 | va_list ap; |
160 | 0 | va_start(ap, format); |
161 | 0 | chars += vfprintf((FILE *)stream, format, ap); |
162 | 0 | va_end(ap); |
163 | 0 | return chars; |
164 | 0 | } |
165 | | |
166 | 0 | INT FDKsprintf(char *str, const char *format, ...) { |
167 | 0 | INT chars = 0; |
168 | 0 | va_list ap; |
169 | 0 | va_start(ap, format); |
170 | 0 | chars += vsprintf(str, format, ap); |
171 | 0 | va_end(ap); |
172 | 0 | return chars; |
173 | 0 | } |
174 | | |
175 | | /************************************************************************************************/ |
176 | | |
177 | | /************************************************************************************************/ |
178 | | |
179 | 0 | char *FDKstrchr(char *s, INT c) { return strchr(s, c); } |
180 | 0 | const char *FDKstrstr(const char *haystack, const char *needle) { |
181 | 0 | return strstr(haystack, needle); |
182 | 0 | } |
183 | 0 | char *FDKstrcpy(char *dest, const char *src) { return strcpy(dest, src); } |
184 | 0 | char *FDKstrncpy(char *dest, const char *src, UINT n) { |
185 | 0 | return strncpy(dest, src, n); |
186 | 0 | } |
187 | | |
188 | | /************************************************************************* |
189 | | * DYNAMIC MEMORY management (heap) |
190 | | *************************************************************************/ |
191 | | |
192 | 0 | void *FDKcalloc(const UINT n, const UINT size) { |
193 | 0 | void *ptr; |
194 | |
|
195 | 0 | ptr = calloc(n, size); |
196 | |
|
197 | 0 | return ptr; |
198 | 0 | } |
199 | | |
200 | 0 | void *FDKmalloc(const UINT size) { |
201 | 0 | void *ptr; |
202 | |
|
203 | 0 | ptr = malloc(size); |
204 | |
|
205 | 0 | return ptr; |
206 | 0 | } |
207 | | |
208 | 0 | void FDKfree(void *ptr) { free((INT *)ptr); } |
209 | | |
210 | 0 | void *FDKaalloc(const UINT size, const UINT alignment) { |
211 | 0 | void *addr, *result = NULL; |
212 | 0 | addr = FDKcalloc(1, size + alignment + |
213 | 0 | (UINT)sizeof(void *)); /* Malloc and clear memory. */ |
214 | |
|
215 | 0 | if (addr != NULL) { |
216 | 0 | result = ALIGN_PTR((unsigned char *)addr + |
217 | 0 | sizeof(void *)); /* Get aligned memory base address. */ |
218 | 0 | *(((void **)result) - 1) = addr; /* Save malloc'ed memory pointer. */ |
219 | 0 | C_ALLOC_ALIGNED_REGISTER(result, size); |
220 | 0 | } |
221 | |
|
222 | 0 | return result; /* Return aligned address. */ |
223 | 0 | } |
224 | | |
225 | 0 | void FDKafree(void *ptr) { |
226 | 0 | void *addr; |
227 | 0 | addr = *(((void **)ptr) - 1); /* Get pointer to malloc'ed memory. */ |
228 | |
|
229 | 0 | C_ALLOC_ALIGNED_UNREGISTER(ptr); |
230 | |
|
231 | 0 | FDKfree(addr); /* Free malloc'ed memory area. */ |
232 | 0 | } |
233 | | |
234 | | /*--------------------------------------------------------------------------* |
235 | | * DATA MEMORY L1/L2 (fallback) |
236 | | *--------------------------------------------------------------------------*/ |
237 | | |
238 | | /*--------------------------------------------------------------------------* |
239 | | * FDKcalloc_L |
240 | | *--------------------------------------------------------------------------*/ |
241 | 0 | void *FDKcalloc_L(const UINT dim, const UINT size, MEMORY_SECTION s) { |
242 | 0 | return FDKcalloc(dim, size); |
243 | 0 | } |
244 | | |
245 | 0 | void FDKfree_L(void *p) { FDKfree(p); } |
246 | | |
247 | 0 | void *FDKaalloc_L(const UINT size, const UINT alignment, MEMORY_SECTION s) { |
248 | 0 | void *addr, *result = NULL; |
249 | 0 | addr = FDKcalloc_L(1, size + alignment + (UINT)sizeof(void *), |
250 | 0 | s); /* Malloc and clear memory. */ |
251 | |
|
252 | 0 | if (addr != NULL) { |
253 | 0 | result = ALIGN_PTR((unsigned char *)addr + |
254 | 0 | sizeof(void *)); /* Get aligned memory base address. */ |
255 | 0 | *(((void **)result) - 1) = addr; /* Save malloc'ed memory pointer. */ |
256 | 0 | C_ALLOC_ALIGNED_REGISTER(result, size); |
257 | 0 | } |
258 | |
|
259 | 0 | return result; /* Return aligned address. */ |
260 | 0 | } |
261 | | |
262 | 0 | void FDKafree_L(void *ptr) { |
263 | 0 | void *addr; |
264 | |
|
265 | 0 | addr = *(((void **)ptr) - 1); /* Get pointer to malloc'ed memory. */ |
266 | |
|
267 | 0 | C_ALLOC_ALIGNED_UNREGISTER(ptr); |
268 | |
|
269 | 0 | FDKfree_L(addr); /* Free malloc'ed memory area. */ |
270 | 0 | } |
271 | | |
272 | | /*--------------------------------------------------------------------------------------- |
273 | | * FUNCTION: FDKmemcpy |
274 | | * DESCRIPTION: - copies memory from "src" to "dst" with length "size" bytes |
275 | | * - compiled with FDK_DEBUG will give you warnings |
276 | | *---------------------------------------------------------------------------------------*/ |
277 | 0 | void FDKmemcpy(void *dst, const void *src, const UINT size) { |
278 | | /* -- check for overlapping memory areas -- */ |
279 | 0 | FDK_ASSERT(((const unsigned char *)dst - (const unsigned char *)src) >= |
280 | 0 | (ptrdiff_t)size || |
281 | 0 | ((const unsigned char *)src - (const unsigned char *)dst) >= |
282 | 0 | (ptrdiff_t)size); |
283 | | |
284 | | /* do the copy */ |
285 | 0 | memcpy(dst, src, size); |
286 | 0 | } |
287 | | |
288 | 0 | void FDKmemmove(void *dst, const void *src, const UINT size) { |
289 | 0 | memmove(dst, src, size); |
290 | 0 | } |
291 | | |
292 | 0 | void FDKmemset(void *memPtr, const INT value, const UINT size) { |
293 | 0 | memset(memPtr, value, size); |
294 | 0 | } |
295 | | |
296 | 0 | void FDKmemclear(void *memPtr, const UINT size) { FDKmemset(memPtr, 0, size); } |
297 | | |
298 | 0 | UINT FDKstrlen(const char *s) { return (UINT)strlen(s); } |
299 | | |
300 | | /* Compare function wrappers */ |
301 | 0 | INT FDKmemcmp(const void *s1, const void *s2, const UINT size) { |
302 | 0 | return memcmp(s1, s2, size); |
303 | 0 | } |
304 | 0 | INT FDKstrcmp(const char *s1, const char *s2) { return strcmp(s1, s2); } |
305 | 0 | INT FDKstrncmp(const char *s1, const char *s2, const UINT size) { |
306 | 0 | return strncmp(s1, s2, size); |
307 | 0 | } |
308 | | |
309 | 0 | int IS_LITTLE_ENDIAN(void) { |
310 | 0 | int __dummy = 1; |
311 | 0 | return (*((UCHAR *)(&(__dummy)))); |
312 | 0 | } |
313 | | |
314 | 0 | UINT TO_LITTLE_ENDIAN(UINT val) { |
315 | 0 | return IS_LITTLE_ENDIAN() |
316 | 0 | ? val |
317 | 0 | : (((val & 0xff) << 24) | ((val & 0xff00) << 8) | |
318 | 0 | ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24)); |
319 | 0 | } |
320 | | |
321 | | /* ==================== FILE I/O ====================== */ |
322 | | |
323 | 0 | FDKFILE *FDKfopen(const char *filename, const char *mode) { |
324 | 0 | return fopen(filename, mode); |
325 | 0 | } |
326 | 0 | INT FDKfclose(FDKFILE *fp) { return fclose((FILE *)fp); } |
327 | 0 | INT FDKfseek(FDKFILE *fp, LONG OFFSET, int WHENCE) { |
328 | 0 | return fseek((FILE *)fp, OFFSET, WHENCE); |
329 | 0 | } |
330 | 0 | INT FDKftell(FDKFILE *fp) { return ftell((FILE *)fp); } |
331 | 0 | INT FDKfflush(FDKFILE *fp) { return fflush((FILE *)fp); } |
332 | | const INT FDKSEEK_SET = SEEK_SET; |
333 | | const INT FDKSEEK_CUR = SEEK_CUR; |
334 | | const INT FDKSEEK_END = SEEK_END; |
335 | | |
336 | 0 | UINT FDKfwrite(const void *ptrf, INT size, UINT nmemb, FDKFILE *fp) { |
337 | 0 | return (UINT)fwrite(ptrf, size, nmemb, (FILE *)fp); |
338 | 0 | } |
339 | 0 | UINT FDKfread(void *dst, INT size, UINT nmemb, FDKFILE *fp) { |
340 | 0 | return (UINT)fread(dst, size, nmemb, (FILE *)fp); |
341 | 0 | } |
342 | 0 | char *FDKfgets(void *dst, INT size, FDKFILE *fp) { |
343 | 0 | return fgets((char *)dst, size, (FILE *)fp); |
344 | 0 | } |
345 | 0 | void FDKrewind(FDKFILE *fp) { FDKfseek((FILE *)fp, 0, FDKSEEK_SET); } |
346 | | |
347 | 0 | UINT FDKfwrite_EL(const void *ptrf, INT size, UINT nmemb, FDKFILE *fp) { |
348 | 0 | if (IS_LITTLE_ENDIAN()) { |
349 | 0 | FDKfwrite(ptrf, size, nmemb, fp); |
350 | 0 | } else { |
351 | 0 | UINT n; |
352 | 0 | INT s; |
353 | |
|
354 | 0 | const UCHAR *ptr = (const UCHAR *)ptrf; |
355 | |
|
356 | 0 | for (n = 0; n < nmemb; n++) { |
357 | 0 | for (s = size - 1; s >= 0; s--) { |
358 | 0 | FDKfwrite(ptr + s, 1, 1, fp); |
359 | 0 | } |
360 | 0 | ptr = ptr + size; |
361 | 0 | } |
362 | 0 | } |
363 | 0 | return nmemb; |
364 | 0 | } |
365 | | |
366 | 0 | UINT FDKfread_EL(void *dst, INT size, UINT nmemb, FDKFILE *fp) { |
367 | 0 | UINT n, s0, s1, err; |
368 | 0 | UCHAR tmp, *ptr; |
369 | 0 | UCHAR tmp24[3]; |
370 | | |
371 | | /* Enforce alignment of 24 bit data. */ |
372 | 0 | if (size == 3) { |
373 | 0 | ptr = (UCHAR *)dst; |
374 | 0 | for (n = 0; n < nmemb; n++) { |
375 | 0 | if ((err = FDKfread(tmp24, 1, 3, fp)) != 3) { |
376 | 0 | return err; |
377 | 0 | } |
378 | 0 | *ptr++ = tmp24[0]; |
379 | 0 | *ptr++ = tmp24[1]; |
380 | 0 | *ptr++ = tmp24[2]; |
381 | | /* Sign extension */ |
382 | 0 | if (tmp24[2] & 0x80) { |
383 | 0 | *ptr++ = 0xff; |
384 | 0 | } else { |
385 | 0 | *ptr++ = 0; |
386 | 0 | } |
387 | 0 | } |
388 | 0 | err = nmemb; |
389 | 0 | size = sizeof(LONG); |
390 | 0 | } else { |
391 | 0 | if ((err = FDKfread(dst, size, nmemb, fp)) != nmemb) { |
392 | 0 | return err; |
393 | 0 | } |
394 | 0 | } |
395 | 0 | if (!IS_LITTLE_ENDIAN() && size > 1) { |
396 | 0 | ptr = (UCHAR *)dst; |
397 | 0 | for (n = 0; n < nmemb; n++) { |
398 | 0 | for (s0 = 0, s1 = size - 1; s0 < s1; s0++, s1--) { |
399 | 0 | tmp = ptr[s0]; |
400 | 0 | ptr[s0] = ptr[s1]; |
401 | 0 | ptr[s1] = tmp; |
402 | 0 | } |
403 | 0 | ptr += size; |
404 | 0 | } |
405 | 0 | } |
406 | 0 | return err; |
407 | 0 | } |
408 | | |
409 | 0 | INT FDKfeof(FDKFILE *fp) { return feof((FILE *)fp); } |
410 | | |
411 | | /* Global initialization/cleanup */ |
412 | | |
413 | 0 | void FDKprintDisclaimer(void) { |
414 | 0 | FDKprintf( |
415 | 0 | "This program is protected by copyright law and international treaties.\n" |
416 | 0 | "Any reproduction or distribution of this program, or any portion\n" |
417 | 0 | "of it, may result in severe civil and criminal penalties, and will be\n" |
418 | 0 | "prosecuted to the maximum extent possible under law.\n\n"); |
419 | 0 | } |