Browse Source

优化redis存储,alarm默认关闭处理

pull/276/head
648540858 3 years ago
parent
commit
241804f5f8
  1. 5
      pom.xml
  2. 17
      src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java
  3. 10
      src/main/java/com/genersoft/iot/vmp/conf/SipConfig.java
  4. 5
      src/main/java/com/genersoft/iot/vmp/conf/WVPTimerTask.java
  5. 6
      src/main/java/com/genersoft/iot/vmp/gb28181/event/DeviceOffLineDetector.java
  6. 19
      src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java
  7. 11
      src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepliveTimeoutListener.java
  8. 6
      src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/OfflineEventListener.java
  9. 7
      src/main/java/com/genersoft/iot/vmp/gb28181/event/online/OnlineEventListener.java
  10. 12
      src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEventLister.java
  11. 14
      src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java
  12. 1104
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/MessageRequestProcessor1.java
  13. 7
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java
  14. 7
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java
  15. 43
      src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
  16. 2
      src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
  17. 80
      src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
  18. 4
      src/main/resources/all-application.yml

5
pom.xml

@ -204,6 +204,11 @@
<version>1.12</version> <version>1.12</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<!-- &lt;!&ndash; 检测文件编码 &ndash;&gt;--> <!-- &lt;!&ndash; 检测文件编码 &ndash;&gt;-->
<!-- &lt;!&ndash; https://mvnrepository.com/artifact/cpdetector/cpdetector &ndash;&gt;--> <!-- &lt;!&ndash; https://mvnrepository.com/artifact/cpdetector/cpdetector &ndash;&gt;-->
<!-- <dependency>--> <!-- <dependency>-->

17
src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java

@ -14,7 +14,7 @@ public class VideoManagerConstants {
public static final String MEDIA_SERVER_PREFIX = "VMP_MEDIA_SERVER_"; public static final String MEDIA_SERVER_PREFIX = "VMP_MEDIA_SERVER_";
public static final String MEDIA_SERVERS_ONLINE_PREFIX = "VMP_MEDIA_ONLINE_SERVERS"; public static final String MEDIA_SERVERS_ONLINE_PREFIX = "VMP_MEDIA_ONLINE_SERVERS_";
public static final String MEDIA_STREAM_PREFIX = "VMP_MEDIA_STREAM"; public static final String MEDIA_STREAM_PREFIX = "VMP_MEDIA_STREAM";
@ -22,14 +22,15 @@ public class VideoManagerConstants {
public static final String CACHEKEY_PREFIX = "VMP_CHANNEL_"; public static final String CACHEKEY_PREFIX = "VMP_CHANNEL_";
public static final String KEEPLIVEKEY_PREFIX = "VMP_keeplive_"; public static final String KEEPLIVEKEY_PREFIX = "VMP_KEEPALIVE_";
// 此处多了一个_,暂不修改
public static final String PLAYER_PREFIX = "VMP_PLAYER_"; public static final String PLAYER_PREFIX = "VMP_PLAYER_";
public static final String PLAY_BLACK_PREFIX = "VMP_PLAYBACK_"; public static final String PLAY_BLACK_PREFIX = "VMP_PLAYBACK_";
public static final String DOWNLOAD_PREFIX = "VMP_DOWNLOAD_"; public static final String DOWNLOAD_PREFIX = "VMP_DOWNLOAD_";
public static final String PLATFORM_KEEPLIVEKEY_PREFIX = "VMP_PLATFORM_KEEPLIVE_"; public static final String PLATFORM_KEEPALIVE_PREFIX = "VMP_PLATFORM_KEEPALIVE_";
public static final String PLATFORM_CATCH_PREFIX = "VMP_PLATFORM_CATCH_"; public static final String PLATFORM_CATCH_PREFIX = "VMP_PLATFORM_CATCH_";
@ -39,8 +40,6 @@ public class VideoManagerConstants {
public static final String PLATFORM_SEND_RTP_INFO_PREFIX = "VMP_PLATFORM_SEND_RTP_INFO_"; public static final String PLATFORM_SEND_RTP_INFO_PREFIX = "VMP_PLATFORM_SEND_RTP_INFO_";
public static final String Pattern_Topic = "VMP_KEEPLIVE_PLATFORM_";
public static final String EVENT_ONLINE_REGISTER = "1"; public static final String EVENT_ONLINE_REGISTER = "1";
public static final String EVENT_ONLINE_KEEPLIVE = "2"; public static final String EVENT_ONLINE_KEEPLIVE = "2";
@ -51,10 +50,10 @@ public class VideoManagerConstants {
public static final String EVENT_OUTLINE_TIMEOUT = "2"; public static final String EVENT_OUTLINE_TIMEOUT = "2";
public static final String MEDIA_SSRC_USED_PREFIX = "VMP_media_used_ssrc_"; public static final String MEDIA_SSRC_USED_PREFIX = "VMP_MEDIA_USED_SSRC_";
public static final String MEDIA_TRANSACTION_USED_PREFIX = "VMP_media_transaction_"; public static final String MEDIA_TRANSACTION_USED_PREFIX = "VMP_MEDIA_TRANSACTION_";
//************************** redis 消息********************************* //************************** redis 消息*********************************
public static final String WVP_MSG_STREAM_PUSH_CHANGE_PREFIX = "WVP_MSG_STREAM_CHANGE_"; public static final String WVP_MSG_STREAM_CHANGE__PREFIX = "WVP_MSG_STREAM_CHANGE_";
} }

10
src/main/java/com/genersoft/iot/vmp/conf/SipConfig.java

@ -29,6 +29,8 @@ public class SipConfig {
Integer registerTimeInterval = 60; Integer registerTimeInterval = 60;
private boolean alarm = false;
public void setIp(String ip) { public void setIp(String ip) {
this.ip = ip; this.ip = ip;
} }
@ -104,4 +106,12 @@ public class SipConfig {
public Integer getRegisterTimeInterval() { public Integer getRegisterTimeInterval() {
return registerTimeInterval; return registerTimeInterval;
} }
public boolean isAlarm() {
return alarm;
}
public void setAlarm(boolean alarm) {
this.alarm = alarm;
}
} }

5
src/main/java/com/genersoft/iot/vmp/conf/WVPTimerTask.java

@ -17,9 +17,6 @@ public class WVPTimerTask {
@Autowired @Autowired
private IMediaServerService mediaServerService; private IMediaServerService mediaServerService;
@Autowired
private UserSetup userSetup;
@Value("${server.port}") @Value("${server.port}")
private int serverPort; private int serverPort;
@ -31,6 +28,6 @@ public class WVPTimerTask {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("ip", sipConfig.getIp()); jsonObject.put("ip", sipConfig.getIp());
jsonObject.put("port", serverPort); jsonObject.put("port", serverPort);
redisCatchStorage.updateWVPInfo(userSetup.getServerId(), jsonObject, 3); redisCatchStorage.updateWVPInfo(jsonObject, 3);
} }
} }

6
src/main/java/com/genersoft/iot/vmp/gb28181/event/DeviceOffLineDetector.java

@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.gb28181.event; package com.genersoft.iot.vmp.gb28181.event;
import com.genersoft.iot.vmp.conf.UserSetup;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -17,8 +18,11 @@ public class DeviceOffLineDetector {
@Autowired @Autowired
private RedisUtil redis; private RedisUtil redis;
@Autowired
private UserSetup userSetup;
public boolean isOnline(String deviceId) { public boolean isOnline(String deviceId) {
String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + deviceId; String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetup.getServerId() + "_" + deviceId;
return redis.hasKey(key); return redis.hasKey(key);
} }
} }

19
src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java

@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.gb28181.event.offline; package com.genersoft.iot.vmp.gb28181.event.offline;
import com.genersoft.iot.vmp.conf.UserSetup;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -24,6 +25,9 @@ public class KeepaliveTimeoutListenerForPlatform extends KeyExpirationEventMessa
@Autowired @Autowired
private EventPublisher publisher; private EventPublisher publisher;
@Autowired
private UserSetup userSetup;
public KeepaliveTimeoutListenerForPlatform(RedisMessageListenerContainer listenerContainer) { public KeepaliveTimeoutListenerForPlatform(RedisMessageListenerContainer listenerContainer) {
super(listenerContainer); super(listenerContainer);
} }
@ -40,17 +44,20 @@ public class KeepaliveTimeoutListenerForPlatform extends KeyExpirationEventMessa
String expiredKey = message.toString(); String expiredKey = message.toString();
logger.debug(expiredKey); logger.debug(expiredKey);
// 平台心跳到期,需要重发, 判断是否已经多次未收到心跳回复, 多次未收到,则重新发起注册, 注册尝试多次未得到回复,则认为平台离线 // 平台心跳到期,需要重发, 判断是否已经多次未收到心跳回复, 多次未收到,则重新发起注册, 注册尝试多次未得到回复,则认为平台离线
if (expiredKey.startsWith(VideoManagerConstants.PLATFORM_KEEPLIVEKEY_PREFIX)) { String PLATFORM_KEEPLIVEKEY_PREFIX = VideoManagerConstants.PLATFORM_KEEPALIVE_PREFIX + userSetup.getServerId() + "_";
String platformGBId = expiredKey.substring(VideoManagerConstants.PLATFORM_KEEPLIVEKEY_PREFIX.length(),expiredKey.length()); String PLATFORM_REGISTER_PREFIX = VideoManagerConstants.PLATFORM_REGISTER_PREFIX + userSetup.getServerId() + "_";
String KEEPLIVEKEY_PREFIX = VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetup.getServerId() + "_";
if (expiredKey.startsWith(PLATFORM_KEEPLIVEKEY_PREFIX)) {
String platformGBId = expiredKey.substring(PLATFORM_KEEPLIVEKEY_PREFIX.length(),expiredKey.length());
publisher.platformKeepaliveExpireEventPublish(platformGBId); publisher.platformKeepaliveExpireEventPublish(platformGBId);
}else if (expiredKey.startsWith(VideoManagerConstants.PLATFORM_REGISTER_PREFIX)) { }else if (expiredKey.startsWith(PLATFORM_REGISTER_PREFIX)) {
String platformGBId = expiredKey.substring(VideoManagerConstants.PLATFORM_REGISTER_PREFIX.length(),expiredKey.length()); String platformGBId = expiredKey.substring(PLATFORM_REGISTER_PREFIX.length(),expiredKey.length());
publisher.platformNotRegisterEventPublish(platformGBId); publisher.platformNotRegisterEventPublish(platformGBId);
}else{ }else{
String deviceId = expiredKey.substring(VideoManagerConstants.KEEPLIVEKEY_PREFIX.length(),expiredKey.length()); String deviceId = expiredKey.substring(KEEPLIVEKEY_PREFIX.length(),expiredKey.length());
publisher.outlineEventPublish(deviceId, VideoManagerConstants.EVENT_OUTLINE_TIMEOUT); publisher.outlineEventPublish(deviceId, KEEPLIVEKEY_PREFIX);
} }
} }

11
src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepliveTimeoutListener.java

@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.gb28181.event.offline; package com.genersoft.iot.vmp.gb28181.event.offline;
import com.genersoft.iot.vmp.conf.UserSetup;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -24,6 +25,9 @@ public class KeepliveTimeoutListener extends KeyExpirationEventMessageListener {
@Autowired @Autowired
private EventPublisher publisher; private EventPublisher publisher;
@Autowired
private UserSetup userSetup;
public KeepliveTimeoutListener(RedisMessageListenerContainer listenerContainer) { public KeepliveTimeoutListener(RedisMessageListenerContainer listenerContainer) {
super(listenerContainer); super(listenerContainer);
} }
@ -37,12 +41,13 @@ public class KeepliveTimeoutListener extends KeyExpirationEventMessageListener {
public void onMessage(Message message, byte[] pattern) { public void onMessage(Message message, byte[] pattern) {
// 获取失效的key // 获取失效的key
String expiredKey = message.toString(); String expiredKey = message.toString();
if(!expiredKey.startsWith(VideoManagerConstants.KEEPLIVEKEY_PREFIX)){ String KEEPLIVEKEY_PREFIX = VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetup.getServerId() + "_";
logger.debug("收到redis过期监听,但开头不是"+VideoManagerConstants.KEEPLIVEKEY_PREFIX+",忽略"); if(!expiredKey.startsWith(KEEPLIVEKEY_PREFIX)){
logger.debug("收到redis过期监听,但开头不是"+KEEPLIVEKEY_PREFIX+",忽略");
return; return;
} }
String deviceId = expiredKey.substring(VideoManagerConstants.KEEPLIVEKEY_PREFIX.length(),expiredKey.length()); String deviceId = expiredKey.substring(KEEPLIVEKEY_PREFIX.length(),expiredKey.length());
publisher.outlineEventPublish(deviceId, VideoManagerConstants.EVENT_OUTLINE_TIMEOUT); publisher.outlineEventPublish(deviceId, VideoManagerConstants.EVENT_OUTLINE_TIMEOUT);
} }
} }

6
src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/OfflineEventListener.java

@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.gb28181.event.offline; package com.genersoft.iot.vmp.gb28181.event.offline;
import com.genersoft.iot.vmp.conf.UserSetup;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -28,6 +29,9 @@ public class OfflineEventListener implements ApplicationListener<OfflineEvent> {
@Autowired @Autowired
private RedisUtil redis; private RedisUtil redis;
@Autowired
private UserSetup userSetup;
@Override @Override
public void onApplicationEvent(OfflineEvent event) { public void onApplicationEvent(OfflineEvent event) {
@ -35,7 +39,7 @@ public class OfflineEventListener implements ApplicationListener<OfflineEvent> {
logger.debug("设备离线事件触发,deviceId:" + event.getDeviceId() + ",from:" + event.getFrom()); logger.debug("设备离线事件触发,deviceId:" + event.getDeviceId() + ",from:" + event.getFrom());
} }
String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + event.getDeviceId(); String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetup.getServerId() + "_" + event.getDeviceId();
switch (event.getFrom()) { switch (event.getFrom()) {
// 心跳超时触发的离线事件,说明redis中已删除,无需处理 // 心跳超时触发的离线事件,说明redis中已删除,无需处理

7
src/main/java/com/genersoft/iot/vmp/gb28181/event/online/OnlineEventListener.java

@ -1,7 +1,9 @@
package com.genersoft.iot.vmp.gb28181.event.online; package com.genersoft.iot.vmp.gb28181.event.online;
import com.genersoft.iot.vmp.conf.SipConfig; import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.conf.UserSetup;
import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.storager.dao.dto.User;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -35,6 +37,9 @@ public class OnlineEventListener implements ApplicationListener<OnlineEvent> {
@Autowired @Autowired
private SipConfig sipConfig; private SipConfig sipConfig;
@Autowired
private UserSetup userSetup;
private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Override @Override
@ -44,7 +49,7 @@ public class OnlineEventListener implements ApplicationListener<OnlineEvent> {
logger.debug("设备上线事件触发,deviceId:" + event.getDevice().getDeviceId() + ",from:" + event.getFrom()); logger.debug("设备上线事件触发,deviceId:" + event.getDevice().getDeviceId() + ",from:" + event.getFrom());
} }
Device device = event.getDevice(); Device device = event.getDevice();
String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + event.getDevice().getDeviceId(); String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetup.getServerId() + "_" + event.getDevice().getDeviceId();
switch (event.getFrom()) { switch (event.getFrom()) {
// 注册时触发的在线事件,先在redis中增加超时超时监听 // 注册时触发的在线事件,先在redis中增加超时超时监听

12
src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEventLister.java

@ -52,18 +52,18 @@ public class PlatformNotRegisterEventLister implements ApplicationListener<Platf
@Override @Override
public void onApplicationEvent(PlatformNotRegisterEvent event) { public void onApplicationEvent(PlatformNotRegisterEvent event) {
logger.info("平台未注册事件触发,平台国标ID:" + event.getPlatformGbID()); logger.info("[ 平台未注册事件 ]平台国标ID:" + event.getPlatformGbID());
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(event.getPlatformGbID()); ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(event.getPlatformGbID());
if (parentPlatform == null) { if (parentPlatform == null) {
logger.info("平台未注册事件触发,但平台已经删除!!! 平台国标ID:" + event.getPlatformGbID()); logger.info("[ 平台未注册事件 ] 平台已经删除!!! 平台国标ID:" + event.getPlatformGbID());
return; return;
} }
// 查询是否有推流, 如果有则都停止 // 查询是否有推流, 如果有则都停止
List<SendRtpItem> sendRtpItems = redisCatchStorage.querySendRTPServer(event.getPlatformGbID()); List<SendRtpItem> sendRtpItems = redisCatchStorage.querySendRTPServer(event.getPlatformGbID());
logger.info("停止[ {} ]的所有推流size", sendRtpItems.size()); logger.info("[ 平台未注册事件 ] 停止[ {} ]的所有推流size", sendRtpItems.size());
if (sendRtpItems != null && sendRtpItems.size() > 0) { if (sendRtpItems != null && sendRtpItems.size() > 0) {
logger.info("停止[ {} ]的所有推流", event.getPlatformGbID()); logger.info("[ 平台未注册事件 ] 停止[ {} ]的所有推流", event.getPlatformGbID());
StringBuilder app = new StringBuilder(); StringBuilder app = new StringBuilder();
StringBuilder stream = new StringBuilder(); StringBuilder stream = new StringBuilder();
for (SendRtpItem sendRtpItem : sendRtpItems) { for (SendRtpItem sendRtpItem : sendRtpItems) {
@ -91,13 +91,13 @@ public class PlatformNotRegisterEventLister implements ApplicationListener<Platf
SipSubscribe.Event okEvent = (responseEvent)->{ SipSubscribe.Event okEvent = (responseEvent)->{
timer.cancel(); timer.cancel();
}; };
logger.info("向平台注册,平台国标ID:" + event.getPlatformGbID()); logger.info("[平台注册]平台国标ID:" + event.getPlatformGbID());
sipCommanderFroPlatform.register(parentPlatform, null, okEvent); sipCommanderFroPlatform.register(parentPlatform, null, okEvent);
// 设置注册失败则每隔15秒发起一次注册 // 设置注册失败则每隔15秒发起一次注册
timer.schedule(new TimerTask() { timer.schedule(new TimerTask() {
@Override @Override
public void run() { public void run() {
logger.info("再次向平台注册,平台国标ID:" + event.getPlatformGbID()); logger.info("[平台注册]再次向平台注册,平台国标ID:" + event.getPlatformGbID());
sipCommanderFroPlatform.register(parentPlatform, null, okEvent); sipCommanderFroPlatform.register(parentPlatform, null, okEvent);
} }
}, config.getRegisterTimeInterval()* 1000, config.getRegisterTimeInterval()* 1000);//十五秒后再次发起注册 }, config.getRegisterTimeInterval()* 1000, config.getRegisterTimeInterval()* 1000);//十五秒后再次发起注册

14
src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java

@ -7,6 +7,7 @@ import javax.sip.ClientTransaction;
import javax.sip.Dialog; import javax.sip.Dialog;
import com.genersoft.iot.vmp.common.VideoManagerConstants; import com.genersoft.iot.vmp.common.VideoManagerConstants;
import com.genersoft.iot.vmp.conf.UserSetup;
import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction; import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction;
import com.genersoft.iot.vmp.utils.SerializeUtils; import com.genersoft.iot.vmp.utils.SerializeUtils;
import com.genersoft.iot.vmp.utils.redis.RedisUtil; import com.genersoft.iot.vmp.utils.redis.RedisUtil;
@ -25,6 +26,9 @@ public class VideoStreamSessionManager {
@Autowired @Autowired
private RedisUtil redisUtil; private RedisUtil redisUtil;
@Autowired
private UserSetup userSetup;
public void put(String deviceId, String channelId ,String ssrc, String streamId, String mediaServerId, ClientTransaction transaction){ public void put(String deviceId, String channelId ,String ssrc, String streamId, String mediaServerId, ClientTransaction transaction){
SsrcTransaction ssrcTransaction = new SsrcTransaction(); SsrcTransaction ssrcTransaction = new SsrcTransaction();
ssrcTransaction.setDeviceId(deviceId); ssrcTransaction.setDeviceId(deviceId);
@ -35,7 +39,7 @@ public class VideoStreamSessionManager {
ssrcTransaction.setSsrc(ssrc); ssrcTransaction.setSsrc(ssrc);
ssrcTransaction.setMediaServerId(mediaServerId); ssrcTransaction.setMediaServerId(mediaServerId);
redisUtil.set(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + deviceId + "_" + channelId, ssrcTransaction); redisUtil.set(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetup.getServerId() + "_" + deviceId + "_" + channelId, ssrcTransaction);
} }
public void put(String deviceId, String channelId , Dialog dialog){ public void put(String deviceId, String channelId , Dialog dialog){
@ -44,7 +48,7 @@ public class VideoStreamSessionManager {
byte[] dialogByteArray = SerializeUtils.serialize(dialog); byte[] dialogByteArray = SerializeUtils.serialize(dialog);
ssrcTransaction.setDialog(dialogByteArray); ssrcTransaction.setDialog(dialogByteArray);
} }
redisUtil.set(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + deviceId + "_" + channelId, ssrcTransaction); redisUtil.set(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetup.getServerId() + "_" + deviceId + "_" + channelId, ssrcTransaction);
} }
@ -66,7 +70,7 @@ public class VideoStreamSessionManager {
} }
public SsrcTransaction getSsrcTransaction(String deviceId, String channelId){ public SsrcTransaction getSsrcTransaction(String deviceId, String channelId){
SsrcTransaction ssrcTransaction = (SsrcTransaction)redisUtil.get(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + deviceId + "_" + channelId); SsrcTransaction ssrcTransaction = (SsrcTransaction)redisUtil.get(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetup.getServerId() + "_" + deviceId + "_" + channelId);
return ssrcTransaction; return ssrcTransaction;
} }
@ -90,11 +94,11 @@ public class VideoStreamSessionManager {
public void remove(String deviceId, String channelId) { public void remove(String deviceId, String channelId) {
SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId); SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId);
if (ssrcTransaction == null) return; if (ssrcTransaction == null) return;
redisUtil.del(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + deviceId + "_" + channelId); redisUtil.del(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetup.getServerId() + "_" + deviceId + "_" + channelId);
} }
public List<SsrcTransaction> getAllSsrc() { public List<SsrcTransaction> getAllSsrc() {
List<Object> ssrcTransactionKeys = redisUtil.scan(String.format("%s_*_*", VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX)); List<Object> ssrcTransactionKeys = redisUtil.scan(String.format("%s_*_*", VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX+ userSetup.getServerId() + "_" ));
List<SsrcTransaction> result= new ArrayList<>(); List<SsrcTransaction> result= new ArrayList<>();
for (int i = 0; i < ssrcTransactionKeys.size(); i++) { for (int i = 0; i < ssrcTransactionKeys.size(); i++) {
String key = (String)ssrcTransactionKeys.get(i); String key = (String)ssrcTransactionKeys.get(i);

1104
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/MessageRequestProcessor1.java

File diff suppressed because it is too large

7
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java

@ -1,6 +1,7 @@
package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl; package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
import com.genersoft.iot.vmp.common.VideoManagerConstants; import com.genersoft.iot.vmp.common.VideoManagerConstants;
import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.conf.UserSetup; import com.genersoft.iot.vmp.conf.UserSetup;
import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector;
@ -49,6 +50,9 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
@Autowired @Autowired
private IVideoManagerStorager storager; private IVideoManagerStorager storager;
@Autowired
private SipConfig sipConfig;
@Autowired @Autowired
private IRedisCatchStorage redisCatchStorage; private IRedisCatchStorage redisCatchStorage;
@ -156,6 +160,9 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
* @param evt * @param evt
*/ */
private void processNotifyAlarm(RequestEvent evt) { private void processNotifyAlarm(RequestEvent evt) {
if (!sipConfig.isAlarm()) {
return;
}
try { try {
Element rootElement = getRootElement(evt); Element rootElement = getRootElement(evt);
Element deviceIdElement = rootElement.element("DeviceID"); Element deviceIdElement = rootElement.element("DeviceID");

7
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java

@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd; package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd;
import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.conf.UserSetup; import com.genersoft.iot.vmp.conf.UserSetup;
import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector;
@ -38,6 +39,9 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme
@Autowired @Autowired
private UserSetup userSetup; private UserSetup userSetup;
@Autowired
private SipConfig sipConfig;
@Autowired @Autowired
private IVideoManagerStorager storager; private IVideoManagerStorager storager;
@ -54,6 +58,9 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme
@Override @Override
public void handForDevice(RequestEvent evt, Device device, Element rootElement) { public void handForDevice(RequestEvent evt, Device device, Element rootElement) {
if (!sipConfig.isAlarm()) {
return;
}
Element deviceIdElement = rootElement.element("DeviceID"); Element deviceIdElement = rootElement.element("DeviceID");
String channelId = deviceIdElement.getText().toString(); String channelId = deviceIdElement.getText().toString();
DeviceAlarm deviceAlarm = new DeviceAlarm(); DeviceAlarm deviceAlarm = new DeviceAlarm();

43
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java

@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.common.VideoManagerConstants; import com.genersoft.iot.vmp.common.VideoManagerConstants;
import com.genersoft.iot.vmp.conf.MediaConfig; import com.genersoft.iot.vmp.conf.MediaConfig;
import com.genersoft.iot.vmp.conf.SipConfig; import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.conf.UserSetup;
import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.session.SsrcConfig; import com.genersoft.iot.vmp.gb28181.session.SsrcConfig;
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
@ -52,7 +53,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
private Integer serverPort; private Integer serverPort;
@Autowired @Autowired
private MediaConfig mediaConfig; private UserSetup userSetup;
@Autowired @Autowired
private ZLMRESTfulUtils zlmresTfulUtils; private ZLMRESTfulUtils zlmresTfulUtils;
@ -89,10 +90,10 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
if (mediaServerItem.getSsrcConfig() == null) { if (mediaServerItem.getSsrcConfig() == null) {
SsrcConfig ssrcConfig = new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getDomain()); SsrcConfig ssrcConfig = new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getDomain());
mediaServerItem.setSsrcConfig(ssrcConfig); mediaServerItem.setSsrcConfig(ssrcConfig);
redisUtil.set(VideoManagerConstants.MEDIA_SERVER_PREFIX + mediaServerItem.getId(), mediaServerItem); redisUtil.set(VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + mediaServerItem.getId(), mediaServerItem);
} }
// 查询redis是否存在此mediaServer // 查询redis是否存在此mediaServer
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + mediaServerItem.getId(); String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + mediaServerItem.getId();
if (!redisUtil.hasKey(key)) { if (!redisUtil.hasKey(key)) {
redisUtil.set(key, mediaServerItem); redisUtil.set(key, mediaServerItem);
} }
@ -110,7 +111,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
return null; return null;
} }
// 获取mediaServer可用的ssrc // 获取mediaServer可用的ssrc
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + mediaServerItem.getId(); String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + mediaServerItem.getId();
SsrcConfig ssrcConfig = mediaServerItem.getSsrcConfig(); SsrcConfig ssrcConfig = mediaServerItem.getSsrcConfig();
if (ssrcConfig == null) { if (ssrcConfig == null) {
@ -156,7 +157,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
SsrcConfig ssrcConfig = mediaServerItem.getSsrcConfig(); SsrcConfig ssrcConfig = mediaServerItem.getSsrcConfig();
ssrcConfig.releaseSsrc(ssrc); ssrcConfig.releaseSsrc(ssrc);
mediaServerItem.setSsrcConfig(ssrcConfig); mediaServerItem.setSsrcConfig(ssrcConfig);
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + mediaServerItem.getId(); String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + mediaServerItem.getId();
redisUtil.set(key, mediaServerItem); redisUtil.set(key, mediaServerItem);
} }
@ -166,7 +167,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
@Override @Override
public void clearRTPServer(MediaServerItem mediaServerItem) { public void clearRTPServer(MediaServerItem mediaServerItem) {
mediaServerItem.setSsrcConfig(new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getDomain())); mediaServerItem.setSsrcConfig(new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getDomain()));
redisUtil.zAdd(VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX, mediaServerItem.getId(), 0); redisUtil.zAdd(VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId(), mediaServerItem.getId(), 0);
} }
@ -186,15 +187,15 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
) )
); );
} }
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + mediaServerItemInDataBase.getId(); String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + mediaServerItemInDataBase.getId();
redisUtil.set(key, mediaServerItemInDataBase); redisUtil.set(key, mediaServerItemInDataBase);
} }
@Override @Override
public List<MediaServerItem> getAll() { public List<MediaServerItem> getAll() {
List<MediaServerItem> result = new ArrayList<>(); List<MediaServerItem> result = new ArrayList<>();
List<Object> mediaServerKeys = redisUtil.scan(String.format("%S*", VideoManagerConstants.MEDIA_SERVER_PREFIX)); List<Object> mediaServerKeys = redisUtil.scan(String.format("%S*", VideoManagerConstants.MEDIA_SERVER_PREFIX+ userSetup.getServerId() + "_" ));
String onlineKey = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX; String onlineKey = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId();
for (Object mediaServerKey : mediaServerKeys) { for (Object mediaServerKey : mediaServerKeys) {
String key = (String) mediaServerKey; String key = (String) mediaServerKey;
MediaServerItem mediaServerItem = (MediaServerItem) redisUtil.get(key); MediaServerItem mediaServerItem = (MediaServerItem) redisUtil.get(key);
@ -224,12 +225,12 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
@Override @Override
public List<MediaServerItem> getAllOnline() { public List<MediaServerItem> getAllOnline() {
String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX; String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId();
Set<String> mediaServerIdSet = redisUtil.zRevRange(key, 0, -1); Set<String> mediaServerIdSet = redisUtil.zRevRange(key, 0, -1);
List<MediaServerItem> result = new ArrayList<>(); List<MediaServerItem> result = new ArrayList<>();
if (mediaServerIdSet != null && mediaServerIdSet.size() > 0) { if (mediaServerIdSet != null && mediaServerIdSet.size() > 0) {
for (String mediaServerId : mediaServerIdSet) { for (String mediaServerId : mediaServerIdSet) {
String serverKey = VideoManagerConstants.MEDIA_SERVER_PREFIX + mediaServerId; String serverKey = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + mediaServerId;
result.add((MediaServerItem) redisUtil.get(serverKey)); result.add((MediaServerItem) redisUtil.get(serverKey));
} }
} }
@ -246,7 +247,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
if (mediaServerId == null) { if (mediaServerId == null) {
return null; return null;
} }
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + mediaServerId; String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + mediaServerId;
return (MediaServerItem)redisUtil.get(key); return (MediaServerItem)redisUtil.get(key);
} }
@ -262,7 +263,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
@Override @Override
public void clearMediaServerForOnline() { public void clearMediaServerForOnline() {
String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX; String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId();
redisUtil.del(key); redisUtil.del(key);
} }
@ -324,10 +325,10 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
if (StringUtils.isEmpty(serverItem.getId())) { if (StringUtils.isEmpty(serverItem.getId())) {
serverItem.setId(zlmServerConfig.getGeneralMediaServerId()); serverItem.setId(zlmServerConfig.getGeneralMediaServerId());
} }
if (redisUtil.get(VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItem.getId()) == null) { if (redisUtil.get(VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + serverItem.getId()) == null) {
SsrcConfig ssrcConfig = new SsrcConfig(serverItem.getId(), null, sipConfig.getDomain()); SsrcConfig ssrcConfig = new SsrcConfig(serverItem.getId(), null, sipConfig.getDomain());
serverItem.setSsrcConfig(ssrcConfig); serverItem.setSsrcConfig(ssrcConfig);
redisUtil.set(VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItem.getId(), serverItem); redisUtil.set(VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + serverItem.getId(), serverItem);
} }
serverItem.setStatus(true); serverItem.setStatus(true);
@ -405,7 +406,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
@Override @Override
public void resetOnlineServerItem(MediaServerItem serverItem) { public void resetOnlineServerItem(MediaServerItem serverItem) {
// 更新缓存 // 更新缓存
String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX; String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId();
// 使用zset的分数作为当前并发量, 默认值设置为0 // 使用zset的分数作为当前并发量, 默认值设置为0
if (redisUtil.zScore(key, serverItem.getId()) == null) { // 不存在则设置默认值 已存在则重置 if (redisUtil.zScore(key, serverItem.getId()) == null) { // 不存在则设置默认值 已存在则重置
redisUtil.zAdd(key, serverItem.getId(), 0L); redisUtil.zAdd(key, serverItem.getId(), 0L);
@ -431,14 +432,14 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
if (mediaServerId == null) { if (mediaServerId == null) {
return; return;
} }
String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX; String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId();
redisUtil.zIncrScore(key, mediaServerId, 1); redisUtil.zIncrScore(key, mediaServerId, 1);
} }
@Override @Override
public void removeCount(String mediaServerId) { public void removeCount(String mediaServerId) {
String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX; String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId();
redisUtil.zIncrScore(key, mediaServerId, - 1); redisUtil.zIncrScore(key, mediaServerId, - 1);
} }
@ -448,7 +449,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
*/ */
@Override @Override
public MediaServerItem getMediaServerForMinimumLoad() { public MediaServerItem getMediaServerForMinimumLoad() {
String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX; String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId();
if (redisUtil.zSize(key) == null || redisUtil.zSize(key) == 0) { if (redisUtil.zSize(key) == null || redisUtil.zSize(key) == 0) {
logger.info("获取负载最低的节点时无在线节点"); logger.info("获取负载最低的节点时无在线节点");
@ -580,8 +581,8 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
@Override @Override
public void delete(String id) { public void delete(String id) {
redisUtil.zRemove(VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX, id); redisUtil.zRemove(VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId() + "_", id);
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + id; String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + id;
redisUtil.del(key); redisUtil.del(key);
mediaServerMapper.delOne(id); mediaServerMapper.delOne(id);
} }

2
src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java

@ -121,7 +121,7 @@ public interface IRedisCatchStorage {
/** /**
* 在redis添加wvp的信息 * 在redis添加wvp的信息
*/ */
void updateWVPInfo(String id, JSONObject jsonObject, int time); void updateWVPInfo(JSONObject jsonObject, int time);
/** /**
* 发送推流生成与推流消失消息 * 发送推流生成与推流消失消息

80
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java

@ -41,7 +41,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
*/ */
@Override @Override
public boolean startPlay(StreamInfo stream) { public boolean startPlay(StreamInfo stream) {
return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, stream.getStreamId(),stream.getDeviceID(), stream.getChannelId()), return redis.set(String.format("%S_%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, userSetup.getServerId(), stream.getStreamId(),stream.getDeviceID(), stream.getChannelId()),
stream); stream);
} }
@ -53,7 +53,8 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override @Override
public boolean stopPlay(StreamInfo streamInfo) { public boolean stopPlay(StreamInfo streamInfo) {
if (streamInfo == null) return false; if (streamInfo == null) return false;
return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, return redis.del(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
userSetup.getServerId(),
streamInfo.getStreamId(), streamInfo.getStreamId(),
streamInfo.getDeviceID(), streamInfo.getDeviceID(),
streamInfo.getChannelId())); streamInfo.getChannelId()));
@ -65,22 +66,23 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
*/ */
@Override @Override
public StreamInfo queryPlay(StreamInfo streamInfo) { public StreamInfo queryPlay(StreamInfo streamInfo) {
return (StreamInfo)redis.get(String.format("%S_%s_%s_%s", return (StreamInfo)redis.get(String.format("%S_%s_%s_%s_%s",
VideoManagerConstants.PLAYER_PREFIX, VideoManagerConstants.PLAYER_PREFIX,
userSetup.getServerId(),
streamInfo.getStreamId(), streamInfo.getStreamId(),
streamInfo.getDeviceID(), streamInfo.getDeviceID(),
streamInfo.getChannelId())); streamInfo.getChannelId()));
} }
@Override @Override
public StreamInfo queryPlayByStreamId(String streamId) { public StreamInfo queryPlayByStreamId(String streamId) {
List<Object> playLeys = redis.scan(String.format("%S_%s_*", VideoManagerConstants.PLAYER_PREFIX, streamId)); List<Object> playLeys = redis.scan(String.format("%S_%s_%s_*", VideoManagerConstants.PLAYER_PREFIX, userSetup.getServerId(), streamId));
if (playLeys == null || playLeys.size() == 0) return null; if (playLeys == null || playLeys.size() == 0) return null;
return (StreamInfo)redis.get(playLeys.get(0).toString()); return (StreamInfo)redis.get(playLeys.get(0).toString());
} }
@Override @Override
public StreamInfo queryPlaybackByStreamId(String streamId) { public StreamInfo queryPlaybackByStreamId(String streamId) {
List<Object> playLeys = redis.scan(String.format("%S_%s_*", VideoManagerConstants.PLAY_BLACK_PREFIX, streamId)); List<Object> playLeys = redis.scan(String.format("%S_%s_%s_*", VideoManagerConstants.PLAY_BLACK_PREFIX, userSetup.getServerId(), streamId));
if (playLeys == null || playLeys.size() == 0) return null; if (playLeys == null || playLeys.size() == 0) return null;
return (StreamInfo)redis.get(playLeys.get(0).toString()); return (StreamInfo)redis.get(playLeys.get(0).toString());
} }
@ -88,7 +90,8 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override @Override
public StreamInfo queryPlayByDevice(String deviceId, String channelId) { public StreamInfo queryPlayByDevice(String deviceId, String channelId) {
// List<Object> playLeys = redis.keys(String.format("%S_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX, // List<Object> playLeys = redis.keys(String.format("%S_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
List<Object> playLeys = redis.scan(String.format("%S_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX, List<Object> playLeys = redis.scan(String.format("%S_%s_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
userSetup.getServerId(),
deviceId, deviceId,
channelId)); channelId));
if (playLeys == null || playLeys.size() == 0) return null; if (playLeys == null || playLeys.size() == 0) return null;
@ -99,7 +102,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
public Map<String, StreamInfo> queryPlayByDeviceId(String deviceId) { public Map<String, StreamInfo> queryPlayByDeviceId(String deviceId) {
Map<String, StreamInfo> streamInfos = new HashMap<>(); Map<String, StreamInfo> streamInfos = new HashMap<>();
// List<Object> playLeys = redis.keys(String.format("%S_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, deviceId)); // List<Object> playLeys = redis.keys(String.format("%S_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, deviceId));
List<Object> players = redis.scan(String.format("%S_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, deviceId)); List<Object> players = redis.scan(String.format("%S_%s_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, userSetup.getServerId(),deviceId));
if (players.size() == 0) return streamInfos; if (players.size() == 0) return streamInfos;
for (int i = 0; i < players.size(); i++) { for (int i = 0; i < players.size(); i++) {
String key = (String) players.get(i); String key = (String) players.get(i);
@ -112,13 +115,13 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override @Override
public boolean startPlayback(StreamInfo stream) { public boolean startPlayback(StreamInfo stream) {
return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, stream.getStreamId(), return redis.set(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, userSetup.getServerId(),stream.getStreamId(),
stream.getDeviceID(), stream.getChannelId()), stream); stream.getDeviceID(), stream.getChannelId()), stream);
} }
@Override @Override
public boolean startDownload(StreamInfo streamInfo) { public boolean startDownload(StreamInfo streamInfo) {
return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX, streamInfo.getStreamId(), return redis.set(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX, userSetup.getServerId(),streamInfo.getStreamId(),
streamInfo.getDeviceID(), streamInfo.getChannelId()), streamInfo); streamInfo.getDeviceID(), streamInfo.getChannelId()), streamInfo);
} }
@ -131,7 +134,8 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
deviceChannel.setDeviceId(streamInfo.getDeviceID()); deviceChannel.setDeviceId(streamInfo.getDeviceID());
deviceChannelMapper.update(deviceChannel); deviceChannelMapper.update(deviceChannel);
} }
return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, return redis.del(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
userSetup.getServerId(),
streamInfo.getStreamId(), streamInfo.getStreamId(),
streamInfo.getDeviceID(), streamInfo.getDeviceID(),
streamInfo.getChannelId())); streamInfo.getChannelId()));
@ -142,11 +146,13 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
// String format = String.format("%S_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, // String format = String.format("%S_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
// deviceId, // deviceId,
// code); // code);
List<Object> playLeys = redis.scan(String.format("%S_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, List<Object> playLeys = redis.scan(String.format("%S_%s_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
userSetup.getServerId(),
deviceId, deviceId,
code)); code));
if (playLeys == null || playLeys.size() == 0) { if (playLeys == null || playLeys.size() == 0) {
playLeys = redis.scan(String.format("%S_*_*_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, playLeys = redis.scan(String.format("%S_%s_*_*_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
userSetup.getServerId(),
deviceId)); deviceId));
} }
if (playLeys == null || playLeys.size() == 0) return null; if (playLeys == null || playLeys.size() == 0) return null;
@ -155,63 +161,63 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override @Override
public void updatePlatformCatchInfo(ParentPlatformCatch parentPlatformCatch) { public void updatePlatformCatchInfo(ParentPlatformCatch parentPlatformCatch) {
String key = VideoManagerConstants.PLATFORM_CATCH_PREFIX + parentPlatformCatch.getId(); String key = VideoManagerConstants.PLATFORM_CATCH_PREFIX + userSetup.getServerId() + "_" + parentPlatformCatch.getId();
redis.set(key, parentPlatformCatch); redis.set(key, parentPlatformCatch);
} }
@Override @Override
public void updatePlatformKeepalive(ParentPlatform parentPlatform) { public void updatePlatformKeepalive(ParentPlatform parentPlatform) {
String key = VideoManagerConstants.PLATFORM_KEEPLIVEKEY_PREFIX + parentPlatform.getServerGBId(); String key = VideoManagerConstants.PLATFORM_KEEPALIVE_PREFIX + userSetup.getServerId() + "_" + parentPlatform.getServerGBId();
redis.set(key, "", Integer.parseInt(parentPlatform.getKeepTimeout())); redis.set(key, "", Integer.parseInt(parentPlatform.getKeepTimeout()));
} }
@Override @Override
public void updatePlatformRegister(ParentPlatform parentPlatform) { public void updatePlatformRegister(ParentPlatform parentPlatform) {
String key = VideoManagerConstants.PLATFORM_REGISTER_PREFIX + parentPlatform.getServerGBId(); String key = VideoManagerConstants.PLATFORM_REGISTER_PREFIX + userSetup.getServerId() + "_" + parentPlatform.getServerGBId();
redis.set(key, "", Integer.parseInt(parentPlatform.getExpires())); redis.set(key, "", Integer.parseInt(parentPlatform.getExpires()));
} }
@Override @Override
public ParentPlatformCatch queryPlatformCatchInfo(String platformGbId) { public ParentPlatformCatch queryPlatformCatchInfo(String platformGbId) {
return (ParentPlatformCatch)redis.get(VideoManagerConstants.PLATFORM_CATCH_PREFIX + platformGbId); return (ParentPlatformCatch)redis.get(VideoManagerConstants.PLATFORM_CATCH_PREFIX + userSetup.getServerId() + "_" + platformGbId);
} }
@Override @Override
public void delPlatformCatchInfo(String platformGbId) { public void delPlatformCatchInfo(String platformGbId) {
redis.del(VideoManagerConstants.PLATFORM_CATCH_PREFIX + platformGbId); redis.del(VideoManagerConstants.PLATFORM_CATCH_PREFIX + userSetup.getServerId() + "_" + platformGbId);
} }
@Override @Override
public void delPlatformKeepalive(String platformGbId) { public void delPlatformKeepalive(String platformGbId) {
redis.del(VideoManagerConstants.PLATFORM_KEEPLIVEKEY_PREFIX + platformGbId); redis.del(VideoManagerConstants.PLATFORM_KEEPALIVE_PREFIX + userSetup.getServerId() + "_" + platformGbId);
} }
@Override @Override
public void delPlatformRegister(String platformGbId) { public void delPlatformRegister(String platformGbId) {
redis.del(VideoManagerConstants.PLATFORM_REGISTER_PREFIX + platformGbId); redis.del(VideoManagerConstants.PLATFORM_REGISTER_PREFIX + userSetup.getServerId() + "_" + platformGbId);
} }
@Override @Override
public void updatePlatformRegisterInfo(String callId, String platformGbId) { public void updatePlatformRegisterInfo(String callId, String platformGbId) {
String key = VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + callId; String key = VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetup.getServerId() + "_" + callId;
redis.set(key, platformGbId); redis.set(key, platformGbId);
} }
@Override @Override
public String queryPlatformRegisterInfo(String callId) { public String queryPlatformRegisterInfo(String callId) {
return (String)redis.get(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + callId); return (String)redis.get(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetup.getServerId() + "_" + callId);
} }
@Override @Override
public void delPlatformRegisterInfo(String callId) { public void delPlatformRegisterInfo(String callId) {
redis.del(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + callId); redis.del(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetup.getServerId() + "_" + callId);
} }
@Override @Override
public void cleanPlatformRegisterInfos() { public void cleanPlatformRegisterInfos() {
List regInfos = redis.scan(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + "*"); List regInfos = redis.scan(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetup.getServerId() + "_" + "*");
for (Object key : regInfos) { for (Object key : regInfos) {
redis.del(key.toString()); redis.del(key.toString());
} }
@ -219,19 +225,19 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override @Override
public void updateSendRTPSever(SendRtpItem sendRtpItem) { public void updateSendRTPSever(SendRtpItem sendRtpItem) {
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + sendRtpItem.getPlatformId() + "_" + sendRtpItem.getChannelId(); String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + sendRtpItem.getPlatformId() + "_" + sendRtpItem.getChannelId();
redis.set(key, sendRtpItem); redis.set(key, sendRtpItem);
} }
@Override @Override
public SendRtpItem querySendRTPServer(String platformGbId, String channelId) { public SendRtpItem querySendRTPServer(String platformGbId, String channelId) {
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + platformGbId + "_" + channelId; String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + platformGbId + "_" + channelId;
return (SendRtpItem)redis.get(key); return (SendRtpItem)redis.get(key);
} }
@Override @Override
public List<SendRtpItem> querySendRTPServer(String platformGbId) { public List<SendRtpItem> querySendRTPServer(String platformGbId) {
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + platformGbId + "_*"; String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + platformGbId + "_*";
List<Object> queryResult = redis.scan(key); List<Object> queryResult = redis.scan(key);
List<SendRtpItem> result= new ArrayList<>(); List<SendRtpItem> result= new ArrayList<>();
@ -250,7 +256,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
*/ */
@Override @Override
public void deleteSendRTPServer(String platformGbId, String channelId) { public void deleteSendRTPServer(String platformGbId, String channelId) {
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + platformGbId + "_" + channelId; String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + platformGbId + "_" + channelId;
redis.del(key); redis.del(key);
} }
@ -260,7 +266,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
*/ */
@Override @Override
public boolean isChannelSendingRTP(String channelId) { public boolean isChannelSendingRTP(String channelId) {
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + "*_" + channelId; String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + "*_" + channelId;
List<Object> RtpStreams = redis.scan(key); List<Object> RtpStreams = redis.scan(key);
if (RtpStreams.size() > 0) { if (RtpStreams.size() > 0) {
return true; return true;
@ -271,7 +277,8 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override @Override
public void clearCatchByDeviceId(String deviceId) { public void clearCatchByDeviceId(String deviceId) {
List<Object> playLeys = redis.scan(String.format("%S_*_%s_*", VideoManagerConstants.PLAYER_PREFIX, List<Object> playLeys = redis.scan(String.format("%S_%s_*_%s_*", VideoManagerConstants.PLAYER_PREFIX,
userSetup.getServerId(),
deviceId)); deviceId));
if (playLeys.size() > 0) { if (playLeys.size() > 0) {
for (Object key : playLeys) { for (Object key : playLeys) {
@ -279,7 +286,8 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
} }
} }
List<Object> playBackers = redis.scan(String.format("%S_*_%s_*", VideoManagerConstants.PLAY_BLACK_PREFIX, List<Object> playBackers = redis.scan(String.format("%S_%s_*_%s_*", VideoManagerConstants.PLAY_BLACK_PREFIX,
userSetup.getServerId(),
deviceId)); deviceId));
if (playBackers.size() > 0) { if (playBackers.size() > 0) {
for (Object key : playBackers) { for (Object key : playBackers) {
@ -290,7 +298,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override @Override
public void outlineForAll() { public void outlineForAll() {
List<Object> onlineDevices = redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX + "*" ); List<Object> onlineDevices = redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetup.getServerId() + "_" + "*" );
for (int i = 0; i < onlineDevices.size(); i++) { for (int i = 0; i < onlineDevices.size(); i++) {
String key = (String) onlineDevices.get(i); String key = (String) onlineDevices.get(i);
redis.del(key); redis.del(key);
@ -300,7 +308,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override @Override
public List<String> getOnlineForAll() { public List<String> getOnlineForAll() {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
List<Object> onlineDevices = redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX + "*" ); List<Object> onlineDevices = redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetup.getServerId() + "_" + "*" );
for (int i = 0; i < onlineDevices.size(); i++) { for (int i = 0; i < onlineDevices.size(); i++) {
String key = (String) onlineDevices.get(i); String key = (String) onlineDevices.get(i);
result.add((String) redis.get(key)); result.add((String) redis.get(key));
@ -309,14 +317,14 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
} }
@Override @Override
public void updateWVPInfo(String id, JSONObject jsonObject, int time) { public void updateWVPInfo(JSONObject jsonObject, int time) {
String key = VideoManagerConstants.WVP_SERVER_PREFIX + id; String key = VideoManagerConstants.WVP_SERVER_PREFIX + userSetup.getServerId();
redis.set(key, jsonObject, time); redis.set(key, jsonObject, time);
} }
@Override @Override
public void sendStreamChangeMsg(String type, JSONObject jsonObject) { public void sendStreamChangeMsg(String type, JSONObject jsonObject) {
String key = VideoManagerConstants.WVP_MSG_STREAM_PUSH_CHANGE_PREFIX + type; String key = VideoManagerConstants.WVP_MSG_STREAM_CHANGE__PREFIX + type;
logger.debug("[redis 流变化事件] {}: {}", key, jsonObject.toString()); logger.debug("[redis 流变化事件] {}: {}", key, jsonObject.toString());
redis.convertAndSend(key, jsonObject); redis.convertAndSend(key, jsonObject);
} }
@ -338,7 +346,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override @Override
public StreamInfo queryDownloadByStreamId(String streamId) { public StreamInfo queryDownloadByStreamId(String streamId) {
List<Object> playLeys = redis.scan(String.format("%S_%s_*", VideoManagerConstants.DOWNLOAD_PREFIX, streamId)); List<Object> playLeys = redis.scan(String.format("%S_%s_%s_*", VideoManagerConstants.DOWNLOAD_PREFIX, userSetup.getServerId(), streamId));
if (playLeys == null || playLeys.size() == 0) return null; if (playLeys == null || playLeys.size() == 0) return null;
return (StreamInfo)redis.get(playLeys.get(0).toString()); return (StreamInfo)redis.get(playLeys.get(0).toString());
} }

4
src/main/resources/all-application.yml

@ -80,6 +80,8 @@ sip:
ptz-speed: 50 ptz-speed: 50
# TODO [可选] 收到心跳后自动上线, 重启服务后会将所有设备置为离线,默认false,等待注册后上线。设置为true则收到心跳设置为上线。 # TODO [可选] 收到心跳后自动上线, 重启服务后会将所有设备置为离线,默认false,等待注册后上线。设置为true则收到心跳设置为上线。
# keepalliveToOnline: false # keepalliveToOnline: false
# 是否存储alarm信息
alarm: false
#zlm 默认服务器配置 #zlm 默认服务器配置
media: media:
@ -134,7 +136,7 @@ logging:
level: level:
com.genersoft.iot: debug com.genersoft.iot: debug
com.genersoft.iot.vmp.storager.dao: info com.genersoft.iot.vmp.storager.dao: info
com.genersoft.iot.vmp.gb28181: info com.genersoft.iot.vmp.gb28181: debug
# [根据业务需求配置] # [根据业务需求配置]
user-settings: user-settings:
# [可选] 服务ID,不写则为000000 # [可选] 服务ID,不写则为000000

Loading…
Cancel
Save