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];
565 av_assert0( inlink-> in_formats->refcount > 0);
567 av_assert0(outlink-> in_formats->refcount > 0);
570 av_assert0( inlink-> in_samplerates->refcount > 0);
572 av_assert0(outlink-> in_samplerates->refcount > 0);
574 av_assert0( inlink-> in_channel_layouts->refcount > 0);
576 av_assert0(outlink-> in_channel_layouts->refcount > 0);
597 "Impossible to convert between the formats supported by the filter "
606 "%d queried, %d merged, %d already done, %d delayed\n",
607 count_queried, count_merged, count_already_merged, count_delayed);
616 if (count_queried || count_merged)
624 "The following filters could not choose their formats: %s\n"
625 "Consider inserting the (a)format filter near their input or "
626 "output.\n", bp.str);
659 " the link between filters %s and %s.\n", link->
src->
name,
668 " the link between filters %s and %s.\n", link->
src->
name,
672 "supported, try specifying a channel layout using "
673 "'aformat=channel_layouts=something'.\n");
694 #define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format) \
696 for (i = 0; i < filter->nb_inputs; i++) { \
697 AVFilterLink *link = filter->inputs[i]; \
700 if (!link->out_ ## list || link->out_ ## list->nb != 1) \
702 fmt = link->out_ ## list->var[0]; \
704 for (j = 0; j < filter->nb_outputs; j++) { \
705 AVFilterLink *out_link = filter->outputs[j]; \
708 if (link->type != out_link->type || \
709 out_link->in_ ## list->nb == 1) \
711 fmts = out_link->in_ ## list; \
713 if (!out_link->in_ ## list->nb) { \
714 add_format(&out_link->in_ ##list, fmt); \
719 for (k = 0; k < out_link->in_ ## list->nb; k++) \
720 if (fmts->var[k] == fmt) { \
721 fmts->var[0] = fmt; \
732 int i, j, k,
ret = 0;
740 for (i = 0; i < filter->
nb_inputs; i++) {
797 for (i = 0; i < filter->
nb_inputs; i++) {
811 int best_idx, best_diff = INT_MAX;
820 if (diff < best_diff) {
838 #define CH_CENTER_PAIR (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER)
839 #define CH_FRONT_PAIR (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT)
840 #define CH_STEREO_PAIR (AV_CH_STEREO_LEFT | AV_CH_STEREO_RIGHT)
841 #define CH_WIDE_PAIR (AV_CH_WIDE_LEFT | AV_CH_WIDE_RIGHT)
842 #define CH_SIDE_PAIR (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)
843 #define CH_DIRECT_PAIR (AV_CH_SURROUND_DIRECT_LEFT | AV_CH_SURROUND_DIRECT_RIGHT)
844 #define CH_BACK_PAIR (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)
877 for (i = 0; i < filter->
nb_inputs; i++) {
889 int best_idx = -1, best_score = INT_MIN, best_count_diff = INT_MAX;
900 int count_diff = out_channels - in_channels;
901 int matched_channels, extra_channels;
913 score -= 10000 +
FFABS(out_channels - in_channels) +
914 (in_channels > out_channels ? 10000 : 0);
915 in_chlayout = out_chlayout = 0;
922 uint64_t cmp0 = ch_subst[k][0];
923 uint64_t cmp1 = ch_subst[k][1];
924 if (( in_chlayout & cmp0) && (!(out_chlayout & cmp0)) &&
925 (out_chlayout & cmp1) && (!( in_chlayout & cmp1))) {
926 in_chlayout &= ~cmp0;
927 out_chlayout &= ~cmp1;
936 (out_chlayout & AV_CH_LOW_FREQUENCY))
938 in_chlayout &= ~AV_CH_LOW_FREQUENCY;
939 out_chlayout &= ~AV_CH_LOW_FREQUENCY;
945 score += 10 * matched_channels - 5 * extra_channels;
947 if (score > best_score ||
948 (count_diff < best_count_diff && score == best_score)) {
951 best_count_diff = count_diff;
975 for (i = 0; i < filter->
nb_inputs; i++) {
990 int best_idx = -1, best_score = INT_MIN;
1008 if (bps == 4 && out_bps == 8) {
1014 score = -abs(out_bps - bps);
1018 if (score > best_score) {
1048 for (j = 0; j < filter->
nb_inputs; j++){
1124 int sink_links_count = 0,
n = 0;
1139 if (f->
nb_inputs > INT_MAX - sink_links_count)
1144 sinks =
av_calloc(sink_links_count,
sizeof(*sinks));
1184 snprintf(name,
sizeof(name),
"auto-inserted fifo %d", fifo_count++);
1236 if (!strcmp(target,
"all") || (filter->
name && !strcmp(target, filter->
name)) || !strcmp(target, filter->
filter->
name)) {
1239 if ((flags & AVFILTER_CMD_FLAG_ONE) || r < 0)
1257 if(filter && (!strcmp(target,
"all") || !strcmp(target, filter->
name) || !strcmp(target, filter->
filter->
name))){
1259 while (*queue && (*queue)->
time <= ts)
1260 queue = &(*queue)->
next;
1265 (*queue)->time = ts;
1266 (*queue)->flags =
flags;
1267 (*queue)->next =
next;
1282 int parent = (index - 1) >> 1;
1283 if (links[parent]->current_pts >= link->
current_pts)
1285 links[
index] = links[parent];
1289 links[
index] = link;
1299 int child = 2 * index + 1;
1311 links[
index] = link;