Rename AVEvalExpr to AVExpr, as suggested by Michael.

The new name is shorter and less confusing.

Originally committed as revision 22833 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Stefano Sabatini 2010-04-11 11:47:29 +00:00
parent 5fccafdbc1
commit 073f6d5b96
3 changed files with 30 additions and 30 deletions

View File

@ -130,10 +130,10 @@ struct ff_expr_s {
double (*func1)(void *, double); double (*func1)(void *, double);
double (*func2)(void *, double, double); double (*func2)(void *, double, double);
} a; } a;
AVEvalExpr * param[2]; AVExpr *param[2];
}; };
static double eval_expr(Parser * p, AVEvalExpr * e) { static double eval_expr(Parser * p, AVExpr * e) {
switch (e->type) { switch (e->type) {
case e_value: return e->value; case e_value: return e->value;
case e_const: return e->value * p->const_value[e->a.const_index]; case e_const: return e->value * p->const_value[e->a.const_index];
@ -171,17 +171,17 @@ static double eval_expr(Parser * p, AVEvalExpr * e) {
return NAN; return NAN;
} }
static AVEvalExpr * parse_expr(Parser *p); static AVExpr * parse_expr(Parser *p);
void ff_eval_free(AVEvalExpr * e) { void ff_eval_free(AVExpr * e) {
if (!e) return; if (!e) return;
ff_eval_free(e->param[0]); ff_eval_free(e->param[0]);
ff_eval_free(e->param[1]); ff_eval_free(e->param[1]);
av_freep(&e); av_freep(&e);
} }
static AVEvalExpr * parse_primary(Parser *p) { static AVExpr * parse_primary(Parser *p) {
AVEvalExpr * d = av_mallocz(sizeof(AVEvalExpr)); AVExpr * d = av_mallocz(sizeof(AVExpr));
char *next= p->s; char *next= p->s;
int i; int i;
@ -259,8 +259,8 @@ static AVEvalExpr * parse_primary(Parser *p) {
else if( strmatch(next, "eq" ) ) d->type = e_eq; else if( strmatch(next, "eq" ) ) d->type = e_eq;
else if( strmatch(next, "gte" ) ) d->type = e_gte; else if( strmatch(next, "gte" ) ) d->type = e_gte;
else if( strmatch(next, "gt" ) ) d->type = e_gt; else if( strmatch(next, "gt" ) ) d->type = e_gt;
else if( strmatch(next, "lte" ) ) { AVEvalExpr * tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gt; } else if( strmatch(next, "lte" ) ) { AVExpr * tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gt; }
else if( strmatch(next, "lt" ) ) { AVEvalExpr * tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gte; } else if( strmatch(next, "lt" ) ) { AVExpr * tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gte; }
else if( strmatch(next, "ld" ) ) d->type = e_ld; else if( strmatch(next, "ld" ) ) d->type = e_ld;
else if( strmatch(next, "st" ) ) d->type = e_st; else if( strmatch(next, "st" ) ) d->type = e_st;
else if( strmatch(next, "while" ) ) d->type = e_while; else if( strmatch(next, "while" ) ) d->type = e_while;
@ -289,8 +289,8 @@ static AVEvalExpr * parse_primary(Parser *p) {
return d; return d;
} }
static AVEvalExpr * new_eval_expr(int type, int value, AVEvalExpr *p0, AVEvalExpr *p1){ static AVExpr * new_eval_expr(int type, int value, AVExpr *p0, AVExpr *p1){
AVEvalExpr * e = av_mallocz(sizeof(AVEvalExpr)); AVExpr * e = av_mallocz(sizeof(AVExpr));
if (!e) if (!e)
return NULL; return NULL;
e->type =type ; e->type =type ;
@ -300,15 +300,15 @@ static AVEvalExpr * new_eval_expr(int type, int value, AVEvalExpr *p0, AVEvalExp
return e; return e;
} }
static AVEvalExpr * parse_pow(Parser *p, int *sign){ static AVExpr * parse_pow(Parser *p, int *sign){
*sign= (*p->s == '+') - (*p->s == '-'); *sign= (*p->s == '+') - (*p->s == '-');
p->s += *sign&1; p->s += *sign&1;
return parse_primary(p); return parse_primary(p);
} }
static AVEvalExpr * parse_factor(Parser *p){ static AVExpr * parse_factor(Parser *p){
int sign, sign2; int sign, sign2;
AVEvalExpr * e = parse_pow(p, &sign); AVExpr * e = parse_pow(p, &sign);
while(p->s[0]=='^'){ while(p->s[0]=='^'){
p->s++; p->s++;
e= new_eval_expr(e_pow, 1, e, parse_pow(p, &sign2)); e= new_eval_expr(e_pow, 1, e, parse_pow(p, &sign2));
@ -320,8 +320,8 @@ static AVEvalExpr * parse_factor(Parser *p){
return e; return e;
} }
static AVEvalExpr * parse_term(Parser *p){ static AVExpr * parse_term(Parser *p){
AVEvalExpr * e = parse_factor(p); AVExpr * e = parse_factor(p);
while(p->s[0]=='*' || p->s[0]=='/'){ while(p->s[0]=='*' || p->s[0]=='/'){
int c= *p->s++; int c= *p->s++;
e= new_eval_expr(c == '*' ? e_mul : e_div, 1, e, parse_factor(p)); e= new_eval_expr(c == '*' ? e_mul : e_div, 1, e, parse_factor(p));
@ -331,8 +331,8 @@ static AVEvalExpr * parse_term(Parser *p){
return e; return e;
} }
static AVEvalExpr * parse_subexpr(Parser *p) { static AVExpr * parse_subexpr(Parser *p) {
AVEvalExpr * e = parse_term(p); AVExpr * e = parse_term(p);
while(*p->s == '+' || *p->s == '-') { while(*p->s == '+' || *p->s == '-') {
e= new_eval_expr(e_add, 1, e, parse_term(p)); e= new_eval_expr(e_add, 1, e, parse_term(p));
if (!e) if (!e)
@ -342,8 +342,8 @@ static AVEvalExpr * parse_subexpr(Parser *p) {
return e; return e;
} }
static AVEvalExpr * parse_expr(Parser *p) { static AVExpr * parse_expr(Parser *p) {
AVEvalExpr * e; AVExpr * e;
if(p->stack_index <= 0) //protect against stack overflows if(p->stack_index <= 0) //protect against stack overflows
return NULL; return NULL;
@ -363,7 +363,7 @@ static AVEvalExpr * parse_expr(Parser *p) {
return e; return e;
} }
static int verify_expr(AVEvalExpr * e) { static int verify_expr(AVExpr * e) {
if (!e) return 0; if (!e) return 0;
switch (e->type) { switch (e->type) {
case e_value: case e_value:
@ -377,12 +377,12 @@ static int verify_expr(AVEvalExpr * e) {
} }
} }
AVEvalExpr * ff_parse(const char *s, const char * const *const_name, AVExpr * ff_parse(const char *s, const char * const *const_name,
double (**func1)(void *, double), const char **func1_name, double (**func1)(void *, double), const char **func1_name,
double (**func2)(void *, double, double), const char **func2_name, double (**func2)(void *, double, double), const char **func2_name,
const char **error){ const char **error){
Parser p; Parser p;
AVEvalExpr *e = NULL; AVExpr *e = NULL;
char *w = av_malloc(strlen(s) + 1); char *w = av_malloc(strlen(s) + 1);
char *wp = w; char *wp = w;
@ -412,7 +412,7 @@ end:
return e; return e;
} }
double ff_parse_eval(AVEvalExpr * e, const double *const_value, void *opaque) { double ff_parse_eval(AVExpr * e, const double *const_value, void *opaque) {
Parser p; Parser p;
p.const_value= const_value; p.const_value= const_value;
@ -424,7 +424,7 @@ double ff_eval2(const char *s, const double *const_value, const char * const *co
double (**func1)(void *, double), const char **func1_name, double (**func1)(void *, double), const char **func1_name,
double (**func2)(void *, double, double), const char **func2_name, double (**func2)(void *, double, double), const char **func2_name,
void *opaque, const char **error){ void *opaque, const char **error){
AVEvalExpr * e = ff_parse(s, const_name, func1, func1_name, func2, func2_name, error); AVExpr * e = ff_parse(s, const_name, func1, func1_name, func2, func2_name, error);
double d; double d;
if (!e) return NAN; if (!e) return NAN;
d = ff_parse_eval(e, const_value, opaque); d = ff_parse_eval(e, const_value, opaque);

View File

@ -28,7 +28,7 @@
#ifndef AVCODEC_EVAL_H #ifndef AVCODEC_EVAL_H
#define AVCODEC_EVAL_H #define AVCODEC_EVAL_H
typedef struct ff_expr_s AVEvalExpr; typedef struct ff_expr_s AVExpr;
/** /**
* Parses and evaluates an expression. * Parses and evaluates an expression.
@ -58,10 +58,10 @@ double ff_eval2(const char *s, const double *const_value, const char * const *co
* @param func1_name NULL terminated array of zero terminated strings of func1 identifers * @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 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 error pointer to a char* which is set to an error message if something goes wrong
* @return AVEvalExpr which must be freed with ff_eval_free by the user when it is not needed anymore * @return AVExpr which must be freed with ff_eval_free by the user when it is not needed anymore
* NULL if anything went wrong * NULL if anything went wrong
*/ */
AVEvalExpr * ff_parse(const char *s, const char * const *const_name, AVExpr * ff_parse(const char *s, const char * const *const_name,
double (**func1)(void *, double), const char **func1_name, double (**func1)(void *, double), const char **func1_name,
double (**func2)(void *, double, double), const char **func2_name, double (**func2)(void *, double, double), const char **func2_name,
const char **error); const char **error);
@ -71,8 +71,8 @@ AVEvalExpr * ff_parse(const char *s, const char * const *const_name,
* @param opaque a pointer which will be passed to all functions from func1 and func2 * @param opaque a pointer which will be passed to all functions from func1 and func2
* @return the value of the expression * @return the value of the expression
*/ */
double ff_parse_eval(AVEvalExpr * e, const double *const_value, void *opaque); double ff_parse_eval(AVExpr * e, const double *const_value, void *opaque);
void ff_eval_free(AVEvalExpr * e); void ff_eval_free(AVExpr * e);
/** /**
* Parses the string in numstr and returns its value as a double. If * Parses the string in numstr and returns its value as a double. If

View File

@ -84,7 +84,7 @@ typedef struct RateControlContext{
void *non_lavc_opaque; ///< context for non lavc rc code (for example xvid) void *non_lavc_opaque; ///< context for non lavc rc code (for example xvid)
float dry_run_qscale; ///< for xvid rc float dry_run_qscale; ///< for xvid rc
int last_picture_number; ///< for xvid rc int last_picture_number; ///< for xvid rc
AVEvalExpr * rc_eq_eval; AVExpr * rc_eq_eval;
}RateControlContext; }RateControlContext;
struct MpegEncContext; struct MpegEncContext;