[FFmpeg-cvslog] AVOptions: add av_opt_set_dict() mapping a dictionary struct to a context.
Anton Khirnov
git at videolan.org
Sat Jun 18 05:18:36 CEST 2011
ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sun May 22 12:52:50 2011 +0200| [7e83e1c511baf0d02f3af75b6180d6af4d50aa99] | committer: Anton Khirnov
AVOptions: add av_opt_set_dict() mapping a dictionary struct to a context.
This way the caller can pass all the options in one nice package.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7e83e1c511baf0d02f3af75b6180d6af4d50aa99
---
libavutil/opt.c | 22 ++++++++++++++++++++++
libavutil/opt.h | 17 +++++++++++++++++
2 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 7775bb2..55bb6d2 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)
@@ -538,6 +539,27 @@ void av_opt_free(void *obj)
av_freep((uint8_t *)obj + o->offset);
}
+int av_opt_set_dict(void *obj, AVDictionary **options)
+{
+ AVDictionaryEntry *t = NULL;
+ AVDictionary *tmp = 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 (ret == AVERROR_OPTION_NOT_FOUND)
+ av_dict_set(&tmp, 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;
+ }
+ av_dict_free(options);
+ *options = tmp;
+ return ret;
+}
+
#ifdef TEST
#undef printf
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 46ad8ac..ef984d9 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,
@@ -191,4 +192,20 @@ void av_opt_free(void *obj);
*/
int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name);
+/*
+ * Set all the options from a given dictionary on an object.
+ *
+ * @param obj a struct whose first element is a pointer to AVClass
+ * @param options options to process. This dictionary will be freed and replaced
+ * by a new one containing all options not found in obj.
+ * Of course this new dictionary needs to be freed by caller
+ * with av_dict_free().
+ *
+ * @return 0 on success, a negative AVERROR if some option was found in obj,
+ * but could not be set.
+ *
+ * @see av_dict_copy()
+ */
+int av_opt_set_dict(void *obj, struct AVDictionary **options);
+
#endif /* AVUTIL_OPT_H */
More information about the ffmpeg-cvslog
mailing list