FFmpeg: libavformat/ape.c Source File
Go to the documentation of this file. 1 /*
2 * Monkey's Audio APE demuxer
3 * Copyright (c) 2007 Benjamin Zores <ben@geexbox.org>
4 * based upon libdemac from Dave Chapman.
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 #include <stdio.h>
24
29
30 /* The earliest and latest file formats supported by this library */
31 #define APE_MIN_VERSION 3800
32 #define APE_MAX_VERSION 3990
33
34 #define MAC_FORMAT_FLAG_8_BIT 1 // is 8-bit [OBSOLETE]
35 #define MAC_FORMAT_FLAG_CRC 2 // uses the new CRC32 error detection [OBSOLETE]
36 #define MAC_FORMAT_FLAG_HAS_PEAK_LEVEL 4 // uint32 nPeakLevel after the header [OBSOLETE]
37 #define MAC_FORMAT_FLAG_24_BIT 8 // is 24-bit [OBSOLETE]
38 #define MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS 16 // has the number of seek elements after the peak level
39 #define MAC_FORMAT_FLAG_CREATE_WAV_HEADER 32 // create the wave header on decompression (not stored)
40
41 #define APE_EXTRADATA_SIZE 6
42
50
52 /* Derived fields */
58
59 /* Info from Descriptor Block */
70
71 /* Info from Header Block */
81
83
85 {
88 return 0;
89
92
94 }
95
97 {
98 #ifdef DEBUG
100
111 for (
i = 0;
i < 16;
i++)
114
116
125
129 }
130
136
141 #endif
142 }
143
145 {
151 int total_blocks, final_size = 0;
152 int64_t
pts, file_size;
153
154 /* Skip any leading junk such as id3v2 tags */
156
158 if (
tag !=
MKTAG(
'M',
'A',
'C',
' '))
160
162
167 }
168
179
180 /* Skip any unknown bytes at the end of the descriptor.
181 This is for future compatibility */
184
185 /* Read header data */
194 } else {
197
206
208 avio_skip(pb, 4);
/* Skip the peak level */
210 }
211
216 } else
218
223 else
225
230 else
232
233 /* Skip any stored wav header */
236 }
237
241 }
246 }
249 "Number of seek entries is less than number of frames: %"SIZE_SPECIFIER " vs. %"PRIu32
"\n",
252 }
260
261
265
271 uint32_t seektable_entry =
avio_rl32(pb);
276
281 }
282 ff_dlog(
s,
"seektable: %8d %"PRIu32
"\n",
i, seektable_entry);
283 }
285
287 /* calculate final packet size from total file size, if available */
289 if (file_size > 0) {
292 final_size -= final_size & 3;
293 }
294 if (file_size <= 0 || final_size <= 0)
297
302 }
304 }
310
318 }
319 }
320 }
321
323
327
328 /* now we are ready: build format streams */
330 if (!st) {
333 }
334
336
343
348
354
360 }
361
362 /* try to read APE tags */
366 }
367
368 return 0;
371
373 }
374
376 {
378 int nblocks;
380 uint32_t extra_size = 8;
381 int64_t ret64;
382
387
389 if (ret64 < 0)
390 return ret64;
391
392 /* Calculate how many blocks there are in this frame */
395 else
397
404 }
405
409
415 }
416
419
420 /* note: we need to modify the packet size here to handle the last
421 packet */
423
425
426 return 0;
427 }
428
430 {
432
434 return 0;
435 }
436
438 {
443
445 return -1;
446
450 return 0;
451 }
452
462 .extensions = "ape,apl,mac",
463 };
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
#define MAC_FORMAT_FLAG_CREATE_WAV_HEADER
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
#define MAC_FORMAT_FLAG_HAS_PEAK_LEVEL
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.
uint32_t finalframeblocks
#define AVERROR_EOF
End of file.
#define MKTAG(a, b, c, d)
#define AV_LOG_VERBOSE
Detailed information.
#define MAC_FORMAT_FLAG_8_BIT
static int ape_probe(const AVProbeData *p)
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
int64_t avio_size(AVIOContext *s)
Get the filesize.
int64_t ff_ape_parse_tag(AVFormatContext *s)
Read and parse an APE tag.
int fileversion
codec version, very important in decoding process
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
static av_cold int read_close(AVFormatContext *ctx)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int64_t duration
Decoding: duration of the stream, in stream time base.
unsigned int avio_rl16(AVIOContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint32_t audiodatalength_high
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
static void ape_dumpinfo(AVFormatContext *s, APEContext *ape_ctx)
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
#define MAC_FORMAT_FLAG_24_BIT
AVCodecParameters * codecpar
Codec parameters associated with this stream.
static int read_header(FFV1Context *f)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
This structure contains the data a format has to probe a file.
int sample_rate
Audio only.
int64_t nb_frames
number of frames in this stream if known or 0
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.
#define APE_EXTRADATA_SIZE
int avio_r8(AVIOContext *s)
static int ape_read_header(AVFormatContext *s)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define av_malloc_array(a, b)
static int ape_read_packet(AVFormatContext *s, AVPacket *pkt)
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.
AVInputFormat ff_ape_demuxer
static int ape_read_close(AVFormatContext *s)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
#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.
int eof_reached
true if was unable to read due to error or eof
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
#define MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS
int bits_per_coded_sample
The number of bits per sample in the codedwords.
static int ape_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
#define flags(name, subs,...)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
uint32_t descriptorlength
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Generated on Wed Aug 24 2022 21:34:39 for FFmpeg by
doxygen
1.8.17