fix(windows): capture the configured audio sink instead of the default device - #5408
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>
Addresses SonarQube finding cpp:S6004. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
f15a863 to
655c7c7
Compare
Bundle ReportBundle size has no change ✅ |
This change adds a shared sink-selection helper so the assigned capture sink takes precedence over the configured sink when present. It also centralizes the Windows endpoint lookup and covers the default-device-change handling with focused unit tests for sink resolution and reinit behavior.
2f26912 to
70c25b5
Compare
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5408 +/- ##
==========================================
+ Coverage 33.82% 34.55% +0.72%
==========================================
Files 102 104 +2
Lines 24639 25314 +675
Branches 10900 11194 +294
==========================================
+ Hits 8335 8748 +413
+ Misses 14309 12890 -1419
- Partials 1995 3676 +1681
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 51 files with indirect coverage changes Continue to review full report in Codecov by Harness.
|



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