X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavutil%2Fopt.c;h=fec840bf71826b8ec985406891cf3bb0361820bb;hb=b8e4c11d93326cd86278d012c28e54dca0a06cef;hp=2a06eb6f39fbed10c53434a15cb28fb017ec5fce;hpb=94d4f9d405074572dc7d4ab40fe32a7e83040dc8;p=ffmpeg diff --git a/libavutil/opt.c b/libavutil/opt.c index 2a06eb6f39f..fec840bf718 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)