FFmpeg: libavformat/aiffdec.c Source File
Go to the documentation of this file. 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
31
33 #define AIFF_C_VERSION1 0xA2805140
34
39
41 {
50
51 /* bigger than 32 isn't allowed */
53 }
54
55 /* returns the size of the found tag */
57 {
59
62
65
68
70 }
71
72 /* Metadata string read */
74 {
76
79 if (res < 0){
81 return;
82 }
86 }
87
89 }
90
91 /* Returns the number of sound data frames or negative on error */
94 {
101 unsigned int num_frames;
102
105
112
115 if (exp <-63 || exp >63) {
118 }
121 else
125
130
131 /* get codec id for AIFF-C */
141 }
142
147 } else {
155 break;
158 break;
161 break;
169 break;
172 break;
173 default:
175 break;
176 }
180 }
181
182 /* Block align needs to be computed in all cases, as the definition
183 * is specific to applications -> here we use the WAVE format definition */
186
192 }
193
194 /* Chunk is over */
197
198 return num_frames;
199 }
200
202 {
203 /* check file header */
204 if (p->
buf[0] ==
'F' && p->
buf[1] ==
'O' &&
205 p->
buf[2] ==
'R' && p->
buf[3] ==
'M' &&
206 p->
buf[8] ==
'A' && p->
buf[9] ==
'I' &&
207 p->
buf[10] ==
'F' && (p->
buf[11] ==
'F' || p->
buf[11] ==
'C'))
209 else
210 return 0;
211 }
212
213 /* aiff input */
215 {
217 int64_t
offset = 0, position;
224
225 /* check FORM header */
227 if (filesize < 0 ||
tag !=
MKTAG(
'F',
'O',
'R',
'M'))
229
230 /* AIFF data type */
232 if (
tag ==
MKTAG(
'A',
'I',
'F',
'F'))
/* Got an AIFF file */
234 else if (
tag !=
MKTAG(
'A',
'I',
'F',
'C'))
/* An AIFF-C file then */
236
237 filesize -= 4;
238
240 if (!st)
242
243 while (filesize > 0) {
244 /* parse different chunks */
246
249 goto got_sound;
250 }
253
254 if (
size >= 0x7fffffff - 8)
255 filesize = 0;
256 else
257 filesize -=
size + 8;
258
260 case MKTAG(
'C',
'O',
'M',
'M'):
/* Common chunk */
261 /* Then for the complete header info */
265 if (
offset > 0)
// COMM is after SSND
266 goto got_sound;
267 break;
268 case MKTAG(
'I',
'D',
'3',
' '):
271 if (id3v2_extra_meta)
276 }
280 break;
281 case MKTAG(
'F',
'V',
'E',
'R'):
/* Version chunk */
283 break;
284 case MKTAG(
'N',
'A',
'M',
'E'):
/* Sample name chunk */
286 break;
287 case MKTAG(
'A',
'U',
'T',
'H'):
/* Author chunk */
289 break;
290 case MKTAG(
'(',
'c',
')',
' '):
/* Copyright chunk */
292 break;
293 case MKTAG(
'A',
'N',
'N',
'O'):
/* Annotation chunk */
295 break;
296 case MKTAG(
'S',
'S',
'N',
'D'):
/* Sampled sound chunk */
301 avio_rb32(pb);
/* BlockSize... don't care */
304 goto got_sound;
307 return -1;
308 }
310 break;
311 case MKTAG(
'w',
'a',
'v',
'e'):
312 if ((uint64_t)
size > (1<<30))
321 char rate = 0;
324 switch (rate) {
325 case 'H': // RATE_HALF
327 break;
328 case 'F': // RATE_FULL
329 default:
331 }
335 }
336 break;
337 case MKTAG(
'C',
'H',
'A',
'N'):
340 break;
341 case MKTAG(
'A',
'P',
'C',
'M'):
/* XA ADPCM compressed sound chunk */
345 /* This field is unknown and its data seems to be irrelevant */
348
349 goto got_sound;
350 break;
351 case 0:
353 goto got_sound;
354 default: /* Jump */
356 }
357
358 /* Skip required padding byte for odd-sized chunks. */
360 filesize--;
362 }
363 }
364
368
369 got_sound:
376 }
377
378 /* Now positioned, get the sound data start and end */
382
383 /* Position the stream at the first block */
385
386 return 0;
387 }
388
389 #define MAX_SIZE 4096
390
393 {
396 int64_t max_size;
398
399 /* calculate size of remaining data */
401 if (max_size <= 0)
403
407 }
408
409 /* Now for that packet */
416 break;
417 default:
421 }
424 if (res < 0)
425 return res;
426
429 /* Only one stream in an AIFF file */
432 return 0;
433 }
434
444 };
#define AV_LOG_WARNING
Something somehow does not look correct.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
@ AV_CODEC_ID_ADPCM_IMA_QT
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
enum AVMediaType codec_type
General type of the encoded data.
This struct describes the properties of an encoded stream.
int ff_replaygain_export(AVStream *st, AVDictionary *metadata)
Parse replaygain tags and export them as per-stream side data.
#define AVERROR_EOF
End of file.
static int aiff_read_packet(AVFormatContext *s, AVPacket *pkt)
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.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
This function is the same as av_get_audio_frame_duration(), except it works with AVCodecParameters in...
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
static double val(void *priv, double ch)
int64_t duration
Decoding: duration of the stream, in stream time base.
int ff_id3v2_parse_chapters(AVFormatContext *s, ID3v2ExtraMeta *cur)
Create chapters for all CHAP tags found in the ID3v2 header.
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
unsigned int avio_rb32(AVIOContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
const AVCodecTag ff_codec_aiff_tags[]
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
static void get_meta(AVFormatContext *s, const char *key, int size)
static int aiff_probe(const AVProbeData *p)
AVCodecParameters * codecpar
Codec parameters associated with this stream.
static int read_header(FFV1Context *f)
@ AV_CODEC_ID_ADPCM_IMA_WS
int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta *extra_meta)
Create a stream for each APIC (attached picture) extracted from the ID3v2 header.
uint64_t avio_rb64(AVIOContext *s)
This structure contains the data a format has to probe a file.
int sample_rate
Audio only.
@ AV_CODEC_ID_GSM
as in Berlin toast format
int64_t nb_frames
number of frames in this stream if known or 0
AVCodecID
Identify the syntax and semantics of the bitstream.
unsigned int avio_rl32(AVIOContext *s)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
const AVInputFormat ff_aiff_demuxer
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
static enum AVCodecID aiff_codec_get_id(int bps)
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
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
int flags
A combination of AV_PKT_FLAG values.
static int get_tag(AVIOContext *pb, uint32_t *tag)
int block_align
Audio only.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
unsigned int avio_rb16(AVIOContext *s)
@ AV_CODEC_ID_ADPCM_G726LE
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
int bits_per_coded_sample
The number of bits per sample in the codedwords.
#define avpriv_request_sample(...)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
const AVCodecTag *const ff_aiff_codec_tags_list[]
This structure stores compressed data.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
Free memory allocated parsing special (non-text) metadata.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define MKTAG(a, b, c, d)
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
static int get_aiff_header(AVFormatContext *s, int size, unsigned version)
#define av_fourcc2str(fourcc)
int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st, int64_t size)
Read 'chan' tag from the input stream.
static int aiff_read_header(AVFormatContext *s)
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Generated on Wed Aug 24 2022 21:38:19 for FFmpeg by
doxygen
1.8.17