From 3d1fb92793c773ef2a7abe17347473905e5caab9 Mon Sep 17 00:00:00 2001 From: AwesomeAdam54321 Date: Wed, 21 Dec 2022 16:21:46 +0800 Subject: [PATCH 3/3] icecat-use-system-media-libs Support building with system media libraries. See Based on: https://svnweb.freebsd.org/ports/head/www/firefox-esr/files/patch-z-bug517422?revision=472833&view=markup Changes to files within the bundled libraries are omitted, since those files are removed from Guix sources. Modified for use with patch -p1, and to apply cleanly to GNU IceCat. --- build/moz.configure/old.configure | 5 ++ config/external/moz.build | 18 +++-- config/system-headers.mozbuild | 22 +++++++ dom/media/AudioStream.cpp | 14 +++- dom/media/AudioStream.h | 4 ++ dom/media/moz.build | 15 +++++ old-configure.in | 105 ++++++++++++++++++++++++++++++ toolkit/library/moz.build | 15 +++++ toolkit/moz.configure | 68 +++++++++++++++++++ xpcom/build/XPCOMInit.cpp | 4 ++ 10 files changed, 261 insertions(+), 9 deletions(-) diff --git a/build/moz.configure/old.configure b/build/moz.configure/old.configure index dc0880e3..dbe00432 100644 --- a/build/moz.configure/old.configure +++ b/build/moz.configure/old.configure @@ -95,6 +95,11 @@ def old_configure_options(*options): "--libdir", "--prefix", "--with-branding", + "--with-system-ogg", + "--with-system-soundtouch", + "--with-system-theora", + "--with-system-tremor", + "--with-system-vorbis", "--with-distribution-id", "--with-macbundlename-prefix", "--x-includes", diff --git a/config/external/moz.build b/config/external/moz.build index 7239fc6c..c1e2bdef 100644 --- a/config/external/moz.build +++ b/config/external/moz.build @@ -36,11 +36,20 @@ external_dirs += ["modules/woff2"] external_dirs += ["modules/xz-embedded"] -if CONFIG["MOZ_VORBIS"]: +if not CONFIG['MOZ_SYSTEM_OGG']: + external_dirs += ['media/libogg'] + +if CONFIG['MOZ_VORBIS'] and not CONFIG['MOZ_SYSTEM_VORBIS']: external_dirs += ["media/libvorbis"] -if CONFIG["MOZ_TREMOR"]: - external_dirs += ["media/libtremor"] +if CONFIG['MOZ_TREMOR'] and not CONFIG['MOZ_SYSTEM_TREMOR']: + external_dirs += ['media/libtremor'] + +if not CONFIG['MOZ_SYSTEM_THEORA']: + external_dirs += ['media/libtheora'] + +if not CONFIG['MOZ_SYSTEM_SOUNDTOUCH']: + external_dirs += ['media/libsoundtouch'] if not CONFIG["MOZ_SYSTEM_LIBVPX"]: external_dirs += ["media/libvpx"] @@ -69,11 +78,8 @@ external_dirs += [ "media/libcubeb", "media/libmkv", "media/libnestegg", - "media/libogg", "media/libopus", - "media/libtheora", "media/libspeex_resampler", - "media/libsoundtouch", "media/mp4parse-rust", "media/psshparser", ] diff --git a/config/system-headers.mozbuild b/config/system-headers.mozbuild index 5594d659..3336216f 100644 --- a/config/system-headers.mozbuild +++ b/config/system-headers.mozbuild @@ -1306,6 +1306,28 @@ if CONFIG['MOZ_SYSTEM_HARFBUZZ']: 'harfbuzz/hb.h', ] +if CONFIG['MOZ_SYSTEM_OGG']: + system_headers += [ + 'ogg/ogg.h', + 'ogg/os_types.h', + ] + +if CONFIG['MOZ_SYSTEM_THEORA']: + system_headers += [ + 'theora/theoradec.h', + ] + +if CONFIG['MOZ_SYSTEM_VORBIS']: + system_headers += [ + 'vorbis/codec.h', + 'vorbis/vorbisenc.h', + ] + +if CONFIG['MOZ_SYSTEM_TREMOR']: + system_headers += [ + 'tremor/ivorbiscodec.h', + ] + if CONFIG['MOZ_SYSTEM_LIBVPX']: system_headers += [ 'vpx_mem/vpx_mem.h', diff --git a/dom/media/AudioStream.cpp b/dom/media/AudioStream.cpp index e6c83328..a89e38bf 100644 --- a/dom/media/AudioStream.cpp +++ b/dom/media/AudioStream.cpp @@ -137,11 +137,14 @@ class FrameHistory { AudioStream::AudioStream(DataSource& aSource, uint32_t aInRate, uint32_t aOutputChannels, AudioConfig::ChannelLayout::ChannelMap aChannelMap) - : mTimeStretcher(nullptr), - mAudioClock(aInRate), + + : mAudioClock(aInRate), mChannelMap(aChannelMap), mMonitor("AudioStream"), mOutChannels(aOutputChannels), +#ifndef MOZ_SYSTEM_SOUNDTOUCH + mTimeStretcher(nullptr), +#endif mState(INITIALIZED), mDataSource(aSource), mAudioThreadId(ProfilerThreadId{}), @@ -170,7 +173,11 @@ size_t AudioStream::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { nsresult AudioStream::EnsureTimeStretcherInitialized() { AssertIsOnAudioThread(); if (!mTimeStretcher) { +#ifdef MOZ_SYSTEM_SOUNDTOUCH + mTimeStretcher = new soundtouch::SoundTouch(); +#else mTimeStretcher = soundtouch::createSoundTouchObj(); +#endif mTimeStretcher->setSampleRate(mAudioClock.GetInputRate()); mTimeStretcher->setChannels(mOutChannels); mTimeStretcher->setPitch(1.0); @@ -410,11 +417,12 @@ Maybe> AudioStream::Shutdown( // After `cubeb_stream_stop` has been called, there is no audio thread // anymore. We can delete the time stretcher. +#ifndef MOZ_SYSTEM_SOUNDTOUCH if (mTimeStretcher) { soundtouch::destroySoundTouchObj(mTimeStretcher); mTimeStretcher = nullptr; } - +#endif mState = SHUTDOWN; // When shutting down, if this AudioStream is shutting down because the // HTMLMediaElement is now muted, hand back the ended promise, so that it can diff --git a/dom/media/AudioStream.h b/dom/media/AudioStream.h index 86975c6a..394a26c9 100644 --- a/dom/media/AudioStream.h +++ b/dom/media/AudioStream.h @@ -342,7 +342,11 @@ class AudioStream final { bool CheckThreadIdChanged(); void AssertIsOnAudioThread() const; +#ifdef MOZ_SYSTEM_SOUNDTOUCH + nsAutoPtr mTimeStretcher; +#else soundtouch::SoundTouch* mTimeStretcher; +#endif AudioClock mAudioClock; diff --git a/dom/media/moz.build b/dom/media/moz.build index aab6f2d3..ded9d0a7 100644 --- a/dom/media/moz.build +++ b/dom/media/moz.build @@ -56,6 +56,21 @@ DIRS += [ "webvtt", ] +if CONFIG['MOZ_SYSTEM_OGG']: + CXXFLAGS += CONFIG['MOZ_OGG_CFLAGS'] + +if CONFIG['MOZ_SYSTEM_THEORA']: + CXXFLAGS += CONFIG['MOZ_THEORA_CFLAGS'] + +if CONFIG['MOZ_SYSTEM_VORBIS']: + CXXFLAGS += CONFIG['MOZ_VORBIS_CFLAGS'] + +if CONFIG['MOZ_SYSTEM_TREMOR']: + CXXFLAGS += CONFIG['MOZ_TREMOR_CFLAGS'] + +if CONFIG['MOZ_SYSTEM_SOUNDTOUCH']: + CXXFLAGS += CONFIG['MOZ_SOUNDTOUCH_CFLAGS'] + if CONFIG["MOZ_ANDROID_HLS_SUPPORT"]: DIRS += ["hls"] diff --git a/old-configure.in b/old-configure.in index 46723226..2af3d0c1 100644 --- a/old-configure.in +++ b/old-configure.in @@ -63,6 +63,111 @@ if test "$COMPILE_ENVIRONMENT"; then MOZ_ANDROID_NDK fi # COMPILE_ENVIRONMENT +dnl ======================================================== +dnl Check for libogg +dnl ======================================================== + +MOZ_ARG_WITH_BOOL(system-ogg, +[ --with-system-ogg Use system libogg (located with pkgconfig)], +MOZ_SYSTEM_OGG=1, +MOZ_SYSTEM_OGG=) + +if test -n "$MOZ_SYSTEM_OGG"; then + PKG_CHECK_MODULES(MOZ_OGG, ogg >= 1.3.3) + + _SAVE_LIBS=$LIBS + LIBS="$LIBS $MOZ_OGG_LIBS" + AC_CHECK_FUNC(ogg_set_mem_functions, [], + [AC_DEFINE(MOZ_OGG_NO_MEM_REPORTING)]) + LIBS=$_SAVE_LIBS +fi + +AC_SUBST(MOZ_SYSTEM_OGG) + +dnl ======================================================== +dnl Check for libvorbis +dnl ======================================================== + +MOZ_ARG_WITH_BOOL(system-vorbis, +[ --with-system-vorbis Use system libvorbis (located with pkgconfig)], +MOZ_SYSTEM_VORBIS=1, +MOZ_SYSTEM_VORBIS=) + +if test -n "$MOZ_SYSTEM_VORBIS"; then + PKG_CHECK_MODULES(MOZ_VORBIS, vorbis vorbisenc >= 1.3.6) +fi + +AC_SUBST(MOZ_SYSTEM_VORBIS) + +dnl ======================================================== +dnl Check for integer-only libvorbis aka tremor +dnl ======================================================== + +MOZ_ARG_WITH_BOOL(system-tremor, +[ --with-system-tremor Use system libtremor (located with pkgconfig)], +MOZ_SYSTEM_TREMOR=1, +MOZ_SYSTEM_TREMOR=) + +if test -n "$MOZ_SYSTEM_TREMOR"; then + PKG_CHECK_MODULES(MOZ_TREMOR, vorbisidec >= 1.2.1) +fi + +AC_SUBST(MOZ_SYSTEM_TREMOR) + +dnl ======================================================== +dnl Check for libtheora +dnl ======================================================== + +MOZ_ARG_WITH_BOOL(system-theora, +[ --with-system-theora Use system libtheora (located with pkgconfig)], +MOZ_SYSTEM_THEORA=1, +MOZ_SYSTEM_THEORA=) + +if test -n "$MOZ_SYSTEM_THEORA"; then + PKG_CHECK_MODULES(MOZ_THEORA, theora >= 1.2) +fi + +AC_SUBST(MOZ_SYSTEM_THEORA) + +dnl ======================================================== +dnl Check for libSoundTouch +dnl ======================================================== + +MOZ_ARG_WITH_BOOL(system-soundtouch, +[ --with-system-soundtouch Use system libSoundTouch (located with pkgconfig)], +MOZ_SYSTEM_SOUNDTOUCH=1, +MOZ_SYSTEM_SOUNDTOUCH=) + +if test -n "$MOZ_SYSTEM_SOUNDTOUCH"; then + PKG_CHECK_MODULES(MOZ_SOUNDTOUCH, soundtouch >= 1.9.0) + + AC_LANG_SAVE + AC_LANG_CPLUSPLUS + _SAVE_CXXFLAGS=$CXXFLAGS + CXXFLAGS="$CXXFLAGS $MOZ_SOUNDTOUCH_CFLAGS" + AC_CACHE_CHECK(for soundtouch sample type, + ac_cv_soundtouch_sample_type, + [AC_TRY_COMPILE([#include + #ifndef SOUNDTOUCH_INTEGER_SAMPLES + #error soundtouch expects float samples + #endif], + [], + [ac_cv_soundtouch_sample_type=short], + [ac_cv_soundtouch_sample_type=float])]) + CXXFLAGS=$_SAVE_CXXFLAGS + AC_LANG_RESTORE + + if test \( -n "$MOZ_SAMPLE_TYPE_S16" -a "$ac_cv_soundtouch_sample_type" != short \) \ + -o \( -n "$MOZ_SAMPLE_TYPE_FLOAT32" -a "$ac_cv_soundtouch_sample_type" != float \) ; then + AC_MSG_ERROR([SoundTouch library is built with incompatible sample type. Either rebuild the library with/without --enable-integer-samples, chase default Mozilla sample type or remove --with-system-soundtouch.]) + fi +fi + +if test -n "$MOZ_SYSTEM_SOUNDTOUCH"; then + AC_DEFINE(MOZ_SYSTEM_SOUNDTOUCH) +fi +AC_SUBST(MOZ_SYSTEM_SOUNDTOUCH) + dnl ======================================================== dnl Checks for compilers. dnl ======================================================== diff --git a/toolkit/library/moz.build b/toolkit/library/moz.build index 3e46b99e..545cf23c 100644 --- a/toolkit/library/moz.build +++ b/toolkit/library/moz.build @@ -306,6 +306,21 @@ if CONFIG['MOZ_SYSTEM_HARFBUZZ']: if CONFIG["MOZ_SYSTEM_WEBP"]: OS_LIBS += CONFIG["MOZ_WEBP_LIBS"] +if CONFIG['MOZ_SYSTEM_OGG']: + OS_LIBS += CONFIG['MOZ_OGG_LIBS'] + +if CONFIG['MOZ_SYSTEM_THEORA']: + OS_LIBS += CONFIG['MOZ_THEORA_LIBS'] + +if CONFIG['MOZ_SYSTEM_VORBIS']: + OS_LIBS += CONFIG['MOZ_VORBIS_LIBS'] + +if CONFIG['MOZ_SYSTEM_TREMOR']: + OS_LIBS += CONFIG['MOZ_TREMOR_LIBS'] + +if CONFIG['MOZ_SYSTEM_SOUNDTOUCH']: + OS_LIBS += CONFIG['MOZ_SOUNDTOUCH_LIBS'] + if CONFIG["MOZ_SYSTEM_LIBEVENT"]: OS_LIBS += CONFIG["MOZ_LIBEVENT_LIBS"] diff --git a/toolkit/moz.configure b/toolkit/moz.configure index f376fc95..06e00959 100644 --- a/toolkit/moz.configure +++ b/toolkit/moz.configure @@ -596,6 +596,74 @@ system_harfbuzz = pkg_check_modules('MOZ_HARFBUZZ', 'harfbuzz >= 1.7.4', set_config('MOZ_SYSTEM_HARFBUZZ', depends_if(system_harfbuzz)(lambda _: True)) +# Ogg +# ============================================================== +system_lib_option( + "--with-system-ogg", help="Use system libogg (located with pkgconfig)" +) + +system_ogg = pkg_check_modules( + "MOZ_OGG", "ogg >= 1.3.3", when="--with-system-ogg" +) + +set_config("MOZ_SYSTEM_OGG", depends(when=system_ogg)(lambda: True)) + +# Vorbis +# ============================================================== +option('--with-system-vorbis', + help="Use system libvorbis (located with pkgconfig)") + +@depends("--with-system-vorbis") +def vorbis(value): + return bool(value) + +system_vorbis = pkg_check_modules('MOZ_VORBIS', 'vorbis vorbisenc >= 1.3.6', + when=vorbis) + +set_config('MOZ_SYSTEM_VORBIS', depends_if(system_vorbis)(lambda _: True)) + +# Tremor +# ============================================================== +option('--with-system-tremor', + help="Use system libtremor (located with pkgconfig)") + +@depends("--with-system-tremor") +def tremor(value): + return bool(value) + +system_tremor = pkg_check_modules('MOZ_TREMOR', 'vorbisidec >= 1.2.1', + when=tremor) + +set_config('MOZ_SYSTEM_TREMOR', depends_if(system_tremor)(lambda _: True)) + +# Theora +# ============================================================== +option('--with-system-theora', + help="Use system libtheora (located with pkgconfig)") + +@depends("--with-system-theora") +def theora(value): + return bool(value) + +system_theora = pkg_check_modules('MOZ_THEORA', 'theora >= 1.2', + when=theora) + +set_config('MOZ_SYSTEM_THEORA', depends_if(system_theora)(lambda _: True)) + +# SoundTouch +# ============================================================== +option('--with-system-soundtouch', + help="Use system libSoundTouch (located with pkgconfig)") + +@depends("--with-system-soundtouch") +def soundtouch(value): + return bool(value) + +system_soundtouch = pkg_check_modules('MOZ_SOUNDTOUCH', 'soundtouch >= 1.9.0', + when=soundtouch) + +set_config('MOZ_SYSTEM_SOUNDTOUCH', depends_if(system_soundtouch)(lambda _: True)) + # Pango # ============================================================== pkg_check_modules("MOZ_PANGO", "pango >= 1.22.0", when=toolkit_gtk) diff --git a/xpcom/build/XPCOMInit.cpp b/xpcom/build/XPCOMInit.cpp index d13ea35e..8dad5f1a 100644 --- a/xpcom/build/XPCOMInit.cpp +++ b/xpcom/build/XPCOMInit.cpp @@ -93,7 +93,9 @@ #include "mozilla/ipc/GeckoChildProcessHost.h" +#ifndef MOZ_OGG_NO_MEM_REPORTING #include "ogg/ogg.h" +#endif #include "GeckoProfiler.h" #include "ProfilerControl.h" @@ -441,10 +443,12 @@ NS_InitXPCOM(nsIServiceManager** aResult, nsIFile* aBinDirectory, // this oddness. mozilla::SetICUMemoryFunctions(); +#ifndef MOZ_OGG_NO_MEM_REPORTING // Do the same for libogg. ogg_set_mem_functions( OggReporter::CountingMalloc, OggReporter::CountingCalloc, OggReporter::CountingRealloc, OggReporter::CountingFree); +#endif // Initialize the JS engine. InitializeJS(); -- 2.38.1