[FFmpeg-devel] [PATCH 6/7] Implement if(expr, cond) binary function evaluation.

Stefano Sabatini stefano.sabatini-lala
Mon Nov 1 00:23:32 CET 2010


---
 doc/eval.texi    |    5 +++++
 libavutil/eval.c |   11 ++++++++++-
 2 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/doc/eval.texi b/doc/eval.texi
index 2416442..c944b3e 100644
--- a/doc/eval.texi
+++ b/doc/eval.texi
@@ -56,6 +56,11 @@ The function returns the loaded value.
 Evaluate expression @var{expr} when the expression @var{cond} is
 true, and returns the value of the last @var{expr} evaluation, or NAN
 if @var{cond} was always false.
+
+ at item if(cond, expr)
+Evaluate expression @var{expr} only if the expression @var{cond} is
+true, and returns the value of the last @var{expr} evaluation, or NAN
+if @var{cond} was false.
 @end table
 
 It is possible to define more unary and binary functions used in an
diff --git a/libavutil/eval.c b/libavutil/eval.c
index 97af022..83e602d 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -121,7 +121,7 @@ struct AVExpr {
         e_squish, e_gauss, e_ld,
         e_mod, e_max, e_min, e_eq, e_gt, e_gte,
         e_pow, e_mul, e_div, e_add,
-        e_last, e_st, e_while,
+        e_last, e_st, e_while, e_if,
     } type;
     double value; // is sign in other types
     union {
@@ -150,6 +150,12 @@ static double eval_expr(Parser *p, AVExpr *e)
                 d=eval_expr(p, e->param[1]);
             return d;
         }
+        case e_if: {
+            double d = NAN;
+            if (eval_expr(p, e->param[0]))
+                d=eval_expr(p, e->param[1]);
+            return d;
+        }
         default: {
             double d = eval_expr(p, e->param[0]);
             double d2 = eval_expr(p, e->param[1]);
@@ -274,6 +280,7 @@ static int parse_primary(AVExpr **e, Parser *p)
     else if (strmatch(next, "ld"    )) d->type = e_ld;
     else if (strmatch(next, "st"    )) d->type = e_st;
     else if (strmatch(next, "while" )) d->type = e_while;
+    else if (strmatch(next, "if"    )) d->type = e_if;
     else {
         for (i=0; p->func1_names && p->func1_names[i]; i++) {
             if (strmatch(next, p->func1_names[i])) {
@@ -574,6 +581,8 @@ int main(void)
         "st(1, 1); st(2, 2); st(0,1); while(lte(ld(0),10), st(3, ld(1)+ld(2)); st(1, ld(2)); st(2, ld(3)); st(0, ld(0)+1)); ld(3)",
         "while(0, 10)",
         "st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0));st(0, ld(0)+1))",
+        "if(1, 123)",
+        "if(eq(0,1), 123)",
         NULL
     };
 
-- 
1.7.1




More information about the ffmpeg-devel mailing list