Merge branch '648540858:wvp-28181-2.0' into wvp-28181-2.0
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.genersoft.iot.vmp.gb28181.auth;
|
||||
|
||||
import com.genersoft.iot.vmp.storager.impl.VideoManagerStoragerImpl;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -20,13 +21,24 @@ public class RegisterLogicHandler {
|
||||
|
||||
@Autowired
|
||||
private SIPCommander cmder;
|
||||
|
||||
@Autowired
|
||||
private VideoManagerStoragerImpl storager;
|
||||
|
||||
public void onRegister(Device device) {
|
||||
// 只有第一次注册时调用查询设备信息,如需更新调用更新API接口
|
||||
// TODO 此处错误无法获取到通道
|
||||
Device device1 = storager.queryVideoDevice(device.getDeviceId());
|
||||
if (device.isFirsRegister()) {
|
||||
logger.info("[{}] 首次注册,查询设备信息以及通道信息", device.getDeviceId());
|
||||
cmder.deviceInfoQuery(device);
|
||||
cmder.catalogQuery(device, null);
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
cmder.deviceInfoQuery(device);
|
||||
Thread.sleep(100);
|
||||
cmder.catalogQuery(device, null);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +81,10 @@ public class SendRtpItem {
|
||||
*/
|
||||
private boolean isPlay;
|
||||
|
||||
private byte[] transaction;
|
||||
|
||||
private byte[] dialog;
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
@@ -200,4 +204,20 @@ public class SendRtpItem {
|
||||
public void setPlay(boolean play) {
|
||||
isPlay = play;
|
||||
}
|
||||
|
||||
public byte[] getTransaction() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
public void setTransaction(byte[] transaction) {
|
||||
this.transaction = transaction;
|
||||
}
|
||||
|
||||
public byte[] getDialog() {
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public void setDialog(byte[] dialog) {
|
||||
this.dialog = dialog;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,10 @@ package com.genersoft.iot.vmp.gb28181.event.offline;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.RedisKeyExpirationEventMessageListener;
|
||||
import com.genersoft.iot.vmp.conf.UserSetup;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -39,6 +42,9 @@ public class KeepaliveTimeoutListenerForPlatform extends RedisKeyExpirationEvent
|
||||
@Autowired
|
||||
private SipSubscribe sipSubscribe;
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorager storager;
|
||||
|
||||
public KeepaliveTimeoutListenerForPlatform(RedisMessageListenerContainer listenerContainer, UserSetup userSetup) {
|
||||
super(listenerContainer, userSetup);
|
||||
}
|
||||
@@ -61,15 +67,22 @@ public class KeepaliveTimeoutListenerForPlatform extends RedisKeyExpirationEvent
|
||||
String REGISTER_INFO_PREFIX = VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetup.getServerId() + "_";
|
||||
if (expiredKey.startsWith(PLATFORM_KEEPLIVEKEY_PREFIX)) {
|
||||
String platformGBId = expiredKey.substring(PLATFORM_KEEPLIVEKEY_PREFIX.length(),expiredKey.length());
|
||||
|
||||
publisher.platformKeepaliveExpireEventPublish(platformGBId);
|
||||
ParentPlatform platform = storager.queryParentPlatByServerGBId(platformGBId);
|
||||
if (platform != null) {
|
||||
publisher.platformKeepaliveExpireEventPublish(platformGBId);
|
||||
}
|
||||
}else if (expiredKey.startsWith(PLATFORM_REGISTER_PREFIX)) {
|
||||
String platformGBId = expiredKey.substring(PLATFORM_REGISTER_PREFIX.length(),expiredKey.length());
|
||||
|
||||
publisher.platformRegisterCycleEventPublish(platformGBId);
|
||||
ParentPlatform platform = storager.queryParentPlatByServerGBId(platformGBId);
|
||||
if (platform != null) {
|
||||
publisher.platformRegisterCycleEventPublish(platformGBId);
|
||||
}
|
||||
}else if (expiredKey.startsWith(KEEPLIVEKEY_PREFIX)){
|
||||
String deviceId = expiredKey.substring(KEEPLIVEKEY_PREFIX.length(),expiredKey.length());
|
||||
publisher.outlineEventPublish(deviceId, KEEPLIVEKEY_PREFIX);
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
if (device != null) {
|
||||
publisher.outlineEventPublish(deviceId, KEEPLIVEKEY_PREFIX);
|
||||
}
|
||||
}else if (expiredKey.startsWith(REGISTER_INFO_PREFIX)) {
|
||||
String callid = expiredKey.substring(REGISTER_INFO_PREFIX.length());
|
||||
SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult();
|
||||
|
||||
@@ -2,8 +2,13 @@ package com.genersoft.iot.vmp.gb28181.event.offline;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.UserSetup;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction;
|
||||
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
|
||||
import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
|
||||
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
|
||||
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 org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -32,6 +37,9 @@ public class OfflineEventListener implements ApplicationListener<OfflineEvent> {
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorager storager;
|
||||
|
||||
@Autowired
|
||||
private VideoStreamSessionManager streamSession;
|
||||
|
||||
@Autowired
|
||||
private RedisUtil redis;
|
||||
@@ -42,6 +50,14 @@ public class OfflineEventListener implements ApplicationListener<OfflineEvent> {
|
||||
@Autowired
|
||||
private EventPublisher eventPublisher;
|
||||
|
||||
|
||||
@Autowired
|
||||
private IMediaServerService mediaServerService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ZLMRTPServerFactory zlmrtpServerFactory;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(OfflineEvent event) {
|
||||
|
||||
@@ -73,5 +89,15 @@ public class OfflineEventListener implements ApplicationListener<OfflineEvent> {
|
||||
|
||||
// TODO 离线取消订阅
|
||||
|
||||
// 离线释放所有ssrc
|
||||
List<SsrcTransaction> ssrcTransactions = streamSession.getSsrcTransactionForAll(event.getDeviceId(), null, null, null);
|
||||
if (ssrcTransactions.size() > 0) {
|
||||
for (SsrcTransaction ssrcTransaction : ssrcTransactions) {
|
||||
mediaServerService.releaseSsrc(ssrcTransaction.getMediaServerId(), ssrcTransaction.getSsrc());
|
||||
mediaServerService.closeRTPServer(event.getDeviceId(), ssrcTransaction.getChannelId(), ssrcTransaction.getStream());
|
||||
streamSession.remove(event.getDeviceId(), ssrcTransaction.getChannelId(), ssrcTransaction.getStream());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class PlatformNotRegisterEventLister implements ApplicationListener<Platf
|
||||
stream.append(",");
|
||||
}
|
||||
stream.append(sendRtpItem.getStreamId());
|
||||
redisCatchStorage.deleteSendRTPServer(event.getPlatformGbID(), sendRtpItem.getChannelId());
|
||||
redisCatchStorage.deleteSendRTPServer(event.getPlatformGbID(), sendRtpItem.getChannelId(), null, null);
|
||||
MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("vhost", "__defaultVhost__");
|
||||
@@ -84,9 +84,7 @@ public class PlatformNotRegisterEventLister implements ApplicationListener<Platf
|
||||
zlmrtpServerFactory.stopSendRtpStream(mediaInfo, param);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Timer timer = new Timer();
|
||||
SipSubscribe.Event okEvent = (responseEvent)->{
|
||||
timer.cancel();
|
||||
|
||||
@@ -4,8 +4,6 @@ import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.conf.RedisKeyExpirationEventMessageListener;
|
||||
import com.genersoft.iot.vmp.conf.UserSetup;
|
||||
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -46,7 +44,7 @@ public class SubscribeListenerForPlatform extends RedisKeyExpirationEventMessage
|
||||
String PLATFORM_KEEPLIVEKEY_PREFIX = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + userSetup.getServerId() + "_";
|
||||
if (expiredKey.startsWith(PLATFORM_KEEPLIVEKEY_PREFIX)) {
|
||||
// 取消定时任务
|
||||
dynamicTask.stopCron(expiredKey);
|
||||
dynamicTask.stop(expiredKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,15 @@ public class VideoStreamSessionManager {
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public SIPDialog getDialogByCallId(String deviceId, String channelId, String callID){
|
||||
SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, callID, null);
|
||||
if (ssrcTransaction == null) return null;
|
||||
byte[] dialogByteArray = ssrcTransaction.getDialog();
|
||||
if (dialogByteArray == null) return null;
|
||||
SIPDialog dialog = (SIPDialog)SerializeUtils.deSerialize(dialogByteArray);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public SsrcTransaction getSsrcTransaction(String deviceId, String channelId, String callId, String stream){
|
||||
if (StringUtils.isEmpty(callId)) callId ="*";
|
||||
if (StringUtils.isEmpty(stream)) stream ="*";
|
||||
@@ -95,6 +104,21 @@ public class VideoStreamSessionManager {
|
||||
return (SsrcTransaction)redisUtil.get((String) scanResult.get(0));
|
||||
}
|
||||
|
||||
public List<SsrcTransaction> getSsrcTransactionForAll(String deviceId, String channelId, String callId, String stream){
|
||||
if (StringUtils.isEmpty(deviceId)) deviceId ="*";
|
||||
if (StringUtils.isEmpty(channelId)) channelId ="*";
|
||||
if (StringUtils.isEmpty(callId)) callId ="*";
|
||||
if (StringUtils.isEmpty(stream)) stream ="*";
|
||||
String key = VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetup.getServerId() + "_" + deviceId + "_" + channelId + "_" + callId+ "_" + stream;
|
||||
List<Object> scanResult = redisUtil.scan(key);
|
||||
if (scanResult.size() == 0) return null;
|
||||
List<SsrcTransaction> result = new ArrayList<>();
|
||||
for (Object keyObj : scanResult) {
|
||||
result.add((SsrcTransaction)redisUtil.get((String) keyObj));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getMediaServerId(String deviceId, String channelId, String stream){
|
||||
SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, null, stream);
|
||||
if (ssrcTransaction == null) return null;
|
||||
|
||||
@@ -63,7 +63,5 @@ public class GPSSubscribeTask implements Runnable{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,4 +96,11 @@ public interface ISIPCommanderForPlatform {
|
||||
* @param recordInfo 录像信息
|
||||
*/
|
||||
boolean recordInfo(DeviceChannel deviceChannel, ParentPlatform parentPlatform, String fromTag, RecordInfo recordInfo);
|
||||
|
||||
/**
|
||||
* 向发起点播的上级回复bye
|
||||
* @param platform 平台信息
|
||||
* @param callId callId
|
||||
*/
|
||||
void streamByeCmd(ParentPlatform platform, String callId);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.conf.SipConfig;
|
||||
import com.genersoft.iot.vmp.conf.UserSetup;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
@@ -85,6 +86,9 @@ public class SIPCommander implements ISIPCommander {
|
||||
@Autowired
|
||||
private IMediaServerService mediaServerService;
|
||||
|
||||
@Autowired
|
||||
private DynamicTask dynamicTask;
|
||||
|
||||
|
||||
/**
|
||||
* 云台方向放控制,使用配置文件中的默认镜头移动速度
|
||||
@@ -330,7 +334,8 @@ public class SIPCommander implements ISIPCommander {
|
||||
* @param errorEvent sip错误订阅
|
||||
*/
|
||||
@Override
|
||||
public void playStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId, ZLMHttpHookSubscribe.Event event, SipSubscribe.Event errorEvent) {
|
||||
public void playStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,
|
||||
ZLMHttpHookSubscribe.Event event, SipSubscribe.Event errorEvent) {
|
||||
String streamId = ssrcInfo.getStream();
|
||||
try {
|
||||
if (device == null) return;
|
||||
@@ -342,15 +347,13 @@ public class SIPCommander implements ISIPCommander {
|
||||
subscribeKey.put("app", "rtp");
|
||||
subscribeKey.put("stream", streamId);
|
||||
subscribeKey.put("regist", true);
|
||||
subscribeKey.put("schema", "rtmp");
|
||||
subscribeKey.put("mediaServerId", mediaServerItem.getId());
|
||||
subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey,
|
||||
(MediaServerItem mediaServerItemInUse, JSONObject json)->{
|
||||
if (userSetup.isWaitTrack() && json.getJSONArray("tracks") == null) return;
|
||||
if (event != null) {
|
||||
event.response(mediaServerItemInUse, json);
|
||||
}
|
||||
|
||||
// subscribe.removeSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey);
|
||||
});
|
||||
//
|
||||
StringBuffer content = new StringBuffer(200);
|
||||
@@ -419,7 +422,7 @@ public class SIPCommander implements ISIPCommander {
|
||||
|
||||
transmitRequest(device, request, (e -> {
|
||||
streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
|
||||
mediaServerService.releaseSsrc(mediaServerItem, ssrcInfo.getSsrc());
|
||||
mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
|
||||
errorEvent.response(e);
|
||||
}), e ->{
|
||||
// 这里为例避免一个通道的点播只有一个callID这个参数使用一个固定值
|
||||
@@ -458,8 +461,6 @@ public class SIPCommander implements ISIPCommander {
|
||||
logger.debug("录像回放添加订阅,订阅内容:" + subscribeKey.toString());
|
||||
subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey,
|
||||
(MediaServerItem mediaServerItemInUse, JSONObject json)->{
|
||||
System.out.println(344444);
|
||||
if (userSetup.isWaitTrack() && json.getJSONArray("tracks") == null) return;
|
||||
if (event != null) {
|
||||
event.response(mediaServerItemInUse, json);
|
||||
}
|
||||
@@ -565,7 +566,6 @@ public class SIPCommander implements ISIPCommander {
|
||||
logger.debug("录像回放添加订阅,订阅内容:" + subscribeKey.toString());
|
||||
subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey,
|
||||
(MediaServerItem mediaServerItemInUse, JSONObject json)->{
|
||||
if (userSetup.isWaitTrack() && json.getJSONArray("tracks") == null) return;
|
||||
event.response(mediaServerItemInUse, json);
|
||||
subscribe.removeSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey);
|
||||
});
|
||||
@@ -662,6 +662,7 @@ public class SIPCommander implements ISIPCommander {
|
||||
@Override
|
||||
public void streamByeCmd(String deviceId, String channelId, String stream, SipSubscribe.Event okEvent) {
|
||||
try {
|
||||
SsrcTransaction ssrcTransaction = streamSession.getSsrcTransaction(deviceId, channelId, null, stream);
|
||||
ClientTransaction transaction = streamSession.getTransactionByStream(deviceId, channelId, stream);
|
||||
if (transaction == null) {
|
||||
logger.warn("[ {} -> {}]停止视频流的时候发现事务已丢失", deviceId, channelId);
|
||||
@@ -715,10 +716,9 @@ public class SIPCommander implements ISIPCommander {
|
||||
|
||||
dialog.sendRequest(clientTransaction);
|
||||
|
||||
SsrcTransaction ssrcTransaction = streamSession.getSsrcTransaction(deviceId, channelId, callIdHeader.getCallId(), null);
|
||||
if (ssrcTransaction != null) {
|
||||
MediaServerItem mediaServerItem = mediaServerService.getOne(ssrcTransaction.getMediaServerId());
|
||||
mediaServerService.releaseSsrc(mediaServerItem, ssrcTransaction.getSsrc());
|
||||
mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcTransaction.getSsrc());
|
||||
mediaServerService.closeRTPServer(deviceId, channelId, ssrcTransaction.getStream());
|
||||
streamSession.remove(deviceId, channelId, ssrcTransaction.getStream());
|
||||
}
|
||||
@@ -1169,8 +1169,6 @@ public class SIPCommander implements ISIPCommander {
|
||||
*/
|
||||
@Override
|
||||
public boolean catalogQuery(Device device, SipSubscribe.Event errorEvent) {
|
||||
// 清空通道
|
||||
// storager.cleanChannelsForDevice(device.getDeviceId());
|
||||
try {
|
||||
StringBuffer catalogXml = new StringBuffer(200);
|
||||
catalogXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
|
||||
|
||||
@@ -5,8 +5,16 @@ import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderPlarformProvider;
|
||||
import com.genersoft.iot.vmp.gb28181.utils.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;
|
||||
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.utils.SerializeUtils;
|
||||
import gov.nist.javax.sip.SipProviderImpl;
|
||||
import gov.nist.javax.sip.SipStackImpl;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
import gov.nist.javax.sip.stack.SIPDialog;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -18,10 +26,14 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.sip.*;
|
||||
import javax.sip.address.SipURI;
|
||||
import javax.sip.header.CallIdHeader;
|
||||
import javax.sip.header.ViaHeader;
|
||||
import javax.sip.header.WWWAuthenticateHeader;
|
||||
import javax.sip.message.Request;
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.ParseException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -37,18 +49,24 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private IMediaServerService mediaServerService;
|
||||
|
||||
@Autowired
|
||||
private SipSubscribe sipSubscribe;
|
||||
|
||||
@Autowired
|
||||
private ZLMRTPServerFactory zlmrtpServerFactory;
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
@Qualifier(value="tcpSipProvider")
|
||||
private SipProvider tcpSipProvider;
|
||||
private SipProviderImpl tcpSipProvider;
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
@Qualifier(value="udpSipProvider")
|
||||
private SipProvider udpSipProvider;
|
||||
private SipProviderImpl udpSipProvider;
|
||||
|
||||
@Override
|
||||
public boolean register(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) {
|
||||
@@ -57,13 +75,12 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
|
||||
@Override
|
||||
public boolean unregister(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) {
|
||||
parentPlatform.setExpires("0");
|
||||
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
|
||||
if (parentPlatformCatch != null) {
|
||||
parentPlatformCatch.setParentPlatform(parentPlatform);
|
||||
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
|
||||
}
|
||||
|
||||
parentPlatform.setExpires("0");
|
||||
return register(parentPlatform, null, null, errorEvent, okEvent, false);
|
||||
}
|
||||
|
||||
@@ -543,4 +560,62 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void streamByeCmd(ParentPlatform platform, String callId) {
|
||||
if (platform == null) {
|
||||
return;
|
||||
}
|
||||
SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(platform.getServerGBId(), null, null, callId);
|
||||
if (sendRtpItem != null) {
|
||||
String mediaServerId = sendRtpItem.getMediaServerId();
|
||||
MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
|
||||
if (mediaServerItem != null) {
|
||||
mediaServerService.releaseSsrc(mediaServerItem.getId(), sendRtpItem.getSsrc());
|
||||
zlmrtpServerFactory.closeRTPServer(mediaServerItem, sendRtpItem.getStreamId());
|
||||
}
|
||||
byte[] dialogByteArray = sendRtpItem.getDialog();
|
||||
if (dialogByteArray != null) {
|
||||
SIPDialog dialog = (SIPDialog) SerializeUtils.deSerialize(dialogByteArray);
|
||||
SipStack sipStack = udpSipProvider.getSipStack();
|
||||
SIPDialog sipDialog = ((SipStackImpl) sipStack).putDialog(dialog);
|
||||
if (dialog != sipDialog) {
|
||||
dialog = sipDialog;
|
||||
} else {
|
||||
try {
|
||||
dialog.setSipProvider(udpSipProvider);
|
||||
Field sipStackField = SIPDialog.class.getDeclaredField("sipStack");
|
||||
sipStackField.setAccessible(true);
|
||||
sipStackField.set(dialog, sipStack);
|
||||
Field eventListenersField = SIPDialog.class.getDeclaredField("eventListeners");
|
||||
eventListenersField.setAccessible(true);
|
||||
eventListenersField.set(dialog, new HashSet<>());
|
||||
|
||||
byte[] transactionByteArray = sendRtpItem.getTransaction();
|
||||
ClientTransaction clientTransaction = (ClientTransaction) SerializeUtils.deSerialize(transactionByteArray);
|
||||
Request byeRequest = dialog.createRequest(Request.BYE);
|
||||
SipURI byeURI = (SipURI) byeRequest.getRequestURI();
|
||||
SIPRequest request = (SIPRequest) clientTransaction.getRequest();
|
||||
byeURI.setHost(request.getRemoteAddress().getHostName());
|
||||
byeURI.setPort(request.getRemotePort());
|
||||
if ("TCP".equals(platform.getTransport())) {
|
||||
clientTransaction = tcpSipProvider.getNewClientTransaction(byeRequest);
|
||||
} else if ("UDP".equals(platform.getTransport())) {
|
||||
clientTransaction = udpSipProvider.getNewClientTransaction(byeRequest);
|
||||
}
|
||||
dialog.sendRequest(clientTransaction);
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor;
|
||||
@@ -22,6 +23,7 @@ import javax.sip.Dialog;
|
||||
import javax.sip.DialogState;
|
||||
import javax.sip.RequestEvent;
|
||||
import javax.sip.address.SipURI;
|
||||
import javax.sip.header.CallIdHeader;
|
||||
import javax.sip.header.FromHeader;
|
||||
import javax.sip.header.HeaderAddress;
|
||||
import javax.sip.header.ToHeader;
|
||||
@@ -60,6 +62,9 @@ public class AckRequestProcessor extends SIPRequestProcessorParent implements In
|
||||
@Autowired
|
||||
private ZLMHttpHookSubscribe subscribe;
|
||||
|
||||
@Autowired
|
||||
private DynamicTask dynamicTask;
|
||||
|
||||
|
||||
/**
|
||||
* 处理 ACK请求
|
||||
@@ -68,13 +73,16 @@ public class AckRequestProcessor extends SIPRequestProcessorParent implements In
|
||||
*/
|
||||
@Override
|
||||
public void process(RequestEvent evt) {
|
||||
logger.info("ACK请求: {}", ((System.currentTimeMillis())));
|
||||
Dialog dialog = evt.getDialog();
|
||||
CallIdHeader callIdHeader = (CallIdHeader)evt.getRequest().getHeader(CallIdHeader.NAME);
|
||||
if (dialog == null) return;
|
||||
if (dialog.getState()== DialogState.CONFIRMED) {
|
||||
String platformGbId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(FromHeader.NAME)).getAddress().getURI()).getUser();
|
||||
logger.info("ACK请求: platformGbId->{}", platformGbId);
|
||||
// 取消设置的超时任务
|
||||
dynamicTask.stop(callIdHeader.getCallId());
|
||||
String channelId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(ToHeader.NAME)).getAddress().getURI()).getUser();
|
||||
SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(platformGbId, channelId);
|
||||
SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(platformGbId, channelId, null, callIdHeader.getCallId());
|
||||
String is_Udp = sendRtpItem.isTcp() ? "0" : "1";
|
||||
String deviceId = sendRtpItem.getDeviceId();
|
||||
StreamInfo streamInfo = null;
|
||||
@@ -83,15 +91,12 @@ public class AckRequestProcessor extends SIPRequestProcessorParent implements In
|
||||
}else {
|
||||
streamInfo = redisCatchStorage.queryPlaybackByDevice(deviceId, channelId);
|
||||
}
|
||||
System.out.println(JSON.toJSON(streamInfo));
|
||||
if (streamInfo == null) {
|
||||
streamInfo = new StreamInfo();
|
||||
streamInfo.setApp(sendRtpItem.getApp());
|
||||
streamInfo.setStream(sendRtpItem.getStreamId());
|
||||
}
|
||||
redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
||||
logger.info(platformGbId);
|
||||
logger.info(channelId);
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("vhost","__defaultVhost__");
|
||||
param.put("app",streamInfo.getApp());
|
||||
@@ -100,42 +105,23 @@ public class AckRequestProcessor extends SIPRequestProcessorParent implements In
|
||||
param.put("dst_url",sendRtpItem.getIp());
|
||||
param.put("dst_port", sendRtpItem.getPort());
|
||||
param.put("is_udp", is_Udp);
|
||||
// 设备推流查询,成功后才能转推
|
||||
MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
|
||||
zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
|
||||
// if (zlmrtpServerFactory.isStreamReady(mediaInfo, streamInfo.getApp(), streamInfo.getStreamId())) {
|
||||
// logger.info("已获取设备推流[{}/{}],开始向上级推流[{}:{}]",
|
||||
// streamInfo.getApp() ,streamInfo.getStreamId(), sendRtpItem.getIp(), sendRtpItem.getPort());
|
||||
// zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
|
||||
// } else {
|
||||
// // 对hook进行订阅
|
||||
// logger.info("等待设备推流[{}/{}].......",
|
||||
// streamInfo.getApp(), streamInfo.getStreamId());
|
||||
// Timer timer = new Timer();
|
||||
// timer.schedule(new TimerTask() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// logger.info("设备推流[{}/{}]超时,终止向上级推流",
|
||||
// finalStreamInfo.getApp() , finalStreamInfo.getStreamId());
|
||||
//
|
||||
// }
|
||||
// }, 30*1000L);
|
||||
// // 添加订阅
|
||||
// JSONObject subscribeKey = new JSONObject();
|
||||
// subscribeKey.put("app", "rtp");
|
||||
// subscribeKey.put("stream", streamInfo.getStreamId());
|
||||
// subscribeKey.put("mediaServerId", streamInfo.getMediaServerId());
|
||||
// subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, subscribeKey,
|
||||
// (MediaServerItem mediaServerItemInUse, JSONObject json) -> {
|
||||
// logger.info("已获取设备推流[{}/{}],开始向上级推流[{}:{}]",
|
||||
// finalStreamInfo.getApp(), finalStreamInfo.getStreamId(), sendRtpItem.getIp(), sendRtpItem.getPort());
|
||||
// timer.cancel();
|
||||
// zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
|
||||
// subscribe.removeSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey);
|
||||
// });
|
||||
// }
|
||||
|
||||
|
||||
JSONObject jsonObject = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
|
||||
if (jsonObject.getInteger("code") != 0) {
|
||||
logger.info("监听流以等待流上线{}/{}", streamInfo.getApp(), streamInfo.getStream());
|
||||
// 监听流上线
|
||||
// 添加订阅
|
||||
JSONObject subscribeKey = new JSONObject();
|
||||
subscribeKey.put("app", "rtp");
|
||||
subscribeKey.put("stream", streamInfo.getStream());
|
||||
subscribeKey.put("regist", true);
|
||||
subscribeKey.put("schema", "rtmp");
|
||||
subscribeKey.put("mediaServerId", sendRtpItem.getMediaServerId());
|
||||
subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey,
|
||||
(MediaServerItem mediaServerItemInUse, JSONObject json)->{
|
||||
zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
|
||||
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.cmd.ISIPCommander;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor;
|
||||
@@ -13,6 +15,8 @@ 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.IVideoManagerStorager;
|
||||
import com.genersoft.iot.vmp.utils.SerializeUtils;
|
||||
import gov.nist.javax.sip.stack.SIPDialog;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -21,6 +25,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sip.*;
|
||||
import javax.sip.address.SipURI;
|
||||
import javax.sip.header.CallIdHeader;
|
||||
import javax.sip.header.FromHeader;
|
||||
import javax.sip.header.HeaderAddress;
|
||||
import javax.sip.header.ToHeader;
|
||||
@@ -56,6 +61,9 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In
|
||||
@Autowired
|
||||
private SIPProcessorObserver sipProcessorObserver;
|
||||
|
||||
@Autowired
|
||||
private VideoStreamSessionManager streamSession;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
// 添加消息处理的订阅
|
||||
@@ -71,11 +79,12 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In
|
||||
try {
|
||||
responseAck(evt, Response.OK);
|
||||
Dialog dialog = evt.getDialog();
|
||||
CallIdHeader callIdHeader = (CallIdHeader)evt.getRequest().getHeader(CallIdHeader.NAME);
|
||||
if (dialog == null) return;
|
||||
if (dialog.getState().equals(DialogState.TERMINATED)) {
|
||||
String platformGbId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(FromHeader.NAME)).getAddress().getURI()).getUser();
|
||||
String channelId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(ToHeader.NAME)).getAddress().getURI()).getUser();
|
||||
SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(platformGbId, channelId);
|
||||
SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(platformGbId, channelId, null, callIdHeader.getCallId());
|
||||
logger.info("收到bye, [{}/{}]", platformGbId, channelId);
|
||||
if (sendRtpItem != null){
|
||||
String streamId = sendRtpItem.getStreamId();
|
||||
@@ -87,35 +96,44 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In
|
||||
logger.info("停止向上级推流:" + streamId);
|
||||
MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
|
||||
zlmrtpServerFactory.stopSendRtpStream(mediaInfo, param);
|
||||
redisCatchStorage.deleteSendRTPServer(platformGbId, channelId);
|
||||
redisCatchStorage.deleteSendRTPServer(platformGbId, channelId, callIdHeader.getCallId(), null);
|
||||
int totalReaderCount = zlmrtpServerFactory.totalReaderCount(mediaInfo, sendRtpItem.getApp(), streamId);
|
||||
if (totalReaderCount == 0) {
|
||||
if (totalReaderCount <= 0) {
|
||||
logger.info(streamId + "无其它观看者,通知设备停止推流");
|
||||
cmder.streamByeCmd(sendRtpItem.getDeviceId(), channelId, streamId);
|
||||
}else if (totalReaderCount == -1){
|
||||
logger.warn(streamId + " 查找其它观看者失败");
|
||||
}
|
||||
}
|
||||
// 可能是设备主动停止
|
||||
Device device = storager.queryVideoDeviceByChannelId(platformGbId);
|
||||
if (device != null) {
|
||||
storager.stopPlay(device.getDeviceId(), channelId);
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(device.getDeviceId(), channelId);
|
||||
if (sendRtpItem != null) {
|
||||
if (sendRtpItem.isPlay()) {
|
||||
if (streamInfo != null) {
|
||||
redisCatchStorage.stopPlay(streamInfo);
|
||||
}
|
||||
}else {
|
||||
if (streamInfo != null) {
|
||||
redisCatchStorage.stopPlayback(streamInfo);
|
||||
}
|
||||
}
|
||||
|
||||
storager.stopPlay(device.getDeviceId(), channelId);
|
||||
if (streamInfo != null) {
|
||||
redisCatchStorage.stopPlay(streamInfo);
|
||||
mediaServerService.closeRTPServer(device.getDeviceId(), channelId, streamInfo.getStream());
|
||||
}
|
||||
SsrcTransaction ssrcTransactionForPlay = streamSession.getSsrcTransaction(device.getDeviceId(), channelId, "play", null);
|
||||
if (ssrcTransactionForPlay != null){
|
||||
SIPDialog dialogForPlay = (SIPDialog) SerializeUtils.deSerialize(ssrcTransactionForPlay.getDialog());
|
||||
if (dialogForPlay.getCallId().equals(callIdHeader.getCallId())){
|
||||
// 释放ssrc
|
||||
MediaServerItem mediaServerItem = mediaServerService.getOne(ssrcTransactionForPlay.getMediaServerId());
|
||||
if (mediaServerItem != null) {
|
||||
mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcTransactionForPlay.getSsrc());
|
||||
}
|
||||
streamSession.remove(device.getDeviceId(), channelId, ssrcTransactionForPlay.getStream());
|
||||
}
|
||||
}
|
||||
SsrcTransaction ssrcTransactionForPlayBack = streamSession.getSsrcTransaction(device.getDeviceId(), channelId, callIdHeader.getCallId(), null);
|
||||
if (ssrcTransactionForPlayBack != null) {
|
||||
// 释放ssrc
|
||||
MediaServerItem mediaServerItem = mediaServerService.getOne(ssrcTransactionForPlayBack.getMediaServerId());
|
||||
if (mediaServerItem != null) {
|
||||
mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcTransactionForPlayBack.getSsrc());
|
||||
}
|
||||
streamSession.remove(device.getDeviceId(), channelId, ssrcTransactionForPlayBack.getStream());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver;
|
||||
@@ -21,6 +22,7 @@ import com.genersoft.iot.vmp.service.IPlayService;
|
||||
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
import com.genersoft.iot.vmp.utils.SerializeUtils;
|
||||
import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.PlayResult;
|
||||
import gov.nist.javax.sdp.TimeDescriptionImpl;
|
||||
import gov.nist.javax.sdp.fields.TimeField;
|
||||
@@ -70,6 +72,9 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private DynamicTask dynamicTask;
|
||||
|
||||
@Autowired
|
||||
private SIPCommander cmder;
|
||||
|
||||
@@ -261,11 +266,13 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
}
|
||||
sendRtpItem.setCallId(callIdHeader.getCallId());
|
||||
sendRtpItem.setPlay("Play".equals(sessionName));
|
||||
byte[] dialogByteArray = SerializeUtils.serialize(evt.getDialog());
|
||||
sendRtpItem.setDialog(dialogByteArray);
|
||||
byte[] transactionByteArray = SerializeUtils.serialize(evt.getServerTransaction());
|
||||
sendRtpItem.setTransaction(transactionByteArray);
|
||||
// 写入redis, 超时时回复
|
||||
redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
||||
|
||||
Device finalDevice = device;
|
||||
MediaServerItem finalMediaServerItem = mediaServerItem;
|
||||
Long finalStartTime = startTime;
|
||||
Long finalStopTime = stopTime;
|
||||
ZLMHttpHookSubscribe.Event hookEvent = (mediaServerItemInUSe, responseJSON)->{
|
||||
@@ -293,7 +300,15 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
content.append("f=\r\n");
|
||||
|
||||
try {
|
||||
// 超时未收到Ack应该回复bye,当前等待时间为10秒
|
||||
dynamicTask.startDelay(callIdHeader.getCallId(), ()->{
|
||||
logger.info("Ack 等待超时");
|
||||
mediaServerService.releaseSsrc(mediaServerItemInUSe.getId(), ssrc);
|
||||
// 回复bye
|
||||
cmderFroPlatform.streamByeCmd(platform, callIdHeader.getCallId());
|
||||
}, 60);
|
||||
responseSdpAck(evt, content.toString(), platform);
|
||||
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
@@ -324,6 +339,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
if (result.getEvent() != null) {
|
||||
errorEvent.response(result.getEvent());
|
||||
}
|
||||
redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null);
|
||||
try {
|
||||
responseAck(evt, Response.REQUEST_TIMEOUT);
|
||||
} catch (SipException e) {
|
||||
@@ -347,7 +363,9 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
sendRtpItem.setStreamId(String.format("%s_%s", device.getDeviceId(), channelId));
|
||||
}
|
||||
sendRtpItem.setPlay(false);
|
||||
playService.play(mediaServerItem,device.getDeviceId(), channelId, hookEvent,errorEvent);
|
||||
playService.play(mediaServerItem,device.getDeviceId(), channelId, hookEvent, errorEvent, ()->{
|
||||
redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null);
|
||||
});
|
||||
}else {
|
||||
sendRtpItem.setStreamId(streamInfo.getStream());
|
||||
hookEvent.response(mediaServerItem, null);
|
||||
@@ -369,6 +387,11 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
|
||||
// 写入redis, 超时时回复
|
||||
sendRtpItem.setStatus(1);
|
||||
sendRtpItem.setCallId(callIdHeader.getCallId());
|
||||
byte[] dialogByteArray = SerializeUtils.serialize(evt.getDialog());
|
||||
sendRtpItem.setDialog(dialogByteArray);
|
||||
byte[] transactionByteArray = SerializeUtils.serialize(evt.getServerTransaction());
|
||||
sendRtpItem.setTransaction(transactionByteArray);
|
||||
redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
||||
StringBuffer content = new StringBuffer(200);
|
||||
content.append("v=0\r\n");
|
||||
|
||||
@@ -158,6 +158,10 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
|
||||
device.setCharset("gb2312");
|
||||
device.setDeviceId(deviceId);
|
||||
device.setFirsRegister(true);
|
||||
}else {
|
||||
if (device.getOnline() == 0) {
|
||||
device.setFirsRegister(true);
|
||||
}
|
||||
}
|
||||
device.setIp(received);
|
||||
device.setPort(rPort);
|
||||
@@ -187,7 +191,6 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
|
||||
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
|
||||
// 注册成功
|
||||
// 保存到redis
|
||||
// 下发catelog查询目录
|
||||
if (registerFlag == 1 ) {
|
||||
logger.info("[{}] 注册成功! deviceId:" + device.getDeviceId(), requestAddress);
|
||||
publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_REGISTER);
|
||||
|
||||
@@ -27,9 +27,7 @@ import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.RequestEvent;
|
||||
import javax.sip.ServerTransaction;
|
||||
import javax.sip.SipException;
|
||||
import javax.sip.header.CallIdHeader;
|
||||
import javax.sip.header.ExpiresHeader;
|
||||
import javax.sip.header.Header;
|
||||
import javax.sip.header.ToHeader;
|
||||
import javax.sip.message.Request;
|
||||
import javax.sip.message.Response;
|
||||
@@ -139,19 +137,17 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
|
||||
|
||||
if (subscribeInfo.getExpires() > 0) {
|
||||
if (redisCatchStorage.getSubscribe(key) != null) {
|
||||
dynamicTask.stopCron(key);
|
||||
dynamicTask.stop(key);
|
||||
}
|
||||
String interval = XmlUtil.getText(rootElement, "Interval"); // GPS上报时间间隔
|
||||
dynamicTask.startCron(key, new GPSSubscribeTask(redisCatchStorage, sipCommanderForPlatform, storager, platformId, sn, key), Integer.parseInt(interval));
|
||||
|
||||
redisCatchStorage.updateSubscribe(key, subscribeInfo);
|
||||
}else if (subscribeInfo.getExpires() == 0) {
|
||||
dynamicTask.stopCron(key);
|
||||
dynamicTask.stop(key);
|
||||
redisCatchStorage.delSubscribe(key);
|
||||
}
|
||||
|
||||
|
||||
|
||||
try {
|
||||
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId);
|
||||
Response response = responseXmlAck(evt, resultXml.toString(), parentPlatform);
|
||||
|
||||
@@ -85,19 +85,18 @@ public class RegisterResponseProcessor extends SIPResponseProcessorAbstract {
|
||||
redisCatchStorage.delPlatformRegisterInfo(callId);
|
||||
parentPlatform.setStatus("注册".equals(action));
|
||||
// 取回Expires设置,避免注销过程中被置为0
|
||||
ParentPlatform parentPlatformTmp = storager.queryParentPlatByServerGBId(platformGBId);
|
||||
String expires = parentPlatformTmp.getExpires();
|
||||
parentPlatform.setExpires(expires);
|
||||
parentPlatform.setId(parentPlatformTmp.getId());
|
||||
if (!parentPlatformCatch.getParentPlatform().getExpires().equals("0")) {
|
||||
ParentPlatform parentPlatformTmp = storager.queryParentPlatByServerGBId(platformGBId);
|
||||
String expires = parentPlatformTmp.getExpires();
|
||||
parentPlatform.setExpires(expires);
|
||||
parentPlatform.setId(parentPlatformTmp.getId());
|
||||
redisCatchStorage.updatePlatformRegister(parentPlatform);
|
||||
redisCatchStorage.updatePlatformKeepalive(parentPlatform);
|
||||
parentPlatformCatch.setParentPlatform(parentPlatform);
|
||||
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
|
||||
}
|
||||
storager.updateParentPlatformStatus(platformGBId, "注册".equals(action));
|
||||
|
||||
redisCatchStorage.updatePlatformRegister(parentPlatform);
|
||||
|
||||
redisCatchStorage.updatePlatformKeepalive(parentPlatform);
|
||||
|
||||
parentPlatformCatch.setParentPlatform(parentPlatform);
|
||||
|
||||
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user