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)
96 if (o->
max*den < num*intnum || o->
min*den > num*intnum) {
137 if (c >=
'0' && c <=
'9')
return c -
'0';
138 if (c >=
'a' && c <=
'f')
return c -
'a' + 10;
139 if (c >=
'A' && c <=
'F')
return c -
'A' + 10;
145 int *lendst = (
int *)(dst + 1);
147 int len = strlen(val);
160 if (a < 0 || b < 0) {
164 *ptr++ = (a << 4) | b;
179 #define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \
180 opt->type == AV_OPT_TYPE_CONST || \
181 opt->type == AV_OPT_TYPE_FLAGS || \
182 opt->type == AV_OPT_TYPE_INT) ? \
183 opt->default_val.i64 : opt->default_val.dbl)
187 int ret = 0, notfirst = 0;
196 if (*val ==
'+' || *val ==
'-') {
203 for (; i <
sizeof(
buf) - 1 && val[i] && val[i] !=
'+' && val[i] !=
'-'; i++)
212 else if (!strcmp(buf,
"max" )) d = o->
max;
213 else if (!strcmp(buf,
"min" )) d = o->
min;
214 else if (!strcmp(buf,
"none" )) d = 0;
215 else if (!strcmp(buf,
"all" )) d = ~0;
217 int res =
av_expr_parse_and_eval(&d, buf,
const_names,
const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);
226 if (cmd ==
'+') d = intnum | (int64_t)d;
227 else if (cmd ==
'-') d = intnum &~(int64_t)d;
230 if (cmd ==
'+') d = notfirst*num*intnum/den + d;
231 else if (cmd ==
'-') d = notfirst*num*intnum/den - d;
245 #if FF_API_OLD_AVOPTIONS
258 void *dst, *target_obj;
260 if (!o || !target_obj)
280 if (!val || !strcmp(val,
"none")) {
281 *(
int *)dst = *((
int *)dst + 1) = 0;
286 av_log(obj,
AV_LOG_ERROR,
"Unable to parse option value \"%s\" as image size\n", val);
295 av_log(obj,
AV_LOG_ERROR,
"Unable to parse option value \"%s\" as video rate\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 pixel format\n", val);
314 if (!val || !strcmp(val,
"none")) {
320 ret = strtol(val, &tail, 0);
322 av_log(obj,
AV_LOG_ERROR,
"Unable to parse option value \"%s\" as sample format\n", val);
350 if (!val || !strcmp(val,
"none")) {
353 #if FF_API_GET_CHANNEL_LAYOUT_COMPAT
359 av_log(obj,
AV_LOG_ERROR,
"Unable to parse option value \"%s\" as channel layout\n", val);
362 *(int64_t *)dst = cl;
372 #define OPT_EVAL_NUMBER(name, opttype, vartype)\
373 int av_opt_eval_ ## name(void *obj, const AVOption *o, const char *val, vartype *name ## _out)\
375 if (!o || o->type != opttype)\
376 return AVERROR(EINVAL);\
377 return set_string_number(obj, obj, o, val, name ## _out);\
387 static
int set_number(
void *obj, const
char *
name,
double num,
int den, int64_t intnum,
390 void *dst, *target_obj;
393 if (!o || !target_obj)
400 #if FF_API_OLD_AVOPTIONS
428 return set_number(obj, name, 1, 1, val, search_flags);
433 return set_number(obj, name, val, 1, 1, search_flags);
449 if (!o || !target_obj)
460 lendst = (
int *)(dst + 1);
466 memcpy(ptr, val, len);
476 if (!o || !target_obj)
480 "The value set by option '%s' is not an image size.\n", o->
name);
485 "Invalid negative size value %dx%d for size '%s'\n", w, h, o->
name);
489 *(
int *)(((
uint8_t *)target_obj+
sizeof(int)) + o->
offset) = h;
498 if (!o || !target_obj)
502 "The value set by option '%s' is not a video rate.\n", o->
name);
505 if (val.
num <= 0 || val.
den <= 0)
515 search_flags, &target_obj);
519 if (!o || !target_obj)
521 if (o->
type != type) {
523 "The value set by option '%s' is not a %s format", name, desc);
527 #if LIBAVUTIL_VERSION_MAJOR < 53
537 if (fmt < min || fmt > max) {
539 "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
540 fmt, name, desc, min, max);
562 if (!o || !target_obj)
566 "The value set by option '%s' is not a channel layout.\n", o->
name);
569 *(
int *)(((int64_t *)target_obj) + o->
offset) = cl;
573 #if FF_API_OLD_AVOPTIONS
591 if (o_out) *o_out= o;
604 if (len >= (buf_len + 1)/2)
return NULL;
606 for (i = 0; i <
len; i++)
snprintf(buf + i*2, 3,
"%02X", bin[i]);
608 default:
return NULL;
616 void *dst, *target_obj;
645 if ((uint64_t)len*2 + 1 > INT_MAX)
650 for (i = 0; i <
len; i++)
651 snprintf(*out_val + i*2, 3,
"%02X", bin[i]);
654 ret =
snprintf(buf,
sizeof(buf),
"%dx%d", ((
int *)dst)[0], ((
int *)dst)[1]);
663 i64 = *(int64_t *)dst;
664 ret =
snprintf(buf,
sizeof(buf),
"%"PRIi64
"d:%02d:%02d.%06d",
665 i64 / 3600000000, (
int)((i64 / 60000000) % 60),
666 (
int)((i64 / 1000000) % 60), (
int)(i64 % 1000000));
669 ret =
snprintf(buf,
sizeof(buf),
"0x%02x%02x%02x%02x", ((
int *)dst)[0], ((
int *)dst)[1], ((
int *)dst)[2], ((
int *)dst)[3]);
672 i64 = *(int64_t *)dst;
673 ret =
snprintf(buf,
sizeof(buf),
"0x%"PRIx64, i64);
679 if (ret >=
sizeof(buf))
688 void *dst, *target_obj;
690 if (!o || !target_obj)
695 if (o_out) *o_out= o;
704 #if FF_API_OLD_AVOPTIONS
711 if (
get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
713 return num*intnum/den;
722 if (
get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
724 if (num == 1.0 && (
int)intnum == intnum)
727 return av_d2q(num*intnum/den, 1<<24);
736 if (
get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
738 return num*intnum/den;
748 if ((ret =
get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
750 *out_val = num*intnum/den;
760 if ((ret =
get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
762 *out_val = num*intnum/den;
772 if ((ret =
get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
775 if (num == 1.0 && (
int)intnum == intnum)
778 *out_val =
av_d2q(num*intnum/den, 1<<24);
784 void *dst, *target_obj;
786 if (!o || !target_obj)
790 "The value for option '%s' is not an image size.\n", name);
795 if (w_out) *w_out = *(
int *)dst;
796 if (h_out) *h_out = *((
int *)dst+1);
806 if ((ret =
get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
809 if (num == 1.0 && (
int)intnum == intnum)
812 *out_val =
av_d2q(num*intnum/den, 1<<24);
816 static int get_format(
void *obj,
const char *
name,
int search_flags,
int *out_fmt,
819 void *dst, *target_obj;
821 if (!o || !target_obj)
823 if (o->
type != type) {
825 "The value for option '%s' is not a %s format.\n", desc, name);
830 *out_fmt = *(
int *)dst;
846 void *dst, *target_obj;
848 if (!o || !target_obj)
852 "The value for option '%s' is not a channel layout.\n", name);
857 *cl = *(int64_t *)dst;
865 field ? field->
unit : NULL, 0, 0);
877 av_log(av_log_obj, level,
"INT_MAX");
878 }
else if (d == INT_MIN) {
879 av_log(av_log_obj, level,
"INT_MIN");
880 }
else if (d == (
double)INT64_MAX) {
881 av_log(av_log_obj, level,
"I64_MAX");
882 }
else if (d == INT64_MIN) {
883 av_log(av_log_obj, level,
"I64_MIN");
884 }
else if (d == FLT_MAX) {
885 av_log(av_log_obj, level,
"FLT_MAX");
886 }
else if (d == FLT_MIN) {
887 av_log(av_log_obj, level,
"FLT_MIN");
889 av_log(av_log_obj, level,
"%g", d);
893 static void opt_list(
void *obj,
void *av_log_obj,
const char *unit,
894 int req_flags,
int rej_flags)
901 if (!(opt->
flags & req_flags) || (opt->
flags & rej_flags))
1009 switch (opt->
type) {
1047 opt_list(obj, av_log_obj, opt->
unit, req_flags, rej_flags);
1052 int av_opt_show2(
void *obj,
void *av_log_obj,
int req_flags,
int rej_flags)
1059 opt_list(obj, av_log_obj, NULL, req_flags, rej_flags);
1066 #if FF_API_OLD_AVOPTIONS
1076 #if FF_API_OLD_AVOPTIONS
1080 switch (opt->
type) {
1111 #if LIBAVUTIL_VERSION_MAJOR < 53
1119 #if LIBAVUTIL_VERSION_MAJOR < 53
1153 const char *key_val_sep,
const char *pairs_sep)
1162 if (*key && strspn(*buf, key_val_sep)) {
1170 av_log(ctx,
AV_LOG_ERROR,
"Missing key or no key/value separator found after key '%s'\n", key);
1187 const char *key_val_sep,
const char *pairs_sep)
1206 #define WHITESPACES " \n\t"
1210 return (
unsigned)((c | 32) -
'a') < 26 ||
1211 (unsigned)(c -
'0') < 10 ||
1212 c ==
'-' || c ==
'_' || c ==
'/' || c ==
'.';
1223 static int get_key(
const char **ropts,
const char *delim,
char **rkey)
1225 const char *opts = *ropts;
1226 const char *key_start, *key_end;
1233 if (!*opts || !strchr(delim, *opts))
1236 if (!(*rkey =
av_malloc(key_end - key_start + 1)))
1238 memcpy(*rkey, key_start, key_end - key_start);
1239 (*rkey)[key_end - key_start] = 0;
1245 const char *key_val_sep,
const char *pairs_sep,
1247 char **rkey,
char **rval)
1250 char *key = NULL, *
val;
1251 const char *opts = *ropts;
1253 if ((ret =
get_key(&opts, key_val_sep, &key)) < 0 &&
1267 const char *
const *shorthand,
1268 const char *key_val_sep,
const char *pairs_sep)
1271 const char *dummy_shorthand = NULL;
1278 shorthand = &dummy_shorthand;
1283 &parsed_key, &
value);
1299 key = *(shorthand++);
1348 int opt_flags,
int search_flags)
1350 return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL);
1354 int opt_flags,
int search_flags,
void **target_obj)
1371 if (o =
av_opt_find2(&child, name, unit, opt_flags, search_flags, NULL))
1376 if (o =
av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
1382 if (!strcmp(o->
name, name) && (o->
flags & opt_flags) == opt_flags &&
1425 if (c->
version > (52 << 16 | 11 << 8))
1431 return callback(ranges_arg, obj, key, flags);
1444 if (!ranges || !range || !range_array || !field) {
1449 ranges->
range = range_array;
1450 ranges->
range[0] = range;
1456 switch (field->
type) {
1494 *ranges_arg = ranges;
1508 for (i = 0; i < ranges->
nb_ranges; i++) {
1519 typedef struct TestContext
1533 int64_t channel_layout;
1536 #define OFFSET(x) offsetof(TestContext, x)
1538 #define TEST_FLAG_COOL 01
1539 #define TEST_FLAG_LAME 02
1540 #define TEST_FLAG_MU 04
1542 static const AVOption test_options[]= {
1548 {
"cool",
"set cool flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_COOL}, INT_MIN, INT_MAX, 0,
"flags" },
1549 {
"lame",
"set lame flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_LAME}, INT_MIN, INT_MAX, 0,
"flags" },
1550 {
"mu",
"set mu flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_MU}, INT_MIN, INT_MAX, 0,
"flags" },
1561 static const char *test_get_name(
void *ctx)
1566 static const AVClass test_class = {
1576 printf(
"\nTesting av_set_options_string()\n");
1578 TestContext test_ctx = { 0 };
1579 static const char *
const options[] = {
1595 "flags=+mu-lame : num=42: toggle=0",
1596 "num=42 : string=blahblah",
1597 "rational=0 : rational=1/2 : rational=1/-1",
1610 "video_rate=30000/1001",
1611 "video_rate=30/1.001",
1615 "duration=1\\:23\\:45.67",
1619 "cl=stereo+downmix",
1623 test_ctx.class = &test_class;
1637 printf(
"\nTesting av_opt_set_from_string()\n");
1639 TestContext test_ctx = { 0 };
1640 static const char *
const options[] = {
1648 " 5 : hello : size = pal ",
1649 "a_very_long_option_name_that_will_need_to_be_ellipsized_around_here=42"
1651 static const char *
const shorthand[] = {
"num",
"string", NULL };
1653 test_ctx.class = &test_class;