This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg.
commit d9e594ca960db6e0d24fdc8e5c6ec5438bff043f Author: Niklas Haas <[email protected]> AuthorDate: Tue Mar 3 17:46:19 2026 +0100 Commit: Niklas Haas <[email protected]> CommitDate: Thu Mar 5 23:34:56 2026 +0000 swscale/graph: have ff_sws_graph_add_pass() return an error code This allows distinguishing between different types of failure, e.g. AVERROR(EINVAL) on invalid pass dimensions. Signed-off-by: Niklas Haas <[email protected]> --- libswscale/graph.c | 49 ++++++++++++++++++++++++----------------------- libswscale/graph.h | 10 ++++++---- libswscale/ops_dispatch.c | 10 +++++----- 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/libswscale/graph.c b/libswscale/graph.c index 81b8ef35d7..5905935c3e 100644 --- a/libswscale/graph.c +++ b/libswscale/graph.c @@ -104,14 +104,15 @@ static void free_buffer(AVRefStructOpaque opaque, void *obj) av_frame_free(&buffer->avframe); } -SwsPass *ff_sws_graph_add_pass(SwsGraph *graph, enum AVPixelFormat fmt, - int width, int height, SwsPass *input, - int align, void *priv, sws_filter_run_t run) +int ff_sws_graph_add_pass(SwsGraph *graph, enum AVPixelFormat fmt, + int width, int height, SwsPass *input, + int align, void *priv, sws_filter_run_t run, + SwsPass **out_pass) { int ret; SwsPass *pass = av_mallocz(sizeof(*pass)); if (!pass) - return NULL; + return AVERROR(ENOMEM); pass->graph = graph; pass->run = run; @@ -121,8 +122,10 @@ SwsPass *ff_sws_graph_add_pass(SwsGraph *graph, enum AVPixelFormat fmt, pass->height = height; pass->input = input; pass->output = av_refstruct_alloc_ext(sizeof(*pass->output), 0, NULL, free_buffer); - if (!pass->output) + if (!pass->output) { + ret = AVERROR(ENOMEM); goto fail; + } ret = pass_alloc_output(input); if (ret < 0) @@ -145,23 +148,20 @@ SwsPass *ff_sws_graph_add_pass(SwsGraph *graph, enum AVPixelFormat fmt, if (ret < 0) goto fail; - return pass; + *out_pass = pass; + return 0; fail: av_refstruct_unref(&pass->output); av_free(pass); - return NULL; + return ret; } /* Wrapper around ff_sws_graph_add_pass() that chains a pass "in-place" */ static int pass_append(SwsGraph *graph, enum AVPixelFormat fmt, int w, int h, SwsPass **pass, int align, void *priv, sws_filter_run_t run) { - SwsPass *new = ff_sws_graph_add_pass(graph, fmt, w, h, *pass, align, priv, run); - if (!new) - return AVERROR(ENOMEM); - *pass = new; - return 0; + return ff_sws_graph_add_pass(graph, fmt, w, h, *pass, align, priv, run, pass); } static void frame_shift(const SwsFrame *f, const int y, uint8_t *data[4]) @@ -415,11 +415,12 @@ static int init_legacy_subpass(SwsGraph *graph, SwsContext *sws, } } - pass = ff_sws_graph_add_pass(graph, sws->dst_format, dst_w, dst_h, input, align, sws, - c->convert_unscaled ? run_legacy_unscaled : run_legacy_swscale); - if (!pass) { + ret = ff_sws_graph_add_pass(graph, sws->dst_format, dst_w, dst_h, input, align, sws, + c->convert_unscaled ? run_legacy_unscaled : run_legacy_swscale, + &pass); + if (ret < 0) { sws_free_context(&sws); - return AVERROR(ENOMEM); + return ret; } pass->setup = setup_legacy_swscale; pass->free = free_legacy_swscale; @@ -707,11 +708,11 @@ static int adapt_colors(SwsGraph *graph, SwsFormat src, SwsFormat dst, return ret; } - pass = ff_sws_graph_add_pass(graph, fmt_out, src.width, src.height, - input, 1, lut, run_lut3d); - if (!pass) { + ret = ff_sws_graph_add_pass(graph, fmt_out, src.width, src.height, + input, 1, lut, run_lut3d, &pass); + if (ret < 0) { ff_sws_lut3d_free(&lut); - return AVERROR(ENOMEM); + return ret; } pass->setup = setup_lut3d; pass->free = free_lut3d; @@ -748,10 +749,10 @@ static int init_passes(SwsGraph *graph) graph->noop = 1; /* Add threaded memcpy pass */ - pass = ff_sws_graph_add_pass(graph, dst.format, dst.width, dst.height, - pass, 1, NULL, run_copy); - if (!pass) - return AVERROR(ENOMEM); + ret = ff_sws_graph_add_pass(graph, dst.format, dst.width, dst.height, + pass, 1, NULL, run_copy, &pass); + if (ret < 0) + return ret; } return 0; diff --git a/libswscale/graph.h b/libswscale/graph.h index 88d8245218..676f8cb46a 100644 --- a/libswscale/graph.h +++ b/libswscale/graph.h @@ -154,11 +154,13 @@ int ff_sws_graph_create(SwsContext *ctx, const SwsFormat *dst, const SwsFormat * * @param align Minimum slice alignment for this pass, or 0 for no threading. * @param priv Private state for the filter run function. * @param run Filter function to run. - * @return The newly created pass, or NULL on error. + * @param out_pass The newly added pass will be written here on success. + * @return 0 or a negative error code */ -SwsPass *ff_sws_graph_add_pass(SwsGraph *graph, enum AVPixelFormat fmt, - int width, int height, SwsPass *input, - int align, void *priv, sws_filter_run_t run); +int ff_sws_graph_add_pass(SwsGraph *graph, enum AVPixelFormat fmt, + int width, int height, SwsPass *input, + int align, void *priv, sws_filter_run_t run, + SwsPass **out_pass); /** * Uninitialize any state associate with this filter graph and free it. diff --git a/libswscale/ops_dispatch.c b/libswscale/ops_dispatch.c index 80dcfe23dd..67ce225b82 100644 --- a/libswscale/ops_dispatch.c +++ b/libswscale/ops_dispatch.c @@ -346,12 +346,12 @@ static int compile(SwsGraph *graph, const SwsOpList *ops, } SwsPass *pass; - pass = ff_sws_graph_add_pass(graph, dst->format, dst->width, dst->height, - input, p->comp.slice_align, p, op_pass_run); - if (!pass) { - ret = AVERROR(ENOMEM); + ret = ff_sws_graph_add_pass(graph, dst->format, dst->width, dst->height, + input, p->comp.slice_align, p, op_pass_run, + &pass); + if (ret < 0) goto fail; - } + pass->setup = op_pass_setup; pass->free = op_pass_free; _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
