From 465c9ed9f1161ee7b9ff0fc90cc1ca4b65112400 Mon Sep 17 00:00:00 2001 From: Yahweasel Date: Fri, 27 Sep 2024 12:07:53 -0400 Subject: [PATCH] Only use threads where necessary Threads use Asyncify, which slow things down, so building all of libav with threads slows down everything. Only the CLI actually needs it. --- mk/ffmpeg.mk | 6 +++--- mk/ffmpeg.mk.m4 | 2 +- patches/ffmpeg/05-fibers.diff | 9 +++++++++ patches/ffmpeg/08-fftools.diff | 16 ++++++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/mk/ffmpeg.mk b/mk/ffmpeg.mk index 6c820603..fd24f214 100644 --- a/mk/ffmpeg.mk +++ b/mk/ffmpeg.mk @@ -35,10 +35,10 @@ build/ffmpeg-$(FFMPEG_VERSION)/build-base-%/ffbuild/config.mak: build/inst/base/ cd build/ffmpeg-$(FFMPEG_VERSION)/build-base-$(*) && \ emconfigure env PKG_CONFIG_PATH="$(PWD)/build/inst/base/lib/pkgconfig" \ ../configure $(FFMPEG_CONFIG) \ - --arch=emscripten \ + --disable-pthreads --arch=emscripten \ --optflags="$(OPTFLAGS)" \ - --extra-cflags="-I$(PWD)/build/inst/base/include " \ - --extra-ldflags="-L$(PWD)/build/inst/base/lib -s INITIAL_MEMORY=25165824" \ + --extra-cflags="-I$(PWD)/build/inst/base/include -lemfiberthreads" \ + --extra-ldflags="-L$(PWD)/build/inst/base/lib -lemfiberthreads -s INITIAL_MEMORY=25165824" \ `cat ../../../configs/configs/$(*)/ffmpeg-config.txt` sed 's/--extra-\(cflags\|ldflags\)='\''[^'\'']*'\''//g' < build/ffmpeg-$(FFMPEG_VERSION)/build-base-$(*)/config.h > build/ffmpeg-$(FFMPEG_VERSION)/build-base-$(*)/config.h.tmp mv build/ffmpeg-$(FFMPEG_VERSION)/build-base-$(*)/config.h.tmp build/ffmpeg-$(FFMPEG_VERSION)/build-base-$(*)/config.h diff --git a/mk/ffmpeg.mk.m4 b/mk/ffmpeg.mk.m4 index b7eb4562..9f930431 100644 --- a/mk/ffmpeg.mk.m4 +++ b/mk/ffmpeg.mk.m4 @@ -47,7 +47,7 @@ part-install-$1-%: build/ffmpeg-$(FFMPEG_VERSION)/build-$1-%/libavformat/libavfo ]]]) # Base (asm.js and wasm) -buildrule(base, build/inst/base/lib/libemfiberthreads.a, [[[--arch=emscripten]]], [[[]]]) +buildrule(base, build/inst/base/lib/libemfiberthreads.a, [[[--disable-pthreads --arch=emscripten]]], [[[-lemfiberthreads]]]) # wasm + threads buildrule(thr, [[[]]], [[[--enable-pthreads --arch=emscripten]]], [[[$(THRFLAGS)]]]) diff --git a/patches/ffmpeg/05-fibers.diff b/patches/ffmpeg/05-fibers.diff index d22a86f3..bf1e62a3 100644 --- a/patches/ffmpeg/05-fibers.diff +++ b/patches/ffmpeg/05-fibers.diff @@ -2,6 +2,15 @@ Index: ffmpeg-7.0.2/configure =================================================================== --- ffmpeg-7.0.2.orig/configure +++ ffmpeg-7.0.2/configure +@@ -3999,7 +3999,7 @@ avfilter_extralibs="pthreads_extralibs" + avutil_extralibs="d3d11va_extralibs d3d12va_extralibs mediacodec_extralibs nanosleep_extralibs pthreads_extralibs vaapi_drm_extralibs vaapi_x11_extralibs vaapi_win32_extralibs vdpau_x11_extralibs" + + # programs +-ffmpeg_deps="avcodec avfilter avformat threads" ++ffmpeg_deps="avcodec avfilter avformat" + ffmpeg_select="aformat_filter anull_filter atrim_filter format_filter + hflip_filter null_filter + transpose_filter trim_filter vflip_filter" @@ -6744,7 +6744,10 @@ fi # check for some common methods of building with pthread support # do this before the optional library checks as some of them require pthreads diff --git a/patches/ffmpeg/08-fftools.diff b/patches/ffmpeg/08-fftools.diff index 1dd64abb..2229e768 100644 --- a/patches/ffmpeg/08-fftools.diff +++ b/patches/ffmpeg/08-fftools.diff @@ -218,3 +218,19 @@ Index: ffmpeg-7.0.2/fftools/ffprobe.c +#endif return ret < 0; } +Index: ffmpeg-7.0.2/libavutil/thread.h +=================================================================== +--- ffmpeg-7.0.2.orig/libavutil/thread.h ++++ ffmpeg-7.0.2/libavutil/thread.h +@@ -32,9 +32,9 @@ + + #include "error.h" + +-#if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS ++#if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS || defined(__EMSCRIPTEN__) + +-#if HAVE_PTHREADS ++#if HAVE_PTHREADS || defined(__EMSCRIPTEN__) + #include + + #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1