audio: Added SDL_GetAudioDeviceProperties() and a unique-id property for it. - #16341
Merged
Merged
Conversation
Collaborator
Author
|
Debated doing this as an optional property, but we'd still have to add an API for that, since we don't have an SDL_GetAudioDeviceProperties() function at the moment (and do logical and physical devices have separate properties? etc). But I'm not against making that change, or even just renaming the new wordy function. |
Collaborator
|
This does seem like a perfect opportunity for properties |
Collaborator
Author
|
Okay, pivoting! The specific changes are in 881f46d, but I'm squashing this down to remove the original API now. |
…for it. In addition to adding properties to audio devices, the new property, `SDL_PROP_AUDIO_DEVICE_UNIQUE_ID_STRING`, allows a best-effort option to find the same specific audio device used on a previous run of a program, even in an imperfect way. Most backends don't support this, but CoreAudio on macOS and IMMDevice on Windows can. coreaudio: Rework device enumeration queries, acquire unique_id. - No longer keeps multiple AudioObjectPropertyAddress objects, just change the selector for each query. - Move string retrieval for AudioObjectProperties off to a separate function. - Query for unique_id. - If a device name is blank, don't reject the device, try to come up with a name of some sort (either the unique_id or "Unnamed audio device"). windows: Add unique audio device identifiers to IMMDevice support. This uses the new "StableId" property on Windows 11 if available, and the device id (IMMDevice::GetId()) otherwise. Microsoft claims that GetId() remains valid between reboots and even disconnecting and reconnecting the audio device (although I am dubious that is universally true when plugging into a different USB port, etc), but driver and OS updates might change the identifier. StableId goes further, promising that software updates won't change it, either. This adds support to our WASAPI and DirectSound backends, if you're on at least Windows Vista. Windows XP will not offer a unique ID for devices. Fixes libsdl-org#16258.
icculus
force-pushed
the
sdl3-audio-guids
branch
from
September 18, 2026 17:52
881f46d to
9305915
Compare
slouken
approved these changes
Sep 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(EDIT: this was the original text, but this now offers audio device properties instead of an API for specifically this one thing.)
This allows a best-effort option to find the same specific audio device used on a previous run of a program, even in an imperfect way. Most backends don't support this, but CoreAudio on macOS and IMMDevice on Windows can.
coreaudio: Rework device enumeration queries, acquire unique_id.
windows: Add unique audio device identifiers to IMMDevice support.
This uses the new "StableId" property on Windows 11 if available, and the device id (IMMDevice::GetId()) otherwise.
Microsoft claims that GetId() remains valid between reboots and even disconnecting and reconnecting the audio device (although I am dubious that is universally true when plugging into a different USB port, etc), but driver and OS updates might change the identifier. StableId goes further, promising that software updates won't change it, either.
This adds support to our WASAPI and DirectSound backends, if you're on at least Windows Vista. Windows XP will not offer a unique ID for devices.
Fixes #16258.