[FFmpeg-cvslog] AVOptions: add av_opt_set*().

Anton Khirnov git at videolan.org
Thu Oct 13 06:01:46 CEST 2011


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Mon Sep  5 08:15:32 2011 +0200| [dac66da63db2eb3df1655d540084703dd93f82e4] | committer: Anton Khirnov

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.

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

 libavutil/opt.c |   64 +++++++++++++++++++++++++++++++++++++++++-------------
 libavutil/opt.h |   45 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 90 insertions(+), 19 deletions(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index b732703..709beed 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -186,18 +186,26 @@ static int set_string_number(void *obj, const AVOption *o, const char *val, void
     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)
 {
     const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
-    void *dst;
     if (o_out)
         *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;
     if (!val)
         return AVERROR(EINVAL);
 
-    dst = ((uint8_t*)obj) + o->offset;
+    dst = ((uint8_t*)target_obj) + o->offset;
     switch (o->type) {
     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);
@@ -213,34 +221,58 @@ int av_set_string3(void *obj, const char *name, const char *val, int alloc, cons
     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;
+    void *dst, *target_obj;
+    const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
 
-    if (!o)
-        return NULL;
+    if (!o || !target_obj)
+        return AVERROR_OPTION_NOT_FOUND;
 
-    dst = ((uint8_t*)obj) + o->offset;
-    if (write_number(obj, o, dst, num, den, intnum) < 0)
-        return NULL;
-    else
-        return o;
+    dst = ((uint8_t*)target_obj) + o->offset;
+    return write_number(obj, o, dst, num, den, intnum);
 }
 
+#if FF_API_OLD_AVOPTIONS
 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)
 {
-    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)
 {
-    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);
 }
 
 /**
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 6f0a03b..93da88c 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -112,6 +112,7 @@ attribute_deprecated
 const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int mask, int flags);
 #endif
 
+#if FF_API_OLD_AVOPTIONS
 /**
  * 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(ERANGE) if the value is out of range
  * 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);
 
-const AVOption *av_set_double(void *obj, const char *name, double n);
-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_double(void *obj, const char *name, double n);
+attribute_deprecated const AVOption *av_set_q(void *obj, const char *name, AVRational 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);
 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);
@@ -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);
 
+/**
+ * @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 */



More information about the ffmpeg-cvslog mailing list