|
1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /* |
|
21 \file |
|
22 \brief SBR codec interface $Revision: 1.1.1.1.4.1 $ |
|
23 */ |
|
24 |
|
25 /************************************************************************** |
|
26 sbr_codec.h - SBR codec interface. |
|
27 |
|
28 Author(s): Juha Ojanpera |
|
29 Copyright (c) 2004 by Nokia Research Center, Multimedia Technologies. |
|
30 *************************************************************************/ |
|
31 |
|
32 #ifndef SBR_CODEC_H_ |
|
33 #define SBR_CODEC_H_ |
|
34 |
|
35 /*-- Project Headers. --*/ |
|
36 #include "nok_bits.h" |
|
37 #include "defines.h" |
|
38 |
|
39 #pragma warning( disable : 4244) |
|
40 |
|
41 #define SBR_EXTENSION (13) /*-- 1101 --*/ |
|
42 #define SBR_EXTENSION_CRC (14) /*-- 1110 --*/ |
|
43 #define MAX_NR_ELEMENTS (2) |
|
44 #define MAX_SBR_BYTES (128) |
|
45 |
|
46 /** |
|
47 * Error codes for SBR processing. |
|
48 */ |
|
49 typedef enum |
|
50 { |
|
51 SBRDEC_OK = 0, |
|
52 SBRDEC_CONCEAL, |
|
53 SBRDEC_NOSYNCH, |
|
54 SBRDEC_ILLEGAL_PROGRAM, |
|
55 SBRDEC_ILLEGAL_TAG, |
|
56 SBRDEC_ILLEGAL_CHN_CONFIG, |
|
57 SBRDEC_ILLEGAL_SECTION, |
|
58 SBRDEC_ILLEGAL_SCFACTORS, |
|
59 SBRDEC_ILLEGAL_PULSE_DATA, |
|
60 SBRDEC_MAIN_PROFILE_NOT_IMPLEMENTED, |
|
61 SBRDEC_GC_NOT_IMPLEMENTED, |
|
62 SBRDEC_ILLEGAL_PLUS_ELE_ID, |
|
63 SBRDEC_CREATE_ERROR, |
|
64 SBRDEC_NOT_INITIALIZED |
|
65 |
|
66 } SBR_ERROR; |
|
67 |
|
68 /** |
|
69 * SBR element tags, these are the same as used in AAC also. |
|
70 */ |
|
71 typedef enum |
|
72 { |
|
73 SBR_ID_SCE = 0, |
|
74 SBR_ID_CPE, |
|
75 SBR_ID_CCE, |
|
76 SBR_ID_LFE, |
|
77 SBR_ID_DSE, |
|
78 SBR_ID_PCE, |
|
79 SBR_ID_FIL, |
|
80 SBR_ID_END |
|
81 |
|
82 } SBR_ELEMENT_ID; |
|
83 |
|
84 /** |
|
85 * Bitstream element for SBR payload data. |
|
86 */ |
|
87 typedef struct |
|
88 { |
|
89 /** |
|
90 * Length of payload data. |
|
91 */ |
|
92 int16 Payload; |
|
93 |
|
94 /** |
|
95 * Channel element ID for the associated SBR data. |
|
96 */ |
|
97 int16 ElementID; |
|
98 |
|
99 /** |
|
100 * Offset to the start of the channel element, in bits. |
|
101 */ |
|
102 int32 elementOffset; |
|
103 |
|
104 /** |
|
105 * Length of the channel element, in bits. |
|
106 */ |
|
107 int32 chElementLen; |
|
108 |
|
109 /** |
|
110 * Decoding status of SBR header. |
|
111 */ |
|
112 uint8 headerStatus; |
|
113 |
|
114 /** |
|
115 * Type of SBR element (with or without CRC codeword). |
|
116 */ |
|
117 int16 ExtensionType; |
|
118 |
|
119 /** |
|
120 * SBR bitstream data. |
|
121 */ |
|
122 uint8 *Data; |
|
123 |
|
124 } SbrElementStream; |
|
125 |
|
126 typedef struct |
|
127 { |
|
128 int16 NrElements; |
|
129 SbrElementStream sbrElement[MAX_NR_ELEMENTS]; |
|
130 |
|
131 } SbrBitStream; |
|
132 |
|
133 /** |
|
134 * SBR handle. |
|
135 */ |
|
136 typedef struct SBR_Decoder_Instance SBR_Decoder; |
|
137 |
|
138 /** |
|
139 * Creates SBR bitstream handle. |
|
140 * |
|
141 * Possible leave codes: |
|
142 * - <code>KErrNoMemory</code> if memory allocation fails |
|
143 * |
|
144 * @return Handle to SBR bitstream handle |
|
145 * |
|
146 */ |
|
147 SbrBitStream * |
|
148 OpenSBRBitStreamL(void); |
|
149 |
|
150 /** |
|
151 * Closes SBR bitstream handle. |
|
152 * |
|
153 * @param Bitstr Handle to SBR bitstream to be deleted |
|
154 * @return NULL |
|
155 * |
|
156 */ |
|
157 SbrBitStream * |
|
158 CloseSBRBitStream(SbrBitStream *Bitstr); |
|
159 |
|
160 /** |
|
161 * Creates SBR decoding/parsing handle. |
|
162 * |
|
163 * Possible leave codes: |
|
164 * - <code>KErrNoMemory</code> if memory allocation fails |
|
165 * |
|
166 * @param sampleRate Sample rate of the AAC bitstream |
|
167 * @param samplesPerFrame Frame length of the AAC stream (1024 or 960) |
|
168 * @param isStereo 1 if stereo AAC stream, 0 otherwise (=mono) |
|
169 * @param isDualMono 1 if two single channel elements present in the AAC bistream, 0 otherwise |
|
170 * @return Handle to SBR decoding/parsing handle |
|
171 * |
|
172 */ |
|
173 SBR_Decoder * |
|
174 OpenSBRDecoderL(int32 sampleRate, |
|
175 int16 samplesPerFrame, |
|
176 uint8 isStereo, |
|
177 uint8 isDualMono); |
|
178 |
|
179 /** |
|
180 * Closes SBR decoding handle. |
|
181 * |
|
182 * @param Bitstr Handle to SBR decoding/parsing to be deleted |
|
183 * @return NULL |
|
184 * |
|
185 */ |
|
186 SBR_Decoder * |
|
187 CloseSBR(SBR_Decoder *self); |
|
188 |
|
189 /** |
|
190 * Parses the SBR payload data and writes the modified bitstream element(s) |
|
191 * to output AAC bitstream. |
|
192 * |
|
193 * @param bsIn Handle to AAC input bitstream |
|
194 * @param bsOut Handle to AAC output bitstream |
|
195 * @param self Handle to SBR parser |
|
196 * @param Bitstr Handle to SBR bitstream element(s) |
|
197 * @param decVal Volume level adjustment factor |
|
198 * @return Number of bytes written to output bitstream |
|
199 * |
|
200 */ |
|
201 int16 |
|
202 ParseSBR(TBitStream *bsIn, |
|
203 TBitStream *bsOut, |
|
204 SBR_Decoder *self, |
|
205 SbrBitStream *Bitstr, |
|
206 int16 decVal); |
|
207 |
|
208 /** |
|
209 * Chacks whether parametric stereo tool is enabled in the SBR elements. |
|
210 * |
|
211 * @param self Handle to SBR parser |
|
212 * @param Bitstr Handle to SBR bitstream element(s) |
|
213 * @return 1 if parametric stereo found, 0 otherwise |
|
214 * |
|
215 */ |
|
216 uint8 |
|
217 IsSBRParametricStereoEnabled(SBR_Decoder *self, SbrBitStream *Bitstr); |
|
218 |
|
219 /** |
|
220 * Chacks whether SBR elements present in the bistream. |
|
221 * |
|
222 * @param Bitstr Handle to SBR bitstream element(s) |
|
223 * @return 1 if SBR elements found, 0 otherwise |
|
224 * |
|
225 */ |
|
226 uint8 |
|
227 IsSBREnabled(SbrBitStream *Bitstr); |
|
228 |
|
229 /** |
|
230 * Reads SBR payload data from AAC bitstream into SBR bitstream handle. |
|
231 * |
|
232 * @param bs Handle to AAC bitstream |
|
233 * @param streamSBR Handle to SBR bitstream handle |
|
234 * @param extension_type SBR payload type |
|
235 * @param prev_element Channel element type prior the fill element |
|
236 * @param dataCount Length of SBR payload data, in bytes |
|
237 * @return 1 if SBR read, 0 otherwise (in which case the callee should read the data) |
|
238 * |
|
239 */ |
|
240 int16 |
|
241 ReadSBRExtensionData(TBitStream *bs, |
|
242 SbrBitStream *streamSBR, |
|
243 int16 extension_type, |
|
244 int16 prev_element, |
|
245 int16 dataCount); |
|
246 |
|
247 /** |
|
248 * Initializes SBR handle for silence data generation. |
|
249 * |
|
250 * @param sbrDec Handle to SBR decoder |
|
251 * @param isStereo 1 if stereo AAC stream, 0 otherwise (=mono) |
|
252 * @param isParametricStereo 1 if parametric stereo should be included in the SBR data |
|
253 * |
|
254 */ |
|
255 void |
|
256 InitSBRSilenceData(SBR_Decoder *sbrDec, uint8 isStereo, uint8 isParametricStereo); |
|
257 |
|
258 /** |
|
259 * Writes silence to SBR channel element. Please note that this method is supposed |
|
260 * to be called inside AAC bitstream multiplexer and is therefore part of encoding. |
|
261 * If you want to upgrade plain AAC bitstream to eAAC+, use 'GenerateSBRSilenceDataL()' |
|
262 * first to generate the silence bits for SBR, then parse the AAC bitstream (so that the |
|
263 * channel element positions and their length are known) and finally call |
|
264 * 'WriteSBRSilence()' to write the output eAAC+ bitstream. |
|
265 * |
|
266 * @param sbrDecoder Handle to SBR codec |
|
267 * @param bsOut Handle to output (AAC) bitstream |
|
268 * @param isStereo 1 if stereo AAC stream, 0 otherwise (=mono) |
|
269 * @return Length of SBR silence data, in bits |
|
270 * |
|
271 */ |
|
272 int16 |
|
273 WriteSBRSilenceElement(SBR_Decoder *sbrDecoder, TBitStream *bsOut, uint8 isStereo); |
|
274 |
|
275 /** |
|
276 * Generates silence bits for SBR bitstream. |
|
277 * |
|
278 * Possible leave codes: |
|
279 * - <code>KErrNoMemory</code> if memory allocation fails |
|
280 * |
|
281 * @param OutBuffer Output buffer receiving silence data bits |
|
282 * @param OutBufferSize Size of output buffer |
|
283 * @param sampleRate Sample rate of the AAC bitstream |
|
284 * @param isStereo 1 if stereo AAC stream, 0 otherwise (=mono) |
|
285 * @param isParametricStereo 1 if parametric stereo should be included in the SBR data |
|
286 * @return Length of SBR silence data, in bits |
|
287 * |
|
288 */ |
|
289 int16 |
|
290 GenerateSBRSilenceDataL(uint8 *OutBuffer, |
|
291 int16 OutBufferSize, |
|
292 int32 sampleRate, |
|
293 uint8 isStereo, |
|
294 uint8 isParametricStereo); |
|
295 |
|
296 /** |
|
297 * Writes silence to the SBR part of the AAC bitstream. |
|
298 * |
|
299 * @param bsIn AAC input bitstream |
|
300 * @param bsOut Output bitstream (AAC + SBR) |
|
301 * @param streamSBR Handle to SBR bitstream element |
|
302 * @param SbrBuffer Payload data to generate SBR silence |
|
303 * @param SbrBits Length of SBR silence, in bits |
|
304 * @return Length of AAC + SBR bitstream, in bytes |
|
305 * |
|
306 */ |
|
307 int16 |
|
308 WriteSBRSilence(TBitStream *bsIn, |
|
309 TBitStream *bsOut, |
|
310 SbrBitStream *streamSBR, |
|
311 uint8 *SbrBuffer, |
|
312 int16 SbrBits); |
|
313 |
|
314 #endif /*-- SBR_CODEC_H_ --*/ |