[FFmpeg-cvslog] AVOptions: refactor set_number/write_number

Anton Khirnov git at videolan.org
Tue Oct 11 03:52:34 CEST 2011


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Tue Aug 23 12:58:49 2011 +0200| [7bb1807c2dd9623842f1c6d454e7f2892b5bc8d7] | committer: Anton Khirnov

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.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7bb1807c2dd9623842f1c6d454e7f2892b5bc8d7
---

 libavutil/opt.c |   25 +++++++++++--------------
 1 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index b3f29a5..78fdf63 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;



More information about the ffmpeg-cvslog mailing list