diff --git a/app/streaming/video/ffmpeg-renderers/mmal.cpp b/app/streaming/video/ffmpeg-renderers/mmal.cpp index 3326724e..6edae8f7 100644 --- a/app/streaming/video/ffmpeg-renderers/mmal.cpp +++ b/app/streaming/video/ffmpeg-renderers/mmal.cpp @@ -7,6 +7,9 @@ #include +#include +#include + MmalRenderer::MmalRenderer() : m_Renderer(nullptr), m_InputPort(nullptr), @@ -108,6 +111,10 @@ bool MmalRenderer::initialize(PDECODER_PARAMETERS params) { MMAL_STATUS_T status; + if (!isMmalOverlaySupported()) { + return false; + } + m_Window = params->window; m_VideoWidth = params->width; m_VideoHeight = params->height; @@ -227,6 +234,45 @@ void MmalRenderer::InputPortCallback(MMAL_PORT_T*, MMAL_BUFFER_HEADER_T* buffer) mmal_buffer_header_release(buffer); } +bool MmalRenderer::isMmalOverlaySupported() +{ + bool ret = true; + + // 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. + QFile file("/var/log/messages"); + if (file.open(QIODevice::ReadOnly | QFile::Text)) { + QTextStream textStream(&file); + bool foundRpiVid = false; + QString line; + + do { + line = textStream.readLine(); + if (line.contains("vc4_crtc_ops")) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, + "Full KMS Mode is enabled! H.264 video decoding/rendering performance will be degraded!"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, + "Remove 'dtoverlay=vc4-kms-v3d' from your /boot/config.txt to fix this!"); + ret = false; + } + if (line.contains("rpivid")) { + foundRpiVid = true; + } + } while (!line.isNull()); + + if (!foundRpiVid) { + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + "Raspberry Pi HEVC decoder is not enabled! Add 'dtoverlay=rpivid-v4l2' to your /boot/config.txt to fix this!"); + } + else if (strcmp(SDL_GetCurrentVideoDriver(), "KMSDRM") != 0) { + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + "Raspberry Pi HEVC decoder cannot be used from within a desktop environment. H.264 will be used instead."); + } + } + + return ret; +} + enum AVPixelFormat MmalRenderer::getPreferredPixelFormat(int) { // Opaque MMAL buffers diff --git a/app/streaming/video/ffmpeg-renderers/mmal.h b/app/streaming/video/ffmpeg-renderers/mmal.h index cf19daf5..04836463 100644 --- a/app/streaming/video/ffmpeg-renderers/mmal.h +++ b/app/streaming/video/ffmpeg-renderers/mmal.h @@ -20,6 +20,7 @@ public: private: static void InputPortCallback(MMAL_PORT_T* port, MMAL_BUFFER_HEADER_T* buffer); + bool isMmalOverlaySupported(); void setupBackground(PDECODER_PARAMETERS params); void updateDisplayRegion();