From 7bfcf2040d3e46fb5ed709e501a199cc7c943985 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Sat, 5 Apr 2025 07:47:58 -0600 Subject: [PATCH] Clean up enabled config updates (#17547) * Immediately end review item for disabled cameras * Clean up checks * Remove duplicate enabled checkers * Cleanup --- frigate/output/birdseye.py | 15 +-------------- frigate/output/output.py | 36 +++++++++++++++++------------------- frigate/review/maintainer.py | 14 ++++++++++---- 3 files changed, 28 insertions(+), 37 deletions(-) diff --git a/frigate/output/birdseye.py b/frigate/output/birdseye.py index 919aa3054..20cda50f7 100644 --- a/frigate/output/birdseye.py +++ b/frigate/output/birdseye.py @@ -754,7 +754,6 @@ class Birdseye: "birdseye", self.converter, websocket_server, stop_event ) self.birdseye_manager = BirdsEyeFrameManager(config, stop_event) - self.config_enabled_subscriber = ConfigSubscriber("config/enabled/") self.birdseye_subscriber = ConfigSubscriber("config/birdseye/") self.frame_manager = SharedMemoryFrameManager() self.stop_event = stop_event @@ -799,24 +798,13 @@ class Birdseye: updated_birdseye_config, ) = self.birdseye_subscriber.check_for_update() - ( - updated_enabled_topic, - updated_enabled_config, - ) = self.config_enabled_subscriber.check_for_update() - - if not updated_birdseye_topic and not updated_enabled_topic: + if not updated_birdseye_topic: break if updated_birdseye_config: camera_name = updated_birdseye_topic.rpartition("/")[-1] self.config.cameras[camera_name].birdseye = updated_birdseye_config - if updated_enabled_config: - camera_name = updated_enabled_topic.rpartition("/")[-1] - self.config.cameras[ - camera_name - ].enabled = updated_enabled_config.enabled - if self.birdseye_manager.update( camera, len([o for o in current_tracked_objects if not o["stationary"]]), @@ -828,6 +816,5 @@ class Birdseye: def stop(self) -> None: self.birdseye_subscriber.stop() - self.config_enabled_subscriber.stop() self.converter.join() self.broadcaster.join() diff --git a/frigate/output/output.py b/frigate/output/output.py index 30900a5ab..befb663eb 100644 --- a/frigate/output/output.py +++ b/frigate/output/output.py @@ -99,12 +99,7 @@ def output_frames( websocket_thread = threading.Thread(target=websocket_server.serve_forever) detection_subscriber = DetectionSubscriber(DetectionTypeEnum.video) - - enabled_subscribers = { - camera: ConfigSubscriber(f"config/enabled/{camera}", True) - for camera in config.cameras.keys() - if config.cameras[camera].enabled_in_config - } + config_enabled_subscriber = ConfigSubscriber("config/enabled/") jsmpeg_cameras: dict[str, JsmpegCamera] = {} birdseye: Birdseye | None = None @@ -128,16 +123,21 @@ def output_frames( websocket_thread.start() - def get_enabled_state(camera: str) -> bool: - _, config_data = enabled_subscribers[camera].check_for_update() - - if config_data: - config.cameras[camera].enabled = config_data.enabled - return config_data.enabled - - return config.cameras[camera].enabled - while not stop_event.is_set(): + # check if there is an updated config + while True: + ( + updated_enabled_topic, + updated_enabled_config, + ) = config_enabled_subscriber.check_for_update() + + if not updated_enabled_topic: + break + + if updated_enabled_config: + camera_name = updated_enabled_topic.rpartition("/")[-1] + config.cameras[camera_name].enabled = updated_enabled_config.enabled + (topic, data) = detection_subscriber.check_for_update(timeout=1) now = datetime.datetime.now().timestamp() @@ -160,7 +160,7 @@ def output_frames( _, ) = data - if not get_enabled_state(camera): + if not config.cameras[camera].enabled: continue frame = frame_manager.get(frame_name, config.cameras[camera].frame_shape_yuv) @@ -240,9 +240,7 @@ def output_frames( if birdseye is not None: birdseye.stop() - for subscriber in enabled_subscribers.values(): - subscriber.stop() - + config_enabled_subscriber.stop() websocket_server.manager.close_all() websocket_server.manager.stop() websocket_server.manager.join() diff --git a/frigate/review/maintainer.py b/frigate/review/maintainer.py index 52f0448f6..004beb8b3 100644 --- a/frigate/review/maintainer.py +++ b/frigate/review/maintainer.py @@ -482,6 +482,10 @@ class ReviewSegmentMaintainer(threading.Thread): camera_name = updated_record_topic.rpartition("/")[-1] self.config.cameras[camera_name].record = updated_record_config + # immediately end segment + if not updated_record_config.enabled: + self.end_segment(camera_name) + if updated_review_topic: camera_name = updated_review_topic.rpartition("/")[-1] self.config.cameras[camera_name].review = updated_review_config @@ -492,6 +496,10 @@ class ReviewSegmentMaintainer(threading.Thread): camera_name ].enabled = updated_enabled_config.enabled + # immediately end segment as we may not get another update + if not updated_enabled_config.enabled: + self.end_segment(camera_name) + (topic, data) = self.detection_subscriber.check_for_update(timeout=1) if not topic: @@ -523,16 +531,14 @@ class ReviewSegmentMaintainer(threading.Thread): if camera not in self.indefinite_events: self.indefinite_events[camera] = {} - current_segment = self.active_review_segments.get(camera) - if ( not self.config.cameras[camera].enabled or not self.config.cameras[camera].record.enabled ): - if current_segment: - self.end_segment(camera) continue + current_segment = self.active_review_segments.get(camera) + # Check if the current segment should be processed based on enabled settings if current_segment: if (