00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #include "libavutil/avstring.h"
00025 #include "libavutil/eval.h"
00026 #include "libavutil/parseutils.h"
00027 #include "avfilter.h"
00028
00029 static const char *var_names[] = {
00030 "E",
00031 "PHI",
00032 "PI",
00033 "AVTB",
00034 NULL
00035 };
00036
00037 enum var_name {
00038 VAR_E,
00039 VAR_PHI,
00040 VAR_PI,
00041 VAR_AVTB,
00042 VAR_VARS_NB
00043 };
00044
00045 typedef struct {
00046 int w, h;
00047 char tb_expr[256];
00048 double var_values[VAR_VARS_NB];
00049 } NullContext;
00050
00051 static int init(AVFilterContext *ctx, const char *args, void *opaque)
00052 {
00053 NullContext *priv = ctx->priv;
00054
00055 priv->w = 352;
00056 priv->h = 288;
00057 av_strlcpy(priv->tb_expr, "AVTB", sizeof(priv->tb_expr));
00058
00059 if (args)
00060 sscanf(args, "%d:%d:%255[^:]", &priv->w, &priv->h, priv->tb_expr);
00061
00062 if (priv->w <= 0 || priv->h <= 0) {
00063 av_log(ctx, AV_LOG_ERROR, "Non-positive size values are not acceptable.\n");
00064 return AVERROR(EINVAL);
00065 }
00066
00067 return 0;
00068 }
00069
00070 static int config_props(AVFilterLink *outlink)
00071 {
00072 AVFilterContext *ctx = outlink->src;
00073 NullContext *priv = ctx->priv;
00074 AVRational tb;
00075 int ret;
00076 double res;
00077
00078 priv->var_values[VAR_E] = M_E;
00079 priv->var_values[VAR_PHI] = M_PHI;
00080 priv->var_values[VAR_PI] = M_PI;
00081 priv->var_values[VAR_AVTB] = av_q2d(AV_TIME_BASE_Q);
00082
00083 if ((ret = av_expr_parse_and_eval(&res, priv->tb_expr, var_names, priv->var_values,
00084 NULL, NULL, NULL, NULL, NULL, 0, NULL)) < 0) {
00085 av_log(ctx, AV_LOG_ERROR, "Invalid expression '%s' for timebase.\n", priv->tb_expr);
00086 return ret;
00087 }
00088 tb = av_d2q(res, INT_MAX);
00089 if (tb.num <= 0 || tb.den <= 0) {
00090 av_log(ctx, AV_LOG_ERROR,
00091 "Invalid non-positive value for the timebase %d/%d.\n",
00092 tb.num, tb.den);
00093 return AVERROR(EINVAL);
00094 }
00095
00096 outlink->w = priv->w;
00097 outlink->h = priv->h;
00098 outlink->time_base = tb;
00099
00100 av_log(outlink->src, AV_LOG_INFO, "w:%d h:%d tb:%d/%d\n", priv->w, priv->h,
00101 tb.num, tb.den);
00102
00103 return 0;
00104 }
00105
00106 static int request_frame(AVFilterLink *link)
00107 {
00108 return -1;
00109 }
00110
00111 AVFilter avfilter_vsrc_nullsrc = {
00112 .name = "nullsrc",
00113 .description = NULL_IF_CONFIG_SMALL("Null video source, never return images."),
00114
00115 .init = init,
00116 .priv_size = sizeof(NullContext),
00117
00118 .inputs = (AVFilterPad[]) {{ .name = NULL}},
00119
00120 .outputs = (AVFilterPad[]) {
00121 {
00122 .name = "default",
00123 .type = AVMEDIA_TYPE_VIDEO,
00124 .config_props = config_props,
00125 .request_frame = request_frame,
00126 },
00127 { .name = NULL}
00128 },
00129 };