feat(cameras): no frame-rate cap on live view by default (viewers get the camera's 12–20 fps)
Build & push images / images (push) Successful in 3m46s
Build & push images / images (push) Successful in 3m46s
Measured: the 10 fps cap cut the 12.5 fps entry camera to ~7 fps and added ~40 ms; the server otherwise adds no measurable delay. CAMERA_LIVE_MAX_FPS still sets a cap when wanted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RZgP5oMncSaVmKRKk1UvN4
This commit is contained in:
@@ -47,7 +47,7 @@ evidence still (full resolution when the camera's snapshot stream is Main).
|
||||
| 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|ANPR loop]] pulls stills from the same unit. |
|
||||
| Delivery to the page | A **WebSocket per open tile** (`/api/cameras/:id/live`), one JPEG per binary message, **latest frame only**, capped at 10 fps per viewer | 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. |
|
||||
| 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. |
|
||||
@@ -88,7 +88,15 @@ agreement.
|
||||
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. Per viewer at the 10 fps cap that is ≈ 0.5–0.8 MB/s.
|
||||
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,
|
||||
@@ -134,7 +142,7 @@ 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 that is up to 10 fps × 83 KB, to be measured). Its CSP already allows `blob:`
|
||||
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).
|
||||
@@ -146,4 +154,4 @@ reconnect); the close rules held.
|
||||
`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` (10).
|
||||
`apps/web/src/ui/CameraDock.tsx`, `ui/DeviceFooter.tsx`. Knob: `CAMERA_LIVE_MAX_FPS` (unset = no cap).
|
||||
|
||||
Reference in New Issue
Block a user