41 #define OFFSET(x) offsetof(AVFilterGraph, x)
42 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
47 {
"threads",
"Maximum number of threads",
OFFSET(nb_threads),
49 {
"scale_sws_opts" ,
"default scale filter options" ,
OFFSET(scale_sws_opts) ,
51 {
"aresample_swr_opts" ,
"default aresample filter options" ,
OFFSET(aresample_swr_opts) ,
99 if (graph->
filters[i] == filter) {
113 while ((*graph)->nb_filters)
120 av_freep(&(*graph)->scale_sws_opts);
121 av_freep(&(*graph)->aresample_swr_opts);
122 av_freep(&(*graph)->resample_lavr_opts);
128 #if FF_API_AVFILTER_OPEN
141 graph->filter_count_unused = graph->
nb_filters;
145 filter->
graph = graph;
152 const char *
name,
const char *
args,
void *opaque,
212 graph->filter_count_unused = graph->
nb_filters;
242 "Input pad \"%s\" with type %s of the filter instance \"%s\" of %s not connected to any source\n",
252 "Output pad \"%s\" with type %s of the filter instance \"%s\" of %s not connected to any destination\n",
408 if (is_sample_rate) {
440 int scaler_count = 0, resampler_count = 0;
441 int count_queried = 0;
442 int count_merged = 0;
443 int count_already_merged = 0;
444 int count_delayed = 0;
454 if (ret < 0 && ret !=
AVERROR(EAGAIN))
457 count_queried += ret >= 0;
464 for (j = 0; j < filter->
nb_inputs; j++) {
466 int convert_needed = 0;
485 #define MERGE_DISPATCH(field, statement) \
486 if (!(link->in_ ## field && link->out_ ## field)) { \
488 } else if (link->in_ ## field == link->out_ ## field) { \
489 count_already_merged++; \
490 } else if (!convert_needed) { \
512 #undef MERGE_DISPATCH
514 if (convert_needed) {
518 char scale_args[256];
522 switch (link->
type) {
526 "not present, cannot convert pixel formats.\n");
530 snprintf(inst_name,
sizeof(inst_name),
"auto-inserted scaler %d",
541 "not present, cannot convert audio formats.\n");
545 snprintf(inst_name,
sizeof(inst_name),
"auto-inserted resampler %d",
547 scale_args[0] =
'\0';
549 snprintf(scale_args,
sizeof(scale_args),
"%s",
564 inlink = convert->
inputs[0];
584 "Impossible to convert between the formats supported by the filter "
593 "%d queried, %d merged, %d already done, %d delayed\n",
594 count_queried, count_merged, count_already_merged, count_delayed);
603 if (count_queried || count_merged)
611 "The following filters could not choose their formats: %s\n"
612 "Consider inserting the (a)format filter near their input or "
613 "output.\n", bp.str);
646 " the link between filters %s and %s.\n", link->
src->
name,
655 " the link between filters %s and %s.\n", link->
src->
name,
659 "supported, try specifying a channel layout using "
660 "'aformat=channel_layouts=something'.\n");
681 #define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format) \
683 for (i = 0; i < filter->nb_inputs; i++) { \
684 AVFilterLink *link = filter->inputs[i]; \
687 if (!link->out_ ## list || link->out_ ## list->nb != 1) \
689 fmt = link->out_ ## list->var[0]; \
691 for (j = 0; j < filter->nb_outputs; j++) { \
692 AVFilterLink *out_link = filter->outputs[j]; \
695 if (link->type != out_link->type || \
696 out_link->in_ ## list->nb == 1) \
698 fmts = out_link->in_ ## list; \
700 if (!out_link->in_ ## list->nb) { \
701 add_format(&out_link->in_ ##list, fmt); \
706 for (k = 0; k < out_link->in_ ## list->nb; k++) \
707 if (fmts->var[k] == fmt) { \
708 fmts->var[0] = fmt; \
719 int i, j, k,
ret = 0;
727 for (i = 0; i < filter->
nb_inputs; i++) {
784 for (i = 0; i < filter->
nb_inputs; i++) {
798 int best_idx, best_diff = INT_MAX;
807 if (diff < best_diff) {
825 #define CH_CENTER_PAIR (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER)
826 #define CH_FRONT_PAIR (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT)
827 #define CH_STEREO_PAIR (AV_CH_STEREO_LEFT | AV_CH_STEREO_RIGHT)
828 #define CH_WIDE_PAIR (AV_CH_WIDE_LEFT | AV_CH_WIDE_RIGHT)
829 #define CH_SIDE_PAIR (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)
830 #define CH_DIRECT_PAIR (AV_CH_SURROUND_DIRECT_LEFT | AV_CH_SURROUND_DIRECT_RIGHT)
831 #define CH_BACK_PAIR (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)
864 for (i = 0; i < filter->
nb_inputs; i++) {
876 int best_idx = -1, best_score = INT_MIN, best_count_diff = INT_MAX;
887 int count_diff = out_channels - in_channels;
888 int matched_channels, extra_channels;
900 score -= 10000 +
FFABS(out_channels - in_channels) +
901 (in_channels > out_channels ? 10000 : 0);
902 in_chlayout = out_chlayout = 0;
909 uint64_t cmp0 = ch_subst[k][0];
910 uint64_t cmp1 = ch_subst[k][1];
911 if (( in_chlayout & cmp0) && (!(out_chlayout & cmp0)) &&
912 (out_chlayout & cmp1) && (!( in_chlayout & cmp1))) {
913 in_chlayout &= ~cmp0;
914 out_chlayout &= ~cmp1;
923 (out_chlayout & AV_CH_LOW_FREQUENCY))
925 in_chlayout &= ~AV_CH_LOW_FREQUENCY;
926 out_chlayout &= ~AV_CH_LOW_FREQUENCY;
932 score += 10 * matched_channels - 5 * extra_channels;
934 if (score > best_score ||
935 (count_diff < best_count_diff && score == best_score)) {
938 best_count_diff = count_diff;
962 for (i = 0; i < filter->
nb_inputs; i++) {
977 int best_idx = -1, best_score = INT_MIN;
995 if (bps == 4 && out_bps == 8) {
1001 score = -abs(out_bps - bps);
1005 if (score > best_score) {
1035 for (j = 0; j < filter->
nb_inputs; j++){
1111 int sink_links_count = 0,
n = 0;
1126 if (f->
nb_inputs > INT_MAX - sink_links_count)
1131 sinks =
av_calloc(sink_links_count,
sizeof(*sinks));
1171 snprintf(name,
sizeof(name),
"auto-inserted fifo %d", fifo_count++);
1223 if (!strcmp(target,
"all") || (filter->
name && !strcmp(target, filter->
name)) || !strcmp(target, filter->
filter->
name)) {
1226 if ((flags & AVFILTER_CMD_FLAG_ONE) || r < 0)
1244 if(filter && (!strcmp(target,
"all") || !strcmp(target, filter->
name) || !strcmp(target, filter->
filter->
name))){
1246 while (*queue && (*queue)->
time <= ts)
1247 queue = &(*queue)->
next;
1252 (*queue)->time = ts;
1253 (*queue)->flags =
flags;
1254 (*queue)->next =
next;
1269 int parent = (index - 1) >> 1;
1270 if (links[parent]->current_pts >= link->
current_pts)
1272 links[
index] = links[parent];
1276 links[
index] = link;
1286 int child = 2 * index + 1;
1298 links[
index] = link;