summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2023-01-17 10:51:57 +0100
committerAnton Khirnov <anton@khirnov.net>2023-01-18 10:09:11 +0100
commit6d3ef96ca62853c48c8dfed9134e89012598b2a5 (patch)
tree0029192cb8fc8670cf15ee35afade40810e18473
parent5b3bd387cb2940e42c7ff263f0ebae528d811de2 (diff)
lavfi/avfilter: track whether a filter has been initialized
Refuse to link uninitialized filters or initialize a filter twice.
-rw-r--r--libavfilter/avfilter.c12
-rw-r--r--libavfilter/internal.h4
2 files changed, 16 insertions, 0 deletions
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,