49 if (!strcmp(o->
name, name) && (!unit || (o->
unit && !strcmp(o->
unit, unit))) && (o->
flags & mask) == flags)
56 #if FF_API_OLD_AVOPTIONS
66 if (!last && class->option && class->option[0].
name)
68 if (last && last[1].
name)
93 if (o->
max*den < num*intnum || o->
min*den > num*intnum) {
132 if (c >=
'0' && c <=
'9')
return c -
'0';
133 if (c >=
'a' && c <=
'f')
return c -
'a' + 10;
134 if (c >=
'A' && c <=
'F')
return c -
'A' + 10;
140 int *lendst = (
int *)(dst + 1);
142 int len = strlen(val);
155 if (a < 0 || b < 0) {
159 *ptr++ = (a << 4) | b;
174 #define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \
175 opt->type == AV_OPT_TYPE_CONST || \
176 opt->type == AV_OPT_TYPE_FLAGS || \
177 opt->type == AV_OPT_TYPE_INT) ? \
178 opt->default_val.i64 : opt->default_val.dbl)
182 int ret = 0, notfirst = 0;
191 if (*val ==
'+' || *val ==
'-') {
198 for (; i <
sizeof(buf) - 1 && val[i] && val[i] !=
'+' && val[i] !=
'-'; i++)
207 else if (!strcmp(buf,
"max" )) d = o->
max;
208 else if (!strcmp(buf,
"min" )) d = o->
min;
209 else if (!strcmp(buf,
"none" )) d = 0;
210 else if (!strcmp(buf,
"all" )) d = ~0;
212 int res =
av_expr_parse_and_eval(&d, buf,
const_names,
const_values,
NULL,
NULL,
NULL,
NULL,
NULL, 0, obj);
221 if (cmd ==
'+') d = intnum | (int64_t)d;
222 else if (cmd ==
'-') d = intnum &~(int64_t)d;
225 if (cmd ==
'+') d = notfirst*num*intnum/den + d;
226 else if (cmd ==
'-') d = notfirst*num*intnum/den - d;
240 #if FF_API_OLD_AVOPTIONS
253 void *
dst, *target_obj;
255 if (!o || !target_obj)
273 if (!val || !strcmp(val,
"none")) {
274 *(
int *)dst = *((
int *)dst + 1) = 0;
279 av_log(obj,
AV_LOG_ERROR,
"Unable to parse option value \"%s\" as image size\n", val);
282 if (!val || !strcmp(val,
"none")) {
288 ret = strtol(val, &tail, 0);
290 av_log(obj,
AV_LOG_ERROR,
"Unable to parse option value \"%s\" as pixel format\n", val);
298 if (!val || !strcmp(val,
"none")) {
304 ret = strtol(val, &tail, 0);
306 av_log(obj,
AV_LOG_ERROR,
"Unable to parse option value \"%s\" as sample format\n", val);
319 #define OPT_EVAL_NUMBER(name, opttype, vartype)\
320 int av_opt_eval_ ## name(void *obj, const AVOption *o, const char *val, vartype *name ## _out)\
322 if (!o || o->type != opttype)\
323 return AVERROR(EINVAL);\
324 return set_string_number(obj, o, val, name ## _out);\
334 static
int set_number(
void *obj, const
char *
name,
double num,
int den, int64_t intnum,
337 void *
dst, *target_obj;
340 if (!o || !target_obj)
347 #if FF_API_OLD_AVOPTIONS
375 return set_number(obj, name, 1, 1, val, search_flags);
380 return set_number(obj, name, val, 1, 1, search_flags);
396 if (!o || !target_obj)
407 lendst = (
int *)(dst + 1);
412 memcpy(ptr, val, len);
422 if (!o || !target_obj)
426 "The value set by option '%s' is not an image size.\n", o->
name);
431 "Invalid negative size value %dx%d for size '%s'\n", w, h, o->
name);
435 *(
int *)(((
uint8_t *)target_obj+
sizeof(int)) + o->
offset) = h;
444 search_flags, &target_obj);
448 if (!o || !target_obj)
450 if (o->
type != type) {
452 "The value set by option '%s' is not a %s format", name, desc);
456 #if LIBAVUTIL_VERSION_MAJOR < 53
457 if (class->version && class->version <
AV_VERSION_INT(52, 11, 100)) {
466 if (fmt < min || fmt > max) {
468 "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
469 fmt, name, desc, min, max);
486 #if FF_API_OLD_AVOPTIONS
504 if (o_out) *o_out= o;
517 if (len >= (buf_len + 1)/2)
return NULL;
519 for (i = 0; i <
len; i++)
snprintf(buf + i*2, 3,
"%02X", bin[i]);
521 default:
return NULL;
529 void *
dst, *target_obj;
556 if ((uint64_t)len*2 + 1 > INT_MAX)
561 for (i = 0; i <
len; i++)
562 snprintf(*out_val + i*2, 3,
"%02X", bin[i]);
565 ret =
snprintf(buf,
sizeof(buf),
"%dx%d", ((
int *)dst)[0], ((
int *)dst)[1]);
577 if (ret >=
sizeof(buf))
586 void *
dst, *target_obj;
588 if (!o || !target_obj)
593 if (o_out) *o_out= o;
602 #if FF_API_OLD_AVOPTIONS
609 if (
get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
611 return num*intnum/den;
620 if (
get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
622 if (num == 1.0 && (
int)intnum == intnum)
625 return av_d2q(num*intnum/den, 1<<24);
634 if (
get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
636 return num*intnum/den;
646 if ((ret =
get_number(obj, name,
NULL, &num, &den, &intnum, search_flags)) < 0)
648 *out_val = num*intnum/den;
658 if ((ret =
get_number(obj, name,
NULL, &num, &den, &intnum, search_flags)) < 0)
660 *out_val = num*intnum/den;
670 if ((ret =
get_number(obj, name,
NULL, &num, &den, &intnum, search_flags)) < 0)
673 if (num == 1.0 && (
int)intnum == intnum)
676 *out_val =
av_d2q(num*intnum/den, 1<<24);
682 void *
dst, *target_obj;
684 if (!o || !target_obj)
688 "The value for option '%s' is not an image size.\n", name);
693 if (w_out) *w_out = *(
int *)dst;
694 if (h_out) *h_out = *((
int *)dst+1);
698 static int get_format(
void *obj,
const char *
name,
int search_flags,
int *out_fmt,
701 void *
dst, *target_obj;
703 if (!o || !target_obj)
705 if (o->
type != type) {
707 "The value for option '%s' is not a %s format.\n", desc, name);
712 *out_fmt = *(
int *)dst;
742 av_log(av_log_obj, level,
"INT_MAX");
743 }
else if (d == INT_MIN) {
744 av_log(av_log_obj, level,
"INT_MIN");
745 }
else if (d == (
double)INT64_MAX) {
746 av_log(av_log_obj, level,
"I64_MAX");
747 }
else if (d == INT64_MIN) {
748 av_log(av_log_obj, level,
"I64_MIN");
749 }
else if (d == FLT_MAX) {
750 av_log(av_log_obj, level,
"FLT_MAX");
751 }
else if (d == FLT_MIN) {
752 av_log(av_log_obj, level,
"FLT_MIN");
754 av_log(av_log_obj, level,
"%g", d);
758 static void opt_list(
void *obj,
void *av_log_obj,
const char *unit,
759 int req_flags,
int rej_flags)
766 if (!(opt->
flags & req_flags) || (opt->
flags & rej_flags))
854 opt_list(obj, av_log_obj, opt->
unit, req_flags, rej_flags);
859 int av_opt_show2(
void *obj,
void *av_log_obj,
int req_flags,
int rej_flags)
873 #if FF_API_OLD_AVOPTIONS
883 #if FF_API_OLD_AVOPTIONS
884 if ((opt->flags & mask) !=
flags)
899 val = opt->default_val.dbl;
905 val =
av_d2q(opt->default_val.dbl, INT_MAX);
911 av_opt_set(s, opt->name, opt->default_val.str, 0);
914 #if LIBAVUTIL_VERSION_MAJOR < 53
915 if (class->version && class->version <
AV_VERSION_INT(52, 10, 100))
916 av_opt_set(s, opt->name, opt->default_val.str, 0);
922 #if LIBAVUTIL_VERSION_MAJOR < 53
923 if (class->version && class->version <
AV_VERSION_INT(52, 10, 100))
924 av_opt_set(s, opt->name, opt->default_val.str, 0);
933 av_log(s,
AV_LOG_DEBUG,
"AVOption type %d of option %s not implemented yet\n", opt->type, opt->name);
956 const char *key_val_sep,
const char *pairs_sep)
962 if (*key && strspn(*buf, key_val_sep)) {
966 av_log(ctx,
AV_LOG_ERROR,
"Missing key or no key/value separator found after key '%s'\n", key);
983 const char *key_val_sep,
const char *pairs_sep)
1002 #define WHITESPACES " \n\t"
1006 return (
unsigned)((c | 32) -
'a') < 26 ||
1007 (unsigned)(c -
'0') < 10 ||
1008 c ==
'-' || c ==
'_' || c ==
'/' || c ==
'.';
1019 static int get_key(
const char **ropts,
const char *delim,
char **rkey)
1021 const char *opts = *ropts;
1022 const char *key_start, *key_end;
1029 if (!*opts || !strchr(delim, *opts))
1032 if (!(*rkey =
av_malloc(key_end - key_start + 1)))
1034 memcpy(*rkey, key_start, key_end - key_start);
1035 (*rkey)[key_end - key_start] = 0;
1041 const char *key_val_sep,
const char *pairs_sep,
1043 char **rkey,
char **rval)
1046 char *key =
NULL, *val;
1047 const char *opts = *ropts;
1049 if ((ret =
get_key(&opts, key_val_sep, &key)) < 0 &&
1063 const char *
const *shorthand,
1064 const char *key_val_sep,
const char *pairs_sep)
1067 const char *dummy_shorthand =
NULL;
1074 shorthand = &dummy_shorthand;
1079 &parsed_key, &
value);
1095 key = *(shorthand++);
1144 int opt_flags,
int search_flags)
1150 int opt_flags,
int search_flags,
void **target_obj)
1169 if (o =
av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
1175 if (!strcmp(o->
name, name) && (o->
flags & opt_flags) == opt_flags &&
1218 if (c->
version > (52 << 16 | 11 << 8))
1224 return callback(ranges_arg, obj, key, flags);
1237 if (!ranges || !range || !range_array || !field) {
1242 ranges->
range = range_array;
1243 ranges->
range[0] = range;
1249 switch (field->
type) {
1278 *ranges_arg = ranges;
1292 for (i = 0; i < ranges->
nb_ranges; i++) {
1303 typedef struct TestContext
1316 #define OFFSET(x) offsetof(TestContext, x)
1318 #define TEST_FLAG_COOL 01
1319 #define TEST_FLAG_LAME 02
1320 #define TEST_FLAG_MU 04
1322 static const AVOption test_options[]= {
1328 {
"cool",
"set cool flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_COOL}, INT_MIN, INT_MAX, 0,
"flags" },
1329 {
"lame",
"set lame flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_LAME}, INT_MIN, INT_MAX, 0,
"flags" },
1330 {
"mu",
"set mu flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_MU}, INT_MIN, INT_MAX, 0,
"flags" },
1337 static const char *test_get_name(
void *ctx)
1342 static const AVClass test_class = {
1352 printf(
"\nTesting av_set_options_string()\n");
1354 TestContext test_ctx = { 0 };
1371 "flags=+mu-lame : num=42: toggle=0",
1372 "num=42 : string=blahblah",
1373 "rational=0 : rational=1/2 : rational=1/-1",
1386 test_ctx.class = &test_class;
1400 printf(
"\nTesting av_opt_set_from_string()\n");
1402 TestContext test_ctx = { 0 };
1403 const char *options[] = {
1411 " 5 : hello : size = pal ",
1412 "a_very_long_option_name_that_will_need_to_be_ellipsized_around_here=42"
1414 const char *shorthand[] = {
"num",
"string",
NULL };
1416 test_ctx.class = &test_class;