Skip to main content

Module diagnostics

Module diagnostics 

Source
Expand description

M-CAM.3 / AUT-257 — runtime diagnostics for the camera pipeline.

Lives in tauri::State so the worker thread can mutate cheap atomic counters per frame without ever holding a mutex on the hot path, and the Leptos overlay can poll a snapshot via the preview_diagnostics IPC command at a much lower rate (~2 Hz).

`WindowEvent::Moved` for the bubble was already locking a mutex
per drag event and that's fine — drag is at most 60 Hz. But the
camera worker pushes 30 frames per second, and `preview_status`
polling from Leptos lands ~2 Hz. A `Mutex<Stats>` would serialise
both producer + consumer on the same lock. Atomic `u64` / `u32`
reads + writes are wait-free; the consumer just snapshots whatever
was last written without blocking the worker.

The first-received frame is also dumped to PNG (one-shot, behind a PathBuf mutex set only once) so the user has visual proof that real pixels reached Rust — see maybe_dump_first_frame.

Structs§

DiagnosticsSnapshot
Wire-format snapshot of PreviewDiagnostics. Returned by the preview_diagnostics IPC command.
PreviewDiagnostics
Tauri-managed diagnostic counters for the camera pipeline.

Functions§

bgra_to_rgba 🔒
In-place byte swap on each pixel: BGRA → RGBA. Allocates a new Vec<u8> rather than mutating in place so the worker’s frame buffer is preserved (the follow-up wisp commit will upload the same BGRA bytes to VideoTexture and benefits from byte order matching the wisp expectation).
maybe_dump_first_frame
One-shot writer: on the very first frame of each session, dump the BGRA bytes to a PNG file under the app cache dir so the user can confirm visually that real pixels reached Rust. Returns the absolute path on success; logs + returns None on encode/write failure (we don’t want a diagnostic to crash the worker).
write_bgra_as_png 🔒
Encode + write BGRA bytes as a PNG. Splits the BGRA→RGBA byte swap from the encode call so the swap itself is unit-testable.