refactor: improve error handling and logging in RTSPReader for frame capture failures
All checks were successful
Build Worker Base and Application Images / check-base-changes (push) Successful in 8s
Build Worker Base and Application Images / build-base (push) Has been skipped
Build Worker Base and Application Images / build-docker (push) Successful in 2m55s
Build Worker Base and Application Images / deploy-stack (push) Successful in 23s

This commit is contained in:
Siwat Sirichai 2025-09-26 01:44:46 +07:00
parent c6a4258055
commit a1e7c42fb3

View file

@ -89,7 +89,11 @@ class RTSPReader:
continue
# Read frame immediately without rate limiting for minimum latency
try:
ret, frame = self.cap.read()
except Exception as read_error:
logger.error(f"Camera {self.camera_id}: cap.read() threw exception: {type(read_error).__name__}: {read_error}")
ret, frame = False, None
if not ret or frame is None:
consecutive_errors += 1
@ -98,10 +102,14 @@ class RTSPReader:
logger.error(f"Camera {self.camera_id}: cap.read() failed - ret={ret}, frame={frame is not None}")
# Try to get more info from the capture
try:
if self.cap.isOpened():
logger.debug(f"Camera {self.camera_id}: Capture still open, backend: {self.cap.getBackendName()}")
backend = self.cap.getBackendName()
logger.debug(f"Camera {self.camera_id}: Capture still open, backend: {backend}")
else:
logger.error(f"Camera {self.camera_id}: Capture is closed!")
except Exception as info_error:
logger.error(f"Camera {self.camera_id}: Error getting capture info: {type(info_error).__name__}: {info_error}")
if consecutive_errors >= self.max_consecutive_errors:
logger.error(f"Camera {self.camera_id}: Too many consecutive errors ({consecutive_errors}), reinitializing")