windows: SDL_IMMDevice needed more deinit code from the Win32 path. Fixes #5919
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
diff --git a/src/audio/wasapi/SDL_wasapi.c b/src/audio/wasapi/SDL_wasapi.c
index 5b6b821..1223611 100644
--- a/src/audio/wasapi/SDL_wasapi.c
+++ b/src/audio/wasapi/SDL_wasapi.c
@@ -45,15 +45,6 @@
#define AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM 0x80000000
#endif
-/* This is a list of device id strings we have inflight, so we have consistent pointers to the same device. */
-typedef struct DevIdList
-{
- WCHAR *str;
- struct DevIdList *next;
-} DevIdList;
-
-static DevIdList *deviceid_list = NULL;
-
/* Some GUIDs we need to know without linking to libraries that aren't available before Vista. */
static const IID SDL_IID_IAudioRenderClient = { 0xf294acfc, 0x3146, 0x4483,{ 0xa7, 0xbf, 0xad, 0xdc, 0xa7, 0xc2, 0x60, 0xe2 } };
static const IID SDL_IID_IAudioCaptureClient = { 0xc8adbd64, 0xe71e, 0x48a0,{ 0xa4, 0xde, 0x18, 0x5c, 0x39, 0x5c, 0xd3, 0x17 } };
@@ -602,17 +593,7 @@ WASAPI_ThreadDeinit(_THIS)
static void
WASAPI_Deinitialize(void)
{
- DevIdList *devidlist;
- DevIdList *next;
-
WASAPI_PlatformDeinit();
-
- for (devidlist = deviceid_list; devidlist; devidlist = next) {
- next = devidlist->next;
- SDL_free(devidlist->str);
- SDL_free(devidlist);
- }
- deviceid_list = NULL;
}
static SDL_bool
diff --git a/src/audio/wasapi/SDL_wasapi_win32.c b/src/audio/wasapi/SDL_wasapi_win32.c
index d76c803..13f05b6 100644
--- a/src/audio/wasapi/SDL_wasapi_win32.c
+++ b/src/audio/wasapi/SDL_wasapi_win32.c
@@ -68,8 +68,6 @@ WASAPI_PlatformInit(void)
void
WASAPI_PlatformDeinit(void)
{
- SDL_IMMDevice_Quit();
-
if (libavrt) {
FreeLibrary(libavrt);
libavrt = NULL;
@@ -78,7 +76,7 @@ WASAPI_PlatformDeinit(void)
pAvSetMmThreadCharacteristicsW = NULL;
pAvRevertMmThreadCharacteristics = NULL;
- WIN_CoUninitialize();
+ SDL_IMMDevice_Quit();
}
void
diff --git a/src/audio/wasapi/SDL_wasapi_winrt.cpp b/src/audio/wasapi/SDL_wasapi_winrt.cpp
index acaaf0b..a4796f3 100644
--- a/src/audio/wasapi/SDL_wasapi_winrt.cpp
+++ b/src/audio/wasapi/SDL_wasapi_winrt.cpp
@@ -62,6 +62,15 @@ extern "C" {
SDL_atomic_t SDL_IMMDevice_DefaultCaptureGeneration;
}
+/* This is a list of device id strings we have inflight, so we have consistent pointers to the same device. */
+typedef struct DevIdList
+{
+ WCHAR *str;
+ struct DevIdList *next;
+} DevIdList;
+
+static DevIdList *deviceid_list = NULL;
+
class SDL_WasapiDeviceEventHandler
{
public:
@@ -204,10 +213,20 @@ int WASAPI_PlatformInit(void)
void WASAPI_PlatformDeinit(void)
{
+ DevIdList *devidlist;
+ DevIdList *next;
+
delete playback_device_event_handler;
playback_device_event_handler = nullptr;
delete capture_device_event_handler;
capture_device_event_handler = nullptr;
+
+ for (devidlist = deviceid_list; devidlist; devidlist = next) {
+ next = devidlist->next;
+ SDL_free(devidlist->str);
+ SDL_free(devidlist);
+ }
+ deviceid_list = NULL;
}
void WASAPI_EnumerateEndpoints(void)
@@ -359,15 +378,6 @@ WaveFormatToSDLFormat(WAVEFORMATEX *waveformat)
return 0;
}
-/* This is a list of device id strings we have inflight, so we have consistent pointers to the same device. */
-typedef struct DevIdList
-{
- WCHAR *str;
- struct DevIdList *next;
-} DevIdList;
-
-static DevIdList *deviceid_list = NULL;
-
static void
WASAPI_RemoveDevice(const SDL_bool iscapture, LPCWSTR devid)
{
diff --git a/src/core/windows/SDL_immdevice.c b/src/core/windows/SDL_immdevice.c
index d626ddf..01658db 100644
--- a/src/core/windows/SDL_immdevice.c
+++ b/src/core/windows/SDL_immdevice.c
@@ -346,11 +346,23 @@ SDL_IMMDevice_Init(void)
void
SDL_IMMDevice_Quit(void)
{
+ DevIdList *devidlist;
+ DevIdList *next;
+
if (enumerator) {
IMMDeviceEnumerator_UnregisterEndpointNotificationCallback(enumerator, (IMMNotificationClient *)¬ification_client);
IMMDeviceEnumerator_Release(enumerator);
enumerator = NULL;
}
+
+ WIN_CoUninitialize();
+
+ for (devidlist = deviceid_list; devidlist; devidlist = next) {
+ next = devidlist->next;
+ SDL_free(devidlist->str);
+ SDL_free(devidlist);
+ }
+ deviceid_list = NULL;
}
int