feat: Windows 平台支持 WASAPI 独占模式音频输出 - #233
Open
GLZ-gaoxiaoling wants to merge 1 commit into
Open
Conversation
GLZ-gaoxiaoling
force-pushed
the
wasapi-exclusive-mode
branch
from
September 4, 2026 08:55
8621ebf to
07037a3
Compare
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.
Closes #232
功能概述
为 Windows 平台实现 WASAPI 独占模式(Exclusive Mode)音频输出,绕过系统混音器,按音源采样率与位深直通声卡,实现 bit-perfect 回放。
实现要点(对应 Discussion #232 的期望行为)
1. 设置中提供音频输出模式选项
player.audioOutputMode,默认共享模式,持久化到主进程 settings.json2. 独占模式下按音源采样率与位深自动切换设备格式
native/audio-engine/src/wasapi_exclusive.rs,基于windowscrate 直接实现 WASAPI 独占客户端(复用既有依赖,未引入新包)AUDCLNT_STREAMFLAGS_EVENTCALLBACK),缓冲未对齐时按AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED重试标准流程3. 设备被占用时优雅回退共享模式并提示
AUDCLNT_E_DEVICE_IN_USE(设备被其他程序独占)或全部候选格式被拒时,自动回退共享模式继续播放outputFallback事件携带稳定分类键(deviceBusy/formatUnsupported/unavailable)逐级上报:Rust → 主进程 → 渲染端,按 i18n 弹出 toast 提示4. 应用内音量调节
其他
PlaybackHandle改为枚举分发 cpal 共享流 / WASAPI 独占流,播放控制(play/pause/音量/停止)接口不变setExclusiveMode(enabled),切换后立即重建设备输出applyConfigChange,启动时同步已保存的模式到引擎验证
cargo check/cargo clippy(audio-engine)通过(本机无 MSVC/libnode,测试运行依赖 CI Linux 环境)pnpm typecheck(node + web)、pnpm test:web(57 tests)、ESLint、Prettier 全部通过