java对接⼤华SDK摄像头监控
java对接⼤华SDK摄像头监控
SDK对接
前⾔
⼩编在接到对接⼤华摄像头实时监控在⽹页显⽰直播视频,先是在⽹上寻了⼀番,发现对接⼤华的博⽂少之⼜少,⽽且⼤多都是收费的。没办法只能硬着头⽪上,功夫不负有⼼⼈,终于搞定这该死的监控了...
获取SDK
我相信看到这篇⽂章的⼩伙伴都已经拥有了SDK,ps:官⽹也可以下载,⼀般调⽤SDK都是分为Windows和Linux的,但是我们开发项⽬基本上都是要上线的,所以此处我基于linux的配置来讲
官⽹提供的类:
IDpsdkCore类为加载动态链接库,Windows加载的是.dll Linux加载的是.so
windows:
linux:
配置环境变量
Windows版本的sdk是不需要配置环境变量的,但我们程序部署于linux时是需要配置环境变量的,配置如下:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:(libDPSDK_Java.so所在⽬录绝对路径):(linuxjava中的lib⽬录绝对路径) export CLASSPATH=$CLASSPATH:(demo/src⽬录所在的绝对路径):(当前⽬录相对路径)
例如:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/linuxjava/:/root/linuxjava/lib
export CLASSPATH=$CLASSPATH:/home/linuxjava/demo/src/:./
拉取实时监控数据
⼤华SDK提供了很多的监控功能,例如回放、报警、实时直播,此处以直播为例:
/*
* 创建DPSDK
* */
public void OnCreate()
{
int nRet =-1;
Return_Value_Info_t res =new Return_Value_Info_t();
nRet =IDpsdkCore.DPSDK_Create(dpsdk_sdk_type_e.DPSDK_CORE_SDK_SERVER,res);
m_nDLLHandle = res.nReturnValue;
String dpsdklog ="D:\\dpsdkjavalog";
nRet = IDpsdkCore.DPSDK_SetLog(m_nDLLHandle, Bytes());
String dumpfile ="D:\\dpsdkjavadump";
nRet = IDpsdkCore.DPSDK_StartMonitor(m_nDLLHandle, Bytes());
if(m_nDLLHandle >0)
{
//设置设备状态上报监听函数
nRet = IDpsdkCore.DPSDK_SetDPSDKDeviceStatusCallback(m_nDLLHandle, fDeviceStatus);
//设置NVR通道状态上报监听函数
nRet =IDpsdkCore.DPSDK_SetDPSDKNVRChnlStatusCallback(m_nDLLHandle, fNVRChnlStatus);
/
/设置通⽤JSON回调
nRet = IDpsdkCore.DPSDK_SetGeneralJsonTransportCallback(m_nDLLHandle, fGeneralJson);
nRet = IDpsdkCore.DPSDK_SetDPSDKGetBayCarInfoCallbackEx(m_nDLLHandle, fBayCarInfo);
nRet = IDpsdkCore.DPSDK_SetDPSDKTrafficAlarmCallback(m_nDLLHandle, fTrafficAlarmCallback);
nRet = IDpsdkCore.DPSDK_SetDPSDKGetAreaSpeedDetectCallback(m_nDLLHandle, fGetAreaSpeedDetectCallback); }
}
System.out.print("创建DPSDK, 返回 m_nDLLHandle = ");
System.out.println(m_nDLLHandle);
}
/*
* 登录
* */
public void OnLogin()
{
Login_Info_t loginInfo =new Login_Info_t();
loginInfo.szIp = Bytes();
loginInfo.nPort = m_nPort;
loginInfo.szUsername = Bytes();
loginInfo.szPassword = Bytes();
loginInfo.nProtocol = dpsdk_protocol_version_e.DPSDK_PROTOCOL_VERSION_II;
loginInfo.iType =1;
int nRet = IDpsdkCore.DPSDK_Login(m_nDLLHandle,loginInfo,10000);
if(nRet == dpsdk_retval_e.DPSDK_RET_SUCCESS)
{
System.out.printf("登录成功,nRet = %d", nRet);
}else
{
System.out.printf("登录失败,nRet = %d", nRet);
}
System.out.println();
}
/*
* 加载所有组织树
* */
public void LoadAllGroup()
{
int nRet = IDpsdkCore.DPSDK_LoadDGroupInfo(m_nDLLHandle, nGroupLen,180000);
if(nRet == dpsdk_retval_e.DPSDK_RET_SUCCESS)
{
System.out.printf("加载所有组织树成功,nRet = %d, nDepCount = %d", nRet, nGroupLen.nReturnValue);
}else
{
System.out.printf("加载所有组织树失败,nRet = %d", nRet);
}
System.out.println();
}
/*
* 获取所有组织树串
* */
public void GetGroupStr()
{
byte[] szGroupBuf =new byte[nGroupLen.nReturnValue];
int nRet = IDpsdkCore.DPSDK_GetDGroupStr(m_nDLLHandle, szGroupBuf, nGroupLen.nReturnValue,10000);
if(nRet == dpsdk_retval_e.DPSDK_RET_SUCCESS)
{
String GroupBuf ="";
try{
GroupBuf =new String(szGroupBuf,"UTF-8");
}catch(IOException e){
e.printStackTrace();
}
System.out.printf("获取所有组织树串成功,nRet = %d, szGroupBuf = [%s]", nRet, GroupBuf);
try{
File file =new File("D:\\l");
if(!ists())
if(!ists())
{
}
FileOutputStream  out =new FileOutputStream(file);
out.write(szGroupBuf);
out.close();
}catch(IOException e1){
// TODO Auto-generated catch block
e1.printStackTrace();
}
}else
{
System.out.printf("获取所有组织树串失败,nRet = %d", nRet);
}
System.out.println();
}
/*
* 登出
* */
public void OnLogout()
{
int nRet = IDpsdkCore.DPSDK_Logout(m_nDLLHandle,10000);
if(nRet == dpsdk_retval_e.DPSDK_RET_SUCCESS)
{
System.out.printf("登出成功,nRet = %d", nRet);
}else
{
System.out.printf("登出失败,nRet = %d", nRet);
}
System.out.println();
}
/*
sdk
* 释放内存
* */
public void OnDestroy()
{
int nRet = IDpsdkCore.DPSDK_Destroy(m_nDLLHandle);
if(nRet == dpsdk_retval_e.DPSDK_RET_SUCCESS)
{
System.out.printf("释放内存成功,nRet = %d", nRet);
}else
{
System.out.printf("释放内存失败,nRet = %d", nRet);
}
System.out.println();
}
补充
1.⼀定要记得释放内存
2.获取的数据是XML格式,可以⾃⼰通过⼯具类解析
3.友情提⽰:如果是使⽤docker部署的话,镜像依赖宿主机的xml⽂件时,⼀定要在创建镜像的配置加⼊环境依赖

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。