h264_metadata: Add option to delete filler data
[libav.git] / libavfilter / vsrc_nullsrc.c
CommitLineData
dd08b83c 1/*
2912e87a 2 * This file is part of Libav.
dd08b83c 3 *
2912e87a 4 * Libav is free software; you can redistribute it and/or
dd08b83c
SS
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 *
2912e87a 9 * Libav is distributed in the hope that it will be useful,
dd08b83c
SS
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
2912e87a 15 * License along with Libav; if not, write to the Free Software
dd08b83c
SS
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19/**
ba87f080 20 * @file
dd08b83c
SS
21 * null video source
22 */
23
1d9c2dc8
MS
24#include <stdio.h>
25
16134b7c
SS
26#include "libavutil/avstring.h"
27#include "libavutil/eval.h"
1d9c2dc8 28#include "libavutil/internal.h"
0ebcdf5c 29#include "libavutil/mathematics.h"
b7b3302f 30#include "libavutil/opt.h"
737eb597 31#include "libavutil/parseutils.h"
dd08b83c 32#include "avfilter.h"
b74a1da4 33#include "formats.h"
9d0bfc50 34#include "internal.h"
dd08b83c 35
b0f29db5 36static const char *const var_names[] = {
16134b7c
SS
37 "E",
38 "PHI",
39 "PI",
40 "AVTB", /* default timebase 1/AV_TIME_BASE */
41 NULL
42};
43
44enum var_name {
45 VAR_E,
46 VAR_PHI,
47 VAR_PI,
48 VAR_AVTB,
16134b7c
SS
49 VAR_VARS_NB
50};
51
58400ac1 52typedef struct NullContext {
b7b3302f 53 const AVClass *class;
dd08b83c 54 int w, h;
b7b3302f 55 char *tb_expr;
16134b7c 56 double var_values[VAR_VARS_NB];
dd08b83c
SS
57} NullContext;
58
dd08b83c
SS
59static int config_props(AVFilterLink *outlink)
60{
16134b7c
SS
61 AVFilterContext *ctx = outlink->src;
62 NullContext *priv = ctx->priv;
63 AVRational tb;
64 int ret;
65 double res;
66
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);
71
d2af7205 72 if ((ret = av_expr_parse_and_eval(&res, priv->tb_expr, var_names, priv->var_values,
16134b7c
SS
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);
75 return ret;
76 }
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",
81 tb.num, tb.den);
82 return AVERROR(EINVAL);
83 }
dd08b83c
SS
84
85 outlink->w = priv->w;
86 outlink->h = priv->h;
16134b7c 87 outlink->time_base = tb;
dd08b83c 88
1a49a169 89 av_log(outlink->src, AV_LOG_VERBOSE, "w:%d h:%d tb:%d/%d\n", priv->w, priv->h,
16134b7c 90 tb.num, tb.den);
dd08b83c
SS
91
92 return 0;
93}
94
95static int request_frame(AVFilterLink *link)
96{
97 return -1;
98}
99
b7b3302f
AK
100#define OFFSET(x) offsetof(NullContext, x)
101#define FLAGS AV_OPT_FLAG_VIDEO_PARAM
102static 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 },
106 { NULL },
107};
108
109static const AVClass nullsrc_class = {
110 .class_name = "nullsrc",
111 .item_name = av_default_item_name,
112 .option = options,
113 .version = LIBAVUTIL_VERSION_INT,
114};
115
568c70e7
MR
116static const AVFilterPad avfilter_vsrc_nullsrc_outputs[] = {
117 {
118 .name = "default",
119 .type = AVMEDIA_TYPE_VIDEO,
120 .config_props = config_props,
121 .request_frame = request_frame,
122 },
123 { NULL }
124};
125
cd43ca04 126AVFilter ff_vsrc_nullsrc = {
dd08b83c 127 .name = "nullsrc",
a6881c6a 128 .description = NULL_IF_CONFIG_SMALL("Null video source, never return images."),
dd08b83c 129
dd08b83c 130 .priv_size = sizeof(NullContext),
b7b3302f 131 .priv_class = &nullsrc_class,
dd08b83c 132
1fce361d 133 .inputs = NULL,
dd08b83c 134
568c70e7 135 .outputs = avfilter_vsrc_nullsrc_outputs,
dd08b83c 136};