diff options
author | Chris Robinson <[email protected]> | 2021-04-26 20:25:24 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2021-04-26 20:25:24 -0700 |
commit | 26c8c50c2605e377f74d7a73bae3bbbf4f7bad61 (patch) | |
tree | 1d66be8cc28a32e965de87e5b51012c26b6b2b95 /al/source.cpp | |
parent | 22a8ebff8094785ec53aadef8489dc60f6939d55 (diff) |
Partially implement an extension to hold sources on disconnect
Rather than stopping voices/sources when the device becomes disconnected, the
context can be set to leave them alone. As a consequence, their state will
remain as playing and they'll keep their last known sample offset indefinately.
For applications mindful of this behavior, it will allow resetting or reopening
the device to reconnect and automatically resume where it left off.
Diffstat (limited to 'al/source.cpp')
-rw-r--r-- | al/source.cpp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/al/source.cpp b/al/source.cpp index 4855b72d..27eeff9c 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -551,15 +551,20 @@ void SendVoiceChanges(ALCcontext *ctx, VoiceChange *tail) device->waitForMix(); if UNLIKELY(!connected) { - /* If the device is disconnected, just ignore all pending changes. */ - VoiceChange *cur{ctx->mCurrentVoiceChange.load(std::memory_order_acquire)}; - while(VoiceChange *next{cur->mNext.load(std::memory_order_acquire)}) + if(ctx->mStopVoicesOnDisconnect.load(std::memory_order_acquire)) { - cur = next; - if(Voice *voice{cur->mVoice}) - voice->mSourceID.store(0, std::memory_order_relaxed); + /* If the device is disconnected and voices are stopped, just + * ignore all pending changes. + */ + VoiceChange *cur{ctx->mCurrentVoiceChange.load(std::memory_order_acquire)}; + while(VoiceChange *next{cur->mNext.load(std::memory_order_acquire)}) + { + cur = next; + if(Voice *voice{cur->mVoice}) + voice->mSourceID.store(0, std::memory_order_relaxed); + } + ctx->mCurrentVoiceChange.store(cur, std::memory_order_release); } - ctx->mCurrentVoiceChange.store(cur, std::memory_order_release); } } @@ -2925,17 +2930,22 @@ START_API_FUNC } ALCdevice *device{context->mALDevice.get()}; - /* If the device is disconnected, go right to stopped. */ + /* If the device is disconnected, and voices stop on disconnect, go right + * to stopped. + */ if UNLIKELY(!device->Connected.load(std::memory_order_acquire)) { - /* TODO: Send state change event? */ - for(ALsource *source : srchandles) + if(context->mStopVoicesOnDisconnect.load(std::memory_order_acquire)) { - source->Offset = 0.0; - source->OffsetType = AL_NONE; - source->state = AL_STOPPED; + for(ALsource *source : srchandles) + { + /* TODO: Send state change event? */ + source->Offset = 0.0; + source->OffsetType = AL_NONE; + source->state = AL_STOPPED; + } + return; } - return; } /* Count the number of reusable voices. */ |