diff options
-rw-r--r-- | al/source.cpp | 4 | ||||
-rw-r--r-- | alc/alc.cpp | 6 | ||||
-rw-r--r-- | alc/backends/base.h | 3 | ||||
-rw-r--r-- | alc/device.cpp | 13 | ||||
-rw-r--r-- | alc/device.h | 11 | ||||
-rw-r--r-- | core/device.cpp | 16 | ||||
-rw-r--r-- | core/device.h | 8 |
7 files changed, 34 insertions, 27 deletions
diff --git a/al/source.cpp b/al/source.cpp index 734a3308..7ba08970 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -1923,7 +1923,7 @@ bool GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a values[0] = GetSourceSecOffset(Source, Context, &srcclock); { std::lock_guard<std::mutex> _{device->StateLock}; - clocktime = GetClockLatency(device); + clocktime = GetClockLatency(device, device->Backend.get()); } if(srcclock == clocktime.ClockTime) values[1] = static_cast<double>(clocktime.Latency.count()) / 1000000000.0; @@ -2216,7 +2216,7 @@ bool GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const values[0] = GetSourceSampleOffset(Source, Context, &srcclock); { std::lock_guard<std::mutex> _{device->StateLock}; - clocktime = GetClockLatency(device); + clocktime = GetClockLatency(device, device->Backend.get()); } if(srcclock == clocktime.ClockTime) values[1] = clocktime.Latency.count(); diff --git a/alc/alc.cpp b/alc/alc.cpp index 36f726fc..1b62e042 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -2817,7 +2817,7 @@ START_API_FUNC values[i++] = ALC_OUTPUT_LIMITER_SOFT; values[i++] = dev->Limiter ? ALC_TRUE : ALC_FALSE; - ClockLatency clock{GetClockLatency(dev.get())}; + ClockLatency clock{GetClockLatency(dev.get(), dev->Backend.get())}; values[i++] = ALC_DEVICE_CLOCK_SOFT; values[i++] = clock.ClockTime.count(); @@ -2843,7 +2843,7 @@ START_API_FUNC break; case ALC_DEVICE_LATENCY_SOFT: - *values = GetClockLatency(dev.get()).Latency.count(); + *values = GetClockLatency(dev.get(), dev->Backend.get()).Latency.count(); break; case ALC_DEVICE_CLOCK_LATENCY_SOFT: @@ -2851,7 +2851,7 @@ START_API_FUNC alcSetError(dev.get(), ALC_INVALID_VALUE); else { - ClockLatency clock{GetClockLatency(dev.get())}; + ClockLatency clock{GetClockLatency(dev.get(), dev->Backend.get())}; values[0] = clock.ClockTime.count(); values[1] = clock.Latency.count(); } diff --git a/alc/backends/base.h b/alc/backends/base.h index d661bc46..a3562f54 100644 --- a/alc/backends/base.h +++ b/alc/backends/base.h @@ -70,9 +70,8 @@ inline std::chrono::nanoseconds GetDeviceClockTime(DeviceBase *device) /* Helper to get the device latency from the backend, including any fixed * latency from post-processing. */ -inline ClockLatency GetClockLatency(DeviceBase *device) +inline ClockLatency GetClockLatency(DeviceBase *device, BackendBase *backend) { - BackendBase *backend{device->Backend.get()}; ClockLatency ret{backend->getClockLatency()}; ret.Latency += device->FixedLatency; return ret; diff --git a/alc/device.cpp b/alc/device.cpp index 41ef6d44..01153d51 100644 --- a/alc/device.cpp +++ b/alc/device.cpp @@ -25,17 +25,8 @@ using voidp = void*; } // namespace -/* This should be in core/device.cpp. */ -DeviceBase::DeviceBase(DeviceType type) : Type{type}, mContexts{&sEmptyContextArray} -{ -} - -DeviceBase::~DeviceBase() -{ - auto *oldarray = mContexts.exchange(nullptr, std::memory_order_relaxed); - if(oldarray != &sEmptyContextArray) delete oldarray; -} - +ALCdevice::ALCdevice(DeviceType type) : DeviceBase{type} +{ } ALCdevice::~ALCdevice() { diff --git a/alc/device.h b/alc/device.h index 09d072a1..4798d422 100644 --- a/alc/device.h +++ b/alc/device.h @@ -2,6 +2,7 @@ #define ALC_DEVICE_H #include <atomic> +#include <memory> #include <mutex> #include <stdint.h> #include <string> @@ -20,6 +21,7 @@ struct ALbuffer; struct ALeffect; struct ALfilter; +struct BackendBase; using uint = unsigned int; @@ -71,6 +73,13 @@ struct FilterSubList { struct ALCdevice : public al::intrusive_ref<ALCdevice>, DeviceBase { + /* This lock protects the device state (format, update size, etc) from + * being from being changed in multiple threads, or being accessed while + * being changed. It's also used to serialize calls to the backend. + */ + std::mutex StateLock; + std::unique_ptr<BackendBase> Backend; + ALCuint NumMonoSources{}; ALCuint NumStereoSources{}; @@ -98,7 +107,7 @@ struct ALCdevice : public al::intrusive_ref<ALCdevice>, DeviceBase { al::vector<FilterSubList> FilterList; - ALCdevice(DeviceType type) : DeviceBase{type} { } + ALCdevice(DeviceType type); ~ALCdevice(); void enumerateHrtfs(); diff --git a/core/device.cpp b/core/device.cpp index 9705c0ac..2766c5e4 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -1,7 +1,23 @@ #include "config.h" +#include "bformatdec.h" +#include "bs2b.h" #include "device.h" +#include "front_stablizer.h" +#include "hrtf.h" +#include "mastering.h" al::FlexArray<ContextBase*> DeviceBase::sEmptyContextArray{0u}; + + +DeviceBase::DeviceBase(DeviceType type) : Type{type}, mContexts{&sEmptyContextArray} +{ +} + +DeviceBase::~DeviceBase() +{ + auto *oldarray = mContexts.exchange(nullptr, std::memory_order_relaxed); + if(oldarray != &sEmptyContextArray) delete oldarray; +} diff --git a/core/device.h b/core/device.h index 88d146aa..194901a2 100644 --- a/core/device.h +++ b/core/device.h @@ -24,7 +24,6 @@ #include "uhjfilter.h" #include "vector.h" -struct BackendBase; class BFormatDec; struct bs2b; struct Compressor; @@ -240,13 +239,6 @@ struct DeviceBase { // Contexts created on this device std::atomic<al::FlexArray<ContextBase*>*> mContexts{nullptr}; - /* This lock protects the device state (format, update size, etc) from - * being from being changed in multiple threads, or being accessed while - * being changed. It's also used to serialize calls to the backend. - */ - std::mutex StateLock; - std::unique_ptr<BackendBase> Backend; - DeviceBase(DeviceType type); DeviceBase(const DeviceBase&) = delete; |