1、 设备搜索,去获取webserver 的地址 ,目的是在获取能力提供服务地址,demo:https://www.cnblogs.com/croxd/p/10683429.html
2、 GetCapabilities获取能力,目的是在GetProfiles时提供媒体地址,demo:https://www.cnblogs.com/croxd/p/10683503.html,
如果GetCapabilities获取能力失败,soap error 4 或者 52的话,可以参考:https://www.cnblogs.com/croxd/p/10684712.html
char sercer_addr[] = "http://172.168.0.211/onvif/device_service";//设备搜索获取到的地址
struct SOAP_ENV__Header header;
struct soap* soap = ONVIF_Initsoap(&header, NULL, NULL, 5);
struct _tds__GetCapabilities *req;
struct _tds__GetCapabilitiesResponse *Response;
req->__sizeCategory = 1;
req->Category = (enum tt__CapabilityCategory *)soap_malloc(soap, sizeof(int));
*(req->Category) = (enum tt__CapabilityCategory)5; //5表示:tt__CapabilityCategory__Media
ONVIF_SetAuthInfo(soap,"admin","123456"); //鉴权,输入摄像头的用户名、密码
ret = soap_call___tds__GetCapabilities(soap, sercer_addr, NULL,req, Response);
3 、GetServices获取多个媒体地址 demo:https://www.cnblogs.com/croxd/p/10683576.html
要是在获取GetProfiles时,用第二步的媒体地址不支持h265,那么你就需要调用这个接口。在这个接口的tds__GetServicesResponse结构体中可以获取两个媒体地址 。要是之前没有安装h265的gsoap环境,这边也是只能获取一个媒体地址,安装h265的环境请查看上一篇的文章 :Linux下onvi支持h265环境的的搭建
char secvre_addr[] = "http://172.168.0.211/onvif/device_service"; //设备搜索获取得到的服务地址
struct SOAP_ENV__Header header;
struct _tds__GetServices *tds__GetServices;
struct _tds__GetServicesResponse *tds__GetServicesResponse;
struct soap* soap = ONVIF_Initsoap(&header, NULL, NULL, 5);
tds__GetServices->IncludeCapability = 0;
ONVIF_SetAuthInfo(soap,"admin","123456"); //鉴权
soap_call___tds__GetServices(soap,secvre_addr,NULL, tds__GetServices, tds__GetServicesResponse);
4、GetProfiles 获取媒体信息文件 demo:https://www.cnblogs.com/croxd/p/10683598.html
从tr2__GetProfilesResponse结构体获取媒体信息文件,soap_call___tr2__GetProfiles接口是安装h265的环境时,gsoap框架所生成的接口。
char media_addr2[] = "http://172.168.0.211/onvif/media2_service"; //GetServices得到的地址
struct SOAP_ENV__Header header;
struct soap* soap = ONVIF_Initsoap(&header, NULL, NULL, 5);
struct _tr2__GetProfiles tr2__GetProfiles;
struct _tr2__GetProfilesResponse tr2__GetProfilesResponse;
tr2__GetProfiles.__sizeType = 1;
tr2__GetProfiles.Token = NULL;
tr2__GetProfiles.Type = NULL;
ONVIF_SetAuthInfo(soap,"admin","123456"); //鉴权
soap_call___tr2__GetProfiles(soap, media_addr2, NULL, &tr2__GetProfiles, &tr2__GetProfilesResponse);
5、 GetStreamUri 获取RTSP地址 demo:https://www.cnblogs.com/croxd/p/10683616.html
从tr2__GetStreamUriResponse结构体中获取h265的RTSP地址,soap_call___tr2__GetStreamUri接口是安装h265的环境时,gsoap框架所生成的接口。
char media_addr2[] = "http://172.168.0.211/onvif/media2_service"; //GetServices得到的地址
char taken[] = "Profile000"; //get_profiles获取
struct SOAP_ENV__Header header;
struct soap* soap = ONVIF_Initsoap(&header, NULL, NULL, 5);
struct _tr2__GetStreamUri tr2__GetStreamUri;
struct _tr2__GetStreamUriResponse tr2__GetStreamUriResponse;
tr2__GetStreamUri.Protocol = (char *)soap_malloc(soap, 128*sizeof(char));//
if (NULL == tr2__GetStreamUri.Protocol){
printf("soap_malloc is error\n");
ret = -1;
}
tr2__GetStreamUri.ProfileToken = (char *)soap_malloc(soap, 128*sizeof(char ));//
if (NULL == tr2__GetStreamUri.ProfileToken){
printf("soap_malloc is error\n");
ret = -1;
}
strcpy(tr2__GetStreamUri.Protocol, "tcp");
strcpy(tr2__GetStreamUri.ProfileToken, taken);
ONVIF_SetAuthInfo(soap,"admin","123456"); //鉴权
soap_call___tr2__GetStreamUri(soap, media_addr2, NULL, &tr2__GetStreamUri, &tr2__GetStreamUriResponse);
来源:oschina
链接:https://my.oschina.net/u/4332772/blog/3579660