diff options
author | Chris Robinson <[email protected]> | 2018-11-15 22:03:20 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-11-15 22:03:20 -0800 |
commit | 2a839e5762fa6bd4b0399e2f588ce0805e92b618 (patch) | |
tree | eba5e4add8e1a496c5731a512904c438529f6190 /Alc | |
parent | d4928d4e7df0517313530db63503a56e8ab63caa (diff) |
Convert the JACK backend factory
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/alc.cpp | 11 | ||||
-rw-r--r-- | Alc/backends/jack.cpp | 51 | ||||
-rw-r--r-- | Alc/backends/jack.h | 20 |
3 files changed, 45 insertions, 37 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index 9319cfc3..d83b545f 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -59,6 +59,9 @@ #include "backends/base.h" #include "backends/null.h" #include "backends/loopback.h" +#ifdef HAVE_JACK +#include "backends/jack.h" +#endif #ifdef HAVE_PULSEAUDIO #include "backends/pulseaudio.h" #endif @@ -90,6 +93,9 @@ struct BackendInfo { }; struct BackendInfo BackendList[] = { +#ifdef HAVE_JACK + { "jack", JackBackendFactory::getFactory }, +#endif #ifdef HAVE_PULSEAUDIO { "pulse", PulseBackendFactory::getFactory }, #endif @@ -105,11 +111,8 @@ struct BackendInfo BackendList[] = { #ifdef HAVE_OPENSL { "opensl", OSLBackendFactory::getFactory }, #endif + #if 0 - { "jack", ALCjackBackendFactory_getFactory }, - { "pulse", ALCpulseBackendFactory_getFactory }, - { "alsa", ALCalsaBackendFactory_getFactory }, - { "core", ALCcoreAudioBackendFactory_getFactory }, { "solaris", ALCsolarisBackendFactory_getFactory }, { "sndio", SndioBackendFactory_getFactory }, { "oss", ALCossBackendFactory_getFactory }, diff --git a/Alc/backends/jack.cpp b/Alc/backends/jack.cpp index 9db75537..ac57ffd5 100644 --- a/Alc/backends/jack.cpp +++ b/Alc/backends/jack.cpp @@ -20,6 +20,8 @@ #include "config.h" +#include "backends/jack.h" + #include <stdlib.h> #include <stdio.h> #include <memory.h> @@ -31,8 +33,6 @@ #include "threads.h" #include "compat.h" -#include "backends/base.h" - #include <jack/jack.h> #include <jack/ringbuffer.h> @@ -520,18 +520,14 @@ static void jack_msg_handler(const char *message) WARN("%s\n", message); } -struct ALCjackBackendFactory final : public ALCbackendFactory { - ALCjackBackendFactory() noexcept; -}; - -static ALCboolean ALCjackBackendFactory_init(ALCjackBackendFactory* UNUSED(self)) +bool JackBackendFactory::init() { void (*old_error_cb)(const char*); jack_client_t *client; jack_status_t status; if(!jack_load()) - return ALC_FALSE; + return false; if(!GetConfigValueBool(NULL, "jack", "spawn-server", 0)) ClientOptions = static_cast<jack_options_t>(ClientOptions | JackNoStartServer); @@ -540,35 +536,31 @@ static ALCboolean ALCjackBackendFactory_init(ALCjackBackendFactory* UNUSED(self) jack_set_error_function(jack_msg_handler); client = jack_client_open("alsoft", ClientOptions, &status, NULL); jack_set_error_function(old_error_cb); - if(client == NULL) + if(!client) { WARN("jack_client_open() failed, 0x%02x\n", status); if((status&JackServerFailed) && !(ClientOptions&JackNoStartServer)) ERR("Unable to connect to JACK server\n"); - return ALC_FALSE; + return false; } jack_client_close(client); - return ALC_TRUE; + return true; } -static void ALCjackBackendFactory_deinit(ALCjackBackendFactory* UNUSED(self)) +void JackBackendFactory::deinit() { #ifdef HAVE_DYNLOAD if(jack_handle) CloseLib(jack_handle); - jack_handle = NULL; + jack_handle = nullptr; #endif } -static ALCboolean ALCjackBackendFactory_querySupport(ALCjackBackendFactory* UNUSED(self), ALCbackend_Type type) -{ - if(type == ALCbackend_Playback) - return ALC_TRUE; - return ALC_FALSE; -} +bool JackBackendFactory::querySupport(ALCbackend_Type type) +{ return (type == ALCbackend_Playback); } -static void ALCjackBackendFactory_probe(ALCjackBackendFactory* UNUSED(self), enum DevProbe type, std::string *outnames) +void JackBackendFactory::probe(enum DevProbe type, std::string *outnames) { switch(type) { @@ -582,28 +574,21 @@ static void ALCjackBackendFactory_probe(ALCjackBackendFactory* UNUSED(self), enu } } -static ALCbackend* ALCjackBackendFactory_createBackend(ALCjackBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type) +ALCbackend *JackBackendFactory::createBackend(ALCdevice *device, ALCbackend_Type type) { if(type == ALCbackend_Playback) { ALCjackPlayback *backend; NEW_OBJ(backend, ALCjackPlayback)(device); - if(!backend) return NULL; + if(!backend) return nullptr; return STATIC_CAST(ALCbackend, backend); } - return NULL; + return nullptr; } -DEFINE_ALCBACKENDFACTORY_VTABLE(ALCjackBackendFactory); - - -ALCjackBackendFactory::ALCjackBackendFactory() noexcept - : ALCbackendFactory{GET_VTABLE2(ALCjackBackendFactory, ALCbackendFactory)} -{ } - -ALCbackendFactory *ALCjackBackendFactory_getFactory(void) +BackendFactory &JackBackendFactory::getFactory() { - static ALCjackBackendFactory factory{}; - return STATIC_CAST(ALCbackendFactory, &factory); + static JackBackendFactory factory{}; + return factory; } diff --git a/Alc/backends/jack.h b/Alc/backends/jack.h new file mode 100644 index 00000000..8a6e3a22 --- /dev/null +++ b/Alc/backends/jack.h @@ -0,0 +1,20 @@ +#ifndef BACKENDS_JACK_H +#define BACKENDS_JACK_H + +#include "backends/base.h" + +struct JackBackendFactory 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_JACK_H */ |