mp3: Properly use AVCodecContext API
[platform/upstream/libav.git] / libavfilter / vsrc_nullsrc.c
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
19 /**
20  * @file
21  * null video source
22  */
23
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 {
45     VAR_E,
46     VAR_PHI,
47     VAR_PI,
48     VAR_AVTB,
49     VAR_VARS_NB
50 };
51
52 typedef struct NullContext {
53     const AVClass *class;
54     int w, h;
55     char *tb_expr;
56     double var_values[VAR_VARS_NB];
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;
70     priv->var_values[VAR_AVTB] = av_q2d(AV_TIME_BASE_Q);
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
116 static const AVFilterPad avfilter_vsrc_nullsrc_outputs[] = {
117     {
118         .name          = "default",
119         .type          = AVMEDIA_TYPE_VIDEO,
120         .config_props  = config_props,
121         .request_frame = request_frame,
122     },
123     { NULL }
124 };
125
126 AVFilter ff_vsrc_nullsrc = {
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 };