From 490c55381f75e4c43c050de593eb1a418d9a83ed Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期六, 06 五月 2023 17:59:12 +0800 Subject: [PATCH] 修复国标视频点播三种点播方式(自动点播,上级点播,接口点播)并发情况下失败的问题 --- src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java | 117 ++++++++++++++++------------------------------------------ 1 files changed, 32 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 67f2e7e..dabe9f8 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 @@ -24,8 +24,10 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; +import java.time.Duration; import java.util.*; @SuppressWarnings("rawtypes") @@ -42,6 +44,9 @@ @Autowired private RedisTemplate<Object, Object> redisTemplate; + + @Autowired + private StringRedisTemplate stringRedisTemplate; @Override public Long getCSEQ() { @@ -87,87 +92,6 @@ } } - /** - * 寮�濮嬫挱鏀炬椂灏嗘祦瀛樺叆redis - */ - @Override - public boolean startPlay(StreamInfo stream) { - - redisTemplate.opsForValue().set(String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(), - stream.getMediaServerId(), stream.getStream(), stream.getDeviceID(), stream.getChannelId()), - stream); - return true; - } - - /** - * 鍋滄鎾斁鏃朵粠redis鍒犻櫎 - */ - @Override - public boolean stopPlay(StreamInfo streamInfo) { - if (streamInfo == null) { - return false; - } - Boolean result = redisTemplate.delete(String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, - userSetting.getServerId(), - streamInfo.getMediaServerId(), - streamInfo.getStream(), - streamInfo.getDeviceID(), - streamInfo.getChannelId())); - return result != null && result; - } - - /** - * 鏌ヨ鎾斁鍒楄〃 - */ - @Override - public StreamInfo queryPlay(StreamInfo streamInfo) { - return (StreamInfo)redisTemplate.opsForValue().get(String.format("%S_%s_%s_%s_%s_%s", - VideoManagerConstants.PLAYER_PREFIX, - userSetting.getServerId(), - streamInfo.getMediaServerId(), - streamInfo.getStream(), - streamInfo.getDeviceID(), - streamInfo.getChannelId())); - } - @Override - public StreamInfo queryPlayByStreamId(String streamId) { - List<Object> playLeys = RedisUtil.scan(redisTemplate, String.format("%S_%s_*_%s_*", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(), streamId)); - if (playLeys.size() == 0) { - return null; - } - return (StreamInfo)redisTemplate.opsForValue().get(playLeys.get(0).toString()); - } - - @Override - public StreamInfo queryPlayByDevice(String deviceId, String channelId) { - List<Object> playLeys = RedisUtil.scan(redisTemplate, String.format("%S_%s_*_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX, - userSetting.getServerId(), - deviceId, - channelId)); - if (playLeys.size() == 0) { - return null; - } - return (StreamInfo)redisTemplate.opsForValue().get(playLeys.get(0).toString()); - } - - @Override - public Map<String, StreamInfo> queryPlayByDeviceId(String deviceId) { - Map<String, StreamInfo> streamInfos = new HashMap<>(); - List<Object> players = RedisUtil.scan(redisTemplate, String.format("%S_%s_*_*_%s_*", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(),deviceId)); - if (players.size() == 0) { - return streamInfos; - } - for (Object player : players) { - String key = (String) player; - StreamInfo streamInfo = JsonUtil.redisJsonToObject(redisTemplate, key, StreamInfo.class); - if (Objects.isNull(streamInfo)) { - continue; - } - streamInfos.put(streamInfo.getDeviceID() + "_" + streamInfo.getChannelId(), streamInfo); - } - return streamInfos; - } - @Override public boolean startPlayback(StreamInfo stream, String callId) { @@ -185,7 +109,8 @@ redisTemplate.opsForValue().set(key, stream); }else { logger.debug("娣诲姞涓嬭浇缂撳瓨==鏈畬鎴愪笅杞�=銆媨}",key); - redisTemplate.opsForValue().set(key, stream, 60*60); + Duration duration = Duration.ofSeconds(60*60L); + redisTemplate.opsForValue().set(key, stream, duration); } return true; } @@ -351,7 +276,8 @@ @Override public void updatePlatformRegisterInfo(String callId, PlatformRegisterInfo platformRegisterInfo) { String key = VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetting.getServerId() + "_" + callId; - redisTemplate.opsForValue().set(key, platformRegisterInfo, 30); + Duration duration = Duration.ofSeconds(30L); + redisTemplate.opsForValue().set(key, platformRegisterInfo, duration); } @@ -562,7 +488,8 @@ @Override public void updateWVPInfo(JSONObject jsonObject, int time) { String key = VideoManagerConstants.WVP_SERVER_PREFIX + userSetting.getServerId(); - redisTemplate.opsForValue().set(key, jsonObject, time); + Duration duration = Duration.ofSeconds(time); + redisTemplate.opsForValue().set(key, jsonObject, duration); } @Override @@ -694,7 +621,8 @@ @Override public void updateGpsMsgInfo(GPSMsgInfo gpsMsgInfo) { String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId() + "_" + gpsMsgInfo.getId(); - redisTemplate.opsForValue().set(key, gpsMsgInfo, 60); // 榛樿GPS娑堟伅淇濆瓨1鍒嗛挓 + Duration duration = Duration.ofSeconds(60L); + redisTemplate.opsForValue().set(key, gpsMsgInfo, duration); // 榛樿GPS娑堟伅淇濆瓨1鍒嗛挓 } @Override @@ -902,4 +830,23 @@ + userSetting.getServerId() + "_*_" + id + "_*"; return RedisUtil.scan(redisTemplate, key).size(); } + + @Override + public void sendDeviceOrChannelStatus(String deviceId, String channelId, boolean online) { + String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_DEVICE_STATUS; + if (channelId == null) { + logger.info("[redis閫氱煡] 鎺ㄩ�佽澶囩姸鎬侊紝 {}-{}", deviceId, online); + }else { + logger.info("[redis閫氱煡] 鎺ㄩ�侀�氶亾鐘舵�侊紝 {}/{}-{}", deviceId, channelId, online); + } + + StringBuilder msg = new StringBuilder(); + msg.append(deviceId); + if (channelId != null) { + msg.append(":").append(channelId); + } + msg.append(" ").append(online? "ON":"OFF"); + // 浣跨敤 RedisTemplate<Object, Object> 鍙戦�佸瓧绗︿覆娑堟伅浼氬鑷村彂閫佺殑娑堟伅澶氬甫浜嗗弻寮曞彿 + stringRedisTemplate.convertAndSend(key, msg.toString()); + } } -- Gitblit v1.8.0