From patchwork Tue Sep 20 15:06:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 38101 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp2004585pzh; Tue, 20 Sep 2022 08:06:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4EwgjL6Z7ETRXGbXQ/VtO2GLKwjfL63qrn9GKI+SOB871WqXb/5mJrBnr6fHVqox0x3Btu X-Received: by 2002:a17:907:6e17:b0:781:9d7c:9de0 with SMTP id sd23-20020a1709076e1700b007819d7c9de0mr4334151ejc.673.1663686383965; Tue, 20 Sep 2022 08:06:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663686383; cv=none; d=google.com; s=arc-20160816; b=CT8UDvu4dC8GLmaI0HV1tTZ6n3xIkPT9w6CNxvnSxLTCgdXqp51+8n2b8PmXS458ge meEs0Aq1NSjhDjJZyzTrXzdtloHVGHQeH9CFcG8aNLaeHmYh98BZb8rtJKiySFcjG7r5 7I7rh6ZAqhhsnJvd6/VpWhlApg6Z9Mz5yO49jNWokmXIs/e/UozQXdbai4DgVxvMSlrZ xeQ2LiaWs/13i0NAJAShcMX8DcBhk+rX5o7N+leMlULWbY1D2KMpW7hwyp8uvwHXFh9r tOns9rlRlA0yMRt6Bza9zPXq8xCQYlVDucraxEyooiS1jRW7cz25tbqE9NkFnpm/pzQY xpMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:mime-version:dkim-signature:delivered-to; bh=6J2q4S0hszbl19JRr1yrUcITnVCBx3AH9t08LsQrAHQ=; b=X7HYGiE917pU9zyrlbOwKpzcmSA5Uh7DjmW188iNjChSkPpUCxKddNjJiAF+pwHOBE dgz39vE2PBNwB5w0lLRLAsOIzpGlnOU+pEHKC6biFZi+5kkrcN76uRyFM64c3u6RyhVJ P/rl2sq4g3cpkM7dKEavST70wD7SwAW2SmLemPZMDz7YbwS9G8ulkrpd2t6+sGmKT7mG v9Ee1zC1ghFPhkC6pgeuiOMSv9Mjx9qf9mX/Wn4qVNBSLEZEwIt2lkJvIY33C5Jk+rAZ DaRghqv8ueK76llCGudpKdpkN1IooJXe4u5iHAd2C+2QbTx7WXcMd7JzE9OWS66AS8JE 0PIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=nY7jBhZV; 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 lw15-20020a170906bccf00b0073dd47c3873si1165919ejb.878.2022.09.20.08.06.23; Tue, 20 Sep 2022 08:06:23 -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=nY7jBhZV; 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 525FE68BB7F; Tue, 20 Sep 2022 18:06:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2538068B7DE for ; Tue, 20 Sep 2022 18:06:14 +0300 (EEST) Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-349c4310cf7so30642747b3.3 for ; Tue, 20 Sep 2022 08:06:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date; bh=qnHBPYws8qbMUz9HGlSR23XUxTOH3nYEd8z3RoM23DY=; b=nY7jBhZVadjfTalrCNerfp0RMOxBxNjLxR0ID10HdWsVQ0GrEArSKzmlddJiJqTkt3 s6HJLBAXEi1e9CMjAtBnsUpQ6DxX8g21ULPi4r50tQIyHcNuL3yNtHnrNgfNBIXYmiS2 53WRQV+MnnEZ7axy7WscnC+GVRxgKIdwptAI3fXpbMvsfBqrEGW8rlQ1sY8VBUAEg5EY 2YSrDsZGrf+6/Rmpt5oHZN9OQAuzpQiAJfSqoz3hEuN28p6gxIYgZ1RKsTxxKgFzgefh 8ji4vScNR9aKr33sDhRGYvM6WLHjSn1vq0pcib8nNWhxtN1PSYDcdEEzefYlWdLNZZuQ NujA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date; bh=qnHBPYws8qbMUz9HGlSR23XUxTOH3nYEd8z3RoM23DY=; b=5vWIlLjMvaE7CKsv97iG+AtLXGs7aDuIWpfzfZ5eJ7gCPPoyeM8M+eCIp/l6JVPVbj nLKfP7Q7x8ryBhGAuK+sLyrJNlhVMQzNEzO5ByJQ4QTQIAwX6gOR7C/xw/fKwck7r7xe 21SQGpRwV8lSCYrgI73pfIFqih6SuB+McJ6/PoSHpzqnvZdiNtZxMVVUWK/1+V/K3LBI Nn1cu4XPtWtUBLMZPdaM1+7erOHrzj1SijGpi7GwyMKZ/OsxjiQLkUyGkJeoJXHOjJKg Fjrged8zWMxxvPaza/lz2KVXtVqNQ17yTX5ggBs9XVA9jXO3Az/Qq1oy41QDMrddmq7I 1Fog== X-Gm-Message-State: ACrzQf3yqf2SaIB6vk99YFXh82ASUo5Q3ZDgmj3zZEWpNRxgE13Olnmp /3bwsGt811edjoXjPcfgsoLAHP1Yk7+Au+1/UKuiHwUz X-Received: by 2002:a81:b09:0:b0:345:30d:77b7 with SMTP id 9-20020a810b09000000b00345030d77b7mr19569247ywl.177.1663686372396; Tue, 20 Sep 2022 08:06:12 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a81:7402:0:0:0:0:0 with HTTP; Tue, 20 Sep 2022 08:06:11 -0700 (PDT) From: Paul B Mahol Date: Tue, 20 Sep 2022 17:06:11 +0200 Message-ID: To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH] avcodec/ac3dec: downmix for 7.1 eac3 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: GLNUkfqYhLdv Patch attached. From 3f33e226b36a0a186e070d743d2c5686c5995a0e Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Tue, 20 Sep 2022 17:07:15 +0200 Subject: [PATCH] avcodec/ac3dec: add downmix support for mono and stereo for eac3 7.1 Signed-off-by: Paul B Mahol --- libavcodec/ac3dec.c | 55 ++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index 5d0add40fe..f628eae33c 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -183,6 +183,33 @@ static av_cold void ac3_tables_init(void) #endif } +static void ac3_downmix(AVCodecContext *avctx) +{ + AC3DecodeContext *s = avctx->priv_data; + const AVChannelLayout mono = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; + const AVChannelLayout stereo = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO; + + /* allow downmixing to stereo or mono */ +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (avctx->request_channel_layout) { + av_channel_layout_uninit(&s->downmix_layout); + av_channel_layout_from_mask(&s->downmix_layout, avctx->request_channel_layout); + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if (avctx->ch_layout.nb_channels > 1 && + !av_channel_layout_compare(&s->downmix_layout, &mono)) { + av_channel_layout_uninit(&avctx->ch_layout); + avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; + } else if (avctx->ch_layout.nb_channels > 2 && + !av_channel_layout_compare(&s->downmix_layout, &stereo)) { + av_channel_layout_uninit(&avctx->ch_layout); + avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO; + } + s->downmixed = 1; +} + /** * AVCodec initialization */ @@ -190,8 +217,6 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx) { static AVOnce init_static_once = AV_ONCE_INIT; AC3DecodeContext *s = avctx->priv_data; - const AVChannelLayout mono = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; - const AVChannelLayout stereo = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO; int i, ret; s->avctx = avctx; @@ -219,25 +244,7 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx) else avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; - /* allow downmixing to stereo or mono */ -#if FF_API_OLD_CHANNEL_LAYOUT -FF_DISABLE_DEPRECATION_WARNINGS - if (avctx->request_channel_layout) { - av_channel_layout_uninit(&s->downmix_layout); - av_channel_layout_from_mask(&s->downmix_layout, avctx->request_channel_layout); - } -FF_ENABLE_DEPRECATION_WARNINGS -#endif - if (avctx->ch_layout.nb_channels > 1 && - !av_channel_layout_compare(&s->downmix_layout, &mono)) { - av_channel_layout_uninit(&avctx->ch_layout); - avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; - } else if (avctx->ch_layout.nb_channels > 2 && - !av_channel_layout_compare(&s->downmix_layout, &stereo)) { - av_channel_layout_uninit(&avctx->ch_layout); - avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO; - } - s->downmixed = 1; + ac3_downmix(avctx); for (i = 0; i < AC3_MAX_CHANNELS; i++) { s->xcfptr[i] = s->transform_coeffs[i]; @@ -1751,7 +1758,7 @@ skip: if (index < 0) return AVERROR_INVALIDDATA; if (extend >= channel_map_size) - return AVERROR_INVALIDDATA; + break; extended_channel_map[index] = offset + channel_map[extend++]; } else { @@ -1763,7 +1770,7 @@ skip: if (index < 0) return AVERROR_INVALIDDATA; if (extend >= channel_map_size) - return AVERROR_INVALIDDATA; + break; extended_channel_map[index] = offset + channel_map[extend++]; } @@ -1771,6 +1778,8 @@ skip: } } } + + ac3_downmix(avctx); } /* get output buffer */ -- 2.37.2