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 /******************* MPEG transport format encoder library *********************
96 
97    Author(s):
98 
99    Description:
100 
101 *******************************************************************************/
102 
103 #ifndef TPENC_LATM_H
104 #define TPENC_LATM_H
105 
106 #include "tpenc_lib.h"
107 #include "FDK_bitstream.h"
108 
109 #define DEFAULT_LATM_NR_OF_SUBFRAMES 1
110 #define DEFAULT_LATM_SMC_REPEAT 8
111 
112 #define MAX_AAC_LAYERS 9
113 
114 #define LATM_MAX_PROGRAMS 1
115 #define LATM_MAX_STREAM_ID 16
116 
117 #define LATM_MAX_LAYERS 1 /*MAX_AAC_LAYERS*/
118 
119 #define MAX_NR_OF_SUBFRAMES                         \
120   2 /* set this carefully to avoid buffer overflows \
121      */
122 
123 typedef enum { LATMVAR_SIMPLE_SEQUENCE } LATM_VAR_MODE;
124 
125 typedef struct {
126   signed int frameLengthType;
127   signed int frameLengthBits;
128   signed int varFrameLengthTable[4];
129   signed int streamID;
130 } LATM_LAYER_INFO;
131 
132 typedef struct {
133   LATM_LAYER_INFO m_linfo[LATM_MAX_PROGRAMS][LATM_MAX_LAYERS];
134   CODER_CONFIG *config[LATM_MAX_PROGRAMS][LATM_MAX_LAYERS];
135 
136   LATM_VAR_MODE varMode;
137   TRANSPORT_TYPE tt;
138 
139   int audioMuxLengthBytes;
140 
141   int audioMuxLengthBytesPos;
142   int taraBufferFullness; /* state of the bit reservoir */
143   int varStreamCnt;
144 
145   UCHAR
146   latmFrameCounter;      /* Current frame number. Counts modulo muxConfigPeriod
147                           */
148   UCHAR muxConfigPeriod; /* Distance in frames between MuxConfig */
149 
150   UCHAR
151   audioMuxVersion; /* AMV1 supports transmission of taraBufferFullness and
152                       ASC lengths */
153   UCHAR audioMuxVersionA; /* for future extensions */
154 
155   UCHAR noProgram;
156   UCHAR noLayer[LATM_MAX_PROGRAMS];
157   UCHAR fractDelayPresent;
158 
159   UCHAR allStreamsSameTimeFraming;
160   UCHAR subFrameCnt;      /* Current Subframe frame */
161   UCHAR noSubframes;      /* Number of subframes    */
162   UINT latmSubframeStart; /* Position of current subframe start */
163   UCHAR noSubframes_next;
164 
165   UCHAR otherDataLenBits; /* AudioMuxElement other data bits */
166   UCHAR fillBits;         /* AudioMuxElement fill bits */
167   UINT streamMuxConfigBits;
168 
169 } LATM_STREAM;
170 
171 typedef LATM_STREAM *HANDLE_LATM_STREAM;
172 
173 /**
174  * \brief Initialize LATM_STREAM Handle. Creates automatically one program with
175  * one layer with the given layerConfig. The layerConfig must be persisten
176  * because references to this pointer are made at any time again. Use
177  * transportEnc_Latm_AddLayer() to add more programs/layers.
178  *
179  * \param hLatmStreamInfo HANDLE_LATM_STREAM handle
180  * \param hBs Bitstream handle
181  * \param layerConfig a valid CODER_CONFIG struct containing the current audio
182  * configuration parameters
183  * \param audioMuxVersion the LATM audioMuxVersion to be used
184  * \param tt the specific TRANSPORT_TYPE to be used, either TT_MP4_LOAS,
185  * TT_MP4_LATM_MCP1 or TT_MP4_LATM_MCP0 LOAS
186  * \param cb callback information structure.
187  *
188  * \return an TRANSPORTENC_ERROR error code
189  */
190 TRANSPORTENC_ERROR transportEnc_Latm_Init(HANDLE_LATM_STREAM hLatmStreamInfo,
191                                           HANDLE_FDK_BITSTREAM hBs,
192                                           CODER_CONFIG *layerConfig,
193                                           UINT audioMuxVersion,
194                                           TRANSPORT_TYPE tt, CSTpCallBacks *cb);
195 
196 /**
197  * \brief Write addional other data bits in AudioMuxElement
198  *
199  * \param hAss HANDLE_LATM_STREAM handle
200  * \param otherDataBits number of other data bits to be written
201  *
202  * \return an TRANSPORTENC_ERROR error code
203  */
204 TRANSPORTENC_ERROR transportEnc_LatmAddOtherDataBits(HANDLE_LATM_STREAM hAss,
205                                                      const int otherDataBits);
206 
207 /**
208  * \brief Get bit demand of next LATM/LOAS header
209  *
210  * \param hAss HANDLE_LATM_STREAM handle
211  * \param streamDataLength the length of the payload
212  *
213  * \return the number of bits required by the LATM/LOAS headers
214  */
215 unsigned int transportEnc_LatmCountTotalBitDemandHeader(
216     HANDLE_LATM_STREAM hAss, unsigned int streamDataLength);
217 
218 /**
219  * \brief Write LATM/LOAS header into given bitstream handle
220  *
221  * \param hLatmStreamInfo HANDLE_LATM_STREAM handle
222  * \param hBitstream Bitstream handle
223  * \param auBits amount of current payload bits
224  * \param bufferFullness LATM buffer fullness value
225  * \param cb callback information structure.
226  *
227  * \return an TRANSPORTENC_ERROR error code
228  */
229 TRANSPORTENC_ERROR
230 transportEnc_LatmWrite(HANDLE_LATM_STREAM hAss, HANDLE_FDK_BITSTREAM hBitstream,
231                        int auBits, int bufferFullness, CSTpCallBacks *cb);
232 
233 /**
234  * \brief Adjust bit count relative to current subframe
235  *
236  * \param hAss HANDLE_LATM_STREAM handle
237  * \param pBits pointer to an int, where the current frame bit count is
238  * contained, and where the subframe relative bit count will be returned into
239  *
240  * \return void
241  */
242 void transportEnc_LatmAdjustSubframeBits(HANDLE_LATM_STREAM hAss, int *pBits);
243 
244 /**
245  * \brief Request an LATM frame, which may, or may not be available
246  *
247  * \param hAss HANDLE_LATM_STREAM handle
248  * \param hBs Bitstream handle
249  * \param pBytes pointer to an int, where the current frame byte count stored
250  * into. A return value of zero means that currently no LATM/LOAS frame can be
251  * returned. The latter is expected in case of multiple subframes being
252  * used.
253  *
254  * \return an TRANSPORTENC_ERROR error code
255  */
256 TRANSPORTENC_ERROR transportEnc_LatmGetFrame(HANDLE_LATM_STREAM hAss,
257                                              HANDLE_FDK_BITSTREAM hBs,
258                                              int *pBytes);
259 
260 /**
261  * \brief Write a StreamMuxConfig into the given bitstream handle
262  *
263  * \param hAss HANDLE_LATM_STREAM handle
264  * \param hBs Bitstream handle
265  * \param bufferFullness LATM buffer fullness value
266  * \param cb callback information structure.
267  *
268  * \return void
269  */
270 TRANSPORTENC_ERROR
271 CreateStreamMuxConfig(HANDLE_LATM_STREAM hAss, HANDLE_FDK_BITSTREAM hBs,
272                       int bufferFullness, CSTpCallBacks *cb);
273 
274 #endif /* TPENC_LATM_H */
275