summaryrefslogtreecommitdiff
path: root/libavutil
diff options
context:
space:
mode:
authorStefano Sabatini <stefano.sabatini-lala@poste.it>2010-11-08 14:06:49 +0000
committerStefano Sabatini <stefano.sabatini-lala@poste.it>2010-11-08 14:06:49 +0000
commitd2af7205a12afde34c916ef96ba8c7a26aa0813e (patch)
treef66721788b2a9ad55d83c74cc075761bf9a5eaea /libavutil
parent24de0edbd589b7cb0da51260073a1a28bb6a2619 (diff)
Use hierarchic names convention (prefix them with av_expr) for the
eval API. More grep-friendly and more consistent with the rest of the FFmpeg API. Originally committed as revision 25708 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/avutil.h12
-rw-r--r--libavutil/eval.c96
-rw-r--r--libavutil/eval.h47
-rw-r--r--libavutil/opt.c2
4 files changed, 116 insertions, 41 deletions
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 5857a0a8f5..d0234a0872 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -40,8 +40,8 @@
#define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
#define LIBAVUTIL_VERSION_MAJOR 50
-#define LIBAVUTIL_VERSION_MINOR 32
-#define LIBAVUTIL_VERSION_MICRO 6
+#define LIBAVUTIL_VERSION_MINOR 33
+#define LIBAVUTIL_VERSION_MICRO 0
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
LIBAVUTIL_VERSION_MINOR, \
@@ -54,6 +54,14 @@
#define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION)
/**
+ * Those FF_API_* defines are not part of public API.
+ * They may change, break or disappear at any time.
+ */
+#ifndef FF_API_OLD_EVAL_NAMES
+#define FF_API_OLD_EVAL_NAMES (LIBAVUTIL_VERSION_MAJOR < 51)
+#endif
+
+/**
* Return the LIBAVUTIL_VERSION_INT constant.
*/
unsigned avutil_version(void);
diff --git a/libavutil/eval.c b/libavutil/eval.c
index fdddd7720d..0fef97bd85 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -175,11 +175,11 @@ static double eval_expr(Parser *p, AVExpr *e)
static int parse_expr(AVExpr **e, Parser *p);
-void av_free_expr(AVExpr *e)
+void av_expr_free(AVExpr *e)
{
if (!e) return;
- av_free_expr(e->param[0]);
- av_free_expr(e->param[1]);
+ av_expr_free(e->param[0]);
+ av_expr_free(e->param[1]);
av_freep(&e);
}
@@ -217,7 +217,7 @@ static int parse_primary(AVExpr **e, Parser *p)
if (p->s==NULL) {
av_log(p, AV_LOG_ERROR, "Undefined constant or missing '(' in '%s'\n", s0);
p->s= next;
- av_free_expr(d);
+ av_expr_free(d);
return AVERROR(EINVAL);
}
p->s++; // "("
@@ -227,7 +227,7 @@ static int parse_primary(AVExpr **e, Parser *p)
return ret;
if (p->s[0] != ')') {
av_log(p, AV_LOG_ERROR, "Missing ')' in '%s'\n", s0);
- av_free_expr(d);
+ av_expr_free(d);
return AVERROR(EINVAL);
}
p->s++; // ")"
@@ -235,7 +235,7 @@ static int parse_primary(AVExpr **e, Parser *p)
return 0;
}
if ((ret = parse_expr(&(d->param[0]), p)) < 0) {
- av_free_expr(d);
+ av_expr_free(d);
return ret;
}
if (p->s[0]== ',') {
@@ -244,7 +244,7 @@ static int parse_primary(AVExpr **e, Parser *p)
}
if (p->s[0] != ')') {
av_log(p, AV_LOG_ERROR, "Missing ')' or too many args in '%s'\n", s0);
- av_free_expr(d);
+ av_expr_free(d);
return AVERROR(EINVAL);
}
p->s++; // ")"
@@ -296,7 +296,7 @@ static int parse_primary(AVExpr **e, Parser *p)
}
av_log(p, AV_LOG_ERROR, "Unknown function in '%s'\n", s0);
- av_free_expr(d);
+ av_expr_free(d);
return AVERROR(EINVAL);
}
@@ -333,13 +333,13 @@ static int parse_factor(AVExpr **e, Parser *p)
e1 = e0;
p->s++;
if ((ret = parse_pow(&e2, p, &sign2)) < 0) {
- av_free_expr(e1);
+ av_expr_free(e1);
return ret;
}
e0 = new_eval_expr(e_pow, 1, e1, e2);
if (!e0) {
- av_free_expr(e1);
- av_free_expr(e2);
+ av_expr_free(e1);
+ av_expr_free(e2);
return AVERROR(ENOMEM);
}
if (e0->param[1]) e0->param[1]->value *= (sign2|1);
@@ -360,13 +360,13 @@ static int parse_term(AVExpr **e, Parser *p)
int c= *p->s++;
e1 = e0;
if ((ret = parse_factor(&e2, p)) < 0) {
- av_free_expr(e1);
+ av_expr_free(e1);
return ret;
}
e0 = new_eval_expr(c == '*' ? e_mul : e_div, 1, e1, e2);
if (!e0) {
- av_free_expr(e1);
- av_free_expr(e2);
+ av_expr_free(e1);
+ av_expr_free(e2);
return AVERROR(ENOMEM);
}
}
@@ -383,13 +383,13 @@ static int parse_subexpr(AVExpr **e, Parser *p)
while (*p->s == '+' || *p->s == '-') {
e1 = e0;
if ((ret = parse_term(&e2, p)) < 0) {
- av_free_expr(e1);
+ av_expr_free(e1);
return ret;
}
e0 = new_eval_expr(e_add, 1, e1, e2);
if (!e0) {
- av_free_expr(e1);
- av_free_expr(e2);
+ av_expr_free(e1);
+ av_expr_free(e2);
return AVERROR(ENOMEM);
}
};
@@ -412,13 +412,13 @@ static int parse_expr(AVExpr **e, Parser *p)
p->s++;
e1 = e0;
if ((ret = parse_subexpr(&e2, p)) < 0) {
- av_free_expr(e1);
+ av_expr_free(e1);
return ret;
}
e0 = new_eval_expr(e_last, 1, e1, e2);
if (!e0) {
- av_free_expr(e1);
- av_free_expr(e2);
+ av_expr_free(e1);
+ av_expr_free(e2);
return AVERROR(ENOMEM);
}
};
@@ -444,7 +444,7 @@ static int verify_expr(AVExpr *e)
}
}
-int av_parse_expr(AVExpr **expr, const char *s,
+int av_expr_parse(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),
@@ -483,7 +483,7 @@ int av_parse_expr(AVExpr **expr, const char *s,
goto end;
}
if (!verify_expr(e)) {
- av_free_expr(e);
+ av_expr_free(e);
ret = AVERROR(EINVAL);
goto end;
}
@@ -493,7 +493,7 @@ end:
return ret;
}
-double av_eval_expr(AVExpr *e, const double *const_values, void *opaque)
+double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
{
Parser p;
@@ -502,24 +502,56 @@ double av_eval_expr(AVExpr *e, const double *const_values, void *opaque)
return eval_expr(&p, e);
}
-int av_parse_and_eval_expr(double *d, const char *s,
+int av_expr_parse_and_eval(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 = av_parse_expr(&e, s, const_names, func1_names, funcs1, func2_names, funcs2, log_offset, log_ctx);
+ int ret = av_expr_parse(&e, s, const_names, func1_names, funcs1, func2_names, funcs2, log_offset, log_ctx);
if (ret < 0) {
*d = NAN;
return ret;
}
- *d = av_eval_expr(e, const_values, opaque);
- av_free_expr(e);
+ *d = av_expr_eval(e, const_values, opaque);
+ av_expr_free(e);
return isnan(*d) ? AVERROR(EINVAL) : 0;
}
+#if FF_API_OLD_EVAL_NAMES
+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),
+ int log_offset, void *log_ctx)
+{
+ return av_expr_parse(expr, s, const_names, func1_names, funcs1, func2_names, funcs2,
+ log_offset, log_ctx);
+}
+
+double av_eval_expr(AVExpr *e, const double *const_values, void *opaque)
+{
+ return av_expr_eval(e, const_values, opaque);
+}
+
+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),
+ void *opaque, int log_offset, void *log_ctx)
+{
+ return av_expr_parse_and_eval(res, s, const_names, const_values, func1_names, funcs1, func2_names, funcs2,
+ opaque, log_offset, log_ctx);
+}
+
+void av_free_expr(AVExpr *e)
+{
+ av_expr_free(e);
+}
+#endif /* FF_API_OLD_EVAL_NAMES */
+
#ifdef TEST
#undef printf
static double const_values[] = {
@@ -584,27 +616,27 @@ int main(void)
for (expr = exprs; *expr; expr++) {
printf("Evaluating '%s'\n", *expr);
- av_parse_and_eval_expr(&d, *expr,
+ av_expr_parse_and_eval(&d, *expr,
const_names, const_values,
NULL, NULL, NULL, NULL, NULL, 0, NULL);
printf("'%s' -> %f\n\n", *expr, d);
}
- av_parse_and_eval_expr(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
+ av_expr_parse_and_eval(&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);
- av_parse_and_eval_expr(&d, "80G/80Gi",
+ av_expr_parse_and_eval(&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
- av_parse_and_eval_expr(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
+ av_expr_parse_and_eval(&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("av_parse_and_eval_expr")
+ STOP_TIMER("av_expr_parse_and_eval")
}
return 0;
}
diff --git a/libavutil/eval.h b/libavutil/eval.h
index 7a4f5f0c27..ee378a29b4 100644
--- a/libavutil/eval.h
+++ b/libavutil/eval.h
@@ -26,11 +26,13 @@
#ifndef AVUTIL_EVAL_H
#define AVUTIL_EVAL_H
+#include "avutil.h"
+
typedef struct AVExpr AVExpr;
/**
* Parse and evaluate an expression.
- * Note, this is significantly slower than av_eval_expr().
+ * Note, this is significantly slower than av_expr_eval().
*
* @param res a pointer to a double where is put the result value of
* the expression, or NAN in case of error
@@ -46,7 +48,7 @@ typedef struct AVExpr AVExpr;
* @return 0 in case of success, a negative value corresponding to an
* AVERROR code otherwise
*/
-int av_parse_and_eval_expr(double *res, const char *s,
+int av_expr_parse_and_eval(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),
@@ -57,7 +59,7 @@ int av_parse_and_eval_expr(double *res, const char *s,
*
* @param expr a pointer where is put an AVExpr containing the parsed
* value in case of successfull parsing, or NULL otherwise.
- * The pointed to AVExpr must be freed with av_free_expr() by the user
+ * The pointed to AVExpr must be freed with av_expr_free() 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 const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}
@@ -69,7 +71,7 @@ int av_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 av_parse_expr(AVExpr **expr, const char *s,
+int av_expr_parse(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),
@@ -78,16 +80,49 @@ int av_parse_expr(AVExpr **expr, const char *s,
/**
* Evaluate a previously parsed expression.
*
- * @param const_values a zero terminated array of values for the identifiers from av_parse_expr() const_names
+ * @param const_values a zero terminated array of values for the identifiers from av_expr_parse() const_names
* @param opaque a pointer which will be passed to all functions from funcs1 and funcs2
* @return the value of the expression
*/
+double av_expr_eval(AVExpr *e, const double *const_values, void *opaque);
+
+/**
+ * Free a parsed expression previously created with av_expr_parse().
+ */
+void av_expr_free(AVExpr *e);
+
+#if FF_API_OLD_EVAL_NAMES
+/**
+ * @deprecated Deprecated in favor of av_expr_parse_and_eval().
+ */
+attribute_deprecated
+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),
+ void *opaque, int log_offset, void *log_ctx);
+
+/**
+ * @deprecated Deprecated in favor of av_expr_parse().
+ */
+attribute_deprecated
+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),
+ int log_offset, void *log_ctx);
+/**
+ * @deprecated Deprecated in favor of av_expr_eval().
+ */
+attribute_deprecated
double av_eval_expr(AVExpr *e, const double *const_values, void *opaque);
/**
- * Free a parsed expression previously created with av_parse_expr().
+ * @deprecated Deprecated in favor of av_expr_free().
*/
+attribute_deprecated
void av_free_expr(AVExpr *e);
+#endif /* FF_API_OLD_EVAL_NAMES */
/**
* Parse the string in numstr and return its value as a double. If
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 29e9fd352c..ab6021c71a 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -171,7 +171,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 = av_parse_and_eval_expr(&d, buf, const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);
+ int res = av_expr_parse_and_eval(&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;