40 #define OFFSET(x) offsetof(AVFilterGraph, x)
41 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
46 {
"threads",
"Maximum number of threads",
OFFSET(nb_threads),
48 {
"scale_sws_opts" ,
"default scale filter options" ,
OFFSET(scale_sws_opts) ,
50 {
"aresample_swr_opts" ,
"default aresample filter options" ,
OFFSET(aresample_swr_opts) ,
98 if (graph->
filters[i] == filter) {
112 while ((*graph)->nb_filters)
119 av_freep(&(*graph)->scale_sws_opts);
120 av_freep(&(*graph)->aresample_swr_opts);
121 av_freep(&(*graph)->resample_lavr_opts);
127 #if FF_API_AVFILTER_OPEN
140 graph->filter_count_unused = graph->
nb_filters;
144 filter->
graph = graph;
151 const char *
name,
const char *
args,
void *opaque,
211 graph->filter_count_unused = graph->
nb_filters;
241 "Input pad \"%s\" with type %s of the filter instance \"%s\" of %s not connected to any source\n",
251 "Output pad \"%s\" with type %s of the filter instance \"%s\" of %s not connected to any destination\n",
407 if (is_sample_rate) {
439 int scaler_count = 0, resampler_count = 0;
440 int count_queried = 0;
441 int count_merged = 0;
442 int count_already_merged = 0;
443 int count_delayed = 0;
453 if (ret < 0 && ret !=
AVERROR(EAGAIN))
456 count_queried += ret >= 0;
463 for (j = 0; j < filter->
nb_inputs; j++) {
465 int convert_needed = 0;
484 #define MERGE_DISPATCH(field, statement) \
485 if (!(link->in_ ## field && link->out_ ## field)) { \
487 } else if (link->in_ ## field == link->out_ ## field) { \
488 count_already_merged++; \
489 } else if (!convert_needed) { \
511 #undef MERGE_DISPATCH
513 if (convert_needed) {
517 char scale_args[256];
521 switch (link->
type) {
525 "not present, cannot convert pixel formats.\n");
529 snprintf(inst_name,
sizeof(inst_name),
"auto-inserted scaler %d",
540 "not present, cannot convert audio formats.\n");
544 snprintf(inst_name,
sizeof(inst_name),
"auto-inserted resampler %d",
546 scale_args[0] =
'\0';
548 snprintf(scale_args,
sizeof(scale_args),
"%s",
563 inlink = convert->
inputs[0];
583 "Impossible to convert between the formats supported by the filter "
592 "%d queried, %d merged, %d already done, %d delayed\n",
593 count_queried, count_merged, count_already_merged, count_delayed);
602 if (count_queried || count_merged)
610 "The following filters could not choose their formats: %s\n"
611 "Consider inserting the (a)format filter near their input or "
612 "output.\n", bp.str);
645 " the link between filters %s and %s.\n", link->
src->
name,
654 " the link between filters %s and %s.\n", link->
src->
name,
658 "supported, try specifying a channel layout using "
659 "'aformat=channel_layouts=something'.\n");
680 #define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format) \
682 for (i = 0; i < filter->nb_inputs; i++) { \
683 AVFilterLink *link = filter->inputs[i]; \
686 if (!link->out_ ## list || link->out_ ## list->nb != 1) \
688 fmt = link->out_ ## list->var[0]; \
690 for (j = 0; j < filter->nb_outputs; j++) { \
691 AVFilterLink *out_link = filter->outputs[j]; \
694 if (link->type != out_link->type || \
695 out_link->in_ ## list->nb == 1) \
697 fmts = out_link->in_ ## list; \
699 if (!out_link->in_ ## list->nb) { \
700 add_format(&out_link->in_ ##list, fmt); \
705 for (k = 0; k < out_link->in_ ## list->nb; k++) \
706 if (fmts->var[k] == fmt) { \
707 fmts->var[0] = fmt; \
718 int i, j, k,
ret = 0;
726 for (i = 0; i < filter->
nb_inputs; i++) {
783 for (i = 0; i < filter->
nb_inputs; i++) {
797 int best_idx, best_diff = INT_MAX;
806 if (diff < best_diff) {
824 #define CH_CENTER_PAIR (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER)
825 #define CH_FRONT_PAIR (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT)
826 #define CH_STEREO_PAIR (AV_CH_STEREO_LEFT | AV_CH_STEREO_RIGHT)
827 #define CH_WIDE_PAIR (AV_CH_WIDE_LEFT | AV_CH_WIDE_RIGHT)
828 #define CH_SIDE_PAIR (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)
829 #define CH_DIRECT_PAIR (AV_CH_SURROUND_DIRECT_LEFT | AV_CH_SURROUND_DIRECT_RIGHT)
830 #define CH_BACK_PAIR (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)
863 for (i = 0; i < filter->
nb_inputs; i++) {
875 int best_idx = -1, best_score = INT_MIN, best_count_diff = INT_MAX;
886 int count_diff = out_channels - in_channels;
887 int matched_channels, extra_channels;
899 score -= 10000 +
FFABS(out_channels - in_channels) +
900 (in_channels > out_channels ? 10000 : 0);
901 in_chlayout = out_chlayout = 0;
908 uint64_t cmp0 = ch_subst[k][0];
909 uint64_t cmp1 = ch_subst[k][1];
910 if (( in_chlayout & cmp0) && (!(out_chlayout & cmp0)) &&
911 (out_chlayout & cmp1) && (!( in_chlayout & cmp1))) {
912 in_chlayout &= ~cmp0;
913 out_chlayout &= ~cmp1;
922 (out_chlayout & AV_CH_LOW_FREQUENCY))
924 in_chlayout &= ~AV_CH_LOW_FREQUENCY;
925 out_chlayout &= ~AV_CH_LOW_FREQUENCY;
931 score += 10 * matched_channels - 5 * extra_channels;
933 if (score > best_score ||
934 (count_diff < best_count_diff && score == best_score)) {
937 best_count_diff = count_diff;
961 for (i = 0; i < filter->
nb_inputs; i++) {
976 int best_idx = -1, best_score = INT_MIN;
994 if (bps == 4 && out_bps == 8) {
1000 score = -abs(out_bps - bps);
1004 if (score > best_score) {
1034 for (j = 0; j < filter->
nb_inputs; j++){
1110 int sink_links_count = 0,
n = 0;
1125 if (f->
nb_inputs > INT_MAX - sink_links_count)
1130 sinks =
av_calloc(sink_links_count,
sizeof(*sinks));
1170 snprintf(name,
sizeof(name),
"auto-inserted fifo %d", fifo_count++);
1222 if (!strcmp(target,
"all") || (filter->
name && !strcmp(target, filter->
name)) || !strcmp(target, filter->
filter->
name)) {
1225 if ((flags & AVFILTER_CMD_FLAG_ONE) || r < 0)
1243 if(filter && (!strcmp(target,
"all") || !strcmp(target, filter->
name) || !strcmp(target, filter->
filter->
name))){
1245 while (*queue && (*queue)->
time <= ts)
1246 queue = &(*queue)->
next;
1251 (*queue)->time = ts;
1252 (*queue)->flags =
flags;
1253 (*queue)->next =
next;
1268 int parent = (index - 1) >> 1;
1269 if (links[parent]->current_pts >= link->
current_pts)
1271 links[
index] = links[parent];
1275 links[
index] = link;
1285 int child = 2 * index + 1;
1297 links[
index] = link;