History

avfilter: Dont partially merge lists

This prevents the unneeded insertion of multiple aresample filters in some cases The format merging is moved to avoid having to call the channel layout merge twice. The channel layout merge code uses different structures and is not compatible with the added dry run wrappers.

Michael Niedermayer committed 13 years ago

Commit fe328f01 parent 65035501 file · +62 −6Browse files

Unified · Split

libavfilter/avfiltergraph.c+62−6
@@ -360,6 +360,47 @@ static int formats_declared(AVFilterContext *f) · 359 unmodified lines
360360 return 1;
361361 }
362362
363+static AVFilterFormats *clone_filter_formats(AVFilterFormats *arg)
364+{
365+ AVFilterFormats *a = av_memdup(arg, sizeof(*arg));
366+ if (a) {
367+ a->refcount = 0;
368+ a->refs = NULL;
369+ a->formats = av_memdup(a->formats, sizeof(*a->formats) * a->nb_formats);
370+ if (!a->formats && arg->formats)
371+ av_freep(&a);
372+ }
373+ return a;
374+}
375+
376+static int can_merge_formats(AVFilterFormats *a_arg,
377+ AVFilterFormats *b_arg,
378+ enum AVMediaType type,
379+ int is_sample_rate)
380+{
381+ AVFilterFormats *a, *b, *ret;
382+ if (a == b)
383+ return 1;
384+ a = clone_filter_formats(a_arg);
385+ b = clone_filter_formats(b_arg);
386+ if (is_sample_rate) {
387+ ret = ff_merge_samplerates(a, b);
388+ } else {
389+ ret = ff_merge_formats(a, b, type);
390+ }
391+ if (ret) {
392+ av_freep(&ret->formats);
393+ av_freep(&ret);
394+ return 1;
395+ } else {
396+ av_freep(&a->formats);
397+ av_freep(&b->formats);
398+ av_freep(&a);
399+ av_freep(&b);
400+ return 0;
401+ }
402+}
403+
363404 /**
364405 * Perform one round of query_formats() and merging formats lists on the
365406 * filter graph.
@@ -404,20 +445,30 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) · 38 unmodified lines
404445 if (!link)
405446 continue;
406447
448+ if (link->in_formats != link->out_formats
449+ && link->in_formats && link->out_formats)
450+ if (!can_merge_formats(link->in_formats, link->out_formats,
451+ link->type, 0))
452+ convert_needed = 1;
453+ if (link->type == AVMEDIA_TYPE_AUDIO) {
454+ if (link->in_samplerates != link->out_samplerates
455+ && link->in_samplerates && link->out_samplerates)
456+ if (!can_merge_formats(link->in_samplerates,
457+ link->out_samplerates,
458+ 0, 1))
459+ convert_needed = 1;
460+ }
461+
407462 #define MERGE_DISPATCH(field, statement) \
408463 if (!(link->in_ ## field && link->out_ ## field)) { \
409464 count_delayed++; \
410465 } else if (link->in_ ## field == link->out_ ## field) { \
411466 count_already_merged++; \
412− } else { \
467+ } else if (!convert_needed) { \
413468 count_merged++; \
414469 statement \
415470 }
416− MERGE_DISPATCH(formats,
417− if (!ff_merge_formats(link->in_formats, link->out_formats,
418− link->type))
419− convert_needed = 1;
420− )
471+
421472 if (link->type == AVMEDIA_TYPE_AUDIO) {
422473 MERGE_DISPATCH(channel_layouts,
423474 if (!ff_merge_channel_layouts(link->in_channel_layouts,
@@ -430,6 +481,11 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) · 6 unmodified lines
430481 convert_needed = 1;
431482 )
432483 }
484+ MERGE_DISPATCH(formats,
485+ if (!ff_merge_formats(link->in_formats, link->out_formats,
486+ link->type))
487+ convert_needed = 1;
488+ )
433489 #undef MERGE_DISPATCH
434490
435491 if (convert_needed) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t