Cameras on devices (openpanel C1): frames in memory, a binary uplink, demand
- Volatile frames are held in memory with a byte-bounded queue instead of the /dev/shm ring scanned on every put; workers keep writing to the directory, which is trimmed on a timer. A volatile upload no longer spools to disk. ARTIFACT_VOLATILE_BYTES=0 turns the ring off. - A device sends camera frames as binary messages on its socket, held and published in one step and credited to its device node; refused frames are logged and dropped. Its snapshot carries demand and the uplink (binary, or http through the portal). - One demand registry for every socket's wanted media, the tunnel's included, plus what running flows read, mapped onto on-demand ports and published as device_demand; at most 8 media names per socket. - Per-message deflate off in serve and dev; a device may fetch the last 8 digests of a message; published dashboards cached per store revision; a revoked device socket is closed with 1008. - Media tiles want bytes only while on screen; the Devices tab previews a wired camera; the device node warns when a flow reads an on-demand port.
This commit is contained in:
@@ -19,6 +19,8 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
QUEUE_SIZE = 256
|
||||
LOG_HISTORY = 400
|
||||
#: How many of a message's last artifact digests are remembered.
|
||||
RECENT_DIGESTS = 8
|
||||
|
||||
|
||||
class EventBus:
|
||||
@@ -42,6 +44,11 @@ class EventBus:
|
||||
# zero and draw a busy graph as idle. A session count, not a metric —
|
||||
# the rollups in `metrics.py` are what survives a restart.
|
||||
self.emits: dict[str, int] = {}
|
||||
#: The last few artifacts each message pointed at, newest last. A
|
||||
#: screen fetching a camera frame by frame asks for one the message
|
||||
#: may already have moved past, and a device's credential reaches
|
||||
#: these as well as the current one.
|
||||
self.digests: dict[str, deque[str]] = {}
|
||||
|
||||
def bind(self, loop: asyncio.AbstractEventLoop) -> None:
|
||||
"""Attach the bus to the running event loop (called once at startup)."""
|
||||
@@ -59,6 +66,14 @@ class EventBus:
|
||||
# increment, which is a count nobody is going to miss.
|
||||
node = str(event.get("node") or "")
|
||||
self.emits[node] = self.emits.get(node, 0) + 1
|
||||
elif kind == "message_value":
|
||||
value = event.get("value")
|
||||
if isinstance(value, dict) and isinstance(value.get("digest"), str):
|
||||
name = str(event.get("name") or "")
|
||||
recent = self.digests.get(name)
|
||||
if recent is None:
|
||||
recent = self.digests[name] = deque(maxlen=RECENT_DIGESTS)
|
||||
recent.append(value["digest"])
|
||||
loop = self._loop
|
||||
if loop is None or not self._subscribers:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user