From 0447b83c3a5e48741adcd85ce9552ff202831784 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期五, 29 三月 2024 23:41:00 +0800
Subject: [PATCH] 临时提交

---
 src/main/java/com/genersoft/iot/vmp/gb28181/session/AudioBroadcastManager.java |   87 +++++++++++++++++++++++++++++++++++++------
 1 files changed, 75 insertions(+), 12 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 dec96c0..f5385d4 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
@@ -1,13 +1,30 @@
 package com.genersoft.iot.vmp.gb28181.session;
 
+import com.genersoft.iot.vmp.conf.SipConfig;
+import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
 import com.genersoft.iot.vmp.gb28181.bean.AudioBroadcastCatch;
+import com.genersoft.iot.vmp.gb28181.bean.Device;
+import com.genersoft.iot.vmp.gb28181.bean.InviteStreamType;
+import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
+import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
+import com.genersoft.iot.vmp.media.event.MediaDepartureEvent;
+import com.genersoft.iot.vmp.service.IDeviceService;
+import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.event.EventListener;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
+import javax.sip.InvalidArgumentException;
+import javax.sip.SipException;
+import java.text.ParseException;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * 璇煶骞挎挱娑堟伅绠$悊绫�
@@ -16,18 +33,30 @@
 @Component
 public class AudioBroadcastManager {
 
+    private final static Logger logger = LoggerFactory.getLogger(AudioBroadcastManager.class);
+
+    @Autowired
+    private SipConfig config;
+
     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())) {
+            audioBroadcastCatch.setChannelId(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) {
@@ -46,14 +75,48 @@
 
     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) {
-        return 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));
+            List<AudioBroadcastCatch> audioBroadcastCatchList = allAudioBroadcastCatchStreamForDevice.collect(Collectors.toList());
+            if (audioBroadcastCatchList.size() == 1 && Objects.equals(config.getId(), channelId)) {
+                audioBroadcastCatch = audioBroadcastCatchList.get(0);
+            }
+        }
+
+        return audioBroadcastCatch;
+    }
+
+    public List<AudioBroadcastCatch> get(String deviceId) {
+        List<AudioBroadcastCatch> audioBroadcastCatchList= new ArrayList<>();
+        if (SipUtils.isFrontEnd(deviceId)) {
+            if (data.get(deviceId) != null) {
+                audioBroadcastCatchList.add(data.get(deviceId));
+            }
+        }else {
+            for (String key : data.keySet()) {
+                if (key.startsWith(deviceId)) {
+                    audioBroadcastCatchList.add(data.get(key));
+                }
+            }
+        }
+
+        return audioBroadcastCatchList;
     }
 }

--
Gitblit v1.8.0