[FFmpeg-devel] [PATCH 09/12] Change the order of parameters for ff_parse_and_eval_expr(), place the names before the values.

Stefano Sabatini stefano.sabatini-lala
Mon Apr 12 00:37:58 CEST 2010


This looks more readable, as the user is expected to know the names
before the values, the other order looks awkward.
---
 libavcodec/eval.c |   27 ++++++++++++++++++++-------
 libavcodec/eval.h |   16 ++++++++--------
 libavcodec/opt.c  |    4 ++--
 3 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/libavcodec/eval.c b/libavcodec/eval.c
index 540236a..50aff9b 100644
--- a/libavcodec/eval.c
+++ b/libavcodec/eval.c
@@ -480,9 +480,10 @@ double ff_eval_expr(AVExpr *e, const double *var_values, void *opaque)
     return eval_expr(&p, e);
 }
 
-int ff_parse_and_eval_expr(double *res, const char *s, const double *var_values, const char * const *var_names,
-                           double (**func1)(void *, double), const char * const *func1_names,
-                           double (**func2)(void *, double, double), const char * const *func2_names,
+int ff_parse_and_eval_expr(double *res, const char *s,
+                           const char * const *var_names, const double *var_values,
+                           const char * const *func1_names, double (**func1)(void *, double),
+                           const char * const *func2_names, double (**func2)(void *, double, double),
                            void *opaque, void *log_ctx)
 {
     AVExpr *e;
@@ -518,16 +519,28 @@ 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)", var_values, var_names, NULL, NULL, NULL, NULL, NULL, NULL);
+    ff_parse_and_eval_expr(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
+                           var_names, var_values,
+                           NULL, NULL,
+                           NULL, NULL,
+                           NULL, NULL);
     printf("%f == 12.7\n", d);
 
-    av_parse_and_eval_expr(&d, "80G/80Gi", var_values, var_names, NULL, NULL, NULL, NULL, NULL, NULL);
+    ff_parse_and_eval_expr(&d, "80G/80Gi",
+                           var_names, var_values,
+                           NULL, NULL,
+                           NULL, NULL,
+                           NULL, 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)", var_values, var_names, NULL, NULL, NULL, NULL, NULL, NULL);
-        STOP_TIMER("ff_parse_and_eval_expr")
+            ff_parse_and_eval_expr(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
+                                   var_names, var_values,
+                                   NULL, NULL,
+                                   NULL, NULL,
+                                   NULL, NULL);
+        STOP_TIMER("ff_eval2")
     }
     return 0;
 }
diff --git a/libavcodec/eval.h b/libavcodec/eval.h
index 52b81af..f0518f4 100644
--- a/libavcodec/eval.h
+++ b/libavcodec/eval.h
@@ -35,20 +35,20 @@ typedef struct AVExpr AVExpr;
  * @param res in case of success puts here the result of the
  * expression evaluation, NAN otherwise
  * @param s expression as a zero terminated string for example "1+2^3+5*5+sin(2/3)"
- * @param var_values a zero terminated array of values for the identifers from var_names
- * @param func1 NULL terminated array of function pointers for functions which take 1 argument
- * @param func2 NULL terminated array of function pointers for functions which take 2 arguments
  * @param var_names NULL terminated array of zero terminated strings of variable identifers for example {"PI", "E", 0}
+ * @param var_values a zero terminated array of values for the identifers from var_names
  * @param func1_names NULL terminated array of zero terminated strings of func1 identifers
+ * @param func1 NULL terminated array of function pointers for functions which take 1 argument
  * @param func2_names NULL terminated array of zero terminated strings of func2 identifers
+ * @param func2 NULL terminated array of function pointers for functions which take 2 arguments
  * @param opaque a pointer which will be passed to all functions from func1 and func2
  * @return 0 in case of successfull parsing, a negative value
  * corresponding to an AVERROR code in case of parsing failure
  */
 int ff_parse_and_eval_expr(double *res, const char *s,
-                           const double *var_values, const char * const *var_names,
-                           double (**func1)(void *, double), const char * const *func1_names,
-                           double (**func2)(void *, double, double), const char * const *func2_names,
+                           const char * const *var_names,   const double *var_values,
+                           const char * const *func1_names, double (**func1)(void *, double),
+                           const char * const *func2_names, double (**func2)(void *, double, double),
                            void *opaque, void *log_ctx);
 
 /**
@@ -58,11 +58,11 @@ int ff_parse_and_eval_expr(double *res, const char *s,
  * which must be freed with ff_free_expr() by the user when it is not
  * needed anymore
  * @param s expression as a zero terminated string for example "1+2^3+5*5+sin(2/3)"
- * @param func1 NULL terminated array of function pointers for functions which take 1 argument
- * @param func2 NULL terminated array of function pointers for functions which take 2 arguments
  * @param var_names NULL terminated array of zero terminated strings of variable identifers for example {"PI", "E", 0}
  * @param func1_names NULL terminated array of zero terminated strings of func1 identifers
+ * @param func1 NULL terminated array of function pointers for functions which take 1 argument
  * @param func2_names NULL terminated array of zero terminated strings of func2 identifers
+ * @param func2 NULL terminated array of function pointers for functions which take 2 arguments
  * @return 0 in case of success, a negative error corresponding to an
  * AVERROR code in case of failure
  */
diff --git a/libavcodec/opt.c b/libavcodec/opt.c
index 30a1612..00ce455 100644
--- a/libavcodec/opt.c
+++ b/libavcodec/opt.c
@@ -164,10 +164,10 @@ int av_set_string3(void *obj, const char *name, const char *val, int alloc, cons
                 else if(!strcmp(buf, "none"   )) d= 0;
                 else if(!strcmp(buf, "all"    )) d= ~0;
                 else {
-                    ff_parse_and_eval_expr(&d, const_values, const_names, NULL, NULL, NULL, NULL, NULL, &error);
+                    ret = ff_parse_and_eval_expr(&d, buf, const_names, const_values, NULL, NULL, NULL, NULL, NULL, obj);
                     if (isnan(d)) {
                         av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val);
-                        return AVERROR(EINVAL);
+                        return ret;
                     }
                 }
             }
-- 
1.7.0




More information about the ffmpeg-devel mailing list