| | |
| | | package com.ard.device.component.sdk.dh.service.impl; |
| | | |
| | | import com.ard.common.core.domain.AjaxResult; |
| | | import com.ard.common.utils.StringUtils; |
| | | import com.ard.device.camera.domain.ArdCamera; |
| | | import com.ard.device.camera.domain.CameraCmd; |
| | | import com.ard.device.camera.service.IArdCameraService; |
| | | import com.ard.device.channel.domain.ArdChannel; |
| | | import com.ard.device.channel.domain.VideoCompressionCfg; |
| | | import com.ard.device.channel.service.IArdChannelService; |
| | | import com.ard.device.component.sdk.common.GlobalVariable; |
| | | import com.ard.device.component.sdk.common.osSelect; |
| | | import com.ard.device.component.sdk.dh.module.ConfigModule; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.context.ApplicationEventPublisher; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.Resource; |
| | | import java.io.*; |
| | |
| | | public class DaHuaSDK implements CameraSDK { |
| | | |
| | | @Resource |
| | | private IArdCameraService ardCameraService; |
| | | @Resource |
| | | private IArdChannelService ardChannelService; |
| | | @Resource |
| | | private ApplicationEventPublisher eventPublisher; |
| | | |
| | | |
| | | public static NetSDKLib netsdk = null; |
| | | public static NetSDKLib configsdk = null; |
| | |
| | | * 登录 |
| | | */ |
| | | @Override |
| | | public AjaxResult login(ArdCamera camera) { |
| | | public void login(ArdCamera camera) { |
| | | try { |
| | | NetSDKLib.NET_DEVICEINFO_Ex m_stDeviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex(); |
| | | NetSDKLib.LLong loginId = LoginModule.login(camera.getIp(), camera.getPort(), camera.getUsername(), camera.getPassword(), m_stDeviceInfo); |
| | | NetSDKLib.LLong loginId = LoginModule.login(camera.getIp(), camera.getPort(), camera.getUsername(), |
| | | camera.getPassword(), m_stDeviceInfo); |
| | | if (loginId.longValue() <= 0) { |
| | | camera.setChanNum(0); |
| | | camera.setLoginId(-1L); |
| | |
| | | LoginEvent loginEvent = new LoginEvent(camera); |
| | | eventPublisher.publishEvent(loginEvent); |
| | | log.warn("设备[{}:{}]登录失败:{}", camera.getIp(), camera.getPort(), getErrorCodePrint()); |
| | | return AjaxResult.warn(getErrorCodePrint()); |
| | | } |
| | | log.debug("设备[{}:{}]登录成功:{}", camera.getIp(), camera.getPort(), loginId); |
| | | camera.setState("1"); |
| | | camera.setChanNum(m_stDeviceInfo.byChanNum); |
| | | camera.setStartChan(1); |
| | | camera.setLoginId(loginId.longValue()); |
| | | GlobalVariable.loginMap.put(camera.getId(), loginId); |
| | | |
| | | //获取最新通道 |
| | | List<ArdChannel> ardChannelList = getChannels(camera); |
| | | if (!ardChannelList.isEmpty()) { |
| | |
| | | } |
| | | LoginEvent loginEvent = new LoginEvent(camera); |
| | | eventPublisher.publishEvent(loginEvent); |
| | | //创建引导队列 |
| | | //createGuideQueue(camera); |
| | | return AjaxResult.success("登录成功"); |
| | | } catch (Exception ex) { |
| | | log.error("登录异常:{}", ex.getMessage()); |
| | | return AjaxResult.error("登录异常:" + ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | |
| | | * 注销 |
| | | * 刘苏义 |
| | | * 2023/10/17 8:28:13 |
| | | * |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean logout(String cameraId) { |
| | | if (!GlobalVariable.loginMap.containsKey(cameraId)) { |
| | | return false; |
| | | } |
| | | NetSDKLib.LLong loginId = (NetSDKLib.LLong) GlobalVariable.loginMap.get(cameraId); |
| | | return LoginModule.logout(loginId); |
| | | public void logout(ArdCamera ardCamera) { |
| | | NetSDKLib.LLong loginId = new NetSDKLib.LLong(ardCamera.getLoginId()); |
| | | LoginModule.logout(loginId); |
| | | } |
| | | |
| | | /** |
| | |
| | | * 2023/10/17 8:28:13 |
| | | */ |
| | | @Override |
| | | public boolean isOnLine(CameraCmd cmd) { |
| | | public boolean isOnLine(ArdCamera ardCamera) { |
| | | try { |
| | | String cameraId = cmd.getCameraId(); |
| | | if (!GlobalVariable.loginMap.containsKey(cameraId)) { |
| | | return false; |
| | | } |
| | | NetSDKLib.LLong loginId = (NetSDKLib.LLong) GlobalVariable.loginMap.get(cameraId); |
| | | NetSDKLib.LLong loginId = new NetSDKLib.LLong(ardCamera.getLoginId()); |
| | | NetSDKLib.NET_WORKSTATE dh_ptz_location_info = new NetSDKLib.NET_WORKSTATE(); |
| | | boolean b = ConfigModule.queryDevState(loginId, NET_DEVSTATE_ONLINE, dh_ptz_location_info); |
| | | if (!b) { |
| | |
| | | /** |
| | | * 获取通道 |
| | | */ |
| | | |
| | | @Override |
| | | public List<ArdChannel> getChannels(ArdCamera camera) { |
| | | if (camera.getLoginId() < 0) { |
| | | return new ArrayList<>(); |
| | |
| | | channel.setDeviceId(camera.getId()); |
| | | channel.setChanNo(i); |
| | | //获取视频编码 |
| | | CameraCmd cameraCmd = new CameraCmd(camera.getId(), channel.getChanNo()); |
| | | VideoCompressionCfg videoCompressionCfg = getVideoCompressionCfg(cameraCmd); |
| | | camera.setChanNo(i); |
| | | VideoCompressionCfg videoCompressionCfg = getVideoCompressionCfg(camera); |
| | | if (StringUtils.isNotNull(videoCompressionCfg)) { |
| | | channel.setVideoCode(videoCompressionCfg.getVideoEncType()); |
| | | } |
| | |
| | | return ardChannelList; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public VideoCompressionCfg getVideoCompressionCfg(CameraCmd cmd) { |
| | | String cameraId = cmd.getCameraId(); |
| | | Integer chanNo = cmd.getChanNo(); |
| | | if (!GlobalVariable.loginMap.containsKey(cameraId)) { |
| | | return null; |
| | | } |
| | | NetSDKLib.LLong loginId = (NetSDKLib.LLong) GlobalVariable.loginMap.get(cameraId); |
| | | public VideoCompressionCfg getVideoCompressionCfg(ArdCamera ardCamera) { |
| | | |
| | | NetSDKLib.LLong loginId = new NetSDKLib.LLong(ardCamera.getLoginId()); |
| | | NetSDKLib.CFG_ENCODE_INFO cfg_encode_info = new NetSDKLib.CFG_ENCODE_INFO(); |
| | | cfg_encode_info.nChannelID = chanNo - 1; |
| | | boolean b = ConfigModule.GetNewDevConfig(loginId, chanNo - 1, CFG_CMD_ENCODE, cfg_encode_info); |
| | | cfg_encode_info.nChannelID = ardCamera.getChanNo() - 1; |
| | | boolean b = ConfigModule.GetNewDevConfig(loginId, ardCamera.getChanNo() - 1, CFG_CMD_ENCODE, cfg_encode_info); |
| | | if (b) { |
| | | int emCompression = cfg_encode_info.stuMainStream[0].stuVideoFormat.emCompression;//视频格式 |
| | | String videoEncType; |
| | |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 动态库加载 - 大华 NetSDK + ConfigSDK |