From 97412b3c7933fc7496e1d2c2d6fa0631d355bc7a Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 19 Dec 2021 20:33:48 -0600 Subject: [PATCH] Display warnings about Full KMS mode and HEVC on the Pi 4 --- app/streaming/video/ffmpeg-renderers/mmal.cpp | 46 +++++++++++++++++++ app/streaming/video/ffmpeg-renderers/mmal.h | 1 + 2 files changed, 47 insertions(+) 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();