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
32
34 #define AIFF_C_VERSION1 0xA2805140
35
40
42 {
51
52 /* bigger than 32 isn't allowed */
54 }
55
56 /* returns the size of the found tag */
58 {
60
63
66
68 }
69
70 /* Metadata string read */
72 {
74
77
80 if (res < 0){
82 return;
83 }
87 }
88
90 }
91
92 /* Returns the number of sound data frames or negative on error */
95 {
102 unsigned int num_frames;
104
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 filesize,
size;
218 int64_t
offset = 0, position;
225
226 /* check FORM header */
228 if (filesize < 4 ||
tag !=
MKTAG(
'F',
'O',
'R',
'M'))
230
231 /* AIFF data type */
233 if (
tag ==
MKTAG(
'A',
'I',
'F',
'F'))
/* Got an AIFF file */
235 else if (
tag !=
MKTAG(
'A',
'I',
'F',
'C'))
/* An AIFF-C file then */
237
238 filesize -= 4;
239
241 if (!st)
243
244 while (filesize > 0) {
245 /* parse different chunks */
247
250 goto got_sound;
251 }
254
255 filesize -=
size + 8;
256
258 case MKTAG(
'C',
'O',
'M',
'M'):
/* Common chunk */
259 /* Then for the complete header info */
263 if (
offset > 0)
// COMM is after SSND
264 goto got_sound;
265 break;
266 case MKTAG(
'I',
'D',
'3',
' '):
269 if (id3v2_extra_meta)
274 }
278 break;
279 case MKTAG(
'F',
'V',
'E',
'R'):
/* Version chunk */
281 break;
282 case MKTAG(
'N',
'A',
'M',
'E'):
/* Sample name chunk */
284 break;
285 case MKTAG(
'A',
'U',
'T',
'H'):
/* Author chunk */
287 break;
288 case MKTAG(
'(',
'c',
')',
' '):
/* Copyright chunk */
290 break;
291 case MKTAG(
'A',
'N',
'N',
'O'):
/* Annotation chunk */
293 break;
294 case MKTAG(
'S',
'S',
'N',
'D'):
/* Sampled sound chunk */
299 avio_rb32(pb);
/* BlockSize... don't care */
302 goto got_sound;
305 return -1;
306 }
308 break;
309 case MKTAG(
'w',
'a',
'v',
'e'):
310 if ((uint64_t)
size > (1<<30))
319 char rate = 0;
322 switch (rate) {
323 case 'H': // RATE_HALF
325 break;
326 case 'F': // RATE_FULL
327 default:
329 }
333 }
334 break;
335 case MKTAG(
'C',
'H',
'A',
'N'):
338 break;
339 case MKTAG(
'A',
'P',
'C',
'M'):
/* XA ADPCM compressed sound chunk */
343 /* This field is unknown and its data seems to be irrelevant */
346
347 goto got_sound;
348 break;
349 case 0:
351 goto got_sound;
352 default: /* Jump */
354 }
355
356 /* Skip required padding byte for odd-sized chunks. */
358 filesize--;
360 }
361 }
362
366
367 got_sound:
374 }
375
376 /* Now positioned, get the sound data start and end */
380
381 /* Position the stream at the first block */
383
384 return 0;
385 }
386
387 #define MAX_SIZE 4096
388
391 {
394 int64_t max_size;
396
397 /* calculate size of remaining data */
399 if (max_size <= 0)
401
405 }
406
407 /* Now for that packet */
414 break;
415 default:
419 }
422 if (res < 0)
423 return res;
424
427 /* Only one stream in an AIFF file */
430 return 0;
431 }
432
442 };
#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 nb_channels
Number of channels in this layout.
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...
int ff_get_extradata(void *logctx, AVCodecParameters *par, AVIOContext *pb, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0 and f...
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 int aiff_probe(const AVProbeData *p)
AVCodecParameters * codecpar
Codec parameters associated with this stream.
static int read_header(FFV1Context *f)
static int64_t get_tag(AVIOContext *pb, uint32_t *tag)
static int get_aiff_header(AVFormatContext *s, int64_t size, unsigned version)
@ 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.
AVChannelLayout ch_layout
Audio only.
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.
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 void get_meta(AVFormatContext *s, const char *key, int64_t size)
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.
#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:42:12 for FFmpeg by
doxygen
1.8.17