[FFmpeg-devel] [PATCH 01/14] lavfi: add common code to handle options parsing.

Clément Bœsch ubitux at gmail.com
Sat Mar 16 23:04:08 CET 2013


On Sat, Mar 16, 2013 at 09:39:21PM +0100, Nicolas George wrote:
> 
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
> ---
>  libavfilter/avfilter.c |   12 ++++++++++++
>  libavfilter/avfilter.h |    8 ++++++++
>  2 files changed, 20 insertions(+)
> 
> 
> The next patches change a few filters (those I had time to do and know how
> to test easily) to use this new feature
> 
> The overall diffstat is:
>  15 files changed, 65 insertions(+), 117 deletions(-)
> 
> 
> diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> index 1d27817..83d2651 100644
> --- a/libavfilter/avfilter.c
> +++ b/libavfilter/avfilter.c
> @@ -24,6 +24,7 @@
>  #include "libavutil/channel_layout.h"
>  #include "libavutil/common.h"
>  #include "libavutil/imgutils.h"
> +#include "libavutil/opt.h"
>  #include "libavutil/pixdesc.h"
>  #include "libavutil/rational.h"
>  #include "libavutil/samplefmt.h"
> @@ -600,6 +601,17 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque
>  {
>      int ret=0;
>  
> +    if (filter->filter->shorthand) {
> +        av_assert0(filter->priv);
> +        av_assert0(filter->filter->priv_class);
> +        *(const AVClass **)filter->priv = filter->filter->priv_class;
> +        av_opt_set_defaults(filter->priv);
> +        ret = av_opt_set_from_string(filter->priv, args,
> +                                     filter->filter->shorthand, "=", ":");
> +        if (ret < 0)
> +            return ret;
> +        args = NULL;
> +    }
>      if (filter->filter->init_opaque)
>          ret = filter->filter->init_opaque(filter, args, opaque);
>      else if (filter->filter->init)
> diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
> index 45ad6f9..f660a7a 100644
> --- a/libavfilter/avfilter.h
> +++ b/libavfilter/avfilter.h
> @@ -486,6 +486,14 @@ typedef struct AVFilter {
>      int (*init_opaque)(AVFilterContext *ctx, const char *args, void *opaque);
>  
>      const AVClass *priv_class;      ///< private class, containing filter specific options
> +
> +    /**
> +     * Shorthand syntax for init arguments.
> +     * If this field is set (even to an empty list), just before init the
> +     * private class will be set and the arguments string will be parsed
> +     * using av_opt_set_from_string() with "=" and ":" delimiters.
> +     */
> +    const char *const *shorthand;
>  } AVFilter;
>  
>  /** An instance of a filter */

Ah, that is pretty cool. What about calling the av_opt_free()
automatically as a post-uninit hook too? Because having the filters doing
it while not doing the av_opt_set_defaults + parse is a bit awkward.

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130316/4a1556de/attachment.asc>


More information about the ffmpeg-devel mailing list