libavfilter/vsrc_nullsrc.c
Go to the documentation of this file.
00001 /*
00002  * This file is part of Libav.
00003  *
00004  * Libav is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * Libav is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with Libav; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00017  */
00018 
00024 #include "libavutil/avstring.h"
00025 #include "libavutil/eval.h"
00026 #include "libavutil/mathematics.h"
00027 #include "libavutil/parseutils.h"
00028 #include "avfilter.h"
00029 
00030 static const char *var_names[] = {
00031     "E",
00032     "PHI",
00033     "PI",
00034     "AVTB",   /* default timebase 1/AV_TIME_BASE */
00035     NULL
00036 };
00037 
00038 enum var_name {
00039     VAR_E,
00040     VAR_PHI,
00041     VAR_PI,
00042     VAR_AVTB,
00043     VAR_VARS_NB
00044 };
00045 
00046 typedef struct {
00047     int w, h;
00048     char tb_expr[256];
00049     double var_values[VAR_VARS_NB];
00050 } NullContext;
00051 
00052 static int init(AVFilterContext *ctx, const char *args, void *opaque)
00053 {
00054     NullContext *priv = ctx->priv;
00055 
00056     priv->w = 352;
00057     priv->h = 288;
00058     av_strlcpy(priv->tb_expr, "AVTB", sizeof(priv->tb_expr));
00059 
00060     if (args)
00061         sscanf(args, "%d:%d:%255[^:]", &priv->w, &priv->h, priv->tb_expr);
00062 
00063     if (priv->w <= 0 || priv->h <= 0) {
00064         av_log(ctx, AV_LOG_ERROR, "Non-positive size values are not acceptable.\n");
00065         return AVERROR(EINVAL);
00066     }
00067 
00068     return 0;
00069 }
00070 
00071 static int config_props(AVFilterLink *outlink)
00072 {
00073     AVFilterContext *ctx = outlink->src;
00074     NullContext *priv = ctx->priv;
00075     AVRational tb;
00076     int ret;
00077     double res;
00078 
00079     priv->var_values[VAR_E]    = M_E;
00080     priv->var_values[VAR_PHI]  = M_PHI;
00081     priv->var_values[VAR_PI]   = M_PI;
00082     priv->var_values[VAR_AVTB] = av_q2d(AV_TIME_BASE_Q);
00083 
00084     if ((ret = av_expr_parse_and_eval(&res, priv->tb_expr, var_names, priv->var_values,
00085                                       NULL, NULL, NULL, NULL, NULL, 0, NULL)) < 0) {
00086         av_log(ctx, AV_LOG_ERROR, "Invalid expression '%s' for timebase.\n", priv->tb_expr);
00087         return ret;
00088     }
00089     tb = av_d2q(res, INT_MAX);
00090     if (tb.num <= 0 || tb.den <= 0) {
00091         av_log(ctx, AV_LOG_ERROR,
00092                "Invalid non-positive value for the timebase %d/%d.\n",
00093                tb.num, tb.den);
00094         return AVERROR(EINVAL);
00095     }
00096 
00097     outlink->w = priv->w;
00098     outlink->h = priv->h;
00099     outlink->time_base = tb;
00100 
00101     av_log(outlink->src, AV_LOG_INFO, "w:%d h:%d tb:%d/%d\n", priv->w, priv->h,
00102            tb.num, tb.den);
00103 
00104     return 0;
00105 }
00106 
00107 static int request_frame(AVFilterLink *link)
00108 {
00109     return -1;
00110 }
00111 
00112 AVFilter avfilter_vsrc_nullsrc = {
00113     .name        = "nullsrc",
00114     .description = NULL_IF_CONFIG_SMALL("Null video source, never return images."),
00115 
00116     .init       = init,
00117     .priv_size = sizeof(NullContext),
00118 
00119     .inputs    = (AVFilterPad[]) {{ .name = NULL}},
00120 
00121     .outputs   = (AVFilterPad[]) {
00122         {
00123             .name            = "default",
00124             .type            = AVMEDIA_TYPE_VIDEO,
00125             .config_props    = config_props,
00126             .request_frame   = request_frame,
00127         },
00128         { .name = NULL}
00129     },
00130 };