buffersrc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 Vitor Sessak
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  * memory buffer source filter
24  */
25 
26 #include <float.h>
27 
29 #include "libavutil/common.h"
30 #include "libavutil/fifo.h"
31 #include "libavutil/frame.h"
32 #include "libavutil/imgutils.h"
33 #include "libavutil/opt.h"
34 #include "libavutil/samplefmt.h"
35 #include "audio.h"
36 #include "avfilter.h"
37 #include "buffersrc.h"
38 #include "formats.h"
39 #include "internal.h"
40 #include "video.h"
41 #include "avcodec.h"
42 
43 typedef struct {
44  const AVClass *class;
46  AVRational time_base; ///< time_base to set in the output link
47  AVRational frame_rate; ///< frame_rate to set in the output link
49  unsigned warning_limit;
50 
51  /* video only */
52  int w, h;
54  char *pix_fmt_str;
56  char *sws_param;
57 
58  /* audio only */
60  enum AVSampleFormat sample_fmt;
62  int channels;
63  uint64_t channel_layout;
65 
66  int eof;
68 
69 #define CHECK_VIDEO_PARAM_CHANGE(s, c, width, height, format)\
70  if (c->w != width || c->h != height || c->pix_fmt != format) {\
71  av_log(s, AV_LOG_INFO, "Changing frame properties on the fly is not supported by all filters.\n");\
72  }
73 
74 #define CHECK_AUDIO_PARAM_CHANGE(s, c, srate, ch_layout, ch_count, format)\
75  if (c->sample_fmt != format || c->sample_rate != srate ||\
76  c->channel_layout != ch_layout || c->channels != ch_count) {\
77  av_log(s, AV_LOG_ERROR, "Changing frame properties on the fly is not supported.\n");\
78  return AVERROR(EINVAL);\
79  }
80 
82 {
83  return av_buffersrc_add_frame_flags(ctx, (AVFrame *)frame,
85 }
86 
88 {
89  return av_buffersrc_add_frame_flags(ctx, frame, 0);
90 }
91 
93  AVFrame *frame, int flags);
94 
96 {
97  AVFrame *copy = NULL;
98  int ret = 0;
99 
100  if (frame && frame->channel_layout &&
102  av_log(0, AV_LOG_ERROR, "Layout indicates a different number of channels than actually present\n");
103  return AVERROR(EINVAL);
104  }
105 
106  if (!(flags & AV_BUFFERSRC_FLAG_KEEP_REF) || !frame)
107  return av_buffersrc_add_frame_internal(ctx, frame, flags);
108 
109  if (!(copy = av_frame_alloc()))
110  return AVERROR(ENOMEM);
111  ret = av_frame_ref(copy, frame);
112  if (ret >= 0)
113  ret = av_buffersrc_add_frame_internal(ctx, copy, flags);
114 
115  av_frame_free(&copy);
116  return ret;
117 }
118 
120  AVFrame *frame, int flags)
121 {
122  BufferSourceContext *s = ctx->priv;
123  AVFrame *copy;
124  int ret;
125 
126  s->nb_failed_requests = 0;
127 
128  if (!frame) {
129  s->eof = 1;
130  return 0;
131  } else if (s->eof)
132  return AVERROR(EINVAL);
133 
134  if (!(flags & AV_BUFFERSRC_FLAG_NO_CHECK_FORMAT)) {
135 
136  switch (ctx->outputs[0]->type) {
137  case AVMEDIA_TYPE_VIDEO:
138  CHECK_VIDEO_PARAM_CHANGE(ctx, s, frame->width, frame->height,
139  frame->format);
140  break;
141  case AVMEDIA_TYPE_AUDIO:
142  /* For layouts unknown on input but known on link after negotiation. */
143  if (!frame->channel_layout)
144  frame->channel_layout = s->channel_layout;
145  CHECK_AUDIO_PARAM_CHANGE(ctx, s, frame->sample_rate, frame->channel_layout,
146  av_frame_get_channels(frame), frame->format);
147  break;
148  default:
149  return AVERROR(EINVAL);
150  }
151 
152  }
153 
154  if (!av_fifo_space(s->fifo) &&
155  (ret = av_fifo_realloc2(s->fifo, av_fifo_size(s->fifo) +
156  sizeof(copy))) < 0)
157  return ret;
158 
159  if (!(copy = av_frame_alloc()))
160  return AVERROR(ENOMEM);
161  av_frame_move_ref(copy, frame);
162 
163  if ((ret = av_fifo_generic_write(s->fifo, &copy, sizeof(copy), NULL)) < 0) {
164  av_frame_move_ref(frame, copy);
165  av_frame_free(&copy);
166  return ret;
167  }
168 
169  if ((flags & AV_BUFFERSRC_FLAG_PUSH))
170  if ((ret = ctx->output_pads[0].request_frame(ctx->outputs[0])) < 0)
171  return ret;
172 
173  return 0;
174 }
175 
176 #if FF_API_AVFILTERBUFFER
177 static void compat_free_buffer(void *opaque, uint8_t *data)
178 {
179  AVFilterBufferRef *buf = opaque;
182  )
183 }
184 
185 static void compat_unref_buffer(void *opaque, uint8_t *data)
186 {
187  AVBufferRef *buf = opaque;
189  av_buffer_unref(&buf);
190  )
191 }
192 
193 int av_buffersrc_add_ref(AVFilterContext *ctx, AVFilterBufferRef *buf,
194  int flags)
195 {
196  BufferSourceContext *s = ctx->priv;
197  AVFrame *frame = NULL;
198  AVBufferRef *dummy_buf = NULL;
199  int ret = 0, planes, i;
200 
201  if (!buf) {
202  s->eof = 1;
203  return 0;
204  } else if (s->eof)
205  return AVERROR(EINVAL);
206 
207  frame = av_frame_alloc();
208  if (!frame)
209  return AVERROR(ENOMEM);
210 
211  dummy_buf = av_buffer_create(NULL, 0, compat_free_buffer, buf,
212  (buf->perms & AV_PERM_WRITE) ? 0 : AV_BUFFER_FLAG_READONLY);
213  if (!dummy_buf) {
214  ret = AVERROR(ENOMEM);
215  goto fail;
216  }
217 
219  if ((ret = avfilter_copy_buf_props(frame, buf)) < 0)
220  goto fail;
221  )
222 
223 #define WRAP_PLANE(ref_out, data, data_size) \
224 do { \
225  AVBufferRef *dummy_ref = av_buffer_ref(dummy_buf); \
226  if (!dummy_ref) { \
227  ret = AVERROR(ENOMEM); \
228  goto fail; \
229  } \
230  ref_out = av_buffer_create(data, data_size, compat_unref_buffer, \
231  dummy_ref, (buf->perms & AV_PERM_WRITE) ? 0 : AV_BUFFER_FLAG_READONLY); \
232  if (!ref_out) { \
233  av_frame_unref(frame); \
234  ret = AVERROR(ENOMEM); \
235  goto fail; \
236  } \
237 } while (0)
238 
239  if (ctx->outputs[0]->type == AVMEDIA_TYPE_VIDEO) {
240  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
241 
242  planes = av_pix_fmt_count_planes(frame->format);
243  if (!desc || planes <= 0) {
244  ret = AVERROR(EINVAL);
245  goto fail;
246  }
247 
248  for (i = 0; i < planes; i++) {
249  int v_shift = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;
250  int plane_size = (frame->height >> v_shift) * frame->linesize[i];
251 
252  WRAP_PLANE(frame->buf[i], frame->data[i], plane_size);
253  }
254  } else {
255  int planar = av_sample_fmt_is_planar(frame->format);
256  int channels = av_get_channel_layout_nb_channels(frame->channel_layout);
257 
258  planes = planar ? channels : 1;
259 
260  if (planes > FF_ARRAY_ELEMS(frame->buf)) {
261  frame->nb_extended_buf = planes - FF_ARRAY_ELEMS(frame->buf);
262  frame->extended_buf = av_mallocz(sizeof(*frame->extended_buf) *
263  frame->nb_extended_buf);
264  if (!frame->extended_buf) {
265  ret = AVERROR(ENOMEM);
266  goto fail;
267  }
268  }
269 
270  for (i = 0; i < FFMIN(planes, FF_ARRAY_ELEMS(frame->buf)); i++)
271  WRAP_PLANE(frame->buf[i], frame->extended_data[i], frame->linesize[0]);
272 
273  for (i = 0; i < planes - FF_ARRAY_ELEMS(frame->buf); i++)
274  WRAP_PLANE(frame->extended_buf[i],
275  frame->extended_data[i + FF_ARRAY_ELEMS(frame->buf)],
276  frame->linesize[0]);
277  }
278 
279  ret = av_buffersrc_add_frame_flags(ctx, frame, flags);
280 
281 fail:
282  av_buffer_unref(&dummy_buf);
283  av_frame_free(&frame);
284 
285  return ret;
286 }
287 
288 int av_buffersrc_buffer(AVFilterContext *ctx, AVFilterBufferRef *buf)
289 {
290  return av_buffersrc_add_ref(ctx, buf, 0);
291 }
292 #endif
293 
295 {
296  BufferSourceContext *c = ctx->priv;
297 
298  if (c->pix_fmt == AV_PIX_FMT_NONE || !c->w || !c->h || av_q2d(c->time_base) <= 0) {
299  av_log(ctx, AV_LOG_ERROR, "Invalid parameters provided.\n");
300  return AVERROR(EINVAL);
301  }
302 
303  if (!(c->fifo = av_fifo_alloc(sizeof(AVFrame*))))
304  return AVERROR(ENOMEM);
305 
306  av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d pixfmt:%s tb:%d/%d fr:%d/%d sar:%d/%d sws_param:%s\n",
307  c->w, c->h, av_get_pix_fmt_name(c->pix_fmt),
309  c->pixel_aspect.num, c->pixel_aspect.den, (char *)av_x_if_null(c->sws_param, ""));
310  c->warning_limit = 100;
311  return 0;
312 }
313 
315 {
316  return ((BufferSourceContext *)buffer_src->priv)->nb_failed_requests;
317 }
318 
319 #define OFFSET(x) offsetof(BufferSourceContext, x)
320 #define A AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM
321 #define V AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
322 
323 static const AVOption buffer_options[] = {
324  { "width", NULL, OFFSET(w), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V },
325  { "video_size", NULL, OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, .flags = V },
326  { "height", NULL, OFFSET(h), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V },
327  { "pix_fmt", NULL, OFFSET(pix_fmt), AV_OPT_TYPE_PIXEL_FMT, .flags = V },
328 #if FF_API_OLD_FILTER_OPTS
329  /* those 4 are for compatibility with the old option passing system where each filter
330  * did its own parsing */
331  { "time_base_num", "deprecated, do not use", OFFSET(time_base.num), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V },
332  { "time_base_den", "deprecated, do not use", OFFSET(time_base.den), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V },
333  { "sar_num", "deprecated, do not use", OFFSET(pixel_aspect.num), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V },
334  { "sar_den", "deprecated, do not use", OFFSET(pixel_aspect.den), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V },
335 #endif
336  { "sar", "sample aspect ratio", OFFSET(pixel_aspect), AV_OPT_TYPE_RATIONAL, { .dbl = 1 }, 0, DBL_MAX, V },
337  { "pixel_aspect", "sample aspect ratio", OFFSET(pixel_aspect), AV_OPT_TYPE_RATIONAL, { .dbl = 1 }, 0, DBL_MAX, V },
338  { "time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V },
339  { "frame_rate", NULL, OFFSET(frame_rate), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V },
340  { "sws_param", NULL, OFFSET(sws_param), AV_OPT_TYPE_STRING, .flags = V },
341  { NULL },
342 };
343 
345 
346 static const AVOption abuffer_options[] = {
347  { "time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, INT_MAX, A },
348  { "sample_rate", NULL, OFFSET(sample_rate), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, A },
349  { "sample_fmt", NULL, OFFSET(sample_fmt_str), AV_OPT_TYPE_STRING, .flags = A },
350  { "channel_layout", NULL, OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, .flags = A },
351  { "channels", NULL, OFFSET(channels), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, A },
352  { NULL },
353 };
354 
355 AVFILTER_DEFINE_CLASS(abuffer);
356 
358 {
359  BufferSourceContext *s = ctx->priv;
360  int ret = 0;
361 
363  if (s->sample_fmt == AV_SAMPLE_FMT_NONE) {
364  av_log(ctx, AV_LOG_ERROR, "Invalid sample format %s\n",
365  s->sample_fmt_str);
366  return AVERROR(EINVAL);
367  }
368 
369  if (s->channel_layout_str) {
370  int n;
371  /* TODO reindent */
373  if (!s->channel_layout) {
374  av_log(ctx, AV_LOG_ERROR, "Invalid channel layout %s.\n",
375  s->channel_layout_str);
376  return AVERROR(EINVAL);
377  }
379  if (s->channels) {
380  if (n != s->channels) {
381  av_log(ctx, AV_LOG_ERROR,
382  "Mismatching channel count %d and layout '%s' "
383  "(%d channels)\n",
384  s->channels, s->channel_layout_str, n);
385  return AVERROR(EINVAL);
386  }
387  }
388  s->channels = n;
389  } else if (!s->channels) {
390  av_log(ctx, AV_LOG_ERROR, "Neither number of channels nor "
391  "channel layout specified\n");
392  return AVERROR(EINVAL);
393  }
394 
395  if (!(s->fifo = av_fifo_alloc(sizeof(AVFrame*))))
396  return AVERROR(ENOMEM);
397 
398  if (!s->time_base.num)
399  s->time_base = (AVRational){1, s->sample_rate};
400 
401  av_log(ctx, AV_LOG_VERBOSE,
402  "tb:%d/%d samplefmt:%s samplerate:%d chlayout:%s\n",
405  s->warning_limit = 100;
406 
407  return ret;
408 }
409 
410 static av_cold void uninit(AVFilterContext *ctx)
411 {
412  BufferSourceContext *s = ctx->priv;
413  while (s->fifo && av_fifo_size(s->fifo)) {
414  AVFrame *frame;
415  av_fifo_generic_read(s->fifo, &frame, sizeof(frame), NULL);
416  av_frame_free(&frame);
417  }
418  av_fifo_free(s->fifo);
419  s->fifo = NULL;
420 }
421 
423 {
424  BufferSourceContext *c = ctx->priv;
425  AVFilterChannelLayouts *channel_layouts = NULL;
427  AVFilterFormats *samplerates = NULL;
428 
429  switch (ctx->outputs[0]->type) {
430  case AVMEDIA_TYPE_VIDEO:
431  ff_add_format(&formats, c->pix_fmt);
432  ff_set_common_formats(ctx, formats);
433  break;
434  case AVMEDIA_TYPE_AUDIO:
435  ff_add_format(&formats, c->sample_fmt);
436  ff_set_common_formats(ctx, formats);
437 
438  ff_add_format(&samplerates, c->sample_rate);
439  ff_set_common_samplerates(ctx, samplerates);
440 
441  ff_add_channel_layout(&channel_layouts,
444  ff_set_common_channel_layouts(ctx, channel_layouts);
445  break;
446  default:
447  return AVERROR(EINVAL);
448  }
449 
450  return 0;
451 }
452 
454 {
455  BufferSourceContext *c = link->src->priv;
456 
457  switch (link->type) {
458  case AVMEDIA_TYPE_VIDEO:
459  link->w = c->w;
460  link->h = c->h;
462  break;
463  case AVMEDIA_TYPE_AUDIO:
464  if (!c->channel_layout)
465  c->channel_layout = link->channel_layout;
466  break;
467  default:
468  return AVERROR(EINVAL);
469  }
470 
471  link->time_base = c->time_base;
472  link->frame_rate = c->frame_rate;
473  return 0;
474 }
475 
477 {
478  BufferSourceContext *c = link->src->priv;
479  AVFrame *frame;
480 
481  if (!av_fifo_size(c->fifo)) {
482  if (c->eof)
483  return AVERROR_EOF;
484  c->nb_failed_requests++;
485  return AVERROR(EAGAIN);
486  }
487  av_fifo_generic_read(c->fifo, &frame, sizeof(frame), NULL);
488 
489  return ff_filter_frame(link, frame);
490 }
491 
493 {
494  BufferSourceContext *c = link->src->priv;
495  int size = av_fifo_size(c->fifo);
496  if (!size && c->eof)
497  return AVERROR_EOF;
498  return size/sizeof(AVFrame*);
499 }
500 
502  {
503  .name = "default",
504  .type = AVMEDIA_TYPE_VIDEO,
505  .request_frame = request_frame,
506  .poll_frame = poll_frame,
507  .config_props = config_props,
508  },
509  { NULL }
510 };
511 
513  .name = "buffer",
514  .description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them accessible to the filterchain."),
515  .priv_size = sizeof(BufferSourceContext),
517 
518  .init = init_video,
519  .uninit = uninit,
520 
521  .inputs = NULL,
522  .outputs = avfilter_vsrc_buffer_outputs,
523  .priv_class = &buffer_class,
524 };
525 
527  {
528  .name = "default",
529  .type = AVMEDIA_TYPE_AUDIO,
530  .request_frame = request_frame,
531  .poll_frame = poll_frame,
532  .config_props = config_props,
533  },
534  { NULL }
535 };
536 
538  .name = "abuffer",
539  .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them accessible to the filterchain."),
540  .priv_size = sizeof(BufferSourceContext),
542 
543  .init = init_audio,
544  .uninit = uninit,
545 
546  .inputs = NULL,
547  .outputs = avfilter_asrc_abuffer_outputs,
548  .priv_class = &abuffer_class,
549 };
#define WRAP_PLANE(ref_out, data, data_size)
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
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1778
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
Immediately push the frame to the output.
Definition: buffersrc.h:48
AVOption.
Definition: opt.h:251
AVRational pixel_aspect
Definition: buffersrc.c:55
Do not check for format changes.
Definition: buffersrc.h:36
misc image utilities
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:117
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1818
#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
external API header
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:343
Memory buffer source API.
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
int nb_extended_buf
Number of elements in extended_buf.
Definition: frame.h:361
int num
numerator
Definition: rational.h:44
static av_cold int init_video(AVFilterContext *ctx)
Definition: buffersrc.c:294
static const AVFilterPad avfilter_vsrc_buffer_outputs[]
Definition: buffersrc.c:501
#define FF_ARRAY_ELEMS(a)
enum AVPixelFormat pix_fmt
Definition: buffersrc.c:53
static const AVRational pixel_aspect[17]
Definition: h264_ps.c:42
static av_cold void uninit(AVFilterContext *ctx)
Definition: buffersrc.c:410
unsigned av_buffersrc_get_nb_failed_requests(AVFilterContext *buffer_src)
Get the number of failed requests.
Definition: buffersrc.c:314
void avfilter_unref_buffer(AVFilterBufferRef *ref)
output residual component w
#define OFFSET(x)
Definition: buffersrc.c:319
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
const char * name
Pad name.
static const AVOption abuffer_options[]
Definition: buffersrc.c:346
unsigned warning_limit
Definition: buffersrc.c:49
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:538
uint8_t
it can be given away to ff_start_frame *A reference passed to ff_filter_frame(or the deprecated ff_start_frame) is given away and must no longer be used.*A reference created with avfilter_ref_buffer belongs to the code that created it.*A reference obtained with ff_get_video_buffer or ff_get_audio_buffer belongs to the code that requested it.*A reference given as return value by the get_video_buffer or get_audio_buffer method is given away and must no longer be used.Link reference fields---------------------The AVFilterLink structure has a few AVFilterBufferRef fields.The cur_buf and out_buf were used with the deprecated start_frame/draw_slice/end_frame API and should no longer be used.src_buf
#define av_cold
Definition: attributes.h:78
AVOptions.
libavcodec/libavfilter gluing utilities
static int poll_frame(AVFilterLink *link)
Definition: buffersrc.c:492
struct AVBufferRef AVBufferRef
A reference to a data buffer.
AVFilter avfilter_asrc_abuffer
Definition: buffersrc.c:537
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everythnig contained in src to dst and reset src.
Definition: frame.c:352
#define AVERROR_EOF
End of file.
Definition: error.h:55
void av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
enum AVPixelFormat pix_fmt
Definition: v4l.c:63
static const AVFilterPad avfilter_asrc_abuffer_outputs[]
Definition: buffersrc.c:526
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
Definition: buffer.h:113
static void copy(LZOContext *c, int cnt)
Copies bytes from input to output buffer with checking.
Definition: lzo.c:79
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
#define CHECK_AUDIO_PARAM_CHANGE(s, c, srate, ch_layout, ch_count, format)
Definition: buffersrc.c:74
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
int width
width and height of the video frame
Definition: frame.h:122
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:75
int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
Definition: formats.c:350
static int av_buffersrc_add_frame_internal(AVFilterContext *ctx, AVFrame *frame, int flags)
Definition: buffersrc.c:119
static int request_frame(AVFilterLink *link)
Definition: buffersrc.c:476
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Spectrum Plot time data
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_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
#define A
Definition: buffersrc.c:320
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
AVRational time_base
time_base to set in the output link
Definition: buffersrc.c:46
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
AVRational frame_rate
frame_rate to set in the output link
Definition: buffersrc.c:47
int size
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
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:331
int av_buffersrc_write_frame(AVFilterContext *ctx, const AVFrame *frame)
Add a frame to the buffer source.
Definition: buffersrc.c:81
#define AV_LOG_VERBOSE
Definition: log.h:157
struct AVRational AVRational
rational number numerator/denominator
AVFILTER_DEFINE_CLASS(buffer)
audio channel layout utility functions
int av_frame_get_channels(const AVFrame *frame)
#define FFMIN(a, b)
Definition: common.h:58
AVBufferRef ** extended_buf
For planar audio which requires more than AV_NUM_DATA_POINTERS AVBufferRef pointers, this array will hold all the references which cannot fit into AVFrame.buf.
Definition: frame.h:357
Keep a reference to the frame.
Definition: buffersrc.h:55
ret
Definition: avfilter.c:821
this is essentially always true and is there for self documentation * AV_PERM_WRITE
static av_cold int init_audio(AVFilterContext *ctx)
Definition: buffersrc.c:357
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:134
#define attribute_align_arg
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...
sample_rate
static const AVOption buffer_options[]
Definition: buffersrc.c:323
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:101
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
Resize an AVFifoBuffer.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:55
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
a very simple circular buffer FIFO implementation
void * buf
Definition: avisynth_c.h:594
#define V
Definition: buffersrc.c:321
Describe the class of an AVClass context structure.
Definition: log.h:50
int sample_rate
Sample rate of the audio data.
Definition: frame.h:326
Filter definition.
Definition: avfilter.h:436
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:118
synthesis window for stochastic i
rational number numerator/denominator
Definition: rational.h:43
static int config_props(AVFilterLink *link)
Definition: buffersrc.c:453
char * sample_fmt_str
Definition: buffersrc.c:61
const char * name
filter name
Definition: avfilter.h:437
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:330
offset must point to two consecutive integers
Definition: opt.h:230
AVFifoBuffer * fifo
Definition: buffersrc.c:45
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
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:539
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:95
int av_buffersrc_add_frame(AVFilterContext *ctx, AVFrame *frame)
Add a frame to the buffer source.
Definition: buffersrc.c:87
int av_buffersrc_add_ref(AVFilterContext *buffer_src, AVFilterBufferRef *picref, int flags)
Add buffer data in picref to buffer_src.
uint64_t channel_layout
Definition: buffersrc.c:63
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
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:87
int av_buffersrc_add_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
Add a frame to the buffer source.
Definition: buffersrc.c:95
AVFilter avfilter_vsrc_buffer
Definition: buffersrc.c:512
void ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:533
A reference to a data buffer.
Definition: buffer.h:81
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
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
static double c[64]
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
the buffer and buffer reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFilterBuffer structures They must not be accessed but through references stored in AVFilterBufferRef structures Several references can point to the same buffer
int den
denominator
Definition: rational.h:45
unsigned nb_failed_requests
Definition: buffersrc.c:48
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
enum AVSampleFormat sample_fmt
Definition: buffersrc.c:60
static int query_formats(AVFilterContext *ctx)
Definition: buffersrc.c:422
uint64_t av_get_channel_layout(const char *name)
Return a channel layout id that matches name, or 0 if no match is found.
A list of supported formats for one end of a filter link.
Definition: formats.h:64
int(* request_frame)(AVFilterLink *link)
Frame request callback.
An instance of a filter.
Definition: avfilter.h:524
int height
Definition: frame.h:122
#define FF_COUNT2LAYOUT(c)
Encode a channel count as a channel layout.
Definition: formats.h:102
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
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:1700
internal API functions
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:117
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
enum AVSampleFormat av_get_sample_fmt(const char *name)
Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE on error.
Definition: samplefmt.c:54
#define CHECK_VIDEO_PARAM_CHANGE(s, c, width, height, format)
Definition: buffersrc.c:69
static void compat_free_buffer(void *opaque, uint8_t *data)
char * channel_layout_str
Definition: buffersrc.c:64