Don't check autotracking onvif requirements for users with autotracking disabled (#10350)

* separate autotracking onvif needs from standard ptz control setup

* try/except around GetServiceCapabilities call
This commit is contained in:
Josh Hawkins 2024-03-09 08:48:31 -06:00 committed by GitHub
parent 62d13024f6
commit 9fc1286568
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -120,101 +120,106 @@ class OnvifController:
ptz = onvif.create_ptz_service() ptz = onvif.create_ptz_service()
request = ptz.create_type("GetConfigurationOptions")
request.ConfigurationToken = profile.PTZConfiguration.token
ptz_config = ptz.GetConfigurationOptions(request)
logger.debug(f"Onvif config for {camera_name}: {ptz_config}")
service_capabilities_request = ptz.create_type("GetServiceCapabilities")
self.cams[camera_name]["service_capabilities_request"] = (
service_capabilities_request
)
fov_space_id = next(
(
i
for i, space in enumerate(
ptz_config.Spaces.RelativePanTiltTranslationSpace
)
if "TranslationSpaceFov" in space["URI"]
),
None,
)
# status request for autotracking and filling ptz-parameters
status_request = ptz.create_type("GetStatus")
status_request.ProfileToken = profile.token
self.cams[camera_name]["status_request"] = status_request
try:
status = ptz.GetStatus(status_request)
logger.debug(f"Onvif status config for {camera_name}: {status}")
except Exception as e:
logger.warning(f"Unable to get status from camera: {camera_name}: {e}")
status = None
# autoracking relative panning/tilting needs a relative zoom value set to 0
# if camera supports relative movement
if (
self.config.cameras[camera_name].onvif.autotracking.zooming
!= ZoomingModeEnum.disabled
):
zoom_space_id = next(
(
i
for i, space in enumerate(
ptz_config.Spaces.RelativeZoomTranslationSpace
)
if "TranslationGenericSpace" in space["URI"]
),
None,
)
# setup continuous moving request # setup continuous moving request
move_request = ptz.create_type("ContinuousMove") move_request = ptz.create_type("ContinuousMove")
move_request.ProfileToken = profile.token move_request.ProfileToken = profile.token
self.cams[camera_name]["move_request"] = move_request self.cams[camera_name]["move_request"] = move_request
# setup relative moving request for autotracking # extra setup for autotracking cameras
move_request = ptz.create_type("RelativeMove") if (
move_request.ProfileToken = profile.token self.config.cameras[camera_name].onvif.autotracking.enabled_in_config
logger.debug(f"{camera_name}: Relative move request: {move_request}") and self.config.cameras[camera_name].onvif.autotracking.enabled
if move_request.Translation is None and fov_space_id is not None: ):
move_request.Translation = status.Position request = ptz.create_type("GetConfigurationOptions")
move_request.Translation.PanTilt.space = ptz_config["Spaces"][ request.ConfigurationToken = profile.PTZConfiguration.token
"RelativePanTiltTranslationSpace" ptz_config = ptz.GetConfigurationOptions(request)
][fov_space_id]["URI"] logger.debug(f"Onvif config for {camera_name}: {ptz_config}")
# try setting relative zoom translation space service_capabilities_request = ptz.create_type("GetServiceCapabilities")
try: self.cams[camera_name]["service_capabilities_request"] = (
service_capabilities_request
)
fov_space_id = next(
(
i
for i, space in enumerate(
ptz_config.Spaces.RelativePanTiltTranslationSpace
)
if "TranslationSpaceFov" in space["URI"]
),
None,
)
# status request for autotracking and filling ptz-parameters
status_request = ptz.create_type("GetStatus")
status_request.ProfileToken = profile.token
self.cams[camera_name]["status_request"] = status_request
try:
status = ptz.GetStatus(status_request)
logger.debug(f"Onvif status config for {camera_name}: {status}")
except Exception as e:
logger.warning(f"Unable to get status from camera: {camera_name}: {e}")
status = None
# autoracking relative panning/tilting needs a relative zoom value set to 0
# if camera supports relative movement
if ( if (
self.config.cameras[camera_name].onvif.autotracking.zooming self.config.cameras[camera_name].onvif.autotracking.zooming
!= ZoomingModeEnum.disabled != ZoomingModeEnum.disabled
): ):
if zoom_space_id is not None: zoom_space_id = next(
move_request.Translation.Zoom.space = ptz_config["Spaces"][ (
"RelativeZoomTranslationSpace" i
][zoom_space_id]["URI"] for i, space in enumerate(
else: ptz_config.Spaces.RelativeZoomTranslationSpace
move_request.Translation.Zoom = [] )
except Exception: if "TranslationGenericSpace" in space["URI"]
self.config.cameras[ ),
camera_name None,
].onvif.autotracking.zooming = ZoomingModeEnum.disabled )
logger.warning(
f"Disabling autotracking zooming for {camera_name}: Relative zoom not supported" # setup relative moving request for autotracking
move_request = ptz.create_type("RelativeMove")
move_request.ProfileToken = profile.token
logger.debug(f"{camera_name}: Relative move request: {move_request}")
if move_request.Translation is None and fov_space_id is not None:
move_request.Translation = status.Position
move_request.Translation.PanTilt.space = ptz_config["Spaces"][
"RelativePanTiltTranslationSpace"
][fov_space_id]["URI"]
# try setting relative zoom translation space
try:
if (
self.config.cameras[camera_name].onvif.autotracking.zooming
!= ZoomingModeEnum.disabled
):
if zoom_space_id is not None:
move_request.Translation.Zoom.space = ptz_config["Spaces"][
"RelativeZoomTranslationSpace"
][zoom_space_id]["URI"]
else:
move_request.Translation.Zoom = []
except Exception:
self.config.cameras[
camera_name
].onvif.autotracking.zooming = ZoomingModeEnum.disabled
logger.warning(
f"Disabling autotracking zooming for {camera_name}: Relative zoom not supported"
)
if move_request.Speed is None:
move_request.Speed = configs.DefaultPTZSpeed if configs else None
logger.debug(
f"{camera_name}: Relative move request after setup: {move_request}"
) )
self.cams[camera_name]["relative_move_request"] = move_request
if move_request.Speed is None: # setup absolute moving request for autotracking zooming
move_request.Speed = configs.DefaultPTZSpeed if configs else None move_request = ptz.create_type("AbsoluteMove")
logger.debug( move_request.ProfileToken = profile.token
f"{camera_name}: Relative move request after setup: {move_request}" self.cams[camera_name]["absolute_move_request"] = move_request
)
self.cams[camera_name]["relative_move_request"] = move_request
# setup absolute moving request for autotracking zooming
move_request = ptz.create_type("AbsoluteMove")
move_request.ProfileToken = profile.token
self.cams[camera_name]["absolute_move_request"] = move_request
# setup existing presets # setup existing presets
try: try:
@ -242,43 +247,53 @@ class OnvifController:
if configs.DefaultRelativeZoomTranslationSpace: if configs.DefaultRelativeZoomTranslationSpace:
supported_features.append("zoom-r") supported_features.append("zoom-r")
try: if (
# get camera's zoom limits from onvif config self.config.cameras[camera_name].onvif.autotracking.enabled_in_config
self.cams[camera_name]["relative_zoom_range"] = ( and self.config.cameras[camera_name].onvif.autotracking.enabled
ptz_config.Spaces.RelativeZoomTranslationSpace[0] ):
) try:
except Exception: # get camera's zoom limits from onvif config
if ( self.cams[camera_name]["relative_zoom_range"] = (
self.config.cameras[camera_name].onvif.autotracking.zooming ptz_config.Spaces.RelativeZoomTranslationSpace[0]
== ZoomingModeEnum.relative
):
self.config.cameras[
camera_name
].onvif.autotracking.zooming = ZoomingModeEnum.disabled
logger.warning(
f"Disabling autotracking zooming for {camera_name}: Relative zoom not supported"
) )
except Exception:
if (
self.config.cameras[camera_name].onvif.autotracking.zooming
== ZoomingModeEnum.relative
):
self.config.cameras[
camera_name
].onvif.autotracking.zooming = ZoomingModeEnum.disabled
logger.warning(
f"Disabling autotracking zooming for {camera_name}: Relative zoom not supported"
)
if configs.DefaultAbsoluteZoomPositionSpace: if configs.DefaultAbsoluteZoomPositionSpace:
supported_features.append("zoom-a") supported_features.append("zoom-a")
try: if (
# get camera's zoom limits from onvif config self.config.cameras[camera_name].onvif.autotracking.enabled_in_config
self.cams[camera_name]["absolute_zoom_range"] = ( and self.config.cameras[camera_name].onvif.autotracking.enabled
ptz_config.Spaces.AbsoluteZoomPositionSpace[0] ):
) try:
self.cams[camera_name]["zoom_limits"] = configs.ZoomLimits # get camera's zoom limits from onvif config
except Exception: self.cams[camera_name]["absolute_zoom_range"] = (
if self.config.cameras[camera_name].onvif.autotracking.zooming: ptz_config.Spaces.AbsoluteZoomPositionSpace[0]
self.config.cameras[
camera_name
].onvif.autotracking.zooming = ZoomingModeEnum.disabled
logger.warning(
f"Disabling autotracking zooming for {camera_name}: Absolute zoom not supported"
) )
self.cams[camera_name]["zoom_limits"] = configs.ZoomLimits
except Exception:
if self.config.cameras[camera_name].onvif.autotracking.zooming:
self.config.cameras[
camera_name
].onvif.autotracking.zooming = ZoomingModeEnum.disabled
logger.warning(
f"Disabling autotracking zooming for {camera_name}: Absolute zoom not supported"
)
# set relative pan/tilt space for autotracker # set relative pan/tilt space for autotracker
if ( if (
fov_space_id is not None self.config.cameras[camera_name].onvif.autotracking.enabled_in_config
and self.config.cameras[camera_name].onvif.autotracking.enabled
and fov_space_id is not None
and configs.DefaultRelativePanTiltTranslationSpace is not None and configs.DefaultRelativePanTiltTranslationSpace is not None
): ):
supported_features.append("pt-r-fov") supported_features.append("pt-r-fov")
@ -554,16 +569,22 @@ class OnvifController:
service_capabilities_request = self.cams[camera_name][ service_capabilities_request = self.cams[camera_name][
"service_capabilities_request" "service_capabilities_request"
] ]
service_capabilities = onvif.get_service("ptz").GetServiceCapabilities( try:
service_capabilities_request service_capabilities = onvif.get_service("ptz").GetServiceCapabilities(
) service_capabilities_request
)
logger.debug( logger.debug(
f"Onvif service capabilities for {camera_name}: {service_capabilities}" f"Onvif service capabilities for {camera_name}: {service_capabilities}"
) )
# MoveStatus is required for autotracking - should return "true" if supported # MoveStatus is required for autotracking - should return "true" if supported
return find_by_key(vars(service_capabilities), "MoveStatus") return find_by_key(vars(service_capabilities), "MoveStatus")
except Exception:
logger.warning(
f"Camera {camera_name} does not support the ONVIF GetServiceCapabilities method. Autotracking will not function correctly and must be disabled in your config."
)
return False
def get_camera_status(self, camera_name: str) -> None: def get_camera_status(self, camera_name: str) -> None:
if camera_name not in self.cams.keys(): if camera_name not in self.cams.keys():