ffmpeg / libavfilter / vsrc_nullsrc.c @ e4852fb3
History | View | Annotate | Download (3.34 KB)
1 | dd08b83c | Stefano Sabatini | /*
|
---|---|---|---|
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 | ba87f080 | Diego Biurrun | * @file
|
21 | dd08b83c | Stefano Sabatini | * null video source
|
22 | */
|
||
23 | |||
24 | 16134b7c | Stefano Sabatini | #include "libavutil/avstring.h" |
25 | #include "libavutil/eval.h" |
||
26 | #include "libavcore/parseutils.h" |
||
27 | dd08b83c | Stefano Sabatini | #include "avfilter.h" |
28 | |||
29 | 16134b7c | Stefano Sabatini | static const char *var_names[] = { |
30 | "E",
|
||
31 | "PHI",
|
||
32 | "PI",
|
||
33 | "AVTB", /* default timebase 1/AV_TIME_BASE */ |
||
34 | NULL
|
||
35 | }; |
||
36 | |||
37 | enum var_name {
|
||
38 | VAR_E, |
||
39 | VAR_PHI, |
||
40 | VAR_PI, |
||
41 | VAR_AVTB, |
||
42 | VAR_VARS_NB |
||
43 | }; |
||
44 | |||
45 | dd08b83c | Stefano Sabatini | typedef struct { |
46 | int w, h;
|
||
47 | 16134b7c | Stefano Sabatini | char tb_expr[256]; |
48 | double var_values[VAR_VARS_NB];
|
||
49 | dd08b83c | Stefano Sabatini | } NullContext; |
50 | |||
51 | static int init(AVFilterContext *ctx, const char *args, void *opaque) |
||
52 | { |
||
53 | NullContext *priv = ctx->priv; |
||
54 | |||
55 | priv->w = 352;
|
||
56 | priv->h = 288;
|
||
57 | 16134b7c | Stefano Sabatini | av_strlcpy(priv->tb_expr, "AVTB", sizeof(priv->tb_expr)); |
58 | dd08b83c | Stefano Sabatini | |
59 | if (args)
|
||
60 | 16134b7c | Stefano Sabatini | sscanf(args, "%d:%d:%255[^:]", &priv->w, &priv->h, priv->tb_expr);
|
61 | dd08b83c | Stefano Sabatini | |
62 | if (priv->w <= 0 || priv->h <= 0) { |
||
63 | av_log(ctx, AV_LOG_ERROR, "Non-positive size values are not acceptable.\n");
|
||
64 | ab3efd00 | Stefano Sabatini | return AVERROR(EINVAL);
|
65 | dd08b83c | Stefano Sabatini | } |
66 | |||
67 | return 0; |
||
68 | } |
||
69 | |||
70 | static int config_props(AVFilterLink *outlink) |
||
71 | { |
||
72 | 16134b7c | Stefano Sabatini | AVFilterContext *ctx = outlink->src; |
73 | NullContext *priv = ctx->priv; |
||
74 | AVRational tb; |
||
75 | int ret;
|
||
76 | double res;
|
||
77 | |||
78 | priv->var_values[VAR_E] = M_E; |
||
79 | priv->var_values[VAR_PHI] = M_PHI; |
||
80 | priv->var_values[VAR_PI] = M_PI; |
||
81 | priv->var_values[VAR_AVTB] = av_q2d(AV_TIME_BASE_Q); |
||
82 | |||
83 | d2af7205 | Stefano Sabatini | if ((ret = av_expr_parse_and_eval(&res, priv->tb_expr, var_names, priv->var_values,
|
84 | 16134b7c | Stefano Sabatini | NULL, NULL, NULL, NULL, NULL, 0, NULL)) < 0) { |
85 | av_log(ctx, AV_LOG_ERROR, "Invalid expression '%s' for timebase.\n", priv->tb_expr);
|
||
86 | return ret;
|
||
87 | } |
||
88 | tb = av_d2q(res, INT_MAX); |
||
89 | if (tb.num <= 0 || tb.den <= 0) { |
||
90 | av_log(ctx, AV_LOG_ERROR, |
||
91 | "Invalid non-positive value for the timebase %d/%d.\n",
|
||
92 | tb.num, tb.den); |
||
93 | return AVERROR(EINVAL);
|
||
94 | } |
||
95 | dd08b83c | Stefano Sabatini | |
96 | outlink->w = priv->w; |
||
97 | outlink->h = priv->h; |
||
98 | 16134b7c | Stefano Sabatini | outlink->time_base = tb; |
99 | dd08b83c | Stefano Sabatini | |
100 | 16134b7c | Stefano Sabatini | av_log(outlink->src, AV_LOG_INFO, "w:%d h:%d tb:%d/%d\n", priv->w, priv->h,
|
101 | tb.num, tb.den); |
||
102 | dd08b83c | Stefano Sabatini | |
103 | return 0; |
||
104 | } |
||
105 | |||
106 | static int request_frame(AVFilterLink *link) |
||
107 | { |
||
108 | return -1; |
||
109 | } |
||
110 | |||
111 | AVFilter avfilter_vsrc_nullsrc = { |
||
112 | .name = "nullsrc",
|
||
113 | a6881c6a | Stefano Sabatini | .description = NULL_IF_CONFIG_SMALL("Null video source, never return images."),
|
114 | dd08b83c | Stefano Sabatini | |
115 | .init = init, |
||
116 | .priv_size = sizeof(NullContext),
|
||
117 | |||
118 | .inputs = (AVFilterPad[]) {{ .name = NULL}},
|
||
119 | |||
120 | .outputs = (AVFilterPad[]) { |
||
121 | { |
||
122 | .name = "default",
|
||
123 | 72415b2a | Stefano Sabatini | .type = AVMEDIA_TYPE_VIDEO, |
124 | dd08b83c | Stefano Sabatini | .config_props = config_props, |
125 | .request_frame = request_frame, |
||
126 | }, |
||
127 | { .name = NULL}
|
||
128 | }, |
||
129 | }; |