History

Make the filter graph just another normal filter.

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

Vitor Sessak committed 18 years ago

Commit b9a7a651 parent 1ac87cc2 files · +69 −43Browse files

Showing the changes to libavfilter/avfiltergraph.c (1 of 2 files). Show all

Unified · Split

libavfilter/avfiltergraph.c+68−16
@@ -26,31 +26,24 @@ · 25 unmodified lines
26#include "avfilter.h"26#include "avfilter.h"
27#include "avfiltergraph.h"27#include "avfiltergraph.h"
28 28
29struct AVFilterGraph {29typedef struct AVFilterGraph {
30 unsigned filter_count;30 unsigned filter_count;
31 AVFilterContext **filters;31 AVFilterContext **filters;
32};32} GraphContext;
33 33
34AVFilterGraph *avfilter_create_graph(void)34static void uninit(AVFilterContext *ctx)
35{35{
36 return av_mallocz(sizeof(AVFilterGraph));36 GraphContext *graph = ctx->priv;
37}
38 37
39static void destroy_graph_filters(AVFilterGraph *graph)
40{
41 for(; graph->filter_count > 0; graph->filter_count --)38 for(; graph->filter_count > 0; graph->filter_count --)
42 avfilter_destroy(graph->filters[graph->filter_count - 1]);39 avfilter_destroy(graph->filters[graph->filter_count - 1]);
43 av_freep(&graph->filters);40 av_freep(&graph->filters);
44}41}
45 42
46void avfilter_destroy_graph(AVFilterGraph *graph)43void avfilter_graph_add_filter(AVFilterContext *graphctx, AVFilterContext *filter)
47{44{
48 destroy_graph_filters(graph);45 GraphContext *graph = graphctx->priv;
49 av_free(graph);
50}
51 46
52void avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter)
53{
54 graph->filters = av_realloc(graph->filters,47 graph->filters = av_realloc(graph->filters,
55 sizeof(AVFilterContext*) * ++graph->filter_count);48 sizeof(AVFilterContext*) * ++graph->filter_count);
56 graph->filters[graph->filter_count - 1] = filter;49 graph->filters[graph->filter_count - 1] = filter;
@@ -89,7 +82,7 @@ fail: · 32 unmodified lines
89 return NULL;82 return NULL;
90}83}
91 84
92int avfilter_graph_load_chain(AVFilterGraph *graph,85static int graph_load_chain(AVFilterContext *graphctx,
93 unsigned count, char **filter_list, void **opaque,86 unsigned count, char **filter_list, void **opaque,
94 AVFilterContext **first, AVFilterContext **last)87 AVFilterContext **first, AVFilterContext **last)
95{88{
@@ -112,7 +105,7 @@ int avfilter_graph_load_chain(AVFilterGraph *graph, · 16 unmodified lines
112 goto fail;105 goto fail;
113 }106 }
114 }107 }
115 avfilter_graph_add_filter(graph, filters[1]);108 avfilter_graph_add_filter(graphctx, filters[1]);
116 filters[0] = filters[1];109 filters[0] = filters[1];
117 }110 }
118 111
@@ -120,9 +113,68 @@ int avfilter_graph_load_chain(AVFilterGraph *graph, · 1 unmodified line
120 return 0;113 return 0;
121 114
122fail:115fail:
123 destroy_graph_filters(graph);116 uninit(graphctx);
124 if(first) *first = NULL;117 if(first) *first = NULL;
125 if(last) *last = NULL;118 if(last) *last = NULL;
126 return -1;119 return -1;
127}120}
128 121
122static 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
148done:
149 av_free(strings[0]);
150 av_free(strings);
151
152 return ret;
153}
154
155static 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
167AVFilter 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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t