Audio hotplug fixes for winmm and XAudio2 backends.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index d937c5a..603a2ad 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -299,7 +299,7 @@ add_audio_device(const char *name, void *handle, SDL_AudioDeviceItem **devices,
return -1;
}
- SDL_assert(handle != NULL);
+ SDL_assert(handle != NULL); /* we reserve NULL, audio backends can't use it. */
item->handle = handle;
SDL_strlcpy(item->name, name, size - sizeof (SDL_AudioDeviceItem));
diff --git a/src/audio/winmm/SDL_winmm.c b/src/audio/winmm/SDL_winmm.c
index b442e88..5600ec3 100644
--- a/src/audio/winmm/SDL_winmm.c
+++ b/src/audio/winmm/SDL_winmm.c
@@ -46,7 +46,7 @@ static void DetectWave##typ##Devs(void) { \
if (wave##typ##GetDevCaps(i,&caps,sizeof(caps))==MMSYSERR_NOERROR) { \
char *name = WIN_StringToUTF8(caps.szPname); \
if (name != NULL) { \
- SDL_AddAudioDevice((int) iscapture, name, (void *) ((size_t) i)); \
+ SDL_AddAudioDevice((int) iscapture, name, (void *) ((size_t) i+1)); \
SDL_free(name); \
} \
} \
@@ -228,7 +228,8 @@ WINMM_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
UINT i;
if (handle != NULL) { /* specific device requested? */
- const size_t val = (size_t) handle;
+ /* -1 because we increment the original value to avoid NULL. */
+ const size_t val = ((size_t) handle) - 1;
devId = (UINT) val;
}
diff --git a/src/audio/xaudio2/SDL_xaudio2.c b/src/audio/xaudio2/SDL_xaudio2.c
index 8aebabf..15fce4a 100644
--- a/src/audio/xaudio2/SDL_xaudio2.c
+++ b/src/audio/xaudio2/SDL_xaudio2.c
@@ -146,7 +146,7 @@ XAUDIO2_DetectDevices(void)
if (IXAudio2_GetDeviceDetails(ixa2, i, &details) == S_OK) {
char *str = WIN_StringToUTF8(details.DisplayName);
if (str != NULL) {
- SDL_AddAudioDevice(SDL_FALSE, str, (void *) ((size_t) i));
+ SDL_AddAudioDevice(SDL_FALSE, str, (void *) ((size_t) i+1));
SDL_free(str); /* SDL_AddAudioDevice made a copy of the string. */
}
}
@@ -297,7 +297,7 @@ XAUDIO2_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
#if defined(SDL_XAUDIO2_WIN8)
LPCWSTR devId = NULL;
#else
- UINT32 devId = (UINT32) ((size_t) handle); /* 0 == system default device. */
+ UINT32 devId = 0; /* 0 == system default device. */
#endif
static IXAudio2VoiceCallbackVtbl callbacks_vtable = {
@@ -312,6 +312,16 @@ XAUDIO2_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
static IXAudio2VoiceCallback callbacks = { &callbacks_vtable };
+#if defined(SDL_XAUDIO2_WIN8)
+ /* !!! FIXME: hook up hotplugging. */
+#else
+ if (handle != NULL) { /* specific device requested? */
+ /* -1 because we increment the original value to avoid NULL. */
+ const size_t val = ((size_t) handle) - 1;
+ devId = (UINT32) val;
+ }
+#endif
+
if (XAudio2Create(&ixa2, 0, XAUDIO2_DEFAULT_PROCESSOR) != S_OK) {
return SDL_SetError("XAudio2: XAudio2Create() failed at open.");
}