From patchwork Sat Nov 16 12:09:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan Doshi X-Patchwork-Id: 16295 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id E465F44AC5E for ; Sat, 16 Nov 2019 14:10:11 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AF4A768A3ED; Sat, 16 Nov 2019 14:10:11 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A6BC2689BCE for ; Sat, 16 Nov 2019 14:10:03 +0200 (EET) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 47FYty6hjhzQlCD for ; Sat, 16 Nov 2019 13:10:02 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by gerste.heinlein-support.de (gerste.heinlein-support.de [91.198.250.173]) (amavisd-new, port 10030) with ESMTP id i29BaRwr2_NF for ; Sat, 16 Nov 2019 13:09:59 +0100 (CET) To: FFmpeg development discussions and patches From: Gyan Message-ID: <16cc4e76-ae53-476d-f406-a12474326feb@gyani.pro> Date: Sat, 16 Nov 2019 17:39:56 +0530 MIME-Version: 1.0 Content-Language: en-US Subject: [FFmpeg-devel] [PATCH v2] avutil/eval: add function to track variable use X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" As suggested by Michael in the review for the vf_scale patch, new eval function tracks count of all variables in a parsed expression in an array. Thanks, Gyan From 6d4d8ab2b582991ccb787d18d14be31256a785aa Mon Sep 17 00:00:00 2001 From: Gyan Doshi Date: Sat, 2 Nov 2019 20:16:42 +0530 Subject: [PATCH v2] avutil/eval: add function to track variable use 1)Some filters allow cross-referenced expressions e.g. x=y+10. In such cases, filters evaluate expressions multiple times for successful evaluation of all expressions. If the expression for one or more variables contains a RNG, the result may vary across evaluation leading to inconsistent values across the cross-referenced expressions. 2)A related case is circular expressions e.g. x=y+10 and y=x+10 which cannot be succesfully resolved. 3)Certain filter variables may only be applicable in specific eval modes and lead to a failure of evaluation in other modes e.g. pts is only relevant for frame eval mode. At present, there is no reliable means to identify these occurrences and thus the error messages provided are broad or inaccurate. The helper function introduced - av_expr_count_vars - allows developers to identify the use and count of variables in expressions and thus tailor the error message, allow for a graceful fallback and/or decide evaluation order. --- doc/APIchanges | 3 +++ libavutil/eval.c | 16 ++++++++++++++++ libavutil/eval.h | 10 ++++++++++ libavutil/version.h | 4 ++-- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 48168f82e6..f39eda7afc 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,9 @@ libavutil: 2017-10-21 API changes, most recent first: +2019-11-16 - xxxxxxxxxx - lavu 56.36.100 - eval API + Add av_expr_count_vars(). + 2019-10-14 - f3746d31f9 - lavu 56.35.101 - opt.h Add AV_OPT_FLAG_RUNTIME_PARAM. diff --git a/libavutil/eval.c b/libavutil/eval.c index 48832979e2..62d2ae938b 100644 --- a/libavutil/eval.c +++ b/libavutil/eval.c @@ -735,6 +735,22 @@ end: return ret; } +int av_expr_count_vars(AVExpr *e, unsigned *counter, int size) +{ + int i; + + if (!e || !counter || !size) + return AVERROR(EINVAL); + + for (i = 0; e->type != e_const && i < 3 && e->param[i]; i++) + av_expr_count_vars(e->param[i], counter, size); + + if (e->type == e_const && e->a.const_index < size) + counter[e->a.const_index]++; + + return 0; +} + double av_expr_eval(AVExpr *e, const double *const_values, void *opaque) { Parser p = { 0 }; diff --git a/libavutil/eval.h b/libavutil/eval.h index dacd22b96e..9bdb10cca2 100644 --- a/libavutil/eval.h +++ b/libavutil/eval.h @@ -86,6 +86,16 @@ int av_expr_parse(AVExpr **expr, const char *s, */ double av_expr_eval(AVExpr *e, const double *const_values, void *opaque); +/** + * Track the presence of variables and their number of occurrences in a parsed expression + * + * @param counter a zero-initialized array where the count of each variable will be stored + * @param size size of array + * @return 0 on success, a negative value indicates that no expression or array was passed + * or size was zero + */ +int av_expr_count_vars(AVExpr *e, unsigned *counter, int size); + /** * Free a parsed expression previously created with av_expr_parse(). */ diff --git a/libavutil/version.h b/libavutil/version.h index 27d663baf1..af3abf7265 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,8 +79,8 @@ */ #define LIBAVUTIL_VERSION_MAJOR 56 -#define LIBAVUTIL_VERSION_MINOR 35 -#define LIBAVUTIL_VERSION_MICRO 101 +#define LIBAVUTIL_VERSION_MINOR 36 +#define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ LIBAVUTIL_VERSION_MINOR, \