[FFmpeg-devel] [PATCH 2/3] avfiltergraph: don't query formats if filter has uninitialized inputs
Matthieu Bouron
matthieu.bouron at gmail.com
Thu May 3 14:36:03 CEST 2012
---
libavfilter/avfiltergraph.c | 46 ++++++++++++++++++++++++++++++++++++-------
1 file changed, 39 insertions(+), 7 deletions(-)
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 9d7b956..064e678 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -202,17 +202,49 @@ static int insert_conv_filter(AVFilterGraph *graph, AVFilterLink *link,
static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
{
- int i, j, ret;
+ int i, j, k, ret;
char filt_args[128];
AVFilterFormats *formats, *chlayouts, *packing;
+ int filters_init;
+ int *filters_state = av_calloc(graph->filter_count, sizeof(int));
/* ask all the sub-filters for their supported media formats */
- for (i = 0; i < graph->filter_count; i++) {
- if (graph->filters[i]->filter->query_formats)
- graph->filters[i]->filter->query_formats(graph->filters[i]);
- else
- avfilter_default_query_formats(graph->filters[i]);
- }
+ do {
+ filters_init = 1;
+ for (i = 0; i < graph->filter_count; i++) {
+ int do_query = 1;
+ AVFilterContext *cur = graph->filters[i];
+
+ if (filters_state[i])
+ continue;
+
+ /* Check state of input links */
+ for (j = 0; j < cur->input_count; j++) {
+ AVFilterContext *ifilter = cur->inputs[j]->src;
+
+ for(k = 0; k < graph->filter_count; k++) {
+ if (ifilter == graph->filters[k]) {
+ break;
+ }
+ }
+
+ if (!filters_state[k]) {
+ do_query = 0;
+ filters_init = 0;
+ }
+ }
+
+ if (do_query) {
+ filters_state[i] = 1;
+ if (graph->filters[i]->filter->query_formats)
+ graph->filters[i]->filter->query_formats(graph->filters[i]);
+ else
+ avfilter_default_query_formats(graph->filters[i]);
+ }
+ }
+ } while (!filters_init);
+
+ av_freep(&filters_state);
/* go through and merge as many format lists as possible */
for (i = 0; i < graph->filter_count; i++) {
--
1.7.10
More information about the ffmpeg-devel
mailing list