Commit cbd2bc8e99a20d1ff65fb1171961e86c790ab024

Authored by 648540858
Committed by GitHub
2 parents 2f165d59 df34954c

Merge pull request #63 from lawrencehj/wvp-28181-2.0

实现级联点播的RTP推送
Showing 28 changed files with 243 additions and 152 deletions
src/main/java/com/genersoft/iot/vmp/conf/SipPlatformRunner.java
@@ -3,7 +3,6 @@ package com.genersoft.iot.vmp.conf; @@ -3,7 +3,6 @@ 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;  
7 import com.genersoft.iot.vmp.storager.IRedisCatchStorage; 6 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
8 import com.genersoft.iot.vmp.storager.IVideoManagerStorager; 7 import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
9 import org.springframework.beans.factory.annotation.Autowired; 8 import org.springframework.beans.factory.annotation.Autowired;
src/main/java/com/genersoft/iot/vmp/gb28181/bean/SendRtpItem.java
@@ -22,7 +22,12 @@ public class SendRtpItem { @@ -22,7 +22,12 @@ public class SendRtpItem {
22 */ 22 */
23 private String platformId; 23 private String platformId;
24 24
25 - /** 25 + /**
  26 + * 对应设备id
  27 + */
  28 + private String deviceId;
  29 +
  30 + /**
26 * 通道id 31 * 通道id
27 */ 32 */
28 private String channelId; 33 private String channelId;
@@ -92,6 +97,14 @@ public class SendRtpItem { @@ -92,6 +97,14 @@ public class SendRtpItem {
92 this.platformId = platformId; 97 this.platformId = platformId;
93 } 98 }
94 99
  100 + public String getDeviceId() {
  101 + return deviceId;
  102 + }
  103 +
  104 + public void setDeviceId(String deviceId) {
  105 + this.deviceId = deviceId;
  106 + }
  107 +
95 public String getChannelId() { 108 public String getChannelId() {
96 return channelId; 109 return channelId;
97 } 110 }
src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java
1 package com.genersoft.iot.vmp.gb28181.event.offline; 1 package com.genersoft.iot.vmp.gb28181.event.offline;
2 2
3 -import org.slf4j.Logger;  
4 -import org.slf4j.LoggerFactory;  
5 import org.springframework.beans.factory.annotation.Autowired; 3 import org.springframework.beans.factory.annotation.Autowired;
6 -import org.springframework.beans.factory.annotation.Value;  
7 import org.springframework.data.redis.connection.Message; 4 import org.springframework.data.redis.connection.Message;
8 -import org.springframework.data.redis.connection.MessageListener;  
9 import org.springframework.data.redis.listener.KeyExpirationEventMessageListener; 5 import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
10 import org.springframework.data.redis.listener.RedisMessageListenerContainer; 6 import org.springframework.data.redis.listener.RedisMessageListenerContainer;
11 import org.springframework.stereotype.Component; 7 import org.springframework.stereotype.Component;
@@ -13,8 +9,6 @@ import org.springframework.stereotype.Component; @@ -13,8 +9,6 @@ import org.springframework.stereotype.Component;
13 import com.genersoft.iot.vmp.common.VideoManagerConstants; 9 import com.genersoft.iot.vmp.common.VideoManagerConstants;
14 import com.genersoft.iot.vmp.gb28181.event.EventPublisher; 10 import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
15 11
16 -import java.nio.charset.StandardCharsets;  
17 -  
18 /** 12 /**
19 * @Description:设备心跳超时监听,借助redis过期特性,进行监听,监听到说明设备心跳超时,发送离线事件 13 * @Description:设备心跳超时监听,借助redis过期特性,进行监听,监听到说明设备心跳超时,发送离线事件
20 * @author: swwheihei 14 * @author: swwheihei
src/main/java/com/genersoft/iot/vmp/gb28181/event/platformKeepaliveExpire/PlatformKeepaliveExpireEvent.java
@@ -7,6 +7,11 @@ import org.springframework.context.ApplicationEvent; @@ -7,6 +7,11 @@ import org.springframework.context.ApplicationEvent;
7 */ 7 */
8 public class PlatformKeepaliveExpireEvent extends ApplicationEvent { 8 public class PlatformKeepaliveExpireEvent extends ApplicationEvent {
9 9
  10 + /**
  11 + * Add default serial version ID
  12 + */
  13 + private static final long serialVersionUID = 1L;
  14 +
10 private String platformGbID; 15 private String platformGbID;
11 16
12 public PlatformKeepaliveExpireEvent(Object source) { 17 public PlatformKeepaliveExpireEvent(Object source) {
src/main/java/com/genersoft/iot/vmp/gb28181/event/platformKeepaliveExpire/PlatformKeepaliveExpireEventLister.java
@@ -2,7 +2,6 @@ package com.genersoft.iot.vmp.gb28181.event.platformKeepaliveExpire; @@ -2,7 +2,6 @@ package com.genersoft.iot.vmp.gb28181.event.platformKeepaliveExpire;
2 2
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.bean.PlatformRegister;  
6 import com.genersoft.iot.vmp.gb28181.event.EventPublisher; 5 import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
7 import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; 6 import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
8 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; 7 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
@@ -52,14 +51,14 @@ public class PlatformKeepaliveExpireEventLister implements ApplicationListener<P @@ -52,14 +51,14 @@ public class PlatformKeepaliveExpireEventLister implements ApplicationListener<P
52 } 51 }
53 ParentPlatform parentPlatform = storager.queryParentPlatById(event.getPlatformGbID()); 52 ParentPlatform parentPlatform = storager.queryParentPlatById(event.getPlatformGbID());
54 ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(event.getPlatformGbID()); 53 ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(event.getPlatformGbID());
55 - parentPlatformCatch.setParentPlatform(parentPlatform);  
56 - if (parentPlatform == null) {  
57 - logger.debug("平台心跳到期事件事件触发,但平台已经删除!!! 平台国标ID:" + event.getPlatformGbID()); 54 + if (parentPlatformCatch == null) {
58 return; 55 return;
59 } 56 }
60 - if (parentPlatformCatch == null) { 57 + if (parentPlatform == null) {
  58 + logger.debug("平台心跳到期事件事件触发,但平台已经删除!!! 平台国标ID:" + event.getPlatformGbID());
61 return; 59 return;
62 } 60 }
  61 + parentPlatformCatch.setParentPlatform(parentPlatform);
63 // 发送心跳 62 // 发送心跳
64 if (parentPlatformCatch.getKeepAliveReply() >= 3) { 63 if (parentPlatformCatch.getKeepAliveReply() >= 3) {
65 // 有3次未收到心跳回复, 设置平台状态为离线, 开始重新注册 64 // 有3次未收到心跳回复, 设置平台状态为离线, 开始重新注册
src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEvent.java
1 package com.genersoft.iot.vmp.gb28181.event.platformNotRegister; 1 package com.genersoft.iot.vmp.gb28181.event.platformNotRegister;
2 2
3 -import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;  
4 import org.springframework.context.ApplicationEvent; 3 import org.springframework.context.ApplicationEvent;
5 4
6 public class PlatformNotRegisterEvent extends ApplicationEvent { 5 public class PlatformNotRegisterEvent extends ApplicationEvent {
7 6
  7 + /**
  8 + * Add default serial version ID
  9 + */
  10 + private static final long serialVersionUID = 1L;
  11 +
8 private String platformGbID; 12 private String platformGbID;
9 13
10 public PlatformNotRegisterEvent(Object source) { 14 public PlatformNotRegisterEvent(Object source) {
src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEventLister.java
1 package com.genersoft.iot.vmp.gb28181.event.platformNotRegister; 1 package com.genersoft.iot.vmp.gb28181.event.platformNotRegister;
2 2
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.event.online.OnlineEvent;  
5 -import com.genersoft.iot.vmp.gb28181.event.online.OnlineEventListener;  
6 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; 4 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
7 import com.genersoft.iot.vmp.storager.IVideoManagerStorager; 5 import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
8 -import com.genersoft.iot.vmp.utils.redis.RedisUtil;  
9 import org.slf4j.Logger; 6 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory; 7 import org.slf4j.LoggerFactory;
11 import org.springframework.beans.factory.annotation.Autowired; 8 import org.springframework.beans.factory.annotation.Autowired;
12 -import org.springframework.context.ApplicationEvent;  
13 import org.springframework.context.ApplicationListener; 9 import org.springframework.context.ApplicationListener;
14 import org.springframework.stereotype.Component; 10 import org.springframework.stereotype.Component;
15 11
@@ -27,11 +23,12 @@ public class PlatformNotRegisterEventLister implements ApplicationListener<Platf @@ -27,11 +23,12 @@ public class PlatformNotRegisterEventLister implements ApplicationListener<Platf
27 23
28 @Autowired 24 @Autowired
29 private IVideoManagerStorager storager; 25 private IVideoManagerStorager storager;
  26 +
30 @Autowired 27 @Autowired
31 private SIPCommanderFroPlatform sipCommanderFroPlatform; 28 private SIPCommanderFroPlatform sipCommanderFroPlatform;
32 29
33 - @Autowired  
34 - private RedisUtil redis; 30 + // @Autowired
  31 + // private RedisUtil redis;
35 32
36 @Override 33 @Override
37 public void onApplicationEvent(PlatformNotRegisterEvent event) { 34 public void onApplicationEvent(PlatformNotRegisterEvent event) {
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorFactory.java
@@ -4,25 +4,17 @@ import javax.sip.RequestEvent; @@ -4,25 +4,17 @@ import javax.sip.RequestEvent;
4 import javax.sip.ResponseEvent; 4 import javax.sip.ResponseEvent;
5 import javax.sip.SipProvider; 5 import javax.sip.SipProvider;
6 import javax.sip.header.CSeqHeader; 6 import javax.sip.header.CSeqHeader;
7 -import javax.sip.header.CallIdHeader;  
8 -import javax.sip.header.Header;  
9 import javax.sip.message.Request; 7 import javax.sip.message.Request;
10 import javax.sip.message.Response; 8 import javax.sip.message.Response;
11 9
12 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; 10 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
13 import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; 11 import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
14 import com.genersoft.iot.vmp.storager.IRedisCatchStorage; 12 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
15 -import com.alibaba.fastjson.JSON;  
16 import com.genersoft.iot.vmp.gb28181.transmit.response.impl.*; 13 import com.genersoft.iot.vmp.gb28181.transmit.response.impl.*;
17 -import com.genersoft.iot.vmp.gb28181.transmit.response.impl.*;  
18 -import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;  
19 import com.genersoft.iot.vmp.vmanager.service.IPlayService; 14 import com.genersoft.iot.vmp.vmanager.service.IPlayService;
20 -import org.slf4j.Logger;  
21 -import org.slf4j.LoggerFactory;  
22 // import org.slf4j.Logger; 15 // import org.slf4j.Logger;
23 // import org.slf4j.LoggerFactory; 16 // import org.slf4j.LoggerFactory;
24 import org.springframework.beans.factory.annotation.Autowired; 17 import org.springframework.beans.factory.annotation.Autowired;
25 -import org.springframework.beans.factory.annotation.Qualifier;  
26 import org.springframework.context.annotation.Lazy; 18 import org.springframework.context.annotation.Lazy;
27 import org.springframework.stereotype.Component; 19 import org.springframework.stereotype.Component;
28 20
@@ -59,7 +51,7 @@ import com.genersoft.iot.vmp.utils.redis.RedisUtil; @@ -59,7 +51,7 @@ import com.genersoft.iot.vmp.utils.redis.RedisUtil;
59 @Component 51 @Component
60 public class SIPProcessorFactory { 52 public class SIPProcessorFactory {
61 53
62 - private final static Logger logger = LoggerFactory.getLogger(SIPProcessorFactory.class); 54 + // private final static Logger logger = LoggerFactory.getLogger(SIPProcessorFactory.class);
63 55
64 @Autowired 56 @Autowired
65 private SipConfig sipConfig; 57 private SipConfig sipConfig;
@@ -156,6 +148,8 @@ public class SIPProcessorFactory { @@ -156,6 +148,8 @@ public class SIPProcessorFactory {
156 } else if (Request.ACK.equals(method)) { 148 } else if (Request.ACK.equals(method)) {
157 AckRequestProcessor processor = new AckRequestProcessor(); 149 AckRequestProcessor processor = new AckRequestProcessor();
158 processor.setRequestEvent(evt); 150 processor.setRequestEvent(evt);
  151 + processor.setRedisCatchStorage(redisCatchStorage);
  152 + processor.setZlmrtpServerFactory(zlmrtpServerFactory);
159 return processor; 153 return processor;
160 } else if (Request.BYE.equals(method)) { 154 } else if (Request.BYE.equals(method)) {
161 ByeRequestProcessor processor = new ByeRequestProcessor(); 155 ByeRequestProcessor processor = new ByeRequestProcessor();
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java
@@ -5,8 +5,6 @@ import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; @@ -5,8 +5,6 @@ import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
5 import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; 5 import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
6 6
7 import javax.sip.header.WWWAuthenticateHeader; 7 import javax.sip.header.WWWAuthenticateHeader;
8 -import java.nio.channels.Channel;  
9 -import java.util.List;  
10 8
11 public interface ISIPCommanderForPlatform { 9 public interface ISIPCommanderForPlatform {
12 10
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java
1 package com.genersoft.iot.vmp.gb28181.transmit.cmd; 1 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.Device;  
5 -import com.genersoft.iot.vmp.gb28181.bean.Host;  
6 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; 4 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
7 -import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;  
8 import org.springframework.beans.factory.annotation.Autowired; 5 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.beans.factory.annotation.Qualifier; 6 import org.springframework.beans.factory.annotation.Qualifier;
10 import org.springframework.stereotype.Component; 7 import org.springframework.stereotype.Component;
@@ -16,10 +13,8 @@ import javax.sip.address.SipURI; @@ -16,10 +13,8 @@ import javax.sip.address.SipURI;
16 import javax.sip.header.*; 13 import javax.sip.header.*;
17 import javax.sip.message.Request; 14 import javax.sip.message.Request;
18 import javax.validation.constraints.NotNull; 15 import javax.validation.constraints.NotNull;
19 -import java.nio.channels.Channel;  
20 import java.text.ParseException; 16 import java.text.ParseException;
21 import java.util.ArrayList; 17 import java.util.ArrayList;
22 -import java.util.List;  
23 import java.util.UUID; 18 import java.util.UUID;
24 19
25 /** 20 /**
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java
@@ -2,7 +2,6 @@ package com.genersoft.iot.vmp.gb28181.transmit.cmd; @@ -2,7 +2,6 @@ package com.genersoft.iot.vmp.gb28181.transmit.cmd;
2 2
3 import java.text.ParseException; 3 import java.text.ParseException;
4 import java.util.ArrayList; 4 import java.util.ArrayList;
5 -import java.util.UUID;  
6 5
7 import javax.sip.InvalidArgumentException; 6 import javax.sip.InvalidArgumentException;
8 import javax.sip.PeerUnavailableException; 7 import javax.sip.PeerUnavailableException;
@@ -12,17 +11,13 @@ import javax.sip.address.Address; @@ -12,17 +11,13 @@ import javax.sip.address.Address;
12 import javax.sip.address.SipURI; 11 import javax.sip.address.SipURI;
13 import javax.sip.header.*; 12 import javax.sip.header.*;
14 import javax.sip.message.Request; 13 import javax.sip.message.Request;
15 -import javax.validation.constraints.NotNull;  
16 14
17 -import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;  
18 import org.springframework.beans.factory.annotation.Autowired; 15 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.beans.factory.annotation.Qualifier; 16 import org.springframework.beans.factory.annotation.Qualifier;
20 import org.springframework.stereotype.Component; 17 import org.springframework.stereotype.Component;
21 18
22 import com.genersoft.iot.vmp.conf.SipConfig; 19 import com.genersoft.iot.vmp.conf.SipConfig;
23 import com.genersoft.iot.vmp.gb28181.bean.Device; 20 import com.genersoft.iot.vmp.gb28181.bean.Device;
24 -import com.genersoft.iot.vmp.gb28181.bean.Host;  
25 -import org.springframework.util.DigestUtils;  
26 21
27 /** 22 /**
28 * @Description:摄像头命令request创造器 TODO 冗余代码太多待优化 23 * @Description:摄像头命令request创造器 TODO 冗余代码太多待优化
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
1 package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl; 1 package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl;
2 2
3 -import com.genersoft.iot.vmp.conf.SipConfig;  
4 -import com.genersoft.iot.vmp.gb28181.bean.Device; 3 +//import com.genersoft.iot.vmp.conf.SipConfig;
  4 +//import com.genersoft.iot.vmp.gb28181.bean.Device;
5 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; 5 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
6 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; 6 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
7 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch; 7 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
8 import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; 8 import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
9 -import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; 9 +//import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
10 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; 10 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
11 import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderPlarformProvider; 11 import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderPlarformProvider;
12 -import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider; 12 +//import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider;
13 import com.genersoft.iot.vmp.storager.IRedisCatchStorage; 13 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
14 -import com.genersoft.iot.vmp.storager.IVideoManagerStorager; 14 +//import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
15 import org.springframework.beans.factory.annotation.Autowired; 15 import org.springframework.beans.factory.annotation.Autowired;
16 import org.springframework.beans.factory.annotation.Qualifier; 16 import org.springframework.beans.factory.annotation.Qualifier;
17 import org.springframework.beans.factory.annotation.Value; 17 import org.springframework.beans.factory.annotation.Value;
@@ -22,28 +22,26 @@ import javax.sip.*; @@ -22,28 +22,26 @@ import javax.sip.*;
22 import javax.sip.header.CallIdHeader; 22 import javax.sip.header.CallIdHeader;
23 import javax.sip.header.WWWAuthenticateHeader; 23 import javax.sip.header.WWWAuthenticateHeader;
24 import javax.sip.message.Request; 24 import javax.sip.message.Request;
25 -import java.nio.channels.Channel;  
26 import java.text.ParseException; 25 import java.text.ParseException;
27 -import java.util.List;  
28 import java.util.UUID; 26 import java.util.UUID;
29 27
30 @Component 28 @Component
31 public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { 29 public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
32 30
33 - @Autowired  
34 - private SipConfig sipConfig; 31 + // @Autowired
  32 + // private SipConfig sipConfig;
35 33
36 - @Autowired  
37 - private SIPRequestHeaderProvider headerProvider; 34 + // @Autowired
  35 + // private SIPRequestHeaderProvider headerProvider;
38 36
39 @Autowired 37 @Autowired
40 private SIPRequestHeaderPlarformProvider headerProviderPlarformProvider; 38 private SIPRequestHeaderPlarformProvider headerProviderPlarformProvider;
41 39
42 - @Autowired  
43 - private VideoStreamSessionManager streamSession; 40 + // @Autowired
  41 + // private VideoStreamSessionManager streamSession;
44 42
45 - @Autowired  
46 - private IVideoManagerStorager storager; 43 + // @Autowired
  44 + // private IVideoManagerStorager storager;
47 45
48 @Autowired 46 @Autowired
49 private IRedisCatchStorage redisCatchStorage; 47 private IRedisCatchStorage redisCatchStorage;
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java
1 package com.genersoft.iot.vmp.gb28181.transmit.request.impl; 1 package com.genersoft.iot.vmp.gb28181.transmit.request.impl;
2 2
  3 +import java.util.HashMap;
  4 +import java.util.Map;
  5 +
3 import javax.sip.*; 6 import javax.sip.*;
4 -import javax.sip.message.Request; 7 +//import javax.sip.message.Request;
5 8
  9 +import com.genersoft.iot.vmp.common.StreamInfo;
  10 +import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
6 import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcessor; 11 import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcessor;
  12 +import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
  13 +import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
7 14
8 -import gov.nist.javax.sip.header.CSeq; 15 +import org.springframework.stereotype.Component;
9 16
10 /** 17 /**
11 * @Description:ACK请求处理器 18 * @Description:ACK请求处理器
12 * @author: swwheihei 19 * @author: swwheihei
13 * @date: 2020年5月3日 下午5:31:45 20 * @date: 2020年5月3日 下午5:31:45
14 */ 21 */
  22 +@Component
15 public class AckRequestProcessor extends SIPRequestAbstractProcessor { 23 public class AckRequestProcessor extends SIPRequestAbstractProcessor {
16 - 24 +
  25 + //@Autowired
  26 + private IRedisCatchStorage redisCatchStorage;
  27 +
  28 + //@Autowired
  29 + private ZLMRTPServerFactory zlmrtpServerFactory;
  30 +
  31 +
17 /** 32 /**
18 * 处理 ACK请求 33 * 处理 ACK请求
19 * 34 *
@@ -21,25 +36,77 @@ public class AckRequestProcessor extends SIPRequestAbstractProcessor { @@ -21,25 +36,77 @@ public class AckRequestProcessor extends SIPRequestAbstractProcessor {
21 */ 36 */
22 @Override 37 @Override
23 public void process(RequestEvent evt) { 38 public void process(RequestEvent evt) {
24 - Request request = evt.getRequest(); 39 + //Request request = evt.getRequest();
25 Dialog dialog = evt.getDialog(); 40 Dialog dialog = evt.getDialog();
26 - DialogState state = dialog.getState();  
27 if (dialog == null) return; 41 if (dialog == null) return;
28 - if (request.getMethod().equals(Request.INVITE) && dialog.getState()== DialogState.CONFIRMED) {  
29 - // TODO 查询并开始推流  
30 - }  
31 - try {  
32 - Request ackRequest = null;  
33 - CSeq csReq = (CSeq) request.getHeader(CSeq.NAME);  
34 - ackRequest = dialog.createAck(csReq.getSeqNumber());  
35 - dialog.sendAck(ackRequest);  
36 - System.out.println("send ack to callee:" + ackRequest.toString());  
37 - } catch (SipException e) {  
38 - e.printStackTrace();  
39 - } catch (InvalidArgumentException e) {  
40 - e.printStackTrace(); 42 + //DialogState state = dialog.getState();
  43 + if (/*request.getMethod().equals(Request.INVITE) &&*/ dialog.getState()== DialogState.CONFIRMED) {
  44 + String remoteUri = dialog.getRemoteParty().getURI().toString();
  45 + String localUri = dialog.getLocalParty().getURI().toString();
  46 + String platformGbId = remoteUri.substring(remoteUri.indexOf(":") + 1, remoteUri.indexOf("@"));
  47 + String channelId = localUri.substring(remoteUri.indexOf(":") + 1, remoteUri.indexOf("@"));
  48 + SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(platformGbId, channelId);
  49 + String is_Udp = sendRtpItem.isTcp() ? "0" : "1";
  50 + String deviceId = sendRtpItem.getDeviceId();
  51 + StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
  52 + System.out.println(platformGbId);
  53 + System.out.println(channelId);
  54 + Map<String, Object> param = new HashMap<>();
  55 + param.put("vhost","__defaultVhost__");
  56 + param.put("app","rtp");
  57 + param.put("stream",streamInfo.getStreamId());
  58 + param.put("ssrc", sendRtpItem.getSsrc());
  59 + param.put("dst_url",sendRtpItem.getIp());
  60 + param.put("dst_port", sendRtpItem.getPort());
  61 + param.put("is_udp", is_Udp);
  62 + //param.put ("src_port", sendRtpItem.getLocalPort());
  63 + // 设备推流查询,成功后才能转推
  64 + boolean rtpPushed = false;
  65 + long startTime = System.currentTimeMillis();
  66 + while (!rtpPushed) {
  67 + try {
  68 + if (System.currentTimeMillis() - startTime < 30 * 1000) {
  69 + if (zlmrtpServerFactory.isRtpReady(streamInfo.getStreamId())) {
  70 + rtpPushed = true;
  71 + zlmrtpServerFactory.startSendRtpStream(param);
  72 + } else {
  73 + Thread.sleep(2000);
  74 + continue;
  75 + }
  76 + }
  77 + } catch (InterruptedException e) {
  78 + e.printStackTrace();
  79 + }
  80 + }
41 } 81 }
  82 + // try {
  83 + // Request ackRequest = null;
  84 + // CSeq csReq = (CSeq) request.getHeader(CSeq.NAME);
  85 + // ackRequest = dialog.createAck(csReq.getSeqNumber());
  86 + // dialog.sendAck(ackRequest);
  87 + // System.out.println("send ack to callee:" + ackRequest.toString());
  88 + // } catch (SipException e) {
  89 + // e.printStackTrace();
  90 + // } catch (InvalidArgumentException e) {
  91 + // e.printStackTrace();
  92 + // }
42 93
43 } 94 }
44 95
  96 + public IRedisCatchStorage getRedisCatchStorage() {
  97 + return redisCatchStorage;
  98 + }
  99 +
  100 + public void setRedisCatchStorage(IRedisCatchStorage redisCatchStorage) {
  101 + this.redisCatchStorage = redisCatchStorage;
  102 + }
  103 +
  104 + public ZLMRTPServerFactory getZlmrtpServerFactory() {
  105 + return zlmrtpServerFactory;
  106 + }
  107 +
  108 + public void setZlmrtpServerFactory(ZLMRTPServerFactory zlmrtpServerFactory) {
  109 + this.zlmrtpServerFactory = zlmrtpServerFactory;
  110 + }
  111 +
45 } 112 }
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java
@@ -7,14 +7,10 @@ import javax.sip.SipException; @@ -7,14 +7,10 @@ import javax.sip.SipException;
7 import javax.sip.SipFactory; 7 import javax.sip.SipFactory;
8 import javax.sip.address.Address; 8 import javax.sip.address.Address;
9 import javax.sip.address.SipURI; 9 import javax.sip.address.SipURI;
10 -import javax.sip.header.ContentTypeHeader;  
11 -import javax.sip.header.FromHeader;  
12 -import javax.sip.header.HeaderFactory;  
13 -import javax.sip.header.SubjectHeader; 10 +import javax.sip.header.*;
14 import javax.sip.message.Request; 11 import javax.sip.message.Request;
15 import javax.sip.message.Response; 12 import javax.sip.message.Response;
16 13
17 -import com.alibaba.fastjson.JSONObject;  
18 import com.genersoft.iot.vmp.conf.MediaServerConfig; 14 import com.genersoft.iot.vmp.conf.MediaServerConfig;
19 import com.genersoft.iot.vmp.gb28181.bean.Device; 15 import com.genersoft.iot.vmp.gb28181.bean.Device;
20 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; 16 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
@@ -27,17 +23,12 @@ import com.genersoft.iot.vmp.storager.IRedisCatchStorage; @@ -27,17 +23,12 @@ import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
27 import com.genersoft.iot.vmp.storager.IVideoManagerStorager; 23 import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
28 import com.genersoft.iot.vmp.vmanager.play.bean.PlayResult; 24 import com.genersoft.iot.vmp.vmanager.play.bean.PlayResult;
29 import com.genersoft.iot.vmp.vmanager.service.IPlayService; 25 import com.genersoft.iot.vmp.vmanager.service.IPlayService;
30 -import gov.nist.javax.sdp.fields.SDPFormat;  
31 import gov.nist.javax.sip.address.AddressImpl; 26 import gov.nist.javax.sip.address.AddressImpl;
32 import gov.nist.javax.sip.address.SipUri; 27 import gov.nist.javax.sip.address.SipUri;
33 import org.slf4j.Logger; 28 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory; 29 import org.slf4j.LoggerFactory;
35 -import org.springframework.beans.factory.annotation.Autowired;  
36 30
37 -import java.io.IOException;  
38 import java.text.ParseException; 31 import java.text.ParseException;
39 -import java.util.List;  
40 -import java.util.UUID;  
41 import java.util.Vector; 32 import java.util.Vector;
42 33
43 /** 34 /**
@@ -45,6 +36,7 @@ import java.util.Vector; @@ -45,6 +36,7 @@ import java.util.Vector;
45 * @author: panll 36 * @author: panll
46 * @date: 2021年1月14日 37 * @date: 2021年1月14日
47 */ 38 */
  39 +@SuppressWarnings("rawtypes")
48 public class InviteRequestProcessor extends SIPRequestAbstractProcessor { 40 public class InviteRequestProcessor extends SIPRequestAbstractProcessor {
49 41
50 private final static Logger logger = LoggerFactory.getLogger(MessageRequestProcessor.class); 42 private final static Logger logger = LoggerFactory.getLogger(MessageRequestProcessor.class);
@@ -122,8 +114,10 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor { @@ -122,8 +114,10 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor {
122 114
123 // jainSip不支持y=字段, 移除移除以解析。 115 // jainSip不支持y=字段, 移除移除以解析。
124 int ssrcIndex = contentString.indexOf("y="); 116 int ssrcIndex = contentString.indexOf("y=");
125 - String ssrc = contentString.substring(ssrcIndex + 2, contentString.length())  
126 - .replace("\r\n", "").replace("\n", ""); 117 + String ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
  118 + //ssrc规定长度为10字节,不取余下长度以避免后续还有“f=”字段
  119 + // String ssrc = contentString.substring(ssrcIndex + 2, contentString.length())
  120 + // .replace("\r\n", "").replace("\n", "");
127 121
128 String substring = contentString.substring(0, contentString.indexOf("y=")); 122 String substring = contentString.substring(0, contentString.indexOf("y="));
129 SessionDescription sdp = SdpFactory.getInstance().createSessionDescription(substring); 123 SessionDescription sdp = SdpFactory.getInstance().createSessionDescription(substring);
@@ -131,9 +125,9 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor { @@ -131,9 +125,9 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor {
131 // 获取支持的格式 125 // 获取支持的格式
132 Vector mediaDescriptions = sdp.getMediaDescriptions(true); 126 Vector mediaDescriptions = sdp.getMediaDescriptions(true);
133 // 查看是否支持PS 负载96 127 // 查看是否支持PS 负载96
134 - String ip = null; 128 + //String ip = null;
135 int port = -1; 129 int port = -1;
136 - boolean recvonly = false; 130 + //boolean recvonly = false;
137 boolean mediaTransmissionTCP = false; 131 boolean mediaTransmissionTCP = false;
138 Boolean tcpActive = null; 132 Boolean tcpActive = null;
139 for (int i = 0; i < mediaDescriptions.size(); i++) { 133 for (int i = 0; i < mediaDescriptions.size(); i++) {
@@ -143,7 +137,7 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor { @@ -143,7 +137,7 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor {
143 Vector mediaFormats = media.getMediaFormats(false); 137 Vector mediaFormats = media.getMediaFormats(false);
144 if (mediaFormats.contains("96")) { 138 if (mediaFormats.contains("96")) {
145 port = media.getMediaPort(); 139 port = media.getMediaPort();
146 - String mediaType = media.getMediaType(); 140 + //String mediaType = media.getMediaType();
147 String protocol = media.getProtocol(); 141 String protocol = media.getProtocol();
148 142
149 // 区分TCP发流还是udp, 当前默认udp 143 // 区分TCP发流还是udp, 当前默认udp
@@ -169,7 +163,7 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor { @@ -169,7 +163,7 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor {
169 } 163 }
170 String username = sdp.getOrigin().getUsername(); 164 String username = sdp.getOrigin().getUsername();
171 String addressStr = sdp.getOrigin().getAddress(); 165 String addressStr = sdp.getOrigin().getAddress();
172 - String sessionName = sdp.getSessionName().getValue(); 166 + //String sessionName = sdp.getSessionName().getValue();
173 logger.info("[上级点播]用户:{}, 地址:{}:{}, ssrc:{}", username, addressStr, port, ssrc); 167 logger.info("[上级点播]用户:{}, 地址:{}:{}, ssrc:{}", username, addressStr, port, ssrc);
174 168
175 Device device = storager.queryVideoDeviceByPlatformIdAndChannelId(platformId, channelId); 169 Device device = storager.queryVideoDeviceByPlatformIdAndChannelId(platformId, channelId);
@@ -178,7 +172,7 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor { @@ -178,7 +172,7 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor {
178 responseAck(evt, Response.SERVER_INTERNAL_ERROR); 172 responseAck(evt, Response.SERVER_INTERNAL_ERROR);
179 return; 173 return;
180 } 174 }
181 - SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(ip, port, platformId, ssrc, channelId, 175 + SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(addressStr, port, ssrc, platformId, device.getDeviceId(), channelId,
182 mediaTransmissionTCP); 176 mediaTransmissionTCP);
183 if (tcpActive != null) { 177 if (tcpActive != null) {
184 sendRtpItem.setTcpActive(tcpActive); 178 sendRtpItem.setTcpActive(tcpActive);
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
@@ -370,31 +370,36 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { @@ -370,31 +370,36 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
370 private void processMessageDeviceInfo(RequestEvent evt) { 370 private void processMessageDeviceInfo(RequestEvent evt) {
371 try { 371 try {
372 Element rootElement = getRootElement(evt); 372 Element rootElement = getRootElement(evt);
  373 + String requestName = rootElement.getName();
373 Element deviceIdElement = rootElement.element("DeviceID"); 374 Element deviceIdElement = rootElement.element("DeviceID");
374 String deviceId = deviceIdElement.getTextTrim().toString(); 375 String deviceId = deviceIdElement.getTextTrim().toString();
375 -  
376 - Device device = storager.queryVideoDevice(deviceId);  
377 - if (device == null) {  
378 - return;  
379 - }  
380 - device.setName(XmlUtil.getText(rootElement, "DeviceName"));  
381 - device.setManufacturer(XmlUtil.getText(rootElement, "Manufacturer"));  
382 - device.setModel(XmlUtil.getText(rootElement, "Model"));  
383 - device.setFirmware(XmlUtil.getText(rootElement, "Firmware"));  
384 - if (StringUtils.isEmpty(device.getStreamMode())) {  
385 - device.setStreamMode("UDP");  
386 - }  
387 - storager.updateDevice(device);  
388 -  
389 - RequestMessage msg = new RequestMessage();  
390 - msg.setDeviceId(deviceId);  
391 - msg.setType(DeferredResultHolder.CALLBACK_CMD_DEVICEINFO);  
392 - msg.setData(device);  
393 - deferredResultHolder.invokeResult(msg);  
394 - // 回复200 OK  
395 - responseAck(evt);  
396 - if (offLineDetector.isOnline(deviceId)) {  
397 - publisher.onlineEventPublish(deviceId, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE); 376 + if (requestName.equals("Query")) {
  377 + // 回复200 OK
  378 + responseAck(evt);
  379 + } else {
  380 + Device device = storager.queryVideoDevice(deviceId);
  381 + if (device == null) {
  382 + return;
  383 + }
  384 + device.setName(XmlUtil.getText(rootElement, "DeviceName"));
  385 + device.setManufacturer(XmlUtil.getText(rootElement, "Manufacturer"));
  386 + device.setModel(XmlUtil.getText(rootElement, "Model"));
  387 + device.setFirmware(XmlUtil.getText(rootElement, "Firmware"));
  388 + if (StringUtils.isEmpty(device.getStreamMode())) {
  389 + device.setStreamMode("UDP");
  390 + }
  391 + storager.updateDevice(device);
  392 +
  393 + RequestMessage msg = new RequestMessage();
  394 + msg.setDeviceId(deviceId);
  395 + msg.setType(DeferredResultHolder.CALLBACK_CMD_DEVICEINFO);
  396 + msg.setData(device);
  397 + deferredResultHolder.invokeResult(msg);
  398 + // 回复200 OK
  399 + responseAck(evt);
  400 + if (offLineDetector.isOnline(deviceId)) {
  401 + publisher.onlineEventPublish(deviceId, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE);
  402 + }
398 } 403 }
399 } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { 404 } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
400 e.printStackTrace(); 405 e.printStackTrace();
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/response/impl/RegisterResponseProcessor.java
@@ -9,24 +9,15 @@ import com.genersoft.iot.vmp.gb28181.transmit.request.impl.RegisterRequestProces @@ -9,24 +9,15 @@ import com.genersoft.iot.vmp.gb28181.transmit.request.impl.RegisterRequestProces
9 import com.genersoft.iot.vmp.gb28181.transmit.response.ISIPResponseProcessor; 9 import com.genersoft.iot.vmp.gb28181.transmit.response.ISIPResponseProcessor;
10 import com.genersoft.iot.vmp.storager.IRedisCatchStorage; 10 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
11 import com.genersoft.iot.vmp.storager.IVideoManagerStorager; 11 import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
12 -import gov.nist.core.Host;  
13 -import gov.nist.javax.sip.address.AddressImpl;  
14 -import gov.nist.javax.sip.address.SipUri;  
15 -import gov.nist.javax.sip.header.To;  
16 import org.slf4j.Logger; 12 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory; 13 import org.slf4j.LoggerFactory;
18 import org.springframework.beans.factory.annotation.Autowired; 14 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.stereotype.Component; 15 import org.springframework.stereotype.Component;
20 16
21 import javax.sip.ResponseEvent; 17 import javax.sip.ResponseEvent;
22 -import javax.sip.address.Address;  
23 -import javax.sip.address.URI;  
24 import javax.sip.header.CallIdHeader; 18 import javax.sip.header.CallIdHeader;
25 -import javax.sip.header.ExpiresHeader;  
26 -import javax.sip.header.ToHeader;  
27 import javax.sip.header.WWWAuthenticateHeader; 19 import javax.sip.header.WWWAuthenticateHeader;
28 import javax.sip.message.Response; 20 import javax.sip.message.Response;
29 -import java.util.UUID;  
30 21
31 /** 22 /**
32 * @Description:Register响应处理器 23 * @Description:Register响应处理器
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
1 package com.genersoft.iot.vmp.media.zlm; 1 package com.genersoft.iot.vmp.media.zlm;
2 2
3 -import java.math.BigInteger;  
4 -import java.text.DecimalFormat;  
5 -import java.util.ArrayList;  
6 -import java.util.List;  
7 import java.util.UUID; 3 import java.util.UUID;
8 4
9 import com.alibaba.fastjson.JSON; 5 import com.alibaba.fastjson.JSON;
10 -import com.alibaba.fastjson.JSONArray;  
11 import com.genersoft.iot.vmp.common.StreamInfo; 6 import com.genersoft.iot.vmp.common.StreamInfo;
12 import com.genersoft.iot.vmp.conf.MediaServerConfig; 7 import com.genersoft.iot.vmp.conf.MediaServerConfig;
13 import com.genersoft.iot.vmp.gb28181.bean.Device; 8 import com.genersoft.iot.vmp.gb28181.bean.Device;
14 import com.genersoft.iot.vmp.storager.IRedisCatchStorage; 9 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
15 import com.genersoft.iot.vmp.storager.IVideoManagerStorager; 10 import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
16 -import com.genersoft.iot.vmp.utils.IpUtil;  
17 import com.genersoft.iot.vmp.vmanager.service.IPlayService; 11 import com.genersoft.iot.vmp.vmanager.service.IPlayService;
18 import org.slf4j.Logger; 12 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory; 13 import org.slf4j.LoggerFactory;
@@ -57,8 +51,8 @@ public class ZLMHttpHookListener { @@ -57,8 +51,8 @@ public class ZLMHttpHookListener {
57 @Autowired 51 @Autowired
58 private IRedisCatchStorage redisCatchStorage; 52 private IRedisCatchStorage redisCatchStorage;
59 53
60 - @Autowired  
61 - private ZLMRESTfulUtils zlmresTfulUtils; 54 + // @Autowired
  55 + // private ZLMRESTfulUtils zlmresTfulUtils;
62 56
63 @Autowired 57 @Autowired
64 private ZLMHttpHookSubscribe subscribe; 58 private ZLMHttpHookSubscribe subscribe;
@@ -217,8 +211,8 @@ public class ZLMHttpHookListener { @@ -217,8 +211,8 @@ public class ZLMHttpHookListener {
217 logger.debug("ZLM HOOK on_shell_login API调用,参数:" + json.toString()); 211 logger.debug("ZLM HOOK on_shell_login API调用,参数:" + json.toString());
218 } 212 }
219 // TODO 如果是带有rtpstream则开启按需拉流 213 // TODO 如果是带有rtpstream则开启按需拉流
220 - String app = json.getString("app");  
221 - String stream = json.getString("stream"); 214 + // String app = json.getString("app");
  215 + // String stream = json.getString("stream");
222 216
223 ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, json); 217 ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, json);
224 if (subscribe != null) subscribe.response(json); 218 if (subscribe != null) subscribe.response(json);
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java
@@ -119,4 +119,8 @@ public class ZLMRESTfulUtils { @@ -119,4 +119,8 @@ public class ZLMRESTfulUtils {
119 public JSONObject closeRtpServer(Map<String, Object> param) { 119 public JSONObject closeRtpServer(Map<String, Object> param) {
120 return sendPost("closeRtpServer",param); 120 return sendPost("closeRtpServer",param);
121 } 121 }
  122 +
  123 + public JSONObject startSendRtp(Map<String, Object> param) {
  124 + return sendPost("startSendRtp",param);
  125 + }
122 } 126 }
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
@@ -105,7 +105,7 @@ public class ZLMRTPServerFactory { @@ -105,7 +105,7 @@ public class ZLMRTPServerFactory {
105 * @param tcp 是否为tcp 105 * @param tcp 是否为tcp
106 * @return SendRtpItem 106 * @return SendRtpItem
107 */ 107 */
108 - public SendRtpItem createSendRtpItem(String ip, int port, String ssrc, String platformId, String channelId, boolean tcp){ 108 + public SendRtpItem createSendRtpItem(String ip, int port, String ssrc, String platformId, String deviceId, String channelId, boolean tcp){
109 String playSsrc = SsrcUtil.getPlaySsrc(); 109 String playSsrc = SsrcUtil.getPlaySsrc();
110 int localPort = createRTPServer(SsrcUtil.getPlaySsrc()); 110 int localPort = createRTPServer(SsrcUtil.getPlaySsrc());
111 if (localPort != -1) { 111 if (localPort != -1) {
@@ -119,9 +119,54 @@ public class ZLMRTPServerFactory { @@ -119,9 +119,54 @@ public class ZLMRTPServerFactory {
119 sendRtpItem.setPort(port); 119 sendRtpItem.setPort(port);
120 sendRtpItem.setSsrc(ssrc); 120 sendRtpItem.setSsrc(ssrc);
121 sendRtpItem.setPlatformId(platformId); 121 sendRtpItem.setPlatformId(platformId);
  122 + sendRtpItem.setDeviceId(deviceId);
122 sendRtpItem.setChannelId(channelId); 123 sendRtpItem.setChannelId(channelId);
123 sendRtpItem.setTcp(tcp); 124 sendRtpItem.setTcp(tcp);
124 sendRtpItem.setLocalPort(localPort); 125 sendRtpItem.setLocalPort(localPort);
125 return sendRtpItem; 126 return sendRtpItem;
126 } 127 }
  128 +
  129 + /**
  130 + *
  131 + */
  132 + public Boolean startSendRtpStream(Map<String, Object>param) {
  133 + Boolean result = false;
  134 + JSONObject jsonObject = zlmresTfulUtils.startSendRtp(param);
  135 + System.out.println(jsonObject);
  136 + if (jsonObject != null) {
  137 + switch (jsonObject.getInteger("code")){
  138 + case 0:
  139 + result= true;
  140 + logger.error("RTP推流请求成功,本地推流端口:" + jsonObject.getString("local_port"));
  141 + break;
  142 + // case -300: // id已经存在
  143 + // result = false;
  144 + // break;
  145 + // case -400: // 端口占用
  146 + // result= false;
  147 + // break;
  148 + default:
  149 + logger.error("RTP推流失败: " + jsonObject.getString("msg"));
  150 + break;
  151 + }
  152 + }else {
  153 + // 检查ZLM状态
  154 + logger.error("RTP推流失败: 请检查ZLM服务");
  155 + }
  156 + return result;
  157 + }
  158 +
  159 + /**
  160 + *
  161 + */
  162 + public Boolean isRtpReady(String streamId) {
  163 + JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId);
  164 + if (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")) {
  165 + logger.info("设备RTP推流成功");
  166 + return true;
  167 + } else {
  168 + logger.info("设备RTP推流未完成");
  169 + return false;
  170 + }
  171 + }
127 } 172 }
src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
@@ -4,7 +4,6 @@ import com.genersoft.iot.vmp.common.StreamInfo; @@ -4,7 +4,6 @@ import com.genersoft.iot.vmp.common.StreamInfo;
4 import com.genersoft.iot.vmp.conf.MediaServerConfig; 4 import com.genersoft.iot.vmp.conf.MediaServerConfig;
5 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; 5 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
6 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch; 6 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
7 -import com.genersoft.iot.vmp.gb28181.bean.PlatformRegister;  
8 import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; 7 import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
9 8
10 import java.util.Map; 9 import java.util.Map;
@@ -81,4 +80,13 @@ public interface IRedisCatchStorage { @@ -81,4 +80,13 @@ public interface IRedisCatchStorage {
81 void delPlatformRegisterInfo(String callId); 80 void delPlatformRegisterInfo(String callId);
82 81
83 void updateSendRTPSever(SendRtpItem sendRtpItem); 82 void updateSendRTPSever(SendRtpItem sendRtpItem);
  83 +
  84 + /**
  85 + * 查询RTP推送信息缓存
  86 + * @param platformGbId
  87 + * @param channelId
  88 + * @return sendRtpItem
  89 + */
  90 + SendRtpItem querySendRTPServer(String platformGbId, String channelId);
  91 +
84 } 92 }
src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java
1 package com.genersoft.iot.vmp.storager; 1 package com.genersoft.iot.vmp.storager;
2 2
3 import java.util.List; 3 import java.util.List;
4 -import java.util.Map;  
5 4
6 -import com.genersoft.iot.vmp.common.StreamInfo;  
7 import com.genersoft.iot.vmp.gb28181.bean.Device; 5 import com.genersoft.iot.vmp.gb28181.bean.Device;
8 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; 6 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
9 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; 7 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
10 import com.genersoft.iot.vmp.vmanager.platform.bean.ChannelReduce; 8 import com.genersoft.iot.vmp.vmanager.platform.bean.ChannelReduce;
11 import com.genersoft.iot.vmp.gb28181.bean.MobilePosition; 9 import com.genersoft.iot.vmp.gb28181.bean.MobilePosition;
12 import com.github.pagehelper.PageInfo; 10 import com.github.pagehelper.PageInfo;
13 -import gov.nist.javax.sip.stack.NioTcpMessageProcessor;  
14 -  
15 -import javax.swing.event.ChangeEvent;  
16 11
17 /** 12 /**
18 * @Description:视频设备数据存储接口 13 * @Description:视频设备数据存储接口
19 * @author: swwheihei 14 * @author: swwheihei
20 * @date: 2020年5月6日 下午2:14:31 15 * @date: 2020年5月6日 下午2:14:31
21 */ 16 */
  17 +@SuppressWarnings("rawtypes")
22 public interface IVideoManagerStorager { 18 public interface IVideoManagerStorager {
23 19
24 /** 20 /**
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
1 package com.genersoft.iot.vmp.storager.dao; 1 package com.genersoft.iot.vmp.storager.dao;
2 2
3 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; 3 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
4 -import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;  
5 import com.genersoft.iot.vmp.vmanager.platform.bean.ChannelReduce; 4 import com.genersoft.iot.vmp.vmanager.platform.bean.ChannelReduce;
6 import org.apache.ibatis.annotations.*; 5 import org.apache.ibatis.annotations.*;
7 import org.springframework.stereotype.Repository; 6 import org.springframework.stereotype.Repository;
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMapper.java
1 package com.genersoft.iot.vmp.storager.dao; 1 package com.genersoft.iot.vmp.storager.dao;
2 2
3 import com.genersoft.iot.vmp.gb28181.bean.Device; 3 import com.genersoft.iot.vmp.gb28181.bean.Device;
4 -import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;  
5 import org.apache.ibatis.annotations.*; 4 import org.apache.ibatis.annotations.*;
6 import org.springframework.stereotype.Repository; 5 import org.springframework.stereotype.Repository;
7 6
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
@@ -218,4 +218,11 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { @@ -218,4 +218,11 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
218 String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + sendRtpItem.getPlatformId() + "_" + sendRtpItem.getChannelId(); 218 String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + sendRtpItem.getPlatformId() + "_" + sendRtpItem.getChannelId();
219 redis.set(key, sendRtpItem); 219 redis.set(key, sendRtpItem);
220 } 220 }
  221 +
  222 + @Override
  223 + public SendRtpItem querySendRTPServer(String platformGbId, String channelId) {
  224 + String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + platformGbId + "_" + channelId;
  225 + return (SendRtpItem)redis.get(key);
  226 + }
  227 +
221 } 228 }
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
@@ -27,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional; @@ -27,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
27 * @author: swwheihei 27 * @author: swwheihei
28 * @date: 2020年5月6日 下午2:31:42 28 * @date: 2020年5月6日 下午2:31:42
29 */ 29 */
  30 +@SuppressWarnings("rawtypes")
30 @Component 31 @Component
31 public class VideoManagerStoragerImpl implements IVideoManagerStorager { 32 public class VideoManagerStoragerImpl implements IVideoManagerStorager {
32 33
src/main/java/com/genersoft/iot/vmp/vmanager/platform/PlatformController.java
1 package com.genersoft.iot.vmp.vmanager.platform; 1 package com.genersoft.iot.vmp.vmanager.platform;
2 2
3 -import com.alibaba.fastjson.JSON;  
4 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
5 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; 4 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
6 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; 5 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
@@ -18,10 +17,6 @@ import org.springframework.util.StringUtils; @@ -18,10 +17,6 @@ import org.springframework.util.StringUtils;
18 import org.springframework.web.bind.annotation.*; 17 import org.springframework.web.bind.annotation.*;
19 import com.genersoft.iot.vmp.conf.SipConfig; 18 import com.genersoft.iot.vmp.conf.SipConfig;
20 19
21 -import java.util.List;  
22 -import java.util.Map;  
23 -  
24 -  
25 @CrossOrigin 20 @CrossOrigin
26 @RestController 21 @RestController
27 @RequestMapping("/api") 22 @RequestMapping("/api")
src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java
1 package com.genersoft.iot.vmp.vmanager.play; 1 package com.genersoft.iot.vmp.vmanager.play;
2 2
3 -import com.alibaba.fastjson.JSON;  
4 import com.genersoft.iot.vmp.common.StreamInfo; 3 import com.genersoft.iot.vmp.common.StreamInfo;
5 import com.genersoft.iot.vmp.conf.MediaServerConfig; 4 import com.genersoft.iot.vmp.conf.MediaServerConfig;
6 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; 5 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
@@ -22,12 +21,10 @@ import org.springframework.web.bind.annotation.RequestMapping; @@ -22,12 +21,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
22 import org.springframework.web.bind.annotation.RestController; 21 import org.springframework.web.bind.annotation.RestController;
23 22
24 import com.alibaba.fastjson.JSONObject; 23 import com.alibaba.fastjson.JSONObject;
25 -import com.genersoft.iot.vmp.gb28181.bean.Device;  
26 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; 24 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
27 import com.genersoft.iot.vmp.storager.IVideoManagerStorager; 25 import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
28 import org.springframework.web.context.request.async.DeferredResult; 26 import org.springframework.web.context.request.async.DeferredResult;
29 27
30 -import javax.sip.message.Response;  
31 import java.util.UUID; 28 import java.util.UUID;
32 29
33 @CrossOrigin 30 @CrossOrigin
src/main/java/com/genersoft/iot/vmp/vmanager/service/impl/PlayServiceImpl.java
@@ -14,7 +14,6 @@ import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe; @@ -14,7 +14,6 @@ import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
14 import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; 14 import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
15 import com.genersoft.iot.vmp.storager.IRedisCatchStorage; 15 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
16 import com.genersoft.iot.vmp.storager.IVideoManagerStorager; 16 import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
17 -import com.genersoft.iot.vmp.vmanager.play.PlayController;  
18 import com.genersoft.iot.vmp.vmanager.play.bean.PlayResult; 17 import com.genersoft.iot.vmp.vmanager.play.bean.PlayResult;
19 import com.genersoft.iot.vmp.vmanager.service.IPlayService; 18 import com.genersoft.iot.vmp.vmanager.service.IPlayService;
20 import org.slf4j.Logger; 19 import org.slf4j.Logger;
@@ -25,7 +24,6 @@ import org.springframework.stereotype.Service; @@ -25,7 +24,6 @@ import org.springframework.stereotype.Service;
25 import org.springframework.web.context.request.async.DeferredResult; 24 import org.springframework.web.context.request.async.DeferredResult;
26 25
27 import javax.sip.message.Response; 26 import javax.sip.message.Response;
28 -import java.text.DecimalFormat;  
29 import java.util.UUID; 27 import java.util.UUID;
30 28
31 @Service 29 @Service