aboutsummaryrefslogtreecommitdiff
path: root/libavutil/opt.c
diff options
context:
space:
mode:
authorAnton Khirnov2011-08-23 12:58:49 +0200
committerAnton Khirnov2011-10-10 20:27:31 +0200
commit7bb1807c2dd9623842f1c6d454e7f2892b5bc8d7 (patch)
tree8a1204e2407dec498d6075137d96cba593d41ed6 /libavutil/opt.c
parentcf10095f0b8bb0963dd895d2825a035fcb7e1bb5 (diff)
AVOptions: refactor set_number/write_number
write_number() does the actual writing of the supplied number to destination. Move finding the option and choosing destination address out of it.
Diffstat (limited to 'libavutil/opt.c')
-rw-r--r--libavutil/opt.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/libavutil/opt.c b/libavutil/opt.c
index b3f29a5b89..78fdf63a32 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -54,22 +54,13 @@ const AVOption *av_next_option(void *obj, const AVOption *last)
else return (*(AVClass**)obj)->option;
}
-static int write_number(void *obj, const char *name, double num, int den, int64_t intnum, const AVOption **o_out)
+static int write_number(void *obj, const AVOption *o, void *dst, double num, int den, int64_t intnum)
{
- const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
- void *dst;
- if (o_out)
- *o_out= o;
- if (!o)
- return AVERROR_OPTION_NOT_FOUND;
-
if (o->max*den < num*intnum || o->min*den > num*intnum) {
- av_log(obj, AV_LOG_ERROR, "Value %lf for parameter '%s' out of range\n", num, name);
+ av_log(obj, AV_LOG_ERROR, "Value %lf for parameter '%s' out of range\n", num, o->name);
return AVERROR(ERANGE);
}
- dst= ((uint8_t*)obj) + o->offset;
-
switch (o->type) {
case FF_OPT_TYPE_FLAGS:
case FF_OPT_TYPE_INT: *(int *)dst= llrint(num/den)*intnum; break;
@@ -184,7 +175,7 @@ static int set_string_number(void *obj, const AVOption *o, const char *val, void
else if (cmd == '-') d = notfirst*av_get_double(obj, o->name, NULL) - d;
}
- if ((ret = write_number(obj, o->name, d, 1, 1, NULL)) < 0)
+ if ((ret = write_number(obj, o, dst, d, 1, 1)) < 0)
return ret;
val += i;
if (!*val)
@@ -224,8 +215,14 @@ int av_set_string3(void *obj, const char *name, const char *val, int alloc, cons
static const AVOption *set_number(void *obj, const char *name, double num, int den, int64_t intnum)
{
- const AVOption *o = NULL;
- if (write_number(obj, name, num, den, intnum, &o) < 0)
+ const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
+ void *dst;
+
+ if (!o)
+ return NULL;
+
+ dst = ((uint8_t*)obj) + o->offset;
+ if (write_number(obj, o, dst, num, den, intnum) < 0)
return NULL;
else
return o;