On 06/09/2011 06:27 AM, Anton Khirnov wrote:

> This way the caller can pass all the options in one nice package.
> ---
>  libavutil/opt.c |   24 ++++++++++++++++++++++++
>  libavutil/opt.h |   13 +++++++++++++
>  2 files changed, 37 insertions(+), 0 deletions(-)
> 
> diff --git a/libavutil/opt.c b/libavutil/opt.c
> index 172fcec..429c9ba 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,29 @@ void av_opt_free(void *obj)
>              av_freep((uint8_t *)obj + o->offset);
>  }
>  
> +int av_opt_apply_dict(void *obj, AVDictionary **options)
> +{
> +    AVDictionaryEntry *t = NULL;
> +    AVDictionary    *tmp = NULL;
> +    int ret = 0;
> +
> +    av_dict_copy(&tmp, *options, 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 >= 0)
> +            av_dict_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;
> +        }
> +        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 8c3b6c1..f16d989 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,16 @@ 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. Will be replaced with an AVDictionary
> + *                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 av_opt_apply_dict(void *obj, struct AVDictionary **options);
> +
>  #endif /* AVUTIL_OPT_H */


Patch looks ok.

I don't care about the name, other than whatever we go with the naming
should be made consistent for similar functions.

-Justin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to