适配zlm的hook保活
This commit is contained in:
parent
a2f0854138
commit
9b1af8ef13
@ -148,6 +148,7 @@ create table media_server
|
||||
defaultServer int not null,
|
||||
createTime varchar(50) not null,
|
||||
updateTime varchar(50) not null,
|
||||
hookAliveInterval int not null,
|
||||
constraint media_server_i
|
||||
unique (ip, httpPort)
|
||||
);
|
||||
|
@ -10,10 +10,12 @@ public class VideoManagerConstants {
|
||||
|
||||
public static final String WVP_SERVER_PREFIX = "VMP_SIGNALLING_SERVER_INFO_";
|
||||
|
||||
public static final String WVP_SERVER_STREAM_PUSH_PREFIX = "VMP_SIGNALLING_STREAM_";
|
||||
public static final String WVP_SERVER_STREAM_PREFIX = "VMP_SIGNALLING_STREAM_";
|
||||
|
||||
public static final String MEDIA_SERVER_PREFIX = "VMP_MEDIA_SERVER_";
|
||||
|
||||
public static final String MEDIA_SERVER_KEEPALIVE_PREFIX = "VMP_MEDIA_SERVER_KEEPALIVE_";
|
||||
|
||||
public static final String MEDIA_SERVERS_ONLINE_PREFIX = "VMP_MEDIA_ONLINE_SERVERS_";
|
||||
|
||||
public static final String MEDIA_STREAM_PREFIX = "VMP_MEDIA_STREAM";
|
||||
|
@ -203,6 +203,7 @@ public class MediaConfig{
|
||||
mediaServerItem.setRtpPortRange(rtpPortRange);
|
||||
mediaServerItem.setSendRtpPortRange(sendRtpPortRange);
|
||||
mediaServerItem.setRecordAssistPort(recordAssistPort);
|
||||
mediaServerItem.setHookAliveInterval(120);
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
mediaServerItem.setCreateTime(format.format(System.currentTimeMillis()));
|
||||
|
@ -27,7 +27,7 @@ public class SipConfig {
|
||||
|
||||
Integer keepaliveTimeOut = 255;
|
||||
|
||||
Integer registerTimeInterval = 60;
|
||||
Integer registerTimeInterval = 120;
|
||||
|
||||
private boolean alarm = false;
|
||||
|
||||
|
@ -1,15 +1,16 @@
|
||||
package com.genersoft.iot.vmp.gb28181.event;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.event.offline.OfflineEvent;
|
||||
import com.genersoft.iot.vmp.gb28181.event.platformKeepaliveExpire.PlatformKeepaliveExpireEvent;
|
||||
import com.genersoft.iot.vmp.gb28181.event.platformNotRegister.PlatformNotRegisterEvent;
|
||||
import com.genersoft.iot.vmp.media.zlm.event.ZLMOfflineEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
|
||||
import com.genersoft.iot.vmp.gb28181.event.alarm.AlarmEvent;
|
||||
import com.genersoft.iot.vmp.gb28181.event.offline.OfflineEvent;
|
||||
import com.genersoft.iot.vmp.gb28181.event.online.OnlineEvent;
|
||||
|
||||
/**
|
||||
@ -66,5 +67,11 @@ public class EventPublisher {
|
||||
alarmEvent.setAlarmInfo(deviceAlarm);
|
||||
applicationEventPublisher.publishEvent(alarmEvent);
|
||||
}
|
||||
|
||||
public void zlmOfflineEventPublish(String mediaServerId){
|
||||
ZLMOfflineEvent outEvent = new ZLMOfflineEvent(this);
|
||||
outEvent.setMediaServerId(mediaServerId);
|
||||
applicationEventPublisher.publishEvent(outEvent);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -359,8 +359,8 @@ public class ZLMHttpHookListener {
|
||||
type = "PULL";
|
||||
}
|
||||
}
|
||||
zlmMediaListManager.removeMedia( app, streamId);
|
||||
redisCatchStorage.removeStream(mediaServerItem, OriginType.values()[item.getOriginType()].getType(), app, streamId);
|
||||
zlmMediaListManager.removeMedia(app, streamId);
|
||||
redisCatchStorage.removeStream(mediaServerItem, type, app, streamId);
|
||||
}
|
||||
|
||||
// 发送流变化redis消息
|
||||
|
@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.conf.MediaConfig;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.service.IStreamProxyService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -39,6 +40,9 @@ public class ZLMRunner implements CommandLineRunner {
|
||||
@Autowired
|
||||
private IMediaServerService mediaServerService;
|
||||
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private MediaConfig mediaConfig;
|
||||
|
||||
@ -70,8 +74,14 @@ public class ZLMRunner implements CommandLineRunner {
|
||||
}
|
||||
});
|
||||
|
||||
// TODO 订阅 zlm保活事件, 当zlm离线时做业务的处理
|
||||
|
||||
// 订阅 zlm保活事件, 当zlm离线时做业务的处理
|
||||
hookSubscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_server_keepalive,null,
|
||||
(MediaServerItem mediaServerItem, JSONObject response)->{
|
||||
String mediaServerId = response.getString("mediaServerId");
|
||||
if (mediaServerId !=null ) {
|
||||
mediaServerService.updateMediaServerKeepalive(mediaServerId, response.getJSONObject("data"));
|
||||
}
|
||||
});
|
||||
|
||||
// 获取zlm信息
|
||||
logger.info("等待默认zlm接入...");
|
||||
|
@ -65,6 +65,9 @@ public class ZLMServerConfig {
|
||||
@JSONField(name = "hook.admin_params")
|
||||
private String hookAdminParams;
|
||||
|
||||
@JSONField(name = "hook.alive_interval")
|
||||
private int hookAliveInterval;
|
||||
|
||||
@JSONField(name = "hook.enable")
|
||||
private String hookEnable;
|
||||
|
||||
@ -791,4 +794,12 @@ public class ZLMServerConfig {
|
||||
public void setShellPhell(String shellPhell) {
|
||||
this.shellPhell = shellPhell;
|
||||
}
|
||||
|
||||
public int getHookAliveInterval() {
|
||||
return hookAliveInterval;
|
||||
}
|
||||
|
||||
public void setHookAliveInterval(int hookAliveInterval) {
|
||||
this.hookAliveInterval = hookAliveInterval;
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ public class MediaServerItem{
|
||||
|
||||
private int streamNoneReaderDelayMS;
|
||||
|
||||
private int hookAliveInterval;
|
||||
|
||||
private boolean rtpEnable;
|
||||
|
||||
private boolean status;
|
||||
@ -87,6 +89,7 @@ public class MediaServerItem{
|
||||
autoConfig = true; // 默认值true;
|
||||
secret = zlmServerConfig.getApiSecret();
|
||||
streamNoneReaderDelayMS = zlmServerConfig.getGeneralStreamNoneReaderDelayMS();
|
||||
hookAliveInterval = zlmServerConfig.getHookAliveInterval();
|
||||
rtpEnable = false; // 默认使用单端口;直到用户自己设置开启多端口
|
||||
rtpPortRange = "30000,30500"; // 默认使用30000,30500作为级联时发送流的端口号
|
||||
sendRtpPortRange = "30000,30500"; // 默认使用30000,30500作为级联时发送流的端口号
|
||||
@ -309,4 +312,12 @@ public class MediaServerItem{
|
||||
public void setSendRtpPortRange(String sendRtpPortRange) {
|
||||
this.sendRtpPortRange = sendRtpPortRange;
|
||||
}
|
||||
|
||||
public int getHookAliveInterval() {
|
||||
return hookAliveInterval;
|
||||
}
|
||||
|
||||
public void setHookAliveInterval(int hookAliveInterval) {
|
||||
this.hookAliveInterval = hookAliveInterval;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package com.genersoft.iot.vmp.media.zlm.event;
|
||||
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
public abstract class ZLMEventAbstract extends ApplicationEvent {
|
||||
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String mediaServerId;
|
||||
|
||||
|
||||
public ZLMEventAbstract(Object source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
public String getMediaServerId() {
|
||||
return mediaServerId;
|
||||
}
|
||||
|
||||
public void setMediaServerId(String mediaServerId) {
|
||||
this.mediaServerId = mediaServerId;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.genersoft.iot.vmp.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
@ -30,6 +31,13 @@ public interface IMediaServerService {
|
||||
*/
|
||||
void zlmServerOnline(ZLMServerConfig zlmServerConfig);
|
||||
|
||||
/**
|
||||
* 节点离线
|
||||
* @param mediaServerId
|
||||
* @return
|
||||
*/
|
||||
void zlmServerOffline(String mediaServerId);
|
||||
|
||||
MediaServerItem getMediaServerForMinimumLoad();
|
||||
|
||||
void setZLMConfig(MediaServerItem mediaServerItem);
|
||||
@ -67,4 +75,6 @@ public interface IMediaServerService {
|
||||
void delete(String id);
|
||||
|
||||
MediaServerItem getDefaultMediaServer();
|
||||
|
||||
void updateMediaServerKeepalive(String zlmServerConfig, JSONObject data);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
@ -73,4 +74,19 @@ public interface IStreamProxyService {
|
||||
* @return
|
||||
*/
|
||||
StreamProxyItem getStreamProxyByAppAndStream(String app, String streamId);
|
||||
|
||||
|
||||
/**
|
||||
* 新的节点加入
|
||||
* @param zlmServerConfig
|
||||
* @return
|
||||
*/
|
||||
void zlmServerOnline(ZLMServerConfig zlmServerConfig);
|
||||
|
||||
/**
|
||||
* 节点离线
|
||||
* @param mediaServerId
|
||||
* @return
|
||||
*/
|
||||
void zlmServerOffline(String mediaServerId);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.genersoft.iot.vmp.service;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
|
||||
@ -46,4 +47,18 @@ public interface IStreamPushService {
|
||||
*/
|
||||
boolean stop(String app, String streamId);
|
||||
|
||||
/**
|
||||
* 新的节点加入
|
||||
* @param zlmServerConfig
|
||||
* @return
|
||||
*/
|
||||
void zlmServerOnline(ZLMServerConfig zlmServerConfig);
|
||||
|
||||
/**
|
||||
* 节点离线
|
||||
* @param mediaServerId
|
||||
* @return
|
||||
*/
|
||||
void zlmServerOffline(String mediaServerId);
|
||||
|
||||
}
|
||||
|
@ -97,6 +97,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
|
||||
if (!redisUtil.hasKey(key)) {
|
||||
redisUtil.set(key, mediaServerItem);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,6 +273,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
|
||||
WVPResult<String> result = new WVPResult<>();
|
||||
mediaServerItem.setCreateTime(this.format.format(System.currentTimeMillis()));
|
||||
mediaServerItem.setUpdateTime(this.format.format(System.currentTimeMillis()));
|
||||
mediaServerItem.setHookAliveInterval(120);
|
||||
JSONObject responseJSON = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
|
||||
if (responseJSON != null) {
|
||||
JSONArray data = responseJSON.getJSONArray("data");
|
||||
@ -329,6 +331,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
|
||||
logger.warn("[未注册的zlm] 拒接接入:来自{}:{}", zlmServerConfig.getIp(),zlmServerConfig.getHttpPort() );
|
||||
return;
|
||||
}
|
||||
serverItem.setHookAliveInterval(zlmServerConfig.getHookAliveInterval());
|
||||
if (serverItem.getHttpPort() == 0) {
|
||||
serverItem.setHttpPort(zlmServerConfig.getHttpPort());
|
||||
}
|
||||
@ -350,87 +353,31 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
|
||||
if (serverItem.getRtpProxyPort() == 0) {
|
||||
serverItem.setRtpProxyPort(zlmServerConfig.getRtpProxyPort());
|
||||
}
|
||||
if (StringUtils.isEmpty(serverItem.getId())) {
|
||||
serverItem.setId(zlmServerConfig.getGeneralMediaServerId());
|
||||
}
|
||||
serverItem.setStatus(true);
|
||||
if (StringUtils.isEmpty(serverItem.getId())) {
|
||||
serverItem.setId(zlmServerConfig.getGeneralMediaServerId());
|
||||
mediaServerMapper.updateByHostAndPort(serverItem);
|
||||
}else {
|
||||
mediaServerMapper.update(serverItem);
|
||||
}
|
||||
if (redisUtil.get(VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + serverItem.getId()) == null) {
|
||||
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + serverItem.getId();
|
||||
if (redisUtil.get(key) == null) {
|
||||
SsrcConfig ssrcConfig = new SsrcConfig(serverItem.getId(), null, sipConfig.getDomain());
|
||||
serverItem.setSsrcConfig(ssrcConfig);
|
||||
redisUtil.set(VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + serverItem.getId(), serverItem);
|
||||
redisUtil.set(key, serverItem);
|
||||
}
|
||||
|
||||
serverItem.setStatus(true);
|
||||
resetOnlineServerItem(serverItem);
|
||||
updateMediaServerKeepalive(serverItem.getId(), null);
|
||||
setZLMConfig(serverItem);
|
||||
}
|
||||
|
||||
// if (zlmServerConfig.getGeneralMediaServerId().equals(mediaConfig.getId())
|
||||
// || (zlmServerConfig.getIp().equals(mediaConfig.getIp()) && zlmServerConfig.getHttpPort() == mediaConfig.getHttpPort())) {
|
||||
// // 配置文件的zlm
|
||||
// // 如果是配置文件中的zlm。 也就是默认zlm。 一切以配置文件内容为准
|
||||
// // wvp互惠修改zlm的端口,需要自行配置。
|
||||
// MediaServerItem serverItemFromConfig = mediaConfig.getMediaSerItem();
|
||||
// serverItemFromConfig.setId(zlmServerConfig.getGeneralMediaServerId());
|
||||
// if (mediaConfig.getHttpPort() == 0) {
|
||||
// serverItemFromConfig.setHttpPort(zlmServerConfig.getHttpPort());
|
||||
// }
|
||||
// if (mediaConfig.getHttpSSlPort() == 0) {
|
||||
// serverItemFromConfig.setHttpSSlPort(zlmServerConfig.getHttpSSLport());
|
||||
// }
|
||||
// if (mediaConfig.getRtmpPort() == 0) {
|
||||
// serverItemFromConfig.setRtmpPort(zlmServerConfig.getRtmpPort());
|
||||
// }
|
||||
// if (mediaConfig.getRtmpSSlPort() == 0) {
|
||||
// serverItemFromConfig.setRtmpSSlPort(zlmServerConfig.getRtmpSslPort());
|
||||
// }
|
||||
// if (mediaConfig.getRtspPort() == 0) {
|
||||
// serverItemFromConfig.setRtspPort(zlmServerConfig.getRtspPort());
|
||||
// }
|
||||
// if (mediaConfig.getRtspSSLPort() == 0) {
|
||||
// serverItemFromConfig.setRtspSSLPort(zlmServerConfig.getRtspSSlport());
|
||||
// }
|
||||
// if (mediaConfig.getRtpProxyPort() == 0) {
|
||||
// serverItemFromConfig.setRtpProxyPort(zlmServerConfig.getRtpProxyPort());
|
||||
// }
|
||||
// if (serverItem != null){
|
||||
// mediaServerMapper.delDefault();
|
||||
// mediaServerMapper.add(serverItemFromConfig);
|
||||
// String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItemFromConfig.getId();
|
||||
// MediaServerItem serverItemInRedis = (MediaServerItem)redisUtil.get(key);
|
||||
// if (serverItemInRedis != null) {
|
||||
// serverItemFromConfig.setSsrcConfig(serverItemInRedis.getSsrcConfig());
|
||||
// }else {
|
||||
// serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getDomain()));
|
||||
// }
|
||||
// redisUtil.set(key, serverItemFromConfig);
|
||||
// }else {
|
||||
// String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItemFromConfig.getId();
|
||||
// serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getDomain()));
|
||||
// redisUtil.set(key, serverItemFromConfig);
|
||||
// mediaServerMapper.add(serverItemFromConfig);
|
||||
// }
|
||||
// resetOnlineServerItem(serverItemFromConfig);
|
||||
// setZLMConfig(serverItemFromConfig);
|
||||
// }
|
||||
// 移除未添加的zlm的接入,所有的zlm必须先添加后才可以加入使用
|
||||
// else {
|
||||
// String now = this.format.format(System.currentTimeMillis());
|
||||
// if (serverItem == null){
|
||||
// // 一个新的zlm接入wvp
|
||||
// serverItem = new MediaServerItem(zlmServerConfig, sipConfig.getIp());
|
||||
// serverItem.setCreateTime(now);
|
||||
// serverItem.setUpdateTime(now);
|
||||
// String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItem.getId();
|
||||
// serverItem.setSsrcConfig(new SsrcConfig(serverItem.getId(), null, sipConfig.getDomain()));
|
||||
// redisUtil.set(key, serverItem);
|
||||
// // 存入数据库
|
||||
// mediaServerMapper.add(serverItem);
|
||||
// setZLMConfig(serverItem);
|
||||
// }
|
||||
// resetOnlineServerItem(serverItem);
|
||||
// }
|
||||
@Override
|
||||
public void zlmServerOffline(String mediaServerId) {
|
||||
delete(mediaServerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -611,9 +558,17 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
|
||||
|
||||
@Override
|
||||
public void delete(String id) {
|
||||
redisUtil.zRemove(VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId() + "_", id);
|
||||
redisUtil.zRemove(VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId(), id);
|
||||
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + id;
|
||||
redisUtil.del(key);
|
||||
mediaServerMapper.delOne(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMediaServerKeepalive(String mediaServerId, JSONObject data) {
|
||||
MediaServerItem mediaServerItem = getOne(mediaServerId);
|
||||
String key = VideoManagerConstants.MEDIA_SERVER_KEEPALIVE_PREFIX + userSetup.getServerId() + "_" + mediaServerId;
|
||||
int hookAliveInterval = mediaServerItem.getHookAliveInterval() + 2;
|
||||
redisUtil.set(key, data, hookAliveInterval);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
@ -50,6 +51,9 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||
@Autowired
|
||||
private StreamProxyMapper streamProxyMapper;
|
||||
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private GbStreamMapper gbStreamMapper;
|
||||
|
||||
@ -249,4 +253,20 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||
public StreamProxyItem getStreamProxyByAppAndStream(String app, String streamId) {
|
||||
return videoManagerStorager.getStreamProxyByAppAndStream(app, streamId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void zlmServerOnline(ZLMServerConfig zlmServerConfig) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void zlmServerOffline(String mediaServerId) {
|
||||
// 移除开启了无人观看自动移除的流
|
||||
streamProxyMapper.deleteAutoRemoveItemByMediaServerId(mediaServerId);
|
||||
// 其他的流设置未启用
|
||||
streamProxyMapper.updateStatus(false, mediaServerId);
|
||||
// 移除redis内流的信息
|
||||
redisCatchStorage.removeStream(mediaServerId, "PULL");
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
|
||||
@ -135,4 +136,18 @@ public class StreamPushServiceImpl implements IStreamPushService {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void zlmServerOnline(ZLMServerConfig zlmServerConfig) {
|
||||
// 似乎没啥需要做的
|
||||
}
|
||||
|
||||
@Override
|
||||
public void zlmServerOffline(String mediaServerId) {
|
||||
// 移除没有serverId的推流
|
||||
streamPushMapper.deleteWithoutGBId(mediaServerId);
|
||||
// 其他的流设置未启用
|
||||
gbStreamMapper.updateStatusByMediaServerId(mediaServerId, false);
|
||||
// 移除redis内流的信息
|
||||
redisCatchStorage.removeStream(mediaServerId, "PUSH");
|
||||
}
|
||||
}
|
||||
|
@ -146,6 +146,13 @@ public interface IRedisCatchStorage {
|
||||
*/
|
||||
void removeStream(MediaServerItem mediaServerItem, String type, String app, String streamId);
|
||||
|
||||
|
||||
/**
|
||||
* 移除流信息从redis
|
||||
* @param mediaServerId
|
||||
*/
|
||||
void removeStream(String mediaServerId, String type);
|
||||
|
||||
/**
|
||||
* 开始下载录像时存入
|
||||
* @param streamInfo
|
||||
|
@ -422,4 +422,5 @@ public interface IVideoManagerStorager {
|
||||
* @return
|
||||
*/
|
||||
StreamProxyItem getStreamProxyByAppAndStream(String app, String streamId);
|
||||
|
||||
}
|
||||
|
@ -60,4 +60,9 @@ public interface GbStreamMapper {
|
||||
|
||||
@Select("SELECT gs.*, pgs.platformId FROM gb_stream gs LEFT JOIN platform_gb_stream pgs ON gs.app = pgs.app AND gs.stream = pgs.stream WHERE mediaServerId=#{mediaServerId} ")
|
||||
List<GbStream> selectAllByMediaServerId(String mediaServerId);
|
||||
|
||||
@Update("UPDATE gb_stream " +
|
||||
"SET status=${status} " +
|
||||
"WHERE mediaServerId=#{mediaServerId} ")
|
||||
void updateStatusByMediaServerId(String mediaServerId, boolean status);
|
||||
}
|
||||
|
@ -36,7 +36,8 @@ public interface MediaServerMapper {
|
||||
"recordAssistPort, " +
|
||||
"defaultServer, " +
|
||||
"createTime, " +
|
||||
"updateTime" +
|
||||
"updateTime, " +
|
||||
"hookAliveInterval" +
|
||||
") VALUES " +
|
||||
"(" +
|
||||
"'${id}', " +
|
||||
@ -60,7 +61,8 @@ public interface MediaServerMapper {
|
||||
"${recordAssistPort}, " +
|
||||
"${defaultServer}, " +
|
||||
"'${createTime}', " +
|
||||
"'${updateTime}')")
|
||||
"'${updateTime}', " +
|
||||
"${hookAliveInterval})")
|
||||
int add(MediaServerItem mediaServerItem);
|
||||
|
||||
@Update(value = {" <script>" +
|
||||
@ -84,6 +86,7 @@ public interface MediaServerMapper {
|
||||
"<if test=\"sendRtpPortRange != null\">, sendRtpPortRange='${sendRtpPortRange}'</if>" +
|
||||
"<if test=\"secret != null\">, secret='${secret}'</if>" +
|
||||
"<if test=\"recordAssistPort != null\">, recordAssistPort=${recordAssistPort}</if>" +
|
||||
"<if test=\"hookAliveInterval != null\">, hookAliveInterval=${hookAliveInterval}</if>" +
|
||||
"WHERE id='${id}'"+
|
||||
" </script>"})
|
||||
int update(MediaServerItem mediaServerItem);
|
||||
@ -108,6 +111,7 @@ public interface MediaServerMapper {
|
||||
"<if test=\"sendRtpPortRange != null\">, sendRtpPortRange='${sendRtpPortRange}'</if>" +
|
||||
"<if test=\"secret != null\">, secret='${secret}'</if>" +
|
||||
"<if test=\"recordAssistPort != null\">, recordAssistPort=${recordAssistPort}</if>" +
|
||||
"<if test=\"hookAliveInterval != null\">, hookAliveInterval=${hookAliveInterval}</if>" +
|
||||
"WHERE ip='${ip}' and httpPort=${httpPort}"+
|
||||
" </script>"})
|
||||
int updateByHostAndPort(MediaServerItem mediaServerItem);
|
||||
|
@ -51,4 +51,17 @@ public interface StreamProxyMapper {
|
||||
"LEFT JOIN gb_stream pgs on st.app = pgs.app AND st.stream = pgs.stream " +
|
||||
"WHERE st.enable=${enable} and st.mediaServerId = '${id}' order by st.createTime desc")
|
||||
List<StreamProxyItem> selectForEnableInMediaServer(String id, boolean enable);
|
||||
|
||||
@Select("SELECT st.*, pgs.gbId, pgs.name, pgs.longitude, pgs.latitude FROM stream_proxy st " +
|
||||
"LEFT JOIN gb_stream pgs on st.app = pgs.app AND st.stream = pgs.stream " +
|
||||
"WHERE st.mediaServerId = '${id}' order by st.createTime desc")
|
||||
List<StreamProxyItem> selectInMediaServer(String id);
|
||||
|
||||
@Update("UPDATE stream_proxy " +
|
||||
"SET enable=#{status} " +
|
||||
"WHERE mediaServerId=#{mediaServerId}")
|
||||
void updateStatus(boolean status, String mediaServerId);
|
||||
|
||||
@Delete("DELETE FROM stream_proxy WHERE mediaServerId=#{mediaServerId}")
|
||||
void deleteAutoRemoveItemByMediaServerId(String mediaServerId);
|
||||
}
|
||||
|
@ -53,4 +53,7 @@ public interface StreamPushMapper {
|
||||
@Delete("DELETE FROM stream_push")
|
||||
void clear();
|
||||
|
||||
@Delete("DELETE FROM stream_push WHERE mediaServerId=#{mediaServerId}")
|
||||
void deleteWithoutGBId(String mediaServerId);
|
||||
|
||||
}
|
||||
|
@ -333,17 +333,14 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||
|
||||
@Override
|
||||
public void addStream(MediaServerItem mediaServerItem, String type, String app, String streamId, StreamInfo streamInfo) {
|
||||
String key = VideoManagerConstants.WVP_SERVER_STREAM_PUSH_PREFIX + userSetup.getServerId() + "_" + type + "_" + app + "_" + streamId + "_" + mediaServerItem.getId();
|
||||
String key = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetup.getServerId() + "_" + type + "_" + app + "_" + streamId + "_" + mediaServerItem.getId();
|
||||
redis.set(key, streamInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeStream(MediaServerItem mediaServerItem, String type, String app, String streamId) {
|
||||
String key = VideoManagerConstants.WVP_SERVER_STREAM_PUSH_PREFIX + userSetup.getServerId() + "_*_" + app + "_" + streamId + "_" + mediaServerItem.getId();
|
||||
List<Object> streams = redis.scan(key);
|
||||
for (Object stream : streams) {
|
||||
redis.del((String) stream);
|
||||
}
|
||||
String key = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetup.getServerId() + "_" + type + "_" + app + "_" + streamId + "_" + mediaServerItem.getId();
|
||||
redis.del(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -359,4 +356,13 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||
JSONObject jsonObject = (JSONObject)redis.get(key);
|
||||
return JSONObject.toJavaObject(jsonObject, ThirdPartyGB.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeStream(String mediaServerId, String type) {
|
||||
String key = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetup.getServerId() + "_" + type + "_*_*_" + mediaServerId;
|
||||
List<Object> streams = redis.scan(key);
|
||||
for (Object stream : streams) {
|
||||
redis.del((String) stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -738,4 +738,5 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
|
||||
public StreamProxyItem getStreamProxyByAppAndStream(String app, String streamId) {
|
||||
return streamProxyMapper.selectOne(app, streamId);
|
||||
}
|
||||
|
||||
}
|
||||
|
Binary file not shown.
@ -25,7 +25,6 @@ class RoleServiceImplTest {
|
||||
void getAllUser() {
|
||||
List<Role> all = roleService.getAll();
|
||||
Role roleById = roleService.getRoleById(1);
|
||||
System.out.println();
|
||||
|
||||
}
|
||||
|
||||
|
@ -27,10 +27,8 @@ class UserServiceImplTest {
|
||||
@org.junit.jupiter.api.Test
|
||||
void getAllUser() {
|
||||
List<User> allUsers = userService.getAllUsers();
|
||||
System.out.println(userService.getAllUsers().size());
|
||||
User admin = userService.getUser("admin", "21232f297a57a5a743894a0e4a801fc3");
|
||||
User admin1 = userService.getUserByUsername("admin");
|
||||
System.out.println(12);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user