Draw background in MMAL renderer on X11

Fixes #412
This commit is contained in:
Cameron Gutman 2020-12-19 21:25:20 -06:00
parent 3162d2c17d
commit cd5b0e74e3
2 changed files with 45 additions and 1 deletions

View file

@ -5,9 +5,12 @@
#include <Limelight.h> #include <Limelight.h>
#include <SDL_syswm.h>
MmalRenderer::MmalRenderer() MmalRenderer::MmalRenderer()
: m_Renderer(nullptr), : m_Renderer(nullptr),
m_InputPort(nullptr) m_InputPort(nullptr),
m_BackgroundRenderer(nullptr)
{ {
} }
@ -20,6 +23,10 @@ MmalRenderer::~MmalRenderer()
if (m_Renderer != nullptr) { if (m_Renderer != nullptr) {
mmal_component_destroy(m_Renderer); mmal_component_destroy(m_Renderer);
} }
if (m_BackgroundRenderer != nullptr) {
SDL_DestroyRenderer(m_BackgroundRenderer);
}
} }
bool MmalRenderer::prepareDecoderContext(AVCodecContext* context, AVDictionary** options) bool MmalRenderer::prepareDecoderContext(AVCodecContext* context, AVDictionary** options)
@ -43,6 +50,9 @@ bool MmalRenderer::initialize(PDECODER_PARAMETERS params)
{ {
MMAL_STATUS_T status; MMAL_STATUS_T status;
// Clear the background if possible
setupBackground(params);
status = mmal_component_create(MMAL_COMPONENT_DEFAULT_VIDEO_RENDERER, &m_Renderer); status = mmal_component_create(MMAL_COMPONENT_DEFAULT_VIDEO_RENDERER, &m_Renderer);
if (status != MMAL_SUCCESS) { if (status != MMAL_SUCCESS) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
@ -134,6 +144,36 @@ bool MmalRenderer::initialize(PDECODER_PARAMETERS params)
return true; return true;
} }
void MmalRenderer::setupBackground(PDECODER_PARAMETERS params)
{
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if (!SDL_GetWindowWMInfo(params->window, &info)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_GetWindowWMInfo() failed: %s",
SDL_GetError());
return;
}
// On X11, we can safely create a renderer and draw a black background.
// Due to conflicts with Qt, it's unsafe to do this for KMSDRM.
if (info.subsystem == SDL_SYSWM_X11) {
m_BackgroundRenderer = SDL_CreateRenderer(params->window, -1, SDL_RENDERER_SOFTWARE);
if (m_BackgroundRenderer == nullptr) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_CreateRenderer() failed: %s",
SDL_GetError());
return;
}
SDL_SetRenderDrawColor(m_BackgroundRenderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(m_BackgroundRenderer);
SDL_RenderPresent(m_BackgroundRenderer);
}
}
void MmalRenderer::InputPortCallback(MMAL_PORT_T*, MMAL_BUFFER_HEADER_T* buffer) void MmalRenderer::InputPortCallback(MMAL_PORT_T*, MMAL_BUFFER_HEADER_T* buffer)
{ {
mmal_buffer_header_release(buffer); mmal_buffer_header_release(buffer);

View file

@ -21,7 +21,11 @@ public:
private: private:
static void InputPortCallback(MMAL_PORT_T* port, MMAL_BUFFER_HEADER_T* buffer); static void InputPortCallback(MMAL_PORT_T* port, MMAL_BUFFER_HEADER_T* buffer);
void setupBackground(PDECODER_PARAMETERS params);
MMAL_COMPONENT_T* m_Renderer; MMAL_COMPONENT_T* m_Renderer;
MMAL_PORT_T* m_InputPort; MMAL_PORT_T* m_InputPort;
SDL_Renderer* m_BackgroundRenderer;
}; };