From patchwork Sun Sep 18 20:27:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 38032 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp858935pzh; Sun, 18 Sep 2022 13:29:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5/Fnm0IOEEBMh0d4lO8wd1OvECXRSia0tsvHHGdu90UV+pMg/SIOu35jl8sirl8Z4Yeldy X-Received: by 2002:a05:6402:5cb:b0:452:e416:2bc4 with SMTP id n11-20020a05640205cb00b00452e4162bc4mr12977833edx.114.1663532990695; Sun, 18 Sep 2022 13:29:50 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id dd18-20020a1709069b9200b007802170e0a0si16213252ejc.32.2022.09.18.13.29.50; Sun, 18 Sep 2022 13:29:50 -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=@outlook.com header.s=selector1 header.b=MLNTOR43; arc=fail (body hash mismatch); 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=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4648268BC5A; Sun, 18 Sep 2022 23:28:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2081.outbound.protection.outlook.com [40.92.91.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7197168BBD3 for ; Sun, 18 Sep 2022 23:28:24 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Oock1yp/ddvyjbuJH6Y/Hj5U/y+uyu4EVnD+Yy7M2Xhf2LDDA/G85oxdN0ecUYIB/oGfmQr0xZUr+7eRxt2UVVQdU7YgcEUJJqj6R2ONx90fvl5+hAH0mEZ9I9GT5AjVQ4eWDjY2bx1N+FQICK7CXAATNG6H0l6h9X0jEGQoliurTIFAaHI++uHi0da3VALWwyY0YR/xi6PuzMm4XThuMc/zL0XPVM0E4LBiCa4DGXjhFCEQR1sQLUpXjP7ofkxg7mQ4wiibTnitd/yFm2jb4ooq/etFk6xbYanqvI2oDguc7HHkozk2YkyVzRYsjvogw0y1AGENC+VI/mThpSTivA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+0BfBLUqN8o5yJ5Qfn2+EIMcygDJxUz30KryGWqU48U=; b=Mg9wid23eg7ccNXDGEOf6UfyBsqHIB/Yug5GkxNB1MAyoq/SxnFE3DfiJ7R0+kmulOZC3V5gmcucn8lKRc+Rx3EKmidffNVASI1rY7GXfdTp23AtPCr6NEmW64423p5eDIDYj4v/VTfhexaEosdK/iUKOCD3Y+o+FDVj2tnV7O+b4VirE7qdye2Gsb7/qmxVw5YPBA8KQFAhd1skBketsJoQuGsqVbyDR+lr62DZxUJGjFcmW9AR26oQEniwu5Gl4/Q/bD4VF/yASi7mNQT5RJb/StZnDosL2WtHS63iWRdLCd3Fjysp29jyYx+acwTBV7QCOF8X4krmogyAvaOvdg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+0BfBLUqN8o5yJ5Qfn2+EIMcygDJxUz30KryGWqU48U=; b=MLNTOR43/wouGFOl3kBXC2RBwLs8l2VCFCAMNXKza1yDSaFrGJhaMlYdUR2TSC/NW/YDIM3WtsBjjJGPnTOv2LE16q1bb8rxurZrkS5/6ua36sQVmHqKQrch71YaXI4i7E4/60I+0aKGMv8J3CLcGN3umlFT2a7iyNDxVmR3TUuWko3uBQSFPMMnWyJpwCdGO1S/VqezP2ebGooqfqVTh0HjoaJM/5VF/k+Puo/Cqoqwt6xF1hbKwf9A+CQa/7nevswcL9C+5m7gxS/XZO7F+bfdm5m/tBu6fA55Gp5aKp9Ap5ubNAntHE/r4l/KJrIeWMGucDleAxNnMhHJyfPGrA== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by DU0P250MB0484.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:34c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.19; Sun, 18 Sep 2022 20:28:21 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::f3f2:4362:56:4785]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::f3f2:4362:56:4785%7]) with mapi id 15.20.5632.019; Sun, 18 Sep 2022 20:28:21 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 18 Sep 2022 22:27:54 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [zUgpwqyUer9nd1VdTsP8Idnjwy4wV+/DsdpRFRtlJ+g=] X-ClientProxiedBy: ZR0P278CA0109.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:20::6) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20220918202757.2345415-13-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|DU0P250MB0484:EE_ X-MS-Office365-Filtering-Correlation-Id: b2538d39-75c2-4c38-ee48-08da99b45442 X-MS-Exchange-SLBlob-MailProps: AZnQBsB9Xmo7HDJh1DrTtIyfVHMwSN51GSU0XTfaVJtkPF152wZN7ptw8FgqKBcSkCJ4H+weigbfYt48F62Dy878w0jnLbxzAuHiWwB8DVqzjueakPUxMKgp5bnZqD6NAhdshjLaZTtZ8ugLRb+tOMZSn1Z5nR5/k71A12hdm7ifw/wFOsfBp+/XBPdVY6RehEj/tfIw6BqoWJS5haVUNFKiTCOGQemZWDSSFRjiDZp/toedQevD6Myf7nrby72lKE5+mlhfrbyTnWZWVzL2akQ8LLJpqS9yjmAJaTjrCvXTIrf8oQnNroLi17PKHZQdbMoCMriPvcWAMhCBZZQIMjPaYknJ5qEewOlOGZOZRKPz4xTCCZtueXh5ZlZ75LGMSGrc3eSWdYzYUDX1QA88AY0yw7clyxBHPmCorEH5vULuTkxwY3N+ZIaz+l1623mPBXSDsC+zQ3fw4WiBeABfcnk0feUyjxEg+y/hIz1n0+BYRJAm6Ct/NfROTFsL3lWwiWVN87dovDbQNBZ4etT39zYFpyqQBpJfO5+vFV8CxNe25oRQw7TgMMMRn4anADlbpWshFOzODAJGvS+Thlp3BpHTE0PwFatMFs1iozc1CHYE6r0IhHQlSzW+Oc0IK+csZIff9JfhPziF73ajYUCJVgwN1AaOtD8yW03R5qTQu2mpdEtIthEG5W90CC7KCBGw4oINSyzZ+avU92uMdfbh1WAoiAhyrjw9yVjG2e452oLku/XoFCKpe8gAFrlTDxMlXLpisib1HaU= X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: g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-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2022 20:28:21.5067 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0P250MB0484 Subject: [FFmpeg-devel] [PATCH 14/17] avcodec/mlpenc: Simplify channel layout comparisons 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: lnCuxTuEbYeX These encoders have AVCodec.ch_layouts set, so ff_encode_preinit() has already checked that the used channel layout is equivalent to one of these native layouts. Therefore one can simply compare the channel masks (with the added complication that one has to use av_channel_layout_subset() to get it, because the channel layout is not guaranteed to have AV_CHANNEL_ORDER_NATIVE). Signed-off-by: Andreas Rheinhardt --- libavcodec/mlpenc.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c index 463332593f..d2e28888f7 100644 --- a/libavcodec/mlpenc.c +++ b/libavcodec/mlpenc.c @@ -480,6 +480,7 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx) static AVOnce init_static_once = AV_ONCE_INIT; MLPEncodeContext *ctx = avctx->priv_data; RestartHeader *const rh = &ctx->restart_header; + uint64_t channels_present; unsigned int sum = 0; size_t size; int ret; @@ -589,19 +590,20 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx) ctx->num_substreams = 1; // TODO: change this after adding multi-channel support for TrueHD + channels_present = av_channel_layout_subset(&avctx->ch_layout, ~(uint64_t)0); if (ctx->avctx->codec_id == AV_CODEC_ID_MLP) { - static const AVChannelLayout layout_arrangement[] = { - AV_CHANNEL_LAYOUT_MONO, AV_CHANNEL_LAYOUT_STEREO, - AV_CHANNEL_LAYOUT_2_1, AV_CHANNEL_LAYOUT_QUAD, - AV_CHANNEL_LAYOUT_2POINT1, { 0 }, { 0 }, - AV_CHANNEL_LAYOUT_SURROUND, AV_CHANNEL_LAYOUT_4POINT0, - AV_CHANNEL_LAYOUT_5POINT0_BACK, AV_CHANNEL_LAYOUT_3POINT1, - AV_CHANNEL_LAYOUT_4POINT1, AV_CHANNEL_LAYOUT_5POINT1_BACK, + static const uint64_t layout_arrangement[] = { + AV_CH_LAYOUT_MONO, AV_CH_LAYOUT_STEREO, + AV_CH_LAYOUT_2_1, AV_CH_LAYOUT_QUAD, + AV_CH_LAYOUT_2POINT1, 0, 0, + AV_CH_LAYOUT_SURROUND, AV_CH_LAYOUT_4POINT0, + AV_CH_LAYOUT_5POINT0_BACK, AV_CH_LAYOUT_3POINT1, + AV_CH_LAYOUT_4POINT1, AV_CH_LAYOUT_5POINT1_BACK, }; int i; for (i = 0; i < FF_ARRAY_ELEMS(layout_arrangement); i++) - if (!av_channel_layout_compare(&avctx->ch_layout, &layout_arrangement[i])) + if (channels_present == layout_arrangement[i]) break; if (i == FF_ARRAY_ELEMS(layout_arrangement)) { av_log(avctx, AV_LOG_ERROR, "Unsupported channel arrangement\n"); @@ -613,29 +615,25 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx) ctx->summary_info = ff_mlp_ch_info[ctx->channel_arrangement].summary_info ; } else { /* TrueHD */ - if (!av_channel_layout_compare(&avctx->ch_layout, - &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO)) { + if (channels_present == AV_CH_LAYOUT_MONO) { ctx->ch_modifier_thd0 = 3; ctx->ch_modifier_thd1 = 3; ctx->ch_modifier_thd2 = 3; ctx->channel_arrangement = 2; ctx->thd_substream_info = 0x14; - } else if (!av_channel_layout_compare(&avctx->ch_layout, - &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) { + } else if (channels_present == AV_CH_LAYOUT_STEREO) { ctx->ch_modifier_thd0 = 1; ctx->ch_modifier_thd1 = 1; ctx->ch_modifier_thd2 = 1; ctx->channel_arrangement = 1; ctx->thd_substream_info = 0x14; - } else if (!av_channel_layout_compare(&avctx->ch_layout, - &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0)) { + } else if (channels_present == AV_CH_LAYOUT_5POINT0) { ctx->ch_modifier_thd0 = 1; ctx->ch_modifier_thd1 = 1; ctx->ch_modifier_thd2 = 1; ctx->channel_arrangement = 11; ctx->thd_substream_info = 0x104; - } else if (!av_channel_layout_compare(&avctx->ch_layout, - &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1)) { + } else if (channels_present == AV_CH_LAYOUT_5POINT1) { ctx->ch_modifier_thd0 = 2; ctx->ch_modifier_thd1 = 1; ctx->ch_modifier_thd2 = 2;