From patchwork Tue Aug 2 16:54:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 37091 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp3256691pzb; Tue, 2 Aug 2022 09:55:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR4l2VBIy85vSgvKNNuOsq83EXFgC+QLL+UTXmy4jhYpBdOD5MR/sM94sME0rJR25S+wRFVO X-Received: by 2002:a17:907:2bf9:b0:730:7a66:71a3 with SMTP id gv57-20020a1709072bf900b007307a6671a3mr8866761ejc.623.1659459301517; Tue, 02 Aug 2022 09:55:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659459301; cv=none; d=google.com; s=arc-20160816; b=c2SkxiILkPo4Wj/iiOjoQ8KSlcaIApyqz195lcy0BIbsW4H4JnWV1rVyN07D0GEQOf WKJav0oqkLl1kuhyDNCny2pEQN3v3Oxa21W8IOoM6JNHuJu9fBa31v9yOz66wHXCf40T IqUa2Vpcs24T1PAb47FvXngOu2C1r6pzKxmmKLGRJBbpgFVkIrLKQcQTO1Uc4vtvXaNa xG+Xt/7gOhZrwtUDctBKRet5modL1GBGiDLGXD/0bOVlMDO8PuU7WS7NmDdpFJfU3qhe jv8BhbzpP06hgqvjsLtYuQIqulgeDAs1GJooZa38JaLa22XN8zqXoIayecAXpIRumzdn i5pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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=SS1FW22R/eNPX0HNKbQUOU2NM98pzbxRGkWBdpDRsAQ=; b=KQJSaHfGejXUM0rtZhmAlVhX3GQUcZSvH87/xwWtdEbCpFYJHGrKiU8FwU7ZTvSGrM mi8B8vK9kiJGVtHJIZJKPzcOtX/W2HCBBIZS0FmWJ+zqrsZjMu3cjWy7i+NWpZzAMzim jq/Y4TOdpGHKwck+7HKZv4NTU0JdnBc+DMnzZWLGTOh9JyiVQ3+Knugl+yP5bErX7z/E gKmfJ8RCxfyaWoQz9p57IlnyOs8j7bMcU0vGxOztZFGiVhZGt8v8UgZ7ifvzxv4WxlXb laKgec9ikGPs+MWVNaYebHIXiNJRRxJvz+vTrR7atPsj4thFbA8jhPShUbKq159QQE04 d9Yw== 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 rl24-20020a170907217800b0072b53e95011si10471393ejb.265.2022.08.02.09.55.01; Tue, 02 Aug 2022 09:55:01 -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 7890868BA82; Tue, 2 Aug 2022 19:54:36 +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 9090868BA07 for ; Tue, 2 Aug 2022 19:54:27 +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 272GsQvf017574 for ; Tue, 2 Aug 2022 18:54:27 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id D43C9EB5BC; Tue, 2 Aug 2022 18:54:26 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Tue, 2 Aug 2022 18:54:18 +0200 Message-Id: <20220802165421.137563-4-george@nsup.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220802165421.137563-1-george@nsup.org> References: <20220802165421.137563-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]); Tue, 02 Aug 2022 18:54:27 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 4/7] lavfi/(a)format: factor finding the delimiter 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: /jPcZXSt8YR6 Signed-off-by: Nicolas George --- libavfilter/af_aformat.c | 8 +++++--- libavfilter/internal.h | 9 +++++++++ libavfilter/vf_format.c | 9 ++++----- 3 files changed, 18 insertions(+), 8 deletions(-) Identical to the one posted months ago. diff --git a/libavfilter/af_aformat.c b/libavfilter/af_aformat.c index a14e4c1240..addabafbfa 100644 --- a/libavfilter/af_aformat.c +++ b/libavfilter/af_aformat.c @@ -65,10 +65,12 @@ do { \ char *next, *cur = str; \ int ret; \ \ - while (cur) { \ + if (!cur) \ + break; \ + while (*cur) { \ type fmt; \ - next = strchr(cur, '|'); \ - if (next) \ + next = ff_formats_list_find_delimiter(cur); \ + if (*next) \ *next++ = 0; \ \ if ((fmt = get_fmt(cur)) == none) { \ diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 0f8da367d0..6dbe7ecee0 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -405,4 +405,13 @@ int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link, int default_pool_size); +/** + * Find the next delimiter in a string of formats. + * The delimiter is '|' or the end of the string. + */ +static inline char *ff_formats_list_find_delimiter(const char *str) +{ + return (char *)str + strcspn(str, "|"); +} + #endif /* AVFILTER_INTERNAL_H */ diff --git a/libavfilter/vf_format.c b/libavfilter/vf_format.c index 24b1c9ca61..b3f168a531 100644 --- a/libavfilter/vf_format.c +++ b/libavfilter/vf_format.c @@ -69,10 +69,9 @@ static av_cold int init(AVFilterContext *ctx) /* count the formats */ cur = s->pix_fmts; - while ((cur = strchr(cur, '|'))) { + while (*(cur = ff_formats_list_find_delimiter(cur))) { nb_formats++; - if (*cur) - cur++; + cur++; } s->formats = av_malloc_array(nb_formats + 1, sizeof(*s->formats)); @@ -82,8 +81,8 @@ static av_cold int init(AVFilterContext *ctx) /* parse the list of formats */ cur = s->pix_fmts; for (i = 0; i < nb_formats; i++) { - sep = strchr(cur, '|'); - if (sep) + sep = ff_formats_list_find_delimiter(cur); + if (*sep) *sep++ = 0; if ((ret = ff_parse_pixel_format(&s->formats[i], cur, ctx)) < 0)