[FFmpeg-devel] [PATCH 1/5] lavfi: remplace passthrough_filter_frame with a flag.

Clément Bœsch ubitux at gmail.com
Fri May 10 17:49:46 CEST 2013


On Thu, May 09, 2013 at 01:53:23AM +0200, Clément Bœsch wrote:
> With the introduction of AVFilterContext->is_disabled, we can simplify
> the custom passthrough mode in filters.
> ---
>  libavfilter/af_apad.c    |  3 +--
>  libavfilter/avfilter.c   |  6 +++---
>  libavfilter/avfilter.h   | 19 ++++++-------------
>  libavfilter/version.h    |  4 ++--
>  libavfilter/vf_overlay.c | 25 ++++---------------------
>  5 files changed, 16 insertions(+), 41 deletions(-)
> 

New version attached.

-- 
Clément B.
-------------- next part --------------
From b0c4e23be426386a2fb6a1a974a5fff751c58e2d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <ubitux at gmail.com>
Date: Thu, 9 May 2013 01:04:41 +0200
Subject: [PATCH 1/5] lavfi: replace passthrough_filter_frame with a flag.

With the introduction of AVFilterContext->is_disabled, we can simplify
the custom passthrough mode in filters.

This commit is technically a compat break, but the timeline was
introduced very recently.
---
 libavfilter/af_apad.c              |  3 +--
 libavfilter/af_volume.c            |  2 +-
 libavfilter/avfilter.c             |  6 +++---
 libavfilter/avfilter.h             | 26 ++++++++++++--------------
 libavfilter/version.h              |  4 ++--
 libavfilter/vf_boxblur.c           |  2 +-
 libavfilter/vf_colorbalance.c      |  2 +-
 libavfilter/vf_colorchannelmixer.c |  2 +-
 libavfilter/vf_colormatrix.c       |  2 +-
 libavfilter/vf_cropdetect.c        |  2 +-
 libavfilter/vf_curves.c            |  2 +-
 libavfilter/vf_delogo.c            |  2 +-
 libavfilter/vf_drawbox.c           |  2 +-
 libavfilter/vf_edgedetect.c        |  2 +-
 libavfilter/vf_gradfun.c           |  2 +-
 libavfilter/vf_histeq.c            |  2 +-
 libavfilter/vf_hue.c               |  2 +-
 libavfilter/vf_lut.c               |  2 +-
 libavfilter/vf_noise.c             |  2 +-
 libavfilter/vf_overlay.c           | 25 ++++---------------------
 libavfilter/vf_pp.c                |  2 +-
 libavfilter/vf_removelogo.c        |  2 +-
 libavfilter/vf_smartblur.c         |  2 +-
 libavfilter/vf_unsharp.c           |  2 +-
 24 files changed, 41 insertions(+), 61 deletions(-)

diff --git a/libavfilter/af_apad.c b/libavfilter/af_apad.c
index 265b76a..c863792 100644
--- a/libavfilter/af_apad.c
+++ b/libavfilter/af_apad.c
@@ -131,7 +131,6 @@ static const AVFilterPad apad_inputs[] = {
         .name         = "default",
         .type         = AVMEDIA_TYPE_AUDIO,
         .filter_frame = filter_frame,
-        .passthrough_filter_frame = filter_frame,
     },
     { NULL },
 };
@@ -153,5 +152,5 @@ AVFilter avfilter_af_apad = {
     .inputs        = apad_inputs,
     .outputs       = apad_outputs,
     .priv_class    = &apad_class,
-    .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags         = AVFILTER_FLAG_INTERNAL_TIMELINE,
 };
diff --git a/libavfilter/af_volume.c b/libavfilter/af_volume.c
index b7aec8d..79054af 100644
--- a/libavfilter/af_volume.c
+++ b/libavfilter/af_volume.c
@@ -296,5 +296,5 @@ AVFilter avfilter_af_volume = {
     .init           = init,
     .inputs         = avfilter_af_volume_inputs,
     .outputs        = avfilter_af_volume_outputs,
-    .flags          = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags          = AVFILTER_FLAG_GENERIC_TIMELINE,
 };
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 3f94dde..6676a58 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -995,9 +995,9 @@ static int ff_filter_frame_framed(AVFilterLink *link, AVFrame *frame)
         dstctx->var_values[VAR_POS] = pos == -1 ? NAN : pos;
 
         dstctx->is_disabled = !av_expr_eval(dstctx->enable, dstctx->var_values, NULL);
-        if (dstctx->is_disabled)
-            filter_frame = dst->passthrough_filter_frame ? dst->passthrough_filter_frame
-                                                         : default_filter_frame;
+        if (dstctx->is_disabled &&
+            (dstctx->filter->flags & AVFILTER_FLAG_GENERIC_TIMELINE))
+            filter_frame = default_filter_frame;
     }
     ret = filter_frame(link, out);
     link->frame_count++;
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index a79c86c..8695a36 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -385,19 +385,6 @@ struct AVFilterPad {
     int needs_fifo;
 
     int needs_writable;
-
-    /**
-     * Passthrough filtering callback.
-     *
-     * If a filter supports timeline editing (in case
-     * AVFILTER_FLAG_SUPPORT_TIMELINE is enabled) then it can implement a
-     * custom passthrough callback to update its local context (for example to
-     * keep a frame reference, or simply send the filter to a custom outlink).
-     * The filter must not do any change to the frame in this callback.
-     *
-     * Input pads only.
-     */
-    int (*passthrough_filter_frame)(AVFilterLink *link, AVFrame *frame);
 };
 #endif
 
@@ -446,7 +433,18 @@ enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx);
  * to enable or disable a filter in the timeline. Filters supporting this
  * option have this flag set.
  */
-#define AVFILTER_FLAG_SUPPORT_TIMELINE      (1 << 16)
+#define AVFILTER_FLAG_GENERIC_TIMELINE      (1 << 16)
+/**
+ * Same as AVFILTER_FLAG_GENERIC_TIMELINE, except that the filter will have its
+ * inpad->filter_frame() callback(s) naturally called (and will use
+ * AVFilterContext->is_disabled internally).
+ */
+#define AVFILTER_FLAG_INTERNAL_TIMELINE     (1 << 17)
+/**
+ * Handy flag to test whether the filter supports or no the timeline feature
+ * (internally or generically)
+ */
+#define AVFILTER_FLAG_SUPPORT_TIMELINE (AVFILTER_FLAG_GENERIC_TIMELINE | AVFILTER_FLAG_INTERNAL_TIMELINE)
 
 /**
  * Filter definition. This defines the pads a filter contains, and all the
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 0773ff7..74e8bce 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -29,8 +29,8 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFILTER_VERSION_MAJOR  3
-#define LIBAVFILTER_VERSION_MINOR  63
-#define LIBAVFILTER_VERSION_MICRO 101
+#define LIBAVFILTER_VERSION_MINOR  64
+#define LIBAVFILTER_VERSION_MICRO 100
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
                                                LIBAVFILTER_VERSION_MINOR, \
diff --git a/libavfilter/vf_boxblur.c b/libavfilter/vf_boxblur.c
index a8a2014..3ac81f0 100644
--- a/libavfilter/vf_boxblur.c
+++ b/libavfilter/vf_boxblur.c
@@ -383,5 +383,5 @@ AVFilter avfilter_vf_boxblur = {
 
     .inputs    = avfilter_vf_boxblur_inputs,
     .outputs   = avfilter_vf_boxblur_outputs,
-    .flags     = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags     = AVFILTER_FLAG_GENERIC_TIMELINE,
 };
diff --git a/libavfilter/vf_colorbalance.c b/libavfilter/vf_colorbalance.c
index b09d170..33d9f6c 100644
--- a/libavfilter/vf_colorbalance.c
+++ b/libavfilter/vf_colorbalance.c
@@ -209,5 +209,5 @@ AVFilter avfilter_vf_colorbalance = {
     .query_formats = query_formats,
     .inputs        = colorbalance_inputs,
     .outputs       = colorbalance_outputs,
-    .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags         = AVFILTER_FLAG_GENERIC_TIMELINE,
 };
diff --git a/libavfilter/vf_colorchannelmixer.c b/libavfilter/vf_colorchannelmixer.c
index 343faac..fabd1f9 100644
--- a/libavfilter/vf_colorchannelmixer.c
+++ b/libavfilter/vf_colorchannelmixer.c
@@ -356,5 +356,5 @@ AVFilter avfilter_vf_colorchannelmixer = {
     .query_formats = query_formats,
     .inputs        = colorchannelmixer_inputs,
     .outputs       = colorchannelmixer_outputs,
-    .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags         = AVFILTER_FLAG_GENERIC_TIMELINE,
 };
diff --git a/libavfilter/vf_colormatrix.c b/libavfilter/vf_colormatrix.c
index 8db5fcf..fb74b0a 100644
--- a/libavfilter/vf_colormatrix.c
+++ b/libavfilter/vf_colormatrix.c
@@ -385,5 +385,5 @@ AVFilter avfilter_vf_colormatrix = {
     .inputs        = colormatrix_inputs,
     .outputs       = colormatrix_outputs,
     .priv_class    = &colormatrix_class,
-    .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags         = AVFILTER_FLAG_GENERIC_TIMELINE,
 };
diff --git a/libavfilter/vf_cropdetect.c b/libavfilter/vf_cropdetect.c
index cb170d0..561ec94 100644
--- a/libavfilter/vf_cropdetect.c
+++ b/libavfilter/vf_cropdetect.c
@@ -233,5 +233,5 @@ AVFilter avfilter_vf_cropdetect = {
     .query_formats = query_formats,
     .inputs    = avfilter_vf_cropdetect_inputs,
     .outputs   = avfilter_vf_cropdetect_outputs,
-    .flags     = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags     = AVFILTER_FLAG_GENERIC_TIMELINE,
 };
diff --git a/libavfilter/vf_curves.c b/libavfilter/vf_curves.c
index 482a046..5f18fce 100644
--- a/libavfilter/vf_curves.c
+++ b/libavfilter/vf_curves.c
@@ -548,5 +548,5 @@ AVFilter avfilter_vf_curves = {
     .inputs        = curves_inputs,
     .outputs       = curves_outputs,
     .priv_class    = &curves_class,
-    .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags         = AVFILTER_FLAG_GENERIC_TIMELINE,
 };
diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c
index b644190..4d77576 100644
--- a/libavfilter/vf_delogo.c
+++ b/libavfilter/vf_delogo.c
@@ -271,5 +271,5 @@ AVFilter avfilter_vf_delogo = {
 
     .inputs    = avfilter_vf_delogo_inputs,
     .outputs   = avfilter_vf_delogo_outputs,
-    .flags     = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags     = AVFILTER_FLAG_GENERIC_TIMELINE,
 };
diff --git a/libavfilter/vf_drawbox.c b/libavfilter/vf_drawbox.c
index c2ffbf3..e294eca 100644
--- a/libavfilter/vf_drawbox.c
+++ b/libavfilter/vf_drawbox.c
@@ -181,5 +181,5 @@ AVFilter avfilter_vf_drawbox = {
     .query_formats   = query_formats,
     .inputs    = avfilter_vf_drawbox_inputs,
     .outputs   = avfilter_vf_drawbox_outputs,
-    .flags     = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags     = AVFILTER_FLAG_GENERIC_TIMELINE,
 };
diff --git a/libavfilter/vf_edgedetect.c b/libavfilter/vf_edgedetect.c
index b4698a8..a48c72f 100644
--- a/libavfilter/vf_edgedetect.c
+++ b/libavfilter/vf_edgedetect.c
@@ -327,5 +327,5 @@ AVFilter avfilter_vf_edgedetect = {
     .inputs        = edgedetect_inputs,
     .outputs       = edgedetect_outputs,
     .priv_class    = &edgedetect_class,
-    .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags         = AVFILTER_FLAG_GENERIC_TIMELINE,
 };
diff --git a/libavfilter/vf_gradfun.c b/libavfilter/vf_gradfun.c
index 52c67ff..3277a60 100644
--- a/libavfilter/vf_gradfun.c
+++ b/libavfilter/vf_gradfun.c
@@ -260,5 +260,5 @@ AVFilter avfilter_vf_gradfun = {
     .query_formats = query_formats,
     .inputs        = avfilter_vf_gradfun_inputs,
     .outputs       = avfilter_vf_gradfun_outputs,
-    .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags         = AVFILTER_FLAG_GENERIC_TIMELINE,
 };
diff --git a/libavfilter/vf_histeq.c b/libavfilter/vf_histeq.c
index a4166c6..dd28469 100644
--- a/libavfilter/vf_histeq.c
+++ b/libavfilter/vf_histeq.c
@@ -279,5 +279,5 @@ AVFilter avfilter_vf_histeq = {
     .inputs        = histeq_inputs,
     .outputs       = histeq_outputs,
     .priv_class    = &histeq_class,
-    .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags         = AVFILTER_FLAG_GENERIC_TIMELINE,
 };
diff --git a/libavfilter/vf_hue.c b/libavfilter/vf_hue.c
index cba39d0..a36a3ad 100644
--- a/libavfilter/vf_hue.c
+++ b/libavfilter/vf_hue.c
@@ -373,5 +373,5 @@ AVFilter avfilter_vf_hue = {
     .inputs          = hue_inputs,
     .outputs         = hue_outputs,
     .priv_class      = &hue_class,
-    .flags           = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags           = AVFILTER_FLAG_GENERIC_TIMELINE,
 };
diff --git a/libavfilter/vf_lut.c b/libavfilter/vf_lut.c
index d544419..658607a 100644
--- a/libavfilter/vf_lut.c
+++ b/libavfilter/vf_lut.c
@@ -353,7 +353,7 @@ static const AVFilterPad outputs[] = {
                                                                         \
         .inputs        = inputs,                                        \
         .outputs       = outputs,                                       \
-        .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE,                \
+        .flags         = AVFILTER_FLAG_GENERIC_TIMELINE,                \
     }
 
 #if CONFIG_LUT_FILTER
diff --git a/libavfilter/vf_noise.c b/libavfilter/vf_noise.c
index da418fe..d62212e 100644
--- a/libavfilter/vf_noise.c
+++ b/libavfilter/vf_noise.c
@@ -471,5 +471,5 @@ AVFilter avfilter_vf_noise = {
     .inputs        = noise_inputs,
     .outputs       = noise_outputs,
     .priv_class    = &noise_class,
-    .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags         = AVFILTER_FLAG_GENERIC_TIMELINE,
 };
diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
index 6494bad..43f58c3 100644
--- a/libavfilter/vf_overlay.c
+++ b/libavfilter/vf_overlay.c
@@ -88,7 +88,6 @@ enum var_name {
 typedef struct {
     const AVClass *class;
     int x, y;                   ///< position of overlayed picture
-    int enable;                 ///< tells if blending is enabled
 
     int allow_packed_rgb;
     uint8_t frame_requested;
@@ -597,7 +596,7 @@ static int try_filter_frame(AVFilterContext *ctx, AVFrame *mainpic)
                    over->var_values[VAR_X], over->x,
                    over->var_values[VAR_Y], over->y);
         }
-        if (over->enable)
+        if (!ctx->is_disabled)
             blend_image(ctx, mainpic, over->overpicref, over->x, over->y);
 
     }
@@ -663,20 +662,6 @@ static int filter_frame_over(AVFilterLink *inlink, AVFrame *inpicref)
     return ret == AVERROR(EAGAIN) ? 0 : ret;
 }
 
-#define DEF_FILTER_FRAME(name, mode, enable_value)                              \
-static int filter_frame_##name##_##mode(AVFilterLink *inlink, AVFrame *frame)   \
-{                                                                               \
-    AVFilterContext *ctx = inlink->dst;                                         \
-    OverlayContext *over = ctx->priv;                                           \
-    over->enable = enable_value;                                                \
-    return filter_frame_##name(inlink, frame);                                  \
-}
-
-DEF_FILTER_FRAME(main, enabled,  1);
-DEF_FILTER_FRAME(main, disabled, 0);
-DEF_FILTER_FRAME(over, enabled,  1);
-DEF_FILTER_FRAME(over, disabled, 0);
-
 static int request_frame(AVFilterLink *outlink)
 {
     AVFilterContext *ctx = outlink->src;
@@ -734,16 +719,14 @@ static const AVFilterPad avfilter_vf_overlay_inputs[] = {
         .type         = AVMEDIA_TYPE_VIDEO,
         .get_video_buffer = ff_null_get_video_buffer,
         .config_props = config_input_main,
-        .filter_frame             = filter_frame_main_enabled,
-        .passthrough_filter_frame = filter_frame_main_disabled,
+        .filter_frame = filter_frame_main,
         .needs_writable = 1,
     },
     {
         .name         = "overlay",
         .type         = AVMEDIA_TYPE_VIDEO,
         .config_props = config_input_overlay,
-        .filter_frame             = filter_frame_over_enabled,
-        .passthrough_filter_frame = filter_frame_over_disabled,
+        .filter_frame = filter_frame_over,
     },
     { NULL }
 };
@@ -773,5 +756,5 @@ AVFilter avfilter_vf_overlay = {
 
     .inputs    = avfilter_vf_overlay_inputs,
     .outputs   = avfilter_vf_overlay_outputs,
-    .flags     = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags     = AVFILTER_FLAG_INTERNAL_TIMELINE,
 };
diff --git a/libavfilter/vf_pp.c b/libavfilter/vf_pp.c
index 0571cfc..e2b73f9 100644
--- a/libavfilter/vf_pp.c
+++ b/libavfilter/vf_pp.c
@@ -180,5 +180,5 @@ AVFilter avfilter_vf_pp = {
     .outputs         = pp_outputs,
     .process_command = pp_process_command,
     .priv_class      = &pp_class,
-    .flags           = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags           = AVFILTER_FLAG_GENERIC_TIMELINE,
 };
diff --git a/libavfilter/vf_removelogo.c b/libavfilter/vf_removelogo.c
index 589c43a..9260843 100644
--- a/libavfilter/vf_removelogo.c
+++ b/libavfilter/vf_removelogo.c
@@ -578,5 +578,5 @@ AVFilter avfilter_vf_removelogo = {
     .inputs        = removelogo_inputs,
     .outputs       = removelogo_outputs,
     .priv_class    = &removelogo_class,
-    .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags         = AVFILTER_FLAG_GENERIC_TIMELINE,
 };
diff --git a/libavfilter/vf_smartblur.c b/libavfilter/vf_smartblur.c
index daf7451..b881dcf 100644
--- a/libavfilter/vf_smartblur.c
+++ b/libavfilter/vf_smartblur.c
@@ -302,5 +302,5 @@ AVFilter avfilter_vf_smartblur = {
     .inputs        = smartblur_inputs,
     .outputs       = smartblur_outputs,
     .priv_class    = &smartblur_class,
-    .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags         = AVFILTER_FLAG_GENERIC_TIMELINE,
 };
diff --git a/libavfilter/vf_unsharp.c b/libavfilter/vf_unsharp.c
index fc0628e..dfe35b21 100644
--- a/libavfilter/vf_unsharp.c
+++ b/libavfilter/vf_unsharp.c
@@ -316,5 +316,5 @@ AVFilter avfilter_vf_unsharp = {
 
     .inputs    = avfilter_vf_unsharp_inputs,
     .outputs   = avfilter_vf_unsharp_outputs,
-    .flags     = AVFILTER_FLAG_SUPPORT_TIMELINE,
+    .flags     = AVFILTER_FLAG_GENERIC_TIMELINE,
 };
-- 
1.8.2.2

-------------- 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/20130510/16808cfb/attachment.asc>


More information about the ffmpeg-devel mailing list