Fix DRM FD leak with Vulkan windows

This commit is contained in:
Cameron Gutman 2024-09-21 21:41:43 -05:00
parent 6f39d120cb
commit 023b6b2772
2 changed files with 9 additions and 7 deletions

View File

@ -141,7 +141,7 @@ DrmRenderer::DrmRenderer(AVHWDeviceType hwDeviceType, IFFmpegRenderer *backendRe
m_HwContext(nullptr), m_HwContext(nullptr),
m_DrmFd(-1), m_DrmFd(-1),
m_DrmIsMaster(false), m_DrmIsMaster(false),
m_SdlOwnsDrmFd(false), m_MustCloseDrmFd(false),
m_SupportsDirectRendering(false), m_SupportsDirectRendering(false),
m_VideoFormat(0), m_VideoFormat(0),
m_ConnectorId(0), m_ConnectorId(0),
@ -225,7 +225,7 @@ DrmRenderer::~DrmRenderer()
av_buffer_unref(&m_HwContext); av_buffer_unref(&m_HwContext);
} }
if (!m_SdlOwnsDrmFd && m_DrmFd != -1) { if (m_MustCloseDrmFd && m_DrmFd != -1) {
close(m_DrmFd); close(m_DrmFd);
} }
} }
@ -346,7 +346,7 @@ bool DrmRenderer::initialize(PDECODER_PARAMETERS params)
m_SwFrameMapper.setVideoFormat(params->videoFormat); m_SwFrameMapper.setVideoFormat(params->videoFormat);
// Try to get the FD that we're sharing with SDL // Try to get the FD that we're sharing with SDL
m_DrmFd = StreamUtils::getDrmFdForWindow(m_Window, &m_SdlOwnsDrmFd); m_DrmFd = StreamUtils::getDrmFdForWindow(m_Window, &m_MustCloseDrmFd);
if (m_DrmFd >= 0) { if (m_DrmFd >= 0) {
// If we got a DRM FD for the window, we can render to it // If we got a DRM FD for the window, we can render to it
m_DrmIsMaster = true; m_DrmIsMaster = true;
@ -354,17 +354,19 @@ bool DrmRenderer::initialize(PDECODER_PARAMETERS params)
// If we just opened a new FD, let's drop master on it // If we just opened a new FD, let's drop master on it
// so SDL can take master for Vulkan rendering. We'll // so SDL can take master for Vulkan rendering. We'll
// regrab master later if we end up direct rendering. // regrab master later if we end up direct rendering.
if (!m_SdlOwnsDrmFd) { if (m_MustCloseDrmFd) {
drmDropMaster(m_DrmFd); drmDropMaster(m_DrmFd);
} }
} }
else { else {
// Try to open any DRM render node // Try to open any DRM render node
m_DrmFd = StreamUtils::getDrmFd(true); m_DrmFd = StreamUtils::getDrmFd(true);
// Drop master in case we somehow got a primary node
if (m_DrmFd >= 0) { if (m_DrmFd >= 0) {
// Drop master in case we somehow got a primary node
drmDropMaster(m_DrmFd); drmDropMaster(m_DrmFd);
// This is a new FD that we must close
m_MustCloseDrmFd = true;
} }
} }

View File

@ -87,7 +87,7 @@ private:
AVBufferRef* m_HwContext; AVBufferRef* m_HwContext;
int m_DrmFd; int m_DrmFd;
bool m_DrmIsMaster; bool m_DrmIsMaster;
bool m_SdlOwnsDrmFd; bool m_MustCloseDrmFd;
bool m_SupportsDirectRendering; bool m_SupportsDirectRendering;
int m_VideoFormat; int m_VideoFormat;
uint32_t m_ConnectorId; uint32_t m_ConnectorId;