|  |  |  | 
|---|
|  |  |  | package com.genersoft.iot.vmp.gb28181.session; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.genersoft.iot.vmp.conf.SipConfig; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.gb28181.bean.AudioBroadcastCatch; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Collection; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.concurrent.ConcurrentHashMap; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  | import java.util.stream.Stream; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 语音广播消息管理类 | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Component | 
|---|
|  |  |  | public class AudioBroadcastManager { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SipConfig config; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static Map<String, AudioBroadcastCatch> data = new ConcurrentHashMap<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public AudioBroadcastCatch get(String deviceId, String channelId) { | 
|---|
|  |  |  | return data.get(deviceId + channelId); | 
|---|
|  |  |  | AudioBroadcastCatch 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|