|
@@ -10,13 +10,13 @@ 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.sdk40.HCNetSDK;
|
|
|
-import com.persagy.cameractl.sdk40.HCNetSDK.NET_DVR_USER_LOGIN_INFO;
|
|
|
+import com.persagy.cameractl.cvr.HCNetSDK;
|
|
|
+import com.persagy.cameractl.cvr.HCNetSDK.NET_DVR_USER_LOGIN_INFO;
|
|
|
+import com.persagy.cameractl.init.SDKInit;
|
|
|
import com.persagy.cameractl.utils.Camera;
|
|
|
import com.persagy.cameractl.utils.ResultClass;
|
|
|
import com.sun.jna.Structure;
|
|
|
import com.sun.jna.Union;
|
|
|
-import com.sun.jna.ptr.IntByReference;
|
|
|
|
|
|
/**
|
|
|
* 测试类
|
|
@@ -33,8 +33,9 @@ public class Test2Controller {
|
|
|
/** 项目根路径*/
|
|
|
public static final String SERVER_ROOT_PATH = System.getProperty("user.dir");
|
|
|
|
|
|
- public static volatile HCNetSDK hCNetSDK;
|
|
|
- private volatile boolean isInit = false;
|
|
|
+ public static Map<String, Integer> STREAM_ID_2_CHANNEL = new HashMap<String, Integer>();
|
|
|
+
|
|
|
+ private HCNetSDK.NET_DVR_STREAM_INFO strStreamInfo;
|
|
|
|
|
|
//@Autowired
|
|
|
//private CameraApiConfig cameraApiConfig;
|
|
@@ -45,7 +46,7 @@ public class Test2Controller {
|
|
|
returnResult.name = false;
|
|
|
|
|
|
// SDK初始化
|
|
|
- boolean init = this.init();
|
|
|
+ boolean init = SDKInit.init();
|
|
|
if (!init) {
|
|
|
returnResult.reason = "SDK初始化失败";
|
|
|
return returnResult;
|
|
@@ -53,77 +54,46 @@ 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(camera.userName, camera.password, camera.cameraIp, (short)camera.cameraPort);
|
|
|
- int lUserID = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
|
|
|
+ NET_DVR_USER_LOGIN_INFO m_strLoginInfo = SDKInit.getLoginObject(camera.userName, camera.password, camera.cameraIp, (short)camera.cameraPort);
|
|
|
+ int lUserID = SDKInit.hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
|
|
|
if (lUserID == -1) {
|
|
|
- int errCode = hCNetSDK.NET_DVR_GetLastError();
|
|
|
+ int errCode = SDKInit.hCNetSDK.NET_DVR_GetLastError();
|
|
|
returnResult.reason = "设备注册失败,错误码: " + errCode;
|
|
|
return returnResult;
|
|
|
}
|
|
|
|
|
|
- HCNetSDK.NET_DVR_STREAM_INFO struStreamID = new HCNetSDK.NET_DVR_STREAM_INFO();
|
|
|
- struStreamID.dwSize = struStreamID.size();
|
|
|
- struStreamID.byID = "18083116593134708100".getBytes();
|
|
|
- struStreamID.write();
|
|
|
+ DevInfoCallBack fDevInfoCallBack = new DevInfoCallBack(strStreamInfo);
|
|
|
+ int startRemoteHandle = SDKInit.hCNetSDK.NET_DVR_StartRemoteConfig(lUserID, HCNetSDK.NET_DVR_GET_STREAM_INFO, null, 0, fDevInfoCallBack, null);
|
|
|
+ if (startRemoteHandle == -1) {
|
|
|
+ returnResult.reason = "启动远程配置失败,错误码: " + SDKInit.hCNetSDK.NET_DVR_GetLastError();
|
|
|
+ return returnResult;
|
|
|
+ }
|
|
|
|
|
|
- NET_DVR_STREAM_SRC_INFO_V40 NET_DVR_STREAM_SRC_INFO_V40 = new NET_DVR_STREAM_SRC_INFO_V40();
|
|
|
+ while (!fDevInfoCallBack.endStatus) {
|
|
|
+ Thread.sleep(1000);
|
|
|
+ }
|
|
|
|
|
|
- IntByReference lpBytesReturned = new IntByReference(0);
|
|
|
- boolean deviceConfig = hCNetSDK.NET_DVR_GetDeviceConfig(lUserID, 6024, 1, struStreamID.getPointer(), struStreamID.size(),
|
|
|
- lpBytesReturned.getPointer(), NET_DVR_STREAM_SRC_INFO_V40.getPointer(), NET_DVR_STREAM_SRC_INFO_V40.size());
|
|
|
- if (!deviceConfig) {
|
|
|
- returnResult.reason = "获取流来源信息失败,错误码: " + hCNetSDK.NET_DVR_GetLastError();
|
|
|
+ //Map<String, Object> temp = new HashMap<String, Object>();
|
|
|
+ //temp.put("streamIds", STREAM_IDS);
|
|
|
+ returnResult.resultData = STREAM_ID_2_CHANNEL;
|
|
|
+
|
|
|
+ // 关闭资源
|
|
|
+ boolean remoteConfig = SDKInit.hCNetSDK.NET_DVR_StopRemoteConfig(startRemoteHandle);
|
|
|
+ if (!remoteConfig) {
|
|
|
+ logger.warn("NET_DVR_StopRemoteConfig failure, errorCode: " + SDKInit.hCNetSDK.NET_DVR_GetLastError());
|
|
|
+ returnResult.reason = "关闭长连接配置接口所创建的句柄,释放资源失败,错误码: " + SDKInit.hCNetSDK.NET_DVR_GetLastError();
|
|
|
return returnResult;
|
|
|
}
|
|
|
- NET_DVR_STREAM_SRC_INFO_V40.read();
|
|
|
- returnResult.name = true;
|
|
|
-
|
|
|
- Map<String, Object> temp = new HashMap<String, Object>();
|
|
|
- temp.put("ip", new String(NET_DVR_STREAM_SRC_INFO_V40.uGetStream.struChanInfo.byAddress));
|
|
|
- temp.put("username", new String(NET_DVR_STREAM_SRC_INFO_V40.uGetStream.struChanInfo.sUserName));
|
|
|
- temp.put("password", new String(NET_DVR_STREAM_SRC_INFO_V40.uGetStream.struChanInfo.sPassword));
|
|
|
- temp.put("port", NET_DVR_STREAM_SRC_INFO_V40.uGetStream.struChanInfo.wDVRPort);
|
|
|
- temp.put("channel", NET_DVR_STREAM_SRC_INFO_V40.uGetStream.struChanInfo.dwChannel);
|
|
|
- temp.put("protocol", NET_DVR_STREAM_SRC_INFO_V40.uGetStream.struChanInfo.byTransProtocol);
|
|
|
- returnResult.resultData = temp;
|
|
|
|
|
|
//退出程序时调用,每一台设备分别注销
|
|
|
- if (hCNetSDK.NET_DVR_Logout(lUserID)) {
|
|
|
+ if (SDKInit.hCNetSDK.NET_DVR_Logout(lUserID)) {
|
|
|
logger.info("logout success");
|
|
|
}
|
|
|
|
|
|
+ returnResult.name = true;
|
|
|
return returnResult;
|
|
|
}
|
|
|
|
|
|
- private boolean init() {
|
|
|
- if (!isInit) {
|
|
|
- // 初始化
|
|
|
- hCNetSDK = HCNetSDK.INSTANCE;
|
|
|
- isInit = hCNetSDK.NET_DVR_Init();
|
|
|
- }
|
|
|
- return isInit;
|
|
|
- }
|
|
|
-
|
|
|
- private HCNetSDK.NET_DVR_USER_LOGIN_INFO getLoginObject(String m_sUsername, String m_sPassword, String m_sDeviceIP, short wPort) {
|
|
|
- HCNetSDK.NET_DVR_USER_LOGIN_INFO m_strLoginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO();//设备登录信息
|
|
|
-
|
|
|
- m_strLoginInfo.sDeviceAddress = new byte[HCNetSDK.NET_DVR_DEV_ADDRESS_MAX_LEN];
|
|
|
- System.arraycopy(m_sDeviceIP.getBytes(), 0, m_strLoginInfo.sDeviceAddress, 0, m_sDeviceIP.length());
|
|
|
-
|
|
|
- m_strLoginInfo.sUserName = new byte[HCNetSDK.NET_DVR_LOGIN_USERNAME_MAX_LEN];
|
|
|
- System.arraycopy(m_sUsername.getBytes(), 0, m_strLoginInfo.sUserName, 0, m_sUsername.length());
|
|
|
-
|
|
|
- m_strLoginInfo.sPassword = new byte[HCNetSDK.NET_DVR_LOGIN_PASSWD_MAX_LEN];
|
|
|
- System.arraycopy(m_sPassword.getBytes(), 0, m_strLoginInfo.sPassword, 0, m_sPassword.length());
|
|
|
-
|
|
|
- m_strLoginInfo.wPort = wPort; //SDK端口
|
|
|
- m_strLoginInfo.bUseAsynLogin = false; //是否异步登录:0- 否,1- 是
|
|
|
- m_strLoginInfo.write();
|
|
|
-
|
|
|
- return m_strLoginInfo;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
public static class NET_DVR_STREAM_SRC_INFO_V40 extends Structure {
|
|
|
public int dwSize;
|
|
|
public byte byGetStreamType;
|
|
@@ -317,4 +287,21 @@ public class Test2Controller {
|
|
|
|
|
|
return returnResult;
|
|
|
}*/
|
|
|
+
|
|
|
+
|
|
|
+ /*HCNetSDK.NET_DVR_STREAM_RECORD_STATUS strStreamStatus = new HCNetSDK.NET_DVR_STREAM_RECORD_STATUS();
|
|
|
+ strStreamStatus.write();
|
|
|
+ Pointer lpOutBuffer = strStreamStatus.getPointer();
|
|
|
+
|
|
|
+ IntByReference pInt = new IntByReference(0);
|
|
|
+ Pointer lpStatusList = pInt.getPointer();
|
|
|
+
|
|
|
+ boolean getDeviceConfig = hCNetSDK.NET_DVR_GetDeviceConfig(lUserID, HCNetSDK.NET_DVR_GET_STREAM_RECORD_STATUS, 1,
|
|
|
+ strStreamInfo.getPointer(), strStreamInfo.size(), lpStatusList, lpOutBuffer, strStreamStatus.size());
|
|
|
+ if (!getDeviceConfig) {
|
|
|
+ returnResult.reason = "获取流来源信息失败,错误码: " + hCNetSDK.NET_DVR_GetLastError();
|
|
|
+ return returnResult;
|
|
|
+ }
|
|
|
+ strStreamStatus.read();*/
|
|
|
+
|
|
|
}
|