|
@@ -171,11 +171,11 @@ static double eval_expr(Parser *p, AVExpr *e)
|
|
|
|
|
|
static int parse_expr(AVExpr **e, Parser *p);
|
|
|
|
|
|
-void ff_free_expr(AVExpr *e)
|
|
|
+void av_free_expr(AVExpr *e)
|
|
|
{
|
|
|
if (!e) return;
|
|
|
- ff_free_expr(e->param[0]);
|
|
|
- ff_free_expr(e->param[1]);
|
|
|
+ av_free_expr(e->param[0]);
|
|
|
+ av_free_expr(e->param[1]);
|
|
|
av_freep(&e);
|
|
|
}
|
|
|
|
|
@@ -213,7 +213,7 @@ static int parse_primary(AVExpr **e, Parser *p)
|
|
|
if (p->s==NULL) {
|
|
|
av_log(p, AV_LOG_ERROR, "undefined constant or missing (\n");
|
|
|
p->s= next;
|
|
|
- ff_free_expr(d);
|
|
|
+ av_free_expr(d);
|
|
|
return AVERROR(EINVAL);
|
|
|
}
|
|
|
p->s++; // "("
|
|
@@ -223,7 +223,7 @@ static int parse_primary(AVExpr **e, Parser *p)
|
|
|
return ret;
|
|
|
if (p->s[0] != ')') {
|
|
|
av_log(p, AV_LOG_ERROR, "missing )\n");
|
|
|
- ff_free_expr(d);
|
|
|
+ av_free_expr(d);
|
|
|
return AVERROR(EINVAL);
|
|
|
}
|
|
|
p->s++; // ")"
|
|
@@ -231,7 +231,7 @@ static int parse_primary(AVExpr **e, Parser *p)
|
|
|
return 0;
|
|
|
}
|
|
|
if ((ret = parse_expr(&(d->param[0]), p)) < 0) {
|
|
|
- ff_free_expr(d);
|
|
|
+ av_free_expr(d);
|
|
|
return ret;
|
|
|
}
|
|
|
if (p->s[0]== ',') {
|
|
@@ -240,7 +240,7 @@ static int parse_primary(AVExpr **e, Parser *p)
|
|
|
}
|
|
|
if (p->s[0] != ')') {
|
|
|
av_log(p, AV_LOG_ERROR, "missing )\n");
|
|
|
- ff_free_expr(d);
|
|
|
+ av_free_expr(d);
|
|
|
return AVERROR(EINVAL);
|
|
|
}
|
|
|
p->s++; // ")"
|
|
@@ -291,7 +291,7 @@ static int parse_primary(AVExpr **e, Parser *p)
|
|
|
}
|
|
|
|
|
|
av_log(p, AV_LOG_ERROR, "unknown function\n");
|
|
|
- ff_free_expr(d);
|
|
|
+ av_free_expr(d);
|
|
|
return AVERROR(EINVAL);
|
|
|
}
|
|
|
|
|
@@ -328,13 +328,13 @@ static int parse_factor(AVExpr **e, Parser *p)
|
|
|
e1 = e0;
|
|
|
p->s++;
|
|
|
if ((ret = parse_pow(&e2, p, &sign2)) < 0) {
|
|
|
- ff_free_expr(e1);
|
|
|
+ av_free_expr(e1);
|
|
|
return ret;
|
|
|
}
|
|
|
e0 = new_eval_expr(e_pow, 1, e1, e2);
|
|
|
if (!e0) {
|
|
|
- ff_free_expr(e1);
|
|
|
- ff_free_expr(e2);
|
|
|
+ av_free_expr(e1);
|
|
|
+ av_free_expr(e2);
|
|
|
return AVERROR(ENOMEM);
|
|
|
}
|
|
|
if (e0->param[1]) e0->param[1]->value *= (sign2|1);
|
|
@@ -355,13 +355,13 @@ static int parse_term(AVExpr **e, Parser *p)
|
|
|
int c= *p->s++;
|
|
|
e1 = e0;
|
|
|
if ((ret = parse_factor(&e2, p)) < 0) {
|
|
|
- ff_free_expr(e1);
|
|
|
+ av_free_expr(e1);
|
|
|
return ret;
|
|
|
}
|
|
|
e0 = new_eval_expr(c == '*' ? e_mul : e_div, 1, e1, e2);
|
|
|
if (!e0) {
|
|
|
- ff_free_expr(e1);
|
|
|
- ff_free_expr(e2);
|
|
|
+ av_free_expr(e1);
|
|
|
+ av_free_expr(e2);
|
|
|
return AVERROR(ENOMEM);
|
|
|
}
|
|
|
}
|
|
@@ -378,13 +378,13 @@ static int parse_subexpr(AVExpr **e, Parser *p)
|
|
|
while (*p->s == '+' || *p->s == '-') {
|
|
|
e1 = e0;
|
|
|
if ((ret = parse_term(&e2, p)) < 0) {
|
|
|
- ff_free_expr(e1);
|
|
|
+ av_free_expr(e1);
|
|
|
return ret;
|
|
|
}
|
|
|
e0 = new_eval_expr(e_add, 1, e1, e2);
|
|
|
if (!e0) {
|
|
|
- ff_free_expr(e1);
|
|
|
- ff_free_expr(e2);
|
|
|
+ av_free_expr(e1);
|
|
|
+ av_free_expr(e2);
|
|
|
return AVERROR(ENOMEM);
|
|
|
}
|
|
|
};
|
|
@@ -406,14 +406,14 @@ static int parse_expr(AVExpr **e, Parser *p)
|
|
|
while (*p->s == ';') {
|
|
|
e1 = e0;
|
|
|
if ((ret = parse_subexpr(&e2, p)) < 0) {
|
|
|
- ff_free_expr(e1);
|
|
|
+ av_free_expr(e1);
|
|
|
return ret;
|
|
|
}
|
|
|
p->s++;
|
|
|
e0 = new_eval_expr(e_last, 1, e1, e2);
|
|
|
if (!e0) {
|
|
|
- ff_free_expr(e1);
|
|
|
- ff_free_expr(e2);
|
|
|
+ av_free_expr(e1);
|
|
|
+ av_free_expr(e2);
|
|
|
return AVERROR(ENOMEM);
|
|
|
}
|
|
|
};
|
|
@@ -438,7 +438,7 @@ static int verify_expr(AVExpr *e)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-int ff_parse_expr(AVExpr **expr, const char *s,
|
|
|
+int av_parse_expr(AVExpr **expr, const char *s,
|
|
|
const char * const *const_names,
|
|
|
const char * const *func1_names, double (* const *funcs1)(void *, double),
|
|
|
const char * const *func2_names, double (* const *funcs2)(void *, double, double),
|
|
@@ -471,7 +471,7 @@ int ff_parse_expr(AVExpr **expr, const char *s,
|
|
|
if ((ret = parse_expr(&e, &p)) < 0)
|
|
|
goto end;
|
|
|
if (!verify_expr(e)) {
|
|
|
- ff_free_expr(e);
|
|
|
+ av_free_expr(e);
|
|
|
ret = AVERROR(EINVAL);
|
|
|
goto end;
|
|
|
}
|
|
@@ -481,7 +481,7 @@ end:
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-double ff_eval_expr(AVExpr *e, const double *const_values, void *opaque)
|
|
|
+double av_eval_expr(AVExpr *e, const double *const_values, void *opaque)
|
|
|
{
|
|
|
Parser p;
|
|
|
|
|
@@ -490,21 +490,21 @@ double ff_eval_expr(AVExpr *e, const double *const_values, void *opaque)
|
|
|
return eval_expr(&p, e);
|
|
|
}
|
|
|
|
|
|
-int ff_parse_and_eval_expr(double *d, const char *s,
|
|
|
+int av_parse_and_eval_expr(double *d, const char *s,
|
|
|
const char * const *const_names, const double *const_values,
|
|
|
const char * const *func1_names, double (* const *funcs1)(void *, double),
|
|
|
const char * const *func2_names, double (* const *funcs2)(void *, double, double),
|
|
|
void *opaque, int log_offset, void *log_ctx)
|
|
|
{
|
|
|
AVExpr *e = NULL;
|
|
|
- int ret = ff_parse_expr(&e, s, const_names, func1_names, funcs1, func2_names, funcs2, log_offset, log_ctx);
|
|
|
+ int ret = av_parse_expr(&e, s, const_names, func1_names, funcs1, func2_names, funcs2, log_offset, log_ctx);
|
|
|
|
|
|
if (ret < 0) {
|
|
|
*d = NAN;
|
|
|
return ret;
|
|
|
}
|
|
|
- *d = ff_eval_expr(e, const_values, opaque);
|
|
|
- ff_free_expr(e);
|
|
|
+ *d = av_eval_expr(e, const_values, opaque);
|
|
|
+ av_free_expr(e);
|
|
|
return isnan(*d) ? AVERROR(EINVAL) : 0;
|
|
|
}
|
|
|
|
|
@@ -526,21 +526,21 @@ int main(void)
|
|
|
{
|
|
|
int i;
|
|
|
double d;
|
|
|
- ff_parse_and_eval_expr(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
|
|
|
+ av_parse_and_eval_expr(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
|
|
|
const_names, const_values,
|
|
|
NULL, NULL, NULL, NULL, NULL, 0, NULL);
|
|
|
printf("%f == 12.7\n", d);
|
|
|
- ff_parse_and_eval_expr(&d, "80G/80Gi",
|
|
|
+ av_parse_and_eval_expr(&d, "80G/80Gi",
|
|
|
const_names, const_values,
|
|
|
NULL, NULL, NULL, NULL, NULL, 0, NULL);
|
|
|
printf("%f == 0.931322575\n", d);
|
|
|
|
|
|
for (i=0; i<1050; i++) {
|
|
|
START_TIMER
|
|
|
- ff_parse_and_eval_expr(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
|
|
|
+ av_parse_and_eval_expr(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
|
|
|
const_names, const_values,
|
|
|
NULL, NULL, NULL, NULL, NULL, 0, NULL);
|
|
|
- STOP_TIMER("ff_parse_and_eval_expr")
|
|
|
+ STOP_TIMER("av_parse_and_eval_expr")
|
|
|
}
|
|
|
return 0;
|
|
|
}
|