| | |
| | | import com.ruoyi.device.hiksdk.util.hikSdkUtil.GisUtil; |
| | | import com.ruoyi.device.hiksdk.util.hikSdkUtil.HCNetSDK; |
| | | import com.ruoyi.device.hiksdk.service.IHikClientService; |
| | | import com.ruoyi.device.hiksdk.util.minioUtil.MinioUtil; |
| | | import com.ruoyi.device.hiksdk.util.minio.MinioUtils; |
| | | import com.ruoyi.system.mapper.SysUserMapper; |
| | | import com.sun.jna.Native; |
| | | import com.sun.jna.Platform; |
| | |
| | | * @Description: 海康操作客户端实现类 |
| | | * @Author: Administrator |
| | | * @Date: 2023年01月17日 11:25 |
| | | * @Version: 1.0 |
| | | * @Version: 1.2 |
| | | **/ |
| | | @Slf4j(topic = "hikSdk") |
| | | @Service |
| | | public class HikClientServiceImpl implements IHikClientService { |
| | | |
| | | @Resource |
| | | private MinioUtil minioUtil; |
| | | |
| | | @Resource |
| | | ArdCamerasMapper ardCamerasMapper; |
| | |
| | | //设置HCNetSDKCom组件库所在路径 |
| | | //libhcnetsdk.so |
| | | String strPathCom = "/home/hiklib"; |
| | | HCNetSDK.NET_DVR_LOCAL_SDK_PATH struComPath = new HCNetSDK.NET_DVR_LOCAL_SDK_PATH(); |
| | | NET_DVR_LOCAL_SDK_PATH struComPath = new NET_DVR_LOCAL_SDK_PATH(); |
| | | System.arraycopy(strPathCom.getBytes(), 0, struComPath.sPath, 0, strPathCom.length()); |
| | | struComPath.write(); |
| | | hCNetSDK.NET_DVR_SetSDKInitCfg(2, struComPath.getPointer()); |
| | | |
| | | //设置libcrypto.so所在路径 |
| | | HCNetSDK.BYTE_ARRAY ptrByteArrayCrypto = new HCNetSDK.BYTE_ARRAY(256); |
| | | BYTE_ARRAY ptrByteArrayCrypto = new BYTE_ARRAY(256); |
| | | String strPathCrypto = "/home/hiklib/libcrypto.so.1.1"; |
| | | System.arraycopy(strPathCrypto.getBytes(), 0, ptrByteArrayCrypto.byValue, 0, strPathCrypto.length()); |
| | | ptrByteArrayCrypto.write(); |
| | | hCNetSDK.NET_DVR_SetSDKInitCfg(3, ptrByteArrayCrypto.getPointer()); |
| | | |
| | | //设置libssl.so所在路径 |
| | | HCNetSDK.BYTE_ARRAY ptrByteArraySsl = new HCNetSDK.BYTE_ARRAY(256); |
| | | BYTE_ARRAY ptrByteArraySsl = new BYTE_ARRAY(256); |
| | | String strPathSsl = "/home/hiklib/libssl.so.1.1"; |
| | | System.arraycopy(strPathSsl.getBytes(), 0, ptrByteArraySsl.byValue, 0, strPathSsl.length()); |
| | | ptrByteArraySsl.write(); |
| | |
| | | hCNetSDK.NET_DVR_SetConnectTime(2000, 1); |
| | | hCNetSDK.NET_DVR_SetReconnect(100000, true); |
| | | //设备信息, 输出参数 |
| | | HCNetSDK.NET_DVR_DEVICEINFO_V30 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30(); |
| | | NET_DVR_DEVICEINFO_V30 m_strDeviceInfo = new NET_DVR_DEVICEINFO_V30(); |
| | | int lUserID = hCNetSDK.NET_DVR_Login_V30(m_sDeviceIP, m_sPort, m_sUsername, m_sPassword, m_strDeviceInfo); |
| | | if (lUserID < 0) { |
| | | //释放SDK资源 |
| | |
| | | Integer userId = globalVariable.loginMap.get(cameraId); |
| | | |
| | | String ResResolution = ""; |
| | | HCNetSDK.NET_DVR_COMPRESSIONCFG_V30 resolution = new HCNetSDK.NET_DVR_COMPRESSIONCFG_V30(); |
| | | NET_DVR_COMPRESSIONCFG_V30 resolution = new NET_DVR_COMPRESSIONCFG_V30(); |
| | | resolution.write(); |
| | | Pointer pioint = resolution.getPointer(); |
| | | IntByReference ibrBytesReturned = new IntByReference(0); |
| | |
| | | } |
| | | Integer userId = globalVariable.loginMap.get(cameraId); |
| | | |
| | | HCNetSDK.NET_DVR_PTZPOS m_ptzPosCurrent = new HCNetSDK.NET_DVR_PTZPOS(); |
| | | NET_DVR_PTZPOS m_ptzPosCurrent = new NET_DVR_PTZPOS(); |
| | | Pointer pioint = m_ptzPosCurrent.getPointer(); |
| | | IntByReference ibrBytesReturned = new IntByReference(0); |
| | | m_ptzPosCurrent.write(); |
| | |
| | | return false; |
| | | } |
| | | Integer userId = globalVariable.loginMap.get(cameraId); |
| | | HCNetSDK.NET_DVR_PTZPOS m_ptzPosCurrent = new HCNetSDK.NET_DVR_PTZPOS(); |
| | | NET_DVR_PTZPOS m_ptzPosCurrent = new NET_DVR_PTZPOS(); |
| | | m_ptzPosCurrent.wAction = 1; |
| | | try { |
| | | String p = String.valueOf((int) ((double) ptz.get("p") * 10)); |
| | |
| | | return false; |
| | | } |
| | | Integer userId = globalVariable.loginMap.get(cameraId); |
| | | HCNetSDK.NET_DVR_PTZPOS m_ptzPosCurrent = new HCNetSDK.NET_DVR_PTZPOS(); |
| | | NET_DVR_PTZPOS m_ptzPosCurrent = new NET_DVR_PTZPOS(); |
| | | m_ptzPosCurrent.wAction = 1; |
| | | try { |
| | | double[] cameraPositon = cmd.getCamPosition(); |
| | |
| | | return false; |
| | | } |
| | | Integer userId = globalVariable.loginMap.get(cameraId); |
| | | HCNetSDK.NET_DVR_INITIALPOSITIONCTRL initialpositionctrl = new HCNetSDK.NET_DVR_INITIALPOSITIONCTRL(); |
| | | NET_DVR_INITIALPOSITIONCTRL initialpositionctrl = new NET_DVR_INITIALPOSITIONCTRL(); |
| | | |
| | | initialpositionctrl.dwSize = initialpositionctrl.size(); |
| | | initialpositionctrl.byWorkMode = 0; |
| | |
| | | InputStream input = new ByteArrayInputStream(array); |
| | | String url = ""; |
| | | try { |
| | | boolean b = minioUtil.putObject(BucketName, ObjectName, input, input.available(), ContentType); |
| | | boolean b = MinioUtils.uploadObject(BucketName, ObjectName, input, input.available(), ContentType); |
| | | if (b) { |
| | | url = minioUtil.presignedGetObject(BucketName, ObjectName, 5); |
| | | url = MinioUtils.getBucketObjectUrl(BucketName, ObjectName); |
| | | log.info("上传文件成功!" + url); |
| | | } |
| | | } catch (IOException ex) { |
| | |
| | | String BucketName = "record"; |
| | | String uuid = UUID.randomUUID().toString().replace("-", ""); |
| | | String time = new SimpleDateFormat("yyyyMMdd").format(new Date()); |
| | | String ObjectName = time + "/" + uuid + ".mp4"; |
| | | String ObjectName = cameraId + "/" + time + "/" + uuid + ".mp4"; |
| | | String ContentType = "video/MP4"; |
| | | FileInputStream stream = null; |
| | | try { |
| | |
| | | } |
| | | String url = ""; |
| | | try { |
| | | boolean b = minioUtil.putObject(BucketName, ObjectName, stream, stream.available(), ContentType); |
| | | boolean b = MinioUtils.uploadObject(BucketName, ObjectName, stream, stream.available(), ContentType); |
| | | if (b) { |
| | | url = minioUtil.presignedGetObject(BucketName, ObjectName, 5); |
| | | url = MinioUtils.getBucketObjectUrl(BucketName, ObjectName); |
| | | log.info("上传文件成功!" + url); |
| | | } |
| | | } catch (IOException ex) { |
| | |
| | | |
| | | @Override |
| | | @SdkOperate |
| | | public void recordToMinio(CameraCmd cmd) throws IOException { |
| | | String cameraId = cmd.getCameraId(); |
| | | Integer channelNum = cmd.getChannelNum(); |
| | | boolean enable = cmd.isEnable(); |
| | | if (!globalVariable.loginMap.containsKey(cameraId)) { |
| | | return; |
| | | } |
| | | Integer userId = globalVariable.loginMap.get(cameraId); |
| | | String path = ""; |
| | | //预览参数 |
| | | NET_DVR_PREVIEWINFO previewinfo = new NET_DVR_PREVIEWINFO(); |
| | | previewinfo.read(); |
| | | previewinfo.lChannel = channelNum; |
| | | previewinfo.dwStreamType = 0;//码流类型:0-主码流,1-子码流,2-三码流,3-虚拟码流,以此类推 |
| | | previewinfo.dwLinkMode = 0;//连接方式:0-TCP方式,1-UDP方式,2-多播方式,3-RTP方式,4-RTP/RTSP,5-RTP/HTTP,6-HRUDP(可靠传输),7-RTSP/HTTPS,8-NPQ |
| | | previewinfo.hPlayWnd = null;//播放窗口的句柄,为NULL表示不解码显示。 |
| | | previewinfo.bBlocked = 0;//0- 非阻塞取流,1-阻塞取流 |
| | | previewinfo.byNPQMode = 0;//NPQ模式:0-直连模式,1-过流媒体模式 |
| | | previewinfo.write(); |
| | | int lRealHandle; |
| | | if (enable) { |
| | | if (!user_real_Map.containsKey(userId)) { |
| | | lRealHandle = hCNetSDK.NET_DVR_RealPlay_V40(userId, previewinfo, null, null); |
| | | if (lRealHandle == -1) { |
| | | int iErr = hCNetSDK.NET_DVR_GetLastError(); |
| | | log.error("取流失败" + iErr); |
| | | public void recordToMinio(CameraCmd cmd) { |
| | | try { |
| | | String cameraId = cmd.getCameraId(); |
| | | Integer channelNum = cmd.getChannelNum(); |
| | | boolean enable = cmd.isEnable(); |
| | | if (!globalVariable.loginMap.containsKey(cameraId)) { |
| | | return; |
| | | } |
| | | Integer userId = globalVariable.loginMap.get(cameraId); |
| | | String path = ""; |
| | | //预览参数 |
| | | NET_DVR_PREVIEWINFO previewinfo = new NET_DVR_PREVIEWINFO(); |
| | | previewinfo.read(); |
| | | previewinfo.lChannel = channelNum; |
| | | previewinfo.dwStreamType = 0;//码流类型:0-主码流,1-子码流,2-三码流,3-虚拟码流,以此类推 |
| | | previewinfo.dwLinkMode = 0;//连接方式:0-TCP方式,1-UDP方式,2-多播方式,3-RTP方式,4-RTP/RTSP,5-RTP/HTTP,6-HRUDP(可靠传输),7-RTSP/HTTPS,8-NPQ |
| | | previewinfo.hPlayWnd = null;//播放窗口的句柄,为NULL表示不解码显示。 |
| | | previewinfo.bBlocked = 0;//0- 非阻塞取流,1-阻塞取流 |
| | | previewinfo.byNPQMode = 0;//NPQ模式:0-直连模式,1-过流媒体模式 |
| | | previewinfo.write(); |
| | | int lRealHandle; |
| | | if (enable) { |
| | | if (!user_real_Map.containsKey(userId)) { |
| | | lRealHandle = hCNetSDK.NET_DVR_RealPlay_V40(userId, previewinfo, null, null); |
| | | if (lRealHandle == -1) { |
| | | int iErr = hCNetSDK.NET_DVR_GetLastError(); |
| | | log.error("取流失败" + iErr); |
| | | return; |
| | | } |
| | | log.info("取流成功"); |
| | | File file = new File("D:/recordTemp/" + cameraId + ".mp4"); |
| | | if (!file.exists()) { |
| | | File fileParent = file.getParentFile(); |
| | | if (!fileParent.exists()) { |
| | | fileParent.mkdirs(); |
| | | } |
| | | file.createNewFile(); |
| | | } |
| | | path = file.getCanonicalPath(); |
| | | recordInfo info = new recordInfo(); |
| | | info.setLRealHandle(lRealHandle); |
| | | info.setRecordPath(path); |
| | | user_real_Map.put(userId, info); |
| | | } |
| | | recordInfo info = user_real_Map.get(userId); |
| | | if (!hCNetSDK.NET_DVR_SaveRealData_V30(info.getLRealHandle(), 1, info.getRecordPath())) { |
| | | log.error("保存视频文件到临时文件夹失败 错误码为: " + hCNetSDK.NET_DVR_GetLastError()); |
| | | return; |
| | | } |
| | | log.info("取流成功"); |
| | | File file = new File("D:/recordTemp/" + cameraId + ".mp4"); |
| | | if (!file.exists()) { |
| | | File fileParent = file.getParentFile(); |
| | | if (!fileParent.exists()) { |
| | | fileParent.mkdirs(); |
| | | } |
| | | file.createNewFile(); |
| | | log.info("录像开始"); |
| | | } else { |
| | | recordInfo info = user_real_Map.get(userId); |
| | | if (StringUtils.isNull(info)) { |
| | | return; |
| | | } |
| | | path = file.getCanonicalPath(); |
| | | recordInfo info = new recordInfo(); |
| | | info.setLRealHandle(lRealHandle); |
| | | info.setRecordPath(path); |
| | | user_real_Map.put(userId, info); |
| | | } |
| | | recordInfo info = user_real_Map.get(userId); |
| | | if (!hCNetSDK.NET_DVR_SaveRealData_V30(info.getLRealHandle(), 1, info.getRecordPath())) { |
| | | log.error("保存视频文件到临时文件夹失败 错误码为: " + hCNetSDK.NET_DVR_GetLastError()); |
| | | return; |
| | | } |
| | | log.info("录像开始"); |
| | | } else { |
| | | recordInfo info = user_real_Map.get(userId); |
| | | if (StringUtils.isNull(info)) { |
| | | return; |
| | | } |
| | | hCNetSDK.NET_DVR_StopRealPlay(info.getLRealHandle()); |
| | | log.info("录像停止"); |
| | | //存入minio |
| | | String BucketName = cmd.getRecordBucketName(); |
| | | String ObjectName = cmd.getRecordObjectName(); |
| | | String ContentType = "video/MP4"; |
| | | FileInputStream stream = new FileInputStream(info.getRecordPath()); |
| | | String url = ""; |
| | | try { |
| | | hCNetSDK.NET_DVR_StopRealPlay(info.getLRealHandle()); |
| | | log.info("录像停止"); |
| | | //存入minio |
| | | String BucketName = cmd.getRecordBucketName(); |
| | | String ObjectName = cmd.getRecordObjectName(); |
| | | String ContentType = "video/MP4"; |
| | | FileInputStream stream = new FileInputStream(info.getRecordPath()); |
| | | String url = ""; |
| | | boolean b = MinioUtils.uploadObject(BucketName, ObjectName, stream, stream.available(), ContentType); |
| | | if (b) { |
| | | url = BucketName + ObjectName; |
| | | log.info("上传文件成功!" + url); |
| | | user_real_Map.remove(userId); |
| | | } |
| | | } catch (IOException ex) { |
| | | log.error("上传文件异常:" + ex.getMessage()); |
| | | } |
| | | user_real_Map.remove(userId); |
| | | } catch (Exception ex) { |
| | | log.error("录像异常" + ex.getMessage()); |
| | | } |
| | | } |
| | | } |