From afb59e7f98f40cde77c150414a8a5bd13f40781a Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 14 Apr 2017 18:15:56 -0700 Subject: Move internal headers out of the include directory --- common/uintmap.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 common/uintmap.h (limited to 'common/uintmap.h') diff --git a/common/uintmap.h b/common/uintmap.h new file mode 100644 index 00000000..f70d99fd --- /dev/null +++ b/common/uintmap.h @@ -0,0 +1,46 @@ +#ifndef AL_UINTMAP_H +#define AL_UINTMAP_H + +#include "AL/al.h" +#include "rwlock.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct UIntMap { + ALuint *keys; + /* Shares memory with keys. */ + ALvoid **values; + + ALsizei size; + ALsizei capacity; + ALsizei limit; + RWLock lock; +} UIntMap; +#define UINTMAP_STATIC_INITIALIZE_N(_n) { NULL, NULL, 0, 0, (_n), RWLOCK_STATIC_INITIALIZE } +#define UINTMAP_STATIC_INITIALIZE UINTMAP_STATIC_INITIALIZE_N(~0) + +void InitUIntMap(UIntMap *map, ALsizei limit); +void ResetUIntMap(UIntMap *map); +ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value); +ALenum InsertUIntMapEntryNoLock(UIntMap *map, ALuint key, ALvoid *value); +ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key); +ALvoid *RemoveUIntMapKeyNoLock(UIntMap *map, ALuint key); +ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key); +ALvoid *LookupUIntMapKeyNoLock(UIntMap *map, ALuint key); + +inline void LockUIntMapRead(UIntMap *map) +{ ReadLock(&map->lock); } +inline void UnlockUIntMapRead(UIntMap *map) +{ ReadUnlock(&map->lock); } +inline void LockUIntMapWrite(UIntMap *map) +{ WriteLock(&map->lock); } +inline void UnlockUIntMapWrite(UIntMap *map) +{ WriteUnlock(&map->lock); } + +#ifdef __cplusplus +} +#endif + +#endif /* AL_UINTMAP_H */ -- cgit v1.2.3 From d9bf4f7620c1e13846a53ee9df5c8c9eb2fcfe7d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 14 Apr 2017 22:56:54 -0700 Subject: Allow increasing the maximum source limit If the requested number of mono and stereo sources exceeds 256, the source limit will be expanded. Any config file setting overrides this. If the device is reset to have fewer sources than are currently allocated, excess sources will remain and be usable as normal, but no more can be generated until enough are delated to go back below the limit. --- Alc/ALc.c | 74 ++++++++++++++++++++++++++++++++++++---------- OpenAL32/alAuxEffectSlot.c | 2 +- common/uintmap.c | 9 ++++-- common/uintmap.h | 3 +- 4 files changed, 69 insertions(+), 19 deletions(-) (limited to 'common/uintmap.h') diff --git a/Alc/ALc.c b/Alc/ALc.c index cc9aa5c3..2d0d64f5 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -1834,13 +1834,18 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) return ALC_INVALID_VALUE; } + if(attrList[attrIdx] == ALC_MONO_SOURCES) + { + numMono = attrList[attrIdx + 1]; + TRACE_ATTR(ALC_MONO_SOURCES, numMono); + numMono = maxi(numMono, 0); + } + if(attrList[attrIdx] == ALC_STEREO_SOURCES) { numStereo = attrList[attrIdx + 1]; TRACE_ATTR(ALC_STEREO_SOURCES, numStereo); - - numStereo = clampi(numStereo, 0, device->SourcesMax); - numMono = device->SourcesMax - numStereo; + numStereo = maxi(numStereo, 0); } if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS) @@ -1898,6 +1903,21 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) device->AmbiLayout = alayout; device->AmbiScale = ascale; } + + if(numMono > INT_MAX-numStereo) + numMono = INT_MAX-numStereo; + numMono += numStereo; + if(ConfigValueInt(NULL, NULL, "sources", &numMono)) + { + if(numMono <= 0) + numMono = 256; + } + else + numMono = maxi(numMono, 256); + numStereo = mini(numStereo, numMono); + numMono -= numStereo; + device->SourcesMax = numMono + numStereo; + device->NumMonoSources = numMono; device->NumStereoSources = numStereo; @@ -1935,13 +1955,18 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) device->Flags |= DEVICE_FREQUENCY_REQUEST; } + if(attrList[attrIdx] == ALC_MONO_SOURCES) + { + numMono = attrList[attrIdx + 1]; + TRACE_ATTR(ALC_MONO_SOURCES, numMono); + numMono = maxi(numMono, 0); + } + if(attrList[attrIdx] == ALC_STEREO_SOURCES) { numStereo = attrList[attrIdx + 1]; TRACE_ATTR(ALC_STEREO_SOURCES, numStereo); - - numStereo = clampi(numStereo, 0, device->SourcesMax); - numMono = device->SourcesMax - numStereo; + numStereo = maxi(numStereo, 0); } if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS) @@ -1982,6 +2007,21 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) device->UpdateSize = (device->UpdateSize+3)&~3; device->Frequency = freq; + + if(numMono > INT_MAX-numStereo) + numMono = INT_MAX-numStereo; + numMono += numStereo; + if(ConfigValueInt(alstr_get_cstr(device->DeviceName), NULL, "sources", &numMono)) + { + if(numMono <= 0) + numMono = 256; + } + else + numMono = maxi(numMono, 256); + numStereo = mini(numStereo, numMono); + numMono -= numStereo; + device->SourcesMax = numMono + numStereo; + device->NumMonoSources = numMono; device->NumStereoSources = numStereo; @@ -2150,6 +2190,9 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) * allocated with the appropriate size. */ device->NumAuxSends = new_sends; + TRACE("Max sources: %d (%d + %d), effect slots: %d, sends: %d\n", + device->SourcesMax, device->NumMonoSources, device->NumStereoSources, + device->AuxiliaryEffectSlotMax, device->NumAuxSends); update_failed = AL_FALSE; SetMixerFPUMode(&oldMode); if(device->DefaultSlot) @@ -2187,6 +2230,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) UnlockUIntMapRead(&context->EffectSlotMap); LockUIntMapRead(&context->SourceMap); + RelimitUIntMapNoLock(&context->SourceMap, device->SourcesMax); for(pos = 0;pos < context->SourceMap.size;pos++) { ALsource *source = context->SourceMap.values[pos]; @@ -3751,9 +3795,9 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) device->AuxiliaryEffectSlotMax = 64; device->NumAuxSends = DEFAULT_SENDS; - InitUIntMap(&device->BufferMap, ~0); - InitUIntMap(&device->EffectMap, ~0); - InitUIntMap(&device->FilterMap, ~0); + InitUIntMap(&device->BufferMap, INT_MAX); + InitUIntMap(&device->EffectMap, INT_MAX); + InitUIntMap(&device->FilterMap, INT_MAX); for(i = 0;i < MAX_OUTPUT_CHANNELS;i++) { @@ -4051,9 +4095,9 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, device->RealOut.Buffer = NULL; device->RealOut.NumChannels = 0; - InitUIntMap(&device->BufferMap, ~0); - InitUIntMap(&device->EffectMap, ~0); - InitUIntMap(&device->FilterMap, ~0); + InitUIntMap(&device->BufferMap, INT_MAX); + InitUIntMap(&device->EffectMap, INT_MAX); + InitUIntMap(&device->FilterMap, INT_MAX); for(i = 0;i < MAX_OUTPUT_CHANNELS;i++) { @@ -4279,9 +4323,9 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN device->AuxiliaryEffectSlotMax = 64; device->NumAuxSends = DEFAULT_SENDS; - InitUIntMap(&device->BufferMap, ~0); - InitUIntMap(&device->EffectMap, ~0); - InitUIntMap(&device->FilterMap, ~0); + InitUIntMap(&device->BufferMap, INT_MAX); + InitUIntMap(&device->EffectMap, INT_MAX); + InitUIntMap(&device->FilterMap, INT_MAX); for(i = 0;i < MAX_OUTPUT_CHANNELS;i++) { diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c index de7de943..3ec857ca 100644 --- a/OpenAL32/alAuxEffectSlot.c +++ b/OpenAL32/alAuxEffectSlot.c @@ -479,7 +479,7 @@ done: void InitEffectFactoryMap(void) { - InitUIntMap(&EffectStateFactoryMap, ~0); + InitUIntMap(&EffectStateFactoryMap, INT_MAX); InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_NULL, ALnullStateFactory_getFactory); InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_EAXREVERB, ALreverbStateFactory_getFactory); diff --git a/common/uintmap.c b/common/uintmap.c index 21a921b2..98ed3191 100644 --- a/common/uintmap.c +++ b/common/uintmap.c @@ -36,6 +36,11 @@ void ResetUIntMap(UIntMap *map) WriteUnlock(&map->lock); } +void RelimitUIntMapNoLock(UIntMap *map, ALsizei limit) +{ + map->limit = limit; +} + ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value) { ALsizei pos = 0; @@ -59,7 +64,7 @@ ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value) if(pos == map->size || map->keys[pos] != key) { - if(map->size == map->limit) + if(map->size >= map->limit) { WriteUnlock(&map->lock); return AL_OUT_OF_MEMORY; @@ -141,7 +146,7 @@ ALenum InsertUIntMapEntryNoLock(UIntMap *map, ALuint key, ALvoid *value) if(pos == map->size || map->keys[pos] != key) { - if(map->size == map->limit) + if(map->size >= map->limit) return AL_OUT_OF_MEMORY; if(map->size == map->capacity) diff --git a/common/uintmap.h b/common/uintmap.h index f70d99fd..47bd0d42 100644 --- a/common/uintmap.h +++ b/common/uintmap.h @@ -19,10 +19,11 @@ typedef struct UIntMap { RWLock lock; } UIntMap; #define UINTMAP_STATIC_INITIALIZE_N(_n) { NULL, NULL, 0, 0, (_n), RWLOCK_STATIC_INITIALIZE } -#define UINTMAP_STATIC_INITIALIZE UINTMAP_STATIC_INITIALIZE_N(~0) +#define UINTMAP_STATIC_INITIALIZE UINTMAP_STATIC_INITIALIZE_N(INT_MAX) void InitUIntMap(UIntMap *map, ALsizei limit); void ResetUIntMap(UIntMap *map); +void RelimitUIntMapNoLock(UIntMap *map, ALsizei limit); ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value); ALenum InsertUIntMapEntryNoLock(UIntMap *map, ALuint key, ALvoid *value); ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key); -- cgit v1.2.3 From e3d99412a20f5476cbf700855a934bf724b13a07 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 30 Aug 2017 12:01:49 -0700 Subject: Include limits.h where INT_MAX is used --- common/uintmap.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'common/uintmap.h') diff --git a/common/uintmap.h b/common/uintmap.h index 47bd0d42..3adc66c4 100644 --- a/common/uintmap.h +++ b/common/uintmap.h @@ -1,6 +1,8 @@ #ifndef AL_UINTMAP_H #define AL_UINTMAP_H +#include + #include "AL/al.h" #include "rwlock.h" -- cgit v1.2.3 From 4d1795e90b83f040aa59cf69616a4ff2b32bf71a Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 27 Jan 2018 15:06:20 -0800 Subject: Remove an unused function --- common/uintmap.c | 5 ----- common/uintmap.h | 1 - 2 files changed, 6 deletions(-) (limited to 'common/uintmap.h') diff --git a/common/uintmap.c b/common/uintmap.c index 98ed3191..be628a5f 100644 --- a/common/uintmap.c +++ b/common/uintmap.c @@ -36,11 +36,6 @@ void ResetUIntMap(UIntMap *map) WriteUnlock(&map->lock); } -void RelimitUIntMapNoLock(UIntMap *map, ALsizei limit) -{ - map->limit = limit; -} - ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value) { ALsizei pos = 0; diff --git a/common/uintmap.h b/common/uintmap.h index 3adc66c4..32cd1eaa 100644 --- a/common/uintmap.h +++ b/common/uintmap.h @@ -25,7 +25,6 @@ typedef struct UIntMap { void InitUIntMap(UIntMap *map, ALsizei limit); void ResetUIntMap(UIntMap *map); -void RelimitUIntMapNoLock(UIntMap *map, ALsizei limit); ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value); ALenum InsertUIntMapEntryNoLock(UIntMap *map, ALuint key, ALvoid *value); ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key); -- cgit v1.2.3 From d1da9f1f679e94b3aa05c9d9d981c63e145399a5 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 28 Jan 2018 00:53:21 -0800 Subject: Remove some now-unused NoLock function variants --- common/uintmap.c | 132 ------------------------------------------------------- common/uintmap.h | 17 +++---- 2 files changed, 5 insertions(+), 144 deletions(-) (limited to 'common/uintmap.h') diff --git a/common/uintmap.c b/common/uintmap.c index be628a5f..18d52d64 100644 --- a/common/uintmap.c +++ b/common/uintmap.c @@ -119,81 +119,6 @@ ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value) return AL_NO_ERROR; } -ALenum InsertUIntMapEntryNoLock(UIntMap *map, ALuint key, ALvoid *value) -{ - ALsizei pos = 0; - - if(map->size > 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) - { - if(map->size >= map->limit) - return AL_OUT_OF_MEMORY; - - if(map->size == map->capacity) - { - ALuint *keys = NULL; - ALvoid **values; - ALsizei newcap, keylen; - - newcap = (map->capacity ? (map->capacity<<1) : 4); - if(map->limit > 0 && newcap > map->limit) - newcap = map->limit; - if(newcap > map->capacity) - { - /* Round the memory size for keys up to a multiple of the - * pointer size. - */ - keylen = newcap * sizeof(map->keys[0]); - keylen += sizeof(map->values[0]) - 1; - keylen -= keylen%sizeof(map->values[0]); - - keys = al_malloc(16, keylen + newcap*sizeof(map->values[0])); - } - if(!keys) - return AL_OUT_OF_MEMORY; - values = (ALvoid**)((ALbyte*)keys + keylen); - - if(map->keys) - { - memcpy(keys, map->keys, map->size*sizeof(map->keys[0])); - memcpy(values, map->values, map->size*sizeof(map->values[0])); - } - al_free(map->keys); - map->keys = keys; - map->values = values; - map->capacity = newcap; - } - - if(pos < map->size) - { - 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])); - } - map->size++; - } - map->keys[pos] = key; - map->values[pos] = value; - - return AL_NO_ERROR; -} - ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key) { ALvoid *ptr = NULL; @@ -230,40 +155,6 @@ ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key) return ptr; } -ALvoid *RemoveUIntMapKeyNoLock(UIntMap *map, ALuint key) -{ - ALvoid *ptr = NULL; - 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) - { - ptr = 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--; - } - } - return ptr; -} - ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key) { ALvoid *ptr = NULL; @@ -289,26 +180,3 @@ ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key) ReadUnlock(&map->lock); return ptr; } - -ALvoid *LookupUIntMapKeyNoLock(UIntMap *map, ALuint key) -{ - 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) - return map->values[pos]; - } - return NULL; -} diff --git a/common/uintmap.h b/common/uintmap.h index 32cd1eaa..32868653 100644 --- a/common/uintmap.h +++ b/common/uintmap.h @@ -26,20 +26,13 @@ typedef struct UIntMap { void InitUIntMap(UIntMap *map, ALsizei limit); void ResetUIntMap(UIntMap *map); ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value); -ALenum InsertUIntMapEntryNoLock(UIntMap *map, ALuint key, ALvoid *value); ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key); -ALvoid *RemoveUIntMapKeyNoLock(UIntMap *map, ALuint key); ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key); -ALvoid *LookupUIntMapKeyNoLock(UIntMap *map, ALuint key); - -inline void LockUIntMapRead(UIntMap *map) -{ ReadLock(&map->lock); } -inline void UnlockUIntMapRead(UIntMap *map) -{ ReadUnlock(&map->lock); } -inline void LockUIntMapWrite(UIntMap *map) -{ WriteLock(&map->lock); } -inline void UnlockUIntMapWrite(UIntMap *map) -{ WriteUnlock(&map->lock); } + +inline void LockUIntMapRead(UIntMap *map) { ReadLock(&map->lock); } +inline void UnlockUIntMapRead(UIntMap *map) { ReadUnlock(&map->lock); } +inline void LockUIntMapWrite(UIntMap *map) { WriteLock(&map->lock); } +inline void UnlockUIntMapWrite(UIntMap *map) { WriteUnlock(&map->lock); } #ifdef __cplusplus } -- cgit v1.2.3