mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-11-27 08:14:20 +00:00
Synchronize several renderer callbacks
Many renderers do not properly synchronize these on their own, so let's do it for them. HDR and window changes are infrequent enough not to really matter.
This commit is contained in:
1 parent
10270ca0f6
commit
1ced9dd9b0
4 files changed
+51
-7
No files matched your search
@@ -1263,8 +1263,12 @@ bool D3D11VARenderer::notifyWindowChanged(PWINDOW_STATE_CHANGE_INFO stateInfo)
|
||||
DXGI_SWAP_CHAIN_DESC1 swapchainDesc;
|
||||
m_SwapChain->GetDesc1(&swapchainDesc);
|
||||
|
||||
// Lock the context to avoid concurrent rendering
|
||||
lockContext(this);
|
||||
// Lock the context to avoid concurrent decoding use. This is
|
||||
// already synchronized with rendering by the render lock, so
|
||||
// we only need to do this when not using separate devices.
|
||||
if (m_DecodeDevice == m_RenderDevice) {
|
||||
lockContext(this);
|
||||
}
|
||||
|
||||
m_DisplayWidth = stateInfo->width;
|
||||
m_DisplayHeight = stateInfo->height;
|
||||
@@ -1294,17 +1298,23 @@ bool D3D11VARenderer::notifyWindowChanged(PWINDOW_STATE_CHANGE_INFO stateInfo)
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"IDXGISwapChain::ResizeBuffers() failed: %x",
|
||||
hr);
|
||||
unlockContext(this);
|
||||
if (m_DecodeDevice == m_RenderDevice) {
|
||||
unlockContext(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reset swapchain-dependent resources (RTV, viewport, etc)
|
||||
if (!setupSwapchainDependentResources()) {
|
||||
unlockContext(this);
|
||||
if (m_DecodeDevice == m_RenderDevice) {
|
||||
unlockContext(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
unlockContext(this);
|
||||
if (m_DecodeDevice == m_RenderDevice) {
|
||||
unlockContext(this);
|
||||
}
|
||||
|
||||
// We've handled this state change
|
||||
stateInfo->stateChangeFlags &= ~WINDOW_STATE_CHANGE_SIZE;
|
||||
|
||||
@@ -357,7 +357,9 @@ void Pacer::renderFrame(AVFrame* frame)
|
||||
m_VideoStats->totalPacerTimeUs += (beforeRender - (uint64_t)frame->pkt_dts);
|
||||
|
||||
// Render it
|
||||
m_VsyncRenderer->acquireRenderLock();
|
||||
m_VsyncRenderer->renderFrame(frame);
|
||||
m_VsyncRenderer->releaseRenderLock();
|
||||
uint64_t afterRender = LiGetMicroseconds();
|
||||
|
||||
m_VideoStats->totalRenderTimeUs += (afterRender - beforeRender);
|
||||
|
||||
@@ -155,10 +155,24 @@ public:
|
||||
VTMetal,
|
||||
};
|
||||
|
||||
IFFmpegRenderer(RendererType type) : m_Type(type) {}
|
||||
IFFmpegRenderer(RendererType type) : m_Type(type), m_RenderLock(SDL_CreateMutex()) {}
|
||||
virtual ~IFFmpegRenderer() {
|
||||
SDL_DestroyMutex(m_RenderLock);
|
||||
}
|
||||
|
||||
// Synchronizes with renderFrame(), setHdrMode(), and notifyWindowChanged()
|
||||
void acquireRenderLock() {
|
||||
SDL_LockMutex(m_RenderLock);
|
||||
}
|
||||
void releaseRenderLock() {
|
||||
SDL_UnlockMutex(m_RenderLock);
|
||||
}
|
||||
|
||||
virtual bool initialize(PDECODER_PARAMETERS params) = 0;
|
||||
virtual bool prepareDecoderContext(AVCodecContext* context, AVDictionary** options) = 0;
|
||||
|
||||
// Synchronized via the render lock
|
||||
// NOT synchronized with notifyOverlayUpdated()
|
||||
virtual void renderFrame(AVFrame* frame) = 0;
|
||||
|
||||
enum class InitFailureReason
|
||||
@@ -287,6 +301,7 @@ public:
|
||||
return getPreferredPixelFormat(videoFormat) == pixelFormat;
|
||||
}
|
||||
|
||||
// Synchronized via the render lock
|
||||
virtual void setHdrMode(bool) {
|
||||
// Nothing
|
||||
}
|
||||
@@ -296,6 +311,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
// Synchronized via the render lock
|
||||
virtual bool notifyWindowChanged(PWINDOW_STATE_CHANGE_INFO) {
|
||||
// Assume the renderer cannot handle window state changes
|
||||
return false;
|
||||
@@ -494,6 +510,13 @@ public:
|
||||
}
|
||||
|
||||
// IOverlayRenderer
|
||||
//
|
||||
// NB: May be called from an arbitrary thread concurrently with renderFrame(),
|
||||
// setHdrMode(), and notifyWindowUpdated(), however it does not race with
|
||||
// prepareToRender(), cleanupRenderContext(), initialize(), etc.
|
||||
//
|
||||
// NB2: This must NOT call acquireRenderLock() due to the possibility of a
|
||||
// deadlock during Pacer shutdown.
|
||||
virtual void notifyOverlayUpdated(Overlay::OverlayType) override {
|
||||
// Nothing
|
||||
}
|
||||
@@ -537,6 +560,7 @@ protected:
|
||||
|
||||
private:
|
||||
RendererType m_Type;
|
||||
SDL_mutex* m_RenderLock;
|
||||
|
||||
// Properties watched by hasFrameFormatChanged()
|
||||
int m_LastFrameWidth = 0;
|
||||
|
||||
@@ -77,12 +77,20 @@ bool FFmpegVideoDecoder::isHdrSupported()
|
||||
|
||||
void FFmpegVideoDecoder::setHdrMode(bool enabled)
|
||||
{
|
||||
m_FrontendRenderer->acquireRenderLock();
|
||||
m_FrontendRenderer->setHdrMode(enabled);
|
||||
m_FrontendRenderer->releaseRenderLock();
|
||||
}
|
||||
|
||||
bool FFmpegVideoDecoder::notifyWindowChanged(PWINDOW_STATE_CHANGE_INFO info)
|
||||
{
|
||||
return m_FrontendRenderer->notifyWindowChanged(info);
|
||||
bool ret;
|
||||
|
||||
m_FrontendRenderer->acquireRenderLock();
|
||||
ret = m_FrontendRenderer->notifyWindowChanged(info);
|
||||
m_FrontendRenderer->releaseRenderLock();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FFmpegVideoDecoder::getDecoderCapabilities()
|
||||
|
||||
Reference in new issue
Block a user