Browse code

Add "Memory buffer source filter" from SOC. This is needed by the current SOC-ffmpeg.c code.

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

Michael Niedermayer authored on 2010/05/07 10:25:00
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,140 @@
0
+/*
1
+ * Memory buffer source filter
2
+ * Copyright (c) 2008 Vitor Sessak
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
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.
10
+ *
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.
15
+ *
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
19
+ */
20
+
21
+#include "avfilter.h"
22
+#include "vsrc_buffer.h"
23
+
24
+typedef struct {
25
+    int64_t           pts;
26
+    AVFrame           frame;
27
+    int               has_frame;
28
+    int               h, w, pix_fmt;
29
+    AVRational        pixel_aspect;
30
+} BufferSourceContext;
31
+
32
+
33
+int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame,
34
+                             int64_t pts, AVRational pixel_aspect)
35
+{
36
+    BufferSourceContext *c = buffer_filter->priv;
37
+
38
+    if (c->has_frame) {
39
+        av_log(buffer_filter, AV_LOG_ERROR,
40
+               "Buffering several frames is not supported. "
41
+               "Please consume all available frames before adding a new one.\n"
42
+            );
43
+        //return -1;
44
+    }
45
+
46
+    memcpy(c->frame.data    , frame->data    , sizeof(frame->data));
47
+    memcpy(c->frame.linesize, frame->linesize, sizeof(frame->linesize));
48
+    c->pts = pts;
49
+    c->pixel_aspect = pixel_aspect;
50
+    c->has_frame = 1;
51
+
52
+    return 0;
53
+}
54
+
55
+static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
56
+{
57
+    BufferSourceContext *c = ctx->priv;
58
+
59
+    if(args && sscanf(args, "%d:%d:%d", &c->w, &c->h, &c->pix_fmt) == 3)
60
+        return 0;
61
+
62
+    av_log(ctx, AV_LOG_ERROR, "init() expected 3 arguments:'%s'\n", args);
63
+    return -1;
64
+}
65
+
66
+static int query_formats(AVFilterContext *ctx)
67
+{
68
+    BufferSourceContext *c = ctx->priv;
69
+    enum PixelFormat pix_fmts[] = { c->pix_fmt, PIX_FMT_NONE };
70
+
71
+    avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
72
+    return 0;
73
+}
74
+
75
+static int config_props(AVFilterLink *link)
76
+{
77
+    BufferSourceContext *c = link->src->priv;
78
+
79
+    link->w = c->w;
80
+    link->h = c->h;
81
+
82
+    return 0;
83
+}
84
+
85
+
86
+static int request_frame(AVFilterLink *link)
87
+{
88
+    BufferSourceContext *c = link->src->priv;
89
+    AVFilterPicRef *picref;
90
+
91
+    if (!c->has_frame) {
92
+        av_log(link->src, AV_LOG_ERROR,
93
+               "request_frame() called with no available frame!\n");
94
+        //return -1;
95
+    }
96
+
97
+    /* This picture will be needed unmodified later for decoding the next
98
+     * frame */
99
+    picref = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE |
100
+                                       AV_PERM_REUSE2,
101
+                                       link->w, link->h);
102
+
103
+    av_picture_copy((AVPicture *)&picref->data, (AVPicture *)&c->frame,
104
+                    picref->pic->format, link->w, link->h);
105
+
106
+    picref->pts = c->pts;
107
+    picref->pixel_aspect = c->pixel_aspect;
108
+    avfilter_start_frame(link, avfilter_ref_pic(picref, ~0));
109
+    avfilter_draw_slice(link, 0, link->h, 1);
110
+    avfilter_end_frame(link);
111
+    avfilter_unref_pic(picref);
112
+
113
+    c->has_frame = 0;
114
+
115
+    return 0;
116
+}
117
+
118
+static int poll_frame(AVFilterLink *link)
119
+{
120
+    BufferSourceContext *c = link->src->priv;
121
+    return !!(c->has_frame);
122
+}
123
+
124
+AVFilter avfilter_vsrc_buffer =
125
+{
126
+    .name      = "buffer",
127
+    .priv_size = sizeof(BufferSourceContext),
128
+    .query_formats = query_formats,
129
+
130
+    .init      = init,
131
+
132
+    .inputs    = (AVFilterPad[]) {{ .name = NULL }},
133
+    .outputs   = (AVFilterPad[]) {{ .name            = "default",
134
+                                    .type            = AVMEDIA_TYPE_VIDEO,
135
+                                    .request_frame   = request_frame,
136
+                                    .poll_frame      = poll_frame,
137
+                                    .config_props    = config_props, },
138
+                                  { .name = NULL}},
139
+};
0 140
new file mode 100644
... ...
@@ -0,0 +1,24 @@
0
+/*
1
+ * Memory buffer source filter
2
+ * Copyright (c) 2008 Vitor Sessak
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
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.
10
+ *
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.
15
+ *
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
19
+ */
20
+
21
+int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame,
22
+                             int64_t pts, AVRational pixel_aspect);
23
+