Skip to content

ONVIF: camera information and discovery

Getting camera information without starting the live stream

  • create the filter instance,
  • query the filter interface and invoke (e.g. in C++):
hr = DatasteadRtspSourceConfig.Action (RTSP_Action_GetONVIFInfo, "rtsp://...");
if (SUCCEEDED (hr)) {
   WCHAR *OnvifInfo;
   hr = DatasteadRtspSourceConfig.GetStr (RTSP_ONVIF_Info_As_XML_str, &OnvifInfo);
   if (SUCCEEDED (hr)) {
      MessageBox (0, OnvifInfo, NULL, 0);
   }
}

The GetStr (RTSP_ONVIF_Info...) functions can then be invoked to read the individual ONVIF settings (manufacturer, model, serial number, firmware version, PTZ information...), see the Parameter identifiers section.

ONVIF discovery

The filter supports the ONVIF discovery through the IDatasteadONVIFDiscovery interface, declared in the following files:

Language Declaration file
C# Include\CSharp\DatasteadRTSPSourceFilter.cs
VB.NET Include\VB.NET\DatasteadRTSPSourceFilter.vb
C++ Include\Cpp\DatasteadRTSPSourceFilter.h
Delphi Include\Delphi\DatasteadRTSPSourceFilter.pas

The interface exposes the following functions:

Function Description
DiscoverCameras_Multicast (timeout) WS-Discovery multicast probe, sent on every network interface of the PC
DiscoverCameras_ScanIPNetwork (network_address, network_mask, timeout) probes every address of the network (network and broadcast addresses excluded)
DiscoverCameras_ScanIPRange (ipaddress_start, ipaddress_stop, timeout) probes every address of the range, 65536 addresses at most
CancelCameraDiscovery () stops the discoveries in progress; returns E_NOT_SET when no discovery is running
EnumCamerasDiscovered (CameraIndex, &CameraType, &CameraONVIFServiceUrl) returns the type and the ONVIF service URL of a camera of the list
SetDiscoveryNotificationCallback (DiscoveryCallback, Context) registers the notification callback

The IP scans (network or range) send a WS-Discovery probe to each address; the addresses that do not answer are then queried over HTTP on port 80 (ONVIF device service).

Timeout

timeout_seconds_or_0_for_default is the total duration of the discovery, in seconds: 0 selects the default duration (4 seconds), 600 seconds at most.

Running a discovery

  • the DiscoverCameras... functions start the discovery in the background and return immediately (S_OK); E_PENDING is returned when a discovery of the same kind (multicast, or IP scan) is already running,
  • a multicast discovery and an IP scan can run at the same time: the cameras found are cumulated in the same list. The list is cleared when a discovery starts while no other discovery is running.

Notification callback

enum TONVIFDiscoveryStatus { dcs_CameraFound, dcs_MulticastCompleted, dcs_IPRangeCompleted };
typedef void (__stdcall *TDiscoveryCallback) (void* opaque, TONVIFDiscoveryStatus DiscoveryCallbackStatus, int CameraCount);
  • dcs_CameraFound occurs for each new camera, dcs_MulticastCompleted and dcs_IPRangeCompleted at the end of each discovery; CameraCount is the number of cameras currently in the list, opaque the context passed to SetDiscoveryNotificationCallback,
  • the callback is invoked from a worker thread of the filter, not from the thread of the application: marshal the call to the UI thread if needed,
  • a new discovery can be started from a completion callback,
  • do not release the filter from a dcs_CameraFound callback (the discovery keeps running afterwards); it can be released from a completion callback or from any other thread.

Enumerating the cameras

Invoke EnumCamerasDiscovered in a loop, with CameraIndex starting from 0, until the function returns an error (E_INVALIDARG when CameraIndex >= the number of cameras). It can be invoked from the notification callback.

The strings returned belong to the filter: do not free them. They remain valid until the second discovery started after the call: copy them to keep them longer.

The sample code is included in the DatasteadRTSPSource_CSharp_Demo C# project.