1 /*
2 * AIFF/AIFF-C demuxer
3 * Copyright (c) 2006 Patrick Guimond
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
32
34 #define AIFF_C_VERSION1 0xA2805140
35
40
42 {
43 if (bps <= 8)
45 if (bps <= 16)
47 if (bps <= 24)
49 if (bps <= 32)
51
52 /* bigger than 32 isn't allowed */
54 }
55
56 /* returns the size of the found tag */
58 {
60
63
66
67 if (size < 0)
68 size = 0x7fffffff;
69
71 }
72
73 /* Metadata string read */
75 {
77
78 if (str) {
80 if (res < 0){
82 return;
83 }
84 size += (size&1)-res;
87 }else
88 size+= size&1;
89
91 }
92
93 /* Returns the number of sound data frames or negative on error */
96 {
100 int exp;
103 unsigned int num_frames;
104
105 if (size & 1)
106 size++;
111
114 sample_rate = ldexp(val, exp - 16383 - 63);
116 size -= 18;
117
118 /* get codec id for AIFF-C */
122 size -= 4;
123 }
124
129 } else {
137 break;
140 break;
143 break;
147 break;
150 break;
151 default:
153 break;
154 }
158 }
159
160 /* Block align needs to be computed in all cases, as the definition
161 * is specific to applications -> here we use the WAVE format definition */
164
168 }
169
170 /* Chunk is over */
171 if (size)
173
174 return num_frames;
175 }
176
178 {
179 /* check file header */
180 if (p->
buf[0] ==
'F' && p->
buf[1] ==
'O' &&
181 p->
buf[2] ==
'R' && p->
buf[3] ==
'M' &&
182 p->
buf[8] ==
'A' && p->
buf[9] ==
'I' &&
183 p->
buf[10] ==
'F' && (p->
buf[11] ==
'F' || p->
buf[11] ==
'C'))
185 else
186 return 0;
187 }
188
189 /* aiff input */
191 {
193 int64_t
offset = 0, position;
200
201 /* check FORM header */
203 if (filesize < 0 || tag !=
MKTAG(
'F',
'O',
'R',
'M'))
205
206 /* AIFF data type */
208 if (tag ==
MKTAG(
'A',
'I',
'F',
'F'))
/* Got an AIFF file */
210 else if (tag !=
MKTAG(
'A',
'I',
'F',
'C'))
/* An AIFF-C file then */
212
213 filesize -= 4;
214
216 if (!st)
218
219 while (filesize > 0) {
220 /* parse different chunks */
222 if (size < 0)
224
225 filesize -= size + 8;
226
227 switch (tag) {
228 case MKTAG(
'C',
'O',
'M',
'M'):
/* Common chunk */
229 /* Then for the complete header info */
233 if (offset > 0) // COMM is after SSND
234 goto got_sound;
235 break;
236 case MKTAG(
'I',
'D',
'3',
' '):
239 if (id3v2_extra_meta)
243 }
247 break;
248 case MKTAG(
'F',
'V',
'E',
'R'):
/* Version chunk */
250 break;
251 case MKTAG(
'N',
'A',
'M',
'E'):
/* Sample name chunk */
253 break;
254 case MKTAG(
'A',
'U',
'T',
'H'):
/* Author chunk */
256 break;
257 case MKTAG(
'(',
'c',
')',
' '):
/* Copyright chunk */
259 break;
260 case MKTAG(
'A',
'N',
'N',
'O'):
/* Annotation chunk */
262 break;
263 case MKTAG(
'S',
'S',
'N',
'D'):
/* Sampled sound chunk */
265 offset =
avio_rb32(pb);
/* Offset of sound data */
266 avio_rb32(pb);
/* BlockSize... don't care */
267 offset +=
avio_tell(pb);
/* Compute absolute data offset */
269 goto got_sound;
272 return -1;
273 }
275 break;
276 case MKTAG(
'w',
'a',
'v',
'e'):
277 if ((uint64_t)size > (1<<30))
278 return -1;
288 char rate = 0;
289 if (size >= 25)
291 switch (rate) {
292 case 'H': // RATE_HALF
294 break;
295 case 'F': // RATE_FULL
296 default:
298 }
302 }
303 break;
304 case MKTAG(
'C',
'H',
'A',
'N'):
307 break;
308 default: /* Jump */
309 if (size & 1) /* Always even aligned */
310 size++;
312 }
313 }
314
315 got_sound:
318 return -1;
319 }
320
321 /* Now positioned, get the sound data start and end */
325
326 /* Position the stream at the first block */
328
329 return 0;
330 }
331
332 #define MAX_SIZE 4096
333
336 {
339 int64_t max_size;
341
342 /* calculate size of remaining data */
344 if (max_size <= 0)
346
347 /* Now for that packet */
350 else
352 size =
FFMIN(max_size, size);
354 if (res < 0)
356
359 /* Only one stream in an AIFF file */
362 return 0;
363 }
364
374 };