From bac9aca311dba1b8796c6166d6618462fc7aa3a5 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期四, 20 七月 2023 17:56:04 +0800 Subject: [PATCH] 合并分支新内容 --- src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java | 73 ++++++++++++++++++++++++++++++------ 1 files changed, 60 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java index 19e82d4..f412816 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java @@ -85,6 +85,24 @@ } @Override + public InviteInfo updateInviteInfoForStream(InviteInfo inviteInfo, String stream) { + + InviteInfo inviteInfoInDb = getInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId(), inviteInfo.getChannelId(), inviteInfo.getStream()); + if (inviteInfoInDb == null) { + return null; + } + removeInviteInfo(inviteInfoInDb); + String key = VideoManagerConstants.INVITE_PREFIX + + "_" + inviteInfo.getType() + + "_" + inviteInfo.getDeviceId() + + "_" + inviteInfo.getChannelId() + + "_" + stream; + inviteInfoInDb.setStream(stream); + redisTemplate.opsForValue().set(key, inviteInfoInDb); + return inviteInfoInDb; + } + + @Override public InviteInfo getInviteInfo(InviteSessionType type, String deviceId, String channelId, String stream) { String key = VideoManagerConstants.INVITE_PREFIX + "_" + (type != null ? type : "*") + @@ -152,19 +170,6 @@ } - @Override - public void call(InviteSessionType type, String deviceId, String channelId, String stream, int code, String msg, Object data) { - String key = buildKey(type, deviceId, channelId, stream); - List<ErrorCallback<Object>> callbacks = inviteErrorCallbackMap.get(key); - if (callbacks == null) { - return; - } - for (ErrorCallback<Object> callback : callbacks) { - callback.run(code, msg, data); - } - inviteErrorCallbackMap.remove(key); - } - private String buildKey(InviteSessionType type, String deviceId, String channelId, String stream) { String key = type + "_" + deviceId + "_" + channelId; // 濡傛灉ssrc鏈猲ull閭d箞鍙互瀹炵幇涓�涓�氶亾鍙兘涓�娆℃搷浣滐紝ssrc涓嶄负null鍒欏彲浠ユ敮鎸佷竴涓�氶亾澶氭invite @@ -179,4 +184,46 @@ public void clearInviteInfo(String deviceId) { removeInviteInfo(null, deviceId, null, null); } + + @Override + public int getStreamInfoCount(String mediaServerId) { + int count = 0; + String key = VideoManagerConstants.INVITE_PREFIX + "_*_*_*_*"; + List<Object> scanResult = RedisUtil.scan(redisTemplate, key); + if (scanResult.size() == 0) { + return 0; + }else { + for (Object keyObj : scanResult) { + String keyStr = (String) keyObj; + InviteInfo inviteInfo = (InviteInfo) redisTemplate.opsForValue().get(keyStr); + if (inviteInfo != null && inviteInfo.getStreamInfo() != null && inviteInfo.getStreamInfo().getMediaServerId().equals(mediaServerId)) { + count++; + } + } + } + return count; + } + + @Override + public void call(InviteSessionType type, String deviceId, String channelId, String stream, int code, String msg, Object data) { + String key = buildSubStreamKey(type, deviceId, channelId, stream); + List<ErrorCallback<Object>> callbacks = inviteErrorCallbackMap.get(key); + if (callbacks == null) { + return; + } + for (ErrorCallback<Object> callback : callbacks) { + callback.run(code, msg, data); + } + inviteErrorCallbackMap.remove(key); + } + + + private String buildSubStreamKey(InviteSessionType type, String deviceId, String channelId, String stream) { + String key = type + "_" + "_" + deviceId + "_" + channelId; + // 濡傛灉ssrc涓簄ull閭d箞鍙互瀹炵幇涓�涓�氶亾鍙兘涓�娆℃搷浣滐紝ssrc涓嶄负null鍒欏彲浠ユ敮鎸佷竴涓�氶亾澶氭invite + if (stream != null) { + key += ("_" + stream); + } + return key; + } } -- Gitblit v1.8.0