[FFmpeg-devel] [PATCH] lavfi/hue: add process_command callback

Stefano Sabatini stefasab at gmail.com
Wed Aug 29 12:12:46 CEST 2012


On date Tuesday 2012-08-28 02:09:03 +0200, Jérémy Tran encoded:
> This allows dynamic reconfiguration of the filter.
> ---
>  doc/filters.texi     | 12 ++++++++++++
>  libavfilter/vf_hue.c | 37 +++++++++++++++++++++++++++++++++----
>  2 files changed, 45 insertions(+), 4 deletions(-)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index bef95f7..4aec59b 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -2313,6 +2313,18 @@ hue=PI/2:1
>  @end example
>  @end itemize
>  
> + at subsection commands

Commands

> +
> +The filter supports the following command:
> + at table @option
> + at item reinit
> +Modify the hue and/or the saturation of the input video.
> +The command accepts the same named options and syntax than when calling the
> +filter from the command-line.
> +

> +If a parameter is omitted, it is not reset to its default value.

... it is kept at its current value.

> + at end table
> +
>  @section idet
>  
>  Interlaceing detect filter. This filter tries to detect if the input is
> diff --git a/libavfilter/vf_hue.c b/libavfilter/vf_hue.c
> index cf1fe5f..690ae15 100644
> --- a/libavfilter/vf_hue.c
> +++ b/libavfilter/vf_hue.c
> @@ -63,16 +63,13 @@ static const AVOption hue_options[] = {
>  
>  AVFILTER_DEFINE_CLASS(hue);
>  
> -static av_cold int init(AVFilterContext *ctx, const char *args)
> +static inline int set_args(AVFilterContext *ctx, const char *args)
>  {
>      HueContext *hue = ctx->priv;
>      int n, ret;
>      char c1 = 0, c2 = 0;
>      char *equal;
>  
> -    hue->class = &hue_class;
> -    av_opt_set_defaults(hue);
> -
>      if (args) {
>          /* named options syntax */
>          if (equal = strchr(args, '=')) {
> @@ -103,6 +100,20 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
>          }
>      }
>  
> +    return 0;
> +}
> +
> +static av_cold int init(AVFilterContext *ctx, const char *args)
> +{
> +    HueContext *hue = ctx->priv;
> +    int ret;
> +
> +    hue->class = &hue_class;
> +    av_opt_set_defaults(hue);
> +
> +    if (ret = set_args(ctx, args) < 0)
> +        return ret;
> +
>      if (hue->saturation == -FLT_MAX)
>          hue->hue = SAT_DEFAULT_VAL;
>      if (hue->hue == -FLT_MAX)
> @@ -223,6 +234,23 @@ static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
>      return ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
>  }
>  

> +static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)

nit: split long line

> +{
> +    HueContext *hue = ctx->priv;
> +    int ret;
> +
> +    if (!strcmp(cmd, "reinit")) {

> +        if (ret = set_args(ctx, arg) < 0)

if ((ret = set_args(...)) < 0)

My mind refuses to remember silly operator priority rules, your code
could be wrong as is.

> +            return ret;
> +
> +        hue->hue_sin = rint(sin(hue->hue) * (1 << 16) * hue->saturation);
> +        hue->hue_cos = rint(cos(hue->hue) * (1 << 16) * hue->saturation);
> +    } else
> +        return AVERROR(ENOSYS);
> +
> +    return 0;
> +}
> +
>  AVFilter avfilter_vf_hue = {
>      .name        = "hue",
>      .description = NULL_IF_CONFIG_SMALL("Adjust the hue and saturation of the input video."),
> @@ -232,6 +260,7 @@ AVFilter avfilter_vf_hue = {
>      .init          = init,
>      .uninit        = uninit,
>      .query_formats = query_formats,
> +    .process_command = command,
>  
>      .inputs = (const AVFilterPad[]) {

Should be fine otherwise if tested (BTW, how did you test it?).
-- 
FFmpeg = Frenzy Freak Multimedia Perfect Eretic Geisha


More information about the ffmpeg-devel mailing list