From patchwork Fri Apr 23 22:35:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan Richmond X-Patchwork-Id: 27228 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:5014:0:0:0:0:0 with SMTP id e20csp1929222iob; Fri, 23 Apr 2021 15:36:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxf6xfjzzhNwJIvpAi10hTk9ZGOtoTBE5KXG08sK75SbEAfKcbzlJrsd7bVRkboSddr/NK0 X-Received: by 2002:a05:6402:518c:: with SMTP id q12mr7159682edd.11.1619217394705; Fri, 23 Apr 2021 15:36:34 -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 o6si7891661edi.504.2021.04.23.15.36.34; Fri, 23 Apr 2021 15:36:34 -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; arc=fail (body hash mismatch); 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=hotmail.co.uk Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7ADAD689E05; Sat, 24 Apr 2021 01:36:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-oln040092068074.outbound.protection.outlook.com [40.92.68.74]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9BF58680157 for ; Sat, 24 Apr 2021 01:36:17 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZIMRUDyCA/7Cn5DkN37Jn6PGCHJ+z+oR9hklzOghM5YRcUGT5RUzI0p7oWLohMJztDb+isfTvuA3ZmB9MvatjmkZ7NGR+tdq/NtnUbWWE3SsskxwYpKr3zW3zpGaiog9Cmy2n4tmYs7z/ef9S4erNqAv6KUI8g+B/tj0EmNqFSM961VY+b4vK3JWRdUpBwiNbt74G15huDR1abU4nJvOAu5i3RHdpgY2xZePXycSPeeQlbbVog9s47/YMe8jGRarxJyKjtwj1n92LOeT2EOj8itE6Rt1AcGSMf5ZAFxvzikEvF2CEbRkY2JYQfD94Q47nBOOMP22TyUFnvYpOKvJAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hnFbXWxoWD5sql5Uy8ZVfYTn67jcMNiajQbwWOZfYD8=; b=Sjvwzo+8IJeROUHiJbKO0z95N0/Ao65RWXCqUlgv80Wxh5kwQEzqcMFkPAPGC77058YdmxMo5/zzIunFx/3OrDqfg/o6wIaO7qPWVI7d3MAI9OAQ/4ons/PtCu36clxXjhK+59Q7Llgvfsi2ih+bvtOyyGMkDRgN/IxI8FDniNYyigWnD1LqsF6Xj7vbaj2tyQ8lCRvcQAZc3pEBhUapSnRE2UVQCr7qZfQxSBMKkw15DMePm2V5UItkeV8ajjpDUa47dnbGMY4J9lBB2aOT0Oblw1wF95xq+zB3NyZl9/d9feWHwlILnSatMYKlghZm938x5JylQKr8bKw7tob85g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from VE1EUR02FT007.eop-EUR02.prod.protection.outlook.com (2a01:111:e400:7e1e::53) by VE1EUR02HT178.eop-EUR02.prod.protection.outlook.com (2a01:111:e400:7e1e::428) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Fri, 23 Apr 2021 22:36:16 +0000 Received: from AM9PR09MB5170.eurprd09.prod.outlook.com (2a01:111:e400:7e1e::48) by VE1EUR02FT007.mail.protection.outlook.com (2a01:111:e400:7e1e::133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21 via Frontend Transport; Fri, 23 Apr 2021 22:36:16 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:3754F228AAFA393CE5AAB556DD6F21F577A1B6A71F790ACE12537B41059128B7; UpperCasedChecksum:FA0563475979CCD6EE92A88EBE40C46709033ACB4E63710E74AFC75E991CB882; SizeAsReceived:7421; Count:46 Received: from AM9PR09MB5170.eurprd09.prod.outlook.com ([fe80::4545:9b8c:a216:3436]) by AM9PR09MB5170.eurprd09.prod.outlook.com ([fe80::4545:9b8c:a216:3436%3]) with mapi id 15.20.4065.021; Fri, 23 Apr 2021 22:36:16 +0000 From: Aidan Richmond To: ffmpeg-devel@ffmpeg.org Date: Fri, 23 Apr 2021 23:35:45 +0100 Message-ID: X-Mailer: git-send-email 2.16.1.windows.1 In-Reply-To: <20210423223545.29960-1-aidan.is@hotmail.co.uk> References: <20210423223545.29960-1-aidan.is@hotmail.co.uk> X-TMN: [besdP7KaAFELcrojFbnexT2l6dMRKdG7] X-ClientProxiedBy: LO2P265CA0502.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:13b::9) To AM9PR09MB5170.eurprd09.prod.outlook.com (2603:10a6:20b:301::8) X-Microsoft-Original-Message-ID: <20210423223545.29960-2-aidan.is@hotmail.co.uk> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (86.28.139.128) by LO2P265CA0502.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:13b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.4042.19 via Frontend Transport; Fri, 23 Apr 2021 22:36:15 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 46 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 5ab39971-e05d-4142-5e6a-08d906a834b3 X-MS-Exchange-SLBlob-MailProps: pt8ZUcDWjMUy3FwHp8phSqozv79zc9q9JVO9foaTpVMg5OhZaeOHlcUjNHipnVrcg1LlOr2GY6nfRZDIvhTcIwoIRjwqmYNiBFQWletX8Csq27Iyi1WjuRIoI0GHLShSW/H8F68c61WFkSMjUMHh2GdWqlWOeBTkWB1ilIwx3qFSsV5R2Z9kwIlQmeB6VBtg0zRZrX5TX01cFyCd8xffxufuu126v9Duc2lXQMQ+2K2QV/LG83cEsLQUmtwndaPM9XyHYaS0eSobH38tz4KlgKNl73tUpS9ZmR1T0DhIvgRBwJImujmDFp02iPmDfdcpJzCzEagzB7UhqB+072hLamwuaBB7LRyMaaTtjITbdvLCLtHZdSQi8mzAY3vMP1swGDrOzw0aduxLmJesZVKOVRQQmGL3RDXKxz3jp4QvfjgofFg9aZn7PciPcWIdffSHsmgGrXZnvg73CK8pPSpkSxuc3b5iM+ZkZU9nxhmzY1L28fmSiHItTXEd1koQ9c9wB+Xe26i9TgUJbe9H/Hfz4Pn1lTSpes8h6IwMTbdxS49hEbmodj92aaCMoK7JWhBjLG9kOjz/FP48tvZV9m4UuTqruPQYTuc3CCgvngc0fhtyk5Mm5408frc+CYp7yc61GBla0iPpHwjLUZ/YQ9Qu9R/EfFVZVxf4QNjYWNsyUkTVJ/gkOcqP7m5JEUgeJR0zDcpqQOvxMqyUDGEJWI6bpOvrtdoqhYKBbVgnmAi2wQ/F//oPRvFyU105jBCf3yucg5tH8y7QRsvmpX4ZXZkl9yDvY311lqDPSFoIYGGqX3wPxZjo8wX6w1ist1yOrP27pAxwchCTQn6c1YNfMaMd4QqfFwlA4Yq8DvW8VytZadD1R1Lbbz4MrQ/UrjkP/VhGGxzHOQjxIYcwKN67ghkc7O6OR/2r5c1NO42GpFE4dtsM6PYxfIGlxh+TydW6vRiH X-MS-TrafficTypeDiagnostic: VE1EUR02HT178: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ODW4cKziau4SKIPkbp3HN9jNBWsdBaqYh70QsGVdCXgEcHuzPDSRau0QY2/NnZmGDNa8Ps6sV6bBevK+LF2wJIMgoMjgNIysMwXKP2Pg5hBkGz79nDrfOpqW2+KeJH6bZayHG1Kq433KGTYa4PL7l2Ummst6A59V12u1wnQ2+4+0/Z7WkJZRF+kVeDjDhicjY4LghUBE819SIcx5N4h6IMgWBiAOyuuhr7IfK5gQ3QJlfumVYPF4RY5TrVH4C5Rqx98Dr9EwIXYUN/ek1MiPKhezUiiLz/5aXVj9xF8zWNbqDdEGspxwsgdiOzhxvfbLgww1Ntp2dyxPik2lf5djFwDFa2Bn77vrOdUEgy4mP0qBXh37JAvKbgTw6y6hpswzVccYIGsFoA4pIEH4/UKH+vd8erifhCfR0yYrZe0ATgU= X-MS-Exchange-AntiSpam-MessageData: JrM/Y4y78LJz14qjwLqM0PWKGRUw+rtZREYoDS/x9GtUovmhVlCoGc3ZTrKk53IFnSVoWTjyvf6XUGzo6vtYWhhc9vR35y6ZuRIPGlwWkda5EYZDXSixqCGfZHD5QIyCEaVwaZ1JUVL1lOs6eKjFqg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5ab39971-e05d-4142-5e6a-08d906a834b3 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2021 22:36:16.0547 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: VE1EUR02FT007.eop-EUR02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR02HT178 Subject: [FFmpeg-devel] [PATCH v2 2/2] avformat/westwoodaudenc: Adds muxer for Westwood AUD format. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Aidan Richmond Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: i0d0xAGayPh5 Format is still used by modders of these old games. --- libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/westwood_audenc.c | 129 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 libavformat/westwood_audenc.c diff --git a/libavformat/Makefile b/libavformat/Makefile index bc1ddfa81c..85b5d8e7eb 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -581,6 +581,7 @@ OBJS-$(CONFIG_WEBP_MUXER) += webpenc.o OBJS-$(CONFIG_WEBVTT_DEMUXER) += webvttdec.o subtitles.o OBJS-$(CONFIG_WEBVTT_MUXER) += webvttenc.o OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood_aud.o +OBJS-$(CONFIG_WSAUD_MUXER) += westwood_audenc.o OBJS-$(CONFIG_WSD_DEMUXER) += wsddec.o rawdec.o OBJS-$(CONFIG_WSVQA_DEMUXER) += westwood_vqa.o OBJS-$(CONFIG_WTV_DEMUXER) += wtvdec.o wtv_common.o \ diff --git a/libavformat/allformats.c b/libavformat/allformats.c index fa093c7ac2..fe70a1e9a2 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -478,6 +478,7 @@ extern AVOutputFormat ff_webp_muxer; extern AVInputFormat ff_webvtt_demuxer; extern AVOutputFormat ff_webvtt_muxer; extern AVInputFormat ff_wsaud_demuxer; +extern AVOutputFormat ff_wsaud_muxer; extern AVInputFormat ff_wsd_demuxer; extern AVInputFormat ff_wsvqa_demuxer; extern AVInputFormat ff_wtv_demuxer; diff --git a/libavformat/westwood_audenc.c b/libavformat/westwood_audenc.c new file mode 100644 index 0000000000..e381aa9a1a --- /dev/null +++ b/libavformat/westwood_audenc.c @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2021 Aidan Richmond + * + * 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 + */ + +/** + * @file + * Westwood Studios AUD file muxer + * by Aidan Richmond (aidan.is@hotmail.co.uk) + * + * This muxer supports IMA ADPCM packed in westwoods format. + * + * @see http://xhp.xwis.net/documents/aud3.txt + */ + +#include "libavutil/avassert.h" + +#include "avformat.h" +#include "avio_internal.h" +#include "internal.h" +#include + +#define AUD_CHUNK_SIGNATURE 0x0000DEAF + +typedef struct AUDMuxContext { + int uncomp_size; + int size; +} AUDMuxContext; + +static int wsaud_write_header(AVFormatContext *ctx) +{ + AVStream *st = ctx->streams[0]; + AVIOContext *pb = ctx->pb; + AUDMuxContext *a = ctx->priv_data; + unsigned char flags = 0; + + if (st->codecpar->codec_id != AV_CODEC_ID_ADPCM_IMA_WS) { + av_log(st, AV_LOG_ERROR, "%s codec not supported for Westwood AUD.\n", + avcodec_get_name(st->codecpar->codec_id)); + return -1; + } + + if (ctx->nb_streams != 1) { + av_log(st, AV_LOG_ERROR, "AUD files have exactly one stream\n"); + return AVERROR(EINVAL); + } + + a->uncomp_size = 0; + a->size = 0; + + /* Flag if we have stereo data. */ + if (st->codecpar->channels == 2) + flags |= 1; + + /* This flags that the file contains 16 bit samples rather than 8 bit + since the encoder only encodes 16 bit samples this should be set. */ + if (av_get_bits_per_sample(st->codecpar->codec_id) == 4) + flags |= 2; + + avio_wl16(pb, st->codecpar->sample_rate); + /* We don't know the file size yet, so just zero 8 bytes */ + ffio_fill(pb, 0, 8); + avio_w8(pb, flags); + /* 99 indicates the ADPCM format. Other formats not supported. */ + avio_w8(pb, 99); + + return 0; +} + +static int wsaud_write_packet(AVFormatContext *ctx, AVPacket *pkt) +{ + AVIOContext *pb = ctx->pb; + AUDMuxContext *a = ctx->priv_data; + + av_assert1(pkt->size < UINT16_MAX && (pkt->size * 4) < UINT16_MAX); + /* Assumes ADPCM since this muxer doesn't support SND1 or PCM format. */ + avio_wl16(pb, pkt->size); + avio_wl16(pb, pkt->size * 4); + avio_wl32(pb, AUD_CHUNK_SIGNATURE); + avio_write(pb, pkt->data, pkt->size); + a->size += pkt->size + 8; + a->uncomp_size += pkt->size * 4; + + return 0; +} + +static int wsaud_write_trailer(AVFormatContext *ctx) +{ + AVIOContext *pb = ctx->pb; + AUDMuxContext *a = ctx->priv_data; + + if(!pb->seekable) { + av_log(ctx->streams[0], AV_LOG_ERROR, "Cannot seek to write file size to header."); + return -1; + } + + avio_seek(pb, 2, SEEK_SET); + avio_wl32(pb, a->size); + avio_wl32(pb, a->uncomp_size); + + return 0; +} + +AVOutputFormat ff_wsaud_muxer = { + .name = "wsaud", + .long_name = NULL_IF_CONFIG_SMALL("Westwood Studios audio"), + .extensions = "aud", + .priv_data_size = sizeof(AUDMuxContext), + .audio_codec = AV_CODEC_ID_ADPCM_IMA_WS, + .video_codec = AV_CODEC_ID_NONE, + .write_header = wsaud_write_header, + .write_packet = wsaud_write_packet, + .write_trailer = wsaud_write_trailer, +};