Make the backend pointer part of ALCdevice instead of DeviceBase

master
Chris Robinson 2021-11-19 20:04:10 -08:00
parent 6e2c1b8431
commit 0c99a6b316
7 changed files with 34 additions and 27 deletions

View File

@ -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();

View File

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

View File

@ -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;

View File

@ -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()
{

View File

@ -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();

View File

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

View File

@ -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;