diff options
-rw-r--r-- | Alc/alc.cpp | 8 | ||||
-rw-r--r-- | Alc/backends/sdl2.cpp | 47 | ||||
-rw-r--r-- | Alc/backends/sdl2.h | 20 | ||||
-rw-r--r-- | CMakeLists.txt | 2 |
4 files changed, 39 insertions, 38 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index d83b545f..63f60e80 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -77,6 +77,9 @@ #ifdef HAVE_OPENSL #include "backends/opensl.h" #endif +#ifdef HAVE_SDL2 +#include "backends/sdl2.h" +#endif #ifdef HAVE_WAVE #include "backends/wave.h" #endif @@ -121,9 +124,10 @@ struct BackendInfo BackendList[] = { { "dsound", ALCdsoundBackendFactory_getFactory }, { "winmm", ALCwinmmBackendFactory_getFactory }, { "port", ALCportBackendFactory_getFactory }, - { "opensl", ALCopenslBackendFactory_getFactory }, - { "sdl2", ALCsdl2BackendFactory_getFactory }, #endif /* 0 */ +#ifdef HAVE_SDL2 + { "sdl2", SDL2BackendFactory::getFactory }, +#endif { "null", NullBackendFactory::getFactory }, #ifdef HAVE_WAVE diff --git a/Alc/backends/sdl2.cpp b/Alc/backends/sdl2.cpp index c918b57c..e1234c1b 100644 --- a/Alc/backends/sdl2.cpp +++ b/Alc/backends/sdl2.cpp @@ -20,6 +20,8 @@ #include "config.h" +#include "backends/sdl2.h" + #include <stdlib.h> #include <SDL2/SDL.h> @@ -30,8 +32,6 @@ #include "threads.h" #include "compat.h" -#include "backends/base.h" - #ifdef _WIN32 #define DEVNAME_PREFIX "OpenAL Soft on " @@ -214,51 +214,28 @@ static void ALCsdl2Backend_unlock(ALCsdl2Backend *self) } -struct ALCsdl2BackendFactory final : public ALCbackendFactory { - ALCsdl2BackendFactory() noexcept; -}; - -ALCbackendFactory *ALCsdl2BackendFactory_getFactory(void); - -static ALCboolean ALCsdl2BackendFactory_init(ALCsdl2BackendFactory *self); -static void ALCsdl2BackendFactory_deinit(ALCsdl2BackendFactory *self); -static ALCboolean ALCsdl2BackendFactory_querySupport(ALCsdl2BackendFactory *self, ALCbackend_Type type); -static void ALCsdl2BackendFactory_probe(ALCsdl2BackendFactory *self, enum DevProbe type, std::string *outnames); -static ALCbackend* ALCsdl2BackendFactory_createBackend(ALCsdl2BackendFactory *self, ALCdevice *device, ALCbackend_Type type); -DEFINE_ALCBACKENDFACTORY_VTABLE(ALCsdl2BackendFactory); - - -ALCsdl2BackendFactory::ALCsdl2BackendFactory() noexcept - : ALCbackendFactory{GET_VTABLE2(ALCsdl2BackendFactory, ALCbackendFactory)} -{ } - -ALCbackendFactory *ALCsdl2BackendFactory_getFactory(void) +BackendFactory &SDL2BackendFactory::getFactory() { - static ALCsdl2BackendFactory factory{}; - return STATIC_CAST(ALCbackendFactory, &factory); + static SDL2BackendFactory factory{}; + return factory; } - -static ALCboolean ALCsdl2BackendFactory_init(ALCsdl2BackendFactory* UNUSED(self)) +bool SDL2BackendFactory::init() { - if(SDL_InitSubSystem(SDL_INIT_AUDIO) == 0) - return AL_TRUE; - return ALC_FALSE; + return (SDL_InitSubSystem(SDL_INIT_AUDIO) == 0); } -static void ALCsdl2BackendFactory_deinit(ALCsdl2BackendFactory* UNUSED(self)) +void SDL2BackendFactory::deinit() { SDL_QuitSubSystem(SDL_INIT_AUDIO); } -static ALCboolean ALCsdl2BackendFactory_querySupport(ALCsdl2BackendFactory* UNUSED(self), ALCbackend_Type type) +bool SDL2BackendFactory::querySupport(ALCbackend_Type type) { - if(type == ALCbackend_Playback) - return ALC_TRUE; - return ALC_FALSE; + return (type == ALCbackend_Playback); } -static void ALCsdl2BackendFactory_probe(ALCsdl2BackendFactory* UNUSED(self), enum DevProbe type, std::string *outnames) +void SDL2BackendFactory::probe(enum DevProbe type, std::string *outnames) { if(type != ALL_DEVICE_PROBE) return; @@ -276,7 +253,7 @@ static void ALCsdl2BackendFactory_probe(ALCsdl2BackendFactory* UNUSED(self), enu } } -static ALCbackend* ALCsdl2BackendFactory_createBackend(ALCsdl2BackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type) +ALCbackend *SDL2BackendFactory::createBackend(ALCdevice *device, ALCbackend_Type type) { if(type == ALCbackend_Playback) { diff --git a/Alc/backends/sdl2.h b/Alc/backends/sdl2.h new file mode 100644 index 00000000..7f383447 --- /dev/null +++ b/Alc/backends/sdl2.h @@ -0,0 +1,20 @@ +#ifndef BACKENDS_SDL2_H +#define BACKENDS_SDL2_H + +#include "backends/base.h" + +struct SDL2BackendFactory 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_SDL2_H */ diff --git a/CMakeLists.txt b/CMakeLists.txt index d487d6d3..67f3ba82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1253,7 +1253,7 @@ IF(SDL2_FOUND) OPTION(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF) IF(ALSOFT_BACKEND_SDL2) SET(HAVE_SDL2 1) - SET(ALC_OBJS ${ALC_OBJS} Alc/backends/sdl2.cpp) + SET(ALC_OBJS ${ALC_OBJS} Alc/backends/sdl2.cpp Alc/backends/sdl2.h) SET(BACKENDS "${BACKENDS} SDL2,") SET(EXTRA_LIBS ${SDL2_LIBRARY} ${EXTRA_LIBS}) SET(INC_PATHS ${INC_PATHS} ${SDL2_INCLUDE_DIR}) |