diff options
author | Chris Robinson <[email protected]> | 2018-11-15 23:32:28 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-11-15 23:32:28 -0800 |
commit | 2ca6119e0eb6253a5a025739f99db2031dca8c2a (patch) | |
tree | a844dcd789d10d06ce1e2d05dde8a5c091a1a18b | |
parent | 5dc1956e18007fe910039487ef5d847bbb72ede0 (diff) |
Convert the DSound backend factory
-rw-r--r-- | Alc/alc.cpp | 7 | ||||
-rw-r--r-- | Alc/backends/dsound.cpp | 154 | ||||
-rw-r--r-- | Alc/backends/dsound.h | 20 | ||||
-rw-r--r-- | CMakeLists.txt | 2 |
4 files changed, 91 insertions, 92 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index 00442458..c86d7260 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -89,6 +89,9 @@ #ifdef HAVE_QSA #include "backends/qsa.h" #endif +#ifdef HAVE_DSOUND +#include "backends/dsound.h" +#endif #ifdef HAVE_SDL2 #include "backends/sdl2.h" #endif @@ -138,9 +141,11 @@ struct BackendInfo BackendList[] = { #ifdef HAVE_QSA { "qsa", QSABackendFactory::getFactory }, #endif +#ifdef HAVE_DSOUND + { "dsound", DSoundBackendFactory::getFactory }, +#endif #if 0 - { "dsound", ALCdsoundBackendFactory_getFactory }, { "winmm", ALCwinmmBackendFactory_getFactory }, { "port", ALCportBackendFactory_getFactory }, #endif /* 0 */ diff --git a/Alc/backends/dsound.cpp b/Alc/backends/dsound.cpp index 478bdf9a..34d7dc23 100644 --- a/Alc/backends/dsound.cpp +++ b/Alc/backends/dsound.cpp @@ -20,11 +20,12 @@ #include "config.h" +#include "backends/dsound.h" + #include <stdlib.h> #include <stdio.h> #include <memory.h> -#include <dsound.h> #include <cguid.h> #include <mmreg.h> #ifndef _WAVEFORMATEXTENSIBLE_ @@ -43,7 +44,10 @@ #include "ringbuffer.h" #include "compat.h" -#include "backends/base.h" +/* MinGW-w64 needs this for some unknown reason now. */ +typedef const WAVEFORMATEX *LPCWAVEFORMATEX; +#include <dsound.h> + #ifndef DSSPEAKER_5POINT1 # define DSSPEAKER_5POINT1 0x00000006 @@ -79,11 +83,11 @@ namespace { #ifdef HAVE_DYNLOAD -static void *ds_handle; -static HRESULT (WINAPI *pDirectSoundCreate)(const GUID *pcGuidDevice, IDirectSound **ppDS, IUnknown *pUnkOuter); -static HRESULT (WINAPI *pDirectSoundEnumerateW)(LPDSENUMCALLBACKW pDSEnumCallback, void *pContext); -static HRESULT (WINAPI *pDirectSoundCaptureCreate)(const GUID *pcGuidDevice, IDirectSoundCapture **ppDSC, IUnknown *pUnkOuter); -static HRESULT (WINAPI *pDirectSoundCaptureEnumerateW)(LPDSENUMCALLBACKW pDSEnumCallback, void *pContext); +void *ds_handle; +HRESULT (WINAPI *pDirectSoundCreate)(const GUID *pcGuidDevice, IDirectSound **ppDS, IUnknown *pUnkOuter); +HRESULT (WINAPI *pDirectSoundEnumerateW)(LPDSENUMCALLBACKW pDSEnumCallback, void *pContext); +HRESULT (WINAPI *pDirectSoundCaptureCreate)(const GUID *pcGuidDevice, IDirectSoundCapture **ppDSC, IUnknown *pUnkOuter); +HRESULT (WINAPI *pDirectSoundCaptureEnumerateW)(LPDSENUMCALLBACKW pDSEnumCallback, void *pContext); #ifndef IN_IDE_PARSER #define DirectSoundCreate pDirectSoundCreate @@ -94,7 +98,7 @@ static HRESULT (WINAPI *pDirectSoundCaptureEnumerateW)(LPDSENUMCALLBACKW pDSEnum #endif -static ALCboolean DSoundLoad(void) +bool DSoundLoad(void) { #ifdef HAVE_DYNLOAD if(!ds_handle) @@ -103,7 +107,7 @@ static ALCboolean DSoundLoad(void) if(!ds_handle) { ERR("Failed to load dsound.dll\n"); - return ALC_FALSE; + return false; } #define LOAD_FUNC(f) do { \ @@ -112,7 +116,7 @@ static ALCboolean DSoundLoad(void) { \ CloseLib(ds_handle); \ ds_handle = nullptr; \ - return ALC_FALSE; \ + return false; \ } \ } while(0) LOAD_FUNC(DirectSoundCreate); @@ -122,7 +126,7 @@ static ALCboolean DSoundLoad(void) #undef LOAD_FUNC } #endif - return ALC_TRUE; + return true; } @@ -179,8 +183,6 @@ BOOL CALLBACK DSoundEnumDevices(GUID *guid, const WCHAR *desc, const WCHAR* UNUS return TRUE; } -} // namespace - struct ALCdsoundPlayback final : public ALCbackend { IDirectSound *DS{nullptr}; @@ -193,32 +195,32 @@ struct ALCdsoundPlayback final : public ALCbackend { std::thread thread; }; -static int ALCdsoundPlayback_mixerProc(ALCdsoundPlayback *self); - -static void ALCdsoundPlayback_Construct(ALCdsoundPlayback *self, ALCdevice *device); -static void ALCdsoundPlayback_Destruct(ALCdsoundPlayback *self); -static ALCenum ALCdsoundPlayback_open(ALCdsoundPlayback *self, const ALCchar *name); -static ALCboolean ALCdsoundPlayback_reset(ALCdsoundPlayback *self); -static ALCboolean ALCdsoundPlayback_start(ALCdsoundPlayback *self); -static void ALCdsoundPlayback_stop(ALCdsoundPlayback *self); -static DECLARE_FORWARD2(ALCdsoundPlayback, ALCbackend, ALCenum, captureSamples, void*, ALCuint) -static DECLARE_FORWARD(ALCdsoundPlayback, ALCbackend, ALCuint, availableSamples) -static DECLARE_FORWARD(ALCdsoundPlayback, ALCbackend, ClockLatency, getClockLatency) -static DECLARE_FORWARD(ALCdsoundPlayback, ALCbackend, void, lock) -static DECLARE_FORWARD(ALCdsoundPlayback, ALCbackend, void, unlock) +int ALCdsoundPlayback_mixerProc(ALCdsoundPlayback *self); + +void ALCdsoundPlayback_Construct(ALCdsoundPlayback *self, ALCdevice *device); +void ALCdsoundPlayback_Destruct(ALCdsoundPlayback *self); +ALCenum ALCdsoundPlayback_open(ALCdsoundPlayback *self, const ALCchar *name); +ALCboolean ALCdsoundPlayback_reset(ALCdsoundPlayback *self); +ALCboolean ALCdsoundPlayback_start(ALCdsoundPlayback *self); +void ALCdsoundPlayback_stop(ALCdsoundPlayback *self); +DECLARE_FORWARD2(ALCdsoundPlayback, ALCbackend, ALCenum, captureSamples, void*, ALCuint) +DECLARE_FORWARD(ALCdsoundPlayback, ALCbackend, ALCuint, availableSamples) +DECLARE_FORWARD(ALCdsoundPlayback, ALCbackend, ClockLatency, getClockLatency) +DECLARE_FORWARD(ALCdsoundPlayback, ALCbackend, void, lock) +DECLARE_FORWARD(ALCdsoundPlayback, ALCbackend, void, unlock) DECLARE_DEFAULT_ALLOCATORS(ALCdsoundPlayback) DEFINE_ALCBACKEND_VTABLE(ALCdsoundPlayback); -static void ALCdsoundPlayback_Construct(ALCdsoundPlayback *self, ALCdevice *device) +void ALCdsoundPlayback_Construct(ALCdsoundPlayback *self, ALCdevice *device) { new (self) ALCdsoundPlayback{}; ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device); SET_VTABLE2(ALCdsoundPlayback, ALCbackend, self); } -static void ALCdsoundPlayback_Destruct(ALCdsoundPlayback *self) +void ALCdsoundPlayback_Destruct(ALCdsoundPlayback *self) { if(self->Notifies) self->Notifies->Release(); @@ -242,7 +244,7 @@ static void ALCdsoundPlayback_Destruct(ALCdsoundPlayback *self) } -FORCE_ALIGN static int ALCdsoundPlayback_mixerProc(ALCdsoundPlayback *self) +FORCE_ALIGN int ALCdsoundPlayback_mixerProc(ALCdsoundPlayback *self) { ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; @@ -348,7 +350,7 @@ FORCE_ALIGN static int ALCdsoundPlayback_mixerProc(ALCdsoundPlayback *self) return 0; } -static ALCenum ALCdsoundPlayback_open(ALCdsoundPlayback *self, const ALCchar *deviceName) +ALCenum ALCdsoundPlayback_open(ALCdsoundPlayback *self, const ALCchar *deviceName) { ALCdevice *device{STATIC_CAST(ALCbackend, self)->mDevice}; @@ -402,7 +404,7 @@ static ALCenum ALCdsoundPlayback_open(ALCdsoundPlayback *self, const ALCchar *de return ALC_NO_ERROR; } -static ALCboolean ALCdsoundPlayback_reset(ALCdsoundPlayback *self) +ALCboolean ALCdsoundPlayback_reset(ALCdsoundPlayback *self) { ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; @@ -623,7 +625,7 @@ retry_open: return ALC_TRUE; } -static ALCboolean ALCdsoundPlayback_start(ALCdsoundPlayback *self) +ALCboolean ALCdsoundPlayback_start(ALCdsoundPlayback *self) { try { self->killNow.store(AL_FALSE, std::memory_order_release); @@ -638,7 +640,7 @@ static ALCboolean ALCdsoundPlayback_start(ALCdsoundPlayback *self) return ALC_FALSE; } -static void ALCdsoundPlayback_stop(ALCdsoundPlayback *self) +void ALCdsoundPlayback_stop(ALCdsoundPlayback *self) { if(self->killNow.exchange(AL_TRUE, std::memory_order_acq_rel) || !self->thread.joinable()) return; @@ -658,29 +660,28 @@ struct ALCdsoundCapture final : public ALCbackend { ll_ringbuffer_t *Ring{nullptr}; }; -static void ALCdsoundCapture_Construct(ALCdsoundCapture *self, ALCdevice *device); -static void ALCdsoundCapture_Destruct(ALCdsoundCapture *self); -static ALCenum ALCdsoundCapture_open(ALCdsoundCapture *self, const ALCchar *name); -static DECLARE_FORWARD(ALCdsoundCapture, ALCbackend, ALCboolean, reset) -static ALCboolean ALCdsoundCapture_start(ALCdsoundCapture *self); -static void ALCdsoundCapture_stop(ALCdsoundCapture *self); -static ALCenum ALCdsoundCapture_captureSamples(ALCdsoundCapture *self, ALCvoid *buffer, ALCuint samples); -static ALCuint ALCdsoundCapture_availableSamples(ALCdsoundCapture *self); -static DECLARE_FORWARD(ALCdsoundCapture, ALCbackend, ClockLatency, getClockLatency) -static DECLARE_FORWARD(ALCdsoundCapture, ALCbackend, void, lock) -static DECLARE_FORWARD(ALCdsoundCapture, ALCbackend, void, unlock) +void ALCdsoundCapture_Construct(ALCdsoundCapture *self, ALCdevice *device); +void ALCdsoundCapture_Destruct(ALCdsoundCapture *self); +ALCenum ALCdsoundCapture_open(ALCdsoundCapture *self, const ALCchar *name); +DECLARE_FORWARD(ALCdsoundCapture, ALCbackend, ALCboolean, reset) +ALCboolean ALCdsoundCapture_start(ALCdsoundCapture *self); +void ALCdsoundCapture_stop(ALCdsoundCapture *self); +ALCenum ALCdsoundCapture_captureSamples(ALCdsoundCapture *self, ALCvoid *buffer, ALCuint samples); +ALCuint ALCdsoundCapture_availableSamples(ALCdsoundCapture *self); +DECLARE_FORWARD(ALCdsoundCapture, ALCbackend, ClockLatency, getClockLatency) +DECLARE_FORWARD(ALCdsoundCapture, ALCbackend, void, lock) +DECLARE_FORWARD(ALCdsoundCapture, ALCbackend, void, unlock) DECLARE_DEFAULT_ALLOCATORS(ALCdsoundCapture) - DEFINE_ALCBACKEND_VTABLE(ALCdsoundCapture); -static void ALCdsoundCapture_Construct(ALCdsoundCapture *self, ALCdevice *device) +void ALCdsoundCapture_Construct(ALCdsoundCapture *self, ALCdevice *device) { new (self) ALCdsoundCapture{}; ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device); SET_VTABLE2(ALCdsoundCapture, ALCbackend, self); } -static void ALCdsoundCapture_Destruct(ALCdsoundCapture *self) +void ALCdsoundCapture_Destruct(ALCdsoundCapture *self) { ll_ringbuffer_free(self->Ring); self->Ring = nullptr; @@ -701,7 +702,7 @@ static void ALCdsoundCapture_Destruct(ALCdsoundCapture *self) } -static ALCenum ALCdsoundCapture_open(ALCdsoundCapture *self, const ALCchar *deviceName) +ALCenum ALCdsoundCapture_open(ALCdsoundCapture *self, const ALCchar *deviceName) { ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; @@ -869,7 +870,7 @@ static ALCenum ALCdsoundCapture_open(ALCdsoundCapture *self, const ALCchar *devi return ALC_NO_ERROR; } -static ALCboolean ALCdsoundCapture_start(ALCdsoundCapture *self) +ALCboolean ALCdsoundCapture_start(ALCdsoundCapture *self) { HRESULT hr{self->DSCbuffer->Start(DSCBSTART_LOOPING)}; if(FAILED(hr)) @@ -883,7 +884,7 @@ static ALCboolean ALCdsoundCapture_start(ALCdsoundCapture *self) return ALC_TRUE; } -static void ALCdsoundCapture_stop(ALCdsoundCapture *self) +void ALCdsoundCapture_stop(ALCdsoundCapture *self) { HRESULT hr{self->DSCbuffer->Stop()}; if(FAILED(hr)) @@ -894,13 +895,13 @@ static void ALCdsoundCapture_stop(ALCdsoundCapture *self) } } -static ALCenum ALCdsoundCapture_captureSamples(ALCdsoundCapture *self, ALCvoid *buffer, ALCuint samples) +ALCenum ALCdsoundCapture_captureSamples(ALCdsoundCapture *self, ALCvoid *buffer, ALCuint samples) { ll_ringbuffer_read(self->Ring, reinterpret_cast<char*>(buffer), samples); return ALC_NO_ERROR; } -static ALCuint ALCdsoundCapture_availableSamples(ALCdsoundCapture *self) +ALCuint ALCdsoundCapture_availableSamples(ALCdsoundCapture *self) { ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; @@ -942,42 +943,19 @@ static ALCuint ALCdsoundCapture_availableSamples(ALCdsoundCapture *self) return ll_ringbuffer_read_space(self->Ring); } - -struct ALCdsoundBackendFactory final : public ALCbackendFactory { - ALCdsoundBackendFactory() noexcept; -}; -#define ALCDSOUNDBACKENDFACTORY_INITIALIZER GET_VTABLE2(ALCdsoundBackendFactory, ALCbackendFactory) - -ALCbackendFactory *ALCdsoundBackendFactory_getFactory(void); - -static ALCboolean ALCdsoundBackendFactory_init(ALCdsoundBackendFactory *self); -static void ALCdsoundBackendFactory_deinit(ALCdsoundBackendFactory *self); -static ALCboolean ALCdsoundBackendFactory_querySupport(ALCdsoundBackendFactory *self, ALCbackend_Type type); -static void ALCdsoundBackendFactory_probe(ALCdsoundBackendFactory *self, enum DevProbe type, std::string *outnames); -static ALCbackend* ALCdsoundBackendFactory_createBackend(ALCdsoundBackendFactory *self, ALCdevice *device, ALCbackend_Type type); -DEFINE_ALCBACKENDFACTORY_VTABLE(ALCdsoundBackendFactory); - - -ALCdsoundBackendFactory::ALCdsoundBackendFactory() noexcept - : ALCbackendFactory{ALCDSOUNDBACKENDFACTORY_INITIALIZER} -{ } +} // namespace -ALCbackendFactory *ALCdsoundBackendFactory_getFactory(void) +BackendFactory &DSoundBackendFactory::getFactory() { - static ALCdsoundBackendFactory factory{}; - return STATIC_CAST(ALCbackendFactory, &factory); + static DSoundBackendFactory factory{}; + return factory; } +bool DSoundBackendFactory::init() +{ return DSoundLoad(); } -static ALCboolean ALCdsoundBackendFactory_init(ALCdsoundBackendFactory* UNUSED(self)) -{ - if(!DSoundLoad()) - return ALC_FALSE; - return ALC_TRUE; -} - -static void ALCdsoundBackendFactory_deinit(ALCdsoundBackendFactory* UNUSED(self)) +void DSoundBackendFactory::deinit() { PlaybackDevices.clear(); CaptureDevices.clear(); @@ -989,14 +967,10 @@ static void ALCdsoundBackendFactory_deinit(ALCdsoundBackendFactory* UNUSED(self) #endif } -static ALCboolean ALCdsoundBackendFactory_querySupport(ALCdsoundBackendFactory* UNUSED(self), ALCbackend_Type type) -{ - if(type == ALCbackend_Playback || type == ALCbackend_Capture) - return ALC_TRUE; - return ALC_FALSE; -} +bool DSoundBackendFactory::querySupport(ALCbackend_Type type) +{ return (type == ALCbackend_Playback || type == ALCbackend_Capture); } -static void ALCdsoundBackendFactory_probe(ALCdsoundBackendFactory* UNUSED(self), enum DevProbe type, std::string *outnames) +void DSoundBackendFactory::probe(enum DevProbe type, std::string *outnames) { auto add_device = [outnames](const DevMap &entry) -> void { @@ -1031,7 +1005,7 @@ static void ALCdsoundBackendFactory_probe(ALCdsoundBackendFactory* UNUSED(self), CoUninitialize(); } -static ALCbackend* ALCdsoundBackendFactory_createBackend(ALCdsoundBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type) +ALCbackend *DSoundBackendFactory::createBackend(ALCdevice *device, ALCbackend_Type type) { if(type == ALCbackend_Playback) { diff --git a/Alc/backends/dsound.h b/Alc/backends/dsound.h new file mode 100644 index 00000000..ebaa9c64 --- /dev/null +++ b/Alc/backends/dsound.h @@ -0,0 +1,20 @@ +#ifndef BACKENDS_DSOUND_H +#define BACKENDS_DSOUND_H + +#include "backends/base.h" + +struct DSoundBackendFactory 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_DSOUND_H */ diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d30bd6c..94df6473 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1112,7 +1112,7 @@ IF(HAVE_WINDOWS_H) IF(ALSOFT_BACKEND_DSOUND) SET(HAVE_DSOUND 1) SET(BACKENDS "${BACKENDS} DirectSound${IS_LINKED},") - SET(ALC_OBJS ${ALC_OBJS} Alc/backends/dsound.cpp) + SET(ALC_OBJS ${ALC_OBJS} Alc/backends/dsound.cpp Alc/backends/dsound.h) ADD_BACKEND_LIBS(${DSOUND_LIBRARIES}) SET(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIRS}) ENDIF() |