From b86f0aaae2f0212bc01ddfd3e5d646c22eb1d8c0 Mon Sep 17 00:00:00 2001 From: panll <m18010473990@163.com> Date: 星期五, 08 三月 2024 09:33:38 +0800 Subject: [PATCH] !28 语音对讲合并 语音对讲合并 --- src/main/java/com/genersoft/iot/vmp/gb28181/session/AudioBroadcastManager.java | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 103 insertions(+), 0 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 new file mode 100644 index 0000000..03aa749 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/session/AudioBroadcastManager.java @@ -0,0 +1,103 @@ +package com.genersoft.iot.vmp.gb28181.session; + +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; + +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * 璇煶骞挎挱娑堟伅绠$悊绫� + * @author lin + */ +@Component +public class AudioBroadcastManager { + + @Autowired + private SipConfig config; + + public static Map<String, AudioBroadcastCatch> data = new ConcurrentHashMap<>(); + + public void update(AudioBroadcastCatch 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) { + if (SipUtils.isFrontEnd(deviceId)) { + data.remove(deviceId); + }else { + data.remove(deviceId + channelId); + } + + } + + public void delByDeviceId(String deviceId) { + for (String key : data.keySet()) { + if (key.startsWith(deviceId)) { + data.remove(key); + } + } + } + + public List<AudioBroadcastCatch> getAll(){ + Collection<AudioBroadcastCatch> values = data.values(); + return new ArrayList<>(values); + } + + + public boolean exit(String deviceId, String channelId) { + for (String key : data.keySet()) { + 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; + 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