|  |  |  | 
|---|
|  |  |  | import com.genersoft.iot.vmp.service.bean.ThirdPartyGB; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.utils.DateUtil; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.utils.redis.RedisUtil; | 
|---|
|  |  |  | import org.slf4j.Logger; | 
|---|
|  |  |  | import org.slf4j.LoggerFactory; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @SuppressWarnings("rawtypes") | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserSetting userSetting; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Long getCSEQ(String method) { | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean stopPlay(StreamInfo streamInfo) { | 
|---|
|  |  |  | if (streamInfo == null) return false; | 
|---|
|  |  |  | if (streamInfo == null) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return redis.del(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, | 
|---|
|  |  |  | userSetting.getServerId(), | 
|---|
|  |  |  | streamInfo.getStream(), | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public StreamInfo queryPlayByStreamId(String streamId) { | 
|---|
|  |  |  | List<Object> playLeys = redis.scan(String.format("%S_%s_%s_*", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(), streamId)); | 
|---|
|  |  |  | if (playLeys == null || playLeys.size() == 0) return null; | 
|---|
|  |  |  | if (playLeys == null || playLeys.size() == 0) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return (StreamInfo)redis.get(playLeys.get(0).toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | userSetting.getServerId(), | 
|---|
|  |  |  | deviceId, | 
|---|
|  |  |  | channelId)); | 
|---|
|  |  |  | if (playLeys == null || playLeys.size() == 0) return null; | 
|---|
|  |  |  | if (playLeys == null || playLeys.size() == 0) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return (StreamInfo)redis.get(playLeys.get(0).toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | Map<String, StreamInfo> streamInfos = new HashMap<>(); | 
|---|
|  |  |  | //      List<Object> playLeys = redis.keys(String.format("%S_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, deviceId)); | 
|---|
|  |  |  | List<Object> players = redis.scan(String.format("%S_%s_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(),deviceId)); | 
|---|
|  |  |  | if (players.size() == 0) return streamInfos; | 
|---|
|  |  |  | if (players.size() == 0) { | 
|---|
|  |  |  | return streamInfos; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (Object player : players) { | 
|---|
|  |  |  | String key = (String) player; | 
|---|
|  |  |  | StreamInfo streamInfo = (StreamInfo) redis.get(key); | 
|---|
|  |  |  | 
|---|
|  |  |  | deviceChannel.setDeviceId(deviceId); | 
|---|
|  |  |  | deviceChannelMapper.update(deviceChannel); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (deviceId == null) deviceId = "*"; | 
|---|
|  |  |  | if (channelId == null) channelId = "*"; | 
|---|
|  |  |  | if (stream == null) stream = "*"; | 
|---|
|  |  |  | if (callId == null) callId = "*"; | 
|---|
|  |  |  | if (deviceId == null) { | 
|---|
|  |  |  | deviceId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (channelId == null) { | 
|---|
|  |  |  | channelId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (stream == null) { | 
|---|
|  |  |  | stream = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (callId == null) { | 
|---|
|  |  |  | callId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX, | 
|---|
|  |  |  | userSetting.getServerId(), | 
|---|
|  |  |  | deviceId, | 
|---|
|  |  |  | 
|---|
|  |  |  | deviceChannel.setDeviceId(deviceId); | 
|---|
|  |  |  | deviceChannelMapper.update(deviceChannel); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (deviceId == null) deviceId = "*"; | 
|---|
|  |  |  | if (channelId == null) channelId = "*"; | 
|---|
|  |  |  | if (stream == null) stream = "*"; | 
|---|
|  |  |  | if (callId == null) callId = "*"; | 
|---|
|  |  |  | if (deviceId == null) { | 
|---|
|  |  |  | deviceId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (channelId == null) { | 
|---|
|  |  |  | channelId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (stream == null) { | 
|---|
|  |  |  | stream = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (callId == null) { | 
|---|
|  |  |  | callId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | 
|---|
|  |  |  | userSetting.getServerId(), | 
|---|
|  |  |  | deviceId, | 
|---|
|  |  |  | 
|---|
|  |  |  | if (stream == null && callId == null) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (deviceId == null) deviceId = "*"; | 
|---|
|  |  |  | if (channelId == null) channelId = "*"; | 
|---|
|  |  |  | if (stream == null) stream = "*"; | 
|---|
|  |  |  | if (callId == null) callId = "*"; | 
|---|
|  |  |  | if (deviceId == null) { | 
|---|
|  |  |  | deviceId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (channelId == null) { | 
|---|
|  |  |  | channelId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (stream == null) { | 
|---|
|  |  |  | stream = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (callId == null) { | 
|---|
|  |  |  | callId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | 
|---|
|  |  |  | userSetting.getServerId(), | 
|---|
|  |  |  | deviceId, | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public SendRtpItem querySendRTPServer(String platformGbId, String channelId, String streamId, String callId) { | 
|---|
|  |  |  | if (platformGbId == null) platformGbId = "*"; | 
|---|
|  |  |  | if (channelId == null) channelId = "*"; | 
|---|
|  |  |  | if (streamId == null) streamId = "*"; | 
|---|
|  |  |  | if (callId == null) callId = "*"; | 
|---|
|  |  |  | if (platformGbId == null) { | 
|---|
|  |  |  | platformGbId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (channelId == null) { | 
|---|
|  |  |  | channelId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (streamId == null) { | 
|---|
|  |  |  | streamId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (callId == null) { | 
|---|
|  |  |  | callId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId | 
|---|
|  |  |  | + "_" + channelId + "_" + streamId + "_" + callId; | 
|---|
|  |  |  | List<Object> scan = redis.scan(key); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<SendRtpItem> querySendRTPServer(String platformGbId) { | 
|---|
|  |  |  | if (platformGbId == null) platformGbId = "*"; | 
|---|
|  |  |  | if (platformGbId == null) { | 
|---|
|  |  |  | platformGbId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId + "_*" + "_*" + "_*"; | 
|---|
|  |  |  | List<Object> queryResult = redis.scan(key); | 
|---|
|  |  |  | List<SendRtpItem> result= new ArrayList<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void deleteSendRTPServer(String platformGbId, String channelId, String callId, String streamId) { | 
|---|
|  |  |  | if (streamId == null) streamId = "*"; | 
|---|
|  |  |  | if (callId == null) callId = "*"; | 
|---|
|  |  |  | if (streamId == null) { | 
|---|
|  |  |  | streamId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (callId == null) { | 
|---|
|  |  |  | callId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId | 
|---|
|  |  |  | + "_" + channelId + "_" + streamId + "_" + callId; | 
|---|
|  |  |  | List<Object> scan = redis.scan(key); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void outlineForAll() { | 
|---|
|  |  |  | List<Object> onlineDevices = redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetting.getServerId() + "_" + "*" ); | 
|---|
|  |  |  | for (int i = 0; i < onlineDevices.size(); i++) { | 
|---|
|  |  |  | String key = (String) onlineDevices.get(i); | 
|---|
|  |  |  | redis.del(key); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<String> getOnlineForAll() { | 
|---|
|  |  |  | List<String> result = new ArrayList<>(); | 
|---|
|  |  |  | List<Object> onlineDevices = redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetting.getServerId() + "_"  + "*" ); | 
|---|
|  |  |  | for (int i = 0; i < onlineDevices.size(); i++) { | 
|---|
|  |  |  | String key = (String) onlineDevices.get(i); | 
|---|
|  |  |  | result.add((String) redis.get(key)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void updateWVPInfo(JSONObject jsonObject, int time) { | 
|---|
|  |  |  | String key = VideoManagerConstants.WVP_SERVER_PREFIX + userSetting.getServerId(); | 
|---|
|  |  |  | redis.set(key, jsonObject, time); | 
|---|
|  |  |  | 
|---|
|  |  |  | if (stream == null && callId == null) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (deviceId == null) deviceId = "*"; | 
|---|
|  |  |  | if (channelId == null) channelId = "*"; | 
|---|
|  |  |  | if (stream == null) stream = "*"; | 
|---|
|  |  |  | if (callId == null) callId = "*"; | 
|---|
|  |  |  | if (deviceId == null) { | 
|---|
|  |  |  | deviceId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (channelId == null) { | 
|---|
|  |  |  | channelId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (stream == null) { | 
|---|
|  |  |  | stream = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (callId == null) { | 
|---|
|  |  |  | callId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX, | 
|---|
|  |  |  | userSetting.getServerId(), | 
|---|
|  |  |  | deviceId, | 
|---|
|  |  |  | 
|---|
|  |  |  | public void addCpuInfo(double cpuInfo) { | 
|---|
|  |  |  | String key = VideoManagerConstants.SYSTEM_INFO_CPU_PREFIX + userSetting.getServerId(); | 
|---|
|  |  |  | SystemInfoDto<Double> systemInfoDto = new SystemInfoDto<>(); | 
|---|
|  |  |  | systemInfoDto.setTime(format.format(System.currentTimeMillis())); | 
|---|
|  |  |  | systemInfoDto.setTime(DateUtil.getNow()); | 
|---|
|  |  |  | systemInfoDto.setData(cpuInfo); | 
|---|
|  |  |  | redis.lSet(key, systemInfoDto); | 
|---|
|  |  |  | // 每秒一个,最多只存30个 | 
|---|
|  |  |  | 
|---|
|  |  |  | public void addMemInfo(double memInfo) { | 
|---|
|  |  |  | String key = VideoManagerConstants.SYSTEM_INFO_MEM_PREFIX + userSetting.getServerId(); | 
|---|
|  |  |  | SystemInfoDto<Double> systemInfoDto = new SystemInfoDto<>(); | 
|---|
|  |  |  | systemInfoDto.setTime(format.format(System.currentTimeMillis())); | 
|---|
|  |  |  | systemInfoDto.setTime(DateUtil.getNow()); | 
|---|
|  |  |  | systemInfoDto.setData(memInfo); | 
|---|
|  |  |  | redis.lSet(key, systemInfoDto); | 
|---|
|  |  |  | // 每秒一个,最多只存30个 | 
|---|
|  |  |  | 
|---|
|  |  |  | public void addNetInfo(Map<String, String> networkInterfaces) { | 
|---|
|  |  |  | String key = VideoManagerConstants.SYSTEM_INFO_NET_PREFIX + userSetting.getServerId(); | 
|---|
|  |  |  | SystemInfoDto<Map<String, String>> systemInfoDto = new SystemInfoDto<>(); | 
|---|
|  |  |  | systemInfoDto.setTime(format.format(System.currentTimeMillis())); | 
|---|
|  |  |  | systemInfoDto.setTime(DateUtil.getNow()); | 
|---|
|  |  |  | systemInfoDto.setData(networkInterfaces); | 
|---|
|  |  |  | redis.lSet(key, systemInfoDto); | 
|---|
|  |  |  | // 每秒一个,最多只存30个 | 
|---|
|  |  |  | 
|---|
|  |  |  | logger.info("[redis 推流被请求通知] {}: {}-{}", key, msg.getApp(), msg.getStream()); | 
|---|
|  |  |  | redis.convertAndSend(key, (JSONObject)JSON.toJSON(msg)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void sendAlarmMsg(AlarmChannelMessage msg) { | 
|---|
|  |  |  | String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_ALARM; | 
|---|
|  |  |  | logger.info("[redis 报警通知] {}: {}", key, JSON.toJSON(msg)); | 
|---|
|  |  |  | redis.convertAndSend(key, (JSONObject)JSON.toJSON(msg)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean deviceIsOnline(String deviceId) { | 
|---|
|  |  |  | return getDevice(deviceId).getOnline() == 1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|