[FFmpeg-devel] [PATCH 2/3] avfiltergraph: don't query formats if filter has uninitialized inputs

Matthieu Bouron matthieu.bouron at gmail.com
Fri May 4 11:04:09 CEST 2012


On Thu, May 03, 2012 at 04:33:17PM +0200, Nicolas George wrote:
> Le quintidi 15 floréal, an CCXX, Matthieu Bouron a écrit :
> > The complex filter system add vsrc_buffer and asrc_buffer (in next patch) at
> > the end of the avfilter context array and query_formats is currently called
> > sequentially it. It can lead to a filter initialization failure for filters
> > with input dependencies (like amerge)
> > 
> > The following example will fail on the amerge filter since the two abbufer
> > are not initialized:
> >   [ amerge ] [ abuffer ] [ abuffer ] [ abuffersink ]
> 
> Well, I had guessed amerge would be somewhere there.
> 
> The fact is that amerge is doing something bad: it selects its format using
> its input's formats. That has all kinds of bad consequences. The one you
> pointed out, but not only that. For example:
> 
> 	[in (stereo)] -> [ resample ] -> [ amerge ] ->
> 
> will, unless I am mistaken, select mono as input and insert a stereo->mono
> converter between resample and amerge.
> 
> (The exact problem is that amerge will select its input format as the first
> supported by resample, which is mono, and this happens before the
> intersection mechanism has restricted this list to only stereo.)
> 
> This is bad, but this is the best I could think of at the time, and still
> now.
> 
> If you have a better idea...
> 
> > I agree, this implementation is naive.
> > 
> > Another solution whould be to order the avfilter context array when
> > avfilter_link is called.
> 
> It would not work with loops. Loops are still unsupported, but Michael says
> they should be eventually.
> 
> I can suggest the following algorithm:
> 
> while (1) {
>     work_to_do = 0;
>     success = 0;
>     for (each filter f) {
> 	if (!all_inputs_and_outputs_configured(f)) {
> 	    r = f->query_format();
> 	    if (r < 0) {
> 		if (r == AVERROR(EAGAIN))
> 		    work_to_do = 1;
> 		else
> 		    return r;
> 	    } else {
> 		success = 1;
> 	    }
> 	}
>     }
>     if (work_to_do) {
> 	if (!success) /* a full round and no progress */
> 	    return AVERROR_SOMEGHING;
> 	break;
>     }
> }
>

I have a question regarding filter initialization and the
all_inputs_and_outputs_configure function implementation.

Is testing filter->inputs[i]->format < 0 good enough to know if a filter
has run query_formats without problems ? Same remark for filter->outputs[i]->format.

This algorithm might not work in the amerge case since it will reach the
state where amerge inputs and outputs are initialized and
all_inputs_outputs_configured will will return 1.

Maybe i am missing something ?

Regard,
Matthieu


More information about the ffmpeg-devel mailing list