38 #define XING_FLAG_FRAMES 0x01
39 #define XING_FLAG_SIZE 0x02
40 #define XING_FLAG_TOC 0x04
41 #define XING_FLAC_QSCALE 0x08
43 #define XING_TOC_COUNT 100
45 #define SAME_HEADER_MASK \
46 (0xffe00000 | (3 << 17) | (3 << 10) | (3 << 19))
71 int max_frames, first_frames = 0;
79 while(buf0 < end && !*buf0)
85 for(; buf <
end; buf= buf2+1) {
87 for(frames = 0; buf2 <
end; frames++) {
96 max_frames =
FFMAX(max_frames, frames);
99 if (buf2 == end +
sizeof(uint32_t))
110 else if(first_frames > 1 && whole_used)
return 5;
111 else if(max_frames>=1 && max_frames >= p->
buf_size/10000)
return 1;
121 int fill_index = (mp3->
usetoc || fast_seek) && duration > 0;
144 #define LAST_BITS(k, n) ((k) & ((1 << (n)) - 1))
145 #define MIDDLE_BITS(k, m, n) LAST_BITS((k) >> (m), ((n) - (m) + 1))
153 int32_t r_gain = INT32_MIN, a_gain = INT32_MIN;
156 static const int64_t
xing_offtbl[2][2] = {{32, 17}, {17,9}};
161 avio_skip(s->
pb, xing_offtbl[c->lsf == 1][c->nb_channels == 1]);
179 "invalid concatenated file detected - using bitrate for duration\n");
180 }
else if (delta > min >> 4) {
182 "filesize and duration do not match (growing file?)\n");
240 mp3->start_pad = v>>12;
241 mp3-> end_pad = v&4095;
242 st->start_skip_samples = mp3->start_pad + 528 + 1;
244 st->first_discard_sample = -mp3->end_pad + 528 + 1 + mp3->frames * (int64_t)spf;
245 st->last_discard_sample = mp3->frames * (int64_t)spf;
287 if (v ==
MKBETAG(
'V',
'B',
'R',
'I')) {
317 vbrtag_size = c.frame_size;
321 spf = c.lsf ? 576 : 1152;
338 if (mp3->header_filesize && mp3->frames && !mp3->is_cbr)
339 st->codecpar->bit_rate =
av_rescale(mp3->header_filesize, 8 *
c.sample_rate, mp3->frames * (int64_t)spf);
384 for (i = 0; i < 64 * 1024; i++) {
389 frame_size =
check(s->
pb, off + i, &header);
390 if (frame_size > 0) {
395 ret =
check(s->
pb, off + i + frame_size, &header2);
405 av_log(s,
AV_LOG_ERROR,
"Invalid frame size (%d): Could not seek to %"PRId64
".\n", frame_size, off + i + frame_size);
409 av_log(s,
AV_LOG_ERROR,
"Failed to read frame size: Could not seek to %"PRId64
".\n", (int64_t) (i + 1024 + frame_size + 4));
425 #define MP3_PACKET_SIZE 1024
451 #define SEEK_WINDOW 4096
455 int64_t ret =
avio_seek(pb, pos, SEEK_SET);
467 header =
AV_RB32(&header_buf[0]);
475 return sd.frame_size;
482 int best_score, i, j;
491 best_pos = target_pos;
494 int64_t pos = target_pos + (dir > 0 ? i - SEEK_WINDOW/4 : -i);
495 int64_t candidate = -1;
511 if ((target_pos - pos)*dir <= 0 &&
FFABS(MIN_VALID/2-j) < score) {
513 score =
FFABS(MIN_VALID/2-j);
517 if (best_score > score && j == MIN_VALID) {
518 best_pos = candidate;
555 }
else if (fast_seek && st->
duration > 0 && filesize > 0) {
560 timestamp = av_clip64(timestamp, 0, st->
duration);
602 .extensions =
"mp2,mp3,m2a,mpa",
603 .priv_class = &demuxer_class,
int64_t avio_size(AVIOContext *s)
Get the filesize.
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.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
void ff_id3v1_read(AVFormatContext *s)
Read an ID3v1 tag.
#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.
const char * av_default_item_name(void *ptr)
Return the context name.
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
static void read_xing_toc(AVFormatContext *s, int64_t filesize, int64_t duration)
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
unsigned int avio_rb16(AVIOContext *s)
int64_t maxsize
max filesize, used to limit allocations This field is internal to libavformat and access from outside...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
unsigned int avio_rb32(AVIOContext *s)
static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
static av_cold int end(AVCodecContext *avctx)
enum AVStreamParseType need_parsing
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
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.
Public header for CRC hash function implementation.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int flags
Flags modifying the (de)muxer behaviour.
static const uint8_t xing_offtbl[2][2]
#define AVERROR_EOF
End of file.
#define AV_LOG_VERBOSE
Detailed information.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
static const uint8_t header[24]
int ff_replaygain_export(AVStream *st, AVDictionary *metadata)
Parse replaygain tags and export them as per-stream side data.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVDictionary * metadata
Metadata that applies to the whole file.
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
int64_t timestamp
Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int mp3_read_header(AVFormatContext *s)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
preferred ID for decoding MPEG audio layer 1, 2 or 3
enum AVMediaType codec_type
General type of the encoded data.
int flags
A combination of AV_PKT_FLAG values.
int avio_r8(AVIOContext *s)
int buf_size
Size of buf except extra allocated bytes.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
void ffio_init_checksum(AVIOContext *s, unsigned long(*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum)
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
unsigned int avio_rb24(AVIOContext *s)
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
static int check(AVIOContext *pb, int64_t pos, uint32_t *header)
static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st, MPADecodeHeader *c, uint32_t spf)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static int64_t mp3_sync(AVFormatContext *s, int64_t target_pos, int flags)
unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
static void mp3_parse_vbri_tag(AVFormatContext *s, AVStream *st, int64_t base)
static int mp3_read_probe(AVProbeData *p)
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
#define AV_LOG_INFO
Standard information.
Libavcodec external API header.
AVIOContext * pb
I/O context.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Describe the class of an AVClass context structure.
static const AVOption options[]
Rational number (pair of numerator and denominator).
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
unsigned long ffio_get_checksum(AVIOContext *s)
This structure contains the data a format has to probe a file.
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
int64_t duration
Decoding: duration of the stream, in stream time base.
static const AVClass demuxer_class
int ff_id3v2_match(const uint8_t *buf, const char *magic)
Detect ID3v2 Header.
int ff_replaygain_export_raw(AVStream *st, int32_t tg, uint32_t tp, int32_t ag, uint32_t ap)
Export already decoded replaygain values as per-stream side data.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
AVInputFormat ff_mp3_demuxer
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
#define MKBETAG(a, b, c, d)
#define MIDDLE_BITS(k, m, n)
int ff_id3v2_tag_len(const uint8_t *buf)
Get the length of an ID3v2 tag.
void * priv_data
Format private data.
static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
Try to find Xing/Info/VBRI tags and compute duration from info therein.
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key, ignoring the suffix of the found key string.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
static int64_t fsize(FILE *f)
This structure stores compressed data.