Ensure that audio recording segments are kept

This commit is contained in:
Nick Mowen 2023-07-12 20:32:51 -06:00
parent 6a81eb7f24
commit 0455097879

View File

@ -201,6 +201,7 @@ class RecordingMaintainer(threading.Thread):
duration, duration,
cache_path, cache_path,
record_mode, record_mode,
events.data.get("type", "object") == "audio",
) )
# if it doesn't overlap with an event, go ahead and drop the segment # if it doesn't overlap with an event, go ahead and drop the segment
# if it ends more than the configured pre_capture for the camera # if it ends more than the configured pre_capture for the camera
@ -215,7 +216,13 @@ class RecordingMaintainer(threading.Thread):
else: else:
record_mode = self.config.cameras[camera].record.retain.mode record_mode = self.config.cameras[camera].record.retain.mode
self.store_segment( self.store_segment(
camera, start_time, end_time, duration, cache_path, record_mode camera,
start_time,
end_time,
duration,
cache_path,
record_mode,
events.data.get("type", "object") == "audio",
) )
def segment_stats( def segment_stats(
@ -251,12 +258,14 @@ class RecordingMaintainer(threading.Thread):
duration: float, duration: float,
cache_path: str, cache_path: str,
store_mode: RetainModeEnum, store_mode: RetainModeEnum,
audio_event: bool,
) -> None: ) -> None:
motion_count, active_count = self.segment_stats(camera, start_time, end_time) motion_count, active_count = self.segment_stats(camera, start_time, end_time)
# check if the segment shouldn't be stored # check if the segment shouldn't be stored
if (store_mode == RetainModeEnum.motion and motion_count == 0) or ( if not audio_event and (
store_mode == RetainModeEnum.active_objects and active_count == 0 (store_mode == RetainModeEnum.motion and motion_count == 0)
or (store_mode == RetainModeEnum.active_objects and active_count == 0)
): ):
Path(cache_path).unlink(missing_ok=True) Path(cache_path).unlink(missing_ok=True)
self.end_time_cache.pop(cache_path, None) self.end_time_cache.pop(cache_path, None)
@ -333,6 +342,7 @@ class RecordingMaintainer(threading.Thread):
motion=motion_count, motion=motion_count,
# TODO: update this to store list of active objects at some point # TODO: update this to store list of active objects at some point
objects=active_count, objects=active_count,
audio=1 if audio_event else 0,
segment_size=segment_size, segment_size=segment_size,
) )
except Exception as e: except Exception as e: