Procházet zdrojové kódy

新增获取所有流ID信息的方法

zhangqiankun před 2 roky
rodič
revize
cb8d299eaf

+ 4 - 1
src/main/java/com/persagy/cameractl/conf/CameraApiConfig.java

@@ -28,7 +28,10 @@ public class CameraApiConfig {
 	
 	@Value("${hk-config.recordLocation:}")
 	private String recordLocation;
-
+	
+	@Value("${hk-config.nginx-address:}")
+	private String nginxAddress;
+	
 	public String getHkApiHost() {
 		return hkApiHost;
 	}

+ 53 - 0
src/main/java/com/persagy/cameractl/controller/DevInfoCallBack.java

@@ -0,0 +1,53 @@
+package com.persagy.cameractl.controller;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.persagy.cameractl.cvr.HCNetSDK;
+import com.persagy.cameractl.cvr.HCNetSDK.FRemoteConfigCallBack;
+import com.sun.jna.Pointer;
+
+import cn.hutool.core.util.StrUtil;
+
+/**
+ * 
+ * @version 1.0.0
+ * @company persagy
+ * @author zhangqiankun
+ * @date 2022年6月27日 下午6:05:59
+ */
+
+public class DevInfoCallBack implements FRemoteConfigCallBack {
+	public static Logger logger = LoggerFactory.getLogger(DevInfoCallBack.class);
+
+	public volatile boolean endStatus = false;
+	
+	private HCNetSDK.NET_DVR_STREAM_INFO strStreamInfo;
+	
+	public DevInfoCallBack(HCNetSDK.NET_DVR_STREAM_INFO strStreamInfo) {
+		this.strStreamInfo = strStreamInfo;
+	}
+	
+	@Override
+	public void invoke(int dwType, Pointer lpBuffer, int dwBufLen, Pointer pUserData) {
+		logger.info("dwType: {}", dwType);
+		switch (dwType) {
+			case 2:
+				strStreamInfo = new HCNetSDK.NET_DVR_STREAM_INFO();
+				strStreamInfo.write();
+				Pointer pInfoV30 = strStreamInfo.getPointer();
+				pInfoV30.write(0, lpBuffer.getByteArray(0, strStreamInfo.size()), 0, strStreamInfo.size());
+				strStreamInfo.read();
+				String streamId = new String(strStreamInfo.byID);
+				logger.info("stream id: {}", streamId);
+				if (StrUtil.isNotBlank(streamId)) {
+					Test2Controller.STREAM_ID_2_CHANNEL.put(streamId.trim(), strStreamInfo.dwChannel);
+				}
+				break;
+			default:
+				endStatus = true;
+				break;
+		}
+	}
+
+}

+ 1 - 1
src/main/java/com/persagy/cameractl/controller/RemoteConfigCallBack.java

@@ -4,7 +4,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 
-import com.persagy.cameractl.sdk40.HCNetSDK.FRemoteConfigCallBack;
+import com.persagy.cameractl.cvr.HCNetSDK.FRemoteConfigCallBack;
 import com.sun.jna.Pointer;
 
 /**

+ 1 - 1
src/main/java/com/persagy/cameractl/controller/RemoteConfigTask.java

@@ -1,6 +1,6 @@
 package com.persagy.cameractl.controller;
 
-import static com.persagy.cameractl.sdk40.PlayBackController.hCNetSDK;
+import static com.persagy.cameractl.cvr.PlayBackController.hCNetSDK;
 
 import java.io.FileOutputStream;
 import java.io.IOException;

+ 47 - 60
src/main/java/com/persagy/cameractl/controller/Test2Controller.java

@@ -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();*/
+    
 }

+ 2 - 2
src/main/java/com/persagy/cameractl/sdk40/DownloadTask.java

@@ -1,6 +1,6 @@
-package com.persagy.cameractl.sdk40;
+package com.persagy.cameractl.cvr;
 
-import static com.persagy.cameractl.sdk40.PlayBackController.hCNetSDK;
+import static com.persagy.cameractl.cvr.PlayBackController.hCNetSDK;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

+ 1 - 1
src/main/java/com/persagy/cameractl/sdk40/HCNetSDK.java

@@ -1,4 +1,4 @@
-package com.persagy.cameractl.sdk40;
+package com.persagy.cameractl.cvr;
 
 import java.util.Arrays;
 import java.util.List;

+ 3 - 3
src/main/java/com/persagy/cameractl/sdk40/PlayBackController.java

@@ -1,4 +1,4 @@
-package com.persagy.cameractl.sdk40;
+package com.persagy.cameractl.cvr;
 
 import java.io.File;
 import java.io.FileOutputStream;
@@ -18,8 +18,8 @@ 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.NET_DVR_USER_LOGIN_INFO;
-import com.persagy.cameractl.sdk40.HCNetSDK.NET_DVR_VOD_PARA;
+import com.persagy.cameractl.cvr.HCNetSDK.NET_DVR_USER_LOGIN_INFO;
+import com.persagy.cameractl.cvr.HCNetSDK.NET_DVR_VOD_PARA;
 import com.persagy.cameractl.utils.Camera;
 import com.persagy.cameractl.utils.OtherTools;
 import com.persagy.cameractl.utils.ResultClass;

+ 3 - 3
src/main/java/com/persagy/cameractl/sdk40/PlayBackEventController.java

@@ -1,4 +1,4 @@
-package com.persagy.cameractl.sdk40;
+package com.persagy.cameractl.cvr;
 
 import java.io.File;
 import java.io.FileOutputStream;
@@ -14,8 +14,8 @@ 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.NET_DVR_USER_LOGIN_INFO;
-import com.persagy.cameractl.sdk40.HCNetSDK.NET_DVR_VOD_PARA;
+import com.persagy.cameractl.cvr.HCNetSDK.NET_DVR_USER_LOGIN_INFO;
+import com.persagy.cameractl.cvr.HCNetSDK.NET_DVR_VOD_PARA;
 import com.persagy.cameractl.utils.Camera;
 import com.persagy.cameractl.utils.OtherTools;
 import com.persagy.cameractl.utils.ResultClass;

+ 1 - 1
src/main/java/com/persagy/cameractl/sdk40/PlayDataCallBack.java

@@ -1,4 +1,4 @@
-package com.persagy.cameractl.sdk40;
+package com.persagy.cameractl.cvr;
 
 import java.io.FileOutputStream;
 import java.io.IOException;

+ 2 - 2
src/main/java/com/persagy/cameractl/sdk40/PlaybackTask.java

@@ -1,6 +1,6 @@
-package com.persagy.cameractl.sdk40;
+package com.persagy.cameractl.cvr;
 
-import static com.persagy.cameractl.sdk40.PlayBackController.hCNetSDK;
+import static com.persagy.cameractl.cvr.PlayBackController.hCNetSDK;
 
 import java.io.FileOutputStream;
 import java.io.IOException;

+ 69 - 0
src/main/java/com/persagy/cameractl/init/SDKInit.java

@@ -0,0 +1,69 @@
+package com.persagy.cameractl.init;
+
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+import com.persagy.cameractl.cvr.HCNetSDK;
+
+/**
+ * SDK初始化
+ *  
+ * @version 1.0.0
+ * @company persagy 
+ * @author zhangqiankun
+ * @date 2022年6月28日 下午4:48:09
+ */
+@Component
+@Order(-100)
+public class SDKInit implements ApplicationRunner {
+	
+	public static volatile HCNetSDK hCNetSDK;
+	private static volatile boolean isInit = false;
+	
+	@Override
+	public void run(ApplicationArguments args) throws Exception {
+		// SDK初始化
+		init();
+	}
+
+	public static boolean init() {
+		if (!isInit) {
+			// 初始化
+			hCNetSDK = HCNetSDK.INSTANCE;
+			isInit = hCNetSDK.NET_DVR_Init();
+		}
+		return isInit;
+	}
+	
+	/**
+	 * 登录
+	 * 
+	 * @param m_sUsername
+	 * @param m_sPassword
+	 * @param m_sDeviceIP
+	 * @param wPort
+	 * @return
+	 * @date 2022年6月28日 下午4:55:40
+	 */
+	public static 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;
+        m_strLoginInfo.bUseAsynLogin = false; //是否异步登录:0- 否,1- 是
+        m_strLoginInfo.write();
+        
+        return m_strLoginInfo;
+	}
+	
+}

+ 24 - 0
src/main/java/com/persagy/cameractl/init/StreamInfoInit.java

@@ -0,0 +1,24 @@
+package com.persagy.cameractl.init;
+
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+/**
+ * 
+ * @version 1.0.0
+ * @company persagy 
+ * @author zhangqiankun
+ * @date 2022年6月28日 下午4:47:15
+ */
+@Component
+@Order(10)
+public class StreamInfoInit implements ApplicationRunner {
+
+	@Override
+	public void run(ApplicationArguments args) throws Exception {
+
+	}
+
+}

+ 2 - 1
src/main/java/com/persagy/cameractl/service/HkCameraExecuteApi.java

@@ -124,7 +124,8 @@ public class HkCameraExecuteApi {
 					+ hkCamera.bitrate + "&videotype=" + hkCamera.videotype;
 			jsonBody.put("expand", expandStr);
 			String body = jsonBody.toString();
-			return SendRequest(url, body);
+			ResultClass sendRequest = SendRequest(url, body);
+			return sendRequest;
 		} catch (Exception e) {
 			logger.error("海康调用实时预览API出错:", e);
 			ResultClass resultClass = new ResultClass(false, "海康调用实时预览API出错");

+ 1 - 1
src/main/java/com/persagy/cameractl/temp/ClinetDemo.java

@@ -1,6 +1,6 @@
 package com.persagy.cameractl.temp;
 
-import com.persagy.cameractl.sdk40.HCNetSDK;
+import com.persagy.cameractl.cvr.HCNetSDK;
 import com.sun.jna.Native;
 import com.sun.jna.Pointer;
 import java.util.Timer;

+ 1 - 1
src/main/java/com/persagy/cameractl/temp/VideoDemo.java

@@ -1,6 +1,6 @@
 package com.persagy.cameractl.temp;
 
-import com.persagy.cameractl.sdk40.HCNetSDK;
+import com.persagy.cameractl.cvr.HCNetSDK;
 import com.sun.jna.Pointer;
 import com.sun.jna.ptr.ByteByReference;
 import com.sun.jna.ptr.IntByReference;

+ 2 - 2
src/main/java/com/persagy/cameractl/utils/TimerInterval.java

@@ -10,7 +10,7 @@ public class TimerInterval {
 	public static void startClearFileTimer() {
 		Timer fileClearTimer = new Timer();
 //		0秒后开始响应函数,每隔五分钟执行一次
-		fileClearTimer.schedule(new ClearTileTimer(), 0, 1000 * 60 * 20);
+		fileClearTimer.schedule(new ClearTileTimer(), 0, 1000 * 60 * 30);
 	};
 }
 
@@ -23,7 +23,7 @@ class ClearTileTimer extends java.util.TimerTask {
 			return;
 		}
 		// 五分钟
-		long timeP = 1000 * 60 * 5;
+		long timeP = 1000 * 60 * 10;
 		long currTime = System.currentTimeMillis();
 		String[] files = dir.list();// 读取目录下的所有目录文件信息
 		for (int i = 0; i < files.length; i++) {// 循环,添加文件名或回调自身

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 1 - 1
src/main/resources/application.yml