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

Stefano Sabatini stefasab at gmail.com
Sun Mar 17 15:15:32 CET 2013


On date Sunday 2013-03-17 11:56:16 +0100, Nicolas George encoded:
[...]
> From aee35f9132223669cd80f5e6f4c446cfbb3ef8ca Mon Sep 17 00:00:00 2001
> From: Nicolas George <nicolas.george at normalesup.org>
> Date: Sat, 16 Mar 2013 20:40:30 +0100
> Subject: [PATCH 01/14] lavfi: add common code to handle options parsing.
> 
> 
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
> ---
>  libavfilter/avfilter.c |   14 ++++++++++++++
>  libavfilter/avfilter.h |    9 +++++++++
>  2 files changed, 23 insertions(+)
> 
> diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> index 1d27817..8a907dc 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"
> @@ -556,6 +557,8 @@ void avfilter_free(AVFilterContext *filter)
>  
>      if (filter->filter->uninit)
>          filter->filter->uninit(filter);
> +    if (filter->filter->shorthand)
> +        av_opt_free(filter->priv);
>  
>      for (i = 0; i < filter->nb_inputs; i++) {
>          if ((link = filter->inputs[i])) {
> @@ -600,6 +603,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..455161f 100644
> --- a/libavfilter/avfilter.h
> +++ b/libavfilter/avfilter.h
> @@ -486,6 +486,15 @@ 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, and
> +     * av_opt_free() will be called just after uninit.
> +     */
> +    const char *const *shorthand;
>  } AVFilter;
>  
>  /** An instance of a filter */
> -- 
> 1.7.10.4
> 
> From abd188ffd460f154faa80143b780e702f2a92ad4 Mon Sep 17 00:00:00 2001
> From: Nicolas George <nicolas.george at normalesup.org>
> Date: Sat, 16 Mar 2013 20:41:06 +0100
> Subject: [PATCH 02/14] lavfi/avf_concat: use standard options parsing.
> 
> 
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
> ---
>  libavfilter/avf_concat.c |   12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/libavfilter/avf_concat.c b/libavfilter/avf_concat.c
> index 7b5d591..192269f 100644
> --- a/libavfilter/avf_concat.c
> +++ b/libavfilter/avf_concat.c
> @@ -354,17 +354,8 @@ static int request_frame(AVFilterLink *outlink)
>  static av_cold int init(AVFilterContext *ctx, const char *args)
>  {
>      ConcatContext *cat = ctx->priv;
> -    int ret;
>      unsigned seg, type, str;
>  
> -    cat->class = &concat_class;
> -    av_opt_set_defaults(cat);
> -    ret = av_set_options_string(cat, args, "=", ":");
> -    if (ret < 0) {
> -        av_log(ctx, AV_LOG_ERROR, "Error parsing options: '%s'\n", args);
> -        return ret;
> -    }
> -
>      /* create input pads */
>      for (seg = 0; seg < cat->nb_segments; seg++) {
>          for (type = 0; type < TYPE_ALL; type++) {
> @@ -414,6 +405,8 @@ static av_cold void uninit(AVFilterContext *ctx)
>      av_free(cat->in);
>  }
>  
> +static const char *const shorthand[] = { NULL };
> +
>  AVFilter avfilter_avf_concat = {
>      .name          = "concat",
>      .description   = NULL_IF_CONFIG_SMALL("Concatenate audio and video streams."),
> @@ -424,4 +417,5 @@ AVFilter avfilter_avf_concat = {
>      .inputs        = NULL,
>      .outputs       = NULL,
>      .priv_class    = &concat_class,
> +    .shorthand     = shorthand,
>  };
> -- 
> 1.7.10.4
> 
> From 0701ad98b92ee0a2a6b1f500a9555bd6100c4b35 Mon Sep 17 00:00:00 2001
> From: Nicolas George <nicolas.george at normalesup.org>
> Date: Sat, 16 Mar 2013 20:41:36 +0100
> Subject: [PATCH 03/14] lavfi/vf_tile: use standard options parsing.
> 
> 
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
> ---
>  libavfilter/vf_tile.c |   12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
> 
> diff --git a/libavfilter/vf_tile.c b/libavfilter/vf_tile.c
> index 30c9809..b45cbb8 100644
> --- a/libavfilter/vf_tile.c
> +++ b/libavfilter/vf_tile.c
> @@ -65,14 +65,6 @@ AVFILTER_DEFINE_CLASS(tile);
>  static av_cold int init(AVFilterContext *ctx, const char *args)
>  {
>      TileContext *tile = ctx->priv;
> -    static const char *shorthand[] = { "layout", "nb_frames", "margin", "padding", NULL };
> -    int ret;
> -
> -    tile->class = &tile_class;
> -    av_opt_set_defaults(tile);
> -
> -    if ((ret = av_opt_set_from_string(tile, args, shorthand, "=", ":")) < 0)
> -        return ret;
>  
>      if (tile->w > REASONABLE_SIZE || tile->h > REASONABLE_SIZE) {
>          av_log(ctx, AV_LOG_ERROR, "Tile size %ux%u is insane.\n",
> @@ -243,6 +235,9 @@ static const AVFilterPad tile_outputs[] = {
>      { NULL }
>  };
>  
> +static const char *const shorthand[] =
> +    { "layout", "nb_frames", "margin", "padding", NULL };
> +
>  AVFilter avfilter_vf_tile = {
>      .name          = "tile",
>      .description   = NULL_IF_CONFIG_SMALL("Tile several successive frames together."),
> @@ -252,4 +247,5 @@ AVFilter avfilter_vf_tile = {
>      .inputs        = tile_inputs,
>      .outputs       = tile_outputs,
>      .priv_class    = &tile_class,
> +    .shorthand     = shorthand,

Nit+: shorthand could be directly defined here in order to avoid one
level of indirection, but I suppose not all compilers like that.

[...]

Patches looks fine, thanks.
-- 
FFmpeg = Fast & Fierce Mortal Philosofic Enhancing Ghost


More information about the ffmpeg-devel mailing list