From ecf4fbb68445cf412d5e946f67f92c9928df8273 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期一, 22 八月 2022 16:53:16 +0800 Subject: [PATCH] Merge branch 'wvp-28181-2.0' --- src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java | 149 ++++++++++++++++++++++++++++++++----------------- 1 files changed, 97 insertions(+), 52 deletions(-) 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 6c06bd3..e767b4f 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 @@ -4,7 +4,6 @@ import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderPlarformProvider; -import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.service.IMediaServerService; @@ -24,14 +23,16 @@ import org.springframework.context.annotation.Lazy; import org.springframework.lang.Nullable; import org.springframework.stereotype.Component; +import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; + +import com.genersoft.iot.vmp.utils.DateUtil; import javax.sip.*; import javax.sip.address.SipURI; import javax.sip.header.*; import javax.sip.message.Request; import java.lang.reflect.Field; -import java.net.InetAddress; import java.text.ParseException; import java.util.ArrayList; import java.util.HashSet; @@ -105,7 +106,7 @@ } request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, - redisCatchStorage.getCSEQ(Request.REGISTER), "FromRegister" + tm, + redisCatchStorage.getCSEQ(), "FromRegister" + tm, "z9hG4bK-" + UUID.randomUUID().toString().replace("-", ""), callIdHeader); // 灏� callid 鍐欏叆缂撳瓨锛� 绛夋敞鍐屾垚鍔熷彲浠ユ洿鏂扮姸鎬� String callIdFromHeader = callIdHeader.getCallId(); @@ -257,37 +258,37 @@ catalogXml.append("<DeviceList Num=\"" + channels.size() +"\">\r\n"); if (channels.size() > 0) { for (DeviceChannel channel : channels) { + if (parentPlatform.getServerGBId().equals(channel.getParentId())) { + channel.setParentId(parentPlatform.getDeviceGBId()); + } catalogXml.append("<Item>\r\n"); + // 琛屾斂鍖哄垝鍒嗙粍鍙渶瑕佽繖涓ら」灏卞彲浠� catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n"); catalogXml.append("<Name>" + channel.getName() + "</Name>\r\n"); - catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n"); if (channel.getParentId() != null) { + // 涓氬姟鍒嗙粍鍔犱笂杩欎竴椤瑰嵆鍙紝鎻愰珮鍏煎鎬э紝 catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n"); } - if (channel.getChannelId().length() == 20) { - if (Integer.parseInt(channel.getChannelId().substring(10, 13)) == 216) { // 铏氭嫙缁勭粐澧炲姞BusinessGroupID瀛楁 - catalogXml.append("<BusinessGroupID>" + channel.getParentId() + "</BusinessGroupID>\r\n"); - } + if (channel.getChannelId().length() == 20 && Integer.parseInt(channel.getChannelId().substring(10, 13)) == 216) { + // 铏氭嫙缁勭粐澧炲姞BusinessGroupID瀛楁 + catalogXml.append("<BusinessGroupID>" + channel.getParentId() + "</BusinessGroupID>\r\n"); + } + catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n"); + if (channel.getParental() == 0) { + // 閫氶亾椤� catalogXml.append("<Manufacturer>" + channel.getManufacture() + "</Manufacturer>\r\n"); + catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n"); catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n"); - catalogXml.append("<Status>" + (channel.getStatus() == 0?"OFF":"ON") + "</Status>\r\n"); - if (channel.getChannelType() != 2) { // 涓氬姟鍒嗙粍/铏氭嫙缁勭粐/琛屾斂鍖哄垝 涓嶈缃互涓嬪瓧娈� - catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n"); + catalogXml.append("<Status>" + (channel.getStatus() == 0 ? "OFF" : "ON") + "</Status>\r\n"); + + if (channel.getChannelType() != 2) { // 涓氬姟鍒嗙粍/铏氭嫙缁勭粐/琛屾斂鍖哄垝 涓嶈缃互涓嬪睘鎬� catalogXml.append("<Model>" + channel.getModel() + "</Model>\r\n"); - catalogXml.append("<Owner>" + channel.getOwner() + "</Owner>\r\n"); + catalogXml.append("<Owner> " + channel.getOwner()+ "</Owner>\r\n"); catalogXml.append("<CivilCode>" + channel.getCivilCode() + "</CivilCode>\r\n"); catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n"); - catalogXml.append("<Longitude>" + channel.getLongitude() + "</Longitude>\r\n"); - catalogXml.append("<Latitude>" + channel.getLatitude() + "</Latitude>\r\n"); - catalogXml.append("<IPAddress>" + channel.getIpAddress() + "</IPAddress>\r\n"); - catalogXml.append("<Port>" + channel.getPort() + "</Port>\r\n"); - catalogXml.append("<Info>\r\n"); - catalogXml.append("<PTZType>" + channel.getPTZType() + "</PTZType>\r\n"); - catalogXml.append("</Info>\r\n"); } + } - - catalogXml.append("</Item>\r\n"); } } @@ -406,7 +407,10 @@ if (parentPlatform == null) { return false; } - logger.info("[鍙戦�� 绉诲姩浣嶇疆璁㈤槄] {}/{}->{},{}", parentPlatform.getServerGBId(), gpsMsgInfo.getId(), gpsMsgInfo.getLng(), gpsMsgInfo.getLat()); + if (logger.isDebugEnabled()) { + logger.debug("[鍙戦�� 绉诲姩浣嶇疆璁㈤槄] {}/{}->{},{}", parentPlatform.getServerGBId(), gpsMsgInfo.getId(), gpsMsgInfo.getLng(), gpsMsgInfo.getLat()); + } + try { String characterSet = parentPlatform.getCharacterSet(); StringBuffer deviceStatusXml = new StringBuffer(600); @@ -589,27 +593,35 @@ channel.setParentId(parentPlatform.getDeviceGBId()); } catalogXml.append("<Item>\r\n"); + // 琛屾斂鍖哄垝鍒嗙粍鍙渶瑕佽繖涓ら」灏卞彲浠� catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n"); catalogXml.append("<Name>" + channel.getName() + "</Name>\r\n"); - catalogXml.append("<Manufacturer>" + channel.getManufacture() + "</Manufacturer>\r\n"); - catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n"); if (channel.getParentId() != null) { + // 涓氬姟鍒嗙粍鍔犱笂杩欎竴椤瑰嵆鍙紝鎻愰珮鍏煎鎬э紝 catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n"); } - catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n"); - catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n"); - catalogXml.append("<Status>" + (channel.getStatus() == 0 ? "OFF" : "ON") + "</Status>\r\n"); - if (channel.getChannelId().length() == 20 && Integer.parseInt(channel.getChannelId().substring(10, 13)) == 216) { // 铏氭嫙缁勭粐澧炲姞BusinessGroupID瀛楁 + if (channel.getChannelId().length() == 20 && Integer.parseInt(channel.getChannelId().substring(10, 13)) == 216) { + // 铏氭嫙缁勭粐澧炲姞BusinessGroupID瀛楁 catalogXml.append("<BusinessGroupID>" + channel.getParentId() + "</BusinessGroupID>\r\n"); } - if (channel.getChannelType() == 2) { // 涓氬姟鍒嗙粍/铏氭嫙缁勭粐/琛屾斂鍖哄垝 涓嶈缃互涓嬪睘鎬� - catalogXml.append("<Model>" + channel.getModel() + "</Model>\r\n"); - catalogXml.append("<Owner>0</Owner>\r\n"); - catalogXml.append("<CivilCode>CivilCode</CivilCode>\r\n"); - catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n"); - } - if (!"presence".equals(subscribeInfo.getEventType())) { - catalogXml.append("<Event>" + type + "</Event>\r\n"); + catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n"); + if (channel.getParental() == 0) { + // 閫氶亾椤� + catalogXml.append("<Manufacturer>" + channel.getManufacture() + "</Manufacturer>\r\n"); + catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n"); + catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n"); + catalogXml.append("<Status>" + (channel.getStatus() == 0 ? "OFF" : "ON") + "</Status>\r\n"); + + if (channel.getChannelType() != 2) { // 涓氬姟鍒嗙粍/铏氭嫙缁勭粐/琛屾斂鍖哄垝 涓嶈缃互涓嬪睘鎬� + catalogXml.append("<Model>" + channel.getModel() + "</Model>\r\n"); + catalogXml.append("<Owner> " + channel.getOwner()+ "</Owner>\r\n"); + catalogXml.append("<CivilCode>" + channel.getCivilCode() + "</CivilCode>\r\n"); + catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n"); + } + if (!"presence".equals(subscribeInfo.getEventType())) { + catalogXml.append("<Event>" + type + "</Event>\r\n"); + } + } catalogXml.append("</Item>\r\n"); } @@ -717,10 +729,10 @@ recordXml.append("<EndTime>" + DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(recordItem.getEndTime()) + "</EndTime>\r\n"); recordXml.append("<Secrecy>" + recordItem.getSecrecy() + "</Secrecy>\r\n"); recordXml.append("<Type>" + recordItem.getType() + "</Type>\r\n"); - if (!StringUtils.isEmpty(recordItem.getFileSize())) { + if (!ObjectUtils.isEmpty(recordItem.getFileSize())) { recordXml.append("<FileSize>" + recordItem.getFileSize() + "</FileSize>\r\n"); } - if (!StringUtils.isEmpty(recordItem.getFilePath())) { + if (!ObjectUtils.isEmpty(recordItem.getFilePath())) { recordXml.append("<FilePath>" + recordItem.getFilePath() + "</FilePath>\r\n"); } } @@ -760,6 +772,29 @@ } try{ SIPDialog dialog = (SIPDialog) SerializeUtils.deSerialize(dialogByteArray); + SipStack sipStack; + if ("TCP".equals(platform.getTransport())) { + sipStack = tcpSipProvider.getSipStack(); + } else { + sipStack = udpSipProvider.getSipStack(); + } + SIPDialog sipDialog = ((SipStackImpl) sipStack).putDialog(dialog); + if (dialog != sipDialog) { + dialog = sipDialog; + } + if ("TCP".equals(platform.getTransport())) { + dialog.setSipProvider(tcpSipProvider); + } else { + 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<>()); + SIPRequest messageRequest = (SIPRequest)dialog.createRequest(Request.MESSAGE); String characterSet = platform.getCharacterSet(); StringBuffer mediaStatusXml = new StringBuffer(200); @@ -775,20 +810,23 @@ SipURI sipURI = (SipURI) messageRequest.getRequestURI(); sipURI.setHost(platform.getServerIP()); sipURI.setPort(platform.getServerPort()); - - ClientTransaction transaction = null; + ClientTransaction clientTransaction; if ("TCP".equals(platform.getTransport())) { - transaction = tcpSipProvider.getNewClientTransaction(messageRequest); - } else if ("UDP".equals(platform.getTransport())) { - transaction = udpSipProvider.getNewClientTransaction(messageRequest); + clientTransaction = tcpSipProvider.getNewClientTransaction(messageRequest); + }else { + clientTransaction = udpSipProvider.getNewClientTransaction(messageRequest); } - transaction.sendRequest(); + dialog.sendRequest(clientTransaction); } catch (SipException e) { e.printStackTrace(); return false; } catch (ParseException e) { e.printStackTrace(); return false; + } catch (NoSuchFieldException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); } return true; @@ -811,13 +849,22 @@ byte[] dialogByteArray = sendRtpItem.getDialog(); if (dialogByteArray != null) { SIPDialog dialog = (SIPDialog) SerializeUtils.deSerialize(dialogByteArray); - SipStack sipStack = udpSipProvider.getSipStack(); + SipStack sipStack; + if ("TCP".equals(platform.getTransport())) { + sipStack = tcpSipProvider.getSipStack(); + } else { + sipStack = udpSipProvider.getSipStack(); + } SIPDialog sipDialog = ((SipStackImpl) sipStack).putDialog(dialog); if (dialog != sipDialog) { dialog = sipDialog; } try { - dialog.setSipProvider(udpSipProvider); + if ("TCP".equals(platform.getTransport())) { + dialog.setSipProvider(tcpSipProvider); + } else { + dialog.setSipProvider(udpSipProvider); + } Field sipStackField = SIPDialog.class.getDeclaredField("sipStack"); sipStackField.setAccessible(true); sipStackField.set(dialog, sipStack); @@ -825,17 +872,15 @@ 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()); + byeURI.setHost(platform.getServerIP()); + byeURI.setPort(platform.getServerPort()); + ClientTransaction clientTransaction; if ("TCP".equals(platform.getTransport())) { clientTransaction = tcpSipProvider.getNewClientTransaction(byeRequest); - } else if ("UDP".equals(platform.getTransport())) { + } else { clientTransaction = udpSipProvider.getNewClientTransaction(byeRequest); } dialog.sendRequest(clientTransaction); -- Gitblit v1.8.0