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);
127 if (a < 0 || b < 0) {
131 *ptr++ = (a << 4) | b;
146 #define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \ 147 opt->type == AV_OPT_TYPE_CONST || \ 148 opt->type == AV_OPT_TYPE_FLAGS || \ 149 opt->type == AV_OPT_TYPE_INT) ? \ 150 opt->default_val.i64 : opt->default_val.dbl) 154 int ret = 0, notfirst = 0;
163 if (*val ==
'+' || *val ==
'-') {
170 for (; i <
sizeof(buf) - 1 && val[i] && val[i] !=
'+' && val[i] !=
'-'; i++)
179 else if (!strcmp(buf,
"max" )) d = o->
max;
180 else if (!strcmp(buf,
"min" )) d = o->
min;
181 else if (!strcmp(buf,
"none" )) d = 0;
182 else if (!strcmp(buf,
"all" )) d = ~0;
184 int res =
av_expr_parse_and_eval(&d, buf,
const_names,
const_values,
NULL,
NULL,
NULL,
NULL,
NULL, 0, obj);
193 if (cmd ==
'+') d = intnum | (int64_t)d;
194 else if (cmd ==
'-') d = intnum &~(int64_t)d;
197 if (cmd ==
'+') d = notfirst*num*intnum/den + d;
198 else if (cmd ==
'-') d = notfirst*num*intnum/den - d;
214 void *dst, *target_obj;
216 if (!o || !target_obj)
237 #define OPT_EVAL_NUMBER(name, opttype, vartype)\ 238 int av_opt_eval_ ## name(void *obj, const AVOption *o, const char *val, vartype *name ## _out)\ 240 if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY)\ 241 return AVERROR(EINVAL);\ 242 return set_string_number(obj, obj, o, val, name ## _out);\ 252 static
int set_number(
void *obj, const
char *
name,
double num,
int den, int64_t intnum,
255 void *dst, *target_obj;
258 if (!o || !target_obj)
270 return set_number(obj, name, 1, 1, val, search_flags);
275 return set_number(obj, name, val, 1, 1, search_flags);
291 if (!o || !target_obj)
302 lendst = (
int *)(dst + 1);
307 memcpy(ptr, val, len);
318 if (!o || !target_obj)
332 void *dst, *target_obj;
337 if (!o || !target_obj)
344 case AV_OPT_TYPE_FLAGS: ret = snprintf(buf,
sizeof(buf),
"0x%08X", *(
int *)dst);
break;
345 case AV_OPT_TYPE_INT: ret = snprintf(buf,
sizeof(buf),
"%d" , *(
int *)dst);
break;
346 case AV_OPT_TYPE_INT64: ret = snprintf(buf,
sizeof(buf),
"%"PRId64, *(int64_t*)dst);
break;
347 case AV_OPT_TYPE_FLOAT: ret = snprintf(buf,
sizeof(buf),
"%f" , *(
float *)dst);
break;
348 case AV_OPT_TYPE_DOUBLE: ret = snprintf(buf,
sizeof(buf),
"%f" , *(
double *)dst);
break;
358 if ((uint64_t)len*2 + 1 > INT_MAX)
363 for (i = 0; i <
len; i++)
364 snprintf(*out_val + i*2, 3,
"%02X", bin[i]);
370 if (ret >=
sizeof(buf))
376 static int get_number(
void *obj,
const char *
name,
double *num,
int *den, int64_t *intnum,
379 void *dst, *target_obj;
381 if (!o || !target_obj)
399 if ((ret =
get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
401 *out_val = num*intnum/den;
411 if ((ret =
get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
413 *out_val = num*intnum/den;
423 if ((ret =
get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
426 if (num == 1.0 && (
int)intnum == intnum)
429 *out_val =
av_d2q(num*intnum/den, 1<<24);
439 if (!o || !target_obj)
463 static void opt_list(
void *obj,
void *av_log_obj,
const char *unit,
464 int req_flags,
int rej_flags)
469 if (!(opt->
flags & req_flags) || (opt->
flags & rej_flags))
529 opt_list(obj, av_log_obj, opt->
unit, req_flags, rej_flags);
534 int av_opt_show2(
void *obj,
void *av_log_obj,
int req_flags,
int rej_flags)
606 const char *key_val_sep,
const char *pairs_sep)
615 if (*key && strspn(*buf, key_val_sep)) {
623 av_log(ctx,
AV_LOG_ERROR,
"Missing key or no key/value separator found after key '%s'\n", key);
640 const char *key_val_sep,
const char *pairs_sep)
701 int opt_flags,
int search_flags)
707 int opt_flags,
int search_flags,
void **target_obj)
724 if (o =
av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
730 if (!strcmp(o->
name, name) && (o->
flags & opt_flags) == opt_flags &&
732 (unit && o->
unit && !strcmp(o->
unit, unit)))) {
762 typedef struct TestContext
772 #define OFFSET(x) offsetof(TestContext, x) 774 #define TEST_FLAG_COOL 01 775 #define TEST_FLAG_LAME 02 776 #define TEST_FLAG_MU 04 778 static const AVOption test_options[]= {
784 {
"cool",
"set cool flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_COOL}, INT_MIN, INT_MAX, 0,
"flags" },
785 {
"lame",
"set lame flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_LAME}, INT_MIN, INT_MAX, 0,
"flags" },
786 {
"mu",
"set mu flag ", 0,
AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_MU}, INT_MIN, INT_MAX, 0,
"flags" },
790 static const char *test_get_name(
void *ctx)
795 static const AVClass test_class = {
805 printf(
"\nTesting av_set_options_string()\n");
807 TestContext test_ctx;
824 "flags=+mu-lame : num=42: toggle=0",
825 "num=42 : string=blahblah",
826 "rational=0 : rational=1/2 : rational=1/-1",
830 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 ...
union AVOption::@131 default_val
the default value for scalar options
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[]
void *(* child_next)(void *obj, void *prev)
Return next AVOptions-enabled child or NULL.
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)
#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)
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)