Bug 1660336 Implement FFmpegLibWrapper::LinkVAAPILibs() to link VAAPI libraries and use at at FFmpegRuntimeLinker/FFVPXRuntimeLinker, r=jya
☠☠ backed out by 1ca5b384f447 ☠ ☠
authorMartin Stransky <stransky@redhat.com>
Thu, 05 Nov 2020 14:42:55 +0000
changeset 556027 bc879f51793059446cc08b2f9a0b230cd47534c0
parent 556026 a1fce14ac3a8d9f9cb797bbe2d3ab4d6efb4cfd1
child 556028 a2976995a4f51521d4074cf7abc9a363b22be1be
push id37924
push userapavel@mozilla.com
push dateThu, 05 Nov 2020 21:37:48 +0000
treeherdermozilla-central@5278acfcd834 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1660336
milestone84.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1660336 Implement FFmpegLibWrapper::LinkVAAPILibs() to link VAAPI libraries and use at at FFmpegRuntimeLinker/FFVPXRuntimeLinker, r=jya Differential Revision: https://phabricator.services.mozilla.com/D90556
dom/media/platforms/ffmpeg/FFmpegLibWrapper.cpp
dom/media/platforms/ffmpeg/FFmpegLibWrapper.h
dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp
dom/media/platforms/ffmpeg/ffvpx/FFVPXRuntimeLinker.cpp
--- a/dom/media/platforms/ffmpeg/FFmpegLibWrapper.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegLibWrapper.cpp
@@ -6,16 +6,19 @@
 #include "FFmpegLog.h"
 #include "mozilla/PodOperations.h"
 #ifdef MOZ_FFMPEG
 #  include "mozilla/StaticPrefs_media.h"
 #endif
 #include "mozilla/Types.h"
 #include "PlatformDecoderModule.h"
 #include "prlink.h"
+#ifdef MOZ_WAYLAND
+#  include "gfxPlatformGtk.h"
+#endif
 
 #define AV_LOG_DEBUG 48
 #define AV_LOG_INFO 32
 
 namespace mozilla {
 
 FFmpegLibWrapper::LinkResult FFmpegLibWrapper::Link() {
   if (!mAVCodecLib || !mAVUtilLib) {
@@ -249,16 +252,62 @@ void FFmpegLibWrapper::Unlink() {
   if (mVALibDrm) {
     PR_UnloadLibrary(mVALibDrm);
   }
 #endif
   PodZero(this);
 }
 
 #ifdef MOZ_WAYLAND
+void FFmpegLibWrapper::LinkVAAPILibs() {
+  if (gfxPlatformGtk::GetPlatform()->UseHardwareVideoDecoding()) {
+    PRLibSpec lspec;
+    lspec.type = PR_LibSpec_Pathname;
+
+    if (gfxPlatformGtk::GetPlatform()->UseDRMVAAPIDisplay()) {
+      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);
+      }
+    } else {
+      if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay()) {
+        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);
+        }
+      } else {
+        FFMPEG_LOG("VA-API X11 display is not implemented.\n");
+      }
+    }
+
+    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)
   return VA_FUNC_LOADED(avcodec_get_hw_config) &&
          VA_FUNC_LOADED(av_hwdevice_ctx_alloc) &&
          VA_FUNC_LOADED(av_hwdevice_ctx_init) &&
          VA_FUNC_LOADED(av_buffer_ref) && VA_FUNC_LOADED(av_buffer_unref) &&
          VA_FUNC_LOADED(av_hwframe_transfer_get_formats) &&
          VA_FUNC_LOADED(av_hwdevice_ctx_create_derived) &&
--- a/dom/media/platforms/ffmpeg/FFmpegLibWrapper.h
+++ b/dom/media/platforms/ffmpeg/FFmpegLibWrapper.h
@@ -51,16 +51,17 @@ struct MOZ_ONLY_USED_TO_AVOID_STATIC_CON
   LinkResult Link();
 
   // Reset the wrapper and unlink all attached libraries.
   void Unlink();
 
 #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.
   // 0 indicates that the function wasn't initialized with Link().
   int mVersion;
 
   // libavcodec
   unsigned (*avcodec_version)();
--- a/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp
@@ -52,60 +52,17 @@ static const char* sLibs[] = {
 
 /* static */
 bool FFmpegRuntimeLinker::Init() {
   if (sLinkStatus != LinkStatus_INIT) {
     return sLinkStatus == LinkStatus_SUCCEEDED;
   }
 
 #ifdef MOZ_WAYLAND
-  if (gfxPlatformGtk::GetPlatform()->UseHardwareVideoDecoding()) {
-    PRLibSpec lspec;
-    lspec.type = PR_LibSpec_Pathname;
-
-    if (gfxPlatformGtk::GetPlatform()->UseDRMVAAPIDisplay()) {
-      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);
-      }
-    } else {
-      if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay()) {
-        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);
-        }
-      } else {
-        FFMPEG_LOG("VA-API X11 display is not implemented.\n");
-      }
-    }
-
-    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
   // more precise error if possible.
   sLinkStatus = LinkStatus_NOT_FOUND;
 
   for (size_t i = 0; i < ArrayLength(sLibs); i++) {
     const char* lib = sLibs[i];
--- a/dom/media/platforms/ffmpeg/ffvpx/FFVPXRuntimeLinker.cpp
+++ b/dom/media/platforms/ffmpeg/ffvpx/FFVPXRuntimeLinker.cpp
@@ -59,16 +59,20 @@ static PRLibrary* MozAVLink(nsIFile* aFi
 bool FFVPXRuntimeLinker::Init() {
   if (sLinkStatus) {
     return sLinkStatus == LinkStatus_SUCCEEDED;
   }
 
   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");
   if (lgpllibsname.IsEmpty()) {
     return false;
   }
   PathString path = GetLibraryFilePathname(
       lgpllibsname.get(), (PRFuncPtr)&soundtouch::SoundTouch::getVersionId);