mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-03-20 23:28:23 +03:00
refactor with helper function
This commit is contained in:
parent
b86d67166b
commit
57bb39b34d
@ -84,6 +84,32 @@ class OutputProcess(FrigateProcess):
|
|||||||
)
|
)
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
|
def is_debug_replay_camera(self, camera: str) -> bool:
|
||||||
|
return camera.startswith(REPLAY_CAMERA_PREFIX)
|
||||||
|
|
||||||
|
def add_camera(
|
||||||
|
self,
|
||||||
|
camera: str,
|
||||||
|
websocket_server: WSGIServer,
|
||||||
|
jsmpeg_cameras: dict[str, JsmpegCamera],
|
||||||
|
preview_recorders: dict[str, PreviewRecorder],
|
||||||
|
preview_write_times: dict[str, float],
|
||||||
|
birdseye: Birdseye | None,
|
||||||
|
) -> None:
|
||||||
|
camera_config = self.config.cameras[camera]
|
||||||
|
jsmpeg_cameras[camera] = JsmpegCamera(
|
||||||
|
camera_config, self.stop_event, websocket_server
|
||||||
|
)
|
||||||
|
preview_recorders[camera] = PreviewRecorder(camera_config)
|
||||||
|
preview_write_times[camera] = 0
|
||||||
|
|
||||||
|
if (
|
||||||
|
birdseye is not None
|
||||||
|
and self.config.birdseye.enabled
|
||||||
|
and camera_config.birdseye.enabled
|
||||||
|
):
|
||||||
|
birdseye.add_camera(camera)
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
self.pre_run_setup(self.config.logger)
|
self.pre_run_setup(self.config.logger)
|
||||||
|
|
||||||
@ -123,18 +149,18 @@ class OutputProcess(FrigateProcess):
|
|||||||
move_preview_frames("cache")
|
move_preview_frames("cache")
|
||||||
|
|
||||||
for camera, cam_config in self.config.cameras.items():
|
for camera, cam_config in self.config.cameras.items():
|
||||||
if not cam_config.enabled_in_config or camera.startswith(
|
if not cam_config.enabled_in_config or self.is_debug_replay_camera(camera):
|
||||||
REPLAY_CAMERA_PREFIX
|
|
||||||
):
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
jsmpeg_cameras[camera] = JsmpegCamera(
|
self.add_camera(
|
||||||
cam_config, self.stop_event, websocket_server
|
camera,
|
||||||
|
websocket_server,
|
||||||
|
jsmpeg_cameras,
|
||||||
|
preview_recorders,
|
||||||
|
preview_write_times,
|
||||||
|
birdseye,
|
||||||
)
|
)
|
||||||
|
|
||||||
preview_recorders[camera] = PreviewRecorder(cam_config)
|
|
||||||
preview_write_times[camera] = 0
|
|
||||||
|
|
||||||
if self.config.birdseye.enabled:
|
if self.config.birdseye.enabled:
|
||||||
birdseye = Birdseye(self.config, self.stop_event, websocket_server)
|
birdseye = Birdseye(self.config, self.stop_event, websocket_server)
|
||||||
|
|
||||||
@ -146,21 +172,15 @@ class OutputProcess(FrigateProcess):
|
|||||||
|
|
||||||
if CameraConfigUpdateEnum.add in updates:
|
if CameraConfigUpdateEnum.add in updates:
|
||||||
for camera in updates["add"]:
|
for camera in updates["add"]:
|
||||||
if camera.startswith(REPLAY_CAMERA_PREFIX):
|
if not self.is_debug_replay_camera(camera):
|
||||||
continue
|
self.add_camera(
|
||||||
|
camera,
|
||||||
camera_config = self.config.cameras[camera]
|
websocket_server,
|
||||||
jsmpeg_cameras[camera] = JsmpegCamera(
|
jsmpeg_cameras,
|
||||||
camera_config, self.stop_event, websocket_server
|
preview_recorders,
|
||||||
)
|
preview_write_times,
|
||||||
preview_recorders[camera] = PreviewRecorder(camera_config)
|
birdseye,
|
||||||
preview_write_times[camera] = 0
|
)
|
||||||
|
|
||||||
if (
|
|
||||||
self.config.birdseye.enabled
|
|
||||||
and self.config.cameras[camera].birdseye.enabled
|
|
||||||
):
|
|
||||||
birdseye.add_camera(camera)
|
|
||||||
|
|
||||||
(topic, data) = detection_subscriber.check_for_update(timeout=1)
|
(topic, data) = detection_subscriber.check_for_update(timeout=1)
|
||||||
now = datetime.datetime.now().timestamp()
|
now = datetime.datetime.now().timestamp()
|
||||||
@ -187,7 +207,7 @@ class OutputProcess(FrigateProcess):
|
|||||||
if (
|
if (
|
||||||
camera not in self.config.cameras
|
camera not in self.config.cameras
|
||||||
or not self.config.cameras[camera].enabled
|
or not self.config.cameras[camera].enabled
|
||||||
or camera.startswith(REPLAY_CAMERA_PREFIX)
|
or self.is_debug_replay_camera(camera)
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user