1 /* ----------------------------------------------------------------------------- 2 Software License for The Fraunhofer FDK AAC Codec Library for Android 3 4 Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Frderung 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 (at) 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 void FDKprintf(const char *szFmt, ...) { 142 va_list ap; 143 va_start(ap, szFmt); 144 vprintf(szFmt, ap); 145 va_end(ap); 146 } 147 148 void FDKprintfErr(const char *szFmt, ...) { 149 va_list ap; 150 va_start(ap, szFmt); 151 vfprintf(stderr, szFmt, ap); 152 va_end(ap); 153 } 154 155 int FDKgetchar(void) { return getchar(); } 156 157 INT FDKfprintf(FDKFILE *stream, const char *format, ...) { 158 INT chars = 0; 159 va_list ap; 160 va_start(ap, format); 161 chars += vfprintf((FILE *)stream, format, ap); 162 va_end(ap); 163 return chars; 164 } 165 166 INT FDKsprintf(char *str, const char *format, ...) { 167 INT chars = 0; 168 va_list ap; 169 va_start(ap, format); 170 chars += vsprintf(str, format, ap); 171 va_end(ap); 172 return chars; 173 } 174 175 /************************************************************************************************/ 176 177 /************************************************************************************************/ 178 179 char *FDKstrchr(char *s, INT c) { return strchr(s, c); } 180 const char *FDKstrstr(const char *haystack, const char *needle) { 181 return strstr(haystack, needle); 182 } 183 char *FDKstrcpy(char *dest, const char *src) { return strcpy(dest, src); } 184 char *FDKstrncpy(char *dest, const char *src, UINT n) { 185 return strncpy(dest, src, n); 186 } 187 188 /************************************************************************* 189 * DYNAMIC MEMORY management (heap) 190 *************************************************************************/ 191 192 void *FDKcalloc(const UINT n, const UINT size) { 193 void *ptr; 194 195 ptr = calloc(n, size); 196 197 return ptr; 198 } 199 200 void *FDKmalloc(const UINT size) { 201 void *ptr; 202 203 ptr = malloc(size); 204 205 return ptr; 206 } 207 208 void FDKfree(void *ptr) { free((INT *)ptr); } 209 210 void *FDKaalloc(const UINT size, const UINT alignment) { 211 void *addr, *result = NULL; 212 addr = FDKcalloc(1, size + alignment + 213 (UINT)sizeof(void *)); /* Malloc and clear memory. */ 214 215 if (addr != NULL) { 216 result = ALIGN_PTR((unsigned char *)addr + 217 sizeof(void *)); /* Get aligned memory base address. */ 218 *(((void **)result) - 1) = addr; /* Save malloc'ed memory pointer. */ 219 C_ALLOC_ALIGNED_REGISTER(result, size); 220 } 221 222 return result; /* Return aligned address. */ 223 } 224 225 void FDKafree(void *ptr) { 226 void *addr; 227 addr = *(((void **)ptr) - 1); /* Get pointer to malloc'ed memory. */ 228 229 C_ALLOC_ALIGNED_UNREGISTER(ptr); 230 231 FDKfree(addr); /* Free malloc'ed memory area. */ 232 } 233 234 /*--------------------------------------------------------------------------* 235 * DATA MEMORY L1/L2 (fallback) 236 *--------------------------------------------------------------------------*/ 237 238 /*--------------------------------------------------------------------------* 239 * FDKcalloc_L 240 *--------------------------------------------------------------------------*/ 241 void *FDKcalloc_L(const UINT dim, const UINT size, MEMORY_SECTION s) { 242 return FDKcalloc(dim, size); 243 } 244 245 void FDKfree_L(void *p) { FDKfree(p); } 246 247 void *FDKaalloc_L(const UINT size, const UINT alignment, MEMORY_SECTION s) { 248 void *addr, *result = NULL; 249 addr = FDKcalloc_L(1, size + alignment + (UINT)sizeof(void *), 250 s); /* Malloc and clear memory. */ 251 252 if (addr != NULL) { 253 result = ALIGN_PTR((unsigned char *)addr + 254 sizeof(void *)); /* Get aligned memory base address. */ 255 *(((void **)result) - 1) = addr; /* Save malloc'ed memory pointer. */ 256 C_ALLOC_ALIGNED_REGISTER(result, size); 257 } 258 259 return result; /* Return aligned address. */ 260 } 261 262 void FDKafree_L(void *ptr) { 263 void *addr; 264 265 addr = *(((void **)ptr) - 1); /* Get pointer to malloc'ed memory. */ 266 267 C_ALLOC_ALIGNED_UNREGISTER(ptr); 268 269 FDKfree_L(addr); /* Free malloc'ed memory area. */ 270 } 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 void FDKmemcpy(void *dst, const void *src, const UINT size) { 278 /* -- check for overlapping memory areas -- */ 279 FDK_ASSERT(((const unsigned char *)dst - (const unsigned char *)src) >= 280 (ptrdiff_t)size || 281 ((const unsigned char *)src - (const unsigned char *)dst) >= 282 (ptrdiff_t)size); 283 284 /* do the copy */ 285 memcpy(dst, src, size); 286 } 287 288 void FDKmemmove(void *dst, const void *src, const UINT size) { 289 memmove(dst, src, size); 290 } 291 292 void FDKmemset(void *memPtr, const INT value, const UINT size) { 293 memset(memPtr, value, size); 294 } 295 296 void FDKmemclear(void *memPtr, const UINT size) { FDKmemset(memPtr, 0, size); } 297 298 UINT FDKstrlen(const char *s) { return (UINT)strlen(s); } 299 300 /* Compare function wrappers */ 301 INT FDKmemcmp(const void *s1, const void *s2, const UINT size) { 302 return memcmp(s1, s2, size); 303 } 304 INT FDKstrcmp(const char *s1, const char *s2) { return strcmp(s1, s2); } 305 INT FDKstrncmp(const char *s1, const char *s2, const UINT size) { 306 return strncmp(s1, s2, size); 307 } 308 309 int IS_LITTLE_ENDIAN(void) { 310 int __dummy = 1; 311 return (*((UCHAR *)(&(__dummy)))); 312 } 313 314 UINT TO_LITTLE_ENDIAN(UINT val) { 315 return IS_LITTLE_ENDIAN() 316 ? val 317 : (((val & 0xff) << 24) | ((val & 0xff00) << 8) | 318 ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24)); 319 } 320 321 /* ==================== FILE I/O ====================== */ 322 323 FDKFILE *FDKfopen(const char *filename, const char *mode) { 324 return fopen(filename, mode); 325 } 326 INT FDKfclose(FDKFILE *fp) { return fclose((FILE *)fp); } 327 INT FDKfseek(FDKFILE *fp, LONG OFFSET, int WHENCE) { 328 return fseek((FILE *)fp, OFFSET, WHENCE); 329 } 330 INT FDKftell(FDKFILE *fp) { return ftell((FILE *)fp); } 331 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 UINT FDKfwrite(const void *ptrf, INT size, UINT nmemb, FDKFILE *fp) { 337 return (UINT)fwrite(ptrf, size, nmemb, (FILE *)fp); 338 } 339 UINT FDKfread(void *dst, INT size, UINT nmemb, FDKFILE *fp) { 340 return (UINT)fread(dst, size, nmemb, (FILE *)fp); 341 } 342 char *FDKfgets(void *dst, INT size, FDKFILE *fp) { 343 return fgets((char *)dst, size, (FILE *)fp); 344 } 345 void FDKrewind(FDKFILE *fp) { FDKfseek((FILE *)fp, 0, FDKSEEK_SET); } 346 347 UINT FDKfwrite_EL(const void *ptrf, INT size, UINT nmemb, FDKFILE *fp) { 348 if (IS_LITTLE_ENDIAN()) { 349 FDKfwrite(ptrf, size, nmemb, fp); 350 } else { 351 UINT n; 352 INT s; 353 354 const UCHAR *ptr = (const UCHAR *)ptrf; 355 356 for (n = 0; n < nmemb; n++) { 357 for (s = size - 1; s >= 0; s--) { 358 FDKfwrite(ptr + s, 1, 1, fp); 359 } 360 ptr = ptr + size; 361 } 362 } 363 return nmemb; 364 } 365 366 UINT FDKfread_EL(void *dst, INT size, UINT nmemb, FDKFILE *fp) { 367 UINT n, s0, s1, err; 368 UCHAR tmp, *ptr; 369 UCHAR tmp24[3]; 370 371 /* Enforce alignment of 24 bit data. */ 372 if (size == 3) { 373 ptr = (UCHAR *)dst; 374 for (n = 0; n < nmemb; n++) { 375 if ((err = FDKfread(tmp24, 1, 3, fp)) != 3) { 376 return err; 377 } 378 *ptr++ = tmp24[0]; 379 *ptr++ = tmp24[1]; 380 *ptr++ = tmp24[2]; 381 /* Sign extension */ 382 if (tmp24[2] & 0x80) { 383 *ptr++ = 0xff; 384 } else { 385 *ptr++ = 0; 386 } 387 } 388 err = nmemb; 389 size = sizeof(LONG); 390 } else { 391 if ((err = FDKfread(dst, size, nmemb, fp)) != nmemb) { 392 return err; 393 } 394 } 395 if (!IS_LITTLE_ENDIAN() && size > 1) { 396 ptr = (UCHAR *)dst; 397 for (n = 0; n < nmemb; n++) { 398 for (s0 = 0, s1 = size - 1; s0 < s1; s0++, s1--) { 399 tmp = ptr[s0]; 400 ptr[s0] = ptr[s1]; 401 ptr[s1] = tmp; 402 } 403 ptr += size; 404 } 405 } 406 return err; 407 } 408 409 INT FDKfeof(FDKFILE *fp) { return feof((FILE *)fp); } 410 411 /* Global initialization/cleanup */ 412 413 void FDKprintDisclaimer(void) { 414 FDKprintf( 415 "This program is protected by copyright law and international treaties.\n" 416 "Any reproduction or distribution of this program, or any portion\n" 417 "of it, may result in severe civil and criminal penalties, and will be\n" 418 "prosecuted to the maximum extent possible under law.\n\n"); 419 } 420