Phase 1: V4L2/MJPEG camera path to fullscreen SDL3 output

A small live-video-to-display appliance for the church stream machine,
replacing MPV/GStreamer for two fixed jobs. This lands job 1 end to end and
scaffolds job 2.

Pipeline: V4L2 mmap capture -> TurboJPEG decode to YUV planes -> interleave to
packed YUY2 -> SDL3 streaming texture -> borderless fullscreen on a chosen
Wayland output. The GPU does the colour conversion, so no CPU matrix multiply
and half the upload bandwidth of RGBA.

Latency is managed by dropping, never queueing: the driver queue is drained to
its newest buffer each wakeup, and a one-deep slot between the input thread and
the renderer discards any frame the renderer has not taken.

Dependency tree is two crates (sdl3-sys, libc). V4L2 and TurboJPEG are
hand-written FFI; the V4L2 struct layouts were taken from the target kernel's
headers and are pinned by compile-time assertions.

Three hardware behaviours found while validating against the real ATEM:

* /dev/video1 is a metadata node with no formats, so MJPEG on /dev/video0 is
  the only path on this hardware.
* The ATEM pads frames with a few bytes before the EOI marker. libjpeg warns,
  and TurboJPEG returns -1 for a warning as well as a failure, so the first
  cut rejected ~97% of frames. Warnings are now distinguished from failures
  via tj3GetErrorCode, with a structural SOI/EOI check to still catch
  genuinely truncated frames.
* On KDE Wayland, SDL reports monitor model names, not connector names.

Also fixes sticky libjpeg error state, where one corrupt frame would latch an
error and fail every valid frame after it.

87 tests. Verified on the real ATEM: sustained 30.0 fps, 0 undecodable frames,
0 frames dropped before display, ~33% of one core.
This commit is contained in:
Claude
2026-08-29 15:55:37 -05:00
commit 4b7ab4f10a
27 changed files with 5232 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
[package]
name = "video-output"
version = "0.1.0"
edition = "2021"
rust-version = "1.82"
description = "Minimal live-video-to-display appliance: V4L2/MJPEG and NDI sources rendered fullscreen on a chosen output."
license = "MIT"
publish = false
[lib]
name = "video_output"
path = "src/lib.rs"
[[bin]]
name = "video-output"
path = "src/main.rs"
[dependencies]
libc = "0.2"
sdl3-sys = "0.6"
[profile.release]
opt-level = 3
lto = "thin"
codegen-units = 1
strip = true