aboutsummaryrefslogtreecommitdiffstats
path: root/alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2021-04-26 20:25:24 -0700
committerChris Robinson <[email protected]>2021-04-26 20:25:24 -0700
commit26c8c50c2605e377f74d7a73bae3bbbf4f7bad61 (patch)
tree1d66be8cc28a32e965de87e5b51012c26b6b2b95 /alc
parent22a8ebff8094785ec53aadef8489dc60f6939d55 (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 'alc')
-rw-r--r--alc/alc.cpp5
-rw-r--r--alc/alcontext.h3
-rw-r--r--alc/alu.cpp6
-rw-r--r--alc/backends/oboe.cpp4
-rw-r--r--alc/inprogext.h5
5 files changed, 22 insertions, 1 deletions
diff --git a/alc/alc.cpp b/alc/alc.cpp
index d06ca067..47b77758 100644
--- a/alc/alc.cpp
+++ b/alc/alc.cpp
@@ -834,6 +834,8 @@ constexpr struct {
DECL(AL_FORMAT_UHJ4CHN8_SOFT),
DECL(AL_FORMAT_UHJ4CHN16_SOFT),
DECL(AL_FORMAT_UHJ4CHN_FLOAT32_SOFT),
+
+ DECL(AL_STOP_SOURCES_ON_DISCONNECT_SOFT),
};
#undef DECL
@@ -889,6 +891,7 @@ constexpr ALchar alExtList[] =
"AL_SOFT_events "
"AL_SOFTX_filter_gain_ex "
"AL_SOFT_gain_clamp_ex "
+ "AL_SOFTX_hold_on_disconnect "
"AL_SOFT_loop_points "
"AL_SOFTX_map_buffer "
"AL_SOFT_MSADPCM "
@@ -2269,6 +2272,8 @@ static bool ResetDeviceParams(ALCdevice *device, const int *attrList)
for(ContextBase *ctxbase : *device->mContexts.load(std::memory_order_acquire))
{
auto *ctx = static_cast<ALCcontext*>(ctxbase);
+ if(!ctx->mStopVoicesOnDisconnect.load(std::memory_order_acquire))
+ continue;
/* Clear any pending voice changes and reallocate voices to get a
* clean restart.
diff --git a/alc/alcontext.h b/alc/alcontext.h
index b1b41e76..075e6a55 100644
--- a/alc/alcontext.h
+++ b/alc/alcontext.h
@@ -35,6 +35,8 @@ struct Voice;
struct VoiceChange;
struct VoicePropsItem;
+using uint = unsigned int;
+
enum class DistanceModel : unsigned char {
Disable,
@@ -108,6 +110,7 @@ struct ContextBase {
*/
RefCount mUpdateCount{0u};
std::atomic<bool> mHoldUpdates{false};
+ std::atomic<bool> mStopVoicesOnDisconnect{true};
float mGainBoost{1.0f};
diff --git a/alc/alu.cpp b/alc/alu.cpp
index 168f0112..d7f4410f 100644
--- a/alc/alu.cpp
+++ b/alc/alu.cpp
@@ -2030,6 +2030,12 @@ void DeviceBase::handleDisconnect(const char *msg, ...)
}
}
+ if(!ctx->mStopVoicesOnDisconnect)
+ {
+ ProcessVoiceChanges(ctx);
+ continue;
+ }
+
auto voicelist = ctx->getVoicesSpanAcquired();
auto stop_voice = [](Voice *voice) -> void
{
diff --git a/alc/backends/oboe.cpp b/alc/backends/oboe.cpp
index d82db834..28ade849 100644
--- a/alc/backends/oboe.cpp
+++ b/alc/backends/oboe.cpp
@@ -5,8 +5,10 @@
#include <cassert>
#include <cstring>
+#include <stdint.h>
-#include "alu.h"
+#include "alnumeric.h"
+#include "core/device.h"
#include "core/logging.h"
#include "oboe/Oboe.h"
diff --git a/alc/inprogext.h b/alc/inprogext.h
index 091703e2..781ccfd3 100644
--- a/alc/inprogext.h
+++ b/alc/inprogext.h
@@ -89,6 +89,11 @@ ALCboolean ALC_APIENTRY alcReopenDeviceSOFT(ALCdevice *device, const ALCchar *de
#define AL_FORMAT_UHJ4CHN_FLOAT32_SOFT 0x19AA
#endif
+#ifndef AL_SOFT_hold_on_disconnect
+#define AL_SOFT_hold_on_disconnect
+#define AL_STOP_SOURCES_ON_DISCONNECT_SOFT 0x19AB
+#endif
+
#ifdef __cplusplus
} /* extern "C" */
#endif