From c551164c89f70e664b498c3a09e615928261e01a Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期六, 01 七月 2023 18:33:42 +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