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))
66 int max_frames, first_frames = 0;
73 while(buf0 < end && !*buf0)
79 for(; buf <
end; buf= buf2+1) {
81 for(frames = 0; buf2 <
end; frames++) {
90 max_frames =
FFMAX(max_frames, frames);
101 else if(max_frames>=1 && max_frames >= p->
buf_size/10000)
return 1;
111 int fill_index = (mp3->
usetoc || fast_seek) && duration > 0;
134 #define LAST_BITS(k, n) ((k) & ((1 << (n)) - 1))
135 #define MIDDLE_BITS(k, m, n) LAST_BITS((k) >> (m), ((n) - (m)))
143 int32_t r_gain = INT32_MIN, a_gain = INT32_MIN;
146 static const int64_t
xing_offtbl[2][2] = {{32, 17}, {17,9}};
151 avio_skip(s->
pb, xing_offtbl[c->lsf == 1][c->nb_channels == 1]);
169 "invalid concatenated file detected - using bitrate for duration\n");
170 }
else if (delta > min >> 4) {
172 "filesize and duration do not match (growing file?)\n");
230 mp3->start_pad = v>>12;
231 mp3-> end_pad = v&4095;
232 st->start_skip_samples = mp3->start_pad + 528 + 1;
234 st->first_discard_sample = -mp3->end_pad + 528 + 1 + mp3->frames * (int64_t)spf;
235 st->last_discard_sample = mp3->frames * (int64_t)spf;
277 if (v ==
MKBETAG(
'V',
'B',
'R',
'I')) {
307 vbrtag_size = c.frame_size;
311 spf = c.lsf ? 576 : 1152;
328 if (mp3->header_filesize && mp3->frames && !mp3->is_cbr)
329 st->codec->bit_rate =
av_rescale(mp3->header_filesize, 8 *
c.sample_rate, mp3->frames * (int64_t)spf);
371 for (i = 0; i < 64 * 1024; i++) {
376 frame_size =
check(s->
pb, off + i, &header);
377 if (frame_size > 0) {
380 if (
check(s->
pb, off + i + frame_size, &header2) >= 0 &&
399 #define MP3_PACKET_SIZE 1024
425 #define SEEK_WINDOW 4096
429 int64_t ret =
avio_seek(pb, pos, SEEK_SET);
443 return sd.frame_size;
450 int best_score, i, j;
459 best_pos = target_pos;
462 int64_t pos = target_pos + (dir > 0 ? i - SEEK_WINDOW/4 : -i);
463 int64_t candidate = -1;
473 if ((target_pos - pos)*dir <= 0 && abs(MIN_VALID/2-j) < score) {
475 score = abs(MIN_VALID/2-j);
479 if (best_score > score && j == MIN_VALID) {
480 best_pos = candidate;
517 }
else if (fast_seek && st->
duration > 0 && filesize > 0) {
522 timestamp = av_clip64(timestamp, 0, st->
duration);
564 .extensions =
"mp2,mp3,m2a,mpa",
565 .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
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.
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.
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.
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.
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
int flags
A combination of AV_PKT_FLAG values.
int avio_r8(AVIOContext *s)
AVCodecContext * codec
Codec context associated with this stream.
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)
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 AV_LOG_INFO
Standard information.
Libavcodec external API header.
enum AVMediaType codec_type
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 numerator/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.
This structure stores compressed data.