42 for (; o && o->
name; o++) {
43 if (!strcmp(o->
name, name) && (!unit || (o->
unit && !strcmp(o->
unit, unit))) && (o->
flags &
mask) == flags)
50 #if FF_API_OLD_AVOPTIONS
60 if (!last && class->option && class->option[0].
name)
62 if (last && last[1].
name)
84 if (o->
max*den < num*intnum || o->
min*den > num*intnum) {
120 if (c >=
'0' && c <=
'9')
return c -
'0';
121 if (c >=
'a' && c <=
'f')
return c -
'a' + 10;
122 if (c >=
'A' && c <=
'F')
return c -
'A' + 10;
128 int *lendst = (
int *)(dst + 1);
130 int len = strlen(val);
143 if (a < 0 || b < 0) {
147 *ptr++ = (a << 4) | b;
164 int ret = 0, notfirst = 0;
172 if (*val ==
'+' || *val ==
'-')
175 for (i = 0; i <
sizeof(buf) - 1 && val[i] && val[i] !=
'+' && val[i] !=
'-'; i++)
184 else if (!strcmp(buf,
"max" )) d = o->
max;
185 else if (!strcmp(buf,
"min" )) d = o->
min;
186 else if (!strcmp(buf,
"none" )) d = 0;
187 else if (!strcmp(buf,
"all" )) d = ~0;
189 int res =
av_expr_parse_and_eval(&d, buf,
const_names,
const_values,
NULL,
NULL,
NULL,
NULL,
NULL, 0, obj);
198 if (cmd ==
'+') d = intnum | (int64_t)d;
199 else if (cmd ==
'-') d = intnum &~(int64_t)d;
202 if (cmd ==
'+') d = notfirst*num*intnum/den + d;
203 else if (cmd ==
'-') d = notfirst*num*intnum/den - d;
217 #if FF_API_OLD_AVOPTIONS
229 void *dst, *target_obj;
231 if (!o || !target_obj)
236 dst = ((uint8_t*)target_obj) + o->
offset;
252 #define OPT_EVAL_NUMBER(name, opttype, vartype)\
253 int av_opt_eval_ ## name(void *obj, const AVOption *o, const char *val, vartype *name ## _out)\
255 if (!o || o->type != opttype)\
256 return AVERROR(EINVAL);\
257 return set_string_number(obj, o, val, name ## _out);\
267 static
int set_number(
void *obj, const
char *
name,
double num,
int den, int64_t intnum,
270 void *dst, *target_obj;
273 if (!o || !target_obj)
276 dst = ((uint8_t*)target_obj) + o->
offset;
280 #if FF_API_OLD_AVOPTIONS
308 return set_number(obj, name, 1, 1, val, search_flags);
313 return set_number(obj, name, val, 1, 1, search_flags);
321 #if FF_API_OLD_AVOPTIONS
338 dst= ((uint8_t*)obj) + o->
offset;
339 if (o_out) *o_out= o;
343 case AV_OPT_TYPE_INT: snprintf(buf, buf_len,
"%d" , *(
int *)dst);
break;
350 len = *(
int*)(((uint8_t *)dst) +
sizeof(uint8_t *));
351 if (len >= (buf_len + 1)/2)
return NULL;
352 bin = *(uint8_t**)dst;
353 for (i = 0; i <
len; i++) snprintf(buf + i*2, 3,
"%02X", bin[i]);
355 default:
return NULL;
363 void *dst, *target_obj;
365 uint8_t *bin, buf[128];
368 if (!o || !target_obj)
371 dst = (uint8_t*)target_obj + o->
offset;
375 case AV_OPT_TYPE_FLAGS: ret = snprintf(buf,
sizeof(buf),
"0x%08X", *(
int *)dst);
break;
376 case AV_OPT_TYPE_INT: ret = snprintf(buf,
sizeof(buf),
"%d" , *(
int *)dst);
break;
377 case AV_OPT_TYPE_INT64: ret = snprintf(buf,
sizeof(buf),
"%"PRId64, *(int64_t*)dst);
break;
378 case AV_OPT_TYPE_FLOAT: ret = snprintf(buf,
sizeof(buf),
"%f" , *(
float *)dst);
break;
379 case AV_OPT_TYPE_DOUBLE: ret = snprintf(buf,
sizeof(buf),
"%f" , *(
double *)dst);
break;
388 len = *(
int*)(((uint8_t *)dst) +
sizeof(uint8_t *));
389 if ((uint64_t)len*2 + 1 > INT_MAX)
393 bin = *(uint8_t**)dst;
394 for (i = 0; i <
len; i++)
395 snprintf(*out_val + i*2, 3,
"%02X", bin[i]);
401 if (ret >=
sizeof(buf))
410 void *dst, *target_obj;
412 if (!o || !target_obj)
415 dst = ((uint8_t*)target_obj) + o->
offset;
417 if (o_out) *o_out= o;
426 #if FF_API_OLD_AVOPTIONS
433 if (
get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
435 return num*intnum/den;
444 if (
get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
446 if (num == 1.0 && (
int)intnum == intnum)
449 return av_d2q(num*intnum/den, 1<<24);
458 if (
get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
460 return num*intnum/den;
470 if ((ret =
get_number(obj, name,
NULL, &num, &den, &intnum, search_flags)) < 0)
472 *out_val = num*intnum/den;
482 if ((ret =
get_number(obj, name,
NULL, &num, &den, &intnum, search_flags)) < 0)
484 *out_val = num*intnum/den;
494 if ((ret =
get_number(obj, name,
NULL, &num, &den, &intnum, search_flags)) < 0)
497 if (num == 1.0 && (
int)intnum == intnum)
500 *out_val =
av_d2q(num*intnum/den, 1<<24);
517 static void opt_list(
void *obj,
void *av_log_obj,
const char *unit,
518 int req_flags,
int rej_flags)
523 if (!(opt->
flags & req_flags) || (opt->
flags & rej_flags))
581 opt_list(obj, av_log_obj, opt->
unit, req_flags, rej_flags);
586 int av_opt_show2(
void *obj,
void *av_log_obj,
int req_flags,
int rej_flags)
600 #if FF_API_OLD_AVOPTIONS
609 #if FF_API_OLD_AVOPTIONS
610 if ((opt->
flags & mask) != flags)
672 const char *key_val_sep,
const char *pairs_sep)
678 if (*key && strspn(*buf, key_val_sep)) {
682 av_log(ctx,
AV_LOG_ERROR,
"Missing key or no key/value separator found after key '%s'\n", key);
699 const char *key_val_sep,
const char *pairs_sep)
748 int opt_flags,
int search_flags)
754 int opt_flags,
int search_flags,
void **target_obj)
768 if (o =
av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
774 if (!strcmp(o->
name, name) && (o->
flags & opt_flags) == opt_flags &&
776 (unit && o->
unit && !strcmp(o->
unit, unit)))) {
808 typedef struct TestContext
818 #define OFFSET(x) offsetof(TestContext, x)
820 #define TEST_FLAG_COOL 01
821 #define TEST_FLAG_LAME 02
822 #define TEST_FLAG_MU 04
824 static const AVOption test_options[]= {
830 {
"cool",
"set cool flag ", 0,
AV_OPT_TYPE_CONST, {TEST_FLAG_COOL}, INT_MIN, INT_MAX, 0,
"flags" },
831 {
"lame",
"set lame flag ", 0,
AV_OPT_TYPE_CONST, {TEST_FLAG_LAME}, INT_MIN, INT_MAX, 0,
"flags" },
832 {
"mu",
"set mu flag ", 0,
AV_OPT_TYPE_CONST, {TEST_FLAG_MU}, INT_MIN, INT_MAX, 0,
"flags" },
836 static const char *test_get_name(
void *ctx)
841 static const AVClass test_class = {
851 printf(
"\nTesting av_set_options_string()\n");
853 TestContext test_ctx;
870 "flags=+mu-lame : num=42: toggle=0",
871 "num=42 : string=blahblah",
872 "rational=0 : rational=1/2 : rational=1/-1",
876 test_ctx.class = &test_class;
static int read_number(const AVOption *o, void *dst, double *num, int *den, int64_t *intnum)
#define AV_OPT_FLAG_VIDEO_PARAM
const AVOption * av_set_int(void *obj, const char *name, int64_t n)
int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
#define AV_OPT_FLAG_AUDIO_PARAM
void * av_opt_child_next(void *obj, void *prev)
Iterate over AVOptions-enabled children of obj.
const AVClass * av_opt_child_class_next(const AVClass *parent, const AVClass *prev)
Iterate over potential AVOptions-enabled children of parent.
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
int av_set_options_string(void *ctx, const char *opts, const char *key_val_sep, const char *pairs_sep)
Parse the key/value pairs list in opts.
#define FF_ARRAY_ELEMS(a)
int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
static void opt_list(void *obj, void *av_log_obj, const char *unit, int req_flags, int rej_flags)
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
const char * av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const char * help
short English help text
const AVOption * av_next_option(void *obj, const AVOption *last)
const struct AVOption * option
a pointer to the first option specified in the class if any or NULL
const AVOption * av_set_double(void *obj, const char *name, double n)
union AVOption::@97 default_val
the default value for scalar options
int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
AVRational av_get_q(void *obj, const char *name, const AVOption **o_out)
static const double const_values[]
static int get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum, int search_flags)
static int hexchar2int(char c)
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
static const uint16_t mask[17]
double max
maximum valid value for the option
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
const AVOption * av_opt_next(void *obj, const AVOption *last)
Iterate over all AVOptions belonging to obj.
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
void av_log(void *avcl, int level, const char *fmt,...)
int main(int argc, char **argv)
void av_log_set_level(int level)
char * av_get_token(const char **buf, const char *term)
Unescape the given string until a non escaped terminating char, and return the token corresponding to...
static const char *const const_names[]
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **dst)
struct AVRational AVRational
rational number numerator/denominator
const AVOption * av_find_opt(void *v, const char *name, const char *unit, int mask, int flags)
Look for an option in obj.
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
const char * unit
The logical unit to which the option belongs.
static int parse_key_value_pair(void *ctx, const char **buf, const char *key_val_sep, const char *pairs_sep)
Store the value in the field in ctx that is named like key.
double min
minimum valid value for the option
static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst)
double av_get_double(void *obj, const char *name, const AVOption **o_out)
const AVOption * av_set_q(void *obj, const char *name, AVRational n)
const struct AVClass *(* child_class_next)(const struct AVClass *prev)
Return an AVClass corresponding to next potential AVOptions-enabled child.
offset must point to a pointer immediately followed by an int for the length
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
int offset
The offset relative to the context structure where the option value is stored.
int av_opt_set_dict(void *obj, AVDictionary **options)
char * av_strdup(const char *s)
Duplicate the string s.
static int set_number(void *obj, const char *name, double num, int den, int64_t intnum, int search_flags)
int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
Show the obj options.
static const OptionDef options[]
#define AV_OPT_FLAG_SUBTITLE_PARAM
int64_t av_get_int(void *obj, const char *name, const AVOption **o_out)
#define OPT_EVAL_NUMBER(name, opttype, vartype)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Describe the class of an AVClass context structure.
rational number numerator/denominator
void av_opt_free(void *obj)
Free all string and binary options in obj.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
void *(* child_next)(void *obj, void *prev)
Return next AVOptions-enabled child or NULL.
#define AV_OPT_SEARCH_FAKE_OBJ
The obj passed to av_opt_find() is fake – only a double pointer to AVClass instead of a required poi...
static int write_number(void *obj, const AVOption *o, void *dst, double num, int den, int64_t intnum)
static int set_string_number(void *obj, const AVOption *o, const char *val, void *dst)
int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out)
Set the field of obj with the given name to value.
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
#define AVERROR_OPTION_NOT_FOUND
Option not found.
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
Check whether a particular flag is set in a flags field.
#define AV_DICT_IGNORE_SUFFIX
const AVOption * av_opt_find2(void *obj, const char *name, const char *unit, int opt_flags, int search_flags, void **target_obj)
Look for an option in an object.
void av_opt_set_defaults2(void *s, int mask, int flags)
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
simple arithmetic expression evaluator