Skip to content

Commit 262e6f8

Browse files
committed
lavfi/avfilter: export AVFilter initialization state
This will allow the AVOption code to detect setting non-runtime options after the filter has been initialized.
1 parent 0548ab2 commit 262e6f8

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

libavfilter/avfilter.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad,
159159
src->outputs[srcpad] || dst->inputs[dstpad])
160160
return AVERROR(EINVAL);
161161

162-
if (!fffilterctx(src)->initialized || !fffilterctx(dst)->initialized) {
162+
if (!(fffilterctx(src)->state_flags & AV_CLASS_STATE_INITIALIZED) ||
163+
!(fffilterctx(dst)->state_flags & AV_CLASS_STATE_INITIALIZED)) {
163164
av_log(src, AV_LOG_ERROR, "Filters must be initialized before linking.\n");
164165
return AVERROR(EINVAL);
165166
}
@@ -676,6 +677,7 @@ static const AVClass avfilter_class = {
676677
.child_next = filter_child_next,
677678
.child_class_iterate = filter_child_class_iterate,
678679
.option = avfilter_options,
680+
.state_flags_offset = offsetof(FFFilterContext, state_flags),
679681
};
680682

681683
static int default_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg,
@@ -909,7 +911,7 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
909911
FFFilterContext *ctxi = fffilterctx(ctx);
910912
int ret = 0;
911913

912-
if (ctxi->initialized) {
914+
if (ctxi->state_flags & AV_CLASS_STATE_INITIALIZED) {
913915
av_log(ctx, AV_LOG_ERROR, "Filter already initialized\n");
914916
return AVERROR(EINVAL);
915917
}
@@ -940,7 +942,7 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
940942
return ret;
941943
}
942944

943-
ctxi->initialized = 1;
945+
ctxi->state_flags |= AV_CLASS_STATE_INITIALIZED;
944946

945947
return 0;
946948
}

libavfilter/avfilter_internal.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ typedef struct FFFilterContext {
100100

101101
avfilter_execute_func *execute;
102102

103-
// 1 when avfilter_init_*() was successfully called on this filter
104-
// 0 otherwise
105-
int initialized;
103+
// AV_CLASS_STATE_FLAG_*
104+
unsigned state_flags;
106105
} FFFilterContext;
107106

108107
static inline FFFilterContext *fffilterctx(AVFilterContext *ctx)

libavfilter/graphparser.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,8 @@ int avfilter_graph_segment_init(AVFilterGraphSegment *seg, int flags)
627627

628628
if (p->filter_name)
629629
return fail_creation_pending(seg, p->filter_name, __func__);
630-
if (!p->filter || fffilterctx(p->filter)->initialized)
630+
if (!p->filter ||
631+
(fffilterctx(p->filter)->state_flags & AV_CLASS_STATE_INITIALIZED))
631632
continue;
632633

633634
ret = avfilter_init_dict(p->filter, NULL);

0 commit comments

Comments
 (0)