diff options
author | Anton Khirnov <anton@khirnov.net> | 2023-07-13 15:11:07 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2023-07-20 20:40:26 +0200 |
commit | 5ba7aa2ce821b39b665fd0ef1e1c236814f3438a (patch) | |
tree | 067c52f1897bc3208dbd3fe0a31654d7f32ad36f /fftools/ffmpeg_filter.c | |
parent | 8db96808bc034ddd007ad5e861d3ce536d9b9514 (diff) | |
download | ffmpeg-5ba7aa2ce821b39b665fd0ef1e1c236814f3438a.tar.gz |
fftools/ffmpeg_filter: return error codes from fg_create() instead of aborting
Diffstat (limited to 'fftools/ffmpeg_filter.c')
-rw-r--r-- | fftools/ffmpeg_filter.c | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index c7e2af494f..378a6c6871 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -538,16 +538,11 @@ static char *describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in) AVFilterContext *ctx = inout->filter_ctx; AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads; int nb_pads = in ? ctx->nb_inputs : ctx->nb_outputs; - char *res; if (nb_pads > 1) - res = av_strdup(ctx->filter->name); - else - res = av_asprintf("%s:%s", ctx->filter->name, - avfilter_pad_get_name(pads, inout->pad_idx)); - if (!res) - report_and_exit(AVERROR(ENOMEM)); - return res; + return av_strdup(ctx->filter->name); + return av_asprintf("%s:%s", ctx->filter->name, + avfilter_pad_get_name(pads, inout->pad_idx)); } static OutputFilter *ofilter_alloc(FilterGraph *fg) @@ -799,7 +794,7 @@ static const AVClass fg_class = { .category = AV_CLASS_CATEGORY_FILTER, }; -FilterGraph *fg_create(char *graph_desc) +int fg_create(FilterGraph **pfg, char *graph_desc) { FilterGraphPriv *fgp = allocate_array_elem(&filtergraphs, sizeof(*fgp), &nb_filtergraphs); FilterGraph *fg = &fgp->fg; @@ -808,6 +803,9 @@ FilterGraph *fg_create(char *graph_desc) AVFilterGraph *graph; int ret = 0; + if (pfg) + *pfg = fg; + fg->class = &fg_class; fg->index = nb_filtergraphs - 1; fgp->graph_desc = graph_desc; @@ -817,13 +815,13 @@ FilterGraph *fg_create(char *graph_desc) fgp->frame = av_frame_alloc(); if (!fgp->frame) - report_and_exit(AVERROR(ENOMEM)); + return AVERROR(ENOMEM); /* this graph is only used for determining the kinds of inputs * and outputs we have, and is discarded on exit from this function */ graph = avfilter_graph_alloc(); if (!graph) - report_and_exit(AVERROR(ENOMEM)); + return AVERROR(ENOMEM);; graph->nb_threads = 1; ret = graph_parse(graph, fgp->graph_desc, &inputs, &outputs, NULL); @@ -840,6 +838,10 @@ FilterGraph *fg_create(char *graph_desc) ifp->type = avfilter_pad_get_type(cur->filter_ctx->input_pads, cur->pad_idx); ifilter->name = describe_filter_link(fg, cur, 1); + if (!ifilter->name) { + ret = AVERROR(ENOMEM); + goto fail; + } } for (AVFilterInOut *cur = outputs; cur; cur = cur->next) { @@ -851,6 +853,10 @@ FilterGraph *fg_create(char *graph_desc) ofilter->type = avfilter_pad_get_type(cur->filter_ctx->output_pads, cur->pad_idx); ofilter->name = describe_filter_link(fg, cur, 0); + if (!ofilter->name) { + ret = AVERROR(ENOMEM); + goto fail; + } } if (!fg->nb_outputs) { @@ -865,9 +871,9 @@ fail: avfilter_graph_free(&graph); if (ret < 0) - report_and_exit(ret); + return ret; - return fg; + return 0; } int init_simple_filtergraph(InputStream *ist, OutputStream *ost, @@ -877,9 +883,9 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost, FilterGraphPriv *fgp; int ret; - fg = fg_create(graph_desc); - if (!fg) - report_and_exit(AVERROR(ENOMEM)); + ret = fg_create(&fg, graph_desc); + if (ret < 0) + return ret; fgp = fgp_from_fg(fg); fgp->is_simple = 1; |