[FFmpeg-devel] [PATCH] avutil/eval: add function to track variable use

Gyan ffmpeg at gyani.pro
Sun Nov 3 07:44:25 EET 2019


Helps better identification of expr eval failures.

Gyan
-------------- next part --------------
From 19bce329464676f071707b99575f80e5abe1cd4c Mon Sep 17 00:00:00 2001
From: Gyan Doshi <ffmpeg at gyani.pro>
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, \
-- 
2.23.0


More information about the ffmpeg-devel mailing list