Files
parking_solution/wiki/decisions/camera-live-view.md
T
julian dd2dd53d7e wiki: H.264 test on park-lab, event-driven refactor decided
- zone-anpr-poc: H.264 instead of MJPEG (load, delay, a car in the zone,
  staff traffic, bad weather); the relay-less test copy is left running
- event-driven-refactor (new): the user's decisions of 2026-11-23, what
  is not decided, what they touch in today's code; waits for the user's
  guidelines
- passage-confirmation: the 2026-11-19 phase order superseded; where the
  video work lives
- vision-hardening, zone-anpr-poc-review: on-screen label read as a
  plate (moved by the user), day-time oversized box, still pause carried
  over
- pointers on vision-service, camera-live-view, lane-presence-and-anpr-entry,
  dingtian-vs-mqtt, entry gates, standing decisions, open questions,
  overview, index

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RZgP5oZdzvo92Eouc9eRv5
2026-11-23 12:02:18 +01:00

13 KiB
Raw Blame History

type, tags, sources, updated, status
type tags sources updated status
decision
parking
camera
ui
booth
video
hikvision
2026-11-23 settled

Camera Live View — Booth Camera Tiles

The booth operator can open a small tile per camera from the [[device-status-monitoring|device footer]] and watch that camera live while a vehicle is in front of it. BUILT 2026-11-17; verified end to end against the two park-lab cameras through the real server and in a browser (not yet in the desktop-shell-tauri — see Not yet verified).

2026-11-23: the user decided that the server holds no video or image work (event-driven-refactor). The live picture is to come from the vision side; how the booth screen gets it is not decided. This page describes what is built and running.

What the user asked for (2026-11-17)

  • The camera chips in the footer are clickable; a click opens that camera's tile in the bottom right, about 15 % of the screen wide. A second camera's tile stacks to the left of the first.
  • A tile closes with ✕; which tiles are open is a user preference (restored on login).
  • A tile rests on the latest entry/exit snapshot of that camera; when the camera's vehicle events reach the booth, it shows live video.
  • (2026-11-17, second round) Live shows a pulsing green LIVE badge. A click on the picture opens a large view with a Live / Snapshot switch whose Live streams on demand — car or no car — so a camera-started stream can be stopped to look at the last snapshot and a snapshot can be switched to live. Closing the large view returns the tile to automatic: a stream the user started stops; a stream the camera started carries on in the tile.
  • (2026-11-17, third round) The large view opens in the tile's state: on Live when the camera is active (the same stream carries on, no reconnect), else on the Snapshot. The choice then holds while the view is open — a car leaving does not drop it to the snapshot, a car arriving does not switch it to live.
  • (2026-11-17, fourth round) On the Snapshot side the large view has ‹ › (and ← →) to step through that camera's older / newer snapshots; a chevron is muted at either end. The caption carries the date ("Dje 17:22:47"). The tile itself stays on the newest; closing the large view drops the browse position, so it reopens on the newest. On Live there are no chevrons. Server: GET /api/cameras/:deviceId/snapshots/:snapshotId/neighbors → { older, newer } (session:read; 404 for another camera's snapshot), ordered by (capturedAt, id) like latest-snapshot, so equal timestamps neither skip nor loop. The caption always names the picture on screen: while a stepped-to still loads, the previous picture and its date stay; if its bytes are gone (retention), the view says Snapshot unavailable rather than show another still.

When the stream stops

A tile streams while its camera is active — 30 s after the camera's last vehicle push (LANE_BUSY_TTL_MS, shared with the lane lights; the camera re-pushes every 1–3 s while a car moves and every 15–25 s while it stands, so a waiting car keeps it live) — or while the large view is open on Live. It also stops on ✕, logout, or a dropped booth feed (resumes on reconnect). The camera session closes 5 s after the last viewer anywhere stops (RTSP TEARDOWN). No upper bound. The large live view is the 1280×720 sub-stream (the same stream as the tile); the Snapshot side shows the stored evidence still (full resolution when the camera's snapshot stream is Main).

Decision

Question Choice Why
Video source The camera's sub-stream (x02) set to MJPEG, pulled over RTSP The G2 firmware answers the HTTP MJPEG preview (/ISAPI/Streaming/channels/102/httpPreview) with notSupport; RTSP offers MJPEG as RTP/JPEG (RFC 2435). Every MJPEG frame is a whole picture, so a view is live ~150 ms after connect — H.264 would wait for a keyframe (every 2.5–4 s on these cameras) and need a decoder.
Where it runs In the server process, as a driver capability (LiveStreamDevice) in packages/devices No sidecar container (camera config + localAddress already live in the DB; the device-adapter-pattern keeps the protocol in the driver). The server reassembles JPEG frames from RTP packets — about 450 small packets/s for two cameras; it never decodes or re-encodes.
Fan-out One RTSP session per camera, shared by every viewer, torn down 5 s after the last leaves A camera has few stream slots and the [[lane-presence-and-anpr-entry
Delivery to the page A WebSocket per open tile (/api/cameras/:id/live), one JPEG per binary message, latest frame only, at the camera's own rate (no cap; CAMERA_LIVE_MAX_FPS can set one) Works in the desktop shell, whose webview cannot carry the session cookie on an <img>/<video> request (the WS already solves that with a ticket). A viewer whose socket still holds > 256 KB unsent skips frames — server memory stays bounded.
When live Per camera, while that camera pushes vehicle events (same 30 s TTL as lane busy/free) On a shared lane (park-lab) only the camera that saw the car goes live; lane state would light both.
Auth Same handshake as /api/ws (Origin allowlist, then desktop ticket or cookie), then device:read One helper (authenticateWsHandshake) for every socket route, so they cannot drift. The resting snapshot needs session:read (it is evidence).
Preference users.open_cameras (JSON id list, migration 0033), PUT /api/auth/open-cameras Same shape as language / theme / font scale.

Advisory viewing only. Nothing here writes to the ledger, gates a ticket or opens a barrier.

Not a reversal of the "livestream" rejection

lane-presence-and-anpr-entry rejected vision monitoring the RTSP livestream continuously for presence — inference on every frame, 24/7. This is an operator watching video, only while a vehicle is present, with no inference at all.

Measured on park-lab (2026-11-17)

Cameras (read from ISAPI/System/deviceInfo the same day): 10.0.10.6 entry = DS-2CD1083G2-LIU (8MP, V5.8.4), 10.0.10.7 exit = DS-2CD1043G2-LIU (4MP, V5.8.10). Both offer H.264, H.265, MJPEG on channel 102 and only two streams (101, 102). Channel 102 on both was switched from H.264 to MJPEG (640×360; other settings unchanged) with the user's agreement.

  • RTSP: first frame 110–155 ms after PLAY; .6 12.5 fps ≈ 310 KB/s, .7 20 fps ≈ 270 KB/s; RFC 2435 type 1 (4:2:0), Q 63 / 48 (no in-band tables), no restart markers, padding on each frame's last packet. Session: …;timeout=60; a 150 s session ran without drops with and without keepalive (a GET_PARAMETER is sent every timeout/2 anyway).
  • Interference with ANPR stills (what was measured — one camera at a time, one stream):
    • main-stream stills (101/picture, back-to-back, ~15–20 s) with an RTSP stream starting mid-run: .6 0/87 → 0/110 HTTP 503; .7 4/55 → 4/71 (the .7 503s occur without the stream too — the transient deviceBusy the driver retries). Starting a stream added none.
    • sub-stream stills (102/picture, back-to-back) while 102 streams MJPEG over RTSP for 180 s: .6 2121/2121 and .7 3187/3187 HTTP 200 (baselines without the stream, 60 s: 672/672 and 594/594); the stream held 12.0 / 20.0 fps throughout.
    • Not measured: several live sessions on one camera at once (the hub opens one), a stream alongside a browser left on the camera's web UI, and the G3H model.
    • 102/picture returns a 640×360 JPEG after the codec switch.
  • Raised to 1280×720 MJPEG (both cameras, same day, user's approval, for the large view; only width/height changed). RTSP: .6 12.2 fps ≈ 1030 KB/s, frames ≈ 83 KB; .7 20 fps ≈ 990 KB/s, frames ≈ 49 KB; first frame 120–190 ms; RFC 2435 header still type 1, Q 63 / 48. Over a 135 s stream: main-stream stills .6 0/169 → 0/251 HTTP 503 (avg 0.16 → 0.23 s per still — slower, not failing); .7 3/159 → 4/330 (the known transient deviceBusy); sub-stream stills 638/638 and 757/757 HTTP 200. Server end to end: three viewers connecting → live in 95–148 ms, 7–9 fps each, zero malformed JPEGs. (That run had the then-default 10 fps cap.) Uncapped, a viewer takes ≈ 1 MB/s per camera.
  • Delay (2026-11-17; the camera's printed clock vs arrival time on a host on the camera LAN, camera clocks bracketed to ±2 ms over ISAPI): camera → host ≈ 0.09–0.10 s; through the server the same (the server adds nothing measurable); the 10 fps cap then in place added ≈ 40 ms and cut .6 to 7 fps, so it was removed (user's decision); browser message → picture 1–2 ms. A viewer on a ~300 KB/s link climbed to 13–14 s behind within 30 s and stayed there — frames queue in TCP buffers the server's 256 KB check cannot see. The user judged the delay a non-issue for now; the fix, if it becomes one, is a per-frame ack from the page (send the next frame only after the last was shown).
  • Main stream in the large view: not possible on this transport. RTP/JPEG carries width and height as one byte × 8 (ceiling 2040×2040), and 101 is the 4MP/8MP H.264 ANPR/evidence stream. A true main-stream view would be a separate H.264 pipeline (depacketizer, in-browser decode, keyframe wait, unverified in the desktop shell).
  • End to end (server + scratch DB + both cameras, 2026-11-17): a simulated vehicle push → camera-activity on /api/ws; two viewers on the entry camera and one on the exit camera went connecting → live in 151 / 181 ms, 8–10 fps each, zero malformed JPEGs.

2026-11-23: channel 102 on both park-lab cameras is on H.264 for a decoding test (zone-anpr-poc, "H.264 instead of MJPEG"). The tiles take MJPEG only, so they show no live video for these cameras until 102 is put back or the live picture moves to the vision side (passage-confirmation, "Where the video work lives").

Install step (new)

Set the camera's sub-stream (102) video encoding to MJPEG (web UI: Configuration → Video/Audio → Video → Sub Stream, or PUT /ISAPI/Streaming/channels/102 with videoCodecType=MJPEG). With H.264 the tile says "camera stream is H264, not MJPEG" and stays on the snapshot. Added to site-device-installation §3. On a camera whose snapshot stream is set to Sub (the G3H workaround), the sub-stream resolution is both the ANPR/evidence still and the live view — MJPEG on the G2 offers 640×360, 640×480 or 1280×720 on channel 102; park-lab runs 1280×720 (~1 MB/s per camera while live, ~300 KB/s at 640×360). Dahua cameras have no live view yet (tile shows the reason).

Consequences elsewhere

  • passage-confirmation planned to decode the H.264 sub-stream. On a camera set up for live view that stream is now MJPEG: OpenCV decodes it too, every frame is a keyframe (the "≤ 1 s I-frame" requirement disappears), at ~5–10× the bandwidth (~1 MB/s per camera at 1280×720 on the device VLAN). The two consumers should share one RTSP session per camera when that is built.
  • Unverified, probably broken today: the existing snapshot thumbnails (SnapshotStrip, WashDesk) use <img src="/api/snapshots/:id"> — a relative, cookie-authed URL that the desktop shell's webview cannot authenticate. The camera tile fetches its snapshot through platformFetch instead. Check on a desktop install.

Verified in a browser (2026-11-17)

Headless Firefox against the server with both park-lab cameras and a simulated vehicle push: footer chips open tiles bottom-right (≈ 15 % wide, first opened rightmost, next to its left), each resting on its camera's latest snapshot with direction and time; after the entry camera's push only the entry tile went LIVE (live OSD clock); a reload restored both tiles; ✕ closed one and the saved preference followed. Second round: the large view on an idle camera streamed live on demand; Snapshot/Live switched both ways; closing it stopped the user's stream; on a camera-started stream, Snapshot in the large view stopped it and closing the view resumed it in the tile. Third round (no camera credentials in that run, so no frames — the socket count and the switch state were checked): an idle tile opens the large view on Snapshot with no socket; an active tile opens it on Live on the same socket (no reconnect); the close rules held.

Not yet verified

  • The Tauri/WebKitGTK shell (binary WS frames through @tauri-apps/plugin-websocket arrive as a number array over IPC — at 1280×720 uncapped that is 12–20 fps × 50–83 KB ≈ 1 MB/s per camera, to be measured). Its CSP already allows blob: images.
  • Through Caddy (reverse_proxy upgrades WebSockets; not exercised).
  • The live → snapshot return 30 s after the last push in the browser (covered by unit tests only).
  • A real vehicle push from the cameras to park-lab itself. Since 2026-11-19 both cameras push to the local dev machine instead (10.0.10.203:3000, user) — see passage-confirmation park-lab rig.

Where the code is

packages/devices/src/drivers/rtsp-mjpeg.ts (RTSP client), rfc2435.ts (frame reassembly, fixture-tested against frames verified with a JPEG decoder), camera.ts (openLiveStream on Hikvision); apps/server/src/camera-live.ts (hub), camera-activity.ts, routes/cameras.ts; apps/web/src/ui/CameraDock.tsx, ui/DeviceFooter.tsx. Knob: CAMERA_LIVE_MAX_FPS (unset = no cap).