buffersrc.c File Reference

memory buffer source filter More...

#include <float.h>
#include "libavutil/channel_layout.h"
#include "libavutil/common.h"
#include "libavutil/fifo.h"
#include "libavutil/frame.h"
#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#include "libavutil/samplefmt.h"
#include "audio.h"
#include "avfilter.h"
#include "buffersrc.h"
#include "formats.h"
#include "internal.h"
#include "video.h"
#include "avcodec.h"
Include dependency graph for buffersrc.c:

Go to the source code of this file.

Data Structures

struct  BufferSourceContext
 

Macros

#define CHECK_VIDEO_PARAM_CHANGE(s, c, width, height, format)
 
#define CHECK_AUDIO_PARAM_CHANGE(s, c, srate, ch_layout, ch_count, format)
 
#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

int av_buffersrc_write_frame (AVFilterContext *ctx, const AVFrame *frame)
 Add a frame to the buffer source. More...
 
int av_buffersrc_add_frame (AVFilterContext *ctx, AVFrame *frame)
 Add a frame to the buffer source. More...
 
static int av_buffersrc_add_frame_internal (AVFilterContext *ctx, AVFrame *frame, int flags)
 
int av_buffersrc_add_frame_flags (AVFilterContext *ctx, AVFrame *frame, int flags)
 Add a frame to the buffer source. 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 request_frame (AVFilterLink *link)
 
static int poll_frame (AVFilterLink *link)
 

Variables

static const AVOption buffer_options []
 
static const AVOption abuffer_options []
 
static const AVFilterPad avfilter_vsrc_buffer_outputs []
 
AVFilter avfilter_vsrc_buffer
 
static const AVFilterPad avfilter_asrc_abuffer_outputs []
 
AVFilter avfilter_asrc_abuffer
 

Detailed Description

memory buffer source filter

Definition in file buffersrc.c.

Macro Definition Documentation

Definition at line 320 of file buffersrc.c.

#define CHECK_AUDIO_PARAM_CHANGE (   s,
  c,
  srate,
  ch_layout,
  ch_count,
  format 
)
Value:
if (c->sample_fmt != format || c->sample_rate != srate ||\
c->channel_layout != ch_layout || c->channels != ch_count) {\
av_log(s, AV_LOG_ERROR, "Changing frame properties on the fly is not supported.\n");\
return AVERROR(EINVAL);\
}
const char * s
Definition: avisynth_c.h:668
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL),};static void cpy1(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, len);}static void cpy2(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 2 *len);}static void cpy4(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 4 *len);}static void cpy8(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;}}if(HAVE_YASM &&HAVE_MMX) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);return ctx;}void swri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len){int ch;int off=0;const int os=(out->planar?1:out->ch_count)*out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){int planes=in->planar?in->ch_count:1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){int planes=out->planar?out-> ch_count
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
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 format(the sample packing is implied by the sample format) and sample rate.The lists are not just lists
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
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
static double c[64]
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 74 of file buffersrc.c.

Referenced by av_buffersrc_add_frame_internal().

#define CHECK_VIDEO_PARAM_CHANGE (   s,
  c,
  width,
  height,
  format 
)
Value:
if (c->w != width || c->h != height || c->pix_fmt != format) {\
av_log(s, AV_LOG_INFO, "Changing frame properties on the fly is not supported by all filters.\n");\
}
const char * s
Definition: avisynth_c.h:668
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
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 format(the sample packing is implied by the sample format) and sample rate.The lists are not just lists
static int width
Definition: tests/utils.c:158
BYTE int const BYTE int int int height
Definition: avisynth_c.h:713
static double c[64]
#define AV_LOG_INFO
Definition: log.h:156

Definition at line 69 of file buffersrc.c.

Referenced by av_buffersrc_add_frame_internal().

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

Definition at line 319 of file buffersrc.c.

Definition at line 321 of file buffersrc.c.

Function Documentation

int av_buffersrc_add_frame ( AVFilterContext ctx,
AVFrame frame 
)

Add a frame to the buffer source.

Parameters
san instance of the buffersrc filter.
frameframe to be added. If the frame is reference counted, this function will take ownership of the reference(s) and reset the frame. Otherwise the frame data will be copied. If this function returns an error, the input frame is not touched.
Returns
0 on success, a negative AVERROR on error.
Note
the difference between this function and av_buffersrc_write_frame() is that av_buffersrc_write_frame() creates a new reference to the input frame, while this function takes ownership of the reference passed to it.

This function is equivalent to av_buffersrc_add_frame_flags() without the AV_BUFFERSRC_FLAG_KEEP_REF flag.

Definition at line 87 of file buffersrc.c.

Referenced by audio_decode_frame(), decode_audio(), decode_video(), and video_thread().

int av_buffersrc_add_frame_flags ( AVFilterContext buffer_src,
AVFrame frame,
int  flags 
)

Add a frame to the buffer source.

By default, if the frame is reference-counted, this function will take ownership of the reference(s) and reset the frame. This can be controled using the flags.

If this function returns an error, the input frame is not touched.

Parameters
buffer_srcpointer to a buffer source context
framea frame, or NULL to mark EOF
flagsa combination of AV_BUFFERSRC_FLAG_*
Returns
>= 0 in case of success, a negative AVERROR code in case of failure

Definition at line 95 of file buffersrc.c.

Referenced by av_buffersrc_add_frame(), av_buffersrc_add_frame_internal(), av_buffersrc_write_frame(), decode_audio(), decode_video(), main(), and sub2video_push_ref().

static int attribute_align_arg av_buffersrc_add_frame_internal ( AVFilterContext ctx,
AVFrame frame,
int  flags 
)
static

Definition at line 119 of file buffersrc.c.

Referenced by av_buffersrc_add_frame(), and av_buffersrc_add_frame_flags().

unsigned av_buffersrc_get_nb_failed_requests ( AVFilterContext buffer_src)

Get the number of failed requests.

A failed request is when the request_frame method is called while no frame is present in the buffer. The number is reset when a frame is added.

Definition at line 314 of file buffersrc.c.

Referenced by sub2video_heartbeat(), and transcode_from_filter().

int av_buffersrc_write_frame ( AVFilterContext s,
const AVFrame frame 
)

Add a frame to the buffer source.

Parameters
san instance of the buffersrc filter.
frameframe to be added. If the frame is reference counted, this function will make a new reference to it. Otherwise the frame data will be copied.
Returns
0 on success, a negative AVERROR on error

This function is equivalent to av_buffersrc_add_frame_flags() with the AV_BUFFERSRC_FLAG_KEEP_REF flag.

Definition at line 81 of file buffersrc.c.

AVFILTER_DEFINE_CLASS ( buffer  )
AVFILTER_DEFINE_CLASS ( abuffer  )
static int config_props ( AVFilterLink link)
static

Definition at line 453 of file buffersrc.c.

static av_cold int init_audio ( AVFilterContext ctx)
static

Definition at line 357 of file buffersrc.c.

static av_cold int init_video ( AVFilterContext ctx)
static

Definition at line 294 of file buffersrc.c.

static int poll_frame ( AVFilterLink link)
static

Definition at line 492 of file buffersrc.c.

static int query_formats ( AVFilterContext ctx)
static

Definition at line 422 of file buffersrc.c.

static int request_frame ( AVFilterLink link)
static

Definition at line 476 of file buffersrc.c.

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 410 of file buffersrc.c.

Variable Documentation

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_str), AV_OPT_TYPE_STRING, .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 },
}
#define OFFSET(x)
Definition: buffersrc.c:319
#define A
Definition: buffersrc.c:320
NULL
Definition: eval.c:55
sample_rate

Definition at line 346 of file buffersrc.c.

AVFilter avfilter_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,
}
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:117
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static av_cold void uninit(AVFilterContext *ctx)
Definition: buffersrc.c:410
static const AVFilterPad avfilter_asrc_abuffer_outputs[]
Definition: buffersrc.c:526
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_cold int init_audio(AVFilterContext *ctx)
Definition: buffersrc.c:357
NULL
Definition: eval.c:55
static int query_formats(AVFilterContext *ctx)
Definition: buffersrc.c:422
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 537 of file buffersrc.c.

const AVFilterPad avfilter_asrc_abuffer_outputs[]
static
Initial value:
= {
{
.name = "default",
.request_frame = request_frame,
.poll_frame = poll_frame,
.config_props = config_props,
},
{ NULL }
}
static int poll_frame(AVFilterLink *link)
Definition: buffersrc.c:492
static int request_frame(AVFilterLink *link)
Definition: buffersrc.c:476
NULL
Definition: eval.c:55
static int config_props(AVFilterLink *link)
Definition: buffersrc.c:453

Definition at line 526 of file buffersrc.c.

AVFilter avfilter_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,
}
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:117
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static av_cold int init_video(AVFilterContext *ctx)
Definition: buffersrc.c:294
static const AVFilterPad avfilter_vsrc_buffer_outputs[]
Definition: buffersrc.c:501
static av_cold void uninit(AVFilterContext *ctx)
Definition: buffersrc.c:410
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
NULL
Definition: eval.c:55
static int query_formats(AVFilterContext *ctx)
Definition: buffersrc.c:422
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 512 of file buffersrc.c.

const AVFilterPad avfilter_vsrc_buffer_outputs[]
static
Initial value:
= {
{
.name = "default",
.request_frame = request_frame,
.poll_frame = poll_frame,
.config_props = config_props,
},
{ NULL }
}
static int poll_frame(AVFilterLink *link)
Definition: buffersrc.c:492
static int request_frame(AVFilterLink *link)
Definition: buffersrc.c:476
NULL
Definition: eval.c:55
static int config_props(AVFilterLink *link)
Definition: buffersrc.c:453

Definition at line 501 of file buffersrc.c.

const AVOption buffer_options[]
static
Initial value:
= {
{ "width", NULL, OFFSET(w), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V },
{ "video_size", NULL, OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, .flags = V },
{ "height", NULL, OFFSET(h), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V },
{ "pix_fmt", NULL, OFFSET(pix_fmt), AV_OPT_TYPE_PIXEL_FMT, .flags = V },
{ "sar", "sample aspect ratio", OFFSET(pixel_aspect), AV_OPT_TYPE_RATIONAL, { .dbl = 1 }, 0, DBL_MAX, V },
{ "pixel_aspect", "sample aspect ratio", OFFSET(pixel_aspect), AV_OPT_TYPE_RATIONAL, { .dbl = 1 }, 0, DBL_MAX, V },
{ "time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V },
{ "frame_rate", NULL, OFFSET(frame_rate), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V },
{ "sws_param", NULL, OFFSET(sws_param), AV_OPT_TYPE_STRING, .flags = V },
{ NULL },
}
static const AVRational pixel_aspect[17]
Definition: h264_ps.c:42
output residual component w
#define OFFSET(x)
Definition: buffersrc.c:319
enum AVPixelFormat pix_fmt
Definition: v4l.c:63
NULL
Definition: eval.c:55
#define V
Definition: buffersrc.c:321
offset must point to two consecutive integers
Definition: opt.h:230

Definition at line 323 of file buffersrc.c.