LIBVONIF FOR WINDOWS
________________________________________________________________________________
INTRODUCTION
libonvif can be built using Visual Studio tools and integrated into a project
by linking as either a static library or DLL. libonvif has a dependency on
libxml2, so the libonvif.zip file is packaged with a libxml2 installation
included. This means you can build the entire project from the appropriate
command prompt by running the BUILD.BAT file. This will produce the debug and
release versions of the static and DLL libraries. Integration of libonvif into
a larger project requires linking with libonvif. Note that if you are using
the DLL version of the library, you will need to include both the
libonvifdll.dll and the libxml2.dll with your distribution. The static library
has all object code included, therefore does not require additional files.
BUILDING LIBONVIF
libonvif can be built from source by extracting the contents of the libonvif.zip
file. The .zip archive has the following directory structure.
<DIR> libonvif
<DIR> libonvif
<DIR> libxml2
Building libonvif from source requires the use of tools installed with Microsoft
Visual Studio. It has been tested with VS2015 and VS2017 but should work with
other versions as well. These installations include the command prompts for
various target platforms, notably x86 for 32 bit executables and x64 for 64 bit.
These command prompts can be found in the installed Visual Studio folder from
the Start menu.
Navigate to the libonvif\libonvif directory and from there run the BUILD.BAT
command using the appropriate Visual Studio command prompt. This will build the
libxml2 dependencies and then compile libonvif. The result is the following
directory structure within the libonvif folder where the files of interest may
be found.
<DIR> libonvif
<DIR> libonvif
<DIR> release
<DIR> debug
<DIR> x64
<DIR> release
<DIR> debug
<DIR> libxml2
<DIR> include
:
RUNNING THE TEST PROGRAM
After completion of the build, you may test the installation by running the test
example program. This program will conduct a broadcast on the local network
using Onvif protocol. Compatible cameras will respond with a udp packet
containing information required to communicate. libonvif will then query the
camera for the RSTP string. There are two versions of the test program, one for
static library and the oher for DLL. For example, to run the static 32 bit
release version:
C:\libonvif\libonvif> release\libonvif_test
The DLL version of the test program can be run by using
C:\libonvif\libonvif> release\libonvifdll_test
The example program will respond with the number of cameras found, and then
prompt for username and password after showing the camera name. A successful
transaction will conclude with the RTSP string, then move on to the next camera.
INTEGRATING LIBONVIF INTO YOUR PROJECT
libonvif may be integrated into a Visual Studio project by linking to the
library. The details are similar for static and DLL versions, but there is a
difference. You should also be aware that bitness and VS version should be
respected. This is done by compiling libonvif with the same version of Visual
Studio you are using with the project.
Linking requires three types of configuration settings, the INCLUDE directories,
the LIBRARY PATH directories and the DEPENDENCIES. These settings are made on
the Project->Property Pages. Please note that when working with the property
pages for a project, that there are separate pages for each Configuration and
Platform. A common mistake can be avoided by insuring that the configuration
and platform of the property page matches the current configuration and platform
of the the projects.
To set the INCLUDE directories, navigate to the C/C++ | General page from the
left hand navigation panel of the Property Pages. The first setting is for
Additional Include Directories and you should add both the libonvif directory
and the libxml2\include directory, for example
C:\libonvif\libonvif;C:\libonvif\libxml2\include
You may also use relative pathnames, which is probably a better solution, but
you will need to determine those based on your individual situation. For
advanced users, this setting may also be applied as All Configurations and
All Platforms, as it is not configuration dependent.
Following the setting of the Additional Include Directories, click the Apply
button of the Property Pages to commit the the change, or risk losing the
setting.
To set the LIBRARY PATH directories, now use the left hand navigation panel to
go to Linker | General page. About halfway down this page is a setting for
Additional Library Directories. This setting will depend on the Configuration
and Platform setting and will be different for each. As an example, the
setting for Release x64 will look as follows
C:\libonvif\libonvif\x64\release
Again, relative pathnames may be used. However, note that this directory will
change for each Configuration and Platform.
To set the DEPENDENCIES, now use the left hand navigation panel to go to the
Linker | Input page. At the top of the page is a setting for Additional
Depecndencies. This will be different depending on whether you are building
with the static library or DLL.
For static library, this setting is: libonvif.lib
For DLL library, this setting is: libonvifdll.lib
Please note that if you are building for DLL, you will need the libonvifdll.dll
and the libxml2.dll files for the executable to run. These files can be found
in the appropriate configuration and platform directories, which will be the
same as the library path set above.
Once you have completed the settings for the linker, you may copy and paste the
code from the example program to discover and query cameras on your network.
Your program file will need the #include "onvif.h" directive to compile.
NOTES ON THE EXAMPLE PROGRAM
The purpose of the example program is to discover cameras on the network and
obtain the RTSP uri string to initiate streaming. This is the most commonly
used Onvif function. libonvif is a c library so you are required to manage the
memory. This is not too difficult as there are only two dat a structure that
require memory allocation, OnvifSession and OnvifData. OnvifSession
encompasses global Onvif variables so you only need one per program. You
should call initializeSession prior to calling any Onvif functions and close
the session when no longer needed. You will need to free the OnvifSession
structure as well at that time.
OnvifData is a structure holding camera parameters and information, and you will
need one of these each time you communicate with a camera. The example program
re-uses a single OnvifData structure each time it communicates with that
camera, but you may want to allocate an OnvifData structure for each camera
you find. You should free the OnvifData structure when it is no longer needed
to avoid memory leaks.
The broadcast function of libonvif sends a UDP broadcast packet recognized by
Onvif devices. Connected cameras will respond with a UDP packet reply which
will be processed by libonvif which will return the number of cameras found.
If you use this example program for a while, you will notice that sometimes a
camera may not respond to the UDP broadcast all the time. This is not unusual
and will vary with network conditions and camera variability. It is common
practice for broadcast functions to be repeated several times to give devices
several chances to respond. It is a good idea when doing this to increase the
time interval between broadcasts.
Once the camera has been found, the function prepareOnvifData will initialize
the OnvifData structure with the parameters needed for successful communication.
At this point, the OnvifData structure is ready for authentication against the
camera and the username and password are collected from the terminal prompt.
The function fillRTSP will get the RTSP uri string from the camera. fillRTSP
will return a non-zero integer in the case of communication error, and the
error message can be found in the last_error field of OnvifData.
LICENSING
LIBONVIF
/*******************************************************************************
*
* copyright 2018 Stephen Rhodes
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*******************************************************************************/
LIBXML2
Except where otherwise noted in the source code (e.g. the files hash.c,
list.c and the trio files, which are covered by a similar licence but
with different Copyright notices) all the files are:
Copyright (C) 1998-2012 Daniel Veillard. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is fur-
nished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
SHA1.C
SHA-1 in C
By Steve Reid <steve@edmweb.com>
100% Public Domain
CENCODE.C
/*
cencoder.c - c source to a base64 encoding algorithm implementation
This is part of the libb64 project, and has been placed in the public domain.
For details, see http://sourceforge.net/projects/libb64
**MODIFIED FOR LIBONVIF - remove trailing \n
*/