On date Monday 2011-05-30 21:15:19 +0200, Anton Khirnov encoded:
> This way the caller can pass all the options in one nice package.
> ---
> libavutil/opt.c | 23 +++++++++++++++++++++++
> libavutil/opt.h | 13 +++++++++++++
> 2 files changed, 36 insertions(+), 0 deletions(-)
>
> diff --git a/libavutil/opt.c b/libavutil/opt.c
> index 9e06b01..e7f7780 100644
> --- a/libavutil/opt.c
> +++ b/libavutil/opt.c
> @@ -29,6 +29,7 @@
> #include "avstring.h"
> #include "opt.h"
> #include "eval.h"
> +#include "meta.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)
> @@ -518,6 +519,28 @@ int av_set_options_string(void *ctx, const char *opts,
> return count;
> }
>
> +int avopt_process(void *obj, AVMetadata **options)
> +{
> + AVMetadataTag *t = NULL;
> + AVMetadata *tmp = NULL;
> + int ret = 0;
> +
> + avmeta_copy(&tmp, *options, 0);
> +
> + while ((t = avmeta_get(*options, "", t, AV_METADATA_IGNORE_SUFFIX))) {
> + int ret = av_set_string3(obj, t->key, t->value, 1, NULL);
> + if (ret >= 0)
> + avmeta_set(&tmp, t->key, NULL, 0);
> + else if (ret != AVERROR_OPTION_NOT_FOUND) {
> + av_log(obj, AV_LOG_ERROR, "Error setting option %s to value
> %s\n", t->key, t->value);
> + break;
In case of missing options I believe this should fail, or user the
will have weird suprises (I'm sure I set "foo", why isn't it set?),
having to check the not set options look awkward.
Maybe a better approach is to pass all the options to the context, and
let it use the private options if an option is not set in the parent
context (or the other way round, you give priority to the private
context and use the parent context in case the option is not found
there).
What's your scenario for this approach?
> +int avopt_process(void *obj, AVMetadata **options)
> + }
> + }
> + avmeta_free(options);
> + *options = tmp;
> + return ret;
> +}
> +
> #ifdef TEST
>
> #undef printf
> diff --git a/libavutil/opt.h b/libavutil/opt.h
> index 6668139..5424d86 100644
> --- a/libavutil/opt.h
> +++ b/libavutil/opt.h
> @@ -29,6 +29,7 @@
>
> #include "rational.h"
> #include "avutil.h"
> +#include "meta.h"
>
> enum AVOptionType{
> FF_OPT_TYPE_FLAGS,
> @@ -176,4 +177,16 @@ void av_opt_set_defaults2(void *s, int mask, int flags);
> int av_set_options_string(void *ctx, const char *opts,
> const char *key_val_sep, const char *pairs_sep);
>
> +/**
> + * Apply all the options from opts_in to obj.
> + *
> + * @param obj A struct whose first element is a pointer to AVClass.
> + * @param options Options to process. Will be replaced with an AVMetadata
> + * containing 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 avopt_process(void *obj, struct AVMetadata **options);
> +
> #endif /* AVUTIL_OPT_H */
> --
> 1.7.5.1
--
Anyone who understands everything that comes out of fortune probably
has a problem
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel