Skip to content

Commit 0a34279

Browse files
committed
audio: Fix SDL_GetAudioDeviceName() not working with logical devices.
Fixes #12977.
1 parent e2f7c40 commit 0a34279

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/audio/SDL_audio.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,8 +1523,10 @@ SDL_AudioDevice *SDL_FindPhysicalAudioDeviceByHandle(void *handle)
15231523

15241524
const char *SDL_GetAudioDeviceName(SDL_AudioDeviceID devid)
15251525
{
1526+
// bit #1 of devid is set for physical devices and unset for logical.
1527+
const bool islogical = !(devid & (1<<1));
15261528
const char *result = NULL;
1527-
SDL_AudioDevice *device = NULL;
1529+
const void *vdev = NULL;
15281530

15291531
if (!SDL_GetCurrentAudioDriver()) {
15301532
SDL_SetError("Audio subsystem is not initialized");
@@ -1534,10 +1536,14 @@ const char *SDL_GetAudioDeviceName(SDL_AudioDeviceID devid)
15341536
// remains valid (in case the device is unplugged at the wrong moment), we hold the
15351537
// device_hash_lock while we copy the string.
15361538
SDL_LockRWLockForReading(current_audio.device_hash_lock);
1537-
SDL_FindInHashTable(current_audio.device_hash, (const void *) (uintptr_t) devid, (const void **) &device);
1538-
if (!device) {
1539+
SDL_FindInHashTable(current_audio.device_hash, (const void *) (uintptr_t) devid, &vdev);
1540+
if (!vdev) {
15391541
SDL_SetError("Invalid audio device instance ID");
1542+
} else if (islogical) {
1543+
const SDL_LogicalAudioDevice *logdev = (const SDL_LogicalAudioDevice *) vdev;
1544+
result = SDL_GetPersistentString(logdev->physical_device->name);
15401545
} else {
1546+
const SDL_AudioDevice *device = (const SDL_AudioDevice *) vdev;
15411547
result = SDL_GetPersistentString(device->name);
15421548
}
15431549
SDL_UnlockRWLock(current_audio.device_hash_lock);

0 commit comments

Comments
 (0)