From patchwork Thu Jan 13 01:50:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33338 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp18969iog; Wed, 12 Jan 2022 18:03:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJzSwf61PYvBooRFiuDOpKUHOG61/U5C4iDi0sLW07gsP03V12Hss8ELsxN6Pf7U8OmG4yuC X-Received: by 2002:a05:6402:2787:: with SMTP id b7mr2258700ede.162.1642039400064; Wed, 12 Jan 2022 18:03:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642039400; cv=none; d=google.com; s=arc-20160816; b=kxr1LI04uFaDd3VzNvg9txh7P1OCzRQnShHPvYDAT92T4OkIg3XfbssgF5bkV37zQX Huy5zRwf/69U/uw5tpdGUqw5RvH/prEEYdDu11kS5JEknDhWQL1a6BoT0u9nQIVjh7m3 E4FgKtcXmqEwF9ZE+hpyKsOQxHdnWaWtWVk5/Gd0NeNPdOdXR3idINQDgotmF2qVT+V/ 2W1gWyPUFnTtHCv7k+DRfzsMLPQgSM681DgkZ+j2MrakBAHf5Jboxvq9uwuT73IpqXV5 W0w8+1dnsHkzBZ8J5un2uelvRbg3NrT4RbaYJZ3yB0r+bcOtsWuBPRQnX2/Xvqi2wAfJ WXkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=fAax/NMfaaPn9jb3poGsBX1O5cbiKBljmtqApttRfqQ=; b=KpgbxTfWEm8AyEAhoVdPMnapi1s0cCQPIHAQf0ymOWQalWyzFWnCYCkjAntnpYaNlD UGe6fagwVmSKoBkATWJDnmDRomnoQ/K1cWAggTuU7a44czNzIuCp++xUtSc1pBStc/No irPCSvOGfEpqvAVYuZosQYsouvSJ45IbkJz+OkJEgYvDLanHLDseCsKRTE0qRdDaLH5Y UbsvkOjyaiWRAY4cD9iRPAE6ZUVnNQTptf0okLd5Yg4WoAMNcTTBpzxfgA2ch772Uyan T9o2oLi20iQ0pC6dSnCw4Q+cpib6jzp6rTA+uVazt2V6Hqfj5Uxwg/IRhVS/w1FtMUrG Otzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=U69Acyls; 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 o5si779292ejy.62.2022.01.12.18.03.19; Wed, 12 Jan 2022 18:03:20 -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=U69Acyls; 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 8F85568B036; Thu, 13 Jan 2022 03:53:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BE52A68B0C5 for ; Thu, 13 Jan 2022 03:53:05 +0200 (EET) Received: by mail-qk1-f173.google.com with SMTP id z10so1202247qkf.7 for ; Wed, 12 Jan 2022 17:53:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=NWV7Yo2d5R++4InoGBcGe8GRs4S4hrv6kb3qCTi6+ao=; b=U69AcylsJnn2PCCmyQ7Q/s95/tfL/kUNh55d3VeGF1uVaZdWub3VaE7e/XvnDn2IPt L/LkEdx3acq0A6a09uY3DZ79T52h/fxPbsTzwsC0GKKRdpE4ndX9FMhJKQXdtRZpCWLd zyBeXAI4tTRKffbz1uGwCD40TRVCDKYVOLJQsBwDegCf1xmyBzNRG9cGldFrAElPsHhP GwkaEMXSwctl4TFfM/OnL4z78fGQqV59tY51dcXzoGh0LjZPlwqW9hyhoCTn5WxHdooR qZnwUV+OIJCOhk8bNlUrwLFJjfIndh3T0Hohz4MiasPbGzGi3pB+2qr/PWky37Ce8AR0 deAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NWV7Yo2d5R++4InoGBcGe8GRs4S4hrv6kb3qCTi6+ao=; b=x4wxyv52Rf0T+J1djh3BAVkspoCAPVF9LQR/tV3G2+YbxPj3rAbBwtqn0LbtZ0jLiX ZhFKdEyU41KkG3LmSDFO8ux563OL1v9oBv/Wz9vLjFpyEdQySevhT+0Ce9qwZqx+9Hct HyPTXIa1TBPonqpWMErCalYqtLpKsZsCinOK+alyq3wgD3C0w1XZ1KmJCDEZKBlCZsqC VujqdziyaEI3Nj6kUPW9Xlva5SxMzbYAuDFqxmH/HUbBASoP6rQ4+vGOMkd9aR09b1XI AEDdukulhFZgn87Fxo8b8v37Za6v5/FMxEwVxAPPnZrWzy/3gfnwgSaLs1LDhNHpw596 PBmA== X-Gm-Message-State: AOAM532guQh+GCXPA58UmxikMu2yAcp3xbAmtPDn9Z8rDFMjOYH7UDqS wLEgudc07cHIS2+xQxEpRduTwjLROdw= X-Received: by 2002:a37:ad0c:: with SMTP id f12mr1824497qkm.671.1642038783919; Wed, 12 Jan 2022 17:53:03 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id i21sm1204710qti.31.2022.01.12.17.53.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 17:53:03 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 22:50:15 -0300 Message-Id: <20220113015101.4-54-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220113015101.4-1-jamrial@gmail.com> References: <20220113015101.4-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 053/281] dsfdec: convert to new channel layout API 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: YJNdOfUkTEeo From: Anton Khirnov Signed-off-by: James Almer --- libavformat/dsfdec.c | 60 ++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/libavformat/dsfdec.c b/libavformat/dsfdec.c index 40c8210a0f..3c00b07ff1 100644 --- a/libavformat/dsfdec.c +++ b/libavformat/dsfdec.c @@ -38,15 +38,15 @@ static int dsf_probe(const AVProbeData *p) return AVPROBE_SCORE_MAX; } -static const uint64_t dsf_channel_layout[] = { - 0, - AV_CH_LAYOUT_MONO, - AV_CH_LAYOUT_STEREO, - AV_CH_LAYOUT_SURROUND, - AV_CH_LAYOUT_QUAD, - AV_CH_LAYOUT_4POINT0, - AV_CH_LAYOUT_5POINT0_BACK, - AV_CH_LAYOUT_5POINT1_BACK, +static const AVChannelLayout dsf_channel_layout[] = { + { .order = AV_CHANNEL_ORDER_UNSPEC }, + AV_CHANNEL_LAYOUT_MONO, + AV_CHANNEL_LAYOUT_STEREO, + AV_CHANNEL_LAYOUT_SURROUND, + AV_CHANNEL_LAYOUT_QUAD, + AV_CHANNEL_LAYOUT_4POINT0, + AV_CHANNEL_LAYOUT_5POINT0_BACK, + AV_CHANNEL_LAYOUT_5POINT1_BACK, }; static void read_id3(AVFormatContext *s, uint64_t id3pos) @@ -70,6 +70,7 @@ static int dsf_read_header(AVFormatContext *s) AVStream *st; uint64_t id3pos; unsigned int channel_type; + int channels; avio_skip(pb, 4); if (avio_rl64(pb) != 28) @@ -104,15 +105,22 @@ static int dsf_read_header(AVFormatContext *s) channel_type = avio_rl32(pb); if (channel_type < FF_ARRAY_ELEMS(dsf_channel_layout)) - st->codecpar->channel_layout = dsf_channel_layout[channel_type]; - if (!st->codecpar->channel_layout) + st->codecpar->ch_layout = dsf_channel_layout[channel_type]; + if (!st->codecpar->ch_layout.nb_channels) avpriv_request_sample(s, "channel type %i", channel_type); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; - st->codecpar->channels = avio_rl32(pb); + channels = avio_rl32(pb); + if (!st->codecpar->ch_layout.nb_channels) { + st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + st->codecpar->ch_layout.nb_channels = channels; + } else if (channels != st->codecpar->ch_layout.nb_channels) { + av_log(s, AV_LOG_ERROR, "Channel count mismatch\n"); + return AVERROR(EINVAL); + } st->codecpar->sample_rate = avio_rl32(pb) / 8; - if (st->codecpar->channels <= 0) + if (st->codecpar->ch_layout.nb_channels <= 0) return AVERROR_INVALIDDATA; switch(avio_rl32(pb)) { @@ -123,14 +131,15 @@ static int dsf_read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; } - dsf->audio_size = avio_rl64(pb) / 8 * st->codecpar->channels; + dsf->audio_size = avio_rl64(pb) / 8 * st->codecpar->ch_layout.nb_channels; st->codecpar->block_align = avio_rl32(pb); - if (st->codecpar->block_align > INT_MAX / st->codecpar->channels || st->codecpar->block_align <= 0) { + if (st->codecpar->block_align > INT_MAX / st->codecpar->ch_layout.nb_channels || + st->codecpar->block_align <= 0) { avpriv_request_sample(s, "block_align invalid"); return AVERROR_INVALIDDATA; } - st->codecpar->block_align *= st->codecpar->channels; - st->codecpar->bit_rate = st->codecpar->channels * 8LL * st->codecpar->sample_rate; + st->codecpar->block_align *= st->codecpar->ch_layout.nb_channels; + st->codecpar->bit_rate = st->codecpar->ch_layout.nb_channels * 8LL * st->codecpar->sample_rate; avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); avio_skip(pb, 4); @@ -152,6 +161,7 @@ static int dsf_read_packet(AVFormatContext *s, AVPacket *pkt) AVIOContext *pb = s->pb; AVStream *st = s->streams[0]; int64_t pos = avio_tell(pb); + int channels = st->codecpar->ch_layout.nb_channels; int ret; if (pos >= dsf->data_end) @@ -173,19 +183,19 @@ static int dsf_read_packet(AVFormatContext *s, AVPacket *pkt) if ((ret = av_new_packet(pkt, packet_size)) < 0) return ret; dst = pkt->data; - for (ch = 0; ch < st->codecpar->channels; ch++) { - ret = avio_read(pb, dst, packet_size / st->codecpar->channels); - if (ret < packet_size / st->codecpar->channels) + for (ch = 0; ch < st->codecpar->ch_layout.nb_channels; ch++) { + ret = avio_read(pb, dst, packet_size / st->codecpar->ch_layout.nb_channels); + if (ret < packet_size / st->codecpar->ch_layout.nb_channels) return AVERROR_EOF; dst += ret; - avio_skip(pb, skip_size / st->codecpar->channels); + avio_skip(pb, skip_size / st->codecpar->ch_layout.nb_channels); } pkt->pos = pos; pkt->stream_index = 0; - pkt->pts = (pos - si->data_offset) / st->codecpar->channels; - pkt->duration = packet_size / st->codecpar->channels; + pkt->pts = (pos - si->data_offset) / channels; + pkt->duration = packet_size / channels; return 0; } } @@ -194,8 +204,8 @@ static int dsf_read_packet(AVFormatContext *s, AVPacket *pkt) return ret; pkt->stream_index = 0; - pkt->pts = (pos - si->data_offset) / st->codecpar->channels; - pkt->duration = st->codecpar->block_align / st->codecpar->channels; + pkt->pts = (pos - si->data_offset) / channels; + pkt->duration = st->codecpar->block_align / channels; return 0; }