From patchwork Thu Sep 24 17:11:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 22571 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 165AA44AB16 for ; Thu, 24 Sep 2020 20:18:38 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D19E168B900; Thu, 24 Sep 2020 20:18:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D999468B739 for ; Thu, 24 Sep 2020 20:18:30 +0300 (EEST) Received: by mail-lj1-f193.google.com with SMTP id s205so51873lja.7 for ; Thu, 24 Sep 2020 10:18:30 -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=pRgQ584RHw/EyJy8tdTbs+rBGE/dLZgJ9xzn/lebrH4=; b=ql1C88gjDw2gYLd46hIJ4wX3mI4GFeq08BkIudHnbqXQnWlKLwl6pKBpugBRgmUcoP l6PG/I3boVVKhtAaTUIEczuyfxgSfco3zLTwV4hJHfzKn4ZlQHdZPQGJnTv/xlKDfQSq X7Ajiaw2FifdNEYR1f184InDP+6qEQi+oEpcgmE6siXVwxKymH/sH+NpDJH44vrKlO5b mnRZJNWbbDQ0UAuFhLqPOu+cqr9dXueoUa0DcApsWmfIL+C13TkuKwnq1Jrl6ojw0CF1 5lW4ydzvvpD4Zd+FAKaAfjzmhAzc4bu4Nv7FjFZg5fEXzqeK0Q632UYajvT3Y5xMqS+C 7crg== 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=pRgQ584RHw/EyJy8tdTbs+rBGE/dLZgJ9xzn/lebrH4=; b=PwON8e5cEEjbzWjOb6+RixL0fqHEM2xlva1wgrSDkR2uSkL4HW3LXKnS1e6B0xvUZb ItWVtJWs6kJeC5SqF71tbtjE9Y0DzCZGUrkrPwAp6Ghl8YwX4jH2XiCvP7mB0MoEXL6X EZl0K3eQm7WT71+IhlO1pTs8Q6XS0Xy8SgarXUG1xOZl2Me4VsdjGF4z4aA2LrcO7iRF XaKaBlgTQ3cgGOYU3jMX5bBRVUCv2jf2xLs7Mkc2QPlDy2fyYVzCohofyoBUcBR92XZa GzpfrRRcLMRYPoZL7Fu8G93pE96zGVM6BJ14dcJLJs5kfroTSN652thce09kZQi5ty+N HpAA== X-Gm-Message-State: AOAM532Q7mdeCQDSrfUt4W2cvHRRiqjayRZaMxGgDeliqd9ZDhpkh5Kp 0N/UOvGn/HvNRKjWTUwIsUxM76FvmoH67A== X-Google-Smtp-Source: ABdhPJzHSIQJd0gLGSgh0LgwLgLxbckT+M3ZiJHeaOkvL8Uhe4r3Ar39+AA0WXFxQ6UNNeN9cnybcA== X-Received: by 2002:a05:6402:1451:: with SMTP id d17mr999840edx.48.1600967479230; Thu, 24 Sep 2020 10:11:19 -0700 (PDT) Received: from localhost.localdomain ([94.250.162.52]) by smtp.gmail.com with ESMTPSA id s22sm2970006eds.21.2020.09.24.10.11.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 10:11:18 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Thu, 24 Sep 2020 19:11:09 +0200 Message-Id: <20200924171109.23125-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] avformat: add tri-ACE demuxer 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" Signed-off-by: Paul B Mahol --- libavformat/Makefile | 1 + libavformat/acedec.c | 114 +++++++++++++++++++++++++++++++++++++++ libavformat/allformats.c | 1 + 3 files changed, 116 insertions(+) create mode 100644 libavformat/acedec.c diff --git a/libavformat/Makefile b/libavformat/Makefile index 213004cb45..e82af409b7 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -71,6 +71,7 @@ OBJS-$(CONFIG_AAC_DEMUXER) += aacdec.o apetag.o img2.o rawdec.o OBJS-$(CONFIG_AAX_DEMUXER) += aaxdec.o OBJS-$(CONFIG_AC3_DEMUXER) += ac3dec.o rawdec.o OBJS-$(CONFIG_AC3_MUXER) += rawenc.o +OBJS-$(CONFIG_ACE_DEMUXER) += acedec.o OBJS-$(CONFIG_ACM_DEMUXER) += acm.o rawdec.o OBJS-$(CONFIG_ACT_DEMUXER) += act.o OBJS-$(CONFIG_ADF_DEMUXER) += bintext.o sauce.o diff --git a/libavformat/acedec.c b/libavformat/acedec.c new file mode 100644 index 0000000000..c6d0c33e52 --- /dev/null +++ b/libavformat/acedec.c @@ -0,0 +1,114 @@ +/* + * ACE demuxer + * Copyright (c) 2020 Paul B Mahol + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/intreadwrite.h" +#include "avformat.h" +#include "internal.h" + +static int ace_probe(const AVProbeData *p) +{ + uint32_t asc; + + if (AV_RB32(p->buf) != MKBETAG('A','A','C',' ')) + return 0; + if (p->buf_size < 0x44) + return 0; + asc = AV_RB32(p->buf + 0x40); + if (asc < 0x44 || asc > p->buf_size - 4) + return 0; + if (AV_RB32(p->buf + asc) != MKBETAG('A','S','C',' ')) + return 0; + + return AVPROBE_SCORE_MAX / 2 + 1; +} + +static int ace_read_header(AVFormatContext *s) +{ + AVIOContext *pb = s->pb; + AVCodecParameters *par; + int ret, codec, rate, nb_channels; + uint32_t asc_pos, size; + AVStream *st; + + avio_skip(pb, 0x40); + asc_pos = avio_rb32(pb); + if (asc_pos < 0x44) + return AVERROR_INVALIDDATA; + avio_skip(pb, asc_pos - 0x44); + if (avio_rb32(pb) != MKBETAG('A','S','C',' ')) + return AVERROR_INVALIDDATA; + avio_skip(pb, 0xec); + codec = avio_rb32(pb); + nb_channels = avio_rb32(pb); + if (nb_channels <= 0 || nb_channels > INT32_MAX / 256) + return AVERROR_INVALIDDATA; + size = avio_rb32(pb); + if (size == 0) + return AVERROR_INVALIDDATA; + rate = avio_rb32(pb); + if (rate <= 0) + return AVERROR_INVALIDDATA; + avio_skip(pb, 16); + + st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + st->start_time = 0; + par = st->codecpar; + par->codec_type = AVMEDIA_TYPE_AUDIO; + par->channels = nb_channels; + par->sample_rate = rate; + par->block_align = (codec == 4 ? 0x60 : codec == 5 ? 0x98 : 0xC0) * nb_channels; + st->duration = (size / par->block_align) * 1024LL; + par->codec_id = AV_CODEC_ID_ATRAC3; + + ret = ff_alloc_extradata(par, 14); + if (ret < 0) + return ret; + + AV_WL16(st->codecpar->extradata, 1); + AV_WL16(st->codecpar->extradata+2, 2048 * par->channels); + AV_WL16(st->codecpar->extradata+4, 0); + AV_WL16(st->codecpar->extradata+6, codec == 4 ? 1 : 0); + AV_WL16(st->codecpar->extradata+8, codec == 4 ? 1 : 0); + AV_WL16(st->codecpar->extradata+10, 1); + AV_WL16(st->codecpar->extradata+12, 0); + + avpriv_set_pts_info(st, 64, 1, par->sample_rate); + + return 0; +} + +static int ace_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + AVCodecParameters *par = s->streams[0]->codecpar; + + return av_get_packet(s->pb, pkt, par->block_align ? par->block_align : 1024 * par->channels); +} + +AVInputFormat ff_ace_demuxer = { + .name = "ace", + .long_name = NULL_IF_CONFIG_SMALL("tri-Ace Audio Container"), + .read_probe = ace_probe, + .read_header = ace_read_header, + .read_packet = ace_read_packet, + .flags = AVFMT_GENERIC_INDEX, +}; diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 3a6b8e6dac..9d85b8ccc3 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -34,6 +34,7 @@ extern AVInputFormat ff_aac_demuxer; extern AVInputFormat ff_aax_demuxer; extern AVInputFormat ff_ac3_demuxer; extern AVOutputFormat ff_ac3_muxer; +extern AVInputFormat ff_ace_demuxer; extern AVInputFormat ff_acm_demuxer; extern AVInputFormat ff_act_demuxer; extern AVInputFormat ff_adf_demuxer;