Screen share 15: Windows stream audio capture (WASAPI process loopback) (#162) #199
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "screenshare-15-audio-capture-windows"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
fluxer_capture::wasapi(spec §9, Windows):WasapiAudioCapturer: StreamAudioCaptureron WASAPI process loopback, ported from the fork'sfluxer_desktop/native/win-process-loopback(activation, format negotiation, packet loop, kernel32 build check, process-tree walk) with an AGPL attribution header, without napi, the sample pool or the session mixer.AudioMode::System→PROCESS_LOOPBACK_MODE_EXCLUDE_TARGET_PROCESS_TREEonexclude_pid_tree(the client never hears itself).AudioMode::Applications→INCLUDE_TARGET_PROCESS_TREEon the firstAppMatch::Pid; a pid in the client's own tree is refused, a rule without a pid isUnsupported.FrameAssembler→ exactly 10 msi16frames, whatever the packet sizes; silent packets are zeros.supported()/unsupported_reason(): kernel32 build ≥ 20348 (PROCESS_LOOPBACK_MIN_BUILD), cached; always unsupported off Windows (the module compiles everywhere so the unit tests run on the Linux runner).startblocks until the stream runs or fails (activation timeout 5 s →Backend, e.g. no audio service on Server Core);set_ruleon a running session reopens it with the same sink;stopis idempotent and joins the thread; drop stops.default_backends()returns it on Windows when supported, elseUnsupported(reason).Tests
pcm16_and_f32_convert_to_i16_frames,frames_are_exactly_10ms, plussystem_mode_excludes_the_given_tree,application_mode_includes_the_first_pid_tree_never_our_own,pid_tree_walk_survives_cycles_and_gaps,support_follows_the_build. Seen failing against stubbed converter/assembler, then passing.tests/wasapi_real.rs::server_core_without_audio_is_an_error_not_a_panic(runs on both runners).FLUXER_CAPTURE_TESTS=1, Windows only):system_mode_hears_other_process_not_self,application_mode_hears_only_target— tones from WAV files, the other processes started through WMI so they are not our descendants, Goertzel detection. Not run: no Windows desktop available to the implementer (Linux machine). They compile and pass clippy forx86_64-pc-windows-msvc(cargo clippy --target x86_64-pc-windows-msvc -p fluxer-capture --all-targets -- -D warnings).FLUXER_SCREENSHOT_TESTS=1 cargo xtask cigreen locally (Linux).Deviations
windows-core0.62 added next towindows0.62 (the#[implement]macro of the activation completion handler expands to::windows_corepaths; same version family, already in the graph via cpal).Win32_Securityfeature is needed forCreateEventW.tests/fake.rs::unsupported_backends_return_errors(Task 3's file): the stream-audio half is skipped on Windows when process loopback is supported, sincedefault_backends()now returns the real backend there.StreamAudioCapturer; a mid-session WASAPI failure just ends the frames. The capture thread does not raise its priority (the fork uses its rt-thread helper).Claude Fable 5.2line inCLAUDE.md.Stacked on: screenshare-3-capture-crate
Closes #162
🤖 Generated with Claude Code
Independent review: Screen share 15 (Windows stream audio, WASAPI process loopback)
Reviewed
d821f19..9cbb0b4cold; the implementer's notes were checked against the code.Checks
pcm16_and_f32_convert_to_i16_framesandframes_are_exactly_10ms(unit, insrc/wasapi/mod.rs) check clamping, the 32767 scale, NaN as silence, PCM pass-through, 960-sample (480 × 2) frames across awkward packet lengths, and that nothing is lost or reordered.server_core_without_audio_is_an_error_not_a_panicruns on CI.system_mode_hears_other_process_not_selfandapplication_mode_hears_only_targetsit behindFLUXER_CAPTURE_TESTS=1(Goertzel on 440/1000 Hz tones, players started through WMI so they fall outside our tree). There are also extra unit tests for the target rules, the pid-tree walk and the build gate.WasapiAudioCapturer: StreamAudioCapturer(start/set_rule/stop with Task 3's merged signatures) andwasapi::supported() -> boolare present.unsupported_reason()andPROCESS_LOOPBACK_MIN_BUILD = 20_348are additive.default_backends()keeps its signature and returns WASAPI on supported Windows.windows/windows-core0.62, target-gated tocfg(windows)(the version cpal already locks; Cargo.lock adds no new package). It has no fluxer-core or livekit dependency, no libwebrtc types, and no public signature exposes a Windows type. No secrets.PROCESS_LOOPBACK_MODE_EXCLUDE_TARGET_PROCESS_TREEonexclude_pid_tree. Application mode uses INCLUDE on the picked pid and refuses any pid inside our own tree (snapshot walk, safe against cycles). This matches spec §9 and the fork (lib.rs:1129-1245,1391-1487). The retry HRESULTs (0x80040155/0x80070002/0x80070490), the backoff and the float→PCM16 fallback are faithful ports. The unsafe code holds up: the PROPVARIANT VT_BLOB is inManuallyDropsoPropVariantClearnever frees the stack params; the handler isIAgileObjectand the result goes throughArc<Completion>+ Mutex + event, so a late completion after the 5 s timeout writes into memory that is still alive; COM objects drop beforeCoUninitialize; buffers are released with their own frame count.Send/SynconCompletionis justified: the IAudioClient comes from the MTA and is consumed on an MTA thread.FLUXER_SCREENSHOT_TESTS=1 cargo xtask ciin the review worktree passed ("all steps passed").cargo clippy -p fluxer-capture --all-targets --target x86_64-pc-windows-msvc -- -D warningsis clean too. I did not check the remote Windows runner.Findings
FLUXER_CAPTURE_TESTS=1 cargo test -p fluxer-capture --test wasapi_real -- --test-threads=1on a Win10 20348+/Win11 desktop. Suggest afollow-upissue linked from this PR, or putting it on the Screen share 31 acceptance checklist.server_core_without_audio_is_an_error_not_a_panicasserts no error whensupported()is true (for example, a Server 2022 runner is build 20348). On such a runner it only proves "no panic, and AlreadyStarted while running". That is acceptable, but the name promises more. If activation can hang, start() also blocks the test for up to 5 s.set_rulecompares the wholeAudioRule. In System mode, a change to only the Linux-only flags (only_speakers,ignore_*) tears down the loopback stream and reopens it, which causes a short gap in stream audio for no effect. Comparing theLoopbackTargetinstead would avoid that.set_rule, the session is gone and the caller getsErr, while the sink has been dropped. That is consistent with the trait, which has no error channel, but Screen share 21 must treatset_ruleErr as "stream audio ended".C:\Windows\System32(same as the fork,lib.rs:797). On a Windows installed elsewhere,supported()is false and the reason is a clear message, so nothing panics.No blocking findings.
Verdict: APPROVE. No blocking findings and local CI is green. Please open a follow-up for the unrun real-device tests.