History

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

Michael Niedermayer committed 12 years ago

Commit 265dadb1 parent 88efc011 file · +36 −25Browse files

Unified · Split

libavutil/opt.c+36−25
@@ -129,18 +129,6 @@ static int write_number(void *obj, const AVOption *o, void *dst, double num, int · 128 unmodified lines
129 return 0;129 return 0;
130}130}
131 131
132static const double const_values[] = {
133 M_PI,
134 M_E,
135 0
136};
137
138static const char * const const_names[] = {
139 "PI",
140 "E",
141 0
142};
143
144static int hexchar2int(char c) {132static int hexchar2int(char c) {
145 if (c >= '0' && c <= '9') return c - '0';133 if (c >= '0' && c <= '9') return c - '0';
146 if (c >= 'a' && c <= 'f') return c - 'a' + 10;134 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 · 73 unmodified lines
220 buf[i] = 0;208 buf[i] = 0;
221 209
222 {210 {
223 const AVOption *o_named = av_opt_find(target_obj, buf, o->unit, 0, 0);211 const AVOption *o_named;
224 if (o_named && o_named->type == AV_OPT_TYPE_CONST)212 int res;
225 d = DEFAULT_NUMVAL(o_named);213 int ci = 0;
226 else if (!strcmp(buf, "default")) d = DEFAULT_NUMVAL(o);214 double const_values[64];
227 else if (!strcmp(buf, "max" )) d = o->max;215 const char * const_names[64];
228 else if (!strcmp(buf, "min" )) d = o->min;216
229 else if (!strcmp(buf, "none" )) d = 0;217 if (o->unit) {
230 else if (!strcmp(buf, "all" )) d = ~0;218 for (o_named = NULL; o_named = av_opt_next(target_obj, o_named); ) {
231 else {219 if (o_named->type == AV_OPT_TYPE_CONST &&
232 int res = av_expr_parse_and_eval(&d, buf, const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);220 o_named->unit &&
233 if (res < 0) {221 !strcmp(o_named->unit, o->unit)) {
234 av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val);222 if (ci + 6 >= FF_ARRAY_ELEMS(const_values)) {
235 return res;223 av_log(obj, AV_LOG_ERROR, "const_values array too small for %s\n", o->unit);
224 return AVERROR_PATCHWELCOME;
225 }
226 const_names [ci ] = o_named->name;
227 const_values[ci++] = DEFAULT_NUMVAL(o_named);
228 }
236 }229 }
237 }230 }
231 const_names [ci ] = "default";
232 const_values[ci++] = DEFAULT_NUMVAL(o);
233 const_names [ci ] = "max";
234 const_values[ci++] = o->max;
235 const_names [ci ] = "min";
236 const_values[ci++] = o->min;
237 const_names [ci ] = "none";
238 const_values[ci++] = 0;
239 const_names [ci ] = "all";
240 const_values[ci++] = ~0;
241 const_names [ci] = NULL;
242 const_values[ci] = 0;
243
244 res = av_expr_parse_and_eval(&d, buf, const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);
245 if (res < 0) {
246 av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val);
247 return res;
248 }
238 }249 }
239 if (o->type == AV_OPT_TYPE_FLAGS) {250 if (o->type == AV_OPT_TYPE_FLAGS) {
240 read_number(o, dst, NULL, NULL, &intnum);251 read_number(o, dst, NULL, NULL, &intnum);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t