对接⼤华Java视频监控SDK
对接⼤华Java视频监控SDK
开发背景
⼩8前⼏天接到项⽬经理的通知:客户想在⽹页上进⾏视频监控.当时我脑海就产⽣了质疑,这东西不都是C/S吗?什么时候变成B/S了?最后带着质疑的态度以及客户提供的⽤户名/密码和ip地址就开⼲了.
思路整理
凡事开发之前,想摸清楚⼤致⽅向,不然边⼲边想,最后可能⾃⼰都迷糊了;
说到底⽆⾮就是调取SDK进⾏摄像头控制、视频实时监控、视频录像查看
那么问题来了,如何调取SDK?
调取SDK
⼩弟也是各⼤论坛各种资料下载;ps:官⽹也提供了SDK,但我没觉得有什么卵⽤.
话不多说,直接贴代码吧.
下⽅是官⽅的提供的类⽂件
关键类IDpsdkCore,接⼝定义,具体实现在库⽂件↓
这些类库⽂件就是官⽅提供的windows.dll⽂件,Linux就是.so⽂件(下⽅提供下载),需要加⼊环境变量(如何操作⾃⾏查询)
库⽂件加⼊环境变量之后就是写我们⼯具类了.
⼯具类
/**
* ⼤华SDK⼯具集成类
*/
@Slf4j
public class DPSDKUtil {
//句柄
private static int m_nDLLHandle =-1;
//组织机构xml长度
private static Return_Value_Info_t nGroupLen =new Return_Value_Info_t();
/**
* 创建DPSDK
*/
public static void OnCreate(){
log.info("创建DPSDK开始");
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;
log.info("创建DPSDK结束,返回 m_nDLLHandle = "+ m_nDLLHandle);
/**
*如果只是简单的视频实时监控和视频控制,此处可注释
*/
if(m_nDLLHandle >0){
//设置设备状态上报监听函数,DPSDKDevStatusCallback实现fDPSDKDevStatusCallback接⼝
nRet = IDpsdkCore.DPSDK_SetDPSDKDeviceStatusCallback(m_nDLLHandle,new DPSDKDevStatusCallback());
//设置NVR通道状态上报监听函数
//设置NVR通道状态上报监听函数
nRet = IDpsdkCore.DPSDK_SetDPSDKNVRChnlStatusCallback(m_nDLLHandle,new DPSDKNVRChnlStatusCallback());
//设置通⽤JSON回调,
nRet = IDpsdkCore.DPSDK_SetGeneralJsonTransportCallback(m_nDLLHandle,new DPSDKGeneralJsonTransportCallback());
//卡⼝过车数据回调
nRet = IDpsdkCore.DPSDK_SetDPSDKGetBayCarInfoCallbackEx(m_nDLLHandle,new DPSDKGetBayCarInfoCallbackEx());
//违章报警回调
nRet = IDpsdkCore.DPSDK_SetDPSDKTrafficAlarmCallback(m_nDLLHandle,new DPSDKTrafficAlarmCallback());
//区间测速回调
nRet = IDpsdkCore.DPSDK_SetDPSDKGetAreaSpeedDetectCallback(m_nDLLHandle,new DPSDKGetAreaSpeedDetectCallback());
}
}
/**
* 登录
*/
public static void OnLogin(){
Login_Info_t loginInfo =new Login_Info_t();
loginInfo.szIp = Bytes();
loginInfo.nPort = FileConfig.dahuaPort;
loginInfo.szUsername = Bytes();sdk
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){
log.info("登录成功,nRet = {}", nRet);
}else{
<("登录失败,nRet = {}", nRet);
}
}
/**
* 加载所有组织机构树
*/
public static void LoadAllGroup(){
int nRet = IDpsdkCore.DPSDK_LoadDGroupInfo(m_nDLLHandle, nGroupLen,180000);
if(nRet == dpsdk_retval_e.DPSDK_RET_SUCCESS){
log.info("加载所有组织树成功,nRet = {}, nDepCount = {}", nRet, nGroupLen.nReturnValue);
}else{
<("加载所有组织树失败,nRet = {}", nRet);
}
}
/**
* 获取所有组织树串
*/
public static String GetGroupStr(){
byte[] szGroupBuf =new byte[nGroupLen.nReturnValue];
int nRet = IDpsdkCore.DPSDK_GetDGroupStr(m_nDLLHandle, szGroupBuf, nGroupLen.nReturnValue,10000);
String GroupBuf;
if(nRet == dpsdk_retval_e.DPSDK_RET_SUCCESS){
try{
GroupBuf =new String(szGroupBuf,"UTF-8");
}catch(IOException e){
throw new OperateException("解析所有组织树串失败");
}
}else{
throw new OperateException("获取所有组织树串失败");
}
return GroupBuf;
}
/**
* 云台⽅向控制.
*
* @param szCameraId 通道id
* @param nDirect 控制命令参考 dpsdk_ptz_direct_e 类
* @param nStep 移动步数
*/
public static int DPSDK_PtzDirection(String szCameraId,int nDirect,int nStep){
public static int DPSDK_PtzDirection(String szCameraId,int nDirect,int nStep){
Ptz_Direct_Info_t directInfo =new Ptz_Direct_Info_t();
//通道ID
directInfo.szCameraId = Bytes();
directInfo.nDirect = nDirect;
//移动步长
directInfo.nStep = nStep;
//是否停⽌,0表⽰不停⽌,1表⽰停⽌
directInfo.bStop =false;
//转向调⽤
return IDpsdkCore.DPSDK_PtzDirection(m_nDLLHandle, directInfo,10000);
}
/**
* 镜头控制
*
* @param szCameraId 通道id
* @param nOperation 控制命令参考 dpsdk_camera_operation_e 类
* @param nStep 移动步数
*/
public static int DPSDK_PtzCameraOperation(String szCameraId,int nOperation,int nStep){ Ptz_Operation_Info_t operation_info_t =new Ptz_Operation_Info_t();
operation_info_t.szCameraId = Bytes();
operation_info_t.nOperation = nOperation;
operation_info_t.nStep = nStep;
operation_info_t.bStop =false;
return IDpsdkCore.DPSDK_PtzCameraOperation(m_nDLLHandle, operation_info_t,10000); }
/**
* 登出
*/
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();
}
/**
* 释放内存
*/
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();
}
}
测试
public static void main(String[] args){
DPSDKUtil.OnCreate();//初始化
DPSDKUtil.OnLogin();//登陆
DPSDKUtil.LoadAllGroup();//加载组织结构
DPSDKUtil.GetGroupStr();//获取组织结构串
//加载组织结构之后,要延时5秒钟左右,等待与各服务模块取得联系
try{
Thread.sleep(5000);
}catch(InterruptedException e){
e.printStackTrace();
}
DPSDKUtil.OnLogout();//登出
DPSDKUtil.OnDestroy();//释放
}
补充:
加载设备信息后才能进⾏其他业务操作,获取组织设备信息串可选
组织设备信息串为xml格式的字符串,串具备可读性,⽤户可⾃⾏使⽤xml解析⼯具解析
解析xml主要⽤于获取通道id等信息;
DPSDK_Create 在⼀个应⽤中只需调⽤⼀次,建议不要同时创建多份,在需要重新创建时也需要调⽤DPSDK_Destroy先释放资源下载
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论