summaryrefslogtreecommitdiff
path: root/libavutil/opt.c
diff options
context:
space:
mode:
authorAndrew Stone <andrew@clovar.com>2014-07-31 19:56:34 -0400
committerAnton Khirnov <anton@khirnov.net>2014-08-13 16:07:40 +0000
commita8c104a511f97e4ea617df73b31737e28a8a5126 (patch)
tree311c7da06d0705948f7f5872460104b02dd03974 /libavutil/opt.c
parentafbd4b7e093adf6d7a830b32759ca3ba8500363d (diff)
AVOption: add support for dictionary types.
In order to support metadata being set as an option, it's necessary to be able to set dictionaries as values. Signed-off-by: Anton Khirnov <anton@khirnov.net>
Diffstat (limited to 'libavutil/opt.c')
-rw-r--r--libavutil/opt.c54
1 files changed, 51 insertions, 3 deletions
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 9f9f1f2fe1..eecc539ea5 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -307,6 +307,24 @@ int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int
return 0;
}
+int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, int search_flags)
+{
+ void *target_obj;
+ AVDictionary **dst;
+ const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
+
+ if (!o || !target_obj)
+ return AVERROR_OPTION_NOT_FOUND;
+ if (o->flags & AV_OPT_FLAG_READONLY)
+ return AVERROR(EINVAL);
+
+ dst = (AVDictionary **)(((uint8_t *)target_obj) + o->offset);
+ av_dict_free(dst);
+ av_dict_copy(dst, val, 0);
+
+ return 0;
+}
+
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
{
void *dst, *target_obj;
@@ -410,6 +428,23 @@ int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_
return 0;
}
+int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
+{
+ void *target_obj;
+ AVDictionary *src;
+ const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
+
+ if (!o || !target_obj)
+ return AVERROR_OPTION_NOT_FOUND;
+ if (o->type != AV_OPT_TYPE_DICT)
+ return AVERROR(EINVAL);
+
+ src = *(AVDictionary **)(((uint8_t *)target_obj) + o->offset);
+ av_dict_copy(out_val, src, 0);
+
+ return 0;
+}
+
int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
{
const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0);
@@ -539,7 +574,8 @@ void av_opt_set_defaults(void *s)
av_opt_set(s, opt->name, opt->default_val.str, 0);
break;
case AV_OPT_TYPE_BINARY:
- /* Cannot set default for binary */
+ case AV_OPT_TYPE_DICT:
+ /* Cannot set defaults for these types */
break;
default:
av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", opt->type, opt->name);
@@ -621,9 +657,21 @@ int av_set_options_string(void *ctx, const char *opts,
void av_opt_free(void *obj)
{
const AVOption *o = NULL;
- while ((o = av_opt_next(obj, o)))
- if (o->type == AV_OPT_TYPE_STRING || o->type == AV_OPT_TYPE_BINARY)
+ while ((o = av_opt_next(obj, o))) {
+ switch (o->type) {
+ case AV_OPT_TYPE_STRING:
+ case AV_OPT_TYPE_BINARY:
av_freep((uint8_t *)obj + o->offset);
+ break;
+
+ case AV_OPT_TYPE_DICT:
+ av_dict_free((AVDictionary **)(((uint8_t *)obj) + o->offset));
+ break;
+
+ default:
+ break;
+ }
+ }
}
int av_opt_set_dict(void *obj, AVDictionary **options)