Commit 4c53b10737ac97861adaacd7cdc7571970860e9f
1 parent
9c5b1060
解决对接中遇到的问题
Showing
23 changed files
with
249 additions
and
133 deletions
src/main/java/com/genersoft/iot/vmp/conf/SipPlatformRunner.java
| ... | ... | @@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.conf; |
| 3 | 3 | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| 4 | 4 | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch; |
| 5 | 5 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 6 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; | |
| 6 | 7 | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; |
| 7 | 8 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 8 | 9 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| ... | ... | @@ -30,7 +31,7 @@ public class SipPlatformRunner implements CommandLineRunner { |
| 30 | 31 | private EventPublisher publisher; |
| 31 | 32 | |
| 32 | 33 | @Autowired |
| 33 | - private ZLMRTPServerFactory zlmrtpServerFactory; | |
| 34 | + private ISIPCommanderForPlatform sipCommanderForPlatform; | |
| 34 | 35 | |
| 35 | 36 | |
| 36 | 37 | @Override |
| ... | ... | @@ -57,6 +58,9 @@ public class SipPlatformRunner implements CommandLineRunner { |
| 57 | 58 | parentPlatformCatch.setId(parentPlatform.getServerGBId()); |
| 58 | 59 | redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch); |
| 59 | 60 | |
| 61 | + // 取消订阅 | |
| 62 | + sipCommanderForPlatform.unregister(parentPlatform, null, null); | |
| 63 | + Thread.sleep(500); | |
| 60 | 64 | // 发送平台未注册消息 |
| 61 | 65 | publisher.platformNotRegisterEventPublish(parentPlatform.getServerGBId()); |
| 62 | 66 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeInfo.java
| ... | ... | @@ -18,13 +18,16 @@ public class SubscribeInfo { |
| 18 | 18 | this.fromTag = fromHeader.getTag(); |
| 19 | 19 | ExpiresHeader expiresHeader = (ExpiresHeader)request.getHeader(ExpiresHeader.NAME); |
| 20 | 20 | this.expires = expiresHeader.getExpires(); |
| 21 | - this.event = ((EventHeader)request.getHeader(EventHeader.NAME)).getName(); | |
| 21 | + EventHeader eventHeader = (EventHeader)request.getHeader(EventHeader.NAME); | |
| 22 | + this.eventId = eventHeader.getEventId(); | |
| 23 | + this.eventType = eventHeader.getEventType(); | |
| 22 | 24 | } |
| 23 | 25 | |
| 24 | 26 | private String id; |
| 25 | 27 | private int expires; |
| 26 | 28 | private String callId; |
| 27 | - private String event; | |
| 29 | + private String eventId; | |
| 30 | + private String eventType; | |
| 28 | 31 | private String fromTag; |
| 29 | 32 | private String toTag; |
| 30 | 33 | |
| ... | ... | @@ -68,11 +71,19 @@ public class SubscribeInfo { |
| 68 | 71 | this.fromTag = fromTag; |
| 69 | 72 | } |
| 70 | 73 | |
| 71 | - public String getEvent() { | |
| 72 | - return event; | |
| 74 | + public String getEventId() { | |
| 75 | + return eventId; | |
| 73 | 76 | } |
| 74 | 77 | |
| 75 | - public void setEvent(String event) { | |
| 76 | - this.event = event; | |
| 78 | + public void setEventId(String eventId) { | |
| 79 | + this.eventId = eventId; | |
| 80 | + } | |
| 81 | + | |
| 82 | + public String getEventType() { | |
| 83 | + return eventType; | |
| 84 | + } | |
| 85 | + | |
| 86 | + public void setEventType(String eventType) { | |
| 87 | + this.eventType = eventType; | |
| 77 | 88 | } |
| 78 | 89 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java
| ... | ... | @@ -101,14 +101,14 @@ public class EventPublisher { |
| 101 | 101 | applicationEventPublisher.publishEvent(outEvent); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - @Async | |
| 104 | + | |
| 105 | 105 | public void catalogEventPublish(String platformId, DeviceChannel deviceChannel, String type) { |
| 106 | 106 | List<DeviceChannel> deviceChannelList = new ArrayList<>(); |
| 107 | 107 | deviceChannelList.add(deviceChannel); |
| 108 | 108 | catalogEventPublish(platformId, deviceChannelList, type); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - @Async | |
| 111 | + | |
| 112 | 112 | public void catalogEventPublish(String platformId, List<DeviceChannel> deviceChannels, String type) { |
| 113 | 113 | CatalogEvent outEvent = new CatalogEvent(this); |
| 114 | 114 | List<DeviceChannel> channels = new ArrayList<>(); |
| ... | ... | @@ -130,8 +130,8 @@ public class EventPublisher { |
| 130 | 130 | applicationEventPublisher.publishEvent(outEvent); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - @Async | |
| 134 | - public void catalogEventPublishForStream(String platformId, GbStream[] gbStreams, String type) { | |
| 133 | + | |
| 134 | + public void catalogEventPublishForStream(String platformId, List<GbStream> gbStreams, String type) { | |
| 135 | 135 | CatalogEvent outEvent = new CatalogEvent(this); |
| 136 | 136 | outEvent.setGbStreams(gbStreams); |
| 137 | 137 | outEvent.setType(type); |
| ... | ... | @@ -139,9 +139,10 @@ public class EventPublisher { |
| 139 | 139 | applicationEventPublisher.publishEvent(outEvent); |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - @Async | |
| 142 | + | |
| 143 | 143 | public void catalogEventPublishForStream(String platformId, GbStream gbStream, String type) { |
| 144 | - GbStream[] gbStreams = {gbStream}; | |
| 145 | - catalogEventPublishForStream(platformId, gbStreams, type); | |
| 144 | + List<GbStream> gbStreamList = new ArrayList<>(); | |
| 145 | + gbStreamList.add(gbStream); | |
| 146 | + catalogEventPublishForStream(platformId, gbStreamList, type); | |
| 146 | 147 | } |
| 147 | 148 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEvent.java
| ... | ... | @@ -20,7 +20,7 @@ public class CatalogEvent extends ApplicationEvent { |
| 20 | 20 | public static final String UPDATE = "UPDATE"; // 更新 |
| 21 | 21 | |
| 22 | 22 | private List<DeviceChannel> deviceChannels; |
| 23 | - private GbStream[] gbStreams; | |
| 23 | + private List<GbStream> gbStreams; | |
| 24 | 24 | private String type; |
| 25 | 25 | private String platformId; |
| 26 | 26 | |
| ... | ... | @@ -48,11 +48,11 @@ public class CatalogEvent extends ApplicationEvent { |
| 48 | 48 | this.platformId = platformId; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - public GbStream[] getGbStreams() { | |
| 51 | + public List<GbStream> getGbStreams() { | |
| 52 | 52 | return gbStreams; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - public void setGbStreams(GbStream[] gbStreams) { | |
| 55 | + public void setGbStreams(List<GbStream> gbStreams) { | |
| 56 | 56 | this.gbStreams = gbStreams; |
| 57 | 57 | } |
| 58 | 58 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java
| ... | ... | @@ -63,7 +63,11 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> { |
| 63 | 63 | if (parentPlatform != null && !parentPlatform.isStatus())return; |
| 64 | 64 | String key = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + userSetup.getServerId() + "_Catalog_" + event.getPlatformId(); |
| 65 | 65 | subscribe = redisCatchStorage.getSubscribe(key); |
| 66 | - if (subscribe == null) return; | |
| 66 | + | |
| 67 | + if (subscribe == null) { | |
| 68 | + logger.debug("发送订阅消息时发现订阅信息已经不存在"); | |
| 69 | + return; | |
| 70 | + } | |
| 67 | 71 | }else { |
| 68 | 72 | // 获取所用订阅 |
| 69 | 73 | List<String> platforms = redisCatchStorage.getAllSubscribePlatform(); |
| ... | ... | @@ -94,7 +98,7 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> { |
| 94 | 98 | if (event.getDeviceChannels() != null) { |
| 95 | 99 | deviceChannelList.addAll(event.getDeviceChannels()); |
| 96 | 100 | } |
| 97 | - if (event.getGbStreams() != null && event.getGbStreams().length > 0){ | |
| 101 | + if (event.getGbStreams() != null && event.getGbStreams().size() > 0){ | |
| 98 | 102 | for (GbStream gbStream : event.getGbStreams()) { |
| 99 | 103 | DeviceChannel deviceChannelByStream = gbStreamService.getDeviceChannelListByStream(gbStream, gbStream.getCatalogId(), parentPlatform.getDeviceGBId()); |
| 100 | 104 | deviceChannelList.add(deviceChannelByStream); |
| ... | ... | @@ -134,7 +138,7 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> { |
| 134 | 138 | if (event.getDeviceChannels() != null) { |
| 135 | 139 | deviceChannelList.addAll(event.getDeviceChannels()); |
| 136 | 140 | } |
| 137 | - if (event.getGbStreams() != null && event.getGbStreams().length > 0){ | |
| 141 | + if (event.getGbStreams() != null && event.getGbStreams().size() > 0){ | |
| 138 | 142 | for (GbStream gbStream : event.getGbStreams()) { |
| 139 | 143 | DeviceChannel deviceChannelByStream = gbStreamService.getDeviceChannelListByStream(gbStream, gbStream.getCatalogId(), parentPlatform.getDeviceGBId()); |
| 140 | 144 | deviceChannelList.add(deviceChannelByStream); |
| ... | ... | @@ -142,7 +146,7 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> { |
| 142 | 146 | } |
| 143 | 147 | if (deviceChannelList.size() > 0) { |
| 144 | 148 | logger.info("[Catalog事件: {}]平台:{},影响通道{}个", event.getType(), event.getPlatformId(), deviceChannelList.size()); |
| 145 | - sipCommanderFroPlatform.sendNotifyForCatalogAddOrUpdate(event.getType(), parentPlatform, deviceChannelList, subscribe); | |
| 149 | + sipCommanderFroPlatform.sendNotifyForCatalogAddOrUpdate(event.getType(), parentPlatform, deviceChannelList, subscribe, null); | |
| 146 | 150 | } |
| 147 | 151 | }else if (parentPlatformMap.keySet().size() > 0) { |
| 148 | 152 | for (String gbId : parentPlatformMap.keySet()) { | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorObserver.java
| ... | ... | @@ -73,6 +73,7 @@ public class SIPProcessorObserver implements ISIPProcessorObserver { |
| 73 | 73 | @Override |
| 74 | 74 | @Async |
| 75 | 75 | public void processRequest(RequestEvent requestEvent) { |
| 76 | + logger.debug("\n收到请求:\n{}", requestEvent.getRequest()); | |
| 76 | 77 | String method = requestEvent.getRequest().getMethod(); |
| 77 | 78 | ISIPRequestProcessor sipRequestProcessor = requestProcessorMap.get(method); |
| 78 | 79 | if (sipRequestProcessor == null) { |
| ... | ... | @@ -90,9 +91,8 @@ public class SIPProcessorObserver implements ISIPProcessorObserver { |
| 90 | 91 | @Override |
| 91 | 92 | @Async |
| 92 | 93 | public void processResponse(ResponseEvent responseEvent) { |
| 93 | - logger.debug(responseEvent.getResponse().toString()); | |
| 94 | 94 | Response response = responseEvent.getResponse(); |
| 95 | - logger.debug(responseEvent.getResponse().toString()); | |
| 95 | + logger.debug("\n收到响应:\n{}", responseEvent.getResponse()); | |
| 96 | 96 | int status = response.getStatusCode(); |
| 97 | 97 | if (((status >= 200) && (status < 300)) || status == 401) { // Success! |
| 98 | 98 | CSeqHeader cseqHeader = (CSeqHeader) responseEvent.getResponse().getHeader(CSeqHeader.NAME); |
| ... | ... | @@ -107,8 +107,8 @@ public class SIPProcessorObserver implements ISIPProcessorObserver { |
| 107 | 107 | SipSubscribe.Event subscribe = sipSubscribe.getOkSubscribe(callIdHeader.getCallId()); |
| 108 | 108 | if (subscribe != null) { |
| 109 | 109 | SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(responseEvent); |
| 110 | - subscribe.response(eventResult); | |
| 111 | 110 | sipSubscribe.removeOkSubscribe(callIdHeader.getCallId()); |
| 111 | + subscribe.response(eventResult); | |
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java
| ... | ... | @@ -78,7 +78,7 @@ public interface ISIPCommanderForPlatform { |
| 78 | 78 | * @param parentPlatform |
| 79 | 79 | * @param deviceChannels |
| 80 | 80 | */ |
| 81 | - boolean sendNotifyForCatalogAddOrUpdate(String type, ParentPlatform parentPlatform, List<DeviceChannel> deviceChannels, SubscribeInfo subscribeInfo); | |
| 81 | + boolean sendNotifyForCatalogAddOrUpdate(String type, ParentPlatform parentPlatform, List<DeviceChannel> deviceChannels, SubscribeInfo subscribeInfo, Integer index); | |
| 82 | 82 | |
| 83 | 83 | /** |
| 84 | 84 | * 回复catalog事件-删除 | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java
| ... | ... | @@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.gb28181.transmit.cmd; |
| 2 | 2 | |
| 3 | 3 | import com.genersoft.iot.vmp.conf.SipConfig; |
| 4 | 4 | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo; | |
| 5 | 6 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 6 | 7 | import gov.nist.javax.sip.message.MessageFactoryImpl; |
| 7 | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| ... | ... | @@ -223,30 +224,31 @@ public class SIPRequestHeaderPlarformProvider { |
| 223 | 224 | UserAgentHeader userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam); |
| 224 | 225 | request.addHeader(userAgentHeader); |
| 225 | 226 | |
| 226 | - ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "MANSCDP+xml"); | |
| 227 | + ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); | |
| 227 | 228 | request.setContent(content, contentTypeHeader); |
| 228 | 229 | return request; |
| 229 | 230 | } |
| 230 | 231 | |
| 231 | - public Request createNotifyRequest(ParentPlatform parentPlatform, String content, String fromTag, String toTag, CallIdHeader callIdHeader) throws PeerUnavailableException, ParseException, InvalidArgumentException { | |
| 232 | + public Request createNotifyRequest(ParentPlatform parentPlatform, String content, CallIdHeader callIdHeader, String viaTag, SubscribeInfo subscribeInfo) throws PeerUnavailableException, ParseException, InvalidArgumentException { | |
| 232 | 233 | Request request = null; |
| 233 | 234 | // sipuri |
| 234 | 235 | SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP()+ ":" + parentPlatform.getServerPort()); |
| 235 | 236 | // via |
| 236 | 237 | ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>(); |
| 237 | 238 | ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(parentPlatform.getDeviceIp(), Integer.parseInt(parentPlatform.getDevicePort()), |
| 238 | - parentPlatform.getTransport(), null); | |
| 239 | + parentPlatform.getTransport(), viaTag); | |
| 239 | 240 | viaHeader.setRPort(); |
| 240 | 241 | viaHeaders.add(viaHeader); |
| 241 | 242 | // from |
| 242 | 243 | SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getDeviceGBId(), |
| 243 | 244 | parentPlatform.getDeviceIp() + ":" + parentPlatform.getDevicePort()); |
| 244 | 245 | Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); |
| 245 | - FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); | |
| 246 | + String tm = Long.toString(System.currentTimeMillis()); | |
| 247 | + FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, "fromtag" + tm); | |
| 246 | 248 | // to |
| 247 | 249 | SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerGBDomain()); |
| 248 | 250 | Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); |
| 249 | - ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag); | |
| 251 | + ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, subscribeInfo.getToTag()); | |
| 250 | 252 | |
| 251 | 253 | // Forwards |
| 252 | 254 | MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70); |
| ... | ... | @@ -262,7 +264,19 @@ public class SIPRequestHeaderPlarformProvider { |
| 262 | 264 | UserAgentHeader userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam); |
| 263 | 265 | request.addHeader(userAgentHeader); |
| 264 | 266 | |
| 265 | - ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "MANSCDP+xml"); | |
| 267 | + EventHeader event = sipFactory.createHeaderFactory().createEventHeader(subscribeInfo.getEventType()); | |
| 268 | + event.setEventId(subscribeInfo.getEventId()); | |
| 269 | + request.addHeader(event); | |
| 270 | + | |
| 271 | + SubscriptionStateHeader active = sipFactory.createHeaderFactory().createSubscriptionStateHeader("active"); | |
| 272 | + request.setHeader(active); | |
| 273 | + | |
| 274 | + String sipAddress = sipConfig.getIp() + ":" + sipConfig.getPort(); | |
| 275 | + Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory() | |
| 276 | + .createSipURI(parentPlatform.getDeviceGBId(), sipAddress)); | |
| 277 | + request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); | |
| 278 | + | |
| 279 | + ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); | |
| 266 | 280 | request.setContent(content, contentTypeHeader); |
| 267 | 281 | return request; |
| 268 | 282 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java
| ... | ... | @@ -67,7 +67,7 @@ public class SIPRequestHeaderProvider { |
| 67 | 67 | |
| 68 | 68 | request = sipFactory.createMessageFactory().createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader, |
| 69 | 69 | toHeader, viaHeaders, maxForwards); |
| 70 | - ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "MANSCDP+xml"); | |
| 70 | + ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); | |
| 71 | 71 | request.setContent(content, contentTypeHeader); |
| 72 | 72 | return request; |
| 73 | 73 | } |
| ... | ... | @@ -217,7 +217,7 @@ public class SIPRequestHeaderProvider { |
| 217 | 217 | EventHeader eventHeader = sipFactory.createHeaderFactory().createEventHeader(event); |
| 218 | 218 | request.addHeader(eventHeader); |
| 219 | 219 | |
| 220 | - ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "MANSCDP+xml"); | |
| 220 | + ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); | |
| 221 | 221 | request.setContent(content, contentTypeHeader); |
| 222 | 222 | return request; |
| 223 | 223 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
| ... | ... | @@ -32,21 +32,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { |
| 32 | 32 | |
| 33 | 33 | private final Logger logger = LoggerFactory.getLogger(SIPCommanderFroPlatform.class); |
| 34 | 34 | |
| 35 | - // @Autowired | |
| 36 | - // private SipConfig sipConfig; | |
| 37 | - | |
| 38 | - // @Autowired | |
| 39 | - // private SIPRequestHeaderProvider headerProvider; | |
| 40 | - | |
| 41 | 35 | @Autowired |
| 42 | 36 | private SIPRequestHeaderPlarformProvider headerProviderPlarformProvider; |
| 43 | 37 | |
| 44 | - // @Autowired | |
| 45 | - // private VideoStreamSessionManager streamSession; | |
| 46 | - | |
| 47 | - // @Autowired | |
| 48 | - // private IVideoManagerStorager storager; | |
| 49 | - | |
| 50 | 38 | @Autowired |
| 51 | 39 | private IRedisCatchStorage redisCatchStorage; |
| 52 | 40 | |
| ... | ... | @@ -173,6 +161,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { |
| 173 | 161 | } |
| 174 | 162 | |
| 175 | 163 | private void transmitRequest(ParentPlatform parentPlatform, Request request, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) throws SipException { |
| 164 | + logger.debug("\n发送消息:\n{}", request); | |
| 176 | 165 | if("TCP".equals(parentPlatform.getTransport())) { |
| 177 | 166 | tcpSipProvider.sendRequest(request); |
| 178 | 167 | |
| ... | ... | @@ -223,7 +212,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { |
| 223 | 212 | catalogXml.append("<CivilCode>" + channel.getCivilCode() + "</CivilCode>\r\n"); |
| 224 | 213 | catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n"); |
| 225 | 214 | catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n"); |
| 226 | - catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n"); | |
| 215 | + if (channel.getParentId() != null) { | |
| 216 | + catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n"); | |
| 217 | + } | |
| 227 | 218 | catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n"); |
| 228 | 219 | catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n"); |
| 229 | 220 | catalogXml.append("<Status>" + (channel.getStatus() == 0?"OFF":"ON") + "</Status>\r\n"); |
| ... | ... | @@ -358,7 +349,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { |
| 358 | 349 | |
| 359 | 350 | String tm = Long.toString(System.currentTimeMillis()); |
| 360 | 351 | |
| 361 | - Request request = headerProviderPlarformProvider.createNotifyRequest(parentPlatform, deviceStatusXml.toString(), subscribeInfo.getToTag(), subscribeInfo.getFromTag(), callIdHeader); | |
| 352 | + Request request = headerProviderPlarformProvider.createNotifyRequest(parentPlatform, | |
| 353 | + deviceStatusXml.toString(),callIdHeader, | |
| 354 | + "z9hG4bK-" + UUID.randomUUID().toString().replace("-", ""), subscribeInfo); | |
| 362 | 355 | transmitRequest(parentPlatform, request); |
| 363 | 356 | |
| 364 | 357 | } catch (SipException | ParseException | InvalidArgumentException e) { |
| ... | ... | @@ -369,63 +362,73 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { |
| 369 | 362 | } |
| 370 | 363 | |
| 371 | 364 | @Override |
| 372 | - public boolean sendNotifyForCatalogAddOrUpdate(String type, ParentPlatform parentPlatform, List<DeviceChannel> deviceChannels, SubscribeInfo subscribeInfo) { | |
| 365 | + public boolean sendNotifyForCatalogAddOrUpdate(String type, ParentPlatform parentPlatform, List<DeviceChannel> deviceChannels, SubscribeInfo subscribeInfo, Integer index) { | |
| 373 | 366 | if (parentPlatform == null || deviceChannels == null || deviceChannels.size() == 0 || subscribeInfo == null) { |
| 374 | 367 | return false; |
| 375 | 368 | } |
| 376 | - for (DeviceChannel channel : deviceChannels) { | |
| 377 | - try { | |
| 378 | - StringBuffer catalogXml = new StringBuffer(600); | |
| 379 | - catalogXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n"); | |
| 380 | - catalogXml.append("<Notify>\r\n"); | |
| 381 | - catalogXml.append("<CmdType>Catalog</CmdType>\r\n"); | |
| 382 | - catalogXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n"); | |
| 383 | - catalogXml.append("<SumNum>" + deviceChannels.size() + "</SumNum>\r\n"); | |
| 384 | - catalogXml.append("<DeviceList Num=\"1\">\r\n"); | |
| 385 | - catalogXml.append("<Item>\r\n"); | |
| 386 | - catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n"); | |
| 387 | - catalogXml.append("<Event>" + type + "</Event>\r\n"); | |
| 388 | - catalogXml.append("<Name>" + channel.getName() + "</Name>\r\n"); | |
| 389 | - catalogXml.append("<Manufacturer>" + channel.getManufacture() + "</Manufacturer>\r\n"); | |
| 390 | - catalogXml.append("<Model>" + channel.getModel() + "</Model>\r\n"); | |
| 391 | - catalogXml.append("<Owner>" + channel.getOwner() + "</Owner>\r\n"); | |
| 392 | - catalogXml.append("<CivilCode>" + channel.getCivilCode() + "</CivilCode>\r\n"); | |
| 393 | - catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n"); | |
| 394 | - catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n"); | |
| 395 | - catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n"); | |
| 396 | - catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n"); | |
| 397 | - catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n"); | |
| 398 | - catalogXml.append("<Status>" + (channel.getStatus() == 0 ? "OFF" : "ON") + "</Status>\r\n"); | |
| 399 | - catalogXml.append("<Longitude>" + channel.getLongitude() + "</Longitude>\r\n"); | |
| 400 | - catalogXml.append("<Latitude>" + channel.getLatitude() + "</Latitude>\r\n"); | |
| 401 | - catalogXml.append("<IPAddress>" + channel.getIpAddress() + "</IPAddress>\r\n"); | |
| 402 | - catalogXml.append("<Port>" + channel.getPort() + "</Port>\r\n"); | |
| 403 | - catalogXml.append("<Info>\r\n"); | |
| 404 | - catalogXml.append("<PTZType>" + channel.getPTZType() + "</PTZType>\r\n"); | |
| 405 | - catalogXml.append("</Info>\r\n"); | |
| 406 | - catalogXml.append("</Item>\r\n"); | |
| 407 | - catalogXml.append("</DeviceList>\r\n"); | |
| 408 | - catalogXml.append("</Notify>\r\n"); | |
| 409 | - | |
| 410 | - CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() | |
| 411 | - : udpSipProvider.getNewCallId(); | |
| 412 | - callIdHeader.setCallId(subscribeInfo.getCallId()); | |
| 413 | - | |
| 414 | - String tm = Long.toString(System.currentTimeMillis()); | |
| 369 | + if (index == null) { | |
| 370 | + index = 0; | |
| 371 | + } | |
| 415 | 372 | |
| 416 | - Request request = headerProviderPlarformProvider.createNotifyRequest(parentPlatform, catalogXml.toString(), subscribeInfo.getToTag(), subscribeInfo.getFromTag(), callIdHeader); | |
| 417 | - transmitRequest(parentPlatform, request); | |
| 418 | - Thread.sleep(10); | |
| 419 | - } catch (SipException | ParseException | InvalidArgumentException e) { | |
| 420 | - e.printStackTrace(); | |
| 421 | - return false; | |
| 422 | - } catch (InterruptedException e) { | |
| 423 | - e.printStackTrace(); | |
| 373 | + try { | |
| 374 | + if (index == deviceChannels.size() - 1) { | |
| 375 | + return true; | |
| 424 | 376 | } |
| 377 | + Request request = getCatalogNotifyRequest(parentPlatform, deviceChannels.get(index), deviceChannels.size(), type, subscribeInfo); | |
| 378 | + index += 1; | |
| 379 | + Integer finalIndex = index; | |
| 380 | + transmitRequest(parentPlatform, request, null, (eventResult -> { | |
| 381 | + sendNotifyForCatalogAddOrUpdate(type, parentPlatform, deviceChannels, subscribeInfo, finalIndex); | |
| 382 | + })); | |
| 383 | + } catch (SipException | ParseException | InvalidArgumentException e) { | |
| 384 | + e.printStackTrace(); | |
| 385 | + return false; | |
| 425 | 386 | } |
| 426 | 387 | return true; |
| 427 | 388 | } |
| 428 | 389 | |
| 390 | + private Request getCatalogNotifyRequest(ParentPlatform parentPlatform, DeviceChannel channel, int size, String type, | |
| 391 | + SubscribeInfo subscribeInfo) throws ParseException, InvalidArgumentException, | |
| 392 | + PeerUnavailableException { | |
| 393 | + String catalogXmlContent = getCatalogXmlContent(parentPlatform, channel, size, type); | |
| 394 | + | |
| 395 | + CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() | |
| 396 | + : udpSipProvider.getNewCallId(); | |
| 397 | + callIdHeader.setCallId(subscribeInfo.getCallId()); | |
| 398 | + Request request = headerProviderPlarformProvider.createNotifyRequest(parentPlatform, catalogXmlContent, | |
| 399 | + callIdHeader, "z9hG4bK-" + UUID.randomUUID().toString().replace("-", ""), subscribeInfo); | |
| 400 | + return request; | |
| 401 | + } | |
| 402 | + | |
| 403 | + private String getCatalogXmlContent(ParentPlatform parentPlatform, DeviceChannel channel, int sumNum, String type) { | |
| 404 | + StringBuffer catalogXml = new StringBuffer(600); | |
| 405 | + catalogXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n"); | |
| 406 | + catalogXml.append("<Notify>\r\n"); | |
| 407 | + catalogXml.append("<CmdType>Catalog</CmdType>\r\n"); | |
| 408 | + catalogXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n"); | |
| 409 | + catalogXml.append("<DeviceID>" + parentPlatform.getDeviceGBId() + "</DeviceID>\r\n"); | |
| 410 | + catalogXml.append("<SumNum>" + sumNum + "</SumNum>\r\n"); | |
| 411 | + catalogXml.append("<DeviceList Num=\"1\">\r\n"); | |
| 412 | + catalogXml.append("<Item>\r\n"); | |
| 413 | + catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n"); | |
| 414 | + catalogXml.append("<Name>" + channel.getName() + "</Name>\r\n"); | |
| 415 | + catalogXml.append("<Manufacturer>" + channel.getManufacture() + "</Manufacturer>\r\n"); | |
| 416 | + catalogXml.append("<Model>" + channel.getModel() + "</Model>\r\n"); | |
| 417 | + catalogXml.append("<Owner>0</Owner>\r\n"); | |
| 418 | + catalogXml.append("<CivilCode>CivilCode</CivilCode>\r\n"); | |
| 419 | + catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n"); | |
| 420 | + catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n"); | |
| 421 | + catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n"); | |
| 422 | + catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n"); | |
| 423 | + catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n"); | |
| 424 | + catalogXml.append("<Status>" + (channel.getStatus() == 0 ? "OFF" : "ON") + "</Status>\r\n"); | |
| 425 | + catalogXml.append("<Event>" + type + "</Event>\r\n"); | |
| 426 | + catalogXml.append("</Item>\r\n"); | |
| 427 | + catalogXml.append("</DeviceList>\r\n"); | |
| 428 | + catalogXml.append("</Notify>\r\n"); | |
| 429 | + return catalogXml.toString(); | |
| 430 | + } | |
| 431 | + | |
| 429 | 432 | @Override |
| 430 | 433 | public boolean sendNotifyForCatalogOther(String type, ParentPlatform parentPlatform, List<DeviceChannel> deviceChannels, SubscribeInfo subscribeInfo) { |
| 431 | 434 | if (parentPlatform == null |
| ... | ... | @@ -442,6 +445,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { |
| 442 | 445 | catalogXml.append("<Notify>\r\n"); |
| 443 | 446 | catalogXml.append("<CmdType>Catalog</CmdType>\r\n"); |
| 444 | 447 | catalogXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n"); |
| 448 | + catalogXml.append("<DeviceID>" + parentPlatform.getDeviceGBId() + "</DeviceID>\r\n"); | |
| 445 | 449 | catalogXml.append("<SumNum>" + deviceChannels.size() + "</SumNum>\r\n"); |
| 446 | 450 | catalogXml.append("<DeviceList Num=\"1\">\r\n"); |
| 447 | 451 | catalogXml.append("<Item>\r\n"); |
| ... | ... | @@ -457,7 +461,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { |
| 457 | 461 | |
| 458 | 462 | String tm = Long.toString(System.currentTimeMillis()); |
| 459 | 463 | |
| 460 | - Request request = headerProviderPlarformProvider.createNotifyRequest(parentPlatform, catalogXml.toString(), subscribeInfo.getToTag(), subscribeInfo.getFromTag(), callIdHeader); | |
| 464 | + Request request = headerProviderPlarformProvider.createNotifyRequest(parentPlatform, catalogXml.toString(), | |
| 465 | + callIdHeader, | |
| 466 | + "z9hG4bK-" + UUID.randomUUID().toString().replace("-", ""), subscribeInfo); | |
| 461 | 467 | transmitRequest(parentPlatform, request); |
| 462 | 468 | Thread.sleep(200); |
| 463 | 469 | } catch (SipException | ParseException | InvalidArgumentException e) { | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/SIPRequestProcessorParent.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.transmit.event.request; |
| 2 | 2 | |
| 3 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 3 | 4 | import gov.nist.javax.sip.SipProviderImpl; |
| 4 | 5 | import gov.nist.javax.sip.SipStackImpl; |
| 5 | 6 | import gov.nist.javax.sip.message.SIPRequest; |
| ... | ... | @@ -160,13 +161,18 @@ public abstract class SIPRequestProcessorParent { |
| 160 | 161 | * @throws InvalidArgumentException |
| 161 | 162 | * @throws ParseException |
| 162 | 163 | */ |
| 163 | - public void responseSdpAck(RequestEvent evt, String sdp) throws SipException, InvalidArgumentException, ParseException { | |
| 164 | + public void responseSdpAck(RequestEvent evt, String sdp, ParentPlatform platform) throws SipException, InvalidArgumentException, ParseException { | |
| 164 | 165 | Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest()); |
| 165 | 166 | SipFactory sipFactory = SipFactory.getInstance(); |
| 166 | 167 | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "SDP"); |
| 167 | 168 | response.setContent(sdp, contentTypeHeader); |
| 168 | 169 | |
| 170 | + // 兼容国标中的使用编码@域名作为RequestURI的情况 | |
| 169 | 171 | SipURI sipURI = (SipURI)evt.getRequest().getRequestURI(); |
| 172 | + if (sipURI.getPort() == -1) { | |
| 173 | + sipURI = sipFactory.createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIP()+":"+platform.getServerPort()); | |
| 174 | + } | |
| 175 | + logger.debug("responseSdpAck SipURI: {}:{}", sipURI.getHost(), sipURI.getPort()); | |
| 170 | 176 | |
| 171 | 177 | Address concatAddress = sipFactory.createAddressFactory().createAddress( |
| 172 | 178 | sipFactory.createAddressFactory().createSipURI(sipURI.getUser(), sipURI.getHost()+":"+sipURI.getPort() |
| ... | ... | @@ -183,13 +189,18 @@ public abstract class SIPRequestProcessorParent { |
| 183 | 189 | * @throws InvalidArgumentException |
| 184 | 190 | * @throws ParseException |
| 185 | 191 | */ |
| 186 | - public Response responseXmlAck(RequestEvent evt, String xml) throws SipException, InvalidArgumentException, ParseException { | |
| 192 | + public Response responseXmlAck(RequestEvent evt, String xml, ParentPlatform platform) throws SipException, InvalidArgumentException, ParseException { | |
| 187 | 193 | Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest()); |
| 188 | 194 | SipFactory sipFactory = SipFactory.getInstance(); |
| 189 | - ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "MANSCDP+xml"); | |
| 195 | + ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); | |
| 190 | 196 | response.setContent(xml, contentTypeHeader); |
| 191 | 197 | |
| 198 | + // 兼容国标中的使用编码@域名作为RequestURI的情况 | |
| 192 | 199 | SipURI sipURI = (SipURI)evt.getRequest().getRequestURI(); |
| 200 | + if (sipURI.getPort() == -1) { | |
| 201 | + sipURI = sipFactory.createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIP()+":"+platform.getServerPort()); | |
| 202 | + } | |
| 203 | + logger.debug("responseXmlAck SipURI: {}:{}", sipURI.getHost(), sipURI.getPort()); | |
| 193 | 204 | |
| 194 | 205 | Address concatAddress = sipFactory.createAddressFactory().createAddress( |
| 195 | 206 | sipFactory.createAddressFactory().createSipURI(sipURI.getUser(), sipURI.getHost()+":"+sipURI.getPort() | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
| ... | ... | @@ -252,7 +252,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements |
| 252 | 252 | content.append("f=\r\n"); |
| 253 | 253 | |
| 254 | 254 | try { |
| 255 | - responseSdpAck(evt, content.toString()); | |
| 255 | + responseSdpAck(evt, content.toString(), platform); | |
| 256 | 256 | } catch (SipException e) { |
| 257 | 257 | e.printStackTrace(); |
| 258 | 258 | } catch (InvalidArgumentException e) { |
| ... | ... | @@ -309,7 +309,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements |
| 309 | 309 | content.append("f=\r\n"); |
| 310 | 310 | |
| 311 | 311 | try { |
| 312 | - responseSdpAck(evt, content.toString()); | |
| 312 | + responseSdpAck(evt, content.toString(), platform); | |
| 313 | 313 | } catch (SipException e) { |
| 314 | 314 | e.printStackTrace(); |
| 315 | 315 | } catch (InvalidArgumentException e) { | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/SubscribeRequestProcessor.java
| ... | ... | @@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.common.VideoManagerConstants; |
| 4 | 4 | import com.genersoft.iot.vmp.conf.DynamicTask; |
| 5 | 5 | import com.genersoft.iot.vmp.conf.UserSetup; |
| 6 | 6 | import com.genersoft.iot.vmp.gb28181.bean.CmdType; |
| 7 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 7 | 8 | import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo; |
| 8 | 9 | import com.genersoft.iot.vmp.gb28181.task.GPSSubscribeTask; |
| 9 | 10 | import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; |
| ... | ... | @@ -105,9 +106,6 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme |
| 105 | 106 | logger.info("processRequest serverTransactionId is null."); |
| 106 | 107 | } |
| 107 | 108 | } |
| 108 | - | |
| 109 | - | |
| 110 | - | |
| 111 | 109 | } catch (ParseException e) { |
| 112 | 110 | e.printStackTrace(); |
| 113 | 111 | } catch (SipException e) { |
| ... | ... | @@ -155,7 +153,8 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme |
| 155 | 153 | |
| 156 | 154 | |
| 157 | 155 | try { |
| 158 | - Response response = responseXmlAck(evt, resultXml.toString()); | |
| 156 | + ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId); | |
| 157 | + Response response = responseXmlAck(evt, resultXml.toString(), parentPlatform); | |
| 159 | 158 | ToHeader toHeader = (ToHeader)response.getHeader(ToHeader.NAME); |
| 160 | 159 | subscribeInfo.setToTag(toHeader.getTag()); |
| 161 | 160 | redisCatchStorage.updateSubscribe(key, subscribeInfo); |
| ... | ... | @@ -196,7 +195,8 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme |
| 196 | 195 | } |
| 197 | 196 | |
| 198 | 197 | try { |
| 199 | - Response response = responseXmlAck(evt, resultXml.toString()); | |
| 198 | + ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId); | |
| 199 | + Response response = responseXmlAck(evt, resultXml.toString(), parentPlatform); | |
| 200 | 200 | ToHeader toHeader = (ToHeader)response.getHeader(ToHeader.NAME); |
| 201 | 201 | subscribeInfo.setToTag(toHeader.getTag()); |
| 202 | 202 | redisCatchStorage.updateSubscribe(key, subscribeInfo); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/CatalogNotifyMessageHandler.java
| ... | ... | @@ -72,6 +72,9 @@ public class CatalogNotifyMessageHandler extends SIPRequestProcessorParent imple |
| 72 | 72 | List<PlatformCatalog> catalogs = storager.queryCatalogInPlatform(parentPlatform.getServerGBId()); |
| 73 | 73 | if (catalogs.size() > 0) { |
| 74 | 74 | for (PlatformCatalog catalog : catalogs) { |
| 75 | + if (catalog.getParentId().equals(catalog.getPlatformId())) { | |
| 76 | + catalog.setParentId(parentPlatform.getDeviceGBId()); | |
| 77 | + } | |
| 75 | 78 | DeviceChannel deviceChannel = new DeviceChannel(); |
| 76 | 79 | deviceChannel.setChannelId(catalog.getId()); |
| 77 | 80 | deviceChannel.setName(catalog.getName()); |
| ... | ... | @@ -83,29 +86,35 @@ public class CatalogNotifyMessageHandler extends SIPRequestProcessorParent imple |
| 83 | 86 | deviceChannel.setParental(1); |
| 84 | 87 | deviceChannel.setParentId(catalog.getParentId()); |
| 85 | 88 | deviceChannel.setRegisterWay(1); |
| 86 | - deviceChannel.setCivilCode(config.getDomain()); | |
| 89 | + deviceChannel.setCivilCode(config.getDomain().substring(0, config.getDomain().length() - 2)); | |
| 87 | 90 | deviceChannel.setModel("live"); |
| 88 | 91 | deviceChannel.setOwner("wvp-pro"); |
| 89 | 92 | deviceChannel.setSecrecy("0"); |
| 90 | 93 | cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size); |
| 91 | 94 | // 防止发送过快 |
| 92 | - Thread.sleep(50); | |
| 95 | + Thread.sleep(100); | |
| 93 | 96 | } |
| 94 | 97 | } |
| 95 | 98 | // 回复级联的通道 |
| 96 | 99 | if (channelReduces.size() > 0) { |
| 97 | 100 | for (ChannelReduce channelReduce : channelReduces) { |
| 101 | + if (channelReduce.getCatalogId().equals(parentPlatform.getServerGBId())) { | |
| 102 | + channelReduce.setCatalogId(parentPlatform.getDeviceGBId()); | |
| 103 | + } | |
| 98 | 104 | DeviceChannel deviceChannel = storager.queryChannel(channelReduce.getDeviceId(), channelReduce.getChannelId()); |
| 99 | 105 | deviceChannel.setParental(0); |
| 100 | 106 | deviceChannel.setParentId(channelReduce.getCatalogId()); |
| 101 | 107 | cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size); |
| 102 | 108 | // 防止发送过快 |
| 103 | - Thread.sleep(50); | |
| 109 | + Thread.sleep(100); | |
| 104 | 110 | } |
| 105 | 111 | } |
| 106 | 112 | // 回复直播的通道 |
| 107 | 113 | if (gbStreams.size() > 0) { |
| 108 | 114 | for (GbStream gbStream : gbStreams) { |
| 115 | + if (gbStream.getCatalogId().equals(parentPlatform.getServerGBId())) { | |
| 116 | + gbStream.setCatalogId(null); | |
| 117 | + } | |
| 109 | 118 | DeviceChannel deviceChannel = new DeviceChannel(); |
| 110 | 119 | deviceChannel.setChannelId(gbStream.getGbId()); |
| 111 | 120 | deviceChannel.setName(gbStream.getName()); |
| ... | ... | @@ -116,14 +125,14 @@ public class CatalogNotifyMessageHandler extends SIPRequestProcessorParent imple |
| 116 | 125 | deviceChannel.setStatus(gbStream.isStatus()?1:0); |
| 117 | 126 | deviceChannel.setParentId(gbStream.getCatalogId()); |
| 118 | 127 | deviceChannel.setRegisterWay(1); |
| 119 | - deviceChannel.setCivilCode(config.getDomain()); | |
| 128 | + deviceChannel.setCivilCode(config.getDomain().substring(0, config.getDomain().length() - 2)); | |
| 120 | 129 | deviceChannel.setModel("live"); |
| 121 | 130 | deviceChannel.setOwner("wvp-pro"); |
| 122 | 131 | deviceChannel.setParental(0); |
| 123 | 132 | deviceChannel.setSecrecy("0"); |
| 124 | 133 | cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size); |
| 125 | 134 | // 防止发送过快 |
| 126 | - Thread.sleep(50); | |
| 135 | + Thread.sleep(100); | |
| 127 | 136 | } |
| 128 | 137 | } |
| 129 | 138 | if (size == 0) { | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/CatalogQueryMessageHandler.java
| ... | ... | @@ -75,6 +75,9 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem |
| 75 | 75 | int size = catalogs.size() + channelReduces.size() + gbStreams.size(); |
| 76 | 76 | if (catalogs.size() > 0) { |
| 77 | 77 | for (PlatformCatalog catalog : catalogs) { |
| 78 | + if (catalog.getParentId().equals(parentPlatform.getServerGBId())) { | |
| 79 | + catalog.setParentId(parentPlatform.getDeviceGBId()); | |
| 80 | + } | |
| 78 | 81 | DeviceChannel deviceChannel = new DeviceChannel(); |
| 79 | 82 | deviceChannel.setChannelId(catalog.getId()); |
| 80 | 83 | deviceChannel.setName(catalog.getName()); |
| ... | ... | @@ -86,30 +89,35 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem |
| 86 | 89 | deviceChannel.setParental(1); |
| 87 | 90 | deviceChannel.setParentId(catalog.getParentId()); |
| 88 | 91 | deviceChannel.setRegisterWay(1); |
| 89 | - deviceChannel.setCivilCode(config.getDomain()); | |
| 92 | + deviceChannel.setCivilCode(config.getDomain().substring(0, config.getDomain().length() - 2)); | |
| 90 | 93 | deviceChannel.setModel("live"); |
| 91 | 94 | deviceChannel.setOwner("wvp-pro"); |
| 92 | 95 | deviceChannel.setSecrecy("0"); |
| 93 | 96 | cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size); |
| 94 | 97 | // 防止发送过快 |
| 95 | - Thread.sleep(50); | |
| 98 | + Thread.sleep(100); | |
| 96 | 99 | } |
| 97 | 100 | } |
| 98 | 101 | // 回复级联的通道 |
| 99 | 102 | if (channelReduces.size() > 0) { |
| 100 | 103 | for (ChannelReduce channelReduce : channelReduces) { |
| 104 | + if (channelReduce.getCatalogId().equals(parentPlatform.getServerGBId())) { | |
| 105 | + channelReduce.setCatalogId(parentPlatform.getDeviceGBId()); | |
| 106 | + } | |
| 101 | 107 | DeviceChannel deviceChannel = storager.queryChannel(channelReduce.getDeviceId(), channelReduce.getChannelId()); |
| 102 | - // TODO 目前暂时认为这里只用通道没有目录 | |
| 103 | 108 | deviceChannel.setParental(0); |
| 104 | 109 | deviceChannel.setParentId(channelReduce.getCatalogId()); |
| 105 | 110 | cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size); |
| 106 | 111 | // 防止发送过快 |
| 107 | - Thread.sleep(50); | |
| 112 | + Thread.sleep(100); | |
| 108 | 113 | } |
| 109 | 114 | } |
| 110 | 115 | // 回复直播的通道 |
| 111 | 116 | if (gbStreams.size() > 0) { |
| 112 | 117 | for (GbStream gbStream : gbStreams) { |
| 118 | + if (gbStream.getCatalogId().equals(parentPlatform.getServerGBId())) { | |
| 119 | + gbStream.setCatalogId(parentPlatform.getDeviceGBId()); | |
| 120 | + } | |
| 113 | 121 | DeviceChannel deviceChannel = new DeviceChannel(); |
| 114 | 122 | deviceChannel.setChannelId(gbStream.getGbId()); |
| 115 | 123 | deviceChannel.setName(gbStream.getName()); |
| ... | ... | @@ -120,7 +128,7 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem |
| 120 | 128 | deviceChannel.setStatus(gbStream.isStatus()?1:0); |
| 121 | 129 | deviceChannel.setParentId(gbStream.getCatalogId()); |
| 122 | 130 | deviceChannel.setRegisterWay(1); |
| 123 | - deviceChannel.setCivilCode(config.getDomain()); | |
| 131 | + deviceChannel.setCivilCode(config.getDomain().substring(0, config.getDomain().length() - 2)); | |
| 124 | 132 | deviceChannel.setModel("live"); |
| 125 | 133 | deviceChannel.setOwner("wvp-pro"); |
| 126 | 134 | deviceChannel.setParental(0); |
| ... | ... | @@ -128,7 +136,7 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem |
| 128 | 136 | |
| 129 | 137 | cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size); |
| 130 | 138 | // 防止发送过快 |
| 131 | - Thread.sleep(50); | |
| 139 | + Thread.sleep(100); | |
| 132 | 140 | } |
| 133 | 141 | } |
| 134 | 142 | if (size == 0) { | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
| ... | ... | @@ -358,6 +358,8 @@ public class ZLMHttpHookListener { |
| 358 | 358 | if (mediaServerItem != null){ |
| 359 | 359 | if (regist) { |
| 360 | 360 | StreamPushItem streamPushItem = null; |
| 361 | + StreamInfo streamInfoByAppAndStream = mediaService.getStreamInfoByAppAndStream(mediaServerItem, app, streamId, tracks); | |
| 362 | + item.setStreamInfo(streamInfoByAppAndStream); | |
| 361 | 363 | redisCatchStorage.addStream(mediaServerItem, type, app, streamId, item); |
| 362 | 364 | if (item.getOriginType() == OriginType.RTSP_PUSH.ordinal() |
| 363 | 365 | || item.getOriginType() == OriginType.RTMP_PUSH.ordinal() |
| ... | ... | @@ -375,7 +377,7 @@ public class ZLMHttpHookListener { |
| 375 | 377 | } |
| 376 | 378 | } |
| 377 | 379 | if (gbStreams.size() > 0) { |
| 378 | - eventPublisher.catalogEventPublishForStream(null, gbStreams.toArray(new GbStream[0]), CatalogEvent.ON); | |
| 380 | + eventPublisher.catalogEventPublishForStream(null, gbStreams, CatalogEvent.ON); | |
| 379 | 381 | } |
| 380 | 382 | |
| 381 | 383 | }else { | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaItem.java
| 1 | 1 | package com.genersoft.iot.vmp.media.zlm.dto; |
| 2 | 2 | |
| 3 | +import com.genersoft.iot.vmp.common.StreamInfo; | |
| 4 | + | |
| 3 | 5 | import java.util.List; |
| 4 | 6 | |
| 5 | 7 | public class MediaItem { |
| ... | ... | @@ -281,6 +283,8 @@ public class MediaItem { |
| 281 | 283 | } |
| 282 | 284 | } |
| 283 | 285 | |
| 286 | + private StreamInfo streamInfo; | |
| 287 | + | |
| 284 | 288 | public String getApp() { |
| 285 | 289 | return app; |
| 286 | 290 | } |
| ... | ... | @@ -402,4 +406,12 @@ public class MediaItem { |
| 402 | 406 | public void setMediaServerId(String mediaServerId) { |
| 403 | 407 | this.mediaServerId = mediaServerId; |
| 404 | 408 | } |
| 409 | + | |
| 410 | + public StreamInfo getStreamInfo() { | |
| 411 | + return streamInfo; | |
| 412 | + } | |
| 413 | + | |
| 414 | + public void setStreamInfo(StreamInfo streamInfo) { | |
| 415 | + this.streamInfo = streamInfo; | |
| 416 | + } | |
| 405 | 417 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java
| ... | ... | @@ -103,7 +103,7 @@ public class GbStreamServiceImpl implements IGbStreamService { |
| 103 | 103 | deviceChannel.setStatus(gbStream.isStatus()?1:0); |
| 104 | 104 | deviceChannel.setParentId(catalogId ==null?gbStream.getCatalogId():catalogId); |
| 105 | 105 | deviceChannel.setRegisterWay(1); |
| 106 | - deviceChannel.setCivilCode(sipConfig.getDomain()); | |
| 106 | + deviceChannel.setCivilCode(sipConfig.getDomain().substring(0, sipConfig.getDomain().length() - 2)); | |
| 107 | 107 | deviceChannel.setModel("live"); |
| 108 | 108 | deviceChannel.setOwner("wvp-pro"); |
| 109 | 109 | deviceChannel.setParental(0); | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/RedisGPSMsgListener.java
| ... | ... | @@ -3,6 +3,8 @@ package com.genersoft.iot.vmp.service.impl; |
| 3 | 3 | import com.alibaba.fastjson.JSON; |
| 4 | 4 | import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; |
| 5 | 5 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 6 | +import org.slf4j.Logger; | |
| 7 | +import org.slf4j.LoggerFactory; | |
| 6 | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 7 | 9 | import org.springframework.data.redis.connection.Message; |
| 8 | 10 | import org.springframework.data.redis.connection.MessageListener; |
| ... | ... | @@ -11,11 +13,14 @@ import org.springframework.stereotype.Component; |
| 11 | 13 | @Component |
| 12 | 14 | public class RedisGPSMsgListener implements MessageListener { |
| 13 | 15 | |
| 16 | + private final static Logger logger = LoggerFactory.getLogger(RedisGPSMsgListener.class); | |
| 17 | + | |
| 14 | 18 | @Autowired |
| 15 | 19 | private IRedisCatchStorage redisCatchStorage; |
| 16 | 20 | |
| 17 | 21 | @Override |
| 18 | 22 | public void onMessage(Message message, byte[] bytes) { |
| 23 | + logger.debug("收到来自REDIS的GPS通知: {}", new String(message.getBody())); | |
| 19 | 24 | GPSMsgInfo gpsMsgInfo = JSON.parseObject(message.getBody(), GPSMsgInfo.class); |
| 20 | 25 | redisCatchStorage.updateGpsMsgInfo(gpsMsgInfo); |
| 21 | 26 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java
| ... | ... | @@ -377,7 +377,7 @@ public class StreamPushServiceImpl implements IStreamPushService { |
| 377 | 377 | |
| 378 | 378 | if (streamPushItemsForPlatform.size() > 0) { |
| 379 | 379 | List<StreamPushItem> streamPushItemListFroPlatform = new ArrayList<>(); |
| 380 | - Map<String, List<StreamPushItem>> platformForEvent = new HashMap<>(); | |
| 380 | + Map<String, List<GbStream>> platformForEvent = new HashMap<>(); | |
| 381 | 381 | // 遍历存储结果,查找app+Stream->platformId+catalogId的对应关系,然后执行批量写入 |
| 382 | 382 | for (StreamPushItem streamPushItem : streamPushItemsForPlatform) { |
| 383 | 383 | List<String[]> platFormInfoList = streamPushItemsForAll.get(streamPushItem.getApp() + streamPushItem.getStream()); |
| ... | ... | @@ -390,16 +390,17 @@ public class StreamPushServiceImpl implements IStreamPushService { |
| 390 | 390 | // 数组 platFormInfoArray 0 为平台ID。 1为目录ID |
| 391 | 391 | streamPushItemForPlatform.setPlatformId(platFormInfoArray[0]); |
| 392 | 392 | |
| 393 | - List<StreamPushItem> streamPushItemsInPlatform = platformForEvent.get(streamPushItem.getPlatformId()); | |
| 394 | - if (streamPushItemsInPlatform == null) { | |
| 395 | - streamPushItemsInPlatform = new ArrayList<>(); | |
| 396 | - platformForEvent.put(platFormInfoArray[0], streamPushItemsInPlatform); | |
| 393 | + List<GbStream> gbStreamList = platformForEvent.get(streamPushItem.getPlatformId()); | |
| 394 | + if (gbStreamList == null) { | |
| 395 | + gbStreamList = new ArrayList<>(); | |
| 396 | + platformForEvent.put(platFormInfoArray[0], gbStreamList); | |
| 397 | 397 | } |
| 398 | 398 | // 为发送通知整理数据 |
| 399 | + streamPushItemForPlatform.setName(streamPushItem.getName()); | |
| 399 | 400 | streamPushItemForPlatform.setApp(streamPushItem.getApp()); |
| 400 | 401 | streamPushItemForPlatform.setStream(streamPushItem.getStream()); |
| 401 | 402 | streamPushItemForPlatform.setGbId(streamPushItem.getGbId()); |
| 402 | - streamPushItemsInPlatform.add(streamPushItemForPlatform); | |
| 403 | + gbStreamList.add(streamPushItemForPlatform); | |
| 403 | 404 | } |
| 404 | 405 | if (platFormInfoArray.length > 1) { |
| 405 | 406 | streamPushItemForPlatform.setCatalogId(platFormInfoArray[1]); |
| ... | ... | @@ -416,7 +417,7 @@ public class StreamPushServiceImpl implements IStreamPushService { |
| 416 | 417 | // 发送通知 |
| 417 | 418 | for (String platformId : platformForEvent.keySet()) { |
| 418 | 419 | eventPublisher.catalogEventPublishForStream( |
| 419 | - platformId, platformForEvent.get(platformId).toArray(new GbStream[0]), CatalogEvent.ADD); | |
| 420 | + platformId, platformForEvent.get(platformId), CatalogEvent.ADD); | |
| 420 | 421 | } |
| 421 | 422 | } |
| 422 | 423 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMapper.java
| ... | ... | @@ -74,7 +74,7 @@ public interface DeviceMapper { |
| 74 | 74 | "<if test=\"keepaliveTime != null\">, keepaliveTime='${keepaliveTime}'</if>" + |
| 75 | 75 | "<if test=\"expires != null\">, expires=${expires}</if>" + |
| 76 | 76 | "<if test=\"charset != null\">, charset='${charset}'</if>" + |
| 77 | - "<if test=\"subscribeCycleForCatalog != null\">, subscribeCycleForCatalog=#{subscribeCycleForCatalog}</if>" + | |
| 77 | + "<if test=\"subscribeCycleForCatalog != null\">, subscribeCycleForCatalog=${subscribeCycleForCatalog}</if>" + | |
| 78 | 78 | "WHERE deviceId='${deviceId}'"+ |
| 79 | 79 | " </script>"}) |
| 80 | 80 | int update(Device device); | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformChannelMapper.java
| ... | ... | @@ -58,11 +58,15 @@ public interface PlatformChannelMapper { |
| 58 | 58 | DeviceChannel queryChannelInParentPlatform(String platformId, String channelId); |
| 59 | 59 | |
| 60 | 60 | @Select("select dc.channelId as id, dc.name as name, pgc.platformId as platformId, pgc.catalogId as parentId, 0 as childrenCount, 1 as type " + |
| 61 | - "from device_channel dc left join platform_gb_channel pgc on dc.deviceId = pgc.deviceId and dc.channelId = pgc.channelId " + | |
| 61 | + "from device_channel dc left join platform_gb_channel pgc on dc.id = pgc.deviceChannelId" + | |
| 62 | 62 | "where pgc.platformId=#{platformId} and pgc.catalogId=#{catalogId}") |
| 63 | 63 | List<PlatformCatalog> queryChannelInParentPlatformAndCatalog(String platformId, String catalogId); |
| 64 | 64 | |
| 65 | - @Select("SELECT * FROM device WHERE deviceId = (SELECT deviceId FROM platform_gb_channel WHERE platformId='${platformId}' AND channelId='${channelId}')") | |
| 65 | + @Select("select d.*\n" + | |
| 66 | + "from platform_gb_channel pgc\n" + | |
| 67 | + " left join device_channel dc on dc.id = pgc.deviceChannelId\n" + | |
| 68 | + " left join device d on dc.deviceId = d.deviceId\n" + | |
| 69 | + "where dc.channelId = #{channelId} and pgc.platformId=#{platformId}") | |
| 66 | 70 | Device queryVideoDeviceByPlatformIdAndChannelId(String platformId, String channelId); |
| 67 | 71 | |
| 68 | 72 | @Delete("<script> "+ | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java
| ... | ... | @@ -149,8 +149,16 @@ public class PlatformController { |
| 149 | 149 | if (updateResult) { |
| 150 | 150 | // 保存时启用就发送注册 |
| 151 | 151 | if (parentPlatform.isEnable()) { |
| 152 | - // 只要保存就发送注册 | |
| 153 | - commanderForPlatform.register(parentPlatform, null, null); | |
| 152 | + if (parentPlatformOld.isStatus()) { | |
| 153 | + commanderForPlatform.unregister(parentPlatformOld, null, eventResult -> { | |
| 154 | + // 只要保存就发送注册 | |
| 155 | + commanderForPlatform.register(parentPlatform, null, null); | |
| 156 | + }); | |
| 157 | + }else { | |
| 158 | + // 只要保存就发送注册 | |
| 159 | + commanderForPlatform.register(parentPlatform, null, null); | |
| 160 | + } | |
| 161 | + | |
| 154 | 162 | } else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()){ // 关闭启用时注销 |
| 155 | 163 | commanderForPlatform.unregister(parentPlatform, null, null); |
| 156 | 164 | } |
| ... | ... | @@ -203,8 +211,24 @@ public class PlatformController { |
| 203 | 211 | if (updateResult) { |
| 204 | 212 | // 保存时启用就发送注册 |
| 205 | 213 | if (parentPlatform.isEnable()) { |
| 206 | - // 只要保存就发送注册 | |
| 207 | - commanderForPlatform.register(parentPlatform, null, null); | |
| 214 | + // 保存时启用就发送注册 | |
| 215 | + if (parentPlatform.isEnable()) { | |
| 216 | + if (parentPlatformOld.isStatus()) { | |
| 217 | + commanderForPlatform.unregister(parentPlatformOld, null, null); | |
| 218 | + try { | |
| 219 | + Thread.sleep(500); | |
| 220 | + } catch (InterruptedException e) { | |
| 221 | + e.printStackTrace(); | |
| 222 | + } | |
| 223 | + // 只要保存就发送注册 | |
| 224 | + commanderForPlatform.register(parentPlatform, null, null); | |
| 225 | + }else { | |
| 226 | + // 只要保存就发送注册 | |
| 227 | + commanderForPlatform.register(parentPlatform, null, null); | |
| 228 | + } | |
| 229 | + } else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()){ // 关闭启用时注销 | |
| 230 | + commanderForPlatform.unregister(parentPlatformOld, null, null); | |
| 231 | + } | |
| 208 | 232 | } else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()){ // 关闭启用时注销 |
| 209 | 233 | commanderForPlatform.unregister(parentPlatform, null, null); |
| 210 | 234 | } | ... | ... |