buffersink.c
Go to the documentation of this file.
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 sink
24  */
25 
26 #include "libavutil/audio_fifo.h"
27 #include "libavutil/avassert.h"
29 #include "libavutil/common.h"
30 #include "libavutil/mathematics.h"
31 #include "libavutil/opt.h"
32 
33 #include "audio.h"
34 #include "avfilter.h"
35 #include "buffersink.h"
36 #include "internal.h"
37 
38 typedef struct {
39  const AVClass *class;
40  AVFifoBuffer *fifo; ///< FIFO buffer of video frame references
41  unsigned warning_limit;
42 
43  /* only used for video */
44  enum AVPixelFormat *pixel_fmts; ///< list of accepted pixel formats, must be terminated with -1
46 
47  /* only used for audio */
48  enum AVSampleFormat *sample_fmts; ///< list of accepted sample formats, terminated by AV_SAMPLE_FMT_NONE
50  int64_t *channel_layouts; ///< list of accepted channel layouts, terminated by -1
52  int *channel_counts; ///< list of accepted channel counts, terminated by -1
55  int *sample_rates; ///< list of accepted sample rates, terminated by -1
57 
58  /* only used for compat API */
59  AVAudioFifo *audio_fifo; ///< FIFO for audio samples
60  int64_t next_pts; ///< interpolating audio pts
62 
63 #define NB_ITEMS(list) (list ## _size / sizeof(*list))
64 
65 static av_cold void uninit(AVFilterContext *ctx)
66 {
67  BufferSinkContext *sink = ctx->priv;
68  AVFrame *frame;
69 
70  if (sink->audio_fifo)
72 
73  if (sink->fifo) {
74  while (av_fifo_size(sink->fifo) >= sizeof(AVFilterBufferRef *)) {
75  av_fifo_generic_read(sink->fifo, &frame, sizeof(frame), NULL);
76  av_frame_free(&frame);
77  }
78  av_fifo_free(sink->fifo);
79  sink->fifo = NULL;
80  }
81 }
82 
84 {
85  BufferSinkContext *buf = ctx->priv;
86 
87  if (av_fifo_space(buf->fifo) < sizeof(AVFilterBufferRef *)) {
88  /* realloc fifo size */
89  if (av_fifo_realloc2(buf->fifo, av_fifo_size(buf->fifo) * 2) < 0) {
90  av_log(ctx, AV_LOG_ERROR,
91  "Cannot buffer more frames. Consume some available frames "
92  "before adding new ones.\n");
93  return AVERROR(ENOMEM);
94  }
95  }
96 
97  /* cache frame */
98  av_fifo_generic_write(buf->fifo, &ref, sizeof(AVFilterBufferRef *), NULL);
99  return 0;
100 }
101 
103 {
104  AVFilterContext *ctx = link->dst;
105  BufferSinkContext *buf = link->dst->priv;
106  int ret;
107 
108  if ((ret = add_buffer_ref(ctx, frame)) < 0)
109  return ret;
110  if (buf->warning_limit &&
111  av_fifo_size(buf->fifo) / sizeof(AVFilterBufferRef *) >= buf->warning_limit) {
112  av_log(ctx, AV_LOG_WARNING,
113  "%d buffers queued in %s, something may be wrong.\n",
114  buf->warning_limit,
115  (char *)av_x_if_null(ctx->name, ctx->filter->name));
116  buf->warning_limit *= 10;
117  }
118  return 0;
119 }
120 
122 {
123  return av_buffersink_get_frame_flags(ctx, frame, 0);
124 }
125 
127 {
128  BufferSinkContext *buf = ctx->priv;
129  AVFilterLink *inlink = ctx->inputs[0];
130  int ret;
131  AVFrame *cur_frame;
132 
133  /* no picref available, fetch it from the filterchain */
134  if (!av_fifo_size(buf->fifo)) {
135  if (flags & AV_BUFFERSINK_FLAG_NO_REQUEST)
136  return AVERROR(EAGAIN);
137  if ((ret = ff_request_frame(inlink)) < 0)
138  return ret;
139  }
140 
141  if (!av_fifo_size(buf->fifo))
142  return AVERROR(EINVAL);
143 
144  if (flags & AV_BUFFERSINK_FLAG_PEEK) {
145  cur_frame = *((AVFrame **)av_fifo_peek2(buf->fifo, 0));
146  if ((ret = av_frame_ref(frame, cur_frame)) < 0)
147  return ret;
148  } else {
149  av_fifo_generic_read(buf->fifo, &cur_frame, sizeof(cur_frame), NULL);
150  av_frame_move_ref(frame, cur_frame);
151  av_frame_free(&cur_frame);
152  }
153 
154  return 0;
155 }
156 
158  int nb_samples)
159 {
160  BufferSinkContext *s = ctx->priv;
161  AVFilterLink *link = ctx->inputs[0];
162  AVFrame *tmp;
163 
164  if (!(tmp = ff_get_audio_buffer(link, nb_samples)))
165  return AVERROR(ENOMEM);
166  av_audio_fifo_read(s->audio_fifo, (void**)tmp->extended_data, nb_samples);
167 
168  tmp->pts = s->next_pts;
169  s->next_pts += av_rescale_q(nb_samples, (AVRational){1, link->sample_rate},
170  link->time_base);
171 
172  av_frame_move_ref(frame, tmp);
173  av_frame_free(&tmp);
174 
175  return 0;
176 
177 }
178 
180 {
181  BufferSinkContext *s = ctx->priv;
182  AVFilterLink *link = ctx->inputs[0];
183  AVFrame *cur_frame;
184  int ret = 0;
185 
186  if (!s->audio_fifo) {
187  int nb_channels = link->channels;
188  if (!(s->audio_fifo = av_audio_fifo_alloc(link->format, nb_channels, nb_samples)))
189  return AVERROR(ENOMEM);
190  }
191 
192  while (ret >= 0) {
193  if (av_audio_fifo_size(s->audio_fifo) >= nb_samples)
194  return read_from_fifo(ctx, frame, nb_samples);
195 
196  if (!(cur_frame = av_frame_alloc()))
197  return AVERROR(ENOMEM);
198  ret = av_buffersink_get_frame_flags(ctx, cur_frame, 0);
199  if (ret == AVERROR_EOF && av_audio_fifo_size(s->audio_fifo)) {
200  av_frame_free(&cur_frame);
201  return read_from_fifo(ctx, frame, av_audio_fifo_size(s->audio_fifo));
202  } else if (ret < 0) {
203  av_frame_free(&cur_frame);
204  return ret;
205  }
206 
207  if (cur_frame->pts != AV_NOPTS_VALUE) {
208  s->next_pts = cur_frame->pts -
210  (AVRational){ 1, link->sample_rate },
211  link->time_base);
212  }
213 
214  ret = av_audio_fifo_write(s->audio_fifo, (void**)cur_frame->extended_data,
215  cur_frame->nb_samples);
216  av_frame_free(&cur_frame);
217  }
218 
219  return ret;
220 
221 }
222 
224 {
225  static const int pixel_fmts[] = { AV_PIX_FMT_NONE };
227  if (!params)
228  return NULL;
229 
230  params->pixel_fmts = pixel_fmts;
231  return params;
232 }
233 
235 {
237 
238  if (!params)
239  return NULL;
240  return params;
241 }
242 
243 #define FIFO_INIT_SIZE 8
244 
246 {
247  BufferSinkContext *buf = ctx->priv;
248 
249  buf->fifo = av_fifo_alloc(FIFO_INIT_SIZE*sizeof(AVFilterBufferRef *));
250  if (!buf->fifo) {
251  av_log(ctx, AV_LOG_ERROR, "Failed to allocate fifo\n");
252  return AVERROR(ENOMEM);
253  }
254  buf->warning_limit = 100;
255  return 0;
256 }
257 
259 {
260  AVFilterLink *inlink = ctx->inputs[0];
261 
262  inlink->min_samples = inlink->max_samples =
263  inlink->partial_buf_size = frame_size;
264 }
265 
266 #if FF_API_AVFILTERBUFFER
267 static void compat_free_buffer(AVFilterBuffer *buf)
268 {
269  AVFrame *frame = buf->priv;
270  av_frame_free(&frame);
271  av_free(buf);
272 }
273 
274 static int attribute_align_arg compat_read(AVFilterContext *ctx, AVFilterBufferRef **pbuf, int nb_samples, int flags)
275 {
276  AVFilterBufferRef *buf;
277  AVFrame *frame;
278  int ret;
279 
280  if (!pbuf)
281  return ff_poll_frame(ctx->inputs[0]);
282 
283  frame = av_frame_alloc();
284  if (!frame)
285  return AVERROR(ENOMEM);
286 
287  if (!nb_samples)
288  ret = av_buffersink_get_frame_flags(ctx, frame, flags);
289  else
290  ret = av_buffersink_get_samples(ctx, frame, nb_samples);
291 
292  if (ret < 0)
293  goto fail;
294 
296  if (ctx->inputs[0]->type == AVMEDIA_TYPE_VIDEO) {
297  buf = avfilter_get_video_buffer_ref_from_arrays(frame->data, frame->linesize,
298  AV_PERM_READ,
299  frame->width, frame->height,
300  frame->format);
301  } else {
302  buf = avfilter_get_audio_buffer_ref_from_arrays(frame->extended_data,
303  frame->linesize[0], AV_PERM_READ,
304  frame->nb_samples,
305  frame->format,
306  frame->channel_layout);
307  }
308  if (!buf) {
309  ret = AVERROR(ENOMEM);
310  goto fail;
311  }
312 
313  avfilter_copy_frame_props(buf, frame);
314  )
315 
316  buf->buf->priv = frame;
317  buf->buf->free = compat_free_buffer;
318 
319  *pbuf = buf;
320 
321  return 0;
322 fail:
323  av_frame_free(&frame);
324  return ret;
325 }
326 
327 int av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf)
328 {
329  return compat_read(ctx, buf, 0, 0);
330 }
331 
332 int av_buffersink_read_samples(AVFilterContext *ctx, AVFilterBufferRef **buf,
333  int nb_samples)
334 {
335  return compat_read(ctx, buf, nb_samples, 0);
336 }
337 
338 int av_buffersink_get_buffer_ref(AVFilterContext *ctx,
339  AVFilterBufferRef **bufref, int flags)
340 {
341  *bufref = NULL;
342 
343  av_assert0( !strcmp(ctx->filter->name, "buffersink")
344  || !strcmp(ctx->filter->name, "abuffersink")
345  || !strcmp(ctx->filter->name, "ffbuffersink")
346  || !strcmp(ctx->filter->name, "ffabuffersink"));
347 
348  return compat_read(ctx, bufref, 0, flags);
349 }
350 #endif
351 
353 {
354  av_assert0( !strcmp(ctx->filter->name, "buffersink")
355  || !strcmp(ctx->filter->name, "ffbuffersink"));
356 
357  return ctx->inputs[0]->frame_rate;
358 }
359 
361 {
362  BufferSinkContext *buf = ctx->priv;
363  AVFilterLink *inlink = ctx->inputs[0];
364 
365  av_assert0( !strcmp(ctx->filter->name, "buffersink")
366  || !strcmp(ctx->filter->name, "abuffersink")
367  || !strcmp(ctx->filter->name, "ffbuffersink")
368  || !strcmp(ctx->filter->name, "ffabuffersink"));
369 
370  return av_fifo_size(buf->fifo)/sizeof(AVFilterBufferRef *) + ff_poll_frame(inlink);
371 }
372 
373 static av_cold int vsink_init(AVFilterContext *ctx, void *opaque)
374 {
375  BufferSinkContext *buf = ctx->priv;
376  AVBufferSinkParams *params = opaque;
377  int ret;
378 
379  if (params) {
380  if ((ret = av_opt_set_int_list(buf, "pix_fmts", params->pixel_fmts, AV_PIX_FMT_NONE, 0)) < 0)
381  return ret;
382  }
383 
384  return common_init(ctx);
385 }
386 
387 #define CHECK_LIST_SIZE(field) \
388  if (buf->field ## _size % sizeof(*buf->field)) { \
389  av_log(ctx, AV_LOG_ERROR, "Invalid size for " #field ": %d, " \
390  "should be multiple of %d\n", \
391  buf->field ## _size, (int)sizeof(*buf->field)); \
392  return AVERROR(EINVAL); \
393  }
395 {
396  BufferSinkContext *buf = ctx->priv;
398  unsigned i;
399  int ret;
400 
401  CHECK_LIST_SIZE(pixel_fmts)
402  if (buf->pixel_fmts_size) {
403  for (i = 0; i < NB_ITEMS(buf->pixel_fmts); i++)
404  if ((ret = ff_add_format(&formats, buf->pixel_fmts[i])) < 0)
405  return ret;
406  ff_set_common_formats(ctx, formats);
407  } else {
409  }
410 
411  return 0;
412 }
413 
414 static av_cold int asink_init(AVFilterContext *ctx, void *opaque)
415 {
416  BufferSinkContext *buf = ctx->priv;
417  AVABufferSinkParams *params = opaque;
418  int ret;
419 
420  if (params) {
421  if ((ret = av_opt_set_int_list(buf, "sample_fmts", params->sample_fmts, AV_SAMPLE_FMT_NONE, 0)) < 0 ||
422  (ret = av_opt_set_int_list(buf, "sample_rates", params->sample_rates, -1, 0)) < 0 ||
423  (ret = av_opt_set_int_list(buf, "channel_layouts", params->channel_layouts, -1, 0)) < 0 ||
424  (ret = av_opt_set_int_list(buf, "channel_counts", params->channel_counts, -1, 0)) < 0 ||
425  (ret = av_opt_set_int(buf, "all_channel_counts", params->all_channel_counts, 0)) < 0)
426  return ret;
427  }
428  return common_init(ctx);
429 }
430 
432 {
433  BufferSinkContext *buf = ctx->priv;
436  unsigned i;
437  int ret;
438 
440  CHECK_LIST_SIZE(sample_rates)
441  CHECK_LIST_SIZE(channel_layouts)
442  CHECK_LIST_SIZE(channel_counts)
443 
444  if (buf->sample_fmts_size) {
445  for (i = 0; i < NB_ITEMS(buf->sample_fmts); i++)
446  if ((ret = ff_add_format(&formats, buf->sample_fmts[i])) < 0)
447  return ret;
448  ff_set_common_formats(ctx, formats);
449  }
450 
451  if (buf->channel_layouts_size || buf->channel_counts_size ||
452  buf->all_channel_counts) {
453  for (i = 0; i < NB_ITEMS(buf->channel_layouts); i++)
454  if ((ret = ff_add_channel_layout(&layouts, buf->channel_layouts[i])) < 0)
455  return ret;
456  for (i = 0; i < NB_ITEMS(buf->channel_counts); i++)
457  if ((ret = ff_add_channel_layout(&layouts, FF_COUNT2LAYOUT(buf->channel_counts[i]))) < 0)
458  return ret;
459  if (buf->all_channel_counts) {
460  if (layouts)
461  av_log(ctx, AV_LOG_WARNING,
462  "Conflicting all_channel_counts and list in options\n");
463  else if (!(layouts = ff_all_channel_counts()))
464  return AVERROR(ENOMEM);
465  }
466  ff_set_common_channel_layouts(ctx, layouts);
467  }
468 
469  if (buf->sample_rates_size) {
470  formats = NULL;
471  for (i = 0; i < NB_ITEMS(buf->sample_rates); i++)
472  if ((ret = ff_add_format(&formats, buf->sample_rates[i])) < 0)
473  return ret;
474  ff_set_common_samplerates(ctx, formats);
475  }
476 
477  return 0;
478 }
479 
480 #define OFFSET(x) offsetof(BufferSinkContext, x)
481 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
482 static const AVOption buffersink_options[] = {
483  { "pix_fmts", "set the supported pixel formats", OFFSET(pixel_fmts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
484  { NULL },
485 };
486 #undef FLAGS
487 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
488 static const AVOption abuffersink_options[] = {
489  { "sample_fmts", "set the supported sample formats", OFFSET(sample_fmts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
490  { "sample_rates", "set the supported sample rates", OFFSET(sample_rates), AV_OPT_TYPE_BINARY, .flags = FLAGS },
491  { "channel_layouts", "set the supported channel layouts", OFFSET(channel_layouts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
492  { "channel_counts", "set the supported channel counts", OFFSET(channel_counts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
493  { "all_channel_counts", "accept all channel counts", OFFSET(all_channel_counts), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS },
494  { NULL },
495 };
496 #undef FLAGS
497 
498 AVFILTER_DEFINE_CLASS(buffersink);
499 AVFILTER_DEFINE_CLASS(abuffersink);
500 
501 #if FF_API_AVFILTERBUFFER
502 
503 #define ffbuffersink_options buffersink_options
504 #define ffabuffersink_options abuffersink_options
505 AVFILTER_DEFINE_CLASS(ffbuffersink);
506 AVFILTER_DEFINE_CLASS(ffabuffersink);
507 
508 static const AVFilterPad ffbuffersink_inputs[] = {
509  {
510  .name = "default",
511  .type = AVMEDIA_TYPE_VIDEO,
512  .filter_frame = filter_frame,
513  },
514  { NULL },
515 };
516 
517 AVFilter avfilter_vsink_ffbuffersink = {
518  .name = "ffbuffersink",
519  .description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."),
520  .priv_size = sizeof(BufferSinkContext),
521  .priv_class = &ffbuffersink_class,
522  .init_opaque = vsink_init,
523  .uninit = uninit,
524 
526  .inputs = ffbuffersink_inputs,
527  .outputs = NULL,
528 };
529 
530 static const AVFilterPad ffabuffersink_inputs[] = {
531  {
532  .name = "default",
533  .type = AVMEDIA_TYPE_AUDIO,
534  .filter_frame = filter_frame,
535  },
536  { NULL },
537 };
538 
539 AVFilter avfilter_asink_ffabuffersink = {
540  .name = "ffabuffersink",
541  .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."),
542  .init_opaque = asink_init,
543  .uninit = uninit,
544  .priv_size = sizeof(BufferSinkContext),
545  .priv_class = &ffabuffersink_class,
547  .inputs = ffabuffersink_inputs,
548  .outputs = NULL,
549 };
550 #endif /* FF_API_AVFILTERBUFFER */
551 
553  {
554  .name = "default",
555  .type = AVMEDIA_TYPE_VIDEO,
556  .filter_frame = filter_frame,
557  },
558  { NULL }
559 };
560 
562  .name = "buffersink",
563  .description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."),
564  .priv_size = sizeof(BufferSinkContext),
565  .priv_class = &buffersink_class,
566  .init_opaque = vsink_init,
567  .uninit = uninit,
568 
570  .inputs = avfilter_vsink_buffer_inputs,
571  .outputs = NULL,
572 };
573 
575  {
576  .name = "default",
577  .type = AVMEDIA_TYPE_AUDIO,
578  .filter_frame = filter_frame,
579  },
580  { NULL }
581 };
582 
584  .name = "abuffersink",
585  .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."),
586  .priv_class = &abuffersink_class,
587  .priv_size = sizeof(BufferSinkContext),
588  .init_opaque = asink_init,
589  .uninit = uninit,
590 
592  .inputs = avfilter_asink_abuffer_inputs,
593  .outputs = NULL,
594 };
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
Definition: audio_fifo.c:113
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:205
const char * s
Definition: avisynth_c.h:668
enum AVSampleFormat * sample_fmts
list of accepted sample formats, terminated by AV_SAMPLE_FMT_NONE
Definition: buffersink.c:48
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
FIXME Range Coding of cr are ref
Definition: snow.txt:367
AVOption.
Definition: opt.h:251
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:117
#define AV_NOWARN_DEPRECATED(code)
Disable warnings about deprecated features This is useful for sections of code kept for backward comp...
Definition: attributes.h:106
static av_cold void uninit(AVFilterContext *ctx)
Definition: buffersink.c:65
external API header
static int read_from_fifo(AVFilterContext *ctx, AVFrame *frame, int nb_samples)
Definition: buffersink.c:157
const int * channel_counts
list of allowed channel counts, terminated by -1
Definition: buffersink.h:132
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:343
#define av_opt_set_int_list(obj, name, val, term, flags)
Set a binary option to an integer list.
Definition: opt.h:671
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:154
int * sample_rates
list of accepted sample rates, terminated by -1
Definition: buffersink.c:55
static const AVOption abuffersink_options[]
Definition: buffersink.c:488
int * channel_counts
list of accepted channel counts, terminated by -1
Definition: buffersink.c:52
static int query_formats(AVFilterContext *ctx)
Definition: af_aconvert.c:73
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
Definition: audio_fifo.c:45
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int(*func)(void *, void *, int))
Feed data from a user-supplied callback to an AVFifoBuffer.
initialize output if(nPeaks >3)%at least 3 peaks in spectrum for trying to find f0 nf0peaks
memory buffer sink API for audio and video
enum AVSampleFormat * sample_fmts
list of allowed sample formats, terminated by AV_SAMPLE_FMT_NONE
Definition: buffersink.h:130
const char * name
Pad name.
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
Read data from an AVAudioFifo.
Definition: audio_fifo.c:139
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:532
char * name
name of this filter instance
Definition: avfilter.h:529
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
static av_cold int vsink_init(AVFilterContext *ctx, void *opaque)
Definition: buffersink.c:373
AVAudioFifo * audio_fifo
FIFO for audio samples.
Definition: buffersink.c:59
#define av_cold
Definition: attributes.h:78
AVOptions.
AVBufferSinkParams * av_buffersink_params_alloc(void)
Create an AVBufferSinkParams structure.
Definition: buffersink.c:223
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:159
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everythnig contained in src to dst and reset src.
Definition: frame.c:352
static av_cold int asink_init(AVFilterContext *ctx, void *opaque)
Definition: buffersink.c:414
static const AVOption buffersink_options[]
Definition: buffersink.c:482
#define AVERROR_EOF
End of file.
Definition: error.h:55
void av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
#define CHECK_LIST_SIZE(field)
Definition: buffersink.c:387
void ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:545
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
Definition: audio_fifo.c:186
AVFilter avfilter_vsink_buffer
Definition: buffersink.c:561
#define FLAGS
Definition: buffersink.c:487
frame
Definition: stft.m:14
A filter pad used for either input or output.
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition: avutil.h:250
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:130
AVFILTER_DEFINE_CLASS(buffersink)
static const uint8_t frame_size[4]
Definition: g723_1_data.h:58
#define AV_BUFFERSINK_FLAG_PEEK
Tell av_buffersink_get_buffer_ref() to read video/samples buffer reference, but not remove it from th...
Definition: buffersink.h:103
static int vsink_query_formats(AVFilterContext *ctx)
Definition: buffersink.c:394
AVABufferSinkParams * av_abuffersink_params_alloc(void)
Create an AVABufferSinkParams structure.
Definition: buffersink.c:234
static uint8_t * av_fifo_peek2(const AVFifoBuffer *f, int offs)
Return a pointer to the data stored in a FIFO buffer at a certain offset.
Definition: fifo.h:134
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:183
#define FIFO_INIT_SIZE
Definition: buffersink.c:243
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
Definition: audio_fifo.c:60
int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
Definition: formats.c:350
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:84
int attribute_align_arg av_buffersink_poll_frame(AVFilterContext *ctx)
Definition: buffersink.c:360
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int * sample_rates
list of allowed sample rates, terminated by -1
Definition: buffersink.h:134
void * priv
private data for use by the filter
Definition: avfilter.h:545
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
Feed data from an AVFifoBuffer to a user-supplied callback.
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:394
#define AV_BUFFERSINK_FLAG_NO_REQUEST
Tell av_buffersink_get_buffer_ref() not to request a frame from its input.
Definition: buffersink.h:110
simple assert() macros that are a bit more flexible than ISO C assert().
static const AVFilterPad avfilter_asink_abuffer_inputs[]
Definition: buffersink.c:574
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:344
int channel_layouts_size
Definition: buffersink.c:51
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
int64_t * channel_layouts
list of accepted channel layouts, terminated by -1
Definition: buffersink.c:50
audio channel layout utility functions
Struct to use for initializing an abuffersink context.
Definition: buffersink.h:129
ret
Definition: avfilter.c:821
Struct to use for initializing a buffersink context.
Definition: buffersink.h:115
int attribute_align_arg av_buffersink_get_samples(AVFilterContext *ctx, AVFrame *frame, int nb_samples)
Same as av_buffersink_get_frame(), but with the ability to specify the number of samples read...
Definition: buffersink.c:179
enum AVPixelFormat * pixel_fmts
list of accepted pixel formats, must be terminated with -1
Definition: buffersink.c:44
int attribute_align_arg av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
Get a frame with filtered data from sink and put it in frame.
Definition: buffersink.c:126
offset must point to a pointer immediately followed by an int for the length
Definition: opt.h:228
A list of supported channel layouts.
Definition: formats.h:85
#define attribute_align_arg
int ff_default_query_formats(AVFilterContext *ctx)
Definition: formats.c:567
NULL
Definition: eval.c:55
int av_fifo_space(AVFifoBuffer *f)
Return the amount of space in bytes in the AVFifoBuffer, that is the amount of data you can write int...
#define OFFSET(x)
Definition: buffersink.c:480
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
Resize an AVFifoBuffer.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
void * buf
Definition: avisynth_c.h:594
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
int all_channel_counts
if not 0, accept any channel count or layout
Definition: buffersink.h:133
Describe the class of an AVClass context structure.
Definition: log.h:50
Filter definition.
Definition: avfilter.h:436
synthesis window for stochastic i
rational number numerator/denominator
Definition: rational.h:43
#define NB_ITEMS(list)
Definition: buffersink.c:63
const char * name
filter name
Definition: avfilter.h:437
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:95
AVFifoBuffer * fifo
FIFO buffer of video frame references.
Definition: buffersink.c:40
static int flags
Definition: cpu.c:23
int av_frame_ref(AVFrame *dst, AVFrame *src)
Setup a new reference to the data described by an given frame.
Definition: frame.c:228
void ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:533
int64_t next_pts
interpolating audio pts
Definition: buffersink.c:60
const char const char * params
Definition: avisynth_c.h:675
int av_fifo_size(AVFifoBuffer *f)
Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from ...
common internal and external API header
int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src)
static int add_buffer_ref(AVFilterContext *ctx, AVFrame *ref)
Definition: buffersink.c:83
enum AVPixelFormat * pixel_fmts
list of allowed pixel formats, terminated by AV_PIX_FMT_NONE
Definition: buffersink.h:116
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common formats
Definition: swscale.txt:33
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:108
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
AVFilter avfilter_asink_abuffer
Definition: buffersink.c:583
AVRational av_buffersink_get_frame_rate(AVFilterContext *ctx)
Get the frame rate of the input.
Definition: buffersink.c:352
static av_cold int common_init(AVFilterContext *ctx)
Definition: buffersink.c:245
Audio FIFO Buffer.
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
static int asink_query_formats(AVFilterContext *ctx)
Definition: buffersink.c:431
static int filter_frame(AVFilterLink *link, AVFrame *frame)
Definition: buffersink.c:102
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:524
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:700
#define FF_COUNT2LAYOUT(c)
Encode a channel count as a channel layout.
Definition: formats.h:102
static const AVFilterPad avfilter_vsink_buffer_inputs[]
Definition: buffersink.c:552
int av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame)
Get a frame with filtered data from sink and put it in frame.
Definition: buffersink.c:121
void ff_set_common_channel_layouts(AVFilterContext *ctx, AVFilterChannelLayouts *layouts)
A helper for query_formats() which sets all links to the same list of channel layouts/sample rates...
Definition: formats.c:526
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:319
int nb_channels
internal API functions
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition...
Definition: formats.c:411
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:117
int ff_poll_frame(AVFilterLink *link)
Poll a frame from the filter chain.
Definition: avfilter.c:350
const int64_t * channel_layouts
list of allowed channel layouts, terminated by -1
Definition: buffersink.h:131
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:127
unsigned warning_limit
Definition: buffersink.c:41
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:527
void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size)
Set the frame size for an audio buffer sink.
Definition: buffersink.c:258
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:190
static void compat_free_buffer(void *opaque, uint8_t *data)