2 * This file is part of Libav.
4 * Libav is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * Libav is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with Libav; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "libavutil/avstring.h"
27 #include "libavutil/eval.h"
28 #include "libavutil/internal.h"
29 #include "libavutil/mathematics.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/parseutils.h"
36 static const char *const var_names[] = {
40 "AVTB", /* default timebase 1/AV_TIME_BASE */
52 typedef struct NullContext {
56 double var_values[VAR_VARS_NB];
59 static int config_props(AVFilterLink *outlink)
61 AVFilterContext *ctx = outlink->src;
62 NullContext *priv = ctx->priv;
67 priv->var_values[VAR_E] = M_E;
68 priv->var_values[VAR_PHI] = M_PHI;
69 priv->var_values[VAR_PI] = M_PI;
70 priv->var_values[VAR_AVTB] = av_q2d(AV_TIME_BASE_Q);
72 if ((ret = av_expr_parse_and_eval(&res, priv->tb_expr, var_names, priv->var_values,
73 NULL, NULL, NULL, NULL, NULL, 0, NULL)) < 0) {
74 av_log(ctx, AV_LOG_ERROR, "Invalid expression '%s' for timebase.\n", priv->tb_expr);
77 tb = av_d2q(res, INT_MAX);
78 if (tb.num <= 0 || tb.den <= 0) {
79 av_log(ctx, AV_LOG_ERROR,
80 "Invalid non-positive value for the timebase %d/%d.\n",
82 return AVERROR(EINVAL);
87 outlink->time_base = tb;
89 av_log(outlink->src, AV_LOG_VERBOSE, "w:%d h:%d tb:%d/%d\n", priv->w, priv->h,
95 static int request_frame(AVFilterLink *link)
100 #define OFFSET(x) offsetof(NullContext, x)
101 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM
102 static const AVOption options[] = {
103 { "width", NULL, OFFSET(w), AV_OPT_TYPE_INT, { .i64 = 352 }, 1, INT_MAX, FLAGS },
104 { "height", NULL, OFFSET(h), AV_OPT_TYPE_INT, { .i64 = 288 }, 1, INT_MAX, FLAGS },
105 { "timebase", NULL, OFFSET(tb_expr), AV_OPT_TYPE_STRING, { .str = "AVTB" }, 0, 0, FLAGS },
109 static const AVClass nullsrc_class = {
110 .class_name = "nullsrc",
111 .item_name = av_default_item_name,
113 .version = LIBAVUTIL_VERSION_INT,
116 static const AVFilterPad avfilter_vsrc_nullsrc_outputs[] = {
119 .type = AVMEDIA_TYPE_VIDEO,
120 .config_props = config_props,
121 .request_frame = request_frame,
126 AVFilter ff_vsrc_nullsrc = {
128 .description = NULL_IF_CONFIG_SMALL("Null video source, never return images."),
130 .priv_size = sizeof(NullContext),
131 .priv_class = &nullsrc_class,
135 .outputs = avfilter_vsrc_nullsrc_outputs,