55 for (; (*graph)->filter_count > 0; (*graph)->filter_count--)
76 const char *
name,
const char *args,
void *opaque,
115 "Input pad \"%s\" for the filter \"%s\" of type \"%s\" not connected to any source\n",
124 "Output pad \"%s\" for the filter \"%s\" of type \"%s\" not connected to any destination\n",
170 int scaler_count = 0, resampler_count = 0;
184 for (j = 0; j < filter->
nb_inputs; j++) {
186 int convert_needed = 0;
206 if (convert_needed) {
210 char scale_args[256];
214 switch (link->
type) {
218 "not present, cannot convert pixel formats.\n");
222 snprintf(inst_name,
sizeof(inst_name),
"auto-inserted scaler %d",
224 av_strlcpy(scale_args,
"0:0",
sizeof(scale_args));
226 av_strlcat(scale_args,
":",
sizeof(scale_args));
230 inst_name, scale_args,
NULL,
237 "not present, cannot convert audio formats.\n");
241 snprintf(inst_name,
sizeof(inst_name),
"auto-inserted resampler %d",
255 inlink = convert->
inputs[0];
275 "Impossible to convert between the formats supported by the filter "
297 " the link between filters %s and %s.\n", link->
src->
name,
306 "the link between filters %s and %s.\n", link->
src->
name,
324 #define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format) \
326 for (i = 0; i < filter->nb_inputs; i++) { \
327 AVFilterLink *link = filter->inputs[i]; \
330 if (!link->out_ ## list || link->out_ ## list->nb != 1) \
332 fmt = link->out_ ## list->var[0]; \
334 for (j = 0; j < filter->nb_outputs; j++) { \
335 AVFilterLink *out_link = filter->outputs[j]; \
338 if (link->type != out_link->type || \
339 out_link->in_ ## list->nb == 1) \
341 fmts = out_link->in_ ## list; \
343 if (!out_link->in_ ## list->nb) { \
344 add_format(&out_link->in_ ##list, fmt); \
348 for (k = 0; k < out_link->in_ ## list->nb; k++) \
349 if (fmts->var[k] == fmt) { \
350 fmts->var[0] = fmt; \
361 int i, j, k, ret = 0;
391 for (i = 0; i < filter->
nb_inputs; i++) {
405 int best_idx, best_diff = INT_MAX;
414 if (diff < best_diff) {
432 #define CH_CENTER_PAIR (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER)
433 #define CH_FRONT_PAIR (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT)
434 #define CH_STEREO_PAIR (AV_CH_STEREO_LEFT | AV_CH_STEREO_RIGHT)
435 #define CH_WIDE_PAIR (AV_CH_WIDE_LEFT | AV_CH_WIDE_RIGHT)
436 #define CH_SIDE_PAIR (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)
437 #define CH_DIRECT_PAIR (AV_CH_SURROUND_DIRECT_LEFT | AV_CH_SURROUND_DIRECT_RIGHT)
438 #define CH_BACK_PAIR (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)
471 for (i = 0; i < filter->
nb_inputs; i++) {
483 int best_idx = -1, best_score = INT_MIN, best_count_diff = INT_MAX;
494 int count_diff = out_channels - in_channels;
495 int matched_channels, extra_channels;
502 if (( in_chlayout & cmp0) && (!(out_chlayout & cmp0)) &&
503 (out_chlayout & cmp1) && (!( in_chlayout & cmp1))) {
504 in_chlayout &= ~cmp0;
505 out_chlayout &= ~cmp1;
514 (out_chlayout & AV_CH_LOW_FREQUENCY))
516 in_chlayout &= ~AV_CH_LOW_FREQUENCY;
517 out_chlayout &= ~AV_CH_LOW_FREQUENCY;
523 score += 10 * matched_channels - 5 * extra_channels;
525 if (score > best_score ||
526 (count_diff < best_count_diff && score == best_score)) {
529 best_count_diff = count_diff;
553 for (i = 0; i < filter->
nb_inputs; i++) {
568 int best_idx = -1, best_score = INT_MIN;
586 if (bps == 4 && out_bps == 8) {
592 score = -abs(out_bps - bps);
596 if (score > best_score) {
683 snprintf(name,
sizeof(name),
"auto-inserted fifo %d", fifo_count++);
AVFilterContext ** filters
static void swap_samplerates(AVFilterGraph *graph)
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
static void swap_sample_fmts(AVFilterGraph *graph)
void avfilter_free(AVFilterContext *filter)
Free a filter context.
static const uint64_t ch_subst[][2]
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.
static int reduce_formats_on_filter(AVFilterContext *filter)
static enum AVSampleFormat formats[]
int(* query_formats)(AVFilterContext *)
Queries formats supported by the filter and its pads, and sets the in_formats for links connected to ...
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
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const char * name
Pad name.
#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.
AVFilterPad * output_pads
array of output pads
#define FFSWAP(type, a, b)
AVFilterContext * avfilter_graph_get_filter(AVFilterGraph *graph, char *name)
Get a filter instance with name name from graph.
int avfilter_config_links(AVFilterContext *filter)
Negotiate the media format, dimensions, etc of all inputs to a filter.
#define AV_CH_LOW_FREQUENCY
static int pick_formats(AVFilterGraph *graph)
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
int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque)
Initialize a filter.
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
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)
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
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
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
static void swap_sample_fmts_on_filter(AVFilterContext *filter)
int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name)
Create a filter instance.
enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt)
Get the packed alternative form of the given sample format.
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 av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
AVFilterFormats * in_samplerates
Lists of channel layouts and sample rates used for automatic negotiation.
int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt, const char *name, const char *args, void *opaque, AVFilterGraph *graph_ctx)
Create and add a filter instance into an existing graph.
Describe the class of an AVClass context structure.
#define FF_ARRAY_ELEMS(a)
const char * name
filter name
AVFilterLink ** outputs
array of pointers to output links
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes...
static void swap_channel_layouts_on_filter(AVFilterContext *filter)
enum AVMediaType type
filter media type
#define AV_CH_BACK_CENTER
static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
static int graph_config_links(AVFilterGraph *graph, AVClass *log_ctx)
Configure all the links of graphctx.
static void swap_channel_layouts(AVFilterGraph *graph)
common internal and external API header
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)
AVFilterContext * dst
dest filter
AVFilter * filter
the AVFilter of which this is an instance
static const AVClass filtergraph_class
int needs_fifo
The filter expects a fifo to be inserted on its input link, typically because it has a delay...
int avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter)
Add an existing filter instance to a filter graph.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
AVFilterFormats * out_formats