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