From 875285418bc340c92f6ba851cc362944d63bb31c Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Fri, 13 Sep 2024 15:06:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=BE=91=E9=80=9A?= =?UTF-8?q?=E9=81=93=E7=BC=96=E5=8F=B7=E5=90=8E=E6=97=A0=E6=B3=95=E7=82=B9?= =?UTF-8?q?=E6=92=AD=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/GBRecordController.java | 3 +- .../gb28181/controller/PlayController.java | 6 +- .../controller/PlaybackController.java | 15 ++- .../vmp/gb28181/dao/DeviceChannelMapper.java | 103 ++++++++++++++++++ .../MobilePositionEventLister.java | 6 +- .../service/IDeviceChannelService.java | 4 + .../iot/vmp/gb28181/service/IPlayService.java | 9 +- .../impl/DeviceChannelServiceImpl.java | 14 +++ .../gb28181/service/impl/PlayServiceImpl.java | 57 ++++++++-- .../cmd/impl/SIPCommanderFroPlatform.java | 4 +- .../request/impl/InviteRequestProcessor.java | 2 +- .../cmd/MediaStatusNotifyMessageHandler.java | 25 ++--- .../vmp/service/impl/MediaServiceImpl.java | 72 +++--------- 13 files changed, 220 insertions(+), 100 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/GBRecordController.java b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/GBRecordController.java index c68af889..ba16222f 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/GBRecordController.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/GBRecordController.java @@ -201,8 +201,7 @@ public class GBRecordController { try { cmder.streamByeCmd(device, channelId, stream, null); } catch (InvalidArgumentException | ParseException | SipException | SsrcTransactionNotFoundException e) { - log.error("[停止历史媒体下载]停止历史媒体下载,发送BYE失败 {}", e.getMessage()); - throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage()); + log.warn("[停止历史媒体下载]停止历史媒体下载,发送BYE失败 {}", e.getMessage()); } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlayController.java b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlayController.java index 86fcb37f..b4519c43 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlayController.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlayController.java @@ -165,11 +165,11 @@ public class PlayController { } Device device = deviceService.getDeviceByDeviceId(deviceId); - DeviceChannel channel = deviceChannelService.getOne(deviceId, channelId); + DeviceChannel channel = deviceChannelService.getOneForSource(deviceId, channelId); Assert.notNull(device, "设备不存在"); Assert.notNull(channel, "通道不存在"); - - playService.stopPlay(device, channel); + String streamId = String.format("%s_%s", device.getDeviceId(), channel.getDeviceId()); + playService.stop(InviteSessionType.PLAY, device, channel, streamId); JSONObject json = new JSONObject(); json.put("deviceId", deviceId); json.put("channelId", channelId); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlaybackController.java b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlaybackController.java index 9145e8b5..d6e2b044 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlaybackController.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlaybackController.java @@ -6,17 +6,16 @@ import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.conf.exception.ServiceException; -import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException; import com.genersoft.iot.vmp.conf.security.JwtUtils; import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.genersoft.iot.vmp.gb28181.service.IDeviceChannelService; -import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; -import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; -import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; import com.genersoft.iot.vmp.gb28181.service.IDeviceService; import com.genersoft.iot.vmp.gb28181.service.IInviteStreamService; import com.genersoft.iot.vmp.gb28181.service.IPlayService; +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; +import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; import com.genersoft.iot.vmp.service.bean.InviteErrorCode; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; @@ -159,11 +158,11 @@ public class PlaybackController { if (device == null) { throw new ControllerException(ErrorCode.ERROR400.getCode(), "设备:" + deviceId + " 未找到"); } - try { - cmder.streamByeCmd(device, channelId, stream, null); - } catch (InvalidArgumentException | ParseException | SipException | SsrcTransactionNotFoundException e) { - throw new ControllerException(ErrorCode.ERROR100.getCode(), "发送bye失败: " + e.getMessage()); + DeviceChannel deviceChannel = channelService.getOneForSource(deviceId, channelId); + if (deviceChannel == null) { + throw new ControllerException(ErrorCode.ERROR400.getCode(), "通道:" + deviceChannel + " 未找到"); } + playService.stop(InviteSessionType.PLAYBACK, device, deviceChannel, stream); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/DeviceChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/DeviceChannelMapper.java index 6f6e1821..5ee523c4 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/DeviceChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/DeviceChannelMapper.java @@ -743,6 +743,57 @@ public interface DeviceChannelMapper { " "}) DeviceChannel getOne(@Param("id") int id); + @Select(value = {" "}) + DeviceChannel getOneForSource(@Param("id") int id); + @Select(value = {" "}) + DeviceChannel getOneByDeviceIdForSource(@Param("deviceDbId") int deviceDbId, @Param("channelId") String channelId); + + @Update(value = {"UPDATE wvp_device_channel SET stream_id=null WHERE id=#{channelId}"}) void stopPlayById(@Param("channelId") Integer channelId); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/mobilePosition/MobilePositionEventLister.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/mobilePosition/MobilePositionEventLister.java index 2ba42af5..35ce8fed 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/mobilePosition/MobilePositionEventLister.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/mobilePosition/MobilePositionEventLister.java @@ -44,8 +44,10 @@ public class MobilePositionEventLister implements ApplicationListener parentPlatformsForGB = platformChannelService.queryPlatFormListByChannelDeviceId(event.getMobilePosition().getChannelId(), platforms); for (Platform platform : parentPlatformsForGB) { - log.info("[向上级发送MobilePosition] 通道:{},平台:{}, 位置: {}:{}", event.getMobilePosition().getChannelId(), - platform.getServerGBId(), event.getMobilePosition().getLongitude(), event.getMobilePosition().getLatitude()); + if (log.isDebugEnabled()){ + log.debug("[向上级发送MobilePosition] 通道:{},平台:{}, 位置: {}:{}", event.getMobilePosition().getChannelId(), + platform.getServerGBId(), event.getMobilePosition().getLongitude(), event.getMobilePosition().getLatitude()); + } SubscribeInfo subscribe = subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId()); try { GPSMsgInfo gpsMsgInfo = GPSMsgInfo.getInstance(event.getMobilePosition()); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IDeviceChannelService.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IDeviceChannelService.java index 644b0717..e5babf36 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IDeviceChannelService.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IDeviceChannelService.java @@ -70,6 +70,8 @@ public interface IDeviceChannelService { */ DeviceChannel getOne(String deviceId, String channelId); + DeviceChannel getOneForSource(String deviceId, String channelId); + /** * 直接批量更新通道 */ @@ -120,5 +122,7 @@ public interface IDeviceChannelService { DeviceChannel getOneById(Integer channelId); + DeviceChannel getOneForSourceById(Integer channelId); + DeviceChannel getBroadcastChannel(int deviceDbId); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IPlayService.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IPlayService.java index e085d1b6..80e063b3 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IPlayService.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IPlayService.java @@ -1,14 +1,16 @@ package com.genersoft.iot.vmp.gb28181.service; +import com.genersoft.iot.vmp.common.InviteInfo; +import com.genersoft.iot.vmp.common.InviteSessionType; import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.conf.exception.ServiceException; import com.genersoft.iot.vmp.gb28181.bean.*; +import com.genersoft.iot.vmp.gb28181.controller.bean.AudioBroadcastEvent; import com.genersoft.iot.vmp.media.bean.MediaInfo; import com.genersoft.iot.vmp.media.bean.MediaServer; import com.genersoft.iot.vmp.service.bean.ErrorCallback; import com.genersoft.iot.vmp.service.bean.SSRCInfo; import com.genersoft.iot.vmp.vmanager.bean.AudioBroadcastResult; -import com.genersoft.iot.vmp.gb28181.controller.bean.AudioBroadcastEvent; import gov.nist.javax.sip.message.SIPResponse; import javax.sip.InvalidArgumentException; @@ -58,11 +60,14 @@ public interface IPlayService { void getSnap(String deviceId, String channelId, String fileName, ErrorCallback errorCallback); - void stopPlay(Device device, DeviceChannel channel); + void stop(InviteSessionType type, Device device, DeviceChannel channel, String stream); + + void stop(InviteInfo inviteInfo); void play(CommonGBChannel channel, ErrorCallback callback); void playBack(CommonGBChannel channel, Long startTime, Long stopTime, ErrorCallback callback); void download(CommonGBChannel channel, Long startTime, Long stopTime, Integer downloadSpeed, ErrorCallback callback); + } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/DeviceChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/DeviceChannelServiceImpl.java index e184134c..fd90386d 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/DeviceChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/DeviceChannelServiceImpl.java @@ -252,6 +252,15 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { return channelMapper.getOneByDeviceId(device.getId(), channelId); } + @Override + public DeviceChannel getOneForSource(String deviceId, String channelId){ + Device device = deviceMapper.getDeviceByDeviceId(deviceId); + if (device == null) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到设备:" + deviceId); + } + return channelMapper.getOneByDeviceIdForSource(device.getId(), channelId); + } + @Override public synchronized void batchUpdateChannel(List channels) { String now = DateUtil.getNow(); @@ -595,6 +604,11 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { return channelMapper.getOne(channelId); } + @Override + public DeviceChannel getOneForSourceById(Integer channelId) { + return channelMapper.getOneForSource(channelId); + } + @Override public DeviceChannel getBroadcastChannel(int deviceDbId) { List channels = channelMapper.getByDeviceId(deviceDbId); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlayServiceImpl.java index e620aa9b..4fbc6b4b 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlayServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlayServiceImpl.java @@ -226,6 +226,15 @@ public class PlayServiceImpl implements IPlayService { } } } + }else if ("rtp".equals(event.getApp())) { + // 释放ssrc + InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(null, event.getStream()); + if (inviteInfo != null && inviteInfo.getStatus() == InviteSessionStatus.ok + && inviteInfo.getStreamInfo() != null && inviteInfo.getSsrcInfo() != null) { + // 发送bye + stop(inviteInfo); + } + } } @@ -286,7 +295,7 @@ public class PlayServiceImpl implements IPlayService { log.warn("[点播] 单端口收流时不支持TCP主动方式收流 deviceId: {},channelId:{}", deviceId, channelId); throw new ControllerException(ErrorCode.ERROR100.getCode(), "单端口收流时不支持TCP主动方式收流"); } - DeviceChannel channel = deviceChannelService.getOne(deviceId, channelId); + DeviceChannel channel = deviceChannelService.getOneForSource(deviceId, channelId); if (channel == null) { log.warn("[点播] 未找到通道 deviceId: {},channelId:{}", deviceId, channelId); throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到通道"); @@ -1529,24 +1538,56 @@ public class PlayServiceImpl implements IPlayService { } @Override - public void stopPlay(Device device, DeviceChannel channel) { - InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, channel.getId()); + public void stop(InviteSessionType type, Device device, DeviceChannel channel, String stream) { + InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(type, stream); if (inviteInfo == null) { throw new ControllerException(ErrorCode.ERROR100.getCode(), "点播未找到"); } if (InviteSessionStatus.ok == inviteInfo.getStatus()) { try { - log.info("[停止点播] {}/{}", device.getDeviceId(), channel.getDeviceId()); + log.info("[停止点播/回放/下载] {}/{}", device.getDeviceId(), channel.getDeviceId()); cmder.streamByeCmd(device, channel.getDeviceId(), inviteInfo.getStream(), null, null); } catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) { - log.error("[命令发送失败] 停止点播, 发送BYE: {}", e.getMessage()); + log.error("[命令发送失败] 停止点播/回放/下载, 发送BYE: {}", e.getMessage()); throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage()); } } - inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, channel.getId()); - deviceChannelService.stopPlay(channel.getId()); + inviteStreamService.removeInviteInfoByDeviceAndChannel(inviteInfo.getType(), channel.getId()); + if (inviteInfo.getType() == InviteSessionType.PLAY) { + deviceChannelService.stopPlay(channel.getId()); + } if (inviteInfo.getStreamInfo() != null) { - mediaServerService.closeRTPServer(inviteInfo.getStreamInfo().getMediaServer(), inviteInfo.getStream()); + receiveRtpServerService.closeRTPServer(inviteInfo.getStreamInfo().getMediaServer(), inviteInfo.getSsrcInfo()); + } + } + + @Override + public void stop(InviteInfo inviteInfo) { + Assert.notNull(inviteInfo, "参数异常"); + DeviceChannel channel = deviceChannelService.getOneForSourceById(inviteInfo.getChannelId()); + if (channel == null) { + log.warn("[停止点播] 发现通道不存在"); + return; + } + Device device = deviceService.getDevice(channel.getDeviceDbId()); + if (device == null) { + log.warn("[停止点播] 发现设备不存在"); + return; + } + if (InviteSessionStatus.ok == inviteInfo.getStatus()) { + try { + log.info("[停止点播/回放/下载] {}/{}", device.getDeviceId(), channel.getDeviceId()); + cmder.streamByeCmd(device, channel.getDeviceId(), inviteInfo.getStream(), null, null); + } catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) { + log.warn("[命令发送失败] 停止点播/回放/下载, 发送BYE: {}", e.getMessage()); + } + } + inviteStreamService.removeInviteInfoByDeviceAndChannel(inviteInfo.getType(), channel.getId()); + if (inviteInfo.getType() == InviteSessionType.PLAY) { + deviceChannelService.stopPlay(channel.getId()); + } + if (inviteInfo.getStreamInfo() != null) { + receiveRtpServerService.closeRTPServer(inviteInfo.getStreamInfo().getMediaServer(), inviteInfo.getSsrcInfo()); } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java index 950f8ff3..fe54f508 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java @@ -360,7 +360,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { if (parentPlatform == null) { return; } - log.info("[发送 移动位置订阅] {}/{}->{},{}", parentPlatform.getServerGBId(), gpsMsgInfo.getChannelId(), gpsMsgInfo.getLng(), gpsMsgInfo.getLat()); + if (log.isDebugEnabled()) { + log.info("[发送 移动位置订阅] {}/{}->{},{}", parentPlatform.getServerGBId(), gpsMsgInfo.getChannelId(), gpsMsgInfo.getLng(), gpsMsgInfo.getLat()); + } String characterSet = parentPlatform.getCharacterSet(); StringBuffer deviceStatusXml = new StringBuffer(600); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java index 9691d380..7a58dbbb 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java @@ -198,7 +198,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements String content = createSendSdp(sendRtpItem, inviteInfo, sdpIp); // 超时未收到Ack应该回复bye,当前等待时间为10秒 dynamicTask.startDelay(inviteInfo.getCallId(), () -> { - log.info("Ack 等待超时"); + log.info("[Ack ] 等待超时, {}/{}", inviteInfo.getCallId(), channel.getGbDeviceId()); mediaServerService.releaseSsrc(streamInfo.getMediaServer().getId(), sendRtpItem.getSsrc()); // 回复bye sendBye(platform, inviteInfo.getCallId()); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusNotifyMessageHandler.java index fd37b94f..3d71ee93 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusNotifyMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusNotifyMessageHandler.java @@ -2,11 +2,14 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify import com.genersoft.iot.vmp.common.InviteInfo; import com.genersoft.iot.vmp.common.InviteSessionType; -import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException; -import com.genersoft.iot.vmp.gb28181.bean.*; +import com.genersoft.iot.vmp.gb28181.bean.Device; +import com.genersoft.iot.vmp.gb28181.bean.Platform; +import com.genersoft.iot.vmp.gb28181.bean.SendRtpInfo; +import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction; import com.genersoft.iot.vmp.gb28181.service.IDeviceChannelService; import com.genersoft.iot.vmp.gb28181.service.IInviteStreamService; import com.genersoft.iot.vmp.gb28181.service.IPlatformService; +import com.genersoft.iot.vmp.gb28181.service.IPlayService; import com.genersoft.iot.vmp.gb28181.session.SipInviteSessionManager; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; @@ -70,6 +73,9 @@ public class MediaStatusNotifyMessageHandler extends SIPRequestProcessorParent i @Autowired private IDeviceChannelService deviceChannelService; + @Autowired + private IPlayService playService; + @Autowired private ISendRtpServerService sendRtpServerService; @@ -96,19 +102,8 @@ public class MediaStatusNotifyMessageHandler extends SIPRequestProcessorParent i if (ssrcTransaction != null) { log.info("[录像流]推送完毕,关流通知, device: {}, channelId: {}", ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId()); InviteInfo inviteInfo = inviteStreamService.getInviteInfo(InviteSessionType.DOWNLOAD, ssrcTransaction.getChannelId(), ssrcTransaction.getStream()); - if (inviteInfo.getStreamInfo() != null) { - inviteInfo.getStreamInfo().setProgress(1); - inviteStreamService.updateInviteInfo(inviteInfo); - } - DeviceChannel deviceChannel = deviceChannelService.getOneById(ssrcTransaction.getChannelId()); - if (deviceChannel == null) { - log.warn("[级联消息发送]:未找到国标设备通道: {}", ssrcTransaction.getChannelId()); - return; - } - try { - cmder.streamByeCmd(device, deviceChannel.getDeviceId(), null, callIdHeader.getCallId()); - } catch (InvalidArgumentException | ParseException | SipException | SsrcTransactionNotFoundException e) { - log.error("[录像流]推送完毕,收到关流通知, 发送BYE失败 {}", e.getMessage()); + if (inviteInfo != null) { + playService.stop(inviteInfo); } // 去除监听流注销自动停止下载的监听 Hook hook = Hook.getInstance(HookType.on_media_arrival, "rtp", ssrcTransaction.getStream(), ssrcTransaction.getMediaServerId()); diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java index 639a4e43..2a0d7ca8 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java @@ -1,13 +1,15 @@ package com.genersoft.iot.vmp.service.impl; import com.genersoft.iot.vmp.common.InviteInfo; +import com.genersoft.iot.vmp.common.InviteSessionStatus; import com.genersoft.iot.vmp.common.InviteSessionType; import com.genersoft.iot.vmp.common.VideoManagerConstants; import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.conf.exception.ControllerException; -import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException; -import com.genersoft.iot.vmp.gb28181.bean.*; +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; +import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction; import com.genersoft.iot.vmp.gb28181.service.*; +import com.genersoft.iot.vmp.gb28181.session.SSRCFactory; import com.genersoft.iot.vmp.gb28181.session.SipInviteSessionManager; import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; @@ -30,10 +32,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; -import javax.sip.InvalidArgumentException; -import javax.sip.SipException; -import java.text.ParseException; -import java.util.List; import java.util.Map; @Slf4j @@ -58,6 +56,9 @@ public class MediaServiceImpl implements IMediaService { @Autowired private IInviteStreamService inviteStreamService; + @Autowired + private SSRCFactory ssrcFactory; + @Autowired private IDeviceChannelService deviceChannelService; @@ -228,7 +229,7 @@ public class MediaServiceImpl implements IMediaService { // 国标流, 点播/录像回放/录像下载 InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(null, stream); // 点播 - if (inviteInfo != null) { + if (inviteInfo != null && inviteInfo.getStatus() == InviteSessionStatus.ok) { // 录像下载 if (inviteInfo.getType() == InviteSessionType.DOWNLOAD) { return false; @@ -237,54 +238,8 @@ public class MediaServiceImpl implements IMediaService { if (deviceChannel == null) { return false; } - // 收到无人观看说明流也没有在往上级推送 - if (sendRtpServerService.isChannelSendingRTP(deviceChannel.getId())) { - List sendRtpItems = sendRtpServerService.queryByChannelId(deviceChannel.getId()); - if (!sendRtpItems.isEmpty()) { - for (SendRtpInfo sendRtpItem : sendRtpItems) { - Platform parentPlatform = platformService.queryPlatformByServerGBId(sendRtpItem.getTargetId()); - CommonGBChannel channel = channelService.getOne(sendRtpItem.getChannelId()); - if (channel == null) { - continue; - } - try { - commanderForPlatform.streamByeCmd(parentPlatform, sendRtpItem, channel); - } catch (SipException | InvalidArgumentException | ParseException e) { - log.error("[命令发送失败] 国标级联 发送BYE: {}", e.getMessage()); - } - sendRtpServerService.delete(sendRtpItem); - if (InviteStreamType.PUSH == sendRtpItem.getPlayType()) { - redisCatchStorage.sendPlatformStopPlayMsg(sendRtpItem, parentPlatform, channel); - redisCatchStorage.sendPlatformStopPlayMsg(sendRtpItem, parentPlatform, channel); - } - } - } - } - Device device = deviceService.getDeviceByDeviceId(inviteInfo.getDeviceId()); - if (device != null) { - try { - DeviceChannel channel = deviceChannelService.getOneById(inviteInfo.getChannelId()); - // 多查询一次防止已经被处理了 - InviteInfo info = inviteStreamService.getInviteInfo(inviteInfo.getType(), inviteInfo.getChannelId(), inviteInfo.getStream()); - if (info != null && channel != null) { - commander.streamByeCmd(device, channel.getDeviceId(), inviteInfo.getStream(), null); - } else { - log.info("[无人观看] 未找到设备的点播信息: {}, 流:{}", inviteInfo.getDeviceId(), stream); - } - } catch (InvalidArgumentException | ParseException | SipException | - SsrcTransactionNotFoundException e) { - log.error("[无人观看]点播, 发送BYE失败 {}", e.getMessage()); - } - } else { - log.info("[无人观看] 未找到设备: {},流:{}", inviteInfo.getDeviceId(), stream); - } - - inviteStreamService.removeInviteInfo(inviteInfo.getType(), inviteInfo.getChannelId(), inviteInfo.getStream()); - deviceChannelService.stopPlay(inviteInfo.getChannelId()); return result; - } - List sendRtpItemList = sendRtpServerService.queryByStream(stream); - if (!sendRtpItemList.isEmpty()) { + }else { return false; } } else if ("talk".equals(app) || "broadcast".equals(app)) { @@ -296,20 +251,21 @@ public class MediaServiceImpl implements IMediaService { if (streamProxy != null) { if (streamProxy.isEnableRemoveNoneReader()) { // 无人观看自动移除 - result = true; streamProxyService.delteByAppAndStream(app, stream); log.info("[{}/{}]<-[{}] 拉流代理无人观看已经移除", app, stream, streamProxy.getSrcUrl()); + return true; } else if (streamProxy.isEnableDisableNoneReader()) { // 无人观看停用 - result = true; // 修改数据 streamProxyService.stopByAppAndStream(app, stream); + return true; } else { // 无人观看不做处理 - result = false; + return false; } + }else { + return false; } } - return result; } }