Browse code

lavfi: rename vsink_buffer.c to sink_buffer.c, and vsink_buffer.h to buffersink.h

This is done in order to clarify the non-video-specific nature of the
buffersink code, as the result of the video/audio API unification of
the previous commit, and for improving overall consistency.

Stefano Sabatini authored on 2011/09/07 01:37:44
Showing 12 changed files
... ...
@@ -52,7 +52,7 @@
52 52
 # include "libavfilter/avcodec.h"
53 53
 # include "libavfilter/avfilter.h"
54 54
 # include "libavfilter/avfiltergraph.h"
55
-# include "libavfilter/vsink_buffer.h"
55
+# include "libavfilter/buffersink.h"
56 56
 # include "libavfilter/vsrc_buffer.h"
57 57
 #endif
58 58
 
... ...
@@ -13,6 +13,9 @@ libavutil:   2011-04-18
13 13
 
14 14
 API changes, most recent first:
15 15
 
16
+2011-09-06 - xxxxxxx - lavfi 2.39.0
17
+  Rename libavfilter/vsink_buffer.h to libavfilter/buffersink.h.
18
+
16 19
 2011-09-06 - xxxxxxx - lavfi 2.38.0
17 20
   Unify video and audio sink API.
18 21
 
... ...
@@ -310,7 +310,7 @@ Below is a description of the currently available audio sinks.
310 310
 Buffer audio frames, and make them available to the end of filter chain.
311 311
 
312 312
 This sink is mainly intended for programmatic use, in particular
313
-through the interface defined in @file{libavfilter/vsink_buffer.h}.
313
+through the interface defined in @file{libavfilter/buffersink.h}.
314 314
 
315 315
 It requires a pointer to an AVABufferSinkContext structure, which
316 316
 defines the incoming buffers' formats, to be passed as the opaque
... ...
@@ -2408,7 +2408,7 @@ Buffer video frames, and make them available to the end of the filter
2408 2408
 graph.
2409 2409
 
2410 2410
 This sink is mainly intended for a programmatic use, in particular
2411
-through the interface defined in @file{libavfilter/vsink_buffer.h}.
2411
+through the interface defined in @file{libavfilter/buffersink.h}.
2412 2412
 
2413 2413
 It does not require a string parameter in input, but you need to
2414 2414
 specify a pointer to a list of supported pixel formats terminated by
... ...
@@ -52,7 +52,7 @@
52 52
 # include "libavfilter/avcodec.h"
53 53
 # include "libavfilter/avfilter.h"
54 54
 # include "libavfilter/avfiltergraph.h"
55
-# include "libavfilter/vsink_buffer.h"
55
+# include "libavfilter/buffersink.h"
56 56
 # include "libavfilter/vsrc_buffer.h"
57 57
 #endif
58 58
 
... ...
@@ -43,7 +43,7 @@
43 43
 # include "libavfilter/avcodec.h"
44 44
 # include "libavfilter/avfilter.h"
45 45
 # include "libavfilter/avfiltergraph.h"
46
-# include "libavfilter/vsink_buffer.h"
46
+# include "libavfilter/buffersink.h"
47 47
 #endif
48 48
 
49 49
 #include <SDL.h>
... ...
@@ -34,7 +34,7 @@
34 34
 #include "libavutil/pixdesc.h"
35 35
 #include "libavfilter/avfilter.h"
36 36
 #include "libavfilter/avfiltergraph.h"
37
-#include "libavfilter/vsink_buffer.h"
37
+#include "libavfilter/buffersink.h"
38 38
 #include "avdevice.h"
39 39
 
40 40
 typedef struct {
... ...
@@ -8,7 +8,7 @@ FFLIBS-$(CONFIG_MOVIE_FILTER) += avformat avcodec
8 8
 FFLIBS-$(CONFIG_SCALE_FILTER) += swscale
9 9
 FFLIBS-$(CONFIG_MP_FILTER) += avcodec
10 10
 
11
-HEADERS = avcodec.h avfilter.h avfiltergraph.h vsink_buffer.h vsrc_buffer.h
11
+HEADERS = avcodec.h avfilter.h avfiltergraph.h buffersink.h vsrc_buffer.h
12 12
 
13 13
 OBJS = allfilters.o                                                     \
14 14
        avfilter.o                                                       \
... ...
@@ -29,7 +29,7 @@ OBJS-$(CONFIG_ABUFFER_FILTER)                += asrc_abuffer.o
29 29
 OBJS-$(CONFIG_AMOVIE_FILTER)                 += src_movie.o
30 30
 OBJS-$(CONFIG_ANULLSRC_FILTER)               += asrc_anullsrc.o
31 31
 
32
-OBJS-$(CONFIG_ABUFFERSINK_FILTER)            += vsink_buffer.o
32
+OBJS-$(CONFIG_ABUFFERSINK_FILTER)            += sink_buffer.o
33 33
 OBJS-$(CONFIG_ANULLSINK_FILTER)              += asink_anullsink.o
34 34
 
35 35
 OBJS-$(CONFIG_BLACKFRAME_FILTER)             += vf_blackframe.o
... ...
@@ -82,7 +82,7 @@ OBJS-$(CONFIG_NULLSRC_FILTER)                += vsrc_nullsrc.o
82 82
 OBJS-$(CONFIG_RGBTESTSRC_FILTER)             += vsrc_testsrc.o
83 83
 OBJS-$(CONFIG_TESTSRC_FILTER)                += vsrc_testsrc.o
84 84
 
85
-OBJS-$(CONFIG_BUFFERSINK_FILTER)             += vsink_buffer.o
85
+OBJS-$(CONFIG_BUFFERSINK_FILTER)             += sink_buffer.o
86 86
 OBJS-$(CONFIG_NULLSINK_FILTER)               += vsink_nullsink.o
87 87
 
88 88
 
... ...
@@ -29,7 +29,7 @@
29 29
 #include "libavutil/rational.h"
30 30
 
31 31
 #define LIBAVFILTER_VERSION_MAJOR  2
32
-#define LIBAVFILTER_VERSION_MINOR 38
32
+#define LIBAVFILTER_VERSION_MINOR 39
33 33
 #define LIBAVFILTER_VERSION_MICRO  0
34 34
 
35 35
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
36 36
new file mode 100644
... ...
@@ -0,0 +1,88 @@
0
+/*
1
+ * This file is part of FFmpeg.
2
+ *
3
+ * FFmpeg is free software; you can redistribute it and/or
4
+ * modify it under the terms of the GNU Lesser General Public
5
+ * License as published by the Free Software Foundation; either
6
+ * version 2.1 of the License, or (at your option) any later version.
7
+ *
8
+ * FFmpeg is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
+ * Lesser General Public License for more details.
12
+ *
13
+ * You should have received a copy of the GNU Lesser General Public
14
+ * License along with FFmpeg; if not, write to the Free Software
15
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+ */
17
+
18
+#ifndef AVFILTER_VSINK_BUFFER_H
19
+#define AVFILTER_VSINK_BUFFER_H
20
+
21
+/**
22
+ * @file
23
+ * memory buffer sink API for audio and video
24
+ */
25
+
26
+#include "avfilter.h"
27
+
28
+/**
29
+ * Struct to use for initializing a buffersink context.
30
+ */
31
+typedef struct {
32
+    const enum PixelFormat *pixel_fmts; ///< list of allowed pixel formats, terminated by PIX_FMT_NONE
33
+} AVBufferSinkParams;
34
+
35
+/**
36
+ * Create an AVBufferSinkParams structure.
37
+ *
38
+ * Must be freed with av_free().
39
+ */
40
+AVBufferSinkParams *av_buffersink_params_alloc(void);
41
+
42
+/**
43
+ * Struct to use for initializing an abuffersink context.
44
+ */
45
+typedef struct {
46
+    const enum AVSampleFormat *sample_fmts; ///< list of allowed sample formats, terminated by AV_SAMPLE_FMT_NONE
47
+    const int64_t *channel_layouts;         ///< list of allowed channel layouts, terminated by -1
48
+    const int *packing_fmts;                ///< list of allowed packing formats
49
+} AVABufferSinkParams;
50
+
51
+/**
52
+ * Create an AVABufferSinkParams structure.
53
+ *
54
+ * Must be freed with av_free().
55
+ */
56
+AVABufferSinkParams *av_abuffersink_params_alloc(void);
57
+
58
+/**
59
+ * Tell av_buffersink_get_buffer_ref() to read video/samples buffer
60
+ * reference, but not remove it from the buffer. This is useful if you
61
+ * need only to read a video/samples buffer, without to fetch it.
62
+ */
63
+#define AV_BUFFERSINK_FLAG_PEEK 1
64
+
65
+/**
66
+ * Get an audio/video buffer data from buffer_sink and put it in bufref.
67
+ *
68
+ * This function works with both audio and video buffer sinks.
69
+ *
70
+ * @param buffer_sink pointer to a buffersink or abuffersink context
71
+ * @param flags a combination of AV_BUFFERSINK_FLAG_* flags
72
+ * @return >= 0 in case of success, a negative AVERROR code in case of
73
+ * failure
74
+ */
75
+int av_buffersink_get_buffer_ref(AVFilterContext *buffer_sink,
76
+                                 AVFilterBufferRef **bufref, int flags);
77
+
78
+#if FF_API_OLD_VSINK_API
79
+/**
80
+ * @deprecated Use av_buffersink_get_buffer_ref() instead.
81
+ */
82
+attribute_deprecated
83
+int av_vsink_buffer_get_video_buffer_ref(AVFilterContext *buffer_sink,
84
+                                         AVFilterBufferRef **picref, int flags);
85
+#endif
86
+
87
+#endif /* AVFILTER_VSINK_BUFFER_H */
0 88
new file mode 100644
... ...
@@ -0,0 +1,263 @@
0
+/*
1
+ * Copyright (c) 2011 Stefano Sabatini
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
+ * buffer video sink
23
+ */
24
+
25
+#include "libavutil/fifo.h"
26
+#include "avfilter.h"
27
+#include "buffersink.h"
28
+
29
+AVBufferSinkParams *av_buffersink_params_alloc(void)
30
+{
31
+    static const int pixel_fmts[] = { -1 };
32
+    AVBufferSinkParams *params = av_malloc(sizeof(AVBufferSinkParams));
33
+    if (!params)
34
+        return NULL;
35
+
36
+    params->pixel_fmts = pixel_fmts;
37
+    return params;
38
+}
39
+
40
+AVABufferSinkParams *av_abuffersink_params_alloc(void)
41
+{
42
+    static const int sample_fmts[] = { -1 };
43
+    static const int packing_fmts[] = { -1 };
44
+    static const int64_t channel_layouts[] = { -1 };
45
+    AVABufferSinkParams *params = av_malloc(sizeof(AVABufferSinkParams));
46
+
47
+    if (!params)
48
+        return NULL;
49
+
50
+    params->sample_fmts = sample_fmts;
51
+    params->channel_layouts = channel_layouts;
52
+    params->packing_fmts = packing_fmts;
53
+    return params;
54
+}
55
+
56
+typedef struct {
57
+    AVFifoBuffer *fifo;                      ///< FIFO buffer of video frame references
58
+
59
+    /* only used for video */
60
+    const enum PixelFormat *pixel_fmts;     ///< list of accepted pixel formats, must be terminated with -1
61
+
62
+    /* only used for audio */
63
+    const enum AVSampleFormat *sample_fmts; ///< list of accepted sample formats, terminated by AV_SAMPLE_FMT_NONE
64
+    const int64_t *channel_layouts;         ///< list of accepted channel layouts, terminated by -1
65
+    const int *packing_fmts;                ///< list of accepted packing formats, terminated by -1
66
+} BufferSinkContext;
67
+
68
+#define FIFO_INIT_SIZE 8
69
+
70
+static av_cold int common_init(AVFilterContext *ctx)
71
+{
72
+    BufferSinkContext *buf = ctx->priv;
73
+
74
+    buf->fifo = av_fifo_alloc(FIFO_INIT_SIZE*sizeof(AVFilterBufferRef *));
75
+    if (!buf->fifo) {
76
+        av_log(ctx, AV_LOG_ERROR, "Failed to allocate fifo\n");
77
+        return AVERROR(ENOMEM);
78
+    }
79
+    return 0;
80
+}
81
+
82
+static av_cold void common_uninit(AVFilterContext *ctx)
83
+{
84
+    BufferSinkContext *buf = ctx->priv;
85
+    AVFilterBufferRef *picref;
86
+
87
+    if (buf->fifo) {
88
+        while (av_fifo_size(buf->fifo) >= sizeof(AVFilterBufferRef *)) {
89
+            av_fifo_generic_read(buf->fifo, &picref, sizeof(picref), NULL);
90
+            avfilter_unref_buffer(picref);
91
+        }
92
+        av_fifo_free(buf->fifo);
93
+        buf->fifo = NULL;
94
+    }
95
+}
96
+
97
+static void end_frame(AVFilterLink *inlink)
98
+{
99
+    AVFilterContext *ctx = inlink->dst;
100
+    BufferSinkContext *buf = inlink->dst->priv;
101
+
102
+    if (av_fifo_space(buf->fifo) < sizeof(AVFilterBufferRef *)) {
103
+        /* realloc fifo size */
104
+        if (av_fifo_realloc2(buf->fifo, av_fifo_size(buf->fifo) * 2) < 0) {
105
+            av_log(ctx, AV_LOG_ERROR,
106
+                   "Cannot buffer more frames. Consume some available frames "
107
+                   "before adding new ones.\n");
108
+            return;
109
+        }
110
+    }
111
+
112
+    /* cache frame */
113
+    av_fifo_generic_write(buf->fifo,
114
+                          &inlink->cur_buf, sizeof(AVFilterBufferRef *), NULL);
115
+}
116
+
117
+int av_buffersink_get_buffer_ref(AVFilterContext *ctx,
118
+                                  AVFilterBufferRef **bufref, int flags)
119
+{
120
+    BufferSinkContext *buf = ctx->priv;
121
+    AVFilterLink *inlink = ctx->inputs[0];
122
+    int ret;
123
+    *bufref = NULL;
124
+
125
+    /* no picref available, fetch it from the filterchain */
126
+    if (!av_fifo_size(buf->fifo)) {
127
+        if ((ret = avfilter_request_frame(inlink)) < 0)
128
+            return ret;
129
+    }
130
+
131
+    if (!av_fifo_size(buf->fifo))
132
+        return AVERROR(EINVAL);
133
+
134
+    if (flags & AV_BUFFERSINK_FLAG_PEEK)
135
+        *bufref = *((AVFilterBufferRef **)av_fifo_peek2(buf->fifo, 0));
136
+    else
137
+        av_fifo_generic_read(buf->fifo, bufref, sizeof(*bufref), NULL);
138
+
139
+    return 0;
140
+}
141
+
142
+#if FF_API_OLD_VSINK_API
143
+int av_vsink_buffer_get_video_buffer_ref(AVFilterContext *ctx,
144
+                                         AVFilterBufferRef **picref, int flags)
145
+{
146
+    return av_buffersink_get_buffer_ref(ctx, picref, flags);
147
+}
148
+#endif
149
+
150
+#if CONFIG_BUFFERSINK_FILTER
151
+
152
+static av_cold int vsink_init(AVFilterContext *ctx, const char *args, void *opaque)
153
+{
154
+    BufferSinkContext *buf = ctx->priv;
155
+    av_unused AVBufferSinkParams *params;
156
+
157
+    if (!opaque) {
158
+        av_log(ctx, AV_LOG_ERROR,
159
+               "No opaque field provided\n");
160
+        return AVERROR(EINVAL);
161
+    } else {
162
+#if FF_API_OLD_VSINK_API
163
+        buf->pixel_fmts = (const enum PixelFormats *)opaque;
164
+#else
165
+        params = (AVBufferSinkParams *)opaque;
166
+        buf->pixel_fmts = params->pixel_fmts;
167
+#endif
168
+    }
169
+
170
+    return common_init(ctx);
171
+}
172
+
173
+static int vsink_query_formats(AVFilterContext *ctx)
174
+{
175
+    BufferSinkContext *buf = ctx->priv;
176
+
177
+    avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(buf->pixel_fmts));
178
+    return 0;
179
+}
180
+
181
+AVFilter avfilter_vsink_buffersink = {
182
+    .name      = "buffersink",
183
+    .description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."),
184
+    .priv_size = sizeof(BufferSinkContext),
185
+    .init      = vsink_init,
186
+    .uninit    = common_uninit,
187
+
188
+    .query_formats = vsink_query_formats,
189
+
190
+    .inputs    = (AVFilterPad[]) {{ .name          = "default",
191
+                                    .type          = AVMEDIA_TYPE_VIDEO,
192
+                                    .end_frame     = end_frame,
193
+                                    .min_perms     = AV_PERM_READ, },
194
+                                  { .name = NULL }},
195
+    .outputs   = (AVFilterPad[]) {{ .name = NULL }},
196
+};
197
+
198
+#endif /* CONFIG_BUFFERSINK_FILTER */
199
+
200
+#if CONFIG_ABUFFERSINK_FILTER
201
+
202
+static void filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
203
+{
204
+    end_frame(link);
205
+}
206
+
207
+static av_cold int asink_init(AVFilterContext *ctx, const char *args, void *opaque)
208
+{
209
+    BufferSinkContext *buf = ctx->priv;
210
+    AVABufferSinkParams *params;
211
+
212
+    if (!opaque) {
213
+        av_log(ctx, AV_LOG_ERROR,
214
+               "No opaque field provided, an AVABufferSinkParams struct is required\n");
215
+        return AVERROR(EINVAL);
216
+    } else
217
+        params = (AVABufferSinkParams *)opaque;
218
+
219
+    buf->sample_fmts     = params->sample_fmts;
220
+    buf->channel_layouts = params->channel_layouts;
221
+    buf->packing_fmts    = params->packing_fmts;
222
+
223
+    return common_init(ctx);
224
+}
225
+
226
+static int asink_query_formats(AVFilterContext *ctx)
227
+{
228
+    BufferSinkContext *buf = ctx->priv;
229
+    AVFilterFormats *formats = NULL;
230
+
231
+    if (!(formats = avfilter_make_format_list(buf->sample_fmts)))
232
+        return AVERROR(ENOMEM);
233
+    avfilter_set_common_sample_formats(ctx, formats);
234
+
235
+    if (!(formats = avfilter_make_format64_list(buf->channel_layouts)))
236
+        return AVERROR(ENOMEM);
237
+    avfilter_set_common_channel_layouts(ctx, formats);
238
+
239
+    if (!(formats = avfilter_make_format_list(buf->packing_fmts)))
240
+        return AVERROR(ENOMEM);
241
+    avfilter_set_common_packing_formats(ctx, formats);
242
+
243
+    return 0;
244
+}
245
+
246
+AVFilter avfilter_asink_abuffersink = {
247
+    .name      = "abuffersink",
248
+    .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."),
249
+    .init      = asink_init,
250
+    .uninit    = common_uninit,
251
+    .priv_size = sizeof(BufferSinkContext),
252
+    .query_formats = asink_query_formats,
253
+
254
+    .inputs    = (AVFilterPad[]) {{ .name           = "default",
255
+                                    .type           = AVMEDIA_TYPE_AUDIO,
256
+                                    .filter_samples = filter_samples,
257
+                                    .min_perms      = AV_PERM_READ, },
258
+                                  { .name = NULL }},
259
+    .outputs   = (AVFilterPad[]) {{ .name = NULL }},
260
+};
261
+
262
+#endif /* CONFIG_ABUFFERSINK_FILTER */
0 263
deleted file mode 100644
... ...
@@ -1,263 +0,0 @@
1
-/*
2
- * Copyright (c) 2011 Stefano Sabatini
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
-/**
22
- * @file
23
- * buffer video sink
24
- */
25
-
26
-#include "libavutil/fifo.h"
27
-#include "avfilter.h"
28
-#include "vsink_buffer.h"
29
-
30
-AVBufferSinkParams *av_buffersink_params_alloc(void)
31
-{
32
-    static const int pixel_fmts[] = { -1 };
33
-    AVBufferSinkParams *params = av_malloc(sizeof(AVBufferSinkParams));
34
-    if (!params)
35
-        return NULL;
36
-
37
-    params->pixel_fmts = pixel_fmts;
38
-    return params;
39
-}
40
-
41
-AVABufferSinkParams *av_abuffersink_params_alloc(void)
42
-{
43
-    static const int sample_fmts[] = { -1 };
44
-    static const int packing_fmts[] = { -1 };
45
-    static const int64_t channel_layouts[] = { -1 };
46
-    AVABufferSinkParams *params = av_malloc(sizeof(AVABufferSinkParams));
47
-
48
-    if (!params)
49
-        return NULL;
50
-
51
-    params->sample_fmts = sample_fmts;
52
-    params->channel_layouts = channel_layouts;
53
-    params->packing_fmts = packing_fmts;
54
-    return params;
55
-}
56
-
57
-typedef struct {
58
-    AVFifoBuffer *fifo;                      ///< FIFO buffer of video frame references
59
-
60
-    /* only used for video */
61
-    const enum PixelFormat *pixel_fmts;     ///< list of accepted pixel formats, must be terminated with -1
62
-
63
-    /* only used for audio */
64
-    const enum AVSampleFormat *sample_fmts; ///< list of accepted sample formats, terminated by AV_SAMPLE_FMT_NONE
65
-    const int64_t *channel_layouts;         ///< list of accepted channel layouts, terminated by -1
66
-    const int *packing_fmts;                ///< list of accepted packing formats, terminated by -1
67
-} BufferSinkContext;
68
-
69
-#define FIFO_INIT_SIZE 8
70
-
71
-static av_cold int common_init(AVFilterContext *ctx)
72
-{
73
-    BufferSinkContext *buf = ctx->priv;
74
-
75
-    buf->fifo = av_fifo_alloc(FIFO_INIT_SIZE*sizeof(AVFilterBufferRef *));
76
-    if (!buf->fifo) {
77
-        av_log(ctx, AV_LOG_ERROR, "Failed to allocate fifo\n");
78
-        return AVERROR(ENOMEM);
79
-    }
80
-    return 0;
81
-}
82
-
83
-static av_cold void common_uninit(AVFilterContext *ctx)
84
-{
85
-    BufferSinkContext *buf = ctx->priv;
86
-    AVFilterBufferRef *picref;
87
-
88
-    if (buf->fifo) {
89
-        while (av_fifo_size(buf->fifo) >= sizeof(AVFilterBufferRef *)) {
90
-            av_fifo_generic_read(buf->fifo, &picref, sizeof(picref), NULL);
91
-            avfilter_unref_buffer(picref);
92
-        }
93
-        av_fifo_free(buf->fifo);
94
-        buf->fifo = NULL;
95
-    }
96
-}
97
-
98
-static void end_frame(AVFilterLink *inlink)
99
-{
100
-    AVFilterContext *ctx = inlink->dst;
101
-    BufferSinkContext *buf = inlink->dst->priv;
102
-
103
-    if (av_fifo_space(buf->fifo) < sizeof(AVFilterBufferRef *)) {
104
-        /* realloc fifo size */
105
-        if (av_fifo_realloc2(buf->fifo, av_fifo_size(buf->fifo) * 2) < 0) {
106
-            av_log(ctx, AV_LOG_ERROR,
107
-                   "Cannot buffer more frames. Consume some available frames "
108
-                   "before adding new ones.\n");
109
-            return;
110
-        }
111
-    }
112
-
113
-    /* cache frame */
114
-    av_fifo_generic_write(buf->fifo,
115
-                          &inlink->cur_buf, sizeof(AVFilterBufferRef *), NULL);
116
-}
117
-
118
-int av_buffersink_get_buffer_ref(AVFilterContext *ctx,
119
-                                  AVFilterBufferRef **bufref, int flags)
120
-{
121
-    BufferSinkContext *buf = ctx->priv;
122
-    AVFilterLink *inlink = ctx->inputs[0];
123
-    int ret;
124
-    *bufref = NULL;
125
-
126
-    /* no picref available, fetch it from the filterchain */
127
-    if (!av_fifo_size(buf->fifo)) {
128
-        if ((ret = avfilter_request_frame(inlink)) < 0)
129
-            return ret;
130
-    }
131
-
132
-    if (!av_fifo_size(buf->fifo))
133
-        return AVERROR(EINVAL);
134
-
135
-    if (flags & AV_BUFFERSINK_FLAG_PEEK)
136
-        *bufref = *((AVFilterBufferRef **)av_fifo_peek2(buf->fifo, 0));
137
-    else
138
-        av_fifo_generic_read(buf->fifo, bufref, sizeof(*bufref), NULL);
139
-
140
-    return 0;
141
-}
142
-
143
-#if FF_API_OLD_VSINK_API
144
-int av_vsink_buffer_get_video_buffer_ref(AVFilterContext *ctx,
145
-                                         AVFilterBufferRef **picref, int flags)
146
-{
147
-    return av_buffersink_get_buffer_ref(ctx, picref, flags);
148
-}
149
-#endif
150
-
151
-#if CONFIG_BUFFERSINK_FILTER
152
-
153
-static av_cold int vsink_init(AVFilterContext *ctx, const char *args, void *opaque)
154
-{
155
-    BufferSinkContext *buf = ctx->priv;
156
-    av_unused AVBufferSinkParams *params;
157
-
158
-    if (!opaque) {
159
-        av_log(ctx, AV_LOG_ERROR,
160
-               "No opaque field provided\n");
161
-        return AVERROR(EINVAL);
162
-    } else {
163
-#if FF_API_OLD_VSINK_API
164
-        buf->pixel_fmts = (const enum PixelFormats *)opaque;
165
-#else
166
-        params = (AVBufferSinkParams *)opaque;
167
-        buf->pixel_fmts = params->pixel_fmts;
168
-#endif
169
-    }
170
-
171
-    return common_init(ctx);
172
-}
173
-
174
-static int vsink_query_formats(AVFilterContext *ctx)
175
-{
176
-    BufferSinkContext *buf = ctx->priv;
177
-
178
-    avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(buf->pixel_fmts));
179
-    return 0;
180
-}
181
-
182
-AVFilter avfilter_vsink_buffersink = {
183
-    .name      = "buffersink",
184
-    .description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."),
185
-    .priv_size = sizeof(BufferSinkContext),
186
-    .init      = vsink_init,
187
-    .uninit    = common_uninit,
188
-
189
-    .query_formats = vsink_query_formats,
190
-
191
-    .inputs    = (AVFilterPad[]) {{ .name          = "default",
192
-                                    .type          = AVMEDIA_TYPE_VIDEO,
193
-                                    .end_frame     = end_frame,
194
-                                    .min_perms     = AV_PERM_READ, },
195
-                                  { .name = NULL }},
196
-    .outputs   = (AVFilterPad[]) {{ .name = NULL }},
197
-};
198
-
199
-#endif /* CONFIG_BUFFERSINK_FILTER */
200
-
201
-#if CONFIG_ABUFFERSINK_FILTER
202
-
203
-static void filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
204
-{
205
-    end_frame(link);
206
-}
207
-
208
-static av_cold int asink_init(AVFilterContext *ctx, const char *args, void *opaque)
209
-{
210
-    BufferSinkContext *buf = ctx->priv;
211
-    AVABufferSinkParams *params;
212
-
213
-    if (!opaque) {
214
-        av_log(ctx, AV_LOG_ERROR,
215
-               "No opaque field provided, an AVABufferSinkParams struct is required\n");
216
-        return AVERROR(EINVAL);
217
-    } else
218
-        params = (AVABufferSinkParams *)opaque;
219
-
220
-    buf->sample_fmts     = params->sample_fmts;
221
-    buf->channel_layouts = params->channel_layouts;
222
-    buf->packing_fmts    = params->packing_fmts;
223
-
224
-    return common_init(ctx);
225
-}
226
-
227
-static int asink_query_formats(AVFilterContext *ctx)
228
-{
229
-    BufferSinkContext *buf = ctx->priv;
230
-    AVFilterFormats *formats = NULL;
231
-
232
-    if (!(formats = avfilter_make_format_list(buf->sample_fmts)))
233
-        return AVERROR(ENOMEM);
234
-    avfilter_set_common_sample_formats(ctx, formats);
235
-
236
-    if (!(formats = avfilter_make_format64_list(buf->channel_layouts)))
237
-        return AVERROR(ENOMEM);
238
-    avfilter_set_common_channel_layouts(ctx, formats);
239
-
240
-    if (!(formats = avfilter_make_format_list(buf->packing_fmts)))
241
-        return AVERROR(ENOMEM);
242
-    avfilter_set_common_packing_formats(ctx, formats);
243
-
244
-    return 0;
245
-}
246
-
247
-AVFilter avfilter_asink_abuffersink = {
248
-    .name      = "abuffersink",
249
-    .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."),
250
-    .init      = asink_init,
251
-    .uninit    = common_uninit,
252
-    .priv_size = sizeof(BufferSinkContext),
253
-    .query_formats = asink_query_formats,
254
-
255
-    .inputs    = (AVFilterPad[]) {{ .name           = "default",
256
-                                    .type           = AVMEDIA_TYPE_AUDIO,
257
-                                    .filter_samples = filter_samples,
258
-                                    .min_perms      = AV_PERM_READ, },
259
-                                  { .name = NULL }},
260
-    .outputs   = (AVFilterPad[]) {{ .name = NULL }},
261
-};
262
-
263
-#endif /* CONFIG_ABUFFERSINK_FILTER */
264 1
deleted file mode 100644
... ...
@@ -1,88 +0,0 @@
1
-/*
2
- * This file is part of FFmpeg.
3
- *
4
- * FFmpeg is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU Lesser General Public
6
- * License as published by the Free Software Foundation; either
7
- * version 2.1 of the License, or (at your option) any later version.
8
- *
9
- * FFmpeg is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
- * Lesser General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU Lesser General Public
15
- * License along with FFmpeg; if not, write to the Free Software
16
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
- */
18
-
19
-#ifndef AVFILTER_VSINK_BUFFER_H
20
-#define AVFILTER_VSINK_BUFFER_H
21
-
22
-/**
23
- * @file
24
- * memory buffer sink API for audio and video
25
- */
26
-
27
-#include "avfilter.h"
28
-
29
-/**
30
- * Struct to use for initializing a buffersink context.
31
- */
32
-typedef struct {
33
-    const enum PixelFormat *pixel_fmts; ///< list of allowed pixel formats, terminated by PIX_FMT_NONE
34
-} AVBufferSinkParams;
35
-
36
-/**
37
- * Create an AVBufferSinkParams structure.
38
- *
39
- * Must be freed with av_free().
40
- */
41
-AVBufferSinkParams *av_buffersink_params_alloc(void);
42
-
43
-/**
44
- * Struct to use for initializing an abuffersink context.
45
- */
46
-typedef struct {
47
-    const enum AVSampleFormat *sample_fmts; ///< list of allowed sample formats, terminated by AV_SAMPLE_FMT_NONE
48
-    const int64_t *channel_layouts;         ///< list of allowed channel layouts, terminated by -1
49
-    const int *packing_fmts;                ///< list of allowed packing formats
50
-} AVABufferSinkParams;
51
-
52
-/**
53
- * Create an AVABufferSinkParams structure.
54
- *
55
- * Must be freed with av_free().
56
- */
57
-AVABufferSinkParams *av_abuffersink_params_alloc(void);
58
-
59
-/**
60
- * Tell av_buffersink_get_buffer_ref() to read video/samples buffer
61
- * reference, but not remove it from the buffer. This is useful if you
62
- * need only to read a video/samples buffer, without to fetch it.
63
- */
64
-#define AV_BUFFERSINK_FLAG_PEEK 1
65
-
66
-/**
67
- * Get an audio/video buffer data from buffer_sink and put it in bufref.
68
- *
69
- * This function works with both audio and video buffer sinks.
70
- *
71
- * @param buffer_sink pointer to a buffersink or abuffersink context
72
- * @param flags a combination of AV_BUFFERSINK_FLAG_* flags
73
- * @return >= 0 in case of success, a negative AVERROR code in case of
74
- * failure
75
- */
76
-int av_buffersink_get_buffer_ref(AVFilterContext *buffer_sink,
77
-                                 AVFilterBufferRef **bufref, int flags);
78
-
79
-#if FF_API_OLD_VSINK_API
80
-/**
81
- * @deprecated Use av_buffersink_get_buffer_ref() instead.
82
- */
83
-attribute_deprecated
84
-int av_vsink_buffer_get_video_buffer_ref(AVFilterContext *buffer_sink,
85
-                                         AVFilterBufferRef **picref, int flags);
86
-#endif
87
-
88
-#endif /* AVFILTER_VSINK_BUFFER_H */