Commit 58f472d1 authored by Vitor Sessak's avatar Vitor Sessak

Simplify graph_load_from_desc3()

Commited in SoC by Vitor Sessak on 2008-03-26 20:37:43

Originally committed as revision 12737 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 9f39bb37
...@@ -160,55 +160,54 @@ int avfilter_graph_config_formats(AVFilterGraph *graph) ...@@ -160,55 +160,54 @@ int avfilter_graph_config_formats(AVFilterGraph *graph)
return 0; return 0;
} }
static int graph_load_from_desc2(AVFilterGraph *ctx, AVFilterGraphDesc *desc) static int create_filter(AVFilterGraph *ctx, int index, char *name,
char *args)
{ {
AVFilterGraphDescFilter *curfilt; AVFilterContext *filt;
AVFilterGraphDescLink *curlink;
AVFilterContext *filt, *filtb;
AVFilter *filterdef; AVFilter *filterdef;
char tmp[20]; char tmp[20];
/* create all filters */ snprintf(tmp, 20, "%d", index);
for(curfilt = desc->filters; curfilt; curfilt = curfilt->next) { if(!(filterdef = avfilter_get_by_name(name)) ||
snprintf(tmp, 20, "%d", curfilt->index); !(filt = avfilter_open(filterdef, tmp))) {
if(!(filterdef = avfilter_get_by_name(curfilt->filter)) || av_log(&log_ctx, AV_LOG_ERROR,
!(filt = avfilter_open(filterdef, tmp))) { "error creating filter '%s'\n", name);
av_log(&log_ctx, AV_LOG_ERROR, return -1;
"error creating filter '%s'\n", curfilt->filter);
goto fail;
}
avfilter_graph_add_filter(ctx, filt);
if(avfilter_init_filter(filt, curfilt->args, NULL)) {
av_log(&log_ctx, AV_LOG_ERROR,
"error initializing filter '%s'\n", curfilt->filter);
goto fail;
}
} }
avfilter_graph_add_filter(ctx, filt);
/* create all links */ if(avfilter_init_filter(filt, args, NULL)) {
for(curlink = desc->links; curlink; curlink = curlink->next) { av_log(&log_ctx, AV_LOG_ERROR,
snprintf(tmp, 20, "%d", curlink->src); "error initializing filter '%s'\n", name);
if(!(filt = avfilter_graph_get_filter(ctx, tmp))) { return -1;
av_log(&log_ctx, AV_LOG_ERROR, "link source does not exist in graph\n");
goto fail;
}
snprintf(tmp, 20, "%d", curlink->dst);
if(!(filtb = avfilter_graph_get_filter(ctx, tmp))) {
av_log(&log_ctx, AV_LOG_ERROR, "link destination does not exist in graph\n");
goto fail;
}
if(avfilter_link(filt, curlink->srcpad, filtb, curlink->dstpad)) {
av_log(&log_ctx, AV_LOG_ERROR, "cannot create link between source and destination filters\n");
goto fail;
}
} }
return 0; return 0;
}
fail: static int link_filter(AVFilterGraph *ctx, int src, int srcpad,
uninit(ctx); int dst, int dstpad)
return -1; {
AVFilterContext *filt, *filtb;
char tmp[20];
snprintf(tmp, 20, "%d", src);
if(!(filt = avfilter_graph_get_filter(ctx, tmp))) {
av_log(&log_ctx, AV_LOG_ERROR, "link source does not exist in graph\n");
return -1;
}
snprintf(tmp, 20, "%d", dst);
if(!(filtb = avfilter_graph_get_filter(ctx, tmp))) {
av_log(&log_ctx, AV_LOG_ERROR, "link destination does not exist in graph\n");
return -1;
}
if(avfilter_link(filt, srcpad, filtb, dstpad)) {
av_log(&log_ctx, AV_LOG_ERROR, "cannot create link between source and destination filters\n");
return -1;
}
return 0;
} }
int graph_load_from_desc3(AVFilterGraph *graph, AVFilterGraphDesc *desc, AVFilterContext *in, int inpad, AVFilterContext *out, int outpad) int graph_load_from_desc3(AVFilterGraph *graph, AVFilterGraphDesc *desc, AVFilterContext *in, int inpad, AVFilterContext *out, int outpad)
...@@ -216,9 +215,23 @@ int graph_load_from_desc3(AVFilterGraph *graph, AVFilterGraphDesc *desc, AVFilte ...@@ -216,9 +215,23 @@ int graph_load_from_desc3(AVFilterGraph *graph, AVFilterGraphDesc *desc, AVFilte
AVFilterGraphDescExport *curpad; AVFilterGraphDescExport *curpad;
char tmp[20]; char tmp[20];
AVFilterContext *filt; AVFilterContext *filt;
AVFilterGraphDescFilter *curfilt;
AVFilterGraphDescLink *curlink;
if (graph_load_from_desc2(graph, desc) < 0)
goto fail; /* create all filters */
for(curfilt = desc->filters; curfilt; curfilt = curfilt->next) {
if (create_filter(graph, curfilt->index, curfilt->filter,
curfilt->args) < 0)
goto fail;
}
/* create all links */
for(curlink = desc->links; curlink; curlink = curlink->next) {
if (link_filter(graph, curlink->src, curlink->srcpad,
curlink->dst, curlink->dstpad) < 0)
goto fail;
}
/* export all input pads */ /* export all input pads */
for(curpad = desc->inputs; curpad; curpad = curpad->next) { for(curpad = desc->inputs; curpad; curpad = curpad->next) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment