]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/eval.c
DCA: ARM/NEON optimised lfe_fir
[ffmpeg] / libavcodec / eval.c
index 46a894582c68285c0521244e5764459a88faad07..0b2aed9ddcb1627b3629558d59fc17d5bae70428 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * simple arithmetic expression evaluator
- *
  * Copyright (c) 2002-2006 Michael Niedermayer <michaelni@gmx.at>
  * Copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
  *
  * see http://joe.hotchkiss.com/programming/eval/eval.html
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "libavutil/mathematics.h"
-#include "avcodec.h"
+#include "libavutil/avutil.h"
 #include "eval.h"
 
 typedef struct Parser{
@@ -42,10 +34,10 @@ typedef struct Parser{
     char *s;
     const double *const_value;
     const char * const *const_name;          // NULL terminated
-    double (**func1)(void *, double a); // NULL terminated
-    const char **func1_name;          // NULL terminated
-    double (**func2)(void *, double a, double b); // NULL terminated
-    const char **func2_name;          // NULL terminated
+    double (* const *func1)(void *, double a);           // NULL terminated
+    const char * const *func1_name;          // NULL terminated
+    double (* const *func2)(void *, double a, double b); // NULL terminated
+    const char * const *func2_name;          // NULL terminated
     void *opaque;
     const char **error;
 #define VARS 10
@@ -115,7 +107,7 @@ static int strmatch(const char *s, const char *prefix){
     return 1;
 }
 
-struct ff_expr_s {
+struct AVExpr {
     enum {
         e_value, e_const, e_func0, e_func1, e_func2,
         e_squish, e_gauss, e_ld,
@@ -130,7 +122,7 @@ struct ff_expr_s {
         double (*func1)(void *, double);
         double (*func2)(void *, double, double);
     } a;
-    AVExpr *param[2];
+    struct AVExpr *param[2];
 };
 
 static double eval_expr(Parser * p, AVExpr * e) {
@@ -173,10 +165,10 @@ static double eval_expr(Parser * p, AVExpr * e) {
 
 static AVExpr * parse_expr(Parser *p);
 
-void ff_eval_free(AVExpr * e) {
+void ff_free_expr(AVExpr * e) {
     if (!e) return;
-    ff_eval_free(e->param[0]);
-    ff_eval_free(e->param[1]);
+    ff_free_expr(e->param[0]);
+    ff_free_expr(e->param[1]);
     av_freep(&e);
 }
 
@@ -211,7 +203,7 @@ static AVExpr * parse_primary(Parser *p) {
     if(p->s==NULL){
         *p->error = "undefined constant or missing (";
         p->s= next;
-        ff_eval_free(d);
+        ff_free_expr(d);
         return NULL;
     }
     p->s++; // "("
@@ -220,7 +212,7 @@ static AVExpr * parse_primary(Parser *p) {
         d = parse_expr(p);
         if(p->s[0] != ')'){
             *p->error = "missing )";
-            ff_eval_free(d);
+            ff_free_expr(d);
             return NULL;
         }
         p->s++; // ")"
@@ -233,7 +225,7 @@ static AVExpr * parse_primary(Parser *p) {
     }
     if(p->s[0] != ')'){
         *p->error = "missing )";
-        ff_eval_free(d);
+        ff_free_expr(d);
         return NULL;
     }
     p->s++; // ")"
@@ -282,7 +274,7 @@ static AVExpr * parse_primary(Parser *p) {
         }
 
         *p->error = "unknown function";
-        ff_eval_free(d);
+        ff_free_expr(d);
         return NULL;
     }
 
@@ -377,9 +369,9 @@ static int verify_expr(AVExpr * e) {
     }
 }
 
-AVExpr * ff_parse(const char *s, const char * const *const_name,
-               double (**func1)(void *, double), const char **func1_name,
-               double (**func2)(void *, double, double), const char **func2_name,
+AVExpr *ff_parse_expr(const char *s, const char * const *const_name,
+               double (* const *func1)(void *, double), const char * const *func1_name,
+               double (* const *func2)(void *, double, double), const char * const *func2_name,
                const char **error){
     Parser p;
     AVExpr *e = NULL;
@@ -404,7 +396,7 @@ AVExpr * ff_parse(const char *s, const char * const *const_name,
 
     e = parse_expr(&p);
     if (!verify_expr(e)) {
-        ff_eval_free(e);
+        ff_free_expr(e);
         e = NULL;
     }
 end:
@@ -412,7 +404,7 @@ end:
     return e;
 }
 
-double ff_parse_eval(AVExpr * e, const double *const_value, void *opaque) {
+double ff_eval_expr(AVExpr * e, const double *const_value, void *opaque) {
     Parser p;
 
     p.const_value= const_value;
@@ -420,15 +412,15 @@ double ff_parse_eval(AVExpr * e, const double *const_value, void *opaque) {
     return eval_expr(&p, e);
 }
 
-double ff_eval2(const char *s, const double *const_value, const char * const *const_name,
-               double (**func1)(void *, double), const char **func1_name,
-               double (**func2)(void *, double, double), const char **func2_name,
+double ff_parse_and_eval_expr(const char *s, const double *const_value, const char * const *const_name,
+               double (* const *func1)(void *, double), const char * const *func1_name,
+               double (* const *func2)(void *, double, double), const char * const *func2_name,
                void *opaque, const char **error){
-    AVExpr * e = ff_parse(s, const_name, func1, func1_name, func2, func2_name, error);
+    AVExpr * e = ff_parse_expr(s, const_name, func1, func1_name, func2, func2_name, error);
     double d;
     if (!e) return NAN;
-    d = ff_parse_eval(e, const_value, opaque);
-    ff_eval_free(e);
+    d = ff_eval_expr(e, const_value, opaque);
+    ff_free_expr(e);
     return d;
 }
 
@@ -446,13 +438,13 @@ static const char *const_names[]={
 };
 int main(void){
     int i;
-    printf("%f == 12.7\n", ff_eval2("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL, NULL));
-    printf("%f == 0.931322575\n", ff_eval2("80G/80Gi", const_values, const_names, NULL, NULL, NULL, NULL, NULL, NULL));
+    printf("%f == 12.7\n", ff_parse_and_eval_expr("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL, NULL));
+    printf("%f == 0.931322575\n", ff_parse_and_eval_expr("80G/80Gi", const_values, const_names, NULL, NULL, NULL, NULL, NULL, NULL));
 
     for(i=0; i<1050; i++){
         START_TIMER
-            ff_eval2("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL, NULL);
-        STOP_TIMER("ff_eval2")
+            ff_parse_and_eval_expr("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL, NULL);
+        STOP_TIMER("ff_parse_and_eval_expr")
     }
     return 0;
 }