[FFmpeg-devel] [PATCH 2/4] lavf: identify MP1 and MP2 as distinct containers from MP3
Rodger Combs
rodger.combs at gmail.com
Thu Oct 19 10:39:46 EEST 2017
This allows us to report the correct codec ID here
---
libavformat/Makefile | 2 ++
libavformat/allformats.c | 4 +--
libavformat/mp3dec.c | 66 +++++++++++++++++++++++++++++++-----------------
libavformat/utils.c | 3 +--
libavformat/version.h | 4 +--
5 files changed, 50 insertions(+), 29 deletions(-)
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 2522a3e768..a978482211 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -296,7 +296,9 @@ OBJS-$(CONFIG_MOV_DEMUXER) += mov.o mov_chan.o replaygain.o
OBJS-$(CONFIG_MOV_MUXER) += movenc.o avc.o hevc.o vpcc.o \
movenchint.o mov_chan.o rtp.o \
movenccenc.o rawutils.o
+OBJS-$(CONFIG_MP1_DEMUXER) += mp3dec.o replaygain.o
OBJS-$(CONFIG_MP1_MUXER) += rawenc.o
+OBJS-$(CONFIG_MP2_DEMUXER) += mp3dec.o replaygain.o
OBJS-$(CONFIG_MP2_MUXER) += rawenc.o
OBJS-$(CONFIG_MP3_DEMUXER) += mp3dec.o replaygain.o
OBJS-$(CONFIG_MP3_MUXER) += mp3enc.o rawenc.o id3v2enc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 32e9a979bc..c02cdacb7b 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -189,8 +189,8 @@ static void register_all(void)
REGISTER_DEMUXER (MM, mm);
REGISTER_MUXDEMUX(MMF, mmf);
REGISTER_MUXDEMUX(MOV, mov);
- REGISTER_MUXER (MP1, mp1);
- REGISTER_MUXER (MP2, mp2);
+ REGISTER_MUXDEMUX(MP1, mp1);
+ REGISTER_MUXDEMUX(MP2, mp2);
REGISTER_MUXDEMUX(MP3, mp3);
REGISTER_MUXER (MP4, mp4);
REGISTER_DEMUXER (MPC, mpc);
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index a5c4f2ea12..d405a98d7b 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -66,7 +66,7 @@ static int check(AVIOContext *pb, int64_t pos, uint32_t *header);
/* mp3 read */
-static int mp3_read_probe(AVProbeData *p)
+static int mpa_read_probe(AVProbeData *p, int layer)
{
int max_frames, first_frames = 0;
int whole_used = 0;
@@ -89,7 +89,7 @@ static int mp3_read_probe(AVProbeData *p)
header = AV_RB32(buf2);
ret = avpriv_mpegaudio_decode_header(&h, header);
- if (ret != 0)
+ if (ret != 0 || h.layer != layer)
break;
buf2 += h.frame_size;
}
@@ -105,7 +105,8 @@ static int mp3_read_probe(AVProbeData *p)
if (first_frames>=7) return AVPROBE_SCORE_EXTENSION + 1;
else if(max_frames>200)return AVPROBE_SCORE_EXTENSION;
else if(max_frames>=4 && max_frames >= p->buf_size/10000) return AVPROBE_SCORE_EXTENSION / 2;
- else if(ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC) && 2*ff_id3v2_tag_len(buf0) >= p->buf_size)
+ else if(ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC) && 2*ff_id3v2_tag_len(buf0) >= p->buf_size &&
+ (p->buf_size < PROBE_BUF_MAX || layer == 3))
return p->buf_size < PROBE_BUF_MAX ? AVPROBE_SCORE_EXTENSION / 4 : AVPROBE_SCORE_EXTENSION - 2;
else if(first_frames > 1 && whole_used) return 5;
else if(max_frames>=1 && max_frames >= p->buf_size/10000) return 1;
@@ -113,6 +114,12 @@ static int mp3_read_probe(AVProbeData *p)
//mpegps_mp3_unrecognized_format.mpg has max_frames=3
}
+#define READ_PROBE(l) \
+static int mp##l##_read_probe(AVProbeData *p) \
+{ \
+ return mpa_read_probe(p, l); \
+}
+
static void read_xing_toc(AVFormatContext *s, int64_t filesize, int64_t duration)
{
int i;
@@ -341,7 +348,7 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
return 0;
}
-static int mp3_read_header(AVFormatContext *s)
+static int mpa_read_header(AVFormatContext *s, enum AVCodecID id)
{
MP3DecContext *mp3 = s->priv_data;
AVStream *st;
@@ -357,7 +364,7 @@ static int mp3_read_header(AVFormatContext *s)
return AVERROR(ENOMEM);
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
- st->codecpar->codec_id = AV_CODEC_ID_MP3;
+ st->codecpar->codec_id = id;
st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
st->start_time = 0;
@@ -422,6 +429,12 @@ static int mp3_read_header(AVFormatContext *s)
return 0;
}
+#define READ_HEADER(l) \
+static int mp##l##_read_header(AVFormatContext *s) \
+{ \
+ return mpa_read_header(s, AV_CODEC_ID_MP##l); \
+}
+
#define MP3_PACKET_SIZE 1024
static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
@@ -582,23 +595,30 @@ static const AVOption options[] = {
{ NULL },
};
-static const AVClass demuxer_class = {
- .class_name = "mp3",
- .item_name = av_default_item_name,
- .option = options,
- .version = LIBAVUTIL_VERSION_INT,
- .category = AV_CLASS_CATEGORY_DEMUXER,
+#define DECLARE_LAYER(l, ext) \
+READ_PROBE(l) \
+READ_HEADER(l) \
+static const AVClass demuxer_class_##l = { \
+ .class_name = "mp" #l, \
+ .item_name = av_default_item_name, \
+ .option = options, \
+ .version = LIBAVUTIL_VERSION_INT, \
+ .category = AV_CLASS_CATEGORY_DEMUXER, \
+}; \
+\
+AVInputFormat ff_mp##l##_demuxer = { \
+ .name = "mp" #l, \
+ .long_name = NULL_IF_CONFIG_SMALL("MP" #l " (MPEG audio layer " #l ")"), \
+ .read_probe = mp##l##_read_probe, \
+ .read_header = mp##l##_read_header, \
+ .read_packet = mp3_read_packet, \
+ .read_seek = mp3_seek, \
+ .priv_data_size = sizeof(MP3DecContext), \
+ .flags = AVFMT_GENERIC_INDEX, \
+ .extensions = ext, /* XXX: use probe */ \
+ .priv_class = &demuxer_class_##l, \
};
-AVInputFormat ff_mp3_demuxer = {
- .name = "mp3",
- .long_name = NULL_IF_CONFIG_SMALL("MP2/3 (MPEG audio layer 2/3)"),
- .read_probe = mp3_read_probe,
- .read_header = mp3_read_header,
- .read_packet = mp3_read_packet,
- .read_seek = mp3_seek,
- .priv_data_size = sizeof(MP3DecContext),
- .flags = AVFMT_GENERIC_INDEX,
- .extensions = "mp2,mp3,m2a,mpa", /* XXX: use probe */
- .priv_class = &demuxer_class,
-};
+DECLARE_LAYER(1, "mp1,mpa")
+DECLARE_LAYER(2, "mp2,m2a,mpa")
+DECLARE_LAYER(3, "mp3,mpa")
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 1a7996c4fd..a54687d239 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -609,8 +609,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename,
}
if (id3v2_extra_meta) {
- if (!strcmp(s->iformat->name, "mp3") || !strcmp(s->iformat->name, "aac") ||
- !strcmp(s->iformat->name, "tta")) {
+ if (av_match_name(s->iformat->name, "mp1,mp2,mp3,aac,tta")) {
if ((ret = ff_id3v2_parse_apic(s, &id3v2_extra_meta)) < 0)
goto fail;
if ((ret = ff_id3v2_parse_chapters(s, &id3v2_extra_meta)) < 0)
diff --git a/libavformat/version.h b/libavformat/version.h
index 22f82a37f7..330ef987bb 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,8 +32,8 @@
// Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
// Also please add any ticket numbers that you believe might be affected here
#define LIBAVFORMAT_VERSION_MAJOR 57
-#define LIBAVFORMAT_VERSION_MINOR 84
-#define LIBAVFORMAT_VERSION_MICRO 101
+#define LIBAVFORMAT_VERSION_MINOR 85
+#define LIBAVFORMAT_VERSION_MICRO 100
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
--
2.14.1
More information about the ffmpeg-devel
mailing list