Libav
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/opt.h"
31 #include "libavutil/parseutils.h"
32 #include "avfilter.h"
33 #include "formats.h"
34 #include "internal.h"
35 
36 static const char *const var_names[] = {
37  "E",
38  "PHI",
39  "PI",
40  "AVTB", /* default timebase 1/AV_TIME_BASE */
41  NULL
42 };
43 
44 enum var_name {
50 };
51 
52 typedef struct NullContext {
53  const AVClass *class;
54  int w, h;
55  char *tb_expr;
57 } NullContext;
58 
59 static int config_props(AVFilterLink *outlink)
60 {
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;
71 
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);
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  }
84 
85  outlink->w = priv->w;
86  outlink->h = priv->h;
87  outlink->time_base = tb;
88 
89  av_log(outlink->src, AV_LOG_VERBOSE, "w:%d h:%d tb:%d/%d\n", priv->w, priv->h,
90  tb.num, tb.den);
91 
92  return 0;
93 }
94 
95 static int request_frame(AVFilterLink *link)
96 {
97  return -1;
98 }
99 
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 },
106  { NULL },
107 };
108 
109 static 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 
117  {
118  .name = "default",
119  .type = AVMEDIA_TYPE_VIDEO,
120  .config_props = config_props,
121  .request_frame = request_frame,
122  },
123  { NULL }
124 };
125 
127  .name = "nullsrc",
128  .description = NULL_IF_CONFIG_SMALL("Null video source, never return images."),
129 
130  .priv_size = sizeof(NullContext),
131  .priv_class = &nullsrc_class,
132 
133  .inputs = NULL,
134 
135  .outputs = avfilter_vsrc_nullsrc_outputs,
136 };
AVOption.
Definition: opt.h:234
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:232
Main libavfilter public API header.
static const AVFilterPad avfilter_vsrc_nullsrc_outputs[]
Definition: vsrc_nullsrc.c:116
int num
numerator
Definition: rational.h:44
static const AVOption options[]
Definition: vsrc_nullsrc.c:102
const char * name
Pad name.
Definition: internal.h:42
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:38
AVOptions.
static const AVClass nullsrc_class
Definition: vsrc_nullsrc.c:109
#define OFFSET(x)
Definition: vsrc_nullsrc.c:100
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:139
A filter pad used for either input or output.
Definition: internal.h:36
#define FLAGS
Definition: vsrc_nullsrc.c:101
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:551
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
#define AVERROR(e)
Definition: error.h:43
char * tb_expr
Definition: vsrc_nullsrc.c:55
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:150
void * priv
private data for use by the filter
Definition: avfilter.h:584
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:169
common internal API header
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
Definition: rational.c:105
#define M_E
Definition: ratecontrol.c:39
static int config_props(AVFilterLink *outlink)
Definition: vsrc_nullsrc.c:59
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
double var_values[VAR_VARS_NB]
Definition: vsrc_nullsrc.c:56
NULL
Definition: eval.c:55
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:240
av_default_item_name
Definition: dnxhdenc.c:52
Describe the class of an AVClass context structure.
Definition: log.h:33
Filter definition.
Definition: avfilter.h:421
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:221
rational number numerator/denominator
Definition: rational.h:43
#define M_PHI
Definition: mathematics.h:34
const char * name
Filter name.
Definition: avfilter.h:425
misc parsing utilities
static const char *const var_names[]
Definition: vsrc_nullsrc.c:36
AVFilter ff_vsrc_nullsrc
Definition: vsrc_nullsrc.c:126
int den
denominator
Definition: rational.h:45
An instance of a filter.
Definition: avfilter.h:563
internal API functions
static int request_frame(AVFilterLink *link)
Definition: vsrc_nullsrc.c:95
var_name
Definition: setpts.c:60
simple arithmetic expression evaluator