aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/ALc.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2012-03-05 07:11:09 -0800
committerChris Robinson <[email protected]>2012-03-05 07:11:09 -0800
commitfe6e532c876bf3ec6776f76f9542038ac9c94d68 (patch)
tree31d29eb21462dbc02287030d8e3b6174dcab92cc /Alc/ALc.c
parent5cdeeb47f3b4dedefd1ceb2b32c2f7754abc058d (diff)
Use a separate backend callback to start playback of the device
This allows us to properly update the ALCdevice and its resources with the new parameters before starting playback, instead of expecting the mixer to block and wait after it has begun. This also lets us avoid holding the device lock while resetting and starting the device, which helps prevent lock inversion on some backends (ie, one thread locking A then B, and another thread locking B then A), ultimately allowing certain backends to asynchronously update the ALCdevice without risk of lockup. Capture still has issues here, however.
Diffstat (limited to 'Alc/ALc.c')
-rw-r--r--Alc/ALc.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 024350ae..9ac841b3 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -40,7 +40,7 @@
#include "alu.h"
-#define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
+#define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
static struct BackendInfo BackendList[] = {
#ifdef HAVE_PULSEAUDIO
{ "pulse", alc_pulse_init, alc_pulse_deinit, alc_pulse_probe, EmptyFuncs },
@@ -1197,8 +1197,6 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
if((device->Flags&DEVICE_RUNNING))
return ALC_NO_ERROR;
- LockDevice(device);
-
oldFreq = device->Frequency;
oldChans = device->FmtChans;
oldType = device->FmtType;
@@ -1211,12 +1209,9 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
device->Frequency,
(device->Flags&DEVICE_FREQUENCY_REQUEST)?" (requested)":"",
device->UpdateSize, device->NumUpdates);
+
if(ALCdevice_ResetPlayback(device) == ALC_FALSE)
- {
- UnlockDevice(device);
return ALC_INVALID_DEVICE;
- }
- device->Flags |= DEVICE_RUNNING;
if(device->FmtChans != oldChans && (device->Flags&DEVICE_CHANNELS_REQUEST))
{
@@ -1290,6 +1285,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
TRACE("Stereo duplication %s\n", (device->Flags&DEVICE_DUPLICATE_STEREO)?"enabled":"disabled");
oldMode = SetMixerFPUMode();
+ LockDevice(device);
context = device->ContextList;
while(context)
{
@@ -1304,10 +1300,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
if(ALeffectState_DeviceUpdate(slot->EffectState, device) == AL_FALSE)
{
UnlockUIntMapRead(&context->EffectSlotMap);
- RestoreFPUMode(oldMode);
UnlockDevice(device);
- ALCdevice_StopPlayback(device);
- device->Flags &= ~DEVICE_RUNNING;
+ RestoreFPUMode(oldMode);
return ALC_INVALID_DEVICE;
}
slot->NeedsUpdate = AL_FALSE;
@@ -1336,8 +1330,12 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
context = context->next;
}
- RestoreFPUMode(oldMode);
UnlockDevice(device);
+ RestoreFPUMode(oldMode);
+
+ if(ALCdevice_StartPlayback(device) == ALC_FALSE)
+ return ALC_INVALID_DEVICE;
+ device->Flags |= DEVICE_RUNNING;
return ALC_NO_ERROR;
}