fix(windows): capture the configured audio sink instead of the default device#5408
Open
tonyctalope wants to merge 2 commits into
Open
fix(windows): capture the configured audio sink instead of the default device#5408tonyctalope wants to merge 2 commits into
tonyctalope wants to merge 2 commits into
Conversation
…t device On Windows, the audio sink setting only switched the Windows default render device via IPolicyConfig::SetDefaultEndpoint, while WASAPI capture was always initialized against the default endpoint. Capture therefore silently recorded the wrong device whenever the default was not (or no longer) the configured sink: - the assigned sink is only applied by the first session of an audio context, so later sessions captured whatever the default happened to be - when the default device changed mid-session, capture followed the new default; the switch-back callback is only registered for virtual sinks Resolve the assigned (or configured) sink to its endpoint and open the loopback capture on that device directly, falling back to the default render device when no sink is set. When capture is pinned to an explicit sink, default-device change notifications no longer trigger a capture reinit, and a sink that cannot be resolved now fails capture initialization (retried by the session) instead of silently recording another device. Fixes LizardByte#4865 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
tonyctalope
marked this pull request as ready for review
July 13, 2026 09:37
Addresses SonarQube finding cpp:S6004. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
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.



Description
On Windows, the
audio_sinksetting never selected the device that gets captured. WASAPI capture was always initialized against the default render endpoint.Changes
audio_control_t::microphone()now resolves the assigned (or configured) sink to its endpoint via a newget_sink_device()helper which handle virtual sink descriptors, device IDs, and friendly names, and checkingDEVICE_STATE_ACTIVEthen it opens the WASAPI loopback capture on that device directly. It falls back to the default render device when no sink is set.mic_wasapi_tnow tracks whether capture follows the default device. When capture is pinned to an explicitly requested sink, default-device change notifications no longer trigger a capture reinit (the virtual-sink switch-back callback still runs).set_sink()behavior (switching the Windows default to the sink at session start) is intentionally unchanged, to avoid breaking existing setups that rely on applications following the default device.Validation
Built and tested on Windows 11 25H2 with the officially supported toolchain (MSYS2/ucrt64,
-DBUILD_WERROR=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo):-Werror(no new warnings).test_sunshine: 336 passed / 0 failed (5 skipped: mouse/HID and external-command tests, which cannot run in a non-interactive SSH session). AllAudioTest.TestEncodevariants (stereo, 5.1, 7.1, custom 5.1) pass against real audio hardware.Note on unit tests: the changed code paths live in
mic_wasapi_t/audio_control_t, which are internal tosrc/platform/windows/audio.cppand require live WASAPI endpoints, so they are not reachable from the current test architecture. The existingAudioTest.TestEncodesuite covers the unchanged default-device fallback path end to end.Screenshot
Issues Fixed or Closed
Roadmap Issues
Type of Change
Checklist
AI Usage
See our AI usage policy.
🤖 Generated with Claude Code