+static int expr_count(AVExpr *e, unsigned *counter, int size, int type)
+{
+ int i;
+
+ if (!e || !counter || !size)
+ return AVERROR(EINVAL);
+
+ for (i = 0; e->type != type && i < 3 && e->param[i]; i++)
+ expr_count(e->param[i], counter, size, type);
+
+ if (e->type == type && e->const_index < size)
+ counter[e->const_index]++;
+
+ return 0;
+}
+
+int av_expr_count_vars(AVExpr *e, unsigned *counter, int size)
+{
+ return expr_count(e, counter, size, e_const);
+}
+
+int av_expr_count_func(AVExpr *e, unsigned *counter, int size, int arg)
+{
+ return expr_count(e, counter, size, ((int[]){e_const, e_func1, e_func2})[arg]);
+}
+