Make configure_filters() return a meaningful error code rather than

always -1.

Originally committed as revision 24903 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Stefano Sabatini 2010-08-24 15:48:11 +00:00
parent b3c1652b82
commit 4ddf0d2915

View File

@ -407,20 +407,21 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost)
AVCodecContext *codec = ost->st->codec; AVCodecContext *codec = ost->st->codec;
AVCodecContext *icodec = ist->st->codec; AVCodecContext *icodec = ist->st->codec;
char args[255]; char args[255];
int ret;
graph = av_mallocz(sizeof(AVFilterGraph)); graph = av_mallocz(sizeof(AVFilterGraph));
if (avfilter_open(&ist->input_video_filter, avfilter_get_by_name("buffer"), "src") < 0) if ((ret = avfilter_open(&ist->input_video_filter, avfilter_get_by_name("buffer"), "src")) < 0)
return -1; return ret;
if (avfilter_open(&ist->out_video_filter, &output_filter, "out") < 0) if ((ret = avfilter_open(&ist->out_video_filter, &output_filter, "out")) < 0)
return -1; return ret;
snprintf(args, 255, "%d:%d:%d", ist->st->codec->width, snprintf(args, 255, "%d:%d:%d", ist->st->codec->width,
ist->st->codec->height, ist->st->codec->pix_fmt); ist->st->codec->height, ist->st->codec->pix_fmt);
if (avfilter_init_filter(ist->input_video_filter, args, NULL)) if ((ret = avfilter_init_filter(ist->input_video_filter, args, NULL)) < 0)
return -1; return ret;
if (avfilter_init_filter(ist->out_video_filter, NULL, &codec->pix_fmt)) if ((ret = avfilter_init_filter(ist->out_video_filter, NULL, &codec->pix_fmt)) < 0)
return -1; return ret;
/* add input and output filters to the overall graph */ /* add input and output filters to the overall graph */
avfilter_graph_add_filter(graph, ist->input_video_filter); avfilter_graph_add_filter(graph, ist->input_video_filter);
@ -432,13 +433,12 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost)
snprintf(args, 255, "%d:%d:%d:%d", ost->leftBand, ost->topBand, snprintf(args, 255, "%d:%d:%d:%d", ost->leftBand, ost->topBand,
codec->width, codec->width,
codec->height); codec->height);
avfilter_open(&filter, avfilter_get_by_name("crop"), NULL); if ((ret = avfilter_open(&filter, avfilter_get_by_name("crop"), NULL)) < 0)
if (!filter) return ret;
return -1; if ((ret = avfilter_init_filter(filter, args, NULL)) < 0)
if (avfilter_init_filter(filter, args, NULL)) return ret;
return -1; if ((ret = avfilter_link(last_filter, 0, filter, 0)) < 0)
if (avfilter_link(last_filter, 0, filter, 0)) return ret;
return -1;
last_filter = filter; last_filter = filter;
avfilter_graph_add_filter(graph, last_filter); avfilter_graph_add_filter(graph, last_filter);
} }
@ -450,13 +450,12 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost)
codec->width, codec->width,
codec->height, codec->height,
(int)av_get_int(sws_opts, "sws_flags", NULL)); (int)av_get_int(sws_opts, "sws_flags", NULL));
avfilter_open(&filter, avfilter_get_by_name("scale"), NULL); if ((ret = avfilter_open(&filter, avfilter_get_by_name("scale"), NULL)) < 0)
if (!filter) return ret;
return -1; if ((ret = avfilter_init_filter(filter, args, NULL)) < 0)
if (avfilter_init_filter(filter, args, NULL)) return ret;
return -1; if ((ret = avfilter_link(last_filter, 0, filter, 0)) < 0)
if (avfilter_link(last_filter, 0, filter, 0)) return ret;
return -1;
last_filter = filter; last_filter = filter;
avfilter_graph_add_filter(graph, last_filter); avfilter_graph_add_filter(graph, last_filter);
} }
@ -478,21 +477,21 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost)
inputs->pad_idx = 0; inputs->pad_idx = 0;
inputs->next = NULL; inputs->next = NULL;
if (avfilter_graph_parse(graph, vfilters, inputs, outputs, NULL) < 0) if ((ret = avfilter_graph_parse(graph, vfilters, inputs, outputs, NULL)) < 0)
return -1; return ret;
av_freep(&vfilters); av_freep(&vfilters);
} else { } else {
if (avfilter_link(last_filter, 0, ist->out_video_filter, 0) < 0) if ((ret = avfilter_link(last_filter, 0, ist->out_video_filter, 0)) < 0)
return -1; return ret;
} }
/* configure all the filter links */ /* configure all the filter links */
if (avfilter_graph_check_validity(graph, NULL)) if ((ret = avfilter_graph_check_validity(graph, NULL)) < 0)
return -1; return ret;
if (avfilter_graph_config_formats(graph, NULL)) if ((ret = avfilter_graph_config_formats(graph, NULL)) < 0)
return -1; return ret;
if (avfilter_graph_config_links(graph, NULL)) if ((ret = avfilter_graph_config_links(graph, NULL)) < 0)
return -1; return ret;
codec->width = ist->out_video_filter->inputs[0]->w; codec->width = ist->out_video_filter->inputs[0]->w;
codec->height = ist->out_video_filter->inputs[0]->h; codec->height = ist->out_video_filter->inputs[0]->h;