aboutsummaryrefslogtreecommitdiff
path: root/libavutil
diff options
context:
space:
mode:
authorMichael Niedermayer2014-05-30 21:04:14 +0200
committerMichael Niedermayer2014-06-01 20:49:18 +0200
commit00759d71a288a25e28ac6393c891f4173084dd6c (patch)
tree0eb38ba59c42e766fca2980d051567089467e165 /libavutil
parentf028b7af7b785d8c69732b09cbddca61f641435a (diff)
avutil/opt: add av_opt_copy()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/opt.c42
-rw-r--r--libavutil/opt.h2
-rw-r--r--libavutil/version.h2
3 files changed, 45 insertions, 1 deletions
diff --git a/libavutil/opt.c b/libavutil/opt.c
index b4dd0fd0c1..694295dc35 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -1539,6 +1539,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 1e1dd69b30..7705990210 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 6fb21b5e14..1b6053cfaf 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -56,7 +56,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 52
-#define LIBAVUTIL_VERSION_MINOR 88
+#define LIBAVUTIL_VERSION_MINOR 89
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \