From 71f176e3ce754bc5c332caccf99e85da90896525 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 3 Oct 2024 20:44:38 +0200 Subject: [PATCH] lavfi/avfilter: move AVFilterContext.{enable,var_values} to FFFilterContext They are private to generic filtering code. --- libavfilter/avfilter.c | 38 ++++++++++++++++++--------------- libavfilter/avfilter.h | 13 +++++++++-- libavfilter/avfilter_internal.h | 5 +++++ 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 1a0e94b21d..dfb30002b1 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -564,11 +564,12 @@ enum { VAR_VARS_NB }; -static int set_enable_expr(AVFilterContext *ctx, const char *expr) +static int set_enable_expr(FFFilterContext *ctxi, const char *expr) { + AVFilterContext *ctx = &ctxi->p; int ret; char *expr_dup; - AVExpr *old = ctx->enable; + AVExpr *old = ctxi->enable; if (!(ctx->filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE)) { av_log(ctx, AV_LOG_ERROR, "Timeline ('enable' option) not supported " @@ -580,15 +581,15 @@ static int set_enable_expr(AVFilterContext *ctx, const char *expr) if (!expr_dup) return AVERROR(ENOMEM); - if (!ctx->var_values) { - ctx->var_values = av_calloc(VAR_VARS_NB, sizeof(*ctx->var_values)); - if (!ctx->var_values) { + if (!ctxi->var_values) { + ctxi->var_values = av_calloc(VAR_VARS_NB, sizeof(*ctxi->var_values)); + if (!ctxi->var_values) { av_free(expr_dup); return AVERROR(ENOMEM); } } - ret = av_expr_parse((AVExpr**)&ctx->enable, expr_dup, var_names, + ret = av_expr_parse(&ctxi->enable, expr_dup, var_names, NULL, NULL, NULL, NULL, 0, ctx->priv); if (ret < 0) { av_log(ctx->priv, AV_LOG_ERROR, @@ -618,7 +619,7 @@ int avfilter_process_command(AVFilterContext *filter, const char *cmd, const cha av_log(filter, AV_LOG_INFO, "%s", res); return 0; }else if(!strcmp(cmd, "enable")) { - return set_enable_expr(filter, arg); + return set_enable_expr(fffilterctx(filter), arg); }else if(filter->filter->process_command) { return filter->filter->process_command(filter, cmd, arg, res, res_len, flags); } @@ -792,10 +793,12 @@ static void free_link(AVFilterLink *link) void avfilter_free(AVFilterContext *filter) { + FFFilterContext *ctxi; int i; if (!filter) return; + ctxi = fffilterctx(filter); if (filter->graph) ff_filter_graph_remove_filter(filter->graph, filter); @@ -829,9 +832,9 @@ void avfilter_free(AVFilterContext *filter) command_queue_pop(filter); } av_opt_free(filter); - av_expr_free(filter->enable); - filter->enable = NULL; - av_freep(&filter->var_values); + av_expr_free(ctxi->enable); + ctxi->enable = NULL; + av_freep(&ctxi->var_values); av_free(filter); } @@ -939,7 +942,7 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options) return ret; if (ctx->enable_str) { - ret = set_enable_expr(ctx, ctx->enable_str); + ret = set_enable_expr(ctxi, ctx->enable_str); if (ret < 0) return ret; } @@ -1559,6 +1562,7 @@ int ff_inlink_evaluate_timeline_at_frame(AVFilterLink *link, const AVFrame *fram { FilterLink *l = ff_filter_link(link); AVFilterContext *dstctx = link->dst; + FFFilterContext *dsti = fffilterctx(dstctx); int64_t pts = frame->pts; #if FF_API_FRAME_PKT FF_DISABLE_DEPRECATION_WARNINGS @@ -1569,15 +1573,15 @@ FF_ENABLE_DEPRECATION_WARNINGS if (!dstctx->enable_str) return 1; - dstctx->var_values[VAR_N] = l->frame_count_out; - dstctx->var_values[VAR_T] = pts == AV_NOPTS_VALUE ? NAN : pts * av_q2d(link->time_base); - dstctx->var_values[VAR_W] = link->w; - dstctx->var_values[VAR_H] = link->h; + dsti->var_values[VAR_N] = l->frame_count_out; + dsti->var_values[VAR_T] = pts == AV_NOPTS_VALUE ? NAN : pts * av_q2d(link->time_base); + dsti->var_values[VAR_W] = link->w; + dsti->var_values[VAR_H] = link->h; #if FF_API_FRAME_PKT - dstctx->var_values[VAR_POS] = pos == -1 ? NAN : pos; + dsti->var_values[VAR_POS] = pos == -1 ? NAN : pos; #endif - return fabs(av_expr_eval(dstctx->enable, dstctx->var_values, NULL)) >= 0.5; + return fabs(av_expr_eval(dsti->enable, dsti->var_values, NULL)) >= 0.5; } void ff_inlink_request_frame(AVFilterLink *link) diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 1748dd3023..e3de3ec9ba 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -501,8 +501,17 @@ struct AVFilterContext { struct AVFilterCommand *command_queue; char *enable_str; ///< enable expression string - void *enable; ///< parsed expression (AVExpr*) - double *var_values; ///< variable values for the enable expression +#if FF_API_CONTEXT_PUBLIC + /** + * @deprecated unused + */ + attribute_deprecated + void *enable; + /** + * @deprecated unused + */ + double *var_values; +#endif int is_disabled; ///< the enabled state from the last expression evaluation /** diff --git a/libavfilter/avfilter_internal.h b/libavfilter/avfilter_internal.h index 7041d787b0..38c7c5b53e 100644 --- a/libavfilter/avfilter_internal.h +++ b/libavfilter/avfilter_internal.h @@ -109,6 +109,11 @@ typedef struct FFFilterContext { * a higher value suggests a more urgent activation. */ unsigned ready; + + ///< parsed expression + struct AVExpr *enable; + ///< variable values for the enable expression + double *var_values; } FFFilterContext; static inline FFFilterContext *fffilterctx(AVFilterContext *ctx)