From patchwork Thu Oct 3 19:31:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 52009 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:b18c:0:b0:48e:c0f8:d0de with SMTP id q12csp584586vqn; Thu, 3 Oct 2024 12:33:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWuFAeK4t5pR6R5IkUqDG91/zcElVHXd9eEk6sKIBNfnhoxFnhpqaNPVdTDcUSyoY9G5CvN/rcweHjz9iRxd2aX@gmail.com X-Google-Smtp-Source: AGHT+IEdQOebtuksVsi0phSRVJREaLwBi8lZEuFRFXPhmrV7VqwH8kkbJ3UTewM+kn7KM6kI25NR X-Received: by 2002:a17:907:26c8:b0:a86:c252:aaa2 with SMTP id a640c23a62f3a-a991c0314d9mr32508866b.51.1727983998719; Thu, 03 Oct 2024 12:33:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727983998; cv=none; d=google.com; s=arc-20240605; b=ZDd+58pgHjwNNcY/dmCr4cHaEuw7cfId+lFmvI85VP20BG7pHQdjDGDMayjx2Mxl8W igOT64VY23YfOxS/2oveCfMNVe1/VMcHrtsDkCmslBhnOY83MUDKJE13NjKP/3y0RSh4 sYTx+0GAmIlyL04eDnmK9tbv801oyfHuHo/iyDVPpFXgMg87m+N8Zxx7wZeXdfWq9P+l NJigBDIb8qxQgejVlFwYBEK8xXBFzagL/rUc9YSJdITTT437IcvYUqQC8ecqj+KeWyoy 3FBxGNrkc8m0KFhdc/D8u8OhOkgh5C+1b6sVS7P4e0gvEZJUCHvg5N/hA15iOHhoRMkB IVAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=EaYznPSpCQIJolJKXxlXQD3OCK3+TXwbGU1osMdJlfE=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=Vfihw/BMuojlQ3tNvRQ1nLJWArArR8Fpif1eZUlnG5NIwT14JHf6kO+NeUdVshocSq WkF57VPdmvpQUkakzL3CDSxhyP+SGQ3zjlzvm3mNWO0ptySPw4FEPaKxabUhoH6oaCRW LZJMMyCIwakkR2sZjWtW/1HaAywJWDYofWxpMMKCevza6F4GOqXnzFlTOIZ9U26sudcV pYtMkkxgS/EJUaYboXcr8oYPzKBdAUOu/gts6FBugza5Mz5LB+beHGjstx79yYdESIdL 8OvINeYWdKKF5LOmTTTgf6N0uDaW0B8MWJ0cooboWd6upJOSMBl3zMT8aqa6YFFqsFxe d5Mg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=B1oh6co4; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a9911105b6esi110266566b.1030.2024.10.03.12.33.18; Thu, 03 Oct 2024 12:33:18 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=B1oh6co4; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EBD1768DAF2; Thu, 3 Oct 2024 22:32:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8EA6F68CB9B for ; Thu, 3 Oct 2024 22:32:24 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=B1oh6co4; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 348FA4E16 for ; Thu, 3 Oct 2024 21:32:24 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id fR56L4ekKfo2 for ; Thu, 3 Oct 2024 21:32:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727983942; bh=ND7E+M2hH9e1x58TCh2B9Pypw/HpPIiD4VKSrRX+pIQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=B1oh6co4nl3quskFAePhc0JUFZzH+vHn3wiqRU8XVwpioS2bJreRpGPnb42rUuzdP WKu13hE1zhLhqDQGQcavbfvGvK0B/UtMGdeLFgp5QhFI+TxbZ7fooPNmENuEA/6cOP J/HVUFdkkZUP40YkW62Es1iqMPNdyaEZnpkYVLWj1tq4YIcT3hNk+1GAtPRwrBDhNa 7tWUqATdfalo7RMcBipIl63/eSCn8YSqpcmVkFGVTT/BtgLWOg9t3aoL7MzkWfuVrJ qT/R4uu49OiNz1Q7CYkoFjADvYC9IQwyZyyqWXUavdyuj1tbdJx+lV8rZRAfEDfHYL 9ktHO2//Ln0jA== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 0DF074E12 for ; Thu, 3 Oct 2024 21:32:22 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id ABAEC3A0F02 for ; Thu, 03 Oct 2024 21:32:15 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 3 Oct 2024 21:31:22 +0200 Message-ID: <20241003193127.15818-2-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241003193127.15818-1-anton@khirnov.net> References: <20241003193127.15818-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/7] lavfi/avfilter: move AVFilterContext.{enable, var_values} to FFFilterContext X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Q7Gh3KXoVSJd They are private to generic filtering code. --- libavfilter/avfilter.c | 38 ++++++++++++++++++--------------- libavfilter/avfilter.h | 9 ++++++-- libavfilter/avfilter_internal.h | 5 +++++ 3 files changed, 33 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..22dccf9118 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -501,8 +501,13 @@ 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)