Bug 1675453 [Linux] Get VA-API configuration from GetDMABufDevice instead of gfxPlatformGtk, r=jya
authorstransky <stransky@redhat.com>
Fri, 06 Nov 2020 14:12:59 +0000
changeset 556219 c116b0d0608dc5926f4660e36fa02ffe7587c8b8
parent 556218 01fde3de1f86b2aef5f4b6adf8fe98f99d4cfa20
child 556220 38f88d3710f0487f9e6f3c50a4690ea0df6f81e8
push id37929
push usernbeleuzu@mozilla.com
push dateSat, 07 Nov 2020 10:01:27 +0000
treeherdermozilla-central@e40cc6272439 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1675453
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 1675453 [Linux] Get VA-API configuration from GetDMABufDevice instead of gfxPlatformGtk, r=jya - Use static preference media.ffmpeg.vaapi.drm-display.enabled directly instead of gfxPlatformGtk::GetPlatform()->UseDRMVAAPIDisplay(). - Don't check Wayland environment by gfxPlatformGtk::GetPlatform()->IsWaylandDisplay() call, WaylandDisplayGetWLDisplay() will safely return null on X11 displays. - Don't check dmabuf texture state by gfxPlatformGtk::GetPlatform()->UseDMABufVideoTextures(), we wan't it enabled by default when VA-API is used. Disable it only when static pref media.ffmpeg.dmabuf-textures.disabled is set. - Enable VAAPI by GetDMABufDevice()->IsDMABufVAAPIEnabled() call which covers EGL environment check, DMABUF config and VA-API ffmpeg prefence check. Depends on D95997 Differential Revision: https://phabricator.services.mozilla.com/D95998
dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
--- a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
@@ -10,17 +10,16 @@
 #include "ImageContainer.h"
 #include "MP4Decoder.h"
 #include "MediaInfo.h"
 #include "VideoUtils.h"
 #include "VPXDecoder.h"
 #include "mozilla/layers/KnowsCompositor.h"
 #ifdef MOZ_WAYLAND_USE_VAAPI
 #  include "H264.h"
-#  include "gfxPlatformGtk.h"
 #  include "mozilla/layers/DMABUFSurfaceImage.h"
 #  include "mozilla/widget/DMABufLibWrapper.h"
 #endif
 
 #include "libavutil/pixfmt.h"
 #if LIBAVCODEC_VERSION_MAJOR < 54
 #  define AVPixelFormat PixelFormat
 #  define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P
@@ -205,37 +204,32 @@ bool FFmpegVideoDecoder<LIBAV_VER>::Crea
   }
 
   auto releaseVAAPIcontext =
       MakeScopeExit([&] { mLib->av_buffer_unref(&mVAAPIDeviceContext); });
 
   AVHWDeviceContext* hwctx = (AVHWDeviceContext*)mVAAPIDeviceContext->data;
   AVVAAPIDeviceContext* vactx = (AVVAAPIDeviceContext*)hwctx->hwctx;
 
-  if (gfxPlatformGtk::GetPlatform()->UseDRMVAAPIDisplay()) {
+  if (StaticPrefs::media_ffmpeg_vaapi_drm_display_enabled()) {
     mDisplay =
         mLib->vaGetDisplayDRM(widget::GetDMABufDevice()->GetGbmDeviceFd());
     if (!mDisplay) {
       FFMPEG_LOG("Can't get DRM VA-API display.");
       return false;
     }
   } else {
-    if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay()) {
-      wl_display* display = widget::WaylandDisplayGetWLDisplay();
-      if (!display) {
-        FFMPEG_LOG("Can't get default wayland display.");
-        return false;
-      }
-      mDisplay = mLib->vaGetDisplayWl(display);
-      if (!mDisplay) {
-        FFMPEG_LOG("Can't get Wayland VA-API display.");
-        return false;
-      }
-    } else {
-      FFMPEG_LOG("VA-API X11 display is not implemented.");
+    wl_display* display = widget::WaylandDisplayGetWLDisplay();
+    if (!display) {
+      FFMPEG_LOG("Can't get default wayland display.");
+      return false;
+    }
+    mDisplay = mLib->vaGetDisplayWl(display);
+    if (!mDisplay) {
+      FFMPEG_LOG("Can't get Wayland VA-API display.");
       return false;
     }
   }
 
   hwctx->user_opaque = new VAAPIDisplayHolder(mLib, mDisplay);
   hwctx->free = VAAPIDisplayReleaseCallback;
 
   int major, minor;
@@ -354,21 +348,20 @@ FFmpegVideoDecoder<LIBAV_VER>::FFmpegVid
       mInfo(aConfig),
       mLowLatency(aLowLatency) {
   // Use a new MediaByteBuffer as the object will be modified during
   // initialization.
   mExtraData = new MediaByteBuffer;
   mExtraData->AppendElements(*aConfig.mExtraData);
 
 #ifdef MOZ_WAYLAND_USE_VAAPI
-  mUseDMABufSurfaces =
-      gfxPlatformGtk::GetPlatform()->UseDMABufVideoTextures() &&
-      mImageAllocator &&
-      (mImageAllocator->GetCompositorBackendType() ==
-       layers::LayersBackend::LAYERS_WR);
+  mUseDMABufSurfaces = widget::GetDMABufDevice()->IsDMABufVAAPIEnabled() &&
+                       mImageAllocator &&
+                       (mImageAllocator->GetCompositorBackendType() ==
+                        layers::LayersBackend::LAYERS_WR);
 
   if (!mUseDMABufSurfaces) {
     FFMPEG_LOG("DMA-Buf/VA-API can't be used, WebRender/DMA-Buf is disabled");
   }
 #endif
 }
 
 RefPtr<MediaDataDecoder::InitPromise> FFmpegVideoDecoder<LIBAV_VER>::Init() {
@@ -749,20 +742,27 @@ bool FFmpegVideoDecoder<LIBAV_VER>::GetV
 MediaResult FFmpegVideoDecoder<LIBAV_VER>::CreateImageDMABuf(
     int64_t aOffset, int64_t aPts, int64_t aDuration,
     MediaDataDecoder::DecodedData& aResults) {
   FFMPEG_LOG("DMABUF/VA-API Got one frame output with pts=%" PRId64
              "dts=%" PRId64 " duration=%" PRId64 " opaque=%" PRId64,
              aPts, mFrame->pkt_dts, aDuration, mCodecContext->reordered_opaque);
 
   // With SW decode we support only YUV420P format with DMABuf surfaces.
-  if (!mVAAPIDeviceContext && mCodecContext->pix_fmt != AV_PIX_FMT_YUV420P) {
-    return MediaResult(
-        NS_ERROR_NOT_IMPLEMENTED,
-        RESULT_DETAIL("DMA-BUF textures supports YUV420P format only"));
+  if (!mVAAPIDeviceContext) {
+    if (StaticPrefs::media_ffmpeg_dmabuf_textures_disabled()) {
+      return MediaResult(
+          NS_ERROR_NOT_IMPLEMENTED,
+          RESULT_DETAIL("DMA-BUF textures are disabled by preference"));
+    }
+    if (mCodecContext->pix_fmt != AV_PIX_FMT_YUV420P) {
+      return MediaResult(
+          NS_ERROR_NOT_IMPLEMENTED,
+          RESULT_DETAIL("DMA-BUF textures supports YUV420P format only"));
+    }
   }
 
   VADRMPRIMESurfaceDescriptor vaDesc;
   if (mVAAPIDeviceContext && !GetVAAPISurfaceDescriptor(vaDesc)) {
     return MediaResult(
         NS_ERROR_OUT_OF_MEMORY,
         RESULT_DETAIL("Unable to get frame by vaExportSurfaceHandle()"));
   }