feat(media): shade live images — a webcam, a slideshow or a watched folder, end to end

Pictures were a live content type the watch page could show but nothing
could publish. `shade live images`:
- stdin: back-to-back JPEG/PNG, e.g.
  `ffmpeg -f v4l2 -i /dev/video0 -r 1 -c:v mjpeg -f image2pipe -`;
- files/directories: a slideshow, one picture every --every seconds;
- --watch DIR: each new picture once its size holds still (cameras
  write in pieces).
Each picture is a keyframe, so a late viewer opens on the latest. The meta
carries the first picture's type (MIME_RE rightly refuses image/*).

ImageStreamSplitter walks JPEG markers (lengths to SOS, then the
entropy-coded data, where every 0xFF is stuffed) and PNG chunks to IEND,
so an EXIF thumbnail — a whole JPEG inside APP1 — does not end a picture.
Bounded at 16 MiB per picture, junk refused at its first bytes.

The Android demo shows live picture channels and sealed pictures
(decoded off the UI thread, downsampled to the screen).

Verified: splitter on real ffmpeg MJPEG/PNG under random pipe chunking,
the thumbnail case, truncation, junk and the size cap (4 tests); in
Chromium a 2 fps MJPEG "webcam" through the relay (8 → 14 pictures in 3 s,
960×540); a watched folder with a PNG written in two halves (sent once,
whole) and a .txt ignored; slideshow; error paths. Demo APK builds; not
run on a device (none connected).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-10-18 22:53:37 +02:00
parent 1653060494
commit d87db5f4dc
9 changed files with 436 additions and 10 deletions

View File

@@ -66,6 +66,10 @@ New package **`@shade/media`** — see `docs/media.md`.
`PostgresLivePinStore`, `createSharedMediaBackend` in
`@shade/storage-postgres`. A live pin can no longer change key, even between
instances (`LivePinTakenError`).
- **`shade live images`.** A channel of pictures: JPEG/PNG piped in (a
webcam through `ffmpeg -f image2pipe`), a slideshow of files, or each new
picture landing in a watched folder. `ImageStreamSplitter` walks JPEG
markers and PNG chunks. The Android demo shows live and sealed pictures.
- **Live channels across relay instances.** `LiveRelayOptions.mesh` with a
`LivePublisherLocator` (`PostgresLivePublisherLocator`;
`SHADE_MEDIA_RELAY_URL` / `media serve --advertise`): a relay with viewers