ONVIF Profile S, Actions API, and PTZ Controls Implementation - #1205
Conversation
… commit dates to the component header
✅ Deploy Preview for viseron ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
…anges of the ONVIF component
roflcoopter
left a comment
There was a problem hiding this comment.
Finally got through everything, i have a few comments (inline and in this comment)
The ONVIF calls are blocking the Tornado API event loop, slowing down other requests. I think this can be solved by changing the wrapper @operation() to use run_in_executor, and changing the operations to be sync instead.
|
Alright, I'll check and refactor it; thanks for the review. |
|
Great, thanks for the quick fixes. I think some If you remove those i am happy! |
I intentionally included that line: |
Right i see, that is handled in |
|
Ok I will update it |
Yes, the current logger configuration in Viseron will capture all logs from the libraries, not just |
|
Great work, i am OK with merging this now, anything else you wanna change before i do that? |
|
No, enough for now. Any improvements or fix will be on different PR. Thanks for the review 🙏 |
|
Merged, thank you! 🚀 |
TL;DR
PTZ componenthas now been switched toONVIF component.Telegram component(the PTZ control section) has been refactored to accommodate the changes to theONVIF component.Profile S(see Profile S Specs) in Viseron (starting point of ONVIF Profile G support #1166).Actions APIto connect backend and frontend component functions.PTZ Controlsare available on theLive Viewpage as aPlayerMenu(closed [FEATURE] PTZ controls #449).Camera Tuningpage (see PR Add Camera Tuning Implementation (Tuning Interface, Zone/Mask Drawer Tool, Labels Editor, OSD Texts, and Miscellaneous UI) #1165).ONVIF componentcan be used with all types of ONVIF cameras (even if the camera does not support PTZ).PR Overview
PR TODO:
ONVIF Componentbackend implementationActions APIbackend implementation forONVIF ComponentTelegram PTZ ControlforONVIF ComponentAPI Hooksin Frontend forONVIF ComponentPTZ Controlsin Frontend forONVIF ComponentCamera Tuninghandlers in the backend forONVIF ComponentCamera Tuningpage forONVIF ComponentCamera TuningpageCamera Tuning API&Camera Tuning UIONVIF Profile S?
ONVIF consists of a set of profiles; ranging from A to T, that define compatibility, services, and mandatory functional requirements for both clients and devices. Further details can be found at https://www.onvif.org/profiles.
In this PR, I am only implementing client compatibility for Profile S (https://www.onvif.org/profiles/profile-s/). It is certainly possible to implement other ONVIF profiles in Viseron in the future.
What is the Actions API?
The Actions API is a set of APIs that allow frontend components to perform specific actions on specific component functions defined in the backend that directly impact or communicate with the camera. The implementation code must conform to the following folder pattern:
viseron/components/webserver/api/v1/actions/{component_name}.The naming of the Actions API is simply a separation of focus, as the majority of the REST APIs in the webserver components are APIs for Viseron's built-in systems.
Custom Decorators
There are two main decorators introduced in this PR:
@operation: found inviseron/components/onvif/utils.pyand used to wrap all methods that implement ONVIF operations for a service. Any method that calls ONVIF operations within it is required to use this decorator.@action_handler: found inviseron/components/webserver/api/v1/actions/onvif/base.pyand used to wrap methods used by the Actions API. Because the context is an ONVIF component, the@action_handlerdecorator also communicates to determine which service will process the API request.How PTZ Controls works?
On the frontend,
PTZ Controlswill only be rendered on cameras with a non-nullptz_supportkey. This means thePTZ Controlsbutton will not appear in the player on cameras that don't support PTZ. The current implementation is to match theptz_supportkey with the available PTZ controller (referred to here as the UI component). Currently,PTZ Controlscan only be used withONVIF components. It is possible (in the future) to implementPTZ Controlsother thanONVIF components, by integrating custom components with specific brands (for example, Dahua).All PTZ operation communications must go through the
Actions APIdefined infrontend/src/lib/api/actions/{component_name}for frontend and inviseron/components/webserver/api/v1/actions/{component_name}for backend. The UI component forPTZ Controlsmust be located infrontend/src/components/actions/ptz.Tested Devices
Notes:
Notes (dev):
Camera Tuning, but why do we still need theauto_configmechanism and service key inconfig.yamlin the ONVIF component? So many cameras will reset all settings if the camera restarts/reboots, suppose there is a scenario where there is a power outage where the Viseron server and ONVIF cameras are in the same location, then the service key is very useful so that the ONVIF component in Viseron configures each camera based on the configuration that has been written when restarting (Viseron server) without the need to configure each camera one by one.ONVIF Profile S Client Requirements Checklist:
For transparency and reference of ONVIF component development, the following is a checklist based on the official requirements for Profile S client (https://www.onvif.org/wp-content/uploads/2019/12/ONVIF_Profile_-S_Specification_v1-3.pdf) implementation in ONVIF:
WS-Usernametokenaccording to WS-security as covered by the core specification.HTTP Digestas covered by the core specification.GetCapabilities.GetNetworkInterfacesandSetNetworkInterfacesoperations.If configuring a device’s network configuration is supported in any way by the client, the client shall be able to list and set the default gateway of the device using the
GetNetworkDefaultGatewayandSetNetworkDefaultGatewayoperations.GetDeviceInformationoperation.CreateUsers,GetUsers,SetUserandDeleteUsersoperations.- “Pull” using the
CreatePullPointSubscriptionandPullMessageoperations.- “Push” using
Notify,SubscribeandRenewoperations fromWSBaseNotification.GetProfilesoperation.- Client shall be able to get the stream URI for the selected profile using the
GetStreamURIoperation.- Client shall be able to stream video on RTP/UDP or RTP/RTSP/HTTP/TCP using the selected profile over RTSP.
and
🚫 out of scope
and
🚫 out of scope
- Client shall be able to understand RTSP – JPEG RTP header extension.
GetVideoEncoderConfigurationOptionsandSetVideoEncoderConfigurationoperations.GetProfilesoperation.- Client shall be able to create a media profile using the
CreateProfileoperation.GetCompatibleVideoSourceConfigurations,GetVideoSourceConfigurationOptions,SetVideoSourceConfigurationandAddVideoSourceConfigurationoperations.GetMetaDataConfigurationOptionsandSetMetaDataConfigurationoperations.GetNodesorGetNodeoperations.- Client shall be able to add a PTZ configuration to a profile using
GetConfigurationsandAddPTZConfiguration.- Client shall be able to move a PTZ device using the
ContinuousMoveoperation.- Client shall be able to stop a PTZ device using the
Stopoperation.AbsoluteMoveoperation.RelativeMoveoperation.GetPresetsoperation.- Client shall be able to move a PTZ device to a specific preset using the
GotoPresetoperation.GotoHomePositionoperation.SetAuxiliaryCommandoperation.- Client shall be able to configure a media profile for audio streaming using the
GetCompatibleAudioSourceConfigurations,AddAudioSourceConfiguration,GetCompatibleAudioEncoderConfigurations, andAddAudioEncoderConfigurationoperations.StartMultiCastStreamingandStopMultiCastStreamingoperations.- Client shall be able to receive a multicast stream sent by a device.
GetRelayOutputsoperation.- Client shall be able to set the settings of a relay output using the
SetRelayOutputSettingsoperation.- Client shall be able to trigger a relay output using the
SetRelayOutputStateoperation.GetNTPandSetNTPoperations.GetDynamicDNSandSetDynamicDNSoperations.GetZeroConfigurationandSetZeroConfigurationoperations.GetIPAddressFilter,SetIPAddressFilter,AddIPAddressFilterandRemoveIPAddressFilteroperations.