buffersink.c File Reference

buffer sink More...

#include "libavutil/audio_fifo.h"
#include "libavutil/avassert.h"
#include "libavutil/channel_layout.h"
#include "libavutil/common.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "audio.h"
#include "avfilter.h"
#include "buffersink.h"
#include "internal.h"
Include dependency graph for buffersink.c:

Go to the source code of this file.

Data Structures

struct  BufferSinkContext
 

Macros

#define NB_ITEMS(list)   (list ## _size / sizeof(*list))
 
#define FIFO_INIT_SIZE   8
 
#define CHECK_LIST_SIZE(field)
 
#define OFFSET(x)   offsetof(BufferSinkContext, x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 

Functions

static av_cold void uninit (AVFilterContext *ctx)
 
static int add_buffer_ref (AVFilterContext *ctx, AVFrame *ref)
 
static int filter_frame (AVFilterLink *link, AVFrame *frame)
 
int av_buffersink_get_frame (AVFilterContext *ctx, AVFrame *frame)
 Get a frame with filtered data from sink and put it in frame. More...
 
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. More...
 
static int read_from_fifo (AVFilterContext *ctx, AVFrame *frame, int nb_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. More...
 
AVBufferSinkParamsav_buffersink_params_alloc (void)
 Create an AVBufferSinkParams structure. More...
 
AVABufferSinkParamsav_abuffersink_params_alloc (void)
 Create an AVABufferSinkParams structure. More...
 
static av_cold int common_init (AVFilterContext *ctx)
 
void av_buffersink_set_frame_size (AVFilterContext *ctx, unsigned frame_size)
 Set the frame size for an audio buffer sink. More...
 
AVRational av_buffersink_get_frame_rate (AVFilterContext *ctx)
 Get the frame rate of the input. More...
 
int attribute_align_arg av_buffersink_poll_frame (AVFilterContext *ctx)
 
static av_cold int vsink_init (AVFilterContext *ctx, void *opaque)
 
static int vsink_query_formats (AVFilterContext *ctx)
 
static av_cold int asink_init (AVFilterContext *ctx, void *opaque)
 
static int asink_query_formats (AVFilterContext *ctx)
 
 AVFILTER_DEFINE_CLASS (buffersink)
 
 AVFILTER_DEFINE_CLASS (abuffersink)
 

Variables

static const AVOption buffersink_options []
 
static const AVOption abuffersink_options []
 
static const AVFilterPad avfilter_vsink_buffer_inputs []
 
AVFilter avfilter_vsink_buffer
 
static const AVFilterPad avfilter_asink_abuffer_inputs []
 
AVFilter avfilter_asink_abuffer
 

Detailed Description

buffer sink

Definition in file buffersink.c.

Macro Definition Documentation

#define CHECK_LIST_SIZE (   field)
Value:
if (buf->field ## _size % sizeof(*buf->field)) { \
av_log(ctx, AV_LOG_ERROR, "Invalid size for " #field ": %d, " \
"should be multiple of %d\n", \
buf->field ## _size, (int)sizeof(*buf->field)); \
return AVERROR(EINVAL); \
}
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
void * buf
Definition: avisynth_c.h:594
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
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 This method is called when a frame is wanted on an output For an 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 it should return

Definition at line 387 of file buffersink.c.

Referenced by asink_query_formats(), and vsink_query_formats().

#define FIFO_INIT_SIZE   8

Definition at line 243 of file buffersink.c.

Referenced by common_init().

Definition at line 487 of file buffersink.c.

Definition at line 487 of file buffersink.c.

#define NB_ITEMS (   list)    (list ## _size / sizeof(*list))

Definition at line 63 of file buffersink.c.

Referenced by asink_query_formats(), and vsink_query_formats().

#define OFFSET (   x)    offsetof(BufferSinkContext, x)

Definition at line 480 of file buffersink.c.

Function Documentation

static int add_buffer_ref ( AVFilterContext ctx,
AVFrame ref 
)
static

Definition at line 83 of file buffersink.c.

Referenced by filter_frame().

static av_cold int asink_init ( AVFilterContext ctx,
void opaque 
)
static

Definition at line 414 of file buffersink.c.

static int asink_query_formats ( AVFilterContext ctx)
static

Definition at line 431 of file buffersink.c.

AVABufferSinkParams* av_abuffersink_params_alloc ( void  )

Create an AVABufferSinkParams structure.

Must be freed with av_free().

Definition at line 234 of file buffersink.c.

int av_buffersink_get_frame ( AVFilterContext ctx,
AVFrame frame 
)

Get a frame with filtered data from sink and put it in frame.

Parameters
ctxpointer to a context of a buffersink or abuffersink AVFilter.
framepointer to an allocated frame that will be filled with data. The data must be freed using av_frame_unref() / av_frame_free()
Returns
>= 0 in case of success, a negative AVERROR code in case of failure.

Definition at line 121 of file buffersink.c.

Referenced by main().

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.

Parameters
ctxpointer to a buffersink or abuffersink filter context.
framepointer to an allocated frame that will be filled with data. The data must be freed using av_frame_unref() / av_frame_free()
flagsa combination of AV_BUFFERSINK_FLAG_* flags
Returns
>= 0 in for success, a negative AVERROR code for failure.

Definition at line 126 of file buffersink.c.

Referenced by audio_decode_frame(), av_buffersink_get_frame(), av_buffersink_get_samples(), av_buffersink_set_frame_size(), lavfi_read_packet(), reap_filters(), and video_thread().

AVRational av_buffersink_get_frame_rate ( AVFilterContext ctx)

Get the frame rate of the input.

Definition at line 352 of file buffersink.c.

Referenced by transcode_init().

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.

This function is less efficient than av_buffersink_get_frame(), because it copies the data around.

Parameters
ctxpointer to a context of the abuffersink AVFilter.
framepointer to an allocated frame that will be filled with data. The data must be freed using av_frame_unref() / av_frame_free() frame will contain exactly nb_samples audio samples, except at the end of stream, when it can contain less than nb_samples.
Warning
do not mix this function with av_buffersink_get_frame(). Use only one or the other with a single sink, not both.

Definition at line 179 of file buffersink.c.

Referenced by av_buffersink_set_frame_size().

AVBufferSinkParams* av_buffersink_params_alloc ( void  )

Create an AVBufferSinkParams structure.

Must be freed with av_free().

Definition at line 223 of file buffersink.c.

Referenced by init_filters().

int attribute_align_arg av_buffersink_poll_frame ( AVFilterContext ctx)

Definition at line 360 of file buffersink.c.

void av_buffersink_set_frame_size ( AVFilterContext ctx,
unsigned  frame_size 
)

Set the frame size for an audio buffer sink.

All calls to av_buffersink_get_buffer_ref will return a buffer with exactly the specified number of samples, or AVERROR(EAGAIN) if there is not enough. The last buffer at EOF will be padded with 0.

Definition at line 258 of file buffersink.c.

Referenced by decode_audio(), and transcode_init().

AVFILTER_DEFINE_CLASS ( buffersink  )
AVFILTER_DEFINE_CLASS ( abuffersink  )
static av_cold int common_init ( AVFilterContext ctx)
static

Definition at line 245 of file buffersink.c.

Referenced by asink_init(), and vsink_init().

static int filter_frame ( AVFilterLink link,
AVFrame frame 
)
static

Definition at line 102 of file buffersink.c.

static int read_from_fifo ( AVFilterContext ctx,
AVFrame frame,
int  nb_samples 
)
static

Definition at line 157 of file buffersink.c.

Referenced by av_buffersink_get_samples().

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 65 of file buffersink.c.

static av_cold int vsink_init ( AVFilterContext ctx,
void opaque 
)
static

Definition at line 373 of file buffersink.c.

static int vsink_query_formats ( AVFilterContext ctx)
static

Definition at line 394 of file buffersink.c.

Variable Documentation

const AVOption abuffersink_options[]
static
Initial value:
= {
{ "sample_fmts", "set the supported sample formats", OFFSET(sample_fmts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
{ "sample_rates", "set the supported sample rates", OFFSET(sample_rates), AV_OPT_TYPE_BINARY, .flags = FLAGS },
{ "channel_layouts", "set the supported channel layouts", OFFSET(channel_layouts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
{ "channel_counts", "set the supported channel counts", OFFSET(channel_counts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
{ "all_channel_counts", "accept all channel counts", OFFSET(all_channel_counts), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS },
{ NULL },
}
#define FLAGS
Definition: buffersink.c:487
offset must point to a pointer immediately followed by an int for the length
Definition: opt.h:228
NULL
Definition: eval.c:55
#define OFFSET(x)
Definition: buffersink.c:480
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:700

Definition at line 488 of file buffersink.c.

AVFilter avfilter_asink_abuffer
Initial value:
= {
.name = "abuffersink",
.description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."),
.priv_class = &abuffersink_class,
.priv_size = sizeof(BufferSinkContext),
.init_opaque = asink_init,
}
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:117
static av_cold void uninit(AVFilterContext *ctx)
Definition: buffersink.c:65
static int query_formats(AVFilterContext *ctx)
Definition: af_aconvert.c:73
static av_cold int asink_init(AVFilterContext *ctx, void *opaque)
Definition: buffersink.c:414
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static const AVFilterPad avfilter_asink_abuffer_inputs[]
Definition: buffersink.c:574
NULL
Definition: eval.c:55
static int asink_query_formats(AVFilterContext *ctx)
Definition: buffersink.c:431
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

Definition at line 583 of file buffersink.c.

const AVFilterPad avfilter_asink_abuffer_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
},
{ NULL }
}
NULL
Definition: eval.c:55
static int filter_frame(AVFilterLink *link, AVFrame *frame)
Definition: buffersink.c:102

Definition at line 574 of file buffersink.c.

AVFilter avfilter_vsink_buffer
Initial value:
= {
.name = "buffersink",
.description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."),
.priv_size = sizeof(BufferSinkContext),
.priv_class = &buffersink_class,
.init_opaque = vsink_init,
}
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:117
static av_cold void uninit(AVFilterContext *ctx)
Definition: buffersink.c:65
static int query_formats(AVFilterContext *ctx)
Definition: af_aconvert.c:73
static av_cold int vsink_init(AVFilterContext *ctx, void *opaque)
Definition: buffersink.c:373
static int vsink_query_formats(AVFilterContext *ctx)
Definition: buffersink.c:394
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
NULL
Definition: eval.c:55
static const AVFilterPad avfilter_vsink_buffer_inputs[]
Definition: buffersink.c:552
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

Definition at line 561 of file buffersink.c.

const AVFilterPad avfilter_vsink_buffer_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
},
{ NULL }
}
NULL
Definition: eval.c:55
static int filter_frame(AVFilterLink *link, AVFrame *frame)
Definition: buffersink.c:102

Definition at line 552 of file buffersink.c.

const AVOption buffersink_options[]
static
Initial value:
= {
{ "pix_fmts", "set the supported pixel formats", OFFSET(pixel_fmts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
{ NULL },
}
#define FLAGS
Definition: buffersink.c:487
offset must point to a pointer immediately followed by an int for the length
Definition: opt.h:228
NULL
Definition: eval.c:55
#define OFFSET(x)
Definition: buffersink.c:480

Definition at line 482 of file buffersink.c.