[FFmpeg-devel] [PATCH 7/7] Implement isnan() function evaluation.

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


---
 doc/eval.texi    |    1 +
 libavutil/eval.c |    9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/doc/eval.texi b/doc/eval.texi
index c944b3e..768525c 100644
--- a/doc/eval.texi
+++ b/doc/eval.texi
@@ -33,6 +33,7 @@ The following functions are available:
 @item abs(x)
 @item squish(x)
 @item gauss(x)
+ at item isnan(x)
 @item mod(x, y)
 @item max(x, y)
 @item min(x, y)
diff --git a/libavutil/eval.c b/libavutil/eval.c
index 83e602d..7438ab2 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -118,7 +118,7 @@ static int strmatch(const char *s, const char *prefix)
 struct AVExpr {
     enum {
         e_value, e_const, e_func0, e_func1, e_func2,
-        e_squish, e_gauss, e_ld,
+        e_squish, e_gauss, e_ld, e_isnan,
         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_if,
@@ -144,6 +144,7 @@ static double eval_expr(Parser *p, AVExpr *e)
         case e_squish: return 1/(1+exp(4*eval_expr(p, e->param[0])));
         case e_gauss: { double d = eval_expr(p, e->param[0]); return exp(-d*d/2)/sqrt(2*M_PI); }
         case e_ld:     return e->value * p->var[av_clip(eval_expr(p, e->param[0]), 0, VARS-1)];
+        case e_isnan:  return e->value * isnan(eval_expr(p, e->param[0]));
         case e_while: {
             double d = NAN;
             while (eval_expr(p, e->param[0]))
@@ -278,6 +279,7 @@ static int parse_primary(AVExpr **e, Parser *p)
     else if (strmatch(next, "lte"   )) { AVExpr *tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gt; }
     else if (strmatch(next, "lt"    )) { AVExpr *tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gte; }
     else if (strmatch(next, "ld"    )) d->type = e_ld;
+    else if (strmatch(next, "isnan" )) d->type = e_isnan;
     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;
@@ -443,7 +445,8 @@ static int verify_expr(AVExpr *e)
         case e_func1:
         case e_squish:
         case e_ld:
-        case e_gauss: return verify_expr(e->param[0]);
+        case e_gauss:
+        case e_isnan: return verify_expr(e->param[0]);
         default: return verify_expr(e->param[0]) && verify_expr(e->param[1]);
     }
 }
@@ -583,6 +586,8 @@ int main(void)
         "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)",
+        "isnan(1)",
+        "isnan(NAN)",
         NULL
     };
 
-- 
1.7.1




More information about the ffmpeg-devel mailing list