From 189e56c839eba1b29323f83d98dfde80670b8a89 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Mon, 21 Oct 2024 17:42:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=83=A8=E5=88=86redis=20sca?= =?UTF-8?q?n=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/common/VideoManagerConstants.java | 34 ++----------- .../service/impl/InviteStreamServiceImpl.java | 16 ++----- .../impl/SendRtpServerServiceImpl.java | 48 ++++++++++--------- .../iot/vmp/storager/IRedisCatchStorage.java | 1 + .../com/genersoft/iot/vmp/utils/JsonUtil.java | 8 ++++ 5 files changed, 43 insertions(+), 64 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java b/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java index 8b5028cc..86b50c37 100644 --- a/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java +++ b/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java @@ -18,18 +18,7 @@ public class VideoManagerConstants { public static final String DEVICE_PREFIX = "VMP_DEVICE_"; - // 设备同步完成 - public static final String DEVICE_SYNC_PREFIX = "VMP_DEVICE_SYNC_"; - - public static final String CACHEKEY_PREFIX = "VMP_CHANNEL_"; - - public static final String KEEPLIVEKEY_PREFIX = "VMP_KEEPALIVE_"; - - // TODO 此处多了一个_,暂不修改 public static final String INVITE_PREFIX = "VMP_INVITE_INFO"; - public static final String PLAYER_PREFIX = "VMP_INVITE_PLAY_"; - public static final String PLAY_BLACK_PREFIX = "VMP_INVITE_PLAYBACK_"; - public static final String DOWNLOAD_PREFIX = "VMP_INVITE_DOWNLOAD_"; public static final String PLATFORM_KEEPALIVE_PREFIX = "VMP_PLATFORM_KEEPALIVE_"; @@ -40,30 +29,18 @@ public class VideoManagerConstants { public static final String PLATFORM_REGISTER_INFO_PREFIX = "VMP_PLATFORM_REGISTER_INFO_"; public static final String SEND_RTP_INFO = "VMP_SEND_RTP_INFO:"; - public static final String SEND_RTP_INFO_CALLID = "VMP_SEND_RTP_INFO:CALL_ID"; - public static final String SEND_RTP_INFO_STREAM = "VMP_SEND_RTP_INFO:STREAM"; - public static final String SEND_RTP_INFO_CHANNEL = "VMP_SEND_RTP_INFO:CHANNEL"; - - public static final String EVENT_ONLINE_REGISTER = "1"; - - public static final String EVENT_ONLINE_MESSAGE = "3"; - - public static final String EVENT_OUTLINE_UNREGISTER = "1"; - - public static final String EVENT_OUTLINE_TIMEOUT = "2"; - - public static final String MEDIA_SSRC_USED_PREFIX = "VMP_MEDIA_USED_SSRC_"; + public static final String SEND_RTP_INFO_CALLID = "VMP_SEND_RTP_INFO:CALL_ID:"; + public static final String SEND_RTP_INFO_STREAM = "VMP_SEND_RTP_INFO:STREAM:"; + public static final String SEND_RTP_INFO_CHANNEL = "VMP_SEND_RTP_INFO:CHANNEL:"; public static final String SIP_INVITE_SESSION = "VMP_SIP_INVITE_SESSION:"; - public static final String SIP_INVITE_SESSION_CALL_ID = SIP_INVITE_SESSION + "CALL_ID" + ":"; - public static final String SIP_INVITE_SESSION_STREAM = SIP_INVITE_SESSION + "STREAM" + ":"; + public static final String SIP_INVITE_SESSION_CALL_ID = SIP_INVITE_SESSION + "CALL_ID:"; + public static final String SIP_INVITE_SESSION_STREAM = SIP_INVITE_SESSION + "STREAM:"; public static final String MEDIA_STREAM_AUTHORITY = "VMP_MEDIA_STREAM_AUTHORITY_"; public static final String SIP_CSEQ_PREFIX = "VMP_SIP_CSEQ_"; - public static final String SIP_SN_PREFIX = "VMP_SIP_SN_"; - public static final String SIP_SUBSCRIBE_PREFIX = "VMP_SIP_SUBSCRIBE_"; public static final String SYSTEM_INFO_CPU_PREFIX = "VMP_SYSTEM_INFO_CPU_"; @@ -79,7 +56,6 @@ public class VideoManagerConstants { public static final String PUSH_STREAM_LIST = "VMP_PUSH_STREAM_LIST_"; public static final String WAITE_SEND_PUSH_STREAM = "VMP_WAITE_SEND_PUSH_STREAM:"; public static final String START_SEND_PUSH_STREAM = "VMP_START_SEND_PUSH_STREAM:"; - public static final String PUSH_STREAM_ONLINE = "VMP_PUSH_STREAM_ONLINE:"; diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/InviteStreamServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/InviteStreamServiceImpl.java index 3ca08706..c74a630c 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/InviteStreamServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/InviteStreamServiceImpl.java @@ -79,10 +79,8 @@ public class InviteStreamServiceImpl implements IInviteStreamService { InviteInfo inviteInfoForUpdate; if (InviteSessionStatus.ready == inviteInfo.getStatus()) { - if (inviteInfo.getDeviceId() == null - || inviteInfo.getChannelId() == null - || inviteInfo.getType() == null - || inviteInfo.getStream() == null + if (inviteInfo.getDeviceId() == null || inviteInfo.getChannelId() == null + || inviteInfo.getType() == null || inviteInfo.getStream() == null ) { return; } @@ -118,7 +116,6 @@ public class InviteStreamServiceImpl implements IInviteStreamService { } String key = VideoManagerConstants.INVITE_PREFIX + ":" + inviteInfoForUpdate.getType() + - ":" + inviteInfoForUpdate.getDeviceId() + ":" + inviteInfoForUpdate.getChannelId() + ":" + inviteInfoForUpdate.getStream()+ ":" + inviteInfoForUpdate.getSsrcInfo().getSsrc(); @@ -139,7 +136,6 @@ public class InviteStreamServiceImpl implements IInviteStreamService { removeInviteInfo(inviteInfoInDb); String key = VideoManagerConstants.INVITE_PREFIX + ":" + inviteInfo.getType() + - ":" + inviteInfo.getDeviceId() + ":" + inviteInfo.getChannelId() + ":" + stream + ":" + inviteInfo.getSsrcInfo().getSsrc(); @@ -160,7 +156,6 @@ public class InviteStreamServiceImpl implements IInviteStreamService { public InviteInfo getInviteInfo(InviteSessionType type, Integer channelId, String stream) { String key = VideoManagerConstants.INVITE_PREFIX + ":" + (type != null ? type : "*") + - ":*" + ":" + (channelId != null ? channelId : "*") + ":" + (stream != null ? stream : "*") + ":*"; @@ -179,7 +174,6 @@ public class InviteStreamServiceImpl implements IInviteStreamService { public List getAllInviteInfo(InviteSessionType type, Integer channelId, String stream) { String key = VideoManagerConstants.INVITE_PREFIX + ":" + (type != null ? type : "*") + - ":*" + ":" + (channelId != null ? channelId : "*") + ":" + (stream != null ? stream : "*") + ":*"; @@ -208,7 +202,6 @@ public class InviteStreamServiceImpl implements IInviteStreamService { public void removeInviteInfo(InviteSessionType type, Integer channelId, String stream) { String scanKey = VideoManagerConstants.INVITE_PREFIX + ":" + (type != null ? type : "*") + - ":*" + ":" + (channelId != null ? channelId : "*") + ":" + (stream != null ? stream : "*") + ":*"; @@ -267,7 +260,7 @@ public class InviteStreamServiceImpl implements IInviteStreamService { @Override public int getStreamInfoCount(String mediaServerId) { int count = 0; - String key = VideoManagerConstants.INVITE_PREFIX + ":*:*:*:*:*"; + String key = VideoManagerConstants.INVITE_PREFIX + ":*:*:*:*"; List scanResult = RedisUtil.scan(redisTemplate, key); if (scanResult.isEmpty()) { return 0; @@ -316,7 +309,7 @@ public class InviteStreamServiceImpl implements IInviteStreamService { @Override public InviteInfo getInviteInfoBySSRC(String ssrc) { - String key = VideoManagerConstants.INVITE_PREFIX + ":*:*:*:*:" + ssrc; + String key = VideoManagerConstants.INVITE_PREFIX + ":*:*:*:" + ssrc; List scanResult = RedisUtil.scan(redisTemplate, key); if (scanResult.size() != 1) { return null; @@ -334,7 +327,6 @@ public class InviteStreamServiceImpl implements IInviteStreamService { removeInviteInfo(inviteInfoInDb); String key = VideoManagerConstants.INVITE_PREFIX + ":" + inviteInfo.getType() + - ":" + inviteInfo.getDeviceId() + ":" + inviteInfo.getChannelId() + ":" + inviteInfo.getStream() + ":" + ssrc; diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/SendRtpServerServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/SendRtpServerServiceImpl.java index c4cf7a0b..03713ec7 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/SendRtpServerServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/SendRtpServerServiceImpl.java @@ -65,14 +65,14 @@ public class SendRtpServerServiceImpl implements ISendRtpServerService { @Override public void update(SendRtpInfo sendRtpItem) { redisTemplate.opsForValue().set(VideoManagerConstants.SEND_RTP_INFO_CALLID + sendRtpItem.getCallId(), sendRtpItem); - redisTemplate.opsForValue().set(VideoManagerConstants.SEND_RTP_INFO_STREAM + sendRtpItem.getStream() + ":" + sendRtpItem.getTargetId(), sendRtpItem); - redisTemplate.opsForValue().set(VideoManagerConstants.SEND_RTP_INFO_CHANNEL + sendRtpItem.getChannelId() + ":" + sendRtpItem.getTargetId(), sendRtpItem); + redisTemplate.opsForHash().put(VideoManagerConstants.SEND_RTP_INFO_STREAM + sendRtpItem.getStream(), sendRtpItem.getTargetId(), sendRtpItem); + redisTemplate.opsForHash().put(VideoManagerConstants.SEND_RTP_INFO_CHANNEL + sendRtpItem.getChannelId(), sendRtpItem.getTargetId(), sendRtpItem); } @Override public SendRtpInfo queryByChannelId(Integer channelId, String targetId) { - String key = VideoManagerConstants.SEND_RTP_INFO_CHANNEL + channelId + ":" + targetId; - return JsonUtil.redisJsonToObject(redisTemplate, key, SendRtpInfo.class); + String key = VideoManagerConstants.SEND_RTP_INFO_CHANNEL + channelId; + return JsonUtil.redisHashJsonToObject(redisTemplate, key, targetId, SendRtpInfo.class); } @Override @@ -83,19 +83,17 @@ public class SendRtpServerServiceImpl implements ISendRtpServerService { @Override public SendRtpInfo queryByStream(String stream, String targetId) { - String key = VideoManagerConstants.SEND_RTP_INFO_STREAM + stream + ":" + targetId; - return JsonUtil.redisJsonToObject(redisTemplate, key, SendRtpInfo.class); + String key = VideoManagerConstants.SEND_RTP_INFO_STREAM + stream; + return JsonUtil.redisHashJsonToObject(redisTemplate, key, targetId, SendRtpInfo.class); } @Override public List queryByStream(String stream) { - String key = VideoManagerConstants.SEND_RTP_INFO_STREAM + stream + ":*"; - List queryResult = RedisUtil.scan(redisTemplate, key); + String key = VideoManagerConstants.SEND_RTP_INFO_STREAM + stream; + List values = redisTemplate.opsForHash().values(key); List result= new ArrayList<>(); - - for (Object o : queryResult) { - String keyItem = (String) o; - result.add((SendRtpInfo) redisTemplate.opsForValue().get(keyItem)); + for (Object o : values) { + result.add((SendRtpInfo) o); } return result; @@ -110,8 +108,16 @@ public class SendRtpServerServiceImpl implements ISendRtpServerService { return; } redisTemplate.delete(VideoManagerConstants.SEND_RTP_INFO_CALLID + sendRtpInfo.getCallId()); - redisTemplate.delete(VideoManagerConstants.SEND_RTP_INFO_STREAM + sendRtpInfo.getStream() + ":" + sendRtpInfo.getTargetId()); - redisTemplate.delete(VideoManagerConstants.SEND_RTP_INFO_CHANNEL + sendRtpInfo.getChannelId() + ":" + sendRtpInfo.getTargetId()); + if (redisTemplate.opsForHash().size(VideoManagerConstants.SEND_RTP_INFO_STREAM + sendRtpInfo.getStream()) == 0) { + redisTemplate.delete(VideoManagerConstants.SEND_RTP_INFO_STREAM + sendRtpInfo.getStream()); + }else { + redisTemplate.opsForHash().delete(VideoManagerConstants.SEND_RTP_INFO_STREAM + sendRtpInfo.getStream(), sendRtpInfo.getTargetId()); + } + if (redisTemplate.opsForHash().size(VideoManagerConstants.SEND_RTP_INFO_CHANNEL + sendRtpInfo.getChannelId()) == 0) { + redisTemplate.delete(VideoManagerConstants.SEND_RTP_INFO_CHANNEL + sendRtpInfo.getChannelId()); + }else { + redisTemplate.opsForHash().delete(VideoManagerConstants.SEND_RTP_INFO_CHANNEL + sendRtpInfo.getChannelId(), sendRtpInfo.getTargetId()); + } } @Override public void deleteByCallId(String callId) { @@ -149,22 +155,18 @@ public class SendRtpServerServiceImpl implements ISendRtpServerService { @Override public List queryByChannelId(int channelId) { - String key = VideoManagerConstants.SEND_RTP_INFO_CHANNEL + channelId + ":*"; - List queryResult = RedisUtil.scan(redisTemplate, key); + String key = VideoManagerConstants.SEND_RTP_INFO_CHANNEL + channelId; + List values = redisTemplate.opsForHash().values(key); List result= new ArrayList<>(); - - for (Object o : queryResult) { - String keyItem = (String) o; - result.add((SendRtpInfo) redisTemplate.opsForValue().get(keyItem)); + for (Object o : values) { + result.add((SendRtpInfo) o); } - return result; } @Override public List queryAll() { - String key = VideoManagerConstants.SEND_RTP_INFO_CALLID - + userSetting.getServerId() + ":*"; + String key = VideoManagerConstants.SEND_RTP_INFO_CALLID + ":*"; List queryResult = RedisUtil.scan(redisTemplate, key); List result= new ArrayList<>(); diff --git a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java index e1d6b6f7..11123cc4 100755 --- a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java @@ -98,6 +98,7 @@ public interface IRedisCatchStorage { void updateGpsMsgInfo(GPSMsgInfo gpsMsgInfo); GPSMsgInfo getGpsMsgInfo(String gbId); + List getAllGpsMsgInfo(); MediaInfo getStreamInfo(String app, String streamId, String mediaServerId); diff --git a/src/main/java/com/genersoft/iot/vmp/utils/JsonUtil.java b/src/main/java/com/genersoft/iot/vmp/utils/JsonUtil.java index de8675f1..46c71b4b 100755 --- a/src/main/java/com/genersoft/iot/vmp/utils/JsonUtil.java +++ b/src/main/java/com/genersoft/iot/vmp/utils/JsonUtil.java @@ -31,4 +31,12 @@ public final class JsonUtil { } return clazz.cast(jsonObject); } + + public static T redisHashJsonToObject(RedisTemplate redisTemplate, String key, String objKey, Class clazz) { + Object jsonObject = redisTemplate.opsForHash().get(key, objKey); + if (Objects.isNull(jsonObject)) { + return null; + } + return clazz.cast(jsonObject); + } } \ No newline at end of file