Originally committed as revision 12732 to svn://svn.ffmpeg.org/ffmpeg/trunk
Showing the changes to libavfilter/avfiltergraph.c (1 of 1 file). Show all
Unified · Split
| @@ -53,43 +53,6 @@ static inline AVFilterLink *get_extern_input_link(AVFilterLink *link) · 52 unmodified lines | |||
| 53 | return lctx->graph->inputs[link->srcpad]; | 53 | return lctx->graph->inputs[link->srcpad]; |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | /** request a frame from a filter providing input to the graph */ | ||
| 57 | static int link_in_request_frame(AVFilterLink *link) | ||
| 58 | { | ||
| 59 | AVFilterLink *link2 = get_extern_input_link(link); | ||
| 60 | |||
| 61 | if(!link2) | ||
| 62 | return -1; | ||
| 63 | return avfilter_request_frame(link2); | ||
| 64 | } | ||
| 65 | |||
| 66 | |||
| 67 | static int link_in_poll_frame(AVFilterLink *link) | ||
| 68 | { | ||
| 69 | AVFilterLink *link2 = get_extern_input_link(link); | ||
| 70 | if(!link2) | ||
| 71 | return -1; | ||
| 72 | return avfilter_poll_frame(link2); | ||
| 73 | } | ||
| 74 | |||
| 75 | static int link_in_config_props(AVFilterLink *link) | ||
| 76 | { | ||
| 77 | AVFilterLink *link2 = get_extern_input_link(link); | ||
| 78 | int (*config_props)(AVFilterLink *); | ||
| 79 | int ret; | ||
| 80 | |||
| 81 | if(!link2) | ||
| 82 | return -1; | ||
| 83 | if(!(config_props = link2->src->output_pads[link2->srcpad].config_props)) | ||
| 84 | config_props = avfilter_default_config_output_link; | ||
| 85 | ret = config_props(link2); | ||
| 86 | |||
| 87 | link->w = link2->w; | ||
| 88 | link->h = link2->h; | ||
| 89 | |||
| 90 | return ret; | ||
| 91 | } | ||
| 92 | |||
| 93 | /** | 56 | /** |
| 94 | * Given the link between the dummy filter and an internal filter whose output | 57 | * Given the link between the dummy filter and an internal filter whose output |
| 95 | * is being exported outside the graph, this returns the externally visible | 58 | * is being exported outside the graph, this returns the externally visible |
| @@ -101,54 +64,6 @@ static inline AVFilterLink *get_extern_output_link(AVFilterLink *link) · 5 unmodified lines | |||
| 101 | return lctx->graph->outputs[link->dstpad]; | 64 | return lctx->graph->outputs[link->dstpad]; |
| 102 | } | 65 | } |
| 103 | 66 | ||
| 104 | static int link_out_config_props(AVFilterLink *link) | ||
| 105 | { | ||
| 106 | AVFilterLink *link2 = get_extern_output_link(link); | ||
| 107 | |||
| 108 | if(!link2) | ||
| 109 | return 0; | ||
| 110 | |||
| 111 | link2->w = link->w; | ||
| 112 | link2->h = link->h; | ||
| 113 | |||
| 114 | return 0; | ||
| 115 | } | ||
| 116 | |||
| 117 | static void link_out_start_frame(AVFilterLink *link, AVFilterPicRef *picref) | ||
| 118 | { | ||
| 119 | AVFilterLink *link2 = get_extern_output_link(link); | ||
| 120 | |||
| 121 | if(!link2) | ||
| 122 | avfilter_unref_pic(picref); | ||
| 123 | else | ||
| 124 | avfilter_start_frame(link2, picref); | ||
| 125 | } | ||
| 126 | |||
| 127 | static void link_out_end_frame(AVFilterLink *link) | ||
| 128 | { | ||
| 129 | AVFilterLink *link2 = get_extern_output_link(link); | ||
| 130 | |||
| 131 | if(link2) | ||
| 132 | avfilter_end_frame(link2); | ||
| 133 | } | ||
| 134 | |||
| 135 | static AVFilterPicRef *link_out_get_video_buffer(AVFilterLink *link, int perms) | ||
| 136 | { | ||
| 137 | AVFilterLink *link2 = get_extern_output_link(link); | ||
| 138 | |||
| 139 | if(!link2) | ||
| 140 | return NULL; | ||
| 141 | else | ||
| 142 | return avfilter_get_video_buffer(link2, perms); | ||
| 143 | } | ||
| 144 | |||
| 145 | static void link_out_draw_slice(AVFilterLink *link, int y, int height) | ||
| 146 | { | ||
| 147 | AVFilterLink *link2 = get_extern_output_link(link); | ||
| 148 | |||
| 149 | if(link2) | ||
| 150 | avfilter_draw_slice(link2, y, height); | ||
| 151 | } | ||
| 152 | 67 | ||
| 153 | /** dummy filter used to help export filters pads outside the graph */ | 68 | /** dummy filter used to help export filters pads outside the graph */ |
| 154 | static AVFilter vf_graph_dummy = | 69 | static AVFilter vf_graph_dummy = |
| @@ -163,173 +78,6 @@ static AVFilter vf_graph_dummy = · 8 unmodified lines | |||
| 163 | .outputs = (AVFilterPad[]) {{ .name = NULL, }}, | 78 | .outputs = (AVFilterPad[]) {{ .name = NULL, }}, |
| 164 | }; | 79 | }; |
| 165 | 80 | ||
| 166 | static AVFilterLink *get_intern_input_link(AVFilterLink *link) | ||
| 167 | { | ||
| 168 | GraphContext *graph = link->dst->priv; | ||
| 169 | return graph->link_filter_in->outputs[link->dstpad]; | ||
| 170 | } | ||
| 171 | |||
| 172 | static void graph_in_start_frame(AVFilterLink *link, AVFilterPicRef *picref) | ||
| 173 | { | ||
| 174 | AVFilterLink *link2 = get_intern_input_link(link); | ||
| 175 | if(link2) | ||
| 176 | avfilter_start_frame(link2, picref); | ||
| 177 | } | ||
| 178 | |||
| 179 | static void graph_in_end_frame(AVFilterLink *link) | ||
| 180 | { | ||
| 181 | AVFilterLink *link2 = get_intern_input_link(link); | ||
| 182 | if(link2) | ||
| 183 | avfilter_end_frame(link2); | ||
| 184 | } | ||
| 185 | |||
| 186 | static AVFilterPicRef *graph_in_get_video_buffer(AVFilterLink *link, int perms) | ||
| 187 | { | ||
| 188 | AVFilterLink *link2 = get_intern_input_link(link); | ||
| 189 | if(link2) | ||
| 190 | return avfilter_get_video_buffer(link2, perms); | ||
| 191 | return NULL; | ||
| 192 | } | ||
| 193 | |||
| 194 | static void graph_in_draw_slice(AVFilterLink *link, int y, int height) | ||
| 195 | { | ||
| 196 | AVFilterLink *link2 = get_intern_input_link(link); | ||
| 197 | if(link2) | ||
| 198 | avfilter_draw_slice(link2, y, height); | ||
| 199 | } | ||
| 200 | |||
| 201 | static int graph_in_config_props(AVFilterLink *link) | ||
| 202 | { | ||
| 203 | AVFilterLink *link2 = get_intern_input_link(link); | ||
| 204 | int (*config_props)(AVFilterLink *); | ||
| 205 | int ret; | ||
| 206 | |||
| 207 | if(!link2) | ||
| 208 | return -1; | ||
| 209 | |||
| 210 | /* copy link properties over to the dummy internal link */ | ||
| 211 | link2->w = link->w; | ||
| 212 | link2->h = link->h; | ||
| 213 | link2->format = link->format; | ||
| 214 | |||
| 215 | if(!(config_props = link2->dst->input_pads[link2->dstpad].config_props)) | ||
| 216 | return 0; /* FIXME? */ | ||
| 217 | //config_props = avfilter_default_config_input_link; | ||
| 218 | if(!(ret = config_props(link2))) | ||
| 219 | link2->init_state = AVLINK_INIT; | ||
| 220 | else | ||
| 221 | link2->init_state = AVLINK_STARTINIT; | ||
| 222 | |||
| 223 | return ret; | ||
| 224 | } | ||
| 225 | |||
| 226 | static AVFilterLink *get_intern_output_link(AVFilterLink *link) | ||
| 227 | { | ||
| 228 | GraphContext *graph = link->src->priv; | ||
| 229 | return graph->link_filter_out->inputs[link->srcpad]; | ||
| 230 | } | ||
| 231 | |||
| 232 | static int graph_out_request_frame(AVFilterLink *link) | ||
| 233 | { | ||
| 234 | AVFilterLink *link2 = get_intern_output_link(link); | ||
| 235 | |||
| 236 | if(link2) | ||
| 237 | return avfilter_request_frame(link2); | ||
| 238 | return -1; | ||
| 239 | } | ||
| 240 | |||
| 241 | static int graph_out_poll_frame(AVFilterLink *link) | ||
| 242 | { | ||
| 243 | AVFilterLink *link2 = get_intern_output_link(link); | ||
| 244 | |||
| 245 | if(!link2) | ||
| 246 | return -1; | ||
| 247 | |||
| 248 | return avfilter_poll_frame(link2); | ||
| 249 | } | ||
| 250 | |||
| 251 | static int graph_out_config_props(AVFilterLink *link) | ||
| 252 | { | ||
| 253 | GraphContext *graph = link->src->priv; | ||
| 254 | AVFilterLink *link2 = graph->link_filter_out->inputs[link->srcpad]; | ||
| 255 | int ret; | ||
| 256 | |||
| 257 | if((ret = avfilter_config_links(graph->link_filter_out))) | ||
| 258 | return ret; | ||
| 259 | |||
| 260 | if(!link2) | ||
| 261 | return 0; | ||
| 262 | |||
| 263 | link->w = link2->w; | ||
| 264 | link->h = link2->h; | ||
| 265 | link->format = link2->format; | ||
| 266 | |||
| 267 | return 0; | ||
| 268 | } | ||
| 269 | |||
| 270 | static int add_graph_input(AVFilterContext *gctx, AVFilterContext *filt, unsigned idx, | ||
| 271 | char *name) | ||
| 272 | { | ||
| 273 | GraphContext *graph = gctx->priv; | ||
| 274 | |||
| 275 | AVFilterPad graph_inpad = | ||
| 276 | { | ||
| 277 | .name = name, | ||
| 278 | .type = CODEC_TYPE_VIDEO, | ||
| 279 | .start_frame = graph_in_start_frame, | ||
| 280 | .end_frame = graph_in_end_frame, | ||
| 281 | .get_video_buffer = graph_in_get_video_buffer, | ||
| 282 | .draw_slice = graph_in_draw_slice, | ||
| 283 | .config_props = graph_in_config_props, | ||
| 284 | /* XXX */ | ||
| 285 | }; | ||
| 286 | AVFilterPad dummy_outpad = | ||
| 287 | { | ||
| 288 | .name = NULL, /* FIXME? */ | ||
| 289 | .type = CODEC_TYPE_VIDEO, | ||
| 290 | .request_frame = link_in_request_frame, | ||
| 291 | .poll_frame = link_in_poll_frame, | ||
| 292 | .config_props = link_in_config_props, | ||
| 293 | }; | ||
| 294 | |||
| 295 | avfilter_insert_inpad (gctx, gctx->input_count, &graph_inpad); | ||
| 296 | avfilter_insert_outpad(graph->link_filter_in, graph->link_filter_in->output_count, | ||
| 297 | &dummy_outpad); | ||
| 298 | return avfilter_link(graph->link_filter_in, | ||
| 299 | graph->link_filter_in->output_count-1, filt, idx); | ||
| 300 | } | ||
| 301 | |||
| 302 | static int add_graph_output(AVFilterContext *gctx, AVFilterContext *filt, unsigned idx, | ||
| 303 | char *name) | ||
| 304 | { | ||
| 305 | GraphContext *graph = gctx->priv; | ||
| 306 | |||
| 307 | AVFilterPad graph_outpad = | ||
| 308 | { | ||
| 309 | .name = name, | ||
| 310 | .type = CODEC_TYPE_VIDEO, | ||
| 311 | .request_frame = graph_out_request_frame, | ||
| 312 | .poll_frame = graph_out_poll_frame, | ||
| 313 | .config_props = graph_out_config_props, | ||
| 314 | }; | ||
| 315 | AVFilterPad dummy_inpad = | ||
| 316 | { | ||
| 317 | .name = NULL, /* FIXME? */ | ||
| 318 | .type = CODEC_TYPE_VIDEO, | ||
| 319 | .start_frame = link_out_start_frame, | ||
| 320 | .end_frame = link_out_end_frame, | ||
| 321 | .draw_slice = link_out_draw_slice, | ||
| 322 | .get_video_buffer = link_out_get_video_buffer, | ||
| 323 | .config_props = link_out_config_props, | ||
| 324 | }; | ||
| 325 | |||
| 326 | avfilter_insert_outpad(gctx, gctx->output_count, &graph_outpad); | ||
| 327 | avfilter_insert_inpad (graph->link_filter_out, graph->link_filter_out->input_count, | ||
| 328 | &dummy_inpad); | ||
| 329 | return avfilter_link(filt, idx, graph->link_filter_out, | ||
| 330 | graph->link_filter_out->input_count-1); | ||
| 331 | } | ||
| 332 | |||
| 333 | static void uninit(AVFilterContext *ctx) | 81 | static void uninit(AVFilterContext *ctx) |
| 334 | { | 82 | { |
| 335 | GraphContext *graph = ctx->priv; | 83 | GraphContext *graph = ctx->priv; |
| @@ -539,42 +287,6 @@ fail: · 203 unmodified lines | |||
| 539 | return -1; | 287 | return -1; |
| 540 | } | 288 | } |
| 541 | 289 | ||
| 542 | static int graph_load_from_desc(AVFilterContext *ctx, AVFilterGraphDesc *desc) | ||
| 543 | { | ||
| 544 | AVFilterGraphDescExport *curpad; | ||
| 545 | char tmp[20]; | ||
| 546 | AVFilterContext *filt; | ||
| 547 | |||
| 548 | if (graph_load_from_desc2(ctx, desc) < 0) | ||
| 549 | goto fail; | ||
| 550 | |||
| 551 | /* export all input pads */ | ||
| 552 | for(curpad = desc->inputs; curpad; curpad = curpad->next) { | ||
| 553 | snprintf(tmp, 20, "%d", curpad->filter); | ||
| 554 | if(!(filt = avfilter_graph_get_filter(ctx, tmp))) { | ||
| 555 | av_log(ctx, AV_LOG_ERROR, "filter owning exported pad does not exist\n"); | ||
| 556 | goto fail; | ||
| 557 | } | ||
| 558 | add_graph_input(ctx, filt, curpad->pad, curpad->name); | ||
| 559 | } | ||
| 560 | |||
| 561 | /* export all output pads */ | ||
| 562 | for(curpad = desc->outputs; curpad; curpad = curpad->next) { | ||
| 563 | snprintf(tmp, 20, "%d", curpad->filter); | ||
| 564 | if(!(filt = avfilter_graph_get_filter(ctx, tmp))) { | ||
| 565 | av_log(ctx, AV_LOG_ERROR, "filter owning exported pad does not exist\n"); | ||
| 566 | goto fail; | ||
| 567 | } | ||
| 568 | add_graph_output(ctx, filt, curpad->pad, curpad->name); | ||
| 569 | } | ||
| 570 | |||
| 571 | return 0; | ||
| 572 | |||
| 573 | fail: | ||
| 574 | uninit(ctx); | ||
| 575 | return -1; | ||
| 576 | } | ||
| 577 | |||
| 578 | int graph_load_from_desc3(AVFilterContext *ctx, AVFilterGraphDesc *desc, AVFilterContext *in, int inpad, AVFilterContext *out, int outpad) | 290 | int graph_load_from_desc3(AVFilterContext *ctx, AVFilterGraphDesc *desc, AVFilterContext *in, int inpad, AVFilterContext *out, int outpad) |
| 579 | { | 291 | { |
| 580 | AVFilterGraphDescExport *curpad; | 292 | AVFilterGraphDescExport *curpad; |
| @@ -621,8 +333,6 @@ fail: · 40 unmodified lines | |||
| 621 | static int init(AVFilterContext *ctx, const char *args, void *opaque) | 333 | static int init(AVFilterContext *ctx, const char *args, void *opaque) |
| 622 | { | 334 | { |
| 623 | GraphContext *gctx = ctx->priv; | 335 | GraphContext *gctx = ctx->priv; |
| 624 | AVFilterGraphDesc *desc; | ||
| 625 | int ret; | ||
| 626 | 336 | ||
| 627 | if(!(gctx->link_filter_in = avfilter_open(&vf_graph_dummy, NULL))) | 337 | if(!(gctx->link_filter_in = avfilter_open(&vf_graph_dummy, NULL))) |
| 628 | return -1; | 338 | return -1; |
| @@ -633,15 +343,7 @@ static int init(AVFilterContext *ctx, const char *args, void *opaque) · 4 unmodified lines | |||
| 633 | if(avfilter_init_filter(gctx->link_filter_out, NULL, ctx)) | 343 | if(avfilter_init_filter(gctx->link_filter_out, NULL, ctx)) |
| 634 | goto fail; | 344 | goto fail; |
| 635 | 345 | ||
| 636 | if(!args) | 346 | return 0; |
| 637 | return 0; | ||
| 638 | |||
| 639 | if(!(desc = avfilter_graph_parse_chain(args))) | ||
| 640 | goto fail; | ||
| 641 | |||
| 642 | ret = graph_load_from_desc(ctx, desc); | ||
| 643 | avfilter_graph_free_desc(desc); | ||
| 644 | return ret; | ||
| 645 | 347 | ||
| 646 | fail: | 348 | fail: |
| 647 | avfilter_destroy(gctx->link_filter_in); | 349 | avfilter_destroy(gctx->link_filter_in); |