Skip to content

fix(windows): capture the configured audio sink instead of the default device - #5408

Merged
ReenigneArcher merged 3 commits into
LizardByte:masterfrom
tonyctalope:fix/windows-audio-sink-capture
Sep 1, 2026
Merged

fix(windows): capture the configured audio sink instead of the default device#5408
ReenigneArcher merged 3 commits into
LizardByte:masterfrom
tonyctalope:fix/windows-audio-sink-capture

Conversation

@tonyctalope

@tonyctalope tonyctalope commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Description

On Windows, the audio_sink setting 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 new get_sink_device() helper which handle virtual sink descriptors, device IDs, and friendly names, and checking DEVICE_STATE_ACTIVE then 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_t now 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).
  • A sink that cannot be resolved now fails capture initialization with a clear error.
  • 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):

  • Full build passes with -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). All AudioTest.TestEncode variants (stereo, 5.1, 7.1, custom 5.1) pass against real audio hardware.
  • Working properly in my sunshine environment

Note on unit tests: the changed code paths live in mic_wasapi_t / audio_control_t, which are internal to src/platform/windows/audio.cpp and require live WASAPI endpoints, so they are not reachable from the current test architecture. The existing AudioTest.TestEncode suite covers the unchanged default-device fallback path end to end.

Screenshot

Issues Fixed or Closed

Roadmap Issues

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

See our AI usage policy.

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

🤖 Generated with Claude Code

@tonyctalope
tonyctalope marked this pull request as ready for review July 13, 2026 09:37
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@ReenigneArcher ReenigneArcher added the ai PR has signs of heavy ai usage (either indicated by user or assumed) label Jul 13, 2026
tonyctalope and others added 2 commits September 1, 2026 13:01
…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>
@ReenigneArcher
ReenigneArcher force-pushed the fix/windows-audio-sink-capture branch from f15a863 to 655c7c7 Compare September 1, 2026 17:01
@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Bundle Report

Bundle 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.
@ReenigneArcher
ReenigneArcher force-pushed the fix/windows-audio-sink-capture branch from 2f26912 to 70c25b5 Compare September 1, 2026 18:24
@sonarqubecloud

sonarqubecloud Bot commented Sep 1, 2026

Copy link
Copy Markdown

@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.15663% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 34.55%. Comparing base (c59469b) to head (70c25b5).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/platform/windows/audio.cpp 89.15% 0 Missing and 9 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
Archlinux 0.00% <ø> (ø)
FreeBSD-amd64 19.74% <ø> (-0.01%) ⬇️
Homebrew-macos-14 31.11% <ø> (?)
Homebrew-macos-15 31.77% <ø> (ø)
Homebrew-macos-26 31.87% <ø> (-0.02%) ⬇️
Homebrew-ubuntu-24.04 20.99% <ø> (ø)
Linux-AppImage 20.41% <ø> (+0.03%) ⬆️
Windows-AMD64 27.04% <88.15%> (+1.02%) ⬆️
Windows-ARM64 22.79% <60.97%> (?)
macOS-arm64 25.98% <ø> (ø)
macOS-x86_64 26.62% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/platform/windows/audio.cpp 49.05% <89.15%> (+23.91%) ⬆️

... and 51 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c59469b...70c25b5. Read the comment docs.

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

Labels

ai PR has signs of heavy ai usage (either indicated by user or assumed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audio Sink (explicit device ID) ignored and capture only works if the device is set as Windows default

2 participants