From patchwork Sun Nov 3 05:44:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan Doshi X-Patchwork-Id: 16087 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 4B5D2448478 for ; Sun, 3 Nov 2019 07:44:40 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 26CA268B509; Sun, 3 Nov 2019 07:44:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 32744680AAE for ; Sun, 3 Nov 2019 07:44:33 +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-102.mailbox.org (Postfix) with ESMTPS id 475Py91By8zKmj4 for ; Sun, 3 Nov 2019 06:44:33 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de [80.241.56.116]) (amavisd-new, port 10030) with ESMTP id PmKxnXp2GbpM for ; Sun, 3 Nov 2019 06:44:29 +0100 (CET) To: FFmpeg development discussions and patches From: Gyan Message-ID: <72be1962-95c2-e216-ecb1-5414508e47f9@gyani.pro> Date: Sun, 3 Nov 2019 11:14:25 +0530 MIME-Version: 1.0 Content-Language: en-US Subject: [FFmpeg-devel] [PATCH] 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" Helps better identification of expr eval failures. Gyan From 19bce329464676f071707b99575f80e5abe1cd4c Mon Sep 17 00:00:00 2001 From: Gyan Doshi Date: Sat, 2 Nov 2019 20:16:42 +0530 Subject: [PATCH] avutil/eval: add function to track variable use Helps avoid multiple evals of cross-referenced expressions and catch the use of non-applicable variables with respect to eval or special mode in filters --- libavutil/eval.c | 21 +++++++++++++++++++++ libavutil/eval.h | 10 ++++++++++ libavutil/version.h | 4 ++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/libavutil/eval.c b/libavutil/eval.c index 48832979e2..ed0fe636f7 100644 --- a/libavutil/eval.c +++ b/libavutil/eval.c @@ -735,6 +735,27 @@ end: return ret; } +int av_expr_count_var(AVExpr *e, int var_start, int var_end) +{ + int i, count = 0; + + if (var_start >= var_end) + return AVERROR(EINVAL); + + if (!e) + return AVERROR(EINVAL); + + for (i = 0; e->type != e_const && i < 3 && e->param[i]; i++) + count += av_expr_count_var(e->param[i], var_start, var_end); + + if (e->type == e_const && + e->a.const_index >= var_start && + e->a.const_index < var_end) + count++; + + return count; +} + 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..030e5617cc 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); +/** + * Return the number of occurrences of variables within a range in a parsed expression + * + * @param var_start index of the start of the range of variables being seached for in the const_names identifiers + * @param var_end index of the first variable after the range of variables being seached for in the const_names identifiers + * @return the number of occurrences of the variables in the range, a negative value indicates that no expression was passed + * or the range wasn't strictly monotonic + */ +int av_expr_count_var(AVExpr *e, int var_start, int var_end); + /** * 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, \