[FFmpeg-devel] [PATCH 2/2] Make avfilter_graph_parse() return a meaningful error code, rather than always -1.
Stefano Sabatini
stefano.sabatini-lala
Thu Nov 4 22:23:11 CET 2010
---
libavfilter/graphparser.c | 46 ++++++++++++++++++++++++--------------------
1 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
index fb70805..1ba465a 100644
--- a/libavfilter/graphparser.c
+++ b/libavfilter/graphparser.c
@@ -196,6 +196,7 @@ static int link_filter_inouts(AVFilterContext *filter,
AVFilterInOut **open_inputs, AVClass *log_ctx)
{
int pad = filter->input_count;
+ int ret;
while (pad--) {
AVFilterInOut *p = *curr_inputs;
@@ -203,14 +204,14 @@ static int link_filter_inouts(AVFilterContext *filter,
av_log(log_ctx, AV_LOG_ERROR,
"Not enough inputs specified for the \"%s\" filter.\n",
filter->filter->name);
- return -1;
+ return AVERROR(EINVAL);
}
*curr_inputs = (*curr_inputs)->next;
if (p->filter) {
- if (link_filter(p->filter, p->pad_idx, filter, pad, log_ctx))
- return -1;
+ if ((ret = link_filter(p->filter, p->pad_idx, filter, pad, log_ctx)) < 0)
+ return ret;
av_free(p->name);
av_free(p);
} else {
@@ -224,7 +225,7 @@ static int link_filter_inouts(AVFilterContext *filter,
av_log(log_ctx, AV_LOG_ERROR,
"Too many inputs specified for the \"%s\" filter.\n",
filter->filter->name);
- return -1;
+ return AVERROR(EINVAL);
}
pad = filter->output_count;
@@ -248,7 +249,7 @@ static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs,
AVFilterInOut *match;
if (!name)
- return -1;
+ return AVERROR(EINVAL);
/* First check if the label is not in the open_outputs list */
match = extract_inout(name, open_outputs);
@@ -275,7 +276,7 @@ static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs,
AVFilterInOut **open_inputs,
AVFilterInOut **open_outputs, AVClass *log_ctx)
{
- int pad = 0;
+ int ret, pad = 0;
while (**buf == '[') {
char *name = parse_link_name(buf, log_ctx);
@@ -285,15 +286,15 @@ static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs,
*curr_inputs = (*curr_inputs)->next;
if (!name)
- return -1;
+ return AVERROR(EINVAL);
/* First check if the label is not in the open_inputs list */
match = extract_inout(name, open_inputs);
if (match) {
- if (link_filter(input->filter, input->pad_idx,
- match->filter, match->pad_idx, log_ctx) < 0)
- return -1;
+ if ((ret = link_filter(input->filter, input->pad_idx,
+ match->filter, match->pad_idx, log_ctx)) < 0)
+ return ret;
av_free(match->name);
av_free(name);
av_free(match);
@@ -314,7 +315,7 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
AVFilterInOut *open_inputs,
AVFilterInOut *open_outputs, AVClass *log_ctx)
{
- int index = 0;
+ int index = 0, ret = 0;
char chr = 0;
AVFilterInOut *curr_inputs = NULL;
@@ -323,26 +324,27 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
AVFilterContext *filter;
filters += strspn(filters, WHITESPACES);
- if (parse_inputs(&filters, &curr_inputs, &open_outputs, log_ctx) < 0)
+ if ((ret = parse_inputs(&filters, &curr_inputs, &open_outputs, log_ctx)) < 0)
goto fail;
filter = parse_filter(&filters, graph, index, log_ctx);
-
- if (!filter)
+ if (!filter) {
+ ret = AVERROR(EINVAL);
goto fail;
+ }
if (filter->input_count == 1 && !curr_inputs && !index) {
/* First input can be omitted if it is "[in]" */
const char *tmp = "[in]";
- if(parse_inputs(&tmp, &curr_inputs, &open_outputs, log_ctx) < 0)
+ if ((ret = parse_inputs(&tmp, &curr_inputs, &open_outputs, log_ctx)) < 0)
goto fail;
}
- if (link_filter_inouts(filter, &curr_inputs, &open_inputs, log_ctx) < 0)
+ if ((ret = link_filter_inouts(filter, &curr_inputs, &open_inputs, log_ctx)) < 0)
goto fail;
- if (parse_outputs(&filters, &curr_inputs, &open_inputs, &open_outputs,
- log_ctx) < 0)
+ if ((ret = parse_outputs(&filters, &curr_inputs, &open_inputs, &open_outputs,
+ log_ctx)) < 0)
goto fail;
filters += strspn(filters, WHITESPACES);
@@ -352,6 +354,7 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
av_log(log_ctx, AV_LOG_ERROR,
"Could not find a output to link when parsing \"%s\"\n",
filters - 1);
+ ret = AVERROR(EINVAL);
goto fail;
}
index++;
@@ -361,14 +364,15 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
av_log(log_ctx, AV_LOG_ERROR,
"Unable to parse graph description substring: \"%s\"\n",
filters - 1);
+ ret = AVERROR(EINVAL);
goto fail;
}
if (open_inputs && !strcmp(open_inputs->name, "out") && curr_inputs) {
/* Last output can be omitted if it is "[out]" */
const char *tmp = "[out]";
- if (parse_outputs(&tmp, &curr_inputs, &open_inputs,
- &open_outputs, log_ctx) < 0)
+ if ((ret = parse_outputs(&tmp, &curr_inputs, &open_inputs, &open_outputs,
+ log_ctx)) < 0)
goto fail;
}
@@ -379,5 +383,5 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
free_inout(open_inputs);
free_inout(open_outputs);
free_inout(curr_inputs);
- return -1;
+ return ret;
}
--
1.7.1
More information about the ffmpeg-devel
mailing list