Menu

Rationale

Stephen Rhodes

Rationale for developing libonvif

libonvif was developed as an alternative to the traditional cross platform method of connecting with Onvif compatible devices using GSOAP and OPENSSL. This approach was tried during the early stages of this effort during which a number of problems were encountered. Aside from the difficulty of compiling gsoap for (sometimes defunct) wsdl standard files and the shifting groundwork under openssl, the performance of the final product was weak as it failed to connect to a significant number of devices and was failing in discovery under windows in about half of the instances in which it was launched. Attempting to fix these problems in the source file for gsoap proved untenable as the root cause of the problems was buried so deep in the mountain of code that the effort was abandoned.

Gsoap failed to properly communicate with Hikvision cameras due to a lack of compliance with the Onvif standard in the html header files wrapping the xml code sent to the device. You can observe the header with Wireshark and see that there is a section indicating the service associated with the function the xml code is invoking. Most devices are tolerant of this parameter and will accept a generic device_service. This is not the case for Hikvision, which will fail if the exact string is not observed. The techincally correct method of sending this call is to query the device for its Capabilities and then use the returned service string identifiers to call functions for the respective services. Gsoap is hard coded to use device_service for all of these calls, which Hikvision will reject when addressing services other than device_service.

There is another problem when using windows that arises in this configuration. Gsoap fails to initialize the udp broadcast socket properly during preperation for the broadcast routine. This is not an issue in linux and mac systems as the default socket obtained during setsocketopt call is the one you would expect. Windows on the other hand, will randomly return a socket without qualification, often resulting in the loopback socket, which is obviously not going to get you any traffic on the network. This requires a bit of hunting through the IpAddrable under windows to find a socket that will actually communicate over the network.

Furthermore, Gsoap will rely on the default wsdl specification for the discovery xml message syntax during the discover process. Many cameras will not respond to this message, for whatever reason. The message used in libonvif was developed by trial and error over a large number of different types of camera to find one that will work most often. There is additionally a secondary message that may be invoked should the primary message fail to elicit a response from a particular device.