Statistics
| Branch: | Revision:

ffmpeg / libavfilter / vsrc_nullsrc.c @ 16134b7c

History | View | Annotate | Download (3.35 KB)

1
/*
2
 * This file is part of FFmpeg.
3
 *
4
 * FFmpeg 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
 * FFmpeg 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 FFmpeg; if not, write to the Free Software
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
 */
18

    
19
/**
20
 * @file
21
 * null video source
22
 */
23

    
24
#include "libavutil/avstring.h"
25
#include "libavutil/eval.h"
26
#include "libavcore/parseutils.h"
27
#include "avfilter.h"
28

    
29
static const char *var_names[] = {
30
    "E",
31
    "PHI",
32
    "PI",
33
    "AVTB",   /* default timebase 1/AV_TIME_BASE */
34
    NULL
35
};
36

    
37
enum var_name {
38
    VAR_E,
39
    VAR_PHI,
40
    VAR_PI,
41
    VAR_AVTB,
42
    VAR_INTB,
43
    VAR_VARS_NB
44
};
45

    
46
typedef struct {
47
    int w, h;
48
    char tb_expr[256];
49
    double var_values[VAR_VARS_NB];
50
} NullContext;
51

    
52
static int init(AVFilterContext *ctx, const char *args, void *opaque)
53
{
54
    NullContext *priv = ctx->priv;
55

    
56
    priv->w = 352;
57
    priv->h = 288;
58
    av_strlcpy(priv->tb_expr, "AVTB", sizeof(priv->tb_expr));
59

    
60
    if (args)
61
        sscanf(args, "%d:%d:%255[^:]", &priv->w, &priv->h, priv->tb_expr);
62

    
63
    if (priv->w <= 0 || priv->h <= 0) {
64
        av_log(ctx, AV_LOG_ERROR, "Non-positive size values are not acceptable.\n");
65
        return AVERROR(EINVAL);
66
    }
67

    
68
    return 0;
69
}
70

    
71
static int config_props(AVFilterLink *outlink)
72
{
73
    AVFilterContext *ctx = outlink->src;
74
    NullContext *priv = ctx->priv;
75
    AVRational tb;
76
    int ret;
77
    double res;
78

    
79
    priv->var_values[VAR_E]    = M_E;
80
    priv->var_values[VAR_PHI]  = M_PHI;
81
    priv->var_values[VAR_PI]   = M_PI;
82
    priv->var_values[VAR_AVTB] = av_q2d(AV_TIME_BASE_Q);
83

    
84
    if ((ret = av_parse_and_eval_expr(&res, priv->tb_expr, var_names, priv->var_values,
85
                                      NULL, NULL, NULL, NULL, NULL, 0, NULL)) < 0) {
86
        av_log(ctx, AV_LOG_ERROR, "Invalid expression '%s' for timebase.\n", priv->tb_expr);
87
        return ret;
88
    }
89
    tb = av_d2q(res, INT_MAX);
90
    if (tb.num <= 0 || tb.den <= 0) {
91
        av_log(ctx, AV_LOG_ERROR,
92
               "Invalid non-positive value for the timebase %d/%d.\n",
93
               tb.num, tb.den);
94
        return AVERROR(EINVAL);
95
    }
96

    
97
    outlink->w = priv->w;
98
    outlink->h = priv->h;
99
    outlink->time_base = tb;
100

    
101
    av_log(outlink->src, AV_LOG_INFO, "w:%d h:%d tb:%d/%d\n", priv->w, priv->h,
102
           tb.num, tb.den);
103

    
104
    return 0;
105
}
106

    
107
static int request_frame(AVFilterLink *link)
108
{
109
    return -1;
110
}
111

    
112
AVFilter avfilter_vsrc_nullsrc = {
113
    .name        = "nullsrc",
114
    .description = NULL_IF_CONFIG_SMALL("Null video source, never return images."),
115

    
116
    .init       = init,
117
    .priv_size = sizeof(NullContext),
118

    
119
    .inputs    = (AVFilterPad[]) {{ .name = NULL}},
120

    
121
    .outputs   = (AVFilterPad[]) {
122
        {
123
            .name            = "default",
124
            .type            = AVMEDIA_TYPE_VIDEO,
125
            .config_props    = config_props,
126
            .request_frame   = request_frame,
127
        },
128
        { .name = NULL}
129
    },
130
};