From 28f4f688dd37cbce7f7e2ff4a939d0701f2a8bbe Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期一, 19 十二月 2022 15:39:37 +0800
Subject: [PATCH] 优化语音遇到错误时主动终止对讲流程

---
 src/main/java/com/genersoft/iot/vmp/gb28181/session/AudioBroadcastManager.java |   31 ++++++++++++++++++++++---------
 1 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/session/AudioBroadcastManager.java b/src/main/java/com/genersoft/iot/vmp/gb28181/session/AudioBroadcastManager.java
index d3ddf52..072d0cb 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/session/AudioBroadcastManager.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/session/AudioBroadcastManager.java
@@ -2,6 +2,7 @@
 
 import com.genersoft.iot.vmp.conf.SipConfig;
 import com.genersoft.iot.vmp.gb28181.bean.AudioBroadcastCatch;
+import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -22,16 +23,21 @@
 
     public static Map<String, AudioBroadcastCatch> data = new ConcurrentHashMap<>();
 
-    public void add(AudioBroadcastCatch audioBroadcastCatch) {
-        this.update(audioBroadcastCatch);
-    }
-
     public void update(AudioBroadcastCatch audioBroadcastCatch) {
-        data.put(audioBroadcastCatch.getDeviceId() + audioBroadcastCatch.getChannelId(), audioBroadcastCatch);
+        if (SipUtils.isFrontEnd(audioBroadcastCatch.getDeviceId())) {
+            data.put(audioBroadcastCatch.getDeviceId(), audioBroadcastCatch);
+        }else {
+            data.put(audioBroadcastCatch.getDeviceId() + audioBroadcastCatch.getChannelId(), audioBroadcastCatch);
+        }
     }
 
     public void del(String deviceId, String channelId) {
-        data.remove(deviceId + channelId);
+        if (SipUtils.isFrontEnd(deviceId)) {
+            data.remove(deviceId);
+        }else {
+            data.remove(deviceId + channelId);
+        }
+
     }
 
     public void delByDeviceId(String deviceId) {
@@ -50,15 +56,22 @@
 
     public boolean exit(String deviceId, String channelId) {
         for (String key : data.keySet()) {
-            if (key.equals(deviceId + channelId)) {
-                return true;
+            if (SipUtils.isFrontEnd(deviceId)) {
+                return key.equals(deviceId);
+            }else {
+                return key.equals(deviceId + channelId);
             }
         }
         return false;
     }
 
     public AudioBroadcastCatch get(String deviceId, String channelId) {
-        AudioBroadcastCatch audioBroadcastCatch = data.get(deviceId + channelId);
+        AudioBroadcastCatch audioBroadcastCatch;
+        if (SipUtils.isFrontEnd(deviceId)) {
+            audioBroadcastCatch = data.get(deviceId);
+        }else {
+            audioBroadcastCatch = data.get(deviceId + channelId);
+        }
         if (audioBroadcastCatch == null) {
             Stream<AudioBroadcastCatch> allAudioBroadcastCatchStreamForDevice = data.values().stream().filter(
                     audioBroadcastCatchItem -> Objects.equals(audioBroadcastCatchItem.getDeviceId(), deviceId));

--
Gitblit v1.8.0