提交 265dadbe 编写于 作者: M Michael Niedermayer

avutil/opt: Support general expressions involving AVOption constants in set_string_number()

Signed-off-by: NMichael Niedermayer <michaelni@gmx.at>
上级 88efc013
...@@ -129,18 +129,6 @@ static int write_number(void *obj, const AVOption *o, void *dst, double num, int ...@@ -129,18 +129,6 @@ static int write_number(void *obj, const AVOption *o, void *dst, double num, int
return 0; return 0;
} }
static const double const_values[] = {
M_PI,
M_E,
0
};
static const char * const const_names[] = {
"PI",
"E",
0
};
static int hexchar2int(char c) { static int hexchar2int(char c) {
if (c >= '0' && c <= '9') return c - '0'; if (c >= '0' && c <= '9') return c - '0';
if (c >= 'a' && c <= 'f') return c - 'a' + 10; if (c >= 'a' && c <= 'f') return c - 'a' + 10;
...@@ -220,21 +208,44 @@ static int set_string_number(void *obj, void *target_obj, const AVOption *o, con ...@@ -220,21 +208,44 @@ static int set_string_number(void *obj, void *target_obj, const AVOption *o, con
buf[i] = 0; buf[i] = 0;
{ {
const AVOption *o_named = av_opt_find(target_obj, buf, o->unit, 0, 0); const AVOption *o_named;
if (o_named && o_named->type == AV_OPT_TYPE_CONST) int res;
d = DEFAULT_NUMVAL(o_named); int ci = 0;
else if (!strcmp(buf, "default")) d = DEFAULT_NUMVAL(o); double const_values[64];
else if (!strcmp(buf, "max" )) d = o->max; const char * const_names[64];
else if (!strcmp(buf, "min" )) d = o->min;
else if (!strcmp(buf, "none" )) d = 0; if (o->unit) {
else if (!strcmp(buf, "all" )) d = ~0; for (o_named = NULL; o_named = av_opt_next(target_obj, o_named); ) {
else { if (o_named->type == AV_OPT_TYPE_CONST &&
int res = av_expr_parse_and_eval(&d, buf, const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, obj); o_named->unit &&
if (res < 0) { !strcmp(o_named->unit, o->unit)) {
av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val); if (ci + 6 >= FF_ARRAY_ELEMS(const_values)) {
return res; av_log(obj, AV_LOG_ERROR, "const_values array too small for %s\n", o->unit);
return AVERROR_PATCHWELCOME;
}
const_names [ci ] = o_named->name;
const_values[ci++] = DEFAULT_NUMVAL(o_named);
}
} }
} }
const_names [ci ] = "default";
const_values[ci++] = DEFAULT_NUMVAL(o);
const_names [ci ] = "max";
const_values[ci++] = o->max;
const_names [ci ] = "min";
const_values[ci++] = o->min;
const_names [ci ] = "none";
const_values[ci++] = 0;
const_names [ci ] = "all";
const_values[ci++] = ~0;
const_names [ci] = NULL;
const_values[ci] = 0;
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;
}
} }
if (o->type == AV_OPT_TYPE_FLAGS) { if (o->type == AV_OPT_TYPE_FLAGS) {
read_number(o, dst, NULL, NULL, &intnum); read_number(o, dst, NULL, NULL, &intnum);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册