From 988dc36fa56a47cc4f331ab48c07577805a71425 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期五, 04 八月 2023 15:47:56 +0800
Subject: [PATCH] 重构点播,回放,下载时ssrc不一致以及TCP主动播放的逻辑

---
 src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java |   57 ++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 44 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 2fb6816..6e46082 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,27 @@
     }
 
     @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);
+        if (inviteInfoInDb.getSsrcInfo() != null) {
+            inviteInfoInDb.getSsrcInfo().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 +173,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
@@ -198,4 +206,27 @@
         }
         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