History

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.

Gyan Doshi committed 7 years ago

Commit 1c23abc1 parent 487e7e93 files · +28 −2Browse files

Unified · Split

3 files
  1. libavutil/eval.c +16 −0
  2. libavutil/eval.h +10 −0
  3. libavutil/version.h +2 −2
libavutil/eval.c+16−0
@@ -735,6 +735,22 @@ end: · 734 unmodified lines
735735 return ret;
736736 }
737737
738+int av_expr_count_vars(AVExpr *e, unsigned *counter, int size)
739+{
740+ int i;
741+
742+ if (!e || !counter || !size)
743+ return AVERROR(EINVAL);
744+
745+ for (i = 0; e->type != e_const && i < 3 && e->param[i]; i++)
746+ av_expr_count_vars(e->param[i], counter, size);
747+
748+ if (e->type == e_const && e->a.const_index < size)
749+ counter[e->a.const_index]++;
750+
751+ return 0;
752+}
753+
738754 double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
739755 {
740756 Parser p = { 0 };
libavutil/eval.h+10−0
@@ -86,6 +86,16 @@ int av_expr_parse(AVExpr **expr, const char *s, · 85 unmodified lines
8686 */
8787 double av_expr_eval(AVExpr *e, const double *const_values, void *opaque);
8888
89+/**
90+ * Track the presence of variables and their number of occurrences in a parsed expression
91+ *
92+ * @param counter a zero-initialized array where the count of each variable will be stored
93+ * @param size size of array
94+ * @return 0 on success, a negative value indicates that no expression or array was passed
95+ * or size was zero
96+ */
97+int av_expr_count_vars(AVExpr *e, unsigned *counter, int size);
98+
8999 /**
90100 * Free a parsed expression previously created with av_expr_parse().
91101 */
libavutil/version.h+2−2
@@ -79,8 +79,8 @@ · 78 unmodified lines
7979 */
8080
8181 #define LIBAVUTIL_VERSION_MAJOR 56
82−#define LIBAVUTIL_VERSION_MINOR 35
83−#define LIBAVUTIL_VERSION_MICRO 101
82+#define LIBAVUTIL_VERSION_MINOR 36
83+#define LIBAVUTIL_VERSION_MICRO 100
8484
8585 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
8686 LIBAVUTIL_VERSION_MINOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t