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;
85 str[res] = 0;
87 }else
88 size+= size&1;
89
91 }
92
93 /* Returns the number of sound data frames or negative on error */
96 {
103 unsigned int num_frames;
104
105 if (size & 1)
106 size++;
111
114 if (exp <-63 || exp >63) {
117 }
118 if (exp >= 0)
119 sample_rate = val <<
exp;
120 else
121 sample_rate = (val + (1ULL<<(-exp-1))) >> -exp;
123 size -= 18;
124
125 /* get codec id for AIFF-C */
126 if (size < 4) {
135 }
136 size -= 4;
137 }
138
143 } else {
151 break;
154 break;
157 break;
165 break;
168 break;
169 default:
171 break;
172 }
176 }
177
178 /* Block align needs to be computed in all cases, as the definition
179 * is specific to applications -> here we use the WAVE format definition */
182
186 }
187
188 /* Chunk is over */
189 if (size)
191
192 return num_frames;
193 }
194
196 {
197 /* check file header */
198 if (p->
buf[0] ==
'F' && p->
buf[1] ==
'O' &&
199 p->
buf[2] ==
'R' && p->
buf[3] ==
'M' &&
200 p->
buf[8] ==
'A' && p->
buf[9] ==
'I' &&
201 p->
buf[10] ==
'F' && (p->
buf[11] ==
'F' || p->
buf[11] ==
'C'))
203 else
204 return 0;
205 }
206
207 /* aiff input */
209 {
210 int ret,
size, filesize;
211 int64_t
offset = 0, position;
218
219 /* check FORM header */
221 if (filesize < 0 || tag !=
MKTAG(
'F',
'O',
'R',
'M'))
223
224 /* AIFF data type */
226 if (tag ==
MKTAG(
'A',
'I',
'F',
'F'))
/* Got an AIFF file */
228 else if (tag !=
MKTAG(
'A',
'I',
'F',
'C'))
/* An AIFF-C file then */
230
231 filesize -= 4;
232
234 if (!st)
236
237 while (filesize > 0) {
238 /* parse different chunks */
240
243 goto got_sound;
244 }
245 if (size < 0)
247
248 filesize -= size + 8;
249
250 switch (tag) {
251 case MKTAG(
'C',
'O',
'M',
'M'):
/* Common chunk */
252 /* Then for the complete header info */
256 if (offset > 0) // COMM is after SSND
257 goto got_sound;
258 break;
259 case MKTAG(
'I',
'D',
'3',
' '):
262 if (id3v2_extra_meta)
265 return ret;
266 }
270 break;
271 case MKTAG(
'F',
'V',
'E',
'R'):
/* Version chunk */
273 break;
274 case MKTAG(
'N',
'A',
'M',
'E'):
/* Sample name chunk */
276 break;
277 case MKTAG(
'A',
'U',
'T',
'H'):
/* Author chunk */
279 break;
280 case MKTAG(
'(',
'c',
')',
' '):
/* Copyright chunk */
282 break;
283 case MKTAG(
'A',
'N',
'N',
'O'):
/* Annotation chunk */
285 break;
286 case MKTAG(
'S',
'S',
'N',
'D'):
/* Sampled sound chunk */
288 offset =
avio_rb32(pb);
/* Offset of sound data */
289 avio_rb32(pb);
/* BlockSize... don't care */
290 offset +=
avio_tell(pb);
/* Compute absolute data offset */
292 goto got_sound;
295 return -1;
296 }
298 break;
299 case MKTAG(
'w',
'a',
'v',
'e'):
300 if ((uint64_t)size > (1<<30))
301 return -1;
308 char rate = 0;
309 if (size >= 25)
311 switch (rate) {
312 case 'H': // RATE_HALF
314 break;
315 case 'F': // RATE_FULL
316 default:
318 }
322 }
323 break;
324 case MKTAG(
'C',
'H',
'A',
'N'):
327 break;
328 case 0:
330 goto got_sound;
331 default: /* Jump */
332 if (size & 1) /* Always even aligned */
333 size++;
335 }
336 }
337
338 got_sound:
341 return -1;
342 }
343
344 /* Now positioned, get the sound data start and end */
348
349 /* Position the stream at the first block */
351
352 return 0;
353 }
354
355 #define MAX_SIZE 4096
356
359 {
362 int64_t max_size;
364
365 /* calculate size of remaining data */
367 if (max_size <= 0)
369
370 /* Now for that packet */
377 break;
378 default:
380 }
381 size =
FFMIN(max_size, size);
383 if (res < 0)
384 return res;
385
388 /* Only one stream in an AIFF file */
391 return 0;
392 }
393
403 };
const char const char void * val
static int get_aiff_header(AVFormatContext *s, int size, unsigned version)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t bit_rate
the average bitrate
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
Put a string representing the codec tag codec_tag in buf.
static int aiff_read_header(AVFormatContext *s)
unsigned int avio_rb16(AVIOContext *s)
int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta **extra_meta)
Create a stream for each APIC (attached picture) extracted from the ID3v2 header. ...
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
unsigned int avio_rb32(AVIOContext *s)
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
static int aiff_read_packet(AVFormatContext *s, AVPacket *pkt)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
AVStream ** streams
A list of all streams in the file.
#define AVERROR_EOF
End of file.
uint64_t avio_rb64(AVIOContext *s)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
AVDictionary * metadata
Metadata that applies to the whole file.
unsigned int avio_rl32(AVIOContext *s)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
Free memory allocated parsing special (non-text) metadata.
static void get_meta(AVFormatContext *s, const char *key, int size)
static enum AVCodecID aiff_codec_get_id(int bps)
static const uint8_t offset[127][2]
int flags
A combination of AV_PKT_FLAG values.
AVCodecContext * codec
Codec context associated with this stream.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
static int aiff_probe(AVProbeData *p)
int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st, int64_t size)
Read 'chan' tag from the input stream.
static int read_header(FFV1Context *f)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
static int get_tag(AVIOContext *pb, uint32_t *tag)
enum AVMediaType codec_type
int sample_rate
samples per second
AVIOContext * pb
I/O context.
main external API structure.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
This structure contains the data a format has to probe a file.
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
Return audio frame duration.
int64_t duration
Decoding: duration of the stream, in stream time base.
AVInputFormat ff_aiff_demuxer
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
static const AVCodecTag ff_codec_aiff_tags[]
void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta, unsigned int max_search_size)
Read an ID3v2 tag, including supported extra metadata and chapters.
int64_t nb_frames
number of frames in this stream if known or 0
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
as in Berlin toast format
int channels
number of audio channels
void * priv_data
Format private data.
common header for AIFF muxer and demuxer
int avio_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
#define MKTAG(a, b, c, d)
This structure stores compressed data.