Browse code

Add fifo filter.

Originally committed as revision 24896 to svn://svn.ffmpeg.org/ffmpeg/trunk

Stefano Sabatini authored on 2010/08/24 17:38:00
Showing 5 changed files
... ...
@@ -55,6 +55,15 @@ corner of the input image.
55 55
 
56 56
 The default value of @var{width} and @var{height} is 0.
57 57
 
58
+@section fifo
59
+
60
+Buffer input images and send them when they are requested.
61
+
62
+This filter is mainly useful when auto-inserted by the libavfilter
63
+framework.
64
+
65
+The filter does not take parameters.
66
+
58 67
 @section format
59 68
 
60 69
 Convert the input video to one of the specified pixel formats.
... ...
@@ -18,6 +18,7 @@ OBJS-$(CONFIG_ANULL_FILTER)                  += af_anull.o
18 18
 
19 19
 OBJS-$(CONFIG_ASPECT_FILTER)                 += vf_aspect.o
20 20
 OBJS-$(CONFIG_CROP_FILTER)                   += vf_crop.o
21
+OBJS-$(CONFIG_FIFO_FILTER)                   += vf_fifo.o
21 22
 OBJS-$(CONFIG_FORMAT_FILTER)                 += vf_format.o
22 23
 OBJS-$(CONFIG_HFLIP_FILTER)                  += vf_hflip.o
23 24
 OBJS-$(CONFIG_NOFORMAT_FILTER)               += vf_format.o
... ...
@@ -38,6 +38,7 @@ void avfilter_register_all(void)
38 38
 
39 39
     REGISTER_FILTER (ASPECT,      aspect,      vf);
40 40
     REGISTER_FILTER (CROP,        crop,        vf);
41
+    REGISTER_FILTER (FIFO,        fifo,        vf);
41 42
     REGISTER_FILTER (FORMAT,      format,      vf);
42 43
     REGISTER_FILTER (HFLIP,       hflip,       vf);
43 44
     REGISTER_FILTER (NOFORMAT,    noformat,    vf);
... ...
@@ -25,7 +25,7 @@
25 25
 #include "libavutil/avutil.h"
26 26
 
27 27
 #define LIBAVFILTER_VERSION_MAJOR  1
28
-#define LIBAVFILTER_VERSION_MINOR 37
28
+#define LIBAVFILTER_VERSION_MINOR 38
29 29
 #define LIBAVFILTER_VERSION_MICRO  0
30 30
 
31 31
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
32 32
new file mode 100644
... ...
@@ -0,0 +1,119 @@
0
+/*
1
+ * copyright (c) 2007 Bobby Bingham
2
+ *
3
+ * This file is part of FFmpeg.
4
+ *
5
+ * FFmpeg is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * FFmpeg is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with FFmpeg; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+/**
21
+ * @file
22
+ * FIFO buffering video filter
23
+ */
24
+
25
+#include "avfilter.h"
26
+
27
+typedef struct BufPic {
28
+    AVFilterBufferRef *picref;
29
+    struct BufPic     *next;
30
+} BufPic;
31
+
32
+typedef struct {
33
+    BufPic  root;
34
+    BufPic *last;   ///< last buffered picture
35
+} FifoContext;
36
+
37
+static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
38
+{
39
+    FifoContext *fifo = ctx->priv;
40
+    fifo->last = &fifo->root;
41
+
42
+    av_log(ctx, AV_LOG_INFO, "\n");
43
+    return 0;
44
+}
45
+
46
+static av_cold void uninit(AVFilterContext *ctx)
47
+{
48
+    FifoContext *fifo = ctx->priv;
49
+    BufPic *pic, *tmp;
50
+
51
+    for (pic = fifo->root.next; pic; pic = tmp) {
52
+        tmp = pic->next;
53
+        avfilter_unref_buffer(pic->picref);
54
+        av_free(pic);
55
+    }
56
+}
57
+
58
+static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
59
+{
60
+    FifoContext *fifo = inlink->dst->priv;
61
+
62
+    fifo->last->next = av_mallocz(sizeof(BufPic));
63
+    fifo->last = fifo->last->next;
64
+    fifo->last->picref = picref;
65
+}
66
+
67
+static void end_frame(AVFilterLink *inlink) { }
68
+
69
+static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { }
70
+
71
+static int request_frame(AVFilterLink *outlink)
72
+{
73
+    FifoContext *fifo = outlink->src->priv;
74
+    BufPic *tmp;
75
+    int ret;
76
+
77
+    if (!fifo->root.next) {
78
+        if ((ret = avfilter_request_frame(outlink->src->inputs[0]) < 0))
79
+            return ret;
80
+    }
81
+
82
+    /* by doing this, we give ownership of the reference to the next filter,
83
+     * so we don't have to worry about dereferencing it ourselves. */
84
+    avfilter_start_frame(outlink, fifo->root.next->picref);
85
+    avfilter_draw_slice (outlink, 0, outlink->h, 1);
86
+    avfilter_end_frame  (outlink);
87
+
88
+    if (fifo->last == fifo->root.next)
89
+        fifo->last = &fifo->root;
90
+    tmp = fifo->root.next->next;
91
+    av_free(fifo->root.next);
92
+    fifo->root.next = tmp;
93
+
94
+    return 0;
95
+}
96
+
97
+AVFilter avfilter_vf_fifo = {
98
+    .name      = "fifo",
99
+    .description = NULL_IF_CONFIG_SMALL("Buffer input images and send them when they are requested."),
100
+
101
+    .init      = init,
102
+    .uninit    = uninit,
103
+
104
+    .priv_size = sizeof(FifoContext),
105
+
106
+    .inputs    = (AVFilterPad[]) {{ .name            = "default",
107
+                                    .type            = AVMEDIA_TYPE_VIDEO,
108
+                                    .get_video_buffer= avfilter_null_get_video_buffer,
109
+                                    .start_frame     = start_frame,
110
+                                    .draw_slice      = draw_slice,
111
+                                    .end_frame       = end_frame,
112
+                                    .rej_perms       = AV_PERM_REUSE2, },
113
+                                  { .name = NULL}},
114
+    .outputs   = (AVFilterPad[]) {{ .name            = "default",
115
+                                    .type            = AVMEDIA_TYPE_VIDEO,
116
+                                    .request_frame   = request_frame, },
117
+                                  { .name = NULL}},
118
+};