From 6fc5733c9632d59786b7ba7cb62c01a1a9a6fe0d Mon Sep 17 00:00:00 2001 From: Biswapriyo Nath Date: Mon, 10 Feb 2025 16:12:12 +0000 Subject: [PATCH 1/3] ffmpeg: Enable avfilter and avformat for gst-libav Previously, gst-libav failed to build due to absence of avfilter and avformat libraries from ffmpeg. This commit enables those libraries by fixing the build error with unistd.h. This imports a patch for zlib from vcpkg[^1] to fix the unistd.h check. In gvsbuild, zlib is build using nmake which copies the zconf.h file. So, the imported patch file was modified for zconf.h only. [^1]: https://github.com/microsoft/vcpkg/blob/master/ports/zlib/0001-Prevent-invalid-inclusions-when-HAVE_-is-set-to-0.patch --- gvsbuild/patches/ffmpeg/build/build.sh | 4 +-- ...id-inclusions-when-HAVE_-is-set-to-0.patch | 27 +++++++++++++++++++ gvsbuild/projects/ffmpeg.py | 10 ++++++- gvsbuild/projects/zlib.py | 4 ++- 4 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 gvsbuild/patches/zlib/0001-Prevent-invalid-inclusions-when-HAVE_-is-set-to-0.patch diff --git a/gvsbuild/patches/ffmpeg/build/build.sh b/gvsbuild/patches/ffmpeg/build/build.sh index eeb3fceee..45a578b56 100644 --- a/gvsbuild/patches/ffmpeg/build/build.sh +++ b/gvsbuild/patches/ffmpeg/build/build.sh @@ -15,6 +15,8 @@ configure_cmd[idx++]="--enable-shared" configure_cmd[idx++]="--disable-everything" configure_cmd[idx++]="--enable-swscale" configure_cmd[idx++]="--enable-avcodec" +configure_cmd[idx++]="--enable-avfilter" +configure_cmd[idx++]="--enable-avformat" configure_cmd[idx++]="--enable-hwaccel=av1_dxva2" configure_cmd[idx++]="--enable-hwaccel=h264_dxva2" configure_cmd[idx++]="--enable-hwaccel=hevc_dxva2" @@ -37,8 +39,6 @@ configure_cmd[idx++]="--enable-hwaccel=av1_nvdec" configure_cmd[idx++]="--enable-hwaccel=h264_nvdec" configure_cmd[idx++]="--enable-hwaccel=hevc_nvdec" configure_cmd[idx++]="--disable-programs" -configure_cmd[idx++]="--disable-avformat" -configure_cmd[idx++]="--disable-avfilter" configure_cmd[idx++]="--disable-avdevice" configure_cmd[idx++]="--disable-swresample" configure_cmd[idx++]="--disable-postproc" diff --git a/gvsbuild/patches/zlib/0001-Prevent-invalid-inclusions-when-HAVE_-is-set-to-0.patch b/gvsbuild/patches/zlib/0001-Prevent-invalid-inclusions-when-HAVE_-is-set-to-0.patch new file mode 100644 index 000000000..7e41d2bf3 --- /dev/null +++ b/gvsbuild/patches/zlib/0001-Prevent-invalid-inclusions-when-HAVE_-is-set-to-0.patch @@ -0,0 +1,27 @@ +From https://github.com/microsoft/vcpkg/blob/master/ports/zlib/0001-Prevent-invalid-inclusions-when-HAVE_-is-set-to-0.patch +Commit https://github.com/microsoft/vcpkg/commit/272269583c80a4ba626d405e79a88a2ddd6d950d + +--- a/zconf.h ++++ b/zconf.h +@@ -434,11 +434,19 @@ + #endif + + #ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ +-# define Z_HAVE_UNISTD_H ++# if ~(~HAVE_UNISTD_H + 0) == 0 && ~(~HAVE_UNISTD_H + 1) == 1 ++# define Z_HAVE_UNISTD_H ++# elif HAVE_UNISTD_H != 0 ++# define Z_HAVE_UNISTD_H ++# endif + #endif + + #ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ +-# define Z_HAVE_STDARG_H ++# if ~(~HAVE_STDARG_H + 0) == 0 && ~(~HAVE_STDARG_H + 1) == 1 ++# define Z_HAVE_STDARG_H ++# elif HAVE_STDARG_H != 0 ++# define Z_HAVE_STDARG_H ++# endif + #endif + + #ifdef STDC diff --git a/gvsbuild/projects/ffmpeg.py b/gvsbuild/projects/ffmpeg.py index 8c23a4cdb..318c2675d 100644 --- a/gvsbuild/projects/ffmpeg.py +++ b/gvsbuild/projects/ffmpeg.py @@ -61,6 +61,8 @@ def build(self): if configuration in ["debug-optimized", "debug"]: self.install(r".\libavcodec\avcodec-60.pdb bin") + self.install(r".\libavfilter\avfilter-10.pdb bin") + self.install(r".\libavformat\avformat-61.pdb bin") self.install(r".\libavutil\avutil-58.pdb bin") self.install(r".\libswscale\libswscale-7.pdb bin") @@ -69,7 +71,13 @@ def build(self): self.install(r".\COPYING.GPLv2 " r"share\doc\ffmpeg") def post_install(self): - for lib in ["avcodec.lib", "avutil.lib", "swscale.lib"]: + for lib in [ + "avcodec.lib", + "avfilter.lib", + "avformat.lib", + "avutil.lib", + "swscale.lib", + ]: self.builder.exec_msys( ["mv", lib, "../lib/"], working_dir=os.path.join(self.builder.gtk_dir, "bin"), diff --git a/gvsbuild/projects/zlib.py b/gvsbuild/projects/zlib.py index 2a030e7b1..9c2346cd9 100644 --- a/gvsbuild/projects/zlib.py +++ b/gvsbuild/projects/zlib.py @@ -39,7 +39,9 @@ def __init__(self): version="1.3.1", archive_url="https://github.com/madler/zlib/releases/download/v{version}/zlib-{version}.tar.xz", hash="38ef96b8dfe510d42707d9c781877914792541133e1870841463bfa73f883e32", - patches=[], + patches=[ + "0001-Prevent-invalid-inclusions-when-HAVE_-is-set-to-0.patch", + ], ) def build(self): From 6bcf79904cc98090b6883fadd33b2098ab04c5e7 Mon Sep 17 00:00:00 2001 From: Dan Yeaw Date: Thu, 13 Feb 2025 21:54:15 -0500 Subject: [PATCH 2/3] Simplify patch syntax --- ...id-inclusions-when-HAVE_-is-set-to-0.patch | 27 ------------------- .../zlib/001-fix-ffmpeg-build-failure.patch | 24 +++++++++++++++++ gvsbuild/projects/zlib.py | 2 +- 3 files changed, 25 insertions(+), 28 deletions(-) delete mode 100644 gvsbuild/patches/zlib/0001-Prevent-invalid-inclusions-when-HAVE_-is-set-to-0.patch create mode 100644 gvsbuild/patches/zlib/001-fix-ffmpeg-build-failure.patch diff --git a/gvsbuild/patches/zlib/0001-Prevent-invalid-inclusions-when-HAVE_-is-set-to-0.patch b/gvsbuild/patches/zlib/0001-Prevent-invalid-inclusions-when-HAVE_-is-set-to-0.patch deleted file mode 100644 index 7e41d2bf3..000000000 --- a/gvsbuild/patches/zlib/0001-Prevent-invalid-inclusions-when-HAVE_-is-set-to-0.patch +++ /dev/null @@ -1,27 +0,0 @@ -From https://github.com/microsoft/vcpkg/blob/master/ports/zlib/0001-Prevent-invalid-inclusions-when-HAVE_-is-set-to-0.patch -Commit https://github.com/microsoft/vcpkg/commit/272269583c80a4ba626d405e79a88a2ddd6d950d - ---- a/zconf.h -+++ b/zconf.h -@@ -434,11 +434,19 @@ - #endif - - #ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ --# define Z_HAVE_UNISTD_H -+# if ~(~HAVE_UNISTD_H + 0) == 0 && ~(~HAVE_UNISTD_H + 1) == 1 -+# define Z_HAVE_UNISTD_H -+# elif HAVE_UNISTD_H != 0 -+# define Z_HAVE_UNISTD_H -+# endif - #endif - - #ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ --# define Z_HAVE_STDARG_H -+# if ~(~HAVE_STDARG_H + 0) == 0 && ~(~HAVE_STDARG_H + 1) == 1 -+# define Z_HAVE_STDARG_H -+# elif HAVE_STDARG_H != 0 -+# define Z_HAVE_STDARG_H -+# endif - #endif - - #ifdef STDC diff --git a/gvsbuild/patches/zlib/001-fix-ffmpeg-build-failure.patch b/gvsbuild/patches/zlib/001-fix-ffmpeg-build-failure.patch new file mode 100644 index 000000000..8a898f5d8 --- /dev/null +++ b/gvsbuild/patches/zlib/001-fix-ffmpeg-build-failure.patch @@ -0,0 +1,24 @@ +Subject: [PATCH] Fix FFmpeg build failure +--- +Index: zconf.h +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/zconf.h b/zconf.h +--- a/zconf.h (revision 00161eff1de25e9eed56bffdbe58f2c07ca16e51) ++++ b/zconf.h (date 1739496977666) +@@ -436,11 +436,11 @@ + typedef unsigned long z_crc_t; + #endif + +-#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ ++#if defined(HAVE_UNISTD_H) && HAVE_UNISTD_H + # define Z_HAVE_UNISTD_H + #endif + +-#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ ++#if defined(HAVE_STDARG_H) && HAVE_STDARG_H + # define Z_HAVE_STDARG_H + #endif + diff --git a/gvsbuild/projects/zlib.py b/gvsbuild/projects/zlib.py index 9c2346cd9..48fadc420 100644 --- a/gvsbuild/projects/zlib.py +++ b/gvsbuild/projects/zlib.py @@ -40,7 +40,7 @@ def __init__(self): archive_url="https://github.com/madler/zlib/releases/download/v{version}/zlib-{version}.tar.xz", hash="38ef96b8dfe510d42707d9c781877914792541133e1870841463bfa73f883e32", patches=[ - "0001-Prevent-invalid-inclusions-when-HAVE_-is-set-to-0.patch", + "001-fix-ffmpeg-build-failure.patch", ], ) From 729f3de2c95dbec5629fc4651c144f0def61a8ac Mon Sep 17 00:00:00 2001 From: Dan Yeaw Date: Fri, 14 Feb 2025 10:25:16 -0500 Subject: [PATCH 3/3] Replace with upstream patch --- .../zlib/001-fix-ffmpeg-build-failure.patch | 74 +++++++++++++++---- 1 file changed, 60 insertions(+), 14 deletions(-) diff --git a/gvsbuild/patches/zlib/001-fix-ffmpeg-build-failure.patch b/gvsbuild/patches/zlib/001-fix-ffmpeg-build-failure.patch index 8a898f5d8..714b8d020 100644 --- a/gvsbuild/patches/zlib/001-fix-ffmpeg-build-failure.patch +++ b/gvsbuild/patches/zlib/001-fix-ffmpeg-build-failure.patch @@ -1,24 +1,70 @@ -Subject: [PATCH] Fix FFmpeg build failure +From 7108497fda9d4536a1afade7f42266e06dca4488 Mon Sep 17 00:00:00 2001 +From: Mark Adler +Date: Thu, 13 Feb 2025 22:44:48 -0800 +Subject: [PATCH] Check that HAVE_UNISTD_H and HAVE_STDARG_H are not defined as + 0. + --- -Index: zconf.h -IDEA additional info: -Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP -<+>UTF-8 -=================================================================== + configure | 4 ++-- + zconf.h | 4 ++-- + zconf.h.in | 4 ++-- + 3 files changed, 6 insertions(+), 6 deletions(-) + +diff --git a/configure b/configure +index 393c23c94..1834659fd 100755 +--- a/configure ++++ b/configure +@@ -611,7 +611,7 @@ cat > $test.c < zconf.temp.h ++ sed < zconf.h "/^#if HAVE_UNISTD_H-0.* may be/s/ HAVE_UNISTD_H-0\(.*\) may be/ 1\1 was/" > zconf.temp.h + mv zconf.temp.h zconf.h + echo "Checking for unistd.h... Yes." | tee -a configure.log + else +@@ -626,7 +626,7 @@ cat > $test.c < zconf.temp.h ++ sed < zconf.h "/^#if HAVE_STDARG_H-0.* may be/s/ HAVE_STDARG_H-0\(.*\) may be/ 1\1 was/" > zconf.temp.h + mv zconf.temp.h zconf.h + echo "Checking for stdarg.h... Yes." | tee -a configure.log + else diff --git a/zconf.h b/zconf.h ---- a/zconf.h (revision 00161eff1de25e9eed56bffdbe58f2c07ca16e51) -+++ b/zconf.h (date 1739496977666) -@@ -436,11 +436,11 @@ +index d6c159a1e..bc3ef079b 100644 +--- a/zconf.h ++++ b/zconf.h +@@ -436,11 +436,11 @@ typedef uLong FAR uLongf; typedef unsigned long z_crc_t; #endif - + -#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ -+#if defined(HAVE_UNISTD_H) && HAVE_UNISTD_H ++#if HAVE_UNISTD_H-0 /* may be set to #if 1 by ./configure */ # define Z_HAVE_UNISTD_H #endif - + -#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ -+#if defined(HAVE_STDARG_H) && HAVE_STDARG_H ++#if HAVE_STDARG_H-0 /* may be set to #if 1 by ./configure */ # define Z_HAVE_STDARG_H #endif - + +diff --git a/zconf.h.in b/zconf.h.in +index d6c159a1e..bc3ef079b 100644 +--- a/zconf.h.in ++++ b/zconf.h.in +@@ -436,11 +436,11 @@ typedef uLong FAR uLongf; + typedef unsigned long z_crc_t; + #endif + +-#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ ++#if HAVE_UNISTD_H-0 /* may be set to #if 1 by ./configure */ + # define Z_HAVE_UNISTD_H + #endif + +-#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ ++#if HAVE_STDARG_H-0 /* may be set to #if 1 by ./configure */ + # define Z_HAVE_STDARG_H + #endif +