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"
34 #include "libavutil/opt.h"
35 #include "libavutil/samplefmt.h"
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");\
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);\
102 av_log(0,
AV_LOG_ERROR,
"Layout indicates a different number of channels than actually present\n");
176 #if FF_API_AVFILTERBUFFER
178 static void compat_free_buffer(
void *opaque,
uint8_t *
data)
180 AVFilterBufferRef *
buf = opaque;
182 avfilter_unref_buffer(buf);
186 static void compat_unref_buffer(
void *opaque,
uint8_t *data)
200 int ret = 0, planes, i;
220 if ((ret = avfilter_copy_buf_props(frame, buf)) < 0)
224 #define WRAP_PLANE(ref_out, data, data_size) \
244 if (!desc || planes <= 0) {
249 for (i = 0; i < planes; i++) {
253 WRAP_PLANE(frame->
buf[i], frame->
data[i], plane_size);
259 planes = planar ? channels : 1;
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
330 #if FF_API_OLD_FILTER_OPTS
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 },
384 "Mismatching channel count %d and layout '%s' "
393 "channel layout specified\n");
404 "tb:%d/%d samplefmt:%s samplerate:%d chlayout:%s\n",
459 switch (link->
type) {
516 .description =
NULL_IF_CONFIG_SMALL(
"Buffer video frames, and make them accessible to the filterchain."),
524 .
outputs = avfilter_vsrc_buffer_outputs,
525 .priv_class = &buffer_class,
541 .description =
NULL_IF_CONFIG_SMALL(
"Buffer audio frames, and make them accessible to the filterchain."),
549 .
outputs = avfilter_asrc_abuffer_outputs,
550 .priv_class = &abuffer_class,
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
This structure describes decoded (raw) audio or video data.
unsigned av_buffersrc_get_nb_failed_requests(AVFilterContext *buffer_src)
Get the number of failed requests.
const char * name
Filter name.
void * priv
private data for use by the filter
static const AVFilterPad outputs[]
static av_cold int init(AVCodecContext *avctx)
int h
agreed upon image height
int av_buffersrc_add_frame(AVFilterContext *ctx, AVFrame *frame)
Add a frame to the buffer source.
int nb_extended_buf
Number of elements in extended_buf.
uint8_t ** extended_data
pointers to the data planes/channels.
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.
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)
static const AVFilterPad avfilter_vsrc_buffer_outputs[]
static enum AVSampleFormat formats[]
enum AVPixelFormat pix_fmt
static const AVRational pixel_aspect[17]
static av_cold void uninit(AVFilterContext *ctx)
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
enum AVSampleFormat av_get_sample_fmt(const char *name)
Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE on error.
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 ...
const char * name
Pad name.
static const AVOption abuffer_options[]
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int(* request_frame)(AVFilterLink *link)
Frame request callback.
libavcodec/libavfilter gluing utilities
static int poll_frame(AVFilterLink *link)
int av_frame_ref(AVFrame *dst, AVFrame *src)
Setup a new reference to the data described by a given frame.
AVFilter avfilter_asrc_abuffer
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.
Immediately push the frame to the output.
static double av_q2d(AVRational a)
Convert rational to double.
#define AV_LOG_VERBOSE
Detailed information.
enum AVPixelFormat pix_fmt
static const AVFilterPad avfilter_asrc_abuffer_outputs[]
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
static void copy(LZOContext *c, int cnt)
Copies bytes from input to output buffer with checking.
void av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
#define CHECK_AUDIO_PARAM_CHANGE(s, c, srate, ch_layout, ch_count, format)
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.
A link between two filters.
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown; if left to 0/0, will be automatically be cop...
#define AV_NOWARN_DEPRECATED(code)
Disable warnings about deprecated features This is useful for sections of code kept for backward comp...
static int request_frame(AVFilterLink *link)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
AVFilterContext * src
source filter
int av_frame_get_channels(const AVFrame *frame)
AVRational time_base
time_base to set in the output link
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVRational frame_rate
frame_rate to set in the output link
AVPixelFormat
Pixel format.
Do not check for format changes.
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.
uint64_t channel_layout
Channel layout of the audio data.
int w
agreed upon image width
common internal API header
#define FF_ARRAY_ELEMS(a)
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size)
Resize an AVFifoBuffer.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
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.
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.
static av_cold int init_audio(AVFilterContext *ctx)
A list of supported channel layouts.
Main libavfilter public API header.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVFilterLink ** outputs
array of pointers to output links
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
#define attribute_align_arg
AVSampleFormat
Audio Sample Formats.
static const AVOption buffer_options[]
Keep a reference to the frame.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everythnig contained in src to dst and reset src.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Describe the class of an AVClass context structure.
int sample_rate
Sample rate of the audio data.
static const AVFilterPad inputs[]
rational number numerator/denominator
static int config_props(AVFilterLink *link)
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
static int av_buffersrc_add_frame_internal(AVFilterContext *ctx, AVFrame *frame, int flags)
offset must point to two consecutive integers
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.
enum AVMediaType type
filter media type
AVFilter avfilter_vsrc_buffer
A reference to a data buffer.
#define FF_DISABLE_DEPRECATION_WARNINGS
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
unsigned nb_failed_requests
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define FF_ENABLE_DEPRECATION_WARNINGS
#define AVFILTER_DEFINE_CLASS(fname)
AVFilterPad * output_pads
array of output pads
enum AVSampleFormat sample_fmt
static int query_formats(AVFilterContext *ctx)
uint64_t av_get_channel_layout(const char *name)
Return a channel layout id that matches name, or 0 if no match is found.
Memory buffer source API.
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...
int av_buffersrc_add_frame_flags(AVFilterContext *buffer_src, AVFrame *frame, int flags)
Add a frame to the buffer source.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define CHECK_VIDEO_PARAM_CHANGE(s, c, width, height, format)
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 ...
char * channel_layout_str