-#include "allfilters.h"
-
-typedef struct AVFilterGraph {
- unsigned filter_count;
- AVFilterContext **filters;
-
- /** fake filter to handle links to internal filters */
- AVFilterContext *link_filter;
-} GraphContext;
-
-typedef struct {
- AVFilterContext *graph;
-} GraphLinkContext;
-
-static int link_init(AVFilterContext *ctx, const char *args, void *opaque)
-{
- GraphLinkContext *linkctx = ctx->priv;
- linkctx->graph = opaque;
- return !opaque;
-}
-
-/* given the link between the dummy filter and an internal filter whose input
- * is being exported outside the graph, this returns the externally visible
- * link */
-static inline AVFilterLink *get_extern_input_link(AVFilterLink *link)
-{
- GraphLinkContext *lctx = link->src->priv;
- return lctx->graph->inputs[link->srcpad];
-}
-
-/** query the formats supported by a filter providing input to the graph */
-static int *link_in_query_formats(AVFilterLink *link)
-{
- AVFilterLink *link2 = get_extern_input_link(link);
- int *(*query_formats)(AVFilterLink *);
-
- if(!link2)
- return avfilter_make_format_list(0);
-
- if(!(query_formats = link2->src->output_pads[link2->srcpad].query_formats))
- query_formats = avfilter_default_query_output_formats;
-
- return query_formats(link2);
-}
-
-/** request a frame from a filter providing input to the graph */
-static int link_in_request_frame(AVFilterLink *link)
-{
- AVFilterLink *link2 = get_extern_input_link(link);
-
- if(!link2)
- return -1;
- return avfilter_request_frame(link2);
-}
-
-static int link_in_config_props(AVFilterLink *link)
-{
- AVFilterLink *link2 = get_extern_input_link(link);
- int (*config_props)(AVFilterLink *);
- int ret;
-
- if(!link2)
- return -1;
- if(!(config_props = link2->src->output_pads[link2->srcpad].config_props))
- config_props = avfilter_default_config_output_link;
- ret = config_props(link2);
-
- link->w = link2->w;
- link->h = link2->h;
-
- return ret;
-}
-
-/* given the link between the dummy filter and an internal filter whose input
- * is being exported outside the graph, this returns the externally visible
- * link */
-static inline AVFilterLink *get_extern_output_link(AVFilterLink *link)
-{
- GraphLinkContext *lctx = link->dst->priv;
- return lctx->graph->outputs[link->dstpad];
-}
-
-/** query the formats supported by a filter taking output from the graph */
-static int *link_out_query_formats(AVFilterLink *link)
-{
- AVFilterLink *link2 = get_extern_output_link(link);
-
- if(!link2)
- return avfilter_make_format_list(0);
-
- return link2->dst->input_pads[link2->dstpad].query_formats(link2);
-}
-
-static int link_out_config_props(AVFilterLink *link)
-{
- AVFilterLink *link2 = get_extern_output_link(link);
- int (*config_props)(AVFilterLink *);
-
- if(!link2)
- return 0;
-
- link2->w = link->w;
- link2->h = link->h;
-
- if(!(config_props = link2->dst->input_pads[link2->dstpad].config_props))
- config_props = avfilter_default_config_input_link;
- return config_props(link2);
-}
-
-static void link_out_start_frame(AVFilterLink *link, AVFilterPicRef *picref)
-{
- AVFilterLink *link2 = get_extern_output_link(link);
-
- if(!link2)
- avfilter_unref_pic(picref);
- else
- avfilter_start_frame(link2, picref);
-}
-
-static void link_out_end_frame(AVFilterLink *link)