2 * Copyright (c) 2007 Bobby Bingham
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * FIFO buffering video filter
28 typedef struct BufPic {
29 AVFilterBufferRef *picref;
35 BufPic *last; ///< last buffered picture
38 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
40 FifoContext *fifo = ctx->priv;
41 fifo->last = &fifo->root;
43 av_log(ctx, AV_LOG_INFO, "\n");
47 static av_cold void uninit(AVFilterContext *ctx)
49 FifoContext *fifo = ctx->priv;
52 for (pic = fifo->root.next; pic; pic = tmp) {
54 avfilter_unref_buffer(pic->picref);
59 static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
61 FifoContext *fifo = inlink->dst->priv;
63 fifo->last->next = av_mallocz(sizeof(BufPic));
64 fifo->last = fifo->last->next;
65 fifo->last->picref = picref;
68 static void end_frame(AVFilterLink *inlink) { }
70 static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { }
72 static int request_frame(AVFilterLink *outlink)
74 FifoContext *fifo = outlink->src->priv;
78 if (!fifo->root.next) {
79 if ((ret = avfilter_request_frame(outlink->src->inputs[0])) < 0)
83 /* by doing this, we give ownership of the reference to the next filter,
84 * so we don't have to worry about dereferencing it ourselves. */
85 avfilter_start_frame(outlink, fifo->root.next->picref);
86 avfilter_draw_slice (outlink, 0, outlink->h, 1);
87 avfilter_end_frame (outlink);
89 if (fifo->last == fifo->root.next)
90 fifo->last = &fifo->root;
91 tmp = fifo->root.next->next;
92 av_free(fifo->root.next);
93 fifo->root.next = tmp;
98 AVFilter avfilter_vf_fifo = {
100 .description = NULL_IF_CONFIG_SMALL("Buffer input images and send them when they are requested."),
105 .priv_size = sizeof(FifoContext),
107 .inputs = (const AVFilterPad[]) {{ .name = "default",
108 .type = AVMEDIA_TYPE_VIDEO,
109 .get_video_buffer= avfilter_null_get_video_buffer,
110 .start_frame = start_frame,
111 .draw_slice = draw_slice,
112 .end_frame = end_frame,
113 .rej_perms = AV_PERM_REUSE2, },
115 .outputs = (const AVFilterPad[]) {{ .name = "default",
116 .type = AVMEDIA_TYPE_VIDEO,
117 .request_frame = request_frame, },