Commit 983c7c351f3790d0effe2894ce435552ff0f2feb

Authored by 648540858
1 parent d4fdd975

优化对讲释放流程

src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/ByeRequestProcessor.java
... ... @@ -113,6 +113,7 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In
113 113 CallIdHeader callIdHeader = (CallIdHeader)evt.getRequest().getHeader(CallIdHeader.NAME);
114 114 SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(null, null, null, callIdHeader.getCallId());
115 115  
  116 + // 收流端发送的停止
116 117 if (sendRtpItem != null){
117 118 logger.info("[收到bye] 来自{},停止通道:{}, 类型: {}", sendRtpItem.getPlatformId(), sendRtpItem.getChannelId(), sendRtpItem.getPlayType());
118 119  
... ... @@ -139,6 +140,7 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In
139 140 logger.info("[上级平台停止观看] 未找到平台{}的信息,发送redis消息失败", sendRtpItem.getPlatformId());
140 141 }
141 142 }
  143 +
142 144 AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(sendRtpItem.getDeviceId(), sendRtpItem.getChannelId());
143 145 if (audioBroadcastCatch != null && audioBroadcastCatch.getSipTransactionInfo().getCallId().equals(callIdHeader.getCallId())) {
144 146 // 来自上级平台的停止对讲
... ... @@ -165,54 +167,67 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In
165 167 }
166 168 }
167 169  
168   - // 可能是设备发送的停止
169   - SsrcTransaction ssrcTransaction = streamSession.getSsrcTransaction(null, null, callIdHeader.getCallId(), null);
170   - if (ssrcTransaction == null && sendRtpItem == null) {
171   - logger.info("[收到bye] 但是无法获取推流信息和发流信息,忽略此请求");
172   - logger.info(request.toString());
173   - return;
174   - }
175   - if (ssrcTransaction != null) {
176   - logger.info("[收到bye] 来自设备:{}, 通道已停止推流: {}", ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId());
  170 + // 发流端发送的停止
  171 + SsrcTransaction ssrcTransaction = streamSession.getSsrcTransaction(null, null, callIdHeader.getCallId(), null);
  172 + if (ssrcTransaction == null ) {
  173 + logger.info("[收到bye] 但是无法获取推流信息和发流信息,忽略此请求");
  174 + logger.info(request.toString());
  175 + return;
  176 + }
177 177  
178   - Device device = deviceService.getDevice(ssrcTransaction.getDeviceId());
179   - if (device == null) {
180   - logger.info("[收到bye] 未找到设备:{} ", ssrcTransaction.getDeviceId());
181   - return;
182   - }
183   - DeviceChannel channel = channelService.getOne(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId());
  178 +
  179 + ParentPlatform platform = platformService.queryPlatformByServerGBId(ssrcTransaction.getDeviceId());
  180 + if (platform != null ) {
  181 + if (ssrcTransaction.getType().equals(InviteSessionType.BROADCAST)) {
  182 + logger.info("[收到bye] 上级停止语音对讲,来自:{}, 通道已停止推流: {}", ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId());
  183 + DeviceChannel channel = storager.queryChannelInParentPlatform(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId());
184 184 if (channel == null) {
185 185 logger.info("[收到bye] 未找到通道,设备:{}, 通道:{}", ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId());
186 186 return;
187 187 }
188   - storager.stopPlay(device.getDeviceId(), channel.getChannelId());
189   - InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channel.getChannelId());
190   - if (inviteInfo != null) {
191   - inviteStreamService.removeInviteInfo(inviteInfo);
192   - if (inviteInfo.getStreamInfo() != null) {
193   - mediaServerService.closeRTPServer(inviteInfo.getStreamInfo().getMediaServerId(), inviteInfo.getStreamInfo().getStream());
194   - }
195   - }
196   - // 释放ssrc
197   - MediaServerItem mediaServerItem = mediaServerService.getOne(ssrcTransaction.getMediaServerId());
198   - if (mediaServerItem != null) {
199   - mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcTransaction.getSsrc());
200   - }
201   - streamSession.remove(device.getDeviceId(), channel.getChannelId(), ssrcTransaction.getStream());
202   - if (ssrcTransaction.getType() == InviteSessionType.BROADCAST) {
203   - // 查找来源的对讲设备,发送停止
204   - Device sourceDevice = storager.queryVideoDeviceByPlatformIdAndChannelId(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId());
205   - if (sourceDevice != null) {
206   - playService.stopAudioBroadcast(sourceDevice.getDeviceId(), channel.getChannelId());
207   - }
  188 + String mediaServerId = ssrcTransaction.getMediaServerId();
  189 + platformService.stopBroadcast(platform, channel, ssrcTransaction.getStream(), false,
  190 + mediaServerService.getOne(mediaServerId));
  191 + }
  192 +
  193 + }else {
  194 + Device device = deviceService.getDevice(ssrcTransaction.getDeviceId());
  195 + if (device == null) {
  196 + logger.info("[收到bye] 未找到设备:{} ", ssrcTransaction.getDeviceId());
  197 + return;
  198 + }
  199 + DeviceChannel channel = channelService.getOne(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId());
  200 + if (channel == null) {
  201 + logger.info("[收到bye] 未找到通道,设备:{}, 通道:{}", ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId());
  202 + return;
  203 + }
  204 + storager.stopPlay(device.getDeviceId(), channel.getChannelId());
  205 + InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channel.getChannelId());
  206 + if (inviteInfo != null) {
  207 + inviteStreamService.removeInviteInfo(inviteInfo);
  208 + if (inviteInfo.getStreamInfo() != null) {
  209 + mediaServerService.closeRTPServer(inviteInfo.getStreamInfo().getMediaServerId(), inviteInfo.getStreamInfo().getStream());
208 210 }
209   - AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(ssrcTransaction.getDeviceId(), channel.getChannelId());
210   - if (audioBroadcastCatch != null) {
211   - // 来自上级平台的停止对讲
212   - logger.info("[停止对讲] 来自上级,平台:{}, 通道:{}", ssrcTransaction.getDeviceId(), channel.getChannelId());
213   - audioBroadcastManager.del(ssrcTransaction.getDeviceId(), channel.getChannelId());
  211 + }
  212 + // 释放ssrc
  213 + MediaServerItem mediaServerItem = mediaServerService.getOne(ssrcTransaction.getMediaServerId());
  214 + if (mediaServerItem != null) {
  215 + mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcTransaction.getSsrc());
  216 + }
  217 + streamSession.remove(device.getDeviceId(), channel.getChannelId(), ssrcTransaction.getStream());
  218 + if (ssrcTransaction.getType() == InviteSessionType.BROADCAST) {
  219 + // 查找来源的对讲设备,发送停止
  220 + Device sourceDevice = storager.queryVideoDeviceByPlatformIdAndChannelId(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId());
  221 + if (sourceDevice != null) {
  222 + playService.stopAudioBroadcast(sourceDevice.getDeviceId(), channel.getChannelId());
214 223 }
215 224 }
216   -
  225 + AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(ssrcTransaction.getDeviceId(), channel.getChannelId());
  226 + if (audioBroadcastCatch != null) {
  227 + // 来自上级平台的停止对讲
  228 + logger.info("[停止对讲] 来自上级,平台:{}, 通道:{}", ssrcTransaction.getDeviceId(), channel.getChannelId());
  229 + audioBroadcastManager.del(ssrcTransaction.getDeviceId(), channel.getChannelId());
  230 + }
  231 + }
217 232 }
218 233 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/BroadcastNotifyMessageHandler.java
... ... @@ -137,12 +137,7 @@ public class BroadcastNotifyMessageHandler extends SIPRequestProcessorParent imp
137 137 logger.info("[国标级联] 语音喊话 设备正在使用中 platform: {}, channel: {}",
138 138 platform.getServerGBId(), deviceChannel.getChannelId());
139 139 // 查看语音通道已经建立且已经占用 回复BYE
140   - try {
141   - platformService.stopBroadcast(platform, deviceChannel.getChannelId(), streamChangedHookParam.getStream());
142   - } catch (InvalidArgumentException | ParseException | SsrcTransactionNotFoundException |
143   - SipException e) {
144   - logger.info("[消息发送失败] 国标级联 语音喊话 platform: {}, channel: {}", platform.getServerGBId(), deviceChannel.getChannelId());
145   - }
  140 + platformService.stopBroadcast(platform, deviceChannel, streamChangedHookParam.getStream(), true, mediaServerItem);
146 141 }else {
147 142 // 查看语音通道已经建立但是未占用
148 143 broadcastCatch.setApp(streamChangedHookParam.getApp());
... ...
src/main/java/com/genersoft/iot/vmp/service/IPlatformService.java
1 1 package com.genersoft.iot.vmp.service;
2 2  
3   -import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
  3 +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
4 4 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
5 5 import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
6 6 import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
... ... @@ -78,9 +78,6 @@ public interface IPlatformService {
78 78  
79 79 /**
80 80 * 语音喊话回复BYE
81   - * @param platform 平台
82   - * @param channelId 通道
83   - * @param stream 流信息
84 81 */
85   - void stopBroadcast(ParentPlatform platform, String channelId, String stream )throws InvalidArgumentException, ParseException, SsrcTransactionNotFoundException, SipException;
  82 + void stopBroadcast(ParentPlatform platform, DeviceChannel channel, String stream,boolean sendBye, MediaServerItem mediaServerItem);
86 83 }
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java
... ... @@ -422,7 +422,6 @@ public class PlatformServiceImpl implements IPlatformService {
422 422 }
423 423 InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, platform.getServerGBId(), channelId);
424 424  
425   -
426 425 if (inviteInfo != null && inviteInfo.getStreamInfo() != null) {
427 426 // 如果zlm不存在这个流,则删除数据即可
428 427 MediaServerItem mediaServerItemForStreamInfo = mediaServerService.getOne(inviteInfo.getStreamInfo().getMediaServerId());
... ... @@ -547,7 +546,23 @@ public class PlatformServiceImpl implements IPlatformService {
547 546 }
548 547  
549 548 @Override
550   - public void stopBroadcast(ParentPlatform platform, String channelId, String stream) throws InvalidArgumentException, ParseException, SsrcTransactionNotFoundException, SipException {
551   - commanderForPlatform.streamByeCmd(platform, channelId, stream, null, null);
  549 + public void stopBroadcast(ParentPlatform platform, DeviceChannel channel, String stream, boolean sendBye, MediaServerItem mediaServerItem) {
  550 +
  551 + try {
  552 + if (sendBye) {
  553 + commanderForPlatform.streamByeCmd(platform, channel.getChannelId(), stream, null, null);
  554 + }
  555 + } catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) {
  556 + logger.warn("[消息发送失败] 停止语音对讲, 平台:{},通道:{}", platform.getId(), channel.getChannelId() );
  557 + } finally {
  558 + mediaServerService.closeRTPServer(mediaServerItem, stream);
  559 + InviteInfo inviteInfo = inviteStreamService.getInviteInfo(null, platform.getServerGBId(), channel.getChannelId(), stream);
  560 + if (inviteInfo != null) {
  561 + // 释放ssrc
  562 + mediaServerService.releaseSsrc(mediaServerItem.getId(), inviteInfo.getSsrcInfo().getSsrc());
  563 + inviteStreamService.removeInviteInfo(inviteInfo);
  564 + }
  565 + streamSession.remove(platform.getServerGBId(), channel.getChannelId(), stream);
  566 + }
552 567 }
553 568 }
... ...