1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

Move eval.c and eval.h from libavcodec to libavutil, and make the eval

API public.

Originally committed as revision 23485 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Stefano Sabatini 2010-06-05 12:01:28 +00:00
parent 6532c6f929
commit 0b99215c0e
9 changed files with 53 additions and 52 deletions

View File

@ -11,7 +11,6 @@ OBJS = allcodecs.o \
bitstream.o \
bitstream_filter.o \
dsputil.o \
eval.o \
faanidct.o \
imgconvert.o \
jrevdct.o \

View File

@ -31,7 +31,7 @@
#define LIBAVCODEC_VERSION_MAJOR 52
#define LIBAVCODEC_VERSION_MINOR 74
#define LIBAVCODEC_VERSION_MICRO 0
#define LIBAVCODEC_VERSION_MICRO 1
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \

View File

@ -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;

View File

@ -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;

View File

@ -30,7 +30,7 @@
#include <stdio.h>
#include <stdint.h>
#include "eval.h"
#include "libavutil/eval.h"
typedef struct Predictor{
double coeff;

View File

@ -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 \

View File

@ -40,7 +40,7 @@
#define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
#define LIBAVUTIL_VERSION_MAJOR 50
#define LIBAVUTIL_VERSION_MINOR 17
#define LIBAVUTIL_VERSION_MINOR 18
#define LIBAVUTIL_VERSION_MICRO 0
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

View File

@ -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;
}

View File

@ -23,14 +23,14 @@
* simple arithmetic expression evaluator
*/
#ifndef AVCODEC_EVAL_H
#define AVCODEC_EVAL_H
#ifndef AVUTIL_EVAL_H
#define AVUTIL_EVAL_H
typedef struct AVExpr AVExpr;
/**
* Parses and evaluates an expression.
* Note, this is significantly slower than ff_eval_expr().
* Note, this is significantly slower than av_eval_expr().
*
* @param res a pointer to a double where is put the result value of
* the expression, or NAN in case of error
@ -46,7 +46,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),
@ -57,7 +57,7 @@ int ff_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 ff_free_expr() by the user
* The pointed to AVExpr must be freed with av_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 const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}
@ -69,7 +69,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),
@ -78,16 +78,16 @@ int ff_parse_expr(AVExpr **expr, const char *s,
/**
* Evaluates a previously parsed expression.
*
* @param const_values a zero terminated array of values for the identifiers from ff_parse() const_names
* @param const_values a zero terminated array of values for the identifiers from av_parse_expr() const_names
* @param opaque a pointer which will be passed to all functions from 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().
* Frees a parsed expression previously created with av_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
@ -108,4 +108,4 @@ void ff_free_expr(AVExpr *e);
*/
double av_strtod(const char *numstr, char **tail);
#endif /* AVCODEC_EVAL_H */
#endif /* AVUTIL_EVAL_H */