This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 9fe0ff3d56618c24d95fa4e832148bab54928f18
Author:     Niklas Haas <[email protected]>
AuthorDate: Mon May 11 19:39:02 2026 +0200
Commit:     Niklas Haas <[email protected]>
CommitDate: Fri May 15 18:53:05 2026 +0200

    swscale/graph: make _reinit() only call _init(), not _create()
    
    This allows us to preserve the same memory allocation when
    reinitializing a graph, which is a nice bonus.
    
    Signed-off-by: Niklas Haas <[email protected]>
---
 libswscale/graph.c   | 14 ++++++--------
 libswscale/graph.h   | 11 ++++++-----
 libswscale/swscale.c | 11 ++++++++++-
 3 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/libswscale/graph.c b/libswscale/graph.c
index f779ad45eb..403b66399e 100644
--- a/libswscale/graph.c
+++ b/libswscale/graph.c
@@ -963,20 +963,18 @@ static int opts_equal(const SwsContext *c1, const 
SwsContext *c2)
 
 }
 
-int ff_sws_graph_reinit(SwsContext *ctx, const SwsFormat *dst, const SwsFormat 
*src,
-                        int field, SwsGraph **out_graph)
+int ff_sws_graph_reinit(SwsGraph *graph, SwsContext *ctx, const SwsFormat *dst,
+                        const SwsFormat *src, int field)
 {
-    SwsGraph *graph = *out_graph;
-    if (graph && ff_fmt_equal(&graph->src, src) &&
-                 ff_fmt_equal(&graph->dst, dst) &&
-                 opts_equal(ctx, &graph->opts_copy))
+    if (ff_fmt_equal(&graph->src, src) && ff_fmt_equal(&graph->dst, dst) &&
+        opts_equal(ctx, &graph->opts_copy))
     {
         ff_sws_graph_update_metadata(graph, &src->color);
         return 0;
     }
 
-    ff_sws_graph_free(out_graph);
-    return ff_sws_graph_create(ctx, dst, src, field, out_graph);
+    graph_uninit(graph);
+    return ff_sws_graph_init(graph, ctx, dst, src, field);
 }
 
 void ff_sws_graph_update_metadata(SwsGraph *graph, const SwsColor *color)
diff --git a/libswscale/graph.h b/libswscale/graph.h
index ccf3133558..8098aaed06 100644
--- a/libswscale/graph.h
+++ b/libswscale/graph.h
@@ -212,13 +212,14 @@ void ff_sws_graph_free(SwsGraph **graph);
 void ff_sws_graph_update_metadata(SwsGraph *graph, const SwsColor *color);
 
 /**
- * Wrapper around ff_sws_graph_create() that reuses the existing graph if the
+ * Wrapper around ff_sws_graph_init() that reuses the existing graph if the
  * format is compatible. This will also update dynamic per-frame metadata.
- * Must be called after changing any of the fields in `ctx`, or else they will
- * have no effect.
+ *
+ * Must also be called after changing any of the fields in `ctx`, or else they
+ * will have no effect.
  */
-int ff_sws_graph_reinit(SwsContext *ctx, const SwsFormat *dst, const SwsFormat 
*src,
-                        int field, SwsGraph **graph);
+int ff_sws_graph_reinit(SwsGraph *graph, SwsContext *ctx, const SwsFormat *dst,
+                        const SwsFormat *src, int field);
 
 /**
  * Dispatch the filter graph on a single field of the given frames. Internally
diff --git a/libswscale/swscale.c b/libswscale/swscale.c
index d82f1f9818..25bd8fc293 100644
--- a/libswscale/swscale.c
+++ b/libswscale/swscale.c
@@ -1504,7 +1504,16 @@ int sws_frame_setup(SwsContext *ctx, const AVFrame *dst, 
const AVFrame *src)
             goto fail;
         }
 
-        ret = ff_sws_graph_reinit(ctx, &dst_fmt, &src_fmt, field, 
&s->graph[field]);
+        if (!s->graph[field]) {
+            s->graph[field] = ff_sws_graph_alloc();
+            if (!s->graph[field]) {
+                err_msg = "Failed allocating scaling graph";
+                ret = AVERROR(ENOMEM);
+                goto fail;
+            }
+        }
+
+        ret = ff_sws_graph_reinit(s->graph[field], ctx, &dst_fmt, &src_fmt, 
field);
         if (ret < 0) {
             err_msg = "Failed initializing scaling graph";
             goto fail;

_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to