aboutsummaryrefslogtreecommitdiff
path: root/libavutil/opt.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavutil/opt.c')
-rw-r--r--libavutil/opt.c42
1 files changed, 42 insertions, 0 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;