vsrc_nullsrc.c
Go to the documentation of this file.
1 /*
2  * This file is part of Libav.
3  *
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.
8  *
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.
13  *
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
17  */
18 
24 #include <stdio.h>
25 
26 #include "libavutil/avstring.h"
27 #include "libavutil/eval.h"
28 #include "libavutil/internal.h"
29 #include "libavutil/mathematics.h"
30 #include "libavutil/parseutils.h"
31 #include "avfilter.h"
32 #include "formats.h"
33 #include "internal.h"
34 
35 static const char *const var_names[] = {
36  "E",
37  "PHI",
38  "PI",
39  "AVTB", /* default timebase 1/AV_TIME_BASE */
40  NULL
41 };
42 
43 enum var_name {
49 };
50 
51 typedef struct {
52  int w, h;
53  char tb_expr[256];
54  double var_values[VAR_VARS_NB];
55 } NullContext;
56 
57 static int init(AVFilterContext *ctx, const char *args)
58 {
59  NullContext *priv = ctx->priv;
60 
61  priv->w = 352;
62  priv->h = 288;
63  av_strlcpy(priv->tb_expr, "AVTB", sizeof(priv->tb_expr));
64 
65  if (args)
66  sscanf(args, "%d:%d:%255[^:]", &priv->w, &priv->h, priv->tb_expr);
67 
68  if (priv->w <= 0 || priv->h <= 0) {
69  av_log(ctx, AV_LOG_ERROR, "Non-positive size values are not acceptable.\n");
70  return AVERROR(EINVAL);
71  }
72 
73  return 0;
74 }
75 
76 static int config_props(AVFilterLink *outlink)
77 {
78  AVFilterContext *ctx = outlink->src;
79  NullContext *priv = ctx->priv;
80  AVRational tb;
81  int ret;
82  double res;
83 
84  priv->var_values[VAR_E] = M_E;
85  priv->var_values[VAR_PHI] = M_PHI;
86  priv->var_values[VAR_PI] = M_PI;
88 
89  if ((ret = av_expr_parse_and_eval(&res, priv->tb_expr, var_names, priv->var_values,
90  NULL, NULL, NULL, NULL, NULL, 0, NULL)) < 0) {
91  av_log(ctx, AV_LOG_ERROR, "Invalid expression '%s' for timebase.\n", priv->tb_expr);
92  return ret;
93  }
94  tb = av_d2q(res, INT_MAX);
95  if (tb.num <= 0 || tb.den <= 0) {
96  av_log(ctx, AV_LOG_ERROR,
97  "Invalid non-positive value for the timebase %d/%d.\n",
98  tb.num, tb.den);
99  return AVERROR(EINVAL);
100  }
101 
102  outlink->w = priv->w;
103  outlink->h = priv->h;
104  outlink->time_base = tb;
105 
106  av_log(outlink->src, AV_LOG_VERBOSE, "w:%d h:%d tb:%d/%d\n", priv->w, priv->h,
107  tb.num, tb.den);
108 
109  return 0;
110 }
111 
112 static int request_frame(AVFilterLink *link)
113 {
114  return -1;
115 }
116 
118  {
119  .name = "default",
120  .type = AVMEDIA_TYPE_VIDEO,
121  .config_props = config_props,
122  .request_frame = request_frame,
123  },
124  { NULL }
125 };
126 
128  .name = "nullsrc",
129  .description = NULL_IF_CONFIG_SMALL("Null video source, never return images."),
130 
131  .init = init,
132  .priv_size = sizeof(NullContext),
133 
134  .inputs = NULL,
135 
136  .outputs = avfilter_vsrc_nullsrc_outputs,
137 };
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:122
static const AVFilterPad avfilter_vsrc_nullsrc_outputs[]
Definition: vsrc_nullsrc.c:117
int num
numerator
Definition: rational.h:44
const char * name
Pad name.
Definition: internal.h:39
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
var_name
Definition: vf_boxblur.c:47
A filter pad used for either input or output.
Definition: internal.h:33
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
Definition: eval.c:548
AVFilter avfilter_vsrc_nullsrc
Definition: vsrc_nullsrc.c:127
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:88
static int init(AVFilterContext *ctx, const char *args)
Definition: vsrc_nullsrc.c:57
void * priv
private data for use by the filter
Definition: avfilter.h:439
char tb_expr[256]
Definition: vsrc_nullsrc.c:53
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:146
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:67
common internal API header
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
Definition: rational.c:106
#define M_E
Definition: ratecontrol.c:39
static int config_props(AVFilterLink *outlink)
Definition: vsrc_nullsrc.c:76
double var_values[VAR_VARS_NB]
Definition: vsrc_nullsrc.c:54
NULL
Definition: eval.c:52
Filter definition.
Definition: avfilter.h:371
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:110
rational number numerator/denominator
Definition: rational.h:43
#define M_PHI
Definition: mathematics.h:34
const char * name
filter name
Definition: avfilter.h:372
misc parsing utilities
static const char *const var_names[]
Definition: vsrc_nullsrc.c:35
int den
denominator
Definition: rational.h:45
An instance of a filter.
Definition: avfilter.h:418
internal API functions
static int request_frame(AVFilterLink *link)
Definition: vsrc_nullsrc.c:112
simple arithmetic expression evaluator