-static int graph_load_from_desc2(AVFilterContext *ctx, AVFilterGraphDesc *desc)
-{
- AVFilterGraphDescFilter *curfilt;
- AVFilterGraphDescLink *curlink;
- AVFilterContext *filt, *filtb;
-
- AVFilter *filterdef;
- char tmp[20];
-
- /* create all filters */
- for(curfilt = desc->filters; curfilt; curfilt = curfilt->next) {
- snprintf(tmp, 20, "%d", curfilt->index);
- if(!(filterdef = avfilter_get_by_name(curfilt->filter)) ||
- !(filt = avfilter_open(filterdef, tmp))) {
- av_log(ctx, AV_LOG_ERROR,
- "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(ctx, AV_LOG_ERROR,
- "error initializing filter '%s'\n", curfilt->filter);
- goto fail;
- }
- }
-
- /* create all links */
- for(curlink = desc->links; curlink; curlink = curlink->next) {
- snprintf(tmp, 20, "%d", curlink->src);
- if(!(filt = avfilter_graph_get_filter(ctx, tmp))) {
- av_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(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(ctx, AV_LOG_ERROR, "cannot create link between source and destination filters\n");
- goto fail;
- }
- }
-
- return 0;
-
-fail:
- uninit(ctx);
- return -1;
-}
-
-static int graph_load_from_desc(AVFilterContext *ctx, AVFilterGraphDesc *desc)
-{
- AVFilterGraphDescExport *curpad;
- char tmp[20];
- AVFilterContext *filt;
-
- if (graph_load_from_desc2(ctx, desc) < 0)
- goto fail;
-
- /* export all input pads */
- for(curpad = desc->inputs; curpad; curpad = curpad->next) {
- snprintf(tmp, 20, "%d", curpad->filter);
- if(!(filt = avfilter_graph_get_filter(ctx, tmp))) {
- av_log(ctx, AV_LOG_ERROR, "filter owning exported pad does not exist\n");
- goto fail;
- }
- add_graph_input(ctx, filt, curpad->pad, curpad->name);
- }
-
- /* export all output pads */
- for(curpad = desc->outputs; curpad; curpad = curpad->next) {
- snprintf(tmp, 20, "%d", curpad->filter);
- if(!(filt = avfilter_graph_get_filter(ctx, tmp))) {
- av_log(ctx, AV_LOG_ERROR, "filter owning exported pad does not exist\n");
- goto fail;
- }
- add_graph_output(ctx, filt, curpad->pad, curpad->name);
- }
-
- return 0;
-
-fail:
- uninit(ctx);
- return -1;
-}
-
-int graph_load_from_desc3(AVFilterContext *ctx, AVFilterGraphDesc *desc, AVFilterContext *in, int inpad, AVFilterContext *out, int outpad)
-{
- AVFilterGraphDescExport *curpad;
- char tmp[20];
- AVFilterContext *filt;
-
- if (graph_load_from_desc2(ctx, desc) < 0)
- goto fail;
-
- /* export all input pads */
- for(curpad = desc->inputs; curpad; curpad = curpad->next) {
- snprintf(tmp, 20, "%d", curpad->filter);
- if(!(filt = avfilter_graph_get_filter(ctx, tmp))) {
- av_log(ctx, AV_LOG_ERROR, "filter owning exported pad does not exist\n");
- goto fail;
- }
- if(avfilter_link(in, inpad, filt, curpad->pad)) {
- av_log(ctx, AV_LOG_ERROR, "cannot create link between source and destination filters\n");
- goto fail;
- }
- }
-
- /* export all output pads */
- for(curpad = desc->outputs; curpad; curpad = curpad->next) {
- snprintf(tmp, 20, "%d", curpad->filter);
- if(!(filt = avfilter_graph_get_filter(ctx, tmp))) {
- av_log(ctx, AV_LOG_ERROR, "filter owning exported pad does not exist\n");
- goto fail;
- }
-
- if(avfilter_link(filt, curpad->pad, out, outpad)) {
- av_log(ctx, AV_LOG_ERROR, "cannot create link between source and destination filters\n");
- goto fail;
- }
- }
-
- return 0;
-
-fail:
- uninit(ctx);
- return -1;
-}
-
-static int init(AVFilterContext *ctx, const char *args, void *opaque)
-{
- GraphContext *gctx = ctx->priv;
- AVFilterGraphDesc *desc;
- int ret;
-
- if(!(gctx->link_filter_in = avfilter_open(&vf_graph_dummy, NULL)))
- return -1;
- if(avfilter_init_filter(gctx->link_filter_in, NULL, ctx))
- goto fail;
- if(!(gctx->link_filter_out = avfilter_open(&vf_graph_dummy, NULL)))
- goto fail;
- if(avfilter_init_filter(gctx->link_filter_out, NULL, ctx))
- goto fail;
-
- if(!args)
- return 0;
-
- if(!(desc = avfilter_graph_parse_chain(args)))
- goto fail;
-
- ret = graph_load_from_desc(ctx, desc);
- avfilter_graph_free_desc(desc);
- return ret;
-
-fail:
- avfilter_destroy(gctx->link_filter_in);
- if(gctx->link_filter_out)
- avfilter_destroy(gctx->link_filter_out);
- return -1;
-}
-
-AVFilter avfilter_vf_graph =
-{
- .name = "graph",
-
- .priv_size = sizeof(GraphContext),
-
- .init = init,
- .uninit = uninit,
-
- .query_formats = query_formats,
-
- .inputs = (AVFilterPad[]) {{ .name = NULL, }},
- .outputs = (AVFilterPad[]) {{ .name = NULL, }},
-};
-