From patchwork Sun Jan 29 12:00:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 40168 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3ca3:b0:b9:1511:ac2c with SMTP id b35csp2702270pzj; Sun, 29 Jan 2023 04:01:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXsoruMui0nhujpzbxT+cqjddN+CPyM9juZ7MR8q/GJL21eRVZFFbIRM4QjYfjJjIryRAIhb X-Received: by 2002:a17:907:d40c:b0:872:af53:a028 with SMTP id vi12-20020a170907d40c00b00872af53a028mr49711738ejc.61.1674993663346; Sun, 29 Jan 2023 04:01:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674993663; cv=none; d=google.com; s=arc-20160816; b=vhP03POLc/aUk2ZMHhIr8aVBMCNCjHpb3k2iO90axtHXerMsYBmhstPzwY/wwCBkRd lTfASNGOMZpIxNzodd1OVqQLh6Wd4NUBGPLA+5cmnEHch5jvd9abJ9u4QRtHHGrvau/f TUhu/zRKNz8q2NO09GUvqbWdxBb0Ggd/wNW74iSWYicnRX3k/0UWX9XU4losLZrf4b4f bweRlLmEcYC4A+F9hlUbOoxEWFteYukHEbz21I9VOnp7mlTCExXfRGAz1ld+eACRj2s1 PV99s5f6kORdMrFLIRAUFLbRrELhzLwLy81LJqpT6Ts0yyvCfKJW2N+aj0rhI7pJkU9b NeWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:mime-version:dkim-signature:delivered-to; bh=tVqzjT485M3p7XhuZcD5m/SIcNgiY+iwwyXPeC0MW9c=; b=R5KKrs6OR+a067eO2Bd18HVajvfBXKn0dCwVh/n/9zfdN6wTyJtRuSuBBjn3n8kR9n qgwgCWMrkm9p312KCeYmOvZTRjPtnQEXwuIqF3DvT0WtNLCd1vjW2Igng+fXUP7kOerK knkB9lg/NUhNWsrH54tpBw1F2pu2+1GntK63Vr/gqBEDeMXvBs34cXEKXikH45FegS4u zj92UHszvdkQTNJi23TonT1LSKWAAUTxVQ73y7m+qy1bPsaAuZCZUuLq39bQiFElDPs5 3+rH20bCXo0uTVmYNuuCSV3R0ne7qpWn97TMQ+D5IQs2FTA8vEK4DtfO1QzOYv33ldRI z6WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=dw1PlyxW; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id c16-20020a17090620d000b0078d20d71475si15626595ejc.413.2023.01.29.04.00.38; Sun, 29 Jan 2023 04:01:03 -0800 (PST) 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 header.s=20210112 header.b=dw1PlyxW; 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=QUARANTINE 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 938C568BC90; Sun, 29 Jan 2023 14:00:34 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-vs1-f43.google.com (mail-vs1-f43.google.com [209.85.217.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D6E7968B213 for ; Sun, 29 Jan 2023 14:00:27 +0200 (EET) Received: by mail-vs1-f43.google.com with SMTP id k6so9802257vsk.1 for ; Sun, 29 Jan 2023 04:00:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=lUhLNTqvdj98QWI5BNQ3p4jMZCsrlW4X85DC2D/bbyg=; b=dw1PlyxWsKQRhC259YnHb9N7AQo+Ja4b/pQ5YIEaAOKppISJk5Q2ViW5JiuHfZOBNd m2HGjI15z70euPN5vT8bVxpgtCmOQbnwE5/i5OiLgDX6gELhV9Zb5KElIgI75wCy9P+m Ss2ADIcwAj709e8dhud+sFk0WlH0tzc9naU2gCoLGe7w83zSW6XmJdAry0v703B7s8Gr 2erQoBdhuLNBtF6ALk+3WbA2+vr3wO1VCenS4v1KeEbaEUM+8k4Yp4MhfZK+7QDJuUyI NtFBPqsj6ijx3DY5dqu2jNqHwGzfuO9sljx37uXdbw0WOni3/Dtslj+7oEuEmbPhA8tt kRPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=lUhLNTqvdj98QWI5BNQ3p4jMZCsrlW4X85DC2D/bbyg=; b=2n6fRw85d5vNYlh8frAge+M1jVQXjSPT4eFB815Y16Y91LNXexffYrFUa7+PwqJv8p G1zrP4l6oRRIbO0Kaf+cpGl2ntVWqOMtSblclwa/mA31+X6Z4qmMuwhrRIj0o8qSMT+l juBELSZReWszjn4Hi8xH3+MCsWLIEoy/BoJJ+x6KH4qKCtRG2rPccOu3ypC5ir2xIywy UgFNLqm+IFmqYPPVKn0h6XrbQ/jaYmz1hBlObCo72ST7JjCz6rB0TxiSo7bsKEZcQEex jpsk8KoyvWp5usuaQsFRw+YSIBt5tj4t+iMRO6wMkZQl4C9BivkxH5fCK1uUq8SXfe2e XQ/w== X-Gm-Message-State: AO0yUKX6DZ9rLY2fRGHnTFP/ueLYfWyDhSaxJJQgLVaIK4J3arh+9A/L a3MWcm25omA9XpDLDN/FtZYwCCBulBZYjeWvoczV56IP X-Received: by 2002:a05:6102:3550:b0:3f1:7158:eebd with SMTP id e16-20020a056102355000b003f17158eebdmr631951vss.15.1674993626145; Sun, 29 Jan 2023 04:00:26 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a05:612c:2428:b0:32a:5eaa:92e4 with HTTP; Sun, 29 Jan 2023 04:00:24 -0800 (PST) From: Paul B Mahol Date: Sun, 29 Jan 2023 13:00:24 +0100 Message-ID: To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH] Waveform Archiver decoder and demuxer 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: KmfDMjwSrzkK Patches attached From b54f2ba1e206bff2ef5d9e8882cbdce4a5fbccc4 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sat, 21 Jan 2023 19:17:38 +0100 Subject: [PATCH 2/2] avformat: add WavArc demuxer Signed-off-by: Paul B Mahol --- libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/wavarc.c | 127 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 libavformat/wavarc.c diff --git a/libavformat/Makefile b/libavformat/Makefile index 2d11bcd7a3..9052b023a7 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -598,6 +598,7 @@ OBJS-$(CONFIG_VQF_DEMUXER) += vqf.o OBJS-$(CONFIG_W64_DEMUXER) += wavdec.o w64.o pcm.o OBJS-$(CONFIG_W64_MUXER) += wavenc.o w64.o OBJS-$(CONFIG_WADY_DEMUXER) += wady.o pcm.o +OBJS-$(CONFIG_WAVARC_DEMUXER) += wavarc.o rawdec.o OBJS-$(CONFIG_WAV_DEMUXER) += wavdec.o pcm.o OBJS-$(CONFIG_WAV_MUXER) += wavenc.o OBJS-$(CONFIG_WC3_DEMUXER) += wc3movie.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index bf8afe2078..7c01c7f098 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -480,6 +480,7 @@ extern const AVInputFormat ff_vqf_demuxer; extern const AVInputFormat ff_w64_demuxer; extern const AVOutputFormat ff_w64_muxer; extern const AVInputFormat ff_wady_demuxer; +extern const AVInputFormat ff_wavarc_demuxer; extern const AVInputFormat ff_wav_demuxer; extern const AVOutputFormat ff_wav_muxer; extern const AVInputFormat ff_wc3_demuxer; diff --git a/libavformat/wavarc.c b/libavformat/wavarc.c new file mode 100644 index 0000000000..a475c85f8e --- /dev/null +++ b/libavformat/wavarc.c @@ -0,0 +1,127 @@ +/* + * WavArc demuxer + * Copyright (c) 2023 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/channel_layout.h" +#include "libavutil/intreadwrite.h" +#include "avformat.h" +#include "demux.h" +#include "internal.h" +#include "rawdec.h" + +static int wavarc_probe(const AVProbeData *p) +{ + int len = p->buf[0]; + uint32_t id; + + if (len == 0 || len + 6 >= p->buf_size) + return 0; + + if (p->buf[len + 1] != 0) + return 0; + + id = AV_RL32(p->buf + len + 2); + if (id != MKTAG('1','D','I','F') && + id != MKTAG('2','S','L','P') && + id != MKTAG('3','N','L','P') && + id != MKTAG('4','A','L','P') && + id != MKTAG('5','E','L','P')) + return 0; + + return AVPROBE_SCORE_MAX / 3 * 2; +} + +static int wavarc_read_header(AVFormatContext *s) +{ + AVIOContext *pb = s->pb; + AVCodecParameters *par; + int filename_len, fmt_len, ret; + uint8_t data[36]; + AVStream *st; + uint32_t id; + + filename_len = avio_r8(pb); + if (filename_len == 0) + return AVERROR_INVALIDDATA; + avio_skip(pb, filename_len); + if (avio_r8(pb)) + return AVERROR_INVALIDDATA; + id = avio_rl32(pb); + if (avio_read(pb, data, sizeof(data)) != sizeof(data)) + return AVERROR(EIO); + fmt_len = AV_RL32(data + 32); + if (fmt_len < 12) + return AVERROR_INVALIDDATA; + + st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + par = st->codecpar; + + ret = ff_alloc_extradata(par, fmt_len + sizeof(data)); + if (ret < 0) + return ret; + memcpy(par->extradata, data, sizeof(data)); + avio_read(pb, par->extradata + sizeof(data), fmt_len); + + par->codec_type = AVMEDIA_TYPE_AUDIO; + par->codec_id = AV_CODEC_ID_WAVARC; + par->codec_tag = id; + + do { + id = avio_rl32(pb); + if (id != MKTAG('d','a','t','a')) + avio_skip(pb, avio_rl32(pb)); + } while (id != MKTAG('d','a','t','a')); + avio_skip(pb, 4); + + if (AV_RL32(par->extradata + 16) != MKTAG('R','I','F','F')) + return AVERROR_INVALIDDATA; + if (AV_RL32(par->extradata + 24) != MKTAG('W','A','V','E')) + return AVERROR_INVALIDDATA; + if (AV_RL32(par->extradata + 28) != MKTAG('f','m','t',' ')) + return AVERROR_INVALIDDATA; + + av_channel_layout_uninit(&par->ch_layout); + av_channel_layout_default(&par->ch_layout, AV_RL16(par->extradata + 38)); + par->sample_rate = AV_RL32(par->extradata + 40); + avpriv_set_pts_info(st, 64, 1, par->sample_rate); + st->start_time = 0; + + switch (par->extradata[36]) { + case 0: par->format = AV_SAMPLE_FMT_U8P; break; + case 1: par->format = AV_SAMPLE_FMT_S16P; break; + } + + return 0; +} + +const AVInputFormat ff_wavarc_demuxer = { + .name = "wavarc", + .long_name = NULL_IF_CONFIG_SMALL("Waveform Archiver"), + .read_probe = wavarc_probe, + .read_packet = ff_raw_read_partial_packet, + .flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK | AVFMT_NOTIMESTAMPS, + .read_header = wavarc_read_header, + .extensions = "wa", + .raw_codec_id = AV_CODEC_ID_WAVARC, + .priv_data_size = sizeof(FFRawDemuxerContext), + .priv_class = &ff_raw_demuxer_class, +}; -- 2.39.1