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