lavfi: rewrite nullsrc using the code in vsrc_testsrc.c

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.

This is also changing the syntax of the nullsrc source, and dropping the
framerate expression evaluation, which does not look particularly useful.
This commit is contained in:
Stefano Sabatini 2011-10-23 13:53:25 +02:00
parent 3092509b08
commit 1f4652068e
5 changed files with 56 additions and 142 deletions

View File

@ -2586,22 +2586,6 @@ testsrc=t=dc_luma
will generate a "dc_luma" test pattern.
@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
@var{width}:@var{height}:@var{timebase}.
@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).
@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.
@ -2629,7 +2613,11 @@ Some examples follow:
frei0r_src=200x200:10:partik0l=1234 [overlay]; [in][overlay] overlay
@end example
@section rgbtestsrc, testsrc
@section nullsrc, rgbtestsrc, testsrc
The @code{nullsrc} source returns 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.
The @code{rgbtestsrc} source generates an RGB test pattern useful for
detecting RGB vs BGR issues. You should see a red, green and blue
@ -2639,7 +2627,7 @@ 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,
These sources accept an optional sequence of @var{key}=@var{value} pairs,
separated by ":". The description of the accepted options follows.
@table @option
@ -2679,6 +2667,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 generates noise in the luminance plane by employing
the @code{mp=geq} filter:
@example
nullsrc=s=256x256, mp=geq=random(1)*255:128:128
@end example
@c man end VIDEO SOURCES
@chapter Video Sinks

View File

@ -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

View File

@ -29,8 +29,8 @@
#include "libavutil/rational.h"
#define LIBAVFILTER_VERSION_MAJOR 2
#define LIBAVFILTER_VERSION_MINOR 44
#define LIBAVFILTER_VERSION_MICRO 1
#define LIBAVFILTER_VERSION_MINOR 45
#define LIBAVFILTER_VERSION_MICRO 0
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
LIBAVFILTER_VERSION_MINOR, \

View File

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

View File

@ -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, return unprocessed video frames."),
.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)