From patchwork Thu Jan 13 02:02:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33465 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp38093iog; Wed, 12 Jan 2022 18:34:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJxqyymKzNZVLhUx3cJrt7vJ2LRXPQSmapaLcBbmv/5Bbh7fOf24lc6L8MMWOs73FO38NbdD X-Received: by 2002:a17:906:4453:: with SMTP id i19mr1896943ejp.305.1642041298818; Wed, 12 Jan 2022 18:34:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642041298; cv=none; d=google.com; s=arc-20160816; b=ClfvsfBcXnkiNnkKsRoqyVuoPxdD57VBS2umZMHg/Lz5hgZ5ITLhwCZh/Mp7ULxQ98 KnAjs/eAdoyO1xnsA7t9ypCDbOLIWGQ3DkdYF8KQa6eI0eA/yOdBqvcUL8OW2iX9Jo/p nRB7FUoRwoTdk93FgNXzr6GpG3Il37OHAWsVk47RQfDalr2YYUNbTDIgpy2PFoxVXHzY cXe89bsli1bZC3J/T/Ed2LQSmbhbOcF7Z/lmQKUf9TPxkj+a9uXCo15bev90Rqs+ujWG 8BzhC5O3TpYlLn5UhRDFcxFPrFkuuy0UoxlLwSddnns2XiHmuU94NlyscF5xshnsL+fD au7A== 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=fSG9+LjtHiGkRT28d4KdyBnObuGUNAUcEqWwSY2aedY=; b=ckeukxdidKICZ2rvM0sgx3gio/+BPih3kKM6V6sysEKX6Nk4w63Jjs2HgQOjE1HlNQ v4CNXV7RewuyeZWyd+E8BsfwelaCJ32r5T4Egfk3T965MTczauuYlVO1EQxfYHCRZ0OM doICnJkrw8XMrFaDtptupboOlN8gNyOBMq95wEzWc/oESdfVnpRI/iPiBd8mYmd3HkCC Y249gjDJ9jXQXxf8s9ebX90uEQkRdAahMOwIdD3uIo67Vr5C8F2d4QwY44QUAACQNZDl YpkAO/8BKJqnD8RNUMGK9e0jToj62tL8jWCzBuAnSccTNr4wdMvkwz96yh/y+vfPHEuO R9Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="Wd/beCnL"; 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 gz11si767521ejb.38.2022.01.12.18.34.58; Wed, 12 Jan 2022 18:34:58 -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="Wd/beCnL"; 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 982E968B635; Thu, 13 Jan 2022 04:03:17 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0ED6C68B5F4 for ; Thu, 13 Jan 2022 04:03:11 +0200 (EET) Received: by mail-qk1-f177.google.com with SMTP id j85so5613111qke.2 for ; Wed, 12 Jan 2022 18:03:11 -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=eAIyxwTElAOy4VD4nIxGNR9lb7H4i78+4F0rhyod/3E=; b=Wd/beCnLdWBf6lCHOJ5tLyHveb2r2YICzZc760VJna5x7EWlZ+ZZL7y6SCA1vY8D+Q 5K3e3BYJ0GAxrbtVGFOUVBVSA9RQOrMVkk9g49Qib0NbpQalco/xLSLLGDSaa5F8kxBc hWbC1AGUVDMh4q1qok2HtpazOQOF5XDTUF91kq9c9qyXj77Xn2M/JXxLNMSZwrNDgF2T C1F072aIGTt8Eixd59LjkhPXFut0VZqrtt8sP1RpYlsEULxtS9BcaOrTDJ5DK9iDQBSZ uZfH8RI8JTI5eW27AEJ7oIM1zujI4H7vbKuAZbszJRONkzAdmqsWchC1NnlGO6mAbdSi 9R+g== 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=eAIyxwTElAOy4VD4nIxGNR9lb7H4i78+4F0rhyod/3E=; b=luA5vCUkwddnc/YjkUZs+qh7Vk7pyyi1KN916q8d2vH+MbjblnW7KJULug6ALkiyGb GrRhN/RofMCMS+FaL6KWjgIfqJ996pYqNNjZyzvLZsOzQAO+zUMMAKzYO5gxME1SoA/V QtTfhWk2LfgXPbPHSSNG+n7mnvy21DxFr4DWS9Rzei/Ok7q2Uf20RvYyU7tAZ78eg8zQ T+pvhv79QowwyM7H0vmoQZxqxHANDu5MSQ1Ef3gLmQygMVkjUeu5HCpyVmuaFPPkb4Y0 5G3XFAvb1X3c0p0x6dcG3q8KM2mbu1xnF7Wl8Er64VK7hCBYz0QzNC3zj05Syu/Owvh/ yXAg== X-Gm-Message-State: AOAM530JXeOrVfy8zOwVckLZhzOYWtrXqp7p9Og4rAQGHAZn/0Aol/qz 3rmKtJZtY2YxbMLpkeKKtnP5/Rg0uS8= X-Received: by 2002:ae9:c00f:: with SMTP id u15mr1806330qkk.689.1642039390577; Wed, 12 Jan 2022 18:03:10 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id v1sm1045961qtc.95.2022.01.12.18.03.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 18:03:10 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 23:02:24 -0300 Message-Id: <20220113020242.661-12-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 191/281] atrac3: 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: 3XeZeFpmW9kg From: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavcodec/atrac3.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c index 2376a7cd02..772937f5a3 100644 --- a/libavcodec/atrac3.c +++ b/libavcodec/atrac3.c @@ -646,6 +646,7 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf, ATRAC3Context *q = avctx->priv_data; int ret, i, ch; uint8_t *ptr1; + int channels = avctx->ch_layout.nb_channels; if (q->coding_mode == JOINT_STEREO) { /* channel coupling mode */ @@ -655,9 +656,9 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf, const uint8_t *js_databuf; int js_pair, js_block_align; - js_block_align = (avctx->block_align / avctx->channels) * 2; /* block pair */ + js_block_align = (avctx->block_align / channels) * 2; /* block pair */ - for (ch = 0; ch < avctx->channels; ch = ch + 2) { + for (ch = 0; ch < channels; ch = ch + 2) { js_pair = ch/2; js_databuf = databuf + js_pair * js_block_align; /* align to current pair */ @@ -726,11 +727,11 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf, } else { /* single channels */ /* Decode the channel sound units. */ - for (i = 0; i < avctx->channels; i++) { + for (i = 0; i < channels; i++) { /* Set the bitstream reader at the start of a channel sound unit. */ init_get_bits(&q->gb, - databuf + i * avctx->block_align / avctx->channels, - avctx->block_align * 8 / avctx->channels); + databuf + i * avctx->block_align / channels, + avctx->block_align * 8 / channels); ret = decode_channel_sound_unit(q, &q->gb, &q->units[i], out_samples[i], i, q->coding_mode); @@ -740,7 +741,7 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf, } /* Apply the iQMF synthesis filter. */ - for (i = 0; i < avctx->channels; i++) { + for (i = 0; i < channels; i++) { float *p1 = out_samples[i]; float *p2 = p1 + 256; float *p3 = p2 + 256; @@ -757,24 +758,25 @@ static int al_decode_frame(AVCodecContext *avctx, const uint8_t *databuf, int size, float **out_samples) { ATRAC3Context *q = avctx->priv_data; + int channels = avctx->ch_layout.nb_channels; int ret, i; /* Set the bitstream reader at the start of a channel sound unit. */ init_get_bits(&q->gb, databuf, size * 8); /* single channels */ /* Decode the channel sound units. */ - for (i = 0; i < avctx->channels; i++) { + for (i = 0; i < channels; i++) { ret = decode_channel_sound_unit(q, &q->gb, &q->units[i], out_samples[i], i, q->coding_mode); if (ret != 0) return ret; - while (i < avctx->channels && get_bits_left(&q->gb) > 6 && show_bits(&q->gb, 6) != 0x28) { + while (i < channels && get_bits_left(&q->gb) > 6 && show_bits(&q->gb, 6) != 0x28) { skip_bits(&q->gb, 1); } } /* Apply the iQMF synthesis filter. */ - for (i = 0; i < avctx->channels; i++) { + for (i = 0; i < channels; i++) { float *p1 = out_samples[i]; float *p2 = p1 + 256; float *p3 = p2 + 256; @@ -879,8 +881,9 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) const uint8_t *edata_ptr = avctx->extradata; ATRAC3Context *q = avctx->priv_data; AVFloatDSPContext *fdsp; + int channels = avctx->ch_layout.nb_channels; - if (avctx->channels < MIN_CHANNELS || avctx->channels > MAX_CHANNELS) { + if (channels < MIN_CHANNELS || channels > MAX_CHANNELS) { av_log(avctx, AV_LOG_ERROR, "Channel configuration error!\n"); return AVERROR(EINVAL); } @@ -888,7 +891,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) /* Take care of the codec-specific extradata. */ if (avctx->codec_id == AV_CODEC_ID_ATRAC3AL) { version = 4; - samples_per_frame = SAMPLES_PER_FRAME * avctx->channels; + samples_per_frame = SAMPLES_PER_FRAME * channels; delay = 0x88E; q->coding_mode = SINGLE; } else if (avctx->extradata_size == 14) { @@ -904,18 +907,18 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) bytestream_get_le16(&edata_ptr)); // Unknown always 0 /* setup */ - samples_per_frame = SAMPLES_PER_FRAME * avctx->channels; + samples_per_frame = SAMPLES_PER_FRAME * channels; version = 4; delay = 0x88E; q->coding_mode = q->coding_mode ? JOINT_STEREO : SINGLE; q->scrambled_stream = 0; - if (avctx->block_align != 96 * avctx->channels * frame_factor && - avctx->block_align != 152 * avctx->channels * frame_factor && - avctx->block_align != 192 * avctx->channels * frame_factor) { + if (avctx->block_align != 96 * channels * frame_factor && + avctx->block_align != 152 * channels * frame_factor && + avctx->block_align != 192 * channels * frame_factor) { av_log(avctx, AV_LOG_ERROR, "Unknown frame/channel/frame_factor " "configuration %d/%d/%d\n", avctx->block_align, - avctx->channels, frame_factor); + channels, frame_factor); return AVERROR_INVALIDDATA; } } else if (avctx->extradata_size == 12 || avctx->extradata_size == 10) { @@ -939,7 +942,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) return AVERROR_INVALIDDATA; } - if (samples_per_frame != SAMPLES_PER_FRAME * avctx->channels) { + if (samples_per_frame != SAMPLES_PER_FRAME * channels) { av_log(avctx, AV_LOG_ERROR, "Unknown amount of samples per frame %d.\n", samples_per_frame); return AVERROR_INVALIDDATA; @@ -954,7 +957,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) if (q->coding_mode == SINGLE) av_log(avctx, AV_LOG_DEBUG, "Single channels detected.\n"); else if (q->coding_mode == JOINT_STEREO) { - if (avctx->channels % 2 == 1) { /* Joint stereo channels must be even */ + if (channels % 2 == 1) { /* Joint stereo channels must be even */ av_log(avctx, AV_LOG_ERROR, "Invalid joint stereo channel configuration.\n"); return AVERROR_INVALIDDATA; } @@ -1004,7 +1007,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) q->vector_fmul = fdsp->vector_fmul; av_free(fdsp); - q->units = av_calloc(avctx->channels, sizeof(*q->units)); + q->units = av_calloc(channels, sizeof(*q->units)); if (!q->units) return AVERROR(ENOMEM);