Camera 2: Spike — camera capture on Windows: Media Foundation (#954) #973

Closed
charles wants to merge 0 commits from camera-2-spike-capture-windows into camera
Owner

Spike for Camera 2: camera capture on Windows through Media Foundation. Findings in docs/superpowers/research/2026-11-19-camera-spikes.md §2.

What was built

  • Choice: the Media Foundation source reader with NV12 output (MFEnumDeviceSources → ActivateObject → MFCreateSourceReaderFromMediaSource with MF_SOURCE_READER_ENABLE_ADVANCED_VIDEO_PROCESSING, synchronous ReadSample on a COM-initialised thread). Uses windows 0.62 with one added feature (Win32_Media_MediaFoundation), so no new crate and nokhwa is not needed. Documented fallback for Camera 11: if SetCurrentMediaType(NV12) fails for a native type, set the native NV12/YUY2/MJPG type and convert with camera::decode. The reason: MS documents MJPEG → NV12 in two parts (the reader loads a decoder, then the video processor converts), not as one statement.
  • Hot-plug: RegisterDeviceNotification (KSCATEGORY_CAPTURE + KSCATEGORY_VIDEO_CAMERA) on a message-only window, with a full re-list on any notification. If that fails, fall back to a re-list every 2 s.
  • crates/fluxer-capture/src/camera/mf_errors.rs: a pure HRESULT → MfFailure::{Busy, NotAllowed, Gone, Other} → CameraError table (classify, name, to_camera_error, is_device_lost). It compiles on every OS.
  • crates/fluxer-capture/src/camera/mod.rs: CameraError with the five variants of spec §5.2. The table needs it, so it lands here; Camera 6 builds the trait around it.
  • crates/fluxer-capture/examples/camera_probe_win.rs: list | modes <n> | capture <n> [seconds]. It writes no file and no frame. It refuses to run under FLUXER_CAMERA_FORBID=1 and prints "Windows only" on other OSes.
  • The README has a camera row and a probe section.

How it was tested

  • Unit tests (every OS): hresult_table_maps_busy_denied_gone, unknown_hresult_is_backend_error, table_has_no_duplicate_codes. Watched fail, then pass.
  • Windows-only test table_codes_are_the_sdks compares every code against the windows crate constants. It runs only on the Windows runner.
  • The Windows code (the probe and the cfg(windows) test) was type-checked and linted on Linux with cargo clippy --target x86_64-pc-windows-msvc --all-targets -D warnings in a scratch crate holding the same camera module and example. It came back clean. A deliberate type error in the Windows block was caught, which proves the block really gets checked.
  • FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci is green locally. No FLUXER_DESKTOP_TESTS were run because there are none for this task.
  • No camera was opened and the probe was not run.

Deviations

  • The probe is camera_probe_win.rs because Task 1 has not merged yet. As the plan says, whichever of the two merges later combines them.
  • CameraError is defined here, ahead of Task 6, as explained above. Strings copied from the original: none (this task has no UI).

For Charles (Windows, real camera)

Run cargo run -p fluxer-capture --example camera_probe_win -- list, then modes 0, then capture 0 5, in three situations:

  1. camera free;
  2. camera held by the Camera app;
  3. Settings → Privacy & Security → Camera → "Let desktop apps access your camera" off.

Paste the output into #954. The FAILED at <step>: 0x… <name> -> <CameraError> lines answer which HRESULT "in use" and the privacy switch really give, and at which step. Optionally, unplug the camera during capture 0 30. Spikes §2 lists what each run should show.

Closes #954

🤖 Generated with Claude Code

https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K

Spike for Camera 2: camera capture on Windows through Media Foundation. Findings in `docs/superpowers/research/2026-11-19-camera-spikes.md` §2. ## What was built - **Choice:** the Media Foundation source reader with NV12 output (`MFEnumDeviceSources` → `ActivateObject` → `MFCreateSourceReaderFromMediaSource` with `MF_SOURCE_READER_ENABLE_ADVANCED_VIDEO_PROCESSING`, synchronous `ReadSample` on a COM-initialised thread). Uses `windows` 0.62 with one added feature (`Win32_Media_MediaFoundation`), so no new crate and `nokhwa` is not needed. **Documented fallback for Camera 11:** if `SetCurrentMediaType(NV12)` fails for a native type, set the native NV12/YUY2/MJPG type and convert with `camera::decode`. The reason: MS documents MJPEG → NV12 in two parts (the reader loads a decoder, then the video processor converts), not as one statement. - **Hot-plug:** `RegisterDeviceNotification` (`KSCATEGORY_CAPTURE` + `KSCATEGORY_VIDEO_CAMERA`) on a message-only window, with a full re-list on any notification. If that fails, fall back to a re-list every 2 s. - `crates/fluxer-capture/src/camera/mf_errors.rs`: a pure HRESULT → `MfFailure::{Busy, NotAllowed, Gone, Other}` → `CameraError` table (`classify`, `name`, `to_camera_error`, `is_device_lost`). It compiles on every OS. - `crates/fluxer-capture/src/camera/mod.rs`: `CameraError` with the five variants of spec §5.2. The table needs it, so it lands here; Camera 6 builds the trait around it. - `crates/fluxer-capture/examples/camera_probe_win.rs`: `list | modes <n> | capture <n> [seconds]`. It writes no file and no frame. It refuses to run under `FLUXER_CAMERA_FORBID=1` and prints "Windows only" on other OSes. - The README has a `camera` row and a probe section. ## How it was tested - Unit tests (every OS): `hresult_table_maps_busy_denied_gone`, `unknown_hresult_is_backend_error`, `table_has_no_duplicate_codes`. Watched fail, then pass. - Windows-only test `table_codes_are_the_sdks` compares every code against the `windows` crate constants. It runs only on the Windows runner. - The Windows code (the probe and the cfg(windows) test) was type-checked and linted on Linux with `cargo clippy --target x86_64-pc-windows-msvc --all-targets -D warnings` in a scratch crate holding the same `camera` module and example. It came back clean. A deliberate type error in the Windows block was caught, which proves the block really gets checked. - `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` is green locally. No FLUXER_DESKTOP_TESTS were run because there are none for this task. - No camera was opened and the probe was not run. ## Deviations - The probe is `camera_probe_win.rs` because Task 1 has not merged yet. As the plan says, whichever of the two merges later combines them. - `CameraError` is defined here, ahead of Task 6, as explained above. Strings copied from the original: none (this task has no UI). ## For Charles (Windows, real camera) Run `cargo run -p fluxer-capture --example camera_probe_win -- list`, then `modes 0`, then `capture 0 5`, in three situations: 1. camera free; 2. camera held by the Camera app; 3. Settings → Privacy & Security → Camera → "Let desktop apps access your camera" off. Paste the output into #954. The `FAILED at <step>: 0x… <name> -> <CameraError>` lines answer which HRESULT "in use" and the privacy switch really give, and at which step. Optionally, unplug the camera during `capture 0 30`. Spikes §2 lists what each run should show. Closes #954 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K
The table maps the codes of the windows crate 0.62
(src/Windows/Win32/Media/MediaFoundation/mod.rs:45696,45860,45942-45943,45803;
Win32/Foundation/mod.rs:1298,1737,1739,1743,2355,3477,3988,4716).

Refs #954

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K
Refs #954

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K
Media Foundation source reader with NV12 output (fallback: native
samples through camera::decode); the HRESULT table; a Windows probe for
Charles to run; findings in spikes §2.

Refs #954

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K
Author
Owner

Merged into camera by hand (the merge API returns 405); the commits are in the branch.

Merged into `camera` by hand (the merge API returns 405); the commits are in the branch.
charles closed this pull request 2026-11-19 22:28:15 +00:00

Pull request closed

Sign in to join this conversation.
No description provided.