AVEvalExpr * ff_parse(const char *s, const char **const_name, double (**func1)(void *, double), const char **func1_name, double (**func2)(void *, double, double), char **func2_name, const char **error){ Parser p; AVEvalExpr * e; // char w[strlen(s) + 1], * wp = w; char *w = (char *)malloc((strlen(s) + 1) * sizeof(char)); char *wp; wp = w; while (*s) if (!isspace(*s++)) *wp++ = s[-1]; *wp++ = 0; p.stack_index=100; p.s= w; p.const_name = const_name; p.func1 = func1; p.func1_name = func1_name; p.func2 = func2; p.func2_name = func2_name; p.error= error; e = parse_expr(&p); if (!verify_expr(e)) { ff_eval_free(e); return NULL; } return e; }
double ff_eval2(const char *s, double *const_value, const char **const_name, double (**func1)(void *, double), const char **func1_name, double (**func2)(void *, double, double), char **func2_name, void *opaque, const char **error){ AVEvalExpr * e = ff_parse(s, const_name, func1, func1_name, func2, func2_name, error); double d; if (!e) return 0;//NAN; d = ff_parse_eval(e, const_value, opaque); ff_eval_free(e); return d; }
void ff_rate_control_uninit(MpegEncContext *s) { RateControlContext *rcc= &s->rc_context; emms_c(); ff_eval_free(rcc->rc_eq_eval); av_freep(&rcc->entry); #if CONFIG_LIBXVID if((s->flags&CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID) ff_xvid_rate_control_uninit(s); #endif }
static AVEvalExpr * parse_primary(Parser *p) { AVEvalExpr * d = av_mallocz(sizeof(AVEvalExpr)); char *next= p->s; int i; /* number */ d->value = av_strtod(p->s, &next); if(next != p->s){ d->type = e_value; p->s= next; return d; } d->value = 1; /* named constants */ for(i=0; p->const_name && p->const_name[i]; i++){ if(strmatch(p->s, p->const_name[i])){ p->s+= strlen(p->const_name[i]); d->type = e_const; d->a.const_index = i; return d; } } p->s= strchr(p->s, '('); if(p->s==NULL){ *p->error = "undefined constant or missing ("; p->s= next; ff_eval_free(d); return NULL; } p->s++; // "(" if (*next == '(') { // special case do-nothing av_freep(&d); d = parse_expr(p); if(p->s[0] != ')'){ *p->error = "missing )"; ff_eval_free(d); return NULL; } p->s++; // ")" return d; } d->param[0] = parse_expr(p); if(p->s[0]== ','){ p->s++; // "," d->param[1] = parse_expr(p); } if(p->s[0] != ')'){ *p->error = "missing )"; ff_eval_free(d); return NULL; } p->s++; // ")" d->type = e_func0; if( strmatch(next, "sinh" ) ) d->a.func0 = sinh; else if( strmatch(next, "cosh" ) ) d->a.func0 = cosh; else if( strmatch(next, "tanh" ) ) d->a.func0 = tanh; else if( strmatch(next, "sin" ) ) d->a.func0 = sin; else if( strmatch(next, "cos" ) ) d->a.func0 = cos; else if( strmatch(next, "tan" ) ) d->a.func0 = tan; else if( strmatch(next, "atan" ) ) d->a.func0 = atan; else if( strmatch(next, "asin" ) ) d->a.func0 = asin; else if( strmatch(next, "acos" ) ) d->a.func0 = acos; else if( strmatch(next, "exp" ) ) d->a.func0 = exp; else if( strmatch(next, "log" ) ) d->a.func0 = log; else if( strmatch(next, "abs" ) ) d->a.func0 = fabs; else if( strmatch(next, "squish") ) d->type = e_squish; else if( strmatch(next, "gauss" ) ) d->type = e_gauss; else if( strmatch(next, "mod" ) ) d->type = e_mod; else if( strmatch(next, "max" ) ) d->type = e_max; else if( strmatch(next, "min" ) ) d->type = e_min; else if( strmatch(next, "eq" ) ) d->type = e_eq; else if( strmatch(next, "gte" ) ) d->type = e_gte; 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, "lt" ) ) { AVEvalExpr * 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, "st" ) ) d->type = e_st; else if( strmatch(next, "while" ) ) d->type = e_while; else { for(i=0; p->func1_name && p->func1_name[i]; i++){ if(strmatch(next, p->func1_name[i])){ d->a.func1 = p->func1[i]; d->type = e_func1; return d; } } for(i=0; p->func2_name && p->func2_name[i]; i++){ if(strmatch(next, p->func2_name[i])){ d->a.func2 = p->func2[i]; d->type = e_func2; return d; } } *p->error = "unknown function"; ff_eval_free(d); return NULL; } return d; }
void ff_eval_free(AVEvalExpr * e) { if (!e) return; ff_eval_free(e->param[0]); ff_eval_free(e->param[1]); av_freep(&e); }