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;
149 break;
152 break;
153 default:
155 break;
156 }
160 }
161
162 /* Block align needs to be computed in all cases, as the definition
163 * is specific to applications -> here we use the WAVE format definition */
166
170 }
171
172 /* Chunk is over */
173 if (size)
175
176 return num_frames;
177 }
178
180 {
181 /* check file header */
182 if (p->
buf[0] ==
'F' && p->
buf[1] ==
'O' &&
183 p->
buf[2] ==
'R' && p->
buf[3] ==
'M' &&
184 p->
buf[8] ==
'A' && p->
buf[9] ==
'I' &&
185 p->
buf[10] ==
'F' && (p->
buf[11] ==
'F' || p->
buf[11] ==
'C'))
187 else
188 return 0;
189 }
190
191 /* aiff input */
193 {
195 int64_t
offset = 0, position;
202
203 /* check FORM header */
205 if (filesize < 0 || tag !=
MKTAG(
'F',
'O',
'R',
'M'))
207
208 /* AIFF data type */
210 if (tag ==
MKTAG(
'A',
'I',
'F',
'F'))
/* Got an AIFF file */
212 else if (tag !=
MKTAG(
'A',
'I',
'F',
'C'))
/* An AIFF-C file then */
214
215 filesize -= 4;
216
218 if (!st)
220
221 while (filesize > 0) {
222 /* parse different chunks */
224 if (size < 0)
226
227 filesize -= size + 8;
228
229 switch (tag) {
230 case MKTAG(
'C',
'O',
'M',
'M'):
/* Common chunk */
231 /* Then for the complete header info */
235 if (offset > 0) // COMM is after SSND
236 goto got_sound;
237 break;
238 case MKTAG(
'I',
'D',
'3',
' '):
241 if (id3v2_extra_meta)
245 }
249 break;
250 case MKTAG(
'F',
'V',
'E',
'R'):
/* Version chunk */
252 break;
253 case MKTAG(
'N',
'A',
'M',
'E'):
/* Sample name chunk */
255 break;
256 case MKTAG(
'A',
'U',
'T',
'H'):
/* Author chunk */
258 break;
259 case MKTAG(
'(',
'c',
')',
' '):
/* Copyright chunk */
261 break;
262 case MKTAG(
'A',
'N',
'N',
'O'):
/* Annotation chunk */
264 break;
265 case MKTAG(
'S',
'S',
'N',
'D'):
/* Sampled sound chunk */
267 offset =
avio_rb32(pb);
/* Offset of sound data */
268 avio_rb32(pb);
/* BlockSize... don't care */
269 offset +=
avio_tell(pb);
/* Compute absolute data offset */
271 goto got_sound;
274 return -1;
275 }
277 break;
278 case MKTAG(
'w',
'a',
'v',
'e'):
279 if ((uint64_t)size > (1<<30))
280 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 };