Fix and enhance the Full KMS check

This commit is contained in:
Cameron Gutman
2021-12-28 16:55:39 -06:00
parent 1616d237ae
commit 3da724e76a
+32 -7
View File
@@ -7,7 +7,7 @@
#include <SDL_syswm.h> #include <SDL_syswm.h>
#include <QFile> #include <QProcess>
#include <QTextStream> #include <QTextStream>
MmalRenderer::MmalRenderer() MmalRenderer::MmalRenderer()
@@ -236,13 +236,31 @@ void MmalRenderer::InputPortCallback(MMAL_PORT_T*, MMAL_BUFFER_HEADER_T* buffer)
bool MmalRenderer::isMmalOverlaySupported() bool MmalRenderer::isMmalOverlaySupported()
{ {
bool ret = true; if (qgetenv("MMAL_DISABLE_SUPPORT_CHECK") == "1") {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"MMAL overlay support check is disabled");
return true;
}
static bool mmalOverlayCheckCompleted = false;
static bool mmalOverlayCheckResult = true;
// This overlay support check is expensive, so only do it once. The stuff we're
// checking can't change without restarting Moonlight (or the whole system).
if (mmalOverlayCheckCompleted) {
SDL_MemoryBarrierAcquire();
return mmalOverlayCheckResult;
}
// MMAL rendering will silently fail in Full KMS mode. We'll see if that's // MMAL rendering will silently fail in Full KMS mode. We'll see if that's
// enabled by reading kernel log messages. It's gross but it works. // enabled by reading kernel log messages. It's gross but it works.
QFile file("/var/log/messages"); QProcess dmesgProc;
if (file.open(QIODevice::ReadOnly | QFile::Text)) { dmesgProc.setReadChannel(QProcess::StandardOutput);
QTextStream textStream(&file); dmesgProc.start("dmesg");
dmesgProc.waitForFinished();
if (dmesgProc.exitStatus() == QProcess::NormalExit && dmesgProc.exitCode() == 0) {
QTextStream textStream(&dmesgProc);
bool foundRpiVid = false; bool foundRpiVid = false;
QString line; QString line;
@@ -253,7 +271,7 @@ bool MmalRenderer::isMmalOverlaySupported()
"Full KMS Mode is enabled! H.264 video decoding/rendering performance will be degraded!"); "Full KMS Mode is enabled! H.264 video decoding/rendering performance will be degraded!");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Remove 'dtoverlay=vc4-kms-v3d' from your /boot/config.txt to fix this!"); "Remove 'dtoverlay=vc4-kms-v3d' from your /boot/config.txt to fix this!");
ret = false; mmalOverlayCheckResult = false;
} }
if (line.contains("rpivid")) { if (line.contains("rpivid")) {
foundRpiVid = true; foundRpiVid = true;
@@ -269,8 +287,15 @@ bool MmalRenderer::isMmalOverlaySupported()
"Raspberry Pi HEVC decoder cannot be used from within a desktop environment. H.264 will be used instead."); "Raspberry Pi HEVC decoder cannot be used from within a desktop environment. H.264 will be used instead.");
} }
} }
else {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Unable to check for Full KMS mode and HEVC decoding support (error %d)",
dmesgProc.exitCode());
}
return ret; SDL_MemoryBarrierRelease();
mmalOverlayCheckCompleted = true;
return mmalOverlayCheckResult;
} }
enum AVPixelFormat MmalRenderer::getPreferredPixelFormat(int) enum AVPixelFormat MmalRenderer::getPreferredPixelFormat(int)