diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java index 7007e5a6..d000f5af 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java @@ -103,6 +103,14 @@ public interface ISIPCommanderForPlatform { */ boolean recordInfo(DeviceChannel deviceChannel, ParentPlatform parentPlatform, String fromTag, RecordInfo recordInfo); + /** + * 录像播放推送完成时发送MediaStatus消息 + * @param platform + * @param sendRtpItem + * @return + */ + boolean sendMediaStatusNotify(ParentPlatform platform, SendRtpItem sendRtpItem); + /** * 向发起点播的上级回复bye * @param platform 平台信息 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 76aa4c87..6c06bd3a 100644 --- 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 @@ -745,6 +745,56 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { return true; } + @Override + public boolean sendMediaStatusNotify(ParentPlatform platform, SendRtpItem sendRtpItem) { + if (sendRtpItem == null) { + return false; + } + if (platform == null) { + return false; + } + + byte[] dialogByteArray = sendRtpItem.getDialog(); + if (dialogByteArray == null) { + return false; + } + try{ + SIPDialog dialog = (SIPDialog) SerializeUtils.deSerialize(dialogByteArray); + SIPRequest messageRequest = (SIPRequest)dialog.createRequest(Request.MESSAGE); + String characterSet = platform.getCharacterSet(); + StringBuffer mediaStatusXml = new StringBuffer(200); + mediaStatusXml.append("\r\n"); + mediaStatusXml.append("\r\n"); + mediaStatusXml.append("MediaStatus\r\n"); + mediaStatusXml.append("" + (int)((Math.random()*9+1)*100000) + "\r\n"); + mediaStatusXml.append("" + sendRtpItem.getChannelId() + "\r\n"); + mediaStatusXml.append("121\r\n"); + mediaStatusXml.append("\r\n"); + ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); + messageRequest.setContent(mediaStatusXml.toString(), contentTypeHeader); + SipURI sipURI = (SipURI) messageRequest.getRequestURI(); + sipURI.setHost(platform.getServerIP()); + sipURI.setPort(platform.getServerPort()); + + ClientTransaction transaction = null; + if ("TCP".equals(platform.getTransport())) { + transaction = tcpSipProvider.getNewClientTransaction(messageRequest); + } else if ("UDP".equals(platform.getTransport())) { + transaction = udpSipProvider.getNewClientTransaction(messageRequest); + } + transaction.sendRequest(); + } catch (SipException e) { + e.printStackTrace(); + return false; + } catch (ParseException e) { + e.printStackTrace(); + return false; + } + return true; + + + } + @Override public void streamByeCmd(ParentPlatform platform, String callId) { if (platform == null) { @@ -765,41 +815,40 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { SIPDialog sipDialog = ((SipStackImpl) sipStack).putDialog(dialog); if (dialog != sipDialog) { dialog = sipDialog; - } else { - try { - dialog.setSipProvider(udpSipProvider); - Field sipStackField = SIPDialog.class.getDeclaredField("sipStack"); - sipStackField.setAccessible(true); - sipStackField.set(dialog, sipStack); - Field eventListenersField = SIPDialog.class.getDeclaredField("eventListeners"); - eventListenersField.setAccessible(true); - eventListenersField.set(dialog, new HashSet<>()); - - byte[] transactionByteArray = sendRtpItem.getTransaction(); - ClientTransaction clientTransaction = (ClientTransaction) SerializeUtils.deSerialize(transactionByteArray); - Request byeRequest = dialog.createRequest(Request.BYE); - - SipURI byeURI = (SipURI) byeRequest.getRequestURI(); - SIPRequest request = (SIPRequest) clientTransaction.getRequest(); - byeURI.setHost(request.getRemoteAddress().getHostAddress()); - byeURI.setPort(request.getRemotePort()); - if ("TCP".equals(platform.getTransport())) { - clientTransaction = tcpSipProvider.getNewClientTransaction(byeRequest); - } else if ("UDP".equals(platform.getTransport())) { - clientTransaction = udpSipProvider.getNewClientTransaction(byeRequest); - } - dialog.sendRequest(clientTransaction); - } catch (SipException e) { - e.printStackTrace(); - } catch (ParseException e) { - e.printStackTrace(); - } catch (NoSuchFieldException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } + try { + dialog.setSipProvider(udpSipProvider); + Field sipStackField = SIPDialog.class.getDeclaredField("sipStack"); + sipStackField.setAccessible(true); + sipStackField.set(dialog, sipStack); + Field eventListenersField = SIPDialog.class.getDeclaredField("eventListeners"); + eventListenersField.setAccessible(true); + eventListenersField.set(dialog, new HashSet<>()); + + byte[] transactionByteArray = sendRtpItem.getTransaction(); + ClientTransaction clientTransaction = (ClientTransaction) SerializeUtils.deSerialize(transactionByteArray); + Request byeRequest = dialog.createRequest(Request.BYE); + + SipURI byeURI = (SipURI) byeRequest.getRequestURI(); + SIPRequest request = (SIPRequest) clientTransaction.getRequest(); + byeURI.setHost(request.getRemoteAddress().getHostAddress()); + byeURI.setPort(request.getRemotePort()); + if ("TCP".equals(platform.getTransport())) { + clientTransaction = tcpSipProvider.getNewClientTransaction(byeRequest); + } else if ("UDP".equals(platform.getTransport())) { + clientTransaction = udpSipProvider.getNewClientTransaction(byeRequest); + } + dialog.sendRequest(clientTransaction); + } catch (SipException e) { + e.printStackTrace(); + } catch (ParseException e) { + e.printStackTrace(); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } } } 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 e43bf9d1..d967fb94 100644 --- 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 @@ -188,8 +188,8 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements startTime = startTimeFiled.getStartTime(); stopTime = startTimeFiled.getStopTime(); - start = Instant.ofEpochMilli(startTime*1000); - end = Instant.ofEpochMilli(stopTime*1000); + start = Instant.ofEpochSecond(startTime); + end = Instant.ofEpochSecond(stopTime); } // 获取支持的格式 Vector mediaDescriptions = sdp.getMediaDescriptions(true); 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 5cb39734..b758227e 100644 --- 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 @@ -3,13 +3,16 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; +import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction; import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; +import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import org.dom4j.Element; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,9 +41,15 @@ public class MediaStatusNotifyMessageHandler extends SIPRequestProcessorParent i @Autowired private SIPCommander cmder; + @Autowired + private SIPCommanderFroPlatform sipCommanderFroPlatform; + @Autowired private IRedisCatchStorage redisCatchStorage; + @Autowired + private IVideoManagerStorage storage; + @Autowired private VideoStreamSessionManager sessionManager; @@ -64,7 +73,7 @@ public class MediaStatusNotifyMessageHandler extends SIPRequestProcessorParent i } CallIdHeader callIdHeader = (CallIdHeader)evt.getRequest().getHeader(CallIdHeader.NAME); String NotifyType =getText(rootElement, "NotifyType"); - if (NotifyType.equals("121")){ + if ("121".equals(NotifyType)){ logger.info("[录像流]推送完毕,收到关流通知"); // 查询是设备 StreamInfo streamInfo = redisCatchStorage.queryDownload(null, null, null, callIdHeader.getCallId()); @@ -78,8 +87,17 @@ public class MediaStatusNotifyMessageHandler extends SIPRequestProcessorParent i SsrcTransaction ssrcTransaction = sessionManager.getSsrcTransaction(null, null, callIdHeader.getCallId(), null); if (ssrcTransaction != null) { // 兼容海康 媒体通知 消息from字段不是设备ID的问题 cmder.streamByeCmd(device.getDeviceId(), ssrcTransaction.getChannelId(), null, callIdHeader.getCallId()); + // 如果级联播放,需要给上级发送此通知 + SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(null, ssrcTransaction.getChannelId(), null, callIdHeader.getCallId()); + if (sendRtpItem != null) { + ParentPlatform parentPlatform = storage.queryParentPlatByServerGBId(sendRtpItem.getPlatformId()); + if (parentPlatform == null) { + logger.warn("[级联消息发送]:发送MediaStatus发现上级平台{}不存在", sendRtpItem.getPlatformId()); + return; + } + sipCommanderFroPlatform.sendMediaStatusNotify(parentPlatform, sendRtpItem); + } } - // TODO 如果级联播放,需要给上级发送此通知 } } diff --git a/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java b/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java index 3235a49f..494bcbbb 100644 --- a/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java +++ b/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java @@ -32,12 +32,14 @@ public class DateUtil { */ public static final String PATTERN = "yyyy-MM-dd HH:mm:ss"; + public static final String zoneStr = "Asia/Shanghai"; - public static final DateTimeFormatter formatterCompatibleISO8601 = DateTimeFormatter.ofPattern(ISO8601_COMPATIBLE_PATTERN, Locale.getDefault()).withZone(ZoneId.systemDefault()); - public static final DateTimeFormatter formatterISO8601 = DateTimeFormatter.ofPattern(ISO8601_PATTERN, Locale.getDefault()).withZone(ZoneId.systemDefault()); - public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(PATTERN, Locale.getDefault()).withZone(ZoneId.systemDefault()); + public static final DateTimeFormatter formatterCompatibleISO8601 = DateTimeFormatter.ofPattern(ISO8601_COMPATIBLE_PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr)); + public static final DateTimeFormatter formatterISO8601 = DateTimeFormatter.ofPattern(ISO8601_PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr)); + public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr)); public static String yyyy_MM_dd_HH_mm_ssToISO8601(String formatTime) { + return formatterISO8601.format(formatter.parse(formatTime)); }