History

Remove avfilter_vf_graph Commited in SoC by Vitor Sessak on 2008-03-24 20:13:01

Originally committed as revision 12734 to svn://svn.ffmpeg.org/ffmpeg/trunk

Vitor Sessak committed 18 years ago

Commit f2ee8081 parent 72646952 files · +38 −153Browse files

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

Unified · Split

libavfilter/avfiltergraph.c+30−148
@@ -22,93 +22,39 @@ · 21 unmodified lines
2222 #include "avfilter.h"
2323 #include "avfiltergraph.h"
2424
25−typedef struct AVFilterGraph {
26− unsigned filter_count;
27− AVFilterContext **filters;
28−
29− /** fake filters to handle links to internal filters */
30− AVFilterContext *link_filter_in;
31− AVFilterContext *link_filter_out;
32−} GraphContext;
33−
34−typedef struct {
35− AVFilterContext *graph;
36−} GraphLinkContext;
37−
38−static int link_init(AVFilterContext *ctx, const char *args, void *opaque)
39−{
40− GraphLinkContext *linkctx = ctx->priv;
41− linkctx->graph = opaque;
42− return !opaque;
43−}
44−
4525 /**
46− * Given the link between the dummy filter and an internal filter whose input
47− * is being exported outside the graph, this returns the externally visible
48− * link.
26+ * For use in av_log
4927 */
50−static inline AVFilterLink *get_extern_input_link(AVFilterLink *link)
28+static const char *log_name(void *p)
5129 {
52− GraphLinkContext *lctx = link->src->priv;
53− return lctx->graph->inputs[link->srcpad];
30+ return "Filter parser";
5431 }
5532
56−/**
57− * Given the link between the dummy filter and an internal filter whose output
58− * is being exported outside the graph, this returns the externally visible
59− * link.
60− */
61−static inline AVFilterLink *get_extern_output_link(AVFilterLink *link)
62−{
63− GraphLinkContext *lctx = link->dst->priv;
64− return lctx->graph->outputs[link->dstpad];
65−}
66−
67−
68−/** dummy filter used to help export filters pads outside the graph */
69−static AVFilter vf_graph_dummy =
70−{
71− .name = "graph_dummy",
72−
73− .priv_size = sizeof(GraphLinkContext),
74−
75− .init = link_init,
76−
77− .inputs = (AVFilterPad[]) {{ .name = NULL, }},
78− .outputs = (AVFilterPad[]) {{ .name = NULL, }},
33+static const AVClass filter_parser_class = {
34+ "Filter parser",
35+ log_name
7936 };
8037
81−static void uninit(AVFilterContext *ctx)
82−{
83− GraphContext *graph = ctx->priv;
38+static const AVClass *log_ctx = &filter_parser_class;
8439
85− if(graph->link_filter_in) {
86− avfilter_destroy(graph->link_filter_in);
87− graph->link_filter_in = NULL;
88− }
89− if(graph->link_filter_out) {
90− avfilter_destroy(graph->link_filter_out);
91− graph->link_filter_out = NULL;
92− }
40+static void uninit(GraphContext *graph)
41+{
9342 for(; graph->filter_count > 0; graph->filter_count --)
9443 avfilter_destroy(graph->filters[graph->filter_count - 1]);
9544 av_freep(&graph->filters);
9645 }
9746
9847 /* TODO: insert in sorted order */
99−void avfilter_graph_add_filter(AVFilterContext *graphctx, AVFilterContext *filter)
48+void avfilter_graph_add_filter(GraphContext *graph, AVFilterContext *filter)
10049 {
101− GraphContext *graph = graphctx->priv;
102−
10350 graph->filters = av_realloc(graph->filters,
10451 sizeof(AVFilterContext*) * ++graph->filter_count);
10552 graph->filters[graph->filter_count - 1] = filter;
10653 }
10754
10855 /* search intelligently, once we insert in order */
109−AVFilterContext *avfilter_graph_get_filter(AVFilterContext *ctx, char *name)
56+AVFilterContext *avfilter_graph_get_filter(GraphContext *graph, char *name)
11057 {
111− GraphContext *graph = ctx->priv;
11258 int i;
11359
11460 if(!name)
@@ -121,11 +67,8 @@ AVFilterContext *avfilter_graph_get_filter(AVFilterContext *ctx, char *name) · 6 unmodified lines
12167 return NULL;
12268 }
12369
124−static int query_formats(AVFilterContext *graphctx)
70+static int query_formats(GraphContext *graph)
12571 {
126− GraphContext *graph = graphctx->priv;
127− AVFilterContext *linkfiltin = graph->link_filter_in;
128− AVFilterContext *linkfiltout = graph->link_filter_out;
12972 int i, j;
13073
13174 /* ask all the sub-filters for their supported colorspaces */
@@ -136,24 +79,6 @@ static int query_formats(AVFilterContext *graphctx) · 4 unmodified lines
13679 avfilter_default_query_formats(graph->filters[i]);
13780 }
13881
139− /* use these formats on our exported links */
140− for(i = 0; i < linkfiltout->input_count; i ++) {
141− avfilter_formats_ref( linkfiltout->inputs[i]->in_formats,
142− &linkfiltout->inputs[i]->out_formats);
143−
144− if(graphctx->outputs[i])
145− avfilter_formats_ref(linkfiltout->inputs[i]->in_formats,
146− &graphctx->outputs[i]->in_formats);
147− }
148− for(i = 0; i < linkfiltin->output_count; i ++) {
149− avfilter_formats_ref( linkfiltin->outputs[i]->out_formats,
150− &linkfiltin->outputs[i]->in_formats);
151−
152− if(graphctx->inputs[i])
153− avfilter_formats_ref(linkfiltin->outputs[i]->out_formats,
154− &graphctx-> inputs[i]->out_formats);
155− }
156−
15782 /* go through and merge as many format lists as possible */
15883 for(i = 0; i < graph->filter_count; i ++) {
15984 AVFilterContext *filter = graph->filters[i];
@@ -177,7 +102,7 @@ static int query_formats(AVFilterContext *graphctx) · 17 unmodified lines
177102 return -1;
178103 }
179104
180− avfilter_graph_add_filter(graphctx, scale);
105+ avfilter_graph_add_filter(graph, scale);
181106 scale->filter->query_formats(scale);
182107 if(!avfilter_merge_formats(scale-> inputs[0]->in_formats,
183108 scale-> inputs[0]->out_formats) ||
@@ -211,9 +136,6 @@ static void pick_formats(GraphContext *graph) · 27 unmodified lines
211136 for(i = 0; i < graph->filter_count; i ++) {
212137 AVFilterContext *filter = graph->filters[i];
213138
214− if(filter->filter == &avfilter_vf_graph)
215− pick_formats(filter->priv);
216−
217139 for(j = 0; j < filter->input_count; j ++)
218140 pick_format(filter->inputs[j]);
219141 for(j = 0; j < filter->output_count; j ++)
@@ -221,12 +143,10 @@ static void pick_formats(GraphContext *graph) · 1 unmodified line
221143 }
222144 }
223145
224−int avfilter_graph_config_formats(AVFilterContext *graphctx)
146+int avfilter_graph_config_formats(GraphContext *graph)
225147 {
226− GraphContext *graph = graphctx->priv;
227−
228148 /* find supported formats from sub-filters, and merge along links */
229− if(query_formats(graphctx))
149+ if(query_formats(graph))
230150 return -1;
231151
232152 /* Once everything is merged, it's possible that we'll still have
@@ -236,7 +156,7 @@ int avfilter_graph_config_formats(AVFilterContext *graphctx) · 3 unmodified lines
236156 return 0;
237157 }
238158
239−static int graph_load_from_desc2(AVFilterContext *ctx, AVFilterGraphDesc *desc)
159+static int graph_load_from_desc2(GraphContext *ctx, AVFilterGraphDesc *desc)
240160 {
241161 AVFilterGraphDescFilter *curfilt;
242162 AVFilterGraphDescLink *curlink;
@@ -250,13 +170,13 @@ static int graph_load_from_desc2(AVFilterContext *ctx, AVFilterGraphDesc *desc) · 7 unmodified lines
250170 snprintf(tmp, 20, "%d", curfilt->index);
251171 if(!(filterdef = avfilter_get_by_name(curfilt->filter)) ||
252172 !(filt = avfilter_open(filterdef, tmp))) {
253− av_log(ctx, AV_LOG_ERROR,
173+ av_log(&log_ctx, AV_LOG_ERROR,
254174 "error creating filter '%s'\n", curfilt->filter);
255175 goto fail;
256176 }
257177 avfilter_graph_add_filter(ctx, filt);
258178 if(avfilter_init_filter(filt, curfilt->args, NULL)) {
259− av_log(ctx, AV_LOG_ERROR,
179+ av_log(&log_ctx, AV_LOG_ERROR,
260180 "error initializing filter '%s'\n", curfilt->filter);
261181 goto fail;
262182 }
@@ -266,16 +186,16 @@ static int graph_load_from_desc2(AVFilterContext *ctx, AVFilterGraphDesc *desc) · 3 unmodified lines
266186 for(curlink = desc->links; curlink; curlink = curlink->next) {
267187 snprintf(tmp, 20, "%d", curlink->src);
268188 if(!(filt = avfilter_graph_get_filter(ctx, tmp))) {
269− av_log(ctx, AV_LOG_ERROR, "link source does not exist in graph\n");
189+ av_log(&log_ctx, AV_LOG_ERROR, "link source does not exist in graph\n");
270190 goto fail;
271191 }
272192 snprintf(tmp, 20, "%d", curlink->dst);
273193 if(!(filtb = avfilter_graph_get_filter(ctx, tmp))) {
274− av_log(ctx, AV_LOG_ERROR, "link destination does not exist in graph\n");
194+ av_log(&log_ctx, AV_LOG_ERROR, "link destination does not exist in graph\n");
275195 goto fail;
276196 }
277197 if(avfilter_link(filt, curlink->srcpad, filtb, curlink->dstpad)) {
278− av_log(ctx, AV_LOG_ERROR, "cannot create link between source and destination filters\n");
198+ av_log(&log_ctx, AV_LOG_ERROR, "cannot create link between source and destination filters\n");
279199 goto fail;
280200 }
281201 }
@@ -287,24 +207,24 @@ fail: · 5 unmodified lines
287207 return -1;
288208 }
289209
290−int graph_load_from_desc3(AVFilterContext *ctx, AVFilterGraphDesc *desc, AVFilterContext *in, int inpad, AVFilterContext *out, int outpad)
210+int graph_load_from_desc3(GraphContext *graph, AVFilterGraphDesc *desc, AVFilterContext *in, int inpad, AVFilterContext *out, int outpad)
291211 {
292212 AVFilterGraphDescExport *curpad;
293213 char tmp[20];
294214 AVFilterContext *filt;
295215
296− if (graph_load_from_desc2(ctx, desc) < 0)
216+ if (graph_load_from_desc2(graph, desc) < 0)
297217 goto fail;
298218
299219 /* export all input pads */
300220 for(curpad = desc->inputs; curpad; curpad = curpad->next) {
301221 snprintf(tmp, 20, "%d", curpad->filter);
302− if(!(filt = avfilter_graph_get_filter(ctx, tmp))) {
303− av_log(ctx, AV_LOG_ERROR, "filter owning exported pad does not exist\n");
222+ if(!(filt = avfilter_graph_get_filter(graph, tmp))) {
223+ av_log(&log_ctx, AV_LOG_ERROR, "filter owning exported pad does not exist\n");
304224 goto fail;
305225 }
306226 if(avfilter_link(in, inpad, filt, curpad->pad)) {
307− av_log(ctx, AV_LOG_ERROR, "cannot create link between source and destination filters\n");
227+ av_log(&log_ctx, AV_LOG_ERROR, "cannot create link between source and destination filters\n");
308228 goto fail;
309229 }
310230 }
@@ -312,13 +232,13 @@ int graph_load_from_desc3(AVFilterContext *ctx, AVFilterGraphDesc *desc, AVFilte · 1 unmodified line
312232 /* export all output pads */
313233 for(curpad = desc->outputs; curpad; curpad = curpad->next) {
314234 snprintf(tmp, 20, "%d", curpad->filter);
315− if(!(filt = avfilter_graph_get_filter(ctx, tmp))) {
316− av_log(ctx, AV_LOG_ERROR, "filter owning exported pad does not exist\n");
235+ if(!(filt = avfilter_graph_get_filter(graph, tmp))) {
236+ av_log(&log_ctx, AV_LOG_ERROR, "filter owning exported pad does not exist\n");
317237 goto fail;
318238 }
319239
320240 if(avfilter_link(filt, curpad->pad, out, outpad)) {
321− av_log(ctx, AV_LOG_ERROR, "cannot create link between source and destination filters\n");
241+ av_log(&log_ctx, AV_LOG_ERROR, "cannot create link between source and destination filters\n");
322242 goto fail;
323243 }
324244 }
@@ -326,44 +246,6 @@ int graph_load_from_desc3(AVFilterContext *ctx, AVFilterGraphDesc *desc, AVFilte · 1 unmodified line
326246 return 0;
327247
328248 fail:
329− uninit(ctx);
330− return -1;
331−}
332−
333−static int init(AVFilterContext *ctx, const char *args, void *opaque)
334−{
335− GraphContext *gctx = ctx->priv;
336−
337− if(!(gctx->link_filter_in = avfilter_open(&vf_graph_dummy, NULL)))
338− return -1;
339− if(avfilter_init_filter(gctx->link_filter_in, NULL, ctx))
340− goto fail;
341− if(!(gctx->link_filter_out = avfilter_open(&vf_graph_dummy, NULL)))
342− goto fail;
343− if(avfilter_init_filter(gctx->link_filter_out, NULL, ctx))
344− goto fail;
345−
346− return 0;
347−
348−fail:
349− avfilter_destroy(gctx->link_filter_in);
350− if(gctx->link_filter_out)
351− avfilter_destroy(gctx->link_filter_out);
249+ uninit(graph);
352250 return -1;
353251 }
354−
355−AVFilter avfilter_vf_graph =
356−{
357− .name = "graph",
358−
359− .priv_size = sizeof(GraphContext),
360−
361− .init = init,
362− .uninit = uninit,
363−
364− .query_formats = query_formats,
365−
366− .inputs = (AVFilterPad[]) {{ .name = NULL, }},
367− .outputs = (AVFilterPad[]) {{ .name = NULL, }},
368−};
369−

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