FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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/internal.h"
31 #include "libavutil/mathematics.h"
32 #include "libavutil/opt.h"
33 
34 #include "audio.h"
35 #include "avfilter.h"
36 #include "buffersink.h"
37 #include "internal.h"
38 
39 typedef struct BufferSinkContext {
40  const AVClass *class;
41  AVFifoBuffer *fifo; ///< FIFO buffer of video frame references
42  unsigned warning_limit;
43 
44  /* only used for video */
45  enum AVPixelFormat *pixel_fmts; ///< list of accepted pixel formats, must be terminated with -1
47 
48  /* only used for audio */
49  enum AVSampleFormat *sample_fmts; ///< list of accepted sample formats, terminated by AV_SAMPLE_FMT_NONE
51  int64_t *channel_layouts; ///< list of accepted channel layouts, terminated by -1
53  int *channel_counts; ///< list of accepted channel counts, terminated by -1
56  int *sample_rates; ///< list of accepted sample rates, terminated by -1
58 
59  /* only used for compat API */
60  AVAudioFifo *audio_fifo; ///< FIFO for audio samples
61  int64_t next_pts; ///< interpolating audio pts
63 
64 #define NB_ITEMS(list) (list ## _size / sizeof(*list))
65 
66 static av_cold void uninit(AVFilterContext *ctx)
67 {
68  BufferSinkContext *sink = ctx->priv;
69  AVFrame *frame;
70 
71  if (sink->audio_fifo)
73 
74  if (sink->fifo) {
75  while (av_fifo_size(sink->fifo) >= sizeof(AVFilterBufferRef *)) {
76  av_fifo_generic_read(sink->fifo, &frame, sizeof(frame), NULL);
77  av_frame_free(&frame);
78  }
79  av_fifo_freep(&sink->fifo);
80  }
81 }
82 
83 static int add_buffer_ref(AVFilterContext *ctx, AVFrame *ref)
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 
121 int attribute_align_arg av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame)
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 (inlink->closed)
136  return AVERROR_EOF;
137  if (flags & AV_BUFFERSINK_FLAG_NO_REQUEST)
138  return AVERROR(EAGAIN);
139  if ((ret = ff_request_frame(inlink)) < 0)
140  return ret;
141  }
142 
143  if (!av_fifo_size(buf->fifo))
144  return AVERROR(EINVAL);
145 
146  if (flags & AV_BUFFERSINK_FLAG_PEEK) {
147  cur_frame = *((AVFrame **)av_fifo_peek2(buf->fifo, 0));
148  if ((ret = av_frame_ref(frame, cur_frame)) < 0)
149  return ret;
150  } else {
151  av_fifo_generic_read(buf->fifo, &cur_frame, sizeof(cur_frame), NULL);
152  av_frame_move_ref(frame, cur_frame);
153  av_frame_free(&cur_frame);
154  }
155 
156  return 0;
157 }
158 
160  int nb_samples)
161 {
162  BufferSinkContext *s = ctx->priv;
163  AVFilterLink *link = ctx->inputs[0];
164  AVFrame *tmp;
165 
166  if (!(tmp = ff_get_audio_buffer(link, nb_samples)))
167  return AVERROR(ENOMEM);
168  av_audio_fifo_read(s->audio_fifo, (void**)tmp->extended_data, nb_samples);
169 
170  tmp->pts = s->next_pts;
171  if (s->next_pts != AV_NOPTS_VALUE)
172  s->next_pts += av_rescale_q(nb_samples, (AVRational){1, link->sample_rate},
173  link->time_base);
174 
175  av_frame_move_ref(frame, tmp);
176  av_frame_free(&tmp);
177 
178  return 0;
179 }
180 
181 int attribute_align_arg av_buffersink_get_samples(AVFilterContext *ctx,
182  AVFrame *frame, int nb_samples)
183 {
184  BufferSinkContext *s = ctx->priv;
185  AVFilterLink *link = ctx->inputs[0];
186  AVFrame *cur_frame;
187  int ret = 0;
188 
189  if (!s->audio_fifo) {
190  int nb_channels = link->channels;
191  if (!(s->audio_fifo = av_audio_fifo_alloc(link->format, nb_channels, nb_samples)))
192  return AVERROR(ENOMEM);
193  }
194 
195  while (ret >= 0) {
196  if (av_audio_fifo_size(s->audio_fifo) >= nb_samples)
197  return read_from_fifo(ctx, frame, nb_samples);
198 
199  if (!(cur_frame = av_frame_alloc()))
200  return AVERROR(ENOMEM);
201  ret = av_buffersink_get_frame_flags(ctx, cur_frame, 0);
202  if (ret == AVERROR_EOF && av_audio_fifo_size(s->audio_fifo)) {
203  av_frame_free(&cur_frame);
204  return read_from_fifo(ctx, frame, av_audio_fifo_size(s->audio_fifo));
205  } else if (ret < 0) {
206  av_frame_free(&cur_frame);
207  return ret;
208  }
209 
210  if (cur_frame->pts != AV_NOPTS_VALUE) {
211  s->next_pts = cur_frame->pts -
213  (AVRational){ 1, link->sample_rate },
214  link->time_base);
215  }
216 
217  ret = av_audio_fifo_write(s->audio_fifo, (void**)cur_frame->extended_data,
218  cur_frame->nb_samples);
219  av_frame_free(&cur_frame);
220  }
221 
222  return ret;
223 }
224 
226 {
227  static const int pixel_fmts[] = { AV_PIX_FMT_NONE };
229  if (!params)
230  return NULL;
231 
232  params->pixel_fmts = pixel_fmts;
233  return params;
234 }
235 
237 {
239 
240  if (!params)
241  return NULL;
242  return params;
243 }
244 
245 #define FIFO_INIT_SIZE 8
246 
248 {
249  BufferSinkContext *buf = ctx->priv;
250 
251  buf->fifo = av_fifo_alloc_array(FIFO_INIT_SIZE, sizeof(AVFilterBufferRef *));
252  if (!buf->fifo) {
253  av_log(ctx, AV_LOG_ERROR, "Failed to allocate fifo\n");
254  return AVERROR(ENOMEM);
255  }
256  buf->warning_limit = 100;
257  buf->next_pts = AV_NOPTS_VALUE;
258  return 0;
259 }
260 
262 {
263  AVFilterLink *inlink = ctx->inputs[0];
264 
265  inlink->min_samples = inlink->max_samples =
266  inlink->partial_buf_size = frame_size;
267 }
268 
269 #if FF_API_AVFILTERBUFFER
271 static void compat_free_buffer(AVFilterBuffer *buf)
272 {
273  AVFrame *frame = buf->priv;
274  av_frame_free(&frame);
275  av_free(buf);
276 }
277 
278 static int compat_read(AVFilterContext *ctx,
279  AVFilterBufferRef **pbuf, int nb_samples, int flags)
280 {
281  AVFilterBufferRef *buf;
282  AVFrame *frame;
283  int ret;
284 
285  if (!pbuf)
286  return ff_poll_frame(ctx->inputs[0]);
287 
288  frame = av_frame_alloc();
289  if (!frame)
290  return AVERROR(ENOMEM);
291 
292  if (!nb_samples)
293  ret = av_buffersink_get_frame_flags(ctx, frame, flags);
294  else
295  ret = av_buffersink_get_samples(ctx, frame, nb_samples);
296 
297  if (ret < 0)
298  goto fail;
299 
301  if (ctx->inputs[0]->type == AVMEDIA_TYPE_VIDEO) {
303  AV_PERM_READ,
304  frame->width, frame->height,
305  frame->format);
306  } else {
307  buf = avfilter_get_audio_buffer_ref_from_arrays(frame->extended_data,
308  frame->linesize[0], AV_PERM_READ,
309  frame->nb_samples,
310  frame->format,
311  frame->channel_layout);
312  }
313  if (!buf) {
314  ret = AVERROR(ENOMEM);
315  goto fail;
316  }
317 
318  avfilter_copy_frame_props(buf, frame);
319  )
320 
321  buf->buf->priv = frame;
322  buf->buf->free = compat_free_buffer;
323 
324  *pbuf = buf;
325 
326  return 0;
327 fail:
328  av_frame_free(&frame);
329  return ret;
330 }
331 
332 int attribute_align_arg av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf)
333 {
334  return compat_read(ctx, buf, 0, 0);
335 }
336 
337 int attribute_align_arg av_buffersink_read_samples(AVFilterContext *ctx, AVFilterBufferRef **buf,
338  int nb_samples)
339 {
340  return compat_read(ctx, buf, nb_samples, 0);
341 }
342 
343 int attribute_align_arg av_buffersink_get_buffer_ref(AVFilterContext *ctx,
344  AVFilterBufferRef **bufref, int flags)
345 {
346  *bufref = NULL;
347 
348  av_assert0( !strcmp(ctx->filter->name, "buffersink")
349  || !strcmp(ctx->filter->name, "abuffersink")
350  || !strcmp(ctx->filter->name, "ffbuffersink")
351  || !strcmp(ctx->filter->name, "ffabuffersink"));
352 
353  return compat_read(ctx, bufref, 0, flags);
354 }
356 #endif
357 
359 {
360  av_assert0( !strcmp(ctx->filter->name, "buffersink")
361  || !strcmp(ctx->filter->name, "ffbuffersink"));
362 
363  return ctx->inputs[0]->frame_rate;
364 }
365 
366 int attribute_align_arg av_buffersink_poll_frame(AVFilterContext *ctx)
367 {
368  BufferSinkContext *buf = ctx->priv;
369  AVFilterLink *inlink = ctx->inputs[0];
370 
371  av_assert0( !strcmp(ctx->filter->name, "buffersink")
372  || !strcmp(ctx->filter->name, "abuffersink")
373  || !strcmp(ctx->filter->name, "ffbuffersink")
374  || !strcmp(ctx->filter->name, "ffabuffersink"));
375 
376  return av_fifo_size(buf->fifo)/sizeof(AVFilterBufferRef *) + ff_poll_frame(inlink);
377 }
378 
379 static av_cold int vsink_init(AVFilterContext *ctx, void *opaque)
380 {
381  BufferSinkContext *buf = ctx->priv;
382  AVBufferSinkParams *params = opaque;
383  int ret;
384 
385  if (params) {
386  if ((ret = av_opt_set_int_list(buf, "pix_fmts", params->pixel_fmts, AV_PIX_FMT_NONE, 0)) < 0)
387  return ret;
388  }
389 
390  return common_init(ctx);
391 }
392 
393 #define CHECK_LIST_SIZE(field) \
394  if (buf->field ## _size % sizeof(*buf->field)) { \
395  av_log(ctx, AV_LOG_ERROR, "Invalid size for " #field ": %d, " \
396  "should be multiple of %d\n", \
397  buf->field ## _size, (int)sizeof(*buf->field)); \
398  return AVERROR(EINVAL); \
399  }
401 {
402  BufferSinkContext *buf = ctx->priv;
404  unsigned i;
405  int ret;
406 
407  CHECK_LIST_SIZE(pixel_fmts)
408  if (buf->pixel_fmts_size) {
409  for (i = 0; i < NB_ITEMS(buf->pixel_fmts); i++)
410  if ((ret = ff_add_format(&formats, buf->pixel_fmts[i])) < 0) {
411  ff_formats_unref(&formats);
412  return ret;
413  }
414  ff_set_common_formats(ctx, formats);
415  } else {
417  }
418 
419  return 0;
420 }
421 
422 static av_cold int asink_init(AVFilterContext *ctx, void *opaque)
423 {
424  BufferSinkContext *buf = ctx->priv;
425  AVABufferSinkParams *params = opaque;
426  int ret;
427 
428  if (params) {
429  if ((ret = av_opt_set_int_list(buf, "sample_fmts", params->sample_fmts, AV_SAMPLE_FMT_NONE, 0)) < 0 ||
430  (ret = av_opt_set_int_list(buf, "sample_rates", params->sample_rates, -1, 0)) < 0 ||
431  (ret = av_opt_set_int_list(buf, "channel_layouts", params->channel_layouts, -1, 0)) < 0 ||
432  (ret = av_opt_set_int_list(buf, "channel_counts", params->channel_counts, -1, 0)) < 0 ||
433  (ret = av_opt_set_int(buf, "all_channel_counts", params->all_channel_counts, 0)) < 0)
434  return ret;
435  }
436  return common_init(ctx);
437 }
438 
440 {
441  BufferSinkContext *buf = ctx->priv;
444  unsigned i;
445  int ret;
446 
449  CHECK_LIST_SIZE(channel_layouts)
450  CHECK_LIST_SIZE(channel_counts)
451 
452  if (buf->sample_fmts_size) {
453  for (i = 0; i < NB_ITEMS(buf->sample_fmts); i++)
454  if ((ret = ff_add_format(&formats, buf->sample_fmts[i])) < 0) {
455  ff_formats_unref(&formats);
456  return ret;
457  }
458  ff_set_common_formats(ctx, formats);
459  }
460 
461  if (buf->channel_layouts_size || buf->channel_counts_size ||
462  buf->all_channel_counts) {
463  for (i = 0; i < NB_ITEMS(buf->channel_layouts); i++)
464  if ((ret = ff_add_channel_layout(&layouts, buf->channel_layouts[i])) < 0) {
465  ff_channel_layouts_unref(&layouts);
466  return ret;
467  }
468  for (i = 0; i < NB_ITEMS(buf->channel_counts); i++)
469  if ((ret = ff_add_channel_layout(&layouts, FF_COUNT2LAYOUT(buf->channel_counts[i]))) < 0) {
470  ff_channel_layouts_unref(&layouts);
471  return ret;
472  }
473  if (buf->all_channel_counts) {
474  if (layouts)
475  av_log(ctx, AV_LOG_WARNING,
476  "Conflicting all_channel_counts and list in options\n");
477  else if (!(layouts = ff_all_channel_counts()))
478  return AVERROR(ENOMEM);
479  }
480  ff_set_common_channel_layouts(ctx, layouts);
481  }
482 
483  if (buf->sample_rates_size) {
484  formats = NULL;
485  for (i = 0; i < NB_ITEMS(buf->sample_rates); i++)
486  if ((ret = ff_add_format(&formats, buf->sample_rates[i])) < 0) {
487  ff_formats_unref(&formats);
488  return ret;
489  }
490  ff_set_common_samplerates(ctx, formats);
491  }
492 
493  return 0;
494 }
495 
496 #define OFFSET(x) offsetof(BufferSinkContext, x)
497 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
498 static const AVOption buffersink_options[] = {
499  { "pix_fmts", "set the supported pixel formats", OFFSET(pixel_fmts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
500  { NULL },
501 };
502 #undef FLAGS
503 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
504 static const AVOption abuffersink_options[] = {
505  { "sample_fmts", "set the supported sample formats", OFFSET(sample_fmts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
506  { "sample_rates", "set the supported sample rates", OFFSET(sample_rates), AV_OPT_TYPE_BINARY, .flags = FLAGS },
507  { "channel_layouts", "set the supported channel layouts", OFFSET(channel_layouts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
508  { "channel_counts", "set the supported channel counts", OFFSET(channel_counts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
509  { "all_channel_counts", "accept all channel counts", OFFSET(all_channel_counts), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS },
510  { NULL },
511 };
512 #undef FLAGS
513 
514 AVFILTER_DEFINE_CLASS(buffersink);
515 AVFILTER_DEFINE_CLASS(abuffersink);
516 
517 #if FF_API_AVFILTERBUFFER
518 
519 #define ffbuffersink_options buffersink_options
520 #define ffabuffersink_options abuffersink_options
521 AVFILTER_DEFINE_CLASS(ffbuffersink);
522 AVFILTER_DEFINE_CLASS(ffabuffersink);
523 
524 static const AVFilterPad ffbuffersink_inputs[] = {
525  {
526  .name = "default",
527  .type = AVMEDIA_TYPE_VIDEO,
528  .filter_frame = filter_frame,
529  },
530  { NULL },
531 };
532 
533 AVFilter ff_vsink_ffbuffersink = {
534  .name = "ffbuffersink",
535  .description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."),
536  .priv_size = sizeof(BufferSinkContext),
537  .priv_class = &ffbuffersink_class,
538  .init_opaque = vsink_init,
539  .uninit = uninit,
540 
542  .inputs = ffbuffersink_inputs,
543  .outputs = NULL,
544 };
545 
546 static const AVFilterPad ffabuffersink_inputs[] = {
547  {
548  .name = "default",
549  .type = AVMEDIA_TYPE_AUDIO,
550  .filter_frame = filter_frame,
551  },
552  { NULL },
553 };
554 
555 AVFilter ff_asink_ffabuffersink = {
556  .name = "ffabuffersink",
557  .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."),
558  .init_opaque = asink_init,
559  .uninit = uninit,
560  .priv_size = sizeof(BufferSinkContext),
561  .priv_class = &ffabuffersink_class,
563  .inputs = ffabuffersink_inputs,
564  .outputs = NULL,
565 };
566 #endif /* FF_API_AVFILTERBUFFER */
567 
569  {
570  .name = "default",
571  .type = AVMEDIA_TYPE_VIDEO,
572  .filter_frame = filter_frame,
573  },
574  { NULL }
575 };
576 
578  .name = "buffersink",
579  .description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."),
580  .priv_size = sizeof(BufferSinkContext),
581  .priv_class = &buffersink_class,
582  .init_opaque = vsink_init,
583  .uninit = uninit,
584 
586  .inputs = avfilter_vsink_buffer_inputs,
587  .outputs = NULL,
588 };
589 
591  {
592  .name = "default",
593  .type = AVMEDIA_TYPE_AUDIO,
594  .filter_frame = filter_frame,
595  },
596  { NULL }
597 };
598 
600  .name = "abuffersink",
601  .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."),
602  .priv_class = &abuffersink_class,
603  .priv_size = sizeof(BufferSinkContext),
604  .init_opaque = asink_init,
605  .uninit = uninit,
606 
608  .inputs = avfilter_asink_abuffer_inputs,
609  .outputs = NULL,
610 };
#define NULL
Definition: coverity.c:32
int 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:523
const char * s
Definition: avisynth_c.h:631
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
Definition: audio_fifo.c:60
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
Read data from an AVAudioFifo.
Definition: audio_fifo.c:139
enum AVSampleFormat * sample_fmts
list of accepted sample formats, terminated by AV_SAMPLE_FMT_NONE
Definition: buffersink.c:49
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
AVOption.
Definition: opt.h:255
AVBufferSinkParams * av_buffersink_params_alloc(void)
Create an AVBufferSinkParams structure.
Definition: buffersink.c:225
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
#define AV_NOWARN_DEPRECATED(code)
Disable warnings about deprecated features This is useful for sections of code kept for backward comp...
Definition: attributes.h:100
static av_cold void uninit(AVFilterContext *ctx)
Definition: buffersink.c:66
Main libavfilter public API header.
static int read_from_fifo(AVFilterContext *ctx, AVFrame *frame, int nb_samples)
Definition: buffersink.c:159
const int * channel_counts
list of allowed channel counts, terminated by -1
Definition: buffersink.h:139
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:441
AVABufferSinkParams * av_abuffersink_params_alloc(void)
Create an AVABufferSinkParams structure.
Definition: buffersink.c:236
#define av_opt_set_int_list(obj, name, val, term, flags)
Set a binary option to an integer list.
Definition: opt.h:748
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
Definition: audio_fifo.c:45
int * sample_rates
list of accepted sample rates, terminated by -1
Definition: buffersink.c:56
static const AVOption abuffersink_options[]
Definition: buffersink.c:504
int * channel_counts
list of accepted channel counts, terminated by -1
Definition: buffersink.c:53
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:479
static enum AVSampleFormat formats[]
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.
Definition: fifo.c:122
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:137
const char * name
Pad name.
Definition: internal.h:67
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:641
char * name
name of this filter instance
Definition: avfilter.h:638
#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:379
AVAudioFifo * audio_fifo
FIFO for audio samples.
Definition: buffersink.c:60
#define av_cold
Definition: attributes.h:74
#define av_malloc(s)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:135
AVOptions.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:363
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:257
int av_fifo_space(const AVFifoBuffer *f)
Return the amount of space in bytes in the AVFifoBuffer, that is the amount of data you can write int...
Definition: fifo.c:82
static AVFrame * frame
static av_cold int asink_init(AVFilterContext *ctx, void *opaque)
Definition: buffersink.c:422
static const AVOption buffersink_options[]
Definition: buffersink.c:498
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define CHECK_LIST_SIZE(field)
Definition: buffersink.c:393
#define FLAGS
Definition: buffersink.c:503
#define av_log(a,...)
#define AV_BUFFERSINK_FLAG_NO_REQUEST
Tell av_buffersink_get_buffer_ref() not to request a frame from its input.
Definition: buffersink.h:117
A filter pad used for either input or output.
Definition: internal.h:61
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition: avutil.h:301
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:140
AVFILTER_DEFINE_CLASS(buffersink)
static int vsink_query_formats(AVFilterContext *ctx)
Definition: buffersink.c:400
int width
width and height of the video frame
Definition: frame.h:220
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
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:148
int 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:542
#define FIFO_INIT_SIZE
Definition: buffersink.c:245
int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
Definition: formats.c:329
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:70
int attribute_align_arg av_buffersink_poll_frame(AVFilterContext *ctx)
Definition: buffersink.c:366
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:148
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
int * sample_rates
list of allowed sample rates, terminated by -1
Definition: buffersink.h:141
void * priv
private data for use by the filter
Definition: avfilter.h:654
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.
Definition: fifo.c:150
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:491
GLenum GLint * params
Definition: opengl_enc.c:114
simple assert() macros that are a bit more flexible than ISO C assert().
static const AVFilterPad avfilter_asink_abuffer_inputs[]
Definition: buffersink.c:590
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:323
int channel_layouts_size
Definition: buffersink.c:52
AVFilter ff_vsink_buffer
Definition: buffersink.c:577
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
static const int sample_rates[]
Definition: dcaenc.h:32
Context for an Audio FIFO Buffer.
Definition: audio_fifo.c:34
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:427
common internal API header
int64_t * channel_layouts
list of accepted channel layouts, terminated by -1
Definition: buffersink.c:51
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
Definition: audio_fifo.c:186
audio channel layout utility functions
Struct to use for initializing an abuffersink context.
Definition: buffersink.h:136
ret
Definition: avfilter.c:974
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:181
Struct to use for initializing a buffersink context.
Definition: buffersink.h:122
enum AVPixelFormat * pixel_fmts
list of accepted pixel formats, must be terminated with -1
Definition: buffersink.c:45
offset must point to a pointer immediately followed by an int for the length
Definition: opt.h:229
AVFilter ff_asink_abuffer
Definition: buffersink.c:599
A list of supported channel layouts.
Definition: formats.h:85
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:232
int ff_default_query_formats(AVFilterContext *ctx)
Definition: formats.c:571
int frame_size
Definition: mxfenc.c:1803
#define OFFSET(x)
Definition: buffersink.c:496
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:59
int av_fifo_size(const AVFifoBuffer *f)
Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from ...
Definition: fifo.c:77
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
Resize an AVFifoBuffer.
Definition: fifo.c:87
void ff_channel_layouts_unref(AVFilterChannelLayouts **ref)
Remove a reference to a channel layouts list.
Definition: formats.c:463
void * buf
Definition: avisynth_c.h:553
int all_channel_counts
if not 0, accept any channel count or layout
Definition: buffersink.h:140
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:470
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
rational number numerator/denominator
Definition: rational.h:43
AVFilterBufferRef * avfilter_get_video_buffer_ref_from_arrays(uint8_t *const data[4], const int linesize[4], int perms, int w, int h, enum AVPixelFormat format)
Definition: video.c:64
#define NB_ITEMS(list)
Definition: buffersink.c:64
void ff_formats_unref(AVFilterFormats **ref)
If *ref is non-NULL, remove *ref as a reference to the format list it currently points to...
Definition: formats.c:458
const char * name
Filter name.
Definition: avfilter.h:474
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
AVRational av_buffersink_get_frame_rate(AVFilterContext *ctx)
Get the frame rate of the input.
Definition: buffersink.c:358
AVFifoBuffer * fifo
FIFO buffer of video frame references.
Definition: buffersink.c:41
AVFifoBuffer * av_fifo_alloc_array(size_t nmemb, size_t size)
Initialize an AVFifoBuffer.
Definition: fifo.c:49
static int flags
Definition: cpu.c:47
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
Definition: audio_fifo.c:113
int64_t next_pts
interpolating audio pts
Definition: buffersink.c:61
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:79
static int query_formats(AVFilterContext *ctx)
Definition: aeval.c:244
common internal and external API header
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:123
void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size)
Set the frame size for an audio buffer sink.
Definition: buffersink.c:261
static av_cold int common_init(AVFilterContext *ctx)
Definition: buffersink.c:247
#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:110
#define av_free(p)
Audio FIFO Buffer.
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:80
static int asink_query_formats(AVFilterContext *ctx)
Definition: buffersink.c:439
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:633
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
int height
Definition: frame.h:220
#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:568
void av_fifo_freep(AVFifoBuffer **f)
Free an AVFifoBuffer and reset pointer to NULL.
Definition: fifo.c:63
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:343
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:394
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:215
int ff_poll_frame(AVFilterLink *link)
Poll a frame from the filter chain.
Definition: avfilter.c:374
int attribute_align_arg 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
const int64_t * channel_layouts
list of allowed channel layouts, terminated by -1
Definition: buffersink.h:138
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:225
unsigned warning_limit
Definition: buffersink.c:42
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:250
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:636
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:530
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:241
static void compat_free_buffer(void *opaque, uint8_t *data)
Definition: utils.c:852