Skip to content

Commit

Permalink
Only use threads where necessary
Browse files Browse the repository at this point in the history
Threads use Asyncify, which slow things down, so building all of libav
with threads slows down everything. Only the CLI actually needs it.
  • Loading branch information
Yahweasel committed Sep 27, 2024
1 parent 798b0b6 commit 465c9ed
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
6 changes: 3 additions & 3 deletions mk/ffmpeg.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mk/ffmpeg.mk.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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)]]])

Expand Down
9 changes: 9 additions & 0 deletions patches/ffmpeg/05-fibers.diff
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions patches/ffmpeg/08-fftools.diff
Original file line number Diff line number Diff line change
Expand Up @@ -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 <pthread.h>

#if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1

0 comments on commit 465c9ed

Please sign in to comment.