Update camera management and MQTT logging for improved functionality
- Changed log level in configuration from WARNING to INFO for better visibility of system operations. - Enhanced StandaloneAutoRecorder initialization to accept camera manager, state manager, and event system for improved modularity. - Updated recording routes to handle optional request bodies and improved error logging for better debugging. - Added checks in CameraMonitor to determine if a camera is already in use before initialization, enhancing resource management. - Improved MQTT client logging to provide more detailed connection and message handling information. - Added new MQTT event handling capabilities to the VisionApiClient for better tracking of machine states.
This commit is contained in:
@@ -188,6 +188,34 @@ class CameraMonitor:
|
||||
|
||||
self.logger.info(f"Attempting to initialize camera {camera_name} for availability test...")
|
||||
|
||||
# Check if camera is already in use by recorder or streamer before trying to initialize
|
||||
recorder = self.camera_manager.camera_recorders.get(camera_name) if self.camera_manager else None
|
||||
streamer = self.camera_manager.camera_streamers.get(camera_name) if self.camera_manager else None
|
||||
|
||||
camera_in_use = False
|
||||
if recorder and recorder.hCamera:
|
||||
try:
|
||||
# Check if recorder has camera open
|
||||
if mvsdk.CameraIsOpened(recorder.hCamera):
|
||||
camera_in_use = True
|
||||
self.logger.info(f"Camera {camera_name} is already in use by recorder (handle: {recorder.hCamera})")
|
||||
except:
|
||||
pass
|
||||
|
||||
if not camera_in_use and streamer and streamer.hCamera:
|
||||
try:
|
||||
# Check if streamer has camera open
|
||||
if mvsdk.CameraIsOpened(streamer.hCamera):
|
||||
camera_in_use = True
|
||||
self.logger.info(f"Camera {camera_name} is already in use by streamer (handle: {streamer.hCamera})")
|
||||
except:
|
||||
pass
|
||||
|
||||
# If camera is already in use, mark as available (since it's working, just occupied)
|
||||
if camera_in_use:
|
||||
self.logger.info(f"Camera {camera_name} is in use by system components - marking as available")
|
||||
return "available", "Camera is in use by system", self._get_device_info_dict(device_info)
|
||||
|
||||
# Suppress output to avoid MVCAMAPI error messages during camera testing
|
||||
hCamera = None
|
||||
try:
|
||||
@@ -195,7 +223,26 @@ class CameraMonitor:
|
||||
hCamera = mvsdk.CameraInit(device_info, -1, -1)
|
||||
self.logger.info(f"Camera {camera_name} initialized successfully, starting test capture...")
|
||||
except mvsdk.CameraException as init_e:
|
||||
self.logger.warning(f"CameraInit failed for {camera_name}: {init_e.message} (error_code: {init_e.error_code})")
|
||||
error_msg = f"CameraInit failed for {camera_name}: {init_e.message} (error_code: {init_e.error_code})"
|
||||
|
||||
# Special handling for error code 32774 (camera already in use)
|
||||
if init_e.error_code == 32774:
|
||||
error_msg += " - Camera may be in use by another process or resource conflict. "
|
||||
error_msg += "This camera may still be functional if accessed through existing recorder/streamer."
|
||||
self.logger.warning(error_msg)
|
||||
# Mark as "available" but with warning, since it might be usable through existing connections
|
||||
# The UI can show a warning but camera operations might still work
|
||||
try:
|
||||
device_info_dict = self._get_device_info_dict(device_info)
|
||||
device_info_dict["init_error"] = "Camera appears in use (error 32774) but may be accessible"
|
||||
device_info_dict["init_error_code"] = 32774
|
||||
except Exception as dev_info_e:
|
||||
self.logger.warning(f"Failed to get device info dict after CameraInit failure: {dev_info_e}")
|
||||
device_info_dict = None
|
||||
return "available", "Camera may be in use (error 32774) - check if recorder/streamer is active", device_info_dict
|
||||
else:
|
||||
self.logger.warning(error_msg)
|
||||
|
||||
# Get device info dict before returning - wrap in try/except in case device_info is corrupted
|
||||
try:
|
||||
device_info_dict = self._get_device_info_dict(device_info)
|
||||
|
||||
@@ -26,6 +26,13 @@ from ..core.events import EventSystem, publish_recording_started, publish_record
|
||||
from ..core.timezone_utils import now_atlanta, format_filename_timestamp
|
||||
from .sdk_config import ensure_sdk_initialized
|
||||
from .utils import suppress_camera_errors
|
||||
from .constants import (
|
||||
CAMERA_GET_BUFFER_TIMEOUT,
|
||||
CAMERA_INIT_TIMEOUT,
|
||||
CAMERA_TEST_CAPTURE_TIMEOUT,
|
||||
DEFAULT_VIDEO_FPS,
|
||||
BRIEF_PAUSE_SLEEP,
|
||||
)
|
||||
|
||||
|
||||
class CameraRecorder:
|
||||
|
||||
Reference in New Issue
Block a user