mirror of
https://github.com/love2d/megasource.git
synced 2026-08-19 04:05:09 +02:00
Update OpenAL-soft to 1.21.1
This commit is contained in:
@@ -7,36 +7,36 @@
|
||||
#include "router.h"
|
||||
|
||||
|
||||
atomic_DriverIfacePtr CurrentCtxDriver = ATOMIC_INIT_STATIC(NULL);
|
||||
std::atomic<DriverIface*> CurrentCtxDriver{nullptr};
|
||||
|
||||
#define DECL_THUNK1(R,n,T1) AL_API R AL_APIENTRY n(T1 a) \
|
||||
{ \
|
||||
DriverIface *iface = altss_get(ThreadCtxDriver); \
|
||||
if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
|
||||
DriverIface *iface = ThreadCtxDriver; \
|
||||
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
|
||||
return iface->n(a); \
|
||||
}
|
||||
#define DECL_THUNK2(R,n,T1,T2) AL_API R AL_APIENTRY n(T1 a, T2 b) \
|
||||
{ \
|
||||
DriverIface *iface = altss_get(ThreadCtxDriver); \
|
||||
if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
|
||||
DriverIface *iface = ThreadCtxDriver; \
|
||||
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
|
||||
return iface->n(a, b); \
|
||||
}
|
||||
#define DECL_THUNK3(R,n,T1,T2,T3) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c) \
|
||||
{ \
|
||||
DriverIface *iface = altss_get(ThreadCtxDriver); \
|
||||
if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
|
||||
DriverIface *iface = ThreadCtxDriver; \
|
||||
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
|
||||
return iface->n(a, b, c); \
|
||||
}
|
||||
#define DECL_THUNK4(R,n,T1,T2,T3,T4) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c, T4 d) \
|
||||
{ \
|
||||
DriverIface *iface = altss_get(ThreadCtxDriver); \
|
||||
if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
|
||||
DriverIface *iface = ThreadCtxDriver; \
|
||||
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
|
||||
return iface->n(a, b, c, d); \
|
||||
}
|
||||
#define DECL_THUNK5(R,n,T1,T2,T3,T4,T5) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c, T4 d, T5 e) \
|
||||
{ \
|
||||
DriverIface *iface = altss_get(ThreadCtxDriver); \
|
||||
if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
|
||||
DriverIface *iface = ThreadCtxDriver; \
|
||||
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
|
||||
return iface->n(a, b, c, d, e); \
|
||||
}
|
||||
|
||||
@@ -46,8 +46,8 @@ atomic_DriverIfacePtr CurrentCtxDriver = ATOMIC_INIT_STATIC(NULL);
|
||||
*/
|
||||
AL_API ALenum AL_APIENTRY alGetError(void)
|
||||
{
|
||||
DriverIface *iface = altss_get(ThreadCtxDriver);
|
||||
if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);
|
||||
DriverIface *iface = ThreadCtxDriver;
|
||||
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire);
|
||||
return iface ? iface->alGetError() : AL_NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -130,3 +130,39 @@ DECL_THUNK3(void, alGetBufferi, ALuint, ALenum, ALint*)
|
||||
DECL_THUNK5(void, alGetBuffer3i, ALuint, ALenum, ALint*, ALint*, ALint*)
|
||||
DECL_THUNK3(void, alGetBufferiv, ALuint, ALenum, ALint*)
|
||||
DECL_THUNK5(void, alBufferData, ALuint, ALenum, const ALvoid*, ALsizei, ALsizei)
|
||||
|
||||
DECL_THUNK2(void, alGenFilters, ALsizei, ALuint*)
|
||||
DECL_THUNK2(void, alDeleteFilters, ALsizei, const ALuint*)
|
||||
DECL_THUNK1(ALboolean, alIsFilter, ALuint)
|
||||
DECL_THUNK3(void, alFilterf, ALuint, ALenum, ALfloat)
|
||||
DECL_THUNK3(void, alFilterfv, ALuint, ALenum, const ALfloat*)
|
||||
DECL_THUNK3(void, alFilteri, ALuint, ALenum, ALint)
|
||||
DECL_THUNK3(void, alFilteriv, ALuint, ALenum, const ALint*)
|
||||
DECL_THUNK3(void, alGetFilterf, ALuint, ALenum, ALfloat*)
|
||||
DECL_THUNK3(void, alGetFilterfv, ALuint, ALenum, ALfloat*)
|
||||
DECL_THUNK3(void, alGetFilteri, ALuint, ALenum, ALint*)
|
||||
DECL_THUNK3(void, alGetFilteriv, ALuint, ALenum, ALint*)
|
||||
|
||||
DECL_THUNK2(void, alGenEffects, ALsizei, ALuint*)
|
||||
DECL_THUNK2(void, alDeleteEffects, ALsizei, const ALuint*)
|
||||
DECL_THUNK1(ALboolean, alIsEffect, ALuint)
|
||||
DECL_THUNK3(void, alEffectf, ALuint, ALenum, ALfloat)
|
||||
DECL_THUNK3(void, alEffectfv, ALuint, ALenum, const ALfloat*)
|
||||
DECL_THUNK3(void, alEffecti, ALuint, ALenum, ALint)
|
||||
DECL_THUNK3(void, alEffectiv, ALuint, ALenum, const ALint*)
|
||||
DECL_THUNK3(void, alGetEffectf, ALuint, ALenum, ALfloat*)
|
||||
DECL_THUNK3(void, alGetEffectfv, ALuint, ALenum, ALfloat*)
|
||||
DECL_THUNK3(void, alGetEffecti, ALuint, ALenum, ALint*)
|
||||
DECL_THUNK3(void, alGetEffectiv, ALuint, ALenum, ALint*)
|
||||
|
||||
DECL_THUNK2(void, alGenAuxiliaryEffectSlots, ALsizei, ALuint*)
|
||||
DECL_THUNK2(void, alDeleteAuxiliaryEffectSlots, ALsizei, const ALuint*)
|
||||
DECL_THUNK1(ALboolean, alIsAuxiliaryEffectSlot, ALuint)
|
||||
DECL_THUNK3(void, alAuxiliaryEffectSlotf, ALuint, ALenum, ALfloat)
|
||||
DECL_THUNK3(void, alAuxiliaryEffectSlotfv, ALuint, ALenum, const ALfloat*)
|
||||
DECL_THUNK3(void, alAuxiliaryEffectSloti, ALuint, ALenum, ALint)
|
||||
DECL_THUNK3(void, alAuxiliaryEffectSlotiv, ALuint, ALenum, const ALint*)
|
||||
DECL_THUNK3(void, alGetAuxiliaryEffectSlotf, ALuint, ALenum, ALfloat*)
|
||||
DECL_THUNK3(void, alGetAuxiliaryEffectSlotfv, ALuint, ALenum, ALfloat*)
|
||||
DECL_THUNK3(void, alGetAuxiliaryEffectSloti, ALuint, ALenum, ALint*)
|
||||
DECL_THUNK3(void, alGetAuxiliaryEffectSlotiv, ALuint, ALenum, ALint*)
|
||||
@@ -6,18 +6,21 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
|
||||
#include "AL/alc.h"
|
||||
#include "alstring.h"
|
||||
#include "router.h"
|
||||
#include "almalloc.h"
|
||||
|
||||
|
||||
#define COUNTOF(x) (sizeof(x)/sizeof(x[0]))
|
||||
|
||||
#define DECL(x) { #x, (ALCvoid*)(x) }
|
||||
static const struct {
|
||||
const ALCchar *funcName;
|
||||
ALCvoid *address;
|
||||
} alcFunctions[] = {
|
||||
#define DECL(x) { #x, reinterpret_cast<void*>(x) }
|
||||
struct FuncExportEntry {
|
||||
const char *funcName;
|
||||
void *address;
|
||||
};
|
||||
static const std::array<FuncExportEntry,128> alcFunctions{{
|
||||
DECL(alcCreateContext),
|
||||
DECL(alcMakeContextCurrent),
|
||||
DECL(alcProcessContext),
|
||||
@@ -115,14 +118,49 @@ static const struct {
|
||||
DECL(alDopplerVelocity),
|
||||
DECL(alSpeedOfSound),
|
||||
DECL(alDistanceModel),
|
||||
};
|
||||
|
||||
DECL(alGenFilters),
|
||||
DECL(alDeleteFilters),
|
||||
DECL(alIsFilter),
|
||||
DECL(alFilterf),
|
||||
DECL(alFilterfv),
|
||||
DECL(alFilteri),
|
||||
DECL(alFilteriv),
|
||||
DECL(alGetFilterf),
|
||||
DECL(alGetFilterfv),
|
||||
DECL(alGetFilteri),
|
||||
DECL(alGetFilteriv),
|
||||
DECL(alGenEffects),
|
||||
DECL(alDeleteEffects),
|
||||
DECL(alIsEffect),
|
||||
DECL(alEffectf),
|
||||
DECL(alEffectfv),
|
||||
DECL(alEffecti),
|
||||
DECL(alEffectiv),
|
||||
DECL(alGetEffectf),
|
||||
DECL(alGetEffectfv),
|
||||
DECL(alGetEffecti),
|
||||
DECL(alGetEffectiv),
|
||||
DECL(alGenAuxiliaryEffectSlots),
|
||||
DECL(alDeleteAuxiliaryEffectSlots),
|
||||
DECL(alIsAuxiliaryEffectSlot),
|
||||
DECL(alAuxiliaryEffectSlotf),
|
||||
DECL(alAuxiliaryEffectSlotfv),
|
||||
DECL(alAuxiliaryEffectSloti),
|
||||
DECL(alAuxiliaryEffectSlotiv),
|
||||
DECL(alGetAuxiliaryEffectSlotf),
|
||||
DECL(alGetAuxiliaryEffectSlotfv),
|
||||
DECL(alGetAuxiliaryEffectSloti),
|
||||
DECL(alGetAuxiliaryEffectSlotiv),
|
||||
}};
|
||||
#undef DECL
|
||||
|
||||
#define DECL(x) { #x, (x) }
|
||||
static const struct {
|
||||
struct EnumExportEntry {
|
||||
const ALCchar *enumName;
|
||||
ALCenum value;
|
||||
} alcEnumerations[] = {
|
||||
};
|
||||
static const std::array<EnumExportEntry,92> alcEnumerations{{
|
||||
DECL(ALC_INVALID),
|
||||
DECL(ALC_FALSE),
|
||||
DECL(ALC_TRUE),
|
||||
@@ -228,7 +266,7 @@ static const struct {
|
||||
DECL(AL_LINEAR_DISTANCE_CLAMPED),
|
||||
DECL(AL_EXPONENT_DISTANCE),
|
||||
DECL(AL_EXPONENT_DISTANCE_CLAMPED),
|
||||
};
|
||||
}};
|
||||
#undef DECL
|
||||
|
||||
static const ALCchar alcNoError[] = "No Error";
|
||||
@@ -245,77 +283,54 @@ static const ALCint alcMajorVersion = 1;
|
||||
static const ALCint alcMinorVersion = 1;
|
||||
|
||||
|
||||
static almtx_t EnumerationLock;
|
||||
static almtx_t ContextSwitchLock;
|
||||
static std::recursive_mutex EnumerationLock;
|
||||
static std::mutex ContextSwitchLock;
|
||||
|
||||
static ATOMIC(ALCenum) LastError = ATOMIC_INIT_STATIC(ALC_NO_ERROR);
|
||||
static PtrIntMap DeviceIfaceMap = PTRINTMAP_STATIC_INITIALIZE;
|
||||
static PtrIntMap ContextIfaceMap = PTRINTMAP_STATIC_INITIALIZE;
|
||||
static std::atomic<ALCenum> LastError{ALC_NO_ERROR};
|
||||
static PtrIntMap DeviceIfaceMap;
|
||||
static PtrIntMap ContextIfaceMap;
|
||||
|
||||
|
||||
typedef struct EnumeratedList {
|
||||
ALCchar *Names;
|
||||
ALCchar *NamesEnd;
|
||||
ALCint *Indicies;
|
||||
ALCsizei IndexSize;
|
||||
std::vector<ALCchar> Names;
|
||||
std::vector<ALCint> Indicies;
|
||||
|
||||
void clear()
|
||||
{
|
||||
Names.clear();
|
||||
Indicies.clear();
|
||||
}
|
||||
} EnumeratedList;
|
||||
static EnumeratedList DevicesList = { NULL, NULL, NULL, 0 };
|
||||
static EnumeratedList AllDevicesList = { NULL, NULL, NULL, 0 };
|
||||
static EnumeratedList CaptureDevicesList = { NULL, NULL, NULL, 0 };
|
||||
|
||||
static void ClearDeviceList(EnumeratedList *list)
|
||||
{
|
||||
al_free(list->Names);
|
||||
list->Names = NULL;
|
||||
list->NamesEnd = NULL;
|
||||
|
||||
al_free(list->Indicies);
|
||||
list->Indicies = NULL;
|
||||
list->IndexSize = 0;
|
||||
}
|
||||
static EnumeratedList DevicesList;
|
||||
static EnumeratedList AllDevicesList;
|
||||
static EnumeratedList CaptureDevicesList;
|
||||
|
||||
static void AppendDeviceList(EnumeratedList *list, const ALCchar *names, ALint idx)
|
||||
{
|
||||
const ALCchar *name_end = names;
|
||||
ALCsizei count = 0;
|
||||
ALCchar *new_list;
|
||||
ALCint *new_indicies;
|
||||
size_t len;
|
||||
ALCsizei i;
|
||||
if(!name_end) return;
|
||||
|
||||
if(!name_end)
|
||||
return;
|
||||
ALCsizei count = 0;
|
||||
while(*name_end)
|
||||
{
|
||||
TRACE("Enumerated \"%s\", driver %d\n", name_end, idx);
|
||||
count++;
|
||||
++count;
|
||||
name_end += strlen(name_end)+1;
|
||||
}
|
||||
if(names == name_end)
|
||||
return;
|
||||
|
||||
len = (list->NamesEnd - list->Names) + (name_end - names);
|
||||
new_list = al_calloc(DEF_ALIGN, len + 1);
|
||||
memcpy(new_list, list->Names, list->NamesEnd - list->Names);
|
||||
memcpy(new_list + (list->NamesEnd - list->Names), names, name_end - names);
|
||||
al_free(list->Names);
|
||||
list->Names = new_list;
|
||||
list->NamesEnd = list->Names + len;
|
||||
list->Names.reserve(list->Names.size() + (name_end - names) + 1);
|
||||
list->Names.insert(list->Names.cend(), names, name_end);
|
||||
|
||||
new_indicies = al_calloc(16, sizeof(ALCint)*(list->IndexSize + count));
|
||||
for(i = 0;i < list->IndexSize;i++)
|
||||
new_indicies[i] = list->Indicies[i];
|
||||
for(i = 0;i < count;i++)
|
||||
new_indicies[list->IndexSize+i] = idx;
|
||||
al_free(list->Indicies);
|
||||
list->Indicies = new_indicies;
|
||||
list->IndexSize += count;
|
||||
list->Indicies.reserve(list->Indicies.size() + count);
|
||||
list->Indicies.insert(list->Indicies.cend(), count, idx);
|
||||
}
|
||||
|
||||
static ALint GetDriverIndexForName(const EnumeratedList *list, const ALCchar *name)
|
||||
{
|
||||
const ALCchar *devnames = list->Names;
|
||||
const ALCint *index = list->Indicies;
|
||||
const ALCchar *devnames = list->Names.data();
|
||||
const ALCint *index = list->Indicies.data();
|
||||
|
||||
while(devnames && *devnames)
|
||||
{
|
||||
@@ -327,30 +342,11 @@ static ALint GetDriverIndexForName(const EnumeratedList *list, const ALCchar *na
|
||||
return -1;
|
||||
}
|
||||
|
||||
void InitALC(void)
|
||||
{
|
||||
almtx_init(&EnumerationLock, almtx_recursive);
|
||||
almtx_init(&ContextSwitchLock, almtx_plain);
|
||||
}
|
||||
|
||||
void ReleaseALC(void)
|
||||
{
|
||||
ClearDeviceList(&DevicesList);
|
||||
ClearDeviceList(&AllDevicesList);
|
||||
ClearDeviceList(&CaptureDevicesList);
|
||||
|
||||
ResetPtrIntMap(&ContextIfaceMap);
|
||||
ResetPtrIntMap(&DeviceIfaceMap);
|
||||
|
||||
almtx_destroy(&ContextSwitchLock);
|
||||
almtx_destroy(&EnumerationLock);
|
||||
}
|
||||
|
||||
|
||||
ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *devicename)
|
||||
{
|
||||
ALCdevice *device = NULL;
|
||||
ALint idx;
|
||||
ALCdevice *device = nullptr;
|
||||
ALint idx = 0;
|
||||
|
||||
/* Prior to the enumeration extension, apps would hardcode these names as a
|
||||
* quality hint for the wrapper driver. Ignore them since there's no sane
|
||||
@@ -360,51 +356,52 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *devicename)
|
||||
strcmp(devicename, "DirectSound3D") == 0 ||
|
||||
strcmp(devicename, "DirectSound") == 0 ||
|
||||
strcmp(devicename, "MMSYSTEM") == 0))
|
||||
devicename = NULL;
|
||||
devicename = nullptr;
|
||||
if(devicename)
|
||||
{
|
||||
almtx_lock(&EnumerationLock);
|
||||
if(!DevicesList.Names)
|
||||
(void)alcGetString(NULL, ALC_DEVICE_SPECIFIER);
|
||||
idx = GetDriverIndexForName(&DevicesList, devicename);
|
||||
if(idx < 0)
|
||||
{
|
||||
if(!AllDevicesList.Names)
|
||||
(void)alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
|
||||
idx = GetDriverIndexForName(&AllDevicesList, devicename);
|
||||
std::lock_guard<std::recursive_mutex> _{EnumerationLock};
|
||||
if(DevicesList.Names.empty())
|
||||
(void)alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
|
||||
idx = GetDriverIndexForName(&DevicesList, devicename);
|
||||
if(idx < 0)
|
||||
{
|
||||
if(AllDevicesList.Names.empty())
|
||||
(void)alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER);
|
||||
idx = GetDriverIndexForName(&AllDevicesList, devicename);
|
||||
}
|
||||
}
|
||||
almtx_unlock(&EnumerationLock);
|
||||
|
||||
if(idx < 0)
|
||||
{
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_VALUE);
|
||||
LastError.store(ALC_INVALID_VALUE);
|
||||
TRACE("Failed to find driver for name \"%s\"\n", devicename);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
TRACE("Found driver %d for name \"%s\"\n", idx, devicename);
|
||||
device = DriverList[idx].alcOpenDevice(devicename);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
for(i = 0;i < DriverListSize;i++)
|
||||
for(const auto &drv : DriverList)
|
||||
{
|
||||
if(DriverList[i].ALCVer >= MAKE_ALC_VER(1, 1) ||
|
||||
DriverList[i].alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT"))
|
||||
if(drv.ALCVer >= MAKE_ALC_VER(1, 1) ||
|
||||
drv.alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT"))
|
||||
{
|
||||
idx = i;
|
||||
TRACE("Using default device from driver %d\n", idx);
|
||||
device = DriverList[idx].alcOpenDevice(NULL);
|
||||
device = drv.alcOpenDevice(nullptr);
|
||||
break;
|
||||
}
|
||||
++idx;
|
||||
}
|
||||
}
|
||||
|
||||
if(device)
|
||||
{
|
||||
if(InsertPtrIntMapEntry(&DeviceIfaceMap, device, idx) != ALC_NO_ERROR)
|
||||
if(DeviceIfaceMap.insert(device, idx) != ALC_NO_ERROR)
|
||||
{
|
||||
DriverList[idx].alcCloseDevice(device);
|
||||
device = NULL;
|
||||
device = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,14 +412,14 @@ ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *device)
|
||||
{
|
||||
ALint idx;
|
||||
|
||||
if(!device || (idx=LookupPtrIntMapKey(&DeviceIfaceMap, device)) < 0)
|
||||
if(!device || (idx=DeviceIfaceMap.lookupByKey(device)) < 0)
|
||||
{
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
if(!DriverList[idx].alcCloseDevice(device))
|
||||
return ALC_FALSE;
|
||||
RemovePtrIntMapKey(&DeviceIfaceMap, device);
|
||||
DeviceIfaceMap.removeByKey(device);
|
||||
return ALC_TRUE;
|
||||
}
|
||||
|
||||
@@ -432,18 +429,18 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
|
||||
ALCcontext *context;
|
||||
ALint idx;
|
||||
|
||||
if(!device || (idx=LookupPtrIntMapKey(&DeviceIfaceMap, device)) < 0)
|
||||
if(!device || (idx=DeviceIfaceMap.lookupByKey(device)) < 0)
|
||||
{
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
|
||||
return ALC_FALSE;
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return nullptr;
|
||||
}
|
||||
context = DriverList[idx].alcCreateContext(device, attrlist);
|
||||
if(context)
|
||||
{
|
||||
if(InsertPtrIntMapEntry(&ContextIfaceMap, context, idx) != ALC_NO_ERROR)
|
||||
if(ContextIfaceMap.insert(context, idx) != ALC_NO_ERROR)
|
||||
{
|
||||
DriverList[idx].alcDestroyContext(context);
|
||||
context = NULL;
|
||||
context = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,21 +451,17 @@ ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
|
||||
{
|
||||
ALint idx = -1;
|
||||
|
||||
almtx_lock(&ContextSwitchLock);
|
||||
std::lock_guard<std::mutex> _{ContextSwitchLock};
|
||||
if(context)
|
||||
{
|
||||
idx = LookupPtrIntMapKey(&ContextIfaceMap, context);
|
||||
idx = ContextIfaceMap.lookupByKey(context);
|
||||
if(idx < 0)
|
||||
{
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_CONTEXT);
|
||||
almtx_unlock(&ContextSwitchLock);
|
||||
LastError.store(ALC_INVALID_CONTEXT);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
if(!DriverList[idx].alcMakeContextCurrent(context))
|
||||
{
|
||||
almtx_unlock(&ContextSwitchLock);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Unset the context from the old driver if it's different from the new
|
||||
@@ -476,22 +469,21 @@ ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
|
||||
*/
|
||||
if(idx < 0)
|
||||
{
|
||||
DriverIface *oldiface = altss_get(ThreadCtxDriver);
|
||||
if(oldiface) oldiface->alcSetThreadContext(NULL);
|
||||
oldiface = ATOMIC_EXCHANGE_PTR_SEQ(&CurrentCtxDriver, NULL);
|
||||
if(oldiface) oldiface->alcMakeContextCurrent(NULL);
|
||||
DriverIface *oldiface = ThreadCtxDriver;
|
||||
if(oldiface) oldiface->alcSetThreadContext(nullptr);
|
||||
oldiface = CurrentCtxDriver.exchange(nullptr);
|
||||
if(oldiface) oldiface->alcMakeContextCurrent(nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
DriverIface *oldiface = altss_get(ThreadCtxDriver);
|
||||
DriverIface *oldiface = ThreadCtxDriver;
|
||||
if(oldiface && oldiface != &DriverList[idx])
|
||||
oldiface->alcSetThreadContext(NULL);
|
||||
oldiface = ATOMIC_EXCHANGE_PTR_SEQ(&CurrentCtxDriver, &DriverList[idx]);
|
||||
oldiface->alcSetThreadContext(nullptr);
|
||||
oldiface = CurrentCtxDriver.exchange(&DriverList[idx]);
|
||||
if(oldiface && oldiface != &DriverList[idx])
|
||||
oldiface->alcMakeContextCurrent(NULL);
|
||||
oldiface->alcMakeContextCurrent(nullptr);
|
||||
}
|
||||
almtx_unlock(&ContextSwitchLock);
|
||||
altss_set(ThreadCtxDriver, NULL);
|
||||
ThreadCtxDriver = nullptr;
|
||||
|
||||
return ALC_TRUE;
|
||||
}
|
||||
@@ -500,55 +492,55 @@ ALC_API void ALC_APIENTRY alcProcessContext(ALCcontext *context)
|
||||
{
|
||||
if(context)
|
||||
{
|
||||
ALint idx = LookupPtrIntMapKey(&ContextIfaceMap, context);
|
||||
ALint idx = ContextIfaceMap.lookupByKey(context);
|
||||
if(idx >= 0)
|
||||
return DriverList[idx].alcProcessContext(context);
|
||||
}
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_CONTEXT);
|
||||
LastError.store(ALC_INVALID_CONTEXT);
|
||||
}
|
||||
|
||||
ALC_API void ALC_APIENTRY alcSuspendContext(ALCcontext *context)
|
||||
{
|
||||
if(context)
|
||||
{
|
||||
ALint idx = LookupPtrIntMapKey(&ContextIfaceMap, context);
|
||||
ALint idx = ContextIfaceMap.lookupByKey(context);
|
||||
if(idx >= 0)
|
||||
return DriverList[idx].alcSuspendContext(context);
|
||||
}
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_CONTEXT);
|
||||
LastError.store(ALC_INVALID_CONTEXT);
|
||||
}
|
||||
|
||||
ALC_API void ALC_APIENTRY alcDestroyContext(ALCcontext *context)
|
||||
{
|
||||
ALint idx;
|
||||
|
||||
if(!context || (idx=LookupPtrIntMapKey(&ContextIfaceMap, context)) < 0)
|
||||
if(!context || (idx=ContextIfaceMap.lookupByKey(context)) < 0)
|
||||
{
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_CONTEXT);
|
||||
LastError.store(ALC_INVALID_CONTEXT);
|
||||
return;
|
||||
}
|
||||
|
||||
DriverList[idx].alcDestroyContext(context);
|
||||
RemovePtrIntMapKey(&ContextIfaceMap, context);
|
||||
ContextIfaceMap.removeByKey(context);
|
||||
}
|
||||
|
||||
ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(void)
|
||||
{
|
||||
DriverIface *iface = altss_get(ThreadCtxDriver);
|
||||
if(!iface) iface = ATOMIC_LOAD_SEQ(&CurrentCtxDriver);
|
||||
return iface ? iface->alcGetCurrentContext() : NULL;
|
||||
DriverIface *iface = ThreadCtxDriver;
|
||||
if(!iface) iface = CurrentCtxDriver.load();
|
||||
return iface ? iface->alcGetCurrentContext() : nullptr;
|
||||
}
|
||||
|
||||
ALC_API ALCdevice* ALC_APIENTRY alcGetContextsDevice(ALCcontext *context)
|
||||
{
|
||||
if(context)
|
||||
{
|
||||
ALint idx = LookupPtrIntMapKey(&ContextIfaceMap, context);
|
||||
ALint idx = ContextIfaceMap.lookupByKey(context);
|
||||
if(idx >= 0)
|
||||
return DriverList[idx].alcGetContextsDevice(context);
|
||||
}
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_CONTEXT);
|
||||
return NULL;
|
||||
LastError.store(ALC_INVALID_CONTEXT);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -556,11 +548,11 @@ ALC_API ALCenum ALC_APIENTRY alcGetError(ALCdevice *device)
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx < 0) return ALC_INVALID_DEVICE;
|
||||
return DriverList[idx].alcGetError(device);
|
||||
}
|
||||
return ATOMIC_EXCHANGE_SEQ(&LastError, ALC_NO_ERROR);
|
||||
return LastError.exchange(ALC_NO_ERROR);
|
||||
}
|
||||
|
||||
ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const ALCchar *extname)
|
||||
@@ -570,10 +562,10 @@ ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const A
|
||||
|
||||
if(device)
|
||||
{
|
||||
ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx < 0)
|
||||
{
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
return DriverList[idx].alcIsExtensionPresent(device, extname);
|
||||
@@ -583,9 +575,9 @@ ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const A
|
||||
ptr = alcExtensionList;
|
||||
while(ptr && *ptr)
|
||||
{
|
||||
if(strncasecmp(ptr, extname, len) == 0 && (ptr[len] == '\0' || isspace(ptr[len])))
|
||||
if(al::strncasecmp(ptr, extname, len) == 0 && (ptr[len] == '\0' || isspace(ptr[len])))
|
||||
return ALC_TRUE;
|
||||
if((ptr=strchr(ptr, ' ')) != NULL)
|
||||
if((ptr=strchr(ptr, ' ')) != nullptr)
|
||||
{
|
||||
do {
|
||||
++ptr;
|
||||
@@ -597,61 +589,53 @@ ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const A
|
||||
|
||||
ALC_API void* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *funcname)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if(device)
|
||||
{
|
||||
ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx < 0)
|
||||
{
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
|
||||
return NULL;
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return nullptr;
|
||||
}
|
||||
return DriverList[idx].alcGetProcAddress(device, funcname);
|
||||
}
|
||||
|
||||
for(i = 0;i < COUNTOF(alcFunctions);i++)
|
||||
{
|
||||
if(strcmp(funcname, alcFunctions[i].funcName) == 0)
|
||||
return alcFunctions[i].address;
|
||||
}
|
||||
return NULL;
|
||||
auto iter = std::find_if(alcFunctions.cbegin(), alcFunctions.cend(),
|
||||
[funcname](const FuncExportEntry &entry) -> bool
|
||||
{ return strcmp(funcname, entry.funcName) == 0; }
|
||||
);
|
||||
return (iter != alcFunctions.cend()) ? iter->address : nullptr;
|
||||
}
|
||||
|
||||
ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *enumname)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if(device)
|
||||
{
|
||||
ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx < 0)
|
||||
{
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return 0;
|
||||
}
|
||||
return DriverList[idx].alcGetEnumValue(device, enumname);
|
||||
}
|
||||
|
||||
for(i = 0;i < COUNTOF(alcEnumerations);i++)
|
||||
{
|
||||
if(strcmp(enumname, alcEnumerations[i].enumName) == 0)
|
||||
return alcEnumerations[i].value;
|
||||
}
|
||||
return 0;
|
||||
auto iter = std::find_if(alcEnumerations.cbegin(), alcEnumerations.cend(),
|
||||
[enumname](const EnumExportEntry &entry) -> bool
|
||||
{ return strcmp(enumname, entry.enumName) == 0; }
|
||||
);
|
||||
return (iter != alcEnumerations.cend()) ? iter->value : 0;
|
||||
}
|
||||
|
||||
ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum param)
|
||||
{
|
||||
ALsizei i = 0;
|
||||
|
||||
if(device)
|
||||
{
|
||||
ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx < 0)
|
||||
{
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
|
||||
return NULL;
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return nullptr;
|
||||
}
|
||||
return DriverList[idx].alcGetString(device, param);
|
||||
}
|
||||
@@ -674,104 +658,133 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum para
|
||||
return alcExtensionList;
|
||||
|
||||
case ALC_DEVICE_SPECIFIER:
|
||||
almtx_lock(&EnumerationLock);
|
||||
ClearDeviceList(&DevicesList);
|
||||
for(i = 0;i < DriverListSize;i++)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _{EnumerationLock};
|
||||
DevicesList.clear();
|
||||
ALint idx{0};
|
||||
for(const auto &drv : DriverList)
|
||||
{
|
||||
/* Only enumerate names from drivers that support it. */
|
||||
if(DriverList[i].ALCVer >= MAKE_ALC_VER(1, 1) ||
|
||||
DriverList[i].alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT"))
|
||||
if(drv.ALCVer >= MAKE_ALC_VER(1, 1)
|
||||
|| drv.alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT"))
|
||||
AppendDeviceList(&DevicesList,
|
||||
DriverList[i].alcGetString(NULL, ALC_DEVICE_SPECIFIER), i
|
||||
);
|
||||
drv.alcGetString(nullptr, ALC_DEVICE_SPECIFIER), idx);
|
||||
++idx;
|
||||
}
|
||||
almtx_unlock(&EnumerationLock);
|
||||
return DevicesList.Names;
|
||||
/* Ensure the list is double-null termianted. */
|
||||
if(DevicesList.Names.empty())
|
||||
DevicesList.Names.emplace_back('\0');
|
||||
DevicesList.Names.emplace_back('\0');
|
||||
return DevicesList.Names.data();
|
||||
}
|
||||
|
||||
case ALC_ALL_DEVICES_SPECIFIER:
|
||||
almtx_lock(&EnumerationLock);
|
||||
ClearDeviceList(&AllDevicesList);
|
||||
for(i = 0;i < DriverListSize;i++)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _{EnumerationLock};
|
||||
AllDevicesList.clear();
|
||||
ALint idx{0};
|
||||
for(const auto &drv : DriverList)
|
||||
{
|
||||
/* If the driver doesn't support ALC_ENUMERATE_ALL_EXT, substitute
|
||||
* standard enumeration.
|
||||
*/
|
||||
if(DriverList[i].alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT"))
|
||||
if(drv.alcIsExtensionPresent(nullptr, "ALC_ENUMERATE_ALL_EXT"))
|
||||
AppendDeviceList(&AllDevicesList,
|
||||
DriverList[i].alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER), i
|
||||
);
|
||||
else if(DriverList[i].ALCVer >= MAKE_ALC_VER(1, 1) ||
|
||||
DriverList[i].alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT"))
|
||||
drv.alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER), idx);
|
||||
else if(drv.ALCVer >= MAKE_ALC_VER(1, 1)
|
||||
|| drv.alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT"))
|
||||
AppendDeviceList(&AllDevicesList,
|
||||
DriverList[i].alcGetString(NULL, ALC_DEVICE_SPECIFIER), i
|
||||
);
|
||||
drv.alcGetString(nullptr, ALC_DEVICE_SPECIFIER), idx);
|
||||
++idx;
|
||||
}
|
||||
almtx_unlock(&EnumerationLock);
|
||||
return AllDevicesList.Names;
|
||||
/* Ensure the list is double-null termianted. */
|
||||
if(AllDevicesList.Names.empty())
|
||||
AllDevicesList.Names.emplace_back('\0');
|
||||
AllDevicesList.Names.emplace_back('\0');
|
||||
return AllDevicesList.Names.data();
|
||||
}
|
||||
|
||||
case ALC_CAPTURE_DEVICE_SPECIFIER:
|
||||
almtx_lock(&EnumerationLock);
|
||||
ClearDeviceList(&CaptureDevicesList);
|
||||
for(i = 0;i < DriverListSize;i++)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _{EnumerationLock};
|
||||
CaptureDevicesList.clear();
|
||||
ALint idx{0};
|
||||
for(const auto &drv : DriverList)
|
||||
{
|
||||
if(DriverList[i].ALCVer >= MAKE_ALC_VER(1, 1) ||
|
||||
DriverList[i].alcIsExtensionPresent(NULL, "ALC_EXT_CAPTURE"))
|
||||
if(drv.ALCVer >= MAKE_ALC_VER(1, 1)
|
||||
|| drv.alcIsExtensionPresent(nullptr, "ALC_EXT_CAPTURE"))
|
||||
AppendDeviceList(&CaptureDevicesList,
|
||||
DriverList[i].alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER), i
|
||||
);
|
||||
drv.alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER), idx);
|
||||
++idx;
|
||||
}
|
||||
almtx_unlock(&EnumerationLock);
|
||||
return CaptureDevicesList.Names;
|
||||
/* Ensure the list is double-null termianted. */
|
||||
if(CaptureDevicesList.Names.empty())
|
||||
CaptureDevicesList.Names.emplace_back('\0');
|
||||
CaptureDevicesList.Names.emplace_back('\0');
|
||||
return CaptureDevicesList.Names.data();
|
||||
}
|
||||
|
||||
case ALC_DEFAULT_DEVICE_SPECIFIER:
|
||||
for(i = 0;i < DriverListSize;i++)
|
||||
{
|
||||
if(DriverList[i].ALCVer >= MAKE_ALC_VER(1, 1) ||
|
||||
DriverList[i].alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT"))
|
||||
return DriverList[i].alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
|
||||
}
|
||||
{
|
||||
auto iter = std::find_if(DriverList.cbegin(), DriverList.cend(),
|
||||
[](const DriverIface &drv) -> bool
|
||||
{
|
||||
return drv.ALCVer >= MAKE_ALC_VER(1, 1)
|
||||
|| drv.alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT");
|
||||
}
|
||||
);
|
||||
if(iter != DriverList.cend())
|
||||
return iter->alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER);
|
||||
return "";
|
||||
}
|
||||
|
||||
case ALC_DEFAULT_ALL_DEVICES_SPECIFIER:
|
||||
for(i = 0;i < DriverListSize;i++)
|
||||
{
|
||||
if(DriverList[i].alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT"))
|
||||
return DriverList[i].alcGetString(NULL, ALC_DEFAULT_ALL_DEVICES_SPECIFIER);
|
||||
}
|
||||
{
|
||||
auto iter = std::find_if(DriverList.cbegin(), DriverList.cend(),
|
||||
[](const DriverIface &drv) -> bool
|
||||
{ return drv.alcIsExtensionPresent(nullptr, "ALC_ENUMERATE_ALL_EXT") != ALC_FALSE; });
|
||||
if(iter != DriverList.cend())
|
||||
return iter->alcGetString(nullptr, ALC_DEFAULT_ALL_DEVICES_SPECIFIER);
|
||||
return "";
|
||||
}
|
||||
|
||||
case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER:
|
||||
for(i = 0;i < DriverListSize;i++)
|
||||
{
|
||||
if(DriverList[i].ALCVer >= MAKE_ALC_VER(1, 1) ||
|
||||
DriverList[i].alcIsExtensionPresent(NULL, "ALC_EXT_CAPTURE"))
|
||||
return DriverList[i].alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
|
||||
}
|
||||
{
|
||||
auto iter = std::find_if(DriverList.cbegin(), DriverList.cend(),
|
||||
[](const DriverIface &drv) -> bool
|
||||
{
|
||||
return drv.ALCVer >= MAKE_ALC_VER(1, 1)
|
||||
|| drv.alcIsExtensionPresent(nullptr, "ALC_EXT_CAPTURE");
|
||||
}
|
||||
);
|
||||
if(iter != DriverList.cend())
|
||||
return iter->alcGetString(nullptr, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
|
||||
return "";
|
||||
}
|
||||
|
||||
default:
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_ENUM);
|
||||
LastError.store(ALC_INVALID_ENUM);
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ALC_API void ALC_APIENTRY alcGetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALCint *values)
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx < 0)
|
||||
{
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return;
|
||||
}
|
||||
return DriverList[idx].alcGetIntegerv(device, param, size, values);
|
||||
}
|
||||
|
||||
if(size <= 0 || values == NULL)
|
||||
if(size <= 0 || values == nullptr)
|
||||
{
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_VALUE);
|
||||
LastError.store(ALC_INVALID_VALUE);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -790,7 +803,7 @@ ALC_API void ALC_APIENTRY alcGetIntegerv(ALCdevice *device, ALCenum param, ALCsi
|
||||
values[0] = alcMinorVersion;
|
||||
return;
|
||||
}
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_VALUE);
|
||||
LastError.store(ALC_INVALID_VALUE);
|
||||
return;
|
||||
|
||||
case ALC_ATTRIBUTES_SIZE:
|
||||
@@ -801,11 +814,11 @@ ALC_API void ALC_APIENTRY alcGetIntegerv(ALCdevice *device, ALCenum param, ALCsi
|
||||
case ALC_MONO_SOURCES:
|
||||
case ALC_STEREO_SOURCES:
|
||||
case ALC_CAPTURE_SAMPLES:
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return;
|
||||
|
||||
default:
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_ENUM);
|
||||
LastError.store(ALC_INVALID_ENUM);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -813,53 +826,50 @@ ALC_API void ALC_APIENTRY alcGetIntegerv(ALCdevice *device, ALCenum param, ALCsi
|
||||
|
||||
ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *devicename, ALCuint frequency, ALCenum format, ALCsizei buffersize)
|
||||
{
|
||||
ALCdevice *device = NULL;
|
||||
ALint idx;
|
||||
ALCdevice *device = nullptr;
|
||||
ALint idx = 0;
|
||||
|
||||
if(devicename && devicename[0] == '\0')
|
||||
devicename = NULL;
|
||||
devicename = nullptr;
|
||||
if(devicename)
|
||||
{
|
||||
almtx_lock(&EnumerationLock);
|
||||
if(!CaptureDevicesList.Names)
|
||||
(void)alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
|
||||
idx = GetDriverIndexForName(&CaptureDevicesList, devicename);
|
||||
almtx_unlock(&EnumerationLock);
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _{EnumerationLock};
|
||||
if(CaptureDevicesList.Names.empty())
|
||||
(void)alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER);
|
||||
idx = GetDriverIndexForName(&CaptureDevicesList, devicename);
|
||||
}
|
||||
|
||||
if(idx < 0)
|
||||
{
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_VALUE);
|
||||
LastError.store(ALC_INVALID_VALUE);
|
||||
TRACE("Failed to find driver for name \"%s\"\n", devicename);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
TRACE("Found driver %d for name \"%s\"\n", idx, devicename);
|
||||
device = DriverList[idx].alcCaptureOpenDevice(
|
||||
devicename, frequency, format, buffersize
|
||||
);
|
||||
device = DriverList[idx].alcCaptureOpenDevice(devicename, frequency, format, buffersize);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
for(i = 0;i < DriverListSize;i++)
|
||||
for(const auto &drv : DriverList)
|
||||
{
|
||||
if(DriverList[i].ALCVer >= MAKE_ALC_VER(1, 1) ||
|
||||
DriverList[i].alcIsExtensionPresent(NULL, "ALC_EXT_CAPTURE"))
|
||||
if(drv.ALCVer >= MAKE_ALC_VER(1, 1)
|
||||
|| drv.alcIsExtensionPresent(nullptr, "ALC_EXT_CAPTURE"))
|
||||
{
|
||||
idx = i;
|
||||
TRACE("Using default capture device from driver %d\n", idx);
|
||||
device = DriverList[idx].alcCaptureOpenDevice(
|
||||
NULL, frequency, format, buffersize
|
||||
);
|
||||
device = drv.alcCaptureOpenDevice(nullptr, frequency, format, buffersize);
|
||||
break;
|
||||
}
|
||||
++idx;
|
||||
}
|
||||
}
|
||||
|
||||
if(device)
|
||||
{
|
||||
if(InsertPtrIntMapEntry(&DeviceIfaceMap, device, idx) != ALC_NO_ERROR)
|
||||
if(DeviceIfaceMap.insert(device, idx) != ALC_NO_ERROR)
|
||||
{
|
||||
DriverList[idx].alcCaptureCloseDevice(device);
|
||||
device = NULL;
|
||||
device = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -870,14 +880,14 @@ ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *device)
|
||||
{
|
||||
ALint idx;
|
||||
|
||||
if(!device || (idx=LookupPtrIntMapKey(&DeviceIfaceMap, device)) < 0)
|
||||
if(!device || (idx=DeviceIfaceMap.lookupByKey(device)) < 0)
|
||||
{
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
if(!DriverList[idx].alcCaptureCloseDevice(device))
|
||||
return ALC_FALSE;
|
||||
RemovePtrIntMapKey(&DeviceIfaceMap, device);
|
||||
DeviceIfaceMap.removeByKey(device);
|
||||
return ALC_TRUE;
|
||||
}
|
||||
|
||||
@@ -885,33 +895,33 @@ ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device)
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx >= 0)
|
||||
return DriverList[idx].alcCaptureStart(device);
|
||||
}
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
}
|
||||
|
||||
ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device)
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx >= 0)
|
||||
return DriverList[idx].alcCaptureStop(device);
|
||||
}
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
}
|
||||
|
||||
ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer, ALCsizei samples)
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx >= 0)
|
||||
return DriverList[idx].alcCaptureSamples(device, buffer, samples);
|
||||
}
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
}
|
||||
|
||||
|
||||
@@ -922,35 +932,35 @@ ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context)
|
||||
|
||||
if(!context)
|
||||
{
|
||||
DriverIface *oldiface = altss_get(ThreadCtxDriver);
|
||||
if(oldiface && !oldiface->alcSetThreadContext(NULL))
|
||||
DriverIface *oldiface = ThreadCtxDriver;
|
||||
if(oldiface && !oldiface->alcSetThreadContext(nullptr))
|
||||
return ALC_FALSE;
|
||||
altss_set(ThreadCtxDriver, NULL);
|
||||
ThreadCtxDriver = nullptr;
|
||||
return ALC_TRUE;
|
||||
}
|
||||
|
||||
idx = LookupPtrIntMapKey(&ContextIfaceMap, context);
|
||||
idx = ContextIfaceMap.lookupByKey(context);
|
||||
if(idx >= 0)
|
||||
{
|
||||
if(DriverList[idx].alcSetThreadContext(context))
|
||||
{
|
||||
DriverIface *oldiface = altss_get(ThreadCtxDriver);
|
||||
DriverIface *oldiface = ThreadCtxDriver;
|
||||
if(oldiface != &DriverList[idx])
|
||||
{
|
||||
altss_set(ThreadCtxDriver, &DriverList[idx]);
|
||||
if(oldiface) oldiface->alcSetThreadContext(NULL);
|
||||
ThreadCtxDriver = &DriverList[idx];
|
||||
if(oldiface) oldiface->alcSetThreadContext(nullptr);
|
||||
}
|
||||
return ALC_TRUE;
|
||||
}
|
||||
err = DriverList[idx].alcGetError(NULL);
|
||||
err = DriverList[idx].alcGetError(nullptr);
|
||||
}
|
||||
ATOMIC_STORE_SEQ(&LastError, err);
|
||||
LastError.store(err);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext(void)
|
||||
{
|
||||
DriverIface *iface = altss_get(ThreadCtxDriver);
|
||||
DriverIface *iface = ThreadCtxDriver;
|
||||
if(iface) return iface->alcGetThreadContext();
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
@@ -3,22 +3,23 @@
|
||||
|
||||
#include "router.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "AL/alc.h"
|
||||
#include "AL/al.h"
|
||||
|
||||
#include "almalloc.h"
|
||||
#include "strutils.h"
|
||||
|
||||
#include "version.h"
|
||||
|
||||
|
||||
DriverIface *DriverList = NULL;
|
||||
int DriverListSize = 0;
|
||||
static int DriverListSizeMax = 0;
|
||||
std::vector<DriverIface> DriverList;
|
||||
|
||||
altss_t ThreadCtxDriver;
|
||||
thread_local DriverIface *ThreadCtxDriver;
|
||||
|
||||
enum LogLevel LogLevel = LogLevel_Error;
|
||||
FILE *LogFile;
|
||||
@@ -26,95 +27,65 @@ FILE *LogFile;
|
||||
static void LoadDriverList(void);
|
||||
|
||||
|
||||
BOOL APIENTRY DllMain(HINSTANCE UNUSED(module), DWORD reason, void* UNUSED(reserved))
|
||||
BOOL APIENTRY DllMain(HINSTANCE, DWORD reason, void*)
|
||||
{
|
||||
const char *str;
|
||||
int i;
|
||||
|
||||
switch(reason)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
LogFile = stderr;
|
||||
str = getenv("ALROUTER_LOGFILE");
|
||||
if(str && *str != '\0')
|
||||
{
|
||||
FILE *f = fopen(str, "w");
|
||||
if(f == NULL)
|
||||
ERR("Could not open log file: %s\n", str);
|
||||
else
|
||||
LogFile = f;
|
||||
}
|
||||
str = getenv("ALROUTER_LOGLEVEL");
|
||||
if(str && *str != '\0')
|
||||
{
|
||||
char *end = NULL;
|
||||
long l = strtol(str, &end, 0);
|
||||
if(!end || *end != '\0')
|
||||
ERR("Invalid log level value: %s\n", str);
|
||||
else if(l < LogLevel_None || l > LogLevel_Trace)
|
||||
ERR("Log level out of range: %s\n", str);
|
||||
else
|
||||
LogLevel = l;
|
||||
}
|
||||
TRACE("Initializing router v0.1-%s %s\n", ALSOFT_GIT_COMMIT_HASH, ALSOFT_GIT_BRANCH);
|
||||
LoadDriverList();
|
||||
case DLL_PROCESS_ATTACH:
|
||||
LogFile = stderr;
|
||||
if(auto logfname = al::getenv("ALROUTER_LOGFILE"))
|
||||
{
|
||||
FILE *f = fopen(logfname->c_str(), "w");
|
||||
if(f == nullptr)
|
||||
ERR("Could not open log file: %s\n", logfname->c_str());
|
||||
else
|
||||
LogFile = f;
|
||||
}
|
||||
if(auto loglev = al::getenv("ALROUTER_LOGLEVEL"))
|
||||
{
|
||||
char *end = nullptr;
|
||||
long l = strtol(loglev->c_str(), &end, 0);
|
||||
if(!end || *end != '\0')
|
||||
ERR("Invalid log level value: %s\n", loglev->c_str());
|
||||
else if(l < LogLevel_None || l > LogLevel_Trace)
|
||||
ERR("Log level out of range: %s\n", loglev->c_str());
|
||||
else
|
||||
LogLevel = static_cast<enum LogLevel>(l);
|
||||
}
|
||||
TRACE("Initializing router v0.1-%s %s\n", ALSOFT_GIT_COMMIT_HASH, ALSOFT_GIT_BRANCH);
|
||||
LoadDriverList();
|
||||
|
||||
altss_create(&ThreadCtxDriver, NULL);
|
||||
InitALC();
|
||||
break;
|
||||
break;
|
||||
|
||||
case DLL_THREAD_ATTACH:
|
||||
break;
|
||||
case DLL_THREAD_DETACH:
|
||||
althrd_thread_detach();
|
||||
break;
|
||||
case DLL_THREAD_ATTACH:
|
||||
break;
|
||||
case DLL_THREAD_DETACH:
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
ReleaseALC();
|
||||
altss_delete(ThreadCtxDriver);
|
||||
case DLL_PROCESS_DETACH:
|
||||
DriverList.clear();
|
||||
|
||||
for(i = 0;i < DriverListSize;i++)
|
||||
{
|
||||
if(DriverList[i].Module)
|
||||
FreeLibrary(DriverList[i].Module);
|
||||
}
|
||||
al_free(DriverList);
|
||||
DriverList = NULL;
|
||||
DriverListSize = 0;
|
||||
DriverListSizeMax = 0;
|
||||
if(LogFile && LogFile != stderr)
|
||||
fclose(LogFile);
|
||||
LogFile = nullptr;
|
||||
|
||||
if(LogFile && LogFile != stderr)
|
||||
fclose(LogFile);
|
||||
LogFile = NULL;
|
||||
|
||||
althrd_deinit();
|
||||
break;
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define CAST_FUNC(x) (__typeof(x))
|
||||
#else
|
||||
#define CAST_FUNC(x) (void*)
|
||||
#endif
|
||||
|
||||
static void AddModule(HMODULE module, const WCHAR *name)
|
||||
{
|
||||
DriverIface newdrv;
|
||||
int err = 0;
|
||||
int i;
|
||||
|
||||
for(i = 0;i < DriverListSize;i++)
|
||||
for(auto &drv : DriverList)
|
||||
{
|
||||
if(DriverList[i].Module == module)
|
||||
if(drv.Module == module)
|
||||
{
|
||||
TRACE("Skipping already-loaded module %p\n", module);
|
||||
TRACE("Skipping already-loaded module %p\n", decltype(std::declval<void*>()){module});
|
||||
FreeLibrary(module);
|
||||
return;
|
||||
}
|
||||
if(wcscmp(DriverList[i].Name, name) == 0)
|
||||
if(drv.Name == name)
|
||||
{
|
||||
TRACE("Skipping similarly-named module %ls\n", name);
|
||||
FreeLibrary(module);
|
||||
@@ -122,22 +93,14 @@ static void AddModule(HMODULE module, const WCHAR *name)
|
||||
}
|
||||
}
|
||||
|
||||
if(DriverListSize == DriverListSizeMax)
|
||||
{
|
||||
int newmax = DriverListSizeMax ? DriverListSizeMax<<1 : 4;
|
||||
void *newlist = al_calloc(DEF_ALIGN, sizeof(DriverList[0])*newmax);
|
||||
if(!newlist) return;
|
||||
DriverList.emplace_back(name, module);
|
||||
DriverIface &newdrv = DriverList.back();
|
||||
|
||||
memcpy(newlist, DriverList, DriverListSize*sizeof(DriverList[0]));
|
||||
al_free(DriverList);
|
||||
DriverList = newlist;
|
||||
DriverListSizeMax = newmax;
|
||||
}
|
||||
|
||||
memset(&newdrv, 0, sizeof(newdrv));
|
||||
/* Load required functions. */
|
||||
int err = 0;
|
||||
#define LOAD_PROC(x) do { \
|
||||
newdrv.x = CAST_FUNC(newdrv.x) GetProcAddress(module, #x); \
|
||||
newdrv.x = reinterpret_cast<decltype(newdrv.x)>(reinterpret_cast<void*>( \
|
||||
GetProcAddress(module, #x))); \
|
||||
if(!newdrv.x) \
|
||||
{ \
|
||||
ERR("Failed to find entry point for %s in %ls\n", #x, name); \
|
||||
@@ -241,63 +204,98 @@ static void AddModule(HMODULE module, const WCHAR *name)
|
||||
if(!err)
|
||||
{
|
||||
ALCint alc_ver[2] = { 0, 0 };
|
||||
wcsncpy(newdrv.Name, name, 32);
|
||||
newdrv.Module = module;
|
||||
newdrv.alcGetIntegerv(NULL, ALC_MAJOR_VERSION, 1, &alc_ver[0]);
|
||||
newdrv.alcGetIntegerv(NULL, ALC_MINOR_VERSION, 1, &alc_ver[1]);
|
||||
if(newdrv.alcGetError(NULL) == ALC_NO_ERROR)
|
||||
newdrv.alcGetIntegerv(nullptr, ALC_MAJOR_VERSION, 1, &alc_ver[0]);
|
||||
newdrv.alcGetIntegerv(nullptr, ALC_MINOR_VERSION, 1, &alc_ver[1]);
|
||||
if(newdrv.alcGetError(nullptr) == ALC_NO_ERROR)
|
||||
newdrv.ALCVer = MAKE_ALC_VER(alc_ver[0], alc_ver[1]);
|
||||
else
|
||||
newdrv.ALCVer = MAKE_ALC_VER(1, 0);
|
||||
|
||||
#undef LOAD_PROC
|
||||
#define LOAD_PROC(x) do { \
|
||||
newdrv.x = CAST_FUNC(newdrv.x) newdrv.alcGetProcAddress(NULL, #x); \
|
||||
newdrv.x = reinterpret_cast<decltype(newdrv.x)>( \
|
||||
newdrv.alcGetProcAddress(nullptr, #x)); \
|
||||
if(!newdrv.x) \
|
||||
{ \
|
||||
ERR("Failed to find entry point for %s in %ls\n", #x, name); \
|
||||
err = 1; \
|
||||
} \
|
||||
} while(0)
|
||||
if(newdrv.alcIsExtensionPresent(NULL, "ALC_EXT_thread_local_context"))
|
||||
if(newdrv.alcIsExtensionPresent(nullptr, "ALC_EXT_thread_local_context"))
|
||||
{
|
||||
LOAD_PROC(alcSetThreadContext);
|
||||
LOAD_PROC(alcGetThreadContext);
|
||||
}
|
||||
if(newdrv.alcIsExtensionPresent(nullptr, "ALC_EXT_EFX"))
|
||||
{
|
||||
LOAD_PROC(alGenFilters);
|
||||
LOAD_PROC(alDeleteFilters);
|
||||
LOAD_PROC(alIsFilter);
|
||||
LOAD_PROC(alFilterf);
|
||||
LOAD_PROC(alFilterfv);
|
||||
LOAD_PROC(alFilteri);
|
||||
LOAD_PROC(alFilteriv);
|
||||
LOAD_PROC(alGetFilterf);
|
||||
LOAD_PROC(alGetFilterfv);
|
||||
LOAD_PROC(alGetFilteri);
|
||||
LOAD_PROC(alGetFilteriv);
|
||||
LOAD_PROC(alGenEffects);
|
||||
LOAD_PROC(alDeleteEffects);
|
||||
LOAD_PROC(alIsEffect);
|
||||
LOAD_PROC(alEffectf);
|
||||
LOAD_PROC(alEffectfv);
|
||||
LOAD_PROC(alEffecti);
|
||||
LOAD_PROC(alEffectiv);
|
||||
LOAD_PROC(alGetEffectf);
|
||||
LOAD_PROC(alGetEffectfv);
|
||||
LOAD_PROC(alGetEffecti);
|
||||
LOAD_PROC(alGetEffectiv);
|
||||
LOAD_PROC(alGenAuxiliaryEffectSlots);
|
||||
LOAD_PROC(alDeleteAuxiliaryEffectSlots);
|
||||
LOAD_PROC(alIsAuxiliaryEffectSlot);
|
||||
LOAD_PROC(alAuxiliaryEffectSlotf);
|
||||
LOAD_PROC(alAuxiliaryEffectSlotfv);
|
||||
LOAD_PROC(alAuxiliaryEffectSloti);
|
||||
LOAD_PROC(alAuxiliaryEffectSlotiv);
|
||||
LOAD_PROC(alGetAuxiliaryEffectSlotf);
|
||||
LOAD_PROC(alGetAuxiliaryEffectSlotfv);
|
||||
LOAD_PROC(alGetAuxiliaryEffectSloti);
|
||||
LOAD_PROC(alGetAuxiliaryEffectSlotiv);
|
||||
}
|
||||
}
|
||||
|
||||
if(!err)
|
||||
if(err)
|
||||
{
|
||||
TRACE("Loaded module %p, %ls, ALC %d.%d\n", module, name,
|
||||
newdrv.ALCVer>>8, newdrv.ALCVer&255);
|
||||
DriverList[DriverListSize++] = newdrv;
|
||||
DriverList.pop_back();
|
||||
return;
|
||||
}
|
||||
TRACE("Loaded module %p, %ls, ALC %d.%d\n", decltype(std::declval<void*>()){module}, name,
|
||||
newdrv.ALCVer>>8, newdrv.ALCVer&255);
|
||||
#undef LOAD_PROC
|
||||
}
|
||||
|
||||
static void SearchDrivers(WCHAR *path)
|
||||
{
|
||||
WCHAR srchPath[MAX_PATH+1] = L"";
|
||||
WIN32_FIND_DATAW fdata;
|
||||
HANDLE srchHdl;
|
||||
|
||||
TRACE("Searching for drivers in %ls...\n", path);
|
||||
wcsncpy(srchPath, path, MAX_PATH);
|
||||
wcsncat(srchPath, L"\\*oal.dll", MAX_PATH - lstrlenW(srchPath));
|
||||
srchHdl = FindFirstFileW(srchPath, &fdata);
|
||||
std::wstring srchPath = path;
|
||||
srchPath += L"\\*oal.dll";
|
||||
|
||||
HANDLE srchHdl = FindFirstFileW(srchPath.c_str(), &fdata);
|
||||
if(srchHdl != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
do {
|
||||
HMODULE mod;
|
||||
|
||||
wcsncpy(srchPath, path, MAX_PATH);
|
||||
wcsncat(srchPath, L"\\", MAX_PATH - lstrlenW(srchPath));
|
||||
wcsncat(srchPath, fdata.cFileName, MAX_PATH - lstrlenW(srchPath));
|
||||
TRACE("Found %ls\n", srchPath);
|
||||
srchPath = path;
|
||||
srchPath += L"\\";
|
||||
srchPath += fdata.cFileName;
|
||||
TRACE("Found %ls\n", srchPath.c_str());
|
||||
|
||||
mod = LoadLibraryW(srchPath);
|
||||
mod = LoadLibraryW(srchPath.c_str());
|
||||
if(!mod)
|
||||
WARN("Could not load %ls\n", srchPath);
|
||||
WARN("Could not load %ls\n", srchPath.c_str());
|
||||
else
|
||||
AddModule(mod, fdata.cFileName);
|
||||
} while(FindNextFileW(srchHdl, &fdata));
|
||||
@@ -307,7 +305,7 @@ static void SearchDrivers(WCHAR *path)
|
||||
|
||||
static WCHAR *strrchrW(WCHAR *str, WCHAR ch)
|
||||
{
|
||||
WCHAR *res = NULL;
|
||||
WCHAR *res = nullptr;
|
||||
while(str && *str != '\0')
|
||||
{
|
||||
if(*str == ch)
|
||||
@@ -319,7 +317,7 @@ static WCHAR *strrchrW(WCHAR *str, WCHAR ch)
|
||||
|
||||
static int GetLoadedModuleDirectory(const WCHAR *name, WCHAR *moddir, DWORD length)
|
||||
{
|
||||
HMODULE module = NULL;
|
||||
HMODULE module = nullptr;
|
||||
WCHAR *sep0, *sep1;
|
||||
|
||||
if(name)
|
||||
@@ -359,7 +357,7 @@ void LoadDriverList(void)
|
||||
cwd_path[len-1] = '\0';
|
||||
TRACE("Got current working directory %ls\n", cwd_path);
|
||||
|
||||
if(GetLoadedModuleDirectory(NULL, proc_path, MAX_PATH))
|
||||
if(GetLoadedModuleDirectory(nullptr, proc_path, MAX_PATH))
|
||||
TRACE("Got proc path %ls\n", proc_path);
|
||||
|
||||
GetSystemDirectoryW(sys_path, MAX_PATH);
|
||||
@@ -388,150 +386,90 @@ void LoadDriverList(void)
|
||||
}
|
||||
|
||||
|
||||
void InitPtrIntMap(PtrIntMap *map)
|
||||
PtrIntMap::~PtrIntMap()
|
||||
{
|
||||
map->keys = NULL;
|
||||
map->values = NULL;
|
||||
map->size = 0;
|
||||
map->capacity = 0;
|
||||
RWLockInit(&map->lock);
|
||||
std::lock_guard<std::mutex> maplock{mLock};
|
||||
al_free(mKeys);
|
||||
mKeys = nullptr;
|
||||
mValues = nullptr;
|
||||
mSize = 0;
|
||||
mCapacity = 0;
|
||||
}
|
||||
|
||||
void ResetPtrIntMap(PtrIntMap *map)
|
||||
ALenum PtrIntMap::insert(void *key, int value)
|
||||
{
|
||||
WriteLock(&map->lock);
|
||||
al_free(map->keys);
|
||||
map->keys = NULL;
|
||||
map->values = NULL;
|
||||
map->size = 0;
|
||||
map->capacity = 0;
|
||||
WriteUnlock(&map->lock);
|
||||
}
|
||||
std::lock_guard<std::mutex> maplock{mLock};
|
||||
auto iter = std::lower_bound(mKeys, mKeys+mSize, key);
|
||||
auto pos = static_cast<ALsizei>(std::distance(mKeys, iter));
|
||||
|
||||
ALenum InsertPtrIntMapEntry(PtrIntMap *map, ALvoid *key, ALint value)
|
||||
{
|
||||
ALsizei pos = 0;
|
||||
|
||||
WriteLock(&map->lock);
|
||||
if(map->size > 0)
|
||||
if(pos == mSize || mKeys[pos] != key)
|
||||
{
|
||||
ALsizei count = map->size;
|
||||
do {
|
||||
ALsizei step = count>>1;
|
||||
ALsizei i = pos+step;
|
||||
if(!(map->keys[i] < key))
|
||||
count = step;
|
||||
else
|
||||
{
|
||||
pos = i+1;
|
||||
count -= step+1;
|
||||
}
|
||||
} while(count > 0);
|
||||
}
|
||||
|
||||
if(pos == map->size || map->keys[pos] != key)
|
||||
{
|
||||
if(map->size == map->capacity)
|
||||
if(mSize == mCapacity)
|
||||
{
|
||||
ALvoid **keys = NULL;
|
||||
ALint *values;
|
||||
ALsizei newcap;
|
||||
|
||||
newcap = (map->capacity ? (map->capacity<<1) : 4);
|
||||
if(newcap > map->capacity)
|
||||
keys = al_calloc(16, (sizeof(map->keys[0])+sizeof(map->values[0]))*newcap);
|
||||
if(!keys)
|
||||
{
|
||||
WriteUnlock(&map->lock);
|
||||
void **newkeys{nullptr};
|
||||
ALsizei newcap{mCapacity ? (mCapacity<<1) : 4};
|
||||
if(newcap > mCapacity)
|
||||
newkeys = static_cast<void**>(
|
||||
al_calloc(16, (sizeof(mKeys[0])+sizeof(mValues[0]))*newcap)
|
||||
);
|
||||
if(!newkeys)
|
||||
return AL_OUT_OF_MEMORY;
|
||||
}
|
||||
values = (ALint*)&keys[newcap];
|
||||
auto newvalues = reinterpret_cast<int*>(&newkeys[newcap]);
|
||||
|
||||
if(map->keys)
|
||||
if(mKeys)
|
||||
{
|
||||
memcpy(keys, map->keys, map->size*sizeof(map->keys[0]));
|
||||
memcpy(values, map->values, map->size*sizeof(map->values[0]));
|
||||
std::copy_n(mKeys, mSize, newkeys);
|
||||
std::copy_n(mValues, mSize, newvalues);
|
||||
}
|
||||
al_free(map->keys);
|
||||
map->keys = keys;
|
||||
map->values = values;
|
||||
map->capacity = newcap;
|
||||
al_free(mKeys);
|
||||
mKeys = newkeys;
|
||||
mValues = newvalues;
|
||||
mCapacity = newcap;
|
||||
}
|
||||
|
||||
if(pos < map->size)
|
||||
if(pos < mSize)
|
||||
{
|
||||
memmove(&map->keys[pos+1], &map->keys[pos],
|
||||
(map->size-pos)*sizeof(map->keys[0]));
|
||||
memmove(&map->values[pos+1], &map->values[pos],
|
||||
(map->size-pos)*sizeof(map->values[0]));
|
||||
std::copy_backward(mKeys+pos, mKeys+mSize, mKeys+mSize+1);
|
||||
std::copy_backward(mValues+pos, mValues+mSize, mValues+mSize+1);
|
||||
}
|
||||
map->size++;
|
||||
mSize++;
|
||||
}
|
||||
map->keys[pos] = key;
|
||||
map->values[pos] = value;
|
||||
WriteUnlock(&map->lock);
|
||||
mKeys[pos] = key;
|
||||
mValues[pos] = value;
|
||||
|
||||
return AL_NO_ERROR;
|
||||
}
|
||||
|
||||
ALint RemovePtrIntMapKey(PtrIntMap *map, ALvoid *key)
|
||||
int PtrIntMap::removeByKey(void *key)
|
||||
{
|
||||
ALint ret = -1;
|
||||
WriteLock(&map->lock);
|
||||
if(map->size > 0)
|
||||
int ret = -1;
|
||||
|
||||
std::lock_guard<std::mutex> maplock{mLock};
|
||||
auto iter = std::lower_bound(mKeys, mKeys+mSize, key);
|
||||
auto pos = static_cast<ALsizei>(std::distance(mKeys, iter));
|
||||
if(pos < mSize && mKeys[pos] == key)
|
||||
{
|
||||
ALsizei pos = 0;
|
||||
ALsizei count = map->size;
|
||||
do {
|
||||
ALsizei step = count>>1;
|
||||
ALsizei i = pos+step;
|
||||
if(!(map->keys[i] < key))
|
||||
count = step;
|
||||
else
|
||||
{
|
||||
pos = i+1;
|
||||
count -= step+1;
|
||||
}
|
||||
} while(count > 0);
|
||||
if(pos < map->size && map->keys[pos] == key)
|
||||
ret = mValues[pos];
|
||||
if(pos+1 < mSize)
|
||||
{
|
||||
ret = map->values[pos];
|
||||
if(pos < map->size-1)
|
||||
{
|
||||
memmove(&map->keys[pos], &map->keys[pos+1],
|
||||
(map->size-1-pos)*sizeof(map->keys[0]));
|
||||
memmove(&map->values[pos], &map->values[pos+1],
|
||||
(map->size-1-pos)*sizeof(map->values[0]));
|
||||
}
|
||||
map->size--;
|
||||
std::copy(mKeys+pos+1, mKeys+mSize, mKeys+pos);
|
||||
std::copy(mValues+pos+1, mValues+mSize, mValues+pos);
|
||||
}
|
||||
mSize--;
|
||||
}
|
||||
WriteUnlock(&map->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ALint LookupPtrIntMapKey(PtrIntMap *map, ALvoid *key)
|
||||
int PtrIntMap::lookupByKey(void *key)
|
||||
{
|
||||
ALint ret = -1;
|
||||
ReadLock(&map->lock);
|
||||
if(map->size > 0)
|
||||
{
|
||||
ALsizei pos = 0;
|
||||
ALsizei count = map->size;
|
||||
do {
|
||||
ALsizei step = count>>1;
|
||||
ALsizei i = pos+step;
|
||||
if(!(map->keys[i] < key))
|
||||
count = step;
|
||||
else
|
||||
{
|
||||
pos = i+1;
|
||||
count -= step+1;
|
||||
}
|
||||
} while(count > 0);
|
||||
if(pos < map->size && map->keys[pos] == key)
|
||||
ret = map->values[pos];
|
||||
}
|
||||
ReadUnlock(&map->lock);
|
||||
int ret = -1;
|
||||
|
||||
std::lock_guard<std::mutex> maplock{mLock};
|
||||
auto iter = std::lower_bound(mKeys, mKeys+mSize, key);
|
||||
auto pos = static_cast<ALsizei>(std::distance(mKeys, iter));
|
||||
if(pos < mSize && mKeys[pos] == key)
|
||||
ret = mValues[pos];
|
||||
|
||||
return ret;
|
||||
}
|
||||
+165
-136
@@ -7,160 +7,189 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
|
||||
#include "AL/alc.h"
|
||||
#include "AL/al.h"
|
||||
#include "AL/alext.h"
|
||||
#include "atomic.h"
|
||||
#include "rwlock.h"
|
||||
#include "threads.h"
|
||||
|
||||
|
||||
#ifndef UNUSED
|
||||
#if defined(__cplusplus)
|
||||
#define UNUSED(x)
|
||||
#elif defined(__GNUC__)
|
||||
#define UNUSED(x) UNUSED_##x __attribute__((unused))
|
||||
#elif defined(__LCLINT__)
|
||||
#define UNUSED(x) /*@unused@*/ x
|
||||
#else
|
||||
#define UNUSED(x) x
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MAKE_ALC_VER(major, minor) (((major)<<8) | (minor))
|
||||
|
||||
typedef struct DriverIface {
|
||||
WCHAR Name[32];
|
||||
HMODULE Module;
|
||||
int ALCVer;
|
||||
struct DriverIface {
|
||||
std::wstring Name;
|
||||
HMODULE Module{nullptr};
|
||||
int ALCVer{0};
|
||||
|
||||
LPALCCREATECONTEXT alcCreateContext;
|
||||
LPALCMAKECONTEXTCURRENT alcMakeContextCurrent;
|
||||
LPALCPROCESSCONTEXT alcProcessContext;
|
||||
LPALCSUSPENDCONTEXT alcSuspendContext;
|
||||
LPALCDESTROYCONTEXT alcDestroyContext;
|
||||
LPALCGETCURRENTCONTEXT alcGetCurrentContext;
|
||||
LPALCGETCONTEXTSDEVICE alcGetContextsDevice;
|
||||
LPALCOPENDEVICE alcOpenDevice;
|
||||
LPALCCLOSEDEVICE alcCloseDevice;
|
||||
LPALCGETERROR alcGetError;
|
||||
LPALCISEXTENSIONPRESENT alcIsExtensionPresent;
|
||||
LPALCGETPROCADDRESS alcGetProcAddress;
|
||||
LPALCGETENUMVALUE alcGetEnumValue;
|
||||
LPALCGETSTRING alcGetString;
|
||||
LPALCGETINTEGERV alcGetIntegerv;
|
||||
LPALCCAPTUREOPENDEVICE alcCaptureOpenDevice;
|
||||
LPALCCAPTURECLOSEDEVICE alcCaptureCloseDevice;
|
||||
LPALCCAPTURESTART alcCaptureStart;
|
||||
LPALCCAPTURESTOP alcCaptureStop;
|
||||
LPALCCAPTURESAMPLES alcCaptureSamples;
|
||||
LPALCCREATECONTEXT alcCreateContext{nullptr};
|
||||
LPALCMAKECONTEXTCURRENT alcMakeContextCurrent{nullptr};
|
||||
LPALCPROCESSCONTEXT alcProcessContext{nullptr};
|
||||
LPALCSUSPENDCONTEXT alcSuspendContext{nullptr};
|
||||
LPALCDESTROYCONTEXT alcDestroyContext{nullptr};
|
||||
LPALCGETCURRENTCONTEXT alcGetCurrentContext{nullptr};
|
||||
LPALCGETCONTEXTSDEVICE alcGetContextsDevice{nullptr};
|
||||
LPALCOPENDEVICE alcOpenDevice{nullptr};
|
||||
LPALCCLOSEDEVICE alcCloseDevice{nullptr};
|
||||
LPALCGETERROR alcGetError{nullptr};
|
||||
LPALCISEXTENSIONPRESENT alcIsExtensionPresent{nullptr};
|
||||
LPALCGETPROCADDRESS alcGetProcAddress{nullptr};
|
||||
LPALCGETENUMVALUE alcGetEnumValue{nullptr};
|
||||
LPALCGETSTRING alcGetString{nullptr};
|
||||
LPALCGETINTEGERV alcGetIntegerv{nullptr};
|
||||
LPALCCAPTUREOPENDEVICE alcCaptureOpenDevice{nullptr};
|
||||
LPALCCAPTURECLOSEDEVICE alcCaptureCloseDevice{nullptr};
|
||||
LPALCCAPTURESTART alcCaptureStart{nullptr};
|
||||
LPALCCAPTURESTOP alcCaptureStop{nullptr};
|
||||
LPALCCAPTURESAMPLES alcCaptureSamples{nullptr};
|
||||
|
||||
PFNALCSETTHREADCONTEXTPROC alcSetThreadContext;
|
||||
PFNALCGETTHREADCONTEXTPROC alcGetThreadContext;
|
||||
PFNALCSETTHREADCONTEXTPROC alcSetThreadContext{nullptr};
|
||||
PFNALCGETTHREADCONTEXTPROC alcGetThreadContext{nullptr};
|
||||
|
||||
LPALENABLE alEnable;
|
||||
LPALDISABLE alDisable;
|
||||
LPALISENABLED alIsEnabled;
|
||||
LPALGETSTRING alGetString;
|
||||
LPALGETBOOLEANV alGetBooleanv;
|
||||
LPALGETINTEGERV alGetIntegerv;
|
||||
LPALGETFLOATV alGetFloatv;
|
||||
LPALGETDOUBLEV alGetDoublev;
|
||||
LPALGETBOOLEAN alGetBoolean;
|
||||
LPALGETINTEGER alGetInteger;
|
||||
LPALGETFLOAT alGetFloat;
|
||||
LPALGETDOUBLE alGetDouble;
|
||||
LPALGETERROR alGetError;
|
||||
LPALISEXTENSIONPRESENT alIsExtensionPresent;
|
||||
LPALGETPROCADDRESS alGetProcAddress;
|
||||
LPALGETENUMVALUE alGetEnumValue;
|
||||
LPALLISTENERF alListenerf;
|
||||
LPALLISTENER3F alListener3f;
|
||||
LPALLISTENERFV alListenerfv;
|
||||
LPALLISTENERI alListeneri;
|
||||
LPALLISTENER3I alListener3i;
|
||||
LPALLISTENERIV alListeneriv;
|
||||
LPALGETLISTENERF alGetListenerf;
|
||||
LPALGETLISTENER3F alGetListener3f;
|
||||
LPALGETLISTENERFV alGetListenerfv;
|
||||
LPALGETLISTENERI alGetListeneri;
|
||||
LPALGETLISTENER3I alGetListener3i;
|
||||
LPALGETLISTENERIV alGetListeneriv;
|
||||
LPALGENSOURCES alGenSources;
|
||||
LPALDELETESOURCES alDeleteSources;
|
||||
LPALISSOURCE alIsSource;
|
||||
LPALSOURCEF alSourcef;
|
||||
LPALSOURCE3F alSource3f;
|
||||
LPALSOURCEFV alSourcefv;
|
||||
LPALSOURCEI alSourcei;
|
||||
LPALSOURCE3I alSource3i;
|
||||
LPALSOURCEIV alSourceiv;
|
||||
LPALGETSOURCEF alGetSourcef;
|
||||
LPALGETSOURCE3F alGetSource3f;
|
||||
LPALGETSOURCEFV alGetSourcefv;
|
||||
LPALGETSOURCEI alGetSourcei;
|
||||
LPALGETSOURCE3I alGetSource3i;
|
||||
LPALGETSOURCEIV alGetSourceiv;
|
||||
LPALSOURCEPLAYV alSourcePlayv;
|
||||
LPALSOURCESTOPV alSourceStopv;
|
||||
LPALSOURCEREWINDV alSourceRewindv;
|
||||
LPALSOURCEPAUSEV alSourcePausev;
|
||||
LPALSOURCEPLAY alSourcePlay;
|
||||
LPALSOURCESTOP alSourceStop;
|
||||
LPALSOURCEREWIND alSourceRewind;
|
||||
LPALSOURCEPAUSE alSourcePause;
|
||||
LPALSOURCEQUEUEBUFFERS alSourceQueueBuffers;
|
||||
LPALSOURCEUNQUEUEBUFFERS alSourceUnqueueBuffers;
|
||||
LPALGENBUFFERS alGenBuffers;
|
||||
LPALDELETEBUFFERS alDeleteBuffers;
|
||||
LPALISBUFFER alIsBuffer;
|
||||
LPALBUFFERF alBufferf;
|
||||
LPALBUFFER3F alBuffer3f;
|
||||
LPALBUFFERFV alBufferfv;
|
||||
LPALBUFFERI alBufferi;
|
||||
LPALBUFFER3I alBuffer3i;
|
||||
LPALBUFFERIV alBufferiv;
|
||||
LPALGETBUFFERF alGetBufferf;
|
||||
LPALGETBUFFER3F alGetBuffer3f;
|
||||
LPALGETBUFFERFV alGetBufferfv;
|
||||
LPALGETBUFFERI alGetBufferi;
|
||||
LPALGETBUFFER3I alGetBuffer3i;
|
||||
LPALGETBUFFERIV alGetBufferiv;
|
||||
LPALBUFFERDATA alBufferData;
|
||||
LPALDOPPLERFACTOR alDopplerFactor;
|
||||
LPALDOPPLERVELOCITY alDopplerVelocity;
|
||||
LPALSPEEDOFSOUND alSpeedOfSound;
|
||||
LPALDISTANCEMODEL alDistanceModel;
|
||||
} DriverIface;
|
||||
LPALENABLE alEnable{nullptr};
|
||||
LPALDISABLE alDisable{nullptr};
|
||||
LPALISENABLED alIsEnabled{nullptr};
|
||||
LPALGETSTRING alGetString{nullptr};
|
||||
LPALGETBOOLEANV alGetBooleanv{nullptr};
|
||||
LPALGETINTEGERV alGetIntegerv{nullptr};
|
||||
LPALGETFLOATV alGetFloatv{nullptr};
|
||||
LPALGETDOUBLEV alGetDoublev{nullptr};
|
||||
LPALGETBOOLEAN alGetBoolean{nullptr};
|
||||
LPALGETINTEGER alGetInteger{nullptr};
|
||||
LPALGETFLOAT alGetFloat{nullptr};
|
||||
LPALGETDOUBLE alGetDouble{nullptr};
|
||||
LPALGETERROR alGetError{nullptr};
|
||||
LPALISEXTENSIONPRESENT alIsExtensionPresent{nullptr};
|
||||
LPALGETPROCADDRESS alGetProcAddress{nullptr};
|
||||
LPALGETENUMVALUE alGetEnumValue{nullptr};
|
||||
LPALLISTENERF alListenerf{nullptr};
|
||||
LPALLISTENER3F alListener3f{nullptr};
|
||||
LPALLISTENERFV alListenerfv{nullptr};
|
||||
LPALLISTENERI alListeneri{nullptr};
|
||||
LPALLISTENER3I alListener3i{nullptr};
|
||||
LPALLISTENERIV alListeneriv{nullptr};
|
||||
LPALGETLISTENERF alGetListenerf{nullptr};
|
||||
LPALGETLISTENER3F alGetListener3f{nullptr};
|
||||
LPALGETLISTENERFV alGetListenerfv{nullptr};
|
||||
LPALGETLISTENERI alGetListeneri{nullptr};
|
||||
LPALGETLISTENER3I alGetListener3i{nullptr};
|
||||
LPALGETLISTENERIV alGetListeneriv{nullptr};
|
||||
LPALGENSOURCES alGenSources{nullptr};
|
||||
LPALDELETESOURCES alDeleteSources{nullptr};
|
||||
LPALISSOURCE alIsSource{nullptr};
|
||||
LPALSOURCEF alSourcef{nullptr};
|
||||
LPALSOURCE3F alSource3f{nullptr};
|
||||
LPALSOURCEFV alSourcefv{nullptr};
|
||||
LPALSOURCEI alSourcei{nullptr};
|
||||
LPALSOURCE3I alSource3i{nullptr};
|
||||
LPALSOURCEIV alSourceiv{nullptr};
|
||||
LPALGETSOURCEF alGetSourcef{nullptr};
|
||||
LPALGETSOURCE3F alGetSource3f{nullptr};
|
||||
LPALGETSOURCEFV alGetSourcefv{nullptr};
|
||||
LPALGETSOURCEI alGetSourcei{nullptr};
|
||||
LPALGETSOURCE3I alGetSource3i{nullptr};
|
||||
LPALGETSOURCEIV alGetSourceiv{nullptr};
|
||||
LPALSOURCEPLAYV alSourcePlayv{nullptr};
|
||||
LPALSOURCESTOPV alSourceStopv{nullptr};
|
||||
LPALSOURCEREWINDV alSourceRewindv{nullptr};
|
||||
LPALSOURCEPAUSEV alSourcePausev{nullptr};
|
||||
LPALSOURCEPLAY alSourcePlay{nullptr};
|
||||
LPALSOURCESTOP alSourceStop{nullptr};
|
||||
LPALSOURCEREWIND alSourceRewind{nullptr};
|
||||
LPALSOURCEPAUSE alSourcePause{nullptr};
|
||||
LPALSOURCEQUEUEBUFFERS alSourceQueueBuffers{nullptr};
|
||||
LPALSOURCEUNQUEUEBUFFERS alSourceUnqueueBuffers{nullptr};
|
||||
LPALGENBUFFERS alGenBuffers{nullptr};
|
||||
LPALDELETEBUFFERS alDeleteBuffers{nullptr};
|
||||
LPALISBUFFER alIsBuffer{nullptr};
|
||||
LPALBUFFERF alBufferf{nullptr};
|
||||
LPALBUFFER3F alBuffer3f{nullptr};
|
||||
LPALBUFFERFV alBufferfv{nullptr};
|
||||
LPALBUFFERI alBufferi{nullptr};
|
||||
LPALBUFFER3I alBuffer3i{nullptr};
|
||||
LPALBUFFERIV alBufferiv{nullptr};
|
||||
LPALGETBUFFERF alGetBufferf{nullptr};
|
||||
LPALGETBUFFER3F alGetBuffer3f{nullptr};
|
||||
LPALGETBUFFERFV alGetBufferfv{nullptr};
|
||||
LPALGETBUFFERI alGetBufferi{nullptr};
|
||||
LPALGETBUFFER3I alGetBuffer3i{nullptr};
|
||||
LPALGETBUFFERIV alGetBufferiv{nullptr};
|
||||
LPALBUFFERDATA alBufferData{nullptr};
|
||||
LPALDOPPLERFACTOR alDopplerFactor{nullptr};
|
||||
LPALDOPPLERVELOCITY alDopplerVelocity{nullptr};
|
||||
LPALSPEEDOFSOUND alSpeedOfSound{nullptr};
|
||||
LPALDISTANCEMODEL alDistanceModel{nullptr};
|
||||
|
||||
extern DriverIface *DriverList;
|
||||
extern int DriverListSize;
|
||||
LPALGENFILTERS alGenFilters{nullptr};
|
||||
LPALDELETEFILTERS alDeleteFilters{nullptr};
|
||||
LPALISFILTER alIsFilter{nullptr};
|
||||
LPALFILTERF alFilterf{nullptr};
|
||||
LPALFILTERFV alFilterfv{nullptr};
|
||||
LPALFILTERI alFilteri{nullptr};
|
||||
LPALFILTERIV alFilteriv{nullptr};
|
||||
LPALGETFILTERF alGetFilterf{nullptr};
|
||||
LPALGETFILTERFV alGetFilterfv{nullptr};
|
||||
LPALGETFILTERI alGetFilteri{nullptr};
|
||||
LPALGETFILTERIV alGetFilteriv{nullptr};
|
||||
LPALGENEFFECTS alGenEffects{nullptr};
|
||||
LPALDELETEEFFECTS alDeleteEffects{nullptr};
|
||||
LPALISEFFECT alIsEffect{nullptr};
|
||||
LPALEFFECTF alEffectf{nullptr};
|
||||
LPALEFFECTFV alEffectfv{nullptr};
|
||||
LPALEFFECTI alEffecti{nullptr};
|
||||
LPALEFFECTIV alEffectiv{nullptr};
|
||||
LPALGETEFFECTF alGetEffectf{nullptr};
|
||||
LPALGETEFFECTFV alGetEffectfv{nullptr};
|
||||
LPALGETEFFECTI alGetEffecti{nullptr};
|
||||
LPALGETEFFECTIV alGetEffectiv{nullptr};
|
||||
LPALGENAUXILIARYEFFECTSLOTS alGenAuxiliaryEffectSlots{nullptr};
|
||||
LPALDELETEAUXILIARYEFFECTSLOTS alDeleteAuxiliaryEffectSlots{nullptr};
|
||||
LPALISAUXILIARYEFFECTSLOT alIsAuxiliaryEffectSlot{nullptr};
|
||||
LPALAUXILIARYEFFECTSLOTF alAuxiliaryEffectSlotf{nullptr};
|
||||
LPALAUXILIARYEFFECTSLOTFV alAuxiliaryEffectSlotfv{nullptr};
|
||||
LPALAUXILIARYEFFECTSLOTI alAuxiliaryEffectSloti{nullptr};
|
||||
LPALAUXILIARYEFFECTSLOTIV alAuxiliaryEffectSlotiv{nullptr};
|
||||
LPALGETAUXILIARYEFFECTSLOTF alGetAuxiliaryEffectSlotf{nullptr};
|
||||
LPALGETAUXILIARYEFFECTSLOTFV alGetAuxiliaryEffectSlotfv{nullptr};
|
||||
LPALGETAUXILIARYEFFECTSLOTI alGetAuxiliaryEffectSloti{nullptr};
|
||||
LPALGETAUXILIARYEFFECTSLOTIV alGetAuxiliaryEffectSlotiv{nullptr};
|
||||
|
||||
extern altss_t ThreadCtxDriver;
|
||||
typedef ATOMIC(DriverIface*) atomic_DriverIfacePtr;
|
||||
extern atomic_DriverIfacePtr CurrentCtxDriver;
|
||||
DriverIface(std::wstring name, HMODULE mod)
|
||||
: Name(std::move(name)), Module(mod)
|
||||
{ }
|
||||
~DriverIface()
|
||||
{
|
||||
if(Module)
|
||||
FreeLibrary(Module);
|
||||
Module = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
extern std::vector<DriverIface> DriverList;
|
||||
|
||||
extern thread_local DriverIface *ThreadCtxDriver;
|
||||
extern std::atomic<DriverIface*> CurrentCtxDriver;
|
||||
|
||||
|
||||
typedef struct PtrIntMap {
|
||||
ALvoid **keys;
|
||||
class PtrIntMap {
|
||||
void **mKeys{nullptr};
|
||||
/* Shares memory with keys. */
|
||||
ALint *values;
|
||||
int *mValues{nullptr};
|
||||
|
||||
ALsizei size;
|
||||
ALsizei capacity;
|
||||
RWLock lock;
|
||||
} PtrIntMap;
|
||||
#define PTRINTMAP_STATIC_INITIALIZE { NULL, NULL, 0, 0, RWLOCK_STATIC_INITIALIZE }
|
||||
ALsizei mSize{0};
|
||||
ALsizei mCapacity{0};
|
||||
std::mutex mLock;
|
||||
|
||||
void InitPtrIntMap(PtrIntMap *map);
|
||||
void ResetPtrIntMap(PtrIntMap *map);
|
||||
ALenum InsertPtrIntMapEntry(PtrIntMap *map, ALvoid *key, ALint value);
|
||||
ALint RemovePtrIntMapKey(PtrIntMap *map, ALvoid *key);
|
||||
ALint LookupPtrIntMapKey(PtrIntMap *map, ALvoid *key);
|
||||
public:
|
||||
PtrIntMap() = default;
|
||||
~PtrIntMap();
|
||||
|
||||
|
||||
void InitALC(void);
|
||||
void ReleaseALC(void);
|
||||
ALenum insert(void *key, int value);
|
||||
int removeByKey(void *key);
|
||||
int lookupByKey(void *key);
|
||||
};
|
||||
|
||||
|
||||
enum LogLevel {
|
||||
|
||||
Reference in New Issue
Block a user