From patchwork Thu Feb 6 06:58:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zane van Iperen X-Patchwork-Id: 17699 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 6EC7C44A93E for ; Thu, 6 Feb 2020 08:58:33 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5664B68AF1C; Thu, 6 Feb 2020 08:58:33 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail2.protonmail.ch (mail2.protonmail.ch [185.70.40.22]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8D2AE68A831 for ; Thu, 6 Feb 2020 08:58:26 +0200 (EET) Date: Thu, 06 Feb 2020 06:58:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zanevaniperen.com; s=protonmail; t=1580972305; bh=Hjr/k4S5XLnXrv4BCAYUu5l8A+St9BKeb31mN8C50XY=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References: Feedback-ID:From; b=P5hP3OEOZSeMWnLdgVcjfzBldMZyWXQdwmEKjffABmQzY2W/4IVX7U7N01N/t0sOD K6R1KKrqNj7K8VzJcUnwYMGffwq2OVP5o5HIHZR3EQjMXbAymhsnb7Wurx59UICK3/ SbuELS9aUE5uGyTkf0DxJIZ1Uwo+VtIm+eUAL8WU= To: ffmpeg-devel@ffmpeg.org From: Zane van Iperen Message-ID: <20200206065801.28118-3-zane@zanevaniperen.com> In-Reply-To: <20200206065801.28118-1-zane@zanevaniperen.com> References: <20200206065801.28118-1-zane@zanevaniperen.com> Feedback-ID: xylLYHwBzJW7F28tHN-oL9EBm6h5yqtCqG6YwPpJ2oMwBYJT6-HxTnFTF6p18axLiSywX61iUfj4CElBGg8-GA==:Ext:ProtonMail MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=7.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.protonmail.ch Subject: [FFmpeg-devel] [PATCH v2 2/2] avformat: add demuxer for Simon & Schuster Interactive's VAG format 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 Cc: Zane van Iperen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Adds support for the custom VAG container used by some Simon & Schuster Interactive games such as Real War, and Real War: Rogue States. Signed-off-by: Zane van Iperen --- libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/kvag.c | 117 +++++++++++++++++++++++++++++++++++++++ libavformat/version.h | 2 +- 4 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 libavformat/kvag.c diff --git a/libavformat/Makefile b/libavformat/Makefile index ba6ea8c4a6..710cc4d088 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -279,6 +279,7 @@ OBJS-$(CONFIG_JACOSUB_DEMUXER) += jacosubdec.o subtitles.o OBJS-$(CONFIG_JACOSUB_MUXER) += jacosubenc.o rawenc.o OBJS-$(CONFIG_JV_DEMUXER) += jvdec.o OBJS-$(CONFIG_KUX_DEMUXER) += flvdec.o +OBJS-$(CONFIG_KVAG_DEMUXER) += kvag.o OBJS-$(CONFIG_LATM_MUXER) += latmenc.o rawenc.o OBJS-$(CONFIG_LMLM4_DEMUXER) += lmlm4.o OBJS-$(CONFIG_LOAS_DEMUXER) += loasdec.o rawdec.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index fe74a32e47..3ea4100e85 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -214,6 +214,7 @@ extern AVInputFormat ff_jacosub_demuxer; extern AVOutputFormat ff_jacosub_muxer; extern AVInputFormat ff_jv_demuxer; extern AVInputFormat ff_kux_demuxer; +extern AVInputFormat ff_kvag_demuxer; extern AVOutputFormat ff_latm_muxer; extern AVInputFormat ff_lmlm4_demuxer; extern AVInputFormat ff_loas_demuxer; diff --git a/libavformat/kvag.c b/libavformat/kvag.c new file mode 100644 index 0000000000..71b0eb4118 --- /dev/null +++ b/libavformat/kvag.c @@ -0,0 +1,117 @@ +/* + * Simon & Schuster Interactive VAG demuxer + * + * Copyright (C) 2020 Zane van Iperen (zane@zanevaniperen.com) + * + * 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 "avformat.h" +#include "internal.h" +#include "libavutil/intreadwrite.h" + +#define KVAG_TAG MKTAG('K', 'V', 'A', 'G') +#define KVAG_HEADER_SIZE 14 +#define KVAG_MAX_READ_SIZE 4096 + +typedef struct KVAGHeader { + uint32_t magic; + uint32_t data_size; + uint32_t sample_rate; + uint16_t stereo; +} KVAGHeader; + +static int kvag_probe(const AVProbeData *p) +{ + if (AV_RL32(p->buf) != KVAG_TAG) + return 0; + + return AVPROBE_SCORE_EXTENSION + 1; +} + +static int kvag_read_header(AVFormatContext *s) +{ + int ret; + AVStream *st; + KVAGHeader hdr; + AVCodecParameters *par; + uint8_t buf[KVAG_HEADER_SIZE]; + + if (!(st = avformat_new_stream(s, NULL))) + return AVERROR(ENOMEM); + + if ((ret = avio_read(s->pb, buf, KVAG_HEADER_SIZE)) < 0) + return ret; + else if (ret != KVAG_HEADER_SIZE) + return AVERROR(EIO); + + hdr.magic = AV_RL32(buf + 0); + hdr.data_size = AV_RL32(buf + 4); + hdr.sample_rate = AV_RL32(buf + 8); + hdr.stereo = AV_RL16(buf + 12); + + par = st->codecpar; + par->codec_type = AVMEDIA_TYPE_AUDIO; + par->codec_id = AV_CODEC_ID_ADPCM_IMA_SSI; + par->format = AV_SAMPLE_FMT_S16; + + if (hdr.stereo) { + par->channel_layout = AV_CH_LAYOUT_STEREO; + par->channels = 2; + } else { + par->channel_layout = AV_CH_LAYOUT_MONO; + par->channels = 1; + } + + par->sample_rate = hdr.sample_rate; + par->bits_per_coded_sample = 4; + par->bits_per_raw_sample = 16; + par->block_align = 1; + par->bit_rate = par->channels * + par->sample_rate * + par->bits_per_coded_sample; + + avpriv_set_pts_info(st, 64, 1, par->sample_rate); + st->start_time = 0; + st->duration = hdr.data_size * + (8 / par->bits_per_coded_sample) / + par->channels; + + return 0; +} + +static int kvag_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + int ret; + AVCodecParameters *par = s->streams[0]->codecpar; + + if ((ret = av_get_packet(s->pb, pkt, KVAG_MAX_READ_SIZE)) < 0) + return ret; + + pkt->flags &= ~AV_PKT_FLAG_CORRUPT; + pkt->stream_index = 0; + pkt->duration = ret * (8 / par->bits_per_coded_sample) / par->channels; + + return 0; +} + +AVInputFormat ff_kvag_demuxer = { + .name = "kvag", + .long_name = NULL_IF_CONFIG_SMALL("Simon & Schuster Interactive VAG"), + .read_probe = kvag_probe, + .read_header = kvag_read_header, + .read_packet = kvag_read_packet +}; diff --git a/libavformat/version.h b/libavformat/version.h index 15fdb73e3e..be22abc010 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 58 -#define LIBAVFORMAT_VERSION_MINOR 37 +#define LIBAVFORMAT_VERSION_MINOR 38 #define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \