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 &&
class->option &&
class->option[0].name)
68 if (last && last[1].
name)
94 if (o->
max*den < num*intnum || o->
min*den > num*intnum) {
134 if (c >=
'0' && c <=
'9')
return c -
'0';
135 if (c >=
'a' && c <=
'f')
return c -
'a' + 10;
136 if (c >=
'A' && c <=
'F')
return c -
'A' + 10;
142 int *lendst = (
int *)(dst + 1);
144 int len = strlen(val);
157 if (a < 0 || b < 0) {
161 *ptr++ = (a << 4) | b;
176 #define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \
177 opt->type == AV_OPT_TYPE_CONST || \
178 opt->type == AV_OPT_TYPE_FLAGS || \
179 opt->type == AV_OPT_TYPE_INT) ? \
180 opt->default_val.i64 : opt->default_val.dbl)
184 int ret = 0, notfirst = 0;
193 if (*val ==
'+' || *val ==
'-') {
200 for (; i <
sizeof(
buf) - 1 && val[i] && val[i] !=
'+' && val[i] !=
'-'; i++)
209 else if (!strcmp(buf,
"max" )) d = o->
max;
210 else if (!strcmp(buf,
"min" )) d = o->
min;
211 else if (!strcmp(buf,
"none" )) d = 0;
212 else if (!strcmp(buf,
"all" )) d = ~0;
214 int res =
av_expr_parse_and_eval(&d, buf,
const_names,
const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);
223 if (cmd ==
'+') d = intnum | (int64_t)d;
224 else if (cmd ==
'-') d = intnum &~(int64_t)d;
227 if (cmd ==
'+') d = notfirst*num*intnum/den + d;
228 else if (cmd ==
'-') d = notfirst*num*intnum/den - d;
242 #if FF_API_OLD_AVOPTIONS
255 void *dst, *target_obj;
257 if (!o || !target_obj)
276 if (!val || !strcmp(val,
"none")) {
277 *(
int *)dst = *((
int *)dst + 1) = 0;
282 av_log(obj,
AV_LOG_ERROR,
"Unable to parse option value \"%s\" as image size\n", val);
291 av_log(obj,
AV_LOG_ERROR,
"Unable to parse option value \"%s\" as video rate\n", val);
294 if (!val || !strcmp(val,
"none")) {
300 ret = strtol(val, &tail, 0);
302 av_log(obj,
AV_LOG_ERROR,
"Unable to parse option value \"%s\" as pixel format\n", val);
310 if (!val || !strcmp(val,
"none")) {
316 ret = strtol(val, &tail, 0);
318 av_log(obj,
AV_LOG_ERROR,
"Unable to parse option value \"%s\" as sample format\n", val);
350 #define OPT_EVAL_NUMBER(name, opttype, vartype)\
351 int av_opt_eval_ ## name(void *obj, const AVOption *o, const char *val, vartype *name ## _out)\
353 if (!o || o->type != opttype)\
354 return AVERROR(EINVAL);\
355 return set_string_number(obj, obj, o, val, name ## _out);\
365 static
int set_number(
void *obj, const
char *
name,
double num,
int den, int64_t intnum,
368 void *dst, *target_obj;
371 if (!o || !target_obj)
378 #if FF_API_OLD_AVOPTIONS
406 return set_number(obj, name, 1, 1, val, search_flags);
411 return set_number(obj, name, val, 1, 1, search_flags);
427 if (!o || !target_obj)
438 lendst = (
int *)(dst + 1);
444 memcpy(ptr, val, len);
454 if (!o || !target_obj)
458 "The value set by option '%s' is not an image size.\n", o->
name);
463 "Invalid negative size value %dx%d for size '%s'\n", w, h, o->
name);
467 *(
int *)(((
uint8_t *)target_obj+
sizeof(int)) + o->
offset) = h;
476 if (!o || !target_obj)
480 "The value set by option '%s' is not a video rate.\n", o->
name);
483 if (val.
num <= 0 || val.
den <= 0)
493 search_flags, &target_obj);
497 if (!o || !target_obj)
499 if (o->
type != type) {
501 "The value set by option '%s' is not a %s format", name, desc);
505 #if LIBAVUTIL_VERSION_MAJOR < 53
515 if (fmt < min || fmt > max) {
517 "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
518 fmt, name, desc, min, max);
535 #if FF_API_OLD_AVOPTIONS
553 if (o_out) *o_out= o;
566 if (len >= (buf_len + 1)/2)
return NULL;
568 for (i = 0; i <
len; i++)
snprintf(buf + i*2, 3,
"%02X", bin[i]);
570 default:
return NULL;
578 void *dst, *target_obj;
607 if ((uint64_t)len*2 + 1 > INT_MAX)
612 for (i = 0; i <
len; i++)
613 snprintf(*out_val + i*2, 3,
"%02X", bin[i]);
616 ret =
snprintf(buf,
sizeof(buf),
"%dx%d", ((
int *)dst)[0], ((
int *)dst)[1]);
625 i64 = *(int64_t *)dst;
626 ret =
snprintf(buf,
sizeof(buf),
"%"PRIi64
"d:%02d:%02d.%06d",
627 i64 / 3600000000, (
int)((i64 / 60000000) % 60),
628 (
int)((i64 / 1000000) % 60), (
int)(i64 % 1000000));
631 ret =
snprintf(buf,
sizeof(buf),
"0x%02x%02x%02x%02x", ((
int *)dst)[0], ((
int *)dst)[1], ((
int *)dst)[2], ((
int *)dst)[3]);
637 if (ret >=
sizeof(buf))
646 void *dst, *target_obj;
648 if (!o || !target_obj)
653 if (o_out) *o_out= o;
662 #if FF_API_OLD_AVOPTIONS
669 if (
get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
671 return num*intnum/den;
680 if (
get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
682 if (num == 1.0 && (
int)intnum == intnum)
685 return av_d2q(num*intnum/den, 1<<24);
694 if (
get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
696 return num*intnum/den;
706 if ((ret =
get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
708 *out_val = num*intnum/den;
718 if ((ret =
get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
720 *out_val = num*intnum/den;
730 if ((ret =
get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
733 if (num == 1.0 && (
int)intnum == intnum)
736 *out_val =
av_d2q(num*intnum/den, 1<<24);
742 void *dst, *target_obj;
744 if (!o || !target_obj)
748 "The value for option '%s' is not an image size.\n", name);
753 if (w_out) *w_out = *(
int *)dst;
754 if (h_out) *h_out = *((
int *)dst+1);
764 if ((ret =
get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
767 if (num == 1.0 && (
int)intnum == intnum)
770 *out_val =
av_d2q(num*intnum/den, 1<<24);
774 static int get_format(
void *obj,
const char *
name,
int search_flags,
int *out_fmt,
777 void *dst, *target_obj;
779 if (!o || !target_obj)
781 if (o->
type != type) {
783 "The value for option '%s' is not a %s format.\n", desc, name);
788 *out_fmt = *(
int *)dst;
806 field ? field->
unit : NULL, 0, 0);
818 av_log(av_log_obj, level,
"INT_MAX");
819 }
else if (d == INT_MIN) {
820 av_log(av_log_obj, level,
"INT_MIN");
821 }
else if (d == (
double)INT64_MAX) {
822 av_log(av_log_obj, level,
"I64_MAX");
823 }
else if (d == INT64_MIN) {
824 av_log(av_log_obj, level,
"I64_MIN");
825 }
else if (d == FLT_MAX) {
826 av_log(av_log_obj, level,
"FLT_MAX");
827 }
else if (d == FLT_MIN) {
828 av_log(av_log_obj, level,
"FLT_MIN");
830 av_log(av_log_obj, level,
"%g", d);
834 static void opt_list(
void *obj,
void *av_log_obj,
const char *unit,
835 int req_flags,
int rej_flags)
842 if (!(opt->
flags & req_flags) || (opt->
flags & rej_flags))
975 opt_list(obj, av_log_obj, opt->
unit, req_flags, rej_flags);
980 int av_opt_show2(
void *obj,
void *av_log_obj,
int req_flags,
int rej_flags)
987 opt_list(obj, av_log_obj, NULL, req_flags, rej_flags);
994 #if FF_API_OLD_AVOPTIONS
1004 #if FF_API_OLD_AVOPTIONS
1008 switch (opt->
type) {
1038 #if LIBAVUTIL_VERSION_MAJOR < 53
1046 #if LIBAVUTIL_VERSION_MAJOR < 53
1080 const char *key_val_sep,
const char *pairs_sep)
1089 if (*key && strspn(*buf, key_val_sep)) {
1097 av_log(ctx,
AV_LOG_ERROR,
"Missing key or no key/value separator found after key '%s'\n", key);
1114 const char *key_val_sep,
const char *pairs_sep)
1133 #define WHITESPACES " \n\t"
1137 return (
unsigned)((c | 32) -
'a') < 26 ||
1138 (unsigned)(c -
'0') < 10 ||
1139 c ==
'-' || c ==
'_' || c ==
'/' || c ==
'.';
1150 static int get_key(
const char **ropts,
const char *delim,
char **rkey)
1152 const char *opts = *ropts;
1153 const char *key_start, *key_end;
1160 if (!*opts || !strchr(delim, *opts))
1163 if (!(*rkey =
av_malloc(key_end - key_start + 1)))
1165 memcpy(*rkey, key_start, key_end - key_start);
1166 (*rkey)[key_end - key_start] = 0;
1172 const char *key_val_sep,
const char *pairs_sep,
1174 char **rkey,
char **rval)
1177 char *key = NULL, *
val;
1178 const char *opts = *ropts;
1180 if ((ret =
get_key(&opts, key_val_sep, &key)) < 0 &&
1194 const char *
const *shorthand,
1195 const char *key_val_sep,
const char *pairs_sep)
1198 const char *dummy_shorthand = NULL;
1205 shorthand = &dummy_shorthand;
1210 &parsed_key, &
value);
1226 key = *(shorthand++);
1275 int opt_flags,
int search_flags)
1277 return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL);
1281 int opt_flags,
int search_flags,
void **target_obj)
1295 if (o =
av_opt_find2(&child, name, unit, opt_flags, search_flags, NULL))
1300 if (o =
av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
1306 if (!strcmp(o->
name, name) && (o->
flags & opt_flags) == opt_flags &&
1349 if (c->
version > (52 << 16 | 11 << 8))
1355 return callback(ranges_arg, obj, key, flags);
1368 if (!ranges || !range || !range_array || !field) {
1373 ranges->
range = range_array;
1374 ranges->
range[0] = range;
1380 switch (field->
type) {
1417 *ranges_arg = ranges;
1431 for (i = 0; i < ranges->
nb_ranges; i++) {
1442 typedef struct TestContext
1458 #define OFFSET(x) offsetof(TestContext, x)
1460 #define TEST_FLAG_COOL 01
1461 #define TEST_FLAG_LAME 02
1462 #define TEST_FLAG_MU 04
1464 static const AVOption test_options[]= {
1470 {
"cool",
"set cool flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_COOL}, INT_MIN, INT_MAX, 0,
"flags" },
1471 {
"lame",
"set lame flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_LAME}, INT_MIN, INT_MAX, 0,
"flags" },
1472 {
"mu",
"set mu flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_MU}, INT_MIN, INT_MAX, 0,
"flags" },
1482 static const char *test_get_name(
void *ctx)
1487 static const AVClass test_class = {
1497 printf(
"\nTesting av_set_options_string()\n");
1499 TestContext test_ctx = { 0 };
1516 "flags=+mu-lame : num=42: toggle=0",
1517 "num=42 : string=blahblah",
1518 "rational=0 : rational=1/2 : rational=1/-1",
1531 "video_rate=30000/1001",
1532 "video_rate=30/1.001",
1536 "duration=1\\:23\\:45.67",
1542 test_ctx.class = &test_class;
1556 printf(
"\nTesting av_opt_set_from_string()\n");
1558 TestContext test_ctx = { 0 };
1559 const char *options[] = {
1567 " 5 : hello : size = pal ",
1568 "a_very_long_option_name_that_will_need_to_be_ellipsized_around_here=42"
1570 const char *shorthand[] = {
"num",
"string", NULL };
1572 test_ctx.class = &test_class;