Merge remote-tracking branch 'origin/wvp-28181-2.0' into map
This commit is contained in:
@@ -76,7 +76,6 @@ public class DynamicTask {
|
||||
*/
|
||||
public void startDelay(String key, Runnable task, int delay) {
|
||||
stop(key);
|
||||
System.out.println("定时任务开始了");
|
||||
Date starTime = new Date(System.currentTimeMillis() + delay);
|
||||
|
||||
ScheduledFuture future = futureMap.get(key);
|
||||
@@ -100,7 +99,6 @@ public class DynamicTask {
|
||||
}
|
||||
|
||||
public void stop(String key) {
|
||||
System.out.println("定时任务结束了");
|
||||
if (futureMap.get(key) != null && !futureMap.get(key).isCancelled()) {
|
||||
futureMap.get(key).cancel(true);
|
||||
Runnable runnable = runnableMap.get(key);
|
||||
|
||||
@@ -48,6 +48,7 @@ public class SipLayer{
|
||||
properties.setProperty("javax.sip.STACK_NAME", "GB28181_SIP");
|
||||
properties.setProperty("javax.sip.IP_ADDRESS", sipConfig.getMonitorIp());
|
||||
properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "true");
|
||||
properties.setProperty("gov.nist.javax.sip.DELIVER_UNSOLICITED_NOTIFY", "true"); // 接收所有notify请求,即使没有订阅
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class CatalogData {
|
||||
private int sn; // 命令序列号
|
||||
private int total;
|
||||
private List<DeviceChannel> channelList;
|
||||
private Date lastTime;
|
||||
@@ -15,6 +16,15 @@ public class CatalogData {
|
||||
}
|
||||
private CatalogDataStatus status;
|
||||
|
||||
|
||||
public int getSn() {
|
||||
return sn;
|
||||
}
|
||||
|
||||
public void setSn(int sn) {
|
||||
this.sn = sn;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
@@ -129,6 +129,11 @@ public class Device {
|
||||
*/
|
||||
private int subscribeCycleForAlarm;
|
||||
|
||||
/**
|
||||
* 是否开启ssrc校验,默认关闭,开启可以防止串流
|
||||
*/
|
||||
private boolean ssrcCheck;
|
||||
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
@@ -321,4 +326,12 @@ public class Device {
|
||||
public void setSubscribeCycleForAlarm(int subscribeCycleForAlarm) {
|
||||
this.subscribeCycleForAlarm = subscribeCycleForAlarm;
|
||||
}
|
||||
|
||||
public boolean isSsrcCheck() {
|
||||
return ssrcCheck;
|
||||
}
|
||||
|
||||
public void setSsrcCheck(boolean ssrcCheck) {
|
||||
this.ssrcCheck = ssrcCheck;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,6 +169,11 @@ public class DeviceChannel {
|
||||
*/
|
||||
private boolean hasAudio;
|
||||
|
||||
/**
|
||||
* 标记通道的类型,0->国标通道 1->直播流通道 2->业务分组/虚拟组织/行政区划
|
||||
*/
|
||||
private int channelType;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -441,4 +446,12 @@ public class DeviceChannel {
|
||||
public void setUpdateTime(String updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public int getChannelType() {
|
||||
return channelType;
|
||||
}
|
||||
|
||||
public void setChannelType(int channelType) {
|
||||
this.channelType = channelType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,6 +129,21 @@ public class ParentPlatform {
|
||||
*/
|
||||
private boolean mobilePositionSubscribe;
|
||||
|
||||
/**
|
||||
* 点播未推流的设备时是否使用redis通知拉起
|
||||
*/
|
||||
private boolean startOfflinePush;
|
||||
|
||||
/**
|
||||
* 目录分组-每次向上级发送通道信息时单个包携带的通道数量,取值1,2,4,8
|
||||
*/
|
||||
private int catalogGroup;
|
||||
|
||||
/**
|
||||
* 行政区划
|
||||
*/
|
||||
private String administrativeDivision;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -329,4 +344,28 @@ public class ParentPlatform {
|
||||
public void setMobilePositionSubscribe(boolean mobilePositionSubscribe) {
|
||||
this.mobilePositionSubscribe = mobilePositionSubscribe;
|
||||
}
|
||||
|
||||
public boolean isStartOfflinePush() {
|
||||
return startOfflinePush;
|
||||
}
|
||||
|
||||
public void setStartOfflinePush(boolean startOfflinePush) {
|
||||
this.startOfflinePush = startOfflinePush;
|
||||
}
|
||||
|
||||
public int getCatalogGroup() {
|
||||
return catalogGroup;
|
||||
}
|
||||
|
||||
public void setCatalogGroup(int catalogGroup) {
|
||||
this.catalogGroup = catalogGroup;
|
||||
}
|
||||
|
||||
public String getAdministrativeDivision() {
|
||||
return administrativeDivision;
|
||||
}
|
||||
|
||||
public void setAdministrativeDivision(String administrativeDivision) {
|
||||
this.administrativeDivision = administrativeDivision;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ public class OnlineEventListener implements ApplicationListener<OnlineEvent> {
|
||||
@Autowired
|
||||
private SIPCommander cmder;
|
||||
|
||||
|
||||
private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Override
|
||||
@@ -74,7 +75,7 @@ public class OnlineEventListener implements ApplicationListener<OnlineEvent> {
|
||||
if (deviceInStore == null) { //第一次上线
|
||||
logger.info("[{}] 首次注册,查询设备信息以及通道信息", device.getDeviceId());
|
||||
cmder.deviceInfoQuery(device);
|
||||
cmder.catalogQuery(device, null);
|
||||
deviceService.sync(device);
|
||||
}
|
||||
break;
|
||||
// 设备主动发送心跳触发的在线事件
|
||||
|
||||
@@ -26,28 +26,35 @@ public class CatalogDataCatch {
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
|
||||
public void addReady(String key) {
|
||||
CatalogData catalogData = data.get(key);
|
||||
public void addReady(Device device, int sn ) {
|
||||
CatalogData catalogData = data.get(device.getDeviceId());
|
||||
if (catalogData == null || catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end)) {
|
||||
catalogData = new CatalogData();
|
||||
catalogData.setChannelList(new ArrayList<>());
|
||||
catalogData.setDevice(device);
|
||||
catalogData.setSn(sn);
|
||||
catalogData.setStatus(CatalogData.CatalogDataStatus.ready);
|
||||
catalogData.setLastTime(new Date(System.currentTimeMillis()));
|
||||
data.put(key, catalogData);
|
||||
data.put(device.getDeviceId(), catalogData);
|
||||
}
|
||||
}
|
||||
|
||||
public void put(String key, int total, Device device, List<DeviceChannel> deviceChannelList) {
|
||||
CatalogData catalogData = data.get(key);
|
||||
public void put(String deviceId, int sn, int total, Device device, List<DeviceChannel> deviceChannelList) {
|
||||
CatalogData catalogData = data.get(deviceId);
|
||||
if (catalogData == null) {
|
||||
catalogData = new CatalogData();
|
||||
catalogData.setSn(sn);
|
||||
catalogData.setTotal(total);
|
||||
catalogData.setDevice(device);
|
||||
catalogData.setChannelList(new ArrayList<>());
|
||||
catalogData.setStatus(CatalogData.CatalogDataStatus.runIng);
|
||||
catalogData.setLastTime(new Date(System.currentTimeMillis()));
|
||||
data.put(key, catalogData);
|
||||
data.put(deviceId, catalogData);
|
||||
}else {
|
||||
// 同一个设备的通道同步请求只考虑一个,其他的直接忽略
|
||||
if (catalogData.getSn() != sn) {
|
||||
return;
|
||||
}
|
||||
catalogData.setTotal(total);
|
||||
catalogData.setDevice(device);
|
||||
catalogData.setStatus(CatalogData.CatalogDataStatus.runIng);
|
||||
@@ -56,20 +63,20 @@ public class CatalogDataCatch {
|
||||
}
|
||||
}
|
||||
|
||||
public List<DeviceChannel> get(String key) {
|
||||
CatalogData catalogData = data.get(key);
|
||||
public List<DeviceChannel> get(String deviceId) {
|
||||
CatalogData catalogData = data.get(deviceId);
|
||||
if (catalogData == null) return null;
|
||||
return catalogData.getChannelList();
|
||||
}
|
||||
|
||||
public int getTotal(String key) {
|
||||
CatalogData catalogData = data.get(key);
|
||||
public int getTotal(String deviceId) {
|
||||
CatalogData catalogData = data.get(deviceId);
|
||||
if (catalogData == null) return 0;
|
||||
return catalogData.getTotal();
|
||||
}
|
||||
|
||||
public SyncStatus getSyncStatus(String key) {
|
||||
CatalogData catalogData = data.get(key);
|
||||
public SyncStatus getSyncStatus(String deviceId) {
|
||||
CatalogData catalogData = data.get(deviceId);
|
||||
if (catalogData == null) return null;
|
||||
SyncStatus syncStatus = new SyncStatus();
|
||||
syncStatus.setCurrent(catalogData.getChannelList().size());
|
||||
@@ -78,8 +85,10 @@ public class CatalogDataCatch {
|
||||
return syncStatus;
|
||||
}
|
||||
|
||||
public void del(String key) {
|
||||
data.remove(key);
|
||||
public boolean isSyncRunning(String deviceId) {
|
||||
CatalogData catalogData = data.get(deviceId);
|
||||
if (catalogData == null) return false;
|
||||
return !catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end);
|
||||
}
|
||||
|
||||
@Scheduled(fixedRate = 5 * 1000) //每5秒执行一次, 发现数据5秒未更新则移除数据并认为数据接收超时
|
||||
@@ -92,23 +101,30 @@ public class CatalogDataCatch {
|
||||
Calendar calendarBefore30S = Calendar.getInstance();
|
||||
calendarBefore30S.setTime(new Date());
|
||||
calendarBefore30S.set(Calendar.SECOND, calendarBefore30S.get(Calendar.SECOND) - 30);
|
||||
for (String key : keys) {
|
||||
CatalogData catalogData = data.get(key);
|
||||
if (catalogData.getLastTime().before(calendarBefore5S.getTime())) { // 超过五秒收不到消息任务超时, 只更新这一部分数据
|
||||
storager.resetChannels(catalogData.getDevice().getDeviceId(), catalogData.getChannelList());
|
||||
String errorMsg = "更新成功,共" + catalogData.getTotal() + "条,已更新" + catalogData.getChannelList().size() + "条";
|
||||
for (String deviceId : keys) {
|
||||
CatalogData catalogData = data.get(deviceId);
|
||||
if ( catalogData.getLastTime().before(calendarBefore5S.getTime())) { // 超过五秒收不到消息任务超时, 只更新这一部分数据
|
||||
if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.runIng)) {
|
||||
storager.resetChannels(catalogData.getDevice().getDeviceId(), catalogData.getChannelList());
|
||||
if (catalogData.getTotal() != catalogData.getChannelList().size()) {
|
||||
String errorMsg = "更新成功,共" + catalogData.getTotal() + "条,已更新" + catalogData.getChannelList().size() + "条";
|
||||
catalogData.setErrorMsg(errorMsg);
|
||||
}
|
||||
}else if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.ready)) {
|
||||
String errorMsg = "同步失败,等待回复超时";
|
||||
catalogData.setErrorMsg(errorMsg);
|
||||
}
|
||||
catalogData.setStatus(CatalogData.CatalogDataStatus.end);
|
||||
catalogData.setErrorMsg(errorMsg);
|
||||
}
|
||||
if (catalogData.getLastTime().before(calendarBefore30S.getTime())) { // 超过三十秒,如果标记为end则删除
|
||||
data.remove(key);
|
||||
if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end) && catalogData.getLastTime().before(calendarBefore30S.getTime())) { // 超过三十秒,如果标记为end则删除
|
||||
data.remove(deviceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setChannelSyncEnd(String key, String errorMsg) {
|
||||
CatalogData catalogData = data.get(key);
|
||||
public void setChannelSyncEnd(String deviceId, String errorMsg) {
|
||||
CatalogData catalogData = data.get(deviceId);
|
||||
if (catalogData == null)return;
|
||||
catalogData.setStatus(CatalogData.CatalogDataStatus.end);
|
||||
catalogData.setErrorMsg(errorMsg);
|
||||
|
||||
@@ -10,6 +10,8 @@ import org.springframework.scheduling.annotation.Async;
|
||||
import javax.sip.Dialog;
|
||||
import javax.sip.DialogState;
|
||||
import javax.sip.ResponseEvent;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* 目录订阅任务
|
||||
@@ -20,6 +22,8 @@ public class CatalogSubscribeTask implements ISubscribeTask {
|
||||
private final ISIPCommander sipCommander;
|
||||
private Dialog dialog;
|
||||
|
||||
private Timer timer ;
|
||||
|
||||
public CatalogSubscribeTask(Device device, ISIPCommander sipCommander) {
|
||||
this.device = device;
|
||||
this.sipCommander = sipCommander;
|
||||
@@ -27,6 +31,10 @@ public class CatalogSubscribeTask implements ISubscribeTask {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (timer != null ) {
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
}
|
||||
sipCommander.catalogSubscribe(device, dialog, eventResult -> {
|
||||
if (eventResult.dialog != null || eventResult.dialog.getState().equals(DialogState.CONFIRMED)) {
|
||||
dialog = eventResult.dialog;
|
||||
@@ -43,6 +51,13 @@ public class CatalogSubscribeTask implements ISubscribeTask {
|
||||
dialog = null;
|
||||
// 失败
|
||||
logger.warn("[目录订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg);
|
||||
timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
CatalogSubscribeTask.this.run();
|
||||
}
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -56,9 +71,13 @@ public class CatalogSubscribeTask implements ISubscribeTask {
|
||||
* TERMINATED-> Terminated Dialog状态-终止
|
||||
*/
|
||||
logger.info("取消目录订阅时dialog状态为{}", DialogState.CONFIRMED);
|
||||
if (timer != null ) {
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
}
|
||||
if (dialog != null && dialog.getState().equals(DialogState.CONFIRMED)) {
|
||||
device.setSubscribeCycleForCatalog(0);
|
||||
sipCommander.mobilePositionSubscribe(device, dialog, eventResult -> {
|
||||
sipCommander.catalogSubscribe(device, dialog, eventResult -> {
|
||||
ResponseEvent event = (ResponseEvent) eventResult.event;
|
||||
if (event.getResponse().getRawContent() != null) {
|
||||
// 成功
|
||||
|
||||
@@ -29,7 +29,6 @@ public class MobilePositionSubscribeHandlerTask implements ISubscribeTask {
|
||||
private String key;
|
||||
|
||||
public MobilePositionSubscribeHandlerTask(IRedisCatchStorage redisCatchStorage, ISIPCommanderForPlatform sipCommanderForPlatform, IVideoManagerStorage storager, String platformId, String sn, String key, SubscribeHolder subscribeInfo) {
|
||||
System.out.println("MobilePositionSubscribeHandlerTask 初始化");
|
||||
this.redisCatchStorage = redisCatchStorage;
|
||||
this.storager = storager;
|
||||
this.platform = storager.queryParentPlatByServerGBId(platformId);
|
||||
@@ -42,7 +41,6 @@ public class MobilePositionSubscribeHandlerTask implements ISubscribeTask {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
logger.info("执行MobilePositionSubscribeHandlerTask");
|
||||
if (platform == null) return;
|
||||
SubscribeInfo subscribe = subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId());
|
||||
if (subscribe != null) {
|
||||
@@ -71,7 +69,6 @@ public class MobilePositionSubscribeHandlerTask implements ISubscribeTask {
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.info("结束执行MobilePositionSubscribeHandlerTask");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -250,7 +250,7 @@ public interface ISIPCommander {
|
||||
*
|
||||
* @param device 视频设备
|
||||
*/
|
||||
boolean catalogQuery(Device device, SipSubscribe.Event errorEvent);
|
||||
boolean catalogQuery(Device device, int sn, SipSubscribe.Event errorEvent);
|
||||
|
||||
/**
|
||||
* 查询录像信息
|
||||
|
||||
@@ -1208,14 +1208,14 @@ public class SIPCommander implements ISIPCommander {
|
||||
* @param device 视频设备
|
||||
*/
|
||||
@Override
|
||||
public boolean catalogQuery(Device device, SipSubscribe.Event errorEvent) {
|
||||
public boolean catalogQuery(Device device, int sn, SipSubscribe.Event errorEvent) {
|
||||
try {
|
||||
StringBuffer catalogXml = new StringBuffer(200);
|
||||
String charset = device.getCharset();
|
||||
catalogXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
||||
catalogXml.append("<Query>\r\n");
|
||||
catalogXml.append("<CmdType>Catalog</CmdType>\r\n");
|
||||
catalogXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
||||
catalogXml.append("<SN>" + sn + "</SN>\r\n");
|
||||
catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
catalogXml.append("</Query>\r\n");
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ 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;
|
||||
import java.util.UUID;
|
||||
@@ -215,7 +216,11 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
String catalogXml = getCatalogXml(channel, sn, parentPlatform, size);
|
||||
List<DeviceChannel> channels = new ArrayList<>();
|
||||
if (channel != null) {
|
||||
channels.add(channel);
|
||||
}
|
||||
String catalogXml = getCatalogXml(channels, sn, parentPlatform, size);
|
||||
|
||||
// callid
|
||||
CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
||||
@@ -239,7 +244,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
sendCatalogResponse(channels, parentPlatform, sn, fromTag, 0);
|
||||
return true;
|
||||
}
|
||||
private String getCatalogXml(DeviceChannel channel, String sn, ParentPlatform parentPlatform, int size) {
|
||||
private String getCatalogXml(List<DeviceChannel> channels, String sn, ParentPlatform parentPlatform, int size) {
|
||||
String characterSet = parentPlatform.getCharacterSet();
|
||||
StringBuffer catalogXml = new StringBuffer(600);
|
||||
catalogXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet +"\"?>\r\n");
|
||||
@@ -248,34 +253,38 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
catalogXml.append("<SN>" +sn + "</SN>\r\n");
|
||||
catalogXml.append("<DeviceID>" + parentPlatform.getDeviceGBId() + "</DeviceID>\r\n");
|
||||
catalogXml.append("<SumNum>" + size + "</SumNum>\r\n");
|
||||
catalogXml.append("<DeviceList Num=\"1\">\r\n");
|
||||
catalogXml.append("<Item>\r\n");
|
||||
if (channel != null) {
|
||||
catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n");
|
||||
catalogXml.append("<Name>" + channel.getName() + "</Name>\r\n");
|
||||
catalogXml.append("<Manufacturer>" + channel.getManufacture() + "</Manufacturer>\r\n");
|
||||
catalogXml.append("<Model>" + channel.getModel() + "</Model>\r\n");
|
||||
catalogXml.append("<Owner>" + channel.getOwner() + "</Owner>\r\n");
|
||||
catalogXml.append("<CivilCode>" + channel.getCivilCode() + "</CivilCode>\r\n");
|
||||
catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n");
|
||||
catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n");
|
||||
if (channel.getParentId() != null) {
|
||||
catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n");
|
||||
catalogXml.append("<DeviceList Num=\"" + channels.size() +"\">\r\n");
|
||||
if (channels.size() > 0) {
|
||||
for (DeviceChannel channel : channels) {
|
||||
catalogXml.append("<Item>\r\n");
|
||||
catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n");
|
||||
catalogXml.append("<Name>" + channel.getName() + "</Name>\r\n");
|
||||
catalogXml.append("<Manufacturer>" + channel.getManufacture() + "</Manufacturer>\r\n");
|
||||
catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n");
|
||||
if (channel.getParentId() != null) {
|
||||
catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n");
|
||||
}
|
||||
catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n");
|
||||
catalogXml.append("<Status>" + (channel.getStatus() == 0?"OFF":"ON") + "</Status>\r\n");
|
||||
catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n");
|
||||
if (channel.getChannelType() != 2) { // 业务分组/虚拟组织/行政区划 不设置以下字段
|
||||
catalogXml.append("<Model>" + channel.getModel() + "</Model>\r\n");
|
||||
catalogXml.append("<Owner>" + channel.getOwner() + "</Owner>\r\n");
|
||||
catalogXml.append("<CivilCode>" + channel.getCivilCode() + "</CivilCode>\r\n");
|
||||
catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n");
|
||||
catalogXml.append("<Longitude>" + channel.getLongitude() + "</Longitude>\r\n");
|
||||
catalogXml.append("<Latitude>" + channel.getLatitude() + "</Latitude>\r\n");
|
||||
catalogXml.append("<IPAddress>" + channel.getIpAddress() + "</IPAddress>\r\n");
|
||||
catalogXml.append("<Port>" + channel.getPort() + "</Port>\r\n");
|
||||
catalogXml.append("<Info>\r\n");
|
||||
catalogXml.append("<PTZType>" + channel.getPTZType() + "</PTZType>\r\n");
|
||||
catalogXml.append("</Info>\r\n");
|
||||
}
|
||||
|
||||
catalogXml.append("</Item>\r\n");
|
||||
}
|
||||
catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n");
|
||||
catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n");
|
||||
catalogXml.append("<Status>" + (channel.getStatus() == 0?"OFF":"ON") + "</Status>\r\n");
|
||||
catalogXml.append("<Longitude>" + channel.getLongitude() + "</Longitude>\r\n");
|
||||
catalogXml.append("<Latitude>" + channel.getLatitude() + "</Latitude>\r\n");
|
||||
catalogXml.append("<IPAddress>" + channel.getIpAddress() + "</IPAddress>\r\n");
|
||||
catalogXml.append("<Port>" + channel.getPort() + "</Port>\r\n");
|
||||
catalogXml.append("<Info>\r\n");
|
||||
catalogXml.append("<PTZType>" + channel.getPTZType() + "</PTZType>\r\n");
|
||||
catalogXml.append("</Info>\r\n");
|
||||
}
|
||||
|
||||
|
||||
catalogXml.append("</Item>\r\n");
|
||||
catalogXml.append("</DeviceList>\r\n");
|
||||
catalogXml.append("</Response>\r\n");
|
||||
return catalogXml.toString();
|
||||
@@ -286,15 +295,20 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
DeviceChannel deviceChannel = channels.get(index);
|
||||
String catalogXml = getCatalogXml(deviceChannel, sn, parentPlatform, channels.size());
|
||||
List<DeviceChannel> deviceChannels;
|
||||
if (index + parentPlatform.getCatalogGroup() < channels.size()) {
|
||||
deviceChannels = channels.subList(index, index + parentPlatform.getCatalogGroup());
|
||||
}else {
|
||||
deviceChannels = channels.subList(index, channels.size());
|
||||
}
|
||||
String catalogXml = getCatalogXml(deviceChannels, sn, parentPlatform, channels.size());
|
||||
// callid
|
||||
CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
||||
: udpSipProvider.getNewCallId();
|
||||
|
||||
Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, catalogXml, fromTag, callIdHeader);
|
||||
transmitRequest(parentPlatform, request, null, eventResult -> {
|
||||
int indexNext = index + 1;
|
||||
int indexNext = index + parentPlatform.getCatalogGroup();
|
||||
sendCatalogResponse(channels, parentPlatform, sn, fromTag, indexNext);
|
||||
});
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
@@ -432,13 +446,21 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
if (index >= deviceChannels.size()) {
|
||||
return true;
|
||||
}
|
||||
List<DeviceChannel> channels;
|
||||
if (index + parentPlatform.getCatalogGroup() < deviceChannels.size()) {
|
||||
channels = deviceChannels.subList(index, index + parentPlatform.getCatalogGroup());
|
||||
}else {
|
||||
channels = deviceChannels.subList(index, deviceChannels.size());
|
||||
}
|
||||
try {
|
||||
Integer finalIndex = index;
|
||||
String catalogXmlContent = getCatalogXmlContentForCatalogAddOrUpdate(parentPlatform, deviceChannels.get(index ), deviceChannels.size(), type, subscribeInfo);
|
||||
String catalogXmlContent = getCatalogXmlContentForCatalogAddOrUpdate(parentPlatform, channels,
|
||||
deviceChannels.size(), type, subscribeInfo);
|
||||
sendNotify(parentPlatform, catalogXmlContent, subscribeInfo, eventResult -> {
|
||||
logger.error("发送NOTIFY通知消息失败。错误:{} {}", eventResult.statusCode, eventResult.msg);
|
||||
}, (eventResult -> {
|
||||
sendNotifyForCatalogAddOrUpdate(type, parentPlatform, deviceChannels, subscribeInfo, finalIndex + 1);
|
||||
sendNotifyForCatalogAddOrUpdate(type, parentPlatform, deviceChannels, subscribeInfo,
|
||||
finalIndex + parentPlatform.getCatalogGroup());
|
||||
}));
|
||||
} catch (SipException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
@@ -500,11 +522,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
|
||||
}
|
||||
|
||||
private String getCatalogXmlContentForCatalogAddOrUpdate(ParentPlatform parentPlatform, DeviceChannel channel, int sumNum, String type, SubscribeInfo subscribeInfo) {
|
||||
private String getCatalogXmlContentForCatalogAddOrUpdate(ParentPlatform parentPlatform, List<DeviceChannel> channels, int sumNum, String type, SubscribeInfo subscribeInfo) {
|
||||
StringBuffer catalogXml = new StringBuffer(600);
|
||||
if (parentPlatform.getServerGBId().equals(channel.getParentId())) {
|
||||
channel.setParentId(parentPlatform.getDeviceGBId());
|
||||
}
|
||||
|
||||
String characterSet = parentPlatform.getCharacterSet();
|
||||
catalogXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n");
|
||||
catalogXml.append("<Notify>\r\n");
|
||||
@@ -512,26 +532,35 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
catalogXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
|
||||
catalogXml.append("<DeviceID>" + parentPlatform.getDeviceGBId() + "</DeviceID>\r\n");
|
||||
catalogXml.append("<SumNum>1</SumNum>\r\n");
|
||||
catalogXml.append("<DeviceList Num=\"1\">\r\n");
|
||||
catalogXml.append("<Item>\r\n");
|
||||
catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n");
|
||||
catalogXml.append("<Name>" + channel.getName() + "</Name>\r\n");
|
||||
catalogXml.append("<Manufacturer>" + channel.getManufacture() + "</Manufacturer>\r\n");
|
||||
catalogXml.append("<Model>" + channel.getModel() + "</Model>\r\n");
|
||||
catalogXml.append("<Owner>0</Owner>\r\n");
|
||||
catalogXml.append("<CivilCode>CivilCode</CivilCode>\r\n");
|
||||
catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n");
|
||||
catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n");
|
||||
if (channel.getParentId() != null) {
|
||||
catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n");
|
||||
catalogXml.append("<DeviceList Num=\"" + channels.size() + "\">\r\n");
|
||||
if (channels.size() > 0) {
|
||||
for (DeviceChannel channel : channels) {
|
||||
if (parentPlatform.getServerGBId().equals(channel.getParentId())) {
|
||||
channel.setParentId(parentPlatform.getDeviceGBId());
|
||||
}
|
||||
catalogXml.append("<Item>\r\n");
|
||||
catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n");
|
||||
catalogXml.append("<Name>" + channel.getName() + "</Name>\r\n");
|
||||
catalogXml.append("<Manufacturer>" + channel.getManufacture() + "</Manufacturer>\r\n");
|
||||
catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n");
|
||||
if (channel.getParentId() != null) {
|
||||
catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n");
|
||||
}
|
||||
catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n");
|
||||
catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n");
|
||||
catalogXml.append("<Status>" + (channel.getStatus() == 0 ? "OFF" : "ON") + "</Status>\r\n");
|
||||
if (channel.getChannelType() == 2) { // 业务分组/虚拟组织/行政区划 不设置以下属性
|
||||
catalogXml.append("<Model>" + channel.getModel() + "</Model>\r\n");
|
||||
catalogXml.append("<Owner>0</Owner>\r\n");
|
||||
catalogXml.append("<CivilCode>CivilCode</CivilCode>\r\n");
|
||||
catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n");
|
||||
}
|
||||
if (!"presence".equals(subscribeInfo.getEventType())) {
|
||||
catalogXml.append("<Event>" + type + "</Event>\r\n");
|
||||
}
|
||||
catalogXml.append("</Item>\r\n");
|
||||
}
|
||||
}
|
||||
catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n");
|
||||
catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n");
|
||||
catalogXml.append("<Status>" + (channel.getStatus() == 0 ? "OFF" : "ON") + "</Status>\r\n");
|
||||
if (!"presence".equals(subscribeInfo.getEventType())) {
|
||||
catalogXml.append("<Event>" + type + "</Event>\r\n");
|
||||
}
|
||||
catalogXml.append("</Item>\r\n");
|
||||
catalogXml.append("</DeviceList>\r\n");
|
||||
catalogXml.append("</Notify>\r\n");
|
||||
return catalogXml.toString();
|
||||
@@ -553,13 +582,20 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
if (index >= deviceChannels.size()) {
|
||||
return true;
|
||||
}
|
||||
List<DeviceChannel> channels;
|
||||
if (index + parentPlatform.getCatalogGroup() < deviceChannels.size()) {
|
||||
channels = deviceChannels.subList(index, index + parentPlatform.getCatalogGroup());
|
||||
}else {
|
||||
channels = deviceChannels.subList(index, deviceChannels.size());
|
||||
}
|
||||
try {
|
||||
Integer finalIndex = index;
|
||||
String catalogXmlContent = getCatalogXmlContentForCatalogOther(parentPlatform, deviceChannels.get(index), type);
|
||||
String catalogXmlContent = getCatalogXmlContentForCatalogOther(parentPlatform, channels, type);
|
||||
sendNotify(parentPlatform, catalogXmlContent, subscribeInfo, eventResult -> {
|
||||
logger.error("发送NOTIFY通知消息失败。错误:{} {}", eventResult.statusCode, eventResult.msg);
|
||||
}, (eventResult -> {
|
||||
sendNotifyForCatalogOther(type, parentPlatform, deviceChannels, subscribeInfo, finalIndex + 1);
|
||||
sendNotifyForCatalogOther(type, parentPlatform, deviceChannels, subscribeInfo,
|
||||
finalIndex + parentPlatform.getCatalogGroup());
|
||||
}));
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
@@ -574,10 +610,8 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
return true;
|
||||
}
|
||||
|
||||
private String getCatalogXmlContentForCatalogOther(ParentPlatform parentPlatform, DeviceChannel channel, String type) {
|
||||
if (parentPlatform.getServerGBId().equals(channel.getParentId())) {
|
||||
channel.setParentId(parentPlatform.getDeviceGBId());
|
||||
}
|
||||
private String getCatalogXmlContentForCatalogOther(ParentPlatform parentPlatform, List<DeviceChannel> channels, String type) {
|
||||
|
||||
String characterSet = parentPlatform.getCharacterSet();
|
||||
StringBuffer catalogXml = new StringBuffer(600);
|
||||
catalogXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n");
|
||||
@@ -586,11 +620,18 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
catalogXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
|
||||
catalogXml.append("<DeviceID>" + parentPlatform.getDeviceGBId() + "</DeviceID>\r\n");
|
||||
catalogXml.append("<SumNum>1</SumNum>\r\n");
|
||||
catalogXml.append("<DeviceList Num=\"1\">\r\n");
|
||||
catalogXml.append("<Item>\r\n");
|
||||
catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n");
|
||||
catalogXml.append("<Event>" + type + "</Event>\r\n");
|
||||
catalogXml.append("</Item>\r\n");
|
||||
catalogXml.append("<DeviceList Num=\" " + channels.size() + " \">\r\n");
|
||||
if (channels.size() > 0) {
|
||||
for (DeviceChannel channel : channels) {
|
||||
if (parentPlatform.getServerGBId().equals(channel.getParentId())) {
|
||||
channel.setParentId(parentPlatform.getDeviceGBId());
|
||||
}
|
||||
catalogXml.append("<Item>\r\n");
|
||||
catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n");
|
||||
catalogXml.append("<Event>" + type + "</Event>\r\n");
|
||||
catalogXml.append("</Item>\r\n");
|
||||
}
|
||||
}
|
||||
catalogXml.append("</DeviceList>\r\n");
|
||||
catalogXml.append("</Notify>\r\n");
|
||||
return catalogXml.toString();
|
||||
|
||||
@@ -397,6 +397,10 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
logger.info("[ app={}, stream={} ]通道离线,启用流后开始推流",gbStream.getApp(), gbStream.getStream());
|
||||
responseAck(evt, Response.BAD_REQUEST, "channel [" + gbStream.getGbId() + "] offline");
|
||||
}else if ("push".equals(gbStream.getStreamType())) {
|
||||
if (!platform.isStartOfflinePush()) {
|
||||
responseAck(evt, Response.TEMPORARILY_UNAVAILABLE, "channel unavailable");
|
||||
return;
|
||||
}
|
||||
// 发送redis消息以使设备上线
|
||||
logger.info("[ app={}, stream={} ]通道离线,发送redis信息控制设备开始推流",gbStream.getApp(), gbStream.getStream());
|
||||
MessageForPushChannel messageForPushChannel = new MessageForPushChannel();
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
|
||||
import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
||||
import com.genersoft.iot.vmp.conf.SipConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.auth.DigestServerAuthenticationHelper;
|
||||
import com.genersoft.iot.vmp.gb28181.auth.RegisterLogicHandler;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.WvpSipDate;
|
||||
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
|
||||
@@ -42,166 +41,157 @@ import java.util.Locale;
|
||||
@Component
|
||||
public class RegisterRequestProcessor extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(RegisterRequestProcessor.class);
|
||||
private final Logger logger = LoggerFactory.getLogger(RegisterRequestProcessor.class);
|
||||
|
||||
public String method = "REGISTER";
|
||||
public String method = "REGISTER";
|
||||
|
||||
@Autowired
|
||||
private SipConfig sipConfig;
|
||||
@Autowired
|
||||
private SipConfig sipConfig;
|
||||
|
||||
@Autowired
|
||||
private RegisterLogicHandler handler;
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
@Autowired
|
||||
private EventPublisher publisher;
|
||||
|
||||
@Autowired
|
||||
private EventPublisher publisher;
|
||||
@Autowired
|
||||
private SIPProcessorObserver sipProcessorObserver;
|
||||
|
||||
@Autowired
|
||||
private SIPProcessorObserver sipProcessorObserver;
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
// 添加消息处理的订阅
|
||||
sipProcessorObserver.addRequestProcessor(method, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
// 添加消息处理的订阅
|
||||
sipProcessorObserver.addRequestProcessor(method, this);
|
||||
}
|
||||
/**
|
||||
* 收到注册请求 处理
|
||||
*
|
||||
* @param evt
|
||||
*/
|
||||
@Override
|
||||
public void process(RequestEvent evt) {
|
||||
try {
|
||||
RequestEventExt evtExt = (RequestEventExt) evt;
|
||||
String requestAddress = evtExt.getRemoteIpAddress() + ":" + evtExt.getRemotePort();
|
||||
logger.info("[{}] 收到注册请求,开始处理", requestAddress);
|
||||
Request request = evt.getRequest();
|
||||
ExpiresHeader expiresHeader = (ExpiresHeader) request.getHeader(Expires.NAME);
|
||||
Response response = null;
|
||||
boolean passwordCorrect = false;
|
||||
// 注册标志 0:未携带授权头或者密码错误 1:注册成功 2:注销成功
|
||||
int registerFlag = 0;
|
||||
FromHeader fromHeader = (FromHeader) request.getHeader(FromHeader.NAME);
|
||||
AddressImpl address = (AddressImpl) fromHeader.getAddress();
|
||||
SipUri uri = (SipUri) address.getURI();
|
||||
String deviceId = uri.getUser();
|
||||
|
||||
/**
|
||||
* 收到注册请求 处理
|
||||
* @param evt
|
||||
*/
|
||||
@Override
|
||||
public void process(RequestEvent evt) {
|
||||
try {
|
||||
RequestEventExt evtExt = (RequestEventExt)evt;
|
||||
String requestAddress = evtExt.getRemoteIpAddress() + ":" + evtExt.getRemotePort();
|
||||
logger.info("[{}] 收到注册请求,开始处理", requestAddress);
|
||||
Request request = evt.getRequest();
|
||||
ExpiresHeader expiresHeader = (ExpiresHeader) request.getHeader(Expires.NAME);
|
||||
Response response = null;
|
||||
boolean passwordCorrect = false;
|
||||
// 注册标志 0:未携带授权头或者密码错误 1:注册成功 2:注销成功
|
||||
int registerFlag = 0;
|
||||
FromHeader fromHeader = (FromHeader) request.getHeader(FromHeader.NAME);
|
||||
AddressImpl address = (AddressImpl) fromHeader.getAddress();
|
||||
SipUri uri = (SipUri) address.getURI();
|
||||
String deviceId = uri.getUser();
|
||||
Device deviceInRedis = redisCatchStorage.getDevice(deviceId);
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
if (deviceInRedis != null && device == null) {
|
||||
// redis 存在脏数据
|
||||
redisCatchStorage.clearCatchByDeviceId(deviceId);
|
||||
}
|
||||
AuthorizationHeader authorhead = (AuthorizationHeader) request.getHeader(AuthorizationHeader.NAME);
|
||||
// 校验密码是否正确
|
||||
if (authorhead != null) {
|
||||
passwordCorrect = new DigestServerAuthenticationHelper().doAuthenticatePlainTextPassword(request,
|
||||
sipConfig.getPassword());
|
||||
}
|
||||
if (StringUtils.isEmpty(sipConfig.getPassword())){
|
||||
passwordCorrect = true;
|
||||
}
|
||||
AuthorizationHeader authHead = (AuthorizationHeader) request.getHeader(AuthorizationHeader.NAME);
|
||||
if (authHead == null) {
|
||||
logger.info("[{}] 未携带授权头 回复401", requestAddress);
|
||||
response = getMessageFactory().createResponse(Response.UNAUTHORIZED, request);
|
||||
new DigestServerAuthenticationHelper().generateChallenge(getHeaderFactory(), response, sipConfig.getDomain());
|
||||
sendResponse(evt, response);
|
||||
return;
|
||||
}
|
||||
|
||||
// 未携带授权头或者密码错误 回复401
|
||||
if (authorhead == null ) {
|
||||
// 校验密码是否正确
|
||||
passwordCorrect = StringUtils.isEmpty(sipConfig.getPassword()) ||
|
||||
new DigestServerAuthenticationHelper().doAuthenticatePlainTextPassword(request, sipConfig.getPassword());
|
||||
// 未携带授权头或者密码错误 回复401
|
||||
|
||||
logger.info("[{}] 未携带授权头 回复401", requestAddress);
|
||||
response = getMessageFactory().createResponse(Response.UNAUTHORIZED, request);
|
||||
new DigestServerAuthenticationHelper().generateChallenge(getHeaderFactory(), response, sipConfig.getDomain());
|
||||
}else {
|
||||
if (!passwordCorrect){
|
||||
// 注册失败
|
||||
response = getMessageFactory().createResponse(Response.FORBIDDEN, request);
|
||||
response.setReasonPhrase("wrong password");
|
||||
logger.info("[{}] 密码/SIP服务器ID错误, 回复403", requestAddress);
|
||||
}else {
|
||||
// 携带授权头并且密码正确
|
||||
response = getMessageFactory().createResponse(Response.OK, request);
|
||||
// 添加date头
|
||||
SIPDateHeader dateHeader = new SIPDateHeader();
|
||||
// 使用自己修改的
|
||||
WvpSipDate wvpSipDate = new WvpSipDate(Calendar.getInstance(Locale.ENGLISH).getTimeInMillis());
|
||||
dateHeader.setDate(wvpSipDate);
|
||||
response.addHeader(dateHeader);
|
||||
if (!passwordCorrect) {
|
||||
// 注册失败
|
||||
response = getMessageFactory().createResponse(Response.FORBIDDEN, request);
|
||||
response.setReasonPhrase("wrong password");
|
||||
logger.info("[{}] 密码/SIP服务器ID错误, 回复403", requestAddress);
|
||||
sendResponse(evt, response);
|
||||
return;
|
||||
}
|
||||
|
||||
Device deviceInRedis = redisCatchStorage.getDevice(deviceId);
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
if (deviceInRedis != null && device == null) {
|
||||
// redis 存在脏数据
|
||||
redisCatchStorage.clearCatchByDeviceId(deviceId);
|
||||
}
|
||||
// 携带授权头并且密码正确
|
||||
response = getMessageFactory().createResponse(Response.OK, request);
|
||||
// 添加date头
|
||||
SIPDateHeader dateHeader = new SIPDateHeader();
|
||||
// 使用自己修改的
|
||||
WvpSipDate wvpSipDate = new WvpSipDate(Calendar.getInstance(Locale.ENGLISH).getTimeInMillis());
|
||||
dateHeader.setDate(wvpSipDate);
|
||||
response.addHeader(dateHeader);
|
||||
|
||||
if (expiresHeader == null) {
|
||||
response = getMessageFactory().createResponse(Response.BAD_REQUEST, request);
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
serverTransaction.sendResponse(response);
|
||||
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
|
||||
return;
|
||||
}
|
||||
// 添加Contact头
|
||||
response.addHeader(request.getHeader(ContactHeader.NAME));
|
||||
// 添加Expires头
|
||||
response.addHeader(request.getExpires());
|
||||
if (expiresHeader == null) {
|
||||
response = getMessageFactory().createResponse(Response.BAD_REQUEST, request);
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
serverTransaction.sendResponse(response);
|
||||
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
|
||||
return;
|
||||
}
|
||||
// 添加Contact头
|
||||
response.addHeader(request.getHeader(ContactHeader.NAME));
|
||||
// 添加Expires头
|
||||
response.addHeader(request.getExpires());
|
||||
|
||||
// 获取到通信地址等信息
|
||||
ViaHeader viaHeader = (ViaHeader) request.getHeader(ViaHeader.NAME);
|
||||
String received = viaHeader.getReceived();
|
||||
int rPort = viaHeader.getRPort();
|
||||
// 解析本地地址替代
|
||||
if (StringUtils.isEmpty(received) || rPort == -1) {
|
||||
received = viaHeader.getHost();
|
||||
rPort = viaHeader.getPort();
|
||||
}
|
||||
//
|
||||
// 获取到通信地址等信息
|
||||
ViaHeader viaHeader = (ViaHeader) request.getHeader(ViaHeader.NAME);
|
||||
String received = viaHeader.getReceived();
|
||||
int rPort = viaHeader.getRPort();
|
||||
// 解析本地地址替代
|
||||
if (StringUtils.isEmpty(received) || rPort == -1) {
|
||||
received = viaHeader.getHost();
|
||||
rPort = viaHeader.getPort();
|
||||
}
|
||||
if (device == null) {
|
||||
device = new Device();
|
||||
device.setStreamMode("UDP");
|
||||
device.setCharset("GB2312");
|
||||
device.setDeviceId(deviceId);
|
||||
device.setFirsRegister(true);
|
||||
} else {
|
||||
device.setFirsRegister(device.getOnline() == 0);
|
||||
}
|
||||
device.setIp(received);
|
||||
device.setPort(rPort);
|
||||
device.setHostAddress(received.concat(":").concat(String.valueOf(rPort)));
|
||||
if (expiresHeader.getExpires() == 0) {
|
||||
// 注销成功
|
||||
registerFlag = 2;
|
||||
} else {
|
||||
// 注册成功
|
||||
device.setExpires(expiresHeader.getExpires());
|
||||
registerFlag = 1;
|
||||
// 判断TCP还是UDP
|
||||
ViaHeader reqViaHeader = (ViaHeader) request.getHeader(ViaHeader.NAME);
|
||||
String transport = reqViaHeader.getTransport();
|
||||
device.setTransport("TCP".equals(transport) ? "TCP" : "UDP");
|
||||
}
|
||||
|
||||
if (device == null) {
|
||||
device = new Device();
|
||||
device.setStreamMode("UDP");
|
||||
device.setCharset("GB2312");
|
||||
device.setDeviceId(deviceId);
|
||||
device.setFirsRegister(true);
|
||||
}else {
|
||||
if (device.getOnline() == 0) {
|
||||
device.setFirsRegister(true);
|
||||
}
|
||||
}
|
||||
device.setIp(received);
|
||||
device.setPort(rPort);
|
||||
device.setHostAddress(received.concat(":").concat(String.valueOf(rPort)));
|
||||
// 注销成功
|
||||
if (expiresHeader.getExpires() == 0) {
|
||||
registerFlag = 2;
|
||||
}
|
||||
// 注册成功
|
||||
else {
|
||||
device.setExpires(expiresHeader.getExpires());
|
||||
registerFlag = 1;
|
||||
// 判断TCP还是UDP
|
||||
boolean isTcp = false;
|
||||
ViaHeader reqViaHeader = (ViaHeader) request.getHeader(ViaHeader.NAME);
|
||||
String transport = reqViaHeader.getTransport();
|
||||
if (transport.equals("TCP")) {
|
||||
isTcp = true;
|
||||
}
|
||||
device.setTransport(isTcp ? "TCP" : "UDP");
|
||||
}
|
||||
}
|
||||
}
|
||||
sendResponse(evt, response);
|
||||
// 注册成功
|
||||
// 保存到redis
|
||||
if (registerFlag == 1) {
|
||||
logger.info("[{}] 注册成功! deviceId:" + deviceId, requestAddress);
|
||||
publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_REGISTER, expiresHeader.getExpires());
|
||||
} else if (registerFlag == 2) {
|
||||
logger.info("[{}] 注销成功! deviceId:" + deviceId, requestAddress);
|
||||
publisher.outlineEventPublish(deviceId, VideoManagerConstants.EVENT_OUTLINE_UNREGISTER);
|
||||
}
|
||||
} catch (SipException | InvalidArgumentException | NoSuchAlgorithmException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
serverTransaction.sendResponse(response);
|
||||
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
|
||||
// 注册成功
|
||||
// 保存到redis
|
||||
if (registerFlag == 1 ) {
|
||||
logger.info("[{}] 注册成功! deviceId:" + device.getDeviceId(), requestAddress);
|
||||
publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_REGISTER, expiresHeader.getExpires());
|
||||
} else if (registerFlag == 2) {
|
||||
logger.info("[{}] 注销成功! deviceId:" + device.getDeviceId(), requestAddress);
|
||||
publisher.outlineEventPublish(device.getDeviceId(), VideoManagerConstants.EVENT_OUTLINE_UNREGISTER);
|
||||
}
|
||||
} catch (SipException | InvalidArgumentException | NoSuchAlgorithmException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void sendResponse(RequestEvent evt, Response response) throws InvalidArgumentException, SipException {
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
serverTransaction.sendResponse(response);
|
||||
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public class CatalogNotifyMessageHandler extends SIPRequestProcessorParent imple
|
||||
deviceChannel.setParental(1);
|
||||
deviceChannel.setParentId(catalog.getParentId());
|
||||
deviceChannel.setRegisterWay(1);
|
||||
deviceChannel.setCivilCode(parentPlatform.getDeviceGBId().substring(0,6));
|
||||
deviceChannel.setCivilCode(parentPlatform.getAdministrativeDivision());
|
||||
deviceChannel.setModel("live");
|
||||
deviceChannel.setOwner("wvp-pro");
|
||||
deviceChannel.setSecrecy("0");
|
||||
@@ -116,7 +116,7 @@ public class CatalogNotifyMessageHandler extends SIPRequestProcessorParent imple
|
||||
deviceChannel.setStatus(1);
|
||||
deviceChannel.setParentId(gbStream.getCatalogId());
|
||||
deviceChannel.setRegisterWay(1);
|
||||
deviceChannel.setCivilCode(parentPlatform.getDeviceGBId().substring(0,6));
|
||||
deviceChannel.setCivilCode(parentPlatform.getAdministrativeDivision());
|
||||
deviceChannel.setModel("live");
|
||||
deviceChannel.setOwner("wvp-pro");
|
||||
deviceChannel.setParental(0);
|
||||
|
||||
@@ -83,20 +83,17 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem
|
||||
catalog.setParentId(parentPlatform.getDeviceGBId());
|
||||
}
|
||||
DeviceChannel deviceChannel = new DeviceChannel();
|
||||
// 通道的类型,0->国标通道 1->直播流通道 2->业务分组/虚拟组织/行政区划
|
||||
deviceChannel.setChannelType(2);
|
||||
deviceChannel.setChannelId(catalog.getId());
|
||||
deviceChannel.setName(catalog.getName());
|
||||
deviceChannel.setLongitude(0.0);
|
||||
deviceChannel.setLatitude(0.0);
|
||||
deviceChannel.setDeviceId(parentPlatform.getDeviceGBId());
|
||||
deviceChannel.setManufacture("wvp-pro");
|
||||
deviceChannel.setStatus(1);
|
||||
deviceChannel.setParental(1);
|
||||
deviceChannel.setParentId(catalog.getParentId());
|
||||
deviceChannel.setRegisterWay(1);
|
||||
deviceChannel.setCivilCode(parentPlatform.getDeviceGBId().substring(0,6));
|
||||
deviceChannel.setModel("live");
|
||||
deviceChannel.setOwner("wvp-pro");
|
||||
deviceChannel.setSecrecy("0");
|
||||
deviceChannel.setCivilCode(parentPlatform.getAdministrativeDivision());
|
||||
allChannels.add(deviceChannel);
|
||||
}
|
||||
}
|
||||
@@ -107,6 +104,8 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem
|
||||
channel.setCatalogId(parentPlatform.getDeviceGBId());
|
||||
}
|
||||
DeviceChannel deviceChannel = storage.queryChannel(channel.getDeviceId(), channel.getChannelId());
|
||||
// 通道的类型,0->国标通道 1->直播流通道 2->业务分组/虚拟组织/行政区划
|
||||
deviceChannel.setChannelType(0);
|
||||
deviceChannel.setParental(0);
|
||||
deviceChannel.setParentId(channel.getCatalogId());
|
||||
deviceChannel.setCivilCode(parentPlatform.getDeviceGBId().substring(0, 6));
|
||||
@@ -120,6 +119,8 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem
|
||||
gbStream.setCatalogId(null);
|
||||
}
|
||||
DeviceChannel deviceChannel = new DeviceChannel();
|
||||
// 通道的类型,0->国标通道 1->直播流通道 2->业务分组/虚拟组织/行政区划
|
||||
deviceChannel.setChannelType(1);
|
||||
deviceChannel.setChannelId(gbStream.getGbId());
|
||||
deviceChannel.setName(gbStream.getName());
|
||||
deviceChannel.setLongitude(gbStream.getLongitude());
|
||||
@@ -130,7 +131,7 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem
|
||||
deviceChannel.setStatus(1);
|
||||
deviceChannel.setParentId(gbStream.getCatalogId());
|
||||
deviceChannel.setRegisterWay(1);
|
||||
deviceChannel.setCivilCode(parentPlatform.getDeviceGBId().substring(0,6));
|
||||
deviceChannel.setCivilCode(parentPlatform.getAdministrativeDivision());
|
||||
deviceChannel.setModel("live");
|
||||
deviceChannel.setOwner("wvp-pro");
|
||||
deviceChannel.setParental(0);
|
||||
|
||||
@@ -87,23 +87,17 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
|
||||
rootElement = getRootElement(evt, device.getCharset());
|
||||
Element deviceListElement = rootElement.element("DeviceList");
|
||||
Element sumNumElement = rootElement.element("SumNum");
|
||||
if (sumNumElement == null || deviceListElement == null) {
|
||||
Element snElement = rootElement.element("SN");
|
||||
if (snElement == null || sumNumElement == null || deviceListElement == null) {
|
||||
responseAck(evt, Response.BAD_REQUEST, "xml error");
|
||||
return;
|
||||
}
|
||||
int sumNum = Integer.parseInt(sumNumElement.getText());
|
||||
|
||||
if (sumNum == 0) {
|
||||
// 数据已经完整接收
|
||||
storager.cleanChannelsForDevice(device.getDeviceId());
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setKey(key);
|
||||
WVPResult<Object> result = new WVPResult<>();
|
||||
result.setCode(0);
|
||||
result.setData(device);
|
||||
msg.setData(result);
|
||||
result.setMsg("更新成功,共0条");
|
||||
deferredResultHolder.invokeAllResult(msg);
|
||||
catalogDataCatch.del(key);
|
||||
catalogDataCatch.setChannelSyncEnd(device.getDeviceId(), null);
|
||||
}else {
|
||||
Iterator<Element> deviceListIterator = deviceListElement.elementIterator();
|
||||
if (deviceListIterator != null) {
|
||||
@@ -124,24 +118,18 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
|
||||
|
||||
channelList.add(deviceChannel);
|
||||
}
|
||||
logger.info("收到来自设备【{}】的通道: {}个,{}/{}", device.getDeviceId(), channelList.size(), catalogDataCatch.get(key) == null ? 0 :catalogDataCatch.get(key).size(), sumNum);
|
||||
catalogDataCatch.put(key, sumNum, device, channelList);
|
||||
if (catalogDataCatch.get(key).size() == sumNum) {
|
||||
int sn = Integer.parseInt(snElement.getText());
|
||||
catalogDataCatch.put(device.getDeviceId(), sn, sumNum, device, channelList);
|
||||
logger.info("收到来自设备【{}】的通道: {}个,{}/{}", device.getDeviceId(), channelList.size(), catalogDataCatch.get(device.getDeviceId()) == null ? 0 :catalogDataCatch.get(device.getDeviceId()).size(), sumNum);
|
||||
if (catalogDataCatch.get(device.getDeviceId()).size() == sumNum) {
|
||||
// 数据已经完整接收
|
||||
boolean resetChannelsResult = storager.resetChannels(device.getDeviceId(), catalogDataCatch.get(key));
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setKey(key);
|
||||
WVPResult<Object> result = new WVPResult<>();
|
||||
result.setCode(0);
|
||||
result.setData(device);
|
||||
if (resetChannelsResult || sumNum ==0) {
|
||||
result.setMsg("更新成功,共" + sumNum + "条,已更新" + catalogDataCatch.get(key).size() + "条");
|
||||
boolean resetChannelsResult = storager.resetChannels(device.getDeviceId(), catalogDataCatch.get(device.getDeviceId()));
|
||||
if (!resetChannelsResult) {
|
||||
String errorMsg = "接收成功,写入失败,共" + sumNum + "条,已接收" + catalogDataCatch.get(device.getDeviceId()).size() + "条";
|
||||
catalogDataCatch.setChannelSyncEnd(device.getDeviceId(), errorMsg);
|
||||
}else {
|
||||
result.setMsg("接收成功,写入失败,共" + sumNum + "条,已接收" + catalogDataCatch.get(key).size() + "条");
|
||||
catalogDataCatch.setChannelSyncEnd(device.getDeviceId(), null);
|
||||
}
|
||||
msg.setData(result);
|
||||
deferredResultHolder.invokeAllResult(msg);
|
||||
catalogDataCatch.del(key);
|
||||
}
|
||||
}
|
||||
// 回复200 OK
|
||||
@@ -229,21 +217,26 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
|
||||
}
|
||||
|
||||
public SyncStatus getChannelSyncProgress(String deviceId) {
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_CATALOG + deviceId;
|
||||
if (catalogDataCatch.get(key) == null) {
|
||||
if (catalogDataCatch.get(deviceId) == null) {
|
||||
return null;
|
||||
}else {
|
||||
return catalogDataCatch.getSyncStatus(key);
|
||||
return catalogDataCatch.getSyncStatus(deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
public void setChannelSyncReady(String deviceId) {
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_CATALOG + deviceId;
|
||||
catalogDataCatch.addReady(key);
|
||||
public boolean isSyncRunning(String deviceId) {
|
||||
if (catalogDataCatch.get(deviceId) == null) {
|
||||
return false;
|
||||
}else {
|
||||
return catalogDataCatch.isSyncRunning(deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
public void setChannelSyncReady(Device device, int sn) {
|
||||
catalogDataCatch.addReady(device, sn);
|
||||
}
|
||||
|
||||
public void setChannelSyncEnd(String deviceId, String errorMsg) {
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_CATALOG + deviceId;
|
||||
catalogDataCatch.setChannelSyncEnd(key, errorMsg);
|
||||
catalogDataCatch.setChannelSyncEnd(deviceId, errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ZLMRTPServerFactory {
|
||||
return result;
|
||||
}
|
||||
|
||||
public int createRTPServer(MediaServerItem mediaServerItem, String streamId) {
|
||||
public int createRTPServer(MediaServerItem mediaServerItem, String streamId, int ssrc) {
|
||||
int result = -1;
|
||||
// 查询此rtp server 是否已经存在
|
||||
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaServerItem, streamId);
|
||||
@@ -94,6 +94,7 @@ public class ZLMRTPServerFactory {
|
||||
param.put("enable_tcp", 1);
|
||||
param.put("stream_id", streamId);
|
||||
param.put("port", 0);
|
||||
param.put("ssrc", ssrc);
|
||||
JSONObject openRtpServerResultJson = zlmresTfulUtils.openRtpServer(mediaServerItem, param);
|
||||
|
||||
if (openRtpServerResultJson != null) {
|
||||
|
||||
@@ -44,15 +44,15 @@ public interface IDeviceService {
|
||||
SyncStatus getChannelSyncStatus(String deviceId);
|
||||
|
||||
/**
|
||||
* 设置通道同步状态
|
||||
* 查看是否仍在同步
|
||||
* @param deviceId 设备ID
|
||||
* @return
|
||||
*/
|
||||
void setChannelSyncReady(String deviceId);
|
||||
Boolean isSyncRunning(String deviceId);
|
||||
|
||||
/**
|
||||
* 设置同步结束
|
||||
* @param deviceId 设备ID
|
||||
* @param errorMsg 错误信息
|
||||
* 通道同步
|
||||
* @param device
|
||||
*/
|
||||
void setChannelSyncEnd(String deviceId, String errorMsg);
|
||||
void sync(Device device);
|
||||
}
|
||||
|
||||
@@ -44,9 +44,9 @@ public interface IMediaServerService {
|
||||
|
||||
void updateVmServer(List<MediaServerItem> mediaServerItemList);
|
||||
|
||||
SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId);
|
||||
SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId, boolean ssrcCheck);
|
||||
|
||||
SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId, boolean isPlayback);
|
||||
SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId, boolean ssrcCheck, boolean isPlayback);
|
||||
|
||||
void closeRTPServer(String deviceId, String channelId, String ssrc);
|
||||
|
||||
|
||||
@@ -41,10 +41,6 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
if (device == null || device.getSubscribeCycleForCatalog() < 0) {
|
||||
return false;
|
||||
}
|
||||
CatalogSubscribeTask task = (CatalogSubscribeTask)dynamicTask.get(device.getDeviceId() + "catalog");
|
||||
if (task != null && task.getDialogState() != null && task.getDialogState().equals(DialogState.CONFIRMED)) { // 已存在不需要再次添加
|
||||
return true;
|
||||
}
|
||||
logger.info("[添加目录订阅] 设备{}", device.getDeviceId());
|
||||
// 添加目录订阅
|
||||
CatalogSubscribeTask catalogSubscribeTask = new CatalogSubscribeTask(device, sipCommander);
|
||||
@@ -71,10 +67,6 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
return false;
|
||||
}
|
||||
logger.info("[添加移动位置订阅] 设备{}", device.getDeviceId());
|
||||
MobilePositionSubscribeTask task = (MobilePositionSubscribeTask)dynamicTask.get(device.getDeviceId() + "mobile_position");
|
||||
if (task != null && task.getDialogState() != null && task.getDialogState().equals(DialogState.CONFIRMED)) { // 已存在不需要再次添加
|
||||
return true;
|
||||
}
|
||||
// 添加目录订阅
|
||||
MobilePositionSubscribeTask mobilePositionSubscribeTask = new MobilePositionSubscribeTask(device, sipCommander);
|
||||
// 提前开始刷新订阅
|
||||
@@ -100,12 +92,21 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChannelSyncReady(String deviceId) {
|
||||
catalogResponseMessageHandler.setChannelSyncReady(deviceId);
|
||||
public Boolean isSyncRunning(String deviceId) {
|
||||
return catalogResponseMessageHandler.isSyncRunning(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChannelSyncEnd(String deviceId, String errorMsg) {
|
||||
catalogResponseMessageHandler.setChannelSyncEnd(deviceId, errorMsg);
|
||||
public void sync(Device device) {
|
||||
if (catalogResponseMessageHandler.isSyncRunning(device.getDeviceId())) {
|
||||
logger.info("开启同步时发现同步已经存在");
|
||||
return;
|
||||
}
|
||||
int sn = (int)((Math.random()*9+1)*100000);
|
||||
catalogResponseMessageHandler.setChannelSyncReady(device, sn);
|
||||
sipCommander.catalogQuery(device, sn, event -> {
|
||||
String errorMsg = String.format("同步通道失败,错误码: %s, %s", event.statusCode, event.msg);
|
||||
catalogResponseMessageHandler.setChannelSyncEnd(device.getDeviceId(), errorMsg);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,12 +117,12 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId) {
|
||||
return openRTPServer(mediaServerItem, streamId, false);
|
||||
public SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId, boolean ssrcCheck) {
|
||||
return openRTPServer(mediaServerItem, streamId, ssrcCheck,false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId, boolean isPlayback) {
|
||||
public SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId, boolean ssrcCheck, boolean isPlayback) {
|
||||
if (mediaServerItem == null || mediaServerItem.getId() == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -146,7 +146,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
}
|
||||
int rtpServerPort = mediaServerItem.getRtpProxyPort();
|
||||
if (mediaServerItem.isRtpEnable()) {
|
||||
rtpServerPort = zlmrtpServerFactory.createRTPServer(mediaServerItem, streamId);
|
||||
rtpServerPort = zlmrtpServerFactory.createRTPServer(mediaServerItem, streamId, ssrcCheck?Integer.parseInt(ssrc):0);
|
||||
}
|
||||
redisUtil.set(key, mediaServerItem);
|
||||
return new SSRCInfo(rtpServerPort, ssrc, streamId);
|
||||
|
||||
@@ -188,7 +188,7 @@ public class PlayServiceImpl implements IPlayService {
|
||||
if (mediaServerItem.isRtpEnable()) {
|
||||
streamId = String.format("%s_%s", device.getDeviceId(), channelId);
|
||||
}
|
||||
SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId);
|
||||
SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, device.isSsrcCheck());
|
||||
play(mediaServerItem, ssrcInfo, device, channelId, (mediaServerItemInUse, response)->{
|
||||
if (hookEvent != null) {
|
||||
hookEvent.response(mediaServerItem, response);
|
||||
@@ -232,7 +232,7 @@ public class PlayServiceImpl implements IPlayService {
|
||||
streamId = String.format("%s_%s", device.getDeviceId(), channelId);
|
||||
}
|
||||
if (ssrcInfo == null) {
|
||||
ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId);
|
||||
ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, device.isSsrcCheck());
|
||||
}
|
||||
|
||||
// 超时处理
|
||||
|
||||
@@ -420,9 +420,6 @@ public class StreamPushServiceImpl implements IStreamPushService {
|
||||
continue;
|
||||
}
|
||||
streamPushItemForPlatform.setPlatformId(platFormInfoArray[0]);
|
||||
if (platFormInfoArray[0].equals("34020000002110000001")) {
|
||||
System.out.println(111);
|
||||
}
|
||||
List<GbStream> gbStreamList = platformForEvent.get(platFormInfoArray[0]);
|
||||
if (gbStreamList == null) {
|
||||
gbStreamList = new ArrayList<>();
|
||||
|
||||
@@ -37,6 +37,7 @@ public interface DeviceMapper {
|
||||
"subscribeCycleForMobilePosition," +
|
||||
"mobilePositionSubmissionInterval," +
|
||||
"subscribeCycleForAlarm," +
|
||||
"ssrcCheck," +
|
||||
"online" +
|
||||
") VALUES (" +
|
||||
"#{deviceId}," +
|
||||
@@ -59,6 +60,7 @@ public interface DeviceMapper {
|
||||
"#{subscribeCycleForMobilePosition}," +
|
||||
"#{mobilePositionSubmissionInterval}," +
|
||||
"#{subscribeCycleForAlarm}," +
|
||||
"#{ssrcCheck}," +
|
||||
"#{online}" +
|
||||
")")
|
||||
int add(Device device);
|
||||
@@ -84,6 +86,7 @@ public interface DeviceMapper {
|
||||
"<if test=\"subscribeCycleForMobilePosition != null\">, subscribeCycleForMobilePosition=${subscribeCycleForMobilePosition}</if>" +
|
||||
"<if test=\"mobilePositionSubmissionInterval != null\">, mobilePositionSubmissionInterval=${mobilePositionSubmissionInterval}</if>" +
|
||||
"<if test=\"subscribeCycleForAlarm != null\">, subscribeCycleForAlarm=${subscribeCycleForAlarm}</if>" +
|
||||
"<if test=\"ssrcCheck != null\">, ssrcCheck=${ssrcCheck}</if>" +
|
||||
"WHERE deviceId='${deviceId}'"+
|
||||
" </script>"})
|
||||
int update(Device device);
|
||||
|
||||
@@ -16,10 +16,10 @@ public interface ParentPlatformMapper {
|
||||
|
||||
@Insert("INSERT INTO parent_platform (enable, name, serverGBId, serverGBDomain, serverIP, serverPort, deviceGBId, deviceIp, " +
|
||||
" devicePort, username, password, expires, keepTimeout, transport, characterSet, ptz, rtcp, " +
|
||||
" status, shareAllLiveStream, catalogId) " +
|
||||
" status, shareAllLiveStream, startOfflinePush, catalogId, administrativeDivision, catalogGroup) " +
|
||||
" VALUES (${enable}, '${name}', '${serverGBId}', '${serverGBDomain}', '${serverIP}', ${serverPort}, '${deviceGBId}', '${deviceIp}', " +
|
||||
" '${devicePort}', '${username}', '${password}', '${expires}', '${keepTimeout}', '${transport}', '${characterSet}', ${ptz}, ${rtcp}, " +
|
||||
" ${status}, ${shareAllLiveStream}, #{catalogId})")
|
||||
" ${status}, ${shareAllLiveStream}, ${startOfflinePush}, #{catalogId}, #{administrativeDivision}, #{catalogGroup})")
|
||||
int addParentPlatform(ParentPlatform parentPlatform);
|
||||
|
||||
@Update("UPDATE parent_platform " +
|
||||
@@ -42,6 +42,9 @@ public interface ParentPlatformMapper {
|
||||
"rtcp=#{rtcp}, " +
|
||||
"status=#{status}, " +
|
||||
"shareAllLiveStream=#{shareAllLiveStream}, " +
|
||||
"startOfflinePush=${startOfflinePush}, " +
|
||||
"catalogGroup=#{catalogGroup}, " +
|
||||
"administrativeDivision=#{administrativeDivision}, " +
|
||||
"catalogId=#{catalogId} " +
|
||||
"WHERE id=#{id}")
|
||||
int updateParentPlatform(ParentPlatform parentPlatform);
|
||||
|
||||
@@ -238,12 +238,15 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
|
||||
|
||||
@Override
|
||||
public boolean resetChannels(String deviceId, List<DeviceChannel> deviceChannelList) {
|
||||
if (deviceChannelList == null) {
|
||||
return false;
|
||||
}
|
||||
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
||||
// 数据去重
|
||||
List<DeviceChannel> channels = new ArrayList<>();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
Map<String, Integer> subContMap = new HashMap<>();
|
||||
if (deviceChannelList.size() > 1) {
|
||||
if (deviceChannelList != null && deviceChannelList.size() > 1) {
|
||||
// 数据去重
|
||||
Set<String> gbIdSet = new HashSet<>();
|
||||
for (DeviceChannel deviceChannel : deviceChannelList) {
|
||||
@@ -300,6 +303,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
|
||||
dataSourceTransactionManager.commit(transactionStatus); //手动提交
|
||||
return true;
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
dataSourceTransactionManager.rollback(transactionStatus);
|
||||
return false;
|
||||
}
|
||||
@@ -415,10 +419,9 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
|
||||
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
||||
boolean result = false;
|
||||
try {
|
||||
if (platformChannelMapper.delChannelForDeviceId(deviceId) <0 // 删除与国标平台的关联
|
||||
|| deviceChannelMapper.cleanChannelsByDeviceId(deviceId) < 0 // 删除他的通道
|
||||
|| deviceMapper.del(deviceId) < 0 // 移除设备信息
|
||||
) {
|
||||
platformChannelMapper.delChannelForDeviceId(deviceId);
|
||||
deviceChannelMapper.cleanChannelsByDeviceId(deviceId);
|
||||
if ( deviceMapper.del(deviceId) < 0 ) {
|
||||
//事务回滚
|
||||
dataSourceTransactionManager.rollback(transactionStatus);
|
||||
}
|
||||
@@ -517,6 +520,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
|
||||
@Override
|
||||
public boolean updateParentPlatform(ParentPlatform parentPlatform) {
|
||||
int result = 0;
|
||||
if (parentPlatform.getCatalogGroup() == 0) {
|
||||
parentPlatform.setCatalogGroup(1);
|
||||
}
|
||||
if (parentPlatform.getAdministrativeDivision() == null) {
|
||||
parentPlatform.setAdministrativeDivision(parentPlatform.getAdministrativeDivision());
|
||||
}
|
||||
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId()); // .getDeviceGBId());
|
||||
if (parentPlatform.getId() == null ) {
|
||||
if (parentPlatform.getCatalogId() == null) {
|
||||
@@ -536,6 +545,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
|
||||
parentPlatformCatch.setId(parentPlatform.getServerGBId());
|
||||
redisCatchStorage.delPlatformCatchInfo(parentPlatById.getServerGBId());
|
||||
}
|
||||
|
||||
result = platformMapper.updateParentPlatform(parentPlatform);
|
||||
}
|
||||
// 更新缓存
|
||||
@@ -1071,7 +1081,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
|
||||
deviceChannel.setParentId(catalog.getParentId());
|
||||
deviceChannel.setRegisterWay(1);
|
||||
// 行政区划应该是Domain的前八位
|
||||
deviceChannel.setCivilCode(parentPlatByServerGBId.getDeviceGBId().substring(0,6));
|
||||
deviceChannel.setCivilCode(parentPlatByServerGBId.getAdministrativeDivision());
|
||||
deviceChannel.setModel("live");
|
||||
deviceChannel.setOwner("wvp-pro");
|
||||
deviceChannel.setSecrecy("0");
|
||||
|
||||
@@ -164,20 +164,17 @@ public class DeviceQuery {
|
||||
logger.debug("设备通道信息同步API调用,deviceId:" + deviceId);
|
||||
}
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
SyncStatus syncStatus = deviceService.getChannelSyncStatus(deviceId);
|
||||
boolean status = deviceService.isSyncRunning(deviceId);
|
||||
// 已存在则返回进度
|
||||
if (syncStatus != null && syncStatus.getErrorMsg() == null) {
|
||||
if (status) {
|
||||
WVPResult<SyncStatus> wvpResult = new WVPResult<>();
|
||||
wvpResult.setCode(0);
|
||||
wvpResult.setData(syncStatus);
|
||||
SyncStatus channelSyncStatus = deviceService.getChannelSyncStatus(deviceId);
|
||||
wvpResult.setData(channelSyncStatus);
|
||||
return wvpResult;
|
||||
}
|
||||
SyncStatus syncStatusReady = new SyncStatus();
|
||||
deviceService.setChannelSyncReady(deviceId);
|
||||
cmder.catalogQuery(device, event -> {
|
||||
String errorMsg = String.format("同步通道失败,错误码: %s, %s", event.statusCode, event.msg);
|
||||
deviceService.setChannelSyncEnd(deviceId, errorMsg);
|
||||
});
|
||||
deviceService.sync(device);
|
||||
|
||||
WVPResult<SyncStatus> wvpResult = new WVPResult<>();
|
||||
wvpResult.setCode(0);
|
||||
wvpResult.setMsg("开始同步");
|
||||
|
||||
Reference in New Issue
Block a user