|
@@ -1,24 +1,18 @@
|
|
|
package com.persagy.cameractl.controller;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.util.Timer;
|
|
|
-
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-import com.persagy.cameractl.conf.CameraApiConfig;
|
|
|
import com.persagy.cameractl.sdk40.HCNetSDK;
|
|
|
import com.persagy.cameractl.sdk40.HCNetSDK.NET_DVR_USER_LOGIN_INFO;
|
|
|
import com.persagy.cameractl.utils.Camera;
|
|
|
-import com.persagy.cameractl.utils.OtherTools;
|
|
|
import com.persagy.cameractl.utils.ResultClass;
|
|
|
-import com.persagy.cameractl.utils.StringTools;
|
|
|
+import com.sun.jna.Structure;
|
|
|
+import com.sun.jna.Union;
|
|
|
|
|
|
/**
|
|
|
* 测试类
|
|
@@ -38,8 +32,8 @@ public class Test2Controller {
|
|
|
public static volatile HCNetSDK hCNetSDK;
|
|
|
private volatile boolean isInit = false;
|
|
|
|
|
|
- @Autowired
|
|
|
- private CameraApiConfig cameraApiConfig;
|
|
|
+ //@Autowired
|
|
|
+ //private CameraApiConfig cameraApiConfig;
|
|
|
|
|
|
@RequestMapping(value = "/sso", method = RequestMethod.POST)
|
|
|
public ResultClass hello(@RequestBody Camera camera) throws Exception {
|
|
@@ -54,61 +48,34 @@ public class Test2Controller {
|
|
|
}
|
|
|
|
|
|
HCNetSDK.NET_DVR_DEVICEINFO_V40 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40();//设备信息
|
|
|
- NET_DVR_USER_LOGIN_INFO m_strLoginInfo = this.getLoginObject(cameraApiConfig.getDecodeDeviceUserName(), cameraApiConfig.getDecodeDevicePassword(), cameraApiConfig.getDecodeDeviceIp(), (short)cameraApiConfig.getDecodeDevicePort());
|
|
|
+ //NET_DVR_USER_LOGIN_INFO m_strLoginInfo = this.getLoginObject(cameraApiConfig.getDecodeDeviceUserName(), cameraApiConfig.getDecodeDevicePassword(), cameraApiConfig.getDecodeDeviceIp(), (short)cameraApiConfig.getDecodeDevicePort());
|
|
|
+ NET_DVR_USER_LOGIN_INFO m_strLoginInfo = this.getLoginObject(camera.userName, camera.password, camera.cameraIp, (short)camera.cameraPort);
|
|
|
int lUserID = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
|
|
|
if (lUserID == -1) {
|
|
|
int errCode = hCNetSDK.NET_DVR_GetLastError();
|
|
|
- returnResult.reason = "设备注册失败,失败码: " + errCode;
|
|
|
+ returnResult.reason = "设备注册失败,错误码: " + errCode;
|
|
|
return returnResult;
|
|
|
}
|
|
|
|
|
|
- String targetFile = getVideoFilePath();
|
|
|
- File file = new File(targetFile);
|
|
|
- if (!file.exists()) {
|
|
|
- file.createNewFile();
|
|
|
- }
|
|
|
- // 获取所有的流ID
|
|
|
- FileOutputStream outputStream = new FileOutputStream(file);
|
|
|
- RemoteConfigCallBack remoteConfigCallBack = new RemoteConfigCallBack(outputStream);
|
|
|
- int startRemoteConfig = hCNetSDK.NET_DVR_StartRemoteConfig(lUserID, 6161, null, 0, remoteConfigCallBack, null);
|
|
|
- if (startRemoteConfig <= -1) {
|
|
|
- logger.warn("NET_DVR_StartRemoteConfig failure, errorCode: " + hCNetSDK.NET_DVR_GetLastError());
|
|
|
- returnResult.reason = "启动远程配置失败,错误码: " + hCNetSDK.NET_DVR_GetLastError();
|
|
|
- return returnResult;
|
|
|
- }
|
|
|
-
|
|
|
- // 开始计时器,逐个获取查找到的信息
|
|
|
- Timer remoteConfigTimer = new Timer(); // 新建定时器
|
|
|
- RemoteConfigTask remoteConfigTask = new RemoteConfigTask(outputStream, startRemoteConfig);
|
|
|
- remoteConfigTimer.schedule(remoteConfigTask, 0, 5000); // 0秒后开始响应函数
|
|
|
-
|
|
|
- while (!remoteConfigTask.endStatus) {
|
|
|
- // 等待获取结束
|
|
|
- try {
|
|
|
- Thread.sleep(1000);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 关闭资源
|
|
|
- boolean remoteConfig = hCNetSDK.NET_DVR_StopRemoteConfig(startRemoteConfig);
|
|
|
- if (!remoteConfig) {
|
|
|
- logger.warn("NET_DVR_StopRemoteConfig failure, errorCode: " + hCNetSDK.NET_DVR_GetLastError());
|
|
|
- returnResult.reason = "关闭长连接配置接口所创建的句柄,释放资源失败,错误码: " + hCNetSDK.NET_DVR_GetLastError();
|
|
|
+ NET_DVR_STREAM_SRC_CFG net_dvr_stream_src_cfg = new NET_DVR_STREAM_SRC_CFG();
|
|
|
+ boolean deviceConfig = hCNetSDK.NET_DVR_GetDeviceConfig(lUserID, 9105, 0xffffffff, null, 0, null, net_dvr_stream_src_cfg.getPointer(), net_dvr_stream_src_cfg.size());
|
|
|
+ hCNetSDK.NET_DVR_GetDeviceConfig(lUserID, 6024, lUserID, null, lUserID, null, null, lUserID);
|
|
|
+ if (!deviceConfig) {
|
|
|
+ returnResult.reason = "获取设备流配置失败,错误码: " + hCNetSDK.NET_DVR_GetLastError();
|
|
|
return returnResult;
|
|
|
}
|
|
|
-
|
|
|
- //退出程序时调用,每一台设备分别注销
|
|
|
+ net_dvr_stream_src_cfg.read();
|
|
|
+ returnResult.name = true;
|
|
|
+ returnResult.resultData = net_dvr_stream_src_cfg.toString();
|
|
|
+
|
|
|
+ //退出程序时调用,每一台设备分别注销
|
|
|
if (hCNetSDK.NET_DVR_Logout(lUserID)) {
|
|
|
logger.info("logout success");
|
|
|
}
|
|
|
|
|
|
- returnResult.name = true;
|
|
|
return returnResult;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private boolean init() {
|
|
|
if (!isInit) {
|
|
|
// 初始化
|
|
@@ -137,20 +104,198 @@ public class Test2Controller {
|
|
|
return m_strLoginInfo;
|
|
|
}
|
|
|
|
|
|
- public static String getVideoFilePath() {
|
|
|
- String token = StringTools.getUUID();
|
|
|
- return getVideoFilePathByT(token);
|
|
|
- }
|
|
|
-
|
|
|
- public static String getVideoFilePathByT(String token) {
|
|
|
- try {
|
|
|
- String playFileName = token + ".txt";
|
|
|
- String playFileDir = OtherTools.getVideoFileDir();
|
|
|
- return playFileDir + "/" + playFileName;
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error(e.getMessage());
|
|
|
- return "";
|
|
|
+
|
|
|
+ public static class NET_DVR_STREAM_SRC_INFO_V40 extends Structure {
|
|
|
+ public int dwSize;
|
|
|
+ public byte byGetStreamType;
|
|
|
+ public byte[] byRes1 = new byte[3];
|
|
|
+ public NET_DVR_STREAM_TYPE_V40_UNION uGetStream = new NET_DVR_STREAM_TYPE_V40_UNION();
|
|
|
+ public byte[] byRes = new byte[512];
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class NET_DVR_STREAM_TYPE_V40_UNION extends Union {
|
|
|
+ public NET_DVR_DIRECT_CONNECT_CHAN_INFO_V40 struChanInfo = new NET_DVR_DIRECT_CONNECT_CHAN_INFO_V40();
|
|
|
+ public NET_DVR_PU_STREAM_URL struPuStreamUrl = new NET_DVR_PU_STREAM_URL();
|
|
|
+ public NET_DVR_PU_STREAM_URL_CFG_V40 struStreamUrlCfg = new NET_DVR_PU_STREAM_URL_CFG_V40();
|
|
|
+ public NET_DVR_RTSP_PROTOCAL_CFG struRtspCfg = new NET_DVR_RTSP_PROTOCAL_CFG();
|
|
|
+ public NET_DVR_STREAM_URL_V40 struStreamUrlV40 = new NET_DVR_STREAM_URL_V40();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class NET_DVR_DIRECT_CONNECT_CHAN_INFO_V40 extends Structure {
|
|
|
+ public byte byEnable;
|
|
|
+ public byte byProType;
|
|
|
+ public byte byZeroChan;
|
|
|
+ public byte byRes1;
|
|
|
+ public byte[] sUserName = new byte[32];
|
|
|
+ public byte[] sPassword = new byte[16];
|
|
|
+ public byte[] byAddress = new byte[64];
|
|
|
+ public short wDVRPort;
|
|
|
+ public byte byStreamType;
|
|
|
+ public byte byOnline;
|
|
|
+ public int dwChannel;
|
|
|
+ public byte byTransProtocol;
|
|
|
+ public byte byLocalBackUp;
|
|
|
+ public byte[] byRes2 = new byte[2];
|
|
|
+ public byte[] byVAGChanNo = new byte[32];
|
|
|
+ public byte[] byRes = new byte[340];
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class NET_DVR_PU_STREAM_URL extends Structure {
|
|
|
+ public byte byEnable;//是否启用:0- 禁用,1- 启用
|
|
|
+ public byte[] strURL = new byte[240];//取流URL路径
|
|
|
+ public byte byTransPortocol;//传输协议类型:0-TCP,1-UDP
|
|
|
+ public short wIPID;//设备ID号,wIPID = iDevInfoIndex + iGroupNO*64 +1
|
|
|
+ public byte byChannel;//设备通道号
|
|
|
+ public byte[] byRes = new byte[7];//保留,置为0
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class NET_DVR_PU_STREAM_URL_CFG_V40 extends Structure {
|
|
|
+ public byte byEnable;
|
|
|
+ public byte[] byRes = new byte[3];
|
|
|
+ public byte[] byStreamMediaIP = new byte[64];
|
|
|
+ public short wStreamMediaPort;
|
|
|
+ public byte byTransmitType;
|
|
|
+ public byte byRes1;
|
|
|
+ public byte[] byDevIP = new byte[64];
|
|
|
+ public short wDevPort;
|
|
|
+ public byte byChannel;
|
|
|
+ public byte byTransMode;
|
|
|
+ public byte byProType;
|
|
|
+ public byte byTransProtocol;
|
|
|
+ public byte[] byRes3 = new byte[2];
|
|
|
+ public byte[] sUserName = new byte[32];
|
|
|
+ public byte[] sPassWord = new byte[16];
|
|
|
+ public byte[] byRes2 = new byte[308];
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class NET_DVR_RTSP_PROTOCAL_CFG extends Structure {
|
|
|
+ public byte byEnable;
|
|
|
+ public byte byLocalBackUp;
|
|
|
+ public byte[] byRes = new byte[2];
|
|
|
+ public byte[] strURL = new byte[256];
|
|
|
+ public int dwProtocalType;
|
|
|
+ public byte[] sUserName = new byte[32];
|
|
|
+ public byte[] sPassWord = new byte[16];
|
|
|
+ public byte[] byAddress = new byte[64];
|
|
|
+ public short wPort;
|
|
|
+ public byte[] byRes1 = new byte[122];
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class NET_DVR_STREAM_URL_V40 extends Structure {
|
|
|
+ public byte byEnable;
|
|
|
+ public byte byStreamType;
|
|
|
+ public byte byLocalBackUp;
|
|
|
+ public byte byRes;
|
|
|
+ public byte[] strURL = new byte[256];
|
|
|
+ public int dwProtocalType;
|
|
|
+ public byte[] sUserName = new byte[32];
|
|
|
+ public byte[] sPassWord = new byte[16];
|
|
|
+ public byte[] byAddress = new byte[64];
|
|
|
+ public short wIPPort;
|
|
|
+ public short wChanNo;
|
|
|
+ public byte[] byVAGChanNo = new byte[32];
|
|
|
+ public byte[] byRes1 = new byte[88];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static class NET_DVR_STREAM_SRC_CFG extends Structure {
|
|
|
+ public int dwSize;
|
|
|
+ public HCNetSDK.NET_DVR_STREAM_INFO struStreamID = new HCNetSDK.NET_DVR_STREAM_INFO();
|
|
|
+ public NET_DVR_STREAM_SRC_INFO struStreamSrcInfo = new NET_DVR_STREAM_SRC_INFO();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class NET_DVR_STREAM_SRC_INFO extends Structure {
|
|
|
+ public int dwSize;
|
|
|
+ public NET_DVR_STREAM_MODE_TYPE struStreamSrcInfo = new NET_DVR_STREAM_MODE_TYPE();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class NET_DVR_STREAM_MODE_TYPE extends Structure {
|
|
|
+ public byte byGetStreamType;
|
|
|
+ public byte[] byRes = new byte[3];
|
|
|
+ public NET_DVR_STREAM_TYPE_UNION uGetStream = new NET_DVR_STREAM_TYPE_UNION();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class NET_DVR_STREAM_TYPE_UNION extends Union {
|
|
|
+ public NET_DVR_DIRECT_CONNECT_CHAN_INFO struChanInfo = new NET_DVR_DIRECT_CONNECT_CHAN_INFO();
|
|
|
+ public HCNetSDK.NET_DVR_PU_STREAM_URL struStreamUrl = new HCNetSDK.NET_DVR_PU_STREAM_URL();
|
|
|
+ public NET_DVR_PU_STREAM_URL_CFG struStreamUrlCfg = new NET_DVR_PU_STREAM_URL_CFG();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class NET_DVR_DIRECT_CONNECT_CHAN_INFO extends Structure {
|
|
|
+ public byte byEnable;
|
|
|
+ public byte byProType;
|
|
|
+ public byte byZeroChan;
|
|
|
+ public byte byPriority;
|
|
|
+ public byte[] sUserName = new byte[32];
|
|
|
+ public byte[] sPassword = new byte[16];
|
|
|
+ public byte[] byDomain = new byte[64];
|
|
|
+ public HCNetSDK.NET_DVR_IPADDR struIP;
|
|
|
+ public short wDVRPort;
|
|
|
+ public byte byStreamType;
|
|
|
+ public byte byOnline;
|
|
|
+ public int dwChannel;
|
|
|
+ public byte byTransProtocol;
|
|
|
+ public byte byLocalBackUp;
|
|
|
+ public short wDirectLastTime;
|
|
|
+ public byte[] byChanNo = new byte[24];
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class NET_DVR_PU_STREAM_URL_CFG extends Structure {
|
|
|
+ public byte byEnable;
|
|
|
+ public byte[] byRes = new byte[3];
|
|
|
+ public byte[] byStreamMediaIP = new byte[64];
|
|
|
+ public short wStreamMediaPort;
|
|
|
+ public byte byTransmitType;
|
|
|
+ public byte[] byRes1 = new byte[33];
|
|
|
+ public byte[] byDevIP = new byte[64];
|
|
|
+ public short wDevPort;
|
|
|
+ public short byChannel;
|
|
|
+ public byte byTransMode;
|
|
|
+ public byte byProType;
|
|
|
+ public byte byTransProtocol;
|
|
|
+ public byte[] byRes3 = new byte[2];
|
|
|
+ public byte[] sUserName = new byte[32];
|
|
|
+ public byte[] sPassWord = new byte[16];
|
|
|
+ public byte[] byRes2 = new byte[28];
|
|
|
+ }
|
|
|
+
|
|
|
+ /*@RequestMapping(value = "/sso", method = RequestMethod.POST)
|
|
|
+ public ResultClass hello(@RequestBody Camera camera) throws Exception {
|
|
|
+ ResultClass returnResult = new ResultClass();
|
|
|
+ returnResult.name = false;
|
|
|
+
|
|
|
+ // SDK初始化
|
|
|
+ boolean init = this.init();
|
|
|
+ if (!init) {
|
|
|
+ returnResult.reason = "SDK初始化失败";
|
|
|
+ return returnResult;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+ HCNetSDK.NET_DVR_DEVICEINFO_V40 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40();//设备信息
|
|
|
+ //NET_DVR_USER_LOGIN_INFO m_strLoginInfo = this.getLoginObject(cameraApiConfig.getDecodeDeviceUserName(), cameraApiConfig.getDecodeDevicePassword(), cameraApiConfig.getDecodeDeviceIp(), (short)cameraApiConfig.getDecodeDevicePort());
|
|
|
+ NET_DVR_USER_LOGIN_INFO m_strLoginInfo = this.getLoginObject(camera.userName, camera.password, camera.cameraIp, (short)camera.cameraPort);
|
|
|
+ int lUserID = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
|
|
|
+ if (lUserID == -1) {
|
|
|
+ int errCode = hCNetSDK.NET_DVR_GetLastError();
|
|
|
+ returnResult.reason = "设备注册失败,错误码: " + errCode;
|
|
|
+ return returnResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ NET_DVR_STREAM_SRC_CFG net_dvr_stream_src_cfg = new NET_DVR_STREAM_SRC_CFG();
|
|
|
+ boolean deviceConfig = hCNetSDK.NET_DVR_GetDeviceConfig(lUserID, 9105, 0xffffffff, null, 0, null, net_dvr_stream_src_cfg.getPointer(), net_dvr_stream_src_cfg.size());
|
|
|
+ if (!deviceConfig) {
|
|
|
+ returnResult.reason = "获取设备流配置失败,错误码: " + hCNetSDK.NET_DVR_GetLastError();
|
|
|
+ return returnResult;
|
|
|
+ }
|
|
|
+ net_dvr_stream_src_cfg.read();
|
|
|
+ returnResult.name = true;
|
|
|
+ returnResult.resultData = net_dvr_stream_src_cfg.toString();
|
|
|
+
|
|
|
+ //退出程序时调用,每一台设备分别注销
|
|
|
+ if (hCNetSDK.NET_DVR_Logout(lUserID)) {
|
|
|
+ logger.info("logout success");
|
|
|
+ }
|
|
|
+
|
|
|
+ return returnResult;
|
|
|
+ }*/
|
|
|
}
|