fix(video): recover encoder capacity, pace RTP and isolate preview sessions
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user