21#ifndef AVFILTER_FILTERS_H
22#define AVFILTER_FILTERS_H
34#define FFERROR_NOT_READY FFERRTAG('N','R','D','Y')
35#define FFERROR_BUFFERSRC_EMPTY FFERRTAG('M','P','T','Y')
59#define AVFILTERPAD_FLAG_NEEDS_WRITABLE (1 << 0)
64#define AVFILTERPAD_FLAG_FREE_NAME (1 << 1)
208#define FF_FILTER_FLAG_HWFRAME_AWARE (1 << 0)
215#define FF_INLINK_IDX(link) ((int)((link)->dstpad - (link)->dst->input_pads))
216#define FF_OUTLINK_IDX(link) ((int)((link)->srcpad - (link)->src->output_pads))
238#define FILTER_QUERY_FUNC(func) \
239 .formats.query_func = func, \
240 .formats_state = FF_FILTER_FORMATS_QUERY_FUNC
241#define FILTER_QUERY_FUNC2(func) \
242 .formats.query_func2 = func, \
243 .formats_state = FF_FILTER_FORMATS_QUERY_FUNC2
244#define FILTER_PIXFMTS_ARRAY(array) \
245 .formats.pixels_list = array, \
246 .formats_state = FF_FILTER_FORMATS_PIXFMT_LIST
247#define FILTER_SAMPLEFMTS_ARRAY(array) \
248 .formats.samples_list = array, \
249 .formats_state = FF_FILTER_FORMATS_SAMPLEFMTS_LIST
250#define FILTER_PIXFMTS(...) \
251 FILTER_PIXFMTS_ARRAY(((const enum AVPixelFormat []) { __VA_ARGS__, AV_PIX_FMT_NONE }))
252#define FILTER_SAMPLEFMTS(...) \
253 FILTER_SAMPLEFMTS_ARRAY(((const enum AVSampleFormat[]) { __VA_ARGS__, AV_SAMPLE_FMT_NONE }))
254#define FILTER_SINGLE_PIXFMT(pix_fmt_) \
255 .formats.pix_fmt = pix_fmt_, \
256 .formats_state = FF_FILTER_FORMATS_SINGLE_PIXFMT
257#define FILTER_SINGLE_SAMPLEFMT(sample_fmt_) \
258 .formats.sample_fmt = sample_fmt_, \
259 .formats_state = FF_FILTER_FORMATS_SINGLE_SAMPLEFMT
261#define FILTER_INOUTPADS(inout, array) \
263 .nb_ ## inout = FF_ARRAY_ELEMS(array)
264#define FILTER_INPUTS(array) FILTER_INOUTPADS(inputs, (array))
265#define FILTER_OUTPUTS(array) FILTER_INOUTPADS(outputs, (array))
470#define AVFILTER_DEFINE_CLASS_EXT(name, desc, options) \
471 static const AVClass name##_class = { \
472 .class_name = desc, \
473 .item_name = av_default_item_name, \
475 .version = LIBAVUTIL_VERSION_INT, \
476 .category = AV_CLASS_CATEGORY_FILTER, \
478#define AVFILTER_DEFINE_CLASS(fname) \
479 AVFILTER_DEFINE_CLASS_EXT(fname, #fname, fname##_options)
481#define D2TS(d) (isnan(d) ? AV_NOPTS_VALUE : (int64_t)(d))
482#define TS2D(ts) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts))
483#define TS2T(ts, tb) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts) * av_q2d(tb))
639#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink) do { \
640 int ret = ff_outlink_get_status(outlink); \
642 ff_inlink_set_status(inlink, ret); \
652#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter) do { \
653 int ret = ff_outlink_get_status(outlink); \
656 for (i = 0; i < filter->nb_inputs; i++) \
657 ff_inlink_set_status(filter->inputs[i], ret); \
666#define FF_FILTER_FORWARD_STATUS(inlink, outlink) do { \
669 if (ff_inlink_acknowledge_status(inlink, &status, &pts)) { \
670 ff_outlink_set_status(outlink, status, pts); \
679#define FF_FILTER_FORWARD_STATUS_ALL(inlink, filter) do { \
682 if (ff_inlink_acknowledge_status(inlink, &status, &pts)) { \
684 for (i = 0; i < filter->nb_outputs; i++) \
685 ff_outlink_set_status(filter->outputs[i], status, pts); \
694#define FF_FILTER_FORWARD_WANTED(outlink, inlink) do { \
695 if (ff_outlink_frame_wanted(outlink)) { \
696 ff_inlink_request_frame(inlink); \
705#define FF_FILTER_FORWARD_WANTED_ANY(filter, inlink) do { \
706 for (unsigned i = 0; i < filter->nb_outputs; i++) { \
707 if (ff_outlink_frame_wanted(filter->outputs[i])) { \
708 ff_inlink_request_frame(inlink); \
736 int default_pool_size);
745 const char *
arg,
char *res,
int res_len,
int flags);
765 return (
int)((
int64_t)total * jobnr / nb_jobs);
835 void *
arg,
int *ret,
int nb_jobs);
Main libavfilter public API header.
#define flags(name, subs,...)
static int get_buffer(AVCodecContext *dec_ctx, AVFrame *frame, int flags)
int avfilter_action_func(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
A function pointer passed to the AVFilterGraph::execute callback to be executed multiple times,...
AVSampleFormat
Audio sample formats.
int(* func)(AVBPrint *dst, const char *in, const char *arg)
int ff_append_outpad(AVFilterContext *f, AVFilterPad *p)
int ff_inoutlink_check_flow(AVFilterLink *inlink, AVFilterLink *outlink)
Check for flow control between input and output.
static int ff_slice_pos(int total, int jobnr, int nb_jobs)
Compute the boundary index for a slice when work of size total is split into nb_jobs slices.
int ff_append_inpad_free_name(AVFilterContext *f, AVFilterPad *p)
int ff_pixfmt_is_in(enum AVPixelFormat fmt, const enum AVPixelFormat *fmts)
Tell if a pixel format is contained in the provided AV_PIX_FMT_NONE-terminated list.
void ff_inlink_set_status(AVFilterLink *link, int status)
Set the status on an input link.
int ff_outlink_get_status(AVFilterLink *link)
Get the status on an output link.
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
int ff_inlink_check_available_frame(AVFilterLink *link)
Test if a frame is available on the link.
int ff_inlink_check_available_samples(AVFilterLink *link, unsigned min)
Test if enough samples are available on the link.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_append_inpad(AVFilterContext *f, AVFilterPad *p)
Append a new input/output pad to the filter's list of such pads.
int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link, int default_pool_size)
Perform any additional setup required for hardware frames.
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
void ff_avfilter_link_set_in_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
size_t ff_inlink_queued_frames(AVFilterLink *link)
Get the number of frames available on the link.
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
int ff_append_outpad_free_name(AVFilterContext *f, AVFilterPad *p)
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
AVFrame * ff_inlink_peek_frame(AVFilterLink *link, size_t idx)
Access a frame in the link fifo without consuming it.
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
int ff_inlink_make_frame_writable(AVFilterLink *link, AVFrame **rframe)
Make sure a frame is writable.
static FilterLink * ff_filter_link(AVFilterLink *link)
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
int ff_filter_get_nb_threads(AVFilterContext *ctx) av_pure
Get number of threads for current filter instance.
@ FF_FILTER_FORMATS_QUERY_FUNC
formats.query active.
@ FF_FILTER_FORMATS_SINGLE_PIXFMT
formats.pix_fmt active
@ FF_FILTER_FORMATS_SAMPLEFMTS_LIST
formats.samples_list active.
@ FF_FILTER_FORMATS_SINGLE_SAMPLEFMT
formats.sample_fmt active.
@ FF_FILTER_FORMATS_PASSTHROUGH
The default value meaning that this filter supports all formats and (for audio) sample rates and chan...
@ FF_FILTER_FORMATS_PIXFMT_LIST
formats.pixels_list active.
@ FF_FILTER_FORMATS_QUERY_FUNC2
formats.query_func2 active.
int ff_inlink_queued_samples(AVFilterLink *link)
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
static const FFFilter * fffilter(const AVFilter *f)
AVPixelFormat
Pixel format.
A reference to a data buffer.
A link between two filters.
A filter pad used for either input or output.
int flags
A combination of AVFILTERPAD_FLAG_* flags.
int(* request_frame)(AVFilterLink *link)
Frame request callback.
int(* config_props)(AVFilterLink *link)
Link configuration callback.
enum AVMediaType type
AVFilterPad type.
int(* filter_frame)(AVFilterLink *link, AVFrame *frame)
Filtering callback.
const char * name
Pad name.
This structure describes decoded (raw) audio or video data.
Rational number (pair of numerator and denominator).
enum AVPixelFormat pix_fmt
Equivalent to { pix_fmt, AV_PIX_FMT_NONE } as pixels_list.
AVFilter p
The public AVFilter.
int(* query_func2)(const AVFilterContext *, struct AVFilterFormatsConfig **cfg_in, struct AVFilterFormatsConfig **cfg_out)
Same as query_func(), except this function writes the results into provided arrays.
int(* query_func)(AVFilterContext *)
Query formats supported by the filter on its inputs and outputs.
int(* init)(AVFilterContext *ctx)
Filter initialization function.
uint8_t nb_inputs
The number of entries in the list of inputs.
uint8_t nb_outputs
The number of entries in the list of outputs.
void(* uninit)(AVFilterContext *ctx)
Filter uninitialization function.
enum AVSampleFormat * samples_list
Analogous to pixels, but delimited by AV_SAMPLE_FMT_NONE and restricted to filters that only have AVM...
int flags_internal
Additional flags for avfilter internal use only.
int(* process_command)(AVFilterContext *, const char *cmd, const char *arg, char *res, int res_len, int flags)
Make the filter instance process a command.
enum AVPixelFormat * pixels_list
A pointer to an array of admissible pixel formats delimited by AV_PIX_FMT_NONE.
int(* preinit)(AVFilterContext *ctx)
Filter pre-initialization function.
int(* activate)(AVFilterContext *ctx)
Filter activation function.
enum AVSampleFormat sample_fmt
Equivalent to { sample_fmt, AV_SAMPLE_FMT_NONE } as samples_list.
uint8_t formats_state
This field determines the state of the formats union.
int priv_size
size of private data to allocate for the filter
Link properties exposed to filter code, but not external callers.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
int64_t sample_count_in
Number of past samples sent through the link.
int min_samples
Minimum number of samples to filter at once.
int max_samples
Maximum number of samples to filter at once.
int64_t current_pts_us
Current timestamp of the link, as defined by the most recent frame(s), in AV_TIME_BASE units.
int64_t current_pts
Current timestamp of the link, as defined by the most recent frame(s), in link time_base units.
int64_t frame_count_in
Number of past frames sent through the link.
struct AVFilterGraph * graph
Graph the filter belongs to.
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
static AVFormatContext * ctx