[FFmpeg-devel] [PATCH 3/4] avutil/opt: add av_opt_copy()

Michael Niedermayer michaelni at gmx.at
Fri May 30 21:24:24 CEST 2014


Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 doc/APIchanges      |    3 +++
 libavutil/opt.c     |   42 ++++++++++++++++++++++++++++++++++++++++++
 libavutil/opt.h     |    2 ++
 libavutil/version.h |    2 +-
 4 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 9c3bdf2..aca7977 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil:     2012-10-22
 
 API changes, most recent first:
 
+2014-05-30 - xxxxxxx - lavu 52.88.100 - opt.h
+  Add av_opt_copy()
+
 2014-04-xx - xxxxxxx - lavr 1.3.0 - avresample.h
   Add avresample_max_output_samples
 
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 72de041..85f3b1f 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -1540,6 +1540,48 @@ static int opt_size(enum AVOptionType type)
     return 0;
 }
 
+int av_opt_copy(void *dst, void *src)
+{
+    const AVOption *o = NULL;
+    const AVClass *c;
+    int ret = 0;
+
+    if (!src)
+        return 0;
+
+    c = *(AVClass**)src;
+    if (*(AVClass**)dst && c != *(AVClass**)dst)
+        return AVERROR(EINVAL);
+
+    while ((o = av_opt_next(src, o))) {
+        void *field_dst = ((uint8_t*)dst) + o->offset;
+        void *field_src = ((uint8_t*)src) + o->offset;
+        uint8_t **field_dst8 = (uint8_t**)field_dst;
+        uint8_t **field_src8 = (uint8_t**)field_src;
+
+        if (o->type == AV_OPT_TYPE_STRING) {
+            set_string(dst, o, *field_src8, field_dst8);
+            if (*field_src8 && !*field_dst8)
+                ret = AVERROR(ENOMEM);
+        } else if (o->type == AV_OPT_TYPE_BINARY) {
+            int len = *(int*)(field_src8 + 1);
+            if (*field_dst8 != *field_src8)
+                av_freep(field_dst8);
+            *field_dst8 = av_memdup(*field_src8, len);
+            if (len && !*field_dst8) {
+                ret = AVERROR(ENOMEM);
+                len = 0;
+            }
+            *(int*)(field_dst8 + 1) = len;
+        } else if (o->type == AV_OPT_TYPE_CONST) {
+            // do nothing
+        } else {
+            memcpy(field_dst, field_src, opt_size(o->type));
+        }
+    }
+    return ret;
+}
+
 int av_opt_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
 {
     int ret;
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 1e1dd69..7705990 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -822,6 +822,8 @@ void av_opt_freep_ranges(AVOptionRanges **ranges);
  */
 int av_opt_query_ranges(AVOptionRanges **, void *obj, const char *key, int flags);
 
+int av_opt_copy(void *dest, void *src);
+
 /**
  * Get a default list of allowed ranges for the given option.
  *
diff --git a/libavutil/version.h b/libavutil/version.h
index 4dad89a..c053f0c 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -56,7 +56,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  52
-#define LIBAVUTIL_VERSION_MINOR  87
+#define LIBAVUTIL_VERSION_MINOR  88
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list