Skip to content

Commit

Permalink
run health check on streams #1036 #1037
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlt8 committed Nov 13, 2023
1 parent 7e23ef0 commit 1c16efb
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions app/wyzebridge/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def monitor_streams(self, mtx_health: Callable) -> None:
events = WyzeEvents(self.streams) if MOTION else None
while not self.stop_flag:
event.read(timeout=1)
self.snap_all()
self.snap_all(self.active_streams())
if events:
events.check_motion()
if int(time.time()) % 15 == 0:
Expand Down Expand Up @@ -138,22 +138,23 @@ def active_streams(self) -> list[str]:
"""
return [cam for cam, s in self.streams.items() if s.health_check() > 0]

def snap_all(self, force: bool = False):
def snap_all(self, cams: Optional[list[str]] = None, force: bool = False):
"""
Take an rtsp snapshot of active_streams.
Take an rtsp snapshot of the streams in the list.
Args:
- cams (list[str], optional): names of the streams to take a snapshot of.
- force (bool, optional): Ignore interval and force snapshot. Defaults to False.
"""
if force or (
SNAPSHOT_TYPE == "rtsp" and time.time() - self.last_snap >= SNAPSHOT_INT
):
if force or self._should_snap():
self.last_snap = time.time()
for cam in self.active_streams():
for cam in cams or self.active_streams():
stop_subprocess(self.rtsp_snapshots.get(cam))
self.rtsp_snap_popen(cam, True)

def _should_snap(self):
return SNAPSHOT_TYPE == "rtsp" and time.time() - self.last_snap >= SNAPSHOT_INT

def get_sse_status(self) -> dict:
return {
uri: {"status": cam.status(), "motion": cam.motion}
Expand All @@ -177,7 +178,7 @@ def send_cmd(
resp = {"status": "error", "command": cmd, "payload": payload}

if cam_name == "all" and cmd == "update_snapshot":
self.snap_all(True)
self.snap_all(force=True)
return resp | {"status": "success"}

if not (stream := self.get(cam_name)):
Expand Down

0 comments on commit 1c16efb

Please sign in to comment.