Commited in SoC by Bobby Bingham on 2007-07-31 20:08:38 Originally committed as revision 12693 to svn://svn.ffmpeg.org/ffmpeg/trunk
Showing the changes to libavfilter/avfiltergraph.c (1 of 2 files). Show all
Unified · Split
| @@ -26,31 +26,24 @@ · 25 unmodified lines | ||
| 26 | 26 | #include "avfilter.h" |
| 27 | 27 | #include "avfiltergraph.h" |
| 28 | 28 | |
| 29 | −struct AVFilterGraph { | |
| 29 | +typedef struct AVFilterGraph { | |
| 30 | 30 | unsigned filter_count; |
| 31 | 31 | AVFilterContext **filters; |
| 32 | −}; | |
| 32 | +} GraphContext; | |
| 33 | 33 | |
| 34 | −AVFilterGraph *avfilter_create_graph(void) | |
| 34 | +static void uninit(AVFilterContext *ctx) | |
| 35 | 35 | { |
| 36 | − return av_mallocz(sizeof(AVFilterGraph)); | |
| 37 | −} | |
| 36 | + GraphContext *graph = ctx->priv; | |
| 38 | 37 | |
| 39 | −static void destroy_graph_filters(AVFilterGraph *graph) | |
| 40 | −{ | |
| 41 | 38 | for(; graph->filter_count > 0; graph->filter_count --) |
| 42 | 39 | avfilter_destroy(graph->filters[graph->filter_count - 1]); |
| 43 | 40 | av_freep(&graph->filters); |
| 44 | 41 | } |
| 45 | 42 | |
| 46 | −void avfilter_destroy_graph(AVFilterGraph *graph) | |
| 43 | +void avfilter_graph_add_filter(AVFilterContext *graphctx, AVFilterContext *filter) | |
| 47 | 44 | { |
| 48 | − destroy_graph_filters(graph); | |
| 49 | − av_free(graph); | |
| 50 | −} | |
| 45 | + GraphContext *graph = graphctx->priv; | |
| 51 | 46 | |
| 52 | −void avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter) | |
| 53 | −{ | |
| 54 | 47 | graph->filters = av_realloc(graph->filters, |
| 55 | 48 | sizeof(AVFilterContext*) * ++graph->filter_count); |
| 56 | 49 | graph->filters[graph->filter_count - 1] = filter; |
| @@ -89,7 +82,7 @@ fail: · 32 unmodified lines | ||
| 89 | 82 | return NULL; |
| 90 | 83 | } |
| 91 | 84 | |
| 92 | −int avfilter_graph_load_chain(AVFilterGraph *graph, | |
| 85 | +static int graph_load_chain(AVFilterContext *graphctx, | |
| 93 | 86 | unsigned count, char **filter_list, void **opaque, |
| 94 | 87 | AVFilterContext **first, AVFilterContext **last) |
| 95 | 88 | { |
| @@ -112,7 +105,7 @@ int avfilter_graph_load_chain(AVFilterGraph *graph, · 16 unmodified lines | ||
| 112 | 105 | goto fail; |
| 113 | 106 | } |
| 114 | 107 | } |
| 115 | − avfilter_graph_add_filter(graph, filters[1]); | |
| 108 | + avfilter_graph_add_filter(graphctx, filters[1]); | |
| 116 | 109 | filters[0] = filters[1]; |
| 117 | 110 | } |
| 118 | 111 | |
| @@ -120,9 +113,68 @@ int avfilter_graph_load_chain(AVFilterGraph *graph, · 1 unmodified line | ||
| 120 | 113 | return 0; |
| 121 | 114 | |
| 122 | 115 | fail: |
| 123 | − destroy_graph_filters(graph); | |
| 116 | + uninit(graphctx); | |
| 124 | 117 | if(first) *first = NULL; |
| 125 | 118 | if(last) *last = NULL; |
| 126 | 119 | return -1; |
| 127 | 120 | } |
| 128 | 121 | |
| 122 | +static int graph_load_chain_from_string(AVFilterContext *ctx, const char *str, | |
| 123 | + AVFilterContext **first, | |
| 124 | + AVFilterContext **last) | |
| 125 | +{ | |
| 126 | + int count, ret = 0; | |
| 127 | + char **strings; | |
| 128 | + char *filt; | |
| 129 | + | |
| 130 | + strings = av_malloc(sizeof(char *)); | |
| 131 | + strings[0] = av_strdup(str); | |
| 132 | + | |
| 133 | + filt = strchr(strings[0], ','); | |
| 134 | + for(count = 1; filt; count ++) { | |
| 135 | + if(filt == strings[count-1]) { | |
| 136 | + ret = -1; | |
| 137 | + goto done; | |
| 138 | + } | |
| 139 | + | |
| 140 | + strings = av_realloc(strings, sizeof(char *) * (count+1)); | |
| 141 | + strings[count] = filt + 1; | |
| 142 | + *filt = '\0'; | |
| 143 | + filt = strchr(strings[count], ','); | |
| 144 | + } | |
| 145 | + | |
| 146 | + ret = graph_load_chain(ctx, count, strings, NULL, first, last); | |
| 147 | + | |
| 148 | +done: | |
| 149 | + av_free(strings[0]); | |
| 150 | + av_free(strings); | |
| 151 | + | |
| 152 | + return ret; | |
| 153 | +} | |
| 154 | + | |
| 155 | +static int init(AVFilterContext *ctx, const char *args, void *opaque) | |
| 156 | +{ | |
| 157 | + AVFilterContext **filters = opaque; | |
| 158 | + | |
| 159 | + if(!args) | |
| 160 | + return 0; | |
| 161 | + if(!opaque) | |
| 162 | + return -1; | |
| 163 | + | |
| 164 | + return graph_load_chain_from_string(ctx, args, filters, filters + 1); | |
| 165 | +} | |
| 166 | + | |
| 167 | +AVFilter vf_graph = | |
| 168 | +{ | |
| 169 | + .name = "graph", | |
| 170 | + .author = "Bobby Bingham", | |
| 171 | + | |
| 172 | + .priv_size = sizeof(GraphContext), | |
| 173 | + | |
| 174 | + .init = init, | |
| 175 | + .uninit = uninit, | |
| 176 | + | |
| 177 | + .inputs = (AVFilterPad[]) {{ .name = NULL, }}, | |
| 178 | + .outputs = (AVFilterPad[]) {{ .name = NULL, }}, | |
| 179 | +}; | |
| 180 | + | |