FFmpeg
Loading...
Searching...
No Matches
mp3dec.c File Reference
#include <string.h>
#include "libavutil/opt.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/dict.h"
#include "libavutil/mathematics.h"
#include "libavutil/mem.h"
#include "avformat.h"
#include "internal.h"
#include "avio_internal.h"
#include "apetag.h"
#include "demux.h"
#include "id3v2.h"
#include "id3v1.h"
#include "replaygain.h"
#include "libavcodec/codec_id.h"
#include "libavcodec/mpegaudio.h"
#include "libavcodec/mpegaudiodecheader.h"

Go to the source code of this file.

Data Structures

struct  MP3DecContext
 

Macros

#define XING_FLAG_FRAMES   0x01
 
#define XING_FLAG_SIZE   0x02
 
#define XING_FLAG_TOC   0x04
 
#define XING_FLAC_QSCALE   0x08
 
#define XING_TOC_COUNT   100
 
#define LAST_BITS(k, n)
 
#define MIDDLE_BITS(k, m, n)
 
#define MP3_PACKET_SIZE   1024
 
#define SEEK_WINDOW   4096
 
#define MIN_VALID   3
 

Enumerations

enum  CheckRet { CHECK_WRONG_HEADER = -1 , CHECK_SEEK_FAILED = -2 }
 

Functions

static int check (AVIOContext *pb, int64_t pos, uint32_t *header)
 
static int mp3_read_probe (const AVProbeData *p)
 
static void read_xing_toc (AVFormatContext *s, int64_t filesize, int64_t duration)
 
static int64_t mp3_trailing_tags_size (AVFormatContext *s, int64_t end)
 Size of the ID3v1 and APEv2 tags at the end of the file.
 
static int mp3_parse_info_tag (AVFormatContext *s, AVStream *st, MPADecodeHeader2 *c, uint32_t spf)
 
static void mp3_parse_vbri_tag (AVFormatContext *s, AVStream *st, int64_t base)
 
static const AVDictionaryEntry * find_itunes_smpb (const AVDictionary *metadata)
 Look the iTunSMPB tag up under every key it can land on.
 
static void mp3_parse_itunes_smpb (AVFormatContext *s, AVStream *st, const MPADecodeHeader2 *c, uint32_t spf)
 Parse the gapless playback information Apple encoders store in an iTunSMPB comment instead of in the LAME extension of the Xing 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.
 
static int mp3_read_header (AVFormatContext *s)
 
static int mp3_read_packet (AVFormatContext *s, AVPacket *pkt)
 
static int64_t mp3_sync (AVFormatContext *s, int64_t target_pos, int flags)
 
static int mp3_seek (AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
 

Variables

static const AVOption options []
 
static const AVClass demuxer_class
 
const FFInputFormat ff_mp3_demuxer
 

Macro Definition Documentation

◆ XING_FLAG_FRAMES

#define XING_FLAG_FRAMES   0x01

Definition at line 42 of file mp3dec.c.

Referenced by mp3_parse_info_tag().

◆ XING_FLAG_SIZE

#define XING_FLAG_SIZE   0x02

Definition at line 43 of file mp3dec.c.

Referenced by mp3_parse_info_tag().

◆ XING_FLAG_TOC

#define XING_FLAG_TOC   0x04

Definition at line 44 of file mp3dec.c.

Referenced by mp3_parse_info_tag().

◆ XING_FLAC_QSCALE

#define XING_FLAC_QSCALE   0x08

Definition at line 45 of file mp3dec.c.

Referenced by mp3_parse_info_tag().

◆ XING_TOC_COUNT

#define XING_TOC_COUNT   100

Definition at line 47 of file mp3dec.c.

Referenced by read_xing_toc().

◆ LAST_BITS

#define LAST_BITS ( k,
n )
Value:
((k) & ((1 << (n)) - 1))

◆ MIDDLE_BITS

#define MIDDLE_BITS ( k,
m,
n )
Value:
LAST_BITS((k) >> (m), ((n) - (m) + 1))
#define LAST_BITS(k, n)

Referenced by mp3_parse_info_tag().

◆ MP3_PACKET_SIZE

#define MP3_PACKET_SIZE   1024

Definition at line 589 of file mp3dec.c.

Referenced by mp3_read_packet().

◆ SEEK_WINDOW

#define SEEK_WINDOW   4096

Definition at line 615 of file mp3dec.c.

Referenced by mp3_sync().

◆ MIN_VALID

#define MIN_VALID   3

Referenced by mp3_sync().

Enumeration Type Documentation

◆ CheckRet

enum CheckRet
Enumerator
CHECK_WRONG_HEADER 
CHECK_SEEK_FAILED 

Definition at line 63 of file mp3dec.c.

Function Documentation

◆ check()

static int check ( AVIOContext * pb,
int64_t pos,
uint32_t * header )
static

Definition at line 617 of file mp3dec.c.

◆ mp3_read_probe()

static int mp3_read_probe ( const AVProbeData * p)
static

Definition at line 72 of file mp3dec.c.

◆ read_xing_toc()

static void read_xing_toc ( AVFormatContext * s,
int64_t filesize,
int64_t duration )
static

Definition at line 139 of file mp3dec.c.

Referenced by mp3_parse_info_tag().

◆ mp3_trailing_tags_size()

static int64_t mp3_trailing_tags_size ( AVFormatContext * s,
int64_t end )
static

Size of the ID3v1 and APEv2 tags at the end of the file.

They are not part of the MPEG stream, so the Xing/Info byte count does not include them. The read position is restored.

Returns
the size in bytes, or a negative AVERROR code if seeking failed

Definition at line 172 of file mp3dec.c.

Referenced by mp3_parse_info_tag().

◆ mp3_parse_info_tag()

static int mp3_parse_info_tag ( AVFormatContext * s,
AVStream * st,
MPADecodeHeader2 * c,
uint32_t spf )
static

Definition at line 195 of file mp3dec.c.

Referenced by mp3_parse_vbr_tags().

◆ mp3_parse_vbri_tag()

static void mp3_parse_vbri_tag ( AVFormatContext * s,
AVStream * st,
int64_t base )
static

Definition at line 350 of file mp3dec.c.

Referenced by mp3_parse_vbr_tags().

◆ find_itunes_smpb()

static const AVDictionaryEntry * find_itunes_smpb ( const AVDictionary * metadata)
static

Look the iTunSMPB tag up under every key it can land on.

A COMM frame keeps its language in the key, and while Apple writes eng, anything that retags the file is free to write its own, valid or not.

The bare key is for files remuxed by versions that exposed a COMM descriptor as a metadata key of its own: those wrote the tag back out as a TXXX frame, which carries no language and is keyed by its description alone.

Definition at line 378 of file mp3dec.c.

Referenced by mp3_parse_itunes_smpb().

◆ mp3_parse_itunes_smpb()

static void mp3_parse_itunes_smpb ( AVFormatContext * s,
AVStream * st,
const MPADecodeHeader2 * c,
uint32_t spf )
static

Parse the gapless playback information Apple encoders store in an iTunSMPB comment instead of in the LAME extension of the Xing tag.

Definition at line 398 of file mp3dec.c.

Referenced by mp3_parse_vbr_tags().

◆ mp3_parse_vbr_tags()

static int mp3_parse_vbr_tags ( AVFormatContext * s,
AVStream * st,
int64_t base )
static

Try to find Xing/Info/VBRI tags and compute duration from info therein.

Definition at line 438 of file mp3dec.c.

Referenced by mp3_read_header().

◆ mp3_read_header()

static int mp3_read_header ( AVFormatContext * s)
static

Definition at line 512 of file mp3dec.c.

◆ mp3_read_packet()

static int mp3_read_packet ( AVFormatContext * s,
AVPacket * pkt )
static

Definition at line 591 of file mp3dec.c.

◆ mp3_sync()

static int64_t mp3_sync ( AVFormatContext * s,
int64_t target_pos,
int flags )
static

Definition at line 647 of file mp3dec.c.

Referenced by mp3_seek().

◆ mp3_seek()

static int mp3_seek ( AVFormatContext * s,
int stream_index,
int64_t timestamp,
int flags )
static

Definition at line 697 of file mp3dec.c.

Variable Documentation

◆ options

const AVOption options[]
static
Initial value:
= {
{ "usetoc", "use table of contents", 0x42 , AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM},
{ NULL },
}
#define NULL
Definition coverity.c:32
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition opt.h:355
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326

Definition at line 750 of file mp3dec.c.

◆ demuxer_class

const AVClass demuxer_class
static
Initial value:
= {
.class_name = "mp3",
.item_name = av_default_item_name,
.option = options,
}
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:247
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
@ AV_CLASS_CATEGORY_DEMUXER
Definition log.h:33

Definition at line 755 of file mp3dec.c.

◆ ff_mp3_demuxer

const FFInputFormat ff_mp3_demuxer
Initial value:
= {
.p.name = "mp3",
.p.long_name = NULL_IF_CONFIG_SMALL("MP2/3 (MPEG audio layer 2/3)"),
.p.flags = AVFMT_GENERIC_INDEX,
.p.extensions = "mp2,mp3,m2a,mpa",
.p.priv_class = &demuxer_class,
.p.mime_type = "audio/mpeg",
.flags_internal = FF_INFMT_FLAG_ID3V2_AUTO,
.read_probe = mp3_read_probe,
.read_header = mp3_read_header,
.read_packet = mp3_read_packet,
.read_seek = mp3_seek,
.priv_data_size = sizeof(MP3DecContext),
}
static const AVClass demuxer_class
Definition apngdec.c:478
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition avformat.h:501
#define FF_INFMT_FLAG_ID3V2_AUTO
Automatically parse ID3v2 metadata.
Definition demux.h:45
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:97
static int mp3_read_header(AVFormatContext *s)
Definition mp3dec.c:512
static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition mp3dec.c:697
static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition mp3dec.c:591
static int mp3_read_probe(const AVProbeData *p)
Definition mp3dec.c:72

Definition at line 763 of file mp3dec.c.