aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/ALc.c22
-rw-r--r--Alc/ALu.c36
-rw-r--r--OpenAL32/Include/alMain.h1
-rw-r--r--OpenAL32/Include/alu.h1
-rw-r--r--OpenAL32/alSource.c16
5 files changed, 74 insertions, 2 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 1528c4e6..aa4775de 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -169,7 +169,7 @@ static ALCchar *alcDefaultAllDeviceSpecifier = alcAllDeviceList;
static ALCchar *alcCaptureDefaultDeviceSpecifier = alcCaptureDeviceList;
-static ALCchar alcExtensionList[] = "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_EFX";
+static ALCchar alcExtensionList[] = "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_disconnect ALC_EXT_EFX";
static ALCint alcMajorVersion = 1;
static ALCint alcMinorVersion = 1;
@@ -576,6 +576,7 @@ ALCAPI ALCdevice* ALCAPIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, AL
memset(pDevice, 0, sizeof(ALCdevice));
//Validate device
+ pDevice->Connected = ALC_TRUE;
pDevice->IsCaptureDevice = AL_TRUE;
pDevice->Frequency = frequency;
@@ -808,6 +809,13 @@ ALCAPI ALCvoid ALCAPIENTRY alcGetIntegerv(ALCdevice *device,ALCenum param,ALsize
SetALCError(ALC_INVALID_VALUE);
break;
+ case ALC_CONNECTED:
+ if(size <= 0)
+ SetALCError(ALC_INVALID_VALUE);
+ else
+ *data = device->Connected;
+ break;
+
default:
SetALCError(ALC_INVALID_ENUM);
break;
@@ -944,6 +952,15 @@ ALCAPI ALCvoid ALCAPIENTRY alcGetIntegerv(ALCdevice *device,ALCenum param,ALsize
*data = device->lNumStereoSources;
break;
+ case ALC_CONNECTED:
+ if(!IsDevice(device))
+ SetALCError(ALC_INVALID_DEVICE);
+ else if(size <= 0)
+ SetALCError(ALC_INVALID_VALUE);
+ else
+ *data = device->Connected;
+ break;
+
default:
SetALCError(ALC_INVALID_ENUM);
break;
@@ -1058,7 +1075,7 @@ ALCAPI ALCcontext* ALCAPIENTRY alcCreateContext(ALCdevice *device, const ALCint
ALuint ulAttributeIndex, ulRequestedStereoSources;
ALuint RequestedSends;
- if(IsDevice(device) && !device->IsCaptureDevice)
+ if(IsDevice(device) && !device->IsCaptureDevice && device->Connected)
{
// Reset Context Last Error code
g_eLastContextError = ALC_NO_ERROR;
@@ -1351,6 +1368,7 @@ ALCAPI ALCdevice* ALCAPIENTRY alcOpenDevice(const ALCchar *deviceName)
memset(device, 0, sizeof(ALCdevice));
//Validate device
+ device->Connected = ALC_TRUE;
device->IsCaptureDevice = AL_FALSE;
//Set output format
diff --git a/Alc/ALu.c b/Alc/ALu.c
index ba45f67f..cafc3174 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -1385,3 +1385,39 @@ ALvoid aluMixData(ALCcontext *ALContext,ALvoid *buffer,ALsizei size,ALenum forma
ProcessContext(ALContext);
}
+
+ALvoid aluHandleDisconnect(ALCdevice *device)
+{
+ if(!device->IsCaptureDevice)
+ {
+ ALsource *source = NULL;
+
+ SuspendContext(device->Context);
+ if(device->Context)
+ source = device->Context->Source;
+
+ while(source)
+ {
+ if(source->state == AL_PLAYING)
+ {
+ ALbufferlistitem *BufferListItem;
+
+ source->state = AL_STOPPED;
+ source->inuse = AL_FALSE;
+ source->BuffersPlayed = source->BuffersInQueue;
+ BufferListItem = source->queue;
+ while(BufferListItem != NULL)
+ {
+ BufferListItem->bufferstate = PROCESSED;
+ BufferListItem = BufferListItem->next;
+ }
+ source->position = 0;
+ source->position_fraction = 0;
+ }
+ source = source->next;
+ }
+ ProcessContext(device->Context);
+ }
+
+ device->Connected = ALC_FALSE;
+}
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 782252ba..ca9d8006 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -171,6 +171,7 @@ void alc_pulse_init(BackendFuncs *func_list);
struct ALCdevice_struct
{
+ ALCboolean Connected;
ALboolean IsCaptureDevice;
ALuint Frequency;
diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h
index f2a7b023..4641a698 100644
--- a/OpenAL32/Include/alu.h
+++ b/OpenAL32/Include/alu.h
@@ -147,6 +147,7 @@ static __inline ALuint aluChannelsFromFormat(ALenum format)
ALvoid aluInitPanning(ALCcontext *Context);
ALvoid aluMixData(ALCcontext *context,ALvoid *buffer,ALsizei size,ALenum format);
+ALvoid aluHandleDisconnect(ALCdevice *device);
#ifdef __cplusplus
}
diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c
index 205a1c46..30be074e 100644
--- a/OpenAL32/alSource.c
+++ b/OpenAL32/alSource.c
@@ -1347,6 +1347,22 @@ ALAPI ALvoid ALAPIENTRY alSourcePlayv(ALsizei n, const ALuint *pSourceList)
// Check if an Offset has been set
if(pSource->lOffset)
ApplyOffset(pSource, AL_FALSE);
+
+ // If device is disconnected, go right to stopped
+ if(!pContext->Device->Connected)
+ {
+ pSource->state = AL_STOPPED;
+ pSource->inuse = AL_FALSE;
+ pSource->BuffersPlayed = pSource->BuffersInQueue;
+ ALBufferList = pSource->queue;
+ while(ALBufferList != NULL)
+ {
+ ALBufferList->bufferstate = PROCESSED;
+ ALBufferList = ALBufferList->next;
+ }
+ pSource->position = 0;
+ pSource->position_fraction = 0;
+ }
}
else
{