Commit 241804f5f832c76d8855011ceea713eee4cbf15a
1 parent
42d8fff5
优化redis存储,alarm默认关闭处理
Showing
18 changed files
with
160 additions
and
1199 deletions
pom.xml
| @@ -204,6 +204,11 @@ | @@ -204,6 +204,11 @@ | ||
| 204 | <version>1.12</version> | 204 | <version>1.12</version> |
| 205 | </dependency> | 205 | </dependency> |
| 206 | 206 | ||
| 207 | + <dependency> | ||
| 208 | + <groupId>org.springframework.session</groupId> | ||
| 209 | + <artifactId>spring-session-core</artifactId> | ||
| 210 | + </dependency> | ||
| 211 | + | ||
| 207 | <!-- <!– 检测文件编码 –>--> | 212 | <!-- <!– 检测文件编码 –>--> |
| 208 | <!-- <!– https://mvnrepository.com/artifact/cpdetector/cpdetector –>--> | 213 | <!-- <!– https://mvnrepository.com/artifact/cpdetector/cpdetector –>--> |
| 209 | <!-- <dependency>--> | 214 | <!-- <dependency>--> |
src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java
| @@ -14,7 +14,7 @@ public class VideoManagerConstants { | @@ -14,7 +14,7 @@ public class VideoManagerConstants { | ||
| 14 | 14 | ||
| 15 | public static final String MEDIA_SERVER_PREFIX = "VMP_MEDIA_SERVER_"; | 15 | public static final String MEDIA_SERVER_PREFIX = "VMP_MEDIA_SERVER_"; |
| 16 | 16 | ||
| 17 | - public static final String MEDIA_SERVERS_ONLINE_PREFIX = "VMP_MEDIA_ONLINE_SERVERS"; | 17 | + public static final String MEDIA_SERVERS_ONLINE_PREFIX = "VMP_MEDIA_ONLINE_SERVERS_"; |
| 18 | 18 | ||
| 19 | public static final String MEDIA_STREAM_PREFIX = "VMP_MEDIA_STREAM"; | 19 | public static final String MEDIA_STREAM_PREFIX = "VMP_MEDIA_STREAM"; |
| 20 | 20 | ||
| @@ -22,14 +22,15 @@ public class VideoManagerConstants { | @@ -22,14 +22,15 @@ public class VideoManagerConstants { | ||
| 22 | 22 | ||
| 23 | public static final String CACHEKEY_PREFIX = "VMP_CHANNEL_"; | 23 | public static final String CACHEKEY_PREFIX = "VMP_CHANNEL_"; |
| 24 | 24 | ||
| 25 | - public static final String KEEPLIVEKEY_PREFIX = "VMP_keeplive_"; | 25 | + public static final String KEEPLIVEKEY_PREFIX = "VMP_KEEPALIVE_"; |
| 26 | 26 | ||
| 27 | + // 此处多了一个_,暂不修改 | ||
| 27 | public static final String PLAYER_PREFIX = "VMP_PLAYER_"; | 28 | public static final String PLAYER_PREFIX = "VMP_PLAYER_"; |
| 28 | - | ||
| 29 | public static final String PLAY_BLACK_PREFIX = "VMP_PLAYBACK_"; | 29 | public static final String PLAY_BLACK_PREFIX = "VMP_PLAYBACK_"; |
| 30 | + | ||
| 30 | public static final String DOWNLOAD_PREFIX = "VMP_DOWNLOAD_"; | 31 | public static final String DOWNLOAD_PREFIX = "VMP_DOWNLOAD_"; |
| 31 | 32 | ||
| 32 | - public static final String PLATFORM_KEEPLIVEKEY_PREFIX = "VMP_PLATFORM_KEEPLIVE_"; | 33 | + public static final String PLATFORM_KEEPALIVE_PREFIX = "VMP_PLATFORM_KEEPALIVE_"; |
| 33 | 34 | ||
| 34 | public static final String PLATFORM_CATCH_PREFIX = "VMP_PLATFORM_CATCH_"; | 35 | public static final String PLATFORM_CATCH_PREFIX = "VMP_PLATFORM_CATCH_"; |
| 35 | 36 | ||
| @@ -39,8 +40,6 @@ public class VideoManagerConstants { | @@ -39,8 +40,6 @@ public class VideoManagerConstants { | ||
| 39 | 40 | ||
| 40 | public static final String PLATFORM_SEND_RTP_INFO_PREFIX = "VMP_PLATFORM_SEND_RTP_INFO_"; | 41 | public static final String PLATFORM_SEND_RTP_INFO_PREFIX = "VMP_PLATFORM_SEND_RTP_INFO_"; |
| 41 | 42 | ||
| 42 | - public static final String Pattern_Topic = "VMP_KEEPLIVE_PLATFORM_"; | ||
| 43 | - | ||
| 44 | public static final String EVENT_ONLINE_REGISTER = "1"; | 43 | public static final String EVENT_ONLINE_REGISTER = "1"; |
| 45 | 44 | ||
| 46 | public static final String EVENT_ONLINE_KEEPLIVE = "2"; | 45 | public static final String EVENT_ONLINE_KEEPLIVE = "2"; |
| @@ -51,10 +50,10 @@ public class VideoManagerConstants { | @@ -51,10 +50,10 @@ public class VideoManagerConstants { | ||
| 51 | 50 | ||
| 52 | public static final String EVENT_OUTLINE_TIMEOUT = "2"; | 51 | public static final String EVENT_OUTLINE_TIMEOUT = "2"; |
| 53 | 52 | ||
| 54 | - public static final String MEDIA_SSRC_USED_PREFIX = "VMP_media_used_ssrc_"; | 53 | + public static final String MEDIA_SSRC_USED_PREFIX = "VMP_MEDIA_USED_SSRC_"; |
| 55 | 54 | ||
| 56 | - public static final String MEDIA_TRANSACTION_USED_PREFIX = "VMP_media_transaction_"; | 55 | + public static final String MEDIA_TRANSACTION_USED_PREFIX = "VMP_MEDIA_TRANSACTION_"; |
| 57 | 56 | ||
| 58 | //************************** redis 消息********************************* | 57 | //************************** redis 消息********************************* |
| 59 | - public static final String WVP_MSG_STREAM_PUSH_CHANGE_PREFIX = "WVP_MSG_STREAM_CHANGE_"; | 58 | + public static final String WVP_MSG_STREAM_CHANGE__PREFIX = "WVP_MSG_STREAM_CHANGE_"; |
| 60 | } | 59 | } |
src/main/java/com/genersoft/iot/vmp/conf/SipConfig.java
| @@ -29,6 +29,8 @@ public class SipConfig { | @@ -29,6 +29,8 @@ public class SipConfig { | ||
| 29 | 29 | ||
| 30 | Integer registerTimeInterval = 60; | 30 | Integer registerTimeInterval = 60; |
| 31 | 31 | ||
| 32 | + private boolean alarm = false; | ||
| 33 | + | ||
| 32 | public void setIp(String ip) { | 34 | public void setIp(String ip) { |
| 33 | this.ip = ip; | 35 | this.ip = ip; |
| 34 | } | 36 | } |
| @@ -104,4 +106,12 @@ public class SipConfig { | @@ -104,4 +106,12 @@ public class SipConfig { | ||
| 104 | public Integer getRegisterTimeInterval() { | 106 | public Integer getRegisterTimeInterval() { |
| 105 | return registerTimeInterval; | 107 | return registerTimeInterval; |
| 106 | } | 108 | } |
| 109 | + | ||
| 110 | + public boolean isAlarm() { | ||
| 111 | + return alarm; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + public void setAlarm(boolean alarm) { | ||
| 115 | + this.alarm = alarm; | ||
| 116 | + } | ||
| 107 | } | 117 | } |
src/main/java/com/genersoft/iot/vmp/conf/WVPTimerTask.java
| @@ -17,9 +17,6 @@ public class WVPTimerTask { | @@ -17,9 +17,6 @@ public class WVPTimerTask { | ||
| 17 | @Autowired | 17 | @Autowired |
| 18 | private IMediaServerService mediaServerService; | 18 | private IMediaServerService mediaServerService; |
| 19 | 19 | ||
| 20 | - @Autowired | ||
| 21 | - private UserSetup userSetup; | ||
| 22 | - | ||
| 23 | @Value("${server.port}") | 20 | @Value("${server.port}") |
| 24 | private int serverPort; | 21 | private int serverPort; |
| 25 | 22 | ||
| @@ -31,6 +28,6 @@ public class WVPTimerTask { | @@ -31,6 +28,6 @@ public class WVPTimerTask { | ||
| 31 | JSONObject jsonObject = new JSONObject(); | 28 | JSONObject jsonObject = new JSONObject(); |
| 32 | jsonObject.put("ip", sipConfig.getIp()); | 29 | jsonObject.put("ip", sipConfig.getIp()); |
| 33 | jsonObject.put("port", serverPort); | 30 | jsonObject.put("port", serverPort); |
| 34 | - redisCatchStorage.updateWVPInfo(userSetup.getServerId(), jsonObject, 3); | 31 | + redisCatchStorage.updateWVPInfo(jsonObject, 3); |
| 35 | } | 32 | } |
| 36 | } | 33 | } |
src/main/java/com/genersoft/iot/vmp/gb28181/event/DeviceOffLineDetector.java
| 1 | package com.genersoft.iot.vmp.gb28181.event; | 1 | package com.genersoft.iot.vmp.gb28181.event; |
| 2 | 2 | ||
| 3 | +import com.genersoft.iot.vmp.conf.UserSetup; | ||
| 3 | import org.springframework.beans.factory.annotation.Autowired; | 4 | import org.springframework.beans.factory.annotation.Autowired; |
| 4 | import org.springframework.stereotype.Component; | 5 | import org.springframework.stereotype.Component; |
| 5 | 6 | ||
| @@ -16,9 +17,12 @@ public class DeviceOffLineDetector { | @@ -16,9 +17,12 @@ public class DeviceOffLineDetector { | ||
| 16 | 17 | ||
| 17 | @Autowired | 18 | @Autowired |
| 18 | private RedisUtil redis; | 19 | private RedisUtil redis; |
| 20 | + | ||
| 21 | + @Autowired | ||
| 22 | + private UserSetup userSetup; | ||
| 19 | 23 | ||
| 20 | public boolean isOnline(String deviceId) { | 24 | public boolean isOnline(String deviceId) { |
| 21 | - String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + deviceId; | 25 | + String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetup.getServerId() + "_" + deviceId; |
| 22 | return redis.hasKey(key); | 26 | return redis.hasKey(key); |
| 23 | } | 27 | } |
| 24 | } | 28 | } |
src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java
| 1 | package com.genersoft.iot.vmp.gb28181.event.offline; | 1 | package com.genersoft.iot.vmp.gb28181.event.offline; |
| 2 | 2 | ||
| 3 | +import com.genersoft.iot.vmp.conf.UserSetup; | ||
| 3 | import org.slf4j.Logger; | 4 | import org.slf4j.Logger; |
| 4 | import org.slf4j.LoggerFactory; | 5 | import org.slf4j.LoggerFactory; |
| 5 | import org.springframework.beans.factory.annotation.Autowired; | 6 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -24,6 +25,9 @@ public class KeepaliveTimeoutListenerForPlatform extends KeyExpirationEventMessa | @@ -24,6 +25,9 @@ public class KeepaliveTimeoutListenerForPlatform extends KeyExpirationEventMessa | ||
| 24 | @Autowired | 25 | @Autowired |
| 25 | private EventPublisher publisher; | 26 | private EventPublisher publisher; |
| 26 | 27 | ||
| 28 | + @Autowired | ||
| 29 | + private UserSetup userSetup; | ||
| 30 | + | ||
| 27 | public KeepaliveTimeoutListenerForPlatform(RedisMessageListenerContainer listenerContainer) { | 31 | public KeepaliveTimeoutListenerForPlatform(RedisMessageListenerContainer listenerContainer) { |
| 28 | super(listenerContainer); | 32 | super(listenerContainer); |
| 29 | } | 33 | } |
| @@ -40,17 +44,20 @@ public class KeepaliveTimeoutListenerForPlatform extends KeyExpirationEventMessa | @@ -40,17 +44,20 @@ public class KeepaliveTimeoutListenerForPlatform extends KeyExpirationEventMessa | ||
| 40 | String expiredKey = message.toString(); | 44 | String expiredKey = message.toString(); |
| 41 | logger.debug(expiredKey); | 45 | logger.debug(expiredKey); |
| 42 | // 平台心跳到期,需要重发, 判断是否已经多次未收到心跳回复, 多次未收到,则重新发起注册, 注册尝试多次未得到回复,则认为平台离线 | 46 | // 平台心跳到期,需要重发, 判断是否已经多次未收到心跳回复, 多次未收到,则重新发起注册, 注册尝试多次未得到回复,则认为平台离线 |
| 43 | - if (expiredKey.startsWith(VideoManagerConstants.PLATFORM_KEEPLIVEKEY_PREFIX)) { | ||
| 44 | - String platformGBId = expiredKey.substring(VideoManagerConstants.PLATFORM_KEEPLIVEKEY_PREFIX.length(),expiredKey.length()); | 47 | + String PLATFORM_KEEPLIVEKEY_PREFIX = VideoManagerConstants.PLATFORM_KEEPALIVE_PREFIX + userSetup.getServerId() + "_"; |
| 48 | + String PLATFORM_REGISTER_PREFIX = VideoManagerConstants.PLATFORM_REGISTER_PREFIX + userSetup.getServerId() + "_"; | ||
| 49 | + String KEEPLIVEKEY_PREFIX = VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetup.getServerId() + "_"; | ||
| 50 | + if (expiredKey.startsWith(PLATFORM_KEEPLIVEKEY_PREFIX)) { | ||
| 51 | + String platformGBId = expiredKey.substring(PLATFORM_KEEPLIVEKEY_PREFIX.length(),expiredKey.length()); | ||
| 45 | 52 | ||
| 46 | publisher.platformKeepaliveExpireEventPublish(platformGBId); | 53 | publisher.platformKeepaliveExpireEventPublish(platformGBId); |
| 47 | - }else if (expiredKey.startsWith(VideoManagerConstants.PLATFORM_REGISTER_PREFIX)) { | ||
| 48 | - String platformGBId = expiredKey.substring(VideoManagerConstants.PLATFORM_REGISTER_PREFIX.length(),expiredKey.length()); | 54 | + }else if (expiredKey.startsWith(PLATFORM_REGISTER_PREFIX)) { |
| 55 | + String platformGBId = expiredKey.substring(PLATFORM_REGISTER_PREFIX.length(),expiredKey.length()); | ||
| 49 | 56 | ||
| 50 | publisher.platformNotRegisterEventPublish(platformGBId); | 57 | publisher.platformNotRegisterEventPublish(platformGBId); |
| 51 | }else{ | 58 | }else{ |
| 52 | - String deviceId = expiredKey.substring(VideoManagerConstants.KEEPLIVEKEY_PREFIX.length(),expiredKey.length()); | ||
| 53 | - publisher.outlineEventPublish(deviceId, VideoManagerConstants.EVENT_OUTLINE_TIMEOUT); | 59 | + String deviceId = expiredKey.substring(KEEPLIVEKEY_PREFIX.length(),expiredKey.length()); |
| 60 | + publisher.outlineEventPublish(deviceId, KEEPLIVEKEY_PREFIX); | ||
| 54 | } | 61 | } |
| 55 | 62 | ||
| 56 | } | 63 | } |
src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepliveTimeoutListener.java
| 1 | package com.genersoft.iot.vmp.gb28181.event.offline; | 1 | package com.genersoft.iot.vmp.gb28181.event.offline; |
| 2 | 2 | ||
| 3 | +import com.genersoft.iot.vmp.conf.UserSetup; | ||
| 3 | import org.slf4j.Logger; | 4 | import org.slf4j.Logger; |
| 4 | import org.slf4j.LoggerFactory; | 5 | import org.slf4j.LoggerFactory; |
| 5 | import org.springframework.beans.factory.annotation.Autowired; | 6 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -24,6 +25,9 @@ public class KeepliveTimeoutListener extends KeyExpirationEventMessageListener { | @@ -24,6 +25,9 @@ public class KeepliveTimeoutListener extends KeyExpirationEventMessageListener { | ||
| 24 | @Autowired | 25 | @Autowired |
| 25 | private EventPublisher publisher; | 26 | private EventPublisher publisher; |
| 26 | 27 | ||
| 28 | + @Autowired | ||
| 29 | + private UserSetup userSetup; | ||
| 30 | + | ||
| 27 | public KeepliveTimeoutListener(RedisMessageListenerContainer listenerContainer) { | 31 | public KeepliveTimeoutListener(RedisMessageListenerContainer listenerContainer) { |
| 28 | super(listenerContainer); | 32 | super(listenerContainer); |
| 29 | } | 33 | } |
| @@ -37,12 +41,13 @@ public class KeepliveTimeoutListener extends KeyExpirationEventMessageListener { | @@ -37,12 +41,13 @@ public class KeepliveTimeoutListener extends KeyExpirationEventMessageListener { | ||
| 37 | public void onMessage(Message message, byte[] pattern) { | 41 | public void onMessage(Message message, byte[] pattern) { |
| 38 | // 获取失效的key | 42 | // 获取失效的key |
| 39 | String expiredKey = message.toString(); | 43 | String expiredKey = message.toString(); |
| 40 | - if(!expiredKey.startsWith(VideoManagerConstants.KEEPLIVEKEY_PREFIX)){ | ||
| 41 | - logger.debug("收到redis过期监听,但开头不是"+VideoManagerConstants.KEEPLIVEKEY_PREFIX+",忽略"); | 44 | + String KEEPLIVEKEY_PREFIX = VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetup.getServerId() + "_"; |
| 45 | + if(!expiredKey.startsWith(KEEPLIVEKEY_PREFIX)){ | ||
| 46 | + logger.debug("收到redis过期监听,但开头不是"+KEEPLIVEKEY_PREFIX+",忽略"); | ||
| 42 | return; | 47 | return; |
| 43 | } | 48 | } |
| 44 | 49 | ||
| 45 | - String deviceId = expiredKey.substring(VideoManagerConstants.KEEPLIVEKEY_PREFIX.length(),expiredKey.length()); | 50 | + String deviceId = expiredKey.substring(KEEPLIVEKEY_PREFIX.length(),expiredKey.length()); |
| 46 | publisher.outlineEventPublish(deviceId, VideoManagerConstants.EVENT_OUTLINE_TIMEOUT); | 51 | publisher.outlineEventPublish(deviceId, VideoManagerConstants.EVENT_OUTLINE_TIMEOUT); |
| 47 | } | 52 | } |
| 48 | } | 53 | } |
src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/OfflineEventListener.java
| 1 | package com.genersoft.iot.vmp.gb28181.event.offline; | 1 | package com.genersoft.iot.vmp.gb28181.event.offline; |
| 2 | 2 | ||
| 3 | +import com.genersoft.iot.vmp.conf.UserSetup; | ||
| 3 | import org.slf4j.Logger; | 4 | import org.slf4j.Logger; |
| 4 | import org.slf4j.LoggerFactory; | 5 | import org.slf4j.LoggerFactory; |
| 5 | import org.springframework.beans.factory.annotation.Autowired; | 6 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -28,6 +29,9 @@ public class OfflineEventListener implements ApplicationListener<OfflineEvent> { | @@ -28,6 +29,9 @@ public class OfflineEventListener implements ApplicationListener<OfflineEvent> { | ||
| 28 | @Autowired | 29 | @Autowired |
| 29 | private RedisUtil redis; | 30 | private RedisUtil redis; |
| 30 | 31 | ||
| 32 | + @Autowired | ||
| 33 | + private UserSetup userSetup; | ||
| 34 | + | ||
| 31 | @Override | 35 | @Override |
| 32 | public void onApplicationEvent(OfflineEvent event) { | 36 | public void onApplicationEvent(OfflineEvent event) { |
| 33 | 37 | ||
| @@ -35,7 +39,7 @@ public class OfflineEventListener implements ApplicationListener<OfflineEvent> { | @@ -35,7 +39,7 @@ public class OfflineEventListener implements ApplicationListener<OfflineEvent> { | ||
| 35 | logger.debug("设备离线事件触发,deviceId:" + event.getDeviceId() + ",from:" + event.getFrom()); | 39 | logger.debug("设备离线事件触发,deviceId:" + event.getDeviceId() + ",from:" + event.getFrom()); |
| 36 | } | 40 | } |
| 37 | 41 | ||
| 38 | - String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + event.getDeviceId(); | 42 | + String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetup.getServerId() + "_" + event.getDeviceId(); |
| 39 | 43 | ||
| 40 | switch (event.getFrom()) { | 44 | switch (event.getFrom()) { |
| 41 | // 心跳超时触发的离线事件,说明redis中已删除,无需处理 | 45 | // 心跳超时触发的离线事件,说明redis中已删除,无需处理 |
src/main/java/com/genersoft/iot/vmp/gb28181/event/online/OnlineEventListener.java
| 1 | package com.genersoft.iot.vmp.gb28181.event.online; | 1 | package com.genersoft.iot.vmp.gb28181.event.online; |
| 2 | 2 | ||
| 3 | import com.genersoft.iot.vmp.conf.SipConfig; | 3 | import com.genersoft.iot.vmp.conf.SipConfig; |
| 4 | +import com.genersoft.iot.vmp.conf.UserSetup; | ||
| 4 | import com.genersoft.iot.vmp.gb28181.bean.Device; | 5 | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 6 | +import com.genersoft.iot.vmp.storager.dao.dto.User; | ||
| 5 | import org.slf4j.Logger; | 7 | import org.slf4j.Logger; |
| 6 | import org.slf4j.LoggerFactory; | 8 | import org.slf4j.LoggerFactory; |
| 7 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -35,6 +37,9 @@ public class OnlineEventListener implements ApplicationListener<OnlineEvent> { | @@ -35,6 +37,9 @@ public class OnlineEventListener implements ApplicationListener<OnlineEvent> { | ||
| 35 | @Autowired | 37 | @Autowired |
| 36 | private SipConfig sipConfig; | 38 | private SipConfig sipConfig; |
| 37 | 39 | ||
| 40 | + @Autowired | ||
| 41 | + private UserSetup userSetup; | ||
| 42 | + | ||
| 38 | private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 43 | private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| 39 | 44 | ||
| 40 | @Override | 45 | @Override |
| @@ -44,7 +49,7 @@ public class OnlineEventListener implements ApplicationListener<OnlineEvent> { | @@ -44,7 +49,7 @@ public class OnlineEventListener implements ApplicationListener<OnlineEvent> { | ||
| 44 | logger.debug("设备上线事件触发,deviceId:" + event.getDevice().getDeviceId() + ",from:" + event.getFrom()); | 49 | logger.debug("设备上线事件触发,deviceId:" + event.getDevice().getDeviceId() + ",from:" + event.getFrom()); |
| 45 | } | 50 | } |
| 46 | Device device = event.getDevice(); | 51 | Device device = event.getDevice(); |
| 47 | - String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + event.getDevice().getDeviceId(); | 52 | + String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetup.getServerId() + "_" + event.getDevice().getDeviceId(); |
| 48 | 53 | ||
| 49 | switch (event.getFrom()) { | 54 | switch (event.getFrom()) { |
| 50 | // 注册时触发的在线事件,先在redis中增加超时超时监听 | 55 | // 注册时触发的在线事件,先在redis中增加超时超时监听 |
src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEventLister.java
| @@ -52,18 +52,18 @@ public class PlatformNotRegisterEventLister implements ApplicationListener<Platf | @@ -52,18 +52,18 @@ public class PlatformNotRegisterEventLister implements ApplicationListener<Platf | ||
| 52 | @Override | 52 | @Override |
| 53 | public void onApplicationEvent(PlatformNotRegisterEvent event) { | 53 | public void onApplicationEvent(PlatformNotRegisterEvent event) { |
| 54 | 54 | ||
| 55 | - logger.info("平台未注册事件触发,平台国标ID:" + event.getPlatformGbID()); | 55 | + logger.info("[ 平台未注册事件 ]平台国标ID:" + event.getPlatformGbID()); |
| 56 | 56 | ||
| 57 | ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(event.getPlatformGbID()); | 57 | ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(event.getPlatformGbID()); |
| 58 | if (parentPlatform == null) { | 58 | if (parentPlatform == null) { |
| 59 | - logger.info("平台未注册事件触发,但平台已经删除!!! 平台国标ID:" + event.getPlatformGbID()); | 59 | + logger.info("[ 平台未注册事件 ] 平台已经删除!!! 平台国标ID:" + event.getPlatformGbID()); |
| 60 | return; | 60 | return; |
| 61 | } | 61 | } |
| 62 | // 查询是否有推流, 如果有则都停止 | 62 | // 查询是否有推流, 如果有则都停止 |
| 63 | List<SendRtpItem> sendRtpItems = redisCatchStorage.querySendRTPServer(event.getPlatformGbID()); | 63 | List<SendRtpItem> sendRtpItems = redisCatchStorage.querySendRTPServer(event.getPlatformGbID()); |
| 64 | - logger.info("停止[ {} ]的所有推流size", sendRtpItems.size()); | 64 | + logger.info("[ 平台未注册事件 ] 停止[ {} ]的所有推流size", sendRtpItems.size()); |
| 65 | if (sendRtpItems != null && sendRtpItems.size() > 0) { | 65 | if (sendRtpItems != null && sendRtpItems.size() > 0) { |
| 66 | - logger.info("停止[ {} ]的所有推流", event.getPlatformGbID()); | 66 | + logger.info("[ 平台未注册事件 ] 停止[ {} ]的所有推流", event.getPlatformGbID()); |
| 67 | StringBuilder app = new StringBuilder(); | 67 | StringBuilder app = new StringBuilder(); |
| 68 | StringBuilder stream = new StringBuilder(); | 68 | StringBuilder stream = new StringBuilder(); |
| 69 | for (SendRtpItem sendRtpItem : sendRtpItems) { | 69 | for (SendRtpItem sendRtpItem : sendRtpItems) { |
| @@ -91,13 +91,13 @@ public class PlatformNotRegisterEventLister implements ApplicationListener<Platf | @@ -91,13 +91,13 @@ public class PlatformNotRegisterEventLister implements ApplicationListener<Platf | ||
| 91 | SipSubscribe.Event okEvent = (responseEvent)->{ | 91 | SipSubscribe.Event okEvent = (responseEvent)->{ |
| 92 | timer.cancel(); | 92 | timer.cancel(); |
| 93 | }; | 93 | }; |
| 94 | - logger.info("向平台注册,平台国标ID:" + event.getPlatformGbID()); | 94 | + logger.info("[平台注册]平台国标ID:" + event.getPlatformGbID()); |
| 95 | sipCommanderFroPlatform.register(parentPlatform, null, okEvent); | 95 | sipCommanderFroPlatform.register(parentPlatform, null, okEvent); |
| 96 | // 设置注册失败则每隔15秒发起一次注册 | 96 | // 设置注册失败则每隔15秒发起一次注册 |
| 97 | timer.schedule(new TimerTask() { | 97 | timer.schedule(new TimerTask() { |
| 98 | @Override | 98 | @Override |
| 99 | public void run() { | 99 | public void run() { |
| 100 | - logger.info("再次向平台注册,平台国标ID:" + event.getPlatformGbID()); | 100 | + logger.info("[平台注册]再次向平台注册,平台国标ID:" + event.getPlatformGbID()); |
| 101 | sipCommanderFroPlatform.register(parentPlatform, null, okEvent); | 101 | sipCommanderFroPlatform.register(parentPlatform, null, okEvent); |
| 102 | } | 102 | } |
| 103 | }, config.getRegisterTimeInterval()* 1000, config.getRegisterTimeInterval()* 1000);//十五秒后再次发起注册 | 103 | }, config.getRegisterTimeInterval()* 1000, config.getRegisterTimeInterval()* 1000);//十五秒后再次发起注册 |
src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java
| @@ -7,6 +7,7 @@ import javax.sip.ClientTransaction; | @@ -7,6 +7,7 @@ import javax.sip.ClientTransaction; | ||
| 7 | import javax.sip.Dialog; | 7 | import javax.sip.Dialog; |
| 8 | 8 | ||
| 9 | import com.genersoft.iot.vmp.common.VideoManagerConstants; | 9 | import com.genersoft.iot.vmp.common.VideoManagerConstants; |
| 10 | +import com.genersoft.iot.vmp.conf.UserSetup; | ||
| 10 | import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction; | 11 | import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction; |
| 11 | import com.genersoft.iot.vmp.utils.SerializeUtils; | 12 | import com.genersoft.iot.vmp.utils.SerializeUtils; |
| 12 | import com.genersoft.iot.vmp.utils.redis.RedisUtil; | 13 | import com.genersoft.iot.vmp.utils.redis.RedisUtil; |
| @@ -25,6 +26,9 @@ public class VideoStreamSessionManager { | @@ -25,6 +26,9 @@ public class VideoStreamSessionManager { | ||
| 25 | @Autowired | 26 | @Autowired |
| 26 | private RedisUtil redisUtil; | 27 | private RedisUtil redisUtil; |
| 27 | 28 | ||
| 29 | + @Autowired | ||
| 30 | + private UserSetup userSetup; | ||
| 31 | + | ||
| 28 | public void put(String deviceId, String channelId ,String ssrc, String streamId, String mediaServerId, ClientTransaction transaction){ | 32 | public void put(String deviceId, String channelId ,String ssrc, String streamId, String mediaServerId, ClientTransaction transaction){ |
| 29 | SsrcTransaction ssrcTransaction = new SsrcTransaction(); | 33 | SsrcTransaction ssrcTransaction = new SsrcTransaction(); |
| 30 | ssrcTransaction.setDeviceId(deviceId); | 34 | ssrcTransaction.setDeviceId(deviceId); |
| @@ -35,7 +39,7 @@ public class VideoStreamSessionManager { | @@ -35,7 +39,7 @@ public class VideoStreamSessionManager { | ||
| 35 | ssrcTransaction.setSsrc(ssrc); | 39 | ssrcTransaction.setSsrc(ssrc); |
| 36 | ssrcTransaction.setMediaServerId(mediaServerId); | 40 | ssrcTransaction.setMediaServerId(mediaServerId); |
| 37 | 41 | ||
| 38 | - redisUtil.set(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + deviceId + "_" + channelId, ssrcTransaction); | 42 | + redisUtil.set(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetup.getServerId() + "_" + deviceId + "_" + channelId, ssrcTransaction); |
| 39 | } | 43 | } |
| 40 | 44 | ||
| 41 | public void put(String deviceId, String channelId , Dialog dialog){ | 45 | public void put(String deviceId, String channelId , Dialog dialog){ |
| @@ -44,7 +48,7 @@ public class VideoStreamSessionManager { | @@ -44,7 +48,7 @@ public class VideoStreamSessionManager { | ||
| 44 | byte[] dialogByteArray = SerializeUtils.serialize(dialog); | 48 | byte[] dialogByteArray = SerializeUtils.serialize(dialog); |
| 45 | ssrcTransaction.setDialog(dialogByteArray); | 49 | ssrcTransaction.setDialog(dialogByteArray); |
| 46 | } | 50 | } |
| 47 | - redisUtil.set(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + deviceId + "_" + channelId, ssrcTransaction); | 51 | + redisUtil.set(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetup.getServerId() + "_" + deviceId + "_" + channelId, ssrcTransaction); |
| 48 | } | 52 | } |
| 49 | 53 | ||
| 50 | 54 | ||
| @@ -66,7 +70,7 @@ public class VideoStreamSessionManager { | @@ -66,7 +70,7 @@ public class VideoStreamSessionManager { | ||
| 66 | } | 70 | } |
| 67 | 71 | ||
| 68 | public SsrcTransaction getSsrcTransaction(String deviceId, String channelId){ | 72 | public SsrcTransaction getSsrcTransaction(String deviceId, String channelId){ |
| 69 | - SsrcTransaction ssrcTransaction = (SsrcTransaction)redisUtil.get(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + deviceId + "_" + channelId); | 73 | + SsrcTransaction ssrcTransaction = (SsrcTransaction)redisUtil.get(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetup.getServerId() + "_" + deviceId + "_" + channelId); |
| 70 | return ssrcTransaction; | 74 | return ssrcTransaction; |
| 71 | } | 75 | } |
| 72 | 76 | ||
| @@ -90,11 +94,11 @@ public class VideoStreamSessionManager { | @@ -90,11 +94,11 @@ public class VideoStreamSessionManager { | ||
| 90 | public void remove(String deviceId, String channelId) { | 94 | public void remove(String deviceId, String channelId) { |
| 91 | SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId); | 95 | SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId); |
| 92 | if (ssrcTransaction == null) return; | 96 | if (ssrcTransaction == null) return; |
| 93 | - redisUtil.del(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + deviceId + "_" + channelId); | 97 | + redisUtil.del(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetup.getServerId() + "_" + deviceId + "_" + channelId); |
| 94 | } | 98 | } |
| 95 | 99 | ||
| 96 | public List<SsrcTransaction> getAllSsrc() { | 100 | public List<SsrcTransaction> getAllSsrc() { |
| 97 | - List<Object> ssrcTransactionKeys = redisUtil.scan(String.format("%s_*_*", VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX)); | 101 | + List<Object> ssrcTransactionKeys = redisUtil.scan(String.format("%s_*_*", VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX+ userSetup.getServerId() + "_" )); |
| 98 | List<SsrcTransaction> result= new ArrayList<>(); | 102 | List<SsrcTransaction> result= new ArrayList<>(); |
| 99 | for (int i = 0; i < ssrcTransactionKeys.size(); i++) { | 103 | for (int i = 0; i < ssrcTransactionKeys.size(); i++) { |
| 100 | String key = (String)ssrcTransactionKeys.get(i); | 104 | String key = (String)ssrcTransactionKeys.get(i); |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/MessageRequestProcessor1.java deleted
100644 → 0
| 1 | -package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl; | ||
| 2 | - | ||
| 3 | -import com.alibaba.fastjson.JSONObject; | ||
| 4 | -import com.genersoft.iot.vmp.VManageBootstrap; | ||
| 5 | -import com.genersoft.iot.vmp.common.StreamInfo; | ||
| 6 | -import com.genersoft.iot.vmp.common.VideoManagerConstants; | ||
| 7 | -import com.genersoft.iot.vmp.conf.SipConfig; | ||
| 8 | -import com.genersoft.iot.vmp.conf.UserSetup; | ||
| 9 | -import com.genersoft.iot.vmp.gb28181.bean.*; | ||
| 10 | -import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; | ||
| 11 | -import com.genersoft.iot.vmp.gb28181.event.EventPublisher; | ||
| 12 | -import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; | ||
| 13 | -import com.genersoft.iot.vmp.gb28181.transmit.callback.CheckForAllRecordsThread; | ||
| 14 | -import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | ||
| 15 | -import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | ||
| 16 | -import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | ||
| 17 | -import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; | ||
| 18 | -import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor; | ||
| 19 | -import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | ||
| 20 | -import com.genersoft.iot.vmp.gb28181.utils.DateUtil; | ||
| 21 | -import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; | ||
| 22 | -import com.genersoft.iot.vmp.gb28181.utils.SipUtils; | ||
| 23 | -import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; | ||
| 24 | -import com.genersoft.iot.vmp.service.IDeviceAlarmService; | ||
| 25 | -import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | ||
| 26 | -import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | ||
| 27 | -import com.genersoft.iot.vmp.utils.GpsUtil; | ||
| 28 | -import com.genersoft.iot.vmp.utils.SpringBeanFactory; | ||
| 29 | -import com.genersoft.iot.vmp.utils.redis.RedisUtil; | ||
| 30 | -import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce; | ||
| 31 | -import gov.nist.javax.sip.SipStackImpl; | ||
| 32 | -import gov.nist.javax.sip.address.SipUri; | ||
| 33 | -import org.dom4j.DocumentException; | ||
| 34 | -import org.dom4j.Element; | ||
| 35 | -import org.slf4j.Logger; | ||
| 36 | -import org.slf4j.LoggerFactory; | ||
| 37 | -import org.springframework.beans.factory.InitializingBean; | ||
| 38 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 39 | -import org.springframework.stereotype.Component; | ||
| 40 | -import org.springframework.util.StringUtils; | ||
| 41 | - | ||
| 42 | -import javax.sip.*; | ||
| 43 | -import javax.sip.address.SipURI; | ||
| 44 | -import javax.sip.header.FromHeader; | ||
| 45 | -import javax.sip.header.HeaderAddress; | ||
| 46 | -import javax.sip.header.ToHeader; | ||
| 47 | -import javax.sip.message.Response; | ||
| 48 | -import java.text.ParseException; | ||
| 49 | -import java.util.*; | ||
| 50 | -import java.util.concurrent.ConcurrentHashMap; | ||
| 51 | - | ||
| 52 | -import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; | ||
| 53 | - | ||
| 54 | -/** | ||
| 55 | - * @description: MESSAGE请求分发处理器, | ||
| 56 | - * @author: panlinlin | ||
| 57 | - * @date: 2021年11月8日 10:28 | ||
| 58 | - */ | ||
| 59 | -@SuppressWarnings(value={"unchecked", "rawtypes"}) | ||
| 60 | -@Component | ||
| 61 | -public class MessageRequestProcessor1 extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor { | ||
| 62 | - | ||
| 63 | - public static volatile List<String> threadNameList = new ArrayList(); | ||
| 64 | - private final static Logger logger = LoggerFactory.getLogger(MessageRequestProcessor1.class); | ||
| 65 | - private static Map<String, ISIPRequestProcessor> messageHandlerMap = new ConcurrentHashMap<>(); | ||
| 66 | - | ||
| 67 | - | ||
| 68 | - private final static String CACHE_RECORDINFO_KEY = "CACHE_RECORDINFO_"; | ||
| 69 | - private static final String MESSAGE_KEEP_ALIVE = "Keepalive"; | ||
| 70 | - private static final String MESSAGE_CONFIG_DOWNLOAD = "ConfigDownload"; | ||
| 71 | - private static final String MESSAGE_CATALOG = "Catalog"; | ||
| 72 | - private static final String MESSAGE_DEVICE_INFO = "DeviceInfo"; | ||
| 73 | - private static final String MESSAGE_ALARM = "Alarm"; | ||
| 74 | - private static final String MESSAGE_RECORD_INFO = "RecordInfo"; | ||
| 75 | - private static final String MESSAGE_MEDIA_STATUS = "MediaStatus"; | ||
| 76 | - private static final String MESSAGE_BROADCAST = "Broadcast"; | ||
| 77 | - private static final String MESSAGE_DEVICE_STATUS = "DeviceStatus"; | ||
| 78 | - private static final String MESSAGE_DEVICE_CONTROL = "DeviceControl"; | ||
| 79 | - private static final String MESSAGE_DEVICE_CONFIG = "DeviceConfig"; | ||
| 80 | - private static final String MESSAGE_MOBILE_POSITION = "MobilePosition"; | ||
| 81 | - private static final String MESSAGE_PRESET_QUERY = "PresetQuery"; | ||
| 82 | - private String method = "MESSAGE1111"; | ||
| 83 | - | ||
| 84 | - @Autowired | ||
| 85 | - private UserSetup userSetup; | ||
| 86 | - | ||
| 87 | - @Autowired | ||
| 88 | - private SIPCommander cmder; | ||
| 89 | - | ||
| 90 | - @Autowired | ||
| 91 | - private SipConfig config; | ||
| 92 | - | ||
| 93 | - @Autowired | ||
| 94 | - private SIPCommanderFroPlatform cmderFroPlatform; | ||
| 95 | - | ||
| 96 | - @Autowired | ||
| 97 | - private IVideoManagerStorager storager; | ||
| 98 | - | ||
| 99 | - @Autowired | ||
| 100 | - private IRedisCatchStorage redisCatchStorage; | ||
| 101 | - | ||
| 102 | - @Autowired | ||
| 103 | - private EventPublisher publisher; | ||
| 104 | - | ||
| 105 | - @Autowired | ||
| 106 | - private RedisUtil redis; | ||
| 107 | - | ||
| 108 | - @Autowired | ||
| 109 | - private DeferredResultHolder deferredResultHolder; | ||
| 110 | - | ||
| 111 | - @Autowired | ||
| 112 | - private DeviceOffLineDetector offLineDetector; | ||
| 113 | - | ||
| 114 | - @Autowired | ||
| 115 | - private IDeviceAlarmService deviceAlarmService; | ||
| 116 | - | ||
| 117 | - @Autowired | ||
| 118 | - private SIPProcessorObserver sipProcessorObserver; | ||
| 119 | - | ||
| 120 | - @Override | ||
| 121 | - public void afterPropertiesSet() throws Exception { | ||
| 122 | - // 添加消息处理的订阅 | ||
| 123 | - sipProcessorObserver.addRequestProcessor(method, this); | ||
| 124 | - } | ||
| 125 | - | ||
| 126 | - /** | ||
| 127 | - * 处理MESSAGE请求 | ||
| 128 | - * | ||
| 129 | - * @param evt | ||
| 130 | - */ | ||
| 131 | - @Override | ||
| 132 | - public void process(RequestEvent evt) { | ||
| 133 | - | ||
| 134 | - try { | ||
| 135 | - Element rootElement = getRootElement(evt); | ||
| 136 | - String cmd = getText(rootElement, "CmdType"); | ||
| 137 | - | ||
| 138 | - if (MESSAGE_KEEP_ALIVE.equals(cmd)) { | ||
| 139 | - logger.debug("接收到KeepAlive消息"); | ||
| 140 | - processMessageKeepAlive(evt); | ||
| 141 | - } else if (MESSAGE_CONFIG_DOWNLOAD.equals(cmd)) { | ||
| 142 | - logger.debug("接收到ConfigDownload消息"); | ||
| 143 | - processMessageConfigDownload(evt); | ||
| 144 | - } else if (MESSAGE_CATALOG.equals(cmd)) { | ||
| 145 | - logger.debug("接收到Catalog消息"); | ||
| 146 | - processMessageCatalogList(evt); | ||
| 147 | - } else if (MESSAGE_DEVICE_INFO.equals(cmd)) { | ||
| 148 | - // DeviceInfo消息处理 | ||
| 149 | - processMessageDeviceInfo(evt); | ||
| 150 | - } else if (MESSAGE_DEVICE_STATUS.equals(cmd)) { | ||
| 151 | - // DeviceStatus消息处理 | ||
| 152 | - processMessageDeviceStatus(evt); | ||
| 153 | - } else if (MESSAGE_DEVICE_CONTROL.equals(cmd)) { | ||
| 154 | - logger.debug("接收到DeviceControl消息"); | ||
| 155 | - processMessageDeviceControl(evt); | ||
| 156 | - } else if (MESSAGE_DEVICE_CONFIG.equals(cmd)) { | ||
| 157 | - logger.info("接收到DeviceConfig消息"); | ||
| 158 | - processMessageDeviceConfig(evt); | ||
| 159 | - } else if (MESSAGE_ALARM.equals(cmd)) { | ||
| 160 | - logger.debug("接收到Alarm消息"); | ||
| 161 | - processMessageAlarm(evt); | ||
| 162 | - } else if (MESSAGE_RECORD_INFO.equals(cmd)) { | ||
| 163 | - logger.debug("接收到RecordInfo消息"); | ||
| 164 | - processMessageRecordInfo(evt); | ||
| 165 | - }else if (MESSAGE_MEDIA_STATUS.equals(cmd)) { | ||
| 166 | - logger.debug("接收到MediaStatus消息"); | ||
| 167 | - processMessageMediaStatus(evt); | ||
| 168 | - } else if (MESSAGE_MOBILE_POSITION.equals(cmd)) { | ||
| 169 | - logger.debug("接收到MobilePosition消息"); | ||
| 170 | - processMessageMobilePosition(evt); | ||
| 171 | - } else if (MESSAGE_PRESET_QUERY.equals(cmd)) { | ||
| 172 | - logger.debug("接收到PresetQuery消息"); | ||
| 173 | - processMessagePresetQuery(evt); | ||
| 174 | - } else if (MESSAGE_BROADCAST.equals(cmd)) { | ||
| 175 | - // Broadcast消息处理 | ||
| 176 | - processMessageBroadcast(evt); | ||
| 177 | - } else { | ||
| 178 | - logger.debug("接收到消息:" + cmd); | ||
| 179 | - responseAck(evt, Response.OK); | ||
| 180 | - } | ||
| 181 | - } catch (DocumentException | SipException |InvalidArgumentException | ParseException e) { | ||
| 182 | - e.printStackTrace(); | ||
| 183 | - } | ||
| 184 | - } | ||
| 185 | - | ||
| 186 | - /** | ||
| 187 | - * 处理MobilePosition移动位置消息 | ||
| 188 | - * | ||
| 189 | - * @param evt | ||
| 190 | - */ | ||
| 191 | - private void processMessageMobilePosition(RequestEvent evt) { | ||
| 192 | - try { | ||
| 193 | - String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 194 | - Device device = storager.queryVideoDevice(deviceId); | ||
| 195 | - if (device == null) { | ||
| 196 | - logger.warn("处理MobilePosition移动位置消息时未找到设备信息"); | ||
| 197 | - responseAck(evt, Response.NOT_FOUND); | ||
| 198 | - return; | ||
| 199 | - } | ||
| 200 | - Element rootElement = getRootElement(evt, device.getCharset()); | ||
| 201 | - | ||
| 202 | - MobilePosition mobilePosition = new MobilePosition(); | ||
| 203 | - if (!StringUtils.isEmpty(device.getName())) { | ||
| 204 | - mobilePosition.setDeviceName(device.getName()); | ||
| 205 | - } | ||
| 206 | - mobilePosition.setDeviceId(deviceId); | ||
| 207 | - mobilePosition.setChannelId(getText(rootElement, "DeviceID")); | ||
| 208 | - mobilePosition.setTime(getText(rootElement, "Time")); | ||
| 209 | - mobilePosition.setLongitude(Double.parseDouble(getText(rootElement, "Longitude"))); | ||
| 210 | - mobilePosition.setLatitude(Double.parseDouble(getText(rootElement, "Latitude"))); | ||
| 211 | - if (NumericUtil.isDouble(getText(rootElement, "Speed"))) { | ||
| 212 | - mobilePosition.setSpeed(Double.parseDouble(getText(rootElement, "Speed"))); | ||
| 213 | - } else { | ||
| 214 | - mobilePosition.setSpeed(0.0); | ||
| 215 | - } | ||
| 216 | - if (NumericUtil.isDouble(getText(rootElement, "Direction"))) { | ||
| 217 | - mobilePosition.setDirection(Double.parseDouble(getText(rootElement, "Direction"))); | ||
| 218 | - } else { | ||
| 219 | - mobilePosition.setDirection(0.0); | ||
| 220 | - } | ||
| 221 | - if (NumericUtil.isDouble(getText(rootElement, "Altitude"))) { | ||
| 222 | - mobilePosition.setAltitude(Double.parseDouble(getText(rootElement, "Altitude"))); | ||
| 223 | - } else { | ||
| 224 | - mobilePosition.setAltitude(0.0); | ||
| 225 | - } | ||
| 226 | - mobilePosition.setReportSource("Mobile Position"); | ||
| 227 | - BaiduPoint bp = new BaiduPoint(); | ||
| 228 | - bp = GpsUtil.Wgs84ToBd09(String.valueOf(mobilePosition.getLongitude()), String.valueOf(mobilePosition.getLatitude())); | ||
| 229 | - logger.info("百度坐标:" + bp.getBdLng() + ", " + bp.getBdLat()); | ||
| 230 | - mobilePosition.setGeodeticSystem("BD-09"); | ||
| 231 | - mobilePosition.setCnLng(bp.getBdLng()); | ||
| 232 | - mobilePosition.setCnLat(bp.getBdLat()); | ||
| 233 | - if (!userSetup.getSavePositionHistory()) { | ||
| 234 | - storager.clearMobilePositionsByDeviceId(deviceId); | ||
| 235 | - } | ||
| 236 | - storager.insertMobilePosition(mobilePosition); | ||
| 237 | - //回复 200 OK | ||
| 238 | - responseAck(evt, Response.OK); | ||
| 239 | - } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { | ||
| 240 | - e.printStackTrace(); | ||
| 241 | - } | ||
| 242 | - } | ||
| 243 | - | ||
| 244 | - /** | ||
| 245 | - * 处理DeviceStatus设备状态Message | ||
| 246 | - * | ||
| 247 | - * @param evt | ||
| 248 | - */ | ||
| 249 | - private void processMessageDeviceStatus(RequestEvent evt) { | ||
| 250 | - try { | ||
| 251 | - String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 252 | - Device device = storager.queryVideoDevice(deviceId); | ||
| 253 | - if (device == null) { | ||
| 254 | - logger.warn("处理DeviceStatus设备状态Message时未找到设备信息"); | ||
| 255 | - responseAck(evt, Response.NOT_FOUND); | ||
| 256 | - return; | ||
| 257 | - } | ||
| 258 | - Element rootElement = getRootElement(evt); | ||
| 259 | - String name = rootElement.getName(); | ||
| 260 | - Element deviceIdElement = rootElement.element("DeviceID"); | ||
| 261 | - String channelId = deviceIdElement.getText(); | ||
| 262 | - if (name.equalsIgnoreCase("Query")) { // 区分是Response——查询响应,还是Query——查询请求 | ||
| 263 | - logger.info("接收到DeviceStatus查询消息"); | ||
| 264 | - FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME); | ||
| 265 | - String platformId = ((SipUri) fromHeader.getAddress().getURI()).getUser(); | ||
| 266 | - if (platformId == null) { | ||
| 267 | - responseAck(evt, Response.NOT_FOUND); | ||
| 268 | - return; | ||
| 269 | - } else { | ||
| 270 | - // 回复200 OK | ||
| 271 | - responseAck(evt, Response.OK); | ||
| 272 | - String sn = rootElement.element("SN").getText(); | ||
| 273 | - ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId); | ||
| 274 | - cmderFroPlatform.deviceStatusResponse(parentPlatform, sn, fromHeader.getTag()); | ||
| 275 | - } | ||
| 276 | - } else { | ||
| 277 | - logger.info("接收到DeviceStatus应答消息"); | ||
| 278 | - // 检查设备是否存在, 不存在则不回复 | ||
| 279 | - if (storager.exists(deviceId)) { | ||
| 280 | - // 回复200 OK | ||
| 281 | - responseAck(evt, Response.OK); | ||
| 282 | - JSONObject json = new JSONObject(); | ||
| 283 | - XmlUtil.node2Json(rootElement, json); | ||
| 284 | - if (logger.isDebugEnabled()) { | ||
| 285 | - logger.debug(json.toJSONString()); | ||
| 286 | - } | ||
| 287 | - RequestMessage msg = new RequestMessage(); | ||
| 288 | - msg.setKey(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId + channelId); | ||
| 289 | - msg.setData(json); | ||
| 290 | - deferredResultHolder.invokeAllResult(msg); | ||
| 291 | - | ||
| 292 | - if (offLineDetector.isOnline(deviceId)) { | ||
| 293 | - publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_MESSAGE); | ||
| 294 | - } else { | ||
| 295 | - } | ||
| 296 | - } | ||
| 297 | - } | ||
| 298 | - | ||
| 299 | - } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) { | ||
| 300 | - e.printStackTrace(); | ||
| 301 | - } | ||
| 302 | - } | ||
| 303 | - | ||
| 304 | - /** | ||
| 305 | - * 处理DeviceControl设备状态Message | ||
| 306 | - * | ||
| 307 | - * @param evt | ||
| 308 | - */ | ||
| 309 | - private void processMessageDeviceControl(RequestEvent evt) { | ||
| 310 | - try { | ||
| 311 | - String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 312 | - Device device = storager.queryVideoDevice(deviceId); | ||
| 313 | - if (device == null) { | ||
| 314 | - logger.warn("处理DeviceControl设备状态Message未找到设备信息"); | ||
| 315 | - responseAck(evt, Response.NOT_FOUND); | ||
| 316 | - return; | ||
| 317 | - } | ||
| 318 | - Element rootElement = getRootElement(evt); | ||
| 319 | - String channelId = getText(rootElement, "DeviceID"); | ||
| 320 | - //String result = getText(rootElement, "Result"); | ||
| 321 | - // 回复200 OK | ||
| 322 | - responseAck(evt, Response.OK); | ||
| 323 | - if (rootElement.getName().equals("Response")) {//} !StringUtils.isEmpty(result)) { | ||
| 324 | - // 此处是对本平台发出DeviceControl指令的应答 | ||
| 325 | - JSONObject json = new JSONObject(); | ||
| 326 | - XmlUtil.node2Json(rootElement, json); | ||
| 327 | - if (logger.isDebugEnabled()) { | ||
| 328 | - logger.debug(json.toJSONString()); | ||
| 329 | - } | ||
| 330 | - RequestMessage msg = new RequestMessage(); | ||
| 331 | - String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId + channelId; | ||
| 332 | - msg.setKey(key); | ||
| 333 | - msg.setData(json); | ||
| 334 | - deferredResultHolder.invokeAllResult(msg); | ||
| 335 | - } else { | ||
| 336 | - // 此处是上级发出的DeviceControl指令 | ||
| 337 | - String platformId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(FromHeader.NAME)).getAddress().getURI()).getUser(); | ||
| 338 | - String targetGBId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(ToHeader.NAME)).getAddress().getURI()).getUser(); | ||
| 339 | - // 远程启动功能 | ||
| 340 | - if (!StringUtils.isEmpty(getText(rootElement, "TeleBoot"))) { | ||
| 341 | - if (deviceId.equals(targetGBId)) { | ||
| 342 | - // 远程启动本平台:需要在重新启动程序后先对SipStack解绑 | ||
| 343 | - logger.info("执行远程启动本平台命令"); | ||
| 344 | - ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId); | ||
| 345 | - cmderFroPlatform.unregister(parentPlatform, null, null); | ||
| 346 | - | ||
| 347 | - Thread restartThread = new Thread(new Runnable() { | ||
| 348 | - @Override | ||
| 349 | - public void run() { | ||
| 350 | - try { | ||
| 351 | - Thread.sleep(3000); | ||
| 352 | - SipProvider up = (SipProvider) SpringBeanFactory.getBean("udpSipProvider"); | ||
| 353 | - SipStackImpl stack = (SipStackImpl)up.getSipStack(); | ||
| 354 | - stack.stop(); | ||
| 355 | - Iterator listener = stack.getListeningPoints(); | ||
| 356 | - while (listener.hasNext()) { | ||
| 357 | - stack.deleteListeningPoint((ListeningPoint) listener.next()); | ||
| 358 | - } | ||
| 359 | - Iterator providers = stack.getSipProviders(); | ||
| 360 | - while (providers.hasNext()) { | ||
| 361 | - stack.deleteSipProvider((SipProvider) providers.next()); | ||
| 362 | - } | ||
| 363 | - VManageBootstrap.restart(); | ||
| 364 | - } catch (InterruptedException ignored) { | ||
| 365 | - } catch (ObjectInUseException e) { | ||
| 366 | - e.printStackTrace(); | ||
| 367 | - } | ||
| 368 | - } | ||
| 369 | - }); | ||
| 370 | - | ||
| 371 | - restartThread.setDaemon(false); | ||
| 372 | - restartThread.start(); | ||
| 373 | - } else { | ||
| 374 | - // 远程启动指定设备 | ||
| 375 | - } | ||
| 376 | - } | ||
| 377 | - // 云台/前端控制命令 | ||
| 378 | - if (!StringUtils.isEmpty(getText(rootElement,"PTZCmd")) && !deviceId.equals(targetGBId)) { | ||
| 379 | - String cmdString = getText(rootElement,"PTZCmd"); | ||
| 380 | - Device deviceForPlatform = storager.queryVideoDeviceByPlatformIdAndChannelId(platformId, deviceId); | ||
| 381 | - cmder.fronEndCmd(deviceForPlatform, deviceId, cmdString); | ||
| 382 | - } | ||
| 383 | - } | ||
| 384 | - } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) { | ||
| 385 | - e.printStackTrace(); | ||
| 386 | - } | ||
| 387 | - } | ||
| 388 | - | ||
| 389 | - /** | ||
| 390 | - * 处理DeviceConfig设备状态Message | ||
| 391 | - * | ||
| 392 | - * @param evt | ||
| 393 | - */ | ||
| 394 | - private void processMessageDeviceConfig(RequestEvent evt) { | ||
| 395 | - try { | ||
| 396 | - String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 397 | - // 查询设备是否存在 | ||
| 398 | - Device device = storager.queryVideoDevice(deviceId); | ||
| 399 | - if (device == null) { | ||
| 400 | - logger.warn("处理DeviceConfig设备状态Message消息时未找到设备信息"); | ||
| 401 | - responseAck(evt, Response.NOT_FOUND); | ||
| 402 | - return; | ||
| 403 | - } | ||
| 404 | - Element rootElement = getRootElement(evt); | ||
| 405 | - String channelId = getText(rootElement, "DeviceID"); | ||
| 406 | - // 回复200 OK | ||
| 407 | - responseAck(evt, Response.OK); | ||
| 408 | - if (rootElement.getName().equals("Response")) { | ||
| 409 | - // 此处是对本平台发出DeviceControl指令的应答 | ||
| 410 | - JSONObject json = new JSONObject(); | ||
| 411 | - XmlUtil.node2Json(rootElement, json); | ||
| 412 | - if (logger.isDebugEnabled()) { | ||
| 413 | - logger.debug(json.toJSONString()); | ||
| 414 | - } | ||
| 415 | - String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG + deviceId + channelId; | ||
| 416 | - RequestMessage msg = new RequestMessage(); | ||
| 417 | - msg.setKey(key); | ||
| 418 | - msg.setData(json); | ||
| 419 | - deferredResultHolder.invokeAllResult(msg); | ||
| 420 | - } else { | ||
| 421 | - // 此处是上级发出的DeviceConfig指令 | ||
| 422 | - } | ||
| 423 | - } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) { | ||
| 424 | - e.printStackTrace(); | ||
| 425 | - } | ||
| 426 | - } | ||
| 427 | - | ||
| 428 | - /** | ||
| 429 | - * 处理ConfigDownload设备状态Message | ||
| 430 | - * | ||
| 431 | - * @param evt | ||
| 432 | - */ | ||
| 433 | - private void processMessageConfigDownload(RequestEvent evt) { | ||
| 434 | - try { | ||
| 435 | - String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 436 | - // 查询设备是否存在 | ||
| 437 | - Device device = storager.queryVideoDevice(deviceId); | ||
| 438 | - if (device == null) { | ||
| 439 | - logger.warn("处理ConfigDownload设备状态Message时未找到设备信息"); | ||
| 440 | - responseAck(evt, Response.NOT_FOUND); | ||
| 441 | - return; | ||
| 442 | - } | ||
| 443 | - Element rootElement = getRootElement(evt); | ||
| 444 | - String channelId = getText(rootElement, "DeviceID"); | ||
| 445 | - String key = DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + deviceId + channelId; | ||
| 446 | - // 回复200 OK | ||
| 447 | - responseAck(evt, Response.OK); | ||
| 448 | - if (rootElement.getName().equals("Response")) { | ||
| 449 | - // 此处是对本平台发出DeviceControl指令的应答 | ||
| 450 | - JSONObject json = new JSONObject(); | ||
| 451 | - XmlUtil.node2Json(rootElement, json); | ||
| 452 | - if (logger.isDebugEnabled()) { | ||
| 453 | - logger.debug(json.toJSONString()); | ||
| 454 | - } | ||
| 455 | - RequestMessage msg = new RequestMessage(); | ||
| 456 | - msg.setKey(key); | ||
| 457 | - msg.setData(json); | ||
| 458 | - deferredResultHolder.invokeAllResult(msg); | ||
| 459 | - } else { | ||
| 460 | - // 此处是上级发出的DeviceConfig指令 | ||
| 461 | - } | ||
| 462 | - } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) { | ||
| 463 | - e.printStackTrace(); | ||
| 464 | - } | ||
| 465 | - } | ||
| 466 | - | ||
| 467 | - /** | ||
| 468 | - * 处理PresetQuery预置位列表Message | ||
| 469 | - * | ||
| 470 | - * @param evt | ||
| 471 | - */ | ||
| 472 | - private void processMessagePresetQuery(RequestEvent evt) { | ||
| 473 | - try { | ||
| 474 | - String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 475 | - // 查询设备是否存在 | ||
| 476 | - Device device = storager.queryVideoDevice(deviceId); | ||
| 477 | - if (device == null) { | ||
| 478 | - logger.warn("处理PresetQuery预置位列表Message时未找到设备信息"); | ||
| 479 | - responseAck(evt, Response.NOT_FOUND); | ||
| 480 | - return; | ||
| 481 | - } | ||
| 482 | - Element rootElement = getRootElement(evt); | ||
| 483 | - String channelId = getText(rootElement, "DeviceID"); | ||
| 484 | - String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + deviceId + channelId; | ||
| 485 | - // 回复200 OK | ||
| 486 | - responseAck(evt, Response.OK); | ||
| 487 | - if (rootElement.getName().equals("Response")) {// !StringUtils.isEmpty(result)) { | ||
| 488 | - // 此处是对本平台发出DeviceControl指令的应答 | ||
| 489 | - JSONObject json = new JSONObject(); | ||
| 490 | - XmlUtil.node2Json(rootElement, json); | ||
| 491 | - if (logger.isDebugEnabled()) { | ||
| 492 | - logger.debug(json.toJSONString()); | ||
| 493 | - } | ||
| 494 | - RequestMessage msg = new RequestMessage(); | ||
| 495 | - msg.setKey(key); | ||
| 496 | - msg.setData(json); | ||
| 497 | - deferredResultHolder.invokeAllResult(msg); | ||
| 498 | - } else { | ||
| 499 | - // 此处是上级发出的DeviceControl指令 | ||
| 500 | - } | ||
| 501 | - } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) { | ||
| 502 | - e.printStackTrace(); | ||
| 503 | - } | ||
| 504 | - } | ||
| 505 | - | ||
| 506 | - /** | ||
| 507 | - * 处理DeviceInfo设备信息Message | ||
| 508 | - * | ||
| 509 | - * @param evt | ||
| 510 | - */ | ||
| 511 | - private void processMessageDeviceInfo(RequestEvent evt) { | ||
| 512 | - try { | ||
| 513 | - String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 514 | - // 查询设备是否存在 | ||
| 515 | - Device device = storager.queryVideoDevice(deviceId); | ||
| 516 | - ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(deviceId); | ||
| 517 | - | ||
| 518 | - Element rootElement = getRootElement(evt); | ||
| 519 | - String requestName = rootElement.getName(); | ||
| 520 | - Element deviceIdElement = rootElement.element("DeviceID"); | ||
| 521 | - String channelId = deviceIdElement.getTextTrim(); | ||
| 522 | - String key = DeferredResultHolder.CALLBACK_CMD_DEVICEINFO + deviceId + channelId; | ||
| 523 | - if (device != null ) { | ||
| 524 | - rootElement = getRootElement(evt, device.getCharset()); | ||
| 525 | - } | ||
| 526 | - if (requestName.equals("Query")) { | ||
| 527 | - logger.info("接收到DeviceInfo查询消息"); | ||
| 528 | - FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME); | ||
| 529 | - if (parentPlatform == null) { | ||
| 530 | - responseAck(evt, Response.NOT_FOUND); | ||
| 531 | - return; | ||
| 532 | - } else { | ||
| 533 | - // 回复200 OK | ||
| 534 | - responseAck(evt, Response.OK); | ||
| 535 | - String sn = rootElement.element("SN").getText(); | ||
| 536 | - cmderFroPlatform.deviceInfoResponse(parentPlatform, sn, fromHeader.getTag()); | ||
| 537 | - } | ||
| 538 | - } else { | ||
| 539 | - logger.debug("接收到DeviceInfo应答消息"); | ||
| 540 | - if (device == null) { | ||
| 541 | - logger.warn("处理DeviceInfo设备信息Message时未找到设备信息"); | ||
| 542 | - responseAck(evt, Response.NOT_FOUND); | ||
| 543 | - return; | ||
| 544 | - } | ||
| 545 | - | ||
| 546 | - device.setName(getText(rootElement, "DeviceName")); | ||
| 547 | - | ||
| 548 | - device.setManufacturer(getText(rootElement, "Manufacturer")); | ||
| 549 | - device.setModel(getText(rootElement, "Model")); | ||
| 550 | - device.setFirmware(getText(rootElement, "Firmware")); | ||
| 551 | - if (StringUtils.isEmpty(device.getStreamMode())) { | ||
| 552 | - device.setStreamMode("UDP"); | ||
| 553 | - } | ||
| 554 | - storager.updateDevice(device); | ||
| 555 | - | ||
| 556 | - RequestMessage msg = new RequestMessage(); | ||
| 557 | - msg.setKey(key); | ||
| 558 | - msg.setData(device); | ||
| 559 | - deferredResultHolder.invokeAllResult(msg); | ||
| 560 | - // 回复200 OK | ||
| 561 | - responseAck(evt, Response.OK); | ||
| 562 | - if (offLineDetector.isOnline(deviceId)) { | ||
| 563 | - publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_MESSAGE); | ||
| 564 | - } | ||
| 565 | - } | ||
| 566 | - } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { | ||
| 567 | - e.printStackTrace(); | ||
| 568 | - } | ||
| 569 | - } | ||
| 570 | - | ||
| 571 | - /*** | ||
| 572 | - * 收到catalog设备目录列表请求 处理 | ||
| 573 | - * | ||
| 574 | - * @param evt | ||
| 575 | - */ | ||
| 576 | - private void processMessageCatalogList(RequestEvent evt) { | ||
| 577 | - try { | ||
| 578 | - | ||
| 579 | - String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 580 | - // 查询设备是否存在 | ||
| 581 | - Device device = storager.queryVideoDevice(deviceId); | ||
| 582 | - ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(deviceId); | ||
| 583 | - | ||
| 584 | - | ||
| 585 | - Element rootElement = getRootElement(evt); | ||
| 586 | - String name = rootElement.getName(); | ||
| 587 | - Element deviceIdElement = rootElement.element("DeviceID"); | ||
| 588 | - String channelId = deviceIdElement.getText(); | ||
| 589 | - Element deviceListElement = rootElement.element("DeviceList"); | ||
| 590 | - String key = DeferredResultHolder.CALLBACK_CMD_CATALOG + deviceId; | ||
| 591 | - FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME); | ||
| 592 | - if (name.equalsIgnoreCase("Query")) { // 区分是Response——查询响应,还是Query——查询请求 | ||
| 593 | - // TODO 后续将代码拆分 | ||
| 594 | - if (parentPlatform == null) { | ||
| 595 | - responseAck(evt, Response.NOT_FOUND); | ||
| 596 | - return; | ||
| 597 | - } else { | ||
| 598 | - // 回复200 OK | ||
| 599 | - responseAck(evt, Response.OK); | ||
| 600 | - | ||
| 601 | - Element snElement = rootElement.element("SN"); | ||
| 602 | - String sn = snElement.getText(); | ||
| 603 | - // 准备回复通道信息 | ||
| 604 | - List<ChannelReduce> channelReduces = storager.queryChannelListInParentPlatform(parentPlatform.getServerGBId()); | ||
| 605 | - // 查询关联的直播通道 | ||
| 606 | - List<GbStream> gbStreams = storager.queryGbStreamListInPlatform(parentPlatform.getServerGBId()); | ||
| 607 | - int size = channelReduces.size() + gbStreams.size(); | ||
| 608 | - // 回复级联的通道 | ||
| 609 | - if (channelReduces.size() > 0) { | ||
| 610 | - for (ChannelReduce channelReduce : channelReduces) { | ||
| 611 | - DeviceChannel deviceChannel = storager.queryChannel(channelReduce.getDeviceId(), channelReduce.getChannelId()); | ||
| 612 | - cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size); | ||
| 613 | - } | ||
| 614 | - } | ||
| 615 | - // 回复直播的通道 | ||
| 616 | - if (gbStreams.size() > 0) { | ||
| 617 | - for (GbStream gbStream : gbStreams) { | ||
| 618 | - DeviceChannel deviceChannel = new DeviceChannel(); | ||
| 619 | - deviceChannel.setChannelId(gbStream.getGbId()); | ||
| 620 | - deviceChannel.setName(gbStream.getName()); | ||
| 621 | - deviceChannel.setLongitude(gbStream.getLongitude()); | ||
| 622 | - deviceChannel.setLatitude(gbStream.getLatitude()); | ||
| 623 | - deviceChannel.setDeviceId(parentPlatform.getDeviceGBId()); | ||
| 624 | - deviceChannel.setManufacture("wvp-pro"); | ||
| 625 | - deviceChannel.setStatus(gbStream.isStatus()?1:0); | ||
| 626 | -// deviceChannel.setParentId(parentPlatform.getDeviceGBId()); | ||
| 627 | - deviceChannel.setRegisterWay(1); | ||
| 628 | - deviceChannel.setCivilCode(config.getDomain()); | ||
| 629 | - deviceChannel.setModel("live"); | ||
| 630 | - deviceChannel.setOwner("wvp-pro"); | ||
| 631 | -// deviceChannel.setAddress("test"); | ||
| 632 | - deviceChannel.setParental(0); | ||
| 633 | - deviceChannel.setSecrecy("0"); | ||
| 634 | - deviceChannel.setSecrecy("0"); | ||
| 635 | - | ||
| 636 | - cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size); | ||
| 637 | - } | ||
| 638 | - } | ||
| 639 | - if (size == 0) { | ||
| 640 | - // 回复无通道 | ||
| 641 | - cmderFroPlatform.catalogQuery(null, parentPlatform, sn, fromHeader.getTag(), size); | ||
| 642 | - } | ||
| 643 | - } | ||
| 644 | - | ||
| 645 | - | ||
| 646 | - } else { | ||
| 647 | - if (device == null) { | ||
| 648 | - logger.warn("收到catalog设备目录列表请求时未找到设备信息"); | ||
| 649 | - responseAck(evt, Response.NOT_FOUND); | ||
| 650 | - return; | ||
| 651 | - } | ||
| 652 | - deviceListElement = getRootElement(evt, device.getCharset()).element("DeviceList"); | ||
| 653 | - Iterator<Element> deviceListIterator = deviceListElement.elementIterator(); | ||
| 654 | - if (deviceListIterator != null) { | ||
| 655 | - | ||
| 656 | - // 遍历DeviceList | ||
| 657 | - while (deviceListIterator.hasNext()) { | ||
| 658 | - Element itemDevice = deviceListIterator.next(); | ||
| 659 | - Element channelDeviceElement = itemDevice.element("DeviceID"); | ||
| 660 | - if (channelDeviceElement == null) { | ||
| 661 | - continue; | ||
| 662 | - } | ||
| 663 | - String channelDeviceId = channelDeviceElement.getText(); | ||
| 664 | - Element channdelNameElement = itemDevice.element("Name"); | ||
| 665 | - String channelName = channdelNameElement != null ? channdelNameElement.getTextTrim().toString() : ""; | ||
| 666 | - Element statusElement = itemDevice.element("Status"); | ||
| 667 | - String status = statusElement != null ? statusElement.getText().toString() : "ON"; | ||
| 668 | - DeviceChannel deviceChannel = new DeviceChannel(); | ||
| 669 | - deviceChannel.setName(channelName); | ||
| 670 | - deviceChannel.setChannelId(channelDeviceId); | ||
| 671 | - // ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR的兼容性处理 | ||
| 672 | - if (status.equals("ON") || status.equals("On") || status.equals("ONLINE")) { | ||
| 673 | - deviceChannel.setStatus(1); | ||
| 674 | - } | ||
| 675 | - if (status.equals("OFF") || status.equals("Off") || status.equals("OFFLINE")) { | ||
| 676 | - deviceChannel.setStatus(0); | ||
| 677 | - } | ||
| 678 | - | ||
| 679 | - deviceChannel.setManufacture(getText(itemDevice, "Manufacturer")); | ||
| 680 | - deviceChannel.setModel(getText(itemDevice, "Model")); | ||
| 681 | - deviceChannel.setOwner(getText(itemDevice, "Owner")); | ||
| 682 | - deviceChannel.setCivilCode(getText(itemDevice, "CivilCode")); | ||
| 683 | - deviceChannel.setBlock(getText(itemDevice, "Block")); | ||
| 684 | - deviceChannel.setAddress(getText(itemDevice, "Address")); | ||
| 685 | - if (getText(itemDevice, "Parental") == null || getText(itemDevice, "Parental") == "") { | ||
| 686 | - deviceChannel.setParental(0); | ||
| 687 | - } else { | ||
| 688 | - deviceChannel.setParental(Integer.parseInt(getText(itemDevice, "Parental"))); | ||
| 689 | - } | ||
| 690 | - deviceChannel.setParentId(getText(itemDevice, "ParentID")); | ||
| 691 | - if (getText(itemDevice, "SafetyWay") == null || getText(itemDevice, "SafetyWay") == "") { | ||
| 692 | - deviceChannel.setSafetyWay(0); | ||
| 693 | - } else { | ||
| 694 | - deviceChannel.setSafetyWay(Integer.parseInt(getText(itemDevice, "SafetyWay"))); | ||
| 695 | - } | ||
| 696 | - if (getText(itemDevice, "RegisterWay") == null || getText(itemDevice, "RegisterWay") == "") { | ||
| 697 | - deviceChannel.setRegisterWay(1); | ||
| 698 | - } else { | ||
| 699 | - deviceChannel.setRegisterWay(Integer.parseInt(getText(itemDevice, "RegisterWay"))); | ||
| 700 | - } | ||
| 701 | - deviceChannel.setCertNum(getText(itemDevice, "CertNum")); | ||
| 702 | - if (getText(itemDevice, "Certifiable") == null || getText(itemDevice, "Certifiable") == "") { | ||
| 703 | - deviceChannel.setCertifiable(0); | ||
| 704 | - } else { | ||
| 705 | - deviceChannel.setCertifiable(Integer.parseInt(getText(itemDevice, "Certifiable"))); | ||
| 706 | - } | ||
| 707 | - if (getText(itemDevice, "ErrCode") == null || getText(itemDevice, "ErrCode") == "") { | ||
| 708 | - deviceChannel.setErrCode(0); | ||
| 709 | - } else { | ||
| 710 | - deviceChannel.setErrCode(Integer.parseInt(getText(itemDevice, "ErrCode"))); | ||
| 711 | - } | ||
| 712 | - deviceChannel.setEndTime(getText(itemDevice, "EndTime")); | ||
| 713 | - deviceChannel.setSecrecy(getText(itemDevice, "Secrecy")); | ||
| 714 | - deviceChannel.setIpAddress(getText(itemDevice, "IPAddress")); | ||
| 715 | - if (getText(itemDevice, "Port") == null || getText(itemDevice, "Port") == "") { | ||
| 716 | - deviceChannel.setPort(0); | ||
| 717 | - } else { | ||
| 718 | - deviceChannel.setPort(Integer.parseInt(getText(itemDevice, "Port"))); | ||
| 719 | - } | ||
| 720 | - deviceChannel.setPassword(getText(itemDevice, "Password")); | ||
| 721 | - if (NumericUtil.isDouble(getText(itemDevice, "Longitude"))) { | ||
| 722 | - deviceChannel.setLongitude(Double.parseDouble(getText(itemDevice, "Longitude"))); | ||
| 723 | - } else { | ||
| 724 | - deviceChannel.setLongitude(0.00); | ||
| 725 | - } | ||
| 726 | - if (NumericUtil.isDouble(getText(itemDevice, "Latitude"))) { | ||
| 727 | - deviceChannel.setLatitude(Double.parseDouble(getText(itemDevice, "Latitude"))); | ||
| 728 | - } else { | ||
| 729 | - deviceChannel.setLatitude(0.00); | ||
| 730 | - } | ||
| 731 | - if (getText(itemDevice, "PTZType") == null || getText(itemDevice, "PTZType") == "") { | ||
| 732 | - deviceChannel.setPTZType(0); | ||
| 733 | - } else { | ||
| 734 | - deviceChannel.setPTZType(Integer.parseInt(getText(itemDevice, "PTZType"))); | ||
| 735 | - } | ||
| 736 | - deviceChannel.setHasAudio(true); // 默认含有音频,播放时再检查是否有音频及是否AAC | ||
| 737 | - storager.updateChannel(device.getDeviceId(), deviceChannel); | ||
| 738 | - } | ||
| 739 | - | ||
| 740 | - RequestMessage msg = new RequestMessage(); | ||
| 741 | - msg.setKey(key); | ||
| 742 | - msg.setData(device); | ||
| 743 | - deferredResultHolder.invokeAllResult(msg); | ||
| 744 | - // 回复200 OK | ||
| 745 | - responseAck(evt, Response.OK); | ||
| 746 | - if (offLineDetector.isOnline(deviceId)) { | ||
| 747 | - publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_MESSAGE); | ||
| 748 | - } | ||
| 749 | - } | ||
| 750 | - } | ||
| 751 | - } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { | ||
| 752 | - e.printStackTrace(); | ||
| 753 | - } | ||
| 754 | - } | ||
| 755 | - | ||
| 756 | - /*** | ||
| 757 | - * 收到alarm设备报警信息 处理 | ||
| 758 | - * | ||
| 759 | - * @param evt | ||
| 760 | - */ | ||
| 761 | - private void processMessageAlarm(RequestEvent evt) { | ||
| 762 | - try { | ||
| 763 | - String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 764 | - Device device = storager.queryVideoDevice(deviceId); | ||
| 765 | - if (device == null) { | ||
| 766 | - logger.warn("处理alarm设备报警信息未找到设备信息"); | ||
| 767 | - responseAck(evt, Response.NOT_FOUND); | ||
| 768 | - return; | ||
| 769 | - } | ||
| 770 | - Element rootElement = getRootElement(evt, device.getCharset()); | ||
| 771 | - Element deviceIdElement = rootElement.element("DeviceID"); | ||
| 772 | - String channelId = deviceIdElement.getText().toString(); | ||
| 773 | - String key = DeferredResultHolder.CALLBACK_CMD_ALARM + deviceId + channelId; | ||
| 774 | - // 回复200 OK | ||
| 775 | - responseAck(evt, Response.OK); | ||
| 776 | - | ||
| 777 | - if (device.getCharset() != null) { | ||
| 778 | - rootElement = getRootElement(evt, device.getCharset()); | ||
| 779 | - } | ||
| 780 | - | ||
| 781 | - if (rootElement.getName().equals("Notify")) { // 处理报警通知 | ||
| 782 | - DeviceAlarm deviceAlarm = new DeviceAlarm(); | ||
| 783 | - deviceAlarm.setDeviceId(deviceId); | ||
| 784 | - deviceAlarm.setChannelId(channelId); | ||
| 785 | - deviceAlarm.setAlarmPriority(getText(rootElement, "AlarmPriority")); | ||
| 786 | - deviceAlarm.setAlarmMethod(getText(rootElement, "AlarmMethod")); | ||
| 787 | - deviceAlarm.setAlarmTime(getText(rootElement, "AlarmTime")); | ||
| 788 | - if (getText(rootElement, "AlarmDescription") == null) { | ||
| 789 | - deviceAlarm.setAlarmDescription(""); | ||
| 790 | - } else { | ||
| 791 | - deviceAlarm.setAlarmDescription(getText(rootElement, "AlarmDescription")); | ||
| 792 | - } | ||
| 793 | - if (NumericUtil.isDouble(getText(rootElement, "Longitude"))) { | ||
| 794 | - deviceAlarm.setLongitude(Double.parseDouble(getText(rootElement, "Longitude"))); | ||
| 795 | - } else { | ||
| 796 | - deviceAlarm.setLongitude(0.00); | ||
| 797 | - } | ||
| 798 | - if (NumericUtil.isDouble(getText(rootElement, "Latitude"))) { | ||
| 799 | - deviceAlarm.setLatitude(Double.parseDouble(getText(rootElement, "Latitude"))); | ||
| 800 | - } else { | ||
| 801 | - deviceAlarm.setLatitude(0.00); | ||
| 802 | - } | ||
| 803 | - | ||
| 804 | - if (!StringUtils.isEmpty(deviceAlarm.getAlarmMethod())) { | ||
| 805 | - if ( deviceAlarm.getAlarmMethod().equals("4")) { | ||
| 806 | - MobilePosition mobilePosition = new MobilePosition(); | ||
| 807 | - mobilePosition.setDeviceId(deviceAlarm.getDeviceId()); | ||
| 808 | - mobilePosition.setTime(deviceAlarm.getAlarmTime()); | ||
| 809 | - mobilePosition.setLongitude(deviceAlarm.getLongitude()); | ||
| 810 | - mobilePosition.setLatitude(deviceAlarm.getLatitude()); | ||
| 811 | - mobilePosition.setReportSource("GPS Alarm"); | ||
| 812 | - BaiduPoint bp = new BaiduPoint(); | ||
| 813 | - bp = GpsUtil.Wgs84ToBd09(String.valueOf(mobilePosition.getLongitude()), String.valueOf(mobilePosition.getLatitude())); | ||
| 814 | - logger.info("百度坐标:" + bp.getBdLng() + ", " + bp.getBdLat()); | ||
| 815 | - mobilePosition.setGeodeticSystem("BD-09"); | ||
| 816 | - mobilePosition.setCnLng(bp.getBdLng()); | ||
| 817 | - mobilePosition.setCnLat(bp.getBdLat()); | ||
| 818 | - if (!userSetup.getSavePositionHistory()) { | ||
| 819 | - storager.clearMobilePositionsByDeviceId(deviceId); | ||
| 820 | - } | ||
| 821 | - storager.insertMobilePosition(mobilePosition); | ||
| 822 | - } | ||
| 823 | - } | ||
| 824 | - logger.debug("存储报警信息、报警分类"); | ||
| 825 | - // 存储报警信息、报警分类 | ||
| 826 | - deviceAlarmService.add(deviceAlarm); | ||
| 827 | - | ||
| 828 | - if (offLineDetector.isOnline(deviceId)) { | ||
| 829 | - publisher.deviceAlarmEventPublish(deviceAlarm); | ||
| 830 | - } | ||
| 831 | - } else if (rootElement.getName().equals("Response")) { // 处理报警查询响应 | ||
| 832 | - JSONObject json = new JSONObject(); | ||
| 833 | - XmlUtil.node2Json(rootElement, json); | ||
| 834 | - if (logger.isDebugEnabled()) { | ||
| 835 | - logger.debug(json.toJSONString()); | ||
| 836 | - } | ||
| 837 | - RequestMessage msg = new RequestMessage(); | ||
| 838 | - msg.setKey(key); | ||
| 839 | - msg.setData(json); | ||
| 840 | - deferredResultHolder.invokeAllResult(msg); | ||
| 841 | - } | ||
| 842 | - } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { | ||
| 843 | - e.printStackTrace(); | ||
| 844 | - } | ||
| 845 | - } | ||
| 846 | - | ||
| 847 | - /*** | ||
| 848 | - * 收到keepalive请求 处理 | ||
| 849 | - * | ||
| 850 | - * @param evt | ||
| 851 | - */ | ||
| 852 | - private void processMessageKeepAlive(RequestEvent evt) { | ||
| 853 | - try { | ||
| 854 | - | ||
| 855 | - String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 856 | - // 查询设备是否存在 | ||
| 857 | - Device device = storager.queryVideoDevice(deviceId); | ||
| 858 | - | ||
| 859 | - Element rootElement = getRootElement(evt); | ||
| 860 | - String channelId = getText(rootElement, "DeviceID"); | ||
| 861 | - | ||
| 862 | - // 检查设备是否存在并在线, 不在线则设置为在线 | ||
| 863 | - if (device != null ) { | ||
| 864 | - // 回复200 OK | ||
| 865 | - responseAck(evt, Response.OK); | ||
| 866 | - publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE); | ||
| 867 | - }else{ | ||
| 868 | - logger.warn("收到[ "+deviceId+" ]心跳信息, 但是设备不存在, 回复404"); | ||
| 869 | - Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest()); | ||
| 870 | - ServerTransaction serverTransaction = getServerTransaction(evt); | ||
| 871 | - serverTransaction.sendResponse(response); | ||
| 872 | - if (serverTransaction.getDialog() != null) { | ||
| 873 | - serverTransaction.getDialog().delete(); | ||
| 874 | - } | ||
| 875 | - } | ||
| 876 | - | ||
| 877 | -// if (device != null && device.getOnline() == 1) { | ||
| 878 | -// | ||
| 879 | -// if (offLineDetector.isOnline(deviceId)) { | ||
| 880 | -// publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE); | ||
| 881 | -// } else { | ||
| 882 | -// } | ||
| 883 | -// }else { | ||
| 884 | -//// logger.warn("收到[ "+deviceId+" ]心跳信息, 但是设备" + (device == null? "不存在":"离线") + ", 回复401"); | ||
| 885 | -//// Response response = getMessageFactory().createResponse(Response.UNAUTHORIZED, evt.getRequest()); | ||
| 886 | -//// getServerTransaction(evt).sendResponse(response); | ||
| 887 | -// publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE); | ||
| 888 | -// | ||
| 889 | -// } | ||
| 890 | - } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) { | ||
| 891 | - e.printStackTrace(); | ||
| 892 | - } | ||
| 893 | - } | ||
| 894 | - | ||
| 895 | - /*** | ||
| 896 | - * 处理RecordInfo设备录像列表Message请求 TODO 过期时间暂时写死180秒,后续与DeferredResult超时时间保持一致 | ||
| 897 | - * | ||
| 898 | - * @param evt | ||
| 899 | - */ | ||
| 900 | - private void processMessageRecordInfo(RequestEvent evt) { | ||
| 901 | - try { | ||
| 902 | - | ||
| 903 | - String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 904 | - // 查询设备是否存在 | ||
| 905 | - Device device = storager.queryVideoDevice(deviceId); | ||
| 906 | - if (device == null) { | ||
| 907 | - logger.warn("处理DeviceInfo设备信息Message时未找到设备信息"); | ||
| 908 | - responseAck(evt, Response.NOT_FOUND); | ||
| 909 | - return; | ||
| 910 | - } | ||
| 911 | - | ||
| 912 | - // 回复200 OK | ||
| 913 | - responseAck(evt, Response.OK); | ||
| 914 | - String uuid = UUID.randomUUID().toString().replace("-", ""); | ||
| 915 | - RecordInfo recordInfo = new RecordInfo(); | ||
| 916 | - Element rootElement = getRootElement(evt); | ||
| 917 | - String sn = getText(rootElement, "SN"); | ||
| 918 | - String key = DeferredResultHolder.CALLBACK_CMD_RECORDINFO + deviceId + sn; | ||
| 919 | - if (device != null ) { | ||
| 920 | - rootElement = getRootElement(evt, device.getCharset()); | ||
| 921 | - } | ||
| 922 | - recordInfo.setDeviceId(deviceId); | ||
| 923 | - recordInfo.setSn(sn); | ||
| 924 | - recordInfo.setName(getText(rootElement, "Name")); | ||
| 925 | - if (getText(rootElement, "SumNum")== null || getText(rootElement, "SumNum") =="") { | ||
| 926 | - recordInfo.setSumNum(0); | ||
| 927 | - } else { | ||
| 928 | - recordInfo.setSumNum(Integer.parseInt(getText(rootElement, "SumNum"))); | ||
| 929 | - } | ||
| 930 | - | ||
| 931 | - Element recordListElement = rootElement.element("RecordList"); | ||
| 932 | - if (recordListElement == null || recordInfo.getSumNum() == 0) { | ||
| 933 | - logger.info("无录像数据"); | ||
| 934 | - RequestMessage msg = new RequestMessage(); | ||
| 935 | - msg.setKey(key); | ||
| 936 | - msg.setData(recordInfo); | ||
| 937 | - deferredResultHolder.invokeAllResult(msg); | ||
| 938 | - } else { | ||
| 939 | - Iterator<Element> recordListIterator = recordListElement.elementIterator(); | ||
| 940 | - List<RecordItem> recordList = new ArrayList<RecordItem>(); | ||
| 941 | - if (recordListIterator != null) { | ||
| 942 | - RecordItem record = new RecordItem(); | ||
| 943 | - logger.info("处理录像列表数据..."); | ||
| 944 | - // 遍历DeviceList | ||
| 945 | - while (recordListIterator.hasNext()) { | ||
| 946 | - Element itemRecord = recordListIterator.next(); | ||
| 947 | - Element recordElement = itemRecord.element("DeviceID"); | ||
| 948 | - if (recordElement == null) { | ||
| 949 | - logger.info("记录为空,下一个..."); | ||
| 950 | - continue; | ||
| 951 | - } | ||
| 952 | - record = new RecordItem(); | ||
| 953 | - record.setDeviceId(getText(itemRecord, "DeviceID")); | ||
| 954 | - record.setName(getText(itemRecord, "Name")); | ||
| 955 | - record.setFilePath(getText(itemRecord, "FilePath")); | ||
| 956 | - record.setAddress(getText(itemRecord, "Address")); | ||
| 957 | - record.setStartTime( | ||
| 958 | - DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(getText(itemRecord, "StartTime"))); | ||
| 959 | - record.setEndTime( | ||
| 960 | - DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(getText(itemRecord, "EndTime"))); | ||
| 961 | - record.setSecrecy(itemRecord.element("Secrecy") == null ? 0 | ||
| 962 | - : Integer.parseInt(getText(itemRecord, "Secrecy"))); | ||
| 963 | - record.setType(getText(itemRecord, "Type")); | ||
| 964 | - record.setRecorderId(getText(itemRecord, "RecorderID")); | ||
| 965 | - recordList.add(record); | ||
| 966 | - } | ||
| 967 | - recordInfo.setRecordList(recordList); | ||
| 968 | - } | ||
| 969 | - | ||
| 970 | - // 改用单独线程统计已获取录像文件数量,避免多包并行分别统计不完整的问题 | ||
| 971 | - String cacheKey = CACHE_RECORDINFO_KEY + deviceId + sn; | ||
| 972 | - redis.set(cacheKey + "_" + uuid, recordList, 90); | ||
| 973 | - if (!threadNameList.contains(cacheKey)) { | ||
| 974 | - threadNameList.add(cacheKey); | ||
| 975 | - CheckForAllRecordsThread chk = new CheckForAllRecordsThread(cacheKey, recordInfo); | ||
| 976 | - chk.setName(cacheKey); | ||
| 977 | - chk.setDeferredResultHolder(deferredResultHolder); | ||
| 978 | - chk.setRedis(redis); | ||
| 979 | - chk.setLogger(logger); | ||
| 980 | - chk.start(); | ||
| 981 | - if (logger.isDebugEnabled()) { | ||
| 982 | - logger.debug("Start Thread " + cacheKey + "."); | ||
| 983 | - } | ||
| 984 | - } else { | ||
| 985 | - if (logger.isDebugEnabled()) { | ||
| 986 | - logger.debug("Thread " + cacheKey + " already started."); | ||
| 987 | - } | ||
| 988 | - } | ||
| 989 | - | ||
| 990 | - // 存在录像且如果当前录像明细个数小于总条数,说明拆包返回,需要组装,暂不返回 | ||
| 991 | - // if (recordInfo.getSumNum() > 0 && recordList.size() > 0 && recordList.size() < recordInfo.getSumNum()) { | ||
| 992 | - // // 为防止连续请求该设备的录像数据,返回数据错乱,特增加sn进行区分 | ||
| 993 | - // String cacheKey = CACHE_RECORDINFO_KEY + deviceId + sn; | ||
| 994 | - | ||
| 995 | - // redis.set(cacheKey + "_" + uuid, recordList, 90); | ||
| 996 | - // List<Object> cacheKeys = redis.scan(cacheKey + "_*"); | ||
| 997 | - // List<RecordItem> totalRecordList = new ArrayList<RecordItem>(); | ||
| 998 | - // for (int i = 0; i < cacheKeys.size(); i++) { | ||
| 999 | - // totalRecordList.addAll((List<RecordItem>) redis.get(cacheKeys.get(i).toString())); | ||
| 1000 | - // } | ||
| 1001 | - // if (totalRecordList.size() < recordInfo.getSumNum()) { | ||
| 1002 | - // logger.info("已获取" + totalRecordList.size() + "项录像数据,共" + recordInfo.getSumNum() + "项"); | ||
| 1003 | - // return; | ||
| 1004 | - // } | ||
| 1005 | - // logger.info("录像数据已全部获取,共" + recordInfo.getSumNum() + "项"); | ||
| 1006 | - // recordInfo.setRecordList(totalRecordList); | ||
| 1007 | - // for (int i = 0; i < cacheKeys.size(); i++) { | ||
| 1008 | - // redis.del(cacheKeys.get(i).toString()); | ||
| 1009 | - // } | ||
| 1010 | - // } | ||
| 1011 | - // // 自然顺序排序, 元素进行升序排列 | ||
| 1012 | - // recordInfo.getRecordList().sort(Comparator.naturalOrder()); | ||
| 1013 | - } | ||
| 1014 | - // 走到这里,有以下可能:1、没有录像信息,第一次收到recordinfo的消息即返回响应数据,无redis操作 | ||
| 1015 | - // 2、有录像数据,且第一次即收到完整数据,返回响应数据,无redis操作 | ||
| 1016 | - // 3、有录像数据,在超时时间内收到多次包组装后数量足够,返回数据 | ||
| 1017 | - | ||
| 1018 | - // RequestMessage msg = new RequestMessage(); | ||
| 1019 | - // msg.setDeviceId(deviceId); | ||
| 1020 | - // msg.setType(DeferredResultHolder.CALLBACK_CMD_RECORDINFO); | ||
| 1021 | - // msg.setData(recordInfo); | ||
| 1022 | - // deferredResultHolder.invokeResult(msg); | ||
| 1023 | - // logger.info("处理完成,返回结果"); | ||
| 1024 | - } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { | ||
| 1025 | - e.printStackTrace(); | ||
| 1026 | - } | ||
| 1027 | - } | ||
| 1028 | - | ||
| 1029 | - /** | ||
| 1030 | - * 收到MediaStatus消息处理 | ||
| 1031 | - * | ||
| 1032 | - * @param evt | ||
| 1033 | - */ | ||
| 1034 | - private void processMessageMediaStatus(RequestEvent evt){ | ||
| 1035 | - try { | ||
| 1036 | - | ||
| 1037 | - String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 1038 | - // 查询设备是否存在 | ||
| 1039 | - Device device = storager.queryVideoDevice(deviceId); | ||
| 1040 | - if (device == null) { | ||
| 1041 | - logger.warn("处理DeviceInfo设备信息Message时未找到设备信息"); | ||
| 1042 | - responseAck(evt, Response.NOT_FOUND); | ||
| 1043 | - return; | ||
| 1044 | - } | ||
| 1045 | - | ||
| 1046 | - // 回复200 OK | ||
| 1047 | - responseAck(evt, Response.OK); | ||
| 1048 | - Element rootElement = getRootElement(evt); | ||
| 1049 | - String channelId = getText(rootElement, "DeviceID"); | ||
| 1050 | - String NotifyType =getText(rootElement, "NotifyType"); | ||
| 1051 | - if (NotifyType.equals("121")){ | ||
| 1052 | - logger.info("媒体播放完毕,通知关流"); | ||
| 1053 | - StreamInfo streamInfo = redisCatchStorage.queryPlaybackByDevice(deviceId, "*"); | ||
| 1054 | - if (streamInfo != null) { | ||
| 1055 | - redisCatchStorage.stopPlayback(streamInfo); | ||
| 1056 | - cmder.streamByeCmd(streamInfo.getDeviceID(), streamInfo.getChannelId()); | ||
| 1057 | - } | ||
| 1058 | - } | ||
| 1059 | - } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) { | ||
| 1060 | - e.printStackTrace(); | ||
| 1061 | - } | ||
| 1062 | - } | ||
| 1063 | - | ||
| 1064 | - /** | ||
| 1065 | - * 处理AudioBroadcast语音广播Message | ||
| 1066 | - * | ||
| 1067 | - * @param evt | ||
| 1068 | - */ | ||
| 1069 | - private void processMessageBroadcast(RequestEvent evt) { | ||
| 1070 | - try { | ||
| 1071 | - | ||
| 1072 | - String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 1073 | - // 查询设备是否存在 | ||
| 1074 | - Device device = storager.queryVideoDevice(deviceId); | ||
| 1075 | - if (device == null) { | ||
| 1076 | - logger.warn("处理DeviceInfo设备信息Message时未找到设备信息"); | ||
| 1077 | - responseAck(evt, Response.NOT_FOUND); | ||
| 1078 | - return; | ||
| 1079 | - } | ||
| 1080 | - | ||
| 1081 | - Element rootElement = getRootElement(evt); | ||
| 1082 | - String channelId = getText(rootElement, "DeviceID"); | ||
| 1083 | - String key = DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId + channelId; | ||
| 1084 | - // 回复200 OK | ||
| 1085 | - responseAck(evt, Response.OK); | ||
| 1086 | - if (rootElement.getName().equals("Response")) { | ||
| 1087 | - // 此处是对本平台发出Broadcast指令的应答 | ||
| 1088 | - JSONObject json = new JSONObject(); | ||
| 1089 | - XmlUtil.node2Json(rootElement, json); | ||
| 1090 | - if (logger.isDebugEnabled()) { | ||
| 1091 | - logger.debug(json.toJSONString()); | ||
| 1092 | - } | ||
| 1093 | - RequestMessage msg = new RequestMessage(); | ||
| 1094 | - msg.setKey(key); | ||
| 1095 | - msg.setData(json); | ||
| 1096 | - deferredResultHolder.invokeAllResult(msg); | ||
| 1097 | - } else { | ||
| 1098 | - // 此处是上级发出的Broadcast指令 | ||
| 1099 | - } | ||
| 1100 | - } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) { | ||
| 1101 | - e.printStackTrace(); | ||
| 1102 | - } | ||
| 1103 | - } | ||
| 1104 | -} |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java
| 1 | package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl; | 1 | package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl; |
| 2 | 2 | ||
| 3 | import com.genersoft.iot.vmp.common.VideoManagerConstants; | 3 | import com.genersoft.iot.vmp.common.VideoManagerConstants; |
| 4 | +import com.genersoft.iot.vmp.conf.SipConfig; | ||
| 4 | import com.genersoft.iot.vmp.conf.UserSetup; | 5 | import com.genersoft.iot.vmp.conf.UserSetup; |
| 5 | import com.genersoft.iot.vmp.gb28181.bean.*; | 6 | import com.genersoft.iot.vmp.gb28181.bean.*; |
| 6 | import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; | 7 | import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; |
| @@ -50,6 +51,9 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements | @@ -50,6 +51,9 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements | ||
| 50 | private IVideoManagerStorager storager; | 51 | private IVideoManagerStorager storager; |
| 51 | 52 | ||
| 52 | @Autowired | 53 | @Autowired |
| 54 | + private SipConfig sipConfig; | ||
| 55 | + | ||
| 56 | + @Autowired | ||
| 53 | private IRedisCatchStorage redisCatchStorage; | 57 | private IRedisCatchStorage redisCatchStorage; |
| 54 | 58 | ||
| 55 | @Autowired | 59 | @Autowired |
| @@ -156,6 +160,9 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements | @@ -156,6 +160,9 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements | ||
| 156 | * @param evt | 160 | * @param evt |
| 157 | */ | 161 | */ |
| 158 | private void processNotifyAlarm(RequestEvent evt) { | 162 | private void processNotifyAlarm(RequestEvent evt) { |
| 163 | + if (!sipConfig.isAlarm()) { | ||
| 164 | + return; | ||
| 165 | + } | ||
| 159 | try { | 166 | try { |
| 160 | Element rootElement = getRootElement(evt); | 167 | Element rootElement = getRootElement(evt); |
| 161 | Element deviceIdElement = rootElement.element("DeviceID"); | 168 | Element deviceIdElement = rootElement.element("DeviceID"); |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java
| 1 | package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd; | 1 | package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd; |
| 2 | 2 | ||
| 3 | +import com.genersoft.iot.vmp.conf.SipConfig; | ||
| 3 | import com.genersoft.iot.vmp.conf.UserSetup; | 4 | import com.genersoft.iot.vmp.conf.UserSetup; |
| 4 | import com.genersoft.iot.vmp.gb28181.bean.*; | 5 | import com.genersoft.iot.vmp.gb28181.bean.*; |
| 5 | import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; | 6 | import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; |
| @@ -39,6 +40,9 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme | @@ -39,6 +40,9 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme | ||
| 39 | private UserSetup userSetup; | 40 | private UserSetup userSetup; |
| 40 | 41 | ||
| 41 | @Autowired | 42 | @Autowired |
| 43 | + private SipConfig sipConfig; | ||
| 44 | + | ||
| 45 | + @Autowired | ||
| 42 | private IVideoManagerStorager storager; | 46 | private IVideoManagerStorager storager; |
| 43 | 47 | ||
| 44 | @Autowired | 48 | @Autowired |
| @@ -54,6 +58,9 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme | @@ -54,6 +58,9 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme | ||
| 54 | 58 | ||
| 55 | @Override | 59 | @Override |
| 56 | public void handForDevice(RequestEvent evt, Device device, Element rootElement) { | 60 | public void handForDevice(RequestEvent evt, Device device, Element rootElement) { |
| 61 | + if (!sipConfig.isAlarm()) { | ||
| 62 | + return; | ||
| 63 | + } | ||
| 57 | Element deviceIdElement = rootElement.element("DeviceID"); | 64 | Element deviceIdElement = rootElement.element("DeviceID"); |
| 58 | String channelId = deviceIdElement.getText().toString(); | 65 | String channelId = deviceIdElement.getText().toString(); |
| 59 | DeviceAlarm deviceAlarm = new DeviceAlarm(); | 66 | DeviceAlarm deviceAlarm = new DeviceAlarm(); |
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
| @@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject; | @@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject; | ||
| 6 | import com.genersoft.iot.vmp.common.VideoManagerConstants; | 6 | import com.genersoft.iot.vmp.common.VideoManagerConstants; |
| 7 | import com.genersoft.iot.vmp.conf.MediaConfig; | 7 | import com.genersoft.iot.vmp.conf.MediaConfig; |
| 8 | import com.genersoft.iot.vmp.conf.SipConfig; | 8 | import com.genersoft.iot.vmp.conf.SipConfig; |
| 9 | +import com.genersoft.iot.vmp.conf.UserSetup; | ||
| 9 | import com.genersoft.iot.vmp.gb28181.bean.Device; | 10 | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 10 | import com.genersoft.iot.vmp.gb28181.session.SsrcConfig; | 11 | import com.genersoft.iot.vmp.gb28181.session.SsrcConfig; |
| 11 | import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; | 12 | import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; |
| @@ -52,7 +53,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | @@ -52,7 +53,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | ||
| 52 | private Integer serverPort; | 53 | private Integer serverPort; |
| 53 | 54 | ||
| 54 | @Autowired | 55 | @Autowired |
| 55 | - private MediaConfig mediaConfig; | 56 | + private UserSetup userSetup; |
| 56 | 57 | ||
| 57 | @Autowired | 58 | @Autowired |
| 58 | private ZLMRESTfulUtils zlmresTfulUtils; | 59 | private ZLMRESTfulUtils zlmresTfulUtils; |
| @@ -89,10 +90,10 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | @@ -89,10 +90,10 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | ||
| 89 | if (mediaServerItem.getSsrcConfig() == null) { | 90 | if (mediaServerItem.getSsrcConfig() == null) { |
| 90 | SsrcConfig ssrcConfig = new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getDomain()); | 91 | SsrcConfig ssrcConfig = new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getDomain()); |
| 91 | mediaServerItem.setSsrcConfig(ssrcConfig); | 92 | mediaServerItem.setSsrcConfig(ssrcConfig); |
| 92 | - redisUtil.set(VideoManagerConstants.MEDIA_SERVER_PREFIX + mediaServerItem.getId(), mediaServerItem); | 93 | + redisUtil.set(VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + mediaServerItem.getId(), mediaServerItem); |
| 93 | } | 94 | } |
| 94 | // 查询redis是否存在此mediaServer | 95 | // 查询redis是否存在此mediaServer |
| 95 | - String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + mediaServerItem.getId(); | 96 | + String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + mediaServerItem.getId(); |
| 96 | if (!redisUtil.hasKey(key)) { | 97 | if (!redisUtil.hasKey(key)) { |
| 97 | redisUtil.set(key, mediaServerItem); | 98 | redisUtil.set(key, mediaServerItem); |
| 98 | } | 99 | } |
| @@ -110,7 +111,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | @@ -110,7 +111,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | ||
| 110 | return null; | 111 | return null; |
| 111 | } | 112 | } |
| 112 | // 获取mediaServer可用的ssrc | 113 | // 获取mediaServer可用的ssrc |
| 113 | - String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + mediaServerItem.getId(); | 114 | + String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + mediaServerItem.getId(); |
| 114 | 115 | ||
| 115 | SsrcConfig ssrcConfig = mediaServerItem.getSsrcConfig(); | 116 | SsrcConfig ssrcConfig = mediaServerItem.getSsrcConfig(); |
| 116 | if (ssrcConfig == null) { | 117 | if (ssrcConfig == null) { |
| @@ -156,7 +157,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | @@ -156,7 +157,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | ||
| 156 | SsrcConfig ssrcConfig = mediaServerItem.getSsrcConfig(); | 157 | SsrcConfig ssrcConfig = mediaServerItem.getSsrcConfig(); |
| 157 | ssrcConfig.releaseSsrc(ssrc); | 158 | ssrcConfig.releaseSsrc(ssrc); |
| 158 | mediaServerItem.setSsrcConfig(ssrcConfig); | 159 | mediaServerItem.setSsrcConfig(ssrcConfig); |
| 159 | - String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + mediaServerItem.getId(); | 160 | + String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + mediaServerItem.getId(); |
| 160 | redisUtil.set(key, mediaServerItem); | 161 | redisUtil.set(key, mediaServerItem); |
| 161 | } | 162 | } |
| 162 | 163 | ||
| @@ -166,7 +167,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | @@ -166,7 +167,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | ||
| 166 | @Override | 167 | @Override |
| 167 | public void clearRTPServer(MediaServerItem mediaServerItem) { | 168 | public void clearRTPServer(MediaServerItem mediaServerItem) { |
| 168 | mediaServerItem.setSsrcConfig(new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getDomain())); | 169 | mediaServerItem.setSsrcConfig(new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getDomain())); |
| 169 | - redisUtil.zAdd(VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX, mediaServerItem.getId(), 0); | 170 | + redisUtil.zAdd(VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId(), mediaServerItem.getId(), 0); |
| 170 | } | 171 | } |
| 171 | 172 | ||
| 172 | 173 | ||
| @@ -186,15 +187,15 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | @@ -186,15 +187,15 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | ||
| 186 | ) | 187 | ) |
| 187 | ); | 188 | ); |
| 188 | } | 189 | } |
| 189 | - String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + mediaServerItemInDataBase.getId(); | 190 | + String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + mediaServerItemInDataBase.getId(); |
| 190 | redisUtil.set(key, mediaServerItemInDataBase); | 191 | redisUtil.set(key, mediaServerItemInDataBase); |
| 191 | } | 192 | } |
| 192 | 193 | ||
| 193 | @Override | 194 | @Override |
| 194 | public List<MediaServerItem> getAll() { | 195 | public List<MediaServerItem> getAll() { |
| 195 | List<MediaServerItem> result = new ArrayList<>(); | 196 | List<MediaServerItem> result = new ArrayList<>(); |
| 196 | - List<Object> mediaServerKeys = redisUtil.scan(String.format("%S*", VideoManagerConstants.MEDIA_SERVER_PREFIX)); | ||
| 197 | - String onlineKey = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX; | 197 | + List<Object> mediaServerKeys = redisUtil.scan(String.format("%S*", VideoManagerConstants.MEDIA_SERVER_PREFIX+ userSetup.getServerId() + "_" )); |
| 198 | + String onlineKey = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId(); | ||
| 198 | for (Object mediaServerKey : mediaServerKeys) { | 199 | for (Object mediaServerKey : mediaServerKeys) { |
| 199 | String key = (String) mediaServerKey; | 200 | String key = (String) mediaServerKey; |
| 200 | MediaServerItem mediaServerItem = (MediaServerItem) redisUtil.get(key); | 201 | MediaServerItem mediaServerItem = (MediaServerItem) redisUtil.get(key); |
| @@ -224,12 +225,12 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | @@ -224,12 +225,12 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | ||
| 224 | 225 | ||
| 225 | @Override | 226 | @Override |
| 226 | public List<MediaServerItem> getAllOnline() { | 227 | public List<MediaServerItem> getAllOnline() { |
| 227 | - String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX; | 228 | + String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId(); |
| 228 | Set<String> mediaServerIdSet = redisUtil.zRevRange(key, 0, -1); | 229 | Set<String> mediaServerIdSet = redisUtil.zRevRange(key, 0, -1); |
| 229 | List<MediaServerItem> result = new ArrayList<>(); | 230 | List<MediaServerItem> result = new ArrayList<>(); |
| 230 | if (mediaServerIdSet != null && mediaServerIdSet.size() > 0) { | 231 | if (mediaServerIdSet != null && mediaServerIdSet.size() > 0) { |
| 231 | for (String mediaServerId : mediaServerIdSet) { | 232 | for (String mediaServerId : mediaServerIdSet) { |
| 232 | - String serverKey = VideoManagerConstants.MEDIA_SERVER_PREFIX + mediaServerId; | 233 | + String serverKey = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + mediaServerId; |
| 233 | result.add((MediaServerItem) redisUtil.get(serverKey)); | 234 | result.add((MediaServerItem) redisUtil.get(serverKey)); |
| 234 | } | 235 | } |
| 235 | } | 236 | } |
| @@ -246,7 +247,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | @@ -246,7 +247,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | ||
| 246 | if (mediaServerId == null) { | 247 | if (mediaServerId == null) { |
| 247 | return null; | 248 | return null; |
| 248 | } | 249 | } |
| 249 | - String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + mediaServerId; | 250 | + String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + mediaServerId; |
| 250 | return (MediaServerItem)redisUtil.get(key); | 251 | return (MediaServerItem)redisUtil.get(key); |
| 251 | } | 252 | } |
| 252 | 253 | ||
| @@ -262,7 +263,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | @@ -262,7 +263,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | ||
| 262 | 263 | ||
| 263 | @Override | 264 | @Override |
| 264 | public void clearMediaServerForOnline() { | 265 | public void clearMediaServerForOnline() { |
| 265 | - String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX; | 266 | + String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId(); |
| 266 | redisUtil.del(key); | 267 | redisUtil.del(key); |
| 267 | } | 268 | } |
| 268 | 269 | ||
| @@ -324,10 +325,10 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | @@ -324,10 +325,10 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | ||
| 324 | if (StringUtils.isEmpty(serverItem.getId())) { | 325 | if (StringUtils.isEmpty(serverItem.getId())) { |
| 325 | serverItem.setId(zlmServerConfig.getGeneralMediaServerId()); | 326 | serverItem.setId(zlmServerConfig.getGeneralMediaServerId()); |
| 326 | } | 327 | } |
| 327 | - if (redisUtil.get(VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItem.getId()) == null) { | 328 | + if (redisUtil.get(VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + serverItem.getId()) == null) { |
| 328 | SsrcConfig ssrcConfig = new SsrcConfig(serverItem.getId(), null, sipConfig.getDomain()); | 329 | SsrcConfig ssrcConfig = new SsrcConfig(serverItem.getId(), null, sipConfig.getDomain()); |
| 329 | serverItem.setSsrcConfig(ssrcConfig); | 330 | serverItem.setSsrcConfig(ssrcConfig); |
| 330 | - redisUtil.set(VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItem.getId(), serverItem); | 331 | + redisUtil.set(VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + serverItem.getId(), serverItem); |
| 331 | } | 332 | } |
| 332 | 333 | ||
| 333 | serverItem.setStatus(true); | 334 | serverItem.setStatus(true); |
| @@ -405,7 +406,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | @@ -405,7 +406,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | ||
| 405 | @Override | 406 | @Override |
| 406 | public void resetOnlineServerItem(MediaServerItem serverItem) { | 407 | public void resetOnlineServerItem(MediaServerItem serverItem) { |
| 407 | // 更新缓存 | 408 | // 更新缓存 |
| 408 | - String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX; | 409 | + String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId(); |
| 409 | // 使用zset的分数作为当前并发量, 默认值设置为0 | 410 | // 使用zset的分数作为当前并发量, 默认值设置为0 |
| 410 | if (redisUtil.zScore(key, serverItem.getId()) == null) { // 不存在则设置默认值 已存在则重置 | 411 | if (redisUtil.zScore(key, serverItem.getId()) == null) { // 不存在则设置默认值 已存在则重置 |
| 411 | redisUtil.zAdd(key, serverItem.getId(), 0L); | 412 | redisUtil.zAdd(key, serverItem.getId(), 0L); |
| @@ -431,14 +432,14 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | @@ -431,14 +432,14 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | ||
| 431 | if (mediaServerId == null) { | 432 | if (mediaServerId == null) { |
| 432 | return; | 433 | return; |
| 433 | } | 434 | } |
| 434 | - String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX; | 435 | + String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId(); |
| 435 | redisUtil.zIncrScore(key, mediaServerId, 1); | 436 | redisUtil.zIncrScore(key, mediaServerId, 1); |
| 436 | 437 | ||
| 437 | } | 438 | } |
| 438 | 439 | ||
| 439 | @Override | 440 | @Override |
| 440 | public void removeCount(String mediaServerId) { | 441 | public void removeCount(String mediaServerId) { |
| 441 | - String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX; | 442 | + String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId(); |
| 442 | redisUtil.zIncrScore(key, mediaServerId, - 1); | 443 | redisUtil.zIncrScore(key, mediaServerId, - 1); |
| 443 | } | 444 | } |
| 444 | 445 | ||
| @@ -448,7 +449,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | @@ -448,7 +449,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | ||
| 448 | */ | 449 | */ |
| 449 | @Override | 450 | @Override |
| 450 | public MediaServerItem getMediaServerForMinimumLoad() { | 451 | public MediaServerItem getMediaServerForMinimumLoad() { |
| 451 | - String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX; | 452 | + String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId(); |
| 452 | 453 | ||
| 453 | if (redisUtil.zSize(key) == null || redisUtil.zSize(key) == 0) { | 454 | if (redisUtil.zSize(key) == null || redisUtil.zSize(key) == 0) { |
| 454 | logger.info("获取负载最低的节点时无在线节点"); | 455 | logger.info("获取负载最低的节点时无在线节点"); |
| @@ -580,8 +581,8 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | @@ -580,8 +581,8 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | ||
| 580 | 581 | ||
| 581 | @Override | 582 | @Override |
| 582 | public void delete(String id) { | 583 | public void delete(String id) { |
| 583 | - redisUtil.zRemove(VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX, id); | ||
| 584 | - String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + id; | 584 | + redisUtil.zRemove(VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId() + "_", id); |
| 585 | + String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + id; | ||
| 585 | redisUtil.del(key); | 586 | redisUtil.del(key); |
| 586 | mediaServerMapper.delOne(id); | 587 | mediaServerMapper.delOne(id); |
| 587 | } | 588 | } |
src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
| @@ -121,7 +121,7 @@ public interface IRedisCatchStorage { | @@ -121,7 +121,7 @@ public interface IRedisCatchStorage { | ||
| 121 | /** | 121 | /** |
| 122 | * 在redis添加wvp的信息 | 122 | * 在redis添加wvp的信息 |
| 123 | */ | 123 | */ |
| 124 | - void updateWVPInfo(String id, JSONObject jsonObject, int time); | 124 | + void updateWVPInfo(JSONObject jsonObject, int time); |
| 125 | 125 | ||
| 126 | /** | 126 | /** |
| 127 | * 发送推流生成与推流消失消息 | 127 | * 发送推流生成与推流消失消息 |
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
| @@ -41,7 +41,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -41,7 +41,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 41 | */ | 41 | */ |
| 42 | @Override | 42 | @Override |
| 43 | public boolean startPlay(StreamInfo stream) { | 43 | public boolean startPlay(StreamInfo stream) { |
| 44 | - return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, stream.getStreamId(),stream.getDeviceID(), stream.getChannelId()), | 44 | + return redis.set(String.format("%S_%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, userSetup.getServerId(), stream.getStreamId(),stream.getDeviceID(), stream.getChannelId()), |
| 45 | stream); | 45 | stream); |
| 46 | } | 46 | } |
| 47 | 47 | ||
| @@ -53,7 +53,8 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -53,7 +53,8 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 53 | @Override | 53 | @Override |
| 54 | public boolean stopPlay(StreamInfo streamInfo) { | 54 | public boolean stopPlay(StreamInfo streamInfo) { |
| 55 | if (streamInfo == null) return false; | 55 | if (streamInfo == null) return false; |
| 56 | - return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, | 56 | + return redis.del(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, |
| 57 | + userSetup.getServerId(), | ||
| 57 | streamInfo.getStreamId(), | 58 | streamInfo.getStreamId(), |
| 58 | streamInfo.getDeviceID(), | 59 | streamInfo.getDeviceID(), |
| 59 | streamInfo.getChannelId())); | 60 | streamInfo.getChannelId())); |
| @@ -65,22 +66,23 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -65,22 +66,23 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 65 | */ | 66 | */ |
| 66 | @Override | 67 | @Override |
| 67 | public StreamInfo queryPlay(StreamInfo streamInfo) { | 68 | public StreamInfo queryPlay(StreamInfo streamInfo) { |
| 68 | - return (StreamInfo)redis.get(String.format("%S_%s_%s_%s", | 69 | + return (StreamInfo)redis.get(String.format("%S_%s_%s_%s_%s", |
| 69 | VideoManagerConstants.PLAYER_PREFIX, | 70 | VideoManagerConstants.PLAYER_PREFIX, |
| 71 | + userSetup.getServerId(), | ||
| 70 | streamInfo.getStreamId(), | 72 | streamInfo.getStreamId(), |
| 71 | streamInfo.getDeviceID(), | 73 | streamInfo.getDeviceID(), |
| 72 | streamInfo.getChannelId())); | 74 | streamInfo.getChannelId())); |
| 73 | } | 75 | } |
| 74 | @Override | 76 | @Override |
| 75 | public StreamInfo queryPlayByStreamId(String streamId) { | 77 | public StreamInfo queryPlayByStreamId(String streamId) { |
| 76 | - List<Object> playLeys = redis.scan(String.format("%S_%s_*", VideoManagerConstants.PLAYER_PREFIX, streamId)); | 78 | + List<Object> playLeys = redis.scan(String.format("%S_%s_%s_*", VideoManagerConstants.PLAYER_PREFIX, userSetup.getServerId(), streamId)); |
| 77 | if (playLeys == null || playLeys.size() == 0) return null; | 79 | if (playLeys == null || playLeys.size() == 0) return null; |
| 78 | return (StreamInfo)redis.get(playLeys.get(0).toString()); | 80 | return (StreamInfo)redis.get(playLeys.get(0).toString()); |
| 79 | } | 81 | } |
| 80 | 82 | ||
| 81 | @Override | 83 | @Override |
| 82 | public StreamInfo queryPlaybackByStreamId(String streamId) { | 84 | public StreamInfo queryPlaybackByStreamId(String streamId) { |
| 83 | - List<Object> playLeys = redis.scan(String.format("%S_%s_*", VideoManagerConstants.PLAY_BLACK_PREFIX, streamId)); | 85 | + List<Object> playLeys = redis.scan(String.format("%S_%s_%s_*", VideoManagerConstants.PLAY_BLACK_PREFIX, userSetup.getServerId(), streamId)); |
| 84 | if (playLeys == null || playLeys.size() == 0) return null; | 86 | if (playLeys == null || playLeys.size() == 0) return null; |
| 85 | return (StreamInfo)redis.get(playLeys.get(0).toString()); | 87 | return (StreamInfo)redis.get(playLeys.get(0).toString()); |
| 86 | } | 88 | } |
| @@ -88,7 +90,8 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -88,7 +90,8 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 88 | @Override | 90 | @Override |
| 89 | public StreamInfo queryPlayByDevice(String deviceId, String channelId) { | 91 | public StreamInfo queryPlayByDevice(String deviceId, String channelId) { |
| 90 | // List<Object> playLeys = redis.keys(String.format("%S_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX, | 92 | // List<Object> playLeys = redis.keys(String.format("%S_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX, |
| 91 | - List<Object> playLeys = redis.scan(String.format("%S_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX, | 93 | + List<Object> playLeys = redis.scan(String.format("%S_%s_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX, |
| 94 | + userSetup.getServerId(), | ||
| 92 | deviceId, | 95 | deviceId, |
| 93 | channelId)); | 96 | channelId)); |
| 94 | if (playLeys == null || playLeys.size() == 0) return null; | 97 | if (playLeys == null || playLeys.size() == 0) return null; |
| @@ -99,7 +102,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -99,7 +102,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 99 | public Map<String, StreamInfo> queryPlayByDeviceId(String deviceId) { | 102 | public Map<String, StreamInfo> queryPlayByDeviceId(String deviceId) { |
| 100 | Map<String, StreamInfo> streamInfos = new HashMap<>(); | 103 | Map<String, StreamInfo> streamInfos = new HashMap<>(); |
| 101 | // List<Object> playLeys = redis.keys(String.format("%S_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, deviceId)); | 104 | // List<Object> playLeys = redis.keys(String.format("%S_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, deviceId)); |
| 102 | - List<Object> players = redis.scan(String.format("%S_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, deviceId)); | 105 | + List<Object> players = redis.scan(String.format("%S_%s_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, userSetup.getServerId(),deviceId)); |
| 103 | if (players.size() == 0) return streamInfos; | 106 | if (players.size() == 0) return streamInfos; |
| 104 | for (int i = 0; i < players.size(); i++) { | 107 | for (int i = 0; i < players.size(); i++) { |
| 105 | String key = (String) players.get(i); | 108 | String key = (String) players.get(i); |
| @@ -112,13 +115,13 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -112,13 +115,13 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 112 | 115 | ||
| 113 | @Override | 116 | @Override |
| 114 | public boolean startPlayback(StreamInfo stream) { | 117 | public boolean startPlayback(StreamInfo stream) { |
| 115 | - return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, stream.getStreamId(), | 118 | + return redis.set(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, userSetup.getServerId(),stream.getStreamId(), |
| 116 | stream.getDeviceID(), stream.getChannelId()), stream); | 119 | stream.getDeviceID(), stream.getChannelId()), stream); |
| 117 | } | 120 | } |
| 118 | 121 | ||
| 119 | @Override | 122 | @Override |
| 120 | public boolean startDownload(StreamInfo streamInfo) { | 123 | public boolean startDownload(StreamInfo streamInfo) { |
| 121 | - return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX, streamInfo.getStreamId(), | 124 | + return redis.set(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX, userSetup.getServerId(),streamInfo.getStreamId(), |
| 122 | streamInfo.getDeviceID(), streamInfo.getChannelId()), streamInfo); | 125 | streamInfo.getDeviceID(), streamInfo.getChannelId()), streamInfo); |
| 123 | } | 126 | } |
| 124 | 127 | ||
| @@ -131,7 +134,8 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -131,7 +134,8 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 131 | deviceChannel.setDeviceId(streamInfo.getDeviceID()); | 134 | deviceChannel.setDeviceId(streamInfo.getDeviceID()); |
| 132 | deviceChannelMapper.update(deviceChannel); | 135 | deviceChannelMapper.update(deviceChannel); |
| 133 | } | 136 | } |
| 134 | - return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | 137 | + return redis.del(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, |
| 138 | + userSetup.getServerId(), | ||
| 135 | streamInfo.getStreamId(), | 139 | streamInfo.getStreamId(), |
| 136 | streamInfo.getDeviceID(), | 140 | streamInfo.getDeviceID(), |
| 137 | streamInfo.getChannelId())); | 141 | streamInfo.getChannelId())); |
| @@ -142,11 +146,13 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -142,11 +146,13 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 142 | // String format = String.format("%S_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | 146 | // String format = String.format("%S_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, |
| 143 | // deviceId, | 147 | // deviceId, |
| 144 | // code); | 148 | // code); |
| 145 | - List<Object> playLeys = redis.scan(String.format("%S_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | 149 | + List<Object> playLeys = redis.scan(String.format("%S_%s_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, |
| 150 | + userSetup.getServerId(), | ||
| 146 | deviceId, | 151 | deviceId, |
| 147 | code)); | 152 | code)); |
| 148 | if (playLeys == null || playLeys.size() == 0) { | 153 | if (playLeys == null || playLeys.size() == 0) { |
| 149 | - playLeys = redis.scan(String.format("%S_*_*_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | 154 | + playLeys = redis.scan(String.format("%S_%s_*_*_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, |
| 155 | + userSetup.getServerId(), | ||
| 150 | deviceId)); | 156 | deviceId)); |
| 151 | } | 157 | } |
| 152 | if (playLeys == null || playLeys.size() == 0) return null; | 158 | if (playLeys == null || playLeys.size() == 0) return null; |
| @@ -155,63 +161,63 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -155,63 +161,63 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 155 | 161 | ||
| 156 | @Override | 162 | @Override |
| 157 | public void updatePlatformCatchInfo(ParentPlatformCatch parentPlatformCatch) { | 163 | public void updatePlatformCatchInfo(ParentPlatformCatch parentPlatformCatch) { |
| 158 | - String key = VideoManagerConstants.PLATFORM_CATCH_PREFIX + parentPlatformCatch.getId(); | 164 | + String key = VideoManagerConstants.PLATFORM_CATCH_PREFIX + userSetup.getServerId() + "_" + parentPlatformCatch.getId(); |
| 159 | redis.set(key, parentPlatformCatch); | 165 | redis.set(key, parentPlatformCatch); |
| 160 | } | 166 | } |
| 161 | 167 | ||
| 162 | @Override | 168 | @Override |
| 163 | public void updatePlatformKeepalive(ParentPlatform parentPlatform) { | 169 | public void updatePlatformKeepalive(ParentPlatform parentPlatform) { |
| 164 | - String key = VideoManagerConstants.PLATFORM_KEEPLIVEKEY_PREFIX + parentPlatform.getServerGBId(); | 170 | + String key = VideoManagerConstants.PLATFORM_KEEPALIVE_PREFIX + userSetup.getServerId() + "_" + parentPlatform.getServerGBId(); |
| 165 | redis.set(key, "", Integer.parseInt(parentPlatform.getKeepTimeout())); | 171 | redis.set(key, "", Integer.parseInt(parentPlatform.getKeepTimeout())); |
| 166 | } | 172 | } |
| 167 | 173 | ||
| 168 | @Override | 174 | @Override |
| 169 | public void updatePlatformRegister(ParentPlatform parentPlatform) { | 175 | public void updatePlatformRegister(ParentPlatform parentPlatform) { |
| 170 | - String key = VideoManagerConstants.PLATFORM_REGISTER_PREFIX + parentPlatform.getServerGBId(); | 176 | + String key = VideoManagerConstants.PLATFORM_REGISTER_PREFIX + userSetup.getServerId() + "_" + parentPlatform.getServerGBId(); |
| 171 | redis.set(key, "", Integer.parseInt(parentPlatform.getExpires())); | 177 | redis.set(key, "", Integer.parseInt(parentPlatform.getExpires())); |
| 172 | } | 178 | } |
| 173 | 179 | ||
| 174 | @Override | 180 | @Override |
| 175 | public ParentPlatformCatch queryPlatformCatchInfo(String platformGbId) { | 181 | public ParentPlatformCatch queryPlatformCatchInfo(String platformGbId) { |
| 176 | - return (ParentPlatformCatch)redis.get(VideoManagerConstants.PLATFORM_CATCH_PREFIX + platformGbId); | 182 | + return (ParentPlatformCatch)redis.get(VideoManagerConstants.PLATFORM_CATCH_PREFIX + userSetup.getServerId() + "_" + platformGbId); |
| 177 | } | 183 | } |
| 178 | 184 | ||
| 179 | @Override | 185 | @Override |
| 180 | public void delPlatformCatchInfo(String platformGbId) { | 186 | public void delPlatformCatchInfo(String platformGbId) { |
| 181 | - redis.del(VideoManagerConstants.PLATFORM_CATCH_PREFIX + platformGbId); | 187 | + redis.del(VideoManagerConstants.PLATFORM_CATCH_PREFIX + userSetup.getServerId() + "_" + platformGbId); |
| 182 | } | 188 | } |
| 183 | 189 | ||
| 184 | @Override | 190 | @Override |
| 185 | public void delPlatformKeepalive(String platformGbId) { | 191 | public void delPlatformKeepalive(String platformGbId) { |
| 186 | - redis.del(VideoManagerConstants.PLATFORM_KEEPLIVEKEY_PREFIX + platformGbId); | 192 | + redis.del(VideoManagerConstants.PLATFORM_KEEPALIVE_PREFIX + userSetup.getServerId() + "_" + platformGbId); |
| 187 | } | 193 | } |
| 188 | 194 | ||
| 189 | @Override | 195 | @Override |
| 190 | public void delPlatformRegister(String platformGbId) { | 196 | public void delPlatformRegister(String platformGbId) { |
| 191 | - redis.del(VideoManagerConstants.PLATFORM_REGISTER_PREFIX + platformGbId); | 197 | + redis.del(VideoManagerConstants.PLATFORM_REGISTER_PREFIX + userSetup.getServerId() + "_" + platformGbId); |
| 192 | } | 198 | } |
| 193 | 199 | ||
| 194 | 200 | ||
| 195 | @Override | 201 | @Override |
| 196 | public void updatePlatformRegisterInfo(String callId, String platformGbId) { | 202 | public void updatePlatformRegisterInfo(String callId, String platformGbId) { |
| 197 | - String key = VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + callId; | 203 | + String key = VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetup.getServerId() + "_" + callId; |
| 198 | redis.set(key, platformGbId); | 204 | redis.set(key, platformGbId); |
| 199 | } | 205 | } |
| 200 | 206 | ||
| 201 | 207 | ||
| 202 | @Override | 208 | @Override |
| 203 | public String queryPlatformRegisterInfo(String callId) { | 209 | public String queryPlatformRegisterInfo(String callId) { |
| 204 | - return (String)redis.get(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + callId); | 210 | + return (String)redis.get(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetup.getServerId() + "_" + callId); |
| 205 | } | 211 | } |
| 206 | 212 | ||
| 207 | @Override | 213 | @Override |
| 208 | public void delPlatformRegisterInfo(String callId) { | 214 | public void delPlatformRegisterInfo(String callId) { |
| 209 | - redis.del(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + callId); | 215 | + redis.del(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetup.getServerId() + "_" + callId); |
| 210 | } | 216 | } |
| 211 | 217 | ||
| 212 | @Override | 218 | @Override |
| 213 | public void cleanPlatformRegisterInfos() { | 219 | public void cleanPlatformRegisterInfos() { |
| 214 | - List regInfos = redis.scan(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + "*"); | 220 | + List regInfos = redis.scan(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetup.getServerId() + "_" + "*"); |
| 215 | for (Object key : regInfos) { | 221 | for (Object key : regInfos) { |
| 216 | redis.del(key.toString()); | 222 | redis.del(key.toString()); |
| 217 | } | 223 | } |
| @@ -219,19 +225,19 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -219,19 +225,19 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 219 | 225 | ||
| 220 | @Override | 226 | @Override |
| 221 | public void updateSendRTPSever(SendRtpItem sendRtpItem) { | 227 | public void updateSendRTPSever(SendRtpItem sendRtpItem) { |
| 222 | - String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + sendRtpItem.getPlatformId() + "_" + sendRtpItem.getChannelId(); | 228 | + String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + sendRtpItem.getPlatformId() + "_" + sendRtpItem.getChannelId(); |
| 223 | redis.set(key, sendRtpItem); | 229 | redis.set(key, sendRtpItem); |
| 224 | } | 230 | } |
| 225 | 231 | ||
| 226 | @Override | 232 | @Override |
| 227 | public SendRtpItem querySendRTPServer(String platformGbId, String channelId) { | 233 | public SendRtpItem querySendRTPServer(String platformGbId, String channelId) { |
| 228 | - String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + platformGbId + "_" + channelId; | 234 | + String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + platformGbId + "_" + channelId; |
| 229 | return (SendRtpItem)redis.get(key); | 235 | return (SendRtpItem)redis.get(key); |
| 230 | } | 236 | } |
| 231 | 237 | ||
| 232 | @Override | 238 | @Override |
| 233 | public List<SendRtpItem> querySendRTPServer(String platformGbId) { | 239 | public List<SendRtpItem> querySendRTPServer(String platformGbId) { |
| 234 | - String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + platformGbId + "_*"; | 240 | + String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + platformGbId + "_*"; |
| 235 | List<Object> queryResult = redis.scan(key); | 241 | List<Object> queryResult = redis.scan(key); |
| 236 | List<SendRtpItem> result= new ArrayList<>(); | 242 | List<SendRtpItem> result= new ArrayList<>(); |
| 237 | 243 | ||
| @@ -250,7 +256,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -250,7 +256,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 250 | */ | 256 | */ |
| 251 | @Override | 257 | @Override |
| 252 | public void deleteSendRTPServer(String platformGbId, String channelId) { | 258 | public void deleteSendRTPServer(String platformGbId, String channelId) { |
| 253 | - String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + platformGbId + "_" + channelId; | 259 | + String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + platformGbId + "_" + channelId; |
| 254 | redis.del(key); | 260 | redis.del(key); |
| 255 | } | 261 | } |
| 256 | 262 | ||
| @@ -260,7 +266,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -260,7 +266,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 260 | */ | 266 | */ |
| 261 | @Override | 267 | @Override |
| 262 | public boolean isChannelSendingRTP(String channelId) { | 268 | public boolean isChannelSendingRTP(String channelId) { |
| 263 | - String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + "*_" + channelId; | 269 | + String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetup.getServerId() + "_" + "*_" + channelId; |
| 264 | List<Object> RtpStreams = redis.scan(key); | 270 | List<Object> RtpStreams = redis.scan(key); |
| 265 | if (RtpStreams.size() > 0) { | 271 | if (RtpStreams.size() > 0) { |
| 266 | return true; | 272 | return true; |
| @@ -271,7 +277,8 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -271,7 +277,8 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 271 | 277 | ||
| 272 | @Override | 278 | @Override |
| 273 | public void clearCatchByDeviceId(String deviceId) { | 279 | public void clearCatchByDeviceId(String deviceId) { |
| 274 | - List<Object> playLeys = redis.scan(String.format("%S_*_%s_*", VideoManagerConstants.PLAYER_PREFIX, | 280 | + List<Object> playLeys = redis.scan(String.format("%S_%s_*_%s_*", VideoManagerConstants.PLAYER_PREFIX, |
| 281 | + userSetup.getServerId(), | ||
| 275 | deviceId)); | 282 | deviceId)); |
| 276 | if (playLeys.size() > 0) { | 283 | if (playLeys.size() > 0) { |
| 277 | for (Object key : playLeys) { | 284 | for (Object key : playLeys) { |
| @@ -279,7 +286,8 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -279,7 +286,8 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 279 | } | 286 | } |
| 280 | } | 287 | } |
| 281 | 288 | ||
| 282 | - List<Object> playBackers = redis.scan(String.format("%S_*_%s_*", VideoManagerConstants.PLAY_BLACK_PREFIX, | 289 | + List<Object> playBackers = redis.scan(String.format("%S_%s_*_%s_*", VideoManagerConstants.PLAY_BLACK_PREFIX, |
| 290 | + userSetup.getServerId(), | ||
| 283 | deviceId)); | 291 | deviceId)); |
| 284 | if (playBackers.size() > 0) { | 292 | if (playBackers.size() > 0) { |
| 285 | for (Object key : playBackers) { | 293 | for (Object key : playBackers) { |
| @@ -290,7 +298,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -290,7 +298,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 290 | 298 | ||
| 291 | @Override | 299 | @Override |
| 292 | public void outlineForAll() { | 300 | public void outlineForAll() { |
| 293 | - List<Object> onlineDevices = redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX + "*" ); | 301 | + List<Object> onlineDevices = redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetup.getServerId() + "_" + "*" ); |
| 294 | for (int i = 0; i < onlineDevices.size(); i++) { | 302 | for (int i = 0; i < onlineDevices.size(); i++) { |
| 295 | String key = (String) onlineDevices.get(i); | 303 | String key = (String) onlineDevices.get(i); |
| 296 | redis.del(key); | 304 | redis.del(key); |
| @@ -300,7 +308,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -300,7 +308,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 300 | @Override | 308 | @Override |
| 301 | public List<String> getOnlineForAll() { | 309 | public List<String> getOnlineForAll() { |
| 302 | List<String> result = new ArrayList<>(); | 310 | List<String> result = new ArrayList<>(); |
| 303 | - List<Object> onlineDevices = redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX + "*" ); | 311 | + List<Object> onlineDevices = redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetup.getServerId() + "_" + "*" ); |
| 304 | for (int i = 0; i < onlineDevices.size(); i++) { | 312 | for (int i = 0; i < onlineDevices.size(); i++) { |
| 305 | String key = (String) onlineDevices.get(i); | 313 | String key = (String) onlineDevices.get(i); |
| 306 | result.add((String) redis.get(key)); | 314 | result.add((String) redis.get(key)); |
| @@ -309,14 +317,14 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -309,14 +317,14 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 309 | } | 317 | } |
| 310 | 318 | ||
| 311 | @Override | 319 | @Override |
| 312 | - public void updateWVPInfo(String id, JSONObject jsonObject, int time) { | ||
| 313 | - String key = VideoManagerConstants.WVP_SERVER_PREFIX + id; | 320 | + public void updateWVPInfo(JSONObject jsonObject, int time) { |
| 321 | + String key = VideoManagerConstants.WVP_SERVER_PREFIX + userSetup.getServerId(); | ||
| 314 | redis.set(key, jsonObject, time); | 322 | redis.set(key, jsonObject, time); |
| 315 | } | 323 | } |
| 316 | 324 | ||
| 317 | @Override | 325 | @Override |
| 318 | public void sendStreamChangeMsg(String type, JSONObject jsonObject) { | 326 | public void sendStreamChangeMsg(String type, JSONObject jsonObject) { |
| 319 | - String key = VideoManagerConstants.WVP_MSG_STREAM_PUSH_CHANGE_PREFIX + type; | 327 | + String key = VideoManagerConstants.WVP_MSG_STREAM_CHANGE__PREFIX + type; |
| 320 | logger.debug("[redis 流变化事件] {}: {}", key, jsonObject.toString()); | 328 | logger.debug("[redis 流变化事件] {}: {}", key, jsonObject.toString()); |
| 321 | redis.convertAndSend(key, jsonObject); | 329 | redis.convertAndSend(key, jsonObject); |
| 322 | } | 330 | } |
| @@ -338,7 +346,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -338,7 +346,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 338 | 346 | ||
| 339 | @Override | 347 | @Override |
| 340 | public StreamInfo queryDownloadByStreamId(String streamId) { | 348 | public StreamInfo queryDownloadByStreamId(String streamId) { |
| 341 | - List<Object> playLeys = redis.scan(String.format("%S_%s_*", VideoManagerConstants.DOWNLOAD_PREFIX, streamId)); | 349 | + List<Object> playLeys = redis.scan(String.format("%S_%s_%s_*", VideoManagerConstants.DOWNLOAD_PREFIX, userSetup.getServerId(), streamId)); |
| 342 | if (playLeys == null || playLeys.size() == 0) return null; | 350 | if (playLeys == null || playLeys.size() == 0) return null; |
| 343 | return (StreamInfo)redis.get(playLeys.get(0).toString()); | 351 | return (StreamInfo)redis.get(playLeys.get(0).toString()); |
| 344 | } | 352 | } |
src/main/resources/all-application.yml
| @@ -80,6 +80,8 @@ sip: | @@ -80,6 +80,8 @@ sip: | ||
| 80 | ptz-speed: 50 | 80 | ptz-speed: 50 |
| 81 | # TODO [可选] 收到心跳后自动上线, 重启服务后会将所有设备置为离线,默认false,等待注册后上线。设置为true则收到心跳设置为上线。 | 81 | # TODO [可选] 收到心跳后自动上线, 重启服务后会将所有设备置为离线,默认false,等待注册后上线。设置为true则收到心跳设置为上线。 |
| 82 | # keepalliveToOnline: false | 82 | # keepalliveToOnline: false |
| 83 | + # 是否存储alarm信息 | ||
| 84 | + alarm: false | ||
| 83 | 85 | ||
| 84 | #zlm 默认服务器配置 | 86 | #zlm 默认服务器配置 |
| 85 | media: | 87 | media: |
| @@ -134,7 +136,7 @@ logging: | @@ -134,7 +136,7 @@ logging: | ||
| 134 | level: | 136 | level: |
| 135 | com.genersoft.iot: debug | 137 | com.genersoft.iot: debug |
| 136 | com.genersoft.iot.vmp.storager.dao: info | 138 | com.genersoft.iot.vmp.storager.dao: info |
| 137 | - com.genersoft.iot.vmp.gb28181: info | 139 | + com.genersoft.iot.vmp.gb28181: debug |
| 138 | # [根据业务需求配置] | 140 | # [根据业务需求配置] |
| 139 | user-settings: | 141 | user-settings: |
| 140 | # [可选] 服务ID,不写则为000000 | 142 | # [可选] 服务ID,不写则为000000 |