40#define XING_FLAG_FRAMES 0x01
41#define XING_FLAG_SIZE 0x02
42#define XING_FLAG_TOC 0x04
43#define XING_FLAC_QSCALE 0x08
45#define XING_TOC_COUNT 100
72 int max_frames, first_frames = 0;
75 int framesizes, max_framesizes;
77 const uint8_t *buf, *buf0, *buf2, *buf3, *end;
80 end = p->buf + p->buf_size -
sizeof(uint32_t);
81 while (buf0 < end && !*buf0)
88 for (; buf < end; buf = buf2+1) {
100 available =
FFMIN(
h.frame_size, end - buf2);
101 for (buf3 = buf2 + 4; buf3 < buf2 + available; buf3++) {
102 uint32_t next_sync =
AV_RB32(buf3);
107 framesizes +=
h.frame_size;
108 if (available <
h.frame_size) {
112 buf2 +=
h.frame_size;
115 max_framesizes =
FFMAX(max_framesizes, framesizes);
118 if (buf2 == end +
sizeof(uint32_t))
129 else if (first_frames > 1 && whole_used)
return 5;
130 else if (max_frames>=1 && p->buf_size < 10*max_framesizes)
return 1;
164#define LAST_BITS(k, n) ((k) & ((1 << (n)) - 1))
165#define MIDDLE_BITS(k, m, n) LAST_BITS((k) >> (m), ((n) - (m) + 1))
174 int32_t r_gain = INT32_MIN, a_gain = INT32_MIN;
201 "invalid concatenated file detected - using bitrate for duration\n");
204 "filesize and duration do not match (growing file?)\n");
263 mp3-> end_pad = v&4095;
305 if (v ==
MKBETAG(
'V',
'B',
'R',
'I')) {
327 static const char comment[] =
"comment-iTunSMPB";
331 const char *lang = de->
key +
sizeof(
comment) - 1;
334 if (!*lang || (*lang ==
'-' && strlen(lang + 1) == 3))
351 int64_t priming, remainder, samples;
363 if (priming > 16384 || !samples)
399 vbrtag_size =
c.frame_size;
403 spf =
c.lsf ? 576 : 1152;
414 if (
ffstream(st)->start_skip_samples)
436 full_duration_samples);
489 for (
i = 0;
i < 64 * 1024;
i++) {
502 if (
i == 64 * 1024) {
519#define MP3_PACKET_SIZE 1024
540 pkt->stream_index = 0;
545#define SEEK_WINDOW 4096
550 uint8_t header_buf[4];
569 return sd.frame_size;
576 int best_score,
i, j;
585 best_pos = target_pos;
611 if (best_score > score && j ==
MIN_VALID) {
612 best_pos = candidate;
692 .p.extensions =
"mp2,mp3,m2a,mpa",
694 .p.mime_type =
"audio/mpeg",
static const AVClass demuxer_class
static int64_t fsize(FILE *f)
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)
static av_always_inline FFIOContext * ffiocontext(AVIOContext *ctx)
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.
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static int FUNC comment(CodedBitstreamContext *ctx, RWContext *rw, JPEGRawComment *current)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define FF_INFMT_FLAG_ID3V2_AUTO
Automatically parse ID3v2 metadata.
int ff_itunes_parse_smpb(const char *value, int64_t *priming, int64_t *remainder, int64_t *samples)
Parse the gapless playback information Apple encoders store in an iTunSMPB tag.
void avpriv_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp)
Update cur_dts of all streams based on the given timestamp and AVStream.
static int64_t filesize(AVIOContext *pb)
static const uint8_t frame_size[4]
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ 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 struct 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.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
#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.
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#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 AV_NOPTS_VALUE
Undefined timestamp value.
#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".
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
@ AV_CLASS_CATEGORY_DEMUXER
#define MKBETAG(a, b, c, d)
#define check(x, y, S, v)
static int mp3_read_header(AVFormatContext *s)
static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
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)
static void mp3_parse_vbri_tag(AVFormatContext *s, AVStream *st, int64_t base)
#define MIDDLE_BITS(k, m, n)
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 void mp3_parse_itunes_smpb(AVFormatContext *s, AVStream *st, const MPADecodeHeader *c, uint32_t spf)
Parse the gapless playback information Apple encoders store in an iTunSMPB comment instead of in the ...
static int mp3_read_probe(const AVProbeData *p)
static const AVDictionaryEntry * find_itunes_smpb(const AVDictionary *metadata)
Look the iTunSMPB tag up under every key it can land on.
static const uint8_t xing_offtbl[2][2]
mpeg audio declarations for both encoder and decoder.
#define MPA_MAX_CODED_FRAME_SIZE
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.
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.
This structure contains the data a format has to probe a file.
Rational number (pair of numerator and denominator).
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.
AVDictionary * id3v2_meta
ID3v2 tag useful for MP3 demuxing.
int64_t data_offset
offset of the first packet
int64_t maxsize
max filesize, used to limit allocations
int64_t last_discard_sample
The sample after last sample that is intended to be discarded after first_discard_sample.
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 first_discard_sample
If not 0, the first audio sample that should be discarded from the stream.
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
enum AVStreamParseType need_parsing