50 if (!strcmp(o->
name, name) && (!unit || (o->
unit && !strcmp(o->
unit, unit))) && (o->
flags & mask) == flags)
57 #if FF_API_OLD_AVOPTIONS
67 if (!last &&
class &&
class->option &&
class->option[0].name)
69 if (last && last[1].
name)
97 (o->
max * den < num * intnum || o->
min * den > num * intnum)) {
103 double d = num*intnum/den;
104 if (d < -1.5 || d > 0xFFFFFFFF+0.5 || (
llrint(d*256) & 255)) {
106 "Value %f for parameter '%s' is not a valid set of 32bit integer flags\n",
107 num*intnum/den, o->
name);
147 if (c >=
'0' && c <=
'9')
return c -
'0';
148 if (c >=
'a' && c <=
'f')
return c -
'a' + 10;
149 if (c >=
'A' && c <=
'F')
return c -
'A' + 10;
155 int *lendst = (
int *)(dst + 1);
157 int len = strlen(val);
170 if (a < 0 || b < 0) {
174 *ptr++ = (a << 4) | b;
189 #define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \
190 opt->type == AV_OPT_TYPE_CONST || \
191 opt->type == AV_OPT_TYPE_FLAGS || \
192 opt->type == AV_OPT_TYPE_INT) ? \
193 opt->default_val.i64 : opt->default_val.dbl)
197 int ret = 0, notfirst = 0;
201 if (sscanf(val,
"%d%*1[:/]%d%c", &num, &den, &c) == 2) {
202 if ((ret =
write_number(obj, o, dst, 1, den, num)) >= 0)
215 if (*val ==
'+' || *val ==
'-') {
222 for (; i <
sizeof(
buf) - 1 && val[i] && val[i] !=
'+' && val[i] !=
'-'; i++)
231 else if (!strcmp(buf,
"max" )) d = o->
max;
232 else if (!strcmp(buf,
"min" )) d = o->
min;
233 else if (!strcmp(buf,
"none" )) d = 0;
234 else if (!strcmp(buf,
"all" )) d = ~0;
236 int res =
av_expr_parse_and_eval(&d, buf,
const_names,
const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);
245 if (cmd ==
'+') d = intnum | (int64_t)d;
246 else if (cmd ==
'-') d = intnum &~(int64_t)d;
249 if (cmd ==
'+') d = notfirst*num*intnum/den + d;
250 else if (cmd ==
'-') d = notfirst*num*intnum/den - d;
268 if (!val || !strcmp(val,
"none")) {
275 av_log(obj,
AV_LOG_ERROR,
"Unable to parse option value \"%s\" as image size\n", val);
288 av_log(obj,
AV_LOG_ERROR,
"Unable to parse option value \"%s\" as video rate\n", val);
308 int fmt_nb,
int ((*get_fmt)(
const char *)),
const char *desc)
312 if (!val || !strcmp(val,
"none")) {
318 fmt = strtol(val, &tail, 0);
319 if (*tail || (
unsigned)fmt >= fmt_nb) {
321 "Unable to parse option value \"%s\" as %s\n", val, desc);
331 if(min == 0 && max == 0) {
336 if (fmt < min || fmt > max) {
338 "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
339 fmt, o->
name, desc, min, max);
359 #if FF_API_OLD_AVOPTIONS
372 void *dst, *target_obj;
374 if (!o || !target_obj)
412 if (!val || !strcmp(val,
"none")) {
415 #if FF_API_GET_CHANNEL_LAYOUT_COMPAT
421 av_log(obj,
AV_LOG_ERROR,
"Unable to parse option value \"%s\" as channel layout\n", val);
424 *(int64_t *)dst = cl;
434 #define OPT_EVAL_NUMBER(name, opttype, vartype)\
435 int av_opt_eval_ ## name(void *obj, const AVOption *o, const char *val, vartype *name ## _out)\
437 if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY)\
438 return AVERROR(EINVAL);\
439 return set_string_number(obj, obj, o, val, name ## _out);\
449 static
int set_number(
void *obj, const
char *
name,
double num,
int den, int64_t intnum,
452 void *dst, *target_obj;
455 if (!o || !target_obj)
465 #if FF_API_OLD_AVOPTIONS
493 return set_number(obj, name, 1, 1, val, search_flags);
498 return set_number(obj, name, val, 1, 1, search_flags);
514 if (!o || !target_obj)
525 lendst = (
int *)(dst + 1);
531 memcpy(ptr, val, len);
541 if (!o || !target_obj)
545 "The value set by option '%s' is not an image size.\n", o->
name);
550 "Invalid negative size value %dx%d for size '%s'\n", w, h, o->
name);
554 *(
int *)(((
uint8_t *)target_obj+
sizeof(int)) + o->
offset) = h;
563 if (!o || !target_obj)
567 "The value set by option '%s' is not a video rate.\n", o->
name);
570 if (val.
num <= 0 || val.
den <= 0)
580 search_flags, &target_obj);
584 if (!o || !target_obj)
586 if (o->
type != type) {
588 "The value set by option '%s' is not a %s format", name, desc);
592 #if LIBAVUTIL_VERSION_MAJOR < 54
602 if (fmt < min || fmt > max) {
604 "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
605 fmt, name, desc, min, max);
627 if (!o || !target_obj)
631 "The value set by option '%s' is not a channel layout.\n", o->
name);
634 *(
int *)(((int64_t *)target_obj) + o->
offset) = cl;
638 #if FF_API_OLD_AVOPTIONS
656 if (o_out) *o_out= o;
669 if (len >= (buf_len + 1)/2)
return NULL;
671 for (i = 0; i <
len; i++)
snprintf(buf + i*2, 3,
"%02X", bin[i]);
673 default:
return NULL;
681 void *dst, *target_obj;
710 if ((uint64_t)len*2 + 1 > INT_MAX)
715 for (i = 0; i <
len; i++)
716 snprintf(*out_val + i*2, 3,
"%02X", bin[i]);
719 ret =
snprintf(buf,
sizeof(buf),
"%dx%d", ((
int *)dst)[0], ((
int *)dst)[1]);
728 i64 = *(int64_t *)dst;
729 ret =
snprintf(buf,
sizeof(buf),
"%"PRIi64
"d:%02d:%02d.%06d",
730 i64 / 3600000000, (
int)((i64 / 60000000) % 60),
731 (
int)((i64 / 1000000) % 60), (
int)(i64 % 1000000));
734 ret =
snprintf(buf,
sizeof(buf),
"0x%02x%02x%02x%02x", ((
int *)dst)[0], ((
int *)dst)[1], ((
int *)dst)[2], ((
int *)dst)[3]);
737 i64 = *(int64_t *)dst;
738 ret =
snprintf(buf,
sizeof(buf),
"0x%"PRIx64, i64);
744 if (ret >=
sizeof(buf))
753 void *dst, *target_obj;
755 if (!o || !target_obj)
760 if (o_out) *o_out= o;
769 #if FF_API_OLD_AVOPTIONS
776 if (
get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
778 return num*intnum/den;
787 if (
get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
789 if (num == 1.0 && (
int)intnum == intnum)
792 return av_d2q(num*intnum/den, 1<<24);
801 if (
get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
803 return num*intnum/den;
813 if ((ret =
get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
815 *out_val = num*intnum/den;
825 if ((ret =
get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
827 *out_val = num*intnum/den;
837 if ((ret =
get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
840 if (num == 1.0 && (
int)intnum == intnum)
843 *out_val =
av_d2q(num*intnum/den, 1<<24);
849 void *dst, *target_obj;
851 if (!o || !target_obj)
855 "The value for option '%s' is not an image size.\n", name);
860 if (w_out) *w_out = *(
int *)dst;
861 if (h_out) *h_out = *((
int *)dst+1);
871 if ((ret =
get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
874 if (num == 1.0 && (
int)intnum == intnum)
877 *out_val =
av_d2q(num*intnum/den, 1<<24);
881 static int get_format(
void *obj,
const char *
name,
int search_flags,
int *out_fmt,
884 void *dst, *target_obj;
886 if (!o || !target_obj)
888 if (o->
type != type) {
890 "The value for option '%s' is not a %s format.\n", desc, name);
895 *out_fmt = *(
int *)dst;
911 void *dst, *target_obj;
913 if (!o || !target_obj)
917 "The value for option '%s' is not a channel layout.\n", name);
922 *cl = *(int64_t *)dst;
930 field ? field->
unit : NULL, 0, 0);
942 av_log(av_log_obj, level,
"INT_MAX");
943 }
else if (d == INT_MIN) {
944 av_log(av_log_obj, level,
"INT_MIN");
945 }
else if (d == UINT32_MAX) {
946 av_log(av_log_obj, level,
"UINT32_MAX");
947 }
else if (d == (
double)INT64_MAX) {
948 av_log(av_log_obj, level,
"I64_MAX");
949 }
else if (d == INT64_MIN) {
950 av_log(av_log_obj, level,
"I64_MIN");
951 }
else if (d == FLT_MAX) {
952 av_log(av_log_obj, level,
"FLT_MAX");
953 }
else if (d == FLT_MIN) {
954 av_log(av_log_obj, level,
"FLT_MIN");
955 }
else if (d == -FLT_MAX) {
956 av_log(av_log_obj, level,
"-FLT_MAX");
957 }
else if (d == -FLT_MIN) {
958 av_log(av_log_obj, level,
"-FLT_MIN");
959 }
else if (d == DBL_MAX) {
960 av_log(av_log_obj, level,
"DBL_MAX");
961 }
else if (d == DBL_MIN) {
962 av_log(av_log_obj, level,
"DBL_MIN");
963 }
else if (d == -DBL_MAX) {
964 av_log(av_log_obj, level,
"-DBL_MAX");
965 }
else if (d == -DBL_MIN) {
966 av_log(av_log_obj, level,
"-DBL_MIN");
968 av_log(av_log_obj, level,
"%g", d);
972 static void opt_list(
void *obj,
void *av_log_obj,
const char *unit,
973 int req_flags,
int rej_flags)
980 if (!(opt->
flags & req_flags) || (opt->
flags & rej_flags))
1000 switch (opt->
type) {
1064 switch (opt->
type) {
1090 switch (opt->
type) {
1128 opt_list(obj, av_log_obj, opt->
unit, req_flags, rej_flags);
1133 int av_opt_show2(
void *obj,
void *av_log_obj,
int req_flags,
int rej_flags)
1140 opt_list(obj, av_log_obj, NULL, req_flags, rej_flags);
1147 #if FF_API_OLD_AVOPTIONS
1158 #if FF_API_OLD_AVOPTIONS
1166 switch (opt->
type) {
1203 #if LIBAVUTIL_VERSION_MAJOR < 54
1211 #if LIBAVUTIL_VERSION_MAJOR < 54
1245 const char *key_val_sep,
const char *pairs_sep)
1254 if (*key && strspn(*buf, key_val_sep)) {
1262 av_log(ctx,
AV_LOG_ERROR,
"Missing key or no key/value separator found after key '%s'\n", key);
1279 const char *key_val_sep,
const char *pairs_sep)
1298 #define WHITESPACES " \n\t"
1302 return (
unsigned)((c | 32) -
'a') < 26 ||
1303 (unsigned)(c -
'0') < 10 ||
1304 c ==
'-' || c ==
'_' || c ==
'/' || c ==
'.';
1315 static int get_key(
const char **ropts,
const char *delim,
char **rkey)
1317 const char *opts = *ropts;
1318 const char *key_start, *key_end;
1325 if (!*opts || !strchr(delim, *opts))
1328 if (!(*rkey =
av_malloc(key_end - key_start + 1)))
1330 memcpy(*rkey, key_start, key_end - key_start);
1331 (*rkey)[key_end - key_start] = 0;
1337 const char *key_val_sep,
const char *pairs_sep,
1339 char **rkey,
char **rval)
1342 char *key = NULL, *
val;
1343 const char *opts = *ropts;
1345 if ((ret =
get_key(&opts, key_val_sep, &key)) < 0 &&
1359 const char *
const *shorthand,
1360 const char *key_val_sep,
const char *pairs_sep)
1363 const char *dummy_shorthand = NULL;
1370 shorthand = &dummy_shorthand;
1375 &parsed_key, &
value);
1391 key = *(shorthand++);
1440 int opt_flags,
int search_flags)
1442 return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL);
1446 int opt_flags,
int search_flags,
void **target_obj)
1463 if (o =
av_opt_find2(&child, name, unit, opt_flags, search_flags, NULL))
1468 if (o =
av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
1474 if (!strcmp(o->
name, name) && (o->
flags & opt_flags) == opt_flags &&
1517 if (c->
version > (52 << 16 | 11 << 8))
1523 return callback(ranges_arg, obj, key, flags);
1536 if (!ranges || !range || !range_array || !field) {
1541 ranges->
range = range_array;
1542 ranges->
range[0] = range;
1548 switch (field->
type) {
1586 *ranges_arg = ranges;
1600 for (i = 0; i < ranges->
nb_ranges; i++) {
1611 typedef struct TestContext
1625 int64_t channel_layout;
1628 #define OFFSET(x) offsetof(TestContext, x)
1630 #define TEST_FLAG_COOL 01
1631 #define TEST_FLAG_LAME 02
1632 #define TEST_FLAG_MU 04
1634 static const AVOption test_options[]= {
1640 {
"cool",
"set cool flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_COOL}, INT_MIN, INT_MAX, 0,
"flags" },
1641 {
"lame",
"set lame flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_LAME}, INT_MIN, INT_MAX, 0,
"flags" },
1642 {
"mu",
"set mu flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_MU}, INT_MIN, INT_MAX, 0,
"flags" },
1653 static const char *test_get_name(
void *ctx)
1658 static const AVClass test_class = {
1668 printf(
"\nTesting av_set_options_string()\n");
1670 TestContext test_ctx = { 0 };
1671 static const char *
const options[] = {
1687 "flags=+mu-lame : num=42: toggle=0",
1688 "num=42 : string=blahblah",
1689 "rational=0 : rational=1/2 : rational=1/-1",
1702 "video_rate=30000/1001",
1703 "video_rate=30/1.001",
1707 "duration=1\\:23\\:45.67",
1711 "cl=stereo+downmix",
1715 test_ctx.class = &test_class;
1729 printf(
"\nTesting av_opt_set_from_string()\n");
1731 TestContext test_ctx = { 0 };
1732 static const char *
const options[] = {
1740 " 5 : hello : size = pal ",
1741 "a_very_long_option_name_that_will_need_to_be_ellipsized_around_here=42"
1743 static const char *
const shorthand[] = {
"num",
"string", NULL };
1745 test_ctx.class = &test_class;