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));
}
}