From patchwork Wed Mar 2 18:40:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 34585 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp4904252nkx; Wed, 2 Mar 2022 10:41:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJygyeQyHY2d6pnPuimI2f1vKqi5rlv2nnjNIObmY2udlm958yUqh/kQSBTpk75zDCKvDU4X X-Received: by 2002:a17:906:6716:b0:6cc:7d95:90af with SMTP id a22-20020a170906671600b006cc7d9590afmr23360695ejp.442.1646246469697; Wed, 02 Mar 2022 10:41:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646246469; cv=none; d=google.com; s=arc-20160816; b=lRYS6b168gYOA7/D1Tkos+nupC4w238P01jPP8FfDS7hFVTRWEB4idSa6MbTcH7Rdc a6B+AKu1PfFLSmwg+PTl4jq2zie9Cl7IbDWonNn5To5jtE0pzPihDgTUAuJZAKCc8RMk aRu+tAvMZeTF/3WweLsbk9aVxp1hFgRFp8OuD+VU3ZIMKdICtDNKRfFhVLU/KZcE654e GINjtiYj/O8ggtefCyrpIiLjpDTcZ7CaD1km3eS2tQqutEU9ANGxNwuwiDgR0FuszoX1 S87hKQJdp8dKN2zlFeFgQEZBHFj58bVTODbuO7Gj4MAw05i+CVTXiwqPsiedTM929UDm PieQ== 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=J+/1VWKKLm6nEu8M8ej9pjvLY2Krv2L44SttCA59z64=; b=hKBlh/pbvjNEXpV+CjmXDZ/zNKw1hPcomjhpH1ZUMeh7EUUtYK+roupVyNhoPtEgvH 306EYfXV4fUh77oaJNhbSFJrjIl3bqhxxPSrJw/UIu47o8AB8OUDSZ9XCVrAf4Hw4Q5P S1f3jES31QZAsGN2gIRBEOj7JADV/LfHARgD9kXBBYjugsXLv+6u6VZP1u+0GxfXLruX oVLj95Zqu6m9SK4pB3gvX7FEYN92NKYHRfMQDF+Mu6YNUpUp42AUDzJYhi8/QVVtdiTN 4XVa9/WgzPFWECQNx6qOwCzAdMHqdTcoX5ZLSdxH6pObVKS+/BsyuFxs9kCRnUE+AidK +xwg== 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 co28-20020a0564020c1c00b00410a632cf1asi10919453edb.228.2022.03.02.10.40.57; Wed, 02 Mar 2022 10:41:09 -0800 (PST) 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 B09EB68B362; Wed, 2 Mar 2022 20:40:33 +0200 (EET) 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 0BE8A68B31C for ; Wed, 2 Mar 2022 20:40:25 +0200 (EET) 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 222IePTB010653 for ; Wed, 2 Mar 2022 19:40:25 +0100 Received: by phare.normalesup.org (Postfix, from userid 1001) id 27FA2EB5BD; Wed, 2 Mar 2022 19:40:25 +0100 (CET) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Wed, 2 Mar 2022 19:40:21 +0100 Message-Id: <20220302184023.285022-3-george@nsup.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220302184023.285022-1-george@nsup.org> References: <20220302184023.285022-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]); Wed, 02 Mar 2022 19:40:25 +0100 (CET) Subject: [FFmpeg-devel] [PATCH 3/5] 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: NOEOKYw7sjcU 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(-) Same as sent earlier today. diff --git a/libavfilter/af_aformat.c b/libavfilter/af_aformat.c index d2599431dc..0cdea2220f 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 53883101a8..74037e5eb9 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 c78acbf87b..8940a0e427 100644 --- a/libavfilter/vf_format.c +++ b/libavfilter/vf_format.c @@ -67,10 +67,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)); @@ -80,8 +79,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)