Note: av_buffersink_get_samples() is not yet implemented,
abuffersink is not yet a drop-in replacement of the fork's
abuffersink.
... | ... |
@@ -23,36 +23,17 @@ |
23 | 23 |
* buffer sink |
24 | 24 |
*/ |
25 | 25 |
|
26 |
+#include "libavutil/fifo.h" |
|
26 | 27 |
#include "libavutil/avassert.h" |
27 | 28 |
#include "libavutil/channel_layout.h" |
28 |
-#include "libavutil/fifo.h" |
|
29 |
+#include "libavutil/common.h" |
|
30 |
+#include "libavutil/mathematics.h" |
|
31 |
+ |
|
32 |
+#include "audio.h" |
|
29 | 33 |
#include "avfilter.h" |
30 | 34 |
#include "buffersink.h" |
31 |
-#include "audio.h" |
|
32 | 35 |
#include "internal.h" |
33 | 36 |
|
34 |
-#include "libavutil/audio_fifo.h" |
|
35 |
- |
|
36 |
-AVBufferSinkParams *av_buffersink_params_alloc(void) |
|
37 |
-{ |
|
38 |
- static const int pixel_fmts[] = { AV_PIX_FMT_NONE }; |
|
39 |
- AVBufferSinkParams *params = av_malloc(sizeof(AVBufferSinkParams)); |
|
40 |
- if (!params) |
|
41 |
- return NULL; |
|
42 |
- |
|
43 |
- params->pixel_fmts = pixel_fmts; |
|
44 |
- return params; |
|
45 |
-} |
|
46 |
- |
|
47 |
-AVABufferSinkParams *av_abuffersink_params_alloc(void) |
|
48 |
-{ |
|
49 |
- AVABufferSinkParams *params = av_mallocz(sizeof(AVABufferSinkParams)); |
|
50 |
- |
|
51 |
- if (!params) |
|
52 |
- return NULL; |
|
53 |
- return params; |
|
54 |
-} |
|
55 |
- |
|
56 | 37 |
typedef struct { |
57 | 38 |
AVFifoBuffer *fifo; ///< FIFO buffer of video frame references |
58 | 39 |
unsigned warning_limit; |
... | ... |
@@ -67,34 +48,23 @@ typedef struct { |
67 | 67 |
int *sample_rates; ///< list of accepted sample rates, terminated by -1 |
68 | 68 |
} BufferSinkContext; |
69 | 69 |
|
70 |
-#define FIFO_INIT_SIZE 8 |
|
71 |
- |
|
72 |
-static av_cold int common_init(AVFilterContext *ctx) |
|
73 |
-{ |
|
74 |
- BufferSinkContext *buf = ctx->priv; |
|
75 |
- |
|
76 |
- buf->fifo = av_fifo_alloc(FIFO_INIT_SIZE*sizeof(AVFilterBufferRef *)); |
|
77 |
- if (!buf->fifo) { |
|
78 |
- av_log(ctx, AV_LOG_ERROR, "Failed to allocate fifo\n"); |
|
79 |
- return AVERROR(ENOMEM); |
|
80 |
- } |
|
81 |
- buf->warning_limit = 100; |
|
82 |
- return 0; |
|
83 |
-} |
|
84 |
- |
|
85 |
-static av_cold void common_uninit(AVFilterContext *ctx) |
|
70 |
+static av_cold void uninit(AVFilterContext *ctx) |
|
86 | 71 |
{ |
87 |
- BufferSinkContext *buf = ctx->priv; |
|
88 |
- AVFilterBufferRef *picref; |
|
72 |
+ BufferSinkContext *sink = ctx->priv; |
|
73 |
+ AVFrame *frame; |
|
89 | 74 |
|
90 |
- if (buf->fifo) { |
|
91 |
- while (av_fifo_size(buf->fifo) >= sizeof(AVFilterBufferRef *)) { |
|
92 |
- av_fifo_generic_read(buf->fifo, &picref, sizeof(picref), NULL); |
|
93 |
- av_frame_unref(picref); |
|
75 |
+ if (sink->fifo) { |
|
76 |
+ while (av_fifo_size(sink->fifo) >= sizeof(AVFilterBufferRef *)) { |
|
77 |
+ av_fifo_generic_read(sink->fifo, &frame, sizeof(frame), NULL); |
|
78 |
+ av_frame_unref(frame); |
|
94 | 79 |
} |
95 |
- av_fifo_free(buf->fifo); |
|
96 |
- buf->fifo = NULL; |
|
80 |
+ av_fifo_free(sink->fifo); |
|
81 |
+ sink->fifo = NULL; |
|
97 | 82 |
} |
83 |
+ av_freep(&sink->pixel_fmts); |
|
84 |
+ av_freep(&sink->sample_fmts); |
|
85 |
+ av_freep(&sink->sample_rates); |
|
86 |
+ av_freep(&sink->channel_layouts); |
|
98 | 87 |
} |
99 | 88 |
|
100 | 89 |
static int add_buffer_ref(AVFilterContext *ctx, AVFrame *ref) |
... | ... |
@@ -116,13 +86,13 @@ static int add_buffer_ref(AVFilterContext *ctx, AVFrame *ref) |
116 | 116 |
return 0; |
117 | 117 |
} |
118 | 118 |
|
119 |
-static int filter_frame(AVFilterLink *inlink, AVFrame *ref) |
|
119 |
+static int filter_frame(AVFilterLink *link, AVFrame *frame) |
|
120 | 120 |
{ |
121 |
- AVFilterContext *ctx = inlink->dst; |
|
122 |
- BufferSinkContext *buf = inlink->dst->priv; |
|
121 |
+ AVFilterContext *ctx = link->dst; |
|
122 |
+ BufferSinkContext *buf = link->dst->priv; |
|
123 | 123 |
int ret; |
124 | 124 |
|
125 |
- if ((ret = add_buffer_ref(ctx, ref)) < 0) |
|
125 |
+ if ((ret = add_buffer_ref(ctx, frame)) < 0) |
|
126 | 126 |
return ret; |
127 | 127 |
if (buf->warning_limit && |
128 | 128 |
av_fifo_size(buf->fifo) / sizeof(AVFilterBufferRef *) >= buf->warning_limit) { |
... | ... |
@@ -135,12 +105,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *ref) |
135 | 135 |
return 0; |
136 | 136 |
} |
137 | 137 |
|
138 |
-void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size) |
|
138 |
+int av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame) |
|
139 | 139 |
{ |
140 |
- AVFilterLink *inlink = ctx->inputs[0]; |
|
141 |
- |
|
142 |
- inlink->min_samples = inlink->max_samples = |
|
143 |
- inlink->partial_buf_size = frame_size; |
|
140 |
+ return av_buffersink_get_frame_flags(ctx, frame, 0); |
|
144 | 141 |
} |
145 | 142 |
|
146 | 143 |
int av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags) |
... | ... |
@@ -173,14 +140,52 @@ int av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flag |
173 | 173 |
return 0; |
174 | 174 |
} |
175 | 175 |
|
176 |
-int av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame) |
|
176 |
+int av_buffersink_get_samples(AVFilterContext *ctx, AVFrame *frame, int nb_samples) |
|
177 | 177 |
{ |
178 |
- return av_buffersink_get_frame_flags(ctx, frame, 0); |
|
178 |
+ av_assert0(!"TODO"); |
|
179 | 179 |
} |
180 | 180 |
|
181 |
-int av_buffersink_get_samples(AVFilterContext *ctx, AVFrame *frame, int nb_samples) |
|
181 |
+AVBufferSinkParams *av_buffersink_params_alloc(void) |
|
182 | 182 |
{ |
183 |
- av_assert0(!"TODO"); |
|
183 |
+ static const int pixel_fmts[] = { AV_PIX_FMT_NONE }; |
|
184 |
+ AVBufferSinkParams *params = av_malloc(sizeof(AVBufferSinkParams)); |
|
185 |
+ if (!params) |
|
186 |
+ return NULL; |
|
187 |
+ |
|
188 |
+ params->pixel_fmts = pixel_fmts; |
|
189 |
+ return params; |
|
190 |
+} |
|
191 |
+ |
|
192 |
+AVABufferSinkParams *av_abuffersink_params_alloc(void) |
|
193 |
+{ |
|
194 |
+ AVABufferSinkParams *params = av_mallocz(sizeof(AVABufferSinkParams)); |
|
195 |
+ |
|
196 |
+ if (!params) |
|
197 |
+ return NULL; |
|
198 |
+ return params; |
|
199 |
+} |
|
200 |
+ |
|
201 |
+#define FIFO_INIT_SIZE 8 |
|
202 |
+ |
|
203 |
+static av_cold int common_init(AVFilterContext *ctx) |
|
204 |
+{ |
|
205 |
+ BufferSinkContext *buf = ctx->priv; |
|
206 |
+ |
|
207 |
+ buf->fifo = av_fifo_alloc(FIFO_INIT_SIZE*sizeof(AVFilterBufferRef *)); |
|
208 |
+ if (!buf->fifo) { |
|
209 |
+ av_log(ctx, AV_LOG_ERROR, "Failed to allocate fifo\n"); |
|
210 |
+ return AVERROR(ENOMEM); |
|
211 |
+ } |
|
212 |
+ buf->warning_limit = 100; |
|
213 |
+ return 0; |
|
214 |
+} |
|
215 |
+ |
|
216 |
+void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size) |
|
217 |
+{ |
|
218 |
+ AVFilterLink *inlink = ctx->inputs[0]; |
|
219 |
+ |
|
220 |
+ inlink->min_samples = inlink->max_samples = |
|
221 |
+ inlink->partial_buf_size = frame_size; |
|
184 | 222 |
} |
185 | 223 |
|
186 | 224 |
#if FF_API_AVFILTERBUFFER |
... | ... |
@@ -304,13 +309,6 @@ static av_cold int vsink_init(AVFilterContext *ctx, const char *args, void *opaq |
304 | 304 |
return common_init(ctx); |
305 | 305 |
} |
306 | 306 |
|
307 |
-static av_cold void vsink_uninit(AVFilterContext *ctx) |
|
308 |
-{ |
|
309 |
- BufferSinkContext *buf = ctx->priv; |
|
310 |
- av_freep(&buf->pixel_fmts); |
|
311 |
- common_uninit(ctx); |
|
312 |
-} |
|
313 |
- |
|
314 | 307 |
static int vsink_query_formats(AVFilterContext *ctx) |
315 | 308 |
{ |
316 | 309 |
BufferSinkContext *buf = ctx->priv; |
... | ... |
@@ -337,7 +335,7 @@ AVFilter avfilter_vsink_ffbuffersink = { |
337 | 337 |
.description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."), |
338 | 338 |
.priv_size = sizeof(BufferSinkContext), |
339 | 339 |
.init_opaque = vsink_init, |
340 |
- .uninit = vsink_uninit, |
|
340 |
+ .uninit = uninit, |
|
341 | 341 |
|
342 | 342 |
.query_formats = vsink_query_formats, |
343 | 343 |
.inputs = ffbuffersink_inputs, |
... | ... |
@@ -358,7 +356,7 @@ AVFilter avfilter_vsink_buffersink = { |
358 | 358 |
.description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."), |
359 | 359 |
.priv_size = sizeof(BufferSinkContext), |
360 | 360 |
.init_opaque = vsink_init, |
361 |
- .uninit = vsink_uninit, |
|
361 |
+ .uninit = uninit, |
|
362 | 362 |
|
363 | 363 |
.query_formats = vsink_query_formats, |
364 | 364 |
.inputs = buffersink_inputs, |
... | ... |
@@ -417,16 +415,6 @@ static av_cold int asink_init(AVFilterContext *ctx, const char *args, void *opaq |
417 | 417 |
return common_init(ctx); |
418 | 418 |
} |
419 | 419 |
|
420 |
-static av_cold void asink_uninit(AVFilterContext *ctx) |
|
421 |
-{ |
|
422 |
- BufferSinkContext *buf = ctx->priv; |
|
423 |
- |
|
424 |
- av_freep(&buf->sample_fmts); |
|
425 |
- av_freep(&buf->sample_rates); |
|
426 |
- av_freep(&buf->channel_layouts); |
|
427 |
- common_uninit(ctx); |
|
428 |
-} |
|
429 |
- |
|
430 | 420 |
static int asink_query_formats(AVFilterContext *ctx) |
431 | 421 |
{ |
432 | 422 |
BufferSinkContext *buf = ctx->priv; |
... | ... |
@@ -470,7 +458,7 @@ AVFilter avfilter_asink_ffabuffersink = { |
470 | 470 |
.name = "ffabuffersink", |
471 | 471 |
.description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."), |
472 | 472 |
.init_opaque = asink_init, |
473 |
- .uninit = asink_uninit, |
|
473 |
+ .uninit = uninit, |
|
474 | 474 |
.priv_size = sizeof(BufferSinkContext), |
475 | 475 |
.query_formats = asink_query_formats, |
476 | 476 |
.inputs = ffabuffersink_inputs, |
... | ... |
@@ -490,7 +478,7 @@ AVFilter avfilter_asink_abuffersink = { |
490 | 490 |
.name = "abuffersink", |
491 | 491 |
.description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."), |
492 | 492 |
.init_opaque = asink_init, |
493 |
- .uninit = asink_uninit, |
|
493 |
+ .uninit = uninit, |
|
494 | 494 |
.priv_size = sizeof(BufferSinkContext), |
495 | 495 |
.query_formats = asink_query_formats, |
496 | 496 |
.inputs = abuffersink_inputs, |