FFmpeg
Data Structures | Macros | Functions | Variables
buffersrc.c File Reference
#include <float.h>
#include "libavutil/channel_layout.h"
#include "libavutil/common.h"
#include "libavutil/frame.h"
#include "libavutil/hwcontext.h"
#include "libavutil/imgutils.h"
#include "libavutil/internal.h"
#include "libavutil/opt.h"
#include "libavutil/samplefmt.h"
#include "libavutil/timestamp.h"
#include "audio.h"
#include "avfilter.h"
#include "buffersrc.h"
#include "filters.h"
#include "formats.h"
#include "internal.h"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  BufferSourceContext
 

Macros

#define CHECK_VIDEO_PARAM_CHANGE(s, c, width, height, format, csp, range, pts)
 
#define CHECK_AUDIO_PARAM_CHANGE(s, c, srate, layout, format, pts)
 
#define OFFSET(x)   offsetof(BufferSourceContext, x)
 
#define A   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM
 
#define V   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 

Functions

AVBufferSrcParametersav_buffersrc_parameters_alloc (void)
 Allocate a new AVBufferSrcParameters instance. More...
 
int av_buffersrc_parameters_set (AVFilterContext *ctx, AVBufferSrcParameters *param)
 Initialize the buffersrc or abuffersrc filter with the provided parameters. More...
 
int attribute_align_arg av_buffersrc_write_frame (AVFilterContext *ctx, const AVFrame *frame)
 Add a frame to the buffer source. More...
 
int attribute_align_arg av_buffersrc_add_frame (AVFilterContext *ctx, AVFrame *frame)
 Add a frame to the buffer source. More...
 
static int push_frame (AVFilterGraph *graph)
 
int attribute_align_arg av_buffersrc_add_frame_flags (AVFilterContext *ctx, AVFrame *frame, int flags)
 Add a frame to the buffer source. More...
 
int av_buffersrc_close (AVFilterContext *ctx, int64_t pts, unsigned flags)
 Close the buffer source after EOF. More...
 
static av_cold int init_video (AVFilterContext *ctx)
 
unsigned av_buffersrc_get_nb_failed_requests (AVFilterContext *buffer_src)
 Get the number of failed requests. More...
 
 AVFILTER_DEFINE_CLASS (buffer)
 
 AVFILTER_DEFINE_CLASS (abuffer)
 
static av_cold int init_audio (AVFilterContext *ctx)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static int query_formats (AVFilterContext *ctx)
 
static int config_props (AVFilterLink *link)
 
static int activate (AVFilterContext *ctx)
 

Variables

static const AVOption buffer_options []
 
static const AVOption abuffer_options []
 
static const AVFilterPad avfilter_vsrc_buffer_outputs []
 
const AVFilter ff_vsrc_buffer
 
static const AVFilterPad avfilter_asrc_abuffer_outputs []
 
const AVFilter ff_asrc_abuffer
 

Detailed Description

memory buffer source filter

Definition in file buffersrc.c.

Macro Definition Documentation

◆ CHECK_VIDEO_PARAM_CHANGE

#define CHECK_VIDEO_PARAM_CHANGE (   s,
  c,
  width,
  height,
  format,
  csp,
  range,
  pts 
)
Value:
c->link_delta = c->w != width || c->h != height || c->pix_fmt != format ||\
c->color_space != csp || c->color_range != range;\
c->prev_delta = c->prev_w != width || c->prev_h != height || c->prev_pix_fmt != format ||\
c->prev_color_space != csp || c->prev_color_range != range;\
if (c->link_delta) {\
int loglevel = c->prev_delta ? AV_LOG_WARNING : AV_LOG_DEBUG;\
av_log(s, loglevel, "Changing video frame properties on the fly is not supported by all filters.\n");\
av_log(s, loglevel, "filter context - w: %d h: %d fmt: %d csp: %s range: %s, incoming frame - w: %d h: %d fmt: %d csp: %s range: %s pts_time: %s\n",\
c->w, c->h, c->pix_fmt, av_color_space_name(c->color_space), av_color_range_name(c->color_range),\
av_ts2timestr(pts, &s->outputs[0]->time_base));\
}\
if (c->prev_delta) {\
if (!c->link_delta)\
av_log(s, AV_LOG_VERBOSE, "video frame properties congruent with link at pts_time: %s\n", av_ts2timestr(pts, &s->outputs[0]->time_base));\
c->prev_w = width;\
c->prev_h = height;\
c->prev_pix_fmt = format;\
c->prev_color_space = csp;\
c->prev_color_range = range;\
}

Definition at line 72 of file buffersrc.c.

◆ CHECK_AUDIO_PARAM_CHANGE

#define CHECK_AUDIO_PARAM_CHANGE (   s,
  c,
  srate,
  layout,
  format,
  pts 
)
Value:
if (c->sample_fmt != format || c->sample_rate != srate ||\
av_channel_layout_compare(&c->ch_layout, &layout) || c->channels != layout.nb_channels) {\
av_log(s, AV_LOG_INFO, "filter context - fmt: %s r: %d layout: %"PRIX64" ch: %d, incoming frame - fmt: %s r: %d layout: %"PRIX64" ch: %d pts_time: %s\n",\
av_get_sample_fmt_name(c->sample_fmt), c->sample_rate, c->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? c->ch_layout.u.mask : 0, c->channels,\
av_get_sample_fmt_name(format), srate, layout.order == AV_CHANNEL_ORDER_NATIVE ? layout.u.mask : 0, layout.nb_channels, av_ts2timestr(pts, &s->outputs[0]->time_base));\
av_log(s, AV_LOG_ERROR, "Changing audio frame properties on the fly is not supported.\n");\
return AVERROR(EINVAL);\
}

Definition at line 95 of file buffersrc.c.

◆ OFFSET

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

Definition at line 352 of file buffersrc.c.

◆ A

Definition at line 353 of file buffersrc.c.

◆ V

Definition at line 354 of file buffersrc.c.

Function Documentation

◆ push_frame()

static int push_frame ( AVFilterGraph graph)
static

Definition at line 189 of file buffersrc.c.

Referenced by av_buffersrc_add_frame_flags(), and av_buffersrc_close().

◆ init_video()

static av_cold int init_video ( AVFilterContext ctx)
static

Definition at line 321 of file buffersrc.c.

◆ AVFILTER_DEFINE_CLASS() [1/2]

AVFILTER_DEFINE_CLASS ( buffer  )

◆ AVFILTER_DEFINE_CLASS() [2/2]

AVFILTER_DEFINE_CLASS ( abuffer  )

◆ init_audio()

static av_cold int init_audio ( AVFilterContext ctx)
static

Definition at line 405 of file buffersrc.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 473 of file buffersrc.c.

◆ query_formats()

static int query_formats ( AVFilterContext ctx)
static

Definition at line 480 of file buffersrc.c.

◆ config_props()

static int config_props ( AVFilterLink link)
static

Definition at line 540 of file buffersrc.c.

◆ activate()

static int activate ( AVFilterContext ctx)
static

Definition at line 572 of file buffersrc.c.

Variable Documentation

◆ buffer_options

const AVOption buffer_options[]
static

Definition at line 356 of file buffersrc.c.

◆ abuffer_options

const AVOption abuffer_options[]
static
Initial value:
= {
{ "time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, INT_MAX, A },
{ "sample_rate", NULL, OFFSET(sample_rate), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, A },
{ "sample_fmt", NULL, OFFSET(sample_fmt), AV_OPT_TYPE_SAMPLE_FMT, { .i64 = AV_SAMPLE_FMT_NONE }, .min = AV_SAMPLE_FMT_NONE, .max = INT_MAX, .flags = A },
{ "channel_layout", NULL, OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, .flags = A },
{ "channels", NULL, OFFSET(channels), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, A },
{ NULL },
}

Definition at line 394 of file buffersrc.c.

◆ avfilter_vsrc_buffer_outputs

const AVFilterPad avfilter_vsrc_buffer_outputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_props,
},
}

Definition at line 590 of file buffersrc.c.

◆ ff_vsrc_buffer

const AVFilter ff_vsrc_buffer
Initial value:
= {
.name = "buffer",
.description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them accessible to the filterchain."),
.priv_size = sizeof(BufferSourceContext),
.priv_class = &buffer_class,
}

Definition at line 598 of file buffersrc.c.

◆ avfilter_asrc_abuffer_outputs

const AVFilterPad avfilter_asrc_abuffer_outputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_props,
},
}

Definition at line 612 of file buffersrc.c.

◆ ff_asrc_abuffer

const AVFilter ff_asrc_abuffer
Initial value:
= {
.name = "abuffer",
.description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them accessible to the filterchain."),
.priv_size = sizeof(BufferSourceContext),
.priv_class = &abuffer_class,
}

Definition at line 620 of file buffersrc.c.

AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
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
AV_OPT_TYPE_SAMPLE_FMT
@ AV_OPT_TYPE_SAMPLE_FMT
Definition: opt.h:237
A
#define A
Definition: buffersrc.c:353
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:159
OFFSET
#define OFFSET(x)
Definition: buffersrc.c:352
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
AV_OPT_TYPE_RATIONAL
@ AV_OPT_TYPE_RATIONAL
Definition: opt.h:230
sample_rate
sample_rate
Definition: ffmpeg_filter.c:424
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: buffersrc.c:473
av_color_space_name
const char * av_color_space_name(enum AVColorSpace space)
Definition: pixdesc.c:3344
pts
static int64_t pts
Definition: transcode_aac.c:643
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
width
#define width
s
#define s(width, name)
Definition: cbs_vp9.c:198
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
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
BufferSourceContext
Definition: buffersrc.c:45
avfilter_vsrc_buffer_outputs
static const AVFilterPad avfilter_vsrc_buffer_outputs[]
Definition: buffersrc.c:590
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
channels
channels
Definition: aptx.h:31
av_get_sample_fmt_name
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:51
av_color_range_name
const char * av_color_range_name(enum AVColorRange range)
Definition: pixdesc.c:3284
NULL
#define NULL
Definition: coverity.c:32
inputs
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: filter_design.txt:243
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
av_ts2timestr
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:76
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:106
config_props
static int config_props(AVFilterLink *link)
Definition: buffersrc.c:540
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
range
enum AVColorRange range
Definition: mediacodec_wrapper.c:2646
height
#define height
init_audio
static av_cold int init_audio(AVFilterContext *ctx)
Definition: buffersrc.c:405
AV_CHANNEL_ORDER_NATIVE
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
Definition: channel_layout.h:118
av_channel_layout_compare
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
Definition: channel_layout.c:1003
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: buffersrc.c:480
layout
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 layout
Definition: filter_design.txt:18
init_video
static av_cold int init_video(AVFilterContext *ctx)
Definition: buffersrc.c:321
activate
static int activate(AVFilterContext *ctx)
Definition: buffersrc.c:572
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:183
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
avfilter_asrc_abuffer_outputs
static const AVFilterPad avfilter_asrc_abuffer_outputs[]
Definition: buffersrc.c:612