Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [RFC PATCH 2/3] lavfi/avfilter: track whether a filter has been initialized
Date: Tue, 17 Jan 2023 18:04:59 +0100
Message-ID: <20230117170500.4053-2-anton@khirnov.net> (raw)
In-Reply-To: <20230117170500.4053-1-anton@khirnov.net>

Refuse to link uninitialized filters or initialize a filter twice.
---
 libavfilter/avfilter.c | 12 ++++++++++++
 libavfilter/internal.h |  4 ++++
 2 files changed, 16 insertions(+)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 86b275dc4f..619b96f5ac 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -158,6 +158,11 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad,
         src->outputs[srcpad]      || dst->inputs[dstpad])
         return AVERROR(EINVAL);
 
+    if (!src->internal->initialized || !dst->internal->initialized) {
+        av_log(src, AV_LOG_ERROR, "Filters must be initialized before linking.\n");
+        return AVERROR(EINVAL);
+    }
+
     if (src->output_pads[srcpad].type != dst->input_pads[dstpad].type) {
         av_log(src, AV_LOG_ERROR,
                "Media type mismatch between the '%s' filter output pad %d (%s) and the '%s' filter input pad %d (%s)\n",
@@ -872,6 +877,11 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
 {
     int ret = 0;
 
+    if (ctx->internal->initialized) {
+        av_log(ctx, AV_LOG_ERROR, "Filter already initialized\n");
+        return AVERROR(EINVAL);
+    }
+
     ret = av_opt_set_dict2(ctx, options, AV_OPT_SEARCH_CHILDREN);
     if (ret < 0) {
         av_log(ctx, AV_LOG_ERROR, "Error applying generic filter options.\n");
@@ -898,6 +908,8 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
             return ret;
     }
 
+    ctx->internal->initialized = 1;
+
     return 0;
 }
 
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index 2ec41917f7..8b232a8d8f 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -137,6 +137,10 @@ struct AVFilterGraphInternal {
 
 struct AVFilterInternal {
     avfilter_execute_func *execute;
+
+    // 1 when avfilter_init_*() was successfully called on this filter
+    // 0 otherwise
+    int initialized;
 };
 
 static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func,
-- 
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".

  reply	other threads:[~2023-01-17 17:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-17 17:04 [FFmpeg-devel] [RFC PATCH 1/3] lavfi/avfilter: export process_options() Anton Khirnov
2023-01-17 17:04 ` Anton Khirnov [this message]
2023-01-17 17:05 ` [FFmpeg-devel] [RFC PATCH 3/3] lavfi: add a new filtergraph parsing API Anton Khirnov

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=20230117170500.4053-2-anton@khirnov.net \
    --to=anton@khirnov.net \
    --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