vf_fifo.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 Bobby Bingham
3  *
4  * This file is part of Libav.
5  *
6  * Libav 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.
10  *
11  * Libav 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.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
26 #include "avfilter.h"
27 
28 typedef struct BufPic {
30  struct BufPic *next;
31 } BufPic;
32 
33 typedef struct {
36 } FifoContext;
37 
38 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
39 {
40  FifoContext *fifo = ctx->priv;
41  fifo->last = &fifo->root;
42 
43  av_log(ctx, AV_LOG_INFO, "\n");
44  return 0;
45 }
46 
47 static av_cold void uninit(AVFilterContext *ctx)
48 {
49  FifoContext *fifo = ctx->priv;
50  BufPic *pic, *tmp;
51 
52  for (pic = fifo->root.next; pic; pic = tmp) {
53  tmp = pic->next;
55  av_free(pic);
56  }
57 }
58 
59 static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
60 {
61  FifoContext *fifo = inlink->dst->priv;
62 
63  fifo->last->next = av_mallocz(sizeof(BufPic));
64  fifo->last = fifo->last->next;
65  fifo->last->picref = picref;
66 }
67 
68 static void end_frame(AVFilterLink *inlink) { }
69 
70 static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { }
71 
72 static int request_frame(AVFilterLink *outlink)
73 {
74  FifoContext *fifo = outlink->src->priv;
75  BufPic *tmp;
76  int ret;
77 
78  if (!fifo->root.next) {
79  if ((ret = avfilter_request_frame(outlink->src->inputs[0]) < 0))
80  return ret;
81  }
82 
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);
88 
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;
94 
95  return 0;
96 }
97 
99  .name = "fifo",
100  .description = NULL_IF_CONFIG_SMALL("Buffer input images and send them when they are requested."),
101 
102  .init = init,
103  .uninit = uninit,
104 
105  .priv_size = sizeof(FifoContext),
106 
107  .inputs = (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, },
114  { .name = NULL}},
115  .outputs = (AVFilterPad[]) {{ .name = "default",
116  .type = AVMEDIA_TYPE_VIDEO,
117  .request_frame = request_frame, },
118  { .name = NULL}},
119 };
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:154
static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
Definition: vf_fifo.c:59
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_fifo.c:47
BufPic root
Definition: vf_fifo.c:34
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:547
#define av_cold
Definition: attributes.h:71
void avfilter_end_frame(AVFilterLink *link)
Notifie the next filter that the current frame has finished.
Definition: avfilter.c:430
static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
Definition: vf_fifo.c:38
static void end_frame(AVFilterLink *inlink)
Definition: vf_fifo.c:68
A filter pad used for either input or output.
Definition: avfilter.h:312
AVFilter avfilter_vf_fifo
Definition: vf_fifo.c:98
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:137
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:191
void * priv
private data for use by the filter
Definition: avfilter.h:553
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:140
AVFilterBufferRef * picref
Definition: vf_fifo.c:29
static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
Definition: vf_fifo.c:70
void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
Send a slice to the next filter.
Definition: avfilter.c:447
static int request_frame(AVFilterLink *outlink)
Definition: vf_fifo.c:72
void avfilter_unref_buffer(AVFilterBufferRef *ref)
Remove a reference to a buffer.
Definition: avfilter.c:73
A reference to an AVFilterBuffer.
Definition: avfilter.h:124
NULL
Definition: eval.c:50
Filter definition.
Definition: avfilter.h:497
Definition: vf_fifo.c:28
void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
Notify the next filter of the start of a frame.
Definition: avfilter.c:400
int avfilter_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:369
const char * name
filter name
Definition: avfilter.h:498
AVFilterBufferRef * avfilter_null_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
get_video_buffer() handler for filters which simply pass video along
Definition: defaults.c:288
#define AV_PERM_REUSE2
can output the buffer multiple times, modified each time
Definition: avfilter.h:85
struct BufPic BufPic
An instance of a filter.
Definition: avfilter.h:538
#define AV_LOG_INFO
Definition: log.h:119
struct BufPic * next
Definition: vf_fifo.c:30
BufPic * last
last buffered picture
Definition: vf_fifo.c:35