Skip to content

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

Open
tonyctalope wants to merge 2 commits into
LizardByte:masterfrom
tonyctalope:fix/windows-audio-sink-capture
Open

fix(windows): capture the configured audio sink instead of the default device#5408
tonyctalope wants to merge 2 commits into
LizardByte:masterfrom
tonyctalope:fix/windows-audio-sink-capture

Conversation

@tonyctalope

@tonyctalope tonyctalope commented Jul 13, 2026

Copy link
Copy Markdown

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

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