| | |
| | | import com.ruoyi.utils.sdk.common.SdkErrorCodeEnum; |
| | | import com.ruoyi.utils.sdk.dhsdk.common.ErrorCode; |
| | | import com.ruoyi.utils.sdk.dhsdk.lib.NetSDKLib; |
| | | import com.ruoyi.utils.sdk.dhsdk.lib.ToolKits; |
| | | import com.ruoyi.utils.sdk.dhsdk.lib.enumeration.EM_NEW_CONFIG; |
| | | import com.ruoyi.utils.sdk.dhsdk.lib.enumeration.NET_EM_CFG_OPERATE_TYPE; |
| | | import com.ruoyi.utils.sdk.dhsdk.lib.structure.CFG_INFRARED_INFO; |
| | | import com.ruoyi.utils.sdk.dhsdk.lib.structure.CFG_VIDEO_IN_FOCUS; |
| | | import com.ruoyi.utils.sdk.dhsdk.lib.structure.DH_OUT_PTZ_VIEW_RANGE_STATUS; |
| | | import com.ruoyi.utils.sdk.dhsdk.module.*; |
| | | import com.sun.jna.Native; |
| | | import com.sun.jna.Pointer; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.*; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.text.DecimalFormat; |
| | | import java.util.Comparator; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.concurrent.PriorityBlockingQueue; |
| | | |
| | | import static com.ruoyi.utils.sdk.dhsdk.lib.NetSDKLib.*; |
| | |
| | | |
| | | //创建引导队列 |
| | | private void createGuideQueue(ArdCameras camera) { |
| | | if (camera.getCamAlarmGuideEnable() != null) { |
| | | if (camera.getCamAlarmGuideEnable() == 1) { |
| | | if (!GuidePriorityQueue.cameraQueueMap.containsKey(camera.getId())) { |
| | | Comparator<GuideTask> comparator = GuidePriorityQueue.getComparator(); |
| | | PriorityBlockingQueue<GuideTask> priorityQueue = new PriorityBlockingQueue<>(1000, comparator); |
| | | GuidePriorityQueue.cameraQueueMap.put(camera.getId(), priorityQueue); |
| | | //启动队列处理器 |
| | | queueHandler.process(camera.getId()); |
| | | } |
| | | } |
| | | if (!GuidePriorityQueue.cameraQueueMap.containsKey(camera.getId())) { |
| | | Comparator<GuideTask> comparator = GuidePriorityQueue.getComparator(); |
| | | PriorityBlockingQueue<GuideTask> priorityQueue = new PriorityBlockingQueue<>(1000, comparator); |
| | | GuidePriorityQueue.cameraQueueMap.put(camera.getId(), priorityQueue); |
| | | //启动队列处理器 |
| | | queueHandler.process(camera.getId()); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult localCapture(CameraCmd cmd) { |
| | | try { |
| | | String cameraId = cmd.getCameraId(); |
| | | Integer chanNo = cmd.getChanNo(); |
| | | if (!GlobalVariable.loginMap.containsKey(cameraId)) { |
| | | return AjaxResult.error("设备未登录"); |
| | | } |
| | | LLong loginId = (LLong) GlobalVariable.loginMap.get(cameraId); |
| | | String imagePath = FileUtils.createFile("D:/LocalCaptureTemp/" + cameraId + ".jpeg"); |
| | | fCaptureReceiveCB1 m_CaptureReceiveCB = new fCaptureReceiveCB1(imagePath); |
| | | CapturePictureModule.setSnapRevCallBack(m_CaptureReceiveCB); |
| | | boolean b = CapturePictureModule.remoteCapturePicture(loginId, chanNo - 1); |
| | | if (b) { |
| | | Thread.sleep(200); |
| | | byte[] imageBytes = Files.readAllBytes(Paths.get(imagePath)); |
| | | //OutputStream outputStream = response.getOutputStream(); |
| | | //outputStream.write(imageBytes); |
| | | // 创建ByteBuffer并将字节数组写入其中 |
| | | //ByteBuffer jpegBuffer = ByteBuffer.wrap(imageBytes); |
| | | //Base64.Encoder decoder = Base64.getEncoder(); |
| | | //String png_base64 = decoder.encodeToString(jpegBuffer.array());//转换成base64串 |
| | | return AjaxResult.success(imageBytes); |
| | | } else { |
| | | return AjaxResult.error("本地抓图失败"); |
| | | } |
| | | } catch (Exception ex) { |
| | | return AjaxResult.error("本地抓图异常:" + ex); |
| | | } |
| | | } |
| | | |
| | | //本地录像开始 |
| | | @Override |
| | | public AjaxResult localRecordStart(CameraCmd cmd) { |
| | | try { |
| | | String cameraId = cmd.getCameraId(); |
| | | Integer chanNo = cmd.getChanNo(); |
| | | String path = FileUtils.createFile("D:/LocalRecordTemp/" + cameraId + ".mp4"); |
| | | if (!GlobalVariable.loginMap.containsKey(cameraId)) { |
| | | return AjaxResult.error("设备未登录"); |
| | | } |
| | | LLong loginId = (LLong) GlobalVariable.loginMap.get(cameraId); |
| | | LLong lRealHandle; |
| | | if (GlobalVariable.previewMap.containsKey(cameraId)) { |
| | | lRealHandle = new LLong(GlobalVariable.previewMap.get(cameraId)); |
| | | RealPlayModule.stopRealPlay(lRealHandle); |
| | | GlobalVariable.previewMap.remove(cameraId); |
| | | log.debug("停止当前录像"); |
| | | } |
| | | lRealHandle = RealPlayModule.startRealPlay(loginId, chanNo - 1, path); |
| | | if (lRealHandle.longValue() <= 0) { |
| | | log.error("取流失败" + getErrorCodePrint()); |
| | | } |
| | | log.debug("本地录像开始取流成功"); |
| | | GlobalVariable.previewMap.put(cameraId, lRealHandle.intValue()); |
| | | GlobalVariable.threadMap.put(cameraId, Thread.currentThread().getName()); |
| | | //if (!netsdk.CLIENT_SaveRealData(lRealHandle, path)) { |
| | | // log.error("保存视频文件到临时文件夹失败 错误码为: " +getErrorCodePrint()); |
| | | // return false; |
| | | //} |
| | | log.debug("本地录像开始"); |
| | | return AjaxResult.success("本地录像开始,录像ID:"+lRealHandle); |
| | | } catch (Exception ex) { |
| | | log.error("本地录像开始异常" + ex.getMessage()); |
| | | return AjaxResult.error("本地录像开始异常" + ex.getMessage()); |
| | | } |
| | | } |
| | | //本地录像停止 |
| | | @Override |
| | | public AjaxResult localRecordStop(CameraCmd cmd) { |
| | | try { |
| | | String cameraId = cmd.getCameraId(); |
| | | if (!GlobalVariable.loginMap.containsKey(cameraId)) { |
| | | return AjaxResult.error("设备未登录"); |
| | | } |
| | | LLong lRealHandle; |
| | | if (GlobalVariable.previewMap.containsKey(cameraId)) { |
| | | lRealHandle = new LLong(GlobalVariable.previewMap.get(cameraId)); |
| | | RealPlayModule.stopRealPlay(lRealHandle); |
| | | GlobalVariable.previewMap.remove(cameraId); |
| | | log.debug("本地录像停止"); |
| | | String recordPath = FileUtils.createFile("D:/LocalRecordTemp/" + cameraId + ".mp4"); |
| | | byte[] imageBytes = Files.readAllBytes(Paths.get(recordPath)); |
| | | // OutputStream outputStream = response.getOutputStream(); |
| | | // outputStream.write(imageBytes); |
| | | return AjaxResult.success(imageBytes); |
| | | } |
| | | else { |
| | | return AjaxResult.error("设备未开始录像"); |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error("本地录像停止异常" + ex.getMessage()); |
| | | return AjaxResult.error("本地录像停止异常" + ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @描述 短时录像 |
| | |
| | | } |
| | | LLong loginId = (LLong) GlobalVariable.loginMap.get(cameraId); |
| | | try { |
| | | |
| | | boolean bool = netsdk.CLIENT_DHPTZControlEx(loginId, chanNo - 1, NET_PTZ_POINT_MOVE_CONTROL, 0, PresetIndex, 0, 0); |
| | | if (!bool) { |
| | | log.error("转至预置点失败:" + getErrorCodePrint()); |
| | |
| | | return AjaxResult.success("该功能未实现"); |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult captureJPEGPicture(CameraCmd cmd) { |
| | | return AjaxResult.success("该功能未实现"); |
| | | } |
| | | |
| | | //切换透雾 |
| | | @Override |
| | |
| | | } |
| | | } |
| | | |
| | | // 抓图接收回调:当抓图成功,sdk会调用该函数 |
| | | public static class fCaptureReceiveCB1 implements NetSDKLib.fSnapRev { |
| | | private String picPath; |
| | | public fCaptureReceiveCB1(String picPath) { |
| | | this.picPath = picPath; |
| | | } |
| | | public void invoke(LLong lLoginID, Pointer pBuf, int RevLen, int EncodeType, int CmdSerial, Pointer dwUser) { |
| | | if (pBuf != null && RevLen > 0) { |
| | | byte[] buf = pBuf.getByteArray(0, RevLen); |
| | | //存储到本地 |
| | | InputStream input = new ByteArrayInputStream(buf); |
| | | OutputStream output = null; |
| | | try { |
| | | output = new FileOutputStream(picPath); |
| | | byte[] buffer = new byte[1024]; |
| | | int bytesRead; |
| | | while ((bytesRead = input.read(buffer)) != -1) { |
| | | output.write(buffer, 0, bytesRead); |
| | | } |
| | | input.close(); |
| | | output.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |