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
29 typedef struct BufPic {
30 AVFilterBufferRef *picref;
36 BufPic *last; ///< last buffered picture
39 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
41 FifoContext *fifo = ctx->priv;
42 fifo->last = &fifo->root;
44 av_log(ctx, AV_LOG_INFO, "\n");
48 static av_cold void uninit(AVFilterContext *ctx)
50 FifoContext *fifo = ctx->priv;
53 for (pic = fifo->root.next; pic; pic = tmp) {
55 avfilter_unref_buffer(pic->picref);
60 static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
62 FifoContext *fifo = inlink->dst->priv;
64 fifo->last->next = av_mallocz(sizeof(BufPic));
65 fifo->last = fifo->last->next;
66 fifo->last->picref = picref;
69 static void end_frame(AVFilterLink *inlink) { }
71 static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { }
73 static int request_frame(AVFilterLink *outlink)
75 FifoContext *fifo = outlink->src->priv;
79 if (!fifo->root.next) {
80 if ((ret = avfilter_request_frame(outlink->src->inputs[0])) < 0)
84 /* by doing this, we give ownership of the reference to the next filter,
85 * so we don't have to worry about dereferencing it ourselves. */
86 avfilter_start_frame(outlink, fifo->root.next->picref);
87 avfilter_draw_slice (outlink, 0, outlink->h, 1);
88 avfilter_end_frame (outlink);
90 if (fifo->last == fifo->root.next)
91 fifo->last = &fifo->root;
92 tmp = fifo->root.next->next;
93 av_free(fifo->root.next);
94 fifo->root.next = tmp;
99 AVFilter avfilter_vf_fifo = {
101 .description = NULL_IF_CONFIG_SMALL("Buffer input images and send them when they are requested."),
106 .priv_size = sizeof(FifoContext),
108 .inputs = (const AVFilterPad[]) {{ .name = "default",
109 .type = AVMEDIA_TYPE_VIDEO,
110 .get_video_buffer= ff_null_get_video_buffer,
111 .start_frame = start_frame,
112 .draw_slice = draw_slice,
113 .end_frame = end_frame,
114 .rej_perms = AV_PERM_REUSE2, },
116 .outputs = (const AVFilterPad[]) {{ .name = "default",
117 .type = AVMEDIA_TYPE_VIDEO,
118 .request_frame = request_frame, },