22 #include "libavutil/opt.h"
23 #include "libavutil/avstring.h"
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/dict.h"
26 #include "libavutil/mathematics.h"
33 #define XING_FLAG_FRAMES 0x01
34 #define XING_FLAG_SIZE 0x02
35 #define XING_FLAG_TOC 0x04
37 #define XING_TOC_COUNT 100
54 int max_frames, first_frames = 0;
62 while(buf0 < end && !*buf0)
68 for(; buf <
end; buf= buf2+1) {
71 for(frames = 0; buf2 <
end; frames++) {
78 max_frames =
FFMAX(max_frames, frames);
89 else if(max_frames>=1)
return 1;
98 int fill_index = mp3->
usetoc && duration > 0;
127 static const int64_t
xing_offtbl[2][2] = {{32, 17}, {17,9}};
137 vbrtag_size = c.frame_size;
141 spf = c.lsf ? 576 : 1152;
144 avio_skip(s->
pb, xing_offtbl[c.lsf == 1][c.nb_channels == 1]);
146 is_cbr = v ==
MKBETAG(
'I',
'n',
'f',
'o');
147 if (v ==
MKBETAG(
'X',
'i',
'n',
'g') || is_cbr) {
160 if(v ==
MKBETAG(
'L',
'A',
'M',
'E') || v ==
MKBETAG(
'L',
'a',
'v',
'f')) {
164 mp3-> end_pad = v&4095;
173 if(v ==
MKBETAG(
'V',
'B',
'R',
'I')) {
192 if (size && frames && !is_cbr)
235 #define MP3_PACKET_SIZE 1024
280 return sd.frame_size;
296 if (filesize <= s->data_offset)
301 timestamp = av_clip64(timestamp, 0, duration);
320 for(i=0; i<4096; i++) {
321 int64_t pos = ie->
pos + i*dir;
364 .extensions =
"mp2,mp3,m2a,mpa",
365 .priv_class = &demuxer_class,
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
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
AVCodecContext * codec
Codec context associated with this stream.
void ff_id3v1_read(AVFormatContext *s)
Read an ID3v1 tag.
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
static void read_xing_toc(AVFormatContext *s, int64_t filesize, int64_t duration)
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
int64_t data_offset
offset of the first packet
int64_t maxsize
max filesize, used to limit allocations This field is internal to libavformat and access from outside...
static int check(AVFormatContext *s, int64_t pos)
static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
const char * av_default_item_name(void *ctx)
Return the context name.
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_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
static av_cold int end(AVCodecContext *avctx)
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
enum AVStreamParseType need_parsing
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
static const uint8_t xing_offtbl[2][2]
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
const OptionDef options[]
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const
Rescale a 64-bit integer by 2 rational numbers.
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
void * priv_data
Format private data.
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 skip_samples
Number of samples to skip at the start of the frame decoded from the next packet. ...
int flags
A combination of AV_PKT_FLAG values.
int buf_size
Size of buf except extra allocated bytes.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
int bit_rate
the average bitrate
int64_t av_rescale(int64_t a, int64_t b, int64_t c) av_const
Rescale a 64-bit integer with rounding to nearest.
static int mp3_read_probe(AVProbeData *p)
enum AVMediaType codec_type
main external API structure.
AVIOContext * pb
I/O context.
Describe the class of an AVClass context structure.
rational number numerator/denominator
This structure contains the data a format has to probe a file.
#define MKBETAG(a, b, c, d)
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
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.
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.
int ff_id3v2_tag_len(const uint8_t *buf)
Get the length of an ID3v2 tag.
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
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
This structure stores compressed data.