Convert the CoreAudio backend factory

This commit is contained in:
Chris Robinson 2018-11-15 21:24:09 -08:00
parent b1fb2e9e14
commit ead830814b
4 changed files with 40 additions and 40 deletions

View File

@ -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 },

View File

@ -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;
}
bool CoreAudioBackendFactory::querySupport(ALCbackend_Type type)
{ return (type == ALCbackend_Playback || ALCbackend_Capture); }
static ALCboolean ALCcoreAudioBackendFactory_querySupport(ALCcoreAudioBackendFactory* UNUSED(self), ALCbackend_Type type)
{
if(type == ALCbackend_Playback || ALCbackend_Capture)
return ALC_TRUE;
return ALC_FALSE;
}
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;
}

20
Alc/backends/coreaudio.h Normal file
View File

@ -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 */

View File

@ -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})