This is an automated email from the git hooks/post-receive script.
Git pushed a commit to branch master
in repository ffmpeg.
The following commit(s) were added to refs/heads/master by this push:
new 0540b42657 swscale/graph: correctly handle single threaded mode
0540b42657 is described below
commit 0540b426576bef74f9efce94c97b27577104c28c
Author: Niklas Haas <[email protected]>
AuthorDate: Fri Feb 27 13:32:00 2026 +0100
Commit: Niklas Haas <[email protected]>
CommitDate: Tue Mar 3 23:13:41 2026 +0000
swscale/graph: correctly handle single threaded mode
The code was evidently designed at one point in time to support "direct"
execution (not via a thread pool) for num_threads == 1, but this was never
implemented.
As a side benefit, reduces context creation overhead in single threaded
mode (relevant e.g. inside the libswscale self test), due to not needing to
spawn and destroy several thousand worker threads.
Co-authored-by: Ramiro Polla <[email protected]>
Signed-off-by: Niklas Haas <[email protected]>
---
libswscale/graph.c | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/libswscale/graph.c b/libswscale/graph.c
index 188d57e73b..81b8ef35d7 100644
--- a/libswscale/graph.c
+++ b/libswscale/graph.c
@@ -782,14 +782,20 @@ int ff_sws_graph_create(SwsContext *ctx, const SwsFormat
*dst, const SwsFormat *
graph->field = field;
graph->opts_copy = *ctx;
- ret = avpriv_slicethread_create(&graph->slicethread, (void *) graph,
- sws_graph_worker, NULL, ctx->threads);
- if (ret == AVERROR(ENOSYS))
+ if (ctx->threads == 1) {
graph->num_threads = 1;
- else if (ret < 0)
- goto error;
- else
- graph->num_threads = ret;
+ } else {
+ ret = avpriv_slicethread_create(&graph->slicethread, (void *) graph,
+ sws_graph_worker, NULL, ctx->threads);
+ if (ret == AVERROR(ENOSYS)) {
+ /* Fall back to single threaded operation */
+ graph->num_threads = 1;
+ } else if (ret < 0) {
+ goto error;
+ } else {
+ graph->num_threads = ret;
+ }
+ }
ret = init_passes(graph);
if (ret < 0)
@@ -908,6 +914,11 @@ void ff_sws_graph_run(SwsGraph *graph, const AVFrame *dst,
const AVFrame *src)
graph->exec.output = pass->output->avframe ? &pass->output->frame :
&dst_field;
if (pass->setup)
pass->setup(graph->exec.output, graph->exec.input, pass);
- avpriv_slicethread_execute(graph->slicethread, pass->num_slices, 0);
+
+ if (graph->num_threads == 1) {
+ pass->run(graph->exec.output, graph->exec.input, 0, pass->height,
pass);
+ } else {
+ avpriv_slicethread_execute(graph->slicethread, pass->num_slices,
0);
+ }
}
}
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]