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

Git pushed a commit to branch master
in repository ffmpeg.

commit f535212a2cfede27778bf524db56741b1f1ff230
Author:     Niklas Haas <[email protected]>
AuthorDate: Wed Mar 4 23:11:12 2026 +0100
Commit:     Niklas Haas <[email protected]>
CommitDate: Thu Mar 12 21:02:48 2026 +0000

    swscale/ops_chain: allow free callback to take SwsOpPriv
    
    I mainly want to be able to store two pointers side-by-side.
    
    Sponsored-by: Sovereign Tech Fund
    Signed-off-by: Niklas Haas <[email protected]>
---
 libswscale/ops_chain.c      |  6 +++---
 libswscale/ops_chain.h      | 12 +++++++++---
 libswscale/ops_tmpl_float.c |  4 ++--
 libswscale/x86/ops.c        |  4 ++--
 4 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/libswscale/ops_chain.c b/libswscale/ops_chain.c
index 2445154186..1a4ac539ba 100644
--- a/libswscale/ops_chain.c
+++ b/libswscale/ops_chain.c
@@ -39,14 +39,14 @@ void ff_sws_op_chain_free_cb(void *ptr)
     SwsOpChain *chain = ptr;
     for (int i = 0; i < chain->num_impl + 1; i++) {
         if (chain->free[i])
-            chain->free[i](chain->impl[i].priv.ptr);
+            chain->free[i](chain->impl[i].priv);
     }
 
     av_free(chain);
 }
 
 int ff_sws_op_chain_append(SwsOpChain *chain, SwsFuncPtr func,
-                           void (*free)(void *), const SwsOpPriv *priv)
+                           void (*free)(SwsOpPriv), const SwsOpPriv *priv)
 {
     const int idx = chain->num_impl;
     if (idx == SWS_MAX_OPS)
@@ -235,7 +235,7 @@ int ff_sws_op_compile_tables(const SwsOpTable *const 
tables[], int num_tables,
     ret = ff_sws_op_chain_append(chain, best->func, best->free, &priv);
     if (ret < 0) {
         if (best->free)
-            best->free(priv.ptr);
+            best->free(priv);
         return ret;
     }
 
diff --git a/libswscale/ops_chain.h b/libswscale/ops_chain.h
index 532622fd2c..7d598c2875 100644
--- a/libswscale/ops_chain.h
+++ b/libswscale/ops_chain.h
@@ -22,6 +22,7 @@
 #define SWSCALE_OPS_CHAIN_H
 
 #include "libavutil/cpu.h"
+#include "libavutil/mem.h"
 
 #include "ops_internal.h"
 
@@ -82,7 +83,7 @@ static_assert(offsetof(SwsOpImpl, priv) == 16, "SwsOpImpl 
layout mismatch");
 typedef struct SwsOpChain {
 #define SWS_MAX_OPS 16
     SwsOpImpl impl[SWS_MAX_OPS + 1]; /* reserve extra space for the entrypoint 
*/
-    void (*free[SWS_MAX_OPS + 1])(void *);
+    void (*free[SWS_MAX_OPS + 1])(SwsOpPriv);
     int num_impl;
     int cpu_flags; /* set of all used CPU flags */
 } SwsOpChain;
@@ -96,7 +97,7 @@ static inline void ff_sws_op_chain_free(SwsOpChain *chain)
 
 /* Returns 0 on success, or a negative error code. */
 int ff_sws_op_chain_append(SwsOpChain *chain, SwsFuncPtr func,
-                           void (*free)(void *), const SwsOpPriv *priv);
+                           void (*free)(SwsOpPriv), const SwsOpPriv *priv);
 
 typedef struct SwsOpEntry {
     /* Kernel metadata; reduced size subset of SwsOp */
@@ -119,9 +120,14 @@ typedef struct SwsOpEntry {
     /* Kernel implementation */
     SwsFuncPtr func;
     int (*setup)(const SwsOp *op, SwsOpPriv *out); /* optional */
-    void (*free)(void *priv);
+    void (*free)(SwsOpPriv priv);
 } SwsOpEntry;
 
+static inline void ff_op_priv_free(SwsOpPriv priv)
+{
+    av_free(priv.ptr);
+}
+
 typedef struct SwsOpTable {
     unsigned cpu_flags;   /* required CPU flags for this table */
     int block_size;       /* fixed block size of this table */
diff --git a/libswscale/ops_tmpl_float.c b/libswscale/ops_tmpl_float.c
index 2f1d249168..d5ac7fb75f 100644
--- a/libswscale/ops_tmpl_float.c
+++ b/libswscale/ops_tmpl_float.c
@@ -107,7 +107,7 @@ DECL_ENTRY(dither##N,
     .op = SWS_OP_DITHER,                                                       
 \
     .dither_size = N,                                                          
 \
     .setup = fn(setup_dither),                                                 
 \
-    .free = av_free,                                                           
 \
+    .free = ff_op_priv_free,                                                   
 \
 );
 
 WRAP_DITHER(0)
@@ -193,7 +193,7 @@ DECL_IMPL(linear_##NAME)
 DECL_ENTRY(linear_##NAME,                                                      
 \
     .op    = SWS_OP_LINEAR,                                                    
 \
     .setup = fn(setup_linear),                                                 
 \
-    .free  = av_free,                                                          
 \
+    .free  = ff_op_priv_free,                                                  
 \
     .linear_mask = (MASK),                                                     
 \
 );
 
diff --git a/libswscale/x86/ops.c b/libswscale/x86/ops.c
index 8a7ad3ecca..76d374430c 100644
--- a/libswscale/x86/ops.c
+++ b/libswscale/x86/ops.c
@@ -237,7 +237,7 @@ static int setup_dither(const SwsOp *op, SwsOpPriv *out)
     DECL_MACRO(F32, dither##SIZE##EXT,                                         
 \
         .op    = SWS_OP_DITHER,                                                
 \
         .setup = setup_dither,                                                 
 \
-        .free  = (SIZE) ? av_free : NULL,                                      
 \
+        .free  = (SIZE) ? ff_op_priv_free : NULL,                              
 \
         .dither_size = SIZE,                                                   
 \
     );
 
@@ -259,7 +259,7 @@ static int setup_linear(const SwsOp *op, SwsOpPriv *out)
     DECL_ASM(F32, NAME##EXT,                                                   
 \
         .op    = SWS_OP_LINEAR,                                                
 \
         .setup = setup_linear,                                                 
 \
-        .free  = av_free,                                                      
 \
+        .free  = ff_op_priv_free,                                              
 \
         .linear_mask = (MASK),                                                 
 \
     );
 

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

Reply via email to