Split actual writing to read_number() in the same way as write_number().
Allows set_string_number() to write to a caller-provided destination.
---
libavutil/opt.c | 42 ++++++++++++++++++++++++++----------------
1 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/libavutil/opt.c b/libavutil/opt.c
index d1c2af7..2d13d96 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -90,6 +90,21 @@ static const AVOption *opt_find(void *obj, const char *name,
const char *unit,
return NULL;
}
+static int read_number(const AVOption *o, void *dst, double *num, int *den,
int64_t *intnum)
+{
+ switch (o->type) {
+ case FF_OPT_TYPE_FLAGS: *intnum = *(unsigned int*)dst;return 0;
+ case FF_OPT_TYPE_INT: *intnum = *(int *)dst;return 0;
+ case FF_OPT_TYPE_INT64: *intnum = *(int64_t *)dst;return 0;
+ case FF_OPT_TYPE_FLOAT: *num = *(float *)dst;return 0;
+ case FF_OPT_TYPE_DOUBLE: *num = *(double *)dst;return 0;
+ case FF_OPT_TYPE_RATIONAL: *intnum = ((AVRational*)dst)->num;
+ *den = ((AVRational*)dst)->den;
+ return 0;
+ }
+ return AVERROR(EINVAL);
+}
+
static int write_number(void *obj, const AVOption *o, void *dst, double num,
int den, int64_t intnum)
{
if (o->max*den < num*intnum || o->min*den > num*intnum) {
@@ -174,10 +189,11 @@ static int set_string_number(void *obj, const AVOption
*o, const char *val, void
{
int ret = 0, notfirst = 0;
for (;;) {
- int i;
+ int i, den = 1;
char buf[256];
int cmd = 0;
- double d;
+ double d, num = 1;
+ int64_t intnum = 1;
if (*val == '+' || *val == '-')
cmd = *(val++);
@@ -204,11 +220,13 @@ static int set_string_number(void *obj, const AVOption
*o, const char *val, void
}
}
if (o->type == FF_OPT_TYPE_FLAGS) {
- if (cmd == '+') d = av_get_int(obj, o->name, NULL) |
(int64_t)d;
- else if (cmd == '-') d = av_get_int(obj, o->name, NULL)
&~(int64_t)d;
+ read_number(o, dst, NULL, NULL, &intnum);
+ if (cmd == '+') d = intnum | (int64_t)d;
+ else if (cmd == '-') d = intnum &~(int64_t)d;
} else {
- if (cmd == '+') d = notfirst*av_get_double(obj, o->name,
NULL) + d;
- else if (cmd == '-') d = notfirst*av_get_double(obj, o->name,
NULL) - d;
+ read_number(o, dst, &num, &den, &intnum);
+ if (cmd == '+') d = notfirst*num*intnum/den + d;
+ else if (cmd == '-') d = notfirst*num*intnum/den - d;
}
if ((ret = write_number(obj, o, dst, d, 1, 1)) < 0)
@@ -409,16 +427,8 @@ static int get_number(void *obj, const char *name, const
AVOption **o_out, doubl
if (o_out) *o_out= o;
- switch (o->type) {
- case FF_OPT_TYPE_FLAGS: *intnum= *(unsigned int*)dst;return 0;
- case FF_OPT_TYPE_INT: *intnum= *(int *)dst;return 0;
- case FF_OPT_TYPE_INT64: *intnum= *(int64_t*)dst;return 0;
- case FF_OPT_TYPE_FLOAT: *num= *(float *)dst;return 0;
- case FF_OPT_TYPE_DOUBLE: *num= *(double *)dst;return 0;
- case FF_OPT_TYPE_RATIONAL: *intnum= ((AVRational*)dst)->num;
- *den = ((AVRational*)dst)->den;
- return 0;
- }
+ return read_number(o, dst, num, den, intnum);
+
error:
*den=*intnum=0;
return -1;
--
1.7.6.3
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel