[FFmpeg-devel] [PATCH 10/21] Change interface to ff_eval2().
Stefano Sabatini
stefano.sabatini-lala
Sun Apr 11 01:01:46 CEST 2010
Make it return an error code and take as argument the pointer where to
put the result and a log context rather than a pointer where to put
the error string.
This is consistent with the new revisited API, and allows to provide
to the caller the error code issued by ff_parse_expr() in case of
failure.
---
libavcodec/eval.c | 24 ++++++++++++++----------
libavcodec/eval.h | 10 ++++++----
libavcodec/opt.c | 5 ++---
3 files changed, 22 insertions(+), 17 deletions(-)
diff --git a/libavcodec/eval.c b/libavcodec/eval.c
index 9ca1b91..a2af48f 100644
--- a/libavcodec/eval.c
+++ b/libavcodec/eval.c
@@ -467,20 +467,19 @@ double ff_eval_expr(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,
+int ff_eval2(double *res, 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,
- void *opaque, const char **error){
+ void *opaque, void *log_ctx){
AVExpr * e;
- double d;
int ret = ff_parse_expr(&e, s, const_name, func1, func1_name, func2, func2_name, NULL);
if (ret < 0) {
- *error = "Error occurred during parsing, check log";
- return NAN;
+ *res = NAN;
+ return ret;
}
- d = ff_eval_expr(e, const_value, opaque);
+ *res = ff_eval_expr(e, const_value, opaque);
ff_free_expr(e);
- return d;
+ return 0;
}
#ifdef TEST
@@ -497,12 +496,17 @@ 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));
+ double d;
+
+ ff_eval2(&d, "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 == 12.7\n", d);
+
+ ff_eval2(&d, "80G/80Gi", const_values, const_names, NULL, NULL, NULL, NULL, NULL, NULL);
+ printf("%f == 0.931322575\n", d);
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);
+ ff_eval2(&d, "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")
}
return 0;
diff --git a/libavcodec/eval.h b/libavcodec/eval.h
index c66d9dc..3c74ccf 100644
--- a/libavcodec/eval.h
+++ b/libavcodec/eval.h
@@ -33,21 +33,23 @@ typedef struct AVExpr AVExpr;
/**
* Parses and evaluates an expression.
* Note, this is significantly slower than ff_eval_expr().
+ * @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 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 const_name NULL terminated array of zero terminated strings of constant identifers for example {"PI", "E", 0}
* @param func1_name NULL terminated array of zero terminated strings of func1 identifers
* @param func2_name NULL terminated array of zero terminated strings of func2 identifers
- * @param error pointer to a char* which is set to an error message if something goes wrong
* @param const_value a zero terminated array of values for the identifers from const_name
* @param opaque a pointer which will be passed to all functions from func1 and func2
- * @return the value of the expression
+ * @return 0 in case of successfull parsing, a negative value
+ * corresponding to an AVERROR code in case of parsing failure
*/
-double ff_eval2(const char *s, const double *const_value, const char * const *const_name,
+int ff_eval2(double *res, 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,
- void *opaque, const char **error);
+ void *opaque, void *log_ctx);
/**
* Parses a expression.
diff --git a/libavcodec/opt.c b/libavcodec/opt.c
index 7a72c44..1d97f40 100644
--- a/libavcodec/opt.c
+++ b/libavcodec/opt.c
@@ -147,7 +147,6 @@ int av_set_string3(void *obj, const char *name, const char *val, int alloc, cons
char buf[256];
int cmd=0;
double d;
- const char *error = NULL;
if(*val == '+' || *val == '-')
cmd= *(val++);
@@ -165,9 +164,9 @@ 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 {
- d = ff_eval2(buf, const_values, const_names, NULL, NULL, NULL, NULL, NULL, &error);
+ ret = ff_eval2(&d, buf, const_values, const_names, NULL, NULL, NULL, NULL, NULL, obj);
if (isnan(d)) {
- av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\": %s\n", val, error);
+ av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val);
return AVERROR(EINVAL);
}
}
--
1.7.0
More information about the ffmpeg-devel
mailing list