Home | History | Annotate | Download | only in include
      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 /**************************** SBR decoder library ******************************
     96 
     97    Author(s):
     98 
     99    Description: SBR decoder front-end prototypes and definitions.
    100 
    101 *******************************************************************************/
    102 
    103 #ifndef SBRDECODER_H
    104 #define SBRDECODER_H
    105 
    106 #include "common_fix.h"
    107 
    108 #include "FDK_bitstream.h"
    109 #include "FDK_audio.h"
    110 
    111 #include "FDK_qmf_domain.h"
    112 
    113 #define SBR_DEBUG_EXTHLP \
    114   "\
    115 --- SBR ---\n\
    116     0x00000010 Ancillary data and SBR-Header\n\
    117     0x00000020 SBR-Side info\n\
    118     0x00000040 Decoded SBR-bitstream data, e.g. envelope data\n\
    119     0x00000080 SBR-Bitstream statistics\n\
    120     0x00000100 Miscellaneous SBR-messages\n\
    121     0x00000200 SBR-Energies and gains in the adjustor\n\
    122     0x00000400 Fatal SBR errors\n\
    123     0x00000800 Transposer coefficients for inverse filtering\n\
    124 "
    125 
    126 /* Capability flags */
    127 #define CAPF_SBR_LP \
    128   0x00000001 /*!< Flag indicating library's capability of Low Power mode. */
    129 #define CAPF_SBR_HQ                                                          \
    130   0x00000002 /*!< Flag indicating library's capability of High Quality mode. \
    131               */
    132 #define CAPF_SBR_DRM_BS                                                        \
    133   0x00000004 /*!< Flag indicating library's capability to decode DRM SBR data. \
    134               */
    135 #define CAPF_SBR_CONCEALMENT                                                \
    136   0x00000008 /*!< Flag indicating library's capability to conceal erroneous \
    137                 frames.          */
    138 #define CAPF_SBR_DRC                                                     \
    139   0x00000010 /*!< Flag indicating library's capability for Dynamic Range \
    140                 Control.            */
    141 #define CAPF_SBR_PS_MPEG                                                     \
    142   0x00000020 /*!< Flag indicating library's capability to do MPEG Parametric \
    143                 Stereo.         */
    144 #define CAPF_SBR_PS_DRM                                                     \
    145   0x00000040 /*!< Flag indicating library's capability to do DRM Parametric \
    146                 Stereo.          */
    147 #define CAPF_SBR_ELD_DOWNSCALE                                               \
    148   0x00000080 /*!< Flag indicating library's capability to do ELD decoding in \
    149                 downscaled mode */
    150 #define CAPF_SBR_HBEHQ                                                   \
    151   0x00000100 /*!< Flag indicating library's capability to do HQ Harmonic \
    152                 transposing         */
    153 
    154 typedef enum {
    155   SBRDEC_OK = 0, /*!< All fine. */
    156   /* SBRDEC_CONCEAL, */
    157   /* SBRDEC_NOSYNCH, */
    158   /* SBRDEC_ILLEGAL_PROGRAM, */
    159   /* SBRDEC_ILLEGAL_TAG, */
    160   /* SBRDEC_ILLEGAL_CHN_CONFIG, */
    161   /* SBRDEC_ILLEGAL_SECTION, */
    162   /* SBRDEC_ILLEGAL_SCFACTORS, */
    163   /* SBRDEC_ILLEGAL_PULSE_DATA, */
    164   /* SBRDEC_MAIN_PROFILE_NOT_IMPLEMENTED, */
    165   /* SBRDEC_GC_NOT_IMPLEMENTED, */
    166   /* SBRDEC_ILLEGAL_PLUS_ELE_ID, */
    167   SBRDEC_INVALID_ARGUMENT,   /*!<   */
    168   SBRDEC_CREATE_ERROR,       /*!<       */
    169   SBRDEC_NOT_INITIALIZED,    /*!<    */
    170   SBRDEC_MEM_ALLOC_FAILED,   /*!< Memory allocation failed. Probably not enough
    171                                 memory available. */
    172   SBRDEC_PARSE_ERROR,        /*!<        */
    173   SBRDEC_UNSUPPORTED_CONFIG, /*!< */
    174   SBRDEC_SET_PARAM_FAIL,     /*!<     */
    175   SBRDEC_OUTPUT_BUFFER_TOO_SMALL /*!< */
    176 } SBR_ERROR;
    177 
    178 typedef enum {
    179   SBR_SYSTEM_BITSTREAM_DELAY, /*!< System: Switch to enable an additional SBR
    180                                  bitstream delay of one frame. */
    181   SBR_QMF_MODE,               /*!< Set QMF mode, either complex or low power. */
    182   SBR_LD_QMF_TIME_ALIGN, /*!< Set QMF type, either LD-MPS or CLDFB. Relevant for
    183                             ELD streams only. */
    184   SBR_FLUSH_DATA,     /*!< Set internal state to flush the decoder with the next
    185                          process call. */
    186   SBR_CLEAR_HISTORY,  /*!< Clear all internal states (delay lines, QMF states,
    187                          ...). */
    188   SBR_BS_INTERRUPTION /*!< Signal bit stream interruption. Value is ignored. */
    189   ,
    190   SBR_SKIP_QMF /*!< Enable skipping of QMF step: 1 skip analysis, 2 skip
    191                   synthesis */
    192 } SBRDEC_PARAM;
    193 
    194 typedef struct SBR_DECODER_INSTANCE *HANDLE_SBRDECODER;
    195 
    196 #ifdef __cplusplus
    197 extern "C" {
    198 #endif
    199 
    200 /**
    201  * \brief             Allocates and initializes one SBR decoder instance.
    202  * \param pSelf       Pointer to where a SBR decoder handle is copied into.
    203  * \param pQmfDomain  Pointer to QMF domain data structure.
    204  *
    205  * \return            Error code.
    206  */
    207 SBR_ERROR sbrDecoder_Open(HANDLE_SBRDECODER *pSelf,
    208                           HANDLE_FDK_QMF_DOMAIN pQmfDomain);
    209 
    210 /**
    211  * \brief  Initialize a SBR decoder runtime instance. Must be called before
    212  * decoding starts.
    213  *
    214  * \param self             Handle to a SBR decoder instance.
    215  * \param sampleRateIn     Input samplerate of the SBR decoder instance.
    216  * \param sampleRateOut    Output samplerate of the SBR decoder instance.
    217  * \param samplesPerFrame  Number of samples per frames.
    218  * \param coreCodec        Audio Object Type (AOT) of the core codec.
    219  * \param elementID        Table with MPEG-4 element Ids in canonical order.
    220  * \param elementIndex     SBR element index
    221  * \param harmonicSBR
    222  * \param stereoConfigIndex
    223  * \param downscaleFactor  ELD downscale factor
    224  * \param configMode       Table with MPEG-4 element Ids in canonical order.
    225  * \param configChanged    Flag that enforces a complete decoder reset.
    226  *
    227  * \return  Error code.
    228  */
    229 SBR_ERROR sbrDecoder_InitElement(
    230     HANDLE_SBRDECODER self, const int sampleRateIn, const int sampleRateOut,
    231     const int samplesPerFrame, const AUDIO_OBJECT_TYPE coreCodec,
    232     const MP4_ELEMENT_ID elementID, const int elementIndex,
    233     const UCHAR harmonicSBR, const UCHAR stereoConfigIndex,
    234     const UCHAR configMode, UCHAR *configChanged, const INT downscaleFactor);
    235 
    236 /**
    237  * \brief Free config dependent SBR memory.
    238  * \param self SBR decoder instance handle
    239  */
    240 SBR_ERROR sbrDecoder_FreeMem(HANDLE_SBRDECODER *self);
    241 
    242 /**
    243  * \brief pass out of band SBR header to SBR decoder
    244  *
    245  * \param self         Handle to a SBR decoder instance.
    246  * \param hBs          bit stream handle data source.
    247  * \param sampleRateIn SBR input sampling rate
    248  * \param sampleRateOut SBR output sampling rate
    249  * \param samplesPerFrame frame length
    250  * \param elementID    SBR element ID.
    251  * \param elementIndex SBR element index.
    252  * \param harmonicSBR
    253  * \param stereoConfigIndex
    254  * \param downscaleFactor  ELD downscale factor
    255  *
    256  * \return  Error code.
    257  */
    258 INT sbrDecoder_Header(HANDLE_SBRDECODER self, HANDLE_FDK_BITSTREAM hBs,
    259                       const INT sampleRateIn, const INT sampleRateOut,
    260                       const INT samplesPerFrame,
    261                       const AUDIO_OBJECT_TYPE coreCodec,
    262                       const MP4_ELEMENT_ID elementID, const INT elementIndex,
    263                       const UCHAR harmonicSBR, const UCHAR stereoConfigIndex,
    264                       const UCHAR configMode, UCHAR *configChanged,
    265                       const INT downscaleFactor);
    266 
    267 /**
    268  * \brief        Set a parameter of the SBR decoder runtime instance.
    269  * \param self   SBR decoder handle.
    270  * \param param  Parameter which will be set if successfull.
    271  * \param value  New parameter value.
    272  * \return       Error code.
    273  */
    274 SBR_ERROR sbrDecoder_SetParam(HANDLE_SBRDECODER self, const SBRDEC_PARAM param,
    275                               const INT value);
    276 
    277 /**
    278  * \brief  Feed DRC channel data into a SBR decoder runtime instance.
    279  *
    280  * \param self                    SBR decoder handle.
    281  * \param ch                      Channel number to which the DRC data is
    282  * associated to.
    283  * \param numBands                Number of DRC bands.
    284  * \param pNextFact_mag           Pointer to a table with the DRC factor
    285  * magnitudes.
    286  * \param nextFact_exp            Exponent for all DRC factors.
    287  * \param drcInterpolationScheme  DRC interpolation scheme.
    288  * \param winSequence             Window sequence from core coder (eight short
    289  * or one long window).
    290  * \param pBandTop                Pointer to a table with the top borders for
    291  * all DRC bands.
    292  *
    293  * \return  Error code.
    294  */
    295 SBR_ERROR sbrDecoder_drcFeedChannel(HANDLE_SBRDECODER self, INT ch,
    296                                     UINT numBands, FIXP_DBL *pNextFact_mag,
    297                                     INT nextFact_exp,
    298                                     SHORT drcInterpolationScheme,
    299                                     UCHAR winSequence, USHORT *pBandTop);
    300 
    301 /**
    302  * \brief  Disable SBR DRC for a certain channel.
    303  *
    304  * \param hSbrDecoder  SBR decoder handle.
    305  * \param ch           Number of the channel that has to be disabled.
    306  *
    307  * \return  None.
    308  */
    309 void sbrDecoder_drcDisable(HANDLE_SBRDECODER self, INT ch);
    310 
    311 /**
    312  * \brief  Parse one SBR element data extension data block. The bit stream
    313  * position will be placed at the end of the SBR payload block. The remaining
    314  * bits will be returned into *count if a payload length is given
    315  * (byPayLen > 0). If no SBR payload length is given (bsPayLen < 0) then
    316  * the bit stream position on return will be random after this function
    317  * call in case of errors, and any further decoding will be completely
    318  * pointless. This function accepts either normal ordered SBR data or reverse
    319  * ordered DRM SBR data.
    320  *
    321  * \param self           SBR decoder handle.
    322  * \param hBs            Bit stream handle as data source.
    323  * \param count          Pointer to an integer where the amount of parsed SBR
    324  * payload bits is stored into.
    325  * \param bsPayLen       If > 0 this value is the SBR payload length. If < 0,
    326  * the SBR payload length is unknown.
    327  * \param flags          CRC flag (0: EXT_SBR_DATA; 1: EXT_SBR_DATA_CRC)
    328  * \param prev_element   Previous MPEG-4 element ID.
    329  * \param element_index  Index of the current element.
    330  * \param acFlags        Audio codec flags
    331  *
    332  * \return  Error code.
    333  */
    334 SBR_ERROR sbrDecoder_Parse(HANDLE_SBRDECODER self, HANDLE_FDK_BITSTREAM hBs,
    335                            UCHAR *pDrmBsBuffer, USHORT drmBsBufferSize,
    336                            int *count, int bsPayLen, int crcFlag,
    337                            MP4_ELEMENT_ID prev_element, int element_index,
    338                            UINT acFlags, UINT acElFlags[]);
    339 
    340 /**
    341  * \brief  This function decodes the given SBR bitstreams and applies SBR to the
    342  * given time data.
    343  *
    344  * SBR-processing works InPlace. I.e. the calling function has to provide
    345  * a time domain buffer timeData which can hold the completely decoded
    346  * result.
    347  *
    348  * Left and right channel are read and stored according to the
    349  * interleaving flag, frame length and number of channels.
    350  *
    351  * \param self            Handle of an open SBR decoder instance.
    352  * \param hSbrBs          SBR Bitstream handle.
    353  * \param input           Pointer to input data.
    354  * \param timeData        Pointer to upsampled output data.
    355  * \param timeDataSize    Size of timeData.
    356  * \param numChannels     Pointer to a buffer holding the number of channels in
    357  * time data buffer.
    358  * \param sampleRate      Output samplerate.
    359  * \param channelMapping  Channel mapping indices.
    360  * \param coreDecodedOk   Flag indicating if the core decoder did not find any
    361  * error (0: core decoder found errors, 1: no errors).
    362  * \param psDecoded       Pointer to a buffer holding a flag. Input: PS is
    363  * possible, Output: PS has been rendered.
    364  *
    365  * \return  Error code.
    366  */
    367 SBR_ERROR sbrDecoder_Apply(HANDLE_SBRDECODER self, INT_PCM *input,
    368                            INT_PCM *timeData, const int timeDataSize,
    369                            int *numChannels, int *sampleRate,
    370                            const FDK_channelMapDescr *const mapDescr,
    371                            const int mapIdx, const int coreDecodedOk,
    372                            UCHAR *psDecoded);
    373 
    374 /**
    375  * \brief       Close SBR decoder instance and free memory.
    376  * \param self  SBR decoder handle.
    377  * \return      Error Code.
    378  */
    379 SBR_ERROR sbrDecoder_Close(HANDLE_SBRDECODER *self);
    380 
    381 /**
    382  * \brief       Get SBR decoder library information.
    383  * \param info  Pointer to a LIB_INFO struct, where library information is
    384  * written to.
    385  * \return      0 on success, -1 if invalid handle or if no free element is
    386  * available to write information to.
    387  */
    388 INT sbrDecoder_GetLibInfo(LIB_INFO *info);
    389 
    390 /**
    391  * \brief       Determine the modules output signal delay in samples.
    392  * \param self  SBR decoder handle.
    393  * \return      The number of samples signal delay added by the module.
    394  */
    395 UINT sbrDecoder_GetDelay(const HANDLE_SBRDECODER self);
    396 
    397 #ifdef __cplusplus
    398 }
    399 #endif
    400 
    401 #endif
    402