From patchwork Sat Mar 18 09:38:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodger Combs X-Patchwork-Id: 3007 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.50.79 with SMTP id y76csp621785vsy; Sat, 18 Mar 2017 02:46:06 -0700 (PDT) X-Received: by 10.28.88.2 with SMTP id m2mr2057329wmb.12.1489830366402; Sat, 18 Mar 2017 02:46:06 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v45si14573470wrc.22.2017.03.18.02.46.06; Sat, 18 Mar 2017 02:46:06 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B105D68836E; Sat, 18 Mar 2017 11:45:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f68.google.com (mail-it0-f68.google.com [209.85.214.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 21C01680721 for ; Sat, 18 Mar 2017 11:45:40 +0200 (EET) Received: by mail-it0-f68.google.com with SMTP id y18so8321077itc.2 for ; Sat, 18 Mar 2017 02:45:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=2ceCzzYWHseqmV04zjonPCh/a8eTES/hG79gbk4jjJU=; b=dNhOPE24lY1efYSzLZx++WsWXDhfdckQQQJ5zL+L0gVGG0V57GnPehwr96vb1xcDDS SZI+E7ZTq2BCionlVKwMGKlP1vZO+wxjCCjcZed17susEX5s8srRu7rKBKvHSzMbf0jT lkqS+cLDESqNcw2PCJr23R+nzqXzG69bnhwkJHHqcev0xSr/8MPPYGNHapO6Wl16ozF0 zPVu7G0+DZFP3PhWUs34gLPJI0YVwLz5uRU3prD7GDYqPr7tMMo6eQWo7AqV0964KcRE 8CmSkFIP/55dfZctD8DYZppXRrUtipZXUobyLCiOizEilMijvjrNZjNgHLQxfYt1bpOf 5Pjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=2ceCzzYWHseqmV04zjonPCh/a8eTES/hG79gbk4jjJU=; b=Lmc7Cdce4Y1G38obwL6Ri3aXTtGDxOpAw+HYWTh3sswX89R+MPR4jtC5WDpWOKBDHv axpQ7aWVCx0HkB9kyHO+chnJKpV4gNc75L6OIbQDtpAebBL69grT/LFFKAqkJMEwvlk6 Th89TNyUQV1zm5WwF7pQvJMY4oV7tRTlldoxP7lQUy9K9kuM7L0taiOpW40wmFhCHrf9 3qh6M6NC5fCTIv+jZtJOjMItihLug02TrQwMp+GnOu12akeS1IiYfb9Y0BD3oe4l9vNo YMYMmBmFAgi1LoRTy6MBZW2iwtz8ptmwT+Dp4zGxot2lN4/R79MT/CSiCJOdfw0XFhv6 bE9g== X-Gm-Message-State: AFeK/H3Rs8stA99KX0m0Y16fFBSEgW7J0UcrozCF9wtJNk8Fl3FBZsmHaDfrHnaHSsm+Qg== X-Received: by 10.36.50.138 with SMTP id j132mr2112692ita.102.1489829892010; Sat, 18 Mar 2017 02:38:12 -0700 (PDT) Received: from Rodgers-MacBook-Pro.local.net (c-73-110-121-59.hsd1.il.comcast.net. [73.110.121.59]) by smtp.gmail.com with ESMTPSA id q185sm2274060itc.22.2017.03.18.02.38.11 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 18 Mar 2017 02:38:11 -0700 (PDT) From: Rodger Combs To: ffmpeg-devel@ffmpeg.org Date: Sat, 18 Mar 2017 04:38:03 -0500 Message-Id: <20170318093805.20972-1-rodger.combs@gmail.com> X-Mailer: git-send-email 2.11.1 Subject: [FFmpeg-devel] [PATCH 1/3] lavf: identify MP1 and MP2 as distinct containers from MP3 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This allows us to report the correct codec ID here --- libavformat/allformats.c | 3 ++- libavformat/mp3dec.c | 66 +++++++++++++++++++++++++++++++----------------- libavformat/rawenc.c | 13 ++++++++++ libavformat/utils.c | 4 +-- libavformat/version.h | 4 +-- 5 files changed, 62 insertions(+), 28 deletions(-) diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 09e62c3cfc..b9caeb3737 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -185,7 +185,8 @@ static void register_all(void) REGISTER_DEMUXER (MM, mm); REGISTER_MUXDEMUX(MMF, mmf); REGISTER_MUXDEMUX(MOV, mov); - 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 b45a066686..8773a55f80 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/rawenc.c b/libavformat/rawenc.c index 0edcd1cf99..4e72aa9dfd 100644 --- a/libavformat/rawenc.c +++ b/libavformat/rawenc.c @@ -337,6 +337,19 @@ AVOutputFormat ff_mlp_muxer = { }; #endif +#if CONFIG_MP1_MUXER +AVOutputFormat ff_mp1_muxer = { + .name = "mp1", + .long_name = NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"), + .mime_type = "audio/mpeg", + .extensions = "mp1,m1a", + .audio_codec = AV_CODEC_ID_MP1, + .video_codec = AV_CODEC_ID_NONE, + .write_packet = ff_raw_write_packet, + .flags = AVFMT_NOTIMESTAMPS, +}; +#endif + #if CONFIG_MP2_MUXER AVOutputFormat ff_mp2_muxer = { .name = "mp2", diff --git a/libavformat/utils.c b/libavformat/utils.c index 37d7024465..84acb9c795 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -609,8 +609,8 @@ 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 (!strcmp(s->iformat->name, "mp1") || !strcmp(s->iformat->name, "mp2") || !strcmp(s->iformat->name, "mp3") || + !strcmp(s->iformat->name, "aac") || !strcmp(s->iformat->name, "tta")) { if ((ret = ff_id3v2_parse_apic(s, &id3v2_extra_meta)) < 0) goto fail; } else diff --git a/libavformat/version.h b/libavformat/version.h index dc689d45fb..418701e470 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 66 -#define LIBAVFORMAT_VERSION_MICRO 104 +#define LIBAVFORMAT_VERSION_MINOR 67 +#define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \