1 2 /* ----------------------------------------------------------------------------------------------------------- 3 Software License for The Fraunhofer FDK AAC Codec Library for Android 4 5 Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Frderung der angewandten Forschung e.V. 6 All rights reserved. 7 8 1. INTRODUCTION 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. 12 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. 17 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. 24 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. 28 29 2. COPYRIGHT LICENSE 30 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: 33 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. 36 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. 41 42 The name of Fraunhofer may not be used to endorse or promote products derived from this library without 43 prior written permission. 44 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. 47 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." 52 53 3. NO PATENT LICENSE 54 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. 58 59 You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized 60 by appropriate patent licenses. 61 62 4. DISCLAIMER 63 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. 72 73 5. CONTACT INFORMATION 74 75 Fraunhofer Institute for Integrated Circuits IIS 76 Attention: Audio and Multimedia Departments - FDK AAC LL 77 Am Wolfsmantel 33 78 91058 Erlangen, Germany 79 80 www.iis.fraunhofer.de/amm 81 amm-info (at) iis.fraunhofer.de 82 ----------------------------------------------------------------------------------------------------------- */ 83 84 /************************** Fraunhofer IIS FDK SysLib ********************** 85 86 Author(s): 87 Description: - Generic memory, stdio, string, etc. function wrappers or 88 builtins. 89 - OS dependant function wrappers. 90 91 ******************************************************************************/ 92 93 #define _CRT_SECURE_NO_WARNINGS 94 95 #include <math.h> 96 97 #include "genericStds.h" 98 99 /* library info */ 100 #define SYS_LIB_VL0 1 101 #define SYS_LIB_VL1 3 102 #define SYS_LIB_VL2 8 103 #define SYS_LIB_TITLE "System Integration Library" 104 #ifdef __ANDROID__ 105 #define SYS_LIB_BUILD_DATE "" 106 #define SYS_LIB_BUILD_TIME "" 107 #else 108 #define SYS_LIB_BUILD_DATE __DATE__ 109 #define SYS_LIB_BUILD_TIME __TIME__ 110 #endif 111 112 #include <stdlib.h> 113 #include <stdio.h> 114 #include <string.h> 115 #include <stdarg.h> 116 117 118 /*************************************************************** 119 * memory allocation monitoring variables 120 ***************************************************************/ 121 122 123 /* Include OS/System specific implementations. */ 124 #if defined(__linux__) && !defined(__ANDROID__) /* cppp replaced: elif */ 125 #include "linux/genericStds_linux.cpp" 126 #endif 127 128 129 #if !(defined(USE_BUILTIN_STRING_FUNCTIONS) || defined(__SYMBIAN32__)) 130 #include <string.h> 131 #include <stdlib.h> 132 #include <stdio.h> 133 134 #ifndef FUNCTION_FDKprintf 135 void FDKprintf( const char* szFmt, ...) { 136 va_list ap; 137 va_start(ap, szFmt); 138 vprintf(szFmt, ap); 139 va_end(ap); 140 #ifdef ARCH_WA_FLUSH_CONSOLE 141 fflush(stdout); 142 #endif 143 } 144 #endif 145 146 #ifndef FUNCTION_FDKprintfErr 147 void FDKprintfErr( const char* szFmt, ...) { 148 va_list ap; 149 va_start(ap, szFmt); 150 #if defined(ARCH_WA_SLOWCON) 151 vprintf(szFmt, ap); 152 #else 153 vfprintf(stderr, szFmt, ap); 154 #endif 155 va_end(ap); 156 #ifdef ARCH_WA_FLUSH_CONSOLE 157 fflush(stderr); 158 #endif 159 } 160 #endif 161 162 int FDKgetchar(void) { return getchar(); } 163 164 INT FDKfprintf(FDKFILE *stream, const char *format, ...) { 165 INT chars = 0; 166 va_list ap; 167 va_start(ap, format); 168 chars += vfprintf((FILE*)stream, format, ap); 169 va_end(ap); 170 return chars; 171 } 172 173 #ifndef FUNCTION_FDKsprintf 174 INT FDKsprintf(char *str, const char *format, ...) { 175 INT chars = 0; 176 va_list ap; 177 va_start(ap, format); 178 chars += vsprintf(str, format, ap); 179 va_end(ap); 180 return chars; 181 } 182 #endif 183 184 #else 185 186 void FDKprintf( const char* szFmt, ...) { /* stub! */; } 187 void FDKprintfErr( const char* szFmt, ...) { /* stub! */; } 188 INT FDKfprintf(FILE *stream, const char *format, ...) { /*stub ! */; } 189 INT FDKsprintf(char *str, const char *format, ...) { /* stub! */; } 190 191 #endif 192 193 /************************************************************************************************/ 194 195 196 const char *FDKstrchr(const char *s, INT c) { return strchr(s, c); } 197 const char *FDKstrstr(const char *haystack, const char *needle) { return strstr(haystack, needle); } 198 #ifndef FUNCTION_FDKstrcpy 199 char *FDKstrcpy(char *dest, const char *src) { return strcpy(dest, src); } 200 #endif 201 char *FDKstrncpy(char *dest, const char *src, UINT n) { return strncpy(dest, src, n); } 202 203 /************************************************************************* 204 * DYNAMIC MEMORY management (heap) 205 *************************************************************************/ 206 207 #ifndef FUNCTION_FDKcalloc 208 void *FDKcalloc (const UINT n, const UINT size) 209 { 210 void* ptr; 211 212 ptr = calloc(n, size); 213 214 return ptr; 215 } 216 #endif 217 218 #ifndef FUNCTION_FDKmalloc 219 void *FDKmalloc (const UINT size) 220 { 221 void* ptr; 222 223 ptr = malloc(size); 224 225 return ptr; 226 } 227 #endif 228 229 #ifndef FUNCTION_FDKfree 230 void FDKfree (void *ptr) 231 { 232 /* FDKprintf("f, heapSize: %d\n", heapSizeCurr); */ 233 free((INT*)ptr); 234 } 235 #endif 236 237 #ifndef FUNCTION_FDKaalloc 238 void *FDKaalloc(const UINT size, const UINT alignment) 239 { 240 void *addr, *result=NULL; 241 addr = FDKcalloc(1, size + alignment + sizeof(void*)); /* Malloc and clear memory. */ 242 243 if (addr!=NULL) 244 { 245 result = ALIGN_PTR((unsigned char*)addr + sizeof(void*)); /* Get aligned memory base address. */ 246 *(((void**)result) - 1) = addr; /* Save malloc'ed memory pointer. */ 247 } 248 249 return result; /* Return aligned address. */ 250 } 251 #endif 252 253 #ifndef FUNCTION_FDKafree 254 void FDKafree (void *ptr) 255 { 256 void *addr; 257 addr = *(((void**)ptr)-1); /* Get pointer to malloc'ed memory. */ 258 FDKfree(addr); /* Free malloc'ed memory area. */ 259 } 260 #endif 261 262 263 #ifndef FUNCTION_FDKcalloc_L 264 265 /*--------------------------------------------------------------------------* 266 * DATA MEMORY L1/L2 (fallback) 267 *--------------------------------------------------------------------------*/ 268 269 270 271 /*--------------------------------------------------------------------------* 272 * FDKcalloc_L 273 *--------------------------------------------------------------------------*/ 274 void *FDKcalloc_L(const UINT dim, const UINT size, MEMORY_SECTION s) 275 { 276 int a_size; 277 278 if (s == SECT_DATA_EXTERN) 279 goto fallback; 280 281 a_size = ((dim*size+3)&0xfffffffc); /* force 4 byte alignment (1111 .... 1111 1100) */ 282 283 284 285 286 287 //printf("Warning, out of internal memory\n"); 288 289 fallback: 290 return FDKcalloc(dim, size); 291 } 292 #endif /* FUNCTION_FDKcalloc_L */ 293 294 #ifndef FUNCTION_FDKfree_L 295 void FDKfree_L (void *p) 296 { 297 298 FDKfree(p); 299 } 300 #endif /* FUNCTION_FDKfree_L */ 301 302 #ifndef FUNCTION_FDKaalloc_L 303 void *FDKaalloc_L(const UINT size, const UINT alignment, MEMORY_SECTION s) 304 { 305 void *addr, *result=NULL; 306 addr = FDKcalloc_L(1, size + alignment + sizeof(void*), s); /* Malloc and clear memory. */ 307 308 if (addr!=NULL) 309 { 310 result = ALIGN_PTR((unsigned char *)addr + sizeof(void*)); /* Get aligned memory base address. */ 311 *(((void**)result) - 1) = addr; /* Save malloc'ed memory pointer. */ 312 } 313 314 return result; /* Return aligned address. */ 315 } 316 #endif 317 318 #ifndef FUNCTION_FDKafree_L 319 void FDKafree_L (void *ptr) 320 { 321 void *addr; 322 323 addr = *(((void**)ptr)-1); /* Get pointer to malloc'ed memory. */ 324 FDKfree_L(addr); /* Free malloc'ed memory area. */ 325 } 326 #endif 327 328 329 330 /*--------------------------------------------------------------------------------------- 331 * FUNCTION: FDKmemcpy 332 * DESCRIPTION: - copies memory from "src" to "dst" with length "size" bytes 333 * - compiled with FDK_DEBUG will give you warnings 334 *---------------------------------------------------------------------------------------*/ 335 void FDKmemcpy(void *dst, const void *src, const UINT size) 336 { 337 338 /* do the copy */ 339 memcpy(dst, src, size); 340 } 341 342 void FDKmemmove(void *dst, const void *src, const UINT size) { memmove(dst, src, size); } 343 void FDKmemset(void *memPtr, const INT value, const UINT size) { memset(memPtr, value, size); } 344 void FDKmemclear(void *memPtr, const UINT size) { FDKmemset(memPtr,0,size); } 345 UINT FDKstrlen(const char *s) { return (UINT)strlen(s); } 346 347 /* Compare function wrappers */ 348 INT FDKmemcmp(const void *s1, const void *s2, const UINT size) { return memcmp(s1, s2, size); } 349 INT FDKstrcmp(const char *s1, const char *s2) { return strcmp(s1, s2); } 350 INT FDKstrncmp(const char *s1, const char *s2, const UINT size) { return strncmp(s1, s2, size); } 351 352 353 /* Math function wrappers. Only intended for compatibility, not to be highly optimized. */ 354 355 INT FDKabs(INT j) { return abs(j); } 356 double FDKfabs(double x) { return fabs(x); } 357 double FDKpow(double x, double y) { return pow(x,y); } 358 double FDKsqrt(double x) { return sqrt(x); } 359 double FDKatan(double x) { return atan(x); } 360 double FDKlog(double x) { return log(x); } 361 double FDKsin(double x) { return sin(x); } 362 double FDKcos(double x) { return cos(x); } 363 double FDKexp(double x) { return exp(x); } 364 double FDKatan2(double y, double x) { return atan2(y, x); } 365 double FDKacos(double x) { return acos(x); } 366 double FDKtan(double x) { return tan(x); } 367 double FDKfloor(double x) { return floor(x); } 368 double FDKceil(double x) { return ceil(x); } 369 370 INT FDKatoi(const char *nptr) { return atoi(nptr); } 371 long FDKatol(const char *nptr) { return atol(nptr); } 372 float FDKatof(const char *nptr) { return (float)atof(nptr); } 373 374 375 /* ==================== FILE I/O ====================== */ 376 377 #if !defined(FUNCTION_FDKfopen) 378 FDKFILE *FDKfopen(const char *filename, const char *mode) { return fopen(filename, mode); } 379 #endif 380 #if !defined(FUNCTION_FDKfclose) 381 INT FDKfclose(FDKFILE *fp) { return fclose((FILE*)fp);} 382 #endif 383 #if !defined(FUNCTION_FDKfseek) 384 INT FDKfseek(FDKFILE *fp, LONG OFFSET, int WHENCE) { return fseek((FILE*)fp, OFFSET, WHENCE);} 385 #endif 386 #if !defined(FUNCTION_FDKftell) 387 INT FDKftell(FDKFILE *fp) { return ftell((FILE*)fp); } 388 #endif 389 #if !defined(FUNCTION_FDKfflush) 390 INT FDKfflush(FDKFILE *fp) { return fflush((FILE*)fp); } 391 #endif 392 const INT FDKSEEK_SET = SEEK_SET; 393 const INT FDKSEEK_CUR = SEEK_CUR; 394 const INT FDKSEEK_END = SEEK_END; 395 396 #if !defined(FUNCTION_FDKfwrite) 397 UINT FDKfwrite(void *ptrf, INT size, UINT nmemb, FDKFILE *fp) { return fwrite(ptrf, size, nmemb, (FILE*)fp); } 398 #endif 399 #if !defined(FUNCTION_FDKfread) 400 UINT FDKfread(void *dst, INT size, UINT nmemb, FDKFILE *fp) { return fread(dst, size, nmemb, (FILE*)fp); } 401 #endif 402 #if !defined(FUNCTION_FDKfgets) 403 char* FDKfgets(void *dst, INT size, FDKFILE *fp) { return fgets((char *)dst, size, (FILE*)fp); } 404 #endif 405 #if !defined(FUNCTION_FDKrewind) 406 void FDKrewind(FDKFILE *fp) { FDKfseek((FILE*)fp,0,FDKSEEK_SET); } 407 #endif 408 409 410 UINT FDKfwrite_EL(void *ptrf, INT size, UINT nmemb, FDKFILE *fp) { 411 412 if (IS_LITTLE_ENDIAN()) { 413 FDKfwrite(ptrf, size, nmemb, fp); 414 } else { 415 UINT n; 416 INT s; 417 418 UCHAR *ptr = (UCHAR*) ptrf; 419 420 for (n=0; n<nmemb; n++) { 421 for (s=size-1; s>=0; s--) { 422 //FDKprintf("char = %c\n", (char)*(ptr+s)); 423 FDKfwrite(ptr + s, 1, 1, fp); 424 } 425 ptr = ptr + size; 426 } 427 } 428 return nmemb; 429 } 430 431 432 UINT FDKfread_EL(void *dst, INT size, UINT nmemb, FDKFILE *fp) { 433 UINT n, s0, s1, err; 434 UCHAR tmp, *ptr; 435 UCHAR tmp24[3]; 436 437 /* Enforce alignment of 24 bit data. */ 438 if (size == 3) { 439 ptr = (UCHAR*)dst; 440 err = 0; 441 for (n=0; n<nmemb; n++) { 442 if ((err = FDKfread(tmp24, 1, 3, fp)) != 3) { 443 return err; 444 } 445 *ptr++ = tmp24[0]; 446 *ptr++ = tmp24[1]; 447 *ptr++ = tmp24[2]; 448 /* Sign extension */ 449 if (tmp24[2] & 0x80) { 450 *ptr++ = 0xff; 451 } else { 452 *ptr++ = 0; 453 } 454 } 455 err = nmemb; 456 size = sizeof(LONG); 457 } else { 458 if ((err = FDKfread(dst, size, nmemb, fp)) != nmemb) { 459 return err; 460 } 461 } 462 if (!IS_LITTLE_ENDIAN() && size > 1) { 463 ptr = (UCHAR*)dst; 464 for (n=0; n<nmemb; n++) { 465 for (s0=0, s1=size-1; s0 < s1; s0++, s1--) { 466 tmp = ptr[s0]; 467 ptr[s0] = ptr[s1]; 468 ptr[s1] = tmp; 469 } 470 ptr += size; 471 } 472 } 473 return err; 474 } 475 476 INT FDKfeof(FDKFILE *fp) { return feof((FILE*)fp); } 477 478 /* Global initialization/cleanup */ 479 480 #if defined(_DEBUG) && defined(_WIN32) && !defined(_WIN32_WCE) 481 #define _CRTDBG_MAP_ALLOC 482 #include <crtdbg.h> 483 #endif 484 485 486 487 488 void FDKprintDisclaimer(void) 489 { 490 FDKprintf( 491 "This program is protected by copyright law and international treaties.\n" \ 492 "Any reproduction or distribution of this program, or any portion\n" \ 493 "of it, may result in severe civil and criminal penalties, and will be\n" \ 494 "prosecuted to the maximum extent possible under law.\n\n"); 495 } 496 497