From patchwork Thu Jan 13 02:07:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33524 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp46004iog; Wed, 12 Jan 2022 18:50:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJymh4C/GkRFl5V1NkPQkWyEfQ6/aDuRaNpU2Oss3ZGXtPl5J1o6PaRj5Uct7jn/Xxb7xpEq X-Received: by 2002:a17:907:6d9b:: with SMTP id sb27mr384318ejc.222.1642042216492; Wed, 12 Jan 2022 18:50:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642042216; cv=none; d=google.com; s=arc-20160816; b=hSrm80jYZFLFd7An0zqqDf0phnP22OyIFcn8mBCziSvRDeGSP450tb02fm8IS6C++/ 9kDOIvVZHQf77xPH2ypi4CTXF55IzJ2AoYNJ2tUDMCfylxhVtF4SToud/3k0wMJpPAAB WF17NMYi8dtS5Sgq9A6lQdZG5V4FUMNFB3qFy4zgD+mKiLHVlf1LfIXutF2d0ixfXIgX V1V+UQDj9sWtZfzjm76WS1JmAFhzPeM3/ESb9L29xb2nExeZaoyswhufbLoayywtacHD 7ytna5N57oXNJgs6oVlVIqGsGIhAiETJmcH2qqL4YzMl3106nbqVZLf9DGTahwv2W05s eWZQ== 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=e/jfXOqgUYswjXOuNM+dZHdb6416GjkLvbcGH/MVJBU=; b=yJmAO8jhUYfs6EyzyexLw5buqBGdcczIED6oPccRnnpx8yR+4FpAWPp5Ge2UAtXPyo rygw0K1kkf+O+Cjh558IMhNaX+682Eae0k6FRPptspTL6YnkUn3O0SD5VwTElkUti+CU XkbvaZjAltzi+k4WYZzNXBkJjNmabrTZC/ea4KdVqbm0gsF5J9pr0LrYTDOkFnx4nQ4K 2PrIweEFvZCkLc0mv6/x2E4ah7Q/+RjdAp3KB3xcwUzV7Y6i4aRF/efVlo2NmQ2DKs+b swfkdNFWA9bdmbBFmXTOc+4YN0wdxwzJK8dwlmyduWkPZCynd1zT9GNx+lwJNqK0myuX Okig== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=jYsD2qGt; 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 lc10si728587ejc.549.2022.01.12.18.50.16; Wed, 12 Jan 2022 18:50:16 -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=jYsD2qGt; 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 7729D68BA32; Thu, 13 Jan 2022 04:08:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 013A668BA18 for ; Thu, 13 Jan 2022 04:07:59 +0200 (EET) Received: by mail-qt1-f169.google.com with SMTP id c7so1776607qtc.11 for ; Wed, 12 Jan 2022 18:07:59 -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=M3Vg69kZSNDXFg9TIoIg4Lj9w1jCfXlBy1ACHvQZiGU=; b=jYsD2qGtCVQM4uwNi7Lc/eFJZSJ8Gq4B5hRRioVBs87N/68p1dhgHLA1/gpge1Gfer x3rHA4oUtlRdY12fVu0NJ6nm5HijKQwdoLLvJyycVPVkZp8QJHqzjyvE0r6ISN8Fsdsw 47IEKOXRX+L2Nz7F1XONQAWKRd6nXpQanIFfiNpBt6HehYeI2U/Wv0mjL6FT+ueaAgqw wxP+cctXn4V8oq3/Qq+r8fUFsxt2wUARNVJacMGZ+HWz9p3lkJL/RFvfWk5UHcQdqSHo +HUEUZ+gZ9il3SoeJHIEg8jwvDu2iQ04Uf/slt5zJMpxv/FMZZCoZqKVQ2bbKFDwkHCc khOg== 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=M3Vg69kZSNDXFg9TIoIg4Lj9w1jCfXlBy1ACHvQZiGU=; b=l97jYnmr+lYOhbG6liWb+ZzyaTuLc9bpCxYZKco7H1+zxO8HFiD+Pq8uPL6xWJv9Np TuI+CA14EWGapx1stNTX1CmIhrPCRDrkXltC9Qb3uM4pkUHjrbQL5eIVhb1XBLLhwzA2 nsXQ+QrEj16+HKYXNrOK2osqZhUn5NblZazX1HBxsv+GPlklu5pUm+hVFT3sdqrddbT0 vM4ZeY0+38oNXbkZgq15IvwlvezAWGhGZU8Fa0f7VBOKuaBW4Hid6GxGE5ZMiyuVzeiv sWB7zBjc2VLnvZ3m4wD8CliVKlamD3aAQn+eD+qw1nqQrKVxk4clT5dZ6SAbywF/464/ LsRA== X-Gm-Message-State: AOAM531iPbG6qvbwPn6VEw9C/88135YWTtyBNeQOGypiVNQqR3IESPi3 XPnuzRO8mLnqln0zJr4hwpj2LAuI/Ew= X-Received: by 2002:ac8:5705:: with SMTP id 5mr2038307qtw.27.1642039678544; Wed, 12 Jan 2022 18:07:58 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id a16sm1085946qta.13.2022.01.12.18.07.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 18:07:58 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 23:07:08 -0300 Message-Id: <20220113020713.801-25-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 264/281] tta: 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: VDr+ou0wbVeL From: Anton Khirnov Signed-off-by: James Almer --- libavcodec/tta.c | 18 +++++++++++++----- libavcodec/ttaenc.c | 14 +++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/libavcodec/tta.c b/libavcodec/tta.c index 17b4ca9032..fed18451eb 100644 --- a/libavcodec/tta.c +++ b/libavcodec/tta.c @@ -113,7 +113,7 @@ static int allocate_buffers(AVCodecContext *avctx) return AVERROR(ENOMEM); } else s->decode_buffer = NULL; - s->ch_ctx = av_malloc_array(avctx->channels, sizeof(*s->ch_ctx)); + s->ch_ctx = av_malloc_array(avctx->ch_layout.nb_channels, sizeof(*s->ch_ctx)); if (!s->ch_ctx) { av_freep(&s->decode_buffer); return AVERROR(ENOMEM); @@ -156,9 +156,17 @@ static av_cold int tta_decode_init(AVCodecContext * avctx) } AV_WL64(s->crc_pass, tta_check_crc64(s->pass)); } - avctx->channels = s->channels = get_bits(&gb, 16); - if (s->channels > 1 && s->channels < 9) - avctx->channel_layout = tta_channel_layouts[s->channels-2]; + + s->channels = get_bits(&gb, 16); + + av_channel_layout_uninit(&avctx->ch_layout); + if (s->channels > 1 && s->channels < 9) { + av_channel_layout_from_mask(&avctx->ch_layout, tta_channel_layouts[s->channels-2]); + } else { + avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + avctx->ch_layout.nb_channels = s->channels; + } + avctx->bits_per_raw_sample = get_bits(&gb, 16); s->bps = (avctx->bits_per_raw_sample + 7) / 8; avctx->sample_rate = get_bits_long(&gb, 32); @@ -199,7 +207,7 @@ static av_cold int tta_decode_init(AVCodecContext * avctx) (s->last_frame_length ? 1 : 0); av_log(avctx, AV_LOG_DEBUG, "format: %d chans: %d bps: %d rate: %d block: %d\n", - s->format, avctx->channels, avctx->bits_per_coded_sample, avctx->sample_rate, + s->format, avctx->ch_layout.nb_channels, avctx->bits_per_coded_sample, avctx->sample_rate, avctx->block_align); av_log(avctx, AV_LOG_DEBUG, "data_length: %d frame_length: %d last: %d total: %d\n", s->data_length, s->frame_length, s->last_frame_length, total_frames); diff --git a/libavcodec/ttaenc.c b/libavcodec/ttaenc.c index addaf30bb5..5717ec22d1 100644 --- a/libavcodec/ttaenc.c +++ b/libavcodec/ttaenc.c @@ -56,7 +56,7 @@ static av_cold int tta_encode_init(AVCodecContext *avctx) s->bps = avctx->bits_per_raw_sample >> 3; avctx->frame_size = 256 * avctx->sample_rate / 245; - s->ch_ctx = av_malloc_array(avctx->channels, sizeof(*s->ch_ctx)); + s->ch_ctx = av_malloc_array(avctx->ch_layout.nb_channels, sizeof(*s->ch_ctx)); if (!s->ch_ctx) return AVERROR(ENOMEM); @@ -89,7 +89,7 @@ static int tta_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, TTAEncContext *s = avctx->priv_data; PutBitContext pb; int ret, i, out_bytes, cur_chan, res, samples; - int64_t pkt_size = frame->nb_samples * 2LL * avctx->channels * s->bps; + int64_t pkt_size = frame->nb_samples * 2LL * avctx->ch_layout.nb_channels * s->bps; pkt_alloc: cur_chan = 0, res = 0, samples = 0; @@ -98,13 +98,13 @@ pkt_alloc: init_put_bits(&pb, avpkt->data, avpkt->size); // init per channel states - for (i = 0; i < avctx->channels; i++) { + for (i = 0; i < avctx->ch_layout.nb_channels; i++) { s->ch_ctx[i].predictor = 0; ff_tta_filter_init(&s->ch_ctx[i].filter, ff_tta_filter_configs[s->bps - 1]); ff_tta_rice_init(&s->ch_ctx[i].rice, 10, 10); } - for (i = 0; i < frame->nb_samples * avctx->channels; i++) { + for (i = 0; i < frame->nb_samples * avctx->ch_layout.nb_channels; i++) { TTAChannel *c = &s->ch_ctx[cur_chan]; TTAFilter *filter = &c->filter; TTARice *rice = &c->rice; @@ -113,8 +113,8 @@ pkt_alloc: value = get_sample(frame, samples++, avctx->sample_fmt); - if (avctx->channels > 1) { - if (cur_chan < avctx->channels - 1) + if (avctx->ch_layout.nb_channels > 1) { + if (cur_chan < avctx->ch_layout.nb_channels - 1) value = res = get_sample(frame, samples, avctx->sample_fmt) - value; else value -= res / 2; @@ -176,7 +176,7 @@ pkt_alloc: if (k) put_bits(&pb, k, outval & (ff_tta_shift_1[k] - 1)); - if (cur_chan < avctx->channels - 1) + if (cur_chan < avctx->ch_layout.nb_channels - 1) cur_chan++; else cur_chan = 0;