Use a UIntMap for the Databuffers
This commit is contained in:
parent
90db244b5f
commit
43dadcd9e4
@ -1962,6 +1962,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
|
|||||||
InitUIntMap(&device->BufferMap);
|
InitUIntMap(&device->BufferMap);
|
||||||
InitUIntMap(&device->EffectMap);
|
InitUIntMap(&device->EffectMap);
|
||||||
InitUIntMap(&device->FilterMap);
|
InitUIntMap(&device->FilterMap);
|
||||||
|
InitUIntMap(&device->DatabufferMap);
|
||||||
|
|
||||||
//Set output format
|
//Set output format
|
||||||
device->Frequency = GetConfigValueInt(NULL, "frequency", SWMIXER_OUTPUT_RATE);
|
device->Frequency = GetConfigValueInt(NULL, "frequency", SWMIXER_OUTPUT_RATE);
|
||||||
@ -2093,13 +2094,14 @@ ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *pDevice)
|
|||||||
}
|
}
|
||||||
ResetUIntMap(&pDevice->FilterMap);
|
ResetUIntMap(&pDevice->FilterMap);
|
||||||
|
|
||||||
if(pDevice->DatabufferCount > 0)
|
if(pDevice->DatabufferMap.size > 0)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
AL_PRINT("alcCloseDevice(): deleting %d Databuffer(s)\n", pDevice->DatabufferCount);
|
AL_PRINT("alcCloseDevice(): deleting %d Databuffer(s)\n", pDevice->DatabufferMap.size);
|
||||||
#endif
|
#endif
|
||||||
ReleaseALDatabuffers(pDevice);
|
ReleaseALDatabuffers(pDevice);
|
||||||
}
|
}
|
||||||
|
ResetUIntMap(&pDevice->DatabufferMap);
|
||||||
|
|
||||||
free(pDevice->Bs2b);
|
free(pDevice->Bs2b);
|
||||||
pDevice->Bs2b = NULL;
|
pDevice->Bs2b = NULL;
|
||||||
|
@ -367,9 +367,8 @@ struct ALCdevice_struct
|
|||||||
// Map of Filters for this device
|
// Map of Filters for this device
|
||||||
UIntMap FilterMap;
|
UIntMap FilterMap;
|
||||||
|
|
||||||
// Linked List of Databuffers for this device
|
// Map of Databuffers for this device
|
||||||
struct ALdatabuffer *DatabufferList;
|
UIntMap DatabufferMap;
|
||||||
ALuint DatabufferCount;
|
|
||||||
|
|
||||||
// Stereo-to-binaural filter
|
// Stereo-to-binaural filter
|
||||||
struct bs2b *Bs2b;
|
struct bs2b *Bs2b;
|
||||||
@ -480,14 +479,6 @@ void al_print(const char *fname, unsigned int line, const char *fmt, ...)
|
|||||||
PRINTF_STYLE(3,4);
|
PRINTF_STYLE(3,4);
|
||||||
#define AL_PRINT(...) al_print(__FILE__, __LINE__, __VA_ARGS__)
|
#define AL_PRINT(...) al_print(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
|
||||||
#define DECL_VERIFIER(name, type, field) \
|
|
||||||
static type* Verify##name(type *list, ALuint id) \
|
|
||||||
{ \
|
|
||||||
while(list && list->field != id) \
|
|
||||||
list = list->next; \
|
|
||||||
return list; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
#include "alThunk.h"
|
#include "alThunk.h"
|
||||||
|
|
||||||
|
|
||||||
DECL_VERIFIER(Databuffer, ALdatabuffer, databuffer)
|
#define LookupDatabuffer(m, k) ((ALdatabuffer*)LookupUIntMapKey(&(m), (k)))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* alGenDatabuffersEXT(ALsizei n, ALuint *puiBuffers)
|
* alGenDatabuffersEXT(ALsizei n, ALuint *puiBuffers)
|
||||||
@ -56,38 +56,35 @@ AL_API ALvoid AL_APIENTRY alGenDatabuffersEXT(ALsizei n,ALuint *puiBuffers)
|
|||||||
* Databuffer Names) */
|
* Databuffer Names) */
|
||||||
if(!IsBadWritePtr((void*)puiBuffers, n * sizeof(ALuint)))
|
if(!IsBadWritePtr((void*)puiBuffers, n * sizeof(ALuint)))
|
||||||
{
|
{
|
||||||
ALdatabuffer *end;
|
ALenum err;
|
||||||
ALdatabuffer **list = &device->DatabufferList;
|
|
||||||
while(*list)
|
|
||||||
list = &(*list)->next;
|
|
||||||
|
|
||||||
/* Create all the new Databuffers */
|
/* Create all the new Databuffers */
|
||||||
end = *list;
|
|
||||||
while(i < n)
|
while(i < n)
|
||||||
{
|
{
|
||||||
*list = calloc(1, sizeof(ALdatabuffer));
|
ALdatabuffer *buffer = calloc(1, sizeof(ALdatabuffer));
|
||||||
if(!(*list))
|
if(!buffer)
|
||||||
{
|
{
|
||||||
while(end->next)
|
|
||||||
{
|
|
||||||
ALdatabuffer *temp = end->next;
|
|
||||||
end->next = temp->next;
|
|
||||||
|
|
||||||
ALTHUNK_REMOVEENTRY(temp->databuffer);
|
|
||||||
device->DatabufferCount--;
|
|
||||||
free(temp);
|
|
||||||
}
|
|
||||||
alSetError(Context, AL_OUT_OF_MEMORY);
|
alSetError(Context, AL_OUT_OF_MEMORY);
|
||||||
|
alDeleteDatabuffersEXT(i, puiBuffers);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
puiBuffers[i] = (ALuint)ALTHUNK_ADDENTRY(*list);
|
buffer->databuffer = ALTHUNK_ADDENTRY(buffer);
|
||||||
(*list)->databuffer = puiBuffers[i];
|
err = InsertUIntMapEntry(&device->DatabufferMap,
|
||||||
(*list)->state = UNMAPPED;
|
buffer->databuffer, buffer);
|
||||||
device->DatabufferCount++;
|
if(err != AL_NO_ERROR)
|
||||||
i++;
|
{
|
||||||
|
ALTHUNK_REMOVEENTRY(buffer->databuffer);
|
||||||
|
memset(buffer, 0, sizeof(ALdatabuffer));
|
||||||
|
free(buffer);
|
||||||
|
|
||||||
list = &(*list)->next;
|
alSetError(Context, err);
|
||||||
|
alDeleteDatabuffersEXT(i, puiBuffers);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
puiBuffers[i++] = buffer->databuffer;
|
||||||
|
|
||||||
|
buffer->state = UNMAPPED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -125,7 +122,7 @@ AL_API ALvoid AL_APIENTRY alDeleteDatabuffersEXT(ALsizei n, const ALuint *puiBuf
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Check for valid Buffer ID */
|
/* Check for valid Buffer ID */
|
||||||
if((ALBuf=VerifyDatabuffer(device->DatabufferList, puiBuffers[i])) != NULL)
|
if((ALBuf=LookupDatabuffer(device->DatabufferMap, puiBuffers[i])) != NULL)
|
||||||
{
|
{
|
||||||
if(ALBuf->state != UNMAPPED)
|
if(ALBuf->state != UNMAPPED)
|
||||||
{
|
{
|
||||||
@ -150,16 +147,8 @@ AL_API ALvoid AL_APIENTRY alDeleteDatabuffersEXT(ALsizei n, const ALuint *puiBuf
|
|||||||
{
|
{
|
||||||
for(i = 0;i < n;i++)
|
for(i = 0;i < n;i++)
|
||||||
{
|
{
|
||||||
if((ALBuf=VerifyDatabuffer(device->DatabufferList, puiBuffers[i])) != NULL)
|
if((ALBuf=LookupDatabuffer(device->DatabufferMap, puiBuffers[i])) != NULL)
|
||||||
{
|
{
|
||||||
ALdatabuffer **list = &device->DatabufferList;
|
|
||||||
|
|
||||||
while(*list && *list != ALBuf)
|
|
||||||
list = &(*list)->next;
|
|
||||||
|
|
||||||
if(*list)
|
|
||||||
*list = (*list)->next;
|
|
||||||
|
|
||||||
if(ALBuf == Context->SampleSource)
|
if(ALBuf == Context->SampleSource)
|
||||||
Context->SampleSource = NULL;
|
Context->SampleSource = NULL;
|
||||||
if(ALBuf == Context->SampleSink)
|
if(ALBuf == Context->SampleSink)
|
||||||
@ -169,9 +158,10 @@ AL_API ALvoid AL_APIENTRY alDeleteDatabuffersEXT(ALsizei n, const ALuint *puiBuf
|
|||||||
free(ALBuf->data);
|
free(ALBuf->data);
|
||||||
|
|
||||||
// Release buffer structure
|
// Release buffer structure
|
||||||
|
RemoveUIntMapKey(&device->DatabufferMap, ALBuf->databuffer);
|
||||||
ALTHUNK_REMOVEENTRY(puiBuffers[i]);
|
ALTHUNK_REMOVEENTRY(puiBuffers[i]);
|
||||||
|
|
||||||
memset(ALBuf, 0, sizeof(ALdatabuffer));
|
memset(ALBuf, 0, sizeof(ALdatabuffer));
|
||||||
device->DatabufferCount--;
|
|
||||||
free(ALBuf);
|
free(ALBuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -188,19 +178,18 @@ AL_API ALvoid AL_APIENTRY alDeleteDatabuffersEXT(ALsizei n, const ALuint *puiBuf
|
|||||||
*
|
*
|
||||||
* Checks if ulBuffer is a valid Databuffer Name
|
* Checks if ulBuffer is a valid Databuffer Name
|
||||||
*/
|
*/
|
||||||
AL_API ALboolean AL_APIENTRY alIsDatabufferEXT(ALuint uiBuffer)
|
AL_API ALboolean AL_APIENTRY alIsDatabufferEXT(ALuint buffer)
|
||||||
{
|
{
|
||||||
ALCcontext *Context;
|
ALCcontext *Context;
|
||||||
ALboolean result = AL_TRUE;
|
ALboolean result;
|
||||||
ALCdevice *device;
|
ALCdevice *device;
|
||||||
|
|
||||||
Context = GetContextSuspended();
|
Context = GetContextSuspended();
|
||||||
if(!Context) return AL_FALSE;
|
if(!Context) return AL_FALSE;
|
||||||
|
|
||||||
device = Context->Device;
|
device = Context->Device;
|
||||||
if(uiBuffer)
|
result = ((!buffer || LookupDatabuffer(device->DatabufferMap, buffer)) ?
|
||||||
result = (VerifyDatabuffer(device->DatabufferList, uiBuffer) ?
|
AL_TRUE : AL_FALSE);
|
||||||
AL_TRUE : AL_FALSE);
|
|
||||||
|
|
||||||
ProcessContext(Context);
|
ProcessContext(Context);
|
||||||
|
|
||||||
@ -223,7 +212,7 @@ AL_API ALvoid AL_APIENTRY alDatabufferDataEXT(ALuint buffer,const ALvoid *data,A
|
|||||||
if(!Context) return;
|
if(!Context) return;
|
||||||
|
|
||||||
Device = Context->Device;
|
Device = Context->Device;
|
||||||
if((ALBuf=VerifyDatabuffer(Device->DatabufferList, buffer)) != NULL)
|
if((ALBuf=LookupDatabuffer(Device->DatabufferMap, buffer)) != NULL)
|
||||||
{
|
{
|
||||||
if(ALBuf->state == UNMAPPED)
|
if(ALBuf->state == UNMAPPED)
|
||||||
{
|
{
|
||||||
@ -273,7 +262,7 @@ AL_API ALvoid AL_APIENTRY alDatabufferSubDataEXT(ALuint uiBuffer, ALintptrEXT st
|
|||||||
if(!pContext) return;
|
if(!pContext) return;
|
||||||
|
|
||||||
Device = pContext->Device;
|
Device = pContext->Device;
|
||||||
if((pBuffer=VerifyDatabuffer(Device->DatabufferList, uiBuffer)) != NULL)
|
if((pBuffer=LookupDatabuffer(Device->DatabufferMap, uiBuffer)) != NULL)
|
||||||
{
|
{
|
||||||
if(start >= 0 && length >= 0 && start+length <= pBuffer->size)
|
if(start >= 0 && length >= 0 && start+length <= pBuffer->size)
|
||||||
{
|
{
|
||||||
@ -301,7 +290,7 @@ AL_API ALvoid AL_APIENTRY alGetDatabufferSubDataEXT(ALuint uiBuffer, ALintptrEXT
|
|||||||
if(!pContext) return;
|
if(!pContext) return;
|
||||||
|
|
||||||
Device = pContext->Device;
|
Device = pContext->Device;
|
||||||
if((pBuffer=VerifyDatabuffer(Device->DatabufferList, uiBuffer)) != NULL)
|
if((pBuffer=LookupDatabuffer(Device->DatabufferMap, uiBuffer)) != NULL)
|
||||||
{
|
{
|
||||||
if(start >= 0 && length >= 0 && start+length <= pBuffer->size)
|
if(start >= 0 && length >= 0 && start+length <= pBuffer->size)
|
||||||
{
|
{
|
||||||
@ -331,7 +320,7 @@ AL_API ALvoid AL_APIENTRY alDatabufferfEXT(ALuint buffer, ALenum eParam, ALfloat
|
|||||||
if(!pContext) return;
|
if(!pContext) return;
|
||||||
|
|
||||||
Device = pContext->Device;
|
Device = pContext->Device;
|
||||||
if(VerifyDatabuffer(Device->DatabufferList, buffer) != NULL)
|
if(LookupDatabuffer(Device->DatabufferMap, buffer) != NULL)
|
||||||
{
|
{
|
||||||
switch(eParam)
|
switch(eParam)
|
||||||
{
|
{
|
||||||
@ -357,7 +346,7 @@ AL_API ALvoid AL_APIENTRY alDatabufferfvEXT(ALuint buffer, ALenum eParam, const
|
|||||||
if(!pContext) return;
|
if(!pContext) return;
|
||||||
|
|
||||||
Device = pContext->Device;
|
Device = pContext->Device;
|
||||||
if(VerifyDatabuffer(Device->DatabufferList, buffer) != NULL)
|
if(LookupDatabuffer(Device->DatabufferMap, buffer) != NULL)
|
||||||
{
|
{
|
||||||
switch(eParam)
|
switch(eParam)
|
||||||
{
|
{
|
||||||
@ -384,7 +373,7 @@ AL_API ALvoid AL_APIENTRY alDatabufferiEXT(ALuint buffer, ALenum eParam, ALint l
|
|||||||
if(!pContext) return;
|
if(!pContext) return;
|
||||||
|
|
||||||
Device = pContext->Device;
|
Device = pContext->Device;
|
||||||
if(VerifyDatabuffer(Device->DatabufferList, buffer) != NULL)
|
if(LookupDatabuffer(Device->DatabufferMap, buffer) != NULL)
|
||||||
{
|
{
|
||||||
switch(eParam)
|
switch(eParam)
|
||||||
{
|
{
|
||||||
@ -410,7 +399,7 @@ AL_API ALvoid AL_APIENTRY alDatabufferivEXT(ALuint buffer, ALenum eParam, const
|
|||||||
if(!pContext) return;
|
if(!pContext) return;
|
||||||
|
|
||||||
Device = pContext->Device;
|
Device = pContext->Device;
|
||||||
if(VerifyDatabuffer(Device->DatabufferList, buffer) != NULL)
|
if(LookupDatabuffer(Device->DatabufferMap, buffer) != NULL)
|
||||||
{
|
{
|
||||||
switch(eParam)
|
switch(eParam)
|
||||||
{
|
{
|
||||||
@ -437,7 +426,7 @@ AL_API ALvoid AL_APIENTRY alGetDatabufferfEXT(ALuint buffer, ALenum eParam, ALfl
|
|||||||
if(pflValue)
|
if(pflValue)
|
||||||
{
|
{
|
||||||
Device = pContext->Device;
|
Device = pContext->Device;
|
||||||
if(VerifyDatabuffer(Device->DatabufferList, buffer) != NULL)
|
if(LookupDatabuffer(Device->DatabufferMap, buffer) != NULL)
|
||||||
{
|
{
|
||||||
switch(eParam)
|
switch(eParam)
|
||||||
{
|
{
|
||||||
@ -466,7 +455,7 @@ AL_API ALvoid AL_APIENTRY alGetDatabufferfvEXT(ALuint buffer, ALenum eParam, ALf
|
|||||||
if(pflValues)
|
if(pflValues)
|
||||||
{
|
{
|
||||||
Device = pContext->Device;
|
Device = pContext->Device;
|
||||||
if(VerifyDatabuffer(Device->DatabufferList, buffer) != NULL)
|
if(LookupDatabuffer(Device->DatabufferMap, buffer) != NULL)
|
||||||
{
|
{
|
||||||
switch(eParam)
|
switch(eParam)
|
||||||
{
|
{
|
||||||
@ -496,7 +485,7 @@ AL_API ALvoid AL_APIENTRY alGetDatabufferiEXT(ALuint buffer, ALenum eParam, ALin
|
|||||||
if(plValue)
|
if(plValue)
|
||||||
{
|
{
|
||||||
Device = pContext->Device;
|
Device = pContext->Device;
|
||||||
if((pBuffer=VerifyDatabuffer(Device->DatabufferList, buffer)) != NULL)
|
if((pBuffer=LookupDatabuffer(Device->DatabufferMap, buffer)) != NULL)
|
||||||
{
|
{
|
||||||
switch(eParam)
|
switch(eParam)
|
||||||
{
|
{
|
||||||
@ -529,7 +518,7 @@ AL_API ALvoid AL_APIENTRY alGetDatabufferivEXT(ALuint buffer, ALenum eParam, ALi
|
|||||||
if(plValues)
|
if(plValues)
|
||||||
{
|
{
|
||||||
Device = pContext->Device;
|
Device = pContext->Device;
|
||||||
if(VerifyDatabuffer(Device->DatabufferList, buffer) != NULL)
|
if(LookupDatabuffer(Device->DatabufferMap, buffer) != NULL)
|
||||||
{
|
{
|
||||||
switch (eParam)
|
switch (eParam)
|
||||||
{
|
{
|
||||||
@ -563,7 +552,7 @@ AL_API ALvoid AL_APIENTRY alSelectDatabufferEXT(ALenum target, ALuint uiBuffer)
|
|||||||
|
|
||||||
Device = pContext->Device;
|
Device = pContext->Device;
|
||||||
if(uiBuffer == 0 ||
|
if(uiBuffer == 0 ||
|
||||||
(pBuffer=VerifyDatabuffer(Device->DatabufferList, uiBuffer)) != NULL)
|
(pBuffer=LookupDatabuffer(Device->DatabufferMap, uiBuffer)) != NULL)
|
||||||
{
|
{
|
||||||
if(target == AL_SAMPLE_SOURCE_EXT)
|
if(target == AL_SAMPLE_SOURCE_EXT)
|
||||||
pContext->SampleSource = pBuffer;
|
pContext->SampleSource = pBuffer;
|
||||||
@ -590,7 +579,7 @@ AL_API ALvoid* AL_APIENTRY alMapDatabufferEXT(ALuint uiBuffer, ALintptrEXT start
|
|||||||
if(!pContext) return NULL;
|
if(!pContext) return NULL;
|
||||||
|
|
||||||
Device = pContext->Device;
|
Device = pContext->Device;
|
||||||
if((pBuffer=VerifyDatabuffer(Device->DatabufferList, uiBuffer)) != NULL)
|
if((pBuffer=LookupDatabuffer(Device->DatabufferMap, uiBuffer)) != NULL)
|
||||||
{
|
{
|
||||||
if(start >= 0 && length >= 0 && start+length <= pBuffer->size)
|
if(start >= 0 && length >= 0 && start+length <= pBuffer->size)
|
||||||
{
|
{
|
||||||
@ -629,7 +618,7 @@ AL_API ALvoid AL_APIENTRY alUnmapDatabufferEXT(ALuint uiBuffer)
|
|||||||
if(!pContext) return;
|
if(!pContext) return;
|
||||||
|
|
||||||
Device = pContext->Device;
|
Device = pContext->Device;
|
||||||
if((pBuffer=VerifyDatabuffer(Device->DatabufferList, uiBuffer)) != NULL)
|
if((pBuffer=LookupDatabuffer(Device->DatabufferMap, uiBuffer)) != NULL)
|
||||||
{
|
{
|
||||||
if(pBuffer->state == MAPPED)
|
if(pBuffer->state == MAPPED)
|
||||||
pBuffer->state = UNMAPPED;
|
pBuffer->state = UNMAPPED;
|
||||||
@ -650,10 +639,11 @@ AL_API ALvoid AL_APIENTRY alUnmapDatabufferEXT(ALuint uiBuffer)
|
|||||||
*/
|
*/
|
||||||
ALvoid ReleaseALDatabuffers(ALCdevice *device)
|
ALvoid ReleaseALDatabuffers(ALCdevice *device)
|
||||||
{
|
{
|
||||||
while(device->DatabufferList)
|
ALsizei i;
|
||||||
|
for(i = 0;i < device->DatabufferMap.size;i++)
|
||||||
{
|
{
|
||||||
ALdatabuffer *temp = device->DatabufferList;
|
ALdatabuffer *temp = device->DatabufferMap.array[i].value;
|
||||||
device->DatabufferList = temp->next;
|
device->DatabufferMap.array[i].value = NULL;
|
||||||
|
|
||||||
// Release buffer data
|
// Release buffer data
|
||||||
free(temp->data);
|
free(temp->data);
|
||||||
@ -663,5 +653,4 @@ ALvoid ReleaseALDatabuffers(ALCdevice *device)
|
|||||||
memset(temp, 0, sizeof(ALdatabuffer));
|
memset(temp, 0, sizeof(ALdatabuffer));
|
||||||
free(temp);
|
free(temp);
|
||||||
}
|
}
|
||||||
device->DatabufferCount = 0;
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user