From 1553b39b4547418774ab2bd6da72f75bfd14b972 Mon Sep 17 00:00:00 2001 From: 648540858 <456panlinlin> Date: 星期二, 29 三月 2022 10:04:28 +0800 Subject: [PATCH] 修复级联的国标通道无经纬度问题 --- src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java | 262 +++++++++++++++++++++++++++++++++++----------------- 1 files changed, 177 insertions(+), 85 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java index 56789d9..4840446 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java @@ -2,6 +2,7 @@ import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.common.StreamInfo; +import com.genersoft.iot.vmp.common.SystemInfoDto; import com.genersoft.iot.vmp.common.VideoManagerConstants; import com.genersoft.iot.vmp.conf.UserSetup; import com.genersoft.iot.vmp.gb28181.bean.*; @@ -9,6 +10,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; +import com.genersoft.iot.vmp.service.bean.SSRCInfo; import com.genersoft.iot.vmp.service.bean.ThirdPartyGB; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; @@ -16,6 +18,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.parameters.P; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; @@ -90,7 +93,8 @@ */ @Override public boolean startPlay(StreamInfo stream) { - return redis.set(String.format("%S_%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, userSetup.getServerId(), stream.getStreamId(),stream.getDeviceID(), stream.getChannelId()), + return redis.set(String.format("%S_%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, userSetup.getServerId(), + stream.getStream(), stream.getDeviceID(), stream.getChannelId()), stream); } @@ -104,7 +108,7 @@ if (streamInfo == null) return false; return redis.del(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, userSetup.getServerId(), - streamInfo.getStreamId(), + streamInfo.getStream(), streamInfo.getDeviceID(), streamInfo.getChannelId())); } @@ -118,7 +122,7 @@ return (StreamInfo)redis.get(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, userSetup.getServerId(), - streamInfo.getStreamId(), + streamInfo.getStream(), streamInfo.getDeviceID(), streamInfo.getChannelId())); } @@ -130,15 +134,7 @@ } @Override - public StreamInfo queryPlaybackByStreamId(String streamId) { - List<Object> playLeys = redis.scan(String.format("%S_%s_%s_*", VideoManagerConstants.PLAY_BLACK_PREFIX, userSetup.getServerId(), streamId)); - if (playLeys == null || playLeys.size() == 0) return null; - return (StreamInfo)redis.get(playLeys.get(0).toString()); - } - - @Override public StreamInfo queryPlayByDevice(String deviceId, String channelId) { -// List<Object> playLeys = redis.keys(String.format("%S_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX, List<Object> playLeys = redis.scan(String.format("%S_%s_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX, userSetup.getServerId(), deviceId, @@ -163,49 +159,101 @@ @Override - public boolean startPlayback(StreamInfo stream) { - return redis.set(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, userSetup.getServerId(),stream.getStreamId(), - stream.getDeviceID(), stream.getChannelId()), stream); + public boolean startPlayback(StreamInfo stream, String callId) { + return redis.set(String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, + userSetup.getServerId(), stream.getDeviceID(), stream.getChannelId(), stream.getStream(), callId), stream); } @Override - public boolean startDownload(StreamInfo streamInfo) { - return redis.set(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX, userSetup.getServerId(),streamInfo.getStreamId(), - streamInfo.getDeviceID(), streamInfo.getChannelId()), streamInfo); + public boolean startDownload(StreamInfo stream, String callId) { + boolean result; + if (stream.getProgress() == 1) { + result = redis.set(String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX, + userSetup.getServerId(), stream.getDeviceID(), stream.getChannelId(), stream.getStream(), callId), stream); + }else { + result = redis.set(String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX, + userSetup.getServerId(), stream.getDeviceID(), stream.getChannelId(), stream.getStream(), callId), stream, 60*60); + } + return result; } - @Override - public boolean stopPlayback(StreamInfo streamInfo) { - if (streamInfo == null) return false; - DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(streamInfo.getDeviceID(), streamInfo.getChannelId()); + public boolean stopDownload(String deviceId, String channelId, String stream, String callId) { + DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(deviceId, channelId); if (deviceChannel != null) { deviceChannel.setStreamId(null); - deviceChannel.setDeviceId(streamInfo.getDeviceID()); + deviceChannel.setDeviceId(deviceId); deviceChannelMapper.update(deviceChannel); } - return redis.del(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, + 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, userSetup.getServerId(), - streamInfo.getStreamId(), - streamInfo.getDeviceID(), - streamInfo.getChannelId())); + deviceId, + channelId, + stream, + callId + ); + List<Object> scan = redis.scan(key); + if (scan.size() > 0) { + for (Object keyObj : scan) { + redis.del((String) keyObj); + } + } + return true; } @Override - public StreamInfo queryPlaybackByDevice(String deviceId, String code) { - // String format = String.format("%S_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, - // deviceId, - // code); - List<Object> playLeys = redis.scan(String.format("%S_%s_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, + public boolean stopPlayback(String deviceId, String channelId, String stream, String callId) { + DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(deviceId, channelId); + if (deviceChannel != null) { + deviceChannel.setStreamId(null); + deviceChannel.setDeviceId(deviceId); + deviceChannelMapper.update(deviceChannel); + } + 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, userSetup.getServerId(), deviceId, - code)); - if (playLeys == null || playLeys.size() == 0) { - playLeys = redis.scan(String.format("%S_%s_*_*_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, - userSetup.getServerId(), - deviceId)); + channelId, + stream, + callId + ); + List<Object> scan = redis.scan(key); + if (scan.size() > 0) { + for (Object keyObj : scan) { + redis.del((String) keyObj); + } } - if (playLeys == null || playLeys.size() == 0) return null; - return (StreamInfo)redis.get(playLeys.get(0).toString()); + return true; + } + + @Override + public StreamInfo queryPlayback(String deviceId, String channelId, String stream, String callId) { + if (stream == null && callId == null) { + return null; + } + 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, + userSetup.getServerId(), + deviceId, + channelId, + stream, + callId + ); + List<Object> streamInfoScan = redis.scan(key); + if (streamInfoScan.size() > 0) { + return (StreamInfo) redis.get((String) streamInfoScan.get(0)); + }else { + return null; + } } @Override @@ -274,19 +322,32 @@ @Override public void updateSendRTPSever(SendRtpItem sendRtpItem) { - String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + sendRtpItem.getPlatformId() + "_" + sendRtpItem.getChannelId(); + String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + + sendRtpItem.getPlatformId() + "_" + sendRtpItem.getChannelId() + "_" + + sendRtpItem.getStreamId() + "_" + sendRtpItem.getCallId(); redis.set(key, sendRtpItem); } @Override - public SendRtpItem querySendRTPServer(String platformGbId, String channelId) { - String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + platformGbId + "_" + channelId; - return (SendRtpItem)redis.get(key); + 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 = "*"; + String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + platformGbId + + "_" + channelId + "_" + streamId + "_" + callId; + List<Object> scan = redis.scan(key); + if (scan.size() > 0) { + return (SendRtpItem)redis.get((String)scan.get(0)); + }else { + return null; + } } @Override public List<SendRtpItem> querySendRTPServer(String platformGbId) { - String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + platformGbId + "_*"; + if (platformGbId == null) platformGbId = "*"; + String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + platformGbId + "_*" + "_*" + "_*"; List<Object> queryResult = redis.scan(key); List<SendRtpItem> result= new ArrayList<>(); @@ -304,10 +365,20 @@ * @param channelId */ @Override - public void deleteSendRTPServer(String platformGbId, String channelId) { - String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + platformGbId + "_" + channelId; - redis.del(key); + public void deleteSendRTPServer(String platformGbId, String channelId, String callId, String streamId) { + if (streamId == null) streamId = "*"; + if (callId == null) callId = "*"; + String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + platformGbId + + "_" + channelId + "_" + streamId + "_" + callId; + List<Object> scan = redis.scan(key); + if (scan.size() > 0) { + for (Object keyStr : scan) { + redis.del((String)keyStr); + } + } } + + /** * 鏌ヨ鏌愪釜閫氶亾鏄惁瀛樺湪涓婄骇鐐规挱锛圧TP鎺ㄩ�侊級 @@ -315,7 +386,7 @@ */ @Override public boolean isChannelSendingRTP(String channelId) { - String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + "*_" + channelId; + String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + "*_" + channelId + "*_" + "*_"; List<Object> RtpStreams = redis.scan(key); if (RtpStreams.size() > 0) { return true; @@ -335,7 +406,7 @@ } } - List<Object> playBackers = redis.scan(String.format("%S_%s_*_%s_*", VideoManagerConstants.PLAY_BLACK_PREFIX, + List<Object> playBackers = redis.scan(String.format("%S_%s_%s_*_*_*", VideoManagerConstants.PLAY_BLACK_PREFIX, userSetup.getServerId(), deviceId)); if (playBackers.size() > 0) { @@ -400,10 +471,27 @@ } @Override - public StreamInfo queryDownloadByStreamId(String streamId) { - List<Object> playLeys = redis.scan(String.format("%S_%s_%s_*", VideoManagerConstants.DOWNLOAD_PREFIX, userSetup.getServerId(), streamId)); - if (playLeys == null || playLeys.size() == 0) return null; - return (StreamInfo)redis.get(playLeys.get(0).toString()); + public StreamInfo queryDownload(String deviceId, String channelId, String stream, String callId) { + if (stream == null && callId == null) { + return null; + } + 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, + userSetup.getServerId(), + deviceId, + channelId, + stream, + callId + ); + List<Object> streamInfoScan = redis.scan(key); + if (streamInfoScan.size() > 0) { + return (StreamInfo) redis.get((String) streamInfoScan.get(0)); + }else { + return null; + } } @Override @@ -465,21 +553,6 @@ } @Override - public void updateSubscribe(String key, SubscribeInfo subscribeInfo) { - redis.set(key, subscribeInfo, subscribeInfo.getExpires()); - } - - @Override - public SubscribeInfo getSubscribe(String key) { - return (SubscribeInfo)redis.get(key); - } - - @Override - public void delSubscribe(String key) { - redis.del(key); - } - - @Override public List<GPSMsgInfo> getAllGpsMsgInfo() { String scanKey = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetup.getServerId() + "_*"; List<GPSMsgInfo> result = new ArrayList<>(); @@ -510,28 +583,47 @@ } @Override - public List<SubscribeInfo> getAllSubscribe() { - String scanKey = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + userSetup.getServerId() + "_Catalog_*"; - List<SubscribeInfo> result = new ArrayList<>(); - List<Object> keys = redis.scan(scanKey); - for (int i = 0; i < keys.size(); i++) { - String key = (String) keys.get(i); - SubscribeInfo subscribeInfo = (SubscribeInfo) redis.get(key); - result.add(subscribeInfo); + public void addCpuInfo(double cpuInfo) { + String key = VideoManagerConstants.SYSTEM_INFO_CPU_PREFIX + userSetup.getServerId(); + SystemInfoDto<Double> systemInfoDto = new SystemInfoDto<>(); + systemInfoDto.setTime(format.format(System.currentTimeMillis())); + systemInfoDto.setData(cpuInfo); + redis.lSet(key, systemInfoDto); + // 姣忕涓�涓紝鏈�澶氬彧瀛�30涓� + if (redis.lGetListSize(key) > 30) { + for (int i = 0; i < redis.lGetListSize(key) - 30; i++) { + redis.lLeftPop(key); + } } - return result; } @Override - public List<String> getAllSubscribePlatform() { - String scanKey = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + userSetup.getServerId() + "_Catalog_*"; - List<String> result = new ArrayList<>(); - List<Object> keys = redis.scan(scanKey); - for (int i = 0; i < keys.size(); i++) { - String key = (String) keys.get(i); - String platformId = key.substring(scanKey.length() - 1); - result.add(platformId); + public void addMemInfo(double memInfo) { + String key = VideoManagerConstants.SYSTEM_INFO_MEM_PREFIX + userSetup.getServerId(); + SystemInfoDto<Double> systemInfoDto = new SystemInfoDto<>(); + systemInfoDto.setTime(format.format(System.currentTimeMillis())); + systemInfoDto.setData(memInfo); + redis.lSet(key, systemInfoDto); + // 姣忕涓�涓紝鏈�澶氬彧瀛�30涓� + if (redis.lGetListSize(key) > 30) { + for (int i = 0; i < redis.lGetListSize(key) - 30; i++) { + redis.lLeftPop(key); + } } - return result; + } + + @Override + public void addNetInfo(Map<String, String> networkInterfaces) { + String key = VideoManagerConstants.SYSTEM_INFO_NET_PREFIX + userSetup.getServerId(); + SystemInfoDto<Map<String, String>> systemInfoDto = new SystemInfoDto<>(); + systemInfoDto.setTime(format.format(System.currentTimeMillis())); + systemInfoDto.setData(networkInterfaces); + redis.lSet(key, systemInfoDto); + // 姣忕涓�涓紝鏈�澶氬彧瀛�30涓� + if (redis.lGetListSize(key) > 30) { + for (int i = 0; i < redis.lGetListSize(key) - 30; i++) { + redis.lLeftPop(key); + } + } } } -- Gitblit v1.8.0