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
36
40 int64_t
num_bytes;
///< total number of bytes in stream
41
44
48
50 {
53 return 0;
54 }
55
56 /** Read audio description chunk */
58 {
63
64 /* new audio stream */
66 if (!st)
68
69 /* parse format description */
79
80 /* calculate bit rate for constant size packets */
84 } else {
86 }
87
88 /* determine codec */
91 else
93 return 0;
94 }
95
96 /** Read magic cookie chunk */
98 {
101
103 return -1;
104
106 /* The magic cookie format for AAC is an mp4 esds atom.
107 The lavc AAC decoder requires the data from the codec specific
108 description as extradata input. */
109 int strt, skip;
111
115 if (skip < 0 || !st->codec->extradata ||
119 }
122 #define ALAC_PREAMBLE 12
123 #define ALAC_HEADER 36
124 #define ALAC_NEW_KUKI 24
130 }
132
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 }
158 } else {
164 }
165
166 return 0;
167 }
168
169 /** Read packet table chunk */
171 {
175 int64_t pos = 0, ccount, num_packets;
176 int i;
177
179
181 if (num_packets < 0 || INT32_MAX /
sizeof(
AVIndexEntry) < num_packets)
183
187
189 for (i = 0; i < num_packets; i++) {
193 }
194
198 }
200
202 return 0;
203 }
204
205 /** Read information chunk */
207 {
209 unsigned int i;
211 for (i = 0; i < nb_entries; i++) {
212 char key[32];
217 }
218 }
219
221 {
228
229 avio_skip(pb, 8);
/* magic, version, file flags */
230
231 /* audio description chunk */
235 }
237 if (size != 32)
239
241 if (ret)
244
245 /* parse each chunk */
246 found_data = 0;
248
249 /* stop at data chunk if seeking is not supported or
250 data chunk size is unknown */
252 break;
253
258 break;
259
260 switch (tag) {
264 caf->
data_size = size < 0 ? -1 : size - 4;
267 found_data = 1;
268 break;
269
273 break;
274
275 /* magic cookie chunk */
279 break;
280
281 /* packet table chunk */
285 break;
286
289 break;
290
291 default:
292 #define _(x) ((x) >= ' ' ? (x) : ' ')
294 tag,
_(tag>>24),
_((tag>>16)&0xFF),
_((tag>>8)&0xFF),
_(tag&0xFF), size);
295 #undef _
297 if (size < 0)
299 break;
300 }
301
302 if (size > 0) {
303 if (pos > INT64_MAX - size)
306 }
307 }
308
309 if (!found_data)
311
318 } else {
320 "block size or frame size are variable.\n");
322 }
323
326
327 /* position the stream at the start of data */
330
331 return 0;
332 }
333
334 #define CAF_MAX_PKT_SIZE 4096
335
337 {
341 int res, pkt_size = 0, pkt_frames = 0;
343
346
347 /* don't read past end of data chunk */
350 if (!left)
352 if (left < 0)
354 }
355
358
359 if (pkt_size > 0 && pkt_frames == 1) {
361 pkt_size =
FFMIN(pkt_size, left);
370 } else {
372 }
373 }
374
375 if (pkt_size == 0 || pkt_frames == 0 || pkt_size > left)
377
379 if (res < 0)
381
385
388
389 return 0;
390 }
391
393 int64_t timestamp,
int flags)
394 {
397 int64_t pos, packet_cnt, frame_cnt;
398
399 timestamp =
FFMAX(timestamp, 0);
400
402 /* calculate new byte position based on target frame position */
412 } else {
413 return -1;
414 }
415
417 return -1;
418
421
422 return 0;
423 }
424
434 };