On date Friday 2011-06-10 22:13:28 +0200, Anton Khirnov encoded:
> 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.
Nit, skip the "a convenience function" =>
Apply all the options from options to obj.
Maybe "apply" is not very explicit, so I suggest:
Set the options contained in the options dictionary 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.
Usual grammar nits I already pointed out in another mail, see for
example the documentation of av_opt_show2() for an example.
> + */
> +int av_opt_set_dict(void *obj, AVDictionary *options, AVDictionary
> **out_options);
For the rest I have the same comments as Ronald, I'm as evil as him, I
believe that API-wise this signature is safer, even if not optimal for
the typical use in libavformat, I'm not against an additional
convenience function of the kind:
int av_opt_set_dict_d(void *obj, AVDictionary **options)
(d -> destructive) even if this would very slightly complicate/bloat
the API (or you could implement an internal ff_ variant for it).
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel