From 6468efd7e4030f6f80564d511262e3f2d4382430 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 7 Jul 2019 15:31:15 -0700 Subject: [PATCH] Add VAAPI DRM support --- app/app.pro | 9 ++++ .../video/ffmpeg-renderers/vaapi.cpp | 43 ++++++++++++++++++- app/streaming/video/ffmpeg-renderers/vaapi.h | 4 ++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/app/app.pro b/app/app.pro index 7eb37dad..e9e7cd2e 100644 --- a/app/app.pro +++ b/app/app.pro @@ -84,6 +84,9 @@ unix:!macx { packagesExist(libva-wayland) { CONFIG += libva-wayland } + packagesExist(libva-drm) { + CONFIG += libva-drm + } CONFIG += libva } @@ -216,6 +219,12 @@ libva-wayland { PKGCONFIG += libva-wayland DEFINES += HAVE_LIBVA_WAYLAND } +libva-wayland { + message(VAAPI DRM support enabled) + + PKGCONFIG += libva-drm + DEFINES += HAVE_LIBVA_DRM +} libvdpau { message(VDPAU renderer selected) diff --git a/app/streaming/video/ffmpeg-renderers/vaapi.cpp b/app/streaming/video/ffmpeg-renderers/vaapi.cpp index d50782e7..dc4634b7 100644 --- a/app/streaming/video/ffmpeg-renderers/vaapi.cpp +++ b/app/streaming/video/ffmpeg-renderers/vaapi.cpp @@ -5,8 +5,12 @@ #include +#include +#include + VAAPIRenderer::VAAPIRenderer() - : m_HwContext(nullptr) + : m_HwContext(nullptr), + m_DrmFd(-1) { } @@ -26,6 +30,10 @@ VAAPIRenderer::~VAAPIRenderer() vaTerminate(display); } } + + if (m_DrmFd != -1) { + close(m_DrmFd); + } } bool @@ -86,6 +94,39 @@ VAAPIRenderer::initialize(PDECODER_PARAMETERS params) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Moonlight not compiled with VAAPI Wayland support!"); return false; +#endif + } + // TODO: Upstream a better solution for SDL_GetWindowWMInfo on KMSDRM + else if (strcmp(SDL_GetCurrentVideoDriver(), "KMSDRM") == 0) { +#ifdef HAVE_LIBVA_DRM + const char* device = SDL_getenv("DRM_DEV"); + + if (device == nullptr) { + device = "/dev/dri/card0"; + } + + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, + "Opening DRM device: %s", + device); + + m_DrmFd = open(device, O_RDWR | O_CLOEXEC); + if (m_DrmFd < 0) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, + "Failed to open DRM device: %d", + errno); + return false; + } + + vaDeviceContext->display = vaGetDisplayDRM(m_DrmFd); + if (!vaDeviceContext->display) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, + "Unable to open DRM display for VAAPI"); + return false; + } +#else + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, + "Moonlight not compiled with VAAPI DRM support!"); + return false; #endif } else { diff --git a/app/streaming/video/ffmpeg-renderers/vaapi.h b/app/streaming/video/ffmpeg-renderers/vaapi.h index 58a8260b..74211072 100644 --- a/app/streaming/video/ffmpeg-renderers/vaapi.h +++ b/app/streaming/video/ffmpeg-renderers/vaapi.h @@ -22,6 +22,9 @@ extern "C" { #ifdef HAVE_LIBVA_WAYLAND #include #endif +#ifdef HAVE_LIBVA_DRM +#include +#endif #include } @@ -39,6 +42,7 @@ public: private: int m_WindowSystem; AVBufferRef* m_HwContext; + int m_DrmFd; #ifdef HAVE_LIBVA_X11 Window m_XWindow;