Commit 6ecb7283 authored by David Reid's avatar David Reid

Core Audio: Fix a bug when using multiple contexts.

parent 0ae8adc1
...@@ -24351,6 +24351,8 @@ static ma_result ma_context__init_device_tracking__coreaudio(ma_context* pContex ...@@ -24351,6 +24351,8 @@ static ma_result ma_context__init_device_tracking__coreaudio(ma_context* pContex
ma_spinlock_lock(&g_DeviceTrackingInitLock_CoreAudio); ma_spinlock_lock(&g_DeviceTrackingInitLock_CoreAudio);
{ {
/* Don't do anything if we've already initializd device tracking. */
if (g_DeviceTrackingInitCounter_CoreAudio == 0) {
AudioObjectPropertyAddress propAddress; AudioObjectPropertyAddress propAddress;
propAddress.mScope = kAudioObjectPropertyScopeGlobal; propAddress.mScope = kAudioObjectPropertyScopeGlobal;
propAddress.mElement = kAudioObjectPropertyElementMaster; propAddress.mElement = kAudioObjectPropertyElementMaster;
...@@ -24362,6 +24364,9 @@ static ma_result ma_context__init_device_tracking__coreaudio(ma_context* pContex ...@@ -24362,6 +24364,9 @@ static ma_result ma_context__init_device_tracking__coreaudio(ma_context* pContex
propAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice; propAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
((ma_AudioObjectAddPropertyListener_proc)pContext->coreaudio.AudioObjectAddPropertyListener)(kAudioObjectSystemObject, &propAddress, &ma_default_device_changed__coreaudio, NULL); ((ma_AudioObjectAddPropertyListener_proc)pContext->coreaudio.AudioObjectAddPropertyListener)(kAudioObjectSystemObject, &propAddress, &ma_default_device_changed__coreaudio, NULL);
g_DeviceTrackingInitCounter_CoreAudio += 1;
}
} }
ma_spinlock_unlock(&g_DeviceTrackingInitLock_CoreAudio); ma_spinlock_unlock(&g_DeviceTrackingInitLock_CoreAudio);
...@@ -24374,6 +24379,9 @@ static ma_result ma_context__uninit_device_tracking__coreaudio(ma_context* pCont ...@@ -24374,6 +24379,9 @@ static ma_result ma_context__uninit_device_tracking__coreaudio(ma_context* pCont
ma_spinlock_lock(&g_DeviceTrackingInitLock_CoreAudio); ma_spinlock_lock(&g_DeviceTrackingInitLock_CoreAudio);
{ {
g_DeviceTrackingInitCounter_CoreAudio -= 1;
if (g_DeviceTrackingInitCounter_CoreAudio == 0) {
AudioObjectPropertyAddress propAddress; AudioObjectPropertyAddress propAddress;
propAddress.mScope = kAudioObjectPropertyScopeGlobal; propAddress.mScope = kAudioObjectPropertyScopeGlobal;
propAddress.mElement = kAudioObjectPropertyElementMaster; propAddress.mElement = kAudioObjectPropertyElementMaster;
...@@ -24384,12 +24392,14 @@ static ma_result ma_context__uninit_device_tracking__coreaudio(ma_context* pCont ...@@ -24384,12 +24392,14 @@ static ma_result ma_context__uninit_device_tracking__coreaudio(ma_context* pCont
propAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice; propAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
((ma_AudioObjectRemovePropertyListener_proc)pContext->coreaudio.AudioObjectRemovePropertyListener)(kAudioObjectSystemObject, &propAddress, &ma_default_device_changed__coreaudio, NULL); ((ma_AudioObjectRemovePropertyListener_proc)pContext->coreaudio.AudioObjectRemovePropertyListener)(kAudioObjectSystemObject, &propAddress, &ma_default_device_changed__coreaudio, NULL);
/* At this point there should be no tracked devices. If so there's an error somewhere. */ /* At this point there should be no tracked devices. If not there's an error somewhere. */
MA_ASSERT(g_ppTrackedDevices_CoreAudio == NULL); if (g_ppTrackedDevices_CoreAudio != NULL) {
MA_ASSERT(g_TrackedDeviceCount_CoreAudio == 0); ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_WARNING, "You have uninitialized all contexts while an associated device is still active.", MA_INVALID_OPERATION);
}
ma_mutex_uninit(&g_DeviceTrackingMutex_CoreAudio); ma_mutex_uninit(&g_DeviceTrackingMutex_CoreAudio);
} }
}
ma_spinlock_unlock(&g_DeviceTrackingInitLock_CoreAudio); ma_spinlock_unlock(&g_DeviceTrackingInitLock_CoreAudio);
return MA_SUCCESS; return MA_SUCCESS;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment