mirror of
https://github.com/moonlight-stream/moonlight-qt
synced 2024-12-14 21:32:27 +00:00
Don't block in audio/video renderer callbacks while the renderer is being destroyed
This commit is contained in:
parent
afb2b465a8
commit
605d52f160
2 changed files with 33 additions and 22 deletions
|
@ -120,7 +120,9 @@ void Session::arDecodeAndPlaySample(char* sampleData, int sampleLength)
|
||||||
SAMPLES_PER_FRAME,
|
SAMPLES_PER_FRAME,
|
||||||
0);
|
0);
|
||||||
if (samplesDecoded > 0) {
|
if (samplesDecoded > 0) {
|
||||||
SDL_AtomicLock(&s_ActiveSession->m_AudioRendererLock);
|
// If we can't acquire the lock, that means we're being destroyed
|
||||||
|
// so don't even bother trying to wait.
|
||||||
|
if (SDL_AtomicTryLock(&s_ActiveSession->m_AudioRendererLock)) {
|
||||||
if (s_ActiveSession->m_AudioRenderer != nullptr) {
|
if (s_ActiveSession->m_AudioRenderer != nullptr) {
|
||||||
s_ActiveSession->m_AudioRenderer->submitAudio(s_ActiveSession->m_OpusDecodeBuffer,
|
s_ActiveSession->m_AudioRenderer->submitAudio(s_ActiveSession->m_OpusDecodeBuffer,
|
||||||
static_cast<int>(sizeof(short) *
|
static_cast<int>(sizeof(short) *
|
||||||
|
@ -130,3 +132,4 @@ void Session::arDecodeAndPlaySample(char* sampleData, int sampleLength)
|
||||||
SDL_AtomicUnlock(&s_ActiveSession->m_AudioRendererLock);
|
SDL_AtomicUnlock(&s_ActiveSession->m_AudioRendererLock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -170,10 +170,12 @@ int Session::drSubmitDecodeUnit(PDECODE_UNIT du)
|
||||||
// Use a lock since we'll be yanking this decoder out
|
// Use a lock since we'll be yanking this decoder out
|
||||||
// from underneath the session when we initiate destruction.
|
// from underneath the session when we initiate destruction.
|
||||||
// We need to destroy the decoder on the main thread to satisfy
|
// We need to destroy the decoder on the main thread to satisfy
|
||||||
// some API constraints (like DXVA2).
|
// some API constraints (like DXVA2). If we can't acquire it,
|
||||||
|
// that means the decoder is about to be destroyed, so we can
|
||||||
SDL_AtomicLock(&s_ActiveSession->m_DecoderLock);
|
// safely return DR_OK and wait for m_NeedsIdr to be set by
|
||||||
|
// the decoder reinitialization code.
|
||||||
|
|
||||||
|
if (SDL_AtomicTryLock(&s_ActiveSession->m_DecoderLock)) {
|
||||||
if (s_ActiveSession->m_NeedsIdr) {
|
if (s_ActiveSession->m_NeedsIdr) {
|
||||||
// If we reset our decoder, we'll need to request an IDR frame
|
// If we reset our decoder, we'll need to request an IDR frame
|
||||||
s_ActiveSession->m_NeedsIdr = false;
|
s_ActiveSession->m_NeedsIdr = false;
|
||||||
|
@ -192,6 +194,12 @@ int Session::drSubmitDecodeUnit(PDECODE_UNIT du)
|
||||||
return DR_OK;
|
return DR_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// Decoder is going away. Ignore anything coming in until
|
||||||
|
// the lock is released.
|
||||||
|
return DR_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Session::isHardwareDecodeAvailable(StreamingPreferences::VideoDecoderSelection vds,
|
bool Session::isHardwareDecodeAvailable(StreamingPreferences::VideoDecoderSelection vds,
|
||||||
int videoFormat, int width, int height, int frameRate)
|
int videoFormat, int width, int height, int frameRate)
|
||||||
|
|
Loading…
Reference in a new issue