From b1247e7c1ffc5c95400c2d3adce9406a6c040a8c Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 3 Oct 2024 19:15:58 +0200 Subject: [PATCH] lavfi/avfilter: move AVFilterContext.ready to FFFilterContext This field is private to the generic filtering code. --- libavfilter/avfilter.c | 9 ++++++--- libavfilter/avfilter.h | 7 ++++--- libavfilter/avfilter_internal.h | 7 +++++++ libavfilter/avfiltergraph.c | 18 +++++++++++------- libavfilter/version_major.h | 1 + 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index dc06ebab4d..1a0e94b21d 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -237,7 +237,8 @@ static void update_link_current_pts(FilterLinkInternal *li, int64_t pts) void ff_filter_set_ready(AVFilterContext *filter, unsigned priority) { - filter->ready = FFMAX(filter->ready, priority); + FFFilterContext *ctxi = fffilterctx(filter); + ctxi->ready = FFMAX(ctxi->ready, priority); } /** @@ -473,6 +474,7 @@ void ff_tlog_link(void *ctx, AVFilterLink *link, int end) int ff_request_frame(AVFilterLink *link) { FilterLinkInternal * const li = ff_link_internal(link); + FFFilterContext * const ctxi_dst = fffilterctx(link->dst); FF_TPRINTF_START(NULL, request_frame); ff_tlog_link(NULL, link, 1); @@ -482,7 +484,7 @@ int ff_request_frame(AVFilterLink *link) if (li->status_in) { if (ff_framequeue_queued_frames(&li->fifo)) { av_assert1(!li->frame_wanted_out); - av_assert1(link->dst->ready >= 300); + av_assert1(ctxi_dst->ready >= 300); return 0; } else { /* Acknowledge status change. Filters using ff_request_frame() will @@ -1384,12 +1386,13 @@ static int ff_filter_activate_default(AVFilterContext *filter) int ff_filter_activate(AVFilterContext *filter) { + FFFilterContext *ctxi = fffilterctx(filter); int ret; /* Generic timeline support is not yet implemented but should be easy */ av_assert1(!(filter->filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC && filter->filter->activate)); - filter->ready = 0; + ctxi->ready = 0; ret = filter->filter->activate ? filter->filter->activate(filter) : ff_filter_activate_default(filter); if (ret == FFERROR_NOT_READY) diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index f2c4a64004..1748dd3023 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -518,12 +518,13 @@ struct AVFilterContext { */ AVBufferRef *hw_device_ctx; +#if FF_API_CONTEXT_PUBLIC /** - * Ready status of the filter. - * A non-0 value means that the filter needs activating; - * a higher value suggests a more urgent activation. + * @deprecated this field should never have been accessed by callers */ + attribute_deprecated unsigned ready; +#endif /** * Sets the number of extra hardware frames which the filter will diff --git a/libavfilter/avfilter_internal.h b/libavfilter/avfilter_internal.h index 9ba890a70c..7041d787b0 100644 --- a/libavfilter/avfilter_internal.h +++ b/libavfilter/avfilter_internal.h @@ -102,6 +102,13 @@ typedef struct FFFilterContext { // AV_CLASS_STATE_FLAG_* unsigned state_flags; + + /** + * Ready status of the filter. + * A non-0 value means that the filter needs activating; + * a higher value suggests a more urgent activation. + */ + unsigned ready; } FFFilterContext; static inline FFFilterContext *fffilterctx(AVFilterContext *ctx) diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 38077ff701..7bc7700743 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -1470,15 +1470,19 @@ int avfilter_graph_request_oldest(AVFilterGraph *graph) int ff_filter_graph_run_once(AVFilterGraph *graph) { - AVFilterContext *filter; + FFFilterContext *ctxi; unsigned i; av_assert0(graph->nb_filters); - filter = graph->filters[0]; - for (i = 1; i < graph->nb_filters; i++) - if (graph->filters[i]->ready > filter->ready) - filter = graph->filters[i]; - if (!filter->ready) + ctxi = fffilterctx(graph->filters[0]); + for (i = 1; i < graph->nb_filters; i++) { + FFFilterContext *ctxi_other = fffilterctx(graph->filters[i]); + + if (ctxi_other->ready > ctxi->ready) + ctxi = ctxi_other; + } + + if (!ctxi->ready) return AVERROR(EAGAIN); - return ff_filter_activate(filter); + return ff_filter_activate(&ctxi->p); } diff --git a/libavfilter/version_major.h b/libavfilter/version_major.h index b2c761370f..41374fbbe5 100644 --- a/libavfilter/version_major.h +++ b/libavfilter/version_major.h @@ -37,5 +37,6 @@ #define FF_API_LINK_PUBLIC (LIBAVFILTER_VERSION_MAJOR < 11) #define FF_API_BUFFERSINK_OPTS (LIBAVFILTER_VERSION_MAJOR < 11) +#define FF_API_CONTEXT_PUBLIC (LIBAVFILTER_VERSION_MAJOR < 11) #endif /* AVFILTER_VERSION_MAJOR_H */