Almost from scratch rewrite of filter parser.
Functional as is, but still work-in-progress in the sense that some things need to be fixed before sending it as a patch to SVN. Commited in SoC by Vitor Sessak on 2008-03-20 21:48:30 Originally committed as revision 12729 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
@@ -463,9 +463,7 @@ static void pick_formats(GraphContext *graph)
|
|||||||
for(i = 0; i < graph->filter_count; i ++) {
|
for(i = 0; i < graph->filter_count; i ++) {
|
||||||
AVFilterContext *filter = graph->filters[i];
|
AVFilterContext *filter = graph->filters[i];
|
||||||
|
|
||||||
if(filter->filter == &avfilter_vf_graph ||
|
if(filter->filter == &avfilter_vf_graph)
|
||||||
filter->filter == &avfilter_vf_graphfile ||
|
|
||||||
filter->filter == &avfilter_vf_graphdesc)
|
|
||||||
pick_formats(filter->priv);
|
pick_formats(filter->priv);
|
||||||
|
|
||||||
for(j = 0; j < filter->input_count; j ++)
|
for(j = 0; j < filter->input_count; j ++)
|
||||||
@@ -498,30 +496,34 @@ static int graph_load_from_desc(AVFilterContext *ctx, AVFilterGraphDesc *desc)
|
|||||||
AVFilterContext *filt, *filtb;
|
AVFilterContext *filt, *filtb;
|
||||||
|
|
||||||
AVFilter *filterdef;
|
AVFilter *filterdef;
|
||||||
|
char tmp[20];
|
||||||
|
|
||||||
/* create all filters */
|
/* create all filters */
|
||||||
for(curfilt = desc->filters; curfilt; curfilt = curfilt->next) {
|
for(curfilt = desc->filters; curfilt; curfilt = curfilt->next) {
|
||||||
|
snprintf(tmp, 20, "%d", curfilt->index);
|
||||||
if(!(filterdef = avfilter_get_by_name(curfilt->filter)) ||
|
if(!(filterdef = avfilter_get_by_name(curfilt->filter)) ||
|
||||||
!(filt = avfilter_open(filterdef, curfilt->name))) {
|
!(filt = avfilter_open(filterdef, tmp))) {
|
||||||
av_log(ctx, AV_LOG_ERROR,
|
av_log(ctx, AV_LOG_ERROR,
|
||||||
"error creating filter '%s'\n", curfilt->name);
|
"error creating filter '%s'\n", curfilt->filter);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
avfilter_graph_add_filter(ctx, filt);
|
avfilter_graph_add_filter(ctx, filt);
|
||||||
if(avfilter_init_filter(filt, curfilt->args, NULL)) {
|
if(avfilter_init_filter(filt, curfilt->args, NULL)) {
|
||||||
av_log(ctx, AV_LOG_ERROR,
|
av_log(ctx, AV_LOG_ERROR,
|
||||||
"error initializing filter '%s'\n", curfilt->name);
|
"error initializing filter '%s'\n", curfilt->filter);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create all links */
|
/* create all links */
|
||||||
for(curlink = desc->links; curlink; curlink = curlink->next) {
|
for(curlink = desc->links; curlink; curlink = curlink->next) {
|
||||||
if(!(filt = avfilter_graph_get_filter(ctx, curlink->src))) {
|
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");
|
av_log(ctx, AV_LOG_ERROR, "link source does not exist in graph\n");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if(!(filtb = avfilter_graph_get_filter(ctx, curlink->dst))) {
|
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");
|
av_log(ctx, AV_LOG_ERROR, "link destination does not exist in graph\n");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@@ -533,7 +535,8 @@ static int graph_load_from_desc(AVFilterContext *ctx, AVFilterGraphDesc *desc)
|
|||||||
|
|
||||||
/* export all input pads */
|
/* export all input pads */
|
||||||
for(curpad = desc->inputs; curpad; curpad = curpad->next) {
|
for(curpad = desc->inputs; curpad; curpad = curpad->next) {
|
||||||
if(!(filt = avfilter_graph_get_filter(ctx, curpad->filter))) {
|
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");
|
av_log(ctx, AV_LOG_ERROR, "filter owning exported pad does not exist\n");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@@ -542,7 +545,8 @@ static int graph_load_from_desc(AVFilterContext *ctx, AVFilterGraphDesc *desc)
|
|||||||
|
|
||||||
/* export all output pads */
|
/* export all output pads */
|
||||||
for(curpad = desc->outputs; curpad; curpad = curpad->next) {
|
for(curpad = desc->outputs; curpad; curpad = curpad->next) {
|
||||||
if(!(filt = avfilter_graph_get_filter(ctx, curpad->filter))) {
|
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");
|
av_log(ctx, AV_LOG_ERROR, "filter owning exported pad does not exist\n");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@@ -603,73 +607,3 @@ AVFilter avfilter_vf_graph =
|
|||||||
.outputs = (AVFilterPad[]) {{ .name = NULL, }},
|
.outputs = (AVFilterPad[]) {{ .name = NULL, }},
|
||||||
};
|
};
|
||||||
|
|
||||||
static int init_desc(AVFilterContext *ctx, const char *args, void *opaque)
|
|
||||||
{
|
|
||||||
GraphContext *gctx = ctx->priv;
|
|
||||||
|
|
||||||
if(!opaque)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
return graph_load_from_desc(ctx, opaque);
|
|
||||||
|
|
||||||
fail:
|
|
||||||
avfilter_destroy(gctx->link_filter_in);
|
|
||||||
if(gctx->link_filter_out)
|
|
||||||
avfilter_destroy(gctx->link_filter_out);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
AVFilter avfilter_vf_graphdesc =
|
|
||||||
{
|
|
||||||
.name = "graph_desc",
|
|
||||||
|
|
||||||
.priv_size = sizeof(GraphContext),
|
|
||||||
|
|
||||||
.init = init_desc,
|
|
||||||
.uninit = uninit,
|
|
||||||
|
|
||||||
.query_formats = query_formats,
|
|
||||||
|
|
||||||
.inputs = (AVFilterPad[]) {{ .name = NULL, }},
|
|
||||||
.outputs = (AVFilterPad[]) {{ .name = NULL, }},
|
|
||||||
};
|
|
||||||
|
|
||||||
static int init_file(AVFilterContext *ctx, const char *args, void *opaque)
|
|
||||||
{
|
|
||||||
AVFilterGraphDesc *desc;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if(!args)
|
|
||||||
return -1;
|
|
||||||
if(!(desc = avfilter_graph_load_desc(args)))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
ret = init_desc(ctx, NULL, desc);
|
|
||||||
avfilter_graph_free_desc(desc);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
AVFilter avfilter_vf_graphfile =
|
|
||||||
{
|
|
||||||
.name = "graph_file",
|
|
||||||
|
|
||||||
.priv_size = sizeof(GraphContext),
|
|
||||||
|
|
||||||
.init = init_file,
|
|
||||||
.uninit = uninit,
|
|
||||||
|
|
||||||
.query_formats = query_formats,
|
|
||||||
|
|
||||||
.inputs = (AVFilterPad[]) {{ .name = NULL, }},
|
|
||||||
.outputs = (AVFilterPad[]) {{ .name = NULL, }},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
/** Linked-list of filters to create for an AVFilterGraphDesc */
|
/** Linked-list of filters to create for an AVFilterGraphDesc */
|
||||||
typedef struct AVFilterGraphDescFilter
|
typedef struct AVFilterGraphDescFilter
|
||||||
{
|
{
|
||||||
char *name; ///< filter instance name
|
int index; ///< filter instance index
|
||||||
char *filter; ///< name of filter type
|
char *filter; ///< name of filter type
|
||||||
char *args; ///< filter parameters
|
char *args; ///< filter parameters
|
||||||
struct AVFilterGraphDescFilter *next;
|
struct AVFilterGraphDescFilter *next;
|
||||||
@@ -37,10 +37,10 @@ typedef struct AVFilterGraphDescFilter
|
|||||||
typedef struct AVFilterGraphDescLink
|
typedef struct AVFilterGraphDescLink
|
||||||
{
|
{
|
||||||
/* TODO: allow referencing pads by name, not just by index */
|
/* TODO: allow referencing pads by name, not just by index */
|
||||||
char *src; ///< name of the source filter
|
int src; ///< index of the source filter
|
||||||
unsigned srcpad; ///< index of the output pad on the source filter
|
unsigned srcpad; ///< index of the output pad on the source filter
|
||||||
|
|
||||||
char *dst; ///< name of the dest filter
|
int dst; ///< index of the dest filter
|
||||||
unsigned dstpad; ///< index of the input pad on the dest filter
|
unsigned dstpad; ///< index of the input pad on the dest filter
|
||||||
|
|
||||||
struct AVFilterGraphDescLink *next;
|
struct AVFilterGraphDescLink *next;
|
||||||
@@ -51,7 +51,7 @@ typedef struct AVFilterGraphDescExport
|
|||||||
{
|
{
|
||||||
/* TODO: allow referencing pads by name, not just by index */
|
/* TODO: allow referencing pads by name, not just by index */
|
||||||
char *name; ///< name of the exported pad
|
char *name; ///< name of the exported pad
|
||||||
char *filter; ///< name of the filter
|
int filter; ///< index of the filter
|
||||||
unsigned pad; ///< index of the pad to be exported
|
unsigned pad; ///< index of the pad to be exported
|
||||||
|
|
||||||
struct AVFilterGraphDescExport *next;
|
struct AVFilterGraphDescExport *next;
|
||||||
|
Reference in New Issue
Block a user