mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-28 16:27:07 +03:00
disable relative movement when the camera doesn't report its position
This commit is contained in:
+15
-16
@@ -351,12 +351,13 @@ class OnvifController:
|
|||||||
autotracking_config.enabled_in_config and autotracking_config.enabled
|
autotracking_config.enabled_in_config and autotracking_config.enabled
|
||||||
)
|
)
|
||||||
|
|
||||||
# setup relative move request when FOV relative movement is supported
|
fov_supported = (
|
||||||
if (
|
|
||||||
fov_space_id is not None
|
fov_space_id is not None
|
||||||
and configs.DefaultRelativePanTiltTranslationSpace is not None
|
and configs.DefaultRelativePanTiltTranslationSpace is not None
|
||||||
):
|
)
|
||||||
# one-off GetStatus to seed Translation field
|
|
||||||
|
# relative moves are seeded from the current position
|
||||||
|
if fov_supported:
|
||||||
status = None
|
status = None
|
||||||
try:
|
try:
|
||||||
status = await ptz.GetStatus({"ProfileToken": profile.token})
|
status = await ptz.GetStatus({"ProfileToken": profile.token})
|
||||||
@@ -364,6 +365,15 @@ class OnvifController:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Unable to get status from camera {camera_name}: {e}")
|
logger.warning(f"Unable to get status from camera {camera_name}: {e}")
|
||||||
|
|
||||||
|
if status is None or status.Position is None:
|
||||||
|
logger.warning(
|
||||||
|
"Disabling relative movement for %s: camera does not report its PTZ position",
|
||||||
|
camera_name,
|
||||||
|
)
|
||||||
|
fov_supported = False
|
||||||
|
|
||||||
|
# setup relative move request when FOV relative movement is supported
|
||||||
|
if fov_supported:
|
||||||
rel_move_request = ptz.create_type("RelativeMove")
|
rel_move_request = ptz.create_type("RelativeMove")
|
||||||
rel_move_request.ProfileToken = profile.token
|
rel_move_request.ProfileToken = profile.token
|
||||||
logger.debug(f"{camera_name}: Relative move request: {rel_move_request}")
|
logger.debug(f"{camera_name}: Relative move request: {rel_move_request}")
|
||||||
@@ -373,15 +383,8 @@ class OnvifController:
|
|||||||
]["URI"]
|
]["URI"]
|
||||||
|
|
||||||
if rel_move_request.Translation is None:
|
if rel_move_request.Translation is None:
|
||||||
if status is not None and status.Position is not None:
|
|
||||||
# seed from current position
|
|
||||||
rel_move_request.Translation = status.Position
|
rel_move_request.Translation = status.Position
|
||||||
rel_move_request.Translation.PanTilt.space = fov_uri
|
rel_move_request.Translation.PanTilt.space = fov_uri
|
||||||
else:
|
|
||||||
# fallback: construct Translation explicitly
|
|
||||||
rel_move_request.Translation = {
|
|
||||||
"PanTilt": {"x": 0, "y": 0, "space": fov_uri}
|
|
||||||
}
|
|
||||||
|
|
||||||
# configure zoom on relative move request
|
# configure zoom on relative move request
|
||||||
if (
|
if (
|
||||||
@@ -497,11 +500,7 @@ class OnvifController:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"Focus not supported for {camera_name}: {e}")
|
logger.debug(f"Focus not supported for {camera_name}: {e}")
|
||||||
|
|
||||||
# detect FOV relative movement support
|
if fov_supported:
|
||||||
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")
|
||||||
cam["relative_fov_range"] = (
|
cam["relative_fov_range"] = (
|
||||||
ptz_config.Spaces.RelativePanTiltTranslationSpace[fov_space_id]
|
ptz_config.Spaces.RelativePanTiltTranslationSpace[fov_space_id]
|
||||||
|
|||||||
@@ -165,6 +165,25 @@ class TestOnvifInitRequests(unittest.IsolatedAsyncioTestCase):
|
|||||||
self.assertTrue(await controller._init_onvif(CAMERA))
|
self.assertTrue(await controller._init_onvif(CAMERA))
|
||||||
self.assertIsNone(controller.cams[CAMERA]["video_source_token"])
|
self.assertIsNone(controller.cams[CAMERA]["video_source_token"])
|
||||||
|
|
||||||
|
async def test_fov_movement_requires_reported_position(self) -> None:
|
||||||
|
# cameras with StatusPosition="false" omit Position from GetStatus
|
||||||
|
for position in (MagicMock(), None):
|
||||||
|
with self.subTest(position=position):
|
||||||
|
controller = _make_controller(autotracking_enabled=False)
|
||||||
|
ptz = controller.cams[CAMERA]["onvif"].create_ptz_service.return_value
|
||||||
|
ptz_config = MagicMock()
|
||||||
|
ptz_config.Spaces.RelativePanTiltTranslationSpace = [
|
||||||
|
{"URI": "http://www.onvif.org/TranslationSpaceFov"}
|
||||||
|
]
|
||||||
|
ptz.GetConfigurationOptions = AsyncMock(return_value=ptz_config)
|
||||||
|
ptz.GetStatus = AsyncMock(return_value=MagicMock(Position=position))
|
||||||
|
|
||||||
|
self.assertTrue(await controller._init_onvif(CAMERA))
|
||||||
|
self.assertEqual(
|
||||||
|
"pt-r-fov" in controller.cams[CAMERA]["features"],
|
||||||
|
position is not None,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestManualRelativeMoveMetrics(unittest.IsolatedAsyncioTestCase):
|
class TestManualRelativeMoveMetrics(unittest.IsolatedAsyncioTestCase):
|
||||||
"""A manual move from the UI (click to move, drag to zoom) sends move_relative
|
"""A manual move from the UI (click to move, drag to zoom) sends move_relative
|
||||||
|
|||||||
Reference in New Issue
Block a user