]> git.sesse.net Git - ffmpeg/blob - libavfilter/vsrc_nullsrc.c
vsrc_buffer: FIx incompatible pointer type warning
[ffmpeg] / libavfilter / vsrc_nullsrc.c
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg 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.
8  *
9  * FFmpeg 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.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 /**
20  * @file
21  * null video source
22  */
23
24 #include "libavutil/avstring.h"
25 #include "libavutil/eval.h"
26 #include "libavutil/mathematics.h"
27 #include "libavutil/parseutils.h"
28 #include "avfilter.h"
29
30 static const char *var_names[] = {
31     "AVTB",   /* default timebase 1/AV_TIME_BASE */
32     NULL
33 };
34
35 enum var_name {
36     VAR_AVTB,
37     VAR_VARS_NB
38 };
39
40 typedef struct {
41     int w, h;
42     char tb_expr[256];
43     double var_values[VAR_VARS_NB];
44 } NullContext;
45
46 static int init(AVFilterContext *ctx, const char *args, void *opaque)
47 {
48     NullContext *priv = ctx->priv;
49
50     priv->w = 352;
51     priv->h = 288;
52     av_strlcpy(priv->tb_expr, "AVTB", sizeof(priv->tb_expr));
53
54     if (args)
55         sscanf(args, "%d:%d:%255[^:]", &priv->w, &priv->h, priv->tb_expr);
56
57     if (priv->w <= 0 || priv->h <= 0) {
58         av_log(ctx, AV_LOG_ERROR, "Non-positive size values are not acceptable.\n");
59         return AVERROR(EINVAL);
60     }
61
62     return 0;
63 }
64
65 static int config_props(AVFilterLink *outlink)
66 {
67     AVFilterContext *ctx = outlink->src;
68     NullContext *priv = ctx->priv;
69     AVRational tb;
70     int ret;
71     double res;
72
73     priv->var_values[VAR_AVTB] = av_q2d(AV_TIME_BASE_Q);
74
75     if ((ret = av_expr_parse_and_eval(&res, priv->tb_expr, var_names, priv->var_values,
76                                       NULL, NULL, NULL, NULL, NULL, 0, NULL)) < 0) {
77         av_log(ctx, AV_LOG_ERROR, "Invalid expression '%s' for timebase.\n", priv->tb_expr);
78         return ret;
79     }
80     tb = av_d2q(res, INT_MAX);
81     if (tb.num <= 0 || tb.den <= 0) {
82         av_log(ctx, AV_LOG_ERROR,
83                "Invalid non-positive value for the timebase %d/%d.\n",
84                tb.num, tb.den);
85         return AVERROR(EINVAL);
86     }
87
88     outlink->w = priv->w;
89     outlink->h = priv->h;
90     outlink->time_base = tb;
91
92     av_log(outlink->src, AV_LOG_INFO, "w:%d h:%d tb:%d/%d\n", priv->w, priv->h,
93            tb.num, tb.den);
94
95     return 0;
96 }
97
98 static int request_frame(AVFilterLink *link)
99 {
100     return -1;
101 }
102
103 AVFilter avfilter_vsrc_nullsrc = {
104     .name        = "nullsrc",
105     .description = NULL_IF_CONFIG_SMALL("Null video source, never return images."),
106
107     .init       = init,
108     .priv_size = sizeof(NullContext),
109
110     .inputs    = (AVFilterPad[]) {{ .name = NULL}},
111
112     .outputs   = (AVFilterPad[]) {
113         {
114             .name            = "default",
115             .type            = AVMEDIA_TYPE_VIDEO,
116             .config_props    = config_props,
117             .request_frame   = request_frame,
118         },
119         { .name = NULL}
120     },
121 };