From patchwork Tue Nov 1 00:06:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 39098 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8e01:b0:a3:a294:714c with SMTP id y1csp1228390pzj; Mon, 31 Oct 2022 17:07:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM57qGqTYPutww8MgiEESjr4wWf9lG9ACw9KUWwfcz/SOym7MZjguJoZciSZi5Qk5KNOAH2E X-Received: by 2002:aa7:d744:0:b0:45c:e353:e891 with SMTP id a4-20020aa7d744000000b0045ce353e891mr16710298eds.36.1667261263875; Mon, 31 Oct 2022 17:07:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667261263; cv=none; d=google.com; s=arc-20160816; b=vM8n8wgU8C5+g3YVh8K2fydyCz99EnV7lX4O6M9sEeSPLzX2bXGAq+ZPureYZ7YvYA mK3OSTvYigxCGpQ8jn8xHdUOcZzzRvdlTMzfZjGh01AAWz9ROuVnAHOdn60iAPvGivKD 5lzkuopFrOpwiB3iTp7bAXYvv5vxpGh+w5HZ0uSdR1WMmJK5TIa570fbnQwSURpztpJb NeVtAEtB4vv+PIcecmXdLoSM+WYiM6bI+1OQLumLYTtEt8RXhkk0UHI1rGMnRZcMr+PR oI5YtUgTdR7PWoKCwYvVOVZ6f6cR5N3GuV1yquk2xMex3LdszxcMAfW5QqOjgYI1lpcC /FiQ== 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=K4hotzO8+f+EHzbyMqO0cn8ek4CLfkToyoSOhTQsZlY=; b=AnMSsRUCs9gbxQH8mcQ5jninsFYCTCWhRlFXJPpSlj9Wq9a+pfbVpjjP1cW0kn2If3 yzcyjmpDWMeH7GwmBx0GEoNMQ2xi5xDrTMKSuk7DAIY28rSlg61ngMCtnc1EHTJ2Ux0L FWWzEIMs81fNJHBY4N3xTXFZdmW1Y1TyPEPn2C8c+1CdPDMhND4Zyj3gYOtuLTGxZ+XD R512514Wmr6kltYKofI8/JukCQTqD2ZDrNiD3xf80SEar0uNyFFyqX14jkrjiQ+Q42Ds UAGp2vm2OlvRIkBQ22C0g4wkgswiuuqeiiAttKCXfd3vP7fwcSzuF1rnYxlQ5zS2p3Vr pndg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=hsCj4EQq; 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 mp36-20020a1709071b2400b0072a477a55e0si10597159ejc.369.2022.10.31.17.07.43; Mon, 31 Oct 2022 17:07:43 -0700 (PDT) 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=hsCj4EQq; 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 2B29F68BE37; Tue, 1 Nov 2022 02:07:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 08DBE68BD4C for ; Tue, 1 Nov 2022 02:07:33 +0200 (EET) Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-13bd19c3b68so15206879fac.7 for ; Mon, 31 Oct 2022 17:07:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=1M1ExYQ9h5Y+RUrMUvOMCcNWH4Qg7E+M/AliJkwqxY8=; b=hsCj4EQqK1aoGnzNu7Ekh51Ov+J646Vm3Izz8EenwenjkoqhC/2NeJ07eJx/oboXJy jAHaszVtuPpOwI1wRbQy1fwHRd1s67s/fEluinjODDNxBY8NUUyu7L3qG5xSmKExSvXZ 51gXoqf543PkrpV5JRQaUO/foFJz8CpzLK5wc3pPM4qimQ1oudyaQnEC30Z/YHeohOiw 4pW3d0rMC4lHfdUERg1XBBi1Fu1+zDT2Ba/dA8Y7u965YdJTEERccMq1iNFcgWIVZAwa 93cGPNcesUFXtnf5xe3lv/T7E0dofzIWBB7q8+edDWciriGztLSqQ3PJUCfwg4YjYDlI mP1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1M1ExYQ9h5Y+RUrMUvOMCcNWH4Qg7E+M/AliJkwqxY8=; b=jtzIHfbNoUYkheYpRz+XV2Ili8/feeC2HkXkjv6Kpo4lbb1G36WLYkZIym1qsw9FcT rb8cW6pWevFaBlX7r+5kRedcILh6kMURIniB9gqpilPZcPbpZi5XHJnxLRjM9QwPnJKw z9fXfHf7XrEgjUSPvO9RpuG2hZreMr49AXXdvu+Agyp+YNkDTJWZJi+Z1lIUFMseOjV+ 8OFNMB7ceHRsZyVv8ymXptTTwkfPnTmzX06S8NhiQruoJ1US5CS2mZqeEZdmmoDPM0mq ezrUHp4h+TfL8sBNCCoywvqyxnsf0Z197PNBYZZkr23B9IKygjNeWuXGUlLxfFfNKcf8 WCIA== X-Gm-Message-State: ACrzQf0TjnEmEweiIoU4gWvvASUHdWE9GheLRXswlagQNzQX4gE8Vx3K lUoZ3RSYWeu+9DSO64ftHJ4q0uVZHfo= X-Received: by 2002:a05:6870:40cb:b0:131:4fec:3c7d with SMTP id l11-20020a05687040cb00b001314fec3c7dmr18902852oal.147.1667261251040; Mon, 31 Oct 2022 17:07:31 -0700 (PDT) Received: from localhost.localdomain ([191.97.187.183]) by smtp.gmail.com with ESMTPSA id q16-20020a056870e61000b00136c20b1c59sm3748142oag.43.2022.10.31.17.07.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 17:07:30 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 31 Oct 2022 21:06:27 -0300 Message-Id: <20221101000627.8454-1-jamrial@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3] 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: HFWE5DAKsTR1 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 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libavcodec/atrac3plusdec.c b/libavcodec/atrac3plusdec.c index ee71645a3c..2bc023cb23 100644 --- a/libavcodec/atrac3plusdec.c +++ b/libavcodec/atrac3plusdec.c @@ -48,6 +48,17 @@ #include "atrac.h" #include "atrac3plus.h" +static const 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, 6, 3, }, + { 0, 1, 2, 4, 5, 6, 7, 3, }, +}; + typedef struct ATRAC3PContext { GetBitContext gb; AVFloatDSPContext *fdsp; @@ -65,6 +76,7 @@ typedef struct ATRAC3PContext { int num_channel_blocks; ///< number of channel blocks uint8_t channel_blocks[5]; ///< channel configuration descriptor + const uint8_t *channel_map; ///< channel layout map } ATRAC3PContext; static av_cold int atrac3p_decode_close(AVCodecContext *avctx) @@ -143,6 +155,8 @@ static av_cold int set_channel_params(ATRAC3PContext *ctx, return AVERROR_INVALIDDATA; } + ctx->channel_map = channel_map[channels - 1]; + return 0; } @@ -378,7 +392,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[ctx->channel_map[out_ch_index + i]], ctx->outp_buf[i], ATRAC3P_FRAME_SAMPLES * sizeof(**samples_p)); ch_block++;