]> git.sesse.net Git - ffmpeg/blob - libavfilter/vsrc_buffer.c
Use enum PixelFormat to silence one icc warning:
[ffmpeg] / libavfilter / vsrc_buffer.c
1 /*
2  * Memory buffer source filter
3  * Copyright (c) 2008 Vitor Sessak
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #include "avfilter.h"
23 #include "vsrc_buffer.h"
24
25 typedef struct {
26     int64_t           pts;
27     AVFrame           frame;
28     int               has_frame;
29     int               h, w;
30     enum PixelFormat  pix_fmt;
31     AVRational        pixel_aspect;
32 } BufferSourceContext;
33
34
35 int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame,
36                              int64_t pts, AVRational pixel_aspect)
37 {
38     BufferSourceContext *c = buffer_filter->priv;
39
40     if (c->has_frame) {
41         av_log(buffer_filter, AV_LOG_ERROR,
42                "Buffering several frames is not supported. "
43                "Please consume all available frames before adding a new one.\n"
44             );
45         //return -1;
46     }
47
48     memcpy(c->frame.data    , frame->data    , sizeof(frame->data));
49     memcpy(c->frame.linesize, frame->linesize, sizeof(frame->linesize));
50     c->frame.interlaced_frame= frame->interlaced_frame;
51     c->frame.top_field_first = frame->top_field_first;
52     c->pts = pts;
53     c->pixel_aspect = pixel_aspect;
54     c->has_frame = 1;
55
56     return 0;
57 }
58
59 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
60 {
61     BufferSourceContext *c = ctx->priv;
62
63     if(args && sscanf(args, "%d:%d:%d", &c->w, &c->h, &c->pix_fmt) == 3)
64         return 0;
65
66     av_log(ctx, AV_LOG_ERROR, "init() expected 3 arguments:'%s'\n", args);
67     return -1;
68 }
69
70 static int query_formats(AVFilterContext *ctx)
71 {
72     BufferSourceContext *c = ctx->priv;
73     enum PixelFormat pix_fmts[] = { c->pix_fmt, PIX_FMT_NONE };
74
75     avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
76     return 0;
77 }
78
79 static int config_props(AVFilterLink *link)
80 {
81     BufferSourceContext *c = link->src->priv;
82
83     link->w = c->w;
84     link->h = c->h;
85
86     return 0;
87 }
88
89
90 static int request_frame(AVFilterLink *link)
91 {
92     BufferSourceContext *c = link->src->priv;
93     AVFilterPicRef *picref;
94
95     if (!c->has_frame) {
96         av_log(link->src, AV_LOG_ERROR,
97                "request_frame() called with no available frame!\n");
98         //return -1;
99     }
100
101     /* This picture will be needed unmodified later for decoding the next
102      * frame */
103     picref = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE |
104                                        AV_PERM_REUSE2,
105                                        link->w, link->h);
106
107     av_picture_copy((AVPicture *)&picref->data, (AVPicture *)&c->frame,
108                     picref->pic->format, link->w, link->h);
109
110     picref->pts = c->pts;
111     picref->pixel_aspect = c->pixel_aspect;
112     picref->interlaced      = c->frame.interlaced_frame;
113     picref->top_field_first = c->frame.top_field_first;
114     avfilter_start_frame(link, avfilter_ref_pic(picref, ~0));
115     avfilter_draw_slice(link, 0, link->h, 1);
116     avfilter_end_frame(link);
117     avfilter_unref_pic(picref);
118
119     c->has_frame = 0;
120
121     return 0;
122 }
123
124 static int poll_frame(AVFilterLink *link)
125 {
126     BufferSourceContext *c = link->src->priv;
127     return !!(c->has_frame);
128 }
129
130 AVFilter avfilter_vsrc_buffer =
131 {
132     .name      = "buffer",
133     .priv_size = sizeof(BufferSourceContext),
134     .query_formats = query_formats,
135
136     .init      = init,
137
138     .inputs    = (AVFilterPad[]) {{ .name = NULL }},
139     .outputs   = (AVFilterPad[]) {{ .name            = "default",
140                                     .type            = AVMEDIA_TYPE_VIDEO,
141                                     .request_frame   = request_frame,
142                                     .poll_frame      = poll_frame,
143                                     .config_props    = config_props, },
144                                   { .name = NULL}},
145 };