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
2626 #include "avfilter.h"
2727 #include "avfiltergraph.h"
2828
29−struct AVFilterGraph {
29+typedef struct AVFilterGraph {
3030 unsigned filter_count;
3131 AVFilterContext **filters;
32−};
32+} GraphContext;
3333
34−AVFilterGraph *avfilter_create_graph(void)
34+static void uninit(AVFilterContext *ctx)
3535 {
36− return av_mallocz(sizeof(AVFilterGraph));
37−}
36+ GraphContext *graph = ctx->priv;
3837
39−static void destroy_graph_filters(AVFilterGraph *graph)
40−{
4138 for(; graph->filter_count > 0; graph->filter_count --)
4239 avfilter_destroy(graph->filters[graph->filter_count - 1]);
4340 av_freep(&graph->filters);
4441 }
4542
46−void avfilter_destroy_graph(AVFilterGraph *graph)
43+void avfilter_graph_add_filter(AVFilterContext *graphctx, AVFilterContext *filter)
4744 {
48− destroy_graph_filters(graph);
49− av_free(graph);
50−}
45+ GraphContext *graph = graphctx->priv;
5146
52−void avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter)
53−{
5447 graph->filters = av_realloc(graph->filters,
5548 sizeof(AVFilterContext*) * ++graph->filter_count);
5649 graph->filters[graph->filter_count - 1] = filter;
@@ -89,7 +82,7 @@ fail: · 32 unmodified lines
8982 return NULL;
9083 }
9184
92−int avfilter_graph_load_chain(AVFilterGraph *graph,
85+static int graph_load_chain(AVFilterContext *graphctx,
9386 unsigned count, char **filter_list, void **opaque,
9487 AVFilterContext **first, AVFilterContext **last)
9588 {
@@ -112,7 +105,7 @@ int avfilter_graph_load_chain(AVFilterGraph *graph, · 16 unmodified lines
112105 goto fail;
113106 }
114107 }
115− avfilter_graph_add_filter(graph, filters[1]);
108+ avfilter_graph_add_filter(graphctx, filters[1]);
116109 filters[0] = filters[1];
117110 }
118111
@@ -120,9 +113,68 @@ int avfilter_graph_load_chain(AVFilterGraph *graph, · 1 unmodified line
120113 return 0;
121114
122115 fail:
123− destroy_graph_filters(graph);
116+ uninit(graphctx);
124117 if(first) *first = NULL;
125118 if(last) *last = NULL;
126119 return -1;
127120 }
128121
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+

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