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 /**************************** AAC decoder library ****************************** 96 97 Author(s): Robert Weidner (DSP Solutions) 98 99 Description: HCR Decoder: Common defines and structures; defines for 100 switching error-generator, -detector, and -concealment; 101 102 *******************************************************************************/ 103 104 #ifndef AACDEC_HCR_TYPES_H 105 #define AACDEC_HCR_TYPES_H 106 107 #include "FDK_bitstream.h" 108 #include "overlapadd.h" 109 110 /* ------------------------------------------------ */ 111 /* ------------------------------------------------ */ 112 113 #define LINES_PER_UNIT 4 114 115 /* ------------------------------------------------ */ 116 /* ------------------------------------------------ */ 117 /* ----------- basic HCR configuration ------------ */ 118 119 #define MAX_SFB_HCR \ 120 (((1024 / 8) / LINES_PER_UNIT) * 8) /* (8 * 16) is not enough because sfbs \ 121 are split in units for blocktype \ 122 short */ 123 #define NUMBER_OF_UNIT_GROUPS (LINES_PER_UNIT * 8) 124 #define LINES_PER_UNIT_GROUP (1024 / NUMBER_OF_UNIT_GROUPS) /* 15 16 30 32 */ 125 126 /* ------------------------------------------------ */ 127 /* ------------------------------------------------ */ 128 /* ------------------------------------------------ */ 129 130 #define FROM_LEFT_TO_RIGHT 0 131 #define FROM_RIGHT_TO_LEFT 1 132 133 #define MAX_CB_PAIRS 23 134 #define MAX_HCR_SETS 14 135 136 #define ESCAPE_VALUE 16 137 #define POSITION_OF_FLAG_A 21 138 #define POSITION_OF_FLAG_B 20 139 140 #define MAX_CB 32 /* last used CB is cb #31 when VCB11 is used */ 141 142 #define MAX_CB_CHECK \ 143 32 /* support for VCB11 available -- is more general, could therefore used \ 144 in both cases */ 145 146 #define NUMBER_OF_BIT_IN_WORD 32 147 148 /* log */ 149 #define THIRTYTWO_LOG_DIV_TWO_LOG 5 150 #define EIGHT_LOG_DIV_TWO_LOG 3 151 #define FOUR_LOG_DIV_TWO_LOG 2 152 153 /* borders */ 154 #define CPE_TOP_LENGTH 12288 155 #define SCE_TOP_LENGTH 6144 156 #define LEN_OF_LONGEST_CW_TOP_LENGTH 49 157 158 /* qsc's of high level */ 159 #define Q_VALUE_INVALID \ 160 8192 /* mark a invalid line with this value (to be concealed later on) */ 161 #define HCR_DIRAC 500 /* a line of high level */ 162 163 /* masks */ 164 #define MASK_LEFT 0xFFF000 165 #define MASK_RIGHT 0xFFF 166 #define CLR_BIT_10 0x3FF 167 #define TEST_BIT_10 0x400 168 169 #define LEFT_OFFSET 12 170 171 /* when set HCR is replaced by a dummy-module which just fills the outputbuffer 172 * with a dirac sequence */ 173 /* use this if HCR is suspected to write in other modules -- if error is stell 174 * there, HCR is innocent */ 175 176 /* ------------------------------ */ 177 /* - insert HCR errors - */ 178 /* ------------------------------ */ 179 180 /* modify input lengths -- high protected */ 181 #define ERROR_LORSD 0 /* offset: error if different from zero */ 182 #define ERROR_LOLC 0 /* offset: error if different from zero */ 183 184 /* segments are earlier empty as expected when decoding PCWs */ 185 #define ERROR_PCW_BODY \ 186 0 /* set a positive values to trigger the error (make segments earlyer \ 187 appear to be empty) */ 188 #define ERROR_PCW_BODY_SIGN \ 189 0 /* set a positive values to trigger the error (make segments earlyer \ 190 appear to be empty) */ 191 #define ERROR_PCW_BODY_SIGN_ESC \ 192 0 /* set a positive values to trigger the error (make segments earlyer \ 193 appear to be empty) */ 194 195 /* pretend there are too many bits decoded (enlarge length of codeword) at PCWs 196 * -- use a positive value */ 197 #define ERROR_PCW_BODY_ONLY_TOO_LONG \ 198 0 /* set a positive values to trigger the error */ 199 #define ERROR_PCW_BODY_SIGN_TOO_LONG \ 200 0 /* set a positive values to trigger the error */ 201 #define ERROR_PCW_BODY_SIGN_ESC_TOO_LONG \ 202 0 /* set a positive values to trigger the error */ 203 204 /* modify HCR bitstream block */ 205 206 #define MODULO_DIVISOR_HCR 30 207 208 /* ------------------------------ */ 209 /* - detect HCR errors - */ 210 /* ------------------------------ */ 211 /* check input data */ 212 213 /* during decoding */ 214 215 /* all the segments are checked -- therefore -- if this check passes, its a kind 216 of evidence that the decoded PCWs and non-PCWs are fine */ 217 218 /* if a codeword is decoded there exists a border for the number of bits, which 219 are allowed to read for this codeword. This border is the minimum of the 220 length of the longest codeword (for the currently used codebook) and the 221 separately transmitted 'lengthOfLongestCodeword' in this frame and channel. 222 The number of decoded bits is counted (for PCWs only -- there it makes really 223 sense in my opinion). If this number exceeds the border (derived as minimum 224 -- see above), a error is detected. */ 225 226 /* ----------------------------------------------------------------------------------------------------- 227 This error check could be set to zero because due to a test within 228 RVLC-Escape-huffman-Decoder a too long codeword could not be detected -- it 229 seems that for RVLC-Escape-Codeword the coderoom is used to 100%. Therefore I 230 assume that the coderoom is used to 100% also for the codebooks 1..11 used at 231 HCR Therefore this test is deactivated pending further notice 232 ----------------------------------------------------------------------------------------------------- 233 */ 234 235 /* test if the number of remaining bits in a segment is _below_ zero. If there 236 are no errors the lowest allowed value for remainingBitsInSegment is zero. 237 This check also could be set to zero (save runtime) */ 238 239 /* other */ 240 /* when set to '1', avoid setting the LAV-Flag in errorLog due to a 241 previous-line-marking (at PCW decoder). A little more runtime is needed then 242 when writing values out into output-buffer. */ 243 244 /* ------------------------------ */ 245 /* - conceal HCR errors - */ 246 /* ------------------------------ */ 247 248 #define HCR_ERROR_CONCEALMENT \ 249 1 /* if set to '1', HCR _mutes_ the erred quantized spectral coefficients */ 250 251 // ------------------------------------------------------------------------------------------------------------------ 252 // errorLog: A word of 32 bits used for 253 // logging possible errors within HCR 254 // in case of distorted 255 // bitstreams. Table of all 256 // known errors: 257 // ------------------------------------------------------------------------------------------------------------------------ 258 // bit fatal location meaning 259 // ----+-----+-----------+-------------------------------------- 260 #define SEGMENT_OVERRIDE_ERR_PCW_BODY \ 261 0x80000000 // 31 no PCW-Dec During PCW decoding it is checked after 262 // every PCW if there are too many bits decoded (immediate 263 // check). 264 #define SEGMENT_OVERRIDE_ERR_PCW_BODY_SIGN \ 265 0x40000000 // 30 no PCW-Dec During PCW decoding it is checked after 266 // every PCW if there are too many bits decoded (immediate 267 // check). 268 #define SEGMENT_OVERRIDE_ERR_PCW_BODY_SIGN_ESC \ 269 0x20000000 // 29 no PCW-Dec During PCW decoding it is checked after 270 // every PCW if there are too many bits decoded (immediate 271 // check). 272 #define EXTENDED_SORTED_COUNTER_OVERFLOW \ 273 0x10000000 // 28 yes Init-Dec Error during extending sideinfo 274 // (neither a PCW nor a nonPCW was decoded so far) 275 // 0x08000000 // 27 reserved 276 // 0x04000000 // 26 reserved 277 // 0x02000000 // 25 reserved 278 // 0x01000000 // 24 reserved 279 // 0x00800000 // 23 reserved 280 // 0x00400000 // 22 reserved 281 // 0x00200000 // 21 reserved 282 // 0x00100000 // 20 reserved 283 284 /* special errors */ 285 #define TOO_MANY_PCW_BODY_BITS_DECODED \ 286 0x00080000 // 19 yes PCW-Dec During PCW-body-decoding too many bits 287 // have been read from bitstream -- advice: skip non-PCW decoding 288 #define TOO_MANY_PCW_BODY_SIGN_BITS_DECODED \ 289 0x00040000 // 18 yes PCW-Dec During PCW-body-sign-decoding too many 290 // bits have been read from bitstream -- advice: skip non-PCW 291 // decoding 292 #define TOO_MANY_PCW_BODY_SIGN_ESC_BITS_DECODED \ 293 0x00020000 // 17 yes PCW-Dec During PCW-body-sign-esc-decoding too 294 // many bits have been read from bitstream -- advice: skip 295 // non-PCW decoding 296 297 // 0x00010000 // 16 reserved 298 #define STATE_ERROR_BODY_ONLY \ 299 0x00008000 // 15 no NonPCW-Dec State machine returned with error 300 #define STATE_ERROR_BODY_SIGN__BODY \ 301 0x00004000 // 14 no NonPCW-Dec State machine returned with error 302 #define STATE_ERROR_BODY_SIGN__SIGN \ 303 0x00002000 // 13 no NonPCW-Dec State machine returned with error 304 #define STATE_ERROR_BODY_SIGN_ESC__BODY \ 305 0x00001000 // 12 no NonPCW-Dec State machine returned with error 306 #define STATE_ERROR_BODY_SIGN_ESC__SIGN \ 307 0x00000800 // 11 no NonPCW-Dec State machine returned with error 308 #define STATE_ERROR_BODY_SIGN_ESC__ESC_PREFIX \ 309 0x00000400 // 10 no NonPCW-Dec State machine returned with error 310 #define STATE_ERROR_BODY_SIGN_ESC__ESC_WORD \ 311 0x00000200 // 9 no NonPCW-Dec State machine returned with error 312 #define HCR_SI_LENGTHS_FAILURE \ 313 0x00000100 // 8 yes Init-Dec LengthOfLongestCodeword must not be 314 // less than lenghtOfReorderedSpectralData 315 #define NUM_SECT_OUT_OF_RANGE_SHORT_BLOCK \ 316 0x00000080 // 7 yes Init-Dec The number of sections is not within 317 // the allowed range (short block) 318 #define NUM_SECT_OUT_OF_RANGE_LONG_BLOCK \ 319 0x00000040 // 6 yes Init-Dec The number of sections is not within 320 // the allowed range (long block) 321 #define LINE_IN_SECT_OUT_OF_RANGE_SHORT_BLOCK \ 322 0x00000020 // 5 yes Init-Dec The number of lines per section is not 323 // within the allowed range (short block) 324 #define CB_OUT_OF_RANGE_SHORT_BLOCK \ 325 0x00000010 // 4 yes Init-Dec The codebook is not within the allowed 326 // range (short block) 327 #define LINE_IN_SECT_OUT_OF_RANGE_LONG_BLOCK \ 328 0x00000008 // 3 yes Init-Dec The number of lines per section is not 329 // within the allowed range (long block) 330 #define CB_OUT_OF_RANGE_LONG_BLOCK \ 331 0x00000004 // 2 yes Init-Dec The codebook is not within the allowed 332 // range (long block) 333 #define LAV_VIOLATION \ 334 0x00000002 // 1 no Final The absolute value of at least one 335 // decoded line was too high for the according codebook. 336 #define BIT_IN_SEGMENTATION_ERROR \ 337 0x00000001 // 0 no Final After PCW and non-PWC-decoding at least 338 // one segment is not zero (global check). 339 340 /*----------*/ 341 #define HCR_FATAL_PCW_ERROR_MASK 0x100E01FC 342 343 typedef enum { PCW_BODY, PCW_BODY_SIGN, PCW_BODY_SIGN_ESC } PCW_TYPE; 344 345 /* interface Decoder <---> HCR */ 346 typedef struct { 347 UINT errorLog; 348 SPECTRAL_PTR pQuantizedSpectralCoefficientsBase; 349 int quantizedSpectralCoefficientsIdx; 350 SHORT lengthOfReorderedSpectralData; 351 SHORT numSection; 352 SHORT *pNumLineInSect; 353 INT bitstreamAnchor; 354 SCHAR lengthOfLongestCodeword; 355 UCHAR *pCodebook; 356 } HCR_INPUT_OUTPUT; 357 358 typedef struct { 359 const UCHAR *pMinOfCbPair; 360 const UCHAR *pMaxOfCbPair; 361 } HCR_CB_PAIRS; 362 363 typedef struct { 364 const USHORT *pLargestAbsVal; 365 const UCHAR *pMaxCwLength; 366 const UCHAR *pCbDimension; 367 const UCHAR *pCbDimShift; 368 const UCHAR *pCbSign; 369 const UCHAR *pCbPriority; 370 } HCR_TABLE_INFO; 371 372 typedef struct { 373 UINT numSegment; 374 UINT pSegmentBitfield[((1024 >> 1) / NUMBER_OF_BIT_IN_WORD + 1)]; 375 UINT pCodewordBitfield[((1024 >> 1) / NUMBER_OF_BIT_IN_WORD + 1)]; 376 UINT segmentOffset; 377 INT pLeftStartOfSegment[1024 >> 1]; 378 INT pRightStartOfSegment[1024 >> 1]; 379 SCHAR pRemainingBitsInSegment[1024 >> 1]; 380 UCHAR readDirection; 381 UCHAR numWordForBitfield; 382 USHORT pNumBitValidInLastWord; 383 } HCR_SEGMENT_INFO; 384 385 typedef struct { 386 UINT numCodeword; 387 UINT numSortedSection; 388 USHORT pNumCodewordInSection[MAX_SFB_HCR]; 389 USHORT pNumSortedCodewordInSection[MAX_SFB_HCR]; 390 USHORT pNumExtendedSortedCodewordInSection[MAX_SFB_HCR + MAX_HCR_SETS]; 391 int numExtendedSortedCodewordInSectionIdx; 392 USHORT pNumExtendedSortedSectionsInSets[MAX_HCR_SETS]; 393 int numExtendedSortedSectionsInSetsIdx; 394 USHORT pReorderOffset[MAX_SFB_HCR]; 395 UCHAR pSortedCodebook[MAX_SFB_HCR]; 396 397 UCHAR pExtendedSortedCodebook[MAX_SFB_HCR + MAX_HCR_SETS]; 398 int extendedSortedCodebookIdx; 399 UCHAR pMaxLenOfCbInExtSrtSec[MAX_SFB_HCR + MAX_HCR_SETS]; 400 int maxLenOfCbInExtSrtSecIdx; 401 UCHAR pCodebookSwitch[MAX_SFB_HCR]; 402 } HCR_SECTION_INFO; 403 404 typedef UINT (*STATEFUNC)(HANDLE_FDK_BITSTREAM, void *); 405 406 typedef struct { 407 /* worst-case and 1024/4 non-PCWs exist in worst-case */ 408 FIXP_DBL 409 *pResultBase; /* Base address for spectral data output target buffer */ 410 UINT iNode[1024 >> 2]; /* Helper indices for code books */ 411 USHORT 412 iResultPointer[1024 >> 2]; /* Helper indices for accessing pResultBase */ 413 UINT pEscapeSequenceInfo[1024 >> 2]; 414 UINT codewordOffset; 415 STATEFUNC pState; 416 UCHAR pCodebook[1024 >> 2]; 417 UCHAR pCntSign[1024 >> 2]; 418 /* this array holds the states coded as integer values within the range 419 * [0,1,..,7] */ 420 SCHAR pSta[1024 >> 2]; 421 } HCR_NON_PCW_SIDEINFO; 422 423 typedef struct { 424 HCR_INPUT_OUTPUT decInOut; 425 HCR_SEGMENT_INFO segmentInfo; 426 HCR_SECTION_INFO sectionInfo; 427 HCR_NON_PCW_SIDEINFO nonPcwSideinfo; 428 } CErHcrInfo; 429 430 typedef CErHcrInfo *H_HCR_INFO; 431 432 #endif /* AACDEC_HCR_TYPES_H */ 433