From patchwork Thu Jan 13 02:07:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33529 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp46500iog; Wed, 12 Jan 2022 18:51:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJyfn8274n7dvOYq3HuHqeAxudxWmZEN+8TnaOwhVL1d3Sc2PlqEUj3ouI9N95FyuA6oRyaD X-Received: by 2002:a17:906:43c9:: with SMTP id j9mr2031676ejn.136.1642042284686; Wed, 12 Jan 2022 18:51:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642042284; cv=none; d=google.com; s=arc-20160816; b=ugP9lu6t91DXSjER/NmYDYotWjEI/cibLZupKLiwVJTLh6/vJlK5hj/A1KYQL4QGmJ f4zzVprpXhdmQEa25IZ49C0x1G2jacpLd6vweMruLBvyteLutyXiwE/JvrqK/HtE8G4k 9Gs3oYKbjCjQ3MNsmjBRRu2MQociXuuvc0gMN4BqaK5Z35eyK0Or0JyeJEg8+LaQvD0i 3Gn1u3upXzswUXlLRazE8zYTQo7bDVqNgxmzQzQxYo9xKCEVbVO4C493b22wGgLgj2sj Zw3pNh1GpyCHe+9eDidPNSJ5WCQX9T8HwMqjDXATRgU4AS5rvZkEix1n/d8CQ/OzZxox J70A== 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=eaP2fDWNvZIf4YDhU6+5zLb9f3O43weW167X08p8AT4=; b=QoPqg+cR6miNGUarMERTcddR985nIhwEYWRn6Dj6OavWZH4S9xOz96pGJ+nZAX7RQh Wy08nKvq2Szyrko5mw7HvQiFCjubi+zjhkNx6cmYxF/B1qnL7BKT5yJEzcw/X1X50kYs dTq90OEyHWfxdOz4DrBSgxBVN3TPBwM3U1ZPbHhIbfovW5o2LiQMF66H9fXo/v6stQz2 xXc2HLTq64oUuOFFxSl6DEaJSrHLU2RQYXjqGv7AXo9bjjrUE5sQUyvYjQD6+XnIQzQt La3KMG/pgUf0dgRh2l7LcVRI6/fi9sdwKagcU2nkgZeY8D//0vCG2FTKu0uoxtn61EWQ KOnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=DomrDXhK; 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 gc22si312829ejc.456.2022.01.12.18.51.24; Wed, 12 Jan 2022 18:51:24 -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=DomrDXhK; 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 A983868BA52; Thu, 13 Jan 2022 04:08:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 306C768BA3B for ; Thu, 13 Jan 2022 04:08:06 +0200 (EET) Received: by mail-qt1-f175.google.com with SMTP id v7so5341531qtw.13 for ; Wed, 12 Jan 2022 18:08:06 -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=A1lBuLwAChNLmX0KrzxvL+0h0Rjvk6pN70Jl4ILLMNk=; b=DomrDXhKj1fiysGzJx81K3r1kL7I2gf5tUXlB8ZT6piOfX5ZUtc5Zf1Nm6mbyS7Th6 Qcc81G01jkwy6k3HDVHvHHLV1Ro8LTQL78ckLkBzluDl6tJ81FHNtGW9b0KSbTmPib4u Y30hom373KOgymH+CoPNNgy607uE3ba/tHYGhyCz518kL9rGp8ZuGyTzh27RTyAvxVlG /S+oJvrQMxcVJa2mSxdCN95+5hv5xBKqogPlOJyr+lHPPT4PVm5+fZi1iV+3MxuH5naW WFn6/IYX83rbZ6VN1FWLFH0WKQXPYuiBS0bHr98E58zNPzFXGqjQ3Lney1VKRydgigPY GRFQ== 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=A1lBuLwAChNLmX0KrzxvL+0h0Rjvk6pN70Jl4ILLMNk=; b=vZvjAYS+IAU8zdy7eUrgCjRJVbUToz8aUoOSnHPQWkKN5A4K3ifMdxAATrln+PcyPt Y4sIP4gVWGlI0/LcsCu3wuvt3RrJQZ4Rc6AfNV+hSmDZW6hJh/YeaMRsXdYLbnUmKKOy PtbofJgve5rgaTbU3+qWkQoS+fTV54vGhocmFXh7wdyaMEJez1kOWabMHOaagUi10TPT MGUN0+uEH7x0OBNcUPBxmpVElXcm5GWGwp6w2NkZRjnu4P3EMdBi8czKdpdEKAr8FdQK y38VCnl32usr6AVlCIKppdgchCLK7yWs6Y0RAZT3MJVh999WdkCWAkJV73thYlR+p7Qi 62KA== X-Gm-Message-State: AOAM532futJuWzJ0BtvaLRxqCIx1ofrpFebGDzF0Jcv5bSG1VMPLNz7H mcSgKFkEmCUvLTGjNttoQsdFxMoYn8c= X-Received: by 2002:a05:622a:58b:: with SMTP id c11mr1968502qtb.470.1642039684644; Wed, 12 Jan 2022 18:08:04 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id a16sm1085946qta.13.2022.01.12.18.08.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 18:08:04 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 23:07:13 -0300 Message-Id: <20220113020713.801-30-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 269/281] wavpack: 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: Nsn/Tk6pgPpM From: Anton Khirnov Signed-off-by: Vittorio Giovara Signed-off-by: James Almer --- libavcodec/wavpack.c | 51 ++++++++++++++++++----------------------- libavcodec/wavpackenc.c | 29 ++++++++++++----------- 2 files changed, 37 insertions(+), 43 deletions(-) diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c index 6b2ec19bf1..e0350ce732 100644 --- a/libavcodec/wavpack.c +++ b/libavcodec/wavpack.c @@ -1412,25 +1412,23 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no, size = bytestream2_get_byte(&gb); chan |= (bytestream2_get_byte(&gb) & 0xF) << 8; chan += 1; - if (avctx->channels != chan) + if (avctx->ch_layout.nb_channels != chan) av_log(avctx, AV_LOG_WARNING, "%i channels signalled" - " instead of %i.\n", chan, avctx->channels); + " instead of %i.\n", chan, avctx->ch_layout.nb_channels); chmask = bytestream2_get_le24(&gb); break; case 5: size = bytestream2_get_byte(&gb); chan |= (bytestream2_get_byte(&gb) & 0xF) << 8; chan += 1; - if (avctx->channels != chan) + if (avctx->ch_layout.nb_channels != chan) av_log(avctx, AV_LOG_WARNING, "%i channels signalled" - " instead of %i.\n", chan, avctx->channels); + " instead of %i.\n", chan, avctx->ch_layout.nb_channels); chmask = bytestream2_get_le32(&gb); break; default: av_log(avctx, AV_LOG_ERROR, "Invalid channel info size %d\n", size); - chan = avctx->channels; - chmask = avctx->channel_layout; } break; case WP_ID_SAMPLE_RATE: @@ -1494,8 +1492,7 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no, } if (!wc->ch_offset) { - int new_channels = avctx->channels; - uint64_t new_chmask = avctx->channel_layout; + AVChannelLayout new_ch_layout = { 0 }; int new_samplerate; int sr = (s->frame_flags >> 23) & 0xf; if (sr == 0xf) { @@ -1512,36 +1509,32 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no, new_samplerate *= rate_x; if (multiblock) { - if (chan) - new_channels = chan; - if (chmask) - new_chmask = chmask; + if (chmask) { + av_channel_layout_from_mask(&new_ch_layout, chmask); + if (chan && new_ch_layout.nb_channels != chan) { + av_log(avctx, AV_LOG_ERROR, "Channel mask does not match the channel count\n"); + return AVERROR_INVALIDDATA; + } + } else + av_channel_layout_copy(&new_ch_layout, &avctx->ch_layout); } else { - new_channels = s->stereo ? 2 : 1; - new_chmask = s->stereo ? AV_CH_LAYOUT_STEREO : - AV_CH_LAYOUT_MONO; - } - - if (new_chmask && - av_get_channel_layout_nb_channels(new_chmask) != new_channels) { - av_log(avctx, AV_LOG_ERROR, "Channel mask does not match the channel count\n"); - return AVERROR_INVALIDDATA; + av_channel_layout_default(&new_ch_layout, s->stereo + 1); } /* clear DSD state if stream properties change */ - if (new_channels != wc->dsd_channels || - new_chmask != avctx->channel_layout || + if (new_ch_layout.nb_channels != wc->dsd_channels || + av_channel_layout_compare(&new_ch_layout, &avctx->ch_layout) || new_samplerate != avctx->sample_rate || !!got_dsd != !!wc->dsdctx) { - ret = wv_dsd_reset(wc, got_dsd ? new_channels : 0); + ret = wv_dsd_reset(wc, got_dsd ? new_ch_layout.nb_channels : 0); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Error reinitializing the DSD context\n"); return ret; } ff_thread_release_buffer(avctx, &wc->curr_frame); } - avctx->channels = new_channels; - avctx->channel_layout = new_chmask; + av_channel_layout_uninit(&avctx->ch_layout); + av_channel_layout_copy(&avctx->ch_layout, &new_ch_layout); avctx->sample_rate = new_samplerate; avctx->sample_fmt = sample_fmt; avctx->bits_per_raw_sample = orig_bpp; @@ -1558,7 +1551,7 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no, ff_thread_finish_setup(avctx); } - if (wc->ch_offset + s->stereo >= avctx->channels) { + if (wc->ch_offset + s->stereo >= avctx->ch_layout.nb_channels) { av_log(avctx, AV_LOG_WARNING, "Too many channels coded in a packet.\n"); return ((avctx->err_recognition & AV_EF_EXPLODE) || !wc->ch_offset) ? AVERROR_INVALIDDATA : 0; } @@ -1668,7 +1661,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data, buf_size -= frame_size; } - if (s->ch_offset != avctx->channels) { + if (s->ch_offset != avctx->ch_layout.nb_channels) { av_log(avctx, AV_LOG_ERROR, "Not enough channels coded in a packet.\n"); ret = AVERROR_INVALIDDATA; goto error; @@ -1678,7 +1671,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data, ff_thread_release_buffer(avctx, &s->prev_frame); if (s->modulation == MODULATION_DSD) - avctx->execute2(avctx, dsd_channel, s->frame, NULL, avctx->channels); + avctx->execute2(avctx, dsd_channel, s->frame, NULL, avctx->ch_layout.nb_channels); ff_thread_report_progress(&s->curr_frame, INT_MAX, 0); diff --git a/libavcodec/wavpackenc.c b/libavcodec/wavpackenc.c index dc4f4e303b..bc1049db0a 100644 --- a/libavcodec/wavpackenc.c +++ b/libavcodec/wavpackenc.c @@ -130,8 +130,8 @@ static av_cold int wavpack_encode_init(AVCodecContext *avctx) s->avctx = avctx; - if (avctx->channels > 255) { - av_log(avctx, AV_LOG_ERROR, "Invalid channel count: %d\n", avctx->channels); + if (avctx->ch_layout.nb_channels > 255) { + av_log(avctx, AV_LOG_ERROR, "Invalid channel count: %d\n", avctx->ch_layout.nb_channels); return AVERROR(EINVAL); } @@ -142,10 +142,10 @@ static av_cold int wavpack_encode_init(AVCodecContext *avctx) else block_samples = avctx->sample_rate; - while (block_samples * avctx->channels > WV_MAX_SAMPLES) + while (block_samples * avctx->ch_layout.nb_channels > WV_MAX_SAMPLES) block_samples /= 2; - while (block_samples * avctx->channels < 40000) + while (block_samples * avctx->ch_layout.nb_channels < 40000) block_samples *= 2; avctx->frame_size = block_samples; } else if (avctx->frame_size && (avctx->frame_size < 128 || @@ -2572,7 +2572,7 @@ static int wavpack_encode_block(WavPackEncodeContext *s, s->ch_offset += 1 + !(s->flags & WV_MONO); - if (s->ch_offset == s->avctx->channels) + if (s->ch_offset == s->avctx->ch_layout.nb_channels) s->flags |= WV_FINAL_BLOCK; bytestream2_init_writer(&pb, out, out_size); @@ -2587,11 +2587,12 @@ static int wavpack_encode_block(WavPackEncodeContext *s, bytestream2_put_le32(&pb, crc); if (s->flags & WV_INITIAL_BLOCK && - s->avctx->channel_layout != AV_CH_LAYOUT_MONO && - s->avctx->channel_layout != AV_CH_LAYOUT_STEREO) { + s->avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE && + s->avctx->ch_layout.u.mask != AV_CH_LAYOUT_MONO && + s->avctx->ch_layout.u.mask != AV_CH_LAYOUT_STEREO) { put_metadata_block(&pb, WP_ID_CHANINFO, 5); - bytestream2_put_byte(&pb, s->avctx->channels); - bytestream2_put_le32(&pb, s->avctx->channel_layout); + bytestream2_put_byte(&pb, s->avctx->ch_layout.nb_channels); + bytestream2_put_le32(&pb, s->avctx->ch_layout.u.mask); bytestream2_put_byte(&pb, 0); } @@ -2862,20 +2863,20 @@ static int wavpack_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, sizeof(int32_t) * s->block_samples); if (!s->samples[0]) return AVERROR(ENOMEM); - if (avctx->channels > 1) { + if (avctx->ch_layout.nb_channels > 1) { av_fast_padded_malloc(&s->samples[1], &s->samples_size[1], sizeof(int32_t) * s->block_samples); if (!s->samples[1]) return AVERROR(ENOMEM); } - buf_size = s->block_samples * avctx->channels * 8 - + 200 * avctx->channels /* for headers */; + buf_size = s->block_samples * avctx->ch_layout.nb_channels * 8 + + 200 * avctx->ch_layout.nb_channels /* for headers */; if ((ret = ff_alloc_packet(avctx, avpkt, buf_size)) < 0) return ret; buf = avpkt->data; - for (s->ch_offset = 0; s->ch_offset < avctx->channels;) { + for (s->ch_offset = 0; s->ch_offset < avctx->ch_layout.nb_channels;) { set_samplerate(s); switch (s->avctx->sample_fmt) { @@ -2885,7 +2886,7 @@ static int wavpack_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } fill_buffer(s, frame->extended_data[s->ch_offset], s->samples[0], s->block_samples); - if (avctx->channels - s->ch_offset == 1) { + if (avctx->ch_layout.nb_channels - s->ch_offset == 1) { s->flags |= WV_MONO; } else { s->flags |= WV_CROSS_DECORR;