GetStreamUri:rtsp地址

鉴权:但是在使用这个接口之前是需要鉴权的。ONVIF协议规定,部分接口需要鉴权,部分接口不需要鉴权,在调用需要鉴权的接口时不使用鉴权,会导致接口调用失败。实现鉴权的方式之一可以调用gSOAP源码中的 soap_wsse_add_UsernameTokenDigest()函数。要安装依赖库OpenSSL

实现代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h> #include "soapH.h"
#include "stdsoap2.h"
#include "soapStub.h"
#include "wsseapi.h" #include "wsdd.nsmap" //命名空间 static struct soap* ONVIF_Initsoap(struct SOAP_ENV__Header *header, const char *was_To, const char *was_Action, int timeout)
{
struct soap *soap = NULL; // soap环境变量
unsigned char macaddr[];
char _HwId[];
unsigned int Flagrand; soap = soap_new();
if(soap == NULL)
{
printf("[%d]soap = NULL\n", __LINE__);
return NULL;
} soap_set_namespaces(soap, namespaces); // 设置soap的namespaces,即设置命名空间 // 设置超时(超过指定时间没有数据就退出)
if(timeout > )
{
soap->recv_timeout = timeout;
soap->send_timeout = timeout;
soap->connect_timeout = timeout;
}
else
{
//Maximum waittime : 20s
soap->recv_timeout = ;
soap->send_timeout = ;
soap->connect_timeout = ;
} soap_default_SOAP_ENV__Header(soap, header); //Create SessionID randomly,生成uuid(windows下叫guid,linux下叫uuid),格式为urn:uuid:8-4-4-4-12,由系统随机产生
srand((int)time());
Flagrand = rand()% + ;
macaddr[] = 0x1;
macaddr[] = 0x2;
macaddr[] = 0x3;
macaddr[] = 0x4;
macaddr[] = 0x5;
macaddr[] = 0x6;
sprintf(_HwId, "urn:uuid:%ud68a-1dd2-11b2-a105-%02X%02X%02X%02X%02X%02X", Flagrand, macaddr[], macaddr[], macaddr[],macaddr[],macaddr[],macaddr[]);
header->wsa__MessageID = (char *)malloc();
memset(header->wsa__MessageID, , );
strncpy(header->wsa__MessageID, _HwId, strlen(_HwId)); //wsa__MessageID存放的是uuid if(was_Action != NULL)
{
header->wsa__Action = (char*)malloc();
memset(header->wsa__Action, '\0', );
strncpy(header->wsa__Action, was_Action, ); //
}
if(was_To != NULL)
{
header->wsa__To = (char *)malloc();
memset(header->wsa__To, '\0', );
strncpy(header->wsa__To, was_To, );//"urn:schemas-xmlsoap-org:ws:2005:04:discovery";
}
soap->header = header;
return soap;
} //释放函数
void ONVIF_soap_delete(struct soap *soap)
{
soap_destroy(soap); // remove deserialized class instances (C++ only)
soap_end(soap); // Clean up deserialized data (except class instances) and temporary data
soap_free(soap); // Reset and deallocate the context created with soap_new or soap_copy
} //鉴权
static int ONVIF_SetAuthInfo(struct soap *soap, const char *username, const char *password)
{
int result = ;
if((NULL != username) || (NULL != password)){
soap_wsse_add_UsernameTokenDigest(soap, NULL, username, password);
}else{
printf("un etAuth\n");
result = -;
} return result;
} int main(int argc,char *argv[])
{
int i = ;
int ret = ;
char media_addr[] = "http://172.168.0.211/onvif/media_service"; //GetCapabilities得到的地址
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, ); //...............................................h264通道....................................................
struct _trt__GetStreamUri trt__GetStreamUri;
struct _trt__GetStreamUriResponse response;
trt__GetStreamUri.StreamSetup = (struct tt__StreamSetup*)soap_malloc(soap, sizeof(struct tt__StreamSetup));
if (NULL == trt__GetStreamUri.StreamSetup){
printf("soap_malloc is error\n");
ret = -;
} trt__GetStreamUri.StreamSetup->Stream = tt__StreamType__RTP_Unicast;//stream type
trt__GetStreamUri.StreamSetup->Transport = (struct tt__Transport *)soap_malloc(soap, sizeof(struct tt__Transport));
if (NULL == trt__GetStreamUri.StreamSetup->Transport){
printf("soap_malloc is error\n");
ret = -;
} trt__GetStreamUri.StreamSetup->Transport->Protocol = ;
trt__GetStreamUri.StreamSetup->Transport->Tunnel = ;
trt__GetStreamUri.StreamSetup->__size = ;
trt__GetStreamUri.StreamSetup->__any = NULL;
trt__GetStreamUri.StreamSetup->__anyAttribute = NULL; trt__GetStreamUri.ProfileToken = (char *)soap_malloc(soap, *sizeof(char ));//
if (NULL == trt__GetStreamUri.ProfileToken){
printf("soap_malloc is error\n");
ret = -;
}
strcpy(trt__GetStreamUri.ProfileToken, taken);
ONVIF_SetAuthInfo(soap,"admin",""); //鉴权
soap_call___trt__GetStreamUri(soap, media_addr, NULL, &trt__GetStreamUri, &response);
if(soap->error){
ret = -;
printf("soap error: %d, %s, %s\n", soap->error, *soap_faultcode(soap), *soap_faultstring(soap));
return ret;
}else{
printf("rtsp_addr: %s\n", response.MediaUri->Uri);
}
//...............................................h264通道.................................................... /* //...............................................h265通道....................................................
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);
if(soap->error){
ret = -1;
printf("soap error: %d, %s, %s\n", soap->error, *soap_faultcode(soap), *soap_faultstring(soap));
return ret;
}else{
printf("rtsp_addr: %s\n", tr2__GetStreamUriResponse.Uri);
}*/
//...............................................h265通道.................................................... ONVIF_soap_delete(soap);
return ret;
}

ps:一般情况是如果一开始用的是_tr2(h265),那么获取信息的时候应该就会一直用tr2(h265)通道。但是有些摄像头比较奇葩,一开始走的都是_tr2,也就是h265的通道(如get_profiles),但是在获取onvif的uri(rtsp地址)的时候本该走_tr2(h265)通道,却走了_trt(h264)的通道才能获取,我这个摄像头就是如此。

当然有些h265的摄像头走的是trt(h264)通道,并不会用到_tr2(h265)的通道。

编译:gcc -o test get_Uri_test.c stdsoap2.c soapC.c md5.c dom.c mecevp.c smdevp.c threads.c wsaapi.c wsseapi.c soapClient.c -I import/ -DWITH_OPENSSL -lssl -lcrypto -ldl -pthread

结果:

Linux下onvif客户端获取ipc摄像头 GetStreamUri:rtsp地址(h264、h265)的更多相关文章

  1. Linux下onvif客户端获取ipc摄像头 GetServices:获取媒体地址(有的h265摄像头必须要这个接口)

    GetServices:获取媒体地址(有些h265的摄像头必须用到这个接口,得到获取能力时没获取到的另一个媒体地址) 鉴权:但是在使用这个接口之前是需要鉴权的.ONVIF协议规定,部分接口需要鉴权,部 ...

  2. Linux下onvif客户端获取ipc摄像头 获取能力:GetCapabilities

    GetCapabilities:获取能力,主要目的获取设备能力信息(获取媒体服务地址) 鉴权:但是在调用获取设备能力之前是需要鉴权的.ONVIF协议规定,部分接口需要鉴权,部分接口不需要鉴权,在调用需 ...

  3. Linux下onvif客户端获取ipc摄像头 GetProfiles:获取h265媒体信息文件

    GetProfiles:获取媒体信息文件 鉴权:但是在使用这个接口之前是需要鉴权的.ONVIF协议规定,部分接口需要鉴权,部分接口不需要鉴权,在调用需要鉴权的接口时不使用鉴权,会导致接口调用失败.实现 ...

  4. Linux下onvif客户端关于ipc摄像头的搜索

    设备搜索:要访问一个IPC摄像头,或者说要调用IPC摄像头提供的WEB服务接口,就要先知道其IP地址,这就是设备发现的过程,或者叫设备搜索的过程.IPC摄像头用的是239.255.255.250(端口 ...

  5. Linux下onvif客户端获取h265 IPC摄像头的RTSP地址

    1. 设备搜索,去获取webserver 的地址 ,目的是在获取能力提供服务地址,demo:https://www.cnblogs.com/croxd/p/10683429.html 2. GetCa ...

  6. Linux下librdkafka客户端的编译运行

    Linux下librdkafka客户端的编译运行 librdkafka是一个开源的Kafka客户端C/C++实现,提供了Kafka生产者.消费者接口. 由于项目需要,我要将Kafka生产者接口封装起来 ...

  7. Linux 下 简单客户端服务器通讯模型(TCP)

    原文:Linux 下 简单客户端服务器通讯模型(TCP) 服务器端:server.c #include<stdio.h> #include<stdlib.h> #include ...

  8. Linux下用C获取当前时间

    Linux下用C获取当前时间,具体如下: 代码(可以把clock_gettime换成time(NULL)) ? 1 2 3 4 5 6 7 8 9 10 void getNowTime() {  ti ...

  9. Linux下用FFMPEG采集usb摄像头到RTMP

    Linux下用 FFMPEG 采集 usb摄像头视频 和 摄像头内置麦克风音频 到RTMP服务   ffmpeg -f video4linux2 -qscale 10 -r 12 -s 640x480 ...

随机推荐

  1. 附加到SQL2012的数据库就不能再附加到低于SQL2012的数据库版本

    附加到SQL2012的数据库就不能再附加到低于SQL2012的数据库版本 昨天我只是将数据库附加到SQL2012,然后各个数据库都做了收缩事务日志的操作 兼容级别这些都没有改 再附加回SQL2005的 ...

  2. mysqldump的假注释

    今天在查看mysqldump内容的时候,发现类似注释的东西,仔细了解了下, If you add a version number after the “!” character, the synta ...

  3. 【MySQL】Linux下mysql安装全过程——小白入门篇(含有问题详解)

    本次安装操作在申请的腾讯云上实现(版本:CentOS Linux release 7.4.1708 (Core) ). 根据教程实现(中途各种挖坑,填坑...),地址:http://www.runoo ...

  4. TreeView控件概述、属性与方法

    1.作用:用于显示Node结点的分层列表.2.添加到控件箱菜单命令:工程 | 部件,在部件对话框中选择:Microsoft Windows Common Controls 6.03.TreeView控 ...

  5. 转:动态table分页(ORCALE)

    前端:<table style="width: 100%;"> <tr> <td> 搜索字: <asp:TextBox ID=" ...

  6. [翻译] USING GIT IN XCODE [1] 在XCODE中使用GIT[1]

    USING GIT IN XCODE http://www.cimgf.com/2013/12/10/using-git-in-xcode/ Git has become a very popular ...

  7. 最强自定义PHP集成环境,系统缺失dll和vc也能正常运行

    PHPWAMP支持iis.apache.nginx等web服务器,并全部支持php多版本同时运行,无限自定义mysql.php PHPWAMP支持32和64,支持自定义自动匹配系统所需dll和vc,纯 ...

  8. Linux--安全加固01

    Redhat是目前企业中用的最多的一类Linux,而目前针对Redhat攻击的黑客也越来越多了.我们要如何为这类服务器做好安全加固工作呢? 一. 账户安全 1.1 锁定系统中多余的自建帐号 检查方法: ...

  9. 项目属性的target platform和target platform version到底是什么(vs2015开发windows驱动小记)

    根据官方对属性页的介绍(General Property Page (Project))可了解: target platform是build后的结果会跑在哪个平台,例如windows,android, ...

  10. 将本地已有项目上传到github

    1.在github上创建一个文件 2.看本地C盘中是否有.ssh文件夹 (C:\Users\用户名\.ssh) 检测有没有.ssh文件夹:执行命令   cd ~/.ssh 如果没有的话执行git命令: ...