Commit 16f3b0553d5ea1dd891b56b93e3e13da950cf4dd
1 parent
49e937c3
设备离线清空语音对讲通道
Showing
3 changed files
with
66 additions
and
24 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/session/AudioBroadcastManager.java
| @@ -83,4 +83,19 @@ public class AudioBroadcastManager { | @@ -83,4 +83,19 @@ public class AudioBroadcastManager { | ||
| 83 | 83 | ||
| 84 | return audioBroadcastCatch; | 84 | return audioBroadcastCatch; |
| 85 | } | 85 | } |
| 86 | + | ||
| 87 | + public List<AudioBroadcastCatch> get(String deviceId) { | ||
| 88 | + List<AudioBroadcastCatch> audioBroadcastCatchList= new ArrayList<>(); | ||
| 89 | + if (SipUtils.isFrontEnd(deviceId)) { | ||
| 90 | + audioBroadcastCatchList.add(data.get(deviceId)); | ||
| 91 | + }else { | ||
| 92 | + for (String key : data.keySet()) { | ||
| 93 | + if (key.startsWith(deviceId)) { | ||
| 94 | + audioBroadcastCatchList.add(data.get(key)); | ||
| 95 | + } | ||
| 96 | + } | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + return audioBroadcastCatchList; | ||
| 100 | + } | ||
| 86 | } | 101 | } |
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
| @@ -3,12 +3,15 @@ package com.genersoft.iot.vmp.service.impl; | @@ -3,12 +3,15 @@ package com.genersoft.iot.vmp.service.impl; | ||
| 3 | import com.genersoft.iot.vmp.conf.DynamicTask; | 3 | import com.genersoft.iot.vmp.conf.DynamicTask; |
| 4 | import com.genersoft.iot.vmp.conf.UserSetting; | 4 | import com.genersoft.iot.vmp.conf.UserSetting; |
| 5 | import com.genersoft.iot.vmp.gb28181.bean.*; | 5 | import com.genersoft.iot.vmp.gb28181.bean.*; |
| 6 | +import com.genersoft.iot.vmp.gb28181.session.AudioBroadcastManager; | ||
| 6 | import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; | 7 | import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; |
| 7 | import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask; | 8 | import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask; |
| 8 | import com.genersoft.iot.vmp.gb28181.task.impl.CatalogSubscribeTask; | 9 | import com.genersoft.iot.vmp.gb28181.task.impl.CatalogSubscribeTask; |
| 9 | import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeTask; | 10 | import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeTask; |
| 10 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; | 11 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; |
| 11 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd.CatalogResponseMessageHandler; | 12 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd.CatalogResponseMessageHandler; |
| 13 | +import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; | ||
| 14 | +import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | ||
| 12 | import com.genersoft.iot.vmp.service.IDeviceChannelService; | 15 | import com.genersoft.iot.vmp.service.IDeviceChannelService; |
| 13 | import com.genersoft.iot.vmp.service.IDeviceService; | 16 | import com.genersoft.iot.vmp.service.IDeviceService; |
| 14 | import com.genersoft.iot.vmp.service.IMediaServerService; | 17 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| @@ -32,9 +35,7 @@ import javax.sip.InvalidArgumentException; | @@ -32,9 +35,7 @@ import javax.sip.InvalidArgumentException; | ||
| 32 | import javax.sip.SipException; | 35 | import javax.sip.SipException; |
| 33 | import java.text.ParseException; | 36 | import java.text.ParseException; |
| 34 | import java.time.Instant; | 37 | import java.time.Instant; |
| 35 | -import java.util.ArrayList; | ||
| 36 | -import java.util.Collections; | ||
| 37 | -import java.util.List; | 38 | +import java.util.*; |
| 38 | import java.util.concurrent.TimeUnit; | 39 | import java.util.concurrent.TimeUnit; |
| 39 | 40 | ||
| 40 | /** | 41 | /** |
| @@ -89,6 +90,12 @@ public class DeviceServiceImpl implements IDeviceService { | @@ -89,6 +90,12 @@ public class DeviceServiceImpl implements IDeviceService { | ||
| 89 | @Autowired | 90 | @Autowired |
| 90 | private IMediaServerService mediaServerService; | 91 | private IMediaServerService mediaServerService; |
| 91 | 92 | ||
| 93 | + @Autowired | ||
| 94 | + private AudioBroadcastManager audioBroadcastManager; | ||
| 95 | + | ||
| 96 | + @Autowired | ||
| 97 | + private ZLMRESTfulUtils zlmresTfulUtils; | ||
| 98 | + | ||
| 92 | @Override | 99 | @Override |
| 93 | public void online(Device device) { | 100 | public void online(Device device) { |
| 94 | logger.info("[设备上线] deviceId:{}->{}:{}", device.getDeviceId(), device.getIp(), device.getPort()); | 101 | logger.info("[设备上线] deviceId:{}->{}:{}", device.getDeviceId(), device.getIp(), device.getPort()); |
| @@ -183,6 +190,23 @@ public class DeviceServiceImpl implements IDeviceService { | @@ -183,6 +190,23 @@ public class DeviceServiceImpl implements IDeviceService { | ||
| 183 | // 移除订阅 | 190 | // 移除订阅 |
| 184 | removeCatalogSubscribe(device); | 191 | removeCatalogSubscribe(device); |
| 185 | removeMobilePositionSubscribe(device); | 192 | removeMobilePositionSubscribe(device); |
| 193 | + List<AudioBroadcastCatch> audioBroadcastCatches = audioBroadcastManager.get(deviceId); | ||
| 194 | + if (audioBroadcastCatches.size() > 0) { | ||
| 195 | + for (AudioBroadcastCatch audioBroadcastCatch : audioBroadcastCatches) { | ||
| 196 | + SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(deviceId, audioBroadcastCatch.getChannelId(), null, null); | ||
| 197 | + if (sendRtpItem != null) { | ||
| 198 | + redisCatchStorage.deleteSendRTPServer(deviceId, sendRtpItem.getChannelId(), null, null); | ||
| 199 | + MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId()); | ||
| 200 | + Map<String, Object> param = new HashMap<>(); | ||
| 201 | + param.put("vhost", "__defaultVhost__"); | ||
| 202 | + param.put("app", sendRtpItem.getApp()); | ||
| 203 | + param.put("stream", sendRtpItem.getStreamId()); | ||
| 204 | + zlmresTfulUtils.stopSendRtp(mediaInfo, param); | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + audioBroadcastManager.del(deviceId, audioBroadcastCatch.getChannelId()); | ||
| 208 | + } | ||
| 209 | + } | ||
| 186 | } | 210 | } |
| 187 | 211 | ||
| 188 | @Override | 212 | @Override |
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
| @@ -58,10 +58,7 @@ import javax.sip.header.CallIdHeader; | @@ -58,10 +58,7 @@ import javax.sip.header.CallIdHeader; | ||
| 58 | import java.math.BigDecimal; | 58 | import java.math.BigDecimal; |
| 59 | import java.math.RoundingMode; | 59 | import java.math.RoundingMode; |
| 60 | import java.text.ParseException; | 60 | import java.text.ParseException; |
| 61 | -import java.util.HashMap; | ||
| 62 | -import java.util.List; | ||
| 63 | -import java.util.Map; | ||
| 64 | -import java.util.UUID; | 61 | +import java.util.*; |
| 65 | 62 | ||
| 66 | @SuppressWarnings(value = {"rawtypes", "unchecked"}) | 63 | @SuppressWarnings(value = {"rawtypes", "unchecked"}) |
| 67 | @Service | 64 | @Service |
| @@ -1067,25 +1064,31 @@ public class PlayServiceImpl implements IPlayService { | @@ -1067,25 +1064,31 @@ public class PlayServiceImpl implements IPlayService { | ||
| 1067 | 1064 | ||
| 1068 | @Override | 1065 | @Override |
| 1069 | public void stopAudioBroadcast(String deviceId, String channelId) { | 1066 | public void stopAudioBroadcast(String deviceId, String channelId) { |
| 1070 | - AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(deviceId, channelId); | ||
| 1071 | - if (audioBroadcastCatch != null) { | 1067 | + List<AudioBroadcastCatch> audioBroadcastCatchList = new ArrayList<>(); |
| 1068 | + if (channelId == null) { | ||
| 1069 | + audioBroadcastCatchList.addAll(audioBroadcastManager.get(deviceId)); | ||
| 1070 | + }else { | ||
| 1071 | + audioBroadcastCatchList.add(audioBroadcastManager.get(deviceId, channelId)); | ||
| 1072 | + } | ||
| 1073 | + if (audioBroadcastCatchList.size() > 0) { | ||
| 1074 | + for (AudioBroadcastCatch audioBroadcastCatch : audioBroadcastCatchList) { | ||
| 1075 | + Device device = deviceService.getDevice(deviceId); | ||
| 1076 | + if (device == null || audioBroadcastCatch == null ) { | ||
| 1077 | + return; | ||
| 1078 | + } | ||
| 1079 | + SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(deviceId, audioBroadcastCatch.getChannelId(), null, null); | ||
| 1080 | + if (sendRtpItem != null) { | ||
| 1081 | + redisCatchStorage.deleteSendRTPServer(deviceId, sendRtpItem.getChannelId(), null, null); | ||
| 1082 | + MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId()); | ||
| 1083 | + Map<String, Object> param = new HashMap<>(); | ||
| 1084 | + param.put("vhost", "__defaultVhost__"); | ||
| 1085 | + param.put("app", sendRtpItem.getApp()); | ||
| 1086 | + param.put("stream", sendRtpItem.getStreamId()); | ||
| 1087 | + zlmresTfulUtils.stopSendRtp(mediaInfo, param); | ||
| 1088 | + } | ||
| 1072 | 1089 | ||
| 1073 | - Device device = deviceService.getDevice(deviceId); | ||
| 1074 | - if (device == null) { | ||
| 1075 | - return; | ||
| 1076 | - } | ||
| 1077 | - SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(deviceId, audioBroadcastCatch.getChannelId(), null, null); | ||
| 1078 | - if (sendRtpItem != null) { | ||
| 1079 | - redisCatchStorage.deleteSendRTPServer(deviceId, sendRtpItem.getChannelId(), null, null); | ||
| 1080 | - MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId()); | ||
| 1081 | - Map<String, Object> param = new HashMap<>(); | ||
| 1082 | - param.put("vhost", "__defaultVhost__"); | ||
| 1083 | - param.put("app", sendRtpItem.getApp()); | ||
| 1084 | - param.put("stream", sendRtpItem.getStreamId()); | ||
| 1085 | - zlmresTfulUtils.stopSendRtp(mediaInfo, param); | 1090 | + audioBroadcastManager.del(deviceId, channelId); |
| 1086 | } | 1091 | } |
| 1087 | - | ||
| 1088 | - audioBroadcastManager.del(deviceId, channelId); | ||
| 1089 | } | 1092 | } |
| 1090 | } | 1093 | } |
| 1091 | 1094 |