* commit '1565cbc65cbb9f95c11367314a080068895e0cf0': lavfi: make avfilter_free() remove the filter from its graph. Conflicts: libavfilter/avfilter.c libavfilter/avfiltergraph.c libavfilter/graphparser.c
Unified · Split
| @@ -571,6 +571,9 @@ void avfilter_free(AVFilterContext *filter) · 570 unmodified lines | |||
| 571 | if (!filter) | 571 | if (!filter) |
| 572 | return; | 572 | return; |
| 573 | 573 | ||
| 574 | if (filter->graph) | ||
| 575 | ff_filter_graph_remove_filter(filter->graph, filter); | ||
| 576 | |||
| 574 | if (filter->filter->uninit) | 577 | if (filter->filter->uninit) |
| 575 | filter->filter->uninit(filter); | 578 | filter->filter->uninit(filter); |
| 576 | 579 | ||
| @@ -873,7 +873,8 @@ int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *in · 872 unmodified lines | |||
| 873 | int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque); | 873 | int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque); |
| 874 | 874 | ||
| 875 | /** | 875 | /** |
| 876 | * Free a filter context. | 876 | * Free a filter context. This will also remove the filter from its |
| 877 | * filtergraph's list of filters. | ||
| 877 | * | 878 | * |
| 878 | * @param filter the filter to free | 879 | * @param filter the filter to free |
| 879 | */ | 880 | */ |
| @@ -59,12 +59,27 @@ AVFilterGraph *avfilter_graph_alloc(void) · 58 unmodified lines | |||
| 59 | return ret; | 59 | return ret; |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter) | ||
| 63 | { | ||
| 64 | int i; | ||
| 65 | for (i = 0; i < graph->nb_filters; i++) { | ||
| 66 | if (graph->filters[i] == filter) { | ||
| 67 | FFSWAP(AVFilterContext*, graph->filters[i], | ||
| 68 | graph->filters[graph->nb_filters - 1]); | ||
| 69 | graph->nb_filters--; | ||
| 70 | return; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 62 | void avfilter_graph_free(AVFilterGraph **graph) | 75 | void avfilter_graph_free(AVFilterGraph **graph) |
| 63 | { | 76 | { |
| 64 | if (!*graph) | 77 | if (!*graph) |
| 65 | return; | 78 | return; |
| 66 | for (; (*graph)->nb_filters > 0; (*graph)->nb_filters--) | 79 | |
| 67 | avfilter_free((*graph)->filters[(*graph)->nb_filters - 1]); | 80 | while ((*graph)->nb_filters) |
| 81 | avfilter_free((*graph)->filters[0]); | ||
| 82 | |||
| 68 | av_freep(&(*graph)->sink_links); | 83 | av_freep(&(*graph)->sink_links); |
| 69 | av_freep(&(*graph)->scale_sws_opts); | 84 | av_freep(&(*graph)->scale_sws_opts); |
| 70 | av_freep(&(*graph)->aresample_swr_opts); | 85 | av_freep(&(*graph)->aresample_swr_opts); |
| @@ -103,10 +118,8 @@ int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt, · 32 unmodified lines | |||
| 103 | *filt_ctx = avfilter_graph_alloc_filter(graph_ctx, filt, name); | 118 | *filt_ctx = avfilter_graph_alloc_filter(graph_ctx, filt, name); |
| 104 | if (!*filt_ctx) | 119 | if (!*filt_ctx) |
| 105 | return AVERROR(ENOMEM); | 120 | return AVERROR(ENOMEM); |
| 106 | if ((ret = avfilter_init_filter(*filt_ctx, args, opaque)) < 0) { | 121 | if ((ret = avfilter_init_filter(*filt_ctx, args, opaque)) < 0) |
| 107 | graph_ctx->filters[graph_ctx->nb_filters-1] = NULL; | ||
| 108 | goto fail; | 122 | goto fail; |
| 109 | } | ||
| 110 | 123 | ||
| 111 | return 0; | 124 | return 0; |
| 112 | 125 | ||
| @@ -430,8 +430,8 @@ int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters, · 429 unmodified lines | |||
| 430 | return 0; | 430 | return 0; |
| 431 | 431 | ||
| 432 | fail:end: | 432 | fail:end: |
| 433 | for (; graph->nb_filters > 0; graph->nb_filters--) | 433 | while (graph->nb_filters) |
| 434 | avfilter_free(graph->filters[graph->nb_filters - 1]); | 434 | avfilter_free(graph->filters[0]); |
| 435 | av_freep(&graph->filters); | 435 | av_freep(&graph->filters); |
| 436 | avfilter_inout_free(&open_inputs); | 436 | avfilter_inout_free(&open_inputs); |
| 437 | avfilter_inout_free(&open_outputs); | 437 | avfilter_inout_free(&open_outputs); |
| @@ -498,8 +498,8 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, · 60 unmodified lines | |||
| 498 | 498 | ||
| 499 | fail: | 499 | fail: |
| 500 | if (ret < 0) { | 500 | if (ret < 0) { |
| 501 | for (; graph->nb_filters > 0; graph->nb_filters--) | 501 | while (graph->nb_filters) |
| 502 | avfilter_free(graph->filters[graph->nb_filters - 1]); | 502 | avfilter_free(graph->filters[0]); |
| 503 | av_freep(&graph->filters); | 503 | av_freep(&graph->filters); |
| 504 | } | 504 | } |
| 505 | avfilter_inout_free(&inputs); | 505 | avfilter_inout_free(&inputs); |
| @@ -349,4 +349,9 @@ enum { · 348 unmodified lines | |||
| 349 | */ | 349 | */ |
| 350 | AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name); | 350 | AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name); |
| 351 | 351 | ||
| 352 | /** | ||
| 353 | * Remove a filter from a graph; | ||
| 354 | */ | ||
| 355 | void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter); | ||
| 356 | |||
| 352 | #endif /* AVFILTER_INTERNAL_H */ | 357 | #endif /* AVFILTER_INTERNAL_H */ |