2010-01-16 11:43:53 +01:00
|
|
|
/*
|
2011-03-18 18:35:10 +01:00
|
|
|
* This file is part of Libav.
|
2010-01-16 11:43:53 +01:00
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2010-01-16 11:43:53 +01:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2010-01-16 11:43:53 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2011-03-18 18:35:10 +01:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2010-01-16 11:43:53 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 16:45:34 +02:00
|
|
|
* @file
|
2010-01-16 11:43:53 +01:00
|
|
|
* null video source
|
|
|
|
*/
|
|
|
|
|
2012-08-06 15:49:32 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2010-10-12 01:27:33 +02:00
|
|
|
#include "libavutil/avstring.h"
|
|
|
|
#include "libavutil/eval.h"
|
2012-08-06 15:49:32 +02:00
|
|
|
#include "libavutil/internal.h"
|
2011-06-04 13:58:23 +02:00
|
|
|
#include "libavutil/mathematics.h"
|
2013-02-25 21:21:29 +01:00
|
|
|
#include "libavutil/opt.h"
|
2011-02-07 14:37:08 +01:00
|
|
|
#include "libavutil/parseutils.h"
|
2010-01-16 11:43:53 +01:00
|
|
|
#include "avfilter.h"
|
2012-05-30 10:12:55 +02:00
|
|
|
#include "formats.h"
|
2012-06-12 20:12:42 +02:00
|
|
|
#include "internal.h"
|
2010-01-16 11:43:53 +01:00
|
|
|
|
2012-02-20 09:42:33 +01:00
|
|
|
static const char *const var_names[] = {
|
2010-10-12 01:27:33 +02:00
|
|
|
"E",
|
|
|
|
"PHI",
|
|
|
|
"PI",
|
|
|
|
"AVTB", /* default timebase 1/AV_TIME_BASE */
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum var_name {
|
|
|
|
VAR_E,
|
|
|
|
VAR_PHI,
|
|
|
|
VAR_PI,
|
|
|
|
VAR_AVTB,
|
|
|
|
VAR_VARS_NB
|
|
|
|
};
|
|
|
|
|
2010-01-16 11:43:53 +01:00
|
|
|
typedef struct {
|
2013-02-25 21:21:29 +01:00
|
|
|
const AVClass *class;
|
2010-01-16 11:43:53 +01:00
|
|
|
int w, h;
|
2013-02-25 21:21:29 +01:00
|
|
|
char *tb_expr;
|
2010-10-12 01:27:33 +02:00
|
|
|
double var_values[VAR_VARS_NB];
|
2010-01-16 11:43:53 +01:00
|
|
|
} NullContext;
|
|
|
|
|
|
|
|
static int config_props(AVFilterLink *outlink)
|
|
|
|
{
|
2010-10-12 01:27:33 +02:00
|
|
|
AVFilterContext *ctx = outlink->src;
|
|
|
|
NullContext *priv = ctx->priv;
|
|
|
|
AVRational tb;
|
|
|
|
int ret;
|
|
|
|
double res;
|
|
|
|
|
|
|
|
priv->var_values[VAR_E] = M_E;
|
|
|
|
priv->var_values[VAR_PHI] = M_PHI;
|
|
|
|
priv->var_values[VAR_PI] = M_PI;
|
|
|
|
priv->var_values[VAR_AVTB] = av_q2d(AV_TIME_BASE_Q);
|
|
|
|
|
2010-11-08 15:06:49 +01:00
|
|
|
if ((ret = av_expr_parse_and_eval(&res, priv->tb_expr, var_names, priv->var_values,
|
2010-10-12 01:27:33 +02:00
|
|
|
NULL, NULL, NULL, NULL, NULL, 0, NULL)) < 0) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Invalid expression '%s' for timebase.\n", priv->tb_expr);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
tb = av_d2q(res, INT_MAX);
|
|
|
|
if (tb.num <= 0 || tb.den <= 0) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
|
|
|
"Invalid non-positive value for the timebase %d/%d.\n",
|
|
|
|
tb.num, tb.den);
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
2010-01-16 11:43:53 +01:00
|
|
|
|
|
|
|
outlink->w = priv->w;
|
|
|
|
outlink->h = priv->h;
|
2010-10-12 01:27:33 +02:00
|
|
|
outlink->time_base = tb;
|
2010-01-16 11:43:53 +01:00
|
|
|
|
2012-06-25 06:31:38 +02:00
|
|
|
av_log(outlink->src, AV_LOG_VERBOSE, "w:%d h:%d tb:%d/%d\n", priv->w, priv->h,
|
2010-10-12 01:27:33 +02:00
|
|
|
tb.num, tb.den);
|
2010-01-16 11:43:53 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int request_frame(AVFilterLink *link)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-02-25 21:21:29 +01:00
|
|
|
#define OFFSET(x) offsetof(NullContext, x)
|
|
|
|
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM
|
|
|
|
static const AVOption options[] = {
|
|
|
|
{ "width", NULL, OFFSET(w), AV_OPT_TYPE_INT, { .i64 = 352 }, 1, INT_MAX, FLAGS },
|
|
|
|
{ "height", NULL, OFFSET(h), AV_OPT_TYPE_INT, { .i64 = 288 }, 1, INT_MAX, FLAGS },
|
|
|
|
{ "timebase", NULL, OFFSET(tb_expr), AV_OPT_TYPE_STRING, { .str = "AVTB" }, 0, 0, FLAGS },
|
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVClass nullsrc_class = {
|
|
|
|
.class_name = "nullsrc",
|
|
|
|
.item_name = av_default_item_name,
|
|
|
|
.option = options,
|
|
|
|
.version = LIBAVUTIL_VERSION_INT,
|
|
|
|
};
|
|
|
|
|
2012-07-24 15:14:01 +02:00
|
|
|
static const AVFilterPad avfilter_vsrc_nullsrc_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.config_props = config_props,
|
|
|
|
.request_frame = request_frame,
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2010-01-16 11:43:53 +01:00
|
|
|
AVFilter avfilter_vsrc_nullsrc = {
|
|
|
|
.name = "nullsrc",
|
2010-09-24 22:41:14 +02:00
|
|
|
.description = NULL_IF_CONFIG_SMALL("Null video source, never return images."),
|
2010-01-16 11:43:53 +01:00
|
|
|
|
|
|
|
.priv_size = sizeof(NullContext),
|
2013-02-25 21:21:29 +01:00
|
|
|
.priv_class = &nullsrc_class,
|
2010-01-16 11:43:53 +01:00
|
|
|
|
2012-09-16 13:58:49 +02:00
|
|
|
.inputs = NULL,
|
2010-01-16 11:43:53 +01:00
|
|
|
|
2012-07-24 15:14:01 +02:00
|
|
|
.outputs = avfilter_vsrc_nullsrc_outputs,
|
2010-01-16 11:43:53 +01:00
|
|
|
};
|