summaryrefslogtreecommitdiff
path: root/libavutil/opt.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-08-13 22:39:54 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-08-13 22:39:54 +0200
commit2ba45778095cdd6e1438644e4797b76e9de6c672 (patch)
tree6d7ef68dc6929b79854a0e9803cdb69bc70501e4 /libavutil/opt.c
parented8e6d535cf4c56d82f9c91646dfc42787b719d6 (diff)
parenta8c104a511f97e4ea617df73b31737e28a8a5126 (diff)
Merge commit 'a8c104a511f97e4ea617df73b31737e28a8a5126'
* commit 'a8c104a511f97e4ea617df73b31737e28a8a5126': AVOption: add support for dictionary types. Conflicts: libavutil/opt.c libavutil/opt.h libavutil/version.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
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 2a06eb6f39..fec840bf71 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -680,6 +680,24 @@ const char *av_get_string(void *obj, const char *name, const AVOption **o_out, c
}
#endif
+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;
@@ -927,6 +945,23 @@ int av_opt_get_channel_layout(void *obj, const char *name, int search_flags, int
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);
@@ -1220,7 +1255,8 @@ void av_opt_set_defaults2(void *s, int mask, int flags)
write_number(s, opt, dst, 1, 1, opt->default_val.i64);
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);
@@ -1414,9 +1450,21 @@ int av_opt_set_from_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_dict2(void *obj, AVDictionary **options, int search_flags)