菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
47
0

onvif 协议

原创
05/13 14:22
阅读数 45359

1、ONVIF 协议解读

 

https://www.onvif.org

 

 

一、什么是ONVIF?

1.1形成

2008年5月,由安讯士(AXIS)联合博世(BOSCH)及索尼(SONY)公司三方宣布携手共同成立一个国际开放型网络视频产品标准网络接口开发论坛,取名为ONVIF(Open Network Video Interface Forum,开放型网络视频接口论坛),并以公开、开放的原则共同制定开放性行业标准。ONVIF标准将为网络视频设备之间的信息交换定义通用协议,包括装置搜寻、实时视频、音频、元数据和控制信息等。截止到2011年3月,已有279个公司加入ONVIF成为会员。

2008年11月,论坛正式发布了ONVIF第一版规范。

2010年11月,论坛发布了ONVIF第二版规范。规范涉及设备发现、实时音视频、摄像头PTZ控制、录像控制、视频分析等方面。

1.2规范作用

ONVIF规范描述了网络视频的模型、接口、数据类型以及数据交互的模式。并复用了一些现有的标准,如WS系列标准等。ONVIF规范的目标是实现一个网络视频框架协议,使不同厂商所生产的网络视频产品(包括摄录前端、录像设备等)完全互通。

ONVIF规范中设备管理和控制部分所定义的接口均以Web Services的形式提供,设备作为服务提供者为服务端。ONVIF规范涵盖了完全的XMLWSDL的定义。每一个支持ONVIF规范的终端设备均须提供与功能相应的Web Service。服务端与客户端的数据交互采用SOAP协议。ONVIF中的其他部分比如音视频流则通过RTP/RTSP进行 。

1.3规范优势

协同性:不同厂商所提供的产品,均可以通过一个统一的“语言”来进行交流。方便了系统的集成。

灵活性:终端用户和集成用户不需要被某些设备的固有解决方案所束缚。大大降低了开发成本。

质量保证:不断扩展的规范将由市场来导向,遵循规范的同时也满足主流的用户需求。

由于采用WSDL+XML模式,使ONVIF规范的后续扩展不会遇到太多的麻烦。XML极强的扩展性与SOAP协议开发的便捷性将吸引更多的人来关注和使用ONVIF规范。

ONVIF组织日益扩大,与同领域的PSIA,HDCCTV相比,占据了绝对的人员优势。会员企业不乏国内外著名的设备制造商与集成商。一套规范、协议的生命周期,与市场占有率是息息相关的。而ONVIF规范的发展则正是由市场来导向,由用户来充实的。每一个成员企业都拥有加强、扩充ONVIF规范的权利。ONVIF规范所涵盖的领域将不断增大。目前门禁系统的相关内容也即将被纳入ONVIF规范之中。在安防、监控系统急速发展的今天,效率和质量的领先所带来的价值不言而喻。ONVIF协议提供了这样的潜质。

二、ONVIF规范的实现机制

2.1 Web Service

Web Service是基于网络的、分布式的模块化组件,执行特定的任务。Web Service 主要利用HTTP 和SOAP 协议使数据在Web 上传输。Web 用户能够使用 SOAP 和 HTTP通过 Web 调用的方法来调用远程对象。 

 

       Web Service是基于XML和HTTPS的一种服务,其通信协议主要基于SOAP。服务端、客户端以传递符合XML的SOAP消息实现服务的请求与回应。

 

客户端根据 WSDL 描述文档,会生成一个 SOAP 请求消息,该请求会被嵌入在一个HTTP POST请求中,发送到 Web Services 所在的Web 服务器。Web Services 请求处理器解析收到的SOAP 请求,调用相应的 Web Services。然后再生成相应的 SOAP 应答。Web 服务器得到SOAP 应答后,会再通过 HTTP应答的方式把信息送回到客户端。

 

2.2 WSDL

WSDL是Web services 描述语言(Web Service Description Language)的缩写。是一个用来描述Web服务和说明如何与Web服务通信的XML语言,为用户提供详细的接口说明书。

2.3 SOAP

SOAP是Simple Object Access Protocol的缩写。是基于XML的一种协议。一条 SOAP 消息就是一个普通的 XML 文档,包含下列元素:

必需的 Envelope 元素,可把此 XML 文档标识为一条 SOAP 消息

可选的 Header 元素,包含头部信息

必需的 Body 元素,包含所有的调用和响应信息

可选的 Fault 元素,提供有关在处理此消息所发生错误的信息

在向Web Service发送的SOAP请求中,Body元素中的字段需与WSDL中数据类型的相符合。在构建SOAP的过程中,必须从WSDL文件中获取并映射这一种对应关系。然而这样一个对应过程将是充满了重复性和机械性的,为了避免不必要的人工差错以及节约开发时间,一个名为gSOAP的编译工具应运而生。

gSOAP利用编译器技术提供了一组透明化的SOAP API,并将与开发无关的SOAP实现细节相关的内容对用户隐藏起来。通过将WSDL文件解析序列化为C/C++文件,最小化了Web Service的开发过程。

 

SOAP协议位置

2.4 ONVIF规范

ONVIF规范向视频监控引入了Web Service的概念。设备的实际功能均被抽象为了Web Service的服务,视频监控系统的控制单元以客户端的身份出现,通过Web请求的形式完成控制操作。

 

2.4.1 Web Service能为视频监控什么?

a)     设备的无关性,任何一个设备接入系统,不会对其他系统造成影响。

b)     设备的独立性,每一个设备只负责对接收到的请求做出反馈,甚至不需要知晓控制端的存在。

c)     管理的集中性,所有的控制由客户端来发起。

 

2.4.2 ONVIF规范能为视频监控带来什么?

a)     抽象了功能的接口。统一了对设备的配置以及操作的方式。

b)     控制端关心的不是设备的型号,而是设备所提供的Web Service。

c)     规范了视频系统中Web Service范围之外的行为。

d)     ONVIF提供了各个模块的WSDL,拥有效率非常高的开发方式。

 

3、ONVIF规范的内容

a)        设备发现

b)        设备管理

c)        设备输入输出服务

d)        图像配置

e)        媒体配置

f)         实时流媒体

g)        接收端配置

h)        显示服务

i)          事件处理

j)          PTZ控制

k)        其他

4、ONVIF的应用

4.1 名词说明

CMU(Center Manager Unit),即中心管理单位。

PU(Prefocus Unit),即监控前端单元,负责在CMU的控制下使用摄像机采集视频流、使用麦克风采集音频流、使用控制口采集报警信息、对摄像机云台镜头进行控制。

CU(Client Unit),监控系统的监控客户端单元,负责将PU采集到的视频流、音频流、报警信息提交给监控用户,并根据用户要求操作PU设备,如云台、镜头等。

4.2 传统视频监控系统的一个局域网应用场景

a)        PU设备上线后,向CMU注册,建立连接。

b)        CMU与PU进行信令交互,请求能力集,获取配置。

c)        CU上线,向CMU注册,建立连接。

d)        CMU与CU进行信令交互,传输设备列表。

e)        CU向PU请求码流。

 

4.3 应用ONVIF规范后对应的场景

a)        PU设备上线后,向CMU发送HELLO消息。

b)        CMU需要搜寻设备时,向PU发送PROBE消息。

c)        CMU与PU进行信令交互,请求能力集,获取配置。

d)        CU上线,向CMU注册,建立连接。

e)        CMU与CU进行信令交互,传输设备列表。

f)         在CMU的协调下,CU同PU建立连接传输码流。

 

上述场景中,ONVIF带来了什么变化?

a)        PU与CMU的交互方式发生了改变,CMU不再与PU保持长连接。

       b)       遵循ONVIF规范,信令以及消息内容有了统一的标准。

2

非常重要的部分就是视频流的对接,即能够在符合onvif标准的监控客户端软件里接收到设备端NVT发来的RTSP视频流。这里,我所用的客户端软件是Onvif Device Manager v2.2。

ONVIF Profile S Specification文档描述了Device或者说DVT和Client可以使用的一种Profile,Profile这个词在计算机领域非常常见,我们可以理解成一种方案、配置、框架等。

文档里描述了如果实现VideoStream,device和client应该具备的条件,当然如果实现文档的所有条件,就可以说该设备符合Profile S

如果单纯实现VideoStream,只需完成下列命令。

 

  1. 1、GetProfiles  
  2. 2、GetStreamUri   
  3. 填充rtsp路径,例如:rtsp://192.168.1.201/petrov.m4e  
  4. 3、Media Streaming using RTSP  
  5. 这里使用开源的live555,完成rtsp功能  
  6. 4、GetVideoEncoderConfiguration  
  7. 5、GetVideoEncoderConfigurationOptions  
  8. 6、GetCapabilities  
  9. NVC为了获取DVT所支持的功能的命令  

 

参考文档:

 

  1. 1、ONVIF Profile S Specification  
  2. 描述ProfileS是什么样的一个东西,如何实现  
  3. 2、Reference_of_ONVIF_Development_v1.01.02  
  4. Onvif DVT设计参考,指明了一条道路,但没有具体内容  
  5. 3、ONVIF-Media-Service-Spec-v220  
  6. Onvif Media的说明介绍  
  7. 4、http://www.onvif.org/onvif/ver20/util/operationIndex.html  
  8. onvif几乎全部命令的详细说明,非常重要。该文档告诉我们结构体成员的意义和如何填充。Onvif开发其实就是各种结构体的填充。  

 

一、产生onvif源码框架

1、从wsdl生成C头文件

 

  1. wsdl2h -o onvif.h -c -s -t .\typemap.dat http://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl http://www.onvif.org/onvif/ver10/event/wsdl/event.wsdl http://www.onvif.org/onvif/ver10/display.wsdl http://www.onvif.org/onvif/ver10/deviceio.wsdl http://www.onvif.org/onvif/ver20/imaging/wsdl/imaging.wsdl http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl http://www.onvif.org/onvif/ver20/ptz/wsdl/ptz.wsdl  http://www.onvif.org/onvif/ver10/receiver.wsdl http://www.onvif.org/onvif/ver10/recording.wsdl  http://www.onvif.org/onvif/ver10/search.wsdl http://www.onvif.org/onvif/ver10/network/wsdl/remotediscovery.wsdl http://www.onvif.org/onvif/ver10/replay.wsdl http://www.onvif.org/onvif/ver20/analytics/wsdl/analytics.wsdl http://www.onvif.org/onvif/ver10/analyticsdevice.wsdl  http://www.onvif.org/onvif/ver10/schema/onvif.xsd  http://www.onvif.org/ver10/actionengine.wsdl  

跟前一篇discovery唯一不同的是,这里多了很多wsdl文件,这次创建完整的onvif代码框架

 

2、从头文件生成源码框架

 

  1. soapcpp2 -c onvif.h -x -I /root/onvif/gsoap-2.8/gsoap/import -I /root/onvif/gsoap-2.8/gsoap/  

产生的C文件比较庞大,最大的有十几兆,大部分的内容没有复用导致。

 

二、创建soap运行环境

 

  1. int main(int argc, char **argv)    
  2. {    
  3.     int m, s;    
  4.     struct soap add_soap;    
  5.     int server_udp;  
  6.   
  7.     server_udp = create_server_socket_udp();  
  8.     //bind_server_udp1(server_udp);  
  9.     pthread_t thrHello;  
  10. 10.     pthread_t thrProbe;  
  11. 11.     //pthread_create(&thrHello,NULL,main_Hello,server_udp);  
  12. 12.     //sleep(2);  
  13. 13.     pthread_create(&thrProbe,NULL,main_Probe,server_udp);  
  14. 14.   
  15. 15.     soap_init(&add_soap);    
  16. 16.     soap_set_namespaces(&add_soap, namespaces);    
  17. 17.   
  18. 18.   
  19. 19.     if (argc < 0) {    
  20. 20.         printf("usage: %s <server_port> \n", argv[0]);    
  21. 21.         exit(1);    
  22. 22.     } else {    
  23. 23.         m = soap_bind(&add_soap, NULL, 80, 100);    
  24. 24.         if (m < 0) {    
  25. 25.             soap_print_fault(&add_soap, stderr);    
  26. 26.             exit(-1);    
  27. 27.         }    
  28. 28.         fprintf(stderr, "Socket connection successful: master socket = %d\n", m);    
  29. 29.         for (;;) {    
  30. 30.             s = soap_accept(&add_soap);    
  31. 31.             if (s < 0) {    
  32. 32.                 soap_print_fault(&add_soap, stderr);    
  33. 33.                 exit(-1);    
  34. 34.             }    
  35. 35.             fprintf(stderr, "Socket connection successful: slave socket = %d\n", s);    
  36. 36.             soap_serve(&add_soap);    
  37. 37.             soap_end(&add_soap);    
  38. 38.         }    
  39. 39.     }    
  40. 40.     return 0;    

41. }   

注意,这里绑定了80端口,onvif使用的是http请求,然后附带xml,其实正常的是将onvif集成到web服务器中,普通的http请求有web服务器处理,onvif的http请求则有soap处理。我们这里的做法也可行,只不过onvif的访问web服务器的功能是无法使用的。

 

三、RTSP视频对接

1、实现GetCapabilities命令

客户端发送GetCapabilities命令来得到设备端的能力,然后依据GetCapabilities返回的结果再来进行下一步操作

在__tds__GetCapabilities函数中我们只需要填充Media部分和一些必要的即可

 

  1. //想要对接RTSP视频,必须设置Media  
  2. tds__GetCapabilitiesResponse->Capabilities->Media = (struct tt__MediaCapabilities*)soap_malloc(soap, sizeof(struct tt__MediaCapabilities));  
  3. tds__GetCapabilitiesResponse->Capabilities->Media->XAddr = (char *) soap_malloc(soap, sizeof(char) * LARGE_INFO_LENGTH);  
  4. strcpy(tds__GetCapabilitiesResponse->Capabilities->Media->XAddr, _IPv4Address);  
  5. tds__GetCapabilitiesResponse->Capabilities->Media->StreamingCapabilities = (struct tt__RealTimeStreamingCapabilities*)soap_malloc(soap, sizeof(struct tt__RealTimeStreamingCapabilities));  
  6. tds__GetCapabilitiesResponse->Capabilities->Media->StreamingCapabilities->RTPMulticast = (int *)soap_malloc(soap, sizeof(int));   
  7. *tds__GetCapabilitiesResponse->Capabilities->Media->StreamingCapabilities->RTPMulticast = _false;     
  8. tds__GetCapabilitiesResponse->Capabilities->Media->StreamingCapabilities->RTP_USCORETCP = (int *)soap_malloc(soap, sizeof(int));  
  9. *tds__GetCapabilitiesResponse->Capabilities->Media->StreamingCapabilities->RTP_USCORETCP = _true;     

10. tds__GetCapabilitiesResponse->Capabilities->Media->StreamingCapabilities->RTP_USCORERTSP_USCORETCP = (int *)soap_malloc(soap, sizeof(int));  

11. *tds__GetCapabilitiesResponse->Capabilities->Media->StreamingCapabilities->RTP_USCORERTSP_USCORETCP = _true;      

12. tds__GetCapabilitiesResponse->Capabilities->Media->StreamingCapabilities->Extension = NULL;  

13. tds__GetCapabilitiesResponse->Capabilities->Media->Extension = NULL;  

14. tds__GetCapabilitiesResponse->Capabilities->Media->__size = 0;  

15. tds__GetCapabilitiesResponse->Capabilities->Media->__any = 0;  

另外必要填充的还有

 

 

  1. //下面的重要,这里只实现视频流,需要设置VideoSources  
  2. tds__GetCapabilitiesResponse->Capabilities->Extension->DeviceIO->VideoSources = TRUE;  
  3. tds__GetCapabilitiesResponse->Capabilities->Extension->DeviceIO->VideoOutputs = FALSE;  
  4. tds__GetCapabilitiesResponse->Capabilities->Extension->DeviceIO->AudioSources = FALSE;  
  5. tds__GetCapabilitiesResponse->Capabilities->Extension->DeviceIO->AudioOutputs = FALSE;  
  6. tds__GetCapabilitiesResponse->Capabilities->Extension->DeviceIO->RelayOutputs = FALSE;  
  7. tds__GetCapabilitiesResponse->Capabilities->Extension->DeviceIO->__size = 0;  
  8. tds__GetCapabilitiesResponse->Capabilities->Extension->DeviceIO->__any = NULL;  
  9.   

10. tds__GetCapabilitiesResponse->Capabilities->Extension->Display = NULL;  

11. tds__GetCapabilitiesResponse->Capabilities->Extension->Recording = NULL;  

12. tds__GetCapabilitiesResponse->Capabilities->Extension->Search = NULL;  

13. tds__GetCapabilitiesResponse->Capabilities->Extension->Replay = NULL;  

14. tds__GetCapabilitiesResponse->Capabilities->Extension->Receiver = NULL;  

15. tds__GetCapabilitiesResponse->Capabilities->Extension->AnalyticsDevice = NULL;  

16. tds__GetCapabilitiesResponse->Capabilities->Extension->Extensions = NULL;  

17. tds__GetCapabilitiesResponse->Capabilities->Extension->__size = 0;  

18. tds__GetCapabilitiesResponse->Capabilities->Extension->__any = NULL;  

2、实现GetServices命令

 

 

  1. int  __tds__GetServices(struct soap* soap, struct _tds__GetServices *tds__GetServices, struct _tds__GetServicesResponse *tds__GetServicesResponse)  
  2. {  
  3.     DBG("__tds__GetServices\n");  
  4.     /*该函数很必要*/  
  5.     char _IPAddr[INFO_LENGTH];  
  6.     int i = 0;  
  7.     sprintf(_IPAddr, "http://%03d.%03d.%03d.%03d/onvif/services", 192, 168, 1, 233);  
  8.     tds__GetServicesResponse->__sizeService = 1;  
  9.   
  10. 10.     tds__GetServicesResponse->Service = (struct tds__Service *)soap_malloc(soap, sizeof(struct tds__Service));  
  11. 11.     tds__GetServicesResponse->Service[0].XAddr = (char *)soap_malloc(soap, sizeof(char) * INFO_LENGTH);  
  12. 12.     tds__GetServicesResponse->Service[0].Namespace = (char *)soap_malloc(soap, sizeof(char) * INFO_LENGTH);  
  13. 13.     strcpy(tds__GetServicesResponse->Service[0].Namespace, "http://www.onvif.org/ver10/events/wsdl");  
  14. 14.     strcpy(tds__GetServicesResponse[0].Service->XAddr, _IPAddr);  
  15. 15.     tds__GetServicesResponse->Service[0].Capabilities = NULL;  
  16. 16.     tds__GetServicesResponse->Service[0].Version = (struct tt__OnvifVersion *)soap_malloc(soap, sizeof(struct tt__OnvifVersion));  
  17. 17.     tds__GetServicesResponse->Service[0].Version->Major = 0;  
  18. 18.     tds__GetServicesResponse->Service[0].Version->Minor = 3;  
  19. 19.     tds__GetServicesResponse->Service[0].__any = (char **)soap_malloc(soap, sizeof(char *));  
  20. 20.     tds__GetServicesResponse->Service[0].__any[0] = (char *)soap_malloc(soap, sizeof(char) * INFO_LENGTH);  
  21. 21.     strcpy(tds__GetServicesResponse->Service[0].__any[0],"why1");  
  22. 22.     tds__GetServicesResponse->Service[0].__any[1] = (char *)soap_malloc(soap,sizeof(char) * INFO_LENGTH);  
  23. 23.     strcpy(tds__GetServicesResponse->Service[0].__any[1],"why2");  
  24. 24.     tds__GetServicesResponse->Service[0].__size = NULL;  
  25. 25.     tds__GetServicesResponse->Service[0].__anyAttribute = NULL;  
  26. 26.     return SOAP_OK;  

27. }  

3、实现GetVideoSources命令

  1. int  __tmd__GetVideoSources(struct soap* soap, struct _trt__GetVideoSources *trt__GetVideoSources, struct _trt__GetVideoSourcesResponse *trt__GetVideoSourcesResponse)  
  2. {  
  3.     DBG("__tmd__GetVideoSources\n");  
  4.   
  5.     int size1;  
  6.     size1 = 1;  
  7.     trt__GetVideoSourcesResponse->__sizeVideoSources = size1;  
  8.     trt__GetVideoSourcesResponse->VideoSources = (struct tt__VideoSource *)soap_malloc(soap, sizeof(struct tt__VideoSource) * size1);  
  9.     trt__GetVideoSourcesResponse->VideoSources[0].Framerate = 30;  
  10. 10.     trt__GetVideoSourcesResponse->VideoSources[0].Resolution = (struct tt__VideoResolution *)soap_malloc(soap, sizeof(struct tt__VideoResolution));  
  11. 11.     trt__GetVideoSourcesResponse->VideoSources[0].Resolution->Height = 720;  
  12. 12.     trt__GetVideoSourcesResponse->VideoSources[0].Resolution->Width = 1280;  
  13. 13.     trt__GetVideoSourcesResponse->VideoSources[0].token = (char *)soap_malloc(soap, sizeof(char)*INFO_LENGTH);  
  14. 14.     strcpy(trt__GetVideoSourcesResponse->VideoSources[0].token,"GhostyuSource_token"); //注意这里需要和GetProfile中的sourcetoken相同  
  15. 15.   
  16. 16.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging =(struct tt__ImagingSettings*)soap_malloc(soap, sizeof(struct tt__ImagingSettings));  
  17. 17.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->Brightness = (float*)soap_malloc(soap,sizeof(float));  
  18. 18.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->Brightness[0] = 128;  
  19. 19.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->ColorSaturation = (float*)soap_malloc(soap,sizeof(float));  
  20. 20.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->ColorSaturation[0] = 128;  
  21. 21.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->Contrast = (float*)soap_malloc(soap,sizeof(float));  
  22. 22.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->Contrast[0] = 128;  
  23. 23.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->IrCutFilter = (int *)soap_malloc(soap,sizeof(int));  
  24. 24.     *trt__GetVideoSourcesResponse->VideoSources[0].Imaging->IrCutFilter = 0;   
  25. 25.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->Sharpness = (float*)soap_malloc(soap,sizeof(float));  
  26. 26.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->Sharpness[0] = 128;  
  27. 27.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->BacklightCompensation = (struct tt__BacklightCompensation*)soap_malloc(soap, sizeof(struct tt__BacklightCompensation));  
  28. 28.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->BacklightCompensation->Mode = 0;  
  29. 29.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->BacklightCompensation->Level = 20;  
  30. 30.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->Exposure = NULL;  
  31. 31.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->Focus = NULL;  
  32. 32.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->WideDynamicRange = (struct tt__WideDynamicRange*)soap_malloc(soap, sizeof(struct tt__WideDynamicRange));  
  33. 33.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->WideDynamicRange->Mode = 0;     
  34. 34.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->WideDynamicRange->Level = 20;  
  35. 35.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->WhiteBalance = (struct tt__WhiteBalance*)soap_malloc(soap, sizeof(struct tt__WhiteBalance));  
  36. 36.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->WhiteBalance->Mode = 0;   
  37. 37.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->WhiteBalance->CrGain = 0;   
  38. 38.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->WhiteBalance->CbGain = 0;   
  39. 39.     trt__GetVideoSourcesResponse->VideoSources[0].Imaging->Extension = NULL;  
  40. 40.     trt__GetVideoSourcesResponse->VideoSources[0].Extension = NULL;    
  41. 41.     return SOAP_OK;  

42. }  

__tmd__GetVideoSources最重要的是token的填充,必须要和下面profile中的sourcetoken相同,需要匹配到这个视频源

 

4、实现GetProfiles命令

 

  1. size = 1;  
  2. trt__GetProfilesResponse->Profiles =(struct tt__Profile *)soap_malloc(soap, sizeof(struct tt__Profile) * size);  
  3. trt__GetProfilesResponse->__sizeProfiles = size;  
  4.   
  5. i=0;  
  6. trt__GetProfilesResponse->Profiles[i].Name = (char *)soap_malloc(soap,sizeof(char)*MAX_PROF_TOKEN);  
  7. strcpy(trt__GetProfilesResponse->Profiles[i].Name,"my_profile");  
  8. trt__GetProfilesResponse->Profiles[i].token= (char *)soap_malloc(soap,sizeof(char)*MAX_PROF_TOKEN);  
  9. strcpy(trt__GetProfilesResponse->Profiles[i].token,"token_profile");  

10. trt__GetProfilesResponse->Profiles[i].fixed = _false;  

11. trt__GetProfilesResponse->Profiles[i].__anyAttribute = NULL;  

除了上面的基本信息,还需要填充两大项:VideoSourceConfiguration和VideoEncoderConfiguration,一个用于描述视频源的信息,另外一个描述视频的编码信息

 

先给VideoSourceConfiguration分配空间

  1. trt__GetProfilesResponse->Profiles[i].VideoSourceConfiguration = (struct tt__VideoSourceConfiguration *)soap_malloc(soap,sizeof(struct tt__VideoSourceConfiguration ));  
  2. trt__GetProfilesResponse->Profiles[i].VideoSourceConfiguration->Name = (char *)soap_malloc(soap,sizeof(char)*MAX_PROF_TOKEN);  
  3. trt__GetProfilesResponse->Profiles[i].VideoSourceConfiguration->token = (char *)soap_malloc(soap,sizeof(char)*MAX_PROF_TOKEN);  
  4. trt__GetProfilesResponse->Profiles[i].VideoSourceConfiguration->SourceToken = (char *)soap_malloc(soap,sizeof(char)*MAX_PROF_TOKEN);  
  5. trt__GetProfilesResponse->Profiles[i].VideoSourceConfiguration->Bounds = (struct tt__IntRectangle *)soap_malloc(soap,sizeof(struct tt__IntRectangle));  

然后在填充它

 

 

  1. /*注意SourceToken*/  
  2. strcpy(trt__GetProfilesResponse->Profiles[i].VideoSourceConfiguration->Name,"VS_Name");  
  3. strcpy(trt__GetProfilesResponse->Profiles[i].VideoSourceConfiguration->token,"VS_Token");  
  4. strcpy(trt__GetProfilesResponse->Profiles[i].VideoSourceConfiguration->SourceToken,"GhostyuSource_token"); /*必须与__tmd__GetVideoSources中的token相同*/  
  5. trt__GetProfilesResponse->Profiles[i].VideoSourceConfiguration->UseCount = 1;  
  6. trt__GetProfilesResponse->Profiles[i].VideoSourceConfiguration->Bounds->x = 1;  
  7. trt__GetProfilesResponse->Profiles[i].VideoSourceConfiguration->Bounds->y = 1;  
  8. trt__GetProfilesResponse->Profiles[i].VideoSourceConfiguration->Bounds->height = 720;  
  9. trt__GetProfilesResponse->Profiles[i].VideoSourceConfiguration->Bounds->width = 1280;  

如果是指针必须先用soap_malloc分配内存,然后才能赋值

 

下面是VideoEncoderConfiguration

 

  1. trt__GetProfilesResponse->Profiles[i].VideoEncoderConfiguration = (struct tt__VideoEncoderConfiguration *)soap_malloc(soap,sizeof(struct tt__VideoEncoderConfiguration));  
  2. trt__GetProfilesResponse->Profiles[i].VideoEncoderConfiguration->Name = (char *)soap_malloc(soap,sizeof(char)*MAX_PROF_TOKEN);  
  3. trt__GetProfilesResponse->Profiles[i].VideoEncoderConfiguration->token= (char *)soap_malloc(soap,sizeof(char)*MAX_PROF_TOKEN);  
  4. strcpy(trt__GetProfilesResponse->Profiles[i].VideoEncoderConfiguration->Name,"VE_Name1");  
  5. strcpy(trt__GetProfilesResponse->Profiles[i].VideoEncoderConfiguration->token,"VE_token1");  
  6. trt__GetProfilesResponse->Profiles[i].VideoEncoderConfiguration->UseCount = 1;  
  7. trt__GetProfilesResponse->Profiles[i].VideoEncoderConfiguration->Quality = 10;  
  8. trt__GetProfilesResponse->Profiles[i].VideoEncoderConfiguration->Encoding = 1;//JPEG = 0, MPEG4 = 1, H264 = 2;  
  9. trt__GetProfilesResponse->Profiles[i].VideoEncoderConfiguration->Resolution = (struct tt__VideoResolution *)soap_malloc(soap, sizeof(struct tt__VideoResolution));  

10. trt__GetProfilesResponse->Profiles[i].VideoEncoderConfiguration->Resolution->Height = 720;  

11. trt__GetProfilesResponse->Profiles[i].VideoEncoderConfiguration->Resolution->Width = 1280;  

12. trt__GetProfilesResponse->Profiles[i].VideoEncoderConfiguration->RateControl = (struct tt__VideoRateControl *)soap_malloc(soap, sizeof(struct tt__VideoRateControl));  

13. trt__GetProfilesResponse->Profiles[i].VideoEncoderConfiguration->RateControl->FrameRateLimit = 30;  

14. trt__GetProfilesResponse->Profiles[i].VideoEncoderConfiguration->RateControl->EncodingInterval = 1;  

15. trt__GetProfilesResponse->Profiles[i].VideoEncoderConfiguration->RateControl->BitrateLimit = 500;  

5、GetVideoSourceConfiguration和GetVideoEncoderConfiguration

 

  1. int  __trt__GetVideoSourceConfiguration(struct soap* soap, struct _trt__GetVideoSourceConfiguration *trt__GetVideoSourceConfiguration, struct _trt__GetVideoSourceConfigurationResponse *trt__GetVideoSourceConfigurationResponse)  
  2. {  
  3.     DBG("__trt__GetVideoSourceConfiguration\n");  
  4.     //该函数必要,live video需要  
  5.     return SOAP_OK;  
  6. }  
  7.   
  8. int  __trt__GetVideoEncoderConfiguration(struct soap* soap, struct _trt__GetVideoEncoderConfiguration *trt__GetVideoEncoderConfiguration, struct _trt__GetVideoEncoderConfigurationResponse *trt__GetVideoEncoderConfigurationResponse)  
  9. {  
  10. 10.     DBG("__trt__GetVideoEncoderConfiguration\n");  
  11. 11.     return SOAP_OK;  

12. }  

 

6、GetVideoEncoderConfigurationOptions

 

 

  1. int  __trt__GetVideoEncoderConfigurationOptions(struct soap* soap, struct _trt__GetVideoEncoderConfigurationOptions *trt__GetVideoEncoderConfigurationOptions, struct _trt__GetVideoEncoderConfigurationOptionsResponse *trt__GetVideoEncoderConfigurationOptionsResponse)  
  2. {  
  3.     DBG("__trt__GetVideoEncoderConfigurationOptions\n");  
  4.     //该函数必要,video streaming需要  
  5.     return SOAP_OK;  
  6. }  

以上5、6不分的代码直接返回SOAP_OK即可,正常来说是应该填充的,这里不影响RTSP Video Stream,暂时就不去动它

 

四、运行live555MediaServer服务器

 

live555官网有很多测试文件,我这里用的是MPEG4的测试文件路劲为rtsp://192.168.1.201/petrov.m4e

五、启动Onvif Device Manager测试

有一个问题,OnvifDeviceManager的并不能自动发现设备(OnvifTestTool可以),还好它提供了手动添加功能

单击add,添加如下内容:http://192.168.1.233/onvif/device_service

注意,我在程序中固定了两个IP:linux192.168.1.233,windows:192.168.1.201,这里需看情况修改

测试截图:

1、Live video

 

2、Video streaming

 

3、Profiles

 

最后是运行的live555 rtsp服务器

 

终端打印的DEBUG信息

 

源代码下载地址:http://download.csdn.Net/detail/ghostyu/4796093

onvif规范的实现:成功实现ONVIF协议RTSP-Video-Stream与OnvifDeviceManager的视频对接   http://blog.csdn.net/ghostyu/article/details/8208428

 

 

 

 

 

 

发表评论

0/200
47 点赞
0 评论
收藏
为你推荐 换一批