相关推荐
纯c语言 onvif编程 从搜索到rtsp取流保存视频文件
2024-11-10 17:39
#include "onvif_cfg.h"

纯c语言 onvif编程  从搜索到rtsp取流保存视频文件

#include "onvif_rtsp.h" #if 1 static callback msg_pro_fun; static Onvif_Login_t ipcLoginInfo[IPC_NUM_MAX]; static pthread_mutex_t Login_mutex = PTHREAD_MUTEX_INITIALIZER; void ONVIF_IPC_MSG_CallBack_API(callback fun) { msg_pro_fun = (void*)fun; } int ONVIF_IPC_GetLoginInfo_API(unsigned int usrId,Onvif_Login_t* info) { if(usrId >= IPC_NUM_MAX) { return -1; } memset(info,0,sizeof(Onvif_Login_t)); memcpy(info,&ipcLoginInfo[usrId],sizeof(Onvif_Login_t)); return 0; } int ONVIF_IPC_Login_API(char *ip,int port) { if((ip == NULL) || (port <= 0)) { printf("ip is NULL or port is err "); return -1; } int i = 0; pthread_mutex_lock( &Login_mutex); for(i = 0; i < IPC_NUM_MAX; i++) { if(ipcLoginInfo[i].flag == 0) { ipcLoginInfo[i].idx = i+LOGIN_VAL; ipcLoginInfo[i].port= port; memcpy(ipcLoginInfo[i].ip,ip,strlen(ip)); memcpy(ipcLoginInfo[i].admin,"admin",5); memcpy(ipcLoginInfo[i].passwd,"123456",6); ipcLoginInfo[i].flag = 1; break; } } if(i == IPC_NUM_MAX) { pthread_mutex_unlock( &Login_mutex ); printf("cur ipc login num :%d ",IPC_NUM_MAX); return -1; } pthread_mutex_unlock( &Login_mutex ); return ipcLoginInfo[i].idx; } int ONVIF_IPC_UnLogin_API(unsigned int usrId) { int i = 0; usrId -= LOGIN_VAL; if(usrId >= IPC_NUM_MAX) { printf("usrId is err "); return -1; } pthread_mutex_lock( &Login_mutex); for(i = 0; i < IPC_NUM_MAX; i++) { if(ipcLoginInfo[i].idx == usrId) { ipcLoginInfo[i].idx = 0; ipcLoginInfo[i].port= 0; ipcLoginInfo[i].flag = 0; } } if(i == IPC_NUM_MAX) { printf("this usrId not logined "); pthread_mutex_unlock( &Login_mutex ); return -1; } pthread_mutex_unlock( &Login_mutex ); return 0; } int ONVIF_IPC_GetCapabilities_API(int usrid) { int strlen = 0; int ret = 0; char cfgStr[1024] = { 0 }; usrid -= LOGIN_VAL; if((usrid >= IPC_NUM_MAX) || (usrid < 0)) { printf("usrid is err: usrid = %d ",usrid); return -1; } char * rcvData = (char *)malloc(RCV_BUFF_SIZE); assert(rcvData); strlen = sprintf(cfgStr,"%s","<?xml version="1.0" encoding="utf-8"?> "); strlen += sprintf(cfgStr+strlen,"%s","<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema"> "); strlen += sprintf(cfgStr+strlen,"%s"," <soap:Body> <tds:GetCapabilities> <tds:Category>Media</tds:Category> </tds:GetCapabilities> </soap:Body> </soap:Envelope>"); ret = ONVIF_IPC_Send_API(cfgStr,strlen,ipcLoginInfo[usrid].ip,ipcLoginInfo[usrid].port); if(ret < 0) { printf("Send: GetCapabilities Failed ... "); goto END; } ret = ONVIF_IPC_Recv_API(rcvData); if(ret > 0) { msg_pro_fun(usrid,ONVIF_MSG_GET_CAPABILITIES,rcvData,ret); } else { printf("Recv: GetCapabilities Failed ...ret = %d ",ret); goto END; } END: if(rcvData) { free(rcvData); rcvData = NULL; } return ret; } int ONVIF_IPC_GetStreamUrl_FUN(int usrid,VideoEncodeCfg *cfg) { int strlen = 0; int ret = 0; char *str = NULL; char *str1 = NULL; char cfgStr[1024] = { 0 }; if((usrid >= IPC_NUM_MAX) || (usrid < 0)) { printf("usrid is err: usrid = %d ",usrid); return -1; } char * rcvData = (char *)malloc(RCV_BUFF_SIZE); memset(rcvData,0,RCV_BUFF_SIZE); assert(rcvData); strlen = sprintf(cfgStr,"%s","<?xml version="1.0" encoding="utf-8"?> "); strlen += sprintf(cfgStr+strlen,"%s","<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema"> "); strlen += sprintf(cfgStr+strlen,"%s","<soap:Body><GetStreamUri xmlns="http://www.onvif.org/ver10/media/wsdl">"); strlen += sprintf(cfgStr+strlen,"%s","<StreamSetup><Stream xmlns="http://www.onvif.org/ver10/schema">RTP-Unicast</Stream>"); strlen += sprintf(cfgStr+strlen,"%s","<Transport xmlns="http://www.onvif.org/ver10/schema">"); strlen += sprintf(cfgStr+strlen,"%s","<Protocol>UDP</Protocol>"); strlen += sprintf(cfgStr+strlen,"%s","</Transport></StreamSetup>"); strlen += sprintf(cfgStr+strlen,"<ProfileToken>%s</ProfileToken>",cfg->tokn); strlen += sprintf(cfgStr+strlen,"%s","</GetStreamUri></soap:Body></soap:Envelope>"); ret = ONVIF_IPC_Send_API(cfgStr,strlen,ipcLoginInfo[usrid].ip,ipcLoginInfo[usrid].port); if(ret < 0) { printf("Send: GetStreamUrl Failed ... "); goto END; } //printf("GetStreamUrl send: %s ",cfgStr); ret = ONVIF_IPC_Recv_API(rcvData); if(ret < 0) { printf("Recv: GetStreamUrl Failed ... "); goto END; } //printf("GetStreamUrl Recv: %s ",rcvData); ret = ONVIF_IPC_ChkData_FUN(rcvData); if(ret < 0) { printf("Chk GetStreamUrl Failed ... "); goto END; } str = strstr(rcvData,"<tt:Uri>"); if(!str) { printf("GetStreamUrl Failed ... "); ret = -1; goto END; } str1 = strstr(str,"</tt:Uri>"); if(!str1) { printf("GetStreamUrl Failed ... "); ret = -1; goto END; } memcpy(cfg->url,str+8,str1-str-8); printf("cfg->url = %s ",cfg->url); END: if(rcvData) { free(rcvData); rcvData = NULL; } return ret; } int ONVIF_IPC_GetParam_FUN(char *data,char *sStr,char *param) { assert(data); assert(param); char *str = NULL; str = strstr(data,sStr); if(!str) { return -1; } sscanf(str,"%*[^>]>%[^</]",param); return 0; } int ONVIF_IPC_GetCfgToknAndName_FUN(char *data,char *tokn,char *name) { assert(data); assert(tokn); assert(name); char *temp = NULL; temp = strstr(data,"Configurations token"); if(!temp) { printf("GetCfgTokn Failed ... "); return -1; } sscanf(temp,"%*[^"]"%[^</"]",tokn); if(ONVIF_IPC_GetParam_FUN(temp,"<tt:Name>",name) < 0) { printf("GetCfgName Failed ... "); return -1; } return 0; } int ONVIF_IPC_GetVideoCfg_FUN(Onvif_IpcVideoEnc_t *videoEncCfg,char *data,int len) { assert(videoEncCfg); assert(data); assert(len); char param[32] = { 0 }; char *SubStreamStr = NULL; char *temp = NULL; if(ONVIF_IPC_GetCfgToknAndName_FUN(data,videoEncCfg->encodeCfg[0].tokn,videoEncCfg->encodeCfg[0].name) < 0) { printf("GetCfgToknAndName failed ... "); return -1; } if(ONVIF_IPC_GetParam_FUN(data,"<tt:Encoding>",param) < 0) { printf("get video type failed ... "); return -1; } memcpy(videoEncCfg->encodeCfg[0].encodeFormat,param,strlen(param)); if(ONVIF_IPC_GetParam_FUN(data,"<tt:Width>",param) < 0) { printf("get video Width failed ... "); return -1; } videoEncCfg->encodeCfg[0].width = atoi(param); if(ONVIF_IPC_GetParam_FUN(data,"<tt:Height>",param) < 0) { printf("get video Height failed ... "); return -1; } videoEncCfg->encodeCfg[0].height = atoi(param);
    以上就是本篇文章【纯c语言 onvif编程 从搜索到rtsp取流保存视频文件】的全部内容了,欢迎阅览 ! 文章地址:http://yejunbin01.xhstdz.com/quote/62348.html 
     栏目首页      相关文章      动态      同类文章      热门文章      网站地图      返回首页 物流园资讯移动站 http://yejunbin01.xhstdz.com/mobile/ , 查看更多   
发表评论
0评