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 AEE21446D8 for ; Wed, 21 Sep 2022 07:15:52 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DC3FE68BB5D; Wed, 21 Sep 2022 10:15:50 +0300 (EEST) Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 565AE68B8CF for ; Wed, 21 Sep 2022 10:15:44 +0300 (EEST) Received: by mail-yb1-f173.google.com with SMTP id b136so6777691yba.2 for ; Wed, 21 Sep 2022 00:15:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date; bh=f3PMTkHZmWeYTehqrxTALUKHwoSpufzQjqbw+XKtTrs=; b=n7mIpm5FIXxyy9Lw3cIdXHg0vpLDMZYsYg6SdP3LLeLtWw3YiJsIypb5nhhp/gzrnQ H9tzg7PQo3DMLcyvIrXp8+IaPnBbXD/UFwHPRikO8coPCDmp8VymawNxHw29aEF9bUtD 7dCrjceHIjkf5G0+phRg8rCZo+XSJTQ1cs+Kpduu1p7sB8qiONaPZR0AmJT9Ui7py0oh PmVf4eQfp7VhYzp5l4CKHCjLN6gLse08QzecNVjL7I5zUjBR9zCCoQeKcyDRyzUYcWre xb137tpKQz9FmBNzZLnFnEe7t/lT2zXGcu9D2Lufq+OkPFCl9Gbu9tsQvABPpWwurT3l D1rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=f3PMTkHZmWeYTehqrxTALUKHwoSpufzQjqbw+XKtTrs=; b=4okG1w3DkLPsI5pQ2NT4Krcx8QPrMzKf95CR2vudxcf63ky6wvDU0KJ3k1YTOQIeRr r+mOd4epjImv6ZjJDVzCMxzOIQajY91My8jiT8Puc9rO5a6IwtnTVW5hcPOu/tn4GOuA 9yGCLh6HzDHCAr27ZYcSDLXlLb0Px+PxUqSxbnpV/eNps8lB0VTF+JkwtOMGWpWaB1AI 3qNopLnRZ9iVbzVkycoH/jT7f/e/0kNp6KO08Ej0DHhZVXcOuGpF071s7nuiy6cCX9YZ 2b+TthSJeNmQKSO5+X93LCtFuaan9b3MWMslHS2jKYvYLrdY330kdAHAGLKQr2MTXEE1 8hzw== X-Gm-Message-State: ACrzQf3E/vPLAPajnQUWHfZhQAjzqX1MOJdRzG7PWPPjcEl+wcuDvnxB oX4NhmLbThcZ4756Lm0lXjbPzeuIOXezjLp0ovGLHcae X-Google-Smtp-Source: AMsMyM59kAGD9F4FmCm+YTv5+n8nEZBuFFrowDCD65c7nJC4Ze84Y6xK0ugYt/OYLQpN5K6/ausHwBYzzyQtqyOk3HU= X-Received: by 2002:a25:389:0:b0:6a9:20da:fe68 with SMTP id 131-20020a250389000000b006a920dafe68mr21839494ybd.49.1663744542940; Wed, 21 Sep 2022 00:15:42 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a81:7402:0:0:0:0:0 with HTTP; Wed, 21 Sep 2022 00:15:42 -0700 (PDT) In-Reply-To: References: From: Paul B Mahol Date: Wed, 21 Sep 2022 09:15:42 +0200 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 9/18/22, Andreas Rheinhardt wrote: > 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(-) > probably ok > 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; > -- > 2.34.1 > > _______________________________________________ > 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".