This allows us to report the correct codec ID here --- libavformat/allformats.c | 2 +- libavformat/mp3dec.c | 62 +++++++++++++++++++++++++++++++----------------- libavformat/version.h | 2 +- 3 files changed, 42 insertions(+), 24 deletions(-)
diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 6a79b75d78..6fd8aa609b 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -189,7 +189,7 @@ void av_register_all(void) REGISTER_DEMUXER (MM, mm); REGISTER_MUXDEMUX(MMF, mmf); REGISTER_MUXDEMUX(MOV, mov); - REGISTER_MUXER (MP2, mp2); + 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 099ca57d24..499aa45fd4 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; } @@ -113,6 +113,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 +347,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; @@ -354,7 +360,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; @@ -419,6 +425,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) @@ -579,23 +591,29 @@ 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(2, "mp2,m2a,mpa") +DECLARE_LAYER(3, "mp3,mpa") diff --git a/libavformat/version.h b/libavformat/version.h index 65e6a4ccb7..21cc8a99c7 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,7 +32,7 @@ // 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 61 +#define LIBAVFORMAT_VERSION_MINOR 62 #define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ -- 2.11.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel