From 221f99c764b51c3cd284c6e5a41492c26c5c7ffc Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Fri, 9 Sep 2022 17:06:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96sip=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cmd/SIPRequestHeaderPlarformProvider.java | 62 ++-------- .../cmd/SIPRequestHeaderProvider.java | 25 ++-- .../transmit/cmd/impl/SIPCommander.java | 117 +++++------------- .../cmd/impl/SIPCommanderFroPlatform.java | 40 +++--- .../query/cmd/CatalogQueryMessageHandler.java | 20 +++ .../impl/InviteResponseProcessor.java | 10 +- .../iot/vmp/gb28181/utils/HeaderUtils.java | 22 ---- .../iot/vmp/gb28181/utils/SipUtils.java | 28 +++++ .../iot/vmp/service/impl/PlayServiceImpl.java | 2 + web_src/src/components/channelList.vue | 1 + 10 files changed, 128 insertions(+), 199 deletions(-) delete mode 100644 src/main/java/com/genersoft/iot/vmp/gb28181/utils/HeaderUtils.java diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java index a689b2b4..2f3be356 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java @@ -2,8 +2,7 @@ package com.genersoft.iot.vmp.gb28181.transmit.cmd; import com.genersoft.iot.vmp.conf.SipConfig; import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; -import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo; -import com.genersoft.iot.vmp.gb28181.utils.HeaderUtils; +import com.genersoft.iot.vmp.gb28181.utils.SipUtils; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import gov.nist.javax.sip.message.MessageFactoryImpl; import org.springframework.beans.factory.annotation.Autowired; @@ -38,44 +37,6 @@ public class SIPRequestHeaderPlarformProvider { @Autowired private IRedisCatchStorage redisCatchStorage; - - public Request createKeetpaliveMessageRequest(ParentPlatform parentPlatform, String content, String viaTag, String fromTag, String toTag, CallIdHeader callIdHeader) throws ParseException, InvalidArgumentException, PeerUnavailableException { - Request request = null; - // sipuri - SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP() + ":" + parentPlatform.getServerPort()); - // via - ArrayList viaHeaders = new ArrayList(); - ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getIp(), sipConfig.getPort(), - parentPlatform.getTransport(), viaTag); - viaHeader.setRPort(); - viaHeaders.add(viaHeader); - // from - SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getDeviceGBId(), - sipConfig.getIp() + ":" + sipConfig.getPort()); - Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); - FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); - // to - SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP() + ":" + parentPlatform.getServerPort() ); - Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); - ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag); - - - // Forwards - MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70); - // ceq - CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(), Request.MESSAGE); - - request = sipFactory.createMessageFactory().createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader, - toHeader, viaHeaders, maxForwards); - - List agentParam = new ArrayList<>(); - - ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); - request.setContent(content, contentTypeHeader); - return request; - } - - public Request createRegisterRequest(@NotNull ParentPlatform platform, long CSeq, String fromTag, String viaTag, CallIdHeader callIdHeader, boolean isRegister) throws ParseException, InvalidArgumentException, PeerUnavailableException { Request request = null; String sipAddress = sipConfig.getIp() + ":" + sipConfig.getPort(); @@ -88,16 +49,14 @@ public class SIPRequestHeaderPlarformProvider { viaHeader.setRPort(); viaHeaders.add(viaHeader); //from - SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(platform.getDeviceGBId(),sipAddress); + SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(platform.getDeviceGBId(), sipConfig.getDomain()); Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); //to - SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(platform.getDeviceGBId(),sipAddress); + SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(platform.getDeviceGBId(), sipConfig.getDomain()); Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,null); - - //Forwards MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70); @@ -113,7 +72,7 @@ public class SIPRequestHeaderPlarformProvider { ExpiresHeader expires = sipFactory.createHeaderFactory().createExpiresHeader(isRegister ? platform.getExpires() : 0); request.addHeader(expires); - UserAgentHeader userAgentHeader = HeaderUtils.createUserAgentHeader(sipFactory); + UserAgentHeader userAgentHeader = SipUtils.createUserAgentHeader(sipFactory); request.addHeader(userAgentHeader); return request; @@ -193,23 +152,24 @@ public class SIPRequestHeaderPlarformProvider { } - public Request createMessageRequest(ParentPlatform parentPlatform, String content, String fromTag, CallIdHeader callIdHeader) throws PeerUnavailableException, ParseException, InvalidArgumentException { + public Request createMessageRequest(ParentPlatform parentPlatform, String content, String fromTag, String viaTag, CallIdHeader callIdHeader) throws PeerUnavailableException, ParseException, InvalidArgumentException { Request request = null; + String serverAddress = parentPlatform.getServerIP()+ ":" + parentPlatform.getServerPort(); // sipuri - SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP()+ ":" + parentPlatform.getServerPort()); + SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), serverAddress); // via ArrayList viaHeaders = new ArrayList(); ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(parentPlatform.getDeviceIp(), Integer.parseInt(parentPlatform.getDevicePort()), - parentPlatform.getTransport(), null); + parentPlatform.getTransport(), viaTag); viaHeader.setRPort(); viaHeaders.add(viaHeader); // from - SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getDeviceGBId(), - parentPlatform.getDeviceIp() + ":" + parentPlatform.getDevicePort()); + // SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getDeviceGBId(), parentPlatform.getDeviceIp() + ":" + parentPlatform.getDeviceIp()); + SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getDeviceGBId(), sipConfig.getDomain()); Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); // to - SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerGBDomain()); + SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), serverAddress); Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, null); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java index 8af80a33..807afb42 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java @@ -2,7 +2,6 @@ package com.genersoft.iot.vmp.gb28181.transmit.cmd; import java.text.ParseException; import java.util.ArrayList; -import java.util.List; import javax.sip.*; import javax.sip.address.Address; @@ -12,7 +11,7 @@ import javax.sip.message.Request; import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; -import com.genersoft.iot.vmp.gb28181.utils.HeaderUtils; +import com.genersoft.iot.vmp.gb28181.utils.SipUtils; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import gov.nist.javax.sip.SipProviderImpl; import gov.nist.javax.sip.SipStackImpl; @@ -62,12 +61,11 @@ public class SIPRequestHeaderProvider { viaHeader.setRPort(); viaHeaders.add(viaHeader); // from - SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), - sipConfig.getIp() + ":" + sipConfig.getPort()); + SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getDomain()); Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); // to - SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), sipConfig.getDomain()); + SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress()); Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag); @@ -94,11 +92,11 @@ public class SIPRequestHeaderProvider { viaHeaders.add(viaHeader); //from - SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(),sipConfig.getDomain()); + SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getDomain()); Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack //to - SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId,sipConfig.getDomain()); + SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId, device.getHostAddress()); Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,null); @@ -130,11 +128,11 @@ public class SIPRequestHeaderProvider { viaHeader.setRPort(); viaHeaders.add(viaHeader); //from - SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(),sipConfig.getDomain()); + SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getDomain()); Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack //to - SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId, sipConfig.getDomain()); + SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId, device.getHostAddress()); Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,null); @@ -170,7 +168,7 @@ public class SIPRequestHeaderProvider { Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack //to - SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId,sipConfig.getDomain()); + SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId,device.getHostAddress()); Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,toTag); @@ -198,12 +196,11 @@ public class SIPRequestHeaderProvider { viaHeader.setRPort(); viaHeaders.add(viaHeader); // from - SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), - sipConfig.getIp() + ":" + sipConfig.getPort()); + SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getDomain()); Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); // to - SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), sipConfig.getDomain()); + SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress()); Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag); @@ -267,7 +264,7 @@ public class SIPRequestHeaderProvider { Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory() .createSipURI(sipConfig.getId(), sipConfig.getIp() + ":" + sipConfig.getPort())); infoRequest.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); - UserAgentHeader userAgentHeader = HeaderUtils.createUserAgentHeader(sipFactory); + UserAgentHeader userAgentHeader = SipUtils.createUserAgentHeader(sipFactory); infoRequest.addHeader(userAgentHeader); ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java index aa57f256..a80745d8 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java @@ -10,7 +10,7 @@ import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider; -import com.genersoft.iot.vmp.gb28181.utils.HeaderUtils; +import com.genersoft.iot.vmp.gb28181.utils.SipUtils; import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange; import com.genersoft.iot.vmp.utils.DateUtil; @@ -244,13 +244,11 @@ public class SIPCommander implements ISIPCommander { ptzXml.append("5\r\n"); ptzXml.append("\r\n"); ptzXml.append("\r\n"); - - String tm = Long.toString(System.currentTimeMillis()); CallIdHeader callIdHeader = device.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "z9hG4bK-ViaPtz-" + tm, "FromPtz" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request); return true; @@ -288,12 +286,11 @@ public class SIPCommander implements ISIPCommander { ptzXml.append("\r\n"); ptzXml.append("\r\n"); - String tm = Long.toString(System.currentTimeMillis()); CallIdHeader callIdHeader = device.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "z9hG4bK-ViaPtz-" + tm, "FromPtz" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request); return true; } catch (SipException | ParseException | InvalidArgumentException e) { @@ -324,12 +321,11 @@ public class SIPCommander implements ISIPCommander { ptzXml.append("\r\n"); ptzXml.append("\r\n"); - String tm = Long.toString(System.currentTimeMillis()); CallIdHeader callIdHeader = device.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "z9hG4bK-ViaPtz-" + tm, "FromPtz" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request, errorEvent, okEvent); return true; } catch (SipException | ParseException | InvalidArgumentException e) { @@ -421,12 +417,10 @@ public class SIPCommander implements ISIPCommander { // f字段:f= v/编码格式/分辨率/帧率/码率类型/码率大小a/编码格式/码率大小/采样率 // content.append("f=v/2/5/25/1/4000a/1/8/1" + "\r\n"); // 未发现支持此特性的设备 - String tm = Long.toString(System.currentTimeMillis()); - CallIdHeader callIdHeader = device.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "FromInvt" + tm, null, ssrcInfo.getSsrc(), callIdHeader); + Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, SipUtils.getNewFromTag(), null, ssrcInfo.getSsrc(), callIdHeader); transmitRequest(device, request, (e -> { streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream()); @@ -519,8 +513,6 @@ public class SIPCommander implements ISIPCommander { } content.append("y=" + ssrcInfo.getSsrc() + "\r\n");//ssrc - - String tm = Long.toString(System.currentTimeMillis()); CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); @@ -533,7 +525,7 @@ public class SIPCommander implements ISIPCommander { } subscribe.removeSubscribe(hookSubscribe); }); - Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "fromplybck" + tm, null, callIdHeader, ssrcInfo.getSsrc()); + Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, SipUtils.getNewFromTag(), null, callIdHeader, ssrcInfo.getSsrc()); transmitRequest(device, request, errorEvent, event -> { ResponseEvent responseEvent = (ResponseEvent) event.event; @@ -625,8 +617,6 @@ public class SIPCommander implements ISIPCommander { content.append("a=downloadspeed:" + downloadSpeed + "\r\n"); content.append("y=" + ssrcInfo.getSsrc() + "\r\n");//ssrc - - String tm = Long.toString(System.currentTimeMillis()); CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); @@ -649,7 +639,7 @@ public class SIPCommander implements ISIPCommander { }); }); - Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "fromplybck" + tm, null, callIdHeader, ssrcInfo.getSsrc()); + Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, SipUtils.getNewFromTag(), null, callIdHeader, ssrcInfo.getSsrc()); if (inviteStreamCallback != null) { inviteStreamCallback.call(new InviteStreamInfo(mediaServerItem, null, callIdHeader.getCallId(), "rtp", ssrcInfo.getStream())); } @@ -737,7 +727,7 @@ public class SIPCommander implements ISIPCommander { // 增加Contact header Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort())); byeRequest.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); - UserAgentHeader userAgentHeader = HeaderUtils.createUserAgentHeader(sipFactory); + UserAgentHeader userAgentHeader = SipUtils.createUserAgentHeader(sipFactory); byeRequest.addHeader(userAgentHeader); ClientTransaction clientTransaction = null; if("TCP".equals(protocol)) { @@ -790,13 +780,11 @@ public class SIPCommander implements ISIPCommander { broadcastXml.append("" + sipConfig.getId() + "\r\n"); broadcastXml.append("" + device.getDeviceId() + "\r\n"); broadcastXml.append("\r\n"); - - String tm = Long.toString(System.currentTimeMillis()); - + CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, broadcastXml.toString(), "z9hG4bK-ViaBcst-" + tm, "FromBcst" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, broadcastXml.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request); return true; } catch (SipException | ParseException | InvalidArgumentException e) { @@ -816,13 +804,11 @@ public class SIPCommander implements ISIPCommander { broadcastXml.append("" + sipConfig.getId() + "\r\n"); broadcastXml.append("" + device.getDeviceId() + "\r\n"); broadcastXml.append("\r\n"); - - String tm = Long.toString(System.currentTimeMillis()); CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, broadcastXml.toString(), "z9hG4bK-ViaBcst-" + tm, "FromBcst" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, broadcastXml.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request, errorEvent); } catch (SipException | ParseException | InvalidArgumentException e) { e.printStackTrace(); @@ -853,13 +839,11 @@ public class SIPCommander implements ISIPCommander { } cmdXml.append("" + recordCmdStr + "\r\n"); cmdXml.append("\r\n"); - - String tm = Long.toString(System.currentTimeMillis()); CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromRecord" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request, errorEvent); return true; } catch (SipException | ParseException | InvalidArgumentException e) { @@ -885,13 +869,11 @@ public class SIPCommander implements ISIPCommander { cmdXml.append("" + device.getDeviceId() + "\r\n"); cmdXml.append("Boot\r\n"); cmdXml.append("\r\n"); - - String tm = Long.toString(System.currentTimeMillis()); CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromBoot" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request); return true; } catch (SipException | ParseException | InvalidArgumentException e) { @@ -918,13 +900,11 @@ public class SIPCommander implements ISIPCommander { cmdXml.append("" + device.getDeviceId() + "\r\n"); cmdXml.append("" + guardCmdStr + "\r\n"); cmdXml.append("\r\n"); - - String tm = Long.toString(System.currentTimeMillis()); CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromGuard" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request, errorEvent); return true; } catch (SipException | ParseException | InvalidArgumentException e) { @@ -962,13 +942,11 @@ public class SIPCommander implements ISIPCommander { cmdXml.append("\r\n"); } cmdXml.append("\r\n"); - - String tm = Long.toString(System.currentTimeMillis()); CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromAlarm" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request, errorEvent); return true; } catch (SipException | ParseException | InvalidArgumentException e) { @@ -999,13 +977,11 @@ public class SIPCommander implements ISIPCommander { } cmdXml.append("Send\r\n"); cmdXml.append("\r\n"); - - String tm = Long.toString(System.currentTimeMillis()); CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromBoot" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request); return true; } catch (SipException | ParseException | InvalidArgumentException e) { @@ -1054,13 +1030,11 @@ public class SIPCommander implements ISIPCommander { } cmdXml.append("\r\n"); cmdXml.append("\r\n"); - - String tm = Long.toString(System.currentTimeMillis()); CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromGuard" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request, errorEvent); return true; } catch (SipException | ParseException | InvalidArgumentException e) { @@ -1126,13 +1100,11 @@ public class SIPCommander implements ISIPCommander { } cmdXml.append("\r\n"); cmdXml.append("\r\n"); - - String tm = Long.toString(System.currentTimeMillis()); CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromConfig" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request, errorEvent); return true; } catch (SipException | ParseException | InvalidArgumentException e) { @@ -1157,13 +1129,11 @@ public class SIPCommander implements ISIPCommander { catalogXml.append("" + (int)((Math.random()*9+1)*100000) + "\r\n"); catalogXml.append("" + device.getDeviceId() + "\r\n"); catalogXml.append("\r\n"); - - String tm = Long.toString(System.currentTimeMillis()); CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), null, "FromStatus" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), null, SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request, errorEvent); return true; @@ -1190,13 +1160,11 @@ public class SIPCommander implements ISIPCommander { catalogXml.append("" + (int)((Math.random()*9+1)*100000) + "\r\n"); catalogXml.append("" + device.getDeviceId() + "\r\n"); catalogXml.append("\r\n"); - - String tm = Long.toString(System.currentTimeMillis()); CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "z9hG4bK-ViaDeviceInfo-" + tm, "FromDev" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request); @@ -1223,13 +1191,11 @@ public class SIPCommander implements ISIPCommander { catalogXml.append(" " + sn + "\r\n"); catalogXml.append(" " + device.getDeviceId() + "\r\n"); catalogXml.append("\r\n"); - - String tm = Long.toString(System.currentTimeMillis()); CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "z9hG4bK" + tm, tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request, errorEvent); } catch (SipException | ParseException | InvalidArgumentException e) { @@ -1277,13 +1243,11 @@ public class SIPCommander implements ISIPCommander { } recordInfoXml.append("\r\n"); - String tm = Long.toString(System.currentTimeMillis()); - CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); Request request = headerProvider.createMessageRequest(device, recordInfoXml.toString(), - "z9hG4bK-ViaRecordInfo-" + tm, "fromRec" + tm, null, callIdHeader); + SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request, errorEvent, okEvent); } catch (SipException | ParseException | InvalidArgumentException e) { @@ -1336,12 +1300,10 @@ public class SIPCommander implements ISIPCommander { } cmdXml.append("\r\n"); - String tm = Long.toString(System.currentTimeMillis()); - CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromAlarm" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request, errorEvent); return true; } catch (SipException | ParseException | InvalidArgumentException e) { @@ -1374,12 +1336,10 @@ public class SIPCommander implements ISIPCommander { cmdXml.append("" + configType + "\r\n"); cmdXml.append("\r\n"); - String tm = Long.toString(System.currentTimeMillis()); - CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromConfig" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request, errorEvent); return true; } catch (SipException | ParseException | InvalidArgumentException e) { @@ -1409,12 +1369,10 @@ public class SIPCommander implements ISIPCommander { } cmdXml.append("\r\n"); - String tm = Long.toString(System.currentTimeMillis()); - CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromConfig" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request, errorEvent); return true; } catch (SipException | ParseException | InvalidArgumentException e) { @@ -1441,12 +1399,10 @@ public class SIPCommander implements ISIPCommander { mobilePostitionXml.append("60\r\n"); mobilePostitionXml.append("\r\n"); - String tm = Long.toString(System.currentTimeMillis()); - CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, mobilePostitionXml.toString(), "z9hG4bK-viaPos-" + tm, "fromTagPos" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, mobilePostitionXml.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request, errorEvent); @@ -1495,10 +1451,9 @@ public class SIPCommander implements ISIPCommander { request.removeHeader(CSeqHeader.NAME); request.addHeader(cSeqHeader); }else { - String tm = Long.toString(System.currentTimeMillis()); CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - request = headerProvider.createSubscribeRequest(device, subscribePostitionXml.toString(), "z9hG4bK-viaPos-" + tm, "fromTagPos" + tm, null, device.getSubscribeCycleForMobilePosition(), "presence" ,callIdHeader); //Position;id=" + tm.substring(tm.length() - 4)); + request = headerProvider.createSubscribeRequest(device, subscribePostitionXml.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, device.getSubscribeCycleForMobilePosition(), "presence" ,callIdHeader); //Position;id=" + tm.substring(tm.length() - 4)); } transmitRequest(device, request, errorEvent, okEvent); @@ -1553,12 +1508,10 @@ public class SIPCommander implements ISIPCommander { } cmdXml.append("\r\n"); - String tm = Long.toString(System.currentTimeMillis()); - CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createSubscribeRequest(device, cmdXml.toString(), "z9hG4bK-viaPos-" + tm, "fromTagPos" + tm, null, expires, "presence" , callIdHeader); + Request request = headerProvider.createSubscribeRequest(device, cmdXml.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, expires, "presence" , callIdHeader); transmitRequest(device, request); return true; @@ -1600,14 +1553,12 @@ public class SIPCommander implements ISIPCommander { request.addHeader(cSeqHeader); }else { - String tm = Long.toString(System.currentTimeMillis()); - CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); // 有效时间默认为60秒以上 - request = headerProvider.createSubscribeRequest(device, cmdXml.toString(), "z9hG4bK-viaPos-" + tm, - "fromTagPos" + tm, null, device.getSubscribeCycleForCatalog(), "Catalog" , + request = headerProvider.createSubscribeRequest(device, cmdXml.toString(), SipUtils.getNewViaTag(), + SipUtils.getNewFromTag(), null, device.getSubscribeCycleForCatalog(), "Catalog" , callIdHeader); } @@ -1636,10 +1587,9 @@ public class SIPCommander implements ISIPCommander { } dragXml.append(cmdString); dragXml.append("\r\n"); - String tm = Long.toString(System.currentTimeMillis()); CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProvider.createMessageRequest(device, dragXml.toString(), "z9hG4bK-ViaPtz-" + tm, "FromPtz" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, dragXml.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, callIdHeader); logger.debug("拉框信令: " + request.toString()); transmitRequest(device, request); return true; @@ -1668,7 +1618,7 @@ public class SIPCommander implements ISIPCommander { if (request.getHeader(UserAgentHeader.NAME) == null) { UserAgentHeader userAgentHeader = null; try { - userAgentHeader = HeaderUtils.createUserAgentHeader(sipFactory); + userAgentHeader = SipUtils.createUserAgentHeader(sipFactory); } catch (ParseException e) { logger.error("添加UserAgentHeader失败", e); } @@ -1883,8 +1833,7 @@ public class SIPCommander implements ISIPCommander { CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - String tm = Long.toString(System.currentTimeMillis()); - Request request = headerProvider.createMessageRequest(device, deviceStatusXml.toString(), "z9hG4bK-ViaPtz-" + tm, "FromPtz" + tm, null, callIdHeader); + Request request = headerProvider.createMessageRequest(device, deviceStatusXml.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, callIdHeader); transmitRequest(device, request); 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 d58f778d..4ab4d7fe 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,6 +4,7 @@ import com.genersoft.iot.vmp.gb28181.bean.*; 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.gb28181.utils.SipUtils; import com.genersoft.iot.vmp.storager.dao.dto.PlatformRegisterInfo; import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; @@ -26,19 +27,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 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; import java.util.List; -import java.util.UUID; @Component @DependsOn("sipLayer") @@ -89,7 +87,6 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent, boolean registerAgain, boolean isRegister) { try { Request request; - String tm = Long.toString(System.currentTimeMillis()); if (!registerAgain ) { CallIdHeader callIdHeader = null; if(parentPlatform.getTransport().equalsIgnoreCase("TCP")) { @@ -100,8 +97,8 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { } request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, - redisCatchStorage.getCSEQ(), "FromRegister" + tm, - "z9hG4bK-" + UUID.randomUUID().toString().replace("-", ""), callIdHeader, isRegister); + redisCatchStorage.getCSEQ(), SipUtils.getNewFromTag(), + SipUtils.getNewViaTag(), callIdHeader, isRegister); // 将 callid 写入缓存, 等注册成功可以更新状态 String callIdFromHeader = callIdHeader.getCallId(); redisCatchStorage.updatePlatformRegisterInfo(callIdFromHeader, PlatformRegisterInfo.getInstance(parentPlatform.getServerGBId(), isRegister)); @@ -121,7 +118,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { }else { CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, "FromRegister" + tm, null, callId, www, callIdHeader, isRegister); + request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, SipUtils.getNewFromTag(), null, callId, www, callIdHeader, isRegister); } transmitRequest(parentPlatform, request, null, okEvent); @@ -155,12 +152,11 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProviderPlarformProvider.createKeetpaliveMessageRequest( + Request request = headerProviderPlarformProvider.createMessageRequest( parentPlatform, keepaliveXml.toString(), - "z9hG4bK-" + UUID.randomUUID().toString().replace("-", ""), - UUID.randomUUID().toString().replace("-", ""), - null, + SipUtils.getNewFromTag(), + SipUtils.getNewViaTag(), callIdHeader); transmitRequest(parentPlatform, request, errorEvent, okEvent); callId = callIdHeader.getCallId(); @@ -222,7 +218,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, catalogXml.toString(), fromTag, callIdHeader); + Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, catalogXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader); transmitRequest(parentPlatform, request); } catch (SipException | ParseException | InvalidArgumentException e) { @@ -267,13 +263,18 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { // 虚拟组织增加BusinessGroupID字段 catalogXml.append("" + channel.getParentId() + "\r\n"); } - catalogXml.append("" + channel.getParental() + "\r\n"); + if (!channel.getChannelId().equals(parentPlatform.getDeviceGBId())) { + catalogXml.append("" + channel.getParental() + "\r\n"); + if (channel.getParental() == 0) { + catalogXml.append("" + (channel.getStatus() == 0 ? "OFF" : "ON") + "\r\n"); + } + + } if (channel.getParental() == 0) { // 通道项 catalogXml.append("" + channel.getManufacture() + "\r\n"); catalogXml.append("" + channel.getSecrecy() + "\r\n"); catalogXml.append("" + channel.getRegisterWay() + "\r\n"); - catalogXml.append("" + (channel.getStatus() == 0 ? "OFF" : "ON") + "\r\n"); if (channel.getChannelType() != 2) { // 业务分组/虚拟组织/行政区划 不设置以下属性 catalogXml.append("" + channel.getModel() + "\r\n"); @@ -308,7 +309,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, catalogXml, fromTag, callIdHeader); + Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, catalogXml, fromTag, SipUtils.getNewViaTag(), callIdHeader); transmitRequest(parentPlatform, request, null, eventResult -> { int indexNext = index + parentPlatform.getCatalogGroup(); sendCatalogResponse(channels, parentPlatform, sn, fromTag, indexNext); @@ -348,7 +349,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, deviceInfoXml.toString(), fromTag, callIdHeader); + Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, deviceInfoXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader); transmitRequest(parentPlatform, request); } catch (SipException | ParseException | InvalidArgumentException e) { @@ -386,7 +387,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, deviceStatusXml.toString(), fromTag, callIdHeader); + Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, deviceStatusXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader); transmitRequest(parentPlatform, request); } catch (SipException | ParseException | InvalidArgumentException e) { @@ -471,8 +472,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - String tm = Long.toString(System.currentTimeMillis()); - Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, deviceStatusXml.toString(), "FromPtz" + tm, callIdHeader); + Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, deviceStatusXml.toString(), SipUtils.getNewFromTag(), SipUtils.getNewViaTag(), callIdHeader); transmitRequest(parentPlatform, request); } catch (SipException | ParseException e) { @@ -750,7 +750,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { // callid CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); - Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, recordXml.toString(), fromTag, callIdHeader); + Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, recordXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader); transmitRequest(parentPlatform, request); } catch (SipException | ParseException | InvalidArgumentException e) { diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/CatalogQueryMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/CatalogQueryMessageHandler.java index 7f6f8177..1aafbf6e 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/CatalogQueryMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/CatalogQueryMessageHandler.java @@ -78,6 +78,11 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem List allChannels = new ArrayList<>(); + // 回复平台 + DeviceChannel deviceChannel = getChannelForPlatform(parentPlatform); + allChannels.add(deviceChannel); + + // 回复目录 if (catalogs.size() > 0) { allChannels.addAll(catalogs); } @@ -104,4 +109,19 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem } } + + private DeviceChannel getChannelForPlatform(ParentPlatform platform) { + DeviceChannel deviceChannel = new DeviceChannel(); + + deviceChannel.setChannelId(platform.getDeviceGBId()); + deviceChannel.setName(platform.getName()); + deviceChannel.setManufacture("wvp-pro"); + deviceChannel.setOwner("wvp-pro"); + deviceChannel.setCivilCode(platform.getAdministrativeDivision()); + deviceChannel.setAddress("wvp-pro"); + deviceChannel.setRegisterWay(0); + deviceChannel.setSecrecy("0"); + + return deviceChannel; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/InviteResponseProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/InviteResponseProcessor.java index 1a396353..923d79f1 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/InviteResponseProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/InviteResponseProcessor.java @@ -1,14 +1,11 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.response.impl; import com.genersoft.iot.vmp.conf.SipConfig; -import com.genersoft.iot.vmp.gb28181.SipLayer; -import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction; import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; import com.genersoft.iot.vmp.gb28181.transmit.event.response.SIPResponseProcessorAbstract; -import com.genersoft.iot.vmp.gb28181.utils.HeaderUtils; +import com.genersoft.iot.vmp.gb28181.utils.SipUtils; import gov.nist.javax.sip.ResponseEventExt; -import gov.nist.javax.sip.message.SIPResponse; import gov.nist.javax.sip.stack.SIPDialog; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,13 +19,10 @@ import javax.sip.*; import javax.sip.address.Address; import javax.sip.address.SipURI; import javax.sip.header.CSeqHeader; -import javax.sip.header.CallIdHeader; import javax.sip.header.UserAgentHeader; import javax.sip.message.Request; import javax.sip.message.Response; import java.text.ParseException; -import java.util.ArrayList; -import java.util.List; /** @@ -104,7 +98,7 @@ public class InviteResponseProcessor extends SIPResponseProcessorAbstract { } requestURI.setPort(event.getRemotePort()); reqAck.setRequestURI(requestURI); - UserAgentHeader userAgentHeader = HeaderUtils.createUserAgentHeader(sipFactory); + UserAgentHeader userAgentHeader = SipUtils.createUserAgentHeader(sipFactory); reqAck.addHeader(userAgentHeader); Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort())); reqAck.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/HeaderUtils.java b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/HeaderUtils.java deleted file mode 100644 index 86112672..00000000 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/HeaderUtils.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.genersoft.iot.vmp.gb28181.utils; - -import javax.sip.PeerUnavailableException; -import javax.sip.SipFactory; -import javax.sip.header.UserAgentHeader; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.List; - -/** - * 生成header的工具类 - * @author lin - */ -public class HeaderUtils { - - public static UserAgentHeader createUserAgentHeader(SipFactory sipFactory) throws PeerUnavailableException, ParseException { - List agentParam = new ArrayList<>(); - agentParam.add("WVP PRO"); - // TODO 添加版本信息以及日期 - return sipFactory.createHeaderFactory().createUserAgentHeader(agentParam); - } -} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java index 44e13372..47bf38d3 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java @@ -4,9 +4,16 @@ import gov.nist.javax.sip.address.AddressImpl; import gov.nist.javax.sip.address.SipUri; import gov.nist.javax.sip.header.Subject; +import javax.sip.PeerUnavailableException; +import javax.sip.SipFactory; import javax.sip.header.FromHeader; import javax.sip.header.Header; +import javax.sip.header.UserAgentHeader; import javax.sip.message.Request; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; /** * @author panlinlin @@ -38,4 +45,25 @@ public class SipUtils { return uri.getUser(); } + public static String getNewViaTag() { + return "z9hG4bK" + System.currentTimeMillis(); + } + + public static UserAgentHeader createUserAgentHeader(SipFactory sipFactory) throws PeerUnavailableException, ParseException { + List agentParam = new ArrayList<>(); + agentParam.add("WVP PRO"); + // TODO 添加版本信息以及日期 + return sipFactory.createHeaderFactory().createUserAgentHeader(agentParam); + } + + public static String getNewFromTag(){ + return UUID.randomUUID().toString().replace("-", ""); + +// return getNewTag(); + } + + public static String getNewTag(){ + return String.valueOf(System.currentTimeMillis()); + } + } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java index 5abb3425..f3e01c97 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java @@ -257,6 +257,7 @@ public class PlayServiceImpl implements IPlayService { // 超时处理 String timeOutTaskKey = UUID.randomUUID().toString(); SSRCInfo finalSsrcInfo = ssrcInfo; + System.out.println("设置超时任务: " + timeOutTaskKey); dynamicTask.startDelay( timeOutTaskKey,()->{ SIPDialog dialog = streamSession.getDialogByStream(device.getDeviceId(), channelId, finalSsrcInfo.getStream()); @@ -282,6 +283,7 @@ public class PlayServiceImpl implements IPlayService { } cmder.playStreamCmd(mediaServerItem, ssrcInfo, device, channelId, (MediaServerItem mediaServerItemInuse, JSONObject response) -> { logger.info("收到订阅消息: " + response.toJSONString()); + System.out.println("停止超时任务: " + timeOutTaskKey); dynamicTask.stop(timeOutTaskKey); // hook响应 onPublishHandlerForPlay(mediaServerItemInuse, response, device.getDeviceId(), channelId, uuid); diff --git a/web_src/src/components/channelList.vue b/web_src/src/components/channelList.vue index 933cc443..136ddfe3 100644 --- a/web_src/src/components/channelList.vue +++ b/web_src/src/components/channelList.vue @@ -250,6 +250,7 @@ export default { that.loadSnap[deviceId + channelId] = 0; that.getSnapErrorEvent(snapId) }, 5000) + itemData.streamId = res.data.data.stream; that.$refs.devicePlayer.openDialog("media", deviceId, channelId, { streamInfo: res.data.data, hasAudio: itemData.hasAudio