aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/ALc.c110
-rw-r--r--OpenAL32/Include/alMain.h22
-rw-r--r--OpenAL32/alSource.c4
3 files changed, 110 insertions, 26 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 8eb99e63..a201da35 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -38,10 +38,20 @@
#include "bs2b.h"
#include "alu.h"
+#include "backends/base.h"
+
/************************************************
* Backends
************************************************/
+struct BackendInfo {
+ const char *name;
+ ALCboolean (*Init)(BackendFuncs*);
+ void (*Deinit)(void);
+ void (*Probe)(enum DevProbe);
+ BackendFuncs Funcs;
+};
+
#define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
static struct BackendInfo BackendList[] = {
#ifdef HAVE_PULSEAUDIO
@@ -96,6 +106,77 @@ static struct BackendInfo BackendLoopback = {
static struct BackendInfo PlaybackBackend;
static struct BackendInfo CaptureBackend;
+
+/* Wrapper to use an old-style backend with the new interface. */
+typedef struct BackendWrapper {
+ DERIVE_FROM_TYPE(ALCbackend);
+
+ ALCdevice *mDevice;
+} BackendWrapper;
+#define BACKENDWRAPPER_INITIALIZER { { GET_VTABLE2(ALCbackend, BackendWrapper) }, NULL }
+
+static void BackendWrapper_Destruct(BackendWrapper* UNUSED(self))
+{
+}
+
+static ALCenum BackendWrapper_open(BackendWrapper *self, const ALCchar *name)
+{
+ ALCdevice *device = self->mDevice;
+ return device->Funcs->OpenPlayback(device, name);
+}
+
+static void BackendWrapper_close(BackendWrapper *self)
+{
+ ALCdevice *device = self->mDevice;
+ device->Funcs->ClosePlayback(device);
+}
+
+static ALCboolean BackendWrapper_reset(BackendWrapper *self)
+{
+ ALCdevice *device = self->mDevice;
+ return device->Funcs->ResetPlayback(device);
+}
+
+static ALCboolean BackendWrapper_start(BackendWrapper *self)
+{
+ ALCdevice *device = self->mDevice;
+ return device->Funcs->StartPlayback(device);
+}
+
+static void BackendWrapper_stop(BackendWrapper *self)
+{
+ ALCdevice *device = self->mDevice;
+ device->Funcs->StopPlayback(device);
+}
+
+static ALint64 BackendWrapper_getLatency(BackendWrapper *self)
+{
+ ALCdevice *device = self->mDevice;
+ return device->Funcs->GetLatency(device);
+}
+
+static void BackendWrapper_Delete(BackendWrapper *self)
+{
+ free(self);
+}
+
+DEFINE_ALCBACKEND_VTABLE(BackendWrapper);
+
+
+ALCbackend *create_backend_wrapper(ALCdevice *device)
+{
+ BackendWrapper *backend;
+
+ backend = malloc(sizeof(*backend));
+ if(!backend) return NULL;
+ SET_VTABLE2(BackendWrapper, ALCbackend, backend);
+
+ backend->mDevice = device;
+
+ return STATIC_CAST(ALCbackend, backend);
+}
+
+
/************************************************
* Functions, enums, and errors
************************************************/
@@ -1335,6 +1416,11 @@ ALint64 ALCdevice_GetLatencyDefault(ALCdevice *UNUSED(device))
return 0;
}
+ALint64 alcGetLatency(ALCdevice *device)
+{
+ return VCALL0(device->Backend,getLatency,());
+}
+
/* SetDefaultWFXChannelOrder
*
* Sets the default channel order used by WaveFormatEx.
@@ -1561,7 +1647,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
numSends = minu(MAX_SENDS, numSends);
if((device->Flags&DEVICE_RUNNING))
- ALCdevice_StopPlayback(device);
+ VCALL0(device->Backend,stop,());
device->Flags &= ~DEVICE_RUNNING;
device->Frequency = freq;
@@ -1579,7 +1665,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
/* If a context is already running on the device, stop playback so the
* device attributes can be updated. */
if((device->Flags&DEVICE_RUNNING))
- ALCdevice_StopPlayback(device);
+ VCALL0(device->Backend,close,());
device->Flags &= ~DEVICE_RUNNING;
freq = device->Frequency;
@@ -1664,7 +1750,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
DEVICE_FREQUENCY_REQUEST;
}
- if(ALCdevice_ResetPlayback(device) == ALC_FALSE)
+ if(VCALL0(device->Backend,reset,()) == ALC_FALSE)
return ALC_INVALID_DEVICE;
if(device->FmtChans != oldChans && (device->Flags&DEVICE_CHANNELS_REQUEST))
@@ -1804,7 +1890,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
ALCdevice_Unlock(device);
RestoreFPUMode(&oldMode);
- if(ALCdevice_StartPlayback(device) == ALC_FALSE)
+ if(VCALL0(device->Backend,start,()) == ALC_FALSE)
return ALC_INVALID_DEVICE;
device->Flags |= DEVICE_RUNNING;
@@ -1821,7 +1907,7 @@ static ALCvoid FreeDevice(ALCdevice *device)
TRACE("%p\n", device);
if(device->Type != Capture)
- ALCdevice_ClosePlayback(device);
+ VCALL0(device->Backend,close,());
else
ALCdevice_CloseCapture(device);
@@ -2596,7 +2682,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
{
if(!device->ContextList)
{
- ALCdevice_StopPlayback(device);
+ VCALL0(device->Backend,stop,());
device->Flags &= ~DEVICE_RUNNING;
}
UnlockLists();
@@ -2640,7 +2726,7 @@ ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context)
ReleaseContext(context, Device);
if(!Device->ContextList)
{
- ALCdevice_StopPlayback(Device);
+ VCALL0(Device->Backend,stop,());
Device->Flags &= ~DEVICE_RUNNING;
}
}
@@ -2801,6 +2887,8 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
device->NumUpdates = 4;
device->UpdateSize = 1024;
+ device->Backend = create_backend_wrapper(device);
+
if(ConfigValueStr(NULL, "channels", &fmt))
{
static const struct {
@@ -2937,7 +3025,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
// Find a playback device to open
- if((err=ALCdevice_OpenPlayback(device, deviceName)) != ALC_NO_ERROR)
+ if((err=VCALL(device->Backend,open,(deviceName))) != ALC_NO_ERROR)
{
DeleteCriticalSection(&device->Mutex);
al_free(device);
@@ -3000,7 +3088,7 @@ ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *Device)
ReleaseContext(ctx, Device);
}
if((Device->Flags&DEVICE_RUNNING))
- ALCdevice_StopPlayback(Device);
+ VCALL0(Device->Backend,stop,());
Device->Flags &= ~DEVICE_RUNNING;
ALCdevice_DecRef(Device);
@@ -3215,6 +3303,8 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN
InitUIntMap(&device->EffectMap, ~0);
InitUIntMap(&device->FilterMap, ~0);
+ device->Backend = create_backend_wrapper(device);
+
//Set output format
device->NumUpdates = 0;
device->UpdateSize = 0;
@@ -3236,7 +3326,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN
device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
// Open the "backend"
- ALCdevice_OpenPlayback(device, "Loopback");
+ VCALL(device->Backend,open,("Loopback"));
do {
device->next = DeviceList;
} while(!CompExchangePtr((XchgPtr*)&DeviceList, device->next, device));
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index bfe575bd..29e01034 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -105,6 +105,7 @@ static const union {
/* Call a "virtual" method on an object, with arguments. */
#define VCALL(obj, func, args) ((obj)->vtbl->func((obj), EXTRACT_VCALL_ARGS args))
/* Call a "virtual" method on an object, with no arguments. */
+#define VCALL0(obj, func, args) ((obj)->vtbl->func((obj)))
#define VCALL_NOARGS(obj, func) ((obj)->vtbl->func((obj)))
#define DELETE_OBJ(obj) do { \
@@ -457,14 +458,6 @@ typedef struct {
ALint64 (*GetLatency)(ALCdevice*);
} BackendFuncs;
-struct BackendInfo {
- const char *name;
- ALCboolean (*Init)(BackendFuncs*);
- void (*Deinit)(void);
- void (*Probe)(enum DevProbe);
- BackendFuncs Funcs;
-};
-
ALCboolean alc_alsa_init(BackendFuncs *func_list);
void alc_alsa_deinit(void);
void alc_alsa_probe(enum DevProbe type);
@@ -511,6 +504,8 @@ ALCboolean alc_loopback_init(BackendFuncs *func_list);
void alc_loopback_deinit(void);
void alc_loopback_probe(enum DevProbe type);
+struct ALCbackend;
+
enum DistanceModel {
InverseDistanceClamped = AL_INVERSE_DISTANCE_CLAMPED,
@@ -674,17 +669,14 @@ struct ALCdevice_struct
// Contexts created on this device
ALCcontext *volatile ContextList;
+ struct ALCbackend *Backend;
+
BackendFuncs *Funcs;
void *ExtraData; // For the backend's use
ALCdevice *volatile next;
};
-#define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
-#define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
-#define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
-#define ALCdevice_StartPlayback(a) ((a)->Funcs->StartPlayback((a)))
-#define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
#define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
#define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
#define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
@@ -693,7 +685,6 @@ struct ALCdevice_struct
#define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
#define ALCdevice_Lock(a) ((a)->Funcs->Lock((a)))
#define ALCdevice_Unlock(a) ((a)->Funcs->Unlock((a)))
-#define ALCdevice_GetLatency(a) ((a)->Funcs->GetLatency((a)))
// Frequency was requested by the app or config file
#define DEVICE_FREQUENCY_REQUEST (1<<1)
@@ -719,6 +710,9 @@ struct ALCdevice_struct
#define MIXER_THREAD_NAME "alsoft-mixer"
+ALint64 alcGetLatency(ALCdevice *device);
+
+
static inline struct ALbuffer *LookupBuffer(ALCdevice *device, ALuint id)
{ return (struct ALbuffer*)LookupUIntMapKey(&device->BufferMap, id); }
static inline struct ALeffect *LookupEffect(ALCdevice *device, ALuint id)
diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c
index cae60cc2..e017ff62 100644
--- a/OpenAL32/alSource.c
+++ b/OpenAL32/alSource.c
@@ -947,7 +947,7 @@ static ALboolean GetSourcedv(const ALsource *Source, ALCcontext *Context, SrcFlo
case AL_SEC_OFFSET_LATENCY_SOFT:
LockContext(Context);
values[0] = GetSourceSecOffset(Source);
- values[1] = (ALdouble)ALCdevice_GetLatency(Context->Device) /
+ values[1] = (ALdouble)alcGetLatency(Context->Device) /
1000000000.0;
UnlockContext(Context);
return AL_TRUE;
@@ -1133,7 +1133,7 @@ static ALboolean GetSourcei64v(const ALsource *Source, ALCcontext *Context, SrcI
case AL_SAMPLE_OFFSET_LATENCY_SOFT:
LockContext(Context);
values[0] = GetSourceOffset(Source);
- values[1] = ALCdevice_GetLatency(Context->Device);
+ values[1] = alcGetLatency(Context->Device);
UnlockContext(Context);
return AL_TRUE;