win-wasapi: Use Stable IDs for audio devices - #13903
prgmitchell wants to merge 2 commits into
Conversation
eed7671 to
b54247c
Compare
|
realized there was a backwards compatibility issue I didn't consider, updated the PR to clean up a bit and allow for someone to downgrade OBS without issues. |
|
|
||
| #include <sstream> | ||
|
|
||
| #include <util/windows/device-enum.h> |
There was a problem hiding this comment.
This should be grouped/sorted with (just above) the utility includes above, unless @PatTheMav has different guidance.
| bfree(id); | ||
| bfree(stableId); |
There was a problem hiding this comment.
Free in reverse order of allocation:
| bfree(id); | |
| bfree(stableId); | |
| bfree(stableId); | |
| bfree(id); |
I don't think you actually have to use bfree() with char * not allocated via our memory allocation functions. However, I think these have allocations inside get_audio_device_ids()? Is that correct?
There was a problem hiding this comment.
yes these are created with get_audio_device_ids() and use OBS's allocator so I think the returned strings need bfree()
| if (!id || !*id) | ||
| return false; | ||
| if (strcmp(id, "default") == 0) { | ||
| *device_id = bstrdup(id); | ||
| return true; | ||
| } |
There was a problem hiding this comment.
| if (!id || !*id) | |
| return false; | |
| if (strcmp(id, "default") == 0) { | |
| *device_id = bstrdup(id); | |
| return true; | |
| } | |
| if (!id || !*id) | |
| return false; | |
| if (strcmp(id, "default") == 0) { | |
| *device_id = bstrdup(id); | |
| return true; | |
| } |
| if (SUCCEEDED(hr) && value.vt == VT_LPWSTR && value.pwszVal && *value.pwszVal) | ||
| os_wcs_to_utf8_ptr(value.pwszVal, 0, stable_id); | ||
| PropVariantClear(&value); |
There was a problem hiding this comment.
| if (SUCCEEDED(hr) && value.vt == VT_LPWSTR && value.pwszVal && *value.pwszVal) | |
| os_wcs_to_utf8_ptr(value.pwszVal, 0, stable_id); | |
| PropVariantClear(&value); | |
| if (SUCCEEDED(hr) && value.vt == VT_LPWSTR && value.pwszVal && *value.pwszVal) | |
| os_wcs_to_utf8_ptr(value.pwszVal, 0, stable_id); | |
| PropVariantClear(&value); |
| #ifdef _WIN32 | ||
| #define WIN32_LEAN_AND_MEAN | ||
| #include "Windows.h" | ||
| #include <util/windows/device-enum.h> |
There was a problem hiding this comment.
This should be ordered after #include <qt-wrappers.hpp> unless @PatTheMav has other guidance.
| bfree(resolvedId); | ||
| bfree(resolvedStableId); |
There was a problem hiding this comment.
Free in reverse allocation order.
| bfree(id); | ||
| bfree(stable_id); |
There was a problem hiding this comment.
Free in reverse allocation order.
Store PKEY_AudioEndpoint_StableId separately and use it to recover device selections when their normal IDs no longer resolve after Windows or driver updates.
b54247c to
05cab29
Compare
|
Please avoid using force pushes during reviews and leave resolution of review comments to the reviewer per our contribution guidelines: https://github.com/obsproject/obs-studio/blob/master/CONTRIBUTING.md#pull-request-review-guidelines |
sorry, didn't realize these guidelines were updated last month. |
No problem, just a reminder that those changed. |
PatTheMav
left a comment
There was a problem hiding this comment.
Seems good overall, don't have the means to test this on a live machine.
Only had code-style nits.
25ca396 to
af6dbb2
Compare
|
@PatTheMav made the changes based on your comments and pushed as a separate commit to squash later, let me know if I misunderstood anything please. |


Description
Store PKEY_AudioEndpoint_StableId separately and use it to recover device selections when their normal IDs no longer resolve after Windows or driver updates. This functionality is only available on Windows 11 24H2 and later. Related docs here.
Edited this to simplify into one helper and also properly handle backwards compatibility. My original approach allowed devices to continue to work after downgrading but the UI would not reflect this properly, this now stores both stable ID and the existing ID used.
Motivation and Context
Audio devices (input, output, monitoring) often break after windows or driver updates because it assigns a new device ID. PKEY_AudioEndpoint_StableId is meant to fix this.
How Has This Been Tested?
Tested various scenarios including ID migration, confirmation that manually editing the basic.ini file to use the previous ID still resolves back to the same device and it doesn't need to be selected, and even had a driver update I was able to do for one set of devices that reset the ID but maintained the stableId. Further testing needed though from others.
Types of changes
Checklist: