[ffmpeg] branch master updated (64fafd63f0 -> afdb683a3f)
This is an automated email from the git hooks/post-receive script. Git pushed a change to branch master in repository ffmpeg. from 64fafd63f0 avformat: remove HLS protocol new e1fd274706 swscale/graph: check output plane pointer instead of pixel format new 18060a8820 swscale/graph: simplify ff_sws_graph_run() API new fe25e54d0f swscale/graph: move output image into separate struct new afa08f4971 swscale/graph: duplicate buffer dimensions in SwsPassBuffer new 0b446cdccd swscale/graph: switch to an AVBufferRef per plane new b98751b13c swscale/graph: set up palette using current input image new 1e071c8585 swscale/graph: omit memcpy() if src and dst are identical new cc346b232d swscale/graph: store current pass input instead of global args new d918551650 swscale/graph: switch SwsPass.output to refstruct new afdb683a3f swscale: avoid UB on interlaced frames The 10 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: libswscale/graph.c | 139 +++++++++++++++++++++++++++++++++++++-------------- libswscale/graph.h | 25 ++++++--- libswscale/swscale.c | 28 ++++++----- 3 files changed, 135 insertions(+), 57 deletions(-)
This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg. commit e1fd274706c2d2cb9788646821a5d43eb12dd04e Author: Niklas Haas <git@haasn.dev> AuthorDate: Mon Feb 9 15:27:38 2026 +0100 Commit: Niklas Haas <ffmpeg@haasn.dev> CommitDate: Mon Feb 23 19:39:17 2026 +0000 swscale/graph: check output plane pointer instead of pixel format To see if the output buffers are allocated or not. Signed-off-by: Niklas Haas <git@haasn.dev> --- libswscale/graph.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libswscale/graph.c b/libswscale/graph.c index e47b2d07f2..97329b4b63 100644 --- a/libswscale/graph.c +++ b/libswscale/graph.c @@ -38,7 +38,7 @@ static int pass_alloc_output(SwsPass *pass) { - if (!pass || pass->output.fmt != AV_PIX_FMT_NONE) + if (!pass || pass->output.data[0]) return 0; pass->output.fmt = pass->format; return av_image_alloc(pass->output.data, pass->output.linesize, pass->width, @@ -672,7 +672,7 @@ static void sws_graph_worker(void *priv, int jobnr, int threadnr, int nb_jobs, SwsGraph *graph = priv; const SwsPass *pass = graph->exec.pass; const SwsImg *input = pass->input ? &pass->input->output : &graph->exec.input; - const SwsImg *output = pass->output.fmt != AV_PIX_FMT_NONE ? &pass->output : &graph->exec.output; + const SwsImg *output = pass->output.data[0] ? &pass->output : &graph->exec.output; const int slice_y = jobnr * pass->slice_h; const int slice_h = FFMIN(pass->slice_h, pass->height - slice_y); @@ -729,8 +729,7 @@ void ff_sws_graph_free(SwsGraph **pgraph) SwsPass *pass = graph->passes[i]; if (pass->free) pass->free(pass->priv); - if (pass->output.fmt != AV_PIX_FMT_NONE) - av_free(pass->output.data[0]); + av_free(pass->output.data[0]); av_free(pass); } av_free(graph->passes); @@ -796,7 +795,7 @@ void ff_sws_graph_run(SwsGraph *graph, uint8_t *const out_data[4], const SwsPass *pass = graph->passes[i]; graph->exec.pass = pass; if (pass->setup) { - pass->setup(pass->output.fmt != AV_PIX_FMT_NONE ? &pass->output : out, + pass->setup(pass->output.data[0] ? &pass->output : out, pass->input ? &pass->input->output : in, pass); } avpriv_slicethread_execute(graph->slicethread, pass->num_slices, 0);
This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg. commit 18060a8820accbee5a5d6e4921575a9e2f7a5f17 Author: Niklas Haas <git@haasn.dev> AuthorDate: Sat Feb 7 14:51:35 2026 +0100 Commit: Niklas Haas <ffmpeg@haasn.dev> CommitDate: Mon Feb 23 19:39:17 2026 +0000 swscale/graph: simplify ff_sws_graph_run() API There's little reason not to directly take an SwsImg here; it's already an internally visible struct. Signed-off-by: Niklas Haas <git@haasn.dev> --- libswscale/graph.c | 28 ++++++++++------------------ libswscale/graph.h | 9 +++------ libswscale/swscale.c | 27 ++++++++++++++------------- 3 files changed, 27 insertions(+), 37 deletions(-) diff --git a/libswscale/graph.c b/libswscale/graph.c index 97329b4b63..6b9e6f4b25 100644 --- a/libswscale/graph.c +++ b/libswscale/graph.c @@ -173,7 +173,7 @@ static void setup_legacy_swscale(const SwsImg *out, const SwsImg *in, const SwsPass *pass) { const SwsGraph *graph = pass->graph; - const SwsImg *in_orig = &graph->exec.input; + const SwsImg *in_orig = graph->exec.input; SwsContext *sws = pass->priv; SwsInternal *c = sws_internal(sws); if (sws->flags & SWS_BITEXACT && sws->dither == SWS_DITHER_ED && c->dither_error[0]) { @@ -671,8 +671,8 @@ static void sws_graph_worker(void *priv, int jobnr, int threadnr, int nb_jobs, { SwsGraph *graph = priv; const SwsPass *pass = graph->exec.pass; - const SwsImg *input = pass->input ? &pass->input->output : &graph->exec.input; - const SwsImg *output = pass->output.data[0] ? &pass->output : &graph->exec.output; + const SwsImg *input = pass->input ? &pass->input->output : graph->exec.input; + const SwsImg *output = pass->output.data[0] ? &pass->output : graph->exec.output; const int slice_y = jobnr * pass->slice_h; const int slice_h = FFMIN(pass->slice_h, pass->height - slice_y); @@ -693,9 +693,6 @@ int ff_sws_graph_create(SwsContext *ctx, const SwsFormat *dst, const SwsFormat * graph->field = field; graph->opts_copy = *ctx; - graph->exec.input.fmt = src->format; - graph->exec.output.fmt = dst->format; - ret = avpriv_slicethread_create(&graph->slicethread, (void *) graph, sws_graph_worker, NULL, ctx->threads); if (ret == AVERROR(ENOSYS)) @@ -779,24 +776,19 @@ void ff_sws_graph_update_metadata(SwsGraph *graph, const SwsColor *color) ff_color_update_dynamic(&graph->src.color, color); } -void ff_sws_graph_run(SwsGraph *graph, uint8_t *const out_data[4], - const int out_linesize[4], - const uint8_t *const in_data[4], - const int in_linesize[4]) +void ff_sws_graph_run(SwsGraph *graph, const SwsImg *output, const SwsImg *input) { - SwsImg *out = &graph->exec.output; - SwsImg *in = &graph->exec.input; - memcpy(out->data, out_data, sizeof(out->data)); - memcpy(out->linesize, out_linesize, sizeof(out->linesize)); - memcpy(in->data, in_data, sizeof(in->data)); - memcpy(in->linesize, in_linesize, sizeof(in->linesize)); + av_assert0(output->fmt == graph->dst.format); + av_assert0(input->fmt == graph->src.format); + graph->exec.output = output; + graph->exec.input = input; for (int i = 0; i < graph->num_passes; i++) { const SwsPass *pass = graph->passes[i]; graph->exec.pass = pass; if (pass->setup) { - pass->setup(pass->output.data[0] ? &pass->output : out, - pass->input ? &pass->input->output : in, pass); + pass->setup(pass->output.data[0] ? &pass->output : output, + pass->input ? &pass->input->output : input, pass); } avpriv_slicethread_execute(graph->slicethread, pass->num_slices, 0); } diff --git a/libswscale/graph.h b/libswscale/graph.h index b829bac88c..44944a3c35 100644 --- a/libswscale/graph.h +++ b/libswscale/graph.h @@ -131,8 +131,8 @@ typedef struct SwsGraph { /** Temporary execution state inside ff_sws_graph_run */ struct { const SwsPass *pass; /* current filter pass */ - SwsImg input; - SwsImg output; + const SwsImg *input; /* arguments passed to ff_sws_graph_run() */ + const SwsImg *output; } exec; } SwsGraph; @@ -182,9 +182,6 @@ int ff_sws_graph_reinit(SwsContext *ctx, const SwsFormat *dst, const SwsFormat * /** * Dispatch the filter graph on a single field. Internally threaded. */ -void ff_sws_graph_run(SwsGraph *graph, uint8_t *const out_data[4], - const int out_linesize[4], - const uint8_t *const in_data[4], - const int in_linesize[4]); +void ff_sws_graph_run(SwsGraph *graph, const SwsImg *output, const SwsImg *input); #endif /* SWSCALE_GRAPH_H */ diff --git a/libswscale/swscale.c b/libswscale/swscale.c index 219382505c..4ae0f25b9d 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -1317,24 +1317,26 @@ int sws_receive_slice(SwsContext *sws, unsigned int slice_start, dst, c->frame_dst->linesize, slice_start, slice_height); } -static void get_frame_pointers(const AVFrame *frame, uint8_t *data[4], - int linesize[4], int field) +static SwsImg get_frame_img(const AVFrame *frame, int field) { + SwsImg img = {0}; + + img.fmt = frame->format; for (int i = 0; i < 4; i++) { - data[i] = frame->data[i]; - linesize[i] = frame->linesize[i]; + img.data[i] = frame->data[i]; + img.linesize[i] = frame->linesize[i]; } if (!(frame->flags & AV_FRAME_FLAG_INTERLACED)) { av_assert1(!field); - return; + return img; } if (field == FIELD_BOTTOM) { /* Odd rows, offset by one line */ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); for (int i = 0; i < 4; i++) { - data[i] += linesize[i]; + img.data[i] += img.linesize[i]; if (desc->flags & AV_PIX_FMT_FLAG_PAL) break; } @@ -1342,7 +1344,9 @@ static void get_frame_pointers(const AVFrame *frame, uint8_t *data[4], /* Take only every second line */ for (int i = 0; i < 4; i++) - linesize[i] <<= 1; + img.linesize[i] <<= 1; + + return img; } /* Subset of av_frame_ref() that only references (video) data buffers */ @@ -1409,12 +1413,9 @@ int sws_scale_frame(SwsContext *sws, AVFrame *dst, const AVFrame *src) for (int field = 0; field < 2; field++) { SwsGraph *graph = c->graph[field]; - uint8_t *dst_data[4], *src_data[4]; - int dst_linesize[4], src_linesize[4]; - get_frame_pointers(dst, dst_data, dst_linesize, field); - get_frame_pointers(src, src_data, src_linesize, field); - ff_sws_graph_run(graph, dst_data, dst_linesize, - (const uint8_t **) src_data, src_linesize); + SwsImg input = get_frame_img(src, field); + SwsImg output = get_frame_img(dst, field); + ff_sws_graph_run(graph, &output, &input); if (!graph->dst.interlaced) break; }
This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg. commit fe25e54d0f6b939a1c2fbe44431c0af7bd40867f Author: Niklas Haas <git@haasn.dev> AuthorDate: Sat Feb 21 14:24:54 2026 +0100 Commit: Niklas Haas <ffmpeg@haasn.dev> CommitDate: Mon Feb 23 19:39:17 2026 +0000 swscale/graph: move output image into separate struct I want to add more metadata to this and also turn it into a refstruct, but get the cosmetic diff out of the way first. Signed-off-by: Niklas Haas <git@haasn.dev> --- libswscale/graph.c | 20 +++++++++++--------- libswscale/graph.h | 9 ++++++++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/libswscale/graph.c b/libswscale/graph.c index 6b9e6f4b25..5d697b2660 100644 --- a/libswscale/graph.c +++ b/libswscale/graph.c @@ -38,10 +38,12 @@ static int pass_alloc_output(SwsPass *pass) { - if (!pass || pass->output.data[0]) + if (!pass || pass->output.img.data[0]) return 0; - pass->output.fmt = pass->format; - return av_image_alloc(pass->output.data, pass->output.linesize, pass->width, + + SwsPassBuffer *output = &pass->output; + output->img.fmt = pass->format; + return av_image_alloc(output->img.data, output->img.linesize, pass->width, pass->num_slices * pass->slice_h, pass->format, 64); } @@ -61,7 +63,7 @@ SwsPass *ff_sws_graph_add_pass(SwsGraph *graph, enum AVPixelFormat fmt, pass->width = width; pass->height = height; pass->input = input; - pass->output.fmt = AV_PIX_FMT_NONE; + pass->output.img.fmt = AV_PIX_FMT_NONE; ret = pass_alloc_output(input); if (ret < 0) { @@ -671,8 +673,8 @@ static void sws_graph_worker(void *priv, int jobnr, int threadnr, int nb_jobs, { SwsGraph *graph = priv; const SwsPass *pass = graph->exec.pass; - const SwsImg *input = pass->input ? &pass->input->output : graph->exec.input; - const SwsImg *output = pass->output.data[0] ? &pass->output : graph->exec.output; + const SwsImg *input = pass->input ? &pass->input->output.img : graph->exec.input; + const SwsImg *output = pass->output.img.data[0] ? &pass->output.img : graph->exec.output; const int slice_y = jobnr * pass->slice_h; const int slice_h = FFMIN(pass->slice_h, pass->height - slice_y); @@ -726,7 +728,7 @@ void ff_sws_graph_free(SwsGraph **pgraph) SwsPass *pass = graph->passes[i]; if (pass->free) pass->free(pass->priv); - av_free(pass->output.data[0]); + av_free(pass->output.img.data[0]); av_free(pass); } av_free(graph->passes); @@ -787,8 +789,8 @@ void ff_sws_graph_run(SwsGraph *graph, const SwsImg *output, const SwsImg *input const SwsPass *pass = graph->passes[i]; graph->exec.pass = pass; if (pass->setup) { - pass->setup(pass->output.data[0] ? &pass->output : output, - pass->input ? &pass->input->output : input, pass); + pass->setup(pass->output.img.data[0] ? &pass->output.img : output, + pass->input ? &pass->input->output.img : input, pass); } avpriv_slicethread_execute(graph->slicethread, pass->num_slices, 0); } diff --git a/libswscale/graph.h b/libswscale/graph.h index 44944a3c35..b5f7ed5ff2 100644 --- a/libswscale/graph.h +++ b/libswscale/graph.h @@ -60,6 +60,13 @@ typedef struct SwsGraph SwsGraph; typedef void (*sws_filter_run_t)(const SwsImg *out, const SwsImg *in, int y, int h, const SwsPass *pass); +/** + * Represents an allocated output buffer for a filter pass. + */ +typedef struct SwsPassBuffer { + SwsImg img; +} SwsPassBuffer; + /** * Represents a single filter pass in the scaling graph. Each filter will * read from some previous pass's output, and write to a buffer associated @@ -88,7 +95,7 @@ struct SwsPass { /** * Filter output buffer. Allocated on demand and freed automatically. */ - SwsImg output; + SwsPassBuffer output; /** * Called once from the main thread before running the filter. Optional.
This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg. commit afa08f49711c73d029e4f8de921b0f0b772994e2 Author: Niklas Haas <git@haasn.dev> AuthorDate: Sat Feb 21 14:51:36 2026 +0100 Commit: Niklas Haas <ffmpeg@haasn.dev> CommitDate: Mon Feb 23 19:39:17 2026 +0000 swscale/graph: duplicate buffer dimensions in SwsPassBuffer When multiple passes share a buffer reference, the true buffer dimensions may be different for each pass, depending on slice alignment. So we can't rely on the pass dimensions being representative. Instead, store this information in the SwsPassBuffer itself. Signed-off-by: Niklas Haas <git@haasn.dev> --- libswscale/graph.c | 11 +++++++---- libswscale/graph.h | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/libswscale/graph.c b/libswscale/graph.c index 5d697b2660..efe6bf7c2a 100644 --- a/libswscale/graph.c +++ b/libswscale/graph.c @@ -42,9 +42,8 @@ static int pass_alloc_output(SwsPass *pass) return 0; SwsPassBuffer *output = &pass->output; - output->img.fmt = pass->format; - return av_image_alloc(output->img.data, output->img.linesize, pass->width, - pass->num_slices * pass->slice_h, pass->format, 64); + return av_image_alloc(output->img.data, output->img.linesize, output->width, + output->height, output->img.fmt, 64); } SwsPass *ff_sws_graph_add_pass(SwsGraph *graph, enum AVPixelFormat fmt, @@ -63,7 +62,6 @@ SwsPass *ff_sws_graph_add_pass(SwsGraph *graph, enum AVPixelFormat fmt, pass->width = width; pass->height = height; pass->input = input; - pass->output.img.fmt = AV_PIX_FMT_NONE; ret = pass_alloc_output(input); if (ret < 0) { @@ -80,6 +78,11 @@ SwsPass *ff_sws_graph_add_pass(SwsGraph *graph, enum AVPixelFormat fmt, pass->num_slices = (pass->height + pass->slice_h - 1) / pass->slice_h; } + /* Align output buffer to include extra slice padding */ + pass->output.img.fmt = fmt; + pass->output.width = pass->width; + pass->output.height = pass->slice_h * pass->num_slices; + ret = av_dynarray_add_nofree(&graph->passes, &graph->num_passes, pass); if (ret < 0) av_freep(&pass); diff --git a/libswscale/graph.h b/libswscale/graph.h index b5f7ed5ff2..b3d5aa5dbe 100644 --- a/libswscale/graph.h +++ b/libswscale/graph.h @@ -65,6 +65,7 @@ typedef void (*sws_filter_run_t)(const SwsImg *out, const SwsImg *in, */ typedef struct SwsPassBuffer { SwsImg img; + int width, height; /* dimensions of this buffer */ } SwsPassBuffer; /**
This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg. commit 0b446cdccdd540ff745de34235a934028eb522d6 Author: Niklas Haas <git@haasn.dev> AuthorDate: Sat Feb 21 14:55:23 2026 +0100 Commit: Niklas Haas <ffmpeg@haasn.dev> CommitDate: Mon Feb 23 19:39:17 2026 +0000 swscale/graph: switch to an AVBufferRef per plane This annoyingly requires recreating some of the logic inside av_img_alloc(), because there's no good existing current helper accessible from libswscale that gives per-plane allocations like this. The new code is based off the calculations inside libavframe/bufferpool.c. Signed-off-by: Niklas Haas <git@haasn.dev> --- libswscale/graph.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- libswscale/graph.h | 3 +++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/libswscale/graph.c b/libswscale/graph.c index efe6bf7c2a..985406fc80 100644 --- a/libswscale/graph.c +++ b/libswscale/graph.c @@ -19,6 +19,7 @@ */ #include "libavutil/avassert.h" +#include "libavutil/cpu.h" #include "libavutil/error.h" #include "libavutil/imgutils.h" #include "libavutil/macros.h" @@ -36,14 +37,55 @@ #include "graph.h" #include "ops.h" +static int buffer_get_sizes(SwsPassBuffer *buffer, size_t sizes[4]) +{ + const int align = av_cpu_max_align(); + const int format = buffer->img.fmt; + const int width = FFALIGN(buffer->width, align); + const int height = buffer->height; + int ret; + + ret = av_image_check_size2(width, height, INT64_MAX, format, 0, NULL); + if (ret < 0) + return ret; + + int *linesize = buffer->img.linesize; + ret = av_image_fill_linesizes(linesize, format, width); + if (ret < 0) + return ret; + + ptrdiff_t linesize1[4]; + for (int i = 0; i < 4; i++) + linesize1[i] = linesize[i] = FFALIGN(linesize[i], align); + + return av_image_fill_plane_sizes(sizes, format, height, linesize1); +} + static int pass_alloc_output(SwsPass *pass) { - if (!pass || pass->output.img.data[0]) + if (!pass || pass->output.buf[0]) return 0; + size_t sizes[4]; SwsPassBuffer *output = &pass->output; - return av_image_alloc(output->img.data, output->img.linesize, output->width, - output->height, output->img.fmt, 64); + int ret = buffer_get_sizes(output, sizes); + if (ret < 0) + return ret; + + const int align = av_cpu_max_align(); + for (int i = 0; i < 4; i++) { + if (!sizes[i]) + break; + if (sizes[i] > SIZE_MAX - align) + return AVERROR(EINVAL); + + AVBufferRef *buf = av_buffer_alloc(sizes[i] + align); + if (!buf) + return AVERROR(ENOMEM); + output->img.data[i] = (uint8_t *) FFALIGN((uintptr_t) buf->data, align); + output->buf[i] = buf; + } + return 0; } SwsPass *ff_sws_graph_add_pass(SwsGraph *graph, enum AVPixelFormat fmt, @@ -731,7 +773,8 @@ void ff_sws_graph_free(SwsGraph **pgraph) SwsPass *pass = graph->passes[i]; if (pass->free) pass->free(pass->priv); - av_free(pass->output.img.data[0]); + for (int n = 0; n < FF_ARRAY_ELEMS(pass->output.buf); n++) + av_buffer_unref(&pass->output.buf[n]); av_free(pass); } av_free(graph->passes); diff --git a/libswscale/graph.h b/libswscale/graph.h index b3d5aa5dbe..f8eed09132 100644 --- a/libswscale/graph.h +++ b/libswscale/graph.h @@ -24,6 +24,8 @@ #include <stdbool.h> #include "libavutil/slicethread.h" +#include "libavutil/buffer.h" + #include "swscale.h" #include "format.h" @@ -66,6 +68,7 @@ typedef void (*sws_filter_run_t)(const SwsImg *out, const SwsImg *in, typedef struct SwsPassBuffer { SwsImg img; int width, height; /* dimensions of this buffer */ + AVBufferRef *buf[4]; /* one per plane */ } SwsPassBuffer; /**
This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg. commit b98751b13c7295765ba212ecb0c23a213c6d3a2d Author: Niklas Haas <git@haasn.dev> AuthorDate: Tue Feb 10 18:18:09 2026 +0100 Commit: Niklas Haas <ffmpeg@haasn.dev> CommitDate: Mon Feb 23 19:39:17 2026 +0000 swscale/graph: set up palette using current input image Using the original input image here is completely wrong - the format/palette could have been set to anything else in the meantime. At best, we would want to use the original input to add_legacy_sws_pass(), but it's impossible for this to differ from the per-pass input. The only time legacy subpasses are added is when using cascaded contexts, but in this case, the only context actually reading from the palette format would be the first one. I'm not entirely sure why this code was originally written this way, but I'm reasonably confident that it's not at all necessary. Tested extensively on both FATE, the self-test, and real-world files. Signed-off-by: Niklas Haas <git@haasn.dev> --- libswscale/graph.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libswscale/graph.c b/libswscale/graph.c index 985406fc80..2d07c4bb06 100644 --- a/libswscale/graph.c +++ b/libswscale/graph.c @@ -219,8 +219,6 @@ static void free_legacy_swscale(void *priv) static void setup_legacy_swscale(const SwsImg *out, const SwsImg *in, const SwsPass *pass) { - const SwsGraph *graph = pass->graph; - const SwsImg *in_orig = graph->exec.input; SwsContext *sws = pass->priv; SwsInternal *c = sws_internal(sws); if (sws->flags & SWS_BITEXACT && sws->dither == SWS_DITHER_ED && c->dither_error[0]) { @@ -229,7 +227,7 @@ static void setup_legacy_swscale(const SwsImg *out, const SwsImg *in, } if (usePal(sws->src_format)) - ff_update_palette(c, (const uint32_t *) in_orig->data[1]); + ff_update_palette(c, (const uint32_t *) in->data[1]); } static inline SwsContext *slice_ctx(const SwsPass *pass, int y)
This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg. commit 1e071c8585467539d48cb33f239811309eed46a0 Author: Niklas Haas <git@haasn.dev> AuthorDate: Tue Feb 10 14:58:28 2026 +0100 Commit: Niklas Haas <ffmpeg@haasn.dev> CommitDate: Mon Feb 23 19:39:17 2026 +0000 swscale/graph: omit memcpy() if src and dst are identical This allows already referenced planes to be skipped, in the case of e.g. only some of the output planes being sucessfully referenced. Also avoids what is technically UB, if the user happens to call ff_sws_graph_run() after already having ref'd an image. Signed-off-by: Niklas Haas <git@haasn.dev> --- libswscale/graph.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libswscale/graph.c b/libswscale/graph.c index 2d07c4bb06..b44964e625 100644 --- a/libswscale/graph.c +++ b/libswscale/graph.c @@ -152,7 +152,9 @@ static void run_copy(const SwsImg *out_base, const SwsImg *in_base, const int lines = h >> ff_fmt_vshift(in.fmt, i); av_assert1(in.data[i]); - if (in.linesize[i] == out.linesize[i]) { + if (in.data[i] == out.data[i]) { + av_assert0(in.linesize[i] == out.linesize[i]); + } else if (in.linesize[i] == out.linesize[i]) { memcpy(out.data[i], in.data[i], lines * out.linesize[i]); } else { const int linesize = FFMIN(out.linesize[i], in.linesize[i]);
This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg. commit cc346b232dc8c84e8169fd82051b7d768d6e598f Author: Niklas Haas <git@haasn.dev> AuthorDate: Tue Feb 10 18:22:57 2026 +0100 Commit: Niklas Haas <ffmpeg@haasn.dev> CommitDate: Mon Feb 23 19:39:17 2026 +0000 swscale/graph: store current pass input instead of global args The global args to ff_sws_graph_run() really shouldn't matter inside thread workers. If they ever do, it indicates a leaky abstraction. The only reason it was needed in the first place was because of the way the input/output buffers implicitly defaulted to the global args. However, we can solve this much more elegantly by just calculating it in ff_sws_graph_run() directly and storing the computed SwsImg inside the execution state. Signed-off-by: Niklas Haas <git@haasn.dev> --- libswscale/graph.c | 32 ++++++++++++++++++++++---------- libswscale/graph.h | 9 ++++++--- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/libswscale/graph.c b/libswscale/graph.c index b44964e625..7a9985f56a 100644 --- a/libswscale/graph.c +++ b/libswscale/graph.c @@ -718,12 +718,10 @@ static void sws_graph_worker(void *priv, int jobnr, int threadnr, int nb_jobs, { SwsGraph *graph = priv; const SwsPass *pass = graph->exec.pass; - const SwsImg *input = pass->input ? &pass->input->output.img : graph->exec.input; - const SwsImg *output = pass->output.img.data[0] ? &pass->output.img : graph->exec.output; const int slice_y = jobnr * pass->slice_h; const int slice_h = FFMIN(pass->slice_h, pass->height - slice_y); - pass->run(output, input, slice_y, slice_h, pass); + pass->run(&graph->exec.output, &graph->exec.input, slice_y, slice_h, pass); } int ff_sws_graph_create(SwsContext *ctx, const SwsFormat *dst, const SwsFormat *src, @@ -824,20 +822,34 @@ void ff_sws_graph_update_metadata(SwsGraph *graph, const SwsColor *color) ff_color_update_dynamic(&graph->src.color, color); } +static SwsImg pass_output(const SwsPass *pass, const SwsImg *fallback) +{ + if (!pass) + return *fallback; + + SwsImg img = pass->output.img; + for (int i = 0; i < FF_ARRAY_ELEMS(img.data); i++) { + if (!img.data[i]) { + img.data[i] = fallback->data[i]; + img.linesize[i] = fallback->linesize[i]; + } + } + + return img; +} + void ff_sws_graph_run(SwsGraph *graph, const SwsImg *output, const SwsImg *input) { av_assert0(output->fmt == graph->dst.format); av_assert0(input->fmt == graph->src.format); - graph->exec.output = output; - graph->exec.input = input; for (int i = 0; i < graph->num_passes; i++) { const SwsPass *pass = graph->passes[i]; - graph->exec.pass = pass; - if (pass->setup) { - pass->setup(pass->output.img.data[0] ? &pass->output.img : output, - pass->input ? &pass->input->output.img : input, pass); - } + graph->exec.pass = pass; + graph->exec.input = pass_output(pass->input, input); + graph->exec.output = pass_output(pass, output); + if (pass->setup) + pass->setup(&graph->exec.output, &graph->exec.input, pass); avpriv_slicethread_execute(graph->slicethread, pass->num_slices, 0); } } diff --git a/libswscale/graph.h b/libswscale/graph.h index f8eed09132..f7a17aef59 100644 --- a/libswscale/graph.h +++ b/libswscale/graph.h @@ -139,11 +139,14 @@ typedef struct SwsGraph { SwsFormat src, dst; int field; - /** Temporary execution state inside ff_sws_graph_run */ + /** + * Temporary execution state inside ff_sws_graph_run(); used to pass + * data to worker threads. + */ struct { const SwsPass *pass; /* current filter pass */ - const SwsImg *input; /* arguments passed to ff_sws_graph_run() */ - const SwsImg *output; + SwsImg input; /* current filter pass input/output */ + SwsImg output; } exec; } SwsGraph;
This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg. commit d91855165000324592ac87e2050f868c2a3acabd Author: Niklas Haas <git@haasn.dev> AuthorDate: Sat Feb 21 14:32:44 2026 +0100 Commit: Niklas Haas <ffmpeg@haasn.dev> CommitDate: Mon Feb 23 19:39:17 2026 +0000 swscale/graph: switch SwsPass.output to refstruct Allows multiple passes to share a single output buffer reference. We always allocate an output buffer so that subpasses can share the same output buffer reference while still allowing that reference to implicitly point to the final output image. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas <git@haasn.dev> --- libswscale/graph.c | 40 +++++++++++++++++++++++++++------------- libswscale/graph.h | 2 +- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/libswscale/graph.c b/libswscale/graph.c index 7a9985f56a..0829022bc4 100644 --- a/libswscale/graph.c +++ b/libswscale/graph.c @@ -26,6 +26,7 @@ #include "libavutil/mem.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" +#include "libavutil/refstruct.h" #include "libavutil/slicethread.h" #include "libswscale/swscale.h" @@ -63,11 +64,11 @@ static int buffer_get_sizes(SwsPassBuffer *buffer, size_t sizes[4]) static int pass_alloc_output(SwsPass *pass) { - if (!pass || pass->output.buf[0]) + if (!pass || pass->output->buf[0]) return 0; size_t sizes[4]; - SwsPassBuffer *output = &pass->output; + SwsPassBuffer *output = pass->output; int ret = buffer_get_sizes(output, sizes); if (ret < 0) return ret; @@ -88,6 +89,13 @@ static int pass_alloc_output(SwsPass *pass) return 0; } +static void free_buffer(AVRefStructOpaque opaque, void *obj) +{ + SwsPassBuffer *buffer = obj; + for (int i = 0; i < FF_ARRAY_ELEMS(buffer->buf); i++) + av_buffer_unref(&buffer->buf[i]); +} + 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) @@ -104,12 +112,13 @@ SwsPass *ff_sws_graph_add_pass(SwsGraph *graph, enum AVPixelFormat fmt, pass->width = width; pass->height = height; pass->input = input; + pass->output = av_refstruct_alloc_ext(sizeof(*pass->output), 0, NULL, free_buffer); + if (!pass->output) + goto fail; ret = pass_alloc_output(input); - if (ret < 0) { - av_free(pass); - return NULL; - } + if (ret < 0) + goto fail; if (!align) { pass->slice_h = pass->height; @@ -121,14 +130,20 @@ SwsPass *ff_sws_graph_add_pass(SwsGraph *graph, enum AVPixelFormat fmt, } /* Align output buffer to include extra slice padding */ - pass->output.img.fmt = fmt; - pass->output.width = pass->width; - pass->output.height = pass->slice_h * pass->num_slices; + pass->output->img.fmt = fmt; + pass->output->width = pass->width; + pass->output->height = pass->slice_h * pass->num_slices; ret = av_dynarray_add_nofree(&graph->passes, &graph->num_passes, pass); if (ret < 0) - av_freep(&pass); + goto fail; + return pass; + +fail: + av_refstruct_unref(&pass->output); + av_free(pass); + return NULL; } /* Wrapper around ff_sws_graph_add_pass() that chains a pass "in-place" */ @@ -771,8 +786,7 @@ void ff_sws_graph_free(SwsGraph **pgraph) SwsPass *pass = graph->passes[i]; if (pass->free) pass->free(pass->priv); - for (int n = 0; n < FF_ARRAY_ELEMS(pass->output.buf); n++) - av_buffer_unref(&pass->output.buf[n]); + av_refstruct_unref(&pass->output); av_free(pass); } av_free(graph->passes); @@ -827,7 +841,7 @@ static SwsImg pass_output(const SwsPass *pass, const SwsImg *fallback) if (!pass) return *fallback; - SwsImg img = pass->output.img; + SwsImg img = pass->output->img; for (int i = 0; i < FF_ARRAY_ELEMS(img.data); i++) { if (!img.data[i]) { img.data[i] = fallback->data[i]; diff --git a/libswscale/graph.h b/libswscale/graph.h index f7a17aef59..b9ad2425bd 100644 --- a/libswscale/graph.h +++ b/libswscale/graph.h @@ -99,7 +99,7 @@ struct SwsPass { /** * Filter output buffer. Allocated on demand and freed automatically. */ - SwsPassBuffer output; + SwsPassBuffer *output; /* refstruct */ /** * Called once from the main thread before running the filter. Optional.
This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg. commit afdb683a3fcfb2399141faa5050ec6755ba9c5fe Author: Niklas Haas <git@haasn.dev> AuthorDate: Sat Feb 21 15:27:00 2026 +0100 Commit: Niklas Haas <ffmpeg@haasn.dev> CommitDate: Mon Feb 23 19:39:17 2026 +0000 swscale: avoid UB on interlaced frames NULL+0 is UB. Signed-off-by: Niklas Haas <git@haasn.dev> --- libswscale/swscale.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libswscale/swscale.c b/libswscale/swscale.c index 4ae0f25b9d..0e1831800c 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -1336,7 +1336,8 @@ static SwsImg get_frame_img(const AVFrame *frame, int field) /* Odd rows, offset by one line */ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); for (int i = 0; i < 4; i++) { - img.data[i] += img.linesize[i]; + if (img.data[i]) + img.data[i] += img.linesize[i]; if (desc->flags & AV_PIX_FMT_FLAG_PAL) break; }
participants (2)
-
ffmpeg-git -
Niklas Haas