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

Git pushed a commit to branch master
in repository ffmpeg.

commit 7ce22b085e354758ee3317d7f8d88c67516b7883
Author:     Lynne <[email protected]>
AuthorDate: Fri Jan 2 10:37:12 2026 +0100
Commit:     Lynne <[email protected]>
CommitDate: Mon Jan 12 17:28:41 2026 +0100

    cuda/load_helper: move zlib decompression into a separate file
    
    Allows it to be reused for Vulkan
---
 libavfilter/cuda/load_helper.c                     | 64 ++++------------------
 libavutil/Makefile                                 |  2 +
 .../cuda/load_helper.c => libavutil/zlib_utils.h   | 55 ++++++++-----------
 3 files changed, 35 insertions(+), 86 deletions(-)

diff --git a/libavfilter/cuda/load_helper.c b/libavfilter/cuda/load_helper.c
index 115523d642..d64dce72b6 100644
--- a/libavfilter/cuda/load_helper.c
+++ b/libavfilter/cuda/load_helper.c
@@ -24,8 +24,7 @@
 #include "libavutil/mem.h"
 
 #if CONFIG_SHADER_COMPRESSION
-#include <zlib.h>
-#define CHUNK_SIZE 1024 * 64
+#include "libavutil/zlib_utils.h"
 #endif
 
 #include "load_helper.h"
@@ -38,58 +37,15 @@ int ff_cuda_load_module(void *avctx, AVCUDADeviceContext 
*hwctx, CUmodule *cu_mo
     CudaFunctions *cu = hwctx->internal->cuda_dl;
 
 #if CONFIG_SHADER_COMPRESSION
-    z_stream stream = { 0 };
-    uint8_t *buf, *tmp;
-    uint64_t buf_size;
-    int ret;
-
-    if (inflateInit2(&stream, 32 + 15) != Z_OK) {
-        av_log(avctx, AV_LOG_ERROR, "Error during zlib initialisation: %s\n", 
stream.msg);
-        return AVERROR(ENOSYS);
-    }
-
-    buf_size = CHUNK_SIZE * 4;
-    buf = av_realloc(NULL, buf_size);
-    if (!buf) {
-        inflateEnd(&stream);
-        return AVERROR(ENOMEM);
-    }
-
-    stream.next_in = data;
-    stream.avail_in = length;
-
-    do {
-        stream.avail_out = buf_size - stream.total_out;
-        stream.next_out = buf + stream.total_out;
-
-        ret = inflate(&stream, Z_FINISH);
-        if (ret != Z_OK && ret != Z_STREAM_END && ret != Z_BUF_ERROR) {
-            av_log(avctx, AV_LOG_ERROR, "zlib inflate error(%d): %s\n", ret, 
stream.msg);
-            inflateEnd(&stream);
-            av_free(buf);
-            return AVERROR(EINVAL);
-        }
-
-        if (stream.avail_out == 0) {
-            buf_size += CHUNK_SIZE;
-            tmp = av_realloc(buf, buf_size);
-            if (!tmp) {
-                inflateEnd(&stream);
-                av_free(buf);
-                return AVERROR(ENOMEM);
-            }
-            buf = tmp;
-        }
-    } while (ret != Z_STREAM_END);
-
-    // NULL-terminate string
-    // there is guaranteed to be space for this, due to condition in loop
-    buf[stream.total_out] = 0;
-
-    inflateEnd(&stream);
-
-    ret = CHECK_CU(cu->cuModuleLoadData(cu_module, buf));
-    av_free(buf);
+    uint8_t *out;
+    size_t out_len;
+    int ret = ff_zlib_expand(avctx, &out, &out_len,
+                             data, length);
+    if (ret < 0)
+        return ret;
+
+    ret = CHECK_CU(cu->cuModuleLoadData(cu_module, out));
+    av_free(out);
     return ret;
 #else
     return CHECK_CU(cu->cuModuleLoadData(cu_module, data));
diff --git a/libavutil/Makefile b/libavutil/Makefile
index ee77e51c08..c5241895ff 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -234,6 +234,7 @@ STLIBOBJS-$(CONFIG_SWSCALE)             += half2float.o
 SHLIBOBJS-$(HAVE_GNU_WINDRES)           += avutilres.o
 
 SKIPHEADERS                            += objc.h
+SKIPHEADERS-$(CONFIG_ZLIB)             += zlib_utils.h
 SKIPHEADERS-$(HAVE_CUDA_H)             += hwcontext_cuda.h
 SKIPHEADERS-$(CONFIG_CUDA)             += hwcontext_cuda_internal.h     \
                                           cuda_check.h
@@ -252,6 +253,7 @@ SKIPHEADERS-$(CONFIG_VULKAN)           += 
hwcontext_vulkan.h vulkan.h   \
                                           vulkan_loader.h
 SKIPHEADERS-$(CONFIG_LIBSHADERC)       += vulkan_spirv.h
 SKIPHEADERS-$(CONFIG_LIBGLSLANG)       += vulkan_spirv.h
+SKIPHEADERS-$(CONFIG_SHADER_COMPRESSION) += zlib_utils.h
 
 TESTPROGS = adler32                                                     \
             aes                                                         \
diff --git a/libavfilter/cuda/load_helper.c b/libavutil/zlib_utils.h
similarity index 62%
copy from libavfilter/cuda/load_helper.c
copy to libavutil/zlib_utils.h
index 115523d642..41b97cfd09 100644
--- a/libavfilter/cuda/load_helper.c
+++ b/libavutil/zlib_utils.h
@@ -16,47 +16,38 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "config.h"
+#ifndef AVUTIL_ZLIB_UTILS_H
+#define AVUTIL_ZLIB_UTILS_H
 
-#include "libavutil/hwcontext.h"
-#include "libavutil/hwcontext_cuda_internal.h"
-#include "libavutil/cuda_check.h"
-#include "libavutil/mem.h"
+#include <stdint.h>
+#include "log.h"
+#include "error.h"
+#include "mem.h"
 
-#if CONFIG_SHADER_COMPRESSION
 #include <zlib.h>
 #define CHUNK_SIZE 1024 * 64
-#endif
 
-#include "load_helper.h"
-
-#define CHECK_CU(x) FF_CUDA_CHECK_DL(avctx, cu, x)
-
-int ff_cuda_load_module(void *avctx, AVCUDADeviceContext *hwctx, CUmodule 
*cu_module,
-                        const unsigned char *data, const unsigned int length)
+static inline int ff_zlib_expand(void *ctx, uint8_t **out, size_t *out_len,
+                                 const uint8_t *src, int src_len)
 {
-    CudaFunctions *cu = hwctx->internal->cuda_dl;
-
-#if CONFIG_SHADER_COMPRESSION
-    z_stream stream = { 0 };
-    uint8_t *buf, *tmp;
-    uint64_t buf_size;
     int ret;
 
+    z_stream stream = { 0 };
     if (inflateInit2(&stream, 32 + 15) != Z_OK) {
-        av_log(avctx, AV_LOG_ERROR, "Error during zlib initialisation: %s\n", 
stream.msg);
+        av_log(ctx, AV_LOG_ERROR, "Error during zlib initialisation: %s\n",
+               stream.msg);
         return AVERROR(ENOSYS);
     }
 
-    buf_size = CHUNK_SIZE * 4;
-    buf = av_realloc(NULL, buf_size);
+    uint64_t buf_size = CHUNK_SIZE * 4;
+    uint8_t *buf = av_realloc(NULL, buf_size);
     if (!buf) {
         inflateEnd(&stream);
         return AVERROR(ENOMEM);
     }
 
-    stream.next_in = data;
-    stream.avail_in = length;
+    stream.next_in = src;
+    stream.avail_in = src_len;
 
     do {
         stream.avail_out = buf_size - stream.total_out;
@@ -64,7 +55,8 @@ int ff_cuda_load_module(void *avctx, AVCUDADeviceContext 
*hwctx, CUmodule *cu_mo
 
         ret = inflate(&stream, Z_FINISH);
         if (ret != Z_OK && ret != Z_STREAM_END && ret != Z_BUF_ERROR) {
-            av_log(avctx, AV_LOG_ERROR, "zlib inflate error(%d): %s\n", ret, 
stream.msg);
+            av_log(ctx, AV_LOG_ERROR, "zlib inflate error(%d): %s\n",
+                   ret, stream.msg);
             inflateEnd(&stream);
             av_free(buf);
             return AVERROR(EINVAL);
@@ -72,7 +64,7 @@ int ff_cuda_load_module(void *avctx, AVCUDADeviceContext 
*hwctx, CUmodule *cu_mo
 
         if (stream.avail_out == 0) {
             buf_size += CHUNK_SIZE;
-            tmp = av_realloc(buf, buf_size);
+            uint8_t *tmp = av_realloc(buf, buf_size);
             if (!tmp) {
                 inflateEnd(&stream);
                 av_free(buf);
@@ -88,10 +80,9 @@ int ff_cuda_load_module(void *avctx, AVCUDADeviceContext 
*hwctx, CUmodule *cu_mo
 
     inflateEnd(&stream);
 
-    ret = CHECK_CU(cu->cuModuleLoadData(cu_module, buf));
-    av_free(buf);
-    return ret;
-#else
-    return CHECK_CU(cu->cuModuleLoadData(cu_module, data));
-#endif
+    *out = buf;
+    *out_len = stream.total_out;
+
+    return 0;
 }
+#endif /* AVUTIL_ZLIB_UTILS_H */

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

Reply via email to