mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-07 03:48:14 +00:00
audio: Fix SDL_GetAudioDeviceName() not working with logical devices.
Fixes #12977.
(cherry picked from commit 0a34279578
)
This commit is contained in:
@@ -1502,8 +1502,10 @@ SDL_AudioDevice *SDL_FindPhysicalAudioDeviceByHandle(void *handle)
|
|||||||
|
|
||||||
const char *SDL_GetAudioDeviceName(SDL_AudioDeviceID devid)
|
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;
|
const char *result = NULL;
|
||||||
SDL_AudioDevice *device = NULL;
|
const void *vdev = NULL;
|
||||||
|
|
||||||
if (!SDL_GetCurrentAudioDriver()) {
|
if (!SDL_GetCurrentAudioDriver()) {
|
||||||
SDL_SetError("Audio subsystem is not initialized");
|
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
|
// remains valid (in case the device is unplugged at the wrong moment), we hold the
|
||||||
// device_hash_lock while we copy the string.
|
// device_hash_lock while we copy the string.
|
||||||
SDL_LockRWLockForReading(current_audio.device_hash_lock);
|
SDL_LockRWLockForReading(current_audio.device_hash_lock);
|
||||||
SDL_FindInHashTable(current_audio.device_hash, (const void *) (uintptr_t) devid, (const void **) &device);
|
SDL_FindInHashTable(current_audio.device_hash, (const void *) (uintptr_t) devid, &vdev);
|
||||||
if (!device) {
|
if (!vdev) {
|
||||||
SDL_SetError("Invalid audio device instance ID");
|
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 {
|
} else {
|
||||||
|
const SDL_AudioDevice *device = (const SDL_AudioDevice *) vdev;
|
||||||
result = SDL_GetPersistentString(device->name);
|
result = SDL_GetPersistentString(device->name);
|
||||||
}
|
}
|
||||||
SDL_UnlockRWLock(current_audio.device_hash_lock);
|
SDL_UnlockRWLock(current_audio.device_hash_lock);
|
||||||
|
Reference in New Issue
Block a user