summaryrefslogtreecommitdiff
path: root/Source/3rdParty/SDL2/src/audio/wasapi/SDL_wasapi_win32.c
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-01-31 18:38:35 +0800
committerchai <chaifix@163.com>2019-01-31 18:38:35 +0800
commit2ec55fd974a63b705a4777c256d2222c874fa043 (patch)
tree48f1fea59ee9fc713a28a9aac3f05b98dc5ae66f /Source/3rdParty/SDL2/src/audio/wasapi/SDL_wasapi_win32.c
parentc581dfbf1e849f393861d15e82aa6446c0c1c310 (diff)
*SDL project
Diffstat (limited to 'Source/3rdParty/SDL2/src/audio/wasapi/SDL_wasapi_win32.c')
-rw-r--r--Source/3rdParty/SDL2/src/audio/wasapi/SDL_wasapi_win32.c68
1 files changed, 54 insertions, 14 deletions
diff --git a/Source/3rdParty/SDL2/src/audio/wasapi/SDL_wasapi_win32.c b/Source/3rdParty/SDL2/src/audio/wasapi/SDL_wasapi_win32.c
index 8b55582..9d7c159 100644
--- a/Source/3rdParty/SDL2/src/audio/wasapi/SDL_wasapi_win32.c
+++ b/Source/3rdParty/SDL2/src/audio/wasapi/SDL_wasapi_win32.c
@@ -351,10 +351,42 @@ WASAPI_ActivateDevice(_THIS, const SDL_bool isrecovery)
}
+typedef struct
+{
+ LPWSTR devid;
+ char *devname;
+} EndpointItem;
+
+static int sort_endpoints(const void *_a, const void *_b)
+{
+ LPWSTR a = ((const EndpointItem *) _a)->devid;
+ LPWSTR b = ((const EndpointItem *) _b)->devid;
+ if (!a && b) {
+ return -1;
+ } else if (a && !b) {
+ return 1;
+ }
+
+ while (SDL_TRUE) {
+ if (*a < *b) {
+ return -1;
+ } else if (*a > *b) {
+ return 1;
+ } else if (*a == 0) {
+ break;
+ }
+ a++;
+ b++;
+ }
+
+ return 0;
+}
+
static void
WASAPI_EnumerateEndpointsForFlow(const SDL_bool iscapture)
{
IMMDeviceCollection *collection = NULL;
+ EndpointItem *items;
UINT i, total;
/* Note that WASAPI separates "adapter devices" from "audio endpoint devices"
@@ -369,22 +401,36 @@ WASAPI_EnumerateEndpointsForFlow(const SDL_bool iscapture)
return;
}
+ items = (EndpointItem *) SDL_calloc(total, sizeof (EndpointItem));
+ if (!items) {
+ return; /* oh well. */
+ }
+
for (i = 0; i < total; i++) {
+ EndpointItem *item = items + i;
IMMDevice *device = NULL;
if (SUCCEEDED(IMMDeviceCollection_Item(collection, i, &device))) {
- LPWSTR devid = NULL;
- if (SUCCEEDED(IMMDevice_GetId(device, &devid))) {
- char *devname = GetWasapiDeviceName(device);
- if (devname) {
- WASAPI_AddDevice(iscapture, devname, devid);
- SDL_free(devname);
- }
- CoTaskMemFree(devid);
+ if (SUCCEEDED(IMMDevice_GetId(device, &item->devid))) {
+ item->devname = GetWasapiDeviceName(device);
}
IMMDevice_Release(device);
}
}
+ /* sort the list of devices by their guid so list is consistent between runs */
+ SDL_qsort(items, total, sizeof (*items), sort_endpoints);
+
+ /* Send the sorted list on to the SDL's higher level. */
+ for (i = 0; i < total; i++) {
+ EndpointItem *item = items + i;
+ if ((item->devid) && (item->devname)) {
+ WASAPI_AddDevice(iscapture, item->devname, item->devid);
+ }
+ SDL_free(item->devname);
+ CoTaskMemFree(item->devid);
+ }
+
+ SDL_free(items);
IMMDeviceCollection_Release(collection);
}
@@ -405,12 +451,6 @@ WASAPI_PlatformDeleteActivationHandler(void *handler)
SDL_assert(!"This function should have only been called on WinRT.");
}
-void
-WASAPI_BeginLoopIteration(_THIS)
-{
- /* no-op. */
-}
-
#endif /* SDL_AUDIO_DRIVER_WASAPI && !defined(__WINRT__) */
/* vi: set ts=4 sw=4 expandtab: */