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 /******************* MPEG transport format decoder library ********************* 96 97 Author(s): Josef Hoepfl 98 99 Description: ADTS interface 100 101 *******************************************************************************/ 102 103 #ifndef TPDEC_ADTS_H 104 #define TPDEC_ADTS_H 105 106 #include "tpdec_lib.h" 107 108 #define ADTS_SYNCWORD (0xfff) 109 #define ADTS_SYNCLENGTH (12) /* in bits */ 110 #define ADTS_HEADERLENGTH (56) /* minimum header size in bits */ 111 #define ADTS_FIXED_HEADERLENGTH (28) /* in bits */ 112 #define ADTS_VARIABLE_HEADERLENGTH (ADTS_HEADERLENGTH - ADTS_FIXED_HEADERLENGTH) 113 114 #ifdef CHECK_TWO_SYNCS 115 #define ADTS_MIN_TP_BUF_SIZE (8191 + 2) 116 #else 117 #define ADTS_MIN_TP_BUF_SIZE (8191) 118 #endif 119 120 #include "FDK_crc.h" 121 122 typedef struct { 123 /* ADTS header fields */ 124 UCHAR mpeg_id; 125 UCHAR layer; 126 UCHAR protection_absent; 127 UCHAR profile; 128 UCHAR sample_freq_index; 129 UCHAR private_bit; 130 UCHAR channel_config; 131 UCHAR original; 132 UCHAR home; 133 UCHAR copyright_id; 134 UCHAR copyright_start; 135 USHORT frame_length; 136 USHORT adts_fullness; 137 UCHAR num_raw_blocks; 138 UCHAR num_pce_bits; 139 } STRUCT_ADTS_BS; 140 141 struct STRUCT_ADTS { 142 STRUCT_ADTS_BS bs; 143 144 UCHAR decoderCanDoMpeg4; 145 UCHAR BufferFullnesStartFlag; 146 147 FDK_CRCINFO crcInfo; /* CRC state info */ 148 USHORT crcReadValue; /* CRC value read from bitstream data */ 149 USHORT rawDataBlockDist[4]; /* distance between each raw data block. Not the 150 same as found in the bitstream */ 151 }; 152 153 typedef struct STRUCT_ADTS *HANDLE_ADTS; 154 155 /*! 156 \brief Initialize ADTS CRC 157 158 The function initialzes the crc buffer and the crc lookup table. 159 160 \return none 161 */ 162 void adtsRead_CrcInit(HANDLE_ADTS pAdts); 163 164 /** 165 * \brief Starts CRC region with a maximum number of bits 166 * If mBits is positive zero padding will be used for CRC calculation, if 167 * there are less than mBits bits available. If mBits is negative no zero 168 * padding is done. If mBits is zero the memory for the buffer is 169 * allocated dynamically, the number of bits is not limited. 170 * 171 * \param pAdts ADTS data handle 172 * \param hBs bitstream handle, on which the CRC region referes to 173 * \param mBits max number of bits in crc region to be considered 174 * 175 * \return ID for the created region, -1 in case of an error 176 */ 177 int adtsRead_CrcStartReg(HANDLE_ADTS pAdts, HANDLE_FDK_BITSTREAM hBs, 178 int mBits); 179 180 /** 181 * \brief Ends CRC region identified by reg 182 * 183 * \param pAdts ADTS data handle 184 * \param hBs bitstream handle, on which the CRC region referes to 185 * \param reg CRC regions ID returned by adtsRead_CrcStartReg() 186 * 187 * \return none 188 */ 189 void adtsRead_CrcEndReg(HANDLE_ADTS pAdts, HANDLE_FDK_BITSTREAM hBs, int reg); 190 191 /** 192 * \brief Check CRC 193 * 194 * Checks if the currently calculated CRC matches the CRC field read from the 195 * bitstream Deletes all CRC regions. 196 * 197 * \param pAdts ADTS data handle 198 * 199 * \return Returns 0 if they are identical otherwise 1 200 */ 201 TRANSPORTDEC_ERROR adtsRead_CrcCheck(HANDLE_ADTS pAdts); 202 203 /** 204 * \brief Check if we have a valid ADTS frame at the current bitbuffer position 205 * 206 * This function assumes enough bits in buffer for the current frame. 207 * It reads out the header bits to prepare the bitbuffer for the decode loop. 208 * In case the header bits show an invalid bitstream/frame, the whole frame is 209 * skipped. 210 * 211 * \param pAdts ADTS data handle which is filled with parsed ADTS header data 212 * \param bs handle of bitstream from whom the ADTS header is read 213 * 214 * \return error status 215 */ 216 TRANSPORTDEC_ERROR adtsRead_DecodeHeader(HANDLE_ADTS pAdts, 217 CSAudioSpecificConfig *pAsc, 218 HANDLE_FDK_BITSTREAM bs, 219 const INT ignoreBufferFullness); 220 221 /** 222 * \brief Get the raw data block length of the given block number. 223 * 224 * \param pAdts ADTS data handle 225 * \param blockNum current raw data block index 226 * \param pLength pointer to an INT where the length of the given raw data block 227 * is stored into the returned value might be -1, in which case the raw data 228 * block length is unknown. 229 * 230 * \return error status 231 */ 232 int adtsRead_GetRawDataBlockLength(HANDLE_ADTS pAdts, INT blockNum); 233 234 #endif /* TPDEC_ADTS_H */ 235