Mercurial > mplayer.hg
annotate libfaad2/mp4.c @ 13439:b35ec818ebeb
small fixes
author | diego |
---|---|
date | Wed, 22 Sep 2004 17:43:39 +0000 |
parents | d81145997036 |
children | 6d50ef45a058 |
rev | line source |
---|---|
10725 | 1 /* |
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding | |
12527 | 3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com |
10725 | 4 ** |
5 ** This program is free software; you can redistribute it and/or modify | |
6 ** it under the terms of the GNU General Public License as published by | |
7 ** the Free Software Foundation; either version 2 of the License, or | |
8 ** (at your option) any later version. | |
9 ** | |
10 ** This program is distributed in the hope that it will be useful, | |
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 ** GNU General Public License for more details. | |
14 ** | |
15 ** You should have received a copy of the GNU General Public License | |
16 ** along with this program; if not, write to the Free Software | |
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 ** | |
19 ** Any non-GPL usage of this software or parts of this software is strictly | |
20 ** forbidden. | |
21 ** | |
22 ** Commercial non-GPL licensing of this software is possible. | |
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. | |
24 ** | |
12625
d81145997036
More information about modifications to comply more closely with GPL 2a.
diego
parents:
12527
diff
changeset
|
25 ** Initially modified for use with MPlayer by Arpad Gereöffy on 2003/08/30 |
d81145997036
More information about modifications to comply more closely with GPL 2a.
diego
parents:
12527
diff
changeset
|
26 ** $Id: mp4.c,v 1.3 2004/06/02 22:59:03 diego Exp $ |
d81145997036
More information about modifications to comply more closely with GPL 2a.
diego
parents:
12527
diff
changeset
|
27 ** detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/ |
10725 | 28 **/ |
29 | |
30 #include "common.h" | |
31 #include "structs.h" | |
32 | |
33 #include <stdlib.h> | |
34 | |
35 #include "bits.h" | |
36 #include "mp4.h" | |
37 #include "syntax.h" | |
38 | |
39 /* defines if an object type can be decoded by this library or not */ | |
40 static uint8_t ObjectTypesTable[32] = { | |
41 0, /* 0 NULL */ | |
42 #ifdef MAIN_DEC | |
43 1, /* 1 AAC Main */ | |
44 #else | |
45 0, /* 1 AAC Main */ | |
46 #endif | |
47 1, /* 2 AAC LC */ | |
48 #ifdef SSR_DEC | |
49 1, /* 3 AAC SSR */ | |
50 #else | |
51 0, /* 3 AAC SSR */ | |
52 #endif | |
53 #ifdef LTP_DEC | |
54 1, /* 4 AAC LTP */ | |
55 #else | |
56 0, /* 4 AAC LTP */ | |
57 #endif | |
58 #ifdef SBR_DEC | |
59 1, /* 5 SBR */ | |
60 #else | |
61 0, /* 5 SBR */ | |
62 #endif | |
12527 | 63 #ifdef SCALABLE_DEC |
64 1, /* 6 AAC Scalable */ | |
65 #else | |
10725 | 66 0, /* 6 AAC Scalable */ |
12527 | 67 #endif |
10725 | 68 0, /* 7 TwinVQ */ |
69 0, /* 8 CELP */ | |
70 0, /* 9 HVXC */ | |
71 0, /* 10 Reserved */ | |
72 0, /* 11 Reserved */ | |
73 0, /* 12 TTSI */ | |
74 0, /* 13 Main synthetic */ | |
75 0, /* 14 Wavetable synthesis */ | |
76 0, /* 15 General MIDI */ | |
77 0, /* 16 Algorithmic Synthesis and Audio FX */ | |
78 | |
79 /* MPEG-4 Version 2 */ | |
80 #ifdef ERROR_RESILIENCE | |
81 1, /* 17 ER AAC LC */ | |
82 0, /* 18 (Reserved) */ | |
83 #ifdef LTP_DEC | |
84 1, /* 19 ER AAC LTP */ | |
85 #else | |
86 0, /* 19 ER AAC LTP */ | |
87 #endif | |
12527 | 88 #ifdef SCALABLE_DEC |
89 1, /* 20 ER AAC scalable */ | |
90 #else | |
10725 | 91 0, /* 20 ER AAC scalable */ |
12527 | 92 #endif |
10725 | 93 0, /* 21 ER TwinVQ */ |
94 0, /* 22 ER BSAC */ | |
95 #ifdef LD_DEC | |
96 1, /* 23 ER AAC LD */ | |
97 #else | |
98 0, /* 23 ER AAC LD */ | |
99 #endif | |
100 0, /* 24 ER CELP */ | |
101 0, /* 25 ER HVXC */ | |
102 0, /* 26 ER HILN */ | |
103 0, /* 27 ER Parametric */ | |
104 #else /* No ER defined */ | |
105 0, /* 17 ER AAC LC */ | |
106 0, /* 18 (Reserved) */ | |
107 0, /* 19 ER AAC LTP */ | |
108 0, /* 20 ER AAC scalable */ | |
109 0, /* 21 ER TwinVQ */ | |
110 0, /* 22 ER BSAC */ | |
111 0, /* 23 ER AAC LD */ | |
112 0, /* 24 ER CELP */ | |
113 0, /* 25 ER HVXC */ | |
114 0, /* 26 ER HILN */ | |
115 0, /* 27 ER Parametric */ | |
116 #endif | |
117 0, /* 28 (Reserved) */ | |
118 0, /* 29 (Reserved) */ | |
119 0, /* 30 (Reserved) */ | |
120 0 /* 31 (Reserved) */ | |
121 }; | |
122 | |
123 /* Table 1.6.1 */ | |
124 int8_t FAADAPI AudioSpecificConfig(uint8_t *pBuffer, | |
125 uint32_t buffer_size, | |
126 mp4AudioSpecificConfig *mp4ASC) | |
127 { | |
128 return AudioSpecificConfig2(pBuffer, buffer_size, mp4ASC, NULL); | |
129 } | |
130 | |
131 int8_t FAADAPI AudioSpecificConfig2(uint8_t *pBuffer, | |
132 uint32_t buffer_size, | |
133 mp4AudioSpecificConfig *mp4ASC, | |
134 program_config *pce) | |
135 { | |
136 bitfile ld; | |
137 int8_t result = 0; | |
138 #ifdef SBR_DEC | |
139 int8_t bits_to_decode = 0; | |
140 #endif | |
141 | |
142 if (pBuffer == NULL) | |
143 return -7; | |
144 if (mp4ASC == NULL) | |
145 return -8; | |
146 | |
147 memset(mp4ASC, 0, sizeof(mp4AudioSpecificConfig)); | |
148 | |
149 faad_initbits(&ld, pBuffer, buffer_size); | |
150 faad_byte_align(&ld); | |
151 | |
152 mp4ASC->objectTypeIndex = (uint8_t)faad_getbits(&ld, 5 | |
153 DEBUGVAR(1,1,"parse_audio_decoder_specific_info(): ObjectTypeIndex")); | |
154 | |
155 mp4ASC->samplingFrequencyIndex = (uint8_t)faad_getbits(&ld, 4 | |
156 DEBUGVAR(1,2,"parse_audio_decoder_specific_info(): SamplingFrequencyIndex")); | |
157 | |
158 mp4ASC->channelsConfiguration = (uint8_t)faad_getbits(&ld, 4 | |
159 DEBUGVAR(1,3,"parse_audio_decoder_specific_info(): ChannelsConfiguration")); | |
160 | |
10989 | 161 mp4ASC->samplingFrequency = get_sample_rate(mp4ASC->samplingFrequencyIndex); |
10725 | 162 |
163 if (ObjectTypesTable[mp4ASC->objectTypeIndex] != 1) | |
164 { | |
165 faad_endbits(&ld); | |
166 return -1; | |
167 } | |
168 | |
169 if (mp4ASC->samplingFrequency == 0) | |
170 { | |
171 faad_endbits(&ld); | |
172 return -2; | |
173 } | |
174 | |
175 if (mp4ASC->channelsConfiguration > 7) | |
176 { | |
177 faad_endbits(&ld); | |
178 return -3; | |
179 } | |
180 | |
181 #ifdef SBR_DEC | |
182 mp4ASC->sbr_present_flag = -1; | |
183 if (mp4ASC->objectTypeIndex == 5) | |
184 { | |
185 mp4ASC->sbr_present_flag = 1; | |
186 mp4ASC->samplingFrequencyIndex = (uint8_t)faad_getbits(&ld, 4 | |
187 DEBUGVAR(1,5,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex")); | |
188 if (mp4ASC->samplingFrequencyIndex == 15) | |
189 { | |
190 mp4ASC->samplingFrequency = (uint32_t)faad_getbits(&ld, 24 | |
191 DEBUGVAR(1,6,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex")); | |
192 } else { | |
10989 | 193 mp4ASC->samplingFrequency = get_sample_rate(mp4ASC->samplingFrequencyIndex); |
10725 | 194 } |
195 mp4ASC->objectTypeIndex = (uint8_t)faad_getbits(&ld, 5 | |
196 DEBUGVAR(1,7,"parse_audio_decoder_specific_info(): ObjectTypeIndex")); | |
197 } | |
198 #endif | |
199 | |
200 /* get GASpecificConfig */ | |
201 if (mp4ASC->objectTypeIndex == 1 || mp4ASC->objectTypeIndex == 2 || | |
202 mp4ASC->objectTypeIndex == 3 || mp4ASC->objectTypeIndex == 4 || | |
203 mp4ASC->objectTypeIndex == 6 || mp4ASC->objectTypeIndex == 7) | |
204 { | |
205 result = GASpecificConfig(&ld, mp4ASC, pce); | |
206 | |
207 #ifdef ERROR_RESILIENCE | |
208 } else if (mp4ASC->objectTypeIndex >= ER_OBJECT_START) { /* ER */ | |
209 result = GASpecificConfig(&ld, mp4ASC, pce); | |
210 mp4ASC->epConfig = (uint8_t)faad_getbits(&ld, 2 | |
211 DEBUGVAR(1,143,"parse_audio_decoder_specific_info(): epConfig")); | |
212 | |
213 if (mp4ASC->epConfig != 0) | |
214 result = -5; | |
215 #endif | |
216 | |
217 } else { | |
218 result = -4; | |
219 } | |
220 | |
221 #ifdef SSR_DEC | |
222 /* shorter frames not allowed for SSR */ | |
223 if ((mp4ASC->objectTypeIndex == 4) && mp4ASC->frameLengthFlag) | |
224 return -6; | |
225 #endif | |
226 | |
227 | |
228 #ifdef SBR_DEC | |
10989 | 229 bits_to_decode = (int8_t)(buffer_size*8 - faad_get_processed_bits(&ld)); |
10725 | 230 |
231 if ((mp4ASC->objectTypeIndex != 5) && (bits_to_decode >= 16)) | |
232 { | |
233 int16_t syncExtensionType = (int16_t)faad_getbits(&ld, 11 | |
234 DEBUGVAR(1,9,"parse_audio_decoder_specific_info(): syncExtensionType")); | |
235 | |
236 if (syncExtensionType == 0x2b7) | |
237 { | |
238 mp4ASC->objectTypeIndex = (uint8_t)faad_getbits(&ld, 5 | |
239 DEBUGVAR(1,10,"parse_audio_decoder_specific_info(): extensionAudioObjectType")); | |
240 | |
241 if (mp4ASC->objectTypeIndex == 5) | |
242 { | |
243 mp4ASC->sbr_present_flag = (uint8_t)faad_get1bit(&ld | |
244 DEBUGVAR(1,11,"parse_audio_decoder_specific_info(): sbr_present_flag")); | |
245 | |
246 if (mp4ASC->sbr_present_flag) | |
247 { | |
248 mp4ASC->samplingFrequencyIndex = (uint8_t)faad_getbits(&ld, 4 | |
249 DEBUGVAR(1,12,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex")); | |
250 if (mp4ASC->samplingFrequencyIndex == 15) | |
251 { | |
252 mp4ASC->samplingFrequency = (uint32_t)faad_getbits(&ld, 24 | |
253 DEBUGVAR(1,13,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex")); | |
254 } else { | |
10989 | 255 mp4ASC->samplingFrequency = get_sample_rate(mp4ASC->samplingFrequencyIndex); |
10725 | 256 } |
257 } | |
258 } | |
259 } | |
260 } | |
10989 | 261 |
262 /* no SBR signalled, this could mean either implicit signalling or no SBR in this file */ | |
263 /* MPEG specification states: assume SBR on files with samplerate <= 24000 Hz */ | |
264 if (mp4ASC->sbr_present_flag == -1) | |
265 { | |
266 if (mp4ASC->samplingFrequency <= 24000) | |
267 { | |
268 mp4ASC->samplingFrequency *= 2; | |
269 mp4ASC->forceUpSampling = 1; | |
270 } | |
271 } | |
10725 | 272 #endif |
273 | |
274 faad_endbits(&ld); | |
275 | |
276 return result; | |
277 } |