diff options
author | Chris Robinson <[email protected]> | 2018-11-15 21:24:09 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-11-15 21:24:09 -0800 |
commit | ead830814b95f137fa4d51ebf91b353a823f4e30 (patch) | |
tree | ad11f9312d5e6032831a8b50c823640e8fb2c18e | |
parent | b1fb2e9e142e362ab78c961f8d1069f012b1ece3 (diff) |
Convert the CoreAudio backend factory
-rw-r--r-- | Alc/alc.cpp | 6 | ||||
-rw-r--r-- | Alc/backends/coreaudio.cpp | 52 | ||||
-rw-r--r-- | Alc/backends/coreaudio.h | 20 | ||||
-rw-r--r-- | CMakeLists.txt | 2 |
4 files changed, 40 insertions, 40 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index 52aab346..d4e2dda5 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -65,6 +65,9 @@ #ifdef HAVE_WASAPI #include "backends/wasapi.h" #endif +#ifdef HAVE_COREAUDIO +#include "backends/coreaudio.h" +#endif namespace { @@ -84,6 +87,9 @@ struct BackendInfo BackendList[] = { #ifdef HAVE_WASAPI { "wasapi", WasapiBackendFactory::getFactory }, #endif +#ifdef HAVE_COREAUDIO + { "core", CoreAudioBackendFactory::getFactory }, +#endif #if 0 { "jack", ALCjackBackendFactory_getFactory }, { "pulse", ALCpulseBackendFactory_getFactory }, diff --git a/Alc/backends/coreaudio.cpp b/Alc/backends/coreaudio.cpp index 1a3f2ab1..62df982e 100644 --- a/Alc/backends/coreaudio.cpp +++ b/Alc/backends/coreaudio.cpp @@ -20,6 +20,8 @@ #include "config.h" +#include "backends/coreaudio.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -32,8 +34,6 @@ #include <AudioUnit/AudioUnit.h> #include <AudioToolbox/AudioToolbox.h> -#include "backends/base.h" - static const ALCchar ca_device[] = "CoreAudio Default"; @@ -753,44 +753,18 @@ static ALCuint ALCcoreAudioCapture_availableSamples(ALCcoreAudioCapture *self) } -struct ALCcoreAudioBackendFactory final : public ALCbackendFactory { - ALCcoreAudioBackendFactory() noexcept; -}; - -ALCbackendFactory *ALCcoreAudioBackendFactory_getFactory(void); - -static ALCboolean ALCcoreAudioBackendFactory_init(ALCcoreAudioBackendFactory *self); -static DECLARE_FORWARD(ALCcoreAudioBackendFactory, ALCbackendFactory, void, deinit) -static ALCboolean ALCcoreAudioBackendFactory_querySupport(ALCcoreAudioBackendFactory *self, ALCbackend_Type type); -static void ALCcoreAudioBackendFactory_probe(ALCcoreAudioBackendFactory *self, enum DevProbe type, std::string *outnames); -static ALCbackend* ALCcoreAudioBackendFactory_createBackend(ALCcoreAudioBackendFactory *self, ALCdevice *device, ALCbackend_Type type); -DEFINE_ALCBACKENDFACTORY_VTABLE(ALCcoreAudioBackendFactory); - - -ALCcoreAudioBackendFactory::ALCcoreAudioBackendFactory() noexcept - : ALCbackendFactory{GET_VTABLE2(ALCcoreAudioBackendFactory, ALCbackendFactory)} -{ } - -ALCbackendFactory *ALCcoreAudioBackendFactory_getFactory(void) +BackendFactory &CoreAudioBackendFactory::getFactory() { - static ALCcoreAudioBackendFactory factory{}; - return STATIC_CAST(ALCbackendFactory, &factory); + static CoreAudioBackendFactory factory{}; + return factory; } +bool CoreAudioBackendFactory::init() { return true; } -static ALCboolean ALCcoreAudioBackendFactory_init(ALCcoreAudioBackendFactory* UNUSED(self)) -{ - return ALC_TRUE; -} - -static ALCboolean ALCcoreAudioBackendFactory_querySupport(ALCcoreAudioBackendFactory* UNUSED(self), ALCbackend_Type type) -{ - if(type == ALCbackend_Playback || ALCbackend_Capture) - return ALC_TRUE; - return ALC_FALSE; -} +bool CoreAudioBackendFactory::querySupport(ALCbackend_Type type) +{ return (type == ALCbackend_Playback || ALCbackend_Capture); } -static void ALCcoreAudioBackendFactory_probe(ALCcoreAudioBackendFactory* UNUSED(self), enum DevProbe type, std::string *outnames) +void CoreAudioBackendFactory::probe(enum DevProbe type, std::string *outnames) { switch(type) { @@ -802,22 +776,22 @@ static void ALCcoreAudioBackendFactory_probe(ALCcoreAudioBackendFactory* UNUSED( } } -static ALCbackend* ALCcoreAudioBackendFactory_createBackend(ALCcoreAudioBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type) +ALCbackend *CoreAudioBackendFactory::createBackend(ALCdevice *device, ALCbackend_Type type) { if(type == ALCbackend_Playback) { ALCcoreAudioPlayback *backend; NEW_OBJ(backend, ALCcoreAudioPlayback)(device); - if(!backend) return NULL; + if(!backend) return nullptr; return STATIC_CAST(ALCbackend, backend); } if(type == ALCbackend_Capture) { ALCcoreAudioCapture *backend; NEW_OBJ(backend, ALCcoreAudioCapture)(device); - if(!backend) return NULL; + if(!backend) return nullptr; return STATIC_CAST(ALCbackend, backend); } - return NULL; + return nullptr; } diff --git a/Alc/backends/coreaudio.h b/Alc/backends/coreaudio.h new file mode 100644 index 00000000..2926ee12 --- /dev/null +++ b/Alc/backends/coreaudio.h @@ -0,0 +1,20 @@ +#ifndef BACKENDS_COREAUDIO_H +#define BACKENDS_COREAUDIO_H + +#include "backends/base.h" + +struct CoreAudioBackendFactory 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_COREAUDIO_H */ diff --git a/CMakeLists.txt b/CMakeLists.txt index b8905764..1b2cab60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1203,7 +1203,7 @@ IF(COREAUDIO_FRAMEWORK) OPTION(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON) IF(ALSOFT_BACKEND_COREAUDIO) SET(HAVE_COREAUDIO 1) - SET(ALC_OBJS ${ALC_OBJS} Alc/backends/coreaudio.cpp) + SET(ALC_OBJS ${ALC_OBJS} Alc/backends/coreaudio.cpp Alc/backends/coreaudio.h) SET(BACKENDS "${BACKENDS} CoreAudio,") SET(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${EXTRA_LIBS}) SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS}) |