From patchwork Mon Aug 24 11:36:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 21876 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id DEB3E44B155 for ; Mon, 24 Aug 2020 14:37:07 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CB9C268AA6E; Mon, 24 Aug 2020 14:37:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DAD39689EEC for ; Mon, 24 Aug 2020 14:36:59 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 ( name = phare.normalesup.org ) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 07OBawOA027518 for ; Mon, 24 Aug 2020 13:36:59 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id 05828E8C4D; Mon, 24 Aug 2020 13:36:58 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Mon, 24 Aug 2020 13:36:51 +0200 Message-Id: <20200824113652.255648-4-george@nsup.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200824113652.255648-1-george@nsup.org> References: <20200824113652.255648-1-george@nsup.org> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Mon, 24 Aug 2020 13:36:59 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH v3 4/4] lavfi/buffersink: remove redundant channel layouts. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" The channel_layouts and channel_counts options set what buffersink is supposed to accept. If channel_counts contains 2, then stereo is already accepted, there is no point in having it in channel_layouts too. This was not properly documented until now, so only print a warning. Signed-off-by: Nicolas George --- libavfilter/buffersink.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) Faster algorithm. diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c index 76a46f6678..9338969bf1 100644 --- a/libavfilter/buffersink.c +++ b/libavfilter/buffersink.c @@ -62,6 +62,29 @@ typedef struct BufferSinkContext { #define NB_ITEMS(list) (list ## _size / sizeof(*list)) +static void cleanup_redundant_layouts(AVFilterContext *ctx) +{ + BufferSinkContext *buf = ctx->priv; + int nb_layouts = NB_ITEMS(buf->channel_layouts); + int nb_counts = NB_ITEMS(buf->channel_counts); + uint64_t counts = 0; + int i, lc, n; + + for (i = 0; i < nb_counts; i++) + if (buf->channel_counts[i] < 64) + counts |= 1 << buf->channel_counts[i]; + for (i = lc = 0; i < nb_layouts; i++) { + n = av_get_channel_layout_nb_channels(buf->channel_layouts[i]); + if (n < 64 && (counts & (1 << n))) + av_log(ctx, AV_LOG_WARNING, + "Removing channel layout 0x%"PRIx64", redundant with %d channels\n", + buf->channel_layouts[i], n); + else + buf->channel_layouts[lc++] = buf->channel_layouts[i]; + } + buf->channel_layouts_size = lc * sizeof(*buf->channel_layouts); +} + int attribute_align_arg av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame) { return av_buffersink_get_frame_flags(ctx, frame, 0); @@ -253,6 +276,7 @@ static int asink_query_formats(AVFilterContext *ctx) if (buf->channel_layouts_size || buf->channel_counts_size || buf->all_channel_counts) { + cleanup_redundant_layouts(ctx); for (i = 0; i < NB_ITEMS(buf->channel_layouts); i++) if ((ret = ff_add_channel_layout(&layouts, buf->channel_layouts[i])) < 0) return ret;