天天看點

onvif java開發_Onvif開發紀錄篇(一)

1.介紹

ONVIF(Open Network Video Interface Forum,開放型網絡視訊接口論壇)

ONVIF規範描述了網絡視訊的模型、接口、資料類型以及資料互動的模式。并複用了一些現有的标準,如WS系列标準等。ONVIF規範的目标是實作一個網絡視訊架構協定,使不同廠商所生産的網絡視訊産品(包括攝錄前端、錄像裝置等)完全互通。

ONVIF規範中裝置管理和控制部分所定義的接口均以Web Services的形式提供。ONVIF規範涵蓋了完全的XML及WSDL的定義。每一個支援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目錄:

onvif java開發_Onvif開發紀錄篇(一)

解壓完後,準備環境和安裝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

onvif java開發_Onvif開發紀錄篇(一)

config執行結果

onvif java開發_Onvif開發紀錄篇(一)

編譯成功

執行make install成功後可發現在/usr/local/gSOAP/bin/目錄:

onvif java開發_Onvif開發紀錄篇(一)

這兩個檔案就是wsdl自動生成用戶端服務端源碼的關鍵

3.WSDL自動生成源代碼

可以分為線上配置和本地配置(本文僅會介紹在Ubuntu中自動生成源碼的方法,在Windows或OS,以及生成java/js等其他目标源碼的方法可以自己嘗試):

本地配置:

可通過onvif官網位址右鍵另存檔案如圖:

onvif java開發_Onvif開發紀錄篇(一)

把下載下傳好的wsdl檔案放在onvif目錄:

onvif java開發_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 java開發_Onvif開發紀錄篇(一)

本地檔案在編譯時由于路徑問題可能導緻編譯失敗,修改對應路徑即可,編譯成功後會自動生成一個onvif.h檔案。

修改為本地檔案對應目錄:

onvif java開發_Onvif開發紀錄篇(一)

編譯成功後結果:

onvif java開發_Onvif開發紀錄篇(一)

線上配置:

在可以直接連接配接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 java開發_Onvif開發紀錄篇(一)

生成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)

編譯成功結果:

onvif java開發_Onvif開發紀錄篇(一)

編譯後的檔案清單:

onvif java開發_Onvif開發紀錄篇(一)

有了這些檔案後就可以開始通過soapClient接口來實作各項onvif的功能了。下一篇将會介紹相關onvif的功能實作。