美文网首页开发者协议
Onvif开发纪录篇(一)

Onvif开发纪录篇(一)

作者: Young_Allen | 来源:发表于2017-05-05 16:32 被阅读982次

    1.介绍

    ONVIF(Open Network Video Interface Forum,开放型网络视频接口论坛)
    ONVIF规范描述了网络视频的模型、接口、数据类型以及数据交互的模式。并复用了一些现有的标准,如WS系列标准等。ONVIF规范的目标是实现一个网络视频框架协议,使不同厂商所生产的网络视频产品(包括摄录前端、录像设备等)完全互通。  
    ONVIF规范中设备管理和控制部分所定义的接口均以Web Services的形式提供。ONVIF规范涵盖了完全的XMLWSDL的定义。每一个支持ONVIF规范的终端设备均须提供与功能相应的Web Service。服务端与客户端的数据交互采用SOAP协议。ONVIF中的其他部分比如音视频流则通过RTP/RTSP进行 。
    首页地址:https://www.onvif.org/

    2.Gsoap安装:

    下载gsoap_2.8.45.zip安装包,使用unzip gsoap_2.8.45.zip命令行解压,会解出gsoap-2.8目录:


    解压完后,准备环境和安装Gsoap,如果Ubuntu之前没有安装以下工具包需要先安装:
    # sudo apt-get install build-essential
    # sudo apt-get install libgtk2.0-dev libglib2.0-dev
    # sudo apt-get install checkinstall
    # sudo apt-get install flex bison
    # sudo apt-get install openssl
    # sudo apt-get install libssl-dev

    编译环境准备完后在gsoap解压更目录准备编译:
    # ./configure --prefix=/usr/local/gSOAP
    # make
    # make install

    config执行结果 编译成功

    执行make install成功后可发现在/usr/local/gSOAP/bin/目录:

    这两个文件就是wsdl自动生成客户端服务端源码的关键

    3.WSDL自动生成源代码

    可以分为在线配置和本地配置(本文仅会介绍在Ubuntu中自动生成源码的方法,在Windows或OS,以及生成java/js等其他目标源码的方法可以自己尝试):

    本地配置:

    可通过onvif官网地址右键另存文件如图:


    把下载好的wsdl文件放在onvif目录:

    可以自己编写一个这样的脚本wsdl2hOnvif.sh:
    #!/bin/bash
    /usr/local/gSOAP/bin/wsdl2h -c++ -s -t typemap.dat -o ./onvif.h onvif/devicemgmt.wsdl onvif/event.wsdl onvif/accesscontrol.wsdl onvif/accessrules.wsdl onvif/advancedsecurity.wsdl onvif/analytics.wsdl onvif/credential.wsdl onvif/deviceio.wsdl onvif/display.wsdl onvif/doorcontrol.wsdl onvif/imaging.wsdl onvif/media.wsdl onvif/media2.wsdl onvif/provisioning.wsdl onvif/ptz.wsdl onvif/receiver.wsdl onvif/recording.wsdl onvif/search.wsdl onvif/replay.wsdl onvif/schedule.wsdl onvif/thermal.wsdl onvif/analyticsdevice.wsdl onvif/remotediscovery.wsdl

    wsdl指令介绍:
    Usage: wsdl2h [-a] [-b] [-c|-c++|-c++11] [-d] [-e] [-f] [-g] [-h] [-I(大写i) path] [-i] [-j] [-k] [-l] [-m] [-M] [-N name] [-n name] [-P|-p] [-q name] [-R] [-r proxyhost[:port[:uid:pwd]]] [-r:userid:passwd] [-s] [-t typemapfile] [-U] [-u] [-V] [-v] [-w] [-W] [-x] [-y] [-z#] [-_] [-o outfile.h] infile.wsdl infile.xsd http://www... ...

    args discribe
    -a generate indexed struct names for local elements with anonymous types
    -b bi-directional operations (duplex ops) added to serve one-way responses
    -c generate C source code
    -c++ generate C++ source code (default)
    -c++11 generate C++11 source code
    -d use DOM to populate xs:any, xs:anyType, and xs:anyAttribute
    -e don't qualify enum names
    -f generate flat C++ class hierarchy
    -g generate global top-level element declarations
    -h display help info
    -I(大写i)path use path to find files
    -i don't import (advanced option)
    -j don't generate SOAP_ENV__Header and SOAP_ENV__Detail definitions
    -k don't generate SOAP_ENV__Header mustUnderstand qualifiers
    -l display license information
    -m use xsd.h module to import primitive types
    -M suppress error "must understand element with wsdl:required='true'"
    -Nname use name for service prefixes to produce a service for each binding
    -nname use name as the base namespace prefix instead of 'ns'
    -ofile output to file
    -P don't create polymorphic types inherited from xsd__anyType
    -p create polymorphic types inherited from base xsd__anyType
    -qname use name for the C++ namespace of all declarations
    -R generate REST operations for REST bindings specified in a WSDL
    -rhost[:port[:uid:pwd]] connect via proxy host, port, and proxy credentials
    -r:uid:pwd connect with authentication credentials (digest auth requires SSL)
    -s don't generate STL code (no std::string and no std::vector)
    -tfile use type map file instead of the default file typemap.dat
    -U allow UTF8-encoded Unicode C/C++ identifiers when mapping XML tag names
    -u don't generate unions
    -V display the current version and exit
    -v verbose output
    -W suppress warnings
    -w always wrap response parameters in a response struct (<=1.1.4 behavior)
    -x don't generate _XML any/anyAttribute extensibility elements
    -y generate typedef synonyms for structs and enums
    -z1 compatibility with 2.7.6e: generate pointer-based arrays
    -z2 compatibility with 2.7.7 to 2.7.15: qualify element/attribute references
    -z3 compatibility with 2.7.16 to 2.8.7: qualify element/attribute references
    -z4 compatibility up to 2.8.11: don't generate union structs in std::vector
    -z5 compatibility up to 2.8.15
    -z6 compatibility up to 2.8.17
    -_ don't generate _USCORE (replace with UNICODE _x005f)
    infile.wsdl infile.xsd http://www... list of input sources (if none reads stdin)

    本地文件在编译时由于路径问题可能导致编译失败,修改对应路径即可,编译成功后会自动生成一个onvif.h文件。
    修改为本地文件对应目录:



    编译成功后结果:


    在线配置:

    在可以直接连接onvif网站且网络速度较好情况下,推荐使用在线配置方式,可以避免路径文件不正常问题,但比较依赖网络,配置时间可能较长。
    可以自己编写一个这样的脚本wsdl2hOnvif_Online.sh:

    #!/bin/bash
    /usr/local/gSOAP/bin/wsdl2h -c++ -s -t typemap.dat -o ./onvif.h https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl https://www.onvif.org/ver10/events/wsdl/event.wsdl ohttps://www.onvif.org/ver10/pacs/accesscontrol.wsdl https://www.onvif.org/ver10/pacs/accessrules.wsdl https://www.onvif.org/ver10/actionengine.wsdl https://www.onvif.org/ver10/advancedsecurity/wsdl/advancedsecurity.wsdl https://www.onvif.org/ver20/analytics/wsdl/analytics.wsdl http://www.onvif.org/ver10/credential/wsdl/credential.wsdl https://www.onvif.org/ver10/deviceio.wsdl https://www.onvif.org/ver10/display.wsdl https://www.onvif.org/ver10/pacs/doorcontrol.wsdl https://www.onvif.org/ver20/imaging/wsdl/imaging.wsdl https://www.onvif.org/ver10/media/wsdl/media.wsdl https://www.onvif.org/ver20/media/wsdl/media.wsdl https://www.onvif.org/ver10/provisioning/wsdl/provisioning.wsdl https://www.onvif.org/ver20/ptz/wsdl/ptz.wsdl https://www.onvif.org/ver10/receiver.wsdl https://www.onvif.org/ver10/recording.wsdl https://www.onvif.org/ver10/search.wsdl https://www.onvif.org/ver10/replay.wsdl http://www.onvif.org/ver10/schedule/wsdl/schedule.wsdl https://www.onvif.org/ver10/thermal/wsdl/thermal.wsdl https://www.onvif.org/ver10/analyticsdevice.wsdl https://www.onvif.org/onvif/ver10/network/wsdl/remotediscovery.wsdl 
    

    编译成功结果:


    生成onvif.h文件后,就可以通过onvif.h文件生成对应的cpp源码:
    可以自己编写一个这样的脚本soapcpp2Onvif.sh:
    #!/bin/bash
    rm ./onvif_out/* -rf
    /usr/local/gSOAP/bin/soapcpp2 -C -L -c++ -d ./onvif_out -i -I ../gsoap-2.8/gsoap:../gsoap-2.8/gsoap/import:../gsoap-2.8/gsoap/custom:../gsoap-2.8/gsoap/extras -x onvif.h
    /usr/local/gSOAP/bin/soapcpp2 -C -L -c++ -d ./onvif_out -I ../gsoap-2.8/gsoap:../gsoap-2.8/gsoap/import:../gsoap-2.8/gsoap/custom:../gsoap-2.8/gsoap/extras -x onvif.h
    soapcpp2指令介绍:
    Usage: soapcpp2 [-0|-1|-2] [-C|-S] [-T] [-Ecdt] [-L] [-a] [-A] [-b] [-c|-c++|-c++11] [-d path] [-e] [-f N] [-h] [-i] [-I(大写i) path:path:...] [-l] [-m] [-n] [-p name] [-Q name] [-q name] [-r] [-s] [-t] [-u] [-V] [-v] [-w] [-x] [-y] [-z#] [infile]

    args discribe
    -1 generate SOAP 1.1 bindings
    -2 generate SOAP 1.2 bindings
    -0 no SOAP bindings, use REST
    -C generate client-side code only
    -S generate server-side code only
    -T generate server auto-test code
    -Ec generate extra routines for deep copying
    -Ed generate extra routines for deep deletion
    -Et generate extra routines for data traversals with walker functions
    -L don't generate soapClientLib/soapServerLib
    -a use SOAPAction with WS-Addressing to invoke server-side operations
    -A require SOAPAction to invoke server-side operations
    -b serialize byte arrays char[N] as string
    -c generate C source code
    -c++ generate C++ source code (default)
    -c++11 generate C++ source code optimized for C++11 (compile with -std=c++11)
    -dpath use path to save files
    -e generate SOAP RPC encoding style bindings (also use -1 or -2)
    -fN multiple soapC files, with N serializer definitions per file (N>=10)
    -h display help info
    -I(大写i)path use path(s) for #import (paths separated with ':')
    -i generate C++ service proxies and objects inherited from soap struct
    -j generate C++ service proxies and objects that share a soap struct
    -l generate linkable modules (experimental)
    -m generate Matlab(tm) code for MEX compiler (deprecated)
    -n use service name to rename service functions and namespace table
    -pname save files with new prefix name instead of 'soap'
    -Qname use name as the C++ namespace for decls, including custom serializers
    -qname use name as the C++ namespace for decls, excluding custom serializers
    -r generate soapReadme.md report
    -s generate deserialization code with strict XML validation checks
    -t generate code for fully xsi:type typed SOAP/XML messaging
    -u uncomment comments in WSDL/schema output by suppressing XML comments
    -V display the current version and exit
    -v verbose output
    -w don't generate WSDL and schema files
    -x don't generate sample XML message files
    -y include C/C++ type access information in sample XML messages
    -z1 compatibility: generate old-style C++ service proxies and objects
    -z2 compatibility with 2.7.x: omit XML output for NULL pointers
    -z3 compatibility with 2.8.30 and earlier: _param_N is indexed globally
    infile header file to parse (if none reads stdin)

    编译成功结果:



    编译后的文件列表:

    有了这些文件后就可以开始通过soapClient接口来实现各项onvif的功能了。下一篇将会介绍相关onvif的功能实现。

    相关文章

      网友评论

        本文标题:Onvif开发纪录篇(一)

        本文链接:https://www.haomeiwen.com/subject/zhlvzttx.html