由于本人所在公司是物联网业务巨多,平时跟海康摄像头打交道比较多。
同时,公司使用GB28181协议播放视频流。
当摄像头多了,一个一个配置就比较麻烦了。同时海康的SDK(HCNetSDK)缺少GB28181配置。
只好根据海康(设备网络SDK使用手册.chm)C的代码来定义了
1. 在HCNetSDK中新建一个类
public static class NET_DVR_GBT28181_ACCESS_CFG extends Structure {
public int dwSize;
public byte byEnable;
public byte byTransProtocol;
public short wLocalSipPort;
public byte[] szServerID = new byte[64];
public byte[] szServerDomain = new byte[128];
public byte[] szSipServerAddress = new byte[128];
public short wServerSipPort;
public byte byProtocolVersion;
public byte byRes3;
public byte[] szSipUserName = new byte[64];
public byte[] szSipAuthenticateID = new byte[64];
public byte[] szSipAuthenticatePasswd = new byte[32];
public int dwRegisterValid;
public byte byHeartbeatInterval;
public byte byMaxHeartbeatTimeOut;
public byte byStreamType;
public byte byDeviceStatus;
public int dwRegisterInterval;
public int dwAutoAllocChannelID;
public byte[] szDeviceDomain = new byte[128];
public byte[] byRes4 = new byte[116];
}
- 然后再设置GB28181配置(先要运行成功海康的Demo,不然不知道怎么使用)
public void setGb28181Config() {
HCNetSDK.NET_DVR_GBT28181_ACCESS_CFG config = new HCNetSDK.NET_DVR_GBT28181_ACCESS_CFG();
config.write();
Pointer pointer = config.getPointer();
IntByReference lpBytesReturned = new IntByReference(0);
//先读取配置,让sdk填充一些属性
boolean b1 = hCNetSDK.NET_DVR_GetDVRConfig(lUserID.intValue(), 3249, new NativeLong(0xFFFFFFFF).intValue(),
pointer, config.size(), lpBytesReturned);
config.read();
if (b1) {
config.dwSize = config.size();
config.byEnable = 0x01;
//SIP服务器ID
config.szServerID = "44010200492000000001".getBytes();
//SIP服务器域
config.szServerDomain = "4401020049".getBytes();
// SIP服务器地址
config.szSipServerAddress = "192.168.18.11".getBytes();
//SIP服务器端口
config.wServerSipPort = 5060;
config.byProtocolVersion = 0x02;
// SIP用户名
config.szSipUserName = "34020000001180000001".getBytes();
// SIP用户认证ID
config.szSipAuthenticateID = "34020000001180000001".getBytes();
//密码
config.szSipAuthenticatePasswd = "admin123".getBytes();
config.byHeartbeatInterval = 0x0a;
config.write();
boolean b = hCNetSDK.NET_DVR_SetDVRConfig(lUserID.intValue(), 3250, new NativeLong(0xFFFFFFFF).intValue(), config.getPointer(), config.size());
if (b) {
System.out.println("设置成功:" + hCNetSDK.NET_DVR_GetLastError());
} else {
System.out.println("设置失败:"+ hCNetSDK.NET_DVR_GetLastError());
}
} else {
System.out.println("获取配置失败:" + hCNetSDK.NET_DVR_GetLastError());
}
}
标签:gb28181,NET,海康,new,byte,config,public,摄像头,DVR
From: https://www.cnblogs.com/anlalala/p/16596287.html