Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Nicolas George <george@nsup.org>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 4/7] lavfi/(a)format: factor finding the delimiter
Date: Tue,  2 Aug 2022 18:54:18 +0200
Message-ID: <20220802165421.137563-4-george@nsup.org> (raw)
In-Reply-To: <20220802165421.137563-1-george@nsup.org>

Signed-off-by: Nicolas George <george@nsup.org>
---
 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)
-- 
2.35.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".

  parent reply	other threads:[~2022-08-02 16:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-02 16:54 [FFmpeg-devel] [PATCH 1/7] lavu/pixfmt: summarize yuv naming conventions Nicolas George
2022-08-02 16:54 ` [FFmpeg-devel] [PATCH 2/7] lavfi/graphdump: add plain listing output Nicolas George
2022-08-02 16:54 ` [FFmpeg-devel] [PATCH 3/7] fftools: add -lavfi_dump option Nicolas George
2022-08-02 16:54 ` Nicolas George [this message]
2022-08-02 16:54 ` [FFmpeg-devel] [PATCH 5/7] lavfi/(a)format: support slash as a delimiter Nicolas George
2022-08-02 16:54 ` [FFmpeg-devel] [PATCH 6/7] lavi/pixdesc: add comments about pixel format scoring Nicolas George
2022-08-04 13:52   ` Michael Niedermayer
2022-08-02 16:54 ` [FFmpeg-devel] [PATCH 7/7] tests: add coverage for libavfilter's format negotiation Nicolas George
2022-08-04 13:49 ` [FFmpeg-devel] [PATCH 1/7] lavu/pixfmt: summarize yuv naming conventions Michael Niedermayer
2022-08-04 13:57   ` Nicolas George
2022-08-04 15:04     ` Michael Niedermayer
2022-08-06 10:36       ` Nicolas George

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220802165421.137563-4-george@nsup.org \
    --to=george@nsup.org \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git