summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2009-08-15 09:14:08 -0700
committerChris Robinson <[email protected]>2009-08-15 09:14:08 -0700
commit43067ed2b8d4ab9c3f46b8ee002d6c3f6480cc4f (patch)
treec83c89f3a37a468f18d8aa533b97ca8027fa96f3
parent4e4c9aef1581fbec81294f20e2466d9d63e26ad8 (diff)
Store the buffer list in the device
-rw-r--r--Alc/ALc.c10
-rw-r--r--OpenAL32/Include/alBuffer.h6
-rw-r--r--OpenAL32/Include/alMain.h4
-rw-r--r--OpenAL32/alBuffer.c32
4 files changed, 30 insertions, 22 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index fbabe468..492bed92 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -216,7 +216,6 @@ BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
if(!init_done)
break;
ReleaseALC();
- ReleaseALBuffers();
ReleaseALEffects();
ReleaseALFilters();
FreeALConfig();
@@ -236,7 +235,6 @@ static void my_deinit()
once = AL_TRUE;
ReleaseALC();
- ReleaseALBuffers();
ReleaseALEffects();
ReleaseALFilters();
FreeALConfig();
@@ -1371,6 +1369,14 @@ ALCAPI ALCboolean ALCAPIENTRY alcCloseDevice(ALCdevice *pDevice)
}
ALCdevice_ClosePlayback(pDevice);
+ if(pDevice->BufferCount > 0)
+ {
+#ifdef _DEBUG
+ AL_PRINT("alcCloseDevice(): deleting %d Buffer(s)\n", pDevice->BufferCount);
+#endif
+ ReleaseALBuffers(pDevice);
+ }
+
//Release device structure
memset(pDevice, 0, sizeof(ALCdevice));
free(pDevice);
diff --git a/OpenAL32/Include/alBuffer.h b/OpenAL32/Include/alBuffer.h
index 75e97d18..b25a35c6 100644
--- a/OpenAL32/Include/alBuffer.h
+++ b/OpenAL32/Include/alBuffer.h
@@ -11,7 +11,7 @@ extern "C" {
#define PENDING 1
#define PROCESSED 2
-typedef struct ALbuffer_struct
+typedef struct ALbuffer
{
ALenum format;
ALenum eOriginalFormat;
@@ -21,12 +21,12 @@ typedef struct ALbuffer_struct
ALsizei padding;
ALenum state;
ALuint refcount; // Number of sources using this buffer (deletion can only occur when this is 0)
- struct ALbuffer_struct *next;
+ struct ALbuffer *next;
} ALbuffer;
ALvoid ALAPIENTRY alBufferSubDataEXT(ALuint buffer,ALenum format,const ALvoid *data,ALsizei offset,ALsizei length);
-ALvoid ReleaseALBuffers(ALvoid);
+ALvoid ReleaseALBuffers(ALCdevice *device);
#ifdef __cplusplus
}
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index e3823364..ccfb94ac 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -189,6 +189,10 @@ struct ALCdevice_struct
ALint lNumStereoSources;
ALuint NumAuxSends;
+ // Linked List of Buffers for this device
+ struct ALbuffer *Buffers;
+ ALuint BufferCount;
+
// Context created on this device
ALCcontext *Context;
diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c
index 0dfe05ba..cfac55d7 100644
--- a/OpenAL32/alBuffer.c
+++ b/OpenAL32/alBuffer.c
@@ -49,9 +49,6 @@ static void ConvertDataIMA4(ALshort *dst, const ALvoid *src, ALint origChans, AL
* Global Variables
*/
-static ALbuffer *g_pBuffers = NULL; // Linked List of Buffers
-static ALuint g_uiBufferCount = 0; // Buffer Count
-
static const long g_IMAStep_size[89]={ // IMA ADPCM Stepsize table
7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31,
34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143,
@@ -87,10 +84,12 @@ ALAPI ALvoid ALAPIENTRY alGenBuffers(ALsizei n,ALuint *puiBuffers)
// Check that we are actually generation some Buffers
if (n > 0)
{
+ ALCdevice *device = Context->Device;
+
// Check the pointer is valid (and points to enough memory to store Buffer Names)
if (!IsBadWritePtr((void*)puiBuffers, n * sizeof(ALuint)))
{
- ALbuffer **list = &g_pBuffers;
+ ALbuffer **list = &device->Buffers;
while(*list)
list = &(*list)->next;
@@ -107,7 +106,7 @@ ALAPI ALvoid ALAPIENTRY alGenBuffers(ALsizei n,ALuint *puiBuffers)
puiBuffers[i] = (ALuint)ALTHUNK_ADDENTRY(*list);
(*list)->state = UNUSED;
- g_uiBufferCount++;
+ device->BufferCount++;
i++;
list = &(*list)->next;
@@ -143,6 +142,8 @@ ALAPI ALvoid ALAPIENTRY alDeleteBuffers(ALsizei n, const ALuint *puiBuffers)
// Check we are actually Deleting some Buffers
if (n >= 0)
{
+ ALCdevice *device = Context->Device;
+
// Check that all the buffers are valid and can actually be deleted
for (i = 0; i < n; i++)
{
@@ -176,7 +177,7 @@ ALAPI ALvoid ALAPIENTRY alDeleteBuffers(ALsizei n, const ALuint *puiBuffers)
{
if (puiBuffers[i] && alIsBuffer(puiBuffers[i]))
{
- ALbuffer **list = &g_pBuffers;
+ ALbuffer **list = &device->Buffers;
ALBuf=((ALbuffer *)ALTHUNK_LOOKUPENTRY(puiBuffers[i]));
while(*list && *list != ALBuf)
@@ -191,7 +192,7 @@ ALAPI ALvoid ALAPIENTRY alDeleteBuffers(ALsizei n, const ALuint *puiBuffers)
// Release buffer structure
ALTHUNK_REMOVEENTRY(puiBuffers[i]);
memset(ALBuf, 0, sizeof(ALbuffer));
- g_uiBufferCount--;
+ device->BufferCount--;
free(ALBuf);
}
}
@@ -223,10 +224,12 @@ ALAPI ALboolean ALAPIENTRY alIsBuffer(ALuint uiBuffer)
if (uiBuffer)
{
+ ALCdevice *device = Context->Device;
+
TgtALBuf = (ALbuffer *)ALTHUNK_LOOKUPENTRY(uiBuffer);
// Check through list of generated buffers for uiBuffer
- ALBuf = g_pBuffers;
+ ALBuf = device->Buffers;
while (ALBuf)
{
if (ALBuf == TgtALBuf)
@@ -1069,17 +1072,12 @@ static void ConvertDataIMA4(ALshort *dst, const ALvoid *src, ALint origChans, AL
*
* INTERNAL FN : Called by DLLMain on exit to destroy any buffers that still exist
*/
-ALvoid ReleaseALBuffers(ALvoid)
+ALvoid ReleaseALBuffers(ALCdevice *device)
{
ALbuffer *ALBuffer;
ALbuffer *ALBufferTemp;
-#ifdef _DEBUG
- if(g_uiBufferCount > 0)
- AL_PRINT("exit(): deleting %d Buffer(s)\n", g_uiBufferCount);
-#endif
-
- ALBuffer = g_pBuffers;
+ ALBuffer = device->Buffers;
while(ALBuffer)
{
// Release sample data
@@ -1091,6 +1089,6 @@ ALvoid ReleaseALBuffers(ALvoid)
memset(ALBufferTemp, 0, sizeof(ALbuffer));
free(ALBufferTemp);
}
- g_pBuffers = NULL;
- g_uiBufferCount = 0;
+ device->Buffers = NULL;
+ device->BufferCount = 0;
}