40 #define OFFSET(x) offsetof(AVFilterGraph, x)
41 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM
46 {
"threads",
"Maximum number of threads",
OFFSET(nb_threads),
93 if (graph->
filters[i] == filter) {
107 while ((*graph)->nb_filters)
112 av_freep(&(*graph)->scale_sws_opts);
113 av_freep(&(*graph)->resample_lavr_opts);
119 #if FF_API_AVFILTER_OPEN
136 filter->
graph = graph;
143 const char *
name,
const char *args,
void *opaque,
226 "Input pad \"%s\" for the filter \"%s\" of type \"%s\" not connected to any source\n",
235 "Output pad \"%s\" for the filter \"%s\" of type \"%s\" not connected to any destination\n",
281 int scaler_count = 0, resampler_count = 0;
295 for (j = 0; j < filter->
nb_inputs; j++) {
297 int convert_needed = 0;
317 if (convert_needed) {
321 char scale_args[256];
325 switch (link->
type) {
329 "not present, cannot convert pixel formats.\n");
333 snprintf(inst_name,
sizeof(inst_name),
"auto-inserted scaler %d",
344 "not present, cannot convert audio formats.\n");
348 snprintf(inst_name,
sizeof(inst_name),
"auto-inserted resampler %d",
350 scale_args[0] =
'\0';
352 snprintf(scale_args,
sizeof(scale_args),
"%s",
355 inst_name, scale_args,
367 inlink = convert->
inputs[0];
387 "Impossible to convert between the formats supported by the filter "
409 " the link between filters %s and %s.\n", link->
src->
name,
418 "the link between filters %s and %s.\n", link->
src->
name,
436 #define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format) \
438 for (i = 0; i < filter->nb_inputs; i++) { \
439 AVFilterLink *link = filter->inputs[i]; \
442 if (!link->out_ ## list || link->out_ ## list->nb != 1) \
444 fmt = link->out_ ## list->var[0]; \
446 for (j = 0; j < filter->nb_outputs; j++) { \
447 AVFilterLink *out_link = filter->outputs[j]; \
450 if (link->type != out_link->type || \
451 out_link->in_ ## list->nb == 1) \
453 fmts = out_link->in_ ## list; \
455 if (!out_link->in_ ## list->nb) { \
456 add_format(&out_link->in_ ##list, fmt); \
460 for (k = 0; k < out_link->in_ ## list->nb; k++) \
461 if (fmts->var[k] == fmt) { \
462 fmts->var[0] = fmt; \
473 int i, j, k, ret = 0;
503 for (i = 0; i < filter->
nb_inputs; i++) {
517 int best_idx, best_diff = INT_MAX;
526 if (diff < best_diff) {
544 #define CH_CENTER_PAIR (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER)
545 #define CH_FRONT_PAIR (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT)
546 #define CH_STEREO_PAIR (AV_CH_STEREO_LEFT | AV_CH_STEREO_RIGHT)
547 #define CH_WIDE_PAIR (AV_CH_WIDE_LEFT | AV_CH_WIDE_RIGHT)
548 #define CH_SIDE_PAIR (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)
549 #define CH_DIRECT_PAIR (AV_CH_SURROUND_DIRECT_LEFT | AV_CH_SURROUND_DIRECT_RIGHT)
550 #define CH_BACK_PAIR (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)
583 for (i = 0; i < filter->
nb_inputs; i++) {
595 int best_idx = -1, best_score = INT_MIN, best_count_diff = INT_MAX;
606 int count_diff = out_channels - in_channels;
607 int matched_channels, extra_channels;
614 if (( in_chlayout & cmp0) && (!(out_chlayout & cmp0)) &&
615 (out_chlayout & cmp1) && (!( in_chlayout & cmp1))) {
616 in_chlayout &= ~cmp0;
617 out_chlayout &= ~cmp1;
626 (out_chlayout & AV_CH_LOW_FREQUENCY))
628 in_chlayout &= ~AV_CH_LOW_FREQUENCY;
629 out_chlayout &= ~AV_CH_LOW_FREQUENCY;
635 score += 10 * matched_channels - 5 * extra_channels;
637 if (score > best_score ||
638 (count_diff < best_count_diff && score == best_score)) {
641 best_count_diff = count_diff;
665 for (i = 0; i < filter->
nb_inputs; i++) {
680 int best_idx = -1, best_score = INT_MIN;
698 if (bps == 4 && out_bps == 8) {
704 score = -abs(out_bps - bps);
708 if (score > best_score) {
788 if (!link->
dstpad->needs_fifo)
795 snprintf(name,
sizeof(name),
"auto-inserted fifo %d", fifo_count++);
AVFilterContext ** filters
AVFilterContext * ff_filter_alloc(const AVFilter *filter, const char *inst_name)
Allocate a new filter context and return it.
int thread_type
Type of multithreading allowed for filters in this graph.
static void swap_samplerates(AVFilterGraph *graph)
static void swap_sample_fmts(AVFilterGraph *graph)
void avfilter_free(AVFilterContext *filter)
Free a filter context.
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
Main libavfilter public API header.
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
static const uint64_t ch_subst[][2]
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
#define FF_ARRAY_ELEMS(a)
static int reduce_formats_on_filter(AVFilterContext *filter)
static enum AVSampleFormat formats[]
AVFilterPad * dstpad
input pad on the dest filter
struct AVFilterChannelLayouts * in_channel_layouts
static int graph_insert_fifos(AVFilterGraph *graph, AVClass *log_ctx)
char * scale_sws_opts
sws options to use for the auto-inserted scale filters
#define AVFILTER_THREAD_SLICE
Process multiple parts of the frame concurrently.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
struct AVFilterGraph * graph
filtergraph this filter belongs to
#define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVFilterLink ** inputs
array of pointers to input links
char * name
name of this filter instance
#define av_assert0(cond)
assert() equivalent, that is always enabled.
avfilter_execute_func * execute
This callback may be set by the caller immediately after allocating the graph and before adding any f...
AVFilterPad * output_pads
array of output pads
#define AV_CH_LOW_FREQUENCY
int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt, const char *name, const char *args, void *opaque, AVFilterGraph *graph_ctx)
Create and add a filter instance into an existing graph.
char * resample_lavr_opts
libavresample options to use for the auto-inserted resample filters
static int pick_formats(AVFilterGraph *graph)
int nb_threads
Maximum number of threads used by filters in this graph.
int avfilter_config_links(AVFilterContext *filter)
Negotiate the media format, dimensions, etc of all inputs to a filter.
enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt)
Get the planar alternative form of the given sample format.
A link between two filters.
AVFilterPad * input_pads
array of input pads
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int sample_rate
samples per second
unsigned nb_outputs
number of output pads
uint64_t * channel_layouts
list of channel layouts
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
simple assert() macros that are a bit more flexible than ISO C assert().
struct AVFilterChannelLayouts * out_channel_layouts
void av_log(void *avcl, int level, const char *fmt,...)
AVFilterFormats * in_formats
Lists of formats supported by the input and output filters respectively.
static int pick_format(AVFilterLink *link)
AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
common internal API header
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
static int graph_config_formats(AVFilterGraph *graph, AVClass *log_ctx)
Configure the formats of all the links in the graph.
audio channel layout utility functions
unsigned nb_inputs
number of input pads
static void swap_sample_fmts_on_filter(AVFilterContext *filter)
static const AVOption filtergraph_options[]
static int graph_check_validity(AVFilterGraph *graph, AVClass *log_ctx)
Check for the validity of graph.
AVFilterContext * src
source filter
#define AV_CH_FRONT_CENTER
AVFilterFormats * out_samplerates
int format
agreed upon media format
int avfilter_init_str(AVFilterContext *filter, const char *args)
Initialize a filter with the supplied parameters.
int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt, unsigned filt_srcpad_idx, unsigned filt_dstpad_idx)
Insert a filter in the middle of an existing link.
void ff_graph_thread_free(AVFilterGraph *graph)
AVFilterFormats * in_samplerates
Lists of channel layouts and sample rates used for automatic negotiation.
AVFilterGraphInternal * internal
Opaque object for libavfilter internal use.
Describe the class of an AVClass context structure.
int(* query_formats)(AVFilterContext *)
Query formats supported by the filter on its inputs and outputs.
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
static void swap_channel_layouts_on_filter(AVFilterContext *filter)
enum AVMediaType type
filter media type
#define AV_CH_BACK_CENTER
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
int ff_graph_thread_init(AVFilterGraph *graph)
static int graph_config_links(AVFilterGraph *graph, AVClass *log_ctx)
Configure all the links of graphctx.
static void swap_channel_layouts(AVFilterGraph *graph)
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal and external API header
enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt)
Get the packed alternative form of the given sample format.
int nb_channel_layouts
number of channel layouts
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
static void reduce_formats(AVFilterGraph *graph)
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
static void swap_samplerates_on_filter(AVFilterContext *filter)
void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter)
Remove a filter from a graph;.
avfilter_execute_func * thread_execute
#define FF_ENABLE_DEPRECATION_WARNINGS
AVFilterContext * avfilter_graph_alloc_filter(AVFilterGraph *graph, const AVFilter *filter, const char *name)
Create a new filter instance in a filter graph.
AVFilterContext * dst
dest filter
static const AVClass filtergraph_class
AVFilterContext * avfilter_graph_get_filter(AVFilterGraph *graph, char *name)
Get a filter instance with name name from graph.
#define FFSWAP(type, a, b)
int avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
const AVFilter * filter
the AVFilter of which this is an instance
AVFilterFormats * out_formats