Screen share 3: fluxer-capture crate — traits, model types, fake backend (#150) #190
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "screenshare-3-capture-crate"
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?
Stacked on: screenshare-1-video-frames
What this builds
New crate
crates/fluxer-capture(Screen share plan Task 3, spec §4, §7.1, §9):source:SourceKind::{Screen, Window, SystemPicker},CaptureSource { id, kind, title, app_name, pid, thumbnail },SourceChoice::{Source(String), SystemPicker},CaptureTarget { max_width, max_height, fps }, 480x270 thumbnail constants.screen:trait ScreenCapturer: Send(capabilities,list_sources,start,switch,update,stop),CaptureCapabilities { in_app_picker, window_audio },CaptureOutput::{Frame, Started, Stalled, Resumed, Ended(EndReason), Error},STALL_AFTER= 3 s, plusStallDetectorandPacer(shared stall detection and absolute-deadline pacing for the real backends of Tasks 4/5).audio:trait StreamAudioCapturer: Send(start(&AudioRule, exclude_pid_tree, sink),set_rule,stop),StreamAudioFrame { samples, channels: 2 }(10 ms, 48 kHz),AudioRulewith the original's defaults (VoiceSettings.ts: System, only_speakers, only_default_speakers, ignore_devices, ignore_input_media all true, ignore_virtual false),AudioMode::{System, Applications(Vec<AppMatch>)},AppMatch::{Pid, Name, Binary}.error:CaptureError::{Unsupported, SourceNotFound, AlreadyStarted, Cancelled, Backend}.fake(featurefake):FakeScreenCapturer(test pattern at the target size and rate, thumbnails, switch/update on the fly),FakeAudioCapturer(440 Hz stereo tone, clock-driven 10 ms frames),FakeCaptureControl(sources, capabilities, picker cancel, stall/resume, scripted end; inspection of current source, target, audio rule, excluded pid).default_backends()returnsUnsupportedstubs on every OS until Tasks 4/5/14/15.Depends only on
fluxer-videoandthiserror(nofluxer-core, nolivekit).How it was tested
tests/fake.rs(10 tests): the plan's seven (fake_delivers_frames_at_target_rate_and_size,fake_switch_changes_source_without_ended,scripted_end_is_reported_once,stall_and_resume_after_3s_without_frames,stop_is_idempotent,fake_audio_delivers_10ms_stereo_frames,unsupported_backends_return_errors) plusfake_lists_screens_and_windows_with_optional_thumbnails,start_with_unknown_source_is_an_error,audio_rule_defaults_match_the_original. Unit tests forStallDetectorandPacer.stop_is_idempotentwas found and fixed).FLUXER_SCREENSHOT_TESTS=1 cargo xtask cigreen locally (Linux). No real-device tests belong to this task.Deviations / decisions for the reviewer
EndReasonbut not its variants: choseSourceClosed,SessionEnded,Cancelled.AppMatchvariants beyondPid(Task 15) areNameandBinaryfor the PipeWire matcher (Task 14).CaptureErrorvariants are my choice.StreamAudioCapturer::start/set_ruleandScreenCapturer::starttake&AudioRule/&SourceChoiceby reference.channelsisu16(always 2).Cargo.tomlneeded no edit:members = ["crates/*"]already covers the new crate.Closes #150
🤖 Generated with Claude Code
Independent review: Screen share 3 (capture crate),
d821f19Scope:
git diff 8b8a359..origin/screenshare-3-capture-crate(the crate, its tests, README and Cargo.lock).Checks
tests/fake.rsand assert what the plan says. Rate and size are checked at 640x360@30 (25 to 35 frames) and afterupdateat 320x180@10. A switch produces noEndedorError. A scripted end is reported once and nothing follows it.STALL_AFTER == 3 s:Stalledcomes in the 2.9 to 4 s window, thenResumedbefore the next frame.stopcan be called twice, the sink is dropped (the channel disconnects), and dropping the capturer stops it. Fake audio is 480x2 samples per frame at 48 kHz with a 440 Hz tone that is identical on both channels. TheUnsupportedstubs return errors and never panic. There are 3 more tests (thumbnails are 480x270, an unknown source returnsSourceNotFound, andAudioRuledefaults), plus unit tests forStallDetectorandPacer.SourceKind,CaptureSource,CaptureTarget,ScreenCapturer(all 6 methods),SourceChoice,CaptureOutput,AudioRule,StreamAudioFrame,StreamAudioCapturer::start(rule, exclude_pid_tree: u32, sink)/set_rule/stop,FakeScreenCapturer/FakeAudioCapturer/FakeCaptureControlbehind featurefake, anddefault_backends().AppMatch::Pidexists for Task 15. I checked theAudioRuledefaults against the fork'sVoiceSettings.ts:491-497. They match: System, true, true, true, true, ignore_virtual=false.fluxer-video(path) andthiserror. There is nofluxer-core,livekitorlibwebrtc, and no OS library. Thefakefeature is not on by default and is only enabled for dev-dependencies. There are no secrets in the code or the fixtures, and no server data flows through this crate.cargo xtask ciin the review worktree is green ("all steps passed"). All 10 tests intests/fake.rspass in 3.5 s.Findings
src/fake.rs/ README: whenupdatechanges the size, the fake does not send a newStarted. The README contract says "Started { width, height }comes first, then frames of that size". Consumers (Task 16VideoFrameInfo, Task 21) therefore have to take the size from each frame. Suggestion: say in the README that the size can change afterupdate, and thatFrame.width/heightis the authority.src/fake.rsstop(): this joins the capture thread. If someone callsstopfrom inside the sink (on the capture thread), the thread would try to join itself. The trait docs say the sink must not block, but they do not explicitly forbid callingstoporswitchfrom the sink. A single doc line onCaptureSinkwould close this off for Tasks 4, 5 and 21.tests/fake.rs: the rate assertions depend on wall-clock timing (25 to 35 fps, 40 to 60 audio frames in 500 ms). They passed here. If the shared Windows runner turns out to be flaky, widen the windows rather than retrying.No blocking findings.
Verdict: APPROVE. The interfaces match the plan, the invariants hold and local CI is green. The remote runners were not checked by this review.
🤖 Generated with Claude Code