Browse Source

audio: Fix SDL_GetAudioDeviceName() not working with logical devices.

Fixes #12977.

(cherry picked from commit 0a34279578a2cce104efc0d605cd5a51ece25e95)
Ryan C. Gordon 4 tháng trước cách đây
mục cha
commit
01ef4c46a1
1 tập tin đã thay đổi với 9 bổ sung3 xóa
  1. 9 3
      src/audio/SDL_audio.c

+ 9 - 3
src/audio/SDL_audio.c

@@ -1502,8 +1502,10 @@ SDL_AudioDevice *SDL_FindPhysicalAudioDeviceByHandle(void *handle)
 
 const char *SDL_GetAudioDeviceName(SDL_AudioDeviceID devid)
 {
+    // bit #1 of devid is set for physical devices and unset for logical.
+    const bool islogical = !(devid & (1<<1));
     const char *result = NULL;
-    SDL_AudioDevice *device = NULL;
+    const void *vdev = NULL;
 
     if (!SDL_GetCurrentAudioDriver()) {
         SDL_SetError("Audio subsystem is not initialized");
@@ -1513,10 +1515,14 @@ const char *SDL_GetAudioDeviceName(SDL_AudioDeviceID devid)
         // remains valid (in case the device is unplugged at the wrong moment), we hold the
         // device_hash_lock while we copy the string.
         SDL_LockRWLockForReading(current_audio.device_hash_lock);
-        SDL_FindInHashTable(current_audio.device_hash, (const void *) (uintptr_t) devid, (const void **) &device);
-        if (!device) {
+        SDL_FindInHashTable(current_audio.device_hash, (const void *) (uintptr_t) devid, &vdev);
+        if (!vdev) {
             SDL_SetError("Invalid audio device instance ID");
+        } else if (islogical) {
+            const SDL_LogicalAudioDevice *logdev = (const SDL_LogicalAudioDevice *) vdev;
+            result = SDL_GetPersistentString(logdev->physical_device->name);
         } else {
+            const SDL_AudioDevice *device = (const SDL_AudioDevice *) vdev;
             result = SDL_GetPersistentString(device->name);
         }
         SDL_UnlockRWLock(current_audio.device_hash_lock);