From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 7897444A88 for ; Mon, 31 Oct 2022 22:30:20 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 68E1668BE20; Tue, 1 Nov 2022 00:30:18 +0200 (EET) Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DA77C68BB65 for ; Tue, 1 Nov 2022 00:30:12 +0200 (EET) Received: by mail-ot1-f50.google.com with SMTP id d26-20020a05683018fa00b0066ab705617aso7539629otf.13 for ; Mon, 31 Oct 2022 15:30:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=VfnHMKSS4SeoisyxgDcqpLEG48y8uyoqvHtM9vPWUU8=; b=Jm3nbsAQ3m3AAnUqWVS1MrWqMEU2V9sP+1+nJ3Gkcw4DeVXFJfe1SVql2QgGjgiWJw 6nSLv3DRzatRdKvrO4fsvc95Ddv+yDDj3DyI8klxC2pwwNMdKKQy2STnCywfLlX2yCt5 GqDATuqebezeDIB/vF4Dn7NMfAO0TVFujD9wstKkbsk3u5F7ys63/w9UTjFw7w7kY2r7 0Kn7Wv8vGi8vI0p48g9oWUUm6EsgDh51w5k7IqhQ4QM4U7Mx8excuWt0QjQzEB+wshNX CEbhU/1gzm8wRH58AfUdqnnVMiYl42LlGsrOGuN9AcNUQAEVRnEdOoATAnlTB+Fv0lTV ppxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VfnHMKSS4SeoisyxgDcqpLEG48y8uyoqvHtM9vPWUU8=; b=Av+DenxDYUd9iUHYXz/zXuXneEvvZZThmDK0J7K5EzvuPwfxmeZDRfwGBNLtzjQqN0 TXOSFftyOo2oEBsZ+8E2czNYCWJkNDc03ugCSjoictd6sY3O0Jn5n/c06Qr4ry/xl2lu /mZqLe9wA+sgHTN7/e2y+FUIbmI56/2WhA9TBB6GH+4wbP61StSJyxF1FZTmVxlQGkVA uS2HuFUMvpq4mP/pXXxS0JiJkS7MchfF/EdQPRv90ADvFWqT6X0/cbE1dB1ciDlxcCUX DdTQOUsuI6Pk9fOaxSadXPZF2vnKkXBoJV5VtTNnZfb5OboGO9aBfhNqelAJGzK+Jubc vGDA== X-Gm-Message-State: ACrzQf0Yi20fmjckgpiYz+ZLqpI2P+lU0Ryqbi10Ea2J3IBJKG5VwBax 6FF+6npewl4nJst5Ak86cdmj8DXZ698= X-Google-Smtp-Source: AMsMyM7EXj83oSEuihtSd7ZbqjQsZwk3qmncObV4CIIj55/vOGaarrQ5t+nUiu7SrgG8zwfolEJLBQ== X-Received: by 2002:a05:6830:3c1:b0:661:b7ea:cc70 with SMTP id p1-20020a05683003c100b00661b7eacc70mr7922080otc.53.1667255411004; Mon, 31 Oct 2022 15:30:11 -0700 (PDT) Received: from [192.168.0.13] ([191.97.187.183]) by smtp.gmail.com with ESMTPSA id be17-20020a056870589100b0013626c1a5f6sm1277090oab.10.2022.10.31.15.30.10 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 31 Oct 2022 15:30:10 -0700 (PDT) Message-ID: <4ca477d8-9699-02c2-32da-8df0108bb39a@gmail.com> Date: Mon, 31 Oct 2022 19:30:10 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 To: ffmpeg-devel@ffmpeg.org References: <20221031202845.1860-1-jamrial@gmail.com> Content-Language: en-US From: James Almer In-Reply-To: Subject: Re: [FFmpeg-devel] [PATCH v2] avcodec/atrac3plus: reorder channels to match the output layout 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 10/31/2022 7:13 PM, Andreas Rheinhardt wrote: > James Almer: >> The order in which the channels are coded in the bitstream do not always follow >> the native, bitmask-based order of channels both signaled by the WAV container >> and forced by this same decoder. This is the case with layouts containing an >> LFE channel, as it's always coded last. >> >> Fixes ticket #9964. >> >> Signed-off-by: James Almer >> --- >> libavcodec/atrac3plusdec.c | 13 ++++++++++++- >> 1 file changed, 12 insertions(+), 1 deletion(-) >> >> diff --git a/libavcodec/atrac3plusdec.c b/libavcodec/atrac3plusdec.c >> index ee71645a3c..9e12f21930 100644 >> --- a/libavcodec/atrac3plusdec.c >> +++ b/libavcodec/atrac3plusdec.c >> @@ -48,6 +48,17 @@ >> #include "atrac.h" >> #include "atrac3plus.h" >> >> +static uint8_t channel_map[8][8] = { >> + { 0, }, >> + { 0, 1, }, >> + { 0, 1, 2, }, >> + { 0, 1, 2, 3, }, >> + { 0, }, >> + { 0, 1, 2, 4, 5, 3, }, >> + { 0, 1, 2, 4, 5, 8, 3, }, >> + { 0, 1, 2, 4, 5, 9, 10, 3, }, >> +}; >> + >> typedef struct ATRAC3PContext { >> GetBitContext gb; >> AVFloatDSPContext *fdsp; >> @@ -378,7 +389,7 @@ static int atrac3p_decode_frame(AVCodecContext *avctx, AVFrame *frame, >> channels_to_process, avctx); >> >> for (i = 0; i < channels_to_process; i++) >> - memcpy(samples_p[out_ch_index + i], ctx->outp_buf[i], >> + memcpy(samples_p[channel_map[frame->ch_layout.nb_channels - 1][out_ch_index + i]], ctx->outp_buf[i], >> ATRAC3P_FRAME_SAMPLES * sizeof(**samples_p)); >> >> ch_block++; > > Looking at the last two entries, it seems to me that you simply used the > numerical values of the AV_CHAN_* constants, i.e. as if you wanted to > write { AV_CHAN_FRONT_LEFT, AV_CHAN_FRONT_RIGHT, AV_CHAN_FRONT_CENTER, > AV_CHAN_BACK_LEFT, AV_CHAN_BACK_RIGHT, AV_CHAN_SIDE_LEFT, > AV_CHAN_SIDE_RIGHT, AV_CHAN_LOW_FREQUENCY } for the last entry. This is > wrong, as it conflates the enum AVChannel domain with the index domain; > it will segfault for 6.1 and 7.1, because there are no data planes with > indices 8, 9 and 10 in the output frame. Yeah, i mixed ids and indexes. Will fix. > > The array for 6.1 is { 0, 1, 2, 4, 5, 6, 3 }, for 7.1 it is { 0, 1, 2, > 4, 5, 6, 7, 3, } (presuming that your first patch was right). The > derivation for 6.1 is as follows: The first channel in atrac is FL, > which is also the first channel in AV_CHANNEL_LAYOUT_6POINT1_BACK. So > the first entry is 0; the next channel is FR which is the second channel > in AV_CHANNEL_LAYOUT_6POINT1_BACK, so the second entry is 1. The next > atrac entry is FC, which is also the next entry in > AV_CHANNEL_LAYOUT_6POINT1_BACK, so the next entry is 2. The next atrac > entry is BL, which is not the next channel in > AV_CHANNEL_LAYOUT_6POINT1_BACK (which is lfe), but the one after that. > So the next entry is four. Similarly, the next entry is five. The atrac > entry after that is BC, which is the next (and last) entry of > AV_CHANNEL_LAYOUT_6POINT1_BACK and has index six. It doesn't matter for > this that there are several channels in enum AVChannel between BR and > BC, as these channels are not present in AV_CHANNEL_LAYOUT_6POINT1_BACK > (it would also not matter if there were any gaps in the values of the > AV_CHAN_* constants in between). The next (and last) atrac entry is LFE, > which is the fourth channel in AV_CHANNEL_LAYOUT_6POINT1_BACK and > therefore has index 3. > > Is it really absolutely guaranteed that atrac only has one channel > layout per channel count? It seems to me that adding a const uint8_t > *channel_map to the context that gets set like ctx->channel_map = (const > uint8_t[]){ 0, 1, 2, 4, 5, 6, 3 } (for 6.1) would be simpler. I don't know if it's guaranteed, but that's what this decoder assumes directly during init with user set values (so nothing read from the bitstream for it), so I'll not assume the opposite. > > - Andreas > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".