mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-01-31 00:18:55 +01:00
more robust onvif checks (#9635)
This commit is contained in:
parent
50563eef8d
commit
a33f2f117e
@ -6,6 +6,7 @@ from enum import Enum
|
|||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
from onvif import ONVIFCamera, ONVIFError
|
from onvif import ONVIFCamera, ONVIFError
|
||||||
|
from zeep.exceptions import Fault, TransportError
|
||||||
|
|
||||||
from frigate.config import FrigateConfig, ZoomingModeEnum
|
from frigate.config import FrigateConfig, ZoomingModeEnum
|
||||||
from frigate.types import PTZMetricsTypes
|
from frigate.types import PTZMetricsTypes
|
||||||
@ -68,16 +69,19 @@ class OnvifController:
|
|||||||
media = onvif.create_media_service()
|
media = onvif.create_media_service()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# this will fire an exception if camera is not a ptz
|
||||||
|
capabilities = onvif.get_definition("ptz")
|
||||||
|
logger.debug(f"Onvif capabilities for {camera_name}: {capabilities}")
|
||||||
profile = media.GetProfiles()[0]
|
profile = media.GetProfiles()[0]
|
||||||
except ONVIFError as e:
|
except (ONVIFError, Fault, TransportError) as e:
|
||||||
logger.error(f"Unable to connect to camera: {camera_name}: {e}")
|
logger.error(f"Unable to connect to camera: {camera_name}: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
ptz = onvif.create_ptz_service()
|
ptz = onvif.create_ptz_service()
|
||||||
|
|
||||||
request = ptz.create_type("GetConfigurations")
|
# get the PTZ config for the first onvif profile
|
||||||
configs = ptz.GetConfigurations(request)[0]
|
configs = profile.PTZConfiguration
|
||||||
logger.debug(f"Onvif configs for {camera_name}: {configs}")
|
logger.debug(f"Onvif ptz config for media profile in {camera_name}: {configs}")
|
||||||
|
|
||||||
request = ptz.create_type("GetConfigurationOptions")
|
request = ptz.create_type("GetConfigurationOptions")
|
||||||
request.ConfigurationToken = profile.PTZConfiguration.token
|
request.ConfigurationToken = profile.PTZConfiguration.token
|
||||||
@ -187,19 +191,18 @@ class OnvifController:
|
|||||||
] = preset["token"]
|
] = preset["token"]
|
||||||
|
|
||||||
# get list of supported features
|
# get list of supported features
|
||||||
ptz_config = ptz.GetConfigurationOptions(request)
|
|
||||||
supported_features = []
|
supported_features = []
|
||||||
|
|
||||||
if ptz_config.Spaces and ptz_config.Spaces.ContinuousPanTiltVelocitySpace:
|
if configs.DefaultContinuousPanTiltVelocitySpace:
|
||||||
supported_features.append("pt")
|
supported_features.append("pt")
|
||||||
|
|
||||||
if ptz_config.Spaces and ptz_config.Spaces.ContinuousZoomVelocitySpace:
|
if configs.DefaultContinuousZoomVelocitySpace:
|
||||||
supported_features.append("zoom")
|
supported_features.append("zoom")
|
||||||
|
|
||||||
if ptz_config.Spaces and ptz_config.Spaces.RelativePanTiltTranslationSpace:
|
if configs.DefaultRelativePanTiltTranslationSpace:
|
||||||
supported_features.append("pt-r")
|
supported_features.append("pt-r")
|
||||||
|
|
||||||
if ptz_config.Spaces and ptz_config.Spaces.RelativeZoomTranslationSpace:
|
if configs.DefaultRelativeZoomTranslationSpace:
|
||||||
supported_features.append("zoom-r")
|
supported_features.append("zoom-r")
|
||||||
try:
|
try:
|
||||||
# get camera's zoom limits from onvif config
|
# get camera's zoom limits from onvif config
|
||||||
@ -218,7 +221,7 @@ class OnvifController:
|
|||||||
f"Disabling autotracking zooming for {camera_name}: Relative zoom not supported"
|
f"Disabling autotracking zooming for {camera_name}: Relative zoom not supported"
|
||||||
)
|
)
|
||||||
|
|
||||||
if ptz_config.Spaces and ptz_config.Spaces.AbsoluteZoomPositionSpace:
|
if configs.DefaultAbsoluteZoomPositionSpace:
|
||||||
supported_features.append("zoom-a")
|
supported_features.append("zoom-a")
|
||||||
try:
|
try:
|
||||||
# get camera's zoom limits from onvif config
|
# get camera's zoom limits from onvif config
|
||||||
@ -236,7 +239,10 @@ class OnvifController:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# set relative pan/tilt space for autotracker
|
# set relative pan/tilt space for autotracker
|
||||||
if fov_space_id is not None:
|
if (
|
||||||
|
fov_space_id is not None
|
||||||
|
and configs.DefaultRelativePanTiltTranslationSpace is not None
|
||||||
|
):
|
||||||
supported_features.append("pt-r-fov")
|
supported_features.append("pt-r-fov")
|
||||||
self.cams[camera_name][
|
self.cams[camera_name][
|
||||||
"relative_fov_range"
|
"relative_fov_range"
|
||||||
|
Loading…
Reference in New Issue
Block a user