diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-04-12 00:54:05 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-04-12 00:54:05 +0200 |
commit | eb0f774d4bfdb1e5cb131f63580417cfb6b47514 (patch) | |
tree | 4b09152f83728967ff6bd1bd3a0d72213be4d26f | |
parent | 4fde705396759ad96a662a400d5f1667c19c614b (diff) | |
parent | 1565cbc65cbb9f95c11367314a080068895e0cf0 (diff) | |
download | ffmpeg-eb0f774d4bfdb1e5cb131f63580417cfb6b47514.tar.gz |
Merge commit '1565cbc65cbb9f95c11367314a080068895e0cf0'
* commit '1565cbc65cbb9f95c11367314a080068895e0cf0':
lavfi: make avfilter_free() remove the filter from its graph.
Conflicts:
libavfilter/avfilter.c
libavfilter/avfiltergraph.c
libavfilter/graphparser.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavfilter/avfilter.c | 3 | ||||
-rw-r--r-- | libavfilter/avfilter.h | 3 | ||||
-rw-r--r-- | libavfilter/avfiltergraph.c | 23 | ||||
-rw-r--r-- | libavfilter/graphparser.c | 8 | ||||
-rw-r--r-- | libavfilter/internal.h | 5 |
5 files changed, 32 insertions, 10 deletions
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 406537a5a6..54d90dcd02 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -571,6 +571,9 @@ void avfilter_free(AVFilterContext *filter) if (!filter) return; + if (filter->graph) + ff_filter_graph_remove_filter(filter->graph, filter); + if (filter->filter->uninit) filter->filter->uninit(filter); diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 2360b24f7f..711cf4b551 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -873,7 +873,8 @@ int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *in int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque); /** - * Free a filter context. + * Free a filter context. This will also remove the filter from its + * filtergraph's list of filters. * * @param filter the filter to free */ diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 8dd543362f..8e8edd5134 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -59,12 +59,27 @@ AVFilterGraph *avfilter_graph_alloc(void) return ret; } +void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter) +{ + int i; + for (i = 0; i < graph->nb_filters; i++) { + if (graph->filters[i] == filter) { + FFSWAP(AVFilterContext*, graph->filters[i], + graph->filters[graph->nb_filters - 1]); + graph->nb_filters--; + return; + } + } +} + void avfilter_graph_free(AVFilterGraph **graph) { if (!*graph) return; - for (; (*graph)->nb_filters > 0; (*graph)->nb_filters--) - avfilter_free((*graph)->filters[(*graph)->nb_filters - 1]); + + while ((*graph)->nb_filters) + avfilter_free((*graph)->filters[0]); + av_freep(&(*graph)->sink_links); av_freep(&(*graph)->scale_sws_opts); av_freep(&(*graph)->aresample_swr_opts); @@ -103,10 +118,8 @@ int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt, *filt_ctx = avfilter_graph_alloc_filter(graph_ctx, filt, name); if (!*filt_ctx) return AVERROR(ENOMEM); - if ((ret = avfilter_init_filter(*filt_ctx, args, opaque)) < 0) { - graph_ctx->filters[graph_ctx->nb_filters-1] = NULL; + if ((ret = avfilter_init_filter(*filt_ctx, args, opaque)) < 0) goto fail; - } return 0; diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c index 3af9b56021..447b9ebc5d 100644 --- a/libavfilter/graphparser.c +++ b/libavfilter/graphparser.c @@ -430,8 +430,8 @@ int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters, return 0; fail:end: - for (; graph->nb_filters > 0; graph->nb_filters--) - avfilter_free(graph->filters[graph->nb_filters - 1]); + while (graph->nb_filters) + avfilter_free(graph->filters[0]); av_freep(&graph->filters); avfilter_inout_free(&open_inputs); avfilter_inout_free(&open_outputs); @@ -498,8 +498,8 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, fail: if (ret < 0) { - for (; graph->nb_filters > 0; graph->nb_filters--) - avfilter_free(graph->filters[graph->nb_filters - 1]); + while (graph->nb_filters) + avfilter_free(graph->filters[0]); av_freep(&graph->filters); } avfilter_inout_free(&inputs); diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 6907b76a71..fbe935667f 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -349,4 +349,9 @@ enum { */ AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name); +/** + * Remove a filter from a graph; + */ +void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter); + #endif /* AVFILTER_INTERNAL_H */ |