linux onvif 客户端,Linux下onvif客户端获取ipc摄像头 GetStreamUri:rtsp地址(h264、h265)...

#include #include#include#include#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, inttimeout)

{struct soap *soap = NULL; //soap环境变量

unsigned char macaddr[6];char _HwId[1024];

unsignedintFlagrand;

soap=soap_new();if(soap ==NULL)

{

printf("[%d]soap = NULL\n", __LINE__);returnNULL;

}

soap_set_namespaces(soap, namespaces);//设置soap的namespaces,即设置命名空间//设置超时(超过指定时间没有数据就退出)

if(timeout > 0)

{

soap->recv_timeout =timeout;

soap->send_timeout =timeout;

soap->connect_timeout =timeout;

}else{//Maximum waittime : 20s

soap->recv_timeout = 20;

soap->send_timeout = 20;

soap->connect_timeout = 20;

}

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(0));

Flagrand= rand()%9000 + 8888;

macaddr[0] = 0x1;

macaddr[1] = 0x2;

macaddr[2] = 0x3;

macaddr[3] = 0x4;

macaddr[4] = 0x5;

macaddr[5] = 0x6;

sprintf(_HwId,"urn:uuid:%ud68a-1dd2-11b2-a105-%02X%02X%02X%02X%02X%02X", Flagrand, macaddr[0], macaddr[1], macaddr[2],macaddr[3],macaddr[4],macaddr[5]);

header->wsa__MessageID = (char *)malloc(100);

memset(header->wsa__MessageID, 0, 100);

strncpy(header->wsa__MessageID, _HwId, strlen(_HwId)); //wsa__MessageID存放的是uuid

if(was_Action !=NULL)

{

header->wsa__Action = (char*)malloc(1024);

memset(header->wsa__Action, '\0', 1024);

strncpy(header->wsa__Action, was_Action, 1024); //}if(was_To !=NULL)

{

header->wsa__To = (char *)malloc(1024);

memset(header->wsa__To, '\0', 1024);

strncpy(header->wsa__To, was_To, 1024);//"urn:schemas-xmlsoap-org:ws:2005:04:discovery";

}

soap->header =header;returnsoap;

}//释放函数

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 = 0;if((NULL != username) || (NULL !=password)){

soap_wsse_add_UsernameTokenDigest(soap, NULL, username, password);

}else{

printf("un etAuth\n");

result= -1;

}returnresult;

}int main(int argc,char *argv[])

{int i = 0;int ret = 0;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获取

structSOAP_ENV__Header header;struct soap* soap = ONVIF_Initsoap(&header, NULL, NULL, 5);//...............................................h264通道....................................................

struct_trt__GetStreamUri trt__GetStreamUri;struct_trt__GetStreamUriResponse response;

trt__GetStreamUri.StreamSetup= (struct tt__StreamSetup*)soap_malloc(soap, sizeof(structtt__StreamSetup));if (NULL ==trt__GetStreamUri.StreamSetup){

printf("soap_malloc is error\n");

ret= -1;

}

trt__GetStreamUri.StreamSetup->Stream = tt__StreamType__RTP_Unicast;//stream type

trt__GetStreamUri.StreamSetup->Transport = (struct tt__Transport *)soap_malloc(soap, sizeof(structtt__Transport));if (NULL == trt__GetStreamUri.StreamSetup->Transport){

printf("soap_malloc is error\n");

ret= -1;

}

trt__GetStreamUri.StreamSetup->Transport->Protocol = 1;

trt__GetStreamUri.StreamSetup->Transport->Tunnel = 0;

trt__GetStreamUri.StreamSetup->__size = 1;

trt__GetStreamUri.StreamSetup->__any =NULL;

trt__GetStreamUri.StreamSetup->__anyAttribute =NULL;

trt__GetStreamUri.ProfileToken= (char *)soap_malloc(soap, 128*sizeof(char ));// if (NULL ==trt__GetStreamUri.ProfileToken){

printf("soap_malloc is error\n");

ret= -1;

}

strcpy(trt__GetStreamUri.ProfileToken, taken);

ONVIF_SetAuthInfo(soap,"admin","123456"); //鉴权

soap_call___trt__GetStreamUri(soap, media_addr, NULL, &trt__GetStreamUri, &response);if(soap->error){

ret= -1;

printf("soap error: %d, %s, %s\n", soap->error, *soap_faultcode(soap), *soap_faultstring(soap));returnret;

}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);returnret;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值