Merge branch 'wvp-28181-2.0'
# Conflicts: # src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java # src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/AckRequestProcessor.java # src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java # src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java # src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java
This commit is contained in:
@@ -10,14 +10,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sip.*;
|
||||
import java.util.Properties;
|
||||
import java.util.TooManyListenersException;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Configuration
|
||||
public class SipLayer{
|
||||
@@ -52,7 +48,9 @@ public class SipLayer{
|
||||
* 完整配置参考 gov.nist.javax.sip.SipStackImpl,需要下载源码
|
||||
* gov/nist/javax/sip/SipStackImpl.class
|
||||
*/
|
||||
properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "true");
|
||||
if (logger.isDebugEnabled()) {
|
||||
properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "false");
|
||||
}
|
||||
// 接收所有notify请求,即使没有订阅
|
||||
properties.setProperty("gov.nist.javax.sip.DELIVER_UNSOLICITED_NOTIFY", "true");
|
||||
// 为_NULL _对话框传递_终止的_事件
|
||||
@@ -63,13 +61,13 @@ public class SipLayer{
|
||||
properties.setProperty("gov.nist.javax.sip.RELIABLE_CONNECTION_KEEP_ALIVE_TIMEOUT", "60");
|
||||
|
||||
/**
|
||||
* sip_server_log.log 和 sip_debug_log.log public static final int TRACE_NONE =
|
||||
* 0; public static final int TRACE_MESSAGES = 16; public static final int
|
||||
* TRACE_EXCEPTION = 17; public static final int TRACE_DEBUG = 32;
|
||||
* sip_server_log.log 和 sip_debug_log.log ERROR, INFO, WARNING, OFF, DEBUG, TRACE
|
||||
*/
|
||||
properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "0");
|
||||
properties.setProperty("gov.nist.javax.sip.SERVER_LOG", "sip_server_log");
|
||||
properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", "sip_debug_log");
|
||||
properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "ERROR");
|
||||
// if (logger.isDebugEnabled()) {
|
||||
// properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "DEBUG");
|
||||
// }
|
||||
|
||||
sipStack = (SipStackImpl) sipFactory.createSipStack(properties);
|
||||
|
||||
return sipStack;
|
||||
|
||||
@@ -84,7 +84,7 @@ public class ParentPlatform {
|
||||
* 注册周期 (秒)
|
||||
*/
|
||||
@Schema(description = "注册周期 (秒)")
|
||||
private String expires;
|
||||
private int expires;
|
||||
|
||||
/**
|
||||
* 心跳周期(秒)
|
||||
@@ -286,11 +286,11 @@ public class ParentPlatform {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getExpires() {
|
||||
public int getExpires() {
|
||||
return expires;
|
||||
}
|
||||
|
||||
public void setExpires(String expires) {
|
||||
public void setExpires(int expires) {
|
||||
this.expires = expires;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,9 @@ public class ParentPlatformCatch {
|
||||
|
||||
private String id;
|
||||
|
||||
// 心跳未回复次数
|
||||
/**
|
||||
* 心跳未回复次数
|
||||
*/
|
||||
private int keepAliveReply;
|
||||
|
||||
// 注册未回复次数
|
||||
|
||||
@@ -14,6 +14,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author lin
|
||||
*/
|
||||
@Component
|
||||
public class SubscribeHolder {
|
||||
|
||||
|
||||
@@ -2,9 +2,6 @@ package com.genersoft.iot.vmp.gb28181.event;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.gb28181.event.device.RequestTimeoutEvent;
|
||||
import com.genersoft.iot.vmp.gb28181.event.platformKeepaliveExpire.PlatformKeepaliveExpireEvent;
|
||||
import com.genersoft.iot.vmp.gb28181.event.platformNotRegister.PlatformCycleRegisterEvent;
|
||||
import com.genersoft.iot.vmp.gb28181.event.platformNotRegister.PlatformNotRegisterEvent;
|
||||
import com.genersoft.iot.vmp.gb28181.event.record.RecordEndEvent;
|
||||
import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
|
||||
import com.genersoft.iot.vmp.media.zlm.event.ZLMOfflineEvent;
|
||||
@@ -31,36 +28,6 @@ public class EventPublisher {
|
||||
|
||||
@Autowired
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
/**
|
||||
* 平台心跳到期事件
|
||||
* @param platformGbId
|
||||
*/
|
||||
public void platformKeepaliveExpireEventPublish(String platformGbId){
|
||||
PlatformKeepaliveExpireEvent platformKeepaliveExpireEvent = new PlatformKeepaliveExpireEvent(this);
|
||||
platformKeepaliveExpireEvent.setPlatformGbID(platformGbId);
|
||||
applicationEventPublisher.publishEvent(platformKeepaliveExpireEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台未注册事件
|
||||
* @param platformGbId
|
||||
*/
|
||||
public void platformNotRegisterEventPublish(String platformGbId){
|
||||
PlatformNotRegisterEvent platformNotRegisterEvent = new PlatformNotRegisterEvent(this);
|
||||
platformNotRegisterEvent.setPlatformGbID(platformGbId);
|
||||
applicationEventPublisher.publishEvent(platformNotRegisterEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台周期注册事件
|
||||
* @param paltformGbId
|
||||
*/
|
||||
public void platformRegisterCycleEventPublish(String paltformGbId) {
|
||||
PlatformCycleRegisterEvent platformCycleRegisterEvent = new PlatformCycleRegisterEvent(this);
|
||||
platformCycleRegisterEvent.setPlatformGbID(paltformGbId);
|
||||
applicationEventPublisher.publishEvent(platformCycleRegisterEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备报警事件
|
||||
|
||||
@@ -59,9 +59,25 @@ public class SipSubscribe {
|
||||
void response(EventResult eventResult);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public enum EventResultType{
|
||||
// 超时
|
||||
timeout,
|
||||
// 回复
|
||||
response,
|
||||
// 事务已结束
|
||||
transactionTerminated,
|
||||
// 会话已结束
|
||||
dialogTerminated,
|
||||
// 设备未找到
|
||||
deviceNotFoundEvent
|
||||
}
|
||||
|
||||
public static class EventResult<EventObject>{
|
||||
public int statusCode;
|
||||
public String type;
|
||||
public EventResultType type;
|
||||
public String msg;
|
||||
public String callId;
|
||||
public Dialog dialog;
|
||||
@@ -76,7 +92,7 @@ public class SipSubscribe {
|
||||
ResponseEvent responseEvent = (ResponseEvent)event;
|
||||
Response response = responseEvent.getResponse();
|
||||
this.dialog = responseEvent.getDialog();
|
||||
this.type = "response";
|
||||
this.type = EventResultType.response;
|
||||
if (response != null) {
|
||||
this.msg = response.getReasonPhrase();
|
||||
this.statusCode = response.getStatusCode();
|
||||
@@ -85,28 +101,28 @@ public class SipSubscribe {
|
||||
|
||||
}else if (event instanceof TimeoutEvent) {
|
||||
TimeoutEvent timeoutEvent = (TimeoutEvent)event;
|
||||
this.type = "timeout";
|
||||
this.type = EventResultType.timeout;
|
||||
this.msg = "消息超时未回复";
|
||||
this.statusCode = -1024;
|
||||
this.dialog = timeoutEvent.getClientTransaction().getDialog();
|
||||
this.callId = this.dialog != null?timeoutEvent.getClientTransaction().getDialog().getCallId().getCallId(): null;
|
||||
}else if (event instanceof TransactionTerminatedEvent) {
|
||||
TransactionTerminatedEvent transactionTerminatedEvent = (TransactionTerminatedEvent)event;
|
||||
this.type = "transactionTerminated";
|
||||
this.type = EventResultType.transactionTerminated;
|
||||
this.msg = "事务已结束";
|
||||
this.statusCode = -1024;
|
||||
this.callId = transactionTerminatedEvent.getClientTransaction().getDialog().getCallId().getCallId();
|
||||
this.dialog = transactionTerminatedEvent.getClientTransaction().getDialog();
|
||||
}else if (event instanceof DialogTerminatedEvent) {
|
||||
DialogTerminatedEvent dialogTerminatedEvent = (DialogTerminatedEvent)event;
|
||||
this.type = "dialogTerminated";
|
||||
this.type = EventResultType.dialogTerminated;
|
||||
this.msg = "会话已结束";
|
||||
this.statusCode = -1024;
|
||||
this.callId = dialogTerminatedEvent.getDialog().getCallId().getCallId();
|
||||
this.dialog = dialogTerminatedEvent.getDialog();
|
||||
}else if (event instanceof DeviceNotFoundEvent) {
|
||||
DeviceNotFoundEvent deviceNotFoundEvent = (DeviceNotFoundEvent)event;
|
||||
this.type = "deviceNotFoundEvent";
|
||||
this.type = EventResultType.deviceNotFoundEvent;
|
||||
this.msg = "设备未找到";
|
||||
this.statusCode = -1024;
|
||||
this.dialog = deviceNotFoundEvent.getDialog();
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.genersoft.iot.vmp.gb28181.event.platformKeepaliveExpire;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* 平台心跳超时事件
|
||||
*/
|
||||
public class PlatformKeepaliveExpireEvent extends ApplicationEvent {
|
||||
|
||||
/**
|
||||
* Add default serial version ID
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String platformGbID;
|
||||
|
||||
public PlatformKeepaliveExpireEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
public String getPlatformGbID() {
|
||||
return platformGbID;
|
||||
}
|
||||
|
||||
public void setPlatformGbID(String platformGbID) {
|
||||
this.platformGbID = platformGbID;
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
package com.genersoft.iot.vmp.gb28181.event.platformKeepaliveExpire;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
|
||||
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sip.message.Response;
|
||||
|
||||
/**
|
||||
* @description: 平台心跳超时事件
|
||||
* @author: panll
|
||||
* @date: 2020年11月5日 10:00
|
||||
*/
|
||||
@Component
|
||||
public class PlatformKeepaliveExpireEventLister implements ApplicationListener<PlatformKeepaliveExpireEvent> {
|
||||
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(PlatformKeepaliveExpireEventLister.class);
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private ISIPCommanderForPlatform sipCommanderForPlatform;
|
||||
|
||||
@Autowired
|
||||
private SipSubscribe sipSubscribe;
|
||||
|
||||
@Autowired
|
||||
private EventPublisher publisher;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(@NotNull PlatformKeepaliveExpireEvent event) {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("平台心跳到期事件事件触发,平台国标ID:" + event.getPlatformGbID());
|
||||
}
|
||||
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(event.getPlatformGbID());
|
||||
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(event.getPlatformGbID());
|
||||
if (parentPlatformCatch == null) {
|
||||
return;
|
||||
}
|
||||
if (parentPlatform == null) {
|
||||
logger.debug("平台心跳到期事件事件触发,但平台已经删除!!! 平台国标ID:" + event.getPlatformGbID());
|
||||
return;
|
||||
}
|
||||
parentPlatformCatch.setParentPlatform(parentPlatform);
|
||||
// 发送心跳
|
||||
if (parentPlatformCatch.getKeepAliveReply() >= 3) {
|
||||
// 有3次未收到心跳回复, 设置平台状态为离线, 开始重新注册
|
||||
logger.warn("有3次未收到心跳回复,标记设置平台状态为离线, 并重新注册 平台国标ID:" + event.getPlatformGbID());
|
||||
storager.updateParentPlatformStatus(event.getPlatformGbID(), false);
|
||||
publisher.platformNotRegisterEventPublish(event.getPlatformGbID());
|
||||
parentPlatformCatch.setKeepAliveReply(0);
|
||||
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
|
||||
}else {
|
||||
// 再次发送心跳
|
||||
String callId = sipCommanderForPlatform.keepalive(parentPlatform);
|
||||
|
||||
parentPlatformCatch.setKeepAliveReply( parentPlatformCatch.getKeepAliveReply() + 1);
|
||||
// 存储心跳信息, 并设置状态为未回复, 如果多次过期仍未收到回复,则认为上级平台已经离线
|
||||
redisCatchStorage.updatePlatformKeepalive(parentPlatform);
|
||||
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
|
||||
|
||||
sipSubscribe.addOkSubscribe(callId, (SipSubscribe.EventResult eventResult) ->{
|
||||
if (eventResult.statusCode == Response.OK) {
|
||||
// 收到心跳响应信息,
|
||||
parentPlatformCatch.setKeepAliveReply(0);
|
||||
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.genersoft.iot.vmp.gb28181.event.platformNotRegister;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
public class PlatformCycleRegisterEvent extends ApplicationEvent {
|
||||
/**
|
||||
* Add default serial version ID
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String platformGbID;
|
||||
|
||||
public String getPlatformGbID() {
|
||||
return platformGbID;
|
||||
}
|
||||
|
||||
public void setPlatformGbID(String platformGbID) {
|
||||
this.platformGbID = platformGbID;
|
||||
}
|
||||
|
||||
public PlatformCycleRegisterEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.genersoft.iot.vmp.gb28181.event.platformNotRegister;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
@Component
|
||||
public class PlatformCycleRegisterEventLister implements ApplicationListener<PlatformCycleRegisterEvent> {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(PlatformCycleRegisterEventLister.class);
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
@Autowired
|
||||
private ISIPCommanderForPlatform sipCommanderFroPlatform;
|
||||
@Autowired
|
||||
private DynamicTask dynamicTask;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(PlatformCycleRegisterEvent event) {
|
||||
logger.info("上级平台周期注册事件");
|
||||
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(event.getPlatformGbID());
|
||||
if (parentPlatform == null) {
|
||||
logger.info("[ 平台未注册事件 ] 平台已经删除!!! 平台国标ID:" + event.getPlatformGbID());
|
||||
return;
|
||||
}
|
||||
String taskKey = "platform-cycle-register" + parentPlatform.getServerGBId();;
|
||||
SipSubscribe.Event okEvent = (responseEvent)->{
|
||||
dynamicTask.stop(taskKey);
|
||||
};
|
||||
dynamicTask.startCron(taskKey, ()->{
|
||||
logger.info("[平台注册]再次向平台注册,平台国标ID:" + event.getPlatformGbID());
|
||||
sipCommanderFroPlatform.register(parentPlatform, null, okEvent);
|
||||
}, Integer.parseInt(parentPlatform.getExpires())* 1000);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.genersoft.iot.vmp.gb28181.event.platformNotRegister;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
public class PlatformNotRegisterEvent extends ApplicationEvent {
|
||||
|
||||
/**
|
||||
* Add default serial version ID
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String platformGbID;
|
||||
|
||||
public PlatformNotRegisterEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
public String getPlatformGbID() {
|
||||
return platformGbID;
|
||||
}
|
||||
|
||||
public void setPlatformGbID(String platformGbID) {
|
||||
this.platformGbID = platformGbID;
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
package com.genersoft.iot.vmp.gb28181.event.platformNotRegister;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.conf.SipConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @description: 平台未注册事件,来源有二:
|
||||
* 1、平台新添加
|
||||
* 2、平台心跳超时
|
||||
* @author: panll
|
||||
* @date: 2020年11月24日 10:00
|
||||
*/
|
||||
@Component
|
||||
public class PlatformNotRegisterEventLister implements ApplicationListener<PlatformNotRegisterEvent> {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(PlatformNotRegisterEventLister.class);
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
@Autowired
|
||||
private IMediaServerService mediaServerService;
|
||||
|
||||
@Autowired
|
||||
private SIPCommanderFroPlatform sipCommanderFroPlatform;
|
||||
|
||||
@Autowired
|
||||
private ZLMRTPServerFactory zlmrtpServerFactory;
|
||||
|
||||
@Autowired
|
||||
private SipConfig config;
|
||||
|
||||
@Autowired
|
||||
private DynamicTask dynamicTask;
|
||||
|
||||
// @Autowired
|
||||
// private RedisUtil redis;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(PlatformNotRegisterEvent event) {
|
||||
|
||||
logger.info("[ 平台未注册事件 ]平台国标ID:" + event.getPlatformGbID());
|
||||
|
||||
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(event.getPlatformGbID());
|
||||
if (parentPlatform == null) {
|
||||
logger.info("[ 平台未注册事件 ] 平台已经删除!!! 平台国标ID:" + event.getPlatformGbID());
|
||||
return;
|
||||
}
|
||||
// 查询是否有推流, 如果有则都停止
|
||||
List<SendRtpItem> sendRtpItems = redisCatchStorage.querySendRTPServer(event.getPlatformGbID());
|
||||
if (sendRtpItems != null && sendRtpItems.size() > 0) {
|
||||
logger.info("[ 平台未注册事件 ] 停止[ {} ]的所有推流", event.getPlatformGbID());
|
||||
for (SendRtpItem sendRtpItem : sendRtpItems) {
|
||||
redisCatchStorage.deleteSendRTPServer(event.getPlatformGbID(), sendRtpItem.getChannelId(), null, null);
|
||||
MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("vhost", "__defaultVhost__");
|
||||
param.put("app", sendRtpItem.getApp());
|
||||
param.put("stream", sendRtpItem.getStreamId());
|
||||
zlmrtpServerFactory.stopSendRtpStream(mediaInfo, param);
|
||||
}
|
||||
|
||||
}
|
||||
String taskKey = "platform-not-register-" + parentPlatform.getServerGBId();
|
||||
SipSubscribe.Event okEvent = (responseEvent)->{
|
||||
dynamicTask.stop(taskKey);
|
||||
};
|
||||
dynamicTask.startCron(taskKey, ()->{
|
||||
logger.info("[平台注册]再次向平台注册,平台国标ID:" + event.getPlatformGbID());
|
||||
sipCommanderFroPlatform.register(parentPlatform, null, okEvent);
|
||||
}, config.getRegisterTimeInterval()* 1000);
|
||||
}
|
||||
}
|
||||
@@ -30,23 +30,10 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
@Autowired
|
||||
private IMediaServerService mediaServerService;
|
||||
|
||||
@Autowired
|
||||
private SIPCommanderFroPlatform sipCommanderFroPlatform;
|
||||
|
||||
@Autowired
|
||||
private ZLMRTPServerFactory zlmrtpServerFactory;
|
||||
|
||||
@Autowired
|
||||
private SipConfig config;
|
||||
|
||||
@Autowired
|
||||
private UserSetting userSetting;
|
||||
|
||||
@Autowired
|
||||
private IGbStreamService gbStreamService;
|
||||
|
||||
|
||||
@@ -60,7 +60,6 @@ public class MobilePositionSubscribeHandlerTask implements ISubscribeTask {
|
||||
// TODO 暂时只处理视频流的回复,后续增加对国标设备的支持
|
||||
List<DeviceChannel> gbStreams = storager.queryGbStreamListInPlatform(platform.getServerGBId());
|
||||
if (gbStreams.size() == 0) {
|
||||
logger.info("发送订阅时发现平台已经没有关联的直播流:{}", platform.getServerGBId());
|
||||
return;
|
||||
}
|
||||
for (DeviceChannel deviceChannel : gbStreams) {
|
||||
|
||||
@@ -71,7 +71,6 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
|
||||
@Override
|
||||
@Async
|
||||
public void processRequest(RequestEvent requestEvent) {
|
||||
logger.debug("\n收到请求:\n{}", requestEvent.getRequest());
|
||||
String method = requestEvent.getRequest().getMethod();
|
||||
ISIPRequestProcessor sipRequestProcessor = requestProcessorMap.get(method);
|
||||
if (sipRequestProcessor == null) {
|
||||
@@ -90,7 +89,6 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
|
||||
@Async
|
||||
public void processResponse(ResponseEvent responseEvent) {
|
||||
Response response = responseEvent.getResponse();
|
||||
logger.debug("\n收到响应:\n{}", responseEvent.getResponse());
|
||||
int status = response.getStatusCode();
|
||||
|
||||
if (((status >= 200) && (status < 300)) || status == Response.UNAUTHORIZED) { // Success!
|
||||
@@ -114,7 +112,7 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
|
||||
} else if ((status >= 100) && (status < 200)) {
|
||||
// 增加其它无需回复的响应,如101、180等
|
||||
} else {
|
||||
logger.warn("接收到失败的response响应!status:" + status + ",message:" + response.getReasonPhrase()/* .getContent().toString()*/);
|
||||
logger.warn("接收到失败的response响应!status:" + status + ",message:" + response.getReasonPhrase());
|
||||
if (responseEvent.getResponse() != null && sipSubscribe.getErrorSubscribesSize() > 0 ) {
|
||||
CallIdHeader callIdHeader = (CallIdHeader)responseEvent.getResponse().getHeader(CallIdHeader.NAME);
|
||||
if (callIdHeader != null) {
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.genersoft.iot.vmp.gb28181.transmit.cmd;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
@@ -98,7 +98,7 @@ public interface ISIPCommander {
|
||||
* @param device 视频设备
|
||||
* @param channelId 预览通道
|
||||
*/
|
||||
void playStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId, ZLMHttpHookSubscribe.Event event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent);
|
||||
void playStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId, ZlmHttpHookSubscribe.Event event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent);
|
||||
|
||||
/**
|
||||
* 请求回放视频流
|
||||
|
||||
@@ -15,7 +15,7 @@ public interface ISIPCommanderForPlatform {
|
||||
* @return
|
||||
*/
|
||||
boolean register(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent);
|
||||
boolean register(ParentPlatform parentPlatform, String callId, WWWAuthenticateHeader www, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent, boolean registerAgain);
|
||||
boolean register(ParentPlatform parentPlatform, String callId, WWWAuthenticateHeader www, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent, boolean registerAgain, boolean isRegister);
|
||||
|
||||
/**
|
||||
* 向上级平台注销
|
||||
@@ -30,7 +30,7 @@ public interface ISIPCommanderForPlatform {
|
||||
* @param parentPlatform
|
||||
* @return callId(作为接受回复的判定)
|
||||
*/
|
||||
String keepalive(ParentPlatform parentPlatform);
|
||||
String keepalive(ParentPlatform parentPlatform,SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.gb28181.transmit.cmd;
|
||||
import com.genersoft.iot.vmp.conf.SipConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.utils.HeaderUtils;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import gov.nist.javax.sip.message.MessageFactoryImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -75,7 +76,7 @@ public class SIPRequestHeaderPlarformProvider {
|
||||
}
|
||||
|
||||
|
||||
public Request createRegisterRequest(@NotNull ParentPlatform platform, long CSeq, String fromTag, String viaTag, CallIdHeader callIdHeader) throws ParseException, InvalidArgumentException, PeerUnavailableException {
|
||||
public Request createRegisterRequest(@NotNull ParentPlatform platform, long CSeq, String fromTag, String viaTag, CallIdHeader callIdHeader, boolean isRegister) throws ParseException, InvalidArgumentException, PeerUnavailableException {
|
||||
Request request = null;
|
||||
String sipAddress = sipConfig.getIp() + ":" + sipConfig.getPort();
|
||||
//请求行
|
||||
@@ -109,18 +110,20 @@ public class SIPRequestHeaderPlarformProvider {
|
||||
.createSipURI(platform.getDeviceGBId(), sipAddress));
|
||||
request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
|
||||
|
||||
ExpiresHeader expires = sipFactory.createHeaderFactory().createExpiresHeader(Integer.parseInt(platform.getExpires()));
|
||||
ExpiresHeader expires = sipFactory.createHeaderFactory().createExpiresHeader(isRegister ? platform.getExpires() : 0);
|
||||
request.addHeader(expires);
|
||||
|
||||
UserAgentHeader userAgentHeader = HeaderUtils.createUserAgentHeader(sipFactory);
|
||||
request.addHeader(userAgentHeader);
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
public Request createRegisterRequest(@NotNull ParentPlatform parentPlatform, String fromTag, String viaTag,
|
||||
String callId, WWWAuthenticateHeader www , CallIdHeader callIdHeader) throws ParseException, PeerUnavailableException, InvalidArgumentException {
|
||||
String callId, WWWAuthenticateHeader www , CallIdHeader callIdHeader, boolean isRegister) throws ParseException, PeerUnavailableException, InvalidArgumentException {
|
||||
|
||||
|
||||
Request registerRequest = createRegisterRequest(parentPlatform, redisCatchStorage.getCSEQ(), fromTag, viaTag, callIdHeader);
|
||||
Request registerRequest = createRegisterRequest(parentPlatform, redisCatchStorage.getCSEQ(), fromTag, viaTag, callIdHeader, isRegister);
|
||||
SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP() + ":" + parentPlatform.getServerPort());
|
||||
if (www == null) {
|
||||
AuthorizationHeader authorizationHeader = sipFactory.createHeaderFactory().createAuthorizationHeader("Digest");
|
||||
|
||||
@@ -12,6 +12,7 @@ import javax.sip.message.Request;
|
||||
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
|
||||
import com.genersoft.iot.vmp.gb28181.utils.HeaderUtils;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import gov.nist.javax.sip.SipProviderImpl;
|
||||
import gov.nist.javax.sip.SipStackImpl;
|
||||
@@ -266,15 +267,7 @@ public class SIPRequestHeaderProvider {
|
||||
Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory()
|
||||
.createSipURI(sipConfig.getId(), sipConfig.getIp() + ":" + sipConfig.getPort()));
|
||||
infoRequest.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
|
||||
List<String> agentParam = new ArrayList<>();
|
||||
agentParam.add("wvp-pro");
|
||||
// TODO 添加版本信息以及日期
|
||||
UserAgentHeader userAgentHeader = null;
|
||||
try {
|
||||
userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
UserAgentHeader userAgentHeader = HeaderUtils.createUserAgentHeader(sipFactory);
|
||||
infoRequest.addHeader(userAgentHeader);
|
||||
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application",
|
||||
|
||||
@@ -10,12 +10,12 @@ import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider;
|
||||
import com.genersoft.iot.vmp.gb28181.utils.HeaderUtils;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.HookType;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
||||
@@ -33,19 +33,15 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.sip.*;
|
||||
import javax.sip.address.Address;
|
||||
import javax.sip.address.SipURI;
|
||||
import javax.sip.address.URI;
|
||||
import javax.sip.header.*;
|
||||
import javax.sip.message.Request;
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description:设备能力接口,用于定义设备的控制、查询能力
|
||||
@@ -88,7 +84,7 @@ public class SIPCommander implements ISIPCommander {
|
||||
private UserSetting userSetting;
|
||||
|
||||
@Autowired
|
||||
private ZLMHttpHookSubscribe subscribe;
|
||||
private ZlmHttpHookSubscribe subscribe;
|
||||
|
||||
@Autowired
|
||||
private SipSubscribe sipSubscribe;
|
||||
@@ -351,7 +347,7 @@ public class SIPCommander implements ISIPCommander {
|
||||
*/
|
||||
@Override
|
||||
public void playStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,
|
||||
ZLMHttpHookSubscribe.Event event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) {
|
||||
ZlmHttpHookSubscribe.Event event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) {
|
||||
String stream = ssrcInfo.getStream();
|
||||
try {
|
||||
if (device == null) {
|
||||
@@ -640,7 +636,7 @@ public class SIPCommander implements ISIPCommander {
|
||||
hookEvent.call(new InviteStreamInfo(mediaServerItem, json, callIdHeader.getCallId(), "rtp", ssrcInfo.getStream()));
|
||||
subscribe.removeSubscribe(hookSubscribe);
|
||||
hookSubscribe.getContent().put("regist", false);
|
||||
hookSubscribe.getContent().put("schema", "rtmp");
|
||||
hookSubscribe.getContent().put("schema", "rtsp");
|
||||
// 添加流注销的订阅,注销了后向设备发送bye
|
||||
subscribe.addSubscribe(hookSubscribe,
|
||||
(MediaServerItem mediaServerItemForEnd, JSONObject jsonForEnd)->{
|
||||
@@ -780,15 +776,7 @@ public class SIPCommander implements ISIPCommander {
|
||||
// 增加Contact header
|
||||
Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort()));
|
||||
byeRequest.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
|
||||
List<String> agentParam = new ArrayList<>();
|
||||
agentParam.add("wvp-pro");
|
||||
// TODO 添加版本信息以及日期
|
||||
UserAgentHeader userAgentHeader = null;
|
||||
try {
|
||||
userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
UserAgentHeader userAgentHeader = HeaderUtils.createUserAgentHeader(sipFactory);
|
||||
byeRequest.addHeader(userAgentHeader);
|
||||
ClientTransaction clientTransaction = null;
|
||||
if("TCP".equals(protocol)) {
|
||||
@@ -1680,14 +1668,11 @@ public class SIPCommander implements ISIPCommander {
|
||||
clientTransaction = udpSipProvider.getNewClientTransaction(request);
|
||||
}
|
||||
if (request.getHeader(UserAgentHeader.NAME) == null) {
|
||||
List<String> agentParam = new ArrayList<>();
|
||||
agentParam.add("wvp-pro");
|
||||
// TODO 添加版本信息以及日期
|
||||
UserAgentHeader userAgentHeader = null;
|
||||
try {
|
||||
userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam);
|
||||
userAgentHeader = HeaderUtils.createUserAgentHeader(sipFactory);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
logger.error("添加UserAgentHeader失败", e);
|
||||
}
|
||||
request.addHeader(userAgentHeader);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderPlarformProvider;
|
||||
import com.genersoft.iot.vmp.storager.dao.dto.PlatformRegisterInfo;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
@@ -75,28 +77,21 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
|
||||
@Override
|
||||
public boolean register(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) {
|
||||
return register(parentPlatform, null, null, errorEvent, okEvent, false);
|
||||
return register(parentPlatform, null, null, errorEvent, okEvent, false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unregister(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) {
|
||||
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
|
||||
parentPlatform.setExpires("0");
|
||||
if (parentPlatformCatch != null) {
|
||||
parentPlatformCatch.setParentPlatform(parentPlatform);
|
||||
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
|
||||
}
|
||||
return register(parentPlatform, null, null, errorEvent, okEvent, false);
|
||||
return register(parentPlatform, null, null, errorEvent, okEvent, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean register(ParentPlatform parentPlatform, @Nullable String callId, @Nullable WWWAuthenticateHeader www,
|
||||
SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent, boolean registerAgain) {
|
||||
SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent, boolean registerAgain, boolean isRegister) {
|
||||
try {
|
||||
Request request;
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
if (!registerAgain ) {
|
||||
// //callid
|
||||
CallIdHeader callIdHeader = null;
|
||||
if(parentPlatform.getTransport().equals("TCP")) {
|
||||
callIdHeader = tcpSipProvider.getNewCallId();
|
||||
@@ -107,10 +102,10 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
|
||||
request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform,
|
||||
redisCatchStorage.getCSEQ(), "FromRegister" + tm,
|
||||
"z9hG4bK-" + UUID.randomUUID().toString().replace("-", ""), callIdHeader);
|
||||
"z9hG4bK-" + UUID.randomUUID().toString().replace("-", ""), callIdHeader, isRegister);
|
||||
// 将 callid 写入缓存, 等注册成功可以更新状态
|
||||
String callIdFromHeader = callIdHeader.getCallId();
|
||||
redisCatchStorage.updatePlatformRegisterInfo(callIdFromHeader, parentPlatform.getServerGBId());
|
||||
redisCatchStorage.updatePlatformRegisterInfo(callIdFromHeader, PlatformRegisterInfo.getInstance(parentPlatform.getServerGBId(), isRegister));
|
||||
|
||||
sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), (event)->{
|
||||
if (event != null) {
|
||||
@@ -127,7 +122,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
}else {
|
||||
CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
||||
: udpSipProvider.getNewCallId();
|
||||
request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, "FromRegister" + tm, null, callId, www, callIdHeader);
|
||||
request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, "FromRegister" + tm, null, callId, www, callIdHeader, isRegister);
|
||||
}
|
||||
|
||||
transmitRequest(parentPlatform, request, null, okEvent);
|
||||
@@ -145,7 +140,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String keepalive(ParentPlatform parentPlatform) {
|
||||
public String keepalive(ParentPlatform parentPlatform,SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) {
|
||||
String callId = null;
|
||||
try {
|
||||
String characterSet = parentPlatform.getCharacterSet();
|
||||
@@ -168,7 +163,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
UUID.randomUUID().toString().replace("-", ""),
|
||||
null,
|
||||
callIdHeader);
|
||||
transmitRequest(parentPlatform, request);
|
||||
transmitRequest(parentPlatform, request, errorEvent, okEvent);
|
||||
callId = callIdHeader.getCallId();
|
||||
} catch (ParseException | InvalidArgumentException | SipException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -59,6 +59,9 @@ public abstract class SIPRequestProcessorParent {
|
||||
public ServerTransaction getServerTransaction(RequestEvent evt) {
|
||||
Request request = evt.getRequest();
|
||||
ServerTransaction serverTransaction = evt.getServerTransaction();
|
||||
if (serverTransaction != null) {
|
||||
System.out.println(serverTransaction.getState().toString());
|
||||
}
|
||||
// 判断TCP还是UDP
|
||||
boolean isTcp = false;
|
||||
ViaHeader reqViaHeader = (ViaHeader) request.getHeader(ViaHeader.NAME);
|
||||
@@ -86,6 +89,8 @@ public abstract class SIPRequestProcessorParent {
|
||||
logger.error(e.getMessage());
|
||||
} catch (TransactionUnavailableException e) {
|
||||
logger.error(e.getMessage());
|
||||
}finally {
|
||||
|
||||
}
|
||||
}
|
||||
return serverTransaction;
|
||||
@@ -182,6 +187,10 @@ public abstract class SIPRequestProcessorParent {
|
||||
sipFactory.createAddressFactory().createSipURI(sipURI.getUser(), sipURI.getHost()+":"+sipURI.getPort()
|
||||
));
|
||||
response.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
if (serverTransaction == null) {
|
||||
|
||||
}
|
||||
getServerTransaction(evt).sendResponse(response);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,14 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.gb28181.session.AudioBroadcastManager;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
@@ -66,7 +68,7 @@ public class AckRequestProcessor extends SIPRequestProcessorParent implements In
|
||||
private IMediaServerService mediaServerService;
|
||||
|
||||
@Autowired
|
||||
private ZLMHttpHookSubscribe subscribe;
|
||||
private ZlmHttpHookSubscribe subscribe;
|
||||
|
||||
@Autowired
|
||||
private DynamicTask dynamicTask;
|
||||
|
||||
@@ -19,7 +19,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
|
||||
import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMMediaListManager;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
|
||||
@@ -50,7 +50,6 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sdp.*;
|
||||
import javax.sip.*;
|
||||
import javax.sip.address.SipURI;
|
||||
import javax.sip.header.CallIdHeader;
|
||||
import javax.sip.message.Request;
|
||||
import javax.sip.message.Response;
|
||||
@@ -337,7 +336,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
|
||||
Long finalStartTime = startTime;
|
||||
Long finalStopTime = stopTime;
|
||||
ZLMHttpHookSubscribe.Event hookEvent = (mediaServerItemInUSe, responseJSON) -> {
|
||||
ZlmHttpHookSubscribe.Event hookEvent = (mediaServerItemInUSe, responseJSON) -> {
|
||||
String app = responseJSON.getString("app");
|
||||
String stream = responseJSON.getString("stream");
|
||||
logger.info("[上级点播]下级已经开始推流。 回复200OK(SDP), {}/{}", app, stream);
|
||||
@@ -440,6 +439,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
streamId = String.format("%s_%s", device.getDeviceId(), channelId);
|
||||
}
|
||||
SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, null, device.isSsrcCheck(), false);
|
||||
logger.info(JSONObject.toJSONString(ssrcInfo));
|
||||
sendRtpItem.setStreamId(ssrcInfo.getStream());
|
||||
// 写入redis, 超时时回复
|
||||
redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
||||
|
||||
@@ -180,7 +180,6 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
|
||||
|
||||
private void processNotifyCatalogList(RequestEvent evt, Element rootElement) throws SipException {
|
||||
|
||||
System.out.println(evt.getRequest().toString());
|
||||
String platformId = SipUtils.getUserIdFromFromHeader(evt.getRequest());
|
||||
String deviceId = XmlUtil.getText(rootElement, "DeviceID");
|
||||
ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId);
|
||||
|
||||
@@ -164,7 +164,7 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme
|
||||
}
|
||||
}
|
||||
|
||||
if (channelId.equals(sipConfig.getId())) {
|
||||
if ("7".equals(deviceAlarm.getAlarmMethod()) ) {
|
||||
// 发送给平台的报警信息。 发送redis通知
|
||||
AlarmChannelMessage alarmChannelMessage = new AlarmChannelMessage();
|
||||
alarmChannelMessage.setAlarmSn(Integer.parseInt(deviceAlarm.getAlarmMethod()));
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction;
|
||||
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.response.SIPResponseProcessorAbstract;
|
||||
import com.genersoft.iot.vmp.gb28181.utils.HeaderUtils;
|
||||
import gov.nist.javax.sip.ResponseEventExt;
|
||||
import gov.nist.javax.sip.message.SIPResponse;
|
||||
import gov.nist.javax.sip.stack.SIPDialog;
|
||||
@@ -103,15 +104,7 @@ public class InviteResponseProcessor extends SIPResponseProcessorAbstract {
|
||||
}
|
||||
requestURI.setPort(event.getRemotePort());
|
||||
reqAck.setRequestURI(requestURI);
|
||||
List<String> agentParam = new ArrayList<>();
|
||||
agentParam.add("wvp-pro");
|
||||
// TODO 添加版本信息以及日期
|
||||
UserAgentHeader userAgentHeader = null;
|
||||
try {
|
||||
userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
UserAgentHeader userAgentHeader = HeaderUtils.createUserAgentHeader(sipFactory);
|
||||
reqAck.addHeader(userAgentHeader);
|
||||
Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort()));
|
||||
reqAck.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
|
||||
|
||||
@@ -6,8 +6,10 @@ import com.genersoft.iot.vmp.gb28181.bean.SubscribeHolder;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.response.SIPResponseProcessorAbstract;
|
||||
import com.genersoft.iot.vmp.service.IPlatformService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.storager.dao.dto.PlatformRegisterInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -44,6 +46,9 @@ public class RegisterResponseProcessor extends SIPResponseProcessorAbstract {
|
||||
@Autowired
|
||||
private SubscribeHolder subscribeHolder;
|
||||
|
||||
@Autowired
|
||||
private IPlatformService platformService;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
// 添加消息处理的订阅
|
||||
@@ -60,48 +65,39 @@ public class RegisterResponseProcessor extends SIPResponseProcessorAbstract {
|
||||
Response response = evt.getResponse();
|
||||
CallIdHeader callIdHeader = (CallIdHeader) response.getHeader(CallIdHeader.NAME);
|
||||
String callId = callIdHeader.getCallId();
|
||||
|
||||
String platformGBId = redisCatchStorage.queryPlatformRegisterInfo(callId);
|
||||
if (platformGBId == null) {
|
||||
logger.info(String.format("未找到callId: %s 的注册/注销平台id", callId ));
|
||||
PlatformRegisterInfo platformRegisterInfo = redisCatchStorage.queryPlatformRegisterInfo(callId);
|
||||
if (platformRegisterInfo == null) {
|
||||
logger.info(String.format("[国标级联]未找到callId: %s 的注册/注销平台id", callId ));
|
||||
return;
|
||||
}
|
||||
|
||||
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(platformGBId);
|
||||
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(platformRegisterInfo.getPlatformId());
|
||||
if (parentPlatformCatch == null) {
|
||||
logger.warn(String.format("[收到注册/注销%S请求]平台:%s,但是平台缓存信息未查询到!!!", response.getStatusCode(),platformGBId));
|
||||
logger.warn(String.format("[国标级联]收到注册/注销%S请求,平台:%s,但是平台缓存信息未查询到!!!", response.getStatusCode(),platformRegisterInfo.getPlatformId()));
|
||||
return;
|
||||
}
|
||||
String action = parentPlatformCatch.getParentPlatform().getExpires().equals("0") ? "注销" : "注册";
|
||||
logger.info(String.format("[%s %S响应]%s ", action, response.getStatusCode(), platformGBId ));
|
||||
|
||||
String action = platformRegisterInfo.isRegister() ? "注册" : "注销";
|
||||
logger.info(String.format("[国标级联]%s %S响应,%s ", action, response.getStatusCode(), platformRegisterInfo.getPlatformId() ));
|
||||
ParentPlatform parentPlatform = parentPlatformCatch.getParentPlatform();
|
||||
if (parentPlatform == null) {
|
||||
logger.warn(String.format("收到 %s %s的%S请求, 但是平台信息未查询到!!!", platformGBId, action, response.getStatusCode()));
|
||||
logger.warn(String.format("[国标级联]收到 %s %s的%S请求, 但是平台信息未查询到!!!", platformRegisterInfo.getPlatformId(), action, response.getStatusCode()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.getStatusCode() == 401) {
|
||||
if (response.getStatusCode() == Response.UNAUTHORIZED) {
|
||||
WWWAuthenticateHeader www = (WWWAuthenticateHeader)response.getHeader(WWWAuthenticateHeader.NAME);
|
||||
sipCommanderForPlatform.register(parentPlatform, callId, www, null, null, true);
|
||||
}else if (response.getStatusCode() == 200){
|
||||
// 注册/注销成功
|
||||
logger.info(String.format("%s %s成功", platformGBId, action));
|
||||
sipCommanderForPlatform.register(parentPlatform, callId, www, null, null, true, platformRegisterInfo.isRegister());
|
||||
}else if (response.getStatusCode() == Response.OK){
|
||||
|
||||
if (platformRegisterInfo.isRegister()) {
|
||||
platformService.online(parentPlatform);
|
||||
}else {
|
||||
platformService.offline(parentPlatform);
|
||||
}
|
||||
|
||||
// 注册/注销成功移除缓存的信息
|
||||
redisCatchStorage.delPlatformRegisterInfo(callId);
|
||||
redisCatchStorage.delPlatformCatchInfo(platformGBId);
|
||||
// 取回Expires设置,避免注销过程中被置为0
|
||||
ParentPlatform parentPlatformTmp = storager.queryParentPlatByServerGBId(platformGBId);
|
||||
if (parentPlatformTmp != null) {
|
||||
parentPlatformTmp.setStatus("注册".equals(action));
|
||||
redisCatchStorage.updatePlatformRegister(parentPlatformTmp);
|
||||
redisCatchStorage.updatePlatformKeepalive(parentPlatformTmp);
|
||||
parentPlatformCatch.setParentPlatform(parentPlatformTmp);
|
||||
}
|
||||
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
|
||||
storager.updateParentPlatformStatus(platformGBId, "注册".equals(action));
|
||||
if ("注销".equals(action)) {
|
||||
subscribeHolder.removeCatalogSubscribe(platformGBId);
|
||||
subscribeHolder.removeMobilePositionSubscribe(platformGBId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.genersoft.iot.vmp.gb28181.utils;
|
||||
|
||||
import javax.sip.PeerUnavailableException;
|
||||
import javax.sip.SipFactory;
|
||||
import javax.sip.header.UserAgentHeader;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 生成header的工具类
|
||||
* @author lin
|
||||
*/
|
||||
public class HeaderUtils {
|
||||
|
||||
public static UserAgentHeader createUserAgentHeader(SipFactory sipFactory) throws PeerUnavailableException, ParseException {
|
||||
List<String> agentParam = new ArrayList<>();
|
||||
agentParam.add("WVP PRO");
|
||||
// TODO 添加版本信息以及日期
|
||||
return sipFactory.createHeaderFactory().createUserAgentHeader(agentParam);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user