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
69 int max_frames, first_frames = 0;
72 int framesizes, max_framesizes;
74 const uint8_t *buf, *buf0, *buf2, *buf3, *end;
78 while (buf0 < end && !*buf0)
85 for (; buf < end; buf = buf2+1) {
97 available =
FFMIN(
h.frame_size, end - buf2);
98 for (buf3 = buf2 + 4; buf3 < buf2 + available; buf3++) {
99 uint32_t next_sync =
AV_RB32(buf3);
104 framesizes +=
h.frame_size;
105 if (available <
h.frame_size) {
109 buf2 +=
h.frame_size;
112 max_framesizes =
FFMAX(max_framesizes, framesizes);
115 if (buf2 == end +
sizeof(uint32_t))
126 else if (first_frames > 1 && whole_used)
return 5;
127 else if (max_frames>=1 && p->
buf_size < 10*max_framesizes)
return 1;
160 #define LAST_BITS(k, n) ((k) & ((1 << (n)) - 1))
161 #define MIDDLE_BITS(k, m, n) LAST_BITS((k) >> (m), ((n) - (m) + 1))
169 int32_t r_gain = INT32_MIN, a_gain = INT32_MIN;
172 static const int64_t
xing_offtbl[2][2] = {{32, 17}, {17,9}};
195 "invalid concatenated file detected - using bitrate for duration\n");
198 "filesize and duration do not match (growing file?)\n");
257 mp3-> end_pad = v&4095;
303 if (v ==
MKBETAG(
'V',
'B',
'R',
'I')) {
333 vbrtag_size =
c.frame_size;
337 spf =
c.lsf ? 576 : 1152;
368 s->metadata =
s->internal->id3v2_meta;
369 s->internal->id3v2_meta =
NULL;
400 for (
i = 0;
i < 64 * 1024;
i++) {
441 #define MP3_PACKET_SIZE 1024
467 #define SEEK_WINDOW 4096
491 return sd.frame_size;
498 int best_score,
i, j;
507 best_pos = target_pos;
511 int64_t candidate = -1;
533 if (best_score > score && j ==
MIN_VALID) {
534 best_pos = candidate;
556 if (
size > 0 &&
size >
s->internal->data_offset)
557 filesize =
size -
s->internal->data_offset;
571 }
else if (fast_seek && st->
duration > 0 && filesize > 0) {
618 .extensions =
"mp2,mp3,m2a,mpa",
static int64_t fsize(FILE *f)
Libavcodec external API header.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
int64_t avio_size(AVIOContext *s)
Get the filesize.
unsigned int avio_rb16(AVIOContext *s)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
unsigned int avio_rb24(AVIOContext *s)
unsigned int avio_rb32(AVIOContext *s)
int avio_r8(AVIOContext *s)
void ffio_init_checksum(AVIOContext *s, unsigned long(*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum)
unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
unsigned long ffio_get_checksum(AVIOContext *s)
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
#define flags(name, subs,...)
#define MKBETAG(a, b, c, d)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Public header for CRC hash function implementation.
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
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.
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
#define AVERROR_EOF
End of file.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define LIBAVUTIL_VERSION_INT
void ff_id3v1_read(AVFormatContext *s)
Read an ID3v1 tag.
int ff_id3v2_tag_len(const uint8_t *buf)
Get the length of an ID3v2 tag.
int ff_id3v2_match(const uint8_t *buf, const char *magic)
Detect ID3v2 Header.
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
@ AV_CLASS_CATEGORY_DEMUXER
static int mp3_read_header(AVFormatContext *s)
static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
static const AVOption options[]
static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st, MPADecodeHeader *c, uint32_t spf)
static int check(AVIOContext *pb, int64_t pos, uint32_t *header)
static int64_t mp3_sync(AVFormatContext *s, int64_t target_pos, int flags)
static void mp3_parse_vbri_tag(AVFormatContext *s, AVStream *st, int64_t base)
#define MIDDLE_BITS(k, m, n)
static const AVClass demuxer_class
AVInputFormat ff_mp3_demuxer
static void read_xing_toc(AVFormatContext *s, int64_t filesize, int64_t duration)
static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
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.
static int mp3_read_probe(const AVProbeData *p)
static const uint8_t xing_offtbl[2][2]
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
int ff_replaygain_export(AVStream *st, AVDictionary *metadata)
Parse replaygain tags and export them as per-stream side data.
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.
static const uint8_t header[24]
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
enum AVMediaType codec_type
General type of the encoded data.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int64_t timestamp
Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are...
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
This structure contains the data a format has to probe a file.
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.
Rational number (pair of numerator and denominator).
int64_t first_discard_sample
If not 0, the first audio sample that should be discarded from the stream.
int64_t start_skip_samples
If not 0, the number of samples that should be skipped from the start of the stream (the samples are ...
int64_t last_discard_sample
The sample after last sample that is intended to be discarded after first_discard_sample.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int64_t duration
Decoding: duration of the stream, in stream time base.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
enum AVStreamParseType need_parsing
AVStreamInternal * internal
An opaque field for libavformat internal usage.