You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
AVOptions: add av_opt_set*().
Deprecate av_set_* New functions support setting values on children, return error codes instead of options and have consistent naming and signatures.
This commit is contained in:
@@ -186,18 +186,26 @@ static int set_string_number(void *obj, const AVOption *o, const char *val, void
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FF_API_OLD_AVOPTIONS
|
||||||
int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out)
|
int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out)
|
||||||
{
|
{
|
||||||
const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
|
const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
|
||||||
void *dst;
|
|
||||||
if (o_out)
|
if (o_out)
|
||||||
*o_out = o;
|
*o_out = o;
|
||||||
if (!o)
|
return av_opt_set(obj, name, val, 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
|
||||||
|
{
|
||||||
|
void *dst, *target_obj;
|
||||||
|
const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
|
||||||
|
if (!o || !target_obj)
|
||||||
return AVERROR_OPTION_NOT_FOUND;
|
return AVERROR_OPTION_NOT_FOUND;
|
||||||
if (!val)
|
if (!val)
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
|
|
||||||
dst = ((uint8_t*)obj) + o->offset;
|
dst = ((uint8_t*)target_obj) + o->offset;
|
||||||
switch (o->type) {
|
switch (o->type) {
|
||||||
case FF_OPT_TYPE_STRING: return set_string(obj, o, val, dst);
|
case FF_OPT_TYPE_STRING: return set_string(obj, o, val, dst);
|
||||||
case FF_OPT_TYPE_BINARY: return set_string_binary(obj, o, val, dst);
|
case FF_OPT_TYPE_BINARY: return set_string_binary(obj, o, val, dst);
|
||||||
@@ -213,34 +221,58 @@ int av_set_string3(void *obj, const char *name, const char *val, int alloc, cons
|
|||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const AVOption *set_number(void *obj, const char *name, double num, int den, int64_t intnum)
|
static int set_number(void *obj, const char *name, double num, int den, int64_t intnum,
|
||||||
|
int search_flags)
|
||||||
{
|
{
|
||||||
const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
|
void *dst, *target_obj;
|
||||||
void *dst;
|
const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
|
||||||
|
|
||||||
if (!o)
|
if (!o || !target_obj)
|
||||||
return NULL;
|
return AVERROR_OPTION_NOT_FOUND;
|
||||||
|
|
||||||
dst = ((uint8_t*)obj) + o->offset;
|
dst = ((uint8_t*)target_obj) + o->offset;
|
||||||
if (write_number(obj, o, dst, num, den, intnum) < 0)
|
return write_number(obj, o, dst, num, den, intnum);
|
||||||
return NULL;
|
|
||||||
else
|
|
||||||
return o;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FF_API_OLD_AVOPTIONS
|
||||||
const AVOption *av_set_double(void *obj, const char *name, double n)
|
const AVOption *av_set_double(void *obj, const char *name, double n)
|
||||||
{
|
{
|
||||||
return set_number(obj, name, n, 1, 1);
|
const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
|
||||||
|
if (set_number(obj, name, n, 1, 1, 0) < 0)
|
||||||
|
return NULL;
|
||||||
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AVOption *av_set_q(void *obj, const char *name, AVRational n)
|
const AVOption *av_set_q(void *obj, const char *name, AVRational n)
|
||||||
{
|
{
|
||||||
return set_number(obj, name, n.num, n.den, 1);
|
const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
|
||||||
|
if (set_number(obj, name, n.num, n.den, 1, 0) < 0)
|
||||||
|
return NULL;
|
||||||
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AVOption *av_set_int(void *obj, const char *name, int64_t n)
|
const AVOption *av_set_int(void *obj, const char *name, int64_t n)
|
||||||
{
|
{
|
||||||
return set_number(obj, name, 1, 1, n);
|
const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
|
||||||
|
if (set_number(obj, name, 1, 1, n, 0) < 0)
|
||||||
|
return NULL;
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
|
||||||
|
{
|
||||||
|
return set_number(obj, name, 1, 1, val, search_flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
|
||||||
|
{
|
||||||
|
return set_number(obj, name, val, 1, 1, search_flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
|
||||||
|
{
|
||||||
|
return set_number(obj, name, val.num, val.den, 1, search_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -112,6 +112,7 @@ attribute_deprecated
|
|||||||
const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int mask, int flags);
|
const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int mask, int flags);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if FF_API_OLD_AVOPTIONS
|
||||||
/**
|
/**
|
||||||
* Set the field of obj with the given name to value.
|
* Set the field of obj with the given name to value.
|
||||||
*
|
*
|
||||||
@@ -136,12 +137,16 @@ const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int m
|
|||||||
* AVERROR_OPTION_NOT_FOUND if no matching option exists
|
* AVERROR_OPTION_NOT_FOUND if no matching option exists
|
||||||
* AVERROR(ERANGE) if the value is out of range
|
* AVERROR(ERANGE) if the value is out of range
|
||||||
* AVERROR(EINVAL) if the value is not valid
|
* AVERROR(EINVAL) if the value is not valid
|
||||||
|
* @deprecated use av_opt_set()
|
||||||
*/
|
*/
|
||||||
|
attribute_deprecated
|
||||||
int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out);
|
int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out);
|
||||||
|
|
||||||
const AVOption *av_set_double(void *obj, const char *name, double n);
|
attribute_deprecated const AVOption *av_set_double(void *obj, const char *name, double n);
|
||||||
const AVOption *av_set_q(void *obj, const char *name, AVRational n);
|
attribute_deprecated const AVOption *av_set_q(void *obj, const char *name, AVRational n);
|
||||||
const AVOption *av_set_int(void *obj, const char *name, int64_t n);
|
attribute_deprecated const AVOption *av_set_int(void *obj, const char *name, int64_t n);
|
||||||
|
#endif
|
||||||
|
|
||||||
double av_get_double(void *obj, const char *name, const AVOption **o_out);
|
double av_get_double(void *obj, const char *name, const AVOption **o_out);
|
||||||
AVRational av_get_q(void *obj, const char *name, const AVOption **o_out);
|
AVRational av_get_q(void *obj, const char *name, const AVOption **o_out);
|
||||||
int64_t av_get_int(void *obj, const char *name, const AVOption **o_out);
|
int64_t av_get_int(void *obj, const char *name, const AVOption **o_out);
|
||||||
@@ -296,4 +301,38 @@ void *av_opt_child_next(void *obj, void *prev);
|
|||||||
*/
|
*/
|
||||||
const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *prev);
|
const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *prev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup opt_set_funcs Option setting functions
|
||||||
|
* @{
|
||||||
|
* Those functions set the field of obj with the given name to value.
|
||||||
|
*
|
||||||
|
* @param[in] obj A struct whose first element is a pointer to an AVClass.
|
||||||
|
* @param[in] name the name of the field to set
|
||||||
|
* @param[in] val The value to set. In case of av_opt_set() if the field is not
|
||||||
|
* of a string type, then the given string is parsed.
|
||||||
|
* SI postfixes and some named scalars are supported.
|
||||||
|
* If the field is of a numeric type, it has to be a numeric or named
|
||||||
|
* scalar. Behavior with more than one scalar and +- infix operators
|
||||||
|
* is undefined.
|
||||||
|
* If the field is of a flags type, it has to be a sequence of numeric
|
||||||
|
* scalars or named flags separated by '+' or '-'. Prefixing a flag
|
||||||
|
* with '+' causes it to be set without affecting the other flags;
|
||||||
|
* similarly, '-' unsets a flag.
|
||||||
|
* @param search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN
|
||||||
|
* is passed here, then the option may be set on a child of obj.
|
||||||
|
*
|
||||||
|
* @return 0 if the value has been set, or an AVERROR code in case of
|
||||||
|
* error:
|
||||||
|
* AVERROR_OPTION_NOT_FOUND if no matching option exists
|
||||||
|
* AVERROR(ERANGE) if the value is out of range
|
||||||
|
* AVERROR(EINVAL) if the value is not valid
|
||||||
|
*/
|
||||||
|
int av_opt_set (void *obj, const char *name, const char *val, int search_flags);
|
||||||
|
int av_opt_set_int (void *obj, const char *name, int64_t val, int search_flags);
|
||||||
|
int av_opt_set_double(void *obj, const char *name, double val, int search_flags);
|
||||||
|
int av_opt_set_q (void *obj, const char *name, AVRational val, int search_flags);
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
#endif /* AVUTIL_OPT_H */
|
#endif /* AVUTIL_OPT_H */
|
||||||
|
Reference in New Issue
Block a user