40 if (!last &&
class->option &&
class->option[0].name)
42 if (last && last[1].
name)
65 (o->
max * den < num * intnum || o->
min * den > num * intnum)) {
67 num*intnum/den, o->
name);
102 if (c >=
'0' && c <=
'9')
return c -
'0';
103 if (c >=
'a' && c <=
'f')
return c -
'a' + 10;
104 if (c >=
'A' && c <=
'F')
return c -
'A' + 10;
110 int *lendst = (
int *)(dst + 1);
112 int len = strlen(val);
125 if (a < 0 || b < 0) {
129 *ptr++ = (a << 4) | b;
144 #define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \
145 opt->type == AV_OPT_TYPE_CONST || \
146 opt->type == AV_OPT_TYPE_FLAGS || \
147 opt->type == AV_OPT_TYPE_INT) ? \
148 opt->default_val.i64 : opt->default_val.dbl)
152 int ret = 0, notfirst = 0;
161 if (*val ==
'+' || *val ==
'-') {
168 for (; i <
sizeof(buf) - 1 && val[i] && val[i] !=
'+' && val[i] !=
'-'; i++)
177 else if (!strcmp(buf,
"max" )) d = o->
max;
178 else if (!strcmp(buf,
"min" )) d = o->
min;
179 else if (!strcmp(buf,
"none" )) d = 0;
180 else if (!strcmp(buf,
"all" )) d = ~0;
182 int res =
av_expr_parse_and_eval(&d, buf,
const_names,
const_values,
NULL,
NULL,
NULL,
NULL,
NULL, 0, obj);
191 if (cmd ==
'+') d = intnum | (int64_t)d;
192 else if (cmd ==
'-') d = intnum &~(int64_t)d;
195 if (cmd ==
'+') d = notfirst*num*intnum/den + d;
196 else if (cmd ==
'-') d = notfirst*num*intnum/den - d;
212 void *dst, *target_obj;
214 if (!o || !target_obj)
235 #define OPT_EVAL_NUMBER(name, opttype, vartype)\
236 int av_opt_eval_ ## name(void *obj, const AVOption *o, const char *val, vartype *name ## _out)\
238 if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY)\
239 return AVERROR(EINVAL);\
240 return set_string_number(obj, obj, o, val, name ## _out);\
250 static
int set_number(
void *obj, const
char *
name,
double num,
int den, int64_t intnum,
253 void *dst, *target_obj;
256 if (!o || !target_obj)
268 return set_number(obj, name, 1, 1, val, search_flags);
273 return set_number(obj, name, val, 1, 1, search_flags);
289 if (!o || !target_obj)
300 lendst = (
int *)(dst + 1);
305 memcpy(ptr, val, len);
316 if (!o || !target_obj)
330 void *dst, *target_obj;
335 if (!o || !target_obj)
342 case AV_OPT_TYPE_FLAGS: ret = snprintf(buf,
sizeof(buf),
"0x%08X", *(
int *)dst);
break;
343 case AV_OPT_TYPE_INT: ret = snprintf(buf,
sizeof(buf),
"%d" , *(
int *)dst);
break;
344 case AV_OPT_TYPE_INT64: ret = snprintf(buf,
sizeof(buf),
"%"PRId64, *(int64_t*)dst);
break;
345 case AV_OPT_TYPE_FLOAT: ret = snprintf(buf,
sizeof(buf),
"%f" , *(
float *)dst);
break;
346 case AV_OPT_TYPE_DOUBLE: ret = snprintf(buf,
sizeof(buf),
"%f" , *(
double *)dst);
break;
356 if ((uint64_t)len*2 + 1 > INT_MAX)
361 for (i = 0; i <
len; i++)
362 snprintf(*out_val + i*2, 3,
"%02X", bin[i]);
368 if (ret >=
sizeof(buf))
374 static int get_number(
void *obj,
const char *
name,
double *num,
int *den, int64_t *intnum,
377 void *dst, *target_obj;
379 if (!o || !target_obj)
397 if ((ret =
get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
399 *out_val = num*intnum/den;
409 if ((ret =
get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
411 *out_val = num*intnum/den;
421 if ((ret =
get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
424 if (num == 1.0 && (
int)intnum == intnum)
427 *out_val =
av_d2q(num*intnum/den, 1<<24);
437 if (!o || !target_obj)
461 static void opt_list(
void *obj,
void *av_log_obj,
const char *unit,
462 int req_flags,
int rej_flags)
467 if (!(opt->
flags & req_flags) || (opt->
flags & rej_flags))
527 opt_list(obj, av_log_obj, opt->
unit, req_flags, rej_flags);
532 int av_opt_show2(
void *obj,
void *av_log_obj,
int req_flags,
int rej_flags)
604 const char *key_val_sep,
const char *pairs_sep)
613 if (*key && strspn(*buf, key_val_sep)) {
621 av_log(ctx,
AV_LOG_ERROR,
"Missing key or no key/value separator found after key '%s'\n", key);
638 const char *key_val_sep,
const char *pairs_sep)
699 int opt_flags,
int search_flags)
705 int opt_flags,
int search_flags,
void **target_obj)
722 if (o =
av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
728 if (!strcmp(o->
name, name) && (o->
flags & opt_flags) == opt_flags &&
730 (unit && o->
unit && !strcmp(o->
unit, unit)))) {
760 typedef struct TestContext
770 #define OFFSET(x) offsetof(TestContext, x)
772 #define TEST_FLAG_COOL 01
773 #define TEST_FLAG_LAME 02
774 #define TEST_FLAG_MU 04
776 static const AVOption test_options[]= {
782 {
"cool",
"set cool flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_COOL}, INT_MIN, INT_MAX, 0,
"flags" },
783 {
"lame",
"set lame flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_LAME}, INT_MIN, INT_MAX, 0,
"flags" },
784 {
"mu",
"set mu flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_MU}, INT_MIN, INT_MAX, 0,
"flags" },
788 static const char *test_get_name(
void *ctx)
793 static const AVClass test_class = {
803 printf(
"\nTesting av_set_options_string()\n");
805 TestContext test_ctx;
822 "flags=+mu-lame : num=42: toggle=0",
823 "num=42 : string=blahblah",
824 "rational=0 : rational=1/2 : rational=1/-1",
828 test_ctx.class = &test_class;
static int read_number(const AVOption *o, void *dst, double *num, int *den, int64_t *intnum)
int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
#define AV_OPT_FLAG_EXPORT
The option is inteded for exporting values to the caller.
#define AV_OPT_FLAG_SUBTITLE_PARAM
void * av_opt_child_next(void *obj, void *prev)
Iterate over AVOptions-enabled children of obj.
void av_log_set_level(int level)
Set the log level.
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_AUDIO_PARAM
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.
int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
#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)
int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, int search_flags)
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 struct AVOption * option
a pointer to the first option specified in the class if any or NULL
int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
static const double const_values[]
void av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
const OptionDef options[]
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.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
double max
maximum valid value for the option
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
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)
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)
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_number(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst)
const struct AVClass *(* child_class_next)(const struct AVClass *prev)
Return an AVClass corresponding to the 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)
#define AV_LOG_INFO
Standard information.
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.
#define AV_OPT_FLAG_VIDEO_PARAM
#define OPT_EVAL_NUMBER(name, opttype, vartype)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Describe the class of an AVClass context structure.
rational number numerator/denominator
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
void av_opt_free(void *obj)
Free all allocated objects in obj.
common internal and external API header
#define DEFAULT_NUMVAL(opt)
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)
union AVOption::@130 default_val
the default value for scalar options
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 AV_OPT_FLAG_READONLY
The option may not be set through the AVOptions API, only read.
#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.
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
simple arithmetic expression evaluator
static int get_number(void *obj, const char *name, double *num, int *den, int64_t *intnum, int search_flags)