From patchwork Thu Jan 13 02:05: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: 33505 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp42696iog; Wed, 12 Jan 2022 18:43:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJys7AlI7KFBHU8Wxv2147mxlObGYWwv7CMjdQUZesdRLbV2hJF+ThirkpUCbtpwYv+1DCvb X-Received: by 2002:a17:906:318a:: with SMTP id 10mr1951364ejy.154.1642041837423; Wed, 12 Jan 2022 18:43:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642041837; cv=none; d=google.com; s=arc-20160816; b=Rs4xui1JJX3euWmAkNnBi6iwHHIVWWfMqPbuF4FRjR6oS8Bn1et5aO+loJ3sOvOLpH ueqSvYShNFWD0xhauxcQqPX7mU9c2p/oGbzRvUHG/mBz6Z1TGbeOzrL3vJvJxqIjxeIU 6hfQYmjnI9hwglTRJSZWtTdO7U6diQ7pRa52xINMsOim907wUa2dWcBEJbu6Q64OnYlI C5qbL3eD5sq11RvcVXAsuuGGyg42+b5U3OxQf/DMRrKUTPHiwJMUTNC6pGkDlfVAQ3nr quGw4JL6reCcB009pDZbE/xFBzlK6hszVClhAQeOpAzfrerbtrLHFOcoZNPaoOZDgUOf EaSA== 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=hNRPEmAsOO6gOB7E5WCjZA98FlpfQiNtCluH5ve/xH0=; b=MxT4Fospcs8Bs1Est2YFUD3ZXTRzk1PS1sR89UhwsxpNeJEAamzywGlmvsRyYoRp1M mCXkZZhAhGfg1Dhsh/7Rw8FmzXc1hDMLUZwE7xFB9b5zOM5nDCfngatq9pZBSTkPs0N6 5ZDRUjPrMmrvaiGXFc+ZWgAlLaYLMoaz0+ZXvdJT8QiuitK+Tm8kNWceagQVV1PnSFlY 6abE+zz6njTR+KFQc4BmepHxiYd1gG99FTaiEA3i1zU6/GlhHhU1qLRNkUPJzhnNsivV i/QNAzL7CeHYRX2u0jp6sygQmE8EfkYui0BFikZoOOswqK32Vedb5fF4BEwRsxSRDOJw SILA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=PrG+1tYg; 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 hb19si832147ejc.949.2022.01.12.18.43.57; Wed, 12 Jan 2022 18:43:57 -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=PrG+1tYg; 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 0A2DC68B92A; Thu, 13 Jan 2022 04:06:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D2B6B68B8F7 for ; Thu, 13 Jan 2022 04:06:04 +0200 (EET) Received: by mail-qk1-f181.google.com with SMTP id b127so5657709qkd.0 for ; Wed, 12 Jan 2022 18:06:04 -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=JdabDAtCUkW4BCil5CEYd7Jejxyo066RSonFZMwuX2A=; b=PrG+1tYgisV7w9AlXz1/ZGayYbFovj+rp42y5S2uIGXW31kLnq8OiAwizbu/+tKh0C anucdENXyM1MYm1sQsfdg4AVfRG2GY0oQuAb6DZ/Qb98dghhdSQMrJeyk3MQaKlk0qXL hxyNPRrTESuqYN67PiQdEk7n2Pt0tGBCqJGWrvEQDAbPhjakqj1+F01LuAvXCcYTG/ob U7ZwGWFGO5rTAQRm6hRC9E6rxHum0ayeuV/Hfn7ItWtpz+dV/IzAfrTeMexercYANh7G CF/iOveyVfc0kMtHJU6H+JF9KnxgNvNl0t81YyQ7gJOK289xDRFe1RI7S682s2u6+QOa 4Nhg== 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=JdabDAtCUkW4BCil5CEYd7Jejxyo066RSonFZMwuX2A=; b=quPCwddSNe2NvC1HsC0IKaLVKGhDqdjtqwiUiWDXHeCViQ2oVctOFBhYyLFDG3C7ZO vq7tgDdj31SqjmK9j6h2tJPzM1o5DJwSvlb5KvvE0pjBBRJoDxLXnTy503CaaWdTmKo9 AvmqiOPokbkrcwML3RDQS+fRzs/moahfToZ6HgC/vwtPekJgBl+eAAXourlTYm5ALIp0 jX/QHSyeBwwHFyXp/RWCx40+5QrdeoXfXMiL11PCfZ5QlTbeQZfefeNYHyduIIPgmFPF ExbdAlmyp2paSMlB9vSVXppqi21CNpLRXAekBqv0XEI/SYv6iBbZAsfnALhgsr41rRAA tsYg== X-Gm-Message-State: AOAM533x7GdT1AQyL8Gt8EKqiA1ho7hPqlOIRW2/8JQaivjSY0jsXUmS ykZ22eclFG1uGycfd1o2y9+yjWJYJxM= X-Received: by 2002:a05:620a:1a9d:: with SMTP id bl29mr1888581qkb.55.1642039563197; Wed, 12 Jan 2022 18:06:03 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id k9sm1264556qko.29.2022.01.12.18.06.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 18:06:02 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 23:05:15 -0300 Message-Id: <20220113020518.730-27-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 236/281] metasound: 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: yRLqt4u4TYLn From: Anton Khirnov Signed-off-by: Vittorio Giovara Signed-off-by: James Almer --- libavcodec/metasound.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/libavcodec/metasound.c b/libavcodec/metasound.c index 57851a43c5..32d5e153be 100644 --- a/libavcodec/metasound.c +++ b/libavcodec/metasound.c @@ -65,8 +65,9 @@ static void decode_ppc(TwinVQContext *tctx, int period_coef, int g_coef, const float *shape, float *speech) { const TwinVQModeTab *mtab = tctx->mtab; + int channels = tctx->avctx->ch_layout.nb_channels; int isampf = tctx->avctx->sample_rate / 1000; - int ibps = tctx->avctx->bit_rate / (1000 * tctx->avctx->channels); + int ibps = tctx->avctx->bit_rate / (1000 * channels); int width; float ratio = (float)mtab->size / isampf; @@ -75,7 +76,7 @@ static void decode_ppc(TwinVQContext *tctx, int period_coef, int g_coef, float pgain_base, pgain_step, ppc_gain; - if (tctx->avctx->channels == 1) { + if (channels == 1) { min_period = log2(ratio * 0.2); max_period = min_period + log2(6); } else { @@ -85,7 +86,7 @@ static void decode_ppc(TwinVQContext *tctx, int period_coef, int g_coef, period_range = max_period - min_period; period = min_period + period_coef * period_range / ((1 << mtab->ppc_period_bit) - 1); - if (tctx->avctx->channels == 1) + if (channels == 1) period = powf(2.0, period); else period = (int)(period * 400 + 0.5) / 400.0; @@ -103,7 +104,7 @@ static void decode_ppc(TwinVQContext *tctx, int period_coef, int g_coef, if (isampf == 22 && ibps == 32) width = (int)((2.0 / period + 1) * width + 0.5); - pgain_base = tctx->avctx->channels == 2 ? 25000.0 : 20000.0; + pgain_base = channels == 2 ? 25000.0 : 20000.0; pgain_step = pgain_base / ((1 << mtab->pgain_bit) - 1); ppc_gain = 1.0 / 8192 * twinvq_mulawinv(pgain_step * g_coef + pgain_step / 2, @@ -123,8 +124,9 @@ static void dec_bark_env(TwinVQContext *tctx, const uint8_t *in, int use_hist, int bark_n_coef = mtab->fmode[ftype].bark_n_coef; int fw_cb_len = mtab->fmode[ftype].bark_env_size / bark_n_coef; int idx = 0; + int channels = tctx->avctx->ch_layout.nb_channels; - if (tctx->avctx->channels == 1) + if (channels == 1) val = 0.5; for (i = 0; i < fw_cb_len; i++) for (j = 0; j < bark_n_coef; j++, idx++) { @@ -132,7 +134,7 @@ static void dec_bark_env(TwinVQContext *tctx, const uint8_t *in, int use_hist, (1.0 / 2048); float st; - if (tctx->avctx->channels == 1) + if (channels == 1) st = use_hist ? tmp2 + val * hist[idx] + 1.0 : tmp2 + 1.0; else @@ -167,7 +169,7 @@ static int metasound_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx, { TwinVQFrameData *bits; const TwinVQModeTab *mtab = tctx->mtab; - int channels = tctx->avctx->channels; + int channels = tctx->avctx->ch_layout.nb_channels; int sub; GetBitContext gb; int i, j, k, ret; @@ -276,6 +278,7 @@ static av_cold int metasound_decode_init(AVCodecContext *avctx) TwinVQContext *tctx = avctx->priv_data; uint32_t tag; const MetasoundProps *props = codec_props; + int channels; if (!avctx->extradata || avctx->extradata_size < 16) { av_log(avctx, AV_LOG_ERROR, "Missing or incomplete extradata\n"); @@ -291,7 +294,7 @@ static av_cold int metasound_decode_init(AVCodecContext *avctx) } if (props->tag == tag) { avctx->sample_rate = props->sample_rate; - avctx->channels = props->channels; + channels = props->channels; avctx->bit_rate = props->bit_rate * 1000; isampf = avctx->sample_rate / 1000; break; @@ -299,17 +302,17 @@ static av_cold int metasound_decode_init(AVCodecContext *avctx) props++; } - if (avctx->channels <= 0 || avctx->channels > TWINVQ_CHANNELS_MAX) { + if (channels <= 0 || channels > TWINVQ_CHANNELS_MAX) { av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %i\n", - avctx->channels); + channels); return AVERROR_INVALIDDATA; } - avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO - : AV_CH_LAYOUT_STEREO; + av_channel_layout_uninit(&avctx->ch_layout); + av_channel_layout_default(&avctx->ch_layout, channels); - ibps = avctx->bit_rate / (1000 * avctx->channels); + ibps = avctx->bit_rate / (1000 * channels); - switch ((avctx->channels << 16) + (isampf << 8) + ibps) { + switch ((channels << 16) + (isampf << 8) + ibps) { case (1 << 16) + ( 8 << 8) + 6: tctx->mtab = &ff_metasound_mode0806; break;