FFmpeg  2.1.1
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 
28 #include "libavutil/channel_layout.h"
29 #include "libavutil/common.h"
30 #include "libavutil/fifo.h"
31 #include "libavutil/frame.h"
32 #include "libavutil/imgutils.h"
33 #include "libavutil/internal.h"
34 #include "libavutil/opt.h"
35 #include "libavutil/samplefmt.h"
36 #include "audio.h"
37 #include "avfilter.h"
38 #include "buffersrc.h"
39 #include "formats.h"
40 #include "internal.h"
41 #include "video.h"
42 #include "avcodec.h"
43 
44 typedef struct {
45  const AVClass *class;
47  AVRational time_base; ///< time_base to set in the output link
48  AVRational frame_rate; ///< frame_rate to set in the output link
50  unsigned warning_limit;
51 
52  /* video only */
53  int w, h;
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
178 static void compat_free_buffer(void *opaque, uint8_t *data)
179 {
180  AVFilterBufferRef *buf = opaque;
182  avfilter_unref_buffer(buf);
183  )
184 }
185 
186 static void compat_unref_buffer(void *opaque, uint8_t *data)
187 {
188  AVBufferRef *buf = opaque;
190  av_buffer_unref(&buf);
191  )
192 }
193 
194 int av_buffersrc_add_ref(AVFilterContext *ctx, AVFilterBufferRef *buf,
195  int flags)
196 {
197  BufferSourceContext *s = ctx->priv;
198  AVFrame *frame = NULL;
199  AVBufferRef *dummy_buf = NULL;
200  int ret = 0, planes, i;
201 
202  if (!buf) {
203  s->eof = 1;
204  return 0;
205  } else if (s->eof)
206  return AVERROR(EINVAL);
207 
208  frame = av_frame_alloc();
209  if (!frame)
210  return AVERROR(ENOMEM);
211 
212  dummy_buf = av_buffer_create(NULL, 0, compat_free_buffer, buf,
213  (buf->perms & AV_PERM_WRITE) ? 0 : AV_BUFFER_FLAG_READONLY);
214  if (!dummy_buf) {
215  ret = AVERROR(ENOMEM);
216  goto fail;
217  }
218 
220  if ((ret = avfilter_copy_buf_props(frame, buf)) < 0)
221  goto fail;
222  )
223 
224 #define WRAP_PLANE(ref_out, data, data_size) \
225 do { \
226  AVBufferRef *dummy_ref = av_buffer_ref(dummy_buf); \
227  if (!dummy_ref) { \
228  ret = AVERROR(ENOMEM); \
229  goto fail; \
230  } \
231  ref_out = av_buffer_create(data, data_size, compat_unref_buffer, \
232  dummy_ref, (buf->perms & AV_PERM_WRITE) ? 0 : AV_BUFFER_FLAG_READONLY); \
233  if (!ref_out) { \
234  av_frame_unref(frame); \
235  ret = AVERROR(ENOMEM); \
236  goto fail; \
237  } \
238 } while (0)
239 
240  if (ctx->outputs[0]->type == AVMEDIA_TYPE_VIDEO) {
241  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
242 
243  planes = av_pix_fmt_count_planes(frame->format);
244  if (!desc || planes <= 0) {
245  ret = AVERROR(EINVAL);
246  goto fail;
247  }
248 
249  for (i = 0; i < planes; i++) {
250  int v_shift = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;
251  int plane_size = (frame->height >> v_shift) * frame->linesize[i];
252 
253  WRAP_PLANE(frame->buf[i], frame->data[i], plane_size);
254  }
255  } else {
256  int planar = av_sample_fmt_is_planar(frame->format);
257  int channels = av_get_channel_layout_nb_channels(frame->channel_layout);
258 
259  planes = planar ? channels : 1;
260 
261  if (planes > FF_ARRAY_ELEMS(frame->buf)) {
262  frame->nb_extended_buf = planes - FF_ARRAY_ELEMS(frame->buf);
263  frame->extended_buf = av_mallocz(sizeof(*frame->extended_buf) *
264  frame->nb_extended_buf);
265  if (!frame->extended_buf) {
266  ret = AVERROR(ENOMEM);
267  goto fail;
268  }
269  }
270 
271  for (i = 0; i < FFMIN(planes, FF_ARRAY_ELEMS(frame->buf)); i++)
272  WRAP_PLANE(frame->buf[i], frame->extended_data[i], frame->linesize[0]);
273 
274  for (i = 0; i < planes - FF_ARRAY_ELEMS(frame->buf); i++)
275  WRAP_PLANE(frame->extended_buf[i],
276  frame->extended_data[i + FF_ARRAY_ELEMS(frame->buf)],
277  frame->linesize[0]);
278  }
279 
280  ret = av_buffersrc_add_frame_flags(ctx, frame, flags);
281 
282 fail:
283  av_buffer_unref(&dummy_buf);
284  av_frame_free(&frame);
285 
286  return ret;
287 }
289 
290 int av_buffersrc_buffer(AVFilterContext *ctx, AVFilterBufferRef *buf)
291 {
292  return av_buffersrc_add_ref(ctx, buf, 0);
293 }
294 #endif
295 
297 {
298  BufferSourceContext *c = ctx->priv;
299 
300  if (c->pix_fmt == AV_PIX_FMT_NONE || !c->w || !c->h || av_q2d(c->time_base) <= 0) {
301  av_log(ctx, AV_LOG_ERROR, "Invalid parameters provided.\n");
302  return AVERROR(EINVAL);
303  }
304 
305  if (!(c->fifo = av_fifo_alloc(sizeof(AVFrame*))))
306  return AVERROR(ENOMEM);
307 
308  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",
309  c->w, c->h, av_get_pix_fmt_name(c->pix_fmt),
311  c->pixel_aspect.num, c->pixel_aspect.den, (char *)av_x_if_null(c->sws_param, ""));
312  c->warning_limit = 100;
313  return 0;
314 }
315 
317 {
318  return ((BufferSourceContext *)buffer_src->priv)->nb_failed_requests;
319 }
320 
321 #define OFFSET(x) offsetof(BufferSourceContext, x)
322 #define A AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM
323 #define V AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
324 
325 static const AVOption buffer_options[] = {
326  { "width", NULL, OFFSET(w), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V },
327  { "video_size", NULL, OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, .flags = V },
328  { "height", NULL, OFFSET(h), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V },
329  { "pix_fmt", NULL, OFFSET(pix_fmt), AV_OPT_TYPE_PIXEL_FMT, .flags = V },
330 #if FF_API_OLD_FILTER_OPTS
331  /* those 4 are for compatibility with the old option passing system where each filter
332  * did its own parsing */
333  { "time_base_num", "deprecated, do not use", OFFSET(time_base.num), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V },
334  { "time_base_den", "deprecated, do not use", OFFSET(time_base.den), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V },
335  { "sar_num", "deprecated, do not use", OFFSET(pixel_aspect.num), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V },
336  { "sar_den", "deprecated, do not use", OFFSET(pixel_aspect.den), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V },
337 #endif
338  { "sar", "sample aspect ratio", OFFSET(pixel_aspect), AV_OPT_TYPE_RATIONAL, { .dbl = 1 }, 0, DBL_MAX, V },
339  { "pixel_aspect", "sample aspect ratio", OFFSET(pixel_aspect), AV_OPT_TYPE_RATIONAL, { .dbl = 1 }, 0, DBL_MAX, V },
340  { "time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V },
341  { "frame_rate", NULL, OFFSET(frame_rate), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V },
342  { "sws_param", NULL, OFFSET(sws_param), AV_OPT_TYPE_STRING, .flags = V },
343  { NULL },
344 };
345 
347 
348 static const AVOption abuffer_options[] = {
349  { "time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, INT_MAX, A },
350  { "sample_rate", NULL, OFFSET(sample_rate), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, A },
351  { "sample_fmt", NULL, OFFSET(sample_fmt_str), AV_OPT_TYPE_STRING, .flags = A },
352  { "channel_layout", NULL, OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, .flags = A },
353  { "channels", NULL, OFFSET(channels), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, A },
354  { NULL },
355 };
356 
357 AVFILTER_DEFINE_CLASS(abuffer);
358 
360 {
361  BufferSourceContext *s = ctx->priv;
362  int ret = 0;
363 
365  if (s->sample_fmt == AV_SAMPLE_FMT_NONE) {
366  av_log(ctx, AV_LOG_ERROR, "Invalid sample format %s\n",
367  s->sample_fmt_str);
368  return AVERROR(EINVAL);
369  }
370 
371  if (s->channel_layout_str) {
372  int n;
373  /* TODO reindent */
375  if (!s->channel_layout) {
376  av_log(ctx, AV_LOG_ERROR, "Invalid channel layout %s.\n",
377  s->channel_layout_str);
378  return AVERROR(EINVAL);
379  }
381  if (s->channels) {
382  if (n != s->channels) {
383  av_log(ctx, AV_LOG_ERROR,
384  "Mismatching channel count %d and layout '%s' "
385  "(%d channels)\n",
386  s->channels, s->channel_layout_str, n);
387  return AVERROR(EINVAL);
388  }
389  }
390  s->channels = n;
391  } else if (!s->channels) {
392  av_log(ctx, AV_LOG_ERROR, "Neither number of channels nor "
393  "channel layout specified\n");
394  return AVERROR(EINVAL);
395  }
396 
397  if (!(s->fifo = av_fifo_alloc(sizeof(AVFrame*))))
398  return AVERROR(ENOMEM);
399 
400  if (!s->time_base.num)
401  s->time_base = (AVRational){1, s->sample_rate};
402 
403  av_log(ctx, AV_LOG_VERBOSE,
404  "tb:%d/%d samplefmt:%s samplerate:%d chlayout:%s\n",
407  s->warning_limit = 100;
408 
409  return ret;
410 }
411 
412 static av_cold void uninit(AVFilterContext *ctx)
413 {
414  BufferSourceContext *s = ctx->priv;
415  while (s->fifo && av_fifo_size(s->fifo)) {
416  AVFrame *frame;
417  av_fifo_generic_read(s->fifo, &frame, sizeof(frame), NULL);
418  av_frame_free(&frame);
419  }
420  av_fifo_free(s->fifo);
421  s->fifo = NULL;
422 }
423 
425 {
426  BufferSourceContext *c = ctx->priv;
427  AVFilterChannelLayouts *channel_layouts = NULL;
428  AVFilterFormats *formats = NULL;
429  AVFilterFormats *samplerates = NULL;
430 
431  switch (ctx->outputs[0]->type) {
432  case AVMEDIA_TYPE_VIDEO:
433  ff_add_format(&formats, c->pix_fmt);
434  ff_set_common_formats(ctx, formats);
435  break;
436  case AVMEDIA_TYPE_AUDIO:
437  ff_add_format(&formats, c->sample_fmt);
438  ff_set_common_formats(ctx, formats);
439 
440  ff_add_format(&samplerates, c->sample_rate);
441  ff_set_common_samplerates(ctx, samplerates);
442 
443  ff_add_channel_layout(&channel_layouts,
446  ff_set_common_channel_layouts(ctx, channel_layouts);
447  break;
448  default:
449  return AVERROR(EINVAL);
450  }
451 
452  return 0;
453 }
454 
455 static int config_props(AVFilterLink *link)
456 {
457  BufferSourceContext *c = link->src->priv;
458 
459  switch (link->type) {
460  case AVMEDIA_TYPE_VIDEO:
461  link->w = c->w;
462  link->h = c->h;
464  break;
465  case AVMEDIA_TYPE_AUDIO:
466  if (!c->channel_layout)
467  c->channel_layout = link->channel_layout;
468  break;
469  default:
470  return AVERROR(EINVAL);
471  }
472 
473  link->time_base = c->time_base;
474  link->frame_rate = c->frame_rate;
475  return 0;
476 }
477 
478 static int request_frame(AVFilterLink *link)
479 {
480  BufferSourceContext *c = link->src->priv;
481  AVFrame *frame;
482 
483  if (!av_fifo_size(c->fifo)) {
484  if (c->eof)
485  return AVERROR_EOF;
486  c->nb_failed_requests++;
487  return AVERROR(EAGAIN);
488  }
489  av_fifo_generic_read(c->fifo, &frame, sizeof(frame), NULL);
490 
491  return ff_filter_frame(link, frame);
492 }
493 
494 static int poll_frame(AVFilterLink *link)
495 {
496  BufferSourceContext *c = link->src->priv;
497  int size = av_fifo_size(c->fifo);
498  if (!size && c->eof)
499  return AVERROR_EOF;
500  return size/sizeof(AVFrame*);
501 }
502 
504  {
505  .name = "default",
506  .type = AVMEDIA_TYPE_VIDEO,
507  .request_frame = request_frame,
508  .poll_frame = poll_frame,
509  .config_props = config_props,
510  },
511  { NULL }
512 };
513 
515  .name = "buffer",
516  .description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them accessible to the filterchain."),
517  .priv_size = sizeof(BufferSourceContext),
519 
520  .init = init_video,
521  .uninit = uninit,
522 
523  .inputs = NULL,
524  .outputs = avfilter_vsrc_buffer_outputs,
525  .priv_class = &buffer_class,
526 };
527 
529  {
530  .name = "default",
531  .type = AVMEDIA_TYPE_AUDIO,
532  .request_frame = request_frame,
533  .poll_frame = poll_frame,
534  .config_props = config_props,
535  },
536  { NULL }
537 };
538 
540  .name = "abuffer",
541  .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them accessible to the filterchain."),
542  .priv_size = sizeof(BufferSourceContext),
544 
545  .init = init_audio,
546  .uninit = uninit,
547 
548  .inputs = NULL,
549  .outputs = avfilter_asrc_abuffer_outputs,
550  .priv_class = &abuffer_class,
551 };
const char * s
Definition: avisynth_c.h:668
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1979
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
Definition: buffer.c:105
int size
This structure describes decoded (raw) audio or video data.
Definition: frame.h:96
AVOption.
Definition: opt.h:253
AVRational pixel_aspect
Definition: buffersrc.c:55
unsigned av_buffersrc_get_nb_failed_requests(AVFilterContext *buffer_src)
Get the number of failed requests.
Definition: buffersrc.c:316
const char * name
Filter name.
Definition: avfilter.h:468
void * priv
private data for use by the filter
Definition: avfilter.h:648
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:111
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
int av_buffersrc_add_frame(AVFilterContext *ctx, AVFrame *frame)
Add a frame to the buffer source.
Definition: buffersrc.c:87
int nb_extended_buf
Number of elements in extended_buf.
Definition: frame.h:384
int num
numerator
Definition: rational.h:44
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:140
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:1860
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
static av_cold int init_video(AVFilterContext *ctx)
Definition: buffersrc.c:296
static const AVFilterPad avfilter_vsrc_buffer_outputs[]
Definition: buffersrc.c:503
static enum AVSampleFormat formats[]
enum AVPixelFormat pix_fmt
Definition: buffersrc.c:54
static const AVRational pixel_aspect[17]
Definition: h264_ps.c:38
Pixel format.
Definition: avcodec.h:4533
static av_cold void uninit(AVFilterContext *ctx)
Definition: buffersrc.c:412
#define av_cold
Definition: avcodec.h:653
#define OFFSET(x)
Definition: buffersrc.c:321
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
Definition: avfilter.c:965
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
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 ...
Definition: fifo.c:54
const char * name
Pad name.
Definition: internal.h:66
static const AVOption abuffer_options[]
Definition: buffersrc.c:348
unsigned warning_limit
Definition: buffersrc.c:50
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1118
uint8_t
int(* request_frame)(AVFilterLink *link)
Frame request callback.
Definition: internal.h:119
libavcodec/libavfilter gluing utilities
static int poll_frame(AVFilterLink *link)
Definition: buffersrc.c:494
int av_frame_ref(AVFrame *dst, AVFrame *src)
Setup a new reference to the data described by a given frame.
Definition: frame.c:247
AVFilter avfilter_asrc_abuffer
Definition: buffersrc.c:539
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.
Definition: buffer.c:27
Immediately push the frame to the output.
Definition: buffersrc.h:48
const char data[16]
Definition: mxf.c:68
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
#define AV_LOG_VERBOSE
Detailed information.
Definition: avcodec.h:4163
enum AVPixelFormat pix_fmt
Definition: v4l.c:62
static const AVFilterPad avfilter_asrc_abuffer_outputs[]
Definition: buffersrc.c:528
#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 av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
Definition: fifo.c:40
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:531
#define CHECK_AUDIO_PARAM_CHANGE(s, c, srate, ch_layout, ch_count, format)
Definition: buffersrc.c:74
#define A(x)
Definition: vp56_arith.h:28
static AVFrame * frame
Definition: demuxing.c:51
A filter pad used for either input or output.
Definition: internal.h:60
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition: avutil.h:289
int width
width and height of the video frame
Definition: frame.h:145
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: avcodec.h:4147
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:77
int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
Definition: formats.c:336
#define AV_NOWARN_DEPRECATED(code)
Disable warnings about deprecated features This is useful for sections of code kept for backward comp...
Definition: attributes.h:112
static int request_frame(AVFilterLink *link)
Definition: buffersrc.c:478
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:151
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:110
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
int av_frame_get_channels(const AVFrame *frame)
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:330
AVRational time_base
time_base to set in the output link
Definition: buffersrc.c:47
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:123
AVRational frame_rate
frame_rate to set in the output link
Definition: buffersrc.c:48
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
Do not check for format changes.
Definition: buffersrc.h:36
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:99
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:354
goto fail
Definition: avfilter.c:963
common internal API header
#define FF_ARRAY_ELEMS(a)
Definition: avcodec.h:929
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size)
Resize an AVFifoBuffer.
Definition: fifo.c:64
#define V
Definition: options_table.h:35
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:351
ret
Definition: avfilter.c:961
int av_buffersrc_add_ref(AVFilterContext *buffer_src, AVFilterBufferRef *picref, int flags)
Add buffer data in picref to buffer_src.
int av_buffersrc_write_frame(AVFilterContext *s, const AVFrame *frame)
Add a frame to the buffer source.
Definition: buffersrc.c:81
#define FFMIN(a, b)
Definition: avcodec.h:925
static char buffer[20]
Definition: seek-test.c:31
int n
Definition: avisynth_c.h:588
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:380
static av_cold int init_audio(AVFilterContext *ctx)
Definition: buffersrc.c:359
A list of supported channel layouts.
Definition: formats.h:85
Main libavfilter public API header.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1938
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:642
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:157
#define attribute_align_arg
Definition: internal.h:56
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
sample_rate
static const AVOption buffer_options[]
Definition: buffersrc.c:325
Keep a reference to the frame.
Definition: buffersrc.h:55
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:57
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everythnig contained in src to dst and reset src.
Definition: frame.c:373
void * buf
Definition: avisynth_c.h:594
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:366
Describe the class of an AVClass context structure.
Definition: log.h:50
int sample_rate
Sample rate of the audio data.
Definition: frame.h:349
Filter definition.
Definition: avfilter.h:464
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:102
rational number numerator/denominator
Definition: rational.h:43
static int config_props(AVFilterLink *link)
Definition: buffersrc.c:455
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
Definition: fifo.c:27
char * sample_fmt_str
Definition: buffersrc.c:61
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:124
static int av_buffersrc_add_frame_internal(AVFilterContext *ctx, AVFrame *frame, int flags)
Definition: buffersrc.c:119
offset must point to two consecutive integers
Definition: opt.h:230
AVFifoBuffer * fifo
Definition: buffersrc.c:46
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:127
uint64_t channel_layout
Definition: buffersrc.c:63
static int flags
Definition: cpu.c:45
#define AVERROR_EOF
AVFilter avfilter_vsrc_buffer
Definition: buffersrc.c:514
void ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:519
A reference to a data buffer.
Definition: buffer.h:81
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:78
static double c[64]
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:118
int den
denominator
Definition: rational.h:45
unsigned nb_failed_requests
Definition: buffersrc.c:49
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:91
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:79
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:301
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:641
enum AVSampleFormat sample_fmt
Definition: buffersrc.c:60
static int query_formats(AVFilterContext *ctx)
Definition: buffersrc.c:424
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
#define AVERROR(e)
An instance of a filter.
Definition: avfilter.h:627
Memory buffer source API.
int height
Definition: frame.h:145
#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:512
internal API functions
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...
Definition: fifo.c:59
int av_buffersrc_add_frame_flags(AVFilterContext *buffer_src, AVFrame *frame, int flags)
Add a frame to the buffer source.
Definition: buffersrc.c:95
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:107
#define CHECK_VIDEO_PARAM_CHANGE(s, c, width, height, format)
Definition: buffersrc.c:69
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:241
char * channel_layout_str
Definition: buffersrc.c:64