Move audio renderer destruction back off the main thread now that we're using atexit(SDL_Quit)

This commit is contained in:
Cameron Gutman 2018-09-30 18:09:12 -07:00
parent f7789a1e4a
commit c239d0814b
3 changed files with 7 additions and 29 deletions

View File

@ -94,21 +94,13 @@ int Session::arInit(int /* audioConfiguration */,
void Session::arCleanup()
{
// m_AudioRenderer is deleted in cleanupAudioRenderer()
delete s_ActiveSession->m_AudioRenderer;
s_ActiveSession->m_AudioRenderer = nullptr;
opus_multistream_decoder_destroy(s_ActiveSession->m_OpusDecoder);
s_ActiveSession->m_OpusDecoder = nullptr;
}
// This is called on the main thread
void Session::cleanupAudioRendererOnMainThread()
{
SDL_AtomicLock(&m_AudioRendererLock);
delete m_AudioRenderer;
m_AudioRenderer = nullptr;
SDL_AtomicUnlock(&m_AudioRendererLock);
}
void Session::arDecodeAndPlaySample(char* sampleData, int sampleLength)
{
int samplesDecoded;
@ -120,16 +112,9 @@ void Session::arDecodeAndPlaySample(char* sampleData, int sampleLength)
SAMPLES_PER_FRAME,
0);
if (samplesDecoded > 0) {
// 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) {
s_ActiveSession->m_AudioRenderer->submitAudio(s_ActiveSession->m_OpusDecodeBuffer,
static_cast<int>(sizeof(short) *
samplesDecoded *
s_ActiveSession->m_AudioConfig.channelCount));
}
SDL_AtomicUnlock(&s_ActiveSession->m_AudioRendererLock);
}
s_ActiveSession->m_AudioRenderer->submitAudio(s_ActiveSession->m_OpusDecodeBuffer,
static_cast<int>(sizeof(short) *
samplesDecoded *
s_ActiveSession->m_AudioConfig.channelCount));
}
}

View File

@ -288,8 +288,7 @@ Session::Session(NvComputer* computer, NvApp& app, StreamingPreferences *prefere
m_DisplayOriginY(0),
m_PendingWindowedTransition(false),
m_OpusDecoder(nullptr),
m_AudioRenderer(nullptr),
m_AudioRendererLock(0)
m_AudioRenderer(nullptr)
{
}
@ -1143,9 +1142,6 @@ DispatchDeferredCleanup:
m_VideoDecoder = nullptr;
SDL_AtomicUnlock(&m_DecoderLock);
// Destroy the audio renderer which must also be done on the main thread
cleanupAudioRendererOnMainThread();
SDL_DestroyWindow(m_Window);
if (iconSurface != nullptr) {
SDL_FreeSurface(iconSurface);

View File

@ -54,8 +54,6 @@ private:
int detectAudioConfiguration();
void cleanupAudioRendererOnMainThread();
bool testAudio(int audioConfiguration);
void getWindowDimensions(int& x, int& y,
@ -126,7 +124,6 @@ private:
short m_OpusDecodeBuffer[MAX_CHANNELS * SAMPLES_PER_FRAME];
IAudioRenderer* m_AudioRenderer;
OPUS_MULTISTREAM_CONFIGURATION m_AudioConfig;
SDL_SpinLock m_AudioRendererLock;
static AUDIO_RENDERER_CALLBACKS k_AudioCallbacks;
static CONNECTION_LISTENER_CALLBACKS k_ConnCallbacks;