* commit '1565cbc65cbb9f95c11367314a080068895e0cf0': lavfi: make avfilter_free() remove the filter from its graph. Conflicts: libavfilter/avfilter.c libavfilter/avfiltergraph.c libavfilter/graphparser.c
Showing the changes to libavfilter/avfiltergraph.c (1 of 5 files). Show all
Unified · Split
| @@ -59,12 +59,27 @@ AVFilterGraph *avfilter_graph_alloc(void) · 58 unmodified lines | ||
| 59 | 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 | 75 | void avfilter_graph_free(AVFilterGraph **graph) |
| 63 | 76 | { |
| 64 | 77 | if (!*graph) |
| 65 | 78 | return; |
| 66 | − for (; (*graph)->nb_filters > 0; (*graph)->nb_filters--) | |
| 67 | − avfilter_free((*graph)->filters[(*graph)->nb_filters - 1]); | |
| 79 | + | |
| 80 | + while ((*graph)->nb_filters) | |
| 81 | + avfilter_free((*graph)->filters[0]); | |
| 82 | + | |
| 68 | 83 | av_freep(&(*graph)->sink_links); |
| 69 | 84 | av_freep(&(*graph)->scale_sws_opts); |
| 70 | 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 | 118 | *filt_ctx = avfilter_graph_alloc_filter(graph_ctx, filt, name); |
| 104 | 119 | if (!*filt_ctx) |
| 105 | 120 | return AVERROR(ENOMEM); |
| 106 | − if ((ret = avfilter_init_filter(*filt_ctx, args, opaque)) < 0) { | |
| 107 | − graph_ctx->filters[graph_ctx->nb_filters-1] = NULL; | |
| 121 | + if ((ret = avfilter_init_filter(*filt_ctx, args, opaque)) < 0) | |
| 108 | 122 | goto fail; |
| 109 | − } | |
| 110 | 123 | |
| 111 | 124 | return 0; |
| 112 | 125 | |