Move ownership of the overlay callback registration to Pacer

This allows it to synchronize with the lifetime of the rendering context.
This commit is contained in:
Cameron Gutman committed 2026-10-29 22:54:19 -05:00
1 parent 017b603972
commit 10270ca0f6
2 files changed
+18 -18

No files matched your search

@@ -1,5 +1,6 @@
#include "pacer.h"
#include "streaming/streamutils.h"
#include "streaming/session.h"
#ifdef Q_OS_WIN32
#define WIN32_LEAN_AND_MEAN
@@ -64,6 +65,9 @@ Pacer::~Pacer()
SDL_WaitThread(m_RenderThread, nullptr);
}
else {
// Stop any further overlay callbacks
Session::get()->getOverlayManager().setOverlayRenderer(nullptr);
// Notify the renderer that it is being destroyed soon
// NB: This must happen on the same thread that calls renderFrame().
m_VsyncRenderer->cleanupRenderContext();
@@ -177,6 +181,9 @@ int Pacer::renderThread(void* context)
me->renderFrame(frame);
}
// Stop any further overlay callbacks
Session::get()->getOverlayManager().setOverlayRenderer(nullptr);
// Notify the renderer that it is being destroyed soon
// NB: This must happen on the same thread that calls renderFrame().
me->m_VsyncRenderer->cleanupRenderContext();
@@ -325,6 +332,12 @@ bool Pacer::initialize(SDL_Window* window, int maxVideoFps, bool enablePacing)
m_VsyncThread = SDL_CreateThread(Pacer::vsyncThread, "PacerVsync", this);
}
// Allow the renderer to perform final preparations for rendering
m_VsyncRenderer->prepareToRender();
// Tell overlay manager to use this frontend renderer
Session::get()->getOverlayManager().setOverlayRenderer(m_VsyncRenderer);
if (m_VsyncRenderer->isRenderThreadSupported()) {
m_RenderThread = SDL_CreateThread(Pacer::renderThread, "PacerRender", this);
}
+5 -18
View File
@@ -288,10 +288,6 @@ void FFmpegVideoDecoder::reset()
// need to delete in the renderer destructor.
avcodec_free_context(&m_VideoDecoderCtx);
if (m_CurrentTestMode != TestMode::TestFrameOnly) {
Session::get()->getOverlayManager().setOverlayRenderer(nullptr);
}
// If we have a separate frontend renderer, free that first
if (m_FrontendRenderer != m_BackendRenderer) {
delete m_FrontendRenderer;
@@ -494,15 +490,6 @@ bool FFmpegVideoDecoder::completeInitialization(const AVCodec* decoder, enum AVP
m_VideoFormat = params->videoFormat;
m_CurrentTestMode = testMode;
// Don't bother initializing Pacer if we're not actually going to render
if (testMode != TestMode::TestFrameOnly) {
m_Pacer = new Pacer(m_FrontendRenderer, &m_ActiveWndVideoStats);
if (!m_Pacer->initialize(params->window, params->frameRate,
params->enableFramePacing || (params->enableVsync && (m_FrontendRenderer->getRendererAttributes() & RENDERER_ATTRIBUTE_FORCE_PACING)))) {
return false;
}
}
m_VideoDecoderCtx = avcodec_alloc_context3(decoder);
if (!m_VideoDecoderCtx) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
@@ -723,11 +710,11 @@ bool FFmpegVideoDecoder::completeInitialization(const AVCodec* decoder, enum AVP
m_NeedsSpsFixup = false;
}
// Tell overlay manager to use this frontend renderer
Session::get()->getOverlayManager().setOverlayRenderer(m_FrontendRenderer);
// Allow the renderer to perform final preparations for rendering
m_FrontendRenderer->prepareToRender();
m_Pacer = new Pacer(m_FrontendRenderer, &m_ActiveWndVideoStats);
if (!m_Pacer->initialize(params->window, params->frameRate,
params->enableFramePacing || (params->enableVsync && (m_FrontendRenderer->getRendererAttributes() & RENDERER_ATTRIBUTE_FORCE_PACING)))) {
return false;
}
// Only create the decoder thread when instantiating the decoder for real. It will use APIs from
// moonlight-common-c that can only be legally called with an established connection.