From patchwork Sat Apr 15 13:36:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Darnley X-Patchwork-Id: 3425 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp615949vsd; Sat, 15 Apr 2017 06:48:46 -0700 (PDT) X-Received: by 10.223.165.5 with SMTP id i5mr11183315wrb.13.1492264125921; Sat, 15 Apr 2017 06:48:45 -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 u190si2998943wmf.146.2017.04.15.06.48.45; Sat, 15 Apr 2017 06:48:45 -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 800A768839D; Sat, 15 Apr 2017 16:48:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CFEB0680AAC for ; Sat, 15 Apr 2017 16:48:28 +0300 (EEST) Received: by mail-wr0-f193.google.com with SMTP id l44so15308276wrc.2 for ; Sat, 15 Apr 2017 06:48:36 -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=ne/19O0mY9v+dfOpWE9ALX9C8uYpQvNiPKy3S9ZngMM=; b=tbQLXUGGsbllg6LljhAJnWqy/MzqgJAZpKYXp3X6bqq7kk6WzCOt5UumrAInuI6paD 6D041ZMBRQspuM9uQoUnAywcgMoe/V/8Sshtfyfbfz8+O7n4DrUNueN1ko/LRnpyovSF uMBEcs2iu4Vc9w0mSRP30CbzJ2hUNSqGAG8fmRy0C9FcuFfMFIq09kPClmhC2ERV1qHf coyXItTclKPW7ogfB+9NRZiiPwQ6hdibu2vQzPwT+oqhkikpkCwvVLuUvoJtnQFcwllt TwfJRl4dloxp3E5YniZiOS/YKugHZxPlrDM71/zVkIvMnZsBcRG2AUbAOjUHfgoHaT7N +pUg== 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=ne/19O0mY9v+dfOpWE9ALX9C8uYpQvNiPKy3S9ZngMM=; b=V8N0E+3Y5hxIopZbk8W3+LA6u65Xm6OL8fbNhZJqERemohnN/qizq9seCOoKLy8PJg BnDPFfZ98qn0j0+995xifU8K6wkUNv+6PURH0EeMFXCTj2JxJiass46hBSQkqDMtDx81 IPK9kpBxbzarjHyCGmFvmGECMVid3PFl3PDN+bvVoBg4lMsIqlmjsDhWPQqQ37/uV9q/ AXlEchTrNeNtSU7YvZLLG9OKwpfYibT8TGYV7qopIFM4VyJDG2q5BnlZqnqXVRl1uG6E vGIZyP8RSvqPKQ5+1FyvxML0BRaffMVaym/mtWktVDVabC347HFOWn/v3tUYZYJXdcxy GX+Q== X-Gm-Message-State: AN3rC/4IrG88+UpDdJl6krccVNGnMfXCP61asnKQVJzLmek81VH9WnD9 2031/7pHwiwp+ULN X-Received: by 10.223.155.130 with SMTP id d2mr12184308wrc.36.1492263653353; Sat, 15 Apr 2017 06:40:53 -0700 (PDT) Received: from Ifrit.systemlords.lan (d51A44418.access.telenet.be. [81.164.68.24]) by smtp.gmail.com with ESMTPSA id i21sm6397947wrc.50.2017.04.15.06.40.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Apr 2017 06:40:52 -0700 (PDT) From: James Darnley To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Apr 2017 15:36:06 +0200 Message-Id: <20170415133606.21049-1-james.darnley@gmail.com> X-Mailer: git-send-email 2.12.2 Subject: [FFmpeg-devel] [PATCH] add Falcom Xanadu 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" --- libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/falcom_xa.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 libavformat/falcom_xa.c diff --git a/libavformat/Makefile b/libavformat/Makefile index 6bdfbe6789..06b6b5da57 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -158,6 +158,7 @@ OBJS-$(CONFIG_EA_DEMUXER) += electronicarts.o OBJS-$(CONFIG_EAC3_DEMUXER) += ac3dec.o rawdec.o OBJS-$(CONFIG_EAC3_MUXER) += rawenc.o OBJS-$(CONFIG_EPAF_DEMUXER) += epafdec.o pcm.o +OBJS-$(CONFIG_FALCOM_XA_DEMUXER) += falcom_xa.o OBJS-$(CONFIG_FFM_DEMUXER) += ffmdec.o OBJS-$(CONFIG_FFM_MUXER) += ffmenc.o OBJS-$(CONFIG_FFMETADATA_DEMUXER) += ffmetadec.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 09e62c3cfc..0c23ea9df0 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -117,6 +117,7 @@ static void register_all(void) REGISTER_MUXDEMUX(EAC3, eac3); REGISTER_DEMUXER (EPAF, epaf); REGISTER_MUXER (F4V, f4v); + REGISTER_DEMUXER (FALCOM_XA, falcom_xa); REGISTER_MUXDEMUX(FFM, ffm); REGISTER_MUXDEMUX(FFMETADATA, ffmetadata); REGISTER_MUXER (FIFO, fifo); diff --git a/libavformat/falcom_xa.c b/libavformat/falcom_xa.c new file mode 100644 index 0000000000..4c5f32a1b6 --- /dev/null +++ b/libavformat/falcom_xa.c @@ -0,0 +1,98 @@ +/* + * Falcom Xanadu demuxer + * Copyright (c) 2016 James Darnley + * + * 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" + +typedef struct FalcomXADemuxContext { + const AVClass *class; + unsigned frame_size; +} FalcomXADemuxContext; + +static av_cold +int falcom_xa_read_header(AVFormatContext *s) +{ + int sample_rate, bit_depth, channels; + AVStream *st; + AVIOContext *pb = s->pb; + + avio_seek(pb, 22, SEEK_SET); + channels = avio_rl16(pb); + if (channels != 2) + return AVERROR_INVALIDDATA; + + sample_rate = avio_rl32(pb); + if (sample_rate != 44100) + return AVERROR_INVALIDDATA; + + avio_seek(pb, 34, SEEK_SET); + bit_depth = avio_rl16(pb); + if (bit_depth != 16) + return AVERROR_INVALIDDATA; + + avio_seek(pb, 44, SEEK_SET); + + st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_MS; + st->codecpar->sample_rate = sample_rate; + st->codecpar->channels = channels; + st->codecpar->block_align = 2048; + + return 0; +} + +static +int falcom_xa_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + FalcomXADemuxContext *ctx = s->priv_data; + + if (ctx->frame_size == 0) { + unsigned tell = avio_tell(s->pb); + unsigned size = avio_rl32(s->pb); + av_log(ctx, AV_LOG_DEBUG, "read size %u (0x%x) at offset %u (0x%x)\n", + size, size, tell, tell); + if (size % 2048) + return AVERROR_INVALIDDATA; + ctx->frame_size = size; + avio_skip(s->pb, 4); // unknown bytes + } + + ctx->frame_size -= 2048; + return av_get_packet(s->pb, pkt, 2048); +} + +static const AVClass falcom_xa_demux_class = { + .class_name = "Falcom Xanadu demuxer", + .item_name = av_default_item_name, + .version = LIBAVUTIL_VERSION_INT, +}; + +AVInputFormat ff_falcom_xa_demuxer = { + .name = "falcom_xa", + .long_name = NULL_IF_CONFIG_SMALL("Falcom Xanadu demuxer"), + .priv_data_size = sizeof(FalcomXADemuxContext), + .read_header = falcom_xa_read_header, + .read_packet = falcom_xa_read_packet, + .priv_class = &falcom_xa_demux_class, +};