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:
@@ -118,6 +118,14 @@ describe("CameraLiveHub", () => {
|
||||
expect(slow.frames).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("sends every frame when no cap is set (the default)", () => {
|
||||
const hub = new CameraLiveHub(() => device, logger);
|
||||
const v = viewer();
|
||||
hub.subscribe("cam1", v);
|
||||
for (let i = 0; i < 5; i++) sources[0]!.frame(); // same instant: all pass
|
||||
expect(v.frames).toHaveLength(5);
|
||||
});
|
||||
|
||||
it("reconnects with backoff while viewers remain", async () => {
|
||||
const hub = new CameraLiveHub(() => device, logger);
|
||||
const v = viewer();
|
||||
|
||||
@@ -8,8 +8,9 @@ import type { LiveStreamDevice, LiveVideoSource } from "@parking/devices";
|
||||
//
|
||||
// Frames are complete JPEGs (the driver reassembles RTP/JPEG; nothing is decoded here).
|
||||
// Delivery is LATEST-FRAME-ONLY: a viewer whose socket still holds unsent bytes simply
|
||||
// misses frames, so a slow client can never grow server memory, and a per-viewer frame
|
||||
// cap keeps the desktop shell's IPC light. Advisory viewing only: nothing here touches
|
||||
// misses frames, so a slow client can never grow server memory. No frame-rate cap by
|
||||
// default — viewers get the camera's own rate (measured: a cap only dropped frames and
|
||||
// added ~40 ms); CAMERA_LIVE_MAX_FPS sets one if a client ever needs it. Advisory viewing only: nothing here touches
|
||||
// the ledger, a gate or a barrier. See wiki/decisions/camera-live-view.md.
|
||||
|
||||
export type LiveStatus =
|
||||
@@ -31,7 +32,7 @@ export type LiveResolver = (deviceId: string) => LiveStreamDevice | string;
|
||||
export interface CameraLiveOptions {
|
||||
/** Keep the upstream this long after the last viewer leaves (re-render churn). */
|
||||
lingerMs?: number;
|
||||
/** Per-viewer frame cap. The cameras send 12.5–20 fps; 10 is plenty to watch a car. */
|
||||
/** Per-viewer frame cap; 0 / unset = none (the camera's own rate, 12.5–20 fps). */
|
||||
maxFps?: number;
|
||||
/** Backoff ceiling for reconnects while viewers are present. */
|
||||
maxRetryMs?: number;
|
||||
@@ -49,9 +50,10 @@ interface Upstream {
|
||||
retry: ReturnType<typeof setTimeout> | null;
|
||||
}
|
||||
|
||||
/** Optional per-viewer cap from CAMERA_LIVE_MAX_FPS; 0 (the default) means no cap. */
|
||||
export function liveMaxFps(): number {
|
||||
const raw = Number(process.env.CAMERA_LIVE_MAX_FPS ?? 10);
|
||||
return Number.isFinite(raw) && raw > 0 ? raw : 10;
|
||||
const raw = Number(process.env.CAMERA_LIVE_MAX_FPS ?? 0);
|
||||
return Number.isFinite(raw) && raw > 0 ? raw : 0;
|
||||
}
|
||||
|
||||
export class CameraLiveHub {
|
||||
@@ -67,7 +69,8 @@ export class CameraLiveHub {
|
||||
this.#resolve = resolve;
|
||||
this.#logger = logger;
|
||||
this.#lingerMs = opts.lingerMs ?? 5000;
|
||||
this.#minFrameGapMs = 1000 / (opts.maxFps ?? liveMaxFps());
|
||||
const fps = opts.maxFps ?? liveMaxFps();
|
||||
this.#minFrameGapMs = fps > 0 ? 1000 / fps : 0;
|
||||
this.#maxRetryMs = opts.maxRetryMs ?? 30_000;
|
||||
this.#unavailableRetryMs = opts.unavailableRetryMs ?? 60_000;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user