diff options
author | Anton Khirnov <anton@khirnov.net> | 2011-08-23 14:25:56 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2011-10-12 16:51:16 +0200 |
commit | 059a037fbd0f0f6e47426f5c40ff315fca3e0099 (patch) | |
tree | 28a26d31d43f17a51e4797918d92a423a554e1a4 /libavutil/opt.c | |
parent | 41d9d51a72674562f01118a087cd01093dbead3e (diff) | |
download | ffmpeg-059a037fbd0f0f6e47426f5c40ff315fca3e0099.tar.gz |
AVOptions: split get_number().
Split actual writing to read_number() in the same way as write_number().
Allows set_string_number() to write to a caller-provided destination.
Diffstat (limited to 'libavutil/opt.c')
-rw-r--r-- | libavutil/opt.c | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/libavutil/opt.c b/libavutil/opt.c index 3d42a36d0c..08fba8bc0f 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -54,6 +54,21 @@ const AVOption *av_next_option(void *obj, const AVOption *last) else return (*(AVClass**)obj)->option; } +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) { @@ -138,10 +153,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++); @@ -168,11 +184,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) @@ -373,16 +391,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; |