Skip to content

NVR with realtime local object detection for IP cameras

Clean up enabled config updates (#17547)

Nicolas Mowen7bfcf2040d3e
diff --git a/frigate/output/birdseye.py b/frigate/output/birdseye.py
index 919aa3054a..20cda50f74 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 30900a5ab0..befb663ebe 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()
+ 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 config_data:
- config.cameras[camera].enabled = config_data.enabled
- return config_data.enabled
+ if not updated_enabled_topic:
+ break
- return config.cameras[camera].enabled
+ if updated_enabled_config:
+ camera_name = updated_enabled_topic.rpartition("/")[-1]
+ config.cameras[camera_name].enabled = updated_enabled_config.enabled
- while not stop_event.is_set():
(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 52f0448f6e..004beb8b34 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 (