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);
133 if (c >=
'0' && c <=
'9')
return c -
'0';
134 if (c >=
'a' && c <=
'f')
return c -
'a' + 10;
135 if (c >=
'A' && c <=
'F')
return c -
'A' + 10;
141 int *lendst = (
int *)(dst + 1);
143 int len = strlen(val);
156 if (a < 0 || b < 0) {
160 *ptr++ = (a << 4) | b;
175 #define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \
176 opt->type == AV_OPT_TYPE_CONST || \
177 opt->type == AV_OPT_TYPE_FLAGS || \
178 opt->type == AV_OPT_TYPE_INT) ? \
179 opt->default_val.i64 : opt->default_val.dbl)
187 if (sscanf(val,
"%d%*1[:/]%d%c", &num, &den, &c) == 2) {
188 if ((ret =
write_number(obj, o, dst, 1, den, num)) >= 0)
201 if (*val ==
'+' || *val ==
'-')
203 for (; i <
sizeof(
buf) - 1 && val[i] && val[i] !=
'+' && val[i] !=
'-'; i++)
212 double const_values[64];
213 const char * const_names[64];
218 for (o_named = NULL; o_named =
av_opt_next(target_obj, o_named); ) {
226 const_names [ci ] = o_named->
name;
231 const_names [ci ] =
"default";
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;
245 const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);
254 if (cmd ==
'+') d = intnum | (int64_t)d;
255 else if (cmd ==
'-') d = intnum &~(int64_t)d;
272 if (!val || !strcmp(val,
"none")) {
279 av_log(obj,
AV_LOG_ERROR,
"Unable to parse option value \"%s\" as image size\n", val);
292 av_log(obj,
AV_LOG_ERROR,
"Unable to parse option value \"%s\" as video rate\n", val);
312 int fmt_nb,
int ((*get_fmt)(
const char *)),
const char *desc)
316 if (!val || !strcmp(val,
"none")) {
322 fmt = strtol(val, &tail, 0);
323 if (*tail || (
unsigned)fmt >= fmt_nb) {
325 "Unable to parse option value \"%s\" as %s\n", val, desc);
335 if(min == 0 && max == 0) {
340 if (fmt < min || fmt > max) {
342 "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
343 fmt, o->
name, desc, min, max);
363 #if FF_API_OLD_AVOPTIONS
373 int av_opt_set(
void *obj,
const char *name,
const char *val,
int search_flags)
376 void *dst, *target_obj;
378 if (!o || !target_obj)
416 if (!val || !strcmp(val,
"none")) {
419 #if FF_API_GET_CHANNEL_LAYOUT_COMPAT
425 av_log(obj,
AV_LOG_ERROR,
"Unable to parse option value \"%s\" as channel layout\n", val);
428 *(int64_t *)dst = cl;
438 #define OPT_EVAL_NUMBER(name, opttype, vartype)\
439 int av_opt_eval_ ## name(void *obj, const AVOption *o, const char *val, vartype *name ## _out)\
441 if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY)\
442 return AVERROR(EINVAL);\
443 return set_string_number(obj, obj, o, val, name ## _out);\
453 static
int set_number(
void *obj, const
char *name,
double num,
int den, int64_t intnum,
456 void *dst, *target_obj;
459 if (!o || !target_obj)
469 #if FF_API_OLD_AVOPTIONS
497 return set_number(obj, name, 1, 1, val, search_flags);
502 return set_number(obj, name, val, 1, 1, search_flags);
518 if (!o || !target_obj)
529 lendst = (
int *)(dst + 1);
535 memcpy(ptr, val, len);
545 if (!o || !target_obj)
549 "The value set by option '%s' is not an image size.\n", o->
name);
554 "Invalid negative size value %dx%d for size '%s'\n", w, h, o->
name);
558 *(
int *)(((
uint8_t *)target_obj+
sizeof(int)) + o->
offset) = h;
567 if (!o || !target_obj)
571 "The value set by option '%s' is not a video rate.\n", o->
name);
574 if (val.
num <= 0 || val.
den <= 0)
579 static int set_format(
void *obj,
const char *name,
int fmt,
int search_flags,
584 search_flags, &target_obj);
587 if (!o || !target_obj)
589 if (o->
type != type) {
591 "The value set by option '%s' is not a %s format", name, desc);
598 if (fmt < min || fmt > max) {
600 "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
601 fmt, name, desc, min, max);
623 if (!o || !target_obj)
627 "The value set by option '%s' is not a channel layout.\n", o->
name);
630 *(
int *)(((int64_t *)target_obj) + o->
offset) = cl;
634 #if FF_API_OLD_AVOPTIONS
652 if (o_out) *o_out= o;
665 if (len >= (buf_len + 1)/2)
return NULL;
667 for (i = 0; i <
len; i++)
snprintf(buf + i*2, 3,
"%02X", bin[i]);
669 default:
return NULL;
681 if (!o || !target_obj)
695 void *dst, *target_obj;
724 if ((uint64_t)len*2 + 1 > INT_MAX)
729 for (i = 0; i <
len; i++)
730 snprintf(*out_val + i*2, 3,
"%02X", bin[i]);
733 ret =
snprintf(buf,
sizeof(buf),
"%dx%d", ((
int *)dst)[0], ((
int *)dst)[1]);
742 i64 = *(int64_t *)dst;
743 ret =
snprintf(buf,
sizeof(buf),
"%"PRIi64
"d:%02d:%02d.%06d",
744 i64 / 3600000000, (
int)((i64 / 60000000) % 60),
745 (
int)((i64 / 1000000) % 60), (
int)(i64 % 1000000));
748 ret =
snprintf(buf,
sizeof(buf),
"0x%02x%02x%02x%02x", ((
int *)dst)[0], ((
int *)dst)[1], ((
int *)dst)[2], ((
int *)dst)[3]);
751 i64 = *(int64_t *)dst;
752 ret =
snprintf(buf,
sizeof(buf),
"0x%"PRIx64, i64);
758 if (ret >=
sizeof(buf))
764 static int get_number(
void *obj,
const char *name,
const AVOption **o_out,
double *num,
int *den, int64_t *intnum,
767 void *dst, *target_obj;
769 if (!o || !target_obj)
774 if (o_out) *o_out= o;
783 #if FF_API_OLD_AVOPTIONS
790 if (
get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
792 return num*intnum/den;
801 if (
get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
803 if (num == 1.0 && (
int)intnum == intnum)
806 return av_d2q(num*intnum/den, 1<<24);
815 if (
get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
817 return num*intnum/den;
821 int av_opt_get_int(
void *obj,
const char *name,
int search_flags, int64_t *out_val)
827 if ((ret =
get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
829 *out_val = num*intnum/den;
839 if ((ret =
get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
841 *out_val = num*intnum/den;
851 if ((ret =
get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
854 if (num == 1.0 && (
int)intnum == intnum)
857 *out_val =
av_d2q(num*intnum/den, 1<<24);
863 void *dst, *target_obj;
865 if (!o || !target_obj)
869 "The value for option '%s' is not an image size.\n", name);
874 if (w_out) *w_out = *(
int *)dst;
875 if (h_out) *h_out = *((
int *)dst+1);
885 if ((ret =
get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
888 if (num == 1.0 && (
int)intnum == intnum)
891 *out_val =
av_d2q(num*intnum/den, 1<<24);
895 static int get_format(
void *obj,
const char *name,
int search_flags,
int *out_fmt,
898 void *dst, *target_obj;
900 if (!o || !target_obj)
902 if (o->
type != type) {
904 "The value for option '%s' is not a %s format.\n", desc, name);
909 *out_fmt = *(
int *)dst;
925 void *dst, *target_obj;
927 if (!o || !target_obj)
931 "The value for option '%s' is not a channel layout.\n", name);
936 *cl = *(int64_t *)dst;
946 if (!o || !target_obj)
961 field ? field->
unit : NULL, 0, 0);
973 av_log(av_log_obj, level,
"INT_MAX");
974 }
else if (d == INT_MIN) {
975 av_log(av_log_obj, level,
"INT_MIN");
976 }
else if (d == UINT32_MAX) {
977 av_log(av_log_obj, level,
"UINT32_MAX");
978 }
else if (d == (
double)INT64_MAX) {
979 av_log(av_log_obj, level,
"I64_MAX");
980 }
else if (d == INT64_MIN) {
981 av_log(av_log_obj, level,
"I64_MIN");
982 }
else if (d == FLT_MAX) {
983 av_log(av_log_obj, level,
"FLT_MAX");
984 }
else if (d == FLT_MIN) {
985 av_log(av_log_obj, level,
"FLT_MIN");
986 }
else if (d == -FLT_MAX) {
987 av_log(av_log_obj, level,
"-FLT_MAX");
988 }
else if (d == -FLT_MIN) {
989 av_log(av_log_obj, level,
"-FLT_MIN");
990 }
else if (d == DBL_MAX) {
991 av_log(av_log_obj, level,
"DBL_MAX");
992 }
else if (d == DBL_MIN) {
993 av_log(av_log_obj, level,
"DBL_MIN");
994 }
else if (d == -DBL_MAX) {
995 av_log(av_log_obj, level,
"-DBL_MAX");
996 }
else if (d == -DBL_MIN) {
997 av_log(av_log_obj, level,
"-DBL_MIN");
999 av_log(av_log_obj, level,
"%g", d);
1003 static void opt_list(
void *obj,
void *av_log_obj,
const char *unit,
1004 int req_flags,
int rej_flags)
1011 if (!(opt->
flags & req_flags) || (opt->
flags & rej_flags))
1031 switch (opt->
type) {
1095 switch (opt->
type) {
1121 switch (opt->
type) {
1159 opt_list(obj, av_log_obj, opt->
unit, req_flags, rej_flags);
1164 int av_opt_show2(
void *obj,
void *av_log_obj,
int req_flags,
int rej_flags)
1171 opt_list(obj, av_log_obj, NULL, req_flags, rej_flags);
1178 #if FF_API_OLD_AVOPTIONS
1188 #if FF_API_OLD_AVOPTIONS
1196 switch (opt->
type) {
1266 const char *key_val_sep,
const char *pairs_sep)
1275 if (*key && strspn(*buf, key_val_sep)) {
1283 av_log(ctx,
AV_LOG_ERROR,
"Missing key or no key/value separator found after key '%s'\n", key);
1300 const char *key_val_sep,
const char *pairs_sep)
1319 #define WHITESPACES " \n\t"
1323 return (
unsigned)((c | 32) -
'a') < 26 ||
1324 (unsigned)(c -
'0') < 10 ||
1325 c ==
'-' || c ==
'_' || c ==
'/' || c ==
'.';
1336 static int get_key(
const char **ropts,
const char *delim,
char **rkey)
1338 const char *opts = *ropts;
1339 const char *key_start, *key_end;
1346 if (!*opts || !strchr(delim, *opts))
1349 if (!(*rkey =
av_malloc(key_end - key_start + 1)))
1351 memcpy(*rkey, key_start, key_end - key_start);
1352 (*rkey)[key_end - key_start] = 0;
1358 const char *key_val_sep,
const char *pairs_sep,
1360 char **rkey,
char **rval)
1363 char *key = NULL, *
val;
1364 const char *opts = *ropts;
1366 if ((ret =
get_key(&opts, key_val_sep, &key)) < 0 &&
1380 const char *
const *shorthand,
1381 const char *key_val_sep,
const char *pairs_sep)
1384 const char *dummy_shorthand = NULL;
1391 shorthand = &dummy_shorthand;
1396 &parsed_key, &
value);
1412 key = *(shorthand++);
1481 int opt_flags,
int search_flags)
1483 return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL);
1487 int opt_flags,
int search_flags,
void **target_obj)
1504 if (o =
av_opt_find2(&child, name, unit, opt_flags, search_flags, NULL))
1509 if (o =
av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
1515 if (!strcmp(o->
name, name) && (o->
flags & opt_flags) == opt_flags &&
1595 if (*field_dst8 != *field_src8)
1598 if (*field_src8 && !*field_dst8)
1601 int len = *(
int*)(field_src8 + 1);
1602 if (*field_dst8 != *field_src8)
1604 *field_dst8 =
av_memdup(*field_src8, len);
1605 if (len && !*field_dst8) {
1609 *(
int*)(field_dst8 + 1) =
len;
1625 if (c->
version > (52 << 16 | 11 << 8))
1631 ret =
callback(ranges_arg, obj, key, flags);
1635 (*ranges_arg)->nb_components =
ret;
1650 if (!ranges || !range || !range_array || !field) {
1655 ranges->
range = range_array;
1656 ranges->
range[0] = range;
1663 switch (field->
type) {
1701 *ranges_arg = ranges;
1731 typedef struct TestContext
1745 int64_t channel_layout;
1748 #define OFFSET(x) offsetof(TestContext, x)
1750 #define TEST_FLAG_COOL 01
1751 #define TEST_FLAG_LAME 02
1752 #define TEST_FLAG_MU 04
1754 static const AVOption test_options[]= {
1760 {
"cool",
"set cool flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_COOL}, INT_MIN, INT_MAX, 0,
"flags" },
1761 {
"lame",
"set lame flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_LAME}, INT_MIN, INT_MAX, 0,
"flags" },
1762 {
"mu",
"set mu flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_MU}, INT_MIN, INT_MAX, 0,
"flags" },
1773 static const char *test_get_name(
void *ctx)
1778 static const AVClass test_class = {
1788 printf(
"\nTesting av_set_options_string()\n");
1790 TestContext test_ctx = { 0 };
1791 static const char *
const options[] = {
1807 "flags=+mu-lame : num=42: toggle=0",
1808 "num=42 : string=blahblah",
1809 "rational=0 : rational=1/2 : rational=1/-1",
1822 "video_rate=30000/1001",
1823 "video_rate=30/1.001",
1827 "duration=1\\:23\\:45.67",
1831 "cl=stereo+downmix",
1835 test_ctx.class = &test_class;
1849 printf(
"\nTesting av_opt_set_from_string()\n");
1851 TestContext test_ctx = { 0 };
1852 static const char *
const options[] = {
1860 " 5 : hello : size = pal ",
1861 "a_very_long_option_name_that_will_need_to_be_ellipsized_around_here=42"
1863 static const char *
const shorthand[] = {
"num",
"string", NULL };
1865 test_ctx.class = &test_class;