FFmpeg
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/avassert.h"
27 #include "libavutil/avstring.h"
29 #include "libavutil/common.h"
30 #include "libavutil/internal.h"
31 #include "libavutil/mem.h"
32 #include "libavutil/opt.h"
33 
34 #include "audio.h"
35 #include "avfilter.h"
36 #include "avfilter_internal.h"
37 #include "buffersink.h"
38 #include "filters.h"
39 #include "formats.h"
40 #include "framequeue.h"
41 #include "video.h"
42 
43 typedef struct BufferSinkContext {
44  const AVClass *class;
45  unsigned warning_limit;
46  unsigned frame_size;
47 
48  /* only used for video */
49 #if FF_API_BUFFERSINK_OPTS
50  enum AVPixelFormat *pixel_fmts; ///< list of accepted pixel formats
51  int pixel_fmts_size;
52  enum AVColorSpace *color_spaces; ///< list of accepted color spaces
53  int color_spaces_size;
54  enum AVColorRange *color_ranges; ///< list of accepted color ranges
55  int color_ranges_size;
56 #endif
57 
59  unsigned nb_pixel_formats;
60 
62  unsigned nb_colorspaces;
63 
65  unsigned nb_colorranges;
66 
67  /* only used for audio */
68 #if FF_API_BUFFERSINK_OPTS
69  enum AVSampleFormat *sample_fmts; ///< list of accepted sample formats
70  int sample_fmts_size;
71  char *channel_layouts_str; ///< list of accepted channel layouts
72  int all_channel_counts;
73  int *sample_rates; ///< list of accepted sample rates
74  int sample_rates_size;
75 #endif
76 
79 
81  unsigned nb_samplerates;
82 
85 
88 
90 {
92 }
93 
95 {
97  buf->peeked_frame = in;
98  return out ? av_frame_ref(out, in) : 0;
99  } else {
100  av_assert1(out);
101  buf->peeked_frame = NULL;
102  av_frame_move_ref(out, in);
103  av_frame_free(&in);
104  return 0;
105  }
106 }
107 
109 {
110  BufferSinkContext *buf = ctx->priv;
111  AVFilterLink *inlink = ctx->inputs[0];
113  int status, ret;
114  AVFrame *cur_frame;
115  int64_t pts;
116 
117  if (buf->peeked_frame)
118  return return_or_keep_frame(buf, frame, buf->peeked_frame, flags);
119 
120  while (1) {
122  ff_inlink_consume_frame(inlink, &cur_frame);
123  if (ret < 0) {
124  return ret;
125  } else if (ret) {
126  /* TODO return the frame instead of copying it */
127  return return_or_keep_frame(buf, frame, cur_frame, flags);
128  } else if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
129  return status;
130  } else if ((flags & AV_BUFFERSINK_FLAG_NO_REQUEST)) {
131  return AVERROR(EAGAIN);
132  } else if (li->frame_wanted_out) {
133  ret = ff_filter_graph_run_once(ctx->graph);
134  if (ret < 0)
135  return ret;
136  } else {
138  }
139  }
140 }
141 
143 {
145  ff_filter_link(ctx->inputs[0])->min_samples);
146 }
147 
149  AVFrame *frame, int nb_samples)
150 {
151  return get_frame_internal(ctx, frame, 0, nb_samples);
152 }
153 
155 {
156  BufferSinkContext *buf = ctx->priv;
157  int ret = 0;
158 
159 #if FF_API_BUFFERSINK_OPTS
160 
161 #define CHECK_LIST_SIZE(field) \
162  if (buf->field ## _size % sizeof(*buf->field)) { \
163  av_log(ctx, AV_LOG_ERROR, "Invalid size for " #field ": %d, " \
164  "should be multiple of %d\n", \
165  buf->field ## _size, (int)sizeof(*buf->field)); \
166  return AVERROR(EINVAL); \
167  }
168 
169  if (ctx->input_pads[0].type == AVMEDIA_TYPE_VIDEO) {
170  if ((buf->pixel_fmts_size || buf->color_spaces_size || buf->color_ranges_size) &&
171  (buf->nb_pixel_formats || buf->nb_colorspaces || buf->nb_colorranges)) {
172  av_log(ctx, AV_LOG_ERROR, "Cannot combine old and new format lists\n");
173  return AVERROR(EINVAL);
174  }
175 
176  CHECK_LIST_SIZE(pixel_fmts)
177  CHECK_LIST_SIZE(color_spaces)
178  CHECK_LIST_SIZE(color_ranges)
179  } else {
180  if ((buf->sample_fmts_size || buf->channel_layouts_str || buf->sample_rates_size) &&
181  (buf->nb_sample_formats || buf->nb_samplerates || buf->nb_channel_layouts)) {
182  av_log(ctx, AV_LOG_ERROR, "Cannot combine old and new format lists\n");
183  return AVERROR(EINVAL);
184  }
185 
186  CHECK_LIST_SIZE(sample_fmts)
187  CHECK_LIST_SIZE(sample_rates)
188 
189  if (buf->channel_layouts_str) {
190  const char *cur = buf->channel_layouts_str;
191 
192  if (buf->all_channel_counts)
194  "Conflicting all_channel_counts and list in options\n");
195 
196  while (cur) {
197  void *tmp;
198  char *next = strchr(cur, '|');
199  if (next)
200  *next++ = 0;
201 
202  // +2 for the new element and terminator
204  sizeof(*buf->channel_layouts));
205  if (!tmp)
206  return AVERROR(ENOMEM);
207 
208  buf->channel_layouts = tmp;
209  memset(&buf->channel_layouts[buf->nb_channel_layouts], 0,
210  sizeof(*buf->channel_layouts) * 2);
211  buf->nb_channel_layouts++;
212 
214  if (ret < 0) {
215  av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: %s.\n", cur);
216  return ret;
217  }
218  if (ret < 0)
219  return ret;
220 
221  cur = next;
222  }
223 
224  if (buf->nb_channel_layouts)
226  }
227  }
228 
229 #undef CHECK_LIST_SIZE
230 
231 #endif
232 
233  buf->warning_limit = 100;
234  return 0;
235 }
236 
237 #define TERMINATE_ARRAY(arr, val) \
238  if (s->arr) { \
239  void *tmp = av_realloc_array(s->arr, s->nb_ ## arr + 1, sizeof(*s->arr)); \
240  if (!tmp) \
241  return AVERROR(ENOMEM); \
242  s->arr = tmp; \
243  s->arr[s->nb_ ## arr] = val; \
244  }
245 
247 {
248  BufferSinkContext *s = ctx->priv;
249 
251  TERMINATE_ARRAY(colorranges, -1);
252  TERMINATE_ARRAY(colorspaces, -1);
253 
254  return common_init(ctx);
255 }
256 
258 {
259  BufferSinkContext *s = ctx->priv;
260 
262  TERMINATE_ARRAY(samplerates, -1);
263  TERMINATE_ARRAY(channel_layouts, (AVChannelLayout){ .nb_channels = 0 });
264 
265  return common_init(ctx);
266 }
267 
268 #undef TERMINATE_ARRAY
269 
271 {
272  BufferSinkContext *buf = ctx->priv;
273 
275 }
276 
278 {
279  BufferSinkContext *buf = ctx->priv;
280  FilterLinkInternal * const li = ff_link_internal(ctx->inputs[0]);
281 
282  if (buf->warning_limit &&
285  "%d buffers queued in %s, something may be wrong.\n",
286  buf->warning_limit,
287  (char *)av_x_if_null(ctx->name, ctx->filter->name));
288  buf->warning_limit *= 10;
289  }
290 
291  /* The frame is queued, the rest is up to get_frame_internal */
292  return 0;
293 }
294 
296 {
297  BufferSinkContext *buf = inlink->dst->priv;
299 
300  l->min_samples = l->max_samples = buf->frame_size;
301 
302  return 0;
303 }
304 
306 {
307  BufferSinkContext *buf = ctx->priv;
308  buf->frame_size = frame_size;
309 
310  if (ctx->inputs && ctx->inputs[0]) {
311  FilterLink *l = ff_filter_link(ctx->inputs[0]);
312  l->min_samples = l->max_samples = buf->frame_size;
313  }
314 }
315 
316 #define MAKE_AVFILTERLINK_ACCESSOR(type, field) \
317 type av_buffersink_get_##field(const AVFilterContext *ctx) { \
318  av_assert0(fffilter(ctx->filter)->activate == activate); \
319  return ctx->inputs[0]->field; \
320 }
321 
325 
328 MAKE_AVFILTERLINK_ACCESSOR(AVRational , sample_aspect_ratio)
331 
332 MAKE_AVFILTERLINK_ACCESSOR(int , sample_rate )
333 
335 {
336  FilterLink *l = ff_filter_link(ctx->inputs[0]);
337  av_assert0(fffilter(ctx->filter)->activate == activate);
338  return l->frame_rate;
339 }
340 
342 {
343  FilterLink *l = ff_filter_link(ctx->inputs[0]);
344  av_assert0(fffilter(ctx->filter)->activate == activate);
345  return l->hw_frames_ctx;
346 }
347 
349 {
350  av_assert0(fffilter(ctx->filter)->activate == activate);
351  return ctx->inputs[0]->ch_layout.nb_channels;
352 }
353 
355 {
356  AVChannelLayout ch_layout = { 0 };
357  int ret;
358 
359  av_assert0(fffilter(ctx->filter)->activate == activate);
360  ret = av_channel_layout_copy(&ch_layout, &ctx->inputs[0]->ch_layout);
361  if (ret < 0)
362  return ret;
363  *out = ch_layout;
364  return 0;
365 }
366 
368  int *nb_side_data)
369 {
370  av_assert0(fffilter(ctx->filter)->activate == activate);
371  *nb_side_data = ctx->inputs[0]->nb_side_data;
372  return (const AVFrameSideData *const *)ctx->inputs[0]->side_data;
373 }
374 
375 #if FF_API_BUFFERSINK_OPTS
376 #define NB_ITEMS(list) (list ## _size / sizeof(*list))
377 #endif
378 
380  AVFilterFormatsConfig **cfg_in,
381  AVFilterFormatsConfig **cfg_out)
382 {
383  const BufferSinkContext *buf = ctx->priv;
384  int ret;
385 
386 #if FF_API_BUFFERSINK_OPTS
387  if (buf->nb_pixel_formats || buf->nb_colorspaces || buf->nb_colorranges) {
388 #endif
389  if (buf->nb_pixel_formats) {
390  ret = ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out, buf->pixel_formats);
391  if (ret < 0)
392  return ret;
393  }
394  if (buf->nb_colorspaces) {
395  ret = ff_set_common_color_spaces_from_list2(ctx, cfg_in, cfg_out, buf->colorspaces);
396  if (ret < 0)
397  return ret;
398  }
399  if (buf->nb_colorranges) {
400  ret = ff_set_common_color_ranges_from_list2(ctx, cfg_in, cfg_out, buf->colorranges);
401  if (ret < 0)
402  return ret;
403  }
404 #if FF_API_BUFFERSINK_OPTS
405  } else {
406  unsigned i;
407  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  return ret;
412  if ((ret = ff_set_common_formats2(ctx, cfg_in, cfg_out, formats)) < 0)
413  return ret;
414  }
415 
416  if (buf->color_spaces_size) {
418  for (i = 0; i < NB_ITEMS(buf->color_spaces); i++)
419  if ((ret = ff_add_format(&formats, buf->color_spaces[i])) < 0)
420  return ret;
421  if ((ret = ff_set_common_color_spaces2(ctx, cfg_in, cfg_out, formats)) < 0)
422  return ret;
423  }
424 
425  if (buf->color_ranges_size) {
427  for (i = 0; i < NB_ITEMS(buf->color_ranges); i++)
428  if ((ret = ff_add_format(&formats, buf->color_ranges[i])) < 0)
429  return ret;
430  if ((ret = ff_set_common_color_ranges2(ctx, cfg_in, cfg_out, formats)) < 0)
431  return ret;
432  }
433  }
434 #endif
435 
436  return 0;
437 }
438 
440  AVFilterFormatsConfig **cfg_in,
441  AVFilterFormatsConfig **cfg_out)
442 {
443  const BufferSinkContext *buf = ctx->priv;
444  int ret;
445 
446 #if FF_API_BUFFERSINK_OPTS
447  if (buf->nb_sample_formats || buf->nb_samplerates || buf->nb_channel_layouts) {
448 #endif
449  if (buf->nb_sample_formats) {
450  ret = ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out, buf->sample_formats);
451  if (ret < 0)
452  return ret;
453  }
454  if (buf->nb_samplerates) {
455  ret = ff_set_common_samplerates_from_list2(ctx, cfg_in, cfg_out, buf->samplerates);
456  if (ret < 0)
457  return ret;
458  }
459  if (buf->nb_channel_layouts) {
461  if (ret < 0)
462  return ret;
463  }
464 #if FF_API_BUFFERSINK_OPTS
465  } else {
467  unsigned i;
468 
469  if (buf->sample_fmts_size) {
470  for (i = 0; i < NB_ITEMS(buf->sample_fmts); i++)
471  if ((ret = ff_add_format(&formats, buf->sample_fmts[i])) < 0)
472  return ret;
473  if ((ret = ff_set_common_formats2(ctx, cfg_in, cfg_out, formats)) < 0)
474  return ret;
475  }
476 
477  if (buf->nb_channel_layouts) {
479  if (ret < 0)
480  return ret;
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  return ret;
488  if ((ret = ff_set_common_samplerates2(ctx, cfg_in, cfg_out, formats)) < 0)
489  return ret;
490  }
491  }
492 #endif
493 
494  return 0;
495 }
496 
497 #define OFFSET(x) offsetof(BufferSinkContext, x)
498 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
499 static const AVOption buffersink_options[] = {
500 #if FF_API_BUFFERSINK_OPTS
501  { "pix_fmts", "set the supported pixel formats", OFFSET(pixel_fmts), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED },
502  { "color_spaces", "set the supported color spaces", OFFSET(color_spaces), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED },
503  { "color_ranges", "set the supported color ranges", OFFSET(color_ranges), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED },
504 #endif
505 
506  { "pixel_formats", "array of supported pixel formats", OFFSET(pixel_formats),
507  AV_OPT_TYPE_PIXEL_FMT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = FLAGS },
508  { "colorspaces", "array of supported color spaces", OFFSET(colorspaces),
509  AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = FLAGS },
510  { "colorranges", "array of supported color ranges", OFFSET(colorranges),
511  AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = FLAGS },
512 
513  { NULL },
514 };
515 #undef FLAGS
516 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM
517 static const AVOption abuffersink_options[] = {
518 #if FF_API_BUFFERSINK_OPTS
519  { "sample_fmts", "set the supported sample formats", OFFSET(sample_fmts), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED },
520  { "sample_rates", "set the supported sample rates", OFFSET(sample_rates), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED },
521  { "ch_layouts", "set a '|'-separated list of supported channel layouts",
522  OFFSET(channel_layouts_str), AV_OPT_TYPE_STRING, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED },
523  { "all_channel_counts", "accept all channel counts", OFFSET(all_channel_counts), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS | AV_OPT_FLAG_DEPRECATED },
524 #endif
525 
526  { "sample_formats", "array of supported sample formats", OFFSET(sample_formats),
527  AV_OPT_TYPE_SAMPLE_FMT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = FLAGS },
528  { "samplerates", "array of supported sample formats", OFFSET(samplerates),
529  AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = FLAGS },
530  { "channel_layouts", "array of supported channel layouts", OFFSET(channel_layouts),
532  { NULL },
533 };
534 #undef FLAGS
535 
536 AVFILTER_DEFINE_CLASS(buffersink);
537 AVFILTER_DEFINE_CLASS(abuffersink);
538 
540  .p.name = "buffersink",
541  .p.description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."),
542  .p.priv_class = &buffersink_class,
543  .p.outputs = NULL,
544  .priv_size = sizeof(BufferSinkContext),
545  .init = init_video,
546  .uninit = uninit,
547  .activate = activate,
550 };
551 
552 static const AVFilterPad inputs_audio[] = {
553  {
554  .name = "default",
555  .type = AVMEDIA_TYPE_AUDIO,
556  .config_props = config_input_audio,
557  },
558 };
559 
561  .p.name = "abuffersink",
562  .p.description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."),
563  .p.priv_class = &abuffersink_class,
564  .p.outputs = NULL,
565  .priv_size = sizeof(BufferSinkContext),
566  .init = init_audio,
567  .uninit = uninit,
568  .activate = activate,
571 };
formats
formats
Definition: signature.h:47
ff_filter_graph_run_once
int ff_filter_graph_run_once(AVFilterGraph *graph)
Run one round of processing on a filter graph.
Definition: avfiltergraph.c:1473
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
av_buffersink_get_ch_layout
int av_buffersink_get_ch_layout(const AVFilterContext *ctx, AVChannelLayout *out)
Definition: buffersink.c:354
av_buffersink_get_samples
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:148
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
ff_link_internal
static FilterLinkInternal * ff_link_internal(AVFilterLink *link)
Definition: avfilter_internal.h:90
abuffersink_options
static const AVOption abuffersink_options[]
Definition: buffersink.c:517
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame 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. Frame references ownership and permissions
opt.h
AV_OPT_TYPE_SAMPLE_FMT
@ AV_OPT_TYPE_SAMPLE_FMT
Underlying C type is enum AVSampleFormat.
Definition: opt.h:311
out
FILE * out
Definition: movenc.c:55
ff_set_common_color_ranges2
int ff_set_common_color_ranges2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *color_ranges)
Definition: formats.c:983
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:948
av_buffersink_get_frame_flags
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:142
uninit
static void uninit(AVFilterContext *ctx)
Definition: buffersink.c:270
ff_set_common_formats2
int ff_set_common_formats2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *formats)
Definition: formats.c:1007
int64_t
long long int64_t
Definition: coverity.c:34
TERMINATE_ARRAY
#define TERMINATE_ARRAY(arr, val)
Definition: buffersink.c:237
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:163
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
sample_rates
static const int sample_rates[]
Definition: dcaenc.h:34
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:410
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
w
uint8_t w
Definition: llviddspenc.c:38
AVOption
AVOption.
Definition: opt.h:429
ff_asink_abuffer
const FFFilter ff_asink_abuffer
Definition: buffersink.c:560
ff_set_common_channel_layouts_from_list2
int ff_set_common_channel_layouts_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const AVChannelLayout *fmts)
Definition: formats.c:920
pixel_fmts
static enum AVPixelFormat pixel_fmts[]
Definition: vf_amplify.c:52
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:203
av_buffersink_get_hw_frames_ctx
AVBufferRef * av_buffersink_get_hw_frames_ctx(const AVFilterContext *ctx)
Definition: buffersink.c:341
video.h
ff_set_common_color_ranges_from_list2
int ff_set_common_color_ranges_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *color_ranges)
Definition: formats.c:992
fffilter
static const FFFilter * fffilter(const AVFilter *f)
Definition: filters.h:462
inputs_audio
static const AVFilterPad inputs_audio[]
Definition: buffersink.c:552
FilterLinkInternal
Definition: avfilter_internal.h:34
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
BufferSinkContext::sample_formats
enum AVSampleFormat * sample_formats
Definition: buffersink.c:77
formats.h
ff_inlink_consume_frame
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Definition: avfilter.c:1507
av_buffersink_set_frame_size
void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size)
Set the frame size for an audio buffer sink.
Definition: buffersink.c:305
AV_OPT_TYPE_BINARY
@ AV_OPT_TYPE_BINARY
Underlying C type is a uint8_t* that is either NULL or points to an array allocated with the av_mallo...
Definition: opt.h:286
init_video
static int init_video(AVFilterContext *ctx)
Definition: buffersink.c:246
BufferSinkContext::samplerates
int * samplerates
Definition: buffersink.c:80
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
pts
static int64_t pts
Definition: transcode_aac.c:644
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
av_cold
#define av_cold
Definition: attributes.h:90
ff_video_default_filterpad
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition: video.c:37
ff_set_common_color_spaces2
int ff_set_common_color_spaces2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *color_spaces)
Definition: formats.c:959
FFFilter
Definition: filters.h:265
av_buffersink_get_frame_rate
AVRational av_buffersink_get_frame_rate(const AVFilterContext *ctx)
Definition: buffersink.c:334
AV_BUFFERSINK_FLAG_PEEK
#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:84
ff_inlink_request_frame
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1610
s
#define s(width, name)
Definition: cbs_vp9.c:198
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:217
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame 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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
return_or_keep_frame
static int return_or_keep_frame(BufferSinkContext *buf, AVFrame *out, AVFrame *in, int flags)
Definition: buffersink.c:94
frame_size
int frame_size
Definition: mxfenc.c:2429
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
av_buffersink_get_frame
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:89
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(buffersink)
filters.h
ff_set_common_samplerates_from_list2
int ff_set_common_samplerates_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *samplerates)
Definition: formats.c:944
ctx
AVFormatContext * ctx
Definition: movenc.c:49
pixel_formats
static enum AVPixelFormat pixel_formats[]
Definition: vf_sr.c:64
ff_set_common_samplerates2
int ff_set_common_samplerates2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *samplerates)
Definition: formats.c:935
color_range
color_range
Definition: vf_selectivecolor.c:43
FLAGS
#define FLAGS
Definition: buffersink.c:516
ff_vsink_buffer
const FFFilter ff_vsink_buffer
Definition: buffersink.c:539
BufferSinkContext::pixel_formats
enum AVPixelFormat * pixel_formats
Definition: buffersink.c:58
activate
static int activate(AVFilterContext *ctx)
Definition: buffersink.c:277
FFFilter::activate
int(* activate)(AVFilterContext *ctx)
Filter activation function.
Definition: filters.h:459
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
ff_inlink_consume_samples
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
Definition: avfilter.c:1527
NULL
#define NULL
Definition: coverity.c:32
framequeue.h
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
ff_add_format
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:504
avfilter_internal.h
BufferSinkContext::colorranges
int * colorranges
Definition: buffersink.c:64
AV_OPT_TYPE_CHLAYOUT
@ AV_OPT_TYPE_CHLAYOUT
Underlying C type is AVChannelLayout.
Definition: opt.h:331
ff_inlink_acknowledge_status
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
Definition: avfilter.c:1454
buffersink_options
static const AVOption buffersink_options[]
Definition: buffersink.c:499
AVFilterFormatsConfig
Lists of formats / etc.
Definition: avfilter.h:109
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:197
BufferSinkContext::colorspaces
int * colorspaces
Definition: buffersink.c:61
BufferSinkContext::nb_samplerates
unsigned nb_samplerates
Definition: buffersink.c:81
attribute_align_arg
#define attribute_align_arg
Definition: internal.h:50
BufferSinkContext::nb_sample_formats
unsigned nb_sample_formats
Definition: buffersink.c:78
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
AVMediaType
AVMediaType
Definition: avutil.h:199
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
BufferSinkContext::frame_size
unsigned frame_size
Definition: buffersink.c:46
av_frame_ref
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:401
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:319
sample_formats
static const struct @173 sample_formats[]
AV_OPT_TYPE_FLAG_ARRAY
@ AV_OPT_TYPE_FLAG_ARRAY
May be combined with another regular option type to declare an array option.
Definition: opt.h:346
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
BufferSinkContext::nb_channel_layouts
unsigned nb_channel_layouts
Definition: buffersink.c:84
config_input_audio
static int config_input_audio(AVFilterLink *inlink)
Definition: buffersink.c:295
common_init
static av_cold int common_init(AVFilterContext *ctx)
Definition: buffersink.c:154
ff_set_common_color_spaces_from_list2
int ff_set_common_color_spaces_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *color_ranges)
Definition: formats.c:968
buffersink.h
av_buffersink_get_side_data
const AVFrameSideData *const * av_buffersink_get_side_data(const AVFilterContext *ctx, int *nb_side_data)
Definition: buffersink.c:367
AV_OPT_FLAG_DEPRECATED
#define AV_OPT_FLAG_DEPRECATED
Set if option is deprecated, users should refer to AVOption.help text for more information.
Definition: opt.h:386
av_channel_layout_from_string
int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str)
Initialize a channel layout from a given string description.
Definition: channel_layout.c:312
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
BufferSinkContext::nb_colorspaces
unsigned nb_colorspaces
Definition: buffersink.c:62
internal.h
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:651
common.h
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
FILTER_QUERY_FUNC2
#define FILTER_QUERY_FUNC2(func)
Definition: filters.h:239
FilterLinkInternal::frame_wanted_out
int frame_wanted_out
True if a frame is currently wanted on the output of this filter.
Definition: avfilter_internal.h:75
av_frame_move_ref
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:650
BufferSinkContext
Definition: buffersink.c:43
BufferSinkContext::nb_pixel_formats
unsigned nb_pixel_formats
Definition: buffersink.c:59
init_audio
static int init_audio(AVFilterContext *ctx)
Definition: buffersink.c:257
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
OFFSET
#define OFFSET(x)
Definition: buffersink.c:497
AV_BUFFERSINK_FLAG_NO_REQUEST
#define AV_BUFFERSINK_FLAG_NO_REQUEST
Tell av_buffersink_get_buffer_ref() not to request a frame from its input.
Definition: buffersink.h:91
ret
ret
Definition: filter_design.txt:187
BufferSinkContext::warning_limit
unsigned warning_limit
Definition: buffersink.c:45
frame
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 the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
ff_framequeue_queued_frames
static size_t ff_framequeue_queued_frames(const FFFrameQueue *fq)
Get the number of queued frames.
Definition: framequeue.h:146
status
ov_status_e status
Definition: dnn_backend_openvino.c:100
ff_set_common_formats_from_list2
int ff_set_common_formats_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *fmts)
Definition: formats.c:1016
channel_layout.h
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
asink_query_formats
static int asink_query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: buffersink.c:439
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
avfilter.h
av_buffersink_get_channels
int av_buffersink_get_channels(const AVFilterContext *ctx)
Definition: buffersink.c:348
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
AV_OPT_TYPE_PIXEL_FMT
@ AV_OPT_TYPE_PIXEL_FMT
Underlying C type is enum AVPixelFormat.
Definition: opt.h:307
AVFilterContext
An instance of a filter.
Definition: avfilter.h:257
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:449
get_frame_internal
static int get_frame_internal(AVFilterContext *ctx, AVFrame *frame, int flags, int samples)
Definition: buffersink.c:108
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
FFFilter::p
AVFilter p
The public AVFilter.
Definition: filters.h:269
mem.h
audio.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
MAKE_AVFILTERLINK_ACCESSOR
#define MAKE_AVFILTERLINK_ACCESSOR(type, field)
Definition: buffersink.c:316
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:265
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
channel_layouts
static const uint16_t channel_layouts[7]
Definition: dca_lbr.c:112
BufferSinkContext::peeked_frame
AVFrame * peeked_frame
Definition: buffersink.c:86
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
BufferSinkContext::nb_colorranges
unsigned nb_colorranges
Definition: buffersink.c:65
h
h
Definition: vp9dsp_template.c:2070
FilterLinkInternal::fifo
FFFrameQueue fifo
Queue of frames waiting to be filtered.
Definition: avfilter_internal.h:42
avstring.h
vsink_query_formats
static int vsink_query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: buffersink.c:379
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:693
BufferSinkContext::channel_layouts
AVChannelLayout * channel_layouts
Definition: buffersink.c:83
av_x_if_null
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition: avutil.h:312