Originally committed as revision 12737 to svn://svn.ffmpeg.org/ffmpeg/trunk
Unified · Split
| @@ -160,55 +160,54 @@ int avfilter_graph_config_formats(AVFilterGraph *graph) · 159 unmodified lines | |||
| 160 | return 0; | 160 | return 0; |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | static int graph_load_from_desc2(AVFilterGraph *ctx, AVFilterGraphDesc *desc) | 163 | static int create_filter(AVFilterGraph *ctx, int index, char *name, |
| 164 | char *args) | ||
| 164 | { | 165 | { |
| 165 | AVFilterGraphDescFilter *curfilt; | 166 | AVFilterContext *filt; |
| 166 | AVFilterGraphDescLink *curlink; | ||
| 167 | AVFilterContext *filt, *filtb; | ||
| 168 | 167 | ||
| 169 | AVFilter *filterdef; | 168 | AVFilter *filterdef; |
| 170 | char tmp[20]; | 169 | char tmp[20]; |
| 171 | 170 | ||
| 172 | /* create all filters */ | 171 | snprintf(tmp, 20, "%d", index); |
| 173 | for(curfilt = desc->filters; curfilt; curfilt = curfilt->next) { | 172 | if(!(filterdef = avfilter_get_by_name(name)) || |
| 174 | snprintf(tmp, 20, "%d", curfilt->index); | 173 | !(filt = avfilter_open(filterdef, tmp))) { |
| 175 | if(!(filterdef = avfilter_get_by_name(curfilt->filter)) || | 174 | av_log(&log_ctx, AV_LOG_ERROR, |
| 176 | !(filt = avfilter_open(filterdef, tmp))) { | 175 | "error creating filter '%s'\n", name); |
| 177 | av_log(&log_ctx, AV_LOG_ERROR, | 176 | return -1; |
| 178 | "error creating filter '%s'\n", curfilt->filter); | ||
| 179 | goto fail; | ||
| 180 | } | ||
| 181 | avfilter_graph_add_filter(ctx, filt); | ||
| 182 | if(avfilter_init_filter(filt, curfilt->args, NULL)) { | ||
| 183 | av_log(&log_ctx, AV_LOG_ERROR, | ||
| 184 | "error initializing filter '%s'\n", curfilt->filter); | ||
| 185 | goto fail; | ||
| 186 | } | ||
| 187 | } | 177 | } |
| 188 | 178 | avfilter_graph_add_filter(ctx, filt); | |
| 189 | /* create all links */ | 179 | if(avfilter_init_filter(filt, args, NULL)) { |
| 190 | for(curlink = desc->links; curlink; curlink = curlink->next) { | 180 | av_log(&log_ctx, AV_LOG_ERROR, |
| 191 | snprintf(tmp, 20, "%d", curlink->src); | 181 | "error initializing filter '%s'\n", name); |
| 192 | if(!(filt = avfilter_graph_get_filter(ctx, tmp))) { | 182 | return -1; |
| 193 | av_log(&log_ctx, AV_LOG_ERROR, "link source does not exist in graph\n"); | ||
| 194 | goto fail; | ||
| 195 | } | ||
| 196 | snprintf(tmp, 20, "%d", curlink->dst); | ||
| 197 | if(!(filtb = avfilter_graph_get_filter(ctx, tmp))) { | ||
| 198 | av_log(&log_ctx, AV_LOG_ERROR, "link destination does not exist in graph\n"); | ||
| 199 | goto fail; | ||
| 200 | } | ||
| 201 | if(avfilter_link(filt, curlink->srcpad, filtb, curlink->dstpad)) { | ||
| 202 | av_log(&log_ctx, AV_LOG_ERROR, "cannot create link between source and destination filters\n"); | ||
| 203 | goto fail; | ||
| 204 | } | ||
| 205 | } | 183 | } |
| 206 | 184 | ||
| 207 | return 0; | 185 | return 0; |
| 186 | } | ||
| 208 | 187 | ||
| 209 | fail: | 188 | static int link_filter(AVFilterGraph *ctx, int src, int srcpad, |
| 210 | uninit(ctx); | 189 | int dst, int dstpad) |
| 211 | return -1; | 190 | { |
| 191 | AVFilterContext *filt, *filtb; | ||
| 192 | |||
| 193 | char tmp[20]; | ||
| 194 | |||
| 195 | snprintf(tmp, 20, "%d", src); | ||
| 196 | if(!(filt = avfilter_graph_get_filter(ctx, tmp))) { | ||
| 197 | av_log(&log_ctx, AV_LOG_ERROR, "link source does not exist in graph\n"); | ||
| 198 | return -1; | ||
| 199 | } | ||
| 200 | snprintf(tmp, 20, "%d", dst); | ||
| 201 | if(!(filtb = avfilter_graph_get_filter(ctx, tmp))) { | ||
| 202 | av_log(&log_ctx, AV_LOG_ERROR, "link destination does not exist in graph\n"); | ||
| 203 | return -1; | ||
| 204 | } | ||
| 205 | if(avfilter_link(filt, srcpad, filtb, dstpad)) { | ||
| 206 | av_log(&log_ctx, AV_LOG_ERROR, "cannot create link between source and destination filters\n"); | ||
| 207 | return -1; | ||
| 208 | } | ||
| 209 | |||
| 210 | return 0; | ||
| 212 | } | 211 | } |
| 213 | 212 | ||
| 214 | int graph_load_from_desc3(AVFilterGraph *graph, AVFilterGraphDesc *desc, AVFilterContext *in, int inpad, AVFilterContext *out, int outpad) | 213 | 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 · 1 unmodified line | |||
| 216 | AVFilterGraphDescExport *curpad; | 215 | AVFilterGraphDescExport *curpad; |
| 217 | char tmp[20]; | 216 | char tmp[20]; |
| 218 | AVFilterContext *filt; | 217 | AVFilterContext *filt; |
| 218 | AVFilterGraphDescFilter *curfilt; | ||
| 219 | AVFilterGraphDescLink *curlink; | ||
| 219 | 220 | ||
| 220 | if (graph_load_from_desc2(graph, desc) < 0) | 221 | |
| 221 | goto fail; | 222 | /* create all filters */ |
| 223 | for(curfilt = desc->filters; curfilt; curfilt = curfilt->next) { | ||
| 224 | if (create_filter(graph, curfilt->index, curfilt->filter, | ||
| 225 | curfilt->args) < 0) | ||
| 226 | goto fail; | ||
| 227 | } | ||
| 228 | |||
| 229 | /* create all links */ | ||
| 230 | for(curlink = desc->links; curlink; curlink = curlink->next) { | ||
| 231 | if (link_filter(graph, curlink->src, curlink->srcpad, | ||
| 232 | curlink->dst, curlink->dstpad) < 0) | ||
| 233 | goto fail; | ||
| 234 | } | ||
| 222 | 235 | ||
| 223 | /* export all input pads */ | 236 | /* export all input pads */ |
| 224 | for(curpad = desc->inputs; curpad; curpad = curpad->next) { | 237 | for(curpad = desc->inputs; curpad; curpad = curpad->next) { |