From 36218b54f80e96374f049767cacc80e37c0dc9fe Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 30 Jun 2022 19:25:33 -0500 Subject: [PATCH] Don't hardcode /dev/dri/card0 and /dev/dri/renderD128 --- app/streaming/video/ffmpeg-renderers/drm.cpp | 36 +++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/app/streaming/video/ffmpeg-renderers/drm.cpp b/app/streaming/video/ffmpeg-renderers/drm.cpp index 6bbe3d68..62c5c91e 100644 --- a/app/streaming/video/ffmpeg-renderers/drm.cpp +++ b/app/streaming/video/ffmpeg-renderers/drm.cpp @@ -29,8 +29,15 @@ extern "C" { #include +// HACK: Avoid including X11 headers which conflict with QDir +#ifdef SDL_VIDEO_DRIVER_X11 +#undef SDL_VIDEO_DRIVER_X11 +#endif + #include +#include + DrmRenderer::DrmRenderer(IFFmpegRenderer *backendRenderer) : m_BackendRenderer(backendRenderer), m_HwContext(nullptr), @@ -145,17 +152,36 @@ bool DrmRenderer::initialize(PDECODER_PARAMETERS params) m_DrmFd = open(userDevice, O_RDWR | O_CLOEXEC); } else { - const char* defaultDevices[] = {"/dev/dri/renderD128", "/dev/dri/card0"}; + QDir driDir("/dev/dri"); - for (unsigned int i = 0; i < SDL_arraysize(defaultDevices); i++) { - m_DrmFd = open(defaultDevices[i], O_RDWR | O_CLOEXEC); + // We have to explicitly ask for devices to be returned + driDir.setFilter(QDir::Files | QDir::System); + + // Try a render node first since we aren't using DRM for output in this codepath + for (QFileInfo& node : driDir.entryInfoList(QStringList("renderD*"))) { + QByteArray absolutePath = node.absoluteFilePath().toUtf8(); + m_DrmFd = open(absolutePath.constData(), O_RDWR | O_CLOEXEC); if (m_DrmFd >= 0) { SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, - "Opened DRM device: %s", - defaultDevices[i]); + "Opened DRM render node: %s", + absolutePath.constData()); break; } } + + // If that fails, try to use a primary node and hope for the best + if (m_DrmFd < 0) { + for (QFileInfo& node : driDir.entryInfoList(QStringList("card*"))) { + QByteArray absolutePath = node.absoluteFilePath().toUtf8(); + m_DrmFd = open(absolutePath.constData(), O_RDWR | O_CLOEXEC); + if (m_DrmFd >= 0) { + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, + "Opened DRM primary node: %s", + absolutePath.constData()); + break; + } + } + } } if (m_DrmFd < 0) {