mirror of https://github.com/encounter/SDL.git
ensure SDL_AUDIODEVICEREMOVED gets sent when hotplug removes a device
James Zipperer The problem I was seeing was that the the ALSA hotplug thread would call SDL_RemoveAudioDevice, but my application code was not seeing an SDL_AUDIODEVICEREMOVED event to go along with it. To fix it, I added some code into SDL_RemoveAudioDevice to call SDL_OpenedAudioDeviceDisconnected on the corresponding open audio device. There didn't appear to be a way to cross reference the handle that SDL_RemoveAudioDevice gets and the SDL_AudioDevice pointer that SDL_OpenedAudioDeviceDisconnected needs, so I ended up adding a void *handle field to struct SDL_AudioDevice so that I could do the cross reference. Is there some other way beside adding a void *handle field to the struct to get the proper information for SDL_OpenedAudioDeviceDisconnected?
This commit is contained in:
parent
69cf170356
commit
bac61096d8
|
@ -408,13 +408,26 @@ mark_device_removed(void *handle, SDL_AudioDeviceItem *devices, SDL_bool *remove
|
||||||
void
|
void
|
||||||
SDL_RemoveAudioDevice(const int iscapture, void *handle)
|
SDL_RemoveAudioDevice(const int iscapture, void *handle)
|
||||||
{
|
{
|
||||||
|
int device_index;
|
||||||
|
SDL_AudioDevice *device = NULL;
|
||||||
|
|
||||||
SDL_LockMutex(current_audio.detectionLock);
|
SDL_LockMutex(current_audio.detectionLock);
|
||||||
if (iscapture) {
|
if (iscapture) {
|
||||||
mark_device_removed(handle, current_audio.inputDevices, ¤t_audio.captureDevicesRemoved);
|
mark_device_removed(handle, current_audio.inputDevices, ¤t_audio.captureDevicesRemoved);
|
||||||
} else {
|
} else {
|
||||||
mark_device_removed(handle, current_audio.outputDevices, ¤t_audio.outputDevicesRemoved);
|
mark_device_removed(handle, current_audio.outputDevices, ¤t_audio.outputDevicesRemoved);
|
||||||
}
|
}
|
||||||
|
for (device_index = 0; device_index < SDL_arraysize(open_devices); device_index++)
|
||||||
|
{
|
||||||
|
device = open_devices[device_index];
|
||||||
|
if (device != NULL && device->handle == handle)
|
||||||
|
{
|
||||||
|
SDL_OpenedAudioDeviceDisconnected(device);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
SDL_UnlockMutex(current_audio.detectionLock);
|
SDL_UnlockMutex(current_audio.detectionLock);
|
||||||
|
|
||||||
current_audio.impl.FreeDeviceHandle(handle);
|
current_audio.impl.FreeDeviceHandle(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1254,6 +1267,7 @@ open_audio_device(const char *devname, int iscapture,
|
||||||
device->id = id + 1;
|
device->id = id + 1;
|
||||||
device->spec = *obtained;
|
device->spec = *obtained;
|
||||||
device->iscapture = iscapture ? SDL_TRUE : SDL_FALSE;
|
device->iscapture = iscapture ? SDL_TRUE : SDL_FALSE;
|
||||||
|
device->handle = handle;
|
||||||
|
|
||||||
SDL_AtomicSet(&device->shutdown, 0); /* just in case. */
|
SDL_AtomicSet(&device->shutdown, 0); /* just in case. */
|
||||||
SDL_AtomicSet(&device->paused, 1);
|
SDL_AtomicSet(&device->paused, 1);
|
||||||
|
|
|
@ -187,6 +187,8 @@ struct SDL_AudioDevice
|
||||||
/* * * */
|
/* * * */
|
||||||
/* Data private to this driver */
|
/* Data private to this driver */
|
||||||
struct SDL_PrivateAudioData *hidden;
|
struct SDL_PrivateAudioData *hidden;
|
||||||
|
|
||||||
|
void *handle;
|
||||||
};
|
};
|
||||||
#undef _THIS
|
#undef _THIS
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue