fix(video): recover encoder capacity, pace RTP and isolate preview sessions

This commit is contained in:
DCCONSTRUCTIONS
2026-11-21 20:58:25 +03:00
parent 3d04fa45d3
commit bed1db3508
29 changed files with 1534 additions and 141 deletions
+7
View File
@@ -157,7 +157,14 @@ class Broker:
def item(self, value, node):
status = value["status"]
preview = status.get("preview")
frames = None
if value["online"]:
if preview == 0:
frames = "idle"
elif preview == 1 and self.media is not None:
frames = self.media.frame_state((value["id"], value["session_id"]))
return {
**({"local_frame_state": frames} if frames else {}),
"id": value["id"],
"name": "Insta360 X4",
"model": "Insta360 X4",
+16
View File
@@ -90,6 +90,16 @@ class Source:
with self.lock:
return self.sequence, self.frame, self.observed
def frame_state(self):
# Read only the decoder slot already used by the preview. No SDK call.
with self.lock:
now = time.monotonic()
if self.sequence and now - self.observed < 2:
return "online"
if now - self.started >= 2:
return "lost"
return None
def health(self):
"""Bounded in-memory counters; no encoded media or monitoring history."""
with self.lock:
@@ -435,6 +445,12 @@ class Engine:
self.thread = threading.Thread(target=self.loop.run_forever, daemon=True)
self.thread.start()
def frame_state(self, key):
# Sources are installed/removed atomically on the engine thread. Hold a
# reference during the read; a fresh session always has a different key.
source = self.peers.sources.get(key)
return source.frame_state() if source is not None else None
def capture(self, key, path, start):
work = self.peers.prime(key, path) if start else self.peers.release(key)
future = asyncio.run_coroutine_threadsafe(work, self.loop)