aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/backends
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-11-15 19:15:14 -0800
committerChris Robinson <[email protected]>2018-11-15 19:15:14 -0800
commit49d8ac2537a03dd8d1a60fa4667dc6090da6bcc5 (patch)
tree5048ff5edf738dbde52f4d6f5075fe5dd9c9369d /Alc/backends
parent7c933087718bd1b789f2638164bcf2f8698647cb (diff)
Start a new backend factory API
Using proper class inheritance. Be aware this breaks all backends except null (and loopback). They will be restored individually in due time.
Diffstat (limited to 'Alc/backends')
-rw-r--r--Alc/backends/base.h14
-rw-r--r--Alc/backends/null.cpp91
-rw-r--r--Alc/backends/null.h20
3 files changed, 69 insertions, 56 deletions
diff --git a/Alc/backends/base.h b/Alc/backends/base.h
index 360c2ffd..5f7deb62 100644
--- a/Alc/backends/base.h
+++ b/Alc/backends/base.h
@@ -153,10 +153,22 @@ ALCbackendFactory *ALCdsoundBackendFactory_getFactory(void);
ALCbackendFactory *ALCwinmmBackendFactory_getFactory(void);
ALCbackendFactory *ALCportBackendFactory_getFactory(void);
ALCbackendFactory *ALCopenslBackendFactory_getFactory(void);
-ALCbackendFactory *ALCnullBackendFactory_getFactory(void);
ALCbackendFactory *ALCwaveBackendFactory_getFactory(void);
ALCbackendFactory *ALCsdl2BackendFactory_getFactory(void);
ALCbackendFactory *ALCloopbackFactory_getFactory(void);
+
+struct BackendFactory {
+ virtual bool init() = 0;
+ virtual void deinit() { }
+
+ virtual bool querySupport(ALCbackend_Type type) = 0;
+
+ virtual void probe(enum DevProbe type, std::string *outnames) = 0;
+
+ virtual ALCbackend *createBackend(ALCdevice *device, ALCbackend_Type type) = 0;
+};
+
+
#endif /* __cplusplus */
#endif /* AL_BACKENDS_BASE_H */
diff --git a/Alc/backends/null.cpp b/Alc/backends/null.cpp
index 30d80b76..d376ccdf 100644
--- a/Alc/backends/null.cpp
+++ b/Alc/backends/null.cpp
@@ -20,6 +20,8 @@
#include "config.h"
+#include "backends/null.h"
+
#include <stdlib.h>
#ifdef HAVE_WINDOWS_H
#include <windows.h>
@@ -32,8 +34,6 @@
#include "alu.h"
#include "compat.h"
-#include "backends/base.h"
-
namespace {
@@ -43,32 +43,31 @@ using std::chrono::nanoseconds;
constexpr ALCchar nullDevice[] = "No Output";
-} // namespace
struct ALCnullBackend final : public ALCbackend {
ATOMIC(int) killNow;
std::thread thread;
};
-static int ALCnullBackend_mixerProc(ALCnullBackend *self);
-
-static void ALCnullBackend_Construct(ALCnullBackend *self, ALCdevice *device);
-static void ALCnullBackend_Destruct(ALCnullBackend *self);
-static ALCenum ALCnullBackend_open(ALCnullBackend *self, const ALCchar *name);
-static ALCboolean ALCnullBackend_reset(ALCnullBackend *self);
-static ALCboolean ALCnullBackend_start(ALCnullBackend *self);
-static void ALCnullBackend_stop(ALCnullBackend *self);
-static DECLARE_FORWARD2(ALCnullBackend, ALCbackend, ALCenum, captureSamples, void*, ALCuint)
-static DECLARE_FORWARD(ALCnullBackend, ALCbackend, ALCuint, availableSamples)
-static DECLARE_FORWARD(ALCnullBackend, ALCbackend, ClockLatency, getClockLatency)
-static DECLARE_FORWARD(ALCnullBackend, ALCbackend, void, lock)
-static DECLARE_FORWARD(ALCnullBackend, ALCbackend, void, unlock)
+int ALCnullBackend_mixerProc(ALCnullBackend *self);
+
+void ALCnullBackend_Construct(ALCnullBackend *self, ALCdevice *device);
+void ALCnullBackend_Destruct(ALCnullBackend *self);
+ALCenum ALCnullBackend_open(ALCnullBackend *self, const ALCchar *name);
+ALCboolean ALCnullBackend_reset(ALCnullBackend *self);
+ALCboolean ALCnullBackend_start(ALCnullBackend *self);
+void ALCnullBackend_stop(ALCnullBackend *self);
+DECLARE_FORWARD2(ALCnullBackend, ALCbackend, ALCenum, captureSamples, void*, ALCuint)
+DECLARE_FORWARD(ALCnullBackend, ALCbackend, ALCuint, availableSamples)
+DECLARE_FORWARD(ALCnullBackend, ALCbackend, ClockLatency, getClockLatency)
+DECLARE_FORWARD(ALCnullBackend, ALCbackend, void, lock)
+DECLARE_FORWARD(ALCnullBackend, ALCbackend, void, unlock)
DECLARE_DEFAULT_ALLOCATORS(ALCnullBackend)
DEFINE_ALCBACKEND_VTABLE(ALCnullBackend);
-static void ALCnullBackend_Construct(ALCnullBackend *self, ALCdevice *device)
+void ALCnullBackend_Construct(ALCnullBackend *self, ALCdevice *device)
{
new (self) ALCnullBackend{};
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
@@ -77,14 +76,14 @@ static void ALCnullBackend_Construct(ALCnullBackend *self, ALCdevice *device)
ATOMIC_INIT(&self->killNow, AL_TRUE);
}
-static void ALCnullBackend_Destruct(ALCnullBackend *self)
+void ALCnullBackend_Destruct(ALCnullBackend *self)
{
ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
self->~ALCnullBackend();
}
-static int ALCnullBackend_mixerProc(ALCnullBackend *self)
+int ALCnullBackend_mixerProc(ALCnullBackend *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
const milliseconds restTime{device->UpdateSize*1000/device->Frequency / 2};
@@ -131,7 +130,7 @@ static int ALCnullBackend_mixerProc(ALCnullBackend *self)
}
-static ALCenum ALCnullBackend_open(ALCnullBackend *self, const ALCchar *name)
+ALCenum ALCnullBackend_open(ALCnullBackend *self, const ALCchar *name)
{
ALCdevice *device;
@@ -147,13 +146,13 @@ static ALCenum ALCnullBackend_open(ALCnullBackend *self, const ALCchar *name)
return ALC_NO_ERROR;
}
-static ALCboolean ALCnullBackend_reset(ALCnullBackend *self)
+ALCboolean ALCnullBackend_reset(ALCnullBackend *self)
{
SetDefaultWFXChannelOrder(STATIC_CAST(ALCbackend, self)->mDevice);
return ALC_TRUE;
}
-static ALCboolean ALCnullBackend_start(ALCnullBackend *self)
+ALCboolean ALCnullBackend_start(ALCnullBackend *self)
{
try {
ATOMIC_STORE(&self->killNow, AL_FALSE, almemory_order_release);
@@ -168,7 +167,7 @@ static ALCboolean ALCnullBackend_start(ALCnullBackend *self)
return ALC_FALSE;
}
-static void ALCnullBackend_stop(ALCnullBackend *self)
+void ALCnullBackend_stop(ALCnullBackend *self)
{
if(ATOMIC_EXCHANGE(&self->killNow, AL_TRUE, almemory_order_acq_rel) ||
!self->thread.joinable())
@@ -176,46 +175,22 @@ static void ALCnullBackend_stop(ALCnullBackend *self)
self->thread.join();
}
-
-struct ALCnullBackendFactory final : public ALCbackendFactory {
- ALCnullBackendFactory() noexcept;
-};
-
-ALCbackendFactory *ALCnullBackendFactory_getFactory(void);
-
-static ALCboolean ALCnullBackendFactory_init(ALCnullBackendFactory *self);
-static DECLARE_FORWARD(ALCnullBackendFactory, ALCbackendFactory, void, deinit)
-static ALCboolean ALCnullBackendFactory_querySupport(ALCnullBackendFactory *self, ALCbackend_Type type);
-static void ALCnullBackendFactory_probe(ALCnullBackendFactory *self, enum DevProbe type, std::string *outnames);
-static ALCbackend* ALCnullBackendFactory_createBackend(ALCnullBackendFactory *self, ALCdevice *device, ALCbackend_Type type);
-DEFINE_ALCBACKENDFACTORY_VTABLE(ALCnullBackendFactory);
-
-ALCnullBackendFactory::ALCnullBackendFactory() noexcept
- : ALCbackendFactory{GET_VTABLE2(ALCnullBackendFactory, ALCbackendFactory)}
-{
-}
-
-
-ALCbackendFactory *ALCnullBackendFactory_getFactory(void)
-{
- static ALCnullBackendFactory factory{};
- return STATIC_CAST(ALCbackendFactory, &factory);
-}
+} // namespace
-static ALCboolean ALCnullBackendFactory_init(ALCnullBackendFactory* UNUSED(self))
+bool NullBackendFactory::init()
{
- return ALC_TRUE;
+ return true;
}
-static ALCboolean ALCnullBackendFactory_querySupport(ALCnullBackendFactory* UNUSED(self), ALCbackend_Type type)
+bool NullBackendFactory::querySupport(ALCbackend_Type type)
{
if(type == ALCbackend_Playback)
- return ALC_TRUE;
- return ALC_FALSE;
+ return true;
+ return false;
}
-static void ALCnullBackendFactory_probe(ALCnullBackendFactory* UNUSED(self), enum DevProbe type, std::string *outnames)
+void NullBackendFactory::probe(enum DevProbe type, std::string *outnames)
{
switch(type)
{
@@ -228,7 +203,7 @@ static void ALCnullBackendFactory_probe(ALCnullBackendFactory* UNUSED(self), enu
}
}
-static ALCbackend* ALCnullBackendFactory_createBackend(ALCnullBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type)
+ALCbackend *NullBackendFactory::createBackend(ALCdevice *device, ALCbackend_Type type)
{
if(type == ALCbackend_Playback)
{
@@ -240,3 +215,9 @@ static ALCbackend* ALCnullBackendFactory_createBackend(ALCnullBackendFactory* UN
return NULL;
}
+
+BackendFactory &NullBackendFactory::getFactory()
+{
+ static NullBackendFactory factory{};
+ return factory;
+}
diff --git a/Alc/backends/null.h b/Alc/backends/null.h
new file mode 100644
index 00000000..e2adfc33
--- /dev/null
+++ b/Alc/backends/null.h
@@ -0,0 +1,20 @@
+#ifndef BACKENDS_NULL_H
+#define BACKENDS_NULL_H
+
+#include "backends/base.h"
+
+struct NullBackendFactory final : public BackendFactory {
+public:
+ bool init() override;
+ /*void deinit() override;*/
+
+ bool querySupport(ALCbackend_Type type) override;
+
+ void probe(enum DevProbe type, std::string *outnames) override;
+
+ ALCbackend *createBackend(ALCdevice *device, ALCbackend_Type type) override;
+
+ static BackendFactory &getFactory();
+};
+
+#endif /* BACKENDS_NULL_H */