diff --git a/dom/media/platforms/ffmpeg/FFmpegLibWrapper.cpp b/dom/media/platforms/ffmpeg/FFmpegLibWrapper.cpp index 1ecfd9234544..ede66ec2bebf 100644 --- a/dom/media/platforms/ffmpeg/FFmpegLibWrapper.cpp +++ b/dom/media/platforms/ffmpeg/FFmpegLibWrapper.cpp @@ -11,6 +11,10 @@ #include "mozilla/Types.h" #include "PlatformDecoderModule.h" #include "prlink.h" +#ifdef MOZ_WAYLAND +# include "mozilla/widget/DMABufLibWrapper.h" +# include "mozilla/StaticPrefs_media.h" +#endif #define AV_LOG_DEBUG 48 #define AV_LOG_INFO 32 @@ -253,6 +257,46 @@ void FFmpegLibWrapper::Unlink() { PodZero(this); } +#ifdef MOZ_WAYLAND +void FFmpegLibWrapper::LinkVAAPILibs() { + if (widget::GetDMABufDevice()->IsDMABufVAAPIEnabled()) { + PRLibSpec lspec; + lspec.type = PR_LibSpec_Pathname; + const char* libDrm = "libva-drm.so.2"; + lspec.value.pathname = libDrm; + mVALibDrm = PR_LoadLibraryWithFlags(lspec, PR_LD_NOW | PR_LD_LOCAL); + if (!mVALibDrm) { + FFMPEG_LOG("VA-API support: Missing or old %s library.\n", libDrm); + } + + if (!StaticPrefs::media_ffmpeg_vaapi_drm_display_enabled()) { + const char* libWayland = "libva-wayland.so.2"; + lspec.value.pathname = libWayland; + mVALibWayland = PR_LoadLibraryWithFlags(lspec, PR_LD_NOW | PR_LD_LOCAL); + if (!mVALibWayland) { + FFMPEG_LOG("VA-API support: Missing or old %s library.\n", libWayland); + } + } + + if (mVALibWayland || mVALibDrm) { + const char* lib = "libva.so.2"; + lspec.value.pathname = lib; + mVALib = PR_LoadLibraryWithFlags(lspec, PR_LD_NOW | PR_LD_LOCAL); + // Don't use libva when it's missing vaExportSurfaceHandle. + if (mVALib && !PR_FindSymbol(mVALib, "vaExportSurfaceHandle")) { + PR_UnloadLibrary(mVALib); + mVALib = nullptr; + } + if (!mVALib) { + FFMPEG_LOG("VA-API support: Missing or old %s library.\n", lib); + } + } + } else { + FFMPEG_LOG("VA-API FFmpeg is disabled by platform"); + } +} +#endif + #ifdef MOZ_WAYLAND bool FFmpegLibWrapper::IsVAAPIAvailable() { # define VA_FUNC_LOADED(func) (func != nullptr) diff --git a/dom/media/platforms/ffmpeg/FFmpegLibWrapper.h b/dom/media/platforms/ffmpeg/FFmpegLibWrapper.h index 2a73ccabbc5e..22dc70f14059 100644 --- a/dom/media/platforms/ffmpeg/FFmpegLibWrapper.h +++ b/dom/media/platforms/ffmpeg/FFmpegLibWrapper.h @@ -56,6 +56,7 @@ struct MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS FFmpegLibWrapper { #ifdef MOZ_WAYLAND // Check if mVALib are available and we can use HW decode. bool IsVAAPIAvailable(); + void LinkVAAPILibs(); #endif // indicate the version of libavcodec linked to. diff --git a/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp b/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp index 8ff33c67a18e..63f1b710cdb3 100644 --- a/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp +++ b/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp @@ -9,10 +9,6 @@ #include "mozilla/ArrayUtils.h" #include "FFmpegLog.h" #include "prlink.h" -#ifdef MOZ_WAYLAND -# include "mozilla/widget/DMABufLibWrapper.h" -# include "mozilla/StaticPrefs_media.h" -#endif namespace mozilla { @@ -58,43 +54,7 @@ bool FFmpegRuntimeLinker::Init() { } #ifdef MOZ_WAYLAND - if (widget::GetDMABufDevice()->IsDMABufVAAPIEnabled()) { - PRLibSpec lspec; - lspec.type = PR_LibSpec_Pathname; - const char* libDrm = "libva-drm.so.2"; - lspec.value.pathname = libDrm; - sLibAV.mVALibDrm = PR_LoadLibraryWithFlags(lspec, PR_LD_NOW | PR_LD_LOCAL); - if (!sLibAV.mVALibDrm) { - FFMPEG_LOG("VA-API support: Missing or old %s library.\n", libDrm); - } - - if (!StaticPrefs::media_ffmpeg_vaapi_drm_display_enabled()) { - const char* libWayland = "libva-wayland.so.2"; - lspec.value.pathname = libWayland; - sLibAV.mVALibWayland = - PR_LoadLibraryWithFlags(lspec, PR_LD_NOW | PR_LD_LOCAL); - if (!sLibAV.mVALibWayland) { - FFMPEG_LOG("VA-API support: Missing or old %s library.\n", libWayland); - } - } - - if (sLibAV.mVALibWayland || sLibAV.mVALibDrm) { - const char* lib = "libva.so.2"; - lspec.value.pathname = lib; - sLibAV.mVALib = PR_LoadLibraryWithFlags(lspec, PR_LD_NOW | PR_LD_LOCAL); - // Don't use libva when it's missing vaExportSurfaceHandle. - if (sLibAV.mVALib && - !PR_FindSymbol(sLibAV.mVALib, "vaExportSurfaceHandle")) { - PR_UnloadLibrary(sLibAV.mVALib); - sLibAV.mVALib = nullptr; - } - if (!sLibAV.mVALib) { - FFMPEG_LOG("VA-API support: Missing or old %s library.\n", lib); - } - } - } else { - FFMPEG_LOG("VA-API FFmpeg is disabled by platform"); - } + sLibAV.LinkVAAPILibs(); #endif // While going through all possible libs, this status will be updated with a diff --git a/dom/media/platforms/ffmpeg/ffvpx/FFVPXRuntimeLinker.cpp b/dom/media/platforms/ffmpeg/ffvpx/FFVPXRuntimeLinker.cpp index ca301cb9db76..43480fcf8409 100644 --- a/dom/media/platforms/ffmpeg/ffvpx/FFVPXRuntimeLinker.cpp +++ b/dom/media/platforms/ffmpeg/ffvpx/FFVPXRuntimeLinker.cpp @@ -64,6 +64,10 @@ bool FFVPXRuntimeLinker::Init() { MOZ_ASSERT(NS_IsMainThread()); sLinkStatus = LinkStatus_FAILED; +#ifdef MOZ_WAYLAND + sFFVPXLib.LinkVAAPILibs(); +#endif + // We retrieve the path of the lgpllibs library as this is where mozavcodec // and mozavutil libs are located. PathString lgpllibsname = GetLibraryName(nullptr, "lgpllibs");