This way the caller can pass all the options in one nice package.
---
libavutil/opt.c | 19 +++++++++++++++++++
libavutil/opt.h | 14 ++++++++++++++
2 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 172fcec..94596ed 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -29,6 +29,7 @@
#include "avstring.h"
#include "opt.h"
#include "eval.h"
+#include "dict.h"
//FIXME order them and do a bin search
const AVOption *av_find_opt(void *v, const char *name, const char *unit, int
mask, int flags)
@@ -528,6 +529,24 @@ void av_opt_free(void *obj)
av_freep((uint8_t *)obj + o->offset);
}
+int av_opt_set_dict(void *obj, AVDictionary *options, AVDictionary
**out_options)
+{
+ AVDictionaryEntry *t = NULL;
+ int ret = 0;
+
+ while ((t = av_dict_get(options, "", t, AV_DICT_IGNORE_SUFFIX))) {
+ ret = av_set_string3(obj, t->key, t->value, 1, NULL);
+ if (out_options && ret == AVERROR_OPTION_NOT_FOUND)
+ av_dict_set(out_options, t->key, t->value, 0);
+ else if (ret < 0) {
+ av_log(obj, AV_LOG_ERROR, "Error setting option %s to value
%s.\n", t->key, t->value);
+ break;
+ }
+ ret = 0;
+ }
+ return ret;
+}
+
#ifdef TEST
#undef printf
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 8c3b6c1..b3a33c7 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -29,6 +29,7 @@
#include "rational.h"
#include "avutil.h"
+#include "dict.h"
enum AVOptionType{
FF_OPT_TYPE_FLAGS,
@@ -181,4 +182,17 @@ int av_set_options_string(void *ctx, const char *opts,
*/
void av_opt_free(void *obj);
+/*
+ * A convenience function that applies all the options from options to obj.
+ *
+ * @param obj A struct whose first element is a pointer to AVClass.
+ * @param options Options to process.
+ * @param out_options If non-NULL, this AVDictionary will be filled with all
+ * options not found in obj.
+ *
+ * @return 0 on success, a negative AVERROR if some option was found in obj,
+ * but couldn't be set.
+ */
+int av_opt_set_dict(void *obj, AVDictionary *options, AVDictionary
**out_options);
+
#endif /* AVUTIL_OPT_H */
--
1.7.5.3
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel