From patchwork Tue Mar 19 21:15:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 47235 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8ba5:b0:1a3:31a3:7958 with SMTP id m37csp12889pzh; Tue, 19 Mar 2024 14:15:48 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWpgtFpSvnjweJfYDUEM3LktewU5lXK7r8VzWRVbXZvweKx7A+KFCduSvoYBib/lDVtk4xK8B+kob1kgu/DZXJlzSPnlmRd5gWjDA== X-Google-Smtp-Source: AGHT+IH7tMBrqnDe/onIVZNAllgYFHR3FZ8GxulxbgCe/91Qcq97Tucu/uqfVWEyBEBT0MzbJXhC X-Received: by 2002:a19:434c:0:b0:513:bc95:50c3 with SMTP id m12-20020a19434c000000b00513bc9550c3mr202571lfj.12.1710882948297; Tue, 19 Mar 2024 14:15:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1710882948; cv=none; d=google.com; s=arc-20160816; b=ENvdf+1JKTF6YrrfSTpCPoI+tpe7VaGF29a55eEE34x8/XSKR/ERr0p7NLQLvUZgnB IZsdOCPvUejVyPp7OgToG14m+M9YRp7iq+8nfP3OhqsY13NiAOwmHFL7dszME0Zm+6Hd Xj3/vU5F+i3W66iEsaSG3jcTYS1+HvQKLuROr0yw4lJdYE8qb5FjkMJYaBizbgg6/vU0 Kpi4RN1LQytgiYit8iX+t4aiQc186DLiToft4QP70s4cIfXVCagMoHenrksG4jgegM3L YcSFu5pebmDL4qF+xnE1SDaeQmWQbgX3nbK08UiK9Y3vxDrtjqvsRr0HsLJXzdWxjC3T +4ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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:delivered-to; bh=ejJDrVqYiZnelQkAVB60mtQ9mzTjNfXDRikIj/bXg1s=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=HTV1U4ll3wQvPuIOScdgOeeImLMnQcVOinzXMIJGiaN9JquPEtozjF2R6W6IChxk0L pD/P9UuH7caDTEjnUPphGRPmFvmdMRyyYV15ony/09kfnQDpIo5/zNWSvw7COlT5yGab JSC8UmG+woYI/P1ai3pDfCZV1VYj/C5V1/dy4GAkwtXGjKfFalvK6CADbKtO607B0W5x hGPPjOQBFdZB8FR8KFWDErOHyc2Y+FX72SJr1+MXOsI3EJ2+CVc0ytODN4c0aqj4+Hgs muhD4KZleXVG5780cROl/Sq35hm6cAU3MiTPNGht0TkowX7wNmGMd92WGRfQUNoYHPIu s8TA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id z7-20020a17090655c700b00a4666bb4878si5581962ejp.601.2024.03.19.14.15.47; Tue, 19 Mar 2024 14:15:48 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 74E3B68D449; Tue, 19 Mar 2024 23:15:25 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3988C68D442 for ; Tue, 19 Mar 2024 23:15:18 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 198AEE9BD0; Tue, 19 Mar 2024 22:15:18 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7EzMndVLEG1A; Tue, 19 Mar 2024 22:15:16 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 462E8EA242; Tue, 19 Mar 2024 22:15:16 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Mar 2024 22:15:02 +0100 Message-Id: <20240319211504.8342-4-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240319211504.8342-1-cus@passwd.hu> References: <20240319211504.8342-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/6] avfilter/af_channelmap: factorize checking indexes against a channel 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 Cc: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: VHKWh8LVsxRW Signed-off-by: Marton Balint --- libavfilter/af_channelmap.c | 41 ++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/libavfilter/af_channelmap.c b/libavfilter/af_channelmap.c index 1ecbddd462..62e11103ad 100644 --- a/libavfilter/af_channelmap.c +++ b/libavfilter/af_channelmap.c @@ -116,6 +116,30 @@ static int get_channel(char **map, int *ch, char delim) return 0; } +static int check_idx_and_id(AVFilterContext *ctx, int channel_idx, int channel, AVChannelLayout *ch_layout, const char *io) +{ + char channel_name[64]; + char layout_name[256]; + int nb_channels = ch_layout->nb_channels; + + if (channel_idx < 0 || channel_idx >= nb_channels) { + av_channel_layout_describe(ch_layout, layout_name, sizeof(layout_name)); + if (channel >= 0) { + av_channel_name(channel_name, sizeof(channel_name), channel); + av_log(ctx, AV_LOG_ERROR, + "%sput channel '%s' not available from %sput layout '%s'\n", + io, channel_name, io, layout_name); + } else { + av_log(ctx, AV_LOG_ERROR, + "%sput channel #%d not available from %sput layout '%s'\n", + io, channel_idx, io, layout_name); + } + return AVERROR(EINVAL); + } + + return 0; +} + static av_cold int channelmap_init(AVFilterContext *ctx) { ChannelMapContext *s = ctx->priv; @@ -334,10 +358,7 @@ static int channelmap_config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; ChannelMapContext *s = ctx->priv; - int nb_channels = inlink->ch_layout.nb_channels; int i, err = 0; - char channel_name[64]; - char layout_name[256]; for (i = 0; i < s->nch; i++) { struct ChannelMap *m = &s->map[i]; @@ -347,20 +368,8 @@ static int channelmap_config_input(AVFilterLink *inlink) &inlink->ch_layout, m->in_channel); } - if (m->in_channel_idx < 0 || m->in_channel_idx >= nb_channels) { - av_channel_layout_describe(&inlink->ch_layout, layout_name, sizeof(layout_name)); - if (m->in_channel >= 0) { - av_channel_name(channel_name, sizeof(channel_name), m->in_channel); - av_log(ctx, AV_LOG_ERROR, - "input channel '%s' not available from input layout '%s'\n", - channel_name, layout_name); - } else { - av_log(ctx, AV_LOG_ERROR, - "input channel #%d not available from input layout '%s'\n", - m->in_channel_idx, layout_name); - } + if (check_idx_and_id(ctx, m->in_channel_idx, m->in_channel, &inlink->ch_layout, "in") < 0) err = AVERROR(EINVAL); - } } return err;