1 /*
2 * Core Audio Format demuxer
3 * Copyright (c) 2007 Justin Ruggles
4 * Copyright (c) 2009 Peter Ross
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * Core Audio Format demuxer
26 */
27
28 #include <inttypes.h>
29
38
42 int64_t
num_bytes;
///< total number of bytes in stream
43
46
50
52 {
55 return 0;
56 }
57
58 /** Read audio description chunk */
60 {
65
66 /* new audio stream */
68 if (!st)
70
71 /* parse format description */
81
82 /* calculate bit rate for constant size packets */
86 } else {
88 }
89
90 /* determine codec */
93 else
95 return 0;
96 }
97
98 /** Read magic cookie chunk */
100 {
103
105 return -1;
106
108 /* The magic cookie format for AAC is an mp4 esds atom.
109 The lavc AAC decoder requires the data from the codec specific
110 description as extradata input. */
111 int strt, skip;
112
116 if (skip < 0 || !st->codec->extradata ||
120 }
123 #define ALAC_PREAMBLE 12
124 #define ALAC_HEADER 36
125 #define ALAC_NEW_KUKI 24
131 }
133
136
137 /* For the old style cookie, we skip 12 bytes, then read 36 bytes.
138 * The new style cookie only contains the last 24 bytes of what was
139 * 36 bytes in the old style cookie, so we fabricate the first 12 bytes
140 * in that case to maintain compatibility. */
141 if (!memcmp(&preamble[4], "frmaalac", 8)) {
146 }
149 } else {
156 }
157 } else {
160 }
161
162 return 0;
163 }
164
165 /** Read packet table chunk */
167 {
171 int64_t pos = 0, ccount, num_packets;
172 int i;
173
175
177 if (num_packets < 0 || INT32_MAX /
sizeof(
AVIndexEntry) < num_packets)
179
183
185 for (i = 0; i < num_packets; i++) {
189 }
190
194 }
196
198 return 0;
199 }
200
201 /** Read information chunk */
203 {
205 unsigned int i;
207 for (i = 0; i < nb_entries && !
avio_feof(pb); i++) {
208 char key[32];
213 }
214 }
215
217 {
224
225 avio_skip(pb, 8);
/* magic, version, file flags */
226
227 /* audio description chunk */
231 }
233 if (size != 32)
235
237 if (ret)
240
241 /* parse each chunk */
242 found_data = 0;
244
245 /* stop at data chunk if seeking is not supported or
246 data chunk size is unknown */
248 break;
249
254 break;
255
256 switch (tag) {
260 caf->
data_size = size < 0 ? -1 : size - 4;
263 found_data = 1;
264 break;
265
269 break;
270
271 /* magic cookie chunk */
275 break;
276
277 /* packet table chunk */
281 break;
282
285 break;
286
287 default:
288 #define _(x) ((x) >= ' ' ? (x) : ' ')
290 "skipping CAF chunk: %08"PRIX32" (%c%c%c%c), size %"PRId64"\n",
291 tag,
_(tag>>24),
_((tag>>16)&0xFF),
_((tag>>8)&0xFF),
_(tag&0xFF), size);
292 #undef _
294 if (size < 0)
296 break;
297 }
298
299 if (size > 0) {
300 if (pos > INT64_MAX - size)
303 }
304 }
305
306 if (!found_data)
308
315 } else {
317 "block size or frame size are variable.\n");
319 }
320
323
324 /* position the stream at the start of data */
327
328 return 0;
329 }
330
331 #define CAF_MAX_PKT_SIZE 4096
332
334 {
338 int res, pkt_size = 0, pkt_frames = 0;
340
343
344 /* don't read past end of data chunk */
347 if (!left)
349 if (left < 0)
351 }
352
355
356 if (pkt_size > 0 && pkt_frames == 1) {
358 pkt_size =
FFMIN(pkt_size, left);
367 } else {
369 }
370 }
371
372 if (pkt_size == 0 || pkt_frames == 0 || pkt_size > left)
374
376 if (res < 0)
377 return res;
378
382
385
386 return 0;
387 }
388
390 int64_t timestamp,
int flags)
391 {
394 int64_t pos, packet_cnt, frame_cnt;
395
396 timestamp =
FFMAX(timestamp, 0);
397
399 /* calculate new byte position based on target frame position */
409 } else {
410 return -1;
411 }
412
414 return -1;
415
418
419 return 0;
420 }
421
431 };