[FFmpeg-devel] [PATCH] lavfi: move nullsrc code to vsrc_testsrc.c

Stefano Sabatini stefasab at gmail.com
Sun Oct 23 19:08:38 CEST 2011


Factorize code, extend the functionality of the filter, and make it
return empty buffers. This is useful for filters which ignore the input
frames content.

Note that this is also changing the syntax for the nullsrc source.
---
 doc/filters.texi           |   31 +++++-------
 libavfilter/Makefile       |    2 +-
 libavfilter/vsrc_nullsrc.c |  121 --------------------------------------------
 libavfilter/vsrc_testsrc.c |   40 ++++++++++++++
 4 files changed, 54 insertions(+), 140 deletions(-)
 delete mode 100644 libavfilter/vsrc_nullsrc.c

diff --git a/doc/filters.texi b/doc/filters.texi
index b389ba2..8a7437e 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -2575,22 +2575,6 @@ testsrc=t=dc_luma
 
 will generate a "dc_luma" test pattern.
 
- at section nullsrc
-
-Null video source, never return images. It is mainly useful as a
-template and to be employed in analysis / debugging tools.
-
-It accepts as optional parameter a string of the form
- at var{width}:@var{height}:@var{timebase}.
-
- at var{width} and @var{height} specify the size of the configured
-source. The default values of @var{width} and @var{height} are
-respectively 352 and 288 (corresponding to the CIF size format).
-
- at var{timebase} specifies an arithmetic expression representing a
-timebase. The expression can contain the constant
-"AVTB" (the default timebase), and defaults to the value "AVTB".
-
 @section frei0r_src
 
 Provide a frei0r source.
@@ -2618,7 +2602,7 @@ Some examples follow:
 frei0r_src=200x200:10:partik0l=1234 [overlay]; [in][overlay] overlay
 @end example
 
- at section rgbtestsrc, testsrc
+ at section nullsrc, rgbtestsrc, testsrc
 
 The @code{rgbtestsrc} source generates an RGB test pattern useful for
 detecting RGB vs BGR issues. You should see a red, green and blue
@@ -2628,7 +2612,11 @@ The @code{testsrc} source generates a test video pattern, showing a
 color pattern, a scrolling gradient and a timestamp. This is mainly
 intended for testing purposes.
 
-Both sources accept an optional sequence of @var{key}=@var{value} pairs,
+The @code{nullsrc} null video source. return unprocessed video
+frames. It is mainly useful to be employed in analysis / debugging
+tools, or as the source for filters which ignore the input data.
+
+These sources accept an optional sequence of @var{key}=@var{value} pairs,
 separated by ":". The description of the accepted options follows.
 
 @table @option
@@ -2668,6 +2656,13 @@ testsrc=duration=5.3:size=qcif:rate=10
 will generate a video with a duration of 5.3 seconds, with size
 176x144 and a framerate of 10 frames per second.
 
+If the input content is to be ignored, @code{nullsrc} can be used. The
+following command generate noise in the luminance plane by employing
+the @code{mp=geq} filter:
+ at example
+nullsrc=s=256x256, mp=geq=random(1)*255:128:128
+ at end example
+
 @c man end VIDEO SOURCES
 
 @chapter Video Sinks
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 08a69e4..cfe5d74 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -84,7 +84,7 @@ OBJS-$(CONFIG_COLOR_FILTER)                  += vsrc_color.o
 OBJS-$(CONFIG_FREI0R_SRC_FILTER)             += vf_frei0r.o
 OBJS-$(CONFIG_MOVIE_FILTER)                  += src_movie.o
 OBJS-$(CONFIG_MPTESTSRC_FILTER)              += vsrc_mptestsrc.o
-OBJS-$(CONFIG_NULLSRC_FILTER)                += vsrc_nullsrc.o
+OBJS-$(CONFIG_NULLSRC_FILTER)                += vsrc_testsrc.o
 OBJS-$(CONFIG_RGBTESTSRC_FILTER)             += vsrc_testsrc.o
 OBJS-$(CONFIG_TESTSRC_FILTER)                += vsrc_testsrc.o
 
diff --git a/libavfilter/vsrc_nullsrc.c b/libavfilter/vsrc_nullsrc.c
deleted file mode 100644
index b6d3567..0000000
--- a/libavfilter/vsrc_nullsrc.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file
- * null video source
- */
-
-#include "libavutil/avstring.h"
-#include "libavutil/eval.h"
-#include "libavutil/mathematics.h"
-#include "libavutil/parseutils.h"
-#include "avfilter.h"
-
-static const char *var_names[] = {
-    "AVTB",   /* default timebase 1/AV_TIME_BASE */
-    NULL
-};
-
-enum var_name {
-    VAR_AVTB,
-    VAR_VARS_NB
-};
-
-typedef struct {
-    int w, h;
-    char tb_expr[256];
-    double var_values[VAR_VARS_NB];
-} NullContext;
-
-static int init(AVFilterContext *ctx, const char *args, void *opaque)
-{
-    NullContext *priv = ctx->priv;
-
-    priv->w = 352;
-    priv->h = 288;
-    av_strlcpy(priv->tb_expr, "AVTB", sizeof(priv->tb_expr));
-
-    if (args)
-        sscanf(args, "%d:%d:%255[^:]", &priv->w, &priv->h, priv->tb_expr);
-
-    if (priv->w <= 0 || priv->h <= 0) {
-        av_log(ctx, AV_LOG_ERROR, "Non-positive size values are not acceptable.\n");
-        return AVERROR(EINVAL);
-    }
-
-    return 0;
-}
-
-static int config_props(AVFilterLink *outlink)
-{
-    AVFilterContext *ctx = outlink->src;
-    NullContext *priv = ctx->priv;
-    AVRational tb;
-    int ret;
-    double res;
-
-    priv->var_values[VAR_AVTB] = av_q2d(AV_TIME_BASE_Q);
-
-    if ((ret = av_expr_parse_and_eval(&res, priv->tb_expr, var_names, priv->var_values,
-                                      NULL, NULL, NULL, NULL, NULL, 0, NULL)) < 0) {
-        av_log(ctx, AV_LOG_ERROR, "Invalid expression '%s' for timebase.\n", priv->tb_expr);
-        return ret;
-    }
-    tb = av_d2q(res, INT_MAX);
-    if (tb.num <= 0 || tb.den <= 0) {
-        av_log(ctx, AV_LOG_ERROR,
-               "Invalid non-positive value for the timebase %d/%d.\n",
-               tb.num, tb.den);
-        return AVERROR(EINVAL);
-    }
-
-    outlink->w = priv->w;
-    outlink->h = priv->h;
-    outlink->time_base = tb;
-
-    av_log(outlink->src, AV_LOG_INFO, "w:%d h:%d tb:%d/%d\n", priv->w, priv->h,
-           tb.num, tb.den);
-
-    return 0;
-}
-
-static int request_frame(AVFilterLink *link)
-{
-    return -1;
-}
-
-AVFilter avfilter_vsrc_nullsrc = {
-    .name        = "nullsrc",
-    .description = NULL_IF_CONFIG_SMALL("Null video source, never return images."),
-
-    .init       = init,
-    .priv_size = sizeof(NullContext),
-
-    .inputs    = (AVFilterPad[]) {{ .name = NULL}},
-
-    .outputs   = (AVFilterPad[]) {
-        {
-            .name            = "default",
-            .type            = AVMEDIA_TYPE_VIDEO,
-            .config_props    = config_props,
-            .request_frame   = request_frame,
-        },
-        { .name = NULL}
-    },
-};
diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c
index 2447cb3..904cc33 100644
--- a/libavfilter/vsrc_testsrc.c
+++ b/libavfilter/vsrc_testsrc.c
@@ -148,6 +148,46 @@ static int request_frame(AVFilterLink *outlink)
     return 0;
 }
 
+#if CONFIG_NULLSRC_FILTER
+
+static const char *nullsrc_get_name(void *ctx)
+{
+    return "nullsrc";
+}
+
+static const AVClass nullsrc_class = {
+    .class_name = "NullSourceContext",
+    .item_name  = nullsrc_get_name,
+    .option     = testsrc_options,
+};
+
+static void nullsrc_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref) { }
+
+static av_cold int nullsrc_init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+    TestSourceContext *test = ctx->priv;
+
+    test->class = &nullsrc_class;
+    test->fill_picture_fn = nullsrc_fill_picture;
+    return init(ctx, args, opaque);
+}
+
+AVFilter avfilter_vsrc_nullsrc = {
+    .name        = "nullsrc",
+    .description = NULL_IF_CONFIG_SMALL("Null video source."),
+    .init       = nullsrc_init,
+    .priv_size  = sizeof(TestSourceContext),
+
+    .inputs    = (AVFilterPad[]) {{ .name = NULL}},
+    .outputs   = (AVFilterPad[]) {{ .name = "default",
+                                    .type = AVMEDIA_TYPE_VIDEO,
+                                    .request_frame = request_frame,
+                                    .config_props  = config_props, },
+                                  { .name = NULL}},
+};
+
+#endif /* CONFIG_NULLSRC_FILTER */
+
 #if CONFIG_TESTSRC_FILTER
 
 static const char *testsrc_get_name(void *ctx)
-- 
1.7.4.1



More information about the ffmpeg-devel mailing list