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

Nicolas George nicolas.george at normalesup.org
Sun Mar 17 11:56:16 CET 2013


Le septidi 27 ventôse, an CCXXI, Stefano Sabatini a écrit :
> I suggest to set options whenever the priv_class is defined. This
> should work fine for all filters with a few exceptions (out of my mind
> only hue, which may/should be simplified, at the cost of changing the
> command interface).

It would require quite a few non trivial changes, and make a few features we
want to keep impossible. Setting filter.shorthand to anything (including
{NULL}) is a very simple way of enabling the system without risk.

> At this point we could free the context in uninint, as suggested by
> Clement, which should allow more factorization.

New patch series, with the same test for av_opt_free().

Regards,

-- 
  Nicolas George


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,
 };
-- 
1.7.10.4

From ad1b2ed477cf544ba0da8e15ebe4e84c8307d454 Mon Sep 17 00:00:00 2001
From: Nicolas George <nicolas.george at normalesup.org>
Date: Sat, 16 Mar 2013 20:54:57 +0100
Subject: [PATCH 04/14] lavfi/af_volume: use standard options parsing.


Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavfilter/af_volume.c |   14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/libavfilter/af_volume.c b/libavfilter/af_volume.c
index 226ef93..447e8d5 100644
--- a/libavfilter/af_volume.c
+++ b/libavfilter/af_volume.c
@@ -59,14 +59,6 @@ AVFILTER_DEFINE_CLASS(volume);
 static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     VolumeContext *vol = ctx->priv;
-    static const char *shorthand[] = { "volume", "precision", NULL };
-    int ret;
-
-    vol->class = &volume_class;
-    av_opt_set_defaults(vol);
-
-    if ((ret = av_opt_set_from_string(vol, args, shorthand, "=", ":")) < 0)
-        return ret;
 
     if (vol->precision == PRECISION_FIXED) {
         vol->volume_i = (int)(vol->volume * 256 + 0.5);
@@ -79,8 +71,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
                precision_str[vol->precision]);
     }
 
-    av_opt_free(vol);
-    return ret;
+    return 0;
 }
 
 static int query_formats(AVFilterContext *ctx)
@@ -299,6 +290,8 @@ static const AVFilterPad avfilter_af_volume_outputs[] = {
     { NULL }
 };
 
+static const char *const shorthand[] = { "volume", "precision", NULL };
+
 AVFilter avfilter_af_volume = {
     .name           = "volume",
     .description    = NULL_IF_CONFIG_SMALL("Change input volume."),
@@ -308,4 +301,5 @@ AVFilter avfilter_af_volume = {
     .inputs         = avfilter_af_volume_inputs,
     .outputs        = avfilter_af_volume_outputs,
     .priv_class     = &volume_class,
+    .shorthand      = shorthand,
 };
-- 
1.7.10.4

From 3ebb331de18e6c1e0bac74004be4c5744f09db4a Mon Sep 17 00:00:00 2001
From: Nicolas George <nicolas.george at normalesup.org>
Date: Sat, 16 Mar 2013 21:03:31 +0100
Subject: [PATCH 05/14] lavfi/vf_crop: use standard options parsing.


Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavfilter/vf_crop.c |   16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/libavfilter/vf_crop.c b/libavfilter/vf_crop.c
index 17487a2..f99d1a7 100644
--- a/libavfilter/vf_crop.c
+++ b/libavfilter/vf_crop.c
@@ -107,24 +107,12 @@ static const AVOption crop_options[] = {
 
 AVFILTER_DEFINE_CLASS(crop);
 
-static av_cold int init(AVFilterContext *ctx, const char *args)
-{
-    CropContext *crop = ctx->priv;
-    static const char *shorthand[] = { "w", "h", "x", "y", "keep_aspect", NULL };
-
-    crop->class = &crop_class;
-    av_opt_set_defaults(crop);
-
-    return av_opt_set_from_string(crop, args, shorthand, "=", ":");
-}
-
 static av_cold void uninit(AVFilterContext *ctx)
 {
     CropContext *crop = ctx->priv;
 
     av_expr_free(crop->x_pexpr); crop->x_pexpr = NULL;
     av_expr_free(crop->y_pexpr); crop->y_pexpr = NULL;
-    av_opt_free(crop);
 }
 
 static int query_formats(AVFilterContext *ctx)
@@ -348,6 +336,8 @@ static const AVFilterPad avfilter_vf_crop_outputs[] = {
     { NULL }
 };
 
+static const char *const shorthand[] = { "w", "h", "x", "y", "keep_aspect", NULL };
+
 AVFilter avfilter_vf_crop = {
     .name      = "crop",
     .description = NULL_IF_CONFIG_SMALL("Crop the input video to width:height:x:y."),
@@ -355,10 +345,10 @@ AVFilter avfilter_vf_crop = {
     .priv_size = sizeof(CropContext),
 
     .query_formats = query_formats,
-    .init          = init,
     .uninit        = uninit,
 
     .inputs    = avfilter_vf_crop_inputs,
     .outputs   = avfilter_vf_crop_outputs,
     .priv_class = &crop_class,
+    .shorthand = shorthand,
 };
-- 
1.7.10.4

From 30d2fa4bf6c13bce381ce41dd39aaf46ac51cbcb Mon Sep 17 00:00:00 2001
From: Nicolas George <nicolas.george at normalesup.org>
Date: Sat, 16 Mar 2013 21:08:06 +0100
Subject: [PATCH 06/14] lavfi/vf_decimate: use standard options parsing.


Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavfilter/vf_decimate.c |   12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/libavfilter/vf_decimate.c b/libavfilter/vf_decimate.c
index f0e49c9..630f3ba 100644
--- a/libavfilter/vf_decimate.c
+++ b/libavfilter/vf_decimate.c
@@ -132,14 +132,6 @@ static int decimate_frame(AVFilterContext *ctx,
 static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     DecimateContext *decimate = ctx->priv;
-    static const char *shorthand[] = { "max", "hi", "lo", "frac", NULL };
-    int ret;
-
-    decimate->class = &decimate_class;
-    av_opt_set_defaults(decimate);
-
-    if ((ret = av_opt_set_from_string(decimate, args, shorthand, "=", ":")) < 0)
-        return ret;
 
     av_log(ctx, AV_LOG_VERBOSE, "max_drop_count:%d hi:%d lo:%d frac:%f\n",
            decimate->max_drop_count, decimate->hi, decimate->lo, decimate->frac);
@@ -157,7 +149,6 @@ static av_cold void uninit(AVFilterContext *ctx)
     DecimateContext *decimate = ctx->priv;
     av_frame_free(&decimate->ref);
     avcodec_close(decimate->avctx);
-    av_opt_free(decimate);
     av_freep(&decimate->avctx);
 }
 
@@ -251,6 +242,8 @@ static const AVFilterPad decimate_outputs[] = {
     { NULL }
 };
 
+static const char *const shorthand[] = { "max", "hi", "lo", "frac", NULL };
+
 AVFilter avfilter_vf_decimate = {
     .name        = "decimate",
     .description = NULL_IF_CONFIG_SMALL("Remove near-duplicate frames."),
@@ -262,4 +255,5 @@ AVFilter avfilter_vf_decimate = {
     .inputs        = decimate_inputs,
     .outputs       = decimate_outputs,
     .priv_class    = &decimate_class,
+    .shorthand     = shorthand,
 };
-- 
1.7.10.4

From 0fa62133eec8d1520a2a18ba2faacd167f109a94 Mon Sep 17 00:00:00 2001
From: Nicolas George <nicolas.george at normalesup.org>
Date: Sat, 16 Mar 2013 21:14:57 +0100
Subject: [PATCH 07/14] lavfi/vf_delogo: use standard options parsing.


Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavfilter/vf_delogo.c |   11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c
index 4c0670d..159f69f 100644
--- a/libavfilter/vf_delogo.c
+++ b/libavfilter/vf_delogo.c
@@ -171,14 +171,6 @@ static int query_formats(AVFilterContext *ctx)
 static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     DelogoContext *delogo = ctx->priv;
-    int ret = 0;
-    static const char *shorthand[] = { "x", "y", "w", "h", "band", NULL };
-
-    delogo->class = &delogo_class;
-    av_opt_set_defaults(delogo);
-
-    if ((ret = av_opt_set_from_string(delogo, args, shorthand, "=", ":")) < 0)
-        return ret;
 
 #define CHECK_UNSET_OPT(opt)                                            \
     if (delogo->opt == -1) {                                            \
@@ -267,6 +259,8 @@ static const AVFilterPad avfilter_vf_delogo_outputs[] = {
     { NULL }
 };
 
+static const char *const shorthand[] = { "x", "y", "w", "h", "band", NULL };
+
 AVFilter avfilter_vf_delogo = {
     .name          = "delogo",
     .description   = NULL_IF_CONFIG_SMALL("Remove logo from input video."),
@@ -277,4 +271,5 @@ AVFilter avfilter_vf_delogo = {
     .inputs    = avfilter_vf_delogo_inputs,
     .outputs   = avfilter_vf_delogo_outputs,
     .priv_class = &delogo_class,
+    .shorthand = shorthand,
 };
-- 
1.7.10.4

From e035ed07c5c23ac22eb0b9a15f58cd6f8e3e910b Mon Sep 17 00:00:00 2001
From: Nicolas George <nicolas.george at normalesup.org>
Date: Sat, 16 Mar 2013 21:27:10 +0100
Subject: [PATCH 08/14] lavi/vf_drawbox: use standard options parsing.


Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavfilter/vf_drawbox.c |   18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/libavfilter/vf_drawbox.c b/libavfilter/vf_drawbox.c
index 41601b9..b831182 100644
--- a/libavfilter/vf_drawbox.c
+++ b/libavfilter/vf_drawbox.c
@@ -68,14 +68,6 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     DrawBoxContext *drawbox = ctx->priv;
     uint8_t rgba_color[4];
-    static const char *shorthand[] = { "x", "y", "w", "h", "color", "thickness", NULL };
-    int ret;
-
-    drawbox->class = &drawbox_class;
-    av_opt_set_defaults(drawbox);
-
-    if ((ret = av_opt_set_from_string(drawbox, args, shorthand, "=", ":")) < 0)
-        return ret;
 
     if (!strcmp(drawbox->color_str, "invert"))
         drawbox->invert_color = 1;
@@ -92,12 +84,6 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     return 0;
 }
 
-static av_cold void uninit(AVFilterContext *ctx)
-{
-    DrawBoxContext *drawbox = ctx->priv;
-    av_opt_free(drawbox);
-}
-
 static int query_formats(AVFilterContext *ctx)
 {
     static const enum AVPixelFormat pix_fmts[] = {
@@ -185,15 +171,17 @@ static const AVFilterPad avfilter_vf_drawbox_outputs[] = {
     { NULL }
 };
 
+static const char *const shorthand[] = { "x", "y", "w", "h", "color", "thickness", NULL };
+
 AVFilter avfilter_vf_drawbox = {
     .name      = "drawbox",
     .description = NULL_IF_CONFIG_SMALL("Draw a colored box on the input video."),
     .priv_size = sizeof(DrawBoxContext),
     .init      = init,
-    .uninit    = uninit,
 
     .query_formats   = query_formats,
     .inputs    = avfilter_vf_drawbox_inputs,
     .outputs   = avfilter_vf_drawbox_outputs,
     .priv_class = &drawbox_class,
+    .shorthand = shorthand,
 };
-- 
1.7.10.4

From 0cb72025641890ec268b5fec3c9d6e1cf4828de8 Mon Sep 17 00:00:00 2001
From: Nicolas George <nicolas.george at normalesup.org>
Date: Sat, 16 Mar 2013 21:27:24 +0100
Subject: [PATCH 09/14] lavfi/vf_fade: use standard options parsing.


Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavfilter/vf_fade.c |   19 +++----------------
 1 file changed, 3 insertions(+), 16 deletions(-)

diff --git a/libavfilter/vf_fade.c b/libavfilter/vf_fade.c
index a74e6d8..8036672 100644
--- a/libavfilter/vf_fade.c
+++ b/libavfilter/vf_fade.c
@@ -78,14 +78,6 @@ AVFILTER_DEFINE_CLASS(fade);
 static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     FadeContext *fade = ctx->priv;
-    static const char *shorthand[] = { "type", "start_frame", "nb_frames", NULL };
-    int ret;
-
-    fade->class = &fade_class;
-    av_opt_set_defaults(fade);
-
-    if ((ret = av_opt_set_from_string(fade, args, shorthand, "=", ":")) < 0)
-        return ret;
 
     fade->fade_per_frame = (1 << 16) / fade->nb_frames;
     if (!strcmp(fade->type, "in"))
@@ -106,13 +98,6 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     return 0;
 }
 
-static av_cold void uninit(AVFilterContext *ctx)
-{
-    FadeContext *fade = ctx->priv;
-
-    av_opt_free(fade);
-}
-
 static int query_formats(AVFilterContext *ctx)
 {
     static const enum AVPixelFormat pix_fmts[] = {
@@ -247,15 +232,17 @@ static const AVFilterPad avfilter_vf_fade_outputs[] = {
     { NULL }
 };
 
+static const char *const shorthand[] = { "type", "start_frame", "nb_frames", NULL };
+
 AVFilter avfilter_vf_fade = {
     .name          = "fade",
     .description   = NULL_IF_CONFIG_SMALL("Fade in/out input video."),
     .init          = init,
-    .uninit        = uninit,
     .priv_size     = sizeof(FadeContext),
     .query_formats = query_formats,
 
     .inputs    = avfilter_vf_fade_inputs,
     .outputs   = avfilter_vf_fade_outputs,
     .priv_class = &fade_class,
+    .shorthand = shorthand,
 };
-- 
1.7.10.4

From 494bc1be2cbabfe1738c05ffbacfab3d74ffd440 Mon Sep 17 00:00:00 2001
From: Nicolas George <nicolas.george at normalesup.org>
Date: Sat, 16 Mar 2013 21:27:34 +0100
Subject: [PATCH 10/14] lavfi/vf_fps: use standard options parsing.


Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavfilter/vf_fps.c |   11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/libavfilter/vf_fps.c b/libavfilter/vf_fps.c
index 3394252..5952538 100644
--- a/libavfilter/vf_fps.c
+++ b/libavfilter/vf_fps.c
@@ -74,20 +74,12 @@ AVFILTER_DEFINE_CLASS(fps);
 static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     FPSContext *s = ctx->priv;
-    const char *shorthand[] = { "fps", "round", NULL };
     int ret;
 
-    s->class = &fps_class;
-    av_opt_set_defaults(s);
-
-    if ((ret = av_opt_set_from_string(s, args, shorthand, "=", ":")) < 0)
-        return ret;
-
     if ((ret = av_parse_video_rate(&s->framerate, s->fps)) < 0) {
         av_log(ctx, AV_LOG_ERROR, "Error parsing framerate %s.\n", s->fps);
         return ret;
     }
-    av_opt_free(s);
 
     if (!(s->fifo = av_fifo_alloc(2*sizeof(AVFrame*))))
         return AVERROR(ENOMEM);
@@ -288,6 +280,8 @@ static const AVFilterPad avfilter_vf_fps_outputs[] = {
     { NULL }
 };
 
+static const char *const shorthand[] = { "fps", "round", NULL };
+
 AVFilter avfilter_vf_fps = {
     .name        = "fps",
     .description = NULL_IF_CONFIG_SMALL("Force constant framerate"),
@@ -300,4 +294,5 @@ AVFilter avfilter_vf_fps = {
     .inputs    = avfilter_vf_fps_inputs,
     .outputs   = avfilter_vf_fps_outputs,
     .priv_class = &fps_class,
+    .shorthand = shorthand,
 };
-- 
1.7.10.4

From f36e9d927c79100c53804df91dfd0f33bbafa576 Mon Sep 17 00:00:00 2001
From: Nicolas George <nicolas.george at normalesup.org>
Date: Sat, 16 Mar 2013 21:27:41 +0100
Subject: [PATCH 11/14] lavfi/vf_pad: use standard options parsing.


Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavfilter/vf_pad.c |   18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c
index 3f4a4f0..31420e7 100644
--- a/libavfilter/vf_pad.c
+++ b/libavfilter/vf_pad.c
@@ -111,14 +111,6 @@ AVFILTER_DEFINE_CLASS(pad);
 static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     PadContext *pad = ctx->priv;
-    static const char *shorthand[] = { "width", "height", "x", "y", "color", NULL };
-    int ret;
-
-    pad->class = &pad_class;
-    av_opt_set_defaults(pad);
-
-    if ((ret = av_opt_set_from_string(pad, args, shorthand, "=", ":")) < 0)
-        return ret;
 
     if (av_parse_color(pad->rgba_color, pad->color_str, -1, ctx) < 0)
         return AVERROR(EINVAL);
@@ -126,12 +118,6 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     return 0;
 }
 
-static av_cold void uninit(AVFilterContext *ctx)
-{
-    PadContext *pad = ctx->priv;
-    av_opt_free(pad);
-}
-
 static int config_input(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
@@ -416,17 +402,19 @@ static const AVFilterPad avfilter_vf_pad_outputs[] = {
     { NULL }
 };
 
+static const char *const shorthand[] = { "width", "height", "x", "y", "color", NULL };
+
 AVFilter avfilter_vf_pad = {
     .name          = "pad",
     .description   = NULL_IF_CONFIG_SMALL("Pad input image to width:height[:x:y[:color]] (default x and y: 0, default color: black)."),
 
     .priv_size     = sizeof(PadContext),
     .init          = init,
-    .uninit        = uninit,
     .query_formats = query_formats,
 
     .inputs    = avfilter_vf_pad_inputs,
 
     .outputs   = avfilter_vf_pad_outputs,
     .priv_class = &pad_class,
+    .shorthand = shorthand,
 };
-- 
1.7.10.4

From 8194c58d7263c0c4d2110e7a2c1ad124031dd228 Mon Sep 17 00:00:00 2001
From: Nicolas George <nicolas.george at normalesup.org>
Date: Sat, 16 Mar 2013 21:27:48 +0100
Subject: [PATCH 12/14] lavfi/vf_transpose: use standard options parsing.


Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavfilter/vf_transpose.c |   15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c
index aafb44e..ed87017 100644
--- a/libavfilter/vf_transpose.c
+++ b/libavfilter/vf_transpose.c
@@ -73,17 +73,6 @@ static const AVOption transpose_options[] = {
 
 AVFILTER_DEFINE_CLASS(transpose);
 
-static av_cold int init(AVFilterContext *ctx, const char *args)
-{
-    TransContext *trans = ctx->priv;
-    const char *shorthand[] = { "dir", "passthrough", NULL };
-
-    trans->class = &transpose_class;
-    av_opt_set_defaults(trans);
-
-    return av_opt_set_from_string(trans, args, shorthand, "=", ":");
-}
-
 static int query_formats(AVFilterContext *ctx)
 {
     AVFilterFormats *pix_fmts = NULL;
@@ -266,11 +255,12 @@ static const AVFilterPad avfilter_vf_transpose_outputs[] = {
     { NULL }
 };
 
+static const char *const shorthand[] = { "dir", "passthrough", NULL };
+
 AVFilter avfilter_vf_transpose = {
     .name      = "transpose",
     .description = NULL_IF_CONFIG_SMALL("Transpose input video."),
 
-    .init = init,
     .priv_size = sizeof(TransContext),
 
     .query_formats = query_formats,
@@ -278,4 +268,5 @@ AVFilter avfilter_vf_transpose = {
     .inputs    = avfilter_vf_transpose_inputs,
     .outputs   = avfilter_vf_transpose_outputs,
     .priv_class = &transpose_class,
+    .shorthand = shorthand,
 };
-- 
1.7.10.4

From 38c732420da4315be3f9e8d69b514dde75d5460e Mon Sep 17 00:00:00 2001
From: Nicolas George <nicolas.george at normalesup.org>
Date: Sat, 16 Mar 2013 21:27:56 +0100
Subject: [PATCH 13/14] lavfi/vf_unsharp: use standard options parsing.


Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavfilter/vf_unsharp.c |   20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/libavfilter/vf_unsharp.c b/libavfilter/vf_unsharp.c
index 0c084a8..84a14ee 100644
--- a/libavfilter/vf_unsharp.c
+++ b/libavfilter/vf_unsharp.c
@@ -169,18 +169,6 @@ static void set_filter_param(FilterParam *fp, int msize_x, int msize_y, double a
 static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     UnsharpContext *unsharp = ctx->priv;
-    static const char *shorthand[] = {
-        "luma_msize_x", "luma_msize_y", "luma_amount",
-        "chroma_msize_x", "chroma_msize_y", "chroma_amount",
-        NULL
-    };
-    int ret;
-
-    unsharp->class = &unsharp_class;
-    av_opt_set_defaults(unsharp);
-
-    if ((ret = av_opt_set_from_string(unsharp, args, shorthand, "=", ":")) < 0)
-        return ret;
 
     set_filter_param(&unsharp->luma,   unsharp->luma_msize_x,   unsharp->luma_msize_y,   unsharp->luma_amount);
     set_filter_param(&unsharp->chroma, unsharp->chroma_msize_x, unsharp->chroma_msize_y, unsharp->chroma_amount);
@@ -256,7 +244,6 @@ static av_cold void uninit(AVFilterContext *ctx)
 
     free_filter_param(&unsharp->luma);
     free_filter_param(&unsharp->chroma);
-    av_opt_free(unsharp);
 }
 
 static int filter_frame(AVFilterLink *link, AVFrame *in)
@@ -300,6 +287,12 @@ static const AVFilterPad avfilter_vf_unsharp_outputs[] = {
     { NULL }
 };
 
+static const char *const shorthand[] = {
+    "luma_msize_x", "luma_msize_y", "luma_amount",
+    "chroma_msize_x", "chroma_msize_y", "chroma_amount",
+    NULL
+};
+
 AVFilter avfilter_vf_unsharp = {
     .name      = "unsharp",
     .description = NULL_IF_CONFIG_SMALL("Sharpen or blur the input video."),
@@ -315,4 +308,5 @@ AVFilter avfilter_vf_unsharp = {
     .outputs   = avfilter_vf_unsharp_outputs,
 
     .priv_class = &unsharp_class,
+    .shorthand = shorthand,
 };
-- 
1.7.10.4

From 4fb3d39114e1a58f9bb5d5f311d30dd08ad207c7 Mon Sep 17 00:00:00 2001
From: Nicolas George <nicolas.george at normalesup.org>
Date: Sat, 16 Mar 2013 21:28:02 +0100
Subject: [PATCH 14/14] lavfi/vf_yadif: use standard options parsing.


Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavfilter/vf_yadif.c |   12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c
index 1ec51df..80076f7 100644
--- a/libavfilter/vf_yadif.c
+++ b/libavfilter/vf_yadif.c
@@ -377,7 +377,6 @@ static av_cold void uninit(AVFilterContext *ctx)
     av_frame_free(&yadif->prev);
     av_frame_free(&yadif->cur );
     av_frame_free(&yadif->next);
-    av_opt_free(yadif);
 }
 
 static int query_formats(AVFilterContext *ctx)
@@ -424,14 +423,6 @@ static int query_formats(AVFilterContext *ctx)
 static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     YADIFContext *yadif = ctx->priv;
-    static const char *shorthand[] = { "mode", "parity", "deint", NULL };
-    int ret;
-
-    yadif->class = &yadif_class;
-    av_opt_set_defaults(yadif);
-
-    if ((ret = av_opt_set_from_string(yadif, args, shorthand, "=", ":")) < 0)
-        return ret;
 
     av_log(ctx, AV_LOG_VERBOSE, "mode:%d parity:%d deint:%d\n",
            yadif->mode, yadif->parity, yadif->deint);
@@ -491,6 +482,8 @@ static const AVFilterPad avfilter_vf_yadif_outputs[] = {
     { NULL }
 };
 
+static const char *const shorthand[] = { "mode", "parity", "deint", NULL };
+
 AVFilter avfilter_vf_yadif = {
     .name          = "yadif",
     .description   = NULL_IF_CONFIG_SMALL("Deinterlace the input image."),
@@ -504,4 +497,5 @@ AVFilter avfilter_vf_yadif = {
     .outputs   = avfilter_vf_yadif_outputs,
 
     .priv_class = &yadif_class,
+    .shorthand = shorthand,
 };
-- 
1.7.10.4

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130317/9791870a/attachment.asc>


More information about the ffmpeg-devel mailing list