Skip to content

win-wasapi: Use Stable IDs for audio devices - #13903

Open
prgmitchell wants to merge 2 commits into
obsproject:masterfrom
prgmitchell:useStableID
Open

prgmitchell wants to merge 2 commits into
obsproject:masterfrom
prgmitchell:useStableID

Conversation

@prgmitchell

@prgmitchell prgmitchell commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

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

  • Tweak (non-breaking change to improve existing functionality)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

@github-project-automation github-project-automation Bot moved this to Ready For Review in 33.1 Release Tracker Sep 17, 2026
@WizardCM WizardCM added kind/bug Categorizes issue or PR as related to a bug. kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. platform/windows Categorizes issue or PR as affecting Windows specifically labels Sep 17, 2026
@prgmitchell

Copy link
Copy Markdown
Member Author

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.

Comment thread frontend/settings/OBSBasicSettings.cpp Outdated

#include <sstream>

#include <util/windows/device-enum.h>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be grouped/sorted with (just above) the utility includes above, unless @PatTheMav has different guidance.

Comment thread frontend/settings/OBSBasicSettings.cpp Outdated
Comment on lines +3363 to +3364
bfree(id);
bfree(stableId);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Free in reverse order of allocation:

Suggested change
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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes these are created with get_audio_device_ids() and use OBS's allocator so I think the returned strings need bfree()

Comment on lines +49 to +54
if (!id || !*id)
return false;
if (strcmp(id, "default") == 0) {
*device_id = bstrdup(id);
return true;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
}

Comment on lines +80 to +82
if (SUCCEEDED(hr) && value.vt == VT_LPWSTR && value.pwszVal && *value.pwszVal)
os_wcs_to_utf8_ptr(value.pwszVal, 0, stable_id);
PropVariantClear(&value);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);

Comment thread frontend/widgets/OBSBasic.cpp Outdated
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include "Windows.h"
#include <util/windows/device-enum.h>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be ordered after #include <qt-wrappers.hpp> unless @PatTheMav has other guidance.

Comment thread frontend/widgets/OBSBasic.cpp Outdated
Comment on lines +879 to +880
bfree(resolvedId);
bfree(resolvedStableId);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Free in reverse allocation order.

Comment thread plugins/win-wasapi/win-wasapi.cpp Outdated
Comment on lines +498 to +499
bfree(id);
bfree(stable_id);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Free in reverse allocation order.

@github-project-automation github-project-automation Bot moved this from Ready For Review to Requires Changes in 33.1 Release Tracker Sep 23, 2026
Store PKEY_AudioEndpoint_StableId separately and use it to recover
device selections when their normal IDs no longer resolve after Windows
or driver updates.
@PatTheMav

Copy link
Copy Markdown
Member

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

@prgmitchell

Copy link
Copy Markdown
Member Author

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.

@PatTheMav

Copy link
Copy Markdown
Member

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 PatTheMav left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good overall, don't have the means to test this on a live machine.

Only had code-style nits.

Comment thread plugins/win-wasapi/win-wasapi.cpp Outdated
Comment thread libobs/util/windows/device-enum.c Outdated
Comment thread libobs/util/windows/device-enum.c Outdated
Comment thread frontend/widgets/OBSBasic.cpp Outdated
Comment thread frontend/settings/OBSBasicSettings.cpp Outdated
@prgmitchell

Copy link
Copy Markdown
Member Author

@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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. platform/windows Categorizes issue or PR as affecting Windows specifically

Projects

Status: Requires Changes

Development

Successfully merging this pull request may close these issues.

5 participants