[PATCH 2/2] Move eval.c and eval.h from libavcodec to libavutil, and make the eval API public.

Stefano Sabatini stefano.sabatini-lala
Thu Jun 3 00:16:23 CEST 2010


---
 libavcodec/Makefile              |    1 -
 libavcodec/opt.c                 |    4 +-
 libavcodec/ratecontrol.c         |    8 ++--
 libavcodec/ratecontrol.h         |    2 +-
 libavutil/Makefile               |    2 +
 {libavcodec => libavutil}/eval.c |   62 +++++++++++++++++++-------------------
 {libavcodec => libavutil}/eval.h |   14 ++++----
 7 files changed, 47 insertions(+), 46 deletions(-)
 rename {libavcodec => libavutil}/eval.c (92%)
 rename {libavcodec => libavutil}/eval.h (95%)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 764555e..a5f443c 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -11,7 +11,6 @@ OBJS = allcodecs.o                                                      \
        bitstream.o                                                      \
        bitstream_filter.o                                               \
        dsputil.o                                                        \
-       eval.o                                                           \
        faanidct.o                                                       \
        imgconvert.o                                                     \
        jrevdct.o                                                        \
diff --git a/libavcodec/opt.c b/libavcodec/opt.c
index 8473d90..128d95d 100644
--- a/libavcodec/opt.c
+++ b/libavcodec/opt.c
@@ -27,7 +27,7 @@
 
 #include "avcodec.h"
 #include "opt.h"
-#include "eval.h"
+#include "libavutil/eval.h"
 
 //FIXME order them and do a bin search
 const AVOption *av_find_opt(void *v, const char *name, const char *unit, int mask, int flags){
@@ -165,7 +165,7 @@ 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 {
-                    int res = ff_parse_and_eval_expr(&d, buf, const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);
+                    int res = av_parse_and_eval_expr(&d, buf, const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);
                     if (res < 0) {
                         av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val);
                         return res;
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index 375815a..4261678 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -30,7 +30,7 @@
 #include "dsputil.h"
 #include "ratecontrol.h"
 #include "mpegvideo.h"
-#include "eval.h"
+#include "libavutil/eval.h"
 
 #undef NDEBUG // Always check asserts, the speed effect is far too small to disable them.
 #include <assert.h>
@@ -106,7 +106,7 @@ int ff_rate_control_init(MpegEncContext *s)
     };
     emms_c();
 
-    res = ff_parse_expr(&rcc->rc_eq_eval, s->avctx->rc_eq ? s->avctx->rc_eq : "tex^qComp", const_names, func1_names, func1, NULL, NULL, 0, s->avctx);
+    res = av_parse_expr(&rcc->rc_eq_eval, s->avctx->rc_eq ? s->avctx->rc_eq : "tex^qComp", const_names, func1_names, func1, NULL, NULL, 0, s->avctx);
     if (res < 0) {
         av_log(s->avctx, AV_LOG_ERROR, "Error parsing rc_eq \"%s\"\n", s->avctx->rc_eq);
         return res;
@@ -254,7 +254,7 @@ void ff_rate_control_uninit(MpegEncContext *s)
     RateControlContext *rcc= &s->rc_context;
     emms_c();
 
-    ff_free_expr(rcc->rc_eq_eval);
+    av_free_expr(rcc->rc_eq_eval);
     av_freep(&rcc->entry);
 
 #if CONFIG_LIBXVID
@@ -338,7 +338,7 @@ static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_f
         0
     };
 
-    bits= ff_eval_expr(rcc->rc_eq_eval, const_values, rce);
+    bits = av_eval_expr(rcc->rc_eq_eval, const_values, rce);
     if (isnan(bits)) {
         av_log(s->avctx, AV_LOG_ERROR, "Error evaluating rc_eq \"%s\"\n", s->avctx->rc_eq);
         return -1;
diff --git a/libavcodec/ratecontrol.h b/libavcodec/ratecontrol.h
index d5fe2bc..32efe01 100644
--- a/libavcodec/ratecontrol.h
+++ b/libavcodec/ratecontrol.h
@@ -30,7 +30,7 @@
 
 #include <stdio.h>
 #include <stdint.h>
-#include "eval.h"
+#include "libavutil/eval.h"
 
 typedef struct Predictor{
     double coeff;
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 6035ba6..f6961ac 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -10,6 +10,7 @@ HEADERS = adler32.h                                                     \
           common.h                                                      \
           crc.h                                                         \
           error.h                                                       \
+          eval.h                                                        \
           fifo.h                                                        \
           intfloat_readwrite.h                                          \
           log.h                                                         \
@@ -32,6 +33,7 @@ OBJS = adler32.o                                                        \
        crc.o                                                            \
        des.o                                                            \
        error.o                                                          \
+       eval.o                                                           \
        fifo.o                                                           \
        intfloat_readwrite.o                                             \
        lfg.o                                                            \
diff --git a/libavcodec/eval.c b/libavutil/eval.c
similarity index 92%
rename from libavcodec/eval.c
rename to libavutil/eval.c
index 2a8fc44..59ebd94 100644
--- a/libavcodec/eval.c
+++ b/libavutil/eval.c
@@ -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;
 }
diff --git a/libavcodec/eval.h b/libavutil/eval.h
similarity index 95%
rename from libavcodec/eval.h
rename to libavutil/eval.h
index 2cfa129..f840fbc 100644
--- a/libavcodec/eval.h
+++ b/libavutil/eval.h
@@ -23,8 +23,8 @@
  * simple arithmetic expression evaluator
  */
 
-#ifndef AVCODEC_EVAL_H
-#define AVCODEC_EVAL_H
+#ifndef AVUTIL_EVAL_H
+#define AVUTIL_EVAL_H
 
 typedef struct AVExpr AVExpr;
 
@@ -54,7 +54,7 @@ typedef struct AVExpr AVExpr;
  * @return 0 in case of success, a negative value corresponding to an
  *     AVERROR code otherwise
  */
-int ff_parse_and_eval_expr(double *res, const char *s,
+int av_parse_and_eval_expr(double *res, 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),
@@ -83,7 +83,7 @@ int ff_parse_and_eval_expr(double *res, const char *s,
  * @return 0 in case of success, a negative value corresponding to an
  *     AVERROR code otherwise
  */
-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),
@@ -98,12 +98,12 @@ int ff_parse_expr(AVExpr **expr, const char *s,
  *     funcs1 and funcs2
  * @return the value of the expression
  */
-double ff_eval_expr(AVExpr *e, const double *const_values, void *opaque);
+double av_eval_expr(AVExpr *e, const double *const_values, void *opaque);
 
 /**
  * Frees a parsed expression previously created with ff_parse_expr().
  */
-void ff_free_expr(AVExpr *e);
+void av_free_expr(AVExpr *e);
 
 /**
  * Parses the string in numstr and returns its value as a double. If
@@ -125,4 +125,4 @@ void ff_free_expr(AVExpr *e);
  */
 double av_strtod(const char *numstr, char **tail);
 
-#endif /* AVCODEC_EVAL_H */
+#endif /* AVUTIL_EVAL_H */
-- 
1.7.1


--ctP54qlpMx3WjD+/--



More information about the ffmpeg-devel mailing list