SDL_RemoveAudioDevice() should specify capture vs output.

This lets us reuse values between the two categories without conflicting, etc.
This commit is contained in:
Ryan C. Gordon 2015-03-19 15:43:00 -04:00
parent 1e78ef2155
commit 11cffe1dc9
4 changed files with 9 additions and 11 deletions

View File

@ -400,11 +400,14 @@ mark_device_removed(void *handle, SDL_AudioDeviceItem *devices, SDL_bool *remove
/* The audio backends call this when a device is removed from the system. */ /* The audio backends call this when a device is removed from the system. */
void void
SDL_RemoveAudioDevice(void *handle) SDL_RemoveAudioDevice(const int iscapture, void *handle)
{ {
SDL_LockMutex(current_audio.detectionLock); SDL_LockMutex(current_audio.detectionLock);
mark_device_removed(handle, current_audio.inputDevices, &current_audio.captureDevicesRemoved); if (iscapture) {
mark_device_removed(handle, current_audio.outputDevices, &current_audio.outputDevicesRemoved); mark_device_removed(handle, current_audio.inputDevices, &current_audio.captureDevicesRemoved);
} else {
mark_device_removed(handle, current_audio.outputDevices, &current_audio.outputDevicesRemoved);
}
SDL_UnlockMutex(current_audio.detectionLock); SDL_UnlockMutex(current_audio.detectionLock);
current_audio.impl.FreeDeviceHandle(handle); current_audio.impl.FreeDeviceHandle(handle);
} }

View File

@ -37,7 +37,7 @@ extern void SDL_AddAudioDevice(const int iscapture, const char *name, void *hand
/* Audio targets should call this as devices are removed, so SDL can update /* Audio targets should call this as devices are removed, so SDL can update
its list of available devices. */ its list of available devices. */
extern void SDL_RemoveAudioDevice(void *handle); extern void SDL_RemoveAudioDevice(const int iscapture, void *handle);
/* Audio targets should call this if an opened audio device is lost while /* Audio targets should call this if an opened audio device is lost while
being used. This can happen due to i/o errors, or a device being unplugged, being used. This can happen due to i/o errors, or a device being unplugged,

View File

@ -246,7 +246,7 @@ reprocess_device_list(const int iscapture, AudioDeviceList **list)
if (item->alive) { if (item->alive) {
prev = item; prev = item;
} else { } else {
SDL_RemoveAudioDevice((void *) ((size_t) item->devid)); SDL_RemoveAudioDevice(iscapture, (void *) ((size_t) item->devid));
if (prev) { if (prev) {
prev->next = item->next; prev->next = item->next;
} else { } else {

View File

@ -47,7 +47,7 @@ static void DetectWave##typ##Devs(void) { \
if (wave##typ##GetDevCaps(i,&caps,sizeof(caps))==MMSYSERR_NOERROR) { \ if (wave##typ##GetDevCaps(i,&caps,sizeof(caps))==MMSYSERR_NOERROR) { \
char *name = WIN_StringToUTF8(caps.szPname); \ char *name = WIN_StringToUTF8(caps.szPname); \
if (name != NULL) { \ if (name != NULL) { \
SDL_AddAudioDevice((int) iscapture, name, (void *) ((size_t) i|(iscap<<31))); \ SDL_AddAudioDevice((int) iscapture, name, (void *) ((size_t) i)); \
SDL_free(name); \ SDL_free(name); \
} \ } \
} \ } \
@ -232,11 +232,6 @@ WINMM_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (handle != NULL) { /* specific device requested? */ if (handle != NULL) { /* specific device requested? */
const size_t val = (size_t) handle; const size_t val = (size_t) handle;
devId = (UINT) val; devId = (UINT) val;
if (iscapture) {
/* we use the top bit to make value unique vs output indices. */
SDL_assert((devId & (1<<31)) != 0);
devId &= ~(1<<31);
}
} }
/* Initialize all variables that we clean on shutdown */ /* Initialize all variables that we clean on shutdown */