Commit a2182b5a7ba0ffbba960e774e019a707b5bf26bb
Committed by
GitHub
Merge branch '648540858:wvp-28181-2.0' into wvp-28181-2.0
Showing
68 changed files
with
733 additions
and
459 deletions
src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java
| ... | ... | @@ -7,7 +7,6 @@ import org.springframework.boot.SpringApplication; |
| 7 | 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 8 | 8 | import org.springframework.boot.web.servlet.ServletComponentScan; |
| 9 | 9 | import org.springframework.context.ConfigurableApplicationContext; |
| 10 | -import org.springframework.scheduling.annotation.EnableAsync; | |
| 11 | 10 | import org.springframework.scheduling.annotation.EnableScheduling; |
| 12 | 11 | import springfox.documentation.oas.annotations.EnableOpenApi; |
| 13 | 12 | ... | ... |
src/main/java/com/genersoft/iot/vmp/common/ApiSaveConstant.java
| 1 | 1 | package com.genersoft.iot.vmp.common; |
| 2 | 2 | |
| 3 | +/** | |
| 4 | + * 为API重命名, 方便向数据库记录数据的时候展示 | |
| 5 | + * @author lin | |
| 6 | + */ | |
| 3 | 7 | public class ApiSaveConstant { |
| 4 | 8 | |
| 5 | 9 | public static String getVal(String key) { |
| ... | ... | @@ -35,35 +39,47 @@ public class ApiSaveConstant { |
| 35 | 39 | return "[设备控制] 强制关键帧"; |
| 36 | 40 | case "home_position": |
| 37 | 41 | return "[设备控制] 看守位控制"; |
| 42 | + default: | |
| 43 | + return ""; | |
| 38 | 44 | } |
| 39 | - break; | |
| 40 | 45 | case "query": |
| 41 | - if (keyItemArray.length <= 5) return null; | |
| 46 | + if (keyItemArray.length <= 5) { | |
| 47 | + return null; | |
| 48 | + } | |
| 42 | 49 | switch (keyItemArray[4]) { |
| 43 | 50 | case "devices": |
| 44 | - if (keyItemArray.length < 7) return null; | |
| 51 | + if (keyItemArray.length < 7) { | |
| 52 | + return null; | |
| 53 | + } | |
| 45 | 54 | switch (keyItemArray[6]) { |
| 46 | 55 | case "sync": |
| 47 | 56 | return "[设备查询] 同步设备通道"; |
| 48 | 57 | case "delete": |
| 49 | 58 | return "[设备查询] 移除设备"; |
| 59 | + default: | |
| 60 | + return ""; | |
| 50 | 61 | } |
| 51 | - break; | |
| 52 | 62 | case "channel": |
| 53 | 63 | return "[设备查询] 更新通道信息"; |
| 54 | 64 | case "transport": |
| 55 | 65 | return "[设备查询] 修改数据流传输模式"; |
| 66 | + default: | |
| 67 | + return ""; | |
| 56 | 68 | } |
| 57 | - break; | |
| 69 | + default: | |
| 70 | + return ""; | |
| 58 | 71 | } |
| 72 | + | |
| 73 | + break; | |
| 59 | 74 | case "gbStream": |
| 60 | 75 | switch (keyItemArray[3]) { |
| 61 | 76 | case "del": |
| 62 | 77 | return "移除通道与国标的关联"; |
| 63 | 78 | case "add": |
| 64 | 79 | return "添加通道与国标的关联"; |
| 80 | + default: | |
| 81 | + return ""; | |
| 65 | 82 | } |
| 66 | - break; | |
| 67 | 83 | case "media": |
| 68 | 84 | break; |
| 69 | 85 | case "position": |
| ... | ... | @@ -81,8 +97,9 @@ public class ApiSaveConstant { |
| 81 | 97 | return "向上级平台添加国标通道"; |
| 82 | 98 | case "del_channel_for_gb": |
| 83 | 99 | return "从上级平台移除国标通道"; |
| 100 | + default: | |
| 101 | + return ""; | |
| 84 | 102 | } |
| 85 | - break; | |
| 86 | 103 | case "platform_gb_stream": |
| 87 | 104 | break; |
| 88 | 105 | case "play": |
| ... | ... | @@ -97,32 +114,36 @@ public class ApiSaveConstant { |
| 97 | 114 | return "结束转码"; |
| 98 | 115 | case "broadcast": |
| 99 | 116 | return "语音广播"; |
| 117 | + default: | |
| 118 | + return ""; | |
| 100 | 119 | } |
| 101 | - break; | |
| 102 | 120 | case "download": |
| 103 | 121 | switch (keyItemArray[3]) { |
| 104 | 122 | case "start": |
| 105 | 123 | return "开始历史媒体下载"; |
| 106 | 124 | case "stop": |
| 107 | 125 | return "停止历史媒体下载"; |
| 126 | + default: | |
| 127 | + return ""; | |
| 108 | 128 | } |
| 109 | - break; | |
| 110 | 129 | case "playback": |
| 111 | 130 | switch (keyItemArray[3]) { |
| 112 | 131 | case "start": |
| 113 | 132 | return "开始视频回放"; |
| 114 | 133 | case "stop": |
| 115 | 134 | return "停止视频回放"; |
| 135 | + default: | |
| 136 | + return ""; | |
| 116 | 137 | } |
| 117 | - break; | |
| 118 | 138 | case "ptz": |
| 119 | 139 | switch (keyItemArray[3]) { |
| 120 | 140 | case "control": |
| 121 | 141 | return "云台控制"; |
| 122 | 142 | case "front_end_command": |
| 123 | 143 | return "通用前端控制命令"; |
| 144 | + default: | |
| 145 | + return ""; | |
| 124 | 146 | } |
| 125 | - break; | |
| 126 | 147 | case "gb_record": |
| 127 | 148 | break; |
| 128 | 149 | case "onvif": |
| ... | ... | @@ -142,16 +163,18 @@ public class ApiSaveConstant { |
| 142 | 163 | return "启用代理"; |
| 143 | 164 | case "stop": |
| 144 | 165 | return "停用代理"; |
| 166 | + default: | |
| 167 | + return ""; | |
| 145 | 168 | } |
| 146 | - break; | |
| 147 | 169 | case "push": |
| 148 | 170 | switch (keyItemArray[3]) { |
| 149 | 171 | case "save_to_gb": |
| 150 | 172 | return "将推流添加到国标"; |
| 151 | 173 | case "remove_form_gb": |
| 152 | 174 | return "将推流移出到国标"; |
| 175 | + default: | |
| 176 | + return ""; | |
| 153 | 177 | } |
| 154 | - break; | |
| 155 | 178 | case "user": |
| 156 | 179 | switch (keyItemArray[3]) { |
| 157 | 180 | case "login": |
| ... | ... | @@ -162,8 +185,11 @@ public class ApiSaveConstant { |
| 162 | 185 | return "添加用户"; |
| 163 | 186 | case "delete": |
| 164 | 187 | return "删除用户"; |
| 188 | + default: | |
| 189 | + return ""; | |
| 165 | 190 | } |
| 166 | - break; | |
| 191 | + default: | |
| 192 | + return ""; | |
| 167 | 193 | } |
| 168 | 194 | } |
| 169 | 195 | return null; | ... | ... |
src/main/java/com/genersoft/iot/vmp/conf/ThreadPoolTaskConfig.java
| ... | ... | @@ -7,6 +7,10 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| 7 | 7 | |
| 8 | 8 | import java.util.concurrent.ThreadPoolExecutor; |
| 9 | 9 | |
| 10 | +/** | |
| 11 | + * ThreadPoolTask 配置类 | |
| 12 | + * @author lin | |
| 13 | + */ | |
| 10 | 14 | @Configuration |
| 11 | 15 | @EnableAsync(proxyTargetClass = true) |
| 12 | 16 | public class ThreadPoolTaskConfig { |
| ... | ... | @@ -40,6 +44,10 @@ public class ThreadPoolTaskConfig { |
| 40 | 44 | */ |
| 41 | 45 | private static final String threadNamePrefix = "wvp-"; |
| 42 | 46 | |
| 47 | + /** | |
| 48 | + * | |
| 49 | + * @return | |
| 50 | + */ | |
| 43 | 51 | @Bean("taskExecutor") // bean的名称,默认为首字母小写的方法名 |
| 44 | 52 | public ThreadPoolTaskExecutor taskExecutor() { |
| 45 | 53 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | ... | ... |
src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java
| 1 | 1 | package com.genersoft.iot.vmp.conf; |
| 2 | 2 | |
| 3 | +import io.swagger.models.auth.In; | |
| 3 | 4 | import org.springframework.boot.context.properties.ConfigurationProperties; |
| 4 | 5 | import org.springframework.stereotype.Component; |
| 5 | 6 | |
| ... | ... | @@ -19,7 +20,7 @@ public class UserSetting { |
| 19 | 20 | |
| 20 | 21 | private Boolean seniorSdp = Boolean.FALSE; |
| 21 | 22 | |
| 22 | - private Long playTimeout = 18000L; | |
| 23 | + private Integer playTimeout = 18000; | |
| 23 | 24 | |
| 24 | 25 | private int platformPlayTimeout = 60000; |
| 25 | 26 | |
| ... | ... | @@ -55,7 +56,7 @@ public class UserSetting { |
| 55 | 56 | return seniorSdp; |
| 56 | 57 | } |
| 57 | 58 | |
| 58 | - public Long getPlayTimeout() { | |
| 59 | + public Integer getPlayTimeout() { | |
| 59 | 60 | return playTimeout; |
| 60 | 61 | } |
| 61 | 62 | |
| ... | ... | @@ -83,7 +84,7 @@ public class UserSetting { |
| 83 | 84 | this.seniorSdp = seniorSdp; |
| 84 | 85 | } |
| 85 | 86 | |
| 86 | - public void setPlayTimeout(Long playTimeout) { | |
| 87 | + public void setPlayTimeout(Integer playTimeout) { | |
| 87 | 88 | this.playTimeout = playTimeout; |
| 88 | 89 | } |
| 89 | 90 | ... | ... |
src/main/java/com/genersoft/iot/vmp/conf/security/AnonymousAuthenticationEntryPoint.java
| ... | ... | @@ -13,6 +13,7 @@ import java.io.IOException; |
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * 处理匿名用户访问逻辑 |
| 16 | + * @author lin | |
| 16 | 17 | */ |
| 17 | 18 | @Component |
| 18 | 19 | public class AnonymousAuthenticationEntryPoint implements AuthenticationEntryPoint { |
| ... | ... | @@ -21,7 +22,6 @@ public class AnonymousAuthenticationEntryPoint implements AuthenticationEntryPoi |
| 21 | 22 | |
| 22 | 23 | @Override |
| 23 | 24 | public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) { |
| 24 | -// logger.debug("用户需要登录,访问[{}]失败,AuthenticationException=[{}]", request.getRequestURI(), e.getMessage()); | |
| 25 | 25 | // 允许跨域 |
| 26 | 26 | response.setHeader("Access-Control-Allow-Origin", "*"); |
| 27 | 27 | // 允许自定义请求头token(允许head跨域) |
| ... | ... | @@ -30,7 +30,8 @@ public class AnonymousAuthenticationEntryPoint implements AuthenticationEntryPoi |
| 30 | 30 | JSONObject jsonObject = new JSONObject(); |
| 31 | 31 | jsonObject.put("code", "-1"); |
| 32 | 32 | jsonObject.put("msg", "请登录后重新请求"); |
| 33 | - if (request.getRequestURI().contains("api/user/login")){ | |
| 33 | + String logUri = "api/user/login"; | |
| 34 | + if (request.getRequestURI().contains(logUri)){ | |
| 34 | 35 | jsonObject.put("msg", e.getMessage()); |
| 35 | 36 | } |
| 36 | 37 | response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java
| ... | ... | @@ -8,6 +8,7 @@ import org.slf4j.Logger; |
| 8 | 8 | import org.slf4j.LoggerFactory; |
| 9 | 9 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | 10 | import org.springframework.context.annotation.Bean; |
| 11 | +import org.springframework.context.annotation.Configuration; | |
| 11 | 12 | import org.springframework.context.annotation.DependsOn; |
| 12 | 13 | import org.springframework.stereotype.Component; |
| 13 | 14 | |
| ... | ... | @@ -18,7 +19,7 @@ import java.util.concurrent.LinkedBlockingQueue; |
| 18 | 19 | import java.util.concurrent.ThreadPoolExecutor; |
| 19 | 20 | import java.util.concurrent.TimeUnit; |
| 20 | 21 | |
| 21 | -@Component | |
| 22 | +@Configuration | |
| 22 | 23 | public class SipLayer{ |
| 23 | 24 | |
| 24 | 25 | private final static Logger logger = LoggerFactory.getLogger(SipLayer.class); |
| ... | ... | @@ -35,7 +36,7 @@ public class SipLayer{ |
| 35 | 36 | |
| 36 | 37 | |
| 37 | 38 | @Bean("sipFactory") |
| 38 | - private SipFactory createSipFactory() { | |
| 39 | + SipFactory createSipFactory() { | |
| 39 | 40 | sipFactory = SipFactory.getInstance(); |
| 40 | 41 | sipFactory.setPathName("gov.nist"); |
| 41 | 42 | return sipFactory; |
| ... | ... | @@ -43,7 +44,7 @@ public class SipLayer{ |
| 43 | 44 | |
| 44 | 45 | @Bean("sipStack") |
| 45 | 46 | @DependsOn({"sipFactory"}) |
| 46 | - private SipStack createSipStack() throws PeerUnavailableException { | |
| 47 | + SipStack createSipStack() throws PeerUnavailableException { | |
| 47 | 48 | Properties properties = new Properties(); |
| 48 | 49 | properties.setProperty("javax.sip.STACK_NAME", "GB28181_SIP"); |
| 49 | 50 | properties.setProperty("javax.sip.IP_ADDRESS", sipConfig.getMonitorIp()); |
| ... | ... | @@ -64,7 +65,7 @@ public class SipLayer{ |
| 64 | 65 | |
| 65 | 66 | @Bean(name = "tcpSipProvider") |
| 66 | 67 | @DependsOn("sipStack") |
| 67 | - private SipProviderImpl startTcpListener() { | |
| 68 | + SipProviderImpl startTcpListener() { | |
| 68 | 69 | ListeningPoint tcpListeningPoint = null; |
| 69 | 70 | SipProviderImpl tcpSipProvider = null; |
| 70 | 71 | try { |
| ... | ... | @@ -89,7 +90,7 @@ public class SipLayer{ |
| 89 | 90 | |
| 90 | 91 | @Bean(name = "udpSipProvider") |
| 91 | 92 | @DependsOn("sipStack") |
| 92 | - private SipProviderImpl startUdpListener() { | |
| 93 | + SipProviderImpl startUdpListener() { | |
| 93 | 94 | ListeningPoint udpListeningPoint = null; |
| 94 | 95 | SipProviderImpl udpSipProvider = null; |
| 95 | 96 | try { | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/auth/DigestServerAuthenticationHelper.java
| ... | ... | @@ -129,7 +129,9 @@ public class DigestServerAuthenticationHelper { |
| 129 | 129 | */ |
| 130 | 130 | public boolean doAuthenticateHashedPassword(Request request, String hashedPassword) { |
| 131 | 131 | AuthorizationHeader authHeader = (AuthorizationHeader) request.getHeader(AuthorizationHeader.NAME); |
| 132 | - if ( authHeader == null ) return false; | |
| 132 | + if ( authHeader == null ) { | |
| 133 | + return false; | |
| 134 | + } | |
| 133 | 135 | String realm = authHeader.getRealm(); |
| 134 | 136 | String username = authHeader.getUsername(); |
| 135 | 137 | |
| ... | ... | @@ -176,7 +178,9 @@ public class DigestServerAuthenticationHelper { |
| 176 | 178 | */ |
| 177 | 179 | public boolean doAuthenticatePlainTextPassword(Request request, String pass) { |
| 178 | 180 | AuthorizationHeader authHeader = (AuthorizationHeader) request.getHeader(AuthorizationHeader.NAME); |
| 179 | - if ( authHeader == null ) return false; | |
| 181 | + if ( authHeader == null ) { | |
| 182 | + return false; | |
| 183 | + } | |
| 180 | 184 | String realm = authHeader.getRealm().trim(); |
| 181 | 185 | String username = authHeader.getUsername().trim(); |
| 182 | 186 | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarmMethod.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.bean; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * 报警方式 | |
| 5 | + * @author lin | |
| 6 | + * 1为电话报警, 2为设备报警, 3为短信报警, 4为 GPS报警, 5为视频报警, 6为设备故障报警, | |
| 7 | + * 7其他报警;可以为直接组合如12为电话报警或 设备报警- | |
| 8 | + */ | |
| 9 | +public enum DeviceAlarmMethod { | |
| 10 | + // 1为电话报警 | |
| 11 | + Telephone(1), | |
| 12 | + | |
| 13 | + // 2为设备报警 | |
| 14 | + Device(2), | |
| 15 | + | |
| 16 | + // 3为短信报警 | |
| 17 | + SMS(3), | |
| 18 | + | |
| 19 | + // 4为 GPS报警 | |
| 20 | + GPS(4), | |
| 21 | + | |
| 22 | + // 5为视频报警 | |
| 23 | + Video(5), | |
| 24 | + | |
| 25 | + // 6为设备故障报警 | |
| 26 | + DeviceFailure(6), | |
| 27 | + | |
| 28 | + // 7其他报警 | |
| 29 | + Other(7); | |
| 30 | + | |
| 31 | + private final int val; | |
| 32 | + | |
| 33 | + DeviceAlarmMethod(int val) { | |
| 34 | + this.val=val; | |
| 35 | + } | |
| 36 | + | |
| 37 | + public int getVal() { | |
| 38 | + return val; | |
| 39 | + } | |
| 40 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/bean/GbStream.java
src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeHolder.java
| ... | ... | @@ -59,7 +59,9 @@ public class SubscribeHolder { |
| 59 | 59 | mobilePositionMap.put(platformId, subscribeInfo); |
| 60 | 60 | String key = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + "MobilePosition_" + platformId; |
| 61 | 61 | // 添加任务处理GPS定时推送 |
| 62 | - dynamicTask.startCron(key, new MobilePositionSubscribeHandlerTask(redisCatchStorage, sipCommanderForPlatform, storager, platformId, subscribeInfo.getSn(), key, this), subscribeInfo.getGpsInterval()); | |
| 62 | + dynamicTask.startCron(key, new MobilePositionSubscribeHandlerTask(redisCatchStorage, sipCommanderForPlatform, | |
| 63 | + storager, platformId, subscribeInfo.getSn(), key, this, dynamicTask), | |
| 64 | + subscribeInfo.getGpsInterval()); | |
| 63 | 65 | String taskOverdueKey = taskOverduePrefix + "MobilePosition_" + platformId; |
| 64 | 66 | dynamicTask.stop(taskOverdueKey); |
| 65 | 67 | // 添加任务处理订阅过期 | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/event/DeviceOffLineDetector.java deleted
100644 → 0
| 1 | -package com.genersoft.iot.vmp.gb28181.event; | |
| 2 | - | |
| 3 | -import com.genersoft.iot.vmp.conf.UserSetting; | |
| 4 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 5 | -import org.springframework.stereotype.Component; | |
| 6 | - | |
| 7 | -import com.genersoft.iot.vmp.common.VideoManagerConstants; | |
| 8 | -import com.genersoft.iot.vmp.utils.redis.RedisUtil; | |
| 9 | - | |
| 10 | -/** | |
| 11 | - * @description:设备离在线状态检测器,用于检测设备状态 | |
| 12 | - * @author: swwheihei | |
| 13 | - * @date: 2020年5月13日 下午2:40:29 | |
| 14 | - */ | |
| 15 | -@Component | |
| 16 | -public class DeviceOffLineDetector { | |
| 17 | - | |
| 18 | - @Autowired | |
| 19 | - private RedisUtil redis; | |
| 20 | - | |
| 21 | - @Autowired | |
| 22 | - private UserSetting userSetting; | |
| 23 | - | |
| 24 | - public boolean isOnline(String deviceId) { | |
| 25 | - String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetting.getServerId() + "_" + deviceId; | |
| 26 | - return redis.hasKey(key); | |
| 27 | - } | |
| 28 | -} |
src/main/java/com/genersoft/iot/vmp/gb28181/event/online/OnlineEventListener.java
| ... | ... | @@ -62,7 +62,9 @@ public class OnlineEventListener implements ApplicationListener<OnlineEvent> { |
| 62 | 62 | |
| 63 | 63 | logger.info("设备上线事件触发,deviceId:" + event.getDevice().getDeviceId() + ",from:" + event.getFrom()); |
| 64 | 64 | Device device = event.getDevice(); |
| 65 | - if (device == null) return; | |
| 65 | + if (device == null) { | |
| 66 | + return; | |
| 67 | + } | |
| 66 | 68 | String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetting.getServerId() + "_" + event.getDevice().getDeviceId(); |
| 67 | 69 | Device deviceInStore = storager.queryVideoDevice(device.getDeviceId()); |
| 68 | 70 | device.setOnline(1); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformCycleRegisterEventLister.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.event.platformNotRegister; |
| 2 | 2 | |
| 3 | +import com.genersoft.iot.vmp.conf.DynamicTask; | |
| 3 | 4 | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| 4 | 5 | import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; |
| 5 | 6 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; |
| ... | ... | @@ -22,6 +23,8 @@ public class PlatformCycleRegisterEventLister implements ApplicationListener<Pla |
| 22 | 23 | private IVideoManagerStorage storager; |
| 23 | 24 | @Autowired |
| 24 | 25 | private ISIPCommanderForPlatform sipCommanderFroPlatform; |
| 26 | + @Autowired | |
| 27 | + private DynamicTask dynamicTask; | |
| 25 | 28 | |
| 26 | 29 | @Override |
| 27 | 30 | public void onApplicationEvent(PlatformCycleRegisterEvent event) { |
| ... | ... | @@ -31,17 +34,13 @@ public class PlatformCycleRegisterEventLister implements ApplicationListener<Pla |
| 31 | 34 | logger.info("[ 平台未注册事件 ] 平台已经删除!!! 平台国标ID:" + event.getPlatformGbID()); |
| 32 | 35 | return; |
| 33 | 36 | } |
| 34 | - Timer timer = new Timer(); | |
| 37 | + String taskKey = "platform-cycle-register" + parentPlatform.getServerGBId();; | |
| 35 | 38 | SipSubscribe.Event okEvent = (responseEvent)->{ |
| 36 | - timer.cancel(); | |
| 39 | + dynamicTask.stop(taskKey); | |
| 37 | 40 | }; |
| 38 | - sipCommanderFroPlatform.register(parentPlatform, null, okEvent); | |
| 39 | - timer.schedule(new TimerTask() { | |
| 40 | - @Override | |
| 41 | - public void run() { | |
| 42 | - logger.info("[平台注册]再次向平台注册,平台国标ID:" + event.getPlatformGbID()); | |
| 43 | - sipCommanderFroPlatform.register(parentPlatform, null, okEvent); | |
| 44 | - } | |
| 45 | - }, 15*1000 ,Long.parseLong(parentPlatform.getExpires())* 1000); | |
| 41 | + dynamicTask.startCron(taskKey, ()->{ | |
| 42 | + logger.info("[平台注册]再次向平台注册,平台国标ID:" + event.getPlatformGbID()); | |
| 43 | + sipCommanderFroPlatform.register(parentPlatform, null, okEvent); | |
| 44 | + }, Integer.parseInt(parentPlatform.getExpires())* 1000); | |
| 46 | 45 | } |
| 47 | 46 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEventLister.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.event.platformNotRegister; |
| 2 | 2 | |
| 3 | +import com.genersoft.iot.vmp.conf.DynamicTask; | |
| 3 | 4 | import com.genersoft.iot.vmp.conf.SipConfig; |
| 4 | 5 | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| 5 | 6 | import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; |
| ... | ... | @@ -46,6 +47,9 @@ public class PlatformNotRegisterEventLister implements ApplicationListener<Platf |
| 46 | 47 | @Autowired |
| 47 | 48 | private SipConfig config; |
| 48 | 49 | |
| 50 | + @Autowired | |
| 51 | + private DynamicTask dynamicTask; | |
| 52 | + | |
| 49 | 53 | // @Autowired |
| 50 | 54 | // private RedisUtil redis; |
| 51 | 55 | |
| ... | ... | @@ -75,19 +79,13 @@ public class PlatformNotRegisterEventLister implements ApplicationListener<Platf |
| 75 | 79 | } |
| 76 | 80 | |
| 77 | 81 | } |
| 78 | - Timer timer = new Timer(); | |
| 82 | + String taskKey = "platform-not-register-" + parentPlatform.getServerGBId(); | |
| 79 | 83 | SipSubscribe.Event okEvent = (responseEvent)->{ |
| 80 | - timer.cancel(); | |
| 84 | + dynamicTask.stop(taskKey); | |
| 81 | 85 | }; |
| 82 | - logger.info("[平台注册]平台国标ID:" + event.getPlatformGbID()); | |
| 83 | - sipCommanderFroPlatform.register(parentPlatform, null, okEvent); | |
| 84 | - // 设置注册失败则每隔15秒发起一次注册 | |
| 85 | - timer.schedule(new TimerTask() { | |
| 86 | - @Override | |
| 87 | - public void run() { | |
| 88 | - logger.info("[平台注册]再次向平台注册,平台国标ID:" + event.getPlatformGbID()); | |
| 89 | - sipCommanderFroPlatform.register(parentPlatform, null, okEvent); | |
| 90 | - } | |
| 91 | - }, config.getRegisterTimeInterval()* 1000, config.getRegisterTimeInterval()* 1000);//十五秒后再次发起注册 | |
| 86 | + dynamicTask.startCron(taskKey, ()->{ | |
| 87 | + logger.info("[平台注册]再次向平台注册,平台国标ID:" + event.getPlatformGbID()); | |
| 88 | + sipCommanderFroPlatform.register(parentPlatform, null, okEvent); | |
| 89 | + }, config.getRegisterTimeInterval()* 1000); | |
| 92 | 90 | } |
| 93 | 91 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java
| ... | ... | @@ -60,7 +60,9 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> { |
| 60 | 60 | Map<String, List<ParentPlatform>> parentPlatformMap = new HashMap<>(); |
| 61 | 61 | if (event.getPlatformId() != null) { |
| 62 | 62 | parentPlatform = storager.queryParentPlatByServerGBId(event.getPlatformId()); |
| 63 | - if (parentPlatform != null && !parentPlatform.isStatus())return; | |
| 63 | + if (parentPlatform != null && !parentPlatform.isStatus()) { | |
| 64 | + return; | |
| 65 | + } | |
| 64 | 66 | subscribe = subscribeHolder.getCatalogSubscribe(event.getPlatformId()); |
| 65 | 67 | |
| 66 | 68 | if (subscribe == null) { |
| ... | ... | @@ -80,7 +82,9 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> { |
| 80 | 82 | }else if (event.getGbStreams() != null) { |
| 81 | 83 | if (platforms.size() > 0) { |
| 82 | 84 | for (GbStream gbStream : event.getGbStreams()) { |
| 83 | - if (gbStream == null || StringUtils.isEmpty(gbStream.getGbId())) continue; | |
| 85 | + if (gbStream == null || StringUtils.isEmpty(gbStream.getGbId())) { | |
| 86 | + continue; | |
| 87 | + } | |
| 84 | 88 | List<ParentPlatform> parentPlatformsForGB = storager.queryPlatFormListForStreamWithGBId(gbStream.getApp(),gbStream.getStream(), platforms); |
| 85 | 89 | parentPlatformMap.put(gbStream.getGbId(), parentPlatformsForGB); |
| 86 | 90 | } |
| ... | ... | @@ -113,7 +117,9 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> { |
| 113 | 117 | if (parentPlatforms != null && parentPlatforms.size() > 0) { |
| 114 | 118 | for (ParentPlatform platform : parentPlatforms) { |
| 115 | 119 | SubscribeInfo subscribeInfo = subscribeHolder.getCatalogSubscribe(platform.getServerGBId()); |
| 116 | - if (subscribeInfo == null) continue; | |
| 120 | + if (subscribeInfo == null) { | |
| 121 | + continue; | |
| 122 | + } | |
| 117 | 123 | logger.info("[Catalog事件: {}]平台:{},影响通道{}", event.getType(), platform.getServerGBId(), gbId); |
| 118 | 124 | List<DeviceChannel> deviceChannelList = new ArrayList<>(); |
| 119 | 125 | DeviceChannel deviceChannel = new DeviceChannel(); |
| ... | ... | @@ -155,7 +161,9 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> { |
| 155 | 161 | if (parentPlatforms != null && parentPlatforms.size() > 0) { |
| 156 | 162 | for (ParentPlatform platform : parentPlatforms) { |
| 157 | 163 | SubscribeInfo subscribeInfo = subscribeHolder.getCatalogSubscribe(platform.getServerGBId()); |
| 158 | - if (subscribeInfo == null) continue; | |
| 164 | + if (subscribeInfo == null) { | |
| 165 | + continue; | |
| 166 | + } | |
| 159 | 167 | logger.info("[Catalog事件: {}]平台:{},影响通道{}", event.getType(), platform.getServerGBId(), gbId); |
| 160 | 168 | List<DeviceChannel> deviceChannelList = new ArrayList<>(); |
| 161 | 169 | DeviceChannel deviceChannel = storager.queryChannelInParentPlatform(platform.getServerGBId(), gbId); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java
| ... | ... | @@ -65,19 +65,25 @@ public class CatalogDataCatch { |
| 65 | 65 | |
| 66 | 66 | public List<DeviceChannel> get(String deviceId) { |
| 67 | 67 | CatalogData catalogData = data.get(deviceId); |
| 68 | - if (catalogData == null) return null; | |
| 68 | + if (catalogData == null) { | |
| 69 | + return null; | |
| 70 | + } | |
| 69 | 71 | return catalogData.getChannelList(); |
| 70 | 72 | } |
| 71 | 73 | |
| 72 | 74 | public int getTotal(String deviceId) { |
| 73 | 75 | CatalogData catalogData = data.get(deviceId); |
| 74 | - if (catalogData == null) return 0; | |
| 76 | + if (catalogData == null) { | |
| 77 | + return 0; | |
| 78 | + } | |
| 75 | 79 | return catalogData.getTotal(); |
| 76 | 80 | } |
| 77 | 81 | |
| 78 | 82 | public SyncStatus getSyncStatus(String deviceId) { |
| 79 | 83 | CatalogData catalogData = data.get(deviceId); |
| 80 | - if (catalogData == null) return null; | |
| 84 | + if (catalogData == null) { | |
| 85 | + return null; | |
| 86 | + } | |
| 81 | 87 | SyncStatus syncStatus = new SyncStatus(); |
| 82 | 88 | syncStatus.setCurrent(catalogData.getChannelList().size()); |
| 83 | 89 | syncStatus.setTotal(catalogData.getTotal()); |
| ... | ... | @@ -87,7 +93,9 @@ public class CatalogDataCatch { |
| 87 | 93 | |
| 88 | 94 | public boolean isSyncRunning(String deviceId) { |
| 89 | 95 | CatalogData catalogData = data.get(deviceId); |
| 90 | - if (catalogData == null) return false; | |
| 96 | + if (catalogData == null) { | |
| 97 | + return false; | |
| 98 | + } | |
| 91 | 99 | return !catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end); |
| 92 | 100 | } |
| 93 | 101 | |
| ... | ... | @@ -125,7 +133,9 @@ public class CatalogDataCatch { |
| 125 | 133 | |
| 126 | 134 | public void setChannelSyncEnd(String deviceId, String errorMsg) { |
| 127 | 135 | CatalogData catalogData = data.get(deviceId); |
| 128 | - if (catalogData == null)return; | |
| 136 | + if (catalogData == null) { | |
| 137 | + return; | |
| 138 | + } | |
| 129 | 139 | catalogData.setStatus(CatalogData.CatalogDataStatus.end); |
| 130 | 140 | catalogData.setErrorMsg(errorMsg); |
| 131 | 141 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java
| ... | ... | @@ -78,7 +78,9 @@ public class VideoStreamSessionManager { |
| 78 | 78 | |
| 79 | 79 | public ClientTransaction getTransactionByStream(String deviceId, String channelId, String stream){ |
| 80 | 80 | SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, null, stream); |
| 81 | - if (ssrcTransaction == null) return null; | |
| 81 | + if (ssrcTransaction == null) { | |
| 82 | + return null; | |
| 83 | + } | |
| 82 | 84 | byte[] transactionByteArray = ssrcTransaction.getTransaction(); |
| 83 | 85 | ClientTransaction clientTransaction = (ClientTransaction)SerializeUtils.deSerialize(transactionByteArray); |
| 84 | 86 | return clientTransaction; |
| ... | ... | @@ -86,39 +88,63 @@ public class VideoStreamSessionManager { |
| 86 | 88 | |
| 87 | 89 | public SIPDialog getDialogByStream(String deviceId, String channelId, String stream){ |
| 88 | 90 | SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, null, stream); |
| 89 | - if (ssrcTransaction == null) return null; | |
| 91 | + if (ssrcTransaction == null) { | |
| 92 | + return null; | |
| 93 | + } | |
| 90 | 94 | byte[] dialogByteArray = ssrcTransaction.getDialog(); |
| 91 | - if (dialogByteArray == null) return null; | |
| 95 | + if (dialogByteArray == null) { | |
| 96 | + return null; | |
| 97 | + } | |
| 92 | 98 | SIPDialog dialog = (SIPDialog)SerializeUtils.deSerialize(dialogByteArray); |
| 93 | 99 | return dialog; |
| 94 | 100 | } |
| 95 | 101 | |
| 96 | 102 | public SIPDialog getDialogByCallId(String deviceId, String channelId, String callID){ |
| 97 | 103 | SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, callID, null); |
| 98 | - if (ssrcTransaction == null) return null; | |
| 104 | + if (ssrcTransaction == null) { | |
| 105 | + return null; | |
| 106 | + } | |
| 99 | 107 | byte[] dialogByteArray = ssrcTransaction.getDialog(); |
| 100 | - if (dialogByteArray == null) return null; | |
| 108 | + if (dialogByteArray == null) { | |
| 109 | + return null; | |
| 110 | + } | |
| 101 | 111 | SIPDialog dialog = (SIPDialog)SerializeUtils.deSerialize(dialogByteArray); |
| 102 | 112 | return dialog; |
| 103 | 113 | } |
| 104 | 114 | |
| 105 | 115 | public SsrcTransaction getSsrcTransaction(String deviceId, String channelId, String callId, String stream){ |
| 106 | - if (StringUtils.isEmpty(callId)) callId ="*"; | |
| 107 | - if (StringUtils.isEmpty(stream)) stream ="*"; | |
| 116 | + if (StringUtils.isEmpty(callId)) { | |
| 117 | + callId ="*"; | |
| 118 | + } | |
| 119 | + if (StringUtils.isEmpty(stream)) { | |
| 120 | + stream ="*"; | |
| 121 | + } | |
| 108 | 122 | String key = VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetting.getServerId() + "_" + deviceId + "_" + channelId + "_" + callId+ "_" + stream; |
| 109 | 123 | List<Object> scanResult = redisUtil.scan(key); |
| 110 | - if (scanResult.size() == 0) return null; | |
| 124 | + if (scanResult.size() == 0) { | |
| 125 | + return null; | |
| 126 | + } | |
| 111 | 127 | return (SsrcTransaction)redisUtil.get((String) scanResult.get(0)); |
| 112 | 128 | } |
| 113 | 129 | |
| 114 | 130 | public List<SsrcTransaction> getSsrcTransactionForAll(String deviceId, String channelId, String callId, String stream){ |
| 115 | - if (StringUtils.isEmpty(deviceId)) deviceId ="*"; | |
| 116 | - if (StringUtils.isEmpty(channelId)) channelId ="*"; | |
| 117 | - if (StringUtils.isEmpty(callId)) callId ="*"; | |
| 118 | - if (StringUtils.isEmpty(stream)) stream ="*"; | |
| 131 | + if (StringUtils.isEmpty(deviceId)) { | |
| 132 | + deviceId ="*"; | |
| 133 | + } | |
| 134 | + if (StringUtils.isEmpty(channelId)) { | |
| 135 | + channelId ="*"; | |
| 136 | + } | |
| 137 | + if (StringUtils.isEmpty(callId)) { | |
| 138 | + callId ="*"; | |
| 139 | + } | |
| 140 | + if (StringUtils.isEmpty(stream)) { | |
| 141 | + stream ="*"; | |
| 142 | + } | |
| 119 | 143 | String key = VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetting.getServerId() + "_" + deviceId + "_" + channelId + "_" + callId+ "_" + stream; |
| 120 | 144 | List<Object> scanResult = redisUtil.scan(key); |
| 121 | - if (scanResult.size() == 0) return null; | |
| 145 | + if (scanResult.size() == 0) { | |
| 146 | + return null; | |
| 147 | + } | |
| 122 | 148 | List<SsrcTransaction> result = new ArrayList<>(); |
| 123 | 149 | for (Object keyObj : scanResult) { |
| 124 | 150 | result.add((SsrcTransaction)redisUtil.get((String) keyObj)); |
| ... | ... | @@ -128,19 +154,25 @@ public class VideoStreamSessionManager { |
| 128 | 154 | |
| 129 | 155 | public String getMediaServerId(String deviceId, String channelId, String stream){ |
| 130 | 156 | SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, null, stream); |
| 131 | - if (ssrcTransaction == null) return null; | |
| 157 | + if (ssrcTransaction == null) { | |
| 158 | + return null; | |
| 159 | + } | |
| 132 | 160 | return ssrcTransaction.getMediaServerId(); |
| 133 | 161 | } |
| 134 | 162 | |
| 135 | 163 | public String getSSRC(String deviceId, String channelId, String stream){ |
| 136 | 164 | SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, null, stream); |
| 137 | - if (ssrcTransaction == null) return null; | |
| 165 | + if (ssrcTransaction == null) { | |
| 166 | + return null; | |
| 167 | + } | |
| 138 | 168 | return ssrcTransaction.getSsrc(); |
| 139 | 169 | } |
| 140 | 170 | |
| 141 | 171 | public void remove(String deviceId, String channelId, String stream) { |
| 142 | 172 | SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, null, stream); |
| 143 | - if (ssrcTransaction == null) return; | |
| 173 | + if (ssrcTransaction == null) { | |
| 174 | + return; | |
| 175 | + } | |
| 144 | 176 | redisUtil.del(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetting.getServerId() + "_" |
| 145 | 177 | + deviceId + "_" + channelId + "_" + ssrcTransaction.getCallId() + "_" + ssrcTransaction.getStream()); |
| 146 | 178 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/task/ISubscribeTask.java
src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/CatalogSubscribeTask.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.task.impl; |
| 2 | 2 | |
| 3 | +import com.genersoft.iot.vmp.conf.DynamicTask; | |
| 3 | 4 | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 4 | 5 | import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask; |
| 5 | 6 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; |
| 6 | 7 | import org.slf4j.Logger; |
| 7 | 8 | import org.slf4j.LoggerFactory; |
| 8 | 9 | import org.springframework.scheduling.annotation.Async; |
| 10 | +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | |
| 9 | 11 | |
| 10 | 12 | import javax.sip.Dialog; |
| 11 | 13 | import javax.sip.DialogState; |
| ... | ... | @@ -15,6 +17,7 @@ import java.util.TimerTask; |
| 15 | 17 | |
| 16 | 18 | /** |
| 17 | 19 | * 目录订阅任务 |
| 20 | + * @author lin | |
| 18 | 21 | */ |
| 19 | 22 | public class CatalogSubscribeTask implements ISubscribeTask { |
| 20 | 23 | private final Logger logger = LoggerFactory.getLogger(CatalogSubscribeTask.class); |
| ... | ... | @@ -22,18 +25,21 @@ public class CatalogSubscribeTask implements ISubscribeTask { |
| 22 | 25 | private final ISIPCommander sipCommander; |
| 23 | 26 | private Dialog dialog; |
| 24 | 27 | |
| 25 | - private Timer timer ; | |
| 28 | + private DynamicTask dynamicTask; | |
| 26 | 29 | |
| 27 | - public CatalogSubscribeTask(Device device, ISIPCommander sipCommander) { | |
| 30 | + private String taskKey = "catalog-subscribe-timeout"; | |
| 31 | + | |
| 32 | + | |
| 33 | + public CatalogSubscribeTask(Device device, ISIPCommander sipCommander, DynamicTask dynamicTask) { | |
| 28 | 34 | this.device = device; |
| 29 | 35 | this.sipCommander = sipCommander; |
| 36 | + this.dynamicTask = dynamicTask; | |
| 30 | 37 | } |
| 31 | 38 | |
| 32 | 39 | @Override |
| 33 | 40 | public void run() { |
| 34 | - if (timer != null ) { | |
| 35 | - timer.cancel(); | |
| 36 | - timer = null; | |
| 41 | + if (dynamicTask.get(taskKey) != null) { | |
| 42 | + dynamicTask.stop(taskKey); | |
| 37 | 43 | } |
| 38 | 44 | sipCommander.catalogSubscribe(device, dialog, eventResult -> { |
| 39 | 45 | if (eventResult.dialog != null || eventResult.dialog.getState().equals(DialogState.CONFIRMED)) { |
| ... | ... | @@ -51,13 +57,7 @@ public class CatalogSubscribeTask implements ISubscribeTask { |
| 51 | 57 | dialog = null; |
| 52 | 58 | // 失败 |
| 53 | 59 | logger.warn("[目录订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg); |
| 54 | - timer = new Timer(); | |
| 55 | - timer.schedule(new TimerTask() { | |
| 56 | - @Override | |
| 57 | - public void run() { | |
| 58 | - CatalogSubscribeTask.this.run(); | |
| 59 | - } | |
| 60 | - }, 2000); | |
| 60 | + dynamicTask.startDelay(taskKey, CatalogSubscribeTask.this, 2000); | |
| 61 | 61 | }); |
| 62 | 62 | } |
| 63 | 63 | |
| ... | ... | @@ -71,9 +71,8 @@ public class CatalogSubscribeTask implements ISubscribeTask { |
| 71 | 71 | * TERMINATED-> Terminated Dialog状态-终止 |
| 72 | 72 | */ |
| 73 | 73 | logger.info("取消目录订阅时dialog状态为{}", DialogState.CONFIRMED); |
| 74 | - if (timer != null ) { | |
| 75 | - timer.cancel(); | |
| 76 | - timer = null; | |
| 74 | + if (dynamicTask.get(taskKey) != null) { | |
| 75 | + dynamicTask.stop(taskKey); | |
| 77 | 76 | } |
| 78 | 77 | if (dialog != null && dialog.getState().equals(DialogState.CONFIRMED)) { |
| 79 | 78 | device.setSubscribeCycleForCatalog(0); |
| ... | ... | @@ -95,7 +94,9 @@ public class CatalogSubscribeTask implements ISubscribeTask { |
| 95 | 94 | |
| 96 | 95 | @Override |
| 97 | 96 | public DialogState getDialogState() { |
| 98 | - if (dialog == null) return null; | |
| 97 | + if (dialog == null) { | |
| 98 | + return null; | |
| 99 | + } | |
| 99 | 100 | return dialog.getState(); |
| 100 | 101 | } |
| 101 | 102 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/MobilePositionSubscribeHandlerTask.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.task.impl; |
| 2 | 2 | |
| 3 | +import com.genersoft.iot.vmp.conf.DynamicTask; | |
| 3 | 4 | import com.genersoft.iot.vmp.gb28181.bean.*; |
| 4 | 5 | import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask; |
| 5 | 6 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; |
| ... | ... | @@ -15,6 +16,7 @@ import java.util.List; |
| 15 | 16 | |
| 16 | 17 | /** |
| 17 | 18 | * 向已经订阅(移动位置)的上级发送MobilePosition消息 |
| 19 | + * @author lin | |
| 18 | 20 | */ |
| 19 | 21 | public class MobilePositionSubscribeHandlerTask implements ISubscribeTask { |
| 20 | 22 | |
| ... | ... | @@ -25,10 +27,18 @@ public class MobilePositionSubscribeHandlerTask implements ISubscribeTask { |
| 25 | 27 | private ISIPCommanderForPlatform sipCommanderForPlatform; |
| 26 | 28 | private SubscribeHolder subscribeHolder; |
| 27 | 29 | private ParentPlatform platform; |
| 30 | + | |
| 28 | 31 | private String sn; |
| 29 | 32 | private String key; |
| 30 | 33 | |
| 31 | - public MobilePositionSubscribeHandlerTask(IRedisCatchStorage redisCatchStorage, ISIPCommanderForPlatform sipCommanderForPlatform, IVideoManagerStorage storager, String platformId, String sn, String key, SubscribeHolder subscribeInfo) { | |
| 34 | + public MobilePositionSubscribeHandlerTask(IRedisCatchStorage redisCatchStorage, | |
| 35 | + ISIPCommanderForPlatform sipCommanderForPlatform, | |
| 36 | + IVideoManagerStorage storager, | |
| 37 | + String platformId, | |
| 38 | + String sn, | |
| 39 | + String key, | |
| 40 | + SubscribeHolder subscribeInfo, | |
| 41 | + DynamicTask dynamicTask) { | |
| 32 | 42 | this.redisCatchStorage = redisCatchStorage; |
| 33 | 43 | this.storager = storager; |
| 34 | 44 | this.platform = storager.queryParentPlatByServerGBId(platformId); |
| ... | ... | @@ -41,7 +51,9 @@ public class MobilePositionSubscribeHandlerTask implements ISubscribeTask { |
| 41 | 51 | @Override |
| 42 | 52 | public void run() { |
| 43 | 53 | |
| 44 | - if (platform == null) return; | |
| 54 | + if (platform == null) { | |
| 55 | + return; | |
| 56 | + } | |
| 45 | 57 | SubscribeInfo subscribe = subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId()); |
| 46 | 58 | if (subscribe != null) { |
| 47 | 59 | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/MobilePositionSubscribeTask.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.task.impl; |
| 2 | 2 | |
| 3 | +import com.genersoft.iot.vmp.conf.DynamicTask; | |
| 3 | 4 | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 4 | 5 | import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask; |
| 5 | 6 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; |
| ... | ... | @@ -16,25 +17,26 @@ import java.util.TimerTask; |
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * 移动位置订阅的定时更新 |
| 20 | + * @author lin | |
| 19 | 21 | */ |
| 20 | 22 | public class MobilePositionSubscribeTask implements ISubscribeTask { |
| 21 | 23 | private final Logger logger = LoggerFactory.getLogger(MobilePositionSubscribeTask.class); |
| 22 | 24 | private Device device; |
| 23 | 25 | private ISIPCommander sipCommander; |
| 24 | 26 | private Dialog dialog; |
| 27 | + private DynamicTask dynamicTask; | |
| 28 | + private String taskKey = "mobile-position-subscribe-timeout"; | |
| 25 | 29 | |
| 26 | - private Timer timer ; | |
| 27 | - | |
| 28 | - public MobilePositionSubscribeTask(Device device, ISIPCommander sipCommander) { | |
| 30 | + public MobilePositionSubscribeTask(Device device, ISIPCommander sipCommander, DynamicTask dynamicTask) { | |
| 29 | 31 | this.device = device; |
| 30 | 32 | this.sipCommander = sipCommander; |
| 33 | + this.dynamicTask = dynamicTask; | |
| 31 | 34 | } |
| 32 | 35 | |
| 33 | 36 | @Override |
| 34 | 37 | public void run() { |
| 35 | - if (timer != null ) { | |
| 36 | - timer.cancel(); | |
| 37 | - timer = null; | |
| 38 | + if (dynamicTask.get(taskKey) != null) { | |
| 39 | + dynamicTask.stop(taskKey); | |
| 38 | 40 | } |
| 39 | 41 | sipCommander.mobilePositionSubscribe(device, dialog, eventResult -> { |
| 40 | 42 | // if (eventResult.dialog != null || eventResult.dialog.getState().equals(DialogState.CONFIRMED)) { |
| ... | ... | @@ -52,13 +54,7 @@ public class MobilePositionSubscribeTask implements ISubscribeTask { |
| 52 | 54 | dialog = null; |
| 53 | 55 | // 失败 |
| 54 | 56 | logger.warn("[移动位置订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg); |
| 55 | - timer = new Timer(); | |
| 56 | - timer.schedule(new TimerTask() { | |
| 57 | - @Override | |
| 58 | - public void run() { | |
| 59 | - MobilePositionSubscribeTask.this.run(); | |
| 60 | - } | |
| 61 | - }, 2000); | |
| 57 | + dynamicTask.startDelay(taskKey, MobilePositionSubscribeTask.this, 2000); | |
| 62 | 58 | }); |
| 63 | 59 | |
| 64 | 60 | } |
| ... | ... | @@ -72,9 +68,8 @@ public class MobilePositionSubscribeTask implements ISubscribeTask { |
| 72 | 68 | * COMPLETED-> Completed Dialog状态-已完成 |
| 73 | 69 | * TERMINATED-> Terminated Dialog状态-终止 |
| 74 | 70 | */ |
| 75 | - if (timer != null ) { | |
| 76 | - timer.cancel(); | |
| 77 | - timer = null; | |
| 71 | + if (dynamicTask.get(taskKey) != null) { | |
| 72 | + dynamicTask.stop(taskKey); | |
| 78 | 73 | } |
| 79 | 74 | if (dialog != null && dialog.getState().equals(DialogState.CONFIRMED)) { |
| 80 | 75 | logger.info("取消移动订阅时dialog状态为{}", dialog.getState()); |
| ... | ... | @@ -96,7 +91,9 @@ public class MobilePositionSubscribeTask implements ISubscribeTask { |
| 96 | 91 | } |
| 97 | 92 | @Override |
| 98 | 93 | public DialogState getDialogState() { |
| 99 | - if (dialog == null) return null; | |
| 94 | + if (dialog == null) { | |
| 95 | + return null; | |
| 96 | + } | |
| 100 | 97 | return dialog.getState(); |
| 101 | 98 | } |
| 102 | 99 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorObserver.java
| ... | ... | @@ -62,7 +62,7 @@ public class SIPProcessorObserver implements ISIPProcessorObserver { |
| 62 | 62 | * @param processor 处理程序 |
| 63 | 63 | */ |
| 64 | 64 | public void addTimeoutProcessor(ITimeoutProcessor processor) { |
| 65 | - this.timeoutProcessor = processor; | |
| 65 | + timeoutProcessor = processor; | |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/callback/CheckForAllRecordsThread.java
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/callback/DeferredResultHolder.java
| ... | ... | @@ -65,12 +65,16 @@ public class DeferredResultHolder { |
| 65 | 65 | |
| 66 | 66 | public DeferredResult get(String key, String id) { |
| 67 | 67 | Map<String, DeferredResult> deferredResultMap = map.get(key); |
| 68 | - if (deferredResultMap == null) return null; | |
| 68 | + if (deferredResultMap == null) { | |
| 69 | + return null; | |
| 70 | + } | |
| 69 | 71 | return deferredResultMap.get(id); |
| 70 | 72 | } |
| 71 | 73 | |
| 72 | 74 | public boolean exist(String key, String id){ |
| 73 | - if (key == null) return false; | |
| 75 | + if (key == null) { | |
| 76 | + return false; | |
| 77 | + } | |
| 74 | 78 | Map<String, DeferredResult> deferredResultMap = map.get(key); |
| 75 | 79 | if (id == null) { |
| 76 | 80 | return deferredResultMap != null; | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java
| ... | ... | @@ -68,9 +68,6 @@ public class SIPRequestHeaderPlarformProvider { |
| 68 | 68 | toHeader, viaHeaders, maxForwards); |
| 69 | 69 | |
| 70 | 70 | List<String> agentParam = new ArrayList<>(); |
| 71 | - agentParam.add("wvp-pro"); | |
| 72 | - UserAgentHeader userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam); | |
| 73 | - request.addHeader(userAgentHeader); | |
| 74 | 71 | |
| 75 | 72 | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); |
| 76 | 73 | request.setContent(content, contentTypeHeader); |
| ... | ... | @@ -115,10 +112,6 @@ public class SIPRequestHeaderPlarformProvider { |
| 115 | 112 | ExpiresHeader expires = sipFactory.createHeaderFactory().createExpiresHeader(Integer.parseInt(platform.getExpires())); |
| 116 | 113 | request.addHeader(expires); |
| 117 | 114 | |
| 118 | - List<String> agentParam = new ArrayList<>(); | |
| 119 | - agentParam.add("wvp-pro"); | |
| 120 | - UserAgentHeader userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam); | |
| 121 | - request.addHeader(userAgentHeader); | |
| 122 | 115 | |
| 123 | 116 | return request; |
| 124 | 117 | } |
| ... | ... | @@ -226,10 +219,6 @@ public class SIPRequestHeaderPlarformProvider { |
| 226 | 219 | messageFactory.setDefaultContentEncodingCharset(parentPlatform.getCharacterSet()); |
| 227 | 220 | request = messageFactory.createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader, |
| 228 | 221 | toHeader, viaHeaders, maxForwards); |
| 229 | - List<String> agentParam = new ArrayList<>(); | |
| 230 | - agentParam.add("wvp-pro"); | |
| 231 | - UserAgentHeader userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam); | |
| 232 | - request.addHeader(userAgentHeader); | |
| 233 | 222 | |
| 234 | 223 | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); |
| 235 | 224 | request.setContent(content, contentTypeHeader); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java
| ... | ... | @@ -228,9 +228,13 @@ public class SIPRequestHeaderProvider { |
| 228 | 228 | public Request createInfoRequest(Device device, StreamInfo streamInfo, String content) |
| 229 | 229 | throws PeerUnavailableException, ParseException, InvalidArgumentException { |
| 230 | 230 | Request request = null; |
| 231 | - if (streamInfo == null) return null; | |
| 231 | + if (streamInfo == null) { | |
| 232 | + return null; | |
| 233 | + } | |
| 232 | 234 | Dialog dialog = streamSession.getDialogByStream(streamInfo.getDeviceID(), streamInfo.getChannelId(), streamInfo.getStream()); |
| 233 | - if (dialog == null) return null; | |
| 235 | + if (dialog == null) { | |
| 236 | + return null; | |
| 237 | + } | |
| 234 | 238 | |
| 235 | 239 | SipURI requestLine = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), |
| 236 | 240 | device.getHostAddress()); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
| ... | ... | @@ -27,6 +27,7 @@ import org.slf4j.Logger; |
| 27 | 27 | import org.slf4j.LoggerFactory; |
| 28 | 28 | import org.springframework.beans.factory.annotation.Autowired; |
| 29 | 29 | import org.springframework.beans.factory.annotation.Qualifier; |
| 30 | +import org.springframework.boot.SpringBootVersion; | |
| 30 | 31 | import org.springframework.context.annotation.DependsOn; |
| 31 | 32 | import org.springframework.stereotype.Component; |
| 32 | 33 | import org.springframework.util.StringUtils; |
| ... | ... | @@ -37,7 +38,9 @@ import javax.sip.header.*; |
| 37 | 38 | import javax.sip.message.Request; |
| 38 | 39 | import java.lang.reflect.Field; |
| 39 | 40 | import java.text.ParseException; |
| 41 | +import java.util.ArrayList; | |
| 40 | 42 | import java.util.HashSet; |
| 43 | +import java.util.List; | |
| 41 | 44 | |
| 42 | 45 | /** |
| 43 | 46 | * @description:设备能力接口,用于定义设备的控制、查询能力 |
| ... | ... | @@ -49,7 +52,7 @@ import java.util.HashSet; |
| 49 | 52 | public class SIPCommander implements ISIPCommander { |
| 50 | 53 | |
| 51 | 54 | private final Logger logger = LoggerFactory.getLogger(SIPCommander.class); |
| 52 | - | |
| 55 | + | |
| 53 | 56 | @Autowired |
| 54 | 57 | private SipConfig sipConfig; |
| 55 | 58 | |
| ... | ... | @@ -340,13 +343,15 @@ public class SIPCommander implements ISIPCommander { |
| 340 | 343 | * @param channelId 预览通道 |
| 341 | 344 | * @param event hook订阅 |
| 342 | 345 | * @param errorEvent sip错误订阅 |
| 343 | - */ | |
| 346 | + */ | |
| 344 | 347 | @Override |
| 345 | 348 | public void playStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId, |
| 346 | 349 | ZLMHttpHookSubscribe.Event event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) { |
| 347 | 350 | String streamId = ssrcInfo.getStream(); |
| 348 | 351 | try { |
| 349 | - if (device == null) return; | |
| 352 | + if (device == null) { | |
| 353 | + return; | |
| 354 | + } | |
| 350 | 355 | String streamMode = device.getStreamMode().toUpperCase(); |
| 351 | 356 | |
| 352 | 357 | logger.info("{} 分配的ZLM为: {} [{}:{}]", streamId, mediaServerItem.getId(), mediaServerItem.getIp(), ssrcInfo.getPort()); |
| ... | ... | @@ -694,7 +699,9 @@ public class SIPCommander implements ISIPCommander { |
| 694 | 699 | if (callId != null) { |
| 695 | 700 | dialog = streamSession.getDialogByCallId(deviceId, channelId, callId); |
| 696 | 701 | }else { |
| 697 | - if (stream == null) return; | |
| 702 | + if (stream == null) { | |
| 703 | + return; | |
| 704 | + } | |
| 698 | 705 | dialog = streamSession.getDialogByStream(deviceId, channelId, stream); |
| 699 | 706 | } |
| 700 | 707 | if (ssrcTransaction != null) { |
| ... | ... | @@ -1454,6 +1461,7 @@ public class SIPCommander implements ISIPCommander { |
| 1454 | 1461 | * @param device 视频设备 |
| 1455 | 1462 | * @return true = 命令发送成功 |
| 1456 | 1463 | */ |
| 1464 | + @Override | |
| 1457 | 1465 | public boolean mobilePositionSubscribe(Device device, Dialog dialog, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent) { |
| 1458 | 1466 | try { |
| 1459 | 1467 | StringBuffer subscribePostitionXml = new StringBuffer(200); |
| ... | ... | @@ -1505,6 +1513,7 @@ public class SIPCommander implements ISIPCommander { |
| 1505 | 1513 | * @param endTime 报警发生终止时间(可选) |
| 1506 | 1514 | * @return true = 命令发送成功 |
| 1507 | 1515 | */ |
| 1516 | + @Override | |
| 1508 | 1517 | public boolean alarmSubscribe(Device device, int expires, String startPriority, String endPriority, String alarmMethod, String alarmType, String startTime, String endTime) { |
| 1509 | 1518 | try { |
| 1510 | 1519 | StringBuffer cmdXml = new StringBuffer(200); |
| ... | ... | @@ -1637,7 +1646,18 @@ public class SIPCommander implements ISIPCommander { |
| 1637 | 1646 | } else if("UDP".equals(device.getTransport())) { |
| 1638 | 1647 | clientTransaction = udpSipProvider.getNewClientTransaction(request); |
| 1639 | 1648 | } |
| 1640 | - | |
| 1649 | + if (request.getHeader(UserAgentHeader.NAME) == null) { | |
| 1650 | + List<String> agentParam = new ArrayList<>(); | |
| 1651 | + agentParam.add("wvp-pro"); | |
| 1652 | + // TODO 添加版本信息以及日期 | |
| 1653 | + UserAgentHeader userAgentHeader = null; | |
| 1654 | + try { | |
| 1655 | + userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam); | |
| 1656 | + } catch (ParseException e) { | |
| 1657 | + throw new RuntimeException(e); | |
| 1658 | + } | |
| 1659 | + request.addHeader(userAgentHeader); | |
| 1660 | + } | |
| 1641 | 1661 | CallIdHeader callIdHeader = (CallIdHeader)request.getHeader(CallIdHeader.NAME); |
| 1642 | 1662 | // 添加错误订阅 |
| 1643 | 1663 | if (errorEvent != null) { |
| ... | ... | @@ -1701,7 +1721,9 @@ public class SIPCommander implements ISIPCommander { |
| 1701 | 1721 | content.append("CSeq: " + cseq + "\r\n"); |
| 1702 | 1722 | content.append("Range: npt=now-\r\n"); |
| 1703 | 1723 | Request request = headerProvider.createInfoRequest(device, streamInfo, content.toString()); |
| 1704 | - if (request == null) return; | |
| 1724 | + if (request == null) { | |
| 1725 | + return; | |
| 1726 | + } | |
| 1705 | 1727 | logger.info(request.toString()); |
| 1706 | 1728 | ClientTransaction clientTransaction = null; |
| 1707 | 1729 | if ("TCP".equals(device.getTransport())) { |
| ... | ... | @@ -1730,7 +1752,9 @@ public class SIPCommander implements ISIPCommander { |
| 1730 | 1752 | content.append("Range: npt=" + Math.abs(seekTime) + "-\r\n"); |
| 1731 | 1753 | |
| 1732 | 1754 | Request request = headerProvider.createInfoRequest(device, streamInfo, content.toString()); |
| 1733 | - if (request == null) return; | |
| 1755 | + if (request == null) { | |
| 1756 | + return; | |
| 1757 | + } | |
| 1734 | 1758 | logger.info(request.toString()); |
| 1735 | 1759 | ClientTransaction clientTransaction = null; |
| 1736 | 1760 | if ("TCP".equals(device.getTransport())) { |
| ... | ... | @@ -1758,7 +1782,9 @@ public class SIPCommander implements ISIPCommander { |
| 1758 | 1782 | content.append("CSeq: " + cseq + "\r\n"); |
| 1759 | 1783 | content.append("Scale: " + String.format("%.1f",speed) + "\r\n"); |
| 1760 | 1784 | Request request = headerProvider.createInfoRequest(device, streamInfo, content.toString()); |
| 1761 | - if (request == null) return; | |
| 1785 | + if (request == null) { | |
| 1786 | + return; | |
| 1787 | + } | |
| 1762 | 1788 | logger.info(request.toString()); |
| 1763 | 1789 | ClientTransaction clientTransaction = null; |
| 1764 | 1790 | if ("TCP".equals(device.getTransport())) { |
| ... | ... | @@ -1824,7 +1850,9 @@ public class SIPCommander implements ISIPCommander { |
| 1824 | 1850 | // 设置编码, 防止中文乱码 |
| 1825 | 1851 | messageFactory.setDefaultContentEncodingCharset(characterSet); |
| 1826 | 1852 | Dialog dialog = subscribeInfo.getDialog(); |
| 1827 | - if (dialog == null || !dialog.getState().equals(DialogState.CONFIRMED)) return; | |
| 1853 | + if (dialog == null || !dialog.getState().equals(DialogState.CONFIRMED)) { | |
| 1854 | + return; | |
| 1855 | + } | |
| 1828 | 1856 | SIPRequest notifyRequest = (SIPRequest)dialog.createRequest(Request.NOTIFY); |
| 1829 | 1857 | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); |
| 1830 | 1858 | notifyRequest.setContent(catalogXmlContent, contentTypeHeader); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
| ... | ... | @@ -529,7 +529,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { |
| 529 | 529 | // 设置编码, 防止中文乱码 |
| 530 | 530 | messageFactory.setDefaultContentEncodingCharset(characterSet); |
| 531 | 531 | Dialog dialog = subscribeInfo.getDialog(); |
| 532 | - if (dialog == null || !dialog.getState().equals(DialogState.CONFIRMED)) return; | |
| 532 | + if (dialog == null || !dialog.getState().equals(DialogState.CONFIRMED)) { | |
| 533 | + return; | |
| 534 | + } | |
| 533 | 535 | SIPRequest notifyRequest = (SIPRequest)dialog.createRequest(Request.NOTIFY); |
| 534 | 536 | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); |
| 535 | 537 | notifyRequest.setContent(catalogXmlContent, contentTypeHeader); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/SIPRequestProcessorParent.java
| ... | ... | @@ -139,7 +139,9 @@ public abstract class SIPRequestProcessorParent { |
| 139 | 139 | serverTransaction.sendResponse(response); |
| 140 | 140 | if (statusCode >= 200 && !"NOTIFY".equals(evt.getRequest().getMethod())) { |
| 141 | 141 | |
| 142 | - if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | |
| 142 | + if (serverTransaction.getDialog() != null) { | |
| 143 | + serverTransaction.getDialog().delete(); | |
| 144 | + } | |
| 143 | 145 | } |
| 144 | 146 | } |
| 145 | 147 | |
| ... | ... | @@ -149,7 +151,9 @@ public abstract class SIPRequestProcessorParent { |
| 149 | 151 | ServerTransaction serverTransaction = getServerTransaction(evt); |
| 150 | 152 | serverTransaction.sendResponse(response); |
| 151 | 153 | if (statusCode >= 200 && !"NOTIFY".equals(evt.getRequest().getMethod())) { |
| 152 | - if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | |
| 154 | + if (serverTransaction.getDialog() != null) { | |
| 155 | + serverTransaction.getDialog().delete(); | |
| 156 | + } | |
| 153 | 157 | } |
| 154 | 158 | } |
| 155 | 159 | |
| ... | ... | @@ -215,7 +219,9 @@ public abstract class SIPRequestProcessorParent { |
| 215 | 219 | return getRootElement(evt, "gb2312"); |
| 216 | 220 | } |
| 217 | 221 | public Element getRootElement(RequestEvent evt, String charset) throws DocumentException { |
| 218 | - if (charset == null) charset = "gb2312"; | |
| 222 | + if (charset == null) { | |
| 223 | + charset = "gb2312"; | |
| 224 | + } | |
| 219 | 225 | Request request = evt.getRequest(); |
| 220 | 226 | SAXReader reader = new SAXReader(); |
| 221 | 227 | reader.setEncoding(charset); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/AckRequestProcessor.java
| ... | ... | @@ -72,7 +72,9 @@ public class AckRequestProcessor extends SIPRequestProcessorParent implements In |
| 72 | 72 | public void process(RequestEvent evt) { |
| 73 | 73 | Dialog dialog = evt.getDialog(); |
| 74 | 74 | CallIdHeader callIdHeader = (CallIdHeader)evt.getRequest().getHeader(CallIdHeader.NAME); |
| 75 | - if (dialog == null) return; | |
| 75 | + if (dialog == null) { | |
| 76 | + return; | |
| 77 | + } | |
| 76 | 78 | if (dialog.getState()== DialogState.CONFIRMED) { |
| 77 | 79 | String platformGbId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(FromHeader.NAME)).getAddress().getURI()).getUser(); |
| 78 | 80 | logger.info("ACK请求: platformGbId->{}", platformGbId); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/ByeRequestProcessor.java
| ... | ... | @@ -81,7 +81,9 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In |
| 81 | 81 | responseAck(evt, Response.OK); |
| 82 | 82 | Dialog dialog = evt.getDialog(); |
| 83 | 83 | CallIdHeader callIdHeader = (CallIdHeader)evt.getRequest().getHeader(CallIdHeader.NAME); |
| 84 | - if (dialog == null) return; | |
| 84 | + if (dialog == null) { | |
| 85 | + return; | |
| 86 | + } | |
| 85 | 87 | if (dialog.getState().equals(DialogState.TERMINATED)) { |
| 86 | 88 | String platformGbId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(FromHeader.NAME)).getAddress().getURI()).getUser(); |
| 87 | 89 | String channelId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(ToHeader.NAME)).getAddress().getURI()).getUser(); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
| ... | ... | @@ -321,7 +321,9 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements |
| 321 | 321 | response = getMessageFactory().createResponse(event.statusCode, evt.getRequest()); |
| 322 | 322 | ServerTransaction serverTransaction = getServerTransaction(evt); |
| 323 | 323 | serverTransaction.sendResponse(response); |
| 324 | - if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | |
| 324 | + if (serverTransaction.getDialog() != null) { | |
| 325 | + serverTransaction.getDialog().delete(); | |
| 326 | + } | |
| 325 | 327 | } catch (ParseException | SipException | InvalidArgumentException e) { |
| 326 | 328 | e.printStackTrace(); |
| 327 | 329 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java
| ... | ... | @@ -5,7 +5,6 @@ import com.genersoft.iot.vmp.common.VideoManagerConstants; |
| 5 | 5 | import com.genersoft.iot.vmp.conf.SipConfig; |
| 6 | 6 | import com.genersoft.iot.vmp.conf.UserSetting; |
| 7 | 7 | import com.genersoft.iot.vmp.gb28181.bean.*; |
| 8 | -import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; | |
| 9 | 8 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 10 | 9 | import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; |
| 11 | 10 | import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; |
| ... | ... | @@ -19,7 +18,6 @@ import com.genersoft.iot.vmp.gb28181.utils.SipUtils; |
| 19 | 18 | import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; |
| 20 | 19 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 21 | 20 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| 22 | -import com.genersoft.iot.vmp.utils.GpsUtil; | |
| 23 | 21 | import com.genersoft.iot.vmp.utils.redis.RedisUtil; |
| 24 | 22 | import org.dom4j.DocumentException; |
| 25 | 23 | import org.dom4j.Element; |
| ... | ... | @@ -65,10 +63,6 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements |
| 65 | 63 | @Autowired |
| 66 | 64 | private EventPublisher publisher; |
| 67 | 65 | |
| 68 | - @Autowired | |
| 69 | - private DeviceOffLineDetector offLineDetector; | |
| 70 | - | |
| 71 | - | |
| 72 | 66 | private String method = "NOTIFY"; |
| 73 | 67 | |
| 74 | 68 | @Autowired |
| ... | ... | @@ -240,7 +234,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements |
| 240 | 234 | |
| 241 | 235 | // 回复200 OK |
| 242 | 236 | responseAck(evt, Response.OK); |
| 243 | - if (offLineDetector.isOnline(deviceId)) { | |
| 237 | + if (redisCatchStorage.deviceIsOnline(deviceId)) { | |
| 244 | 238 | publisher.deviceAlarmEventPublish(deviceAlarm); |
| 245 | 239 | } |
| 246 | 240 | } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { |
| ... | ... | @@ -331,7 +325,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements |
| 331 | 325 | |
| 332 | 326 | } |
| 333 | 327 | |
| 334 | - if (!offLineDetector.isOnline(deviceId)) { | |
| 328 | + if (!redisCatchStorage.deviceIsOnline(deviceId)) { | |
| 335 | 329 | publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_MESSAGE); |
| 336 | 330 | } |
| 337 | 331 | } |
| ... | ... | @@ -357,10 +351,6 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements |
| 357 | 351 | public void setDeferredResultHolder(DeferredResultHolder deferredResultHolder) { |
| 358 | 352 | } |
| 359 | 353 | |
| 360 | - public void setOffLineDetector(DeviceOffLineDetector offLineDetector) { | |
| 361 | - this.offLineDetector = offLineDetector; | |
| 362 | - } | |
| 363 | - | |
| 364 | 354 | public IRedisCatchStorage getRedisCatchStorage() { |
| 365 | 355 | return redisCatchStorage; |
| 366 | 356 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java
| ... | ... | @@ -130,7 +130,9 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen |
| 130 | 130 | response = getMessageFactory().createResponse(Response.BAD_REQUEST, request); |
| 131 | 131 | ServerTransaction serverTransaction = getServerTransaction(evt); |
| 132 | 132 | serverTransaction.sendResponse(response); |
| 133 | - if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | |
| 133 | + if (serverTransaction.getDialog() != null) { | |
| 134 | + serverTransaction.getDialog().delete(); | |
| 135 | + } | |
| 134 | 136 | return; |
| 135 | 137 | } |
| 136 | 138 | // 添加Contact头 |
| ... | ... | @@ -195,7 +197,9 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen |
| 195 | 197 | return; |
| 196 | 198 | } |
| 197 | 199 | serverTransaction.sendResponse(response); |
| 198 | - if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | |
| 200 | + if (serverTransaction.getDialog() != null) { | |
| 201 | + serverTransaction.getDialog().delete(); | |
| 202 | + } | |
| 199 | 203 | } |
| 200 | 204 | |
| 201 | 205 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/SubscribeRequestProcessor.java
| ... | ... | @@ -35,23 +35,18 @@ import java.text.ParseException; |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * SIP命令类型: SUBSCRIBE请求 |
| 38 | + * @author lin | |
| 38 | 39 | */ |
| 39 | 40 | @Component |
| 40 | 41 | public class SubscribeRequestProcessor extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor { |
| 41 | 42 | |
| 42 | - private Logger logger = LoggerFactory.getLogger(SubscribeRequestProcessor.class); | |
| 43 | - private String method = "SUBSCRIBE"; | |
| 43 | + private final Logger logger = LoggerFactory.getLogger(SubscribeRequestProcessor.class); | |
| 44 | + private final String method = "SUBSCRIBE"; | |
| 44 | 45 | |
| 45 | 46 | @Autowired |
| 46 | 47 | private SIPProcessorObserver sipProcessorObserver; |
| 47 | 48 | |
| 48 | 49 | @Autowired |
| 49 | - private IRedisCatchStorage redisCatchStorage; | |
| 50 | - | |
| 51 | - @Autowired | |
| 52 | - private ISIPCommanderForPlatform sipCommanderForPlatform; | |
| 53 | - | |
| 54 | - @Autowired | |
| 55 | 50 | private IVideoManagerStorage storager; |
| 56 | 51 | |
| 57 | 52 | @Lazy |
| ... | ... | @@ -82,7 +77,7 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme |
| 82 | 77 | /** |
| 83 | 78 | * 处理SUBSCRIBE请求 |
| 84 | 79 | * |
| 85 | - * @param evt | |
| 80 | + * @param evt 事件 | |
| 86 | 81 | */ |
| 87 | 82 | @Override |
| 88 | 83 | public void process(RequestEvent evt) { |
| ... | ... | @@ -101,13 +96,12 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme |
| 101 | 96 | } else { |
| 102 | 97 | logger.info("接收到消息:" + cmd); |
| 103 | 98 | |
| 104 | - Response response = null; | |
| 105 | - response = getMessageFactory().createResponse(200, request); | |
| 99 | + Response response = getMessageFactory().createResponse(200, request); | |
| 106 | 100 | if (response != null) { |
| 107 | 101 | ExpiresHeader expireHeader = getHeaderFactory().createExpiresHeader(30); |
| 108 | 102 | response.setExpires(expireHeader); |
| 109 | 103 | } |
| 110 | - logger.info("response : " + response.toString()); | |
| 104 | + logger.info("response : " + response); | |
| 111 | 105 | ServerTransaction transaction = getServerTransaction(evt); |
| 112 | 106 | if (transaction != null) { |
| 113 | 107 | transaction.sendResponse(response); |
| ... | ... | @@ -117,13 +111,7 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme |
| 117 | 111 | logger.info("processRequest serverTransactionId is null."); |
| 118 | 112 | } |
| 119 | 113 | } |
| 120 | - } catch (ParseException e) { | |
| 121 | - e.printStackTrace(); | |
| 122 | - } catch (SipException e) { | |
| 123 | - e.printStackTrace(); | |
| 124 | - } catch (InvalidArgumentException e) { | |
| 125 | - e.printStackTrace(); | |
| 126 | - } catch (DocumentException e) { | |
| 114 | + } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) { | |
| 127 | 115 | e.printStackTrace(); |
| 128 | 116 | } |
| 129 | 117 | |
| ... | ... | @@ -134,14 +122,14 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme |
| 134 | 122 | */ |
| 135 | 123 | private void processNotifyMobilePosition(RequestEvent evt, Element rootElement) throws SipException { |
| 136 | 124 | String platformId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); |
| 137 | - String deviceID = XmlUtil.getText(rootElement, "DeviceID"); | |
| 125 | + String deviceId = XmlUtil.getText(rootElement, "DeviceID"); | |
| 138 | 126 | ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId); |
| 139 | 127 | SubscribeInfo subscribeInfo = new SubscribeInfo(evt, platformId); |
| 140 | 128 | if (platform == null) { |
| 141 | 129 | return; |
| 142 | 130 | } |
| 143 | 131 | if (evt.getServerTransaction() == null) { |
| 144 | - ServerTransaction serverTransaction = platform.getTransport().equals("TCP") ? tcpSipProvider.getNewServerTransaction(evt.getRequest()) | |
| 132 | + ServerTransaction serverTransaction = "TCP".equals(platform.getTransport()) ? tcpSipProvider.getNewServerTransaction(evt.getRequest()) | |
| 145 | 133 | : udpSipProvider.getNewServerTransaction(evt.getRequest()); |
| 146 | 134 | subscribeInfo.setTransaction(serverTransaction); |
| 147 | 135 | Dialog dialog = serverTransaction.getDialog(); |
| ... | ... | @@ -154,13 +142,14 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme |
| 154 | 142 | resultXml.append("<?xml version=\"1.0\" ?>\r\n") |
| 155 | 143 | .append("<Response>\r\n") |
| 156 | 144 | .append("<CmdType>MobilePosition</CmdType>\r\n") |
| 157 | - .append("<SN>" + sn + "</SN>\r\n") | |
| 158 | - .append("<DeviceID>" + deviceID + "</DeviceID>\r\n") | |
| 145 | + .append("<SN>").append(sn).append("</SN>\r\n") | |
| 146 | + .append("<DeviceID>").append(deviceId).append("</DeviceID>\r\n") | |
| 159 | 147 | .append("<Result>OK</Result>\r\n") |
| 160 | 148 | .append("</Response>\r\n"); |
| 161 | 149 | |
| 162 | 150 | if (subscribeInfo.getExpires() > 0) { |
| 163 | - String interval = XmlUtil.getText(rootElement, "Interval"); // GPS上报时间间隔 | |
| 151 | + // GPS上报时间间隔 | |
| 152 | + String interval = XmlUtil.getText(rootElement, "Interval"); | |
| 164 | 153 | if (interval == null) { |
| 165 | 154 | subscribeInfo.setGpsInterval(5); |
| 166 | 155 | }else { |
| ... | ... | @@ -169,15 +158,7 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme |
| 169 | 158 | |
| 170 | 159 | subscribeInfo.setSn(sn); |
| 171 | 160 | subscribeHolder.putMobilePositionSubscribe(platformId, subscribeInfo); |
| 172 | -// if (subscribeHolder.getMobilePositionSubscribe(platformId) == null ) { | |
| 173 | -// subscribeHolder.putMobilePositionSubscribe(platformId, subscribeInfo); | |
| 174 | -// }else { | |
| 175 | -// if (subscribeHolder.getMobilePositionSubscribe(platformId).getDialog() != null | |
| 176 | -// && subscribeHolder.getMobilePositionSubscribe(platformId).getDialog().getState() != null | |
| 177 | -// && !subscribeHolder.getMobilePositionSubscribe(platformId).getDialog().getState().equals(DialogState.CONFIRMED)) { | |
| 178 | -// subscribeHolder.putMobilePositionSubscribe(platformId, subscribeInfo); | |
| 179 | -// } | |
| 180 | -// } | |
| 161 | + | |
| 181 | 162 | }else if (subscribeInfo.getExpires() == 0) { |
| 182 | 163 | subscribeHolder.removeMobilePositionSubscribe(platformId); |
| 183 | 164 | } |
| ... | ... | @@ -185,11 +166,7 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme |
| 185 | 166 | try { |
| 186 | 167 | ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId); |
| 187 | 168 | responseXmlAck(evt, resultXml.toString(), parentPlatform); |
| 188 | - } catch (SipException e) { | |
| 189 | - e.printStackTrace(); | |
| 190 | - } catch (InvalidArgumentException e) { | |
| 191 | - e.printStackTrace(); | |
| 192 | - } catch (ParseException e) { | |
| 169 | + } catch (SipException | InvalidArgumentException | ParseException e) { | |
| 193 | 170 | e.printStackTrace(); |
| 194 | 171 | } |
| 195 | 172 | } |
| ... | ... | @@ -200,12 +177,14 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme |
| 200 | 177 | |
| 201 | 178 | private void processNotifyCatalogList(RequestEvent evt, Element rootElement) throws SipException { |
| 202 | 179 | String platformId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); |
| 203 | - String deviceID = XmlUtil.getText(rootElement, "DeviceID"); | |
| 180 | + String deviceId = XmlUtil.getText(rootElement, "DeviceID"); | |
| 204 | 181 | ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId); |
| 205 | - if (platform == null)return; | |
| 182 | + if (platform == null){ | |
| 183 | + return; | |
| 184 | + } | |
| 206 | 185 | SubscribeInfo subscribeInfo = new SubscribeInfo(evt, platformId); |
| 207 | 186 | if (evt.getServerTransaction() == null) { |
| 208 | - ServerTransaction serverTransaction = platform.getTransport().equals("TCP") ? tcpSipProvider.getNewServerTransaction(evt.getRequest()) | |
| 187 | + ServerTransaction serverTransaction = "TCP".equals(platform.getTransport()) ? tcpSipProvider.getNewServerTransaction(evt.getRequest()) | |
| 209 | 188 | : udpSipProvider.getNewServerTransaction(evt.getRequest()); |
| 210 | 189 | subscribeInfo.setTransaction(serverTransaction); |
| 211 | 190 | Dialog dialog = serverTransaction.getDialog(); |
| ... | ... | @@ -213,13 +192,13 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme |
| 213 | 192 | subscribeInfo.setDialog(dialog); |
| 214 | 193 | } |
| 215 | 194 | String sn = XmlUtil.getText(rootElement, "SN"); |
| 216 | - logger.info("[回复 目录订阅]: {}/{}", platformId, deviceID); | |
| 195 | + logger.info("[回复 目录订阅]: {}/{}", platformId, deviceId); | |
| 217 | 196 | StringBuilder resultXml = new StringBuilder(200); |
| 218 | 197 | resultXml.append("<?xml version=\"1.0\" ?>\r\n") |
| 219 | 198 | .append("<Response>\r\n") |
| 220 | 199 | .append("<CmdType>Catalog</CmdType>\r\n") |
| 221 | - .append("<SN>" + sn + "</SN>\r\n") | |
| 222 | - .append("<DeviceID>" + deviceID + "</DeviceID>\r\n") | |
| 200 | + .append("<SN>").append(sn).append("</SN>\r\n") | |
| 201 | + .append("<DeviceID>").append(deviceId).append("</DeviceID>\r\n") | |
| 223 | 202 | .append("<Result>OK</Result>\r\n") |
| 224 | 203 | .append("</Response>\r\n"); |
| 225 | 204 | |
| ... | ... | @@ -232,11 +211,7 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme |
| 232 | 211 | try { |
| 233 | 212 | ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId); |
| 234 | 213 | responseXmlAck(evt, resultXml.toString(), parentPlatform); |
| 235 | - } catch (SipException e) { | |
| 236 | - e.printStackTrace(); | |
| 237 | - } catch (InvalidArgumentException e) { | |
| 238 | - e.printStackTrace(); | |
| 239 | - } catch (ParseException e) { | |
| 214 | + } catch (SipException | InvalidArgumentException | ParseException e) { | |
| 240 | 215 | e.printStackTrace(); |
| 241 | 216 | } |
| 242 | 217 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd; |
| 2 | 2 | |
| 3 | -import com.alibaba.fastjson.JSON; | |
| 4 | 3 | import com.genersoft.iot.vmp.conf.SipConfig; |
| 5 | 4 | import com.genersoft.iot.vmp.conf.UserSetting; |
| 6 | 5 | import com.genersoft.iot.vmp.gb28181.bean.*; |
| 7 | -import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; | |
| 8 | 6 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 9 | 7 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; |
| 10 | 8 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; |
| ... | ... | @@ -14,7 +12,6 @@ import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; |
| 14 | 12 | import com.genersoft.iot.vmp.service.IDeviceAlarmService; |
| 15 | 13 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 16 | 14 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| 17 | -import com.genersoft.iot.vmp.utils.GpsUtil; | |
| 18 | 15 | import org.dom4j.Element; |
| 19 | 16 | import org.slf4j.Logger; |
| 20 | 17 | import org.slf4j.LoggerFactory; |
| ... | ... | @@ -35,7 +32,7 @@ import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.*; |
| 35 | 32 | @Component |
| 36 | 33 | public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { |
| 37 | 34 | |
| 38 | - private Logger logger = LoggerFactory.getLogger(AlarmNotifyMessageHandler.class); | |
| 35 | + private final Logger logger = LoggerFactory.getLogger(AlarmNotifyMessageHandler.class); | |
| 39 | 36 | private final String cmdType = "Alarm"; |
| 40 | 37 | |
| 41 | 38 | @Autowired |
| ... | ... | @@ -59,9 +56,6 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme |
| 59 | 56 | @Autowired |
| 60 | 57 | private IDeviceAlarmService deviceAlarmService; |
| 61 | 58 | |
| 62 | - @Autowired | |
| 63 | - private DeviceOffLineDetector offLineDetector; | |
| 64 | - | |
| 65 | 59 | @Override |
| 66 | 60 | public void afterPropertiesSet() throws Exception { |
| 67 | 61 | notifyMessageHandler.addHandler(cmdType, this); |
| ... | ... | @@ -91,24 +85,27 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme |
| 91 | 85 | deviceAlarm.setAlarmPriority(getText(rootElement, "AlarmPriority")); |
| 92 | 86 | deviceAlarm.setAlarmMethod(getText(rootElement, "AlarmMethod")); |
| 93 | 87 | deviceAlarm.setAlarmTime(getText(rootElement, "AlarmTime")); |
| 94 | - if (getText(rootElement, "AlarmDescription") == null) { | |
| 88 | + String alarmDescription = getText(rootElement, "AlarmDescription"); | |
| 89 | + if (alarmDescription == null) { | |
| 95 | 90 | deviceAlarm.setAlarmDescription(""); |
| 96 | 91 | } else { |
| 97 | - deviceAlarm.setAlarmDescription(getText(rootElement, "AlarmDescription")); | |
| 92 | + deviceAlarm.setAlarmDescription(alarmDescription); | |
| 98 | 93 | } |
| 99 | - if (NumericUtil.isDouble(getText(rootElement, "Longitude"))) { | |
| 100 | - deviceAlarm.setLongitude(Double.parseDouble(getText(rootElement, "Longitude"))); | |
| 94 | + String longitude = getText(rootElement, "Longitude"); | |
| 95 | + if (longitude != null && NumericUtil.isDouble(longitude)) { | |
| 96 | + deviceAlarm.setLongitude(Double.parseDouble(longitude)); | |
| 101 | 97 | } else { |
| 102 | 98 | deviceAlarm.setLongitude(0.00); |
| 103 | 99 | } |
| 104 | - if (NumericUtil.isDouble(getText(rootElement, "Latitude"))) { | |
| 105 | - deviceAlarm.setLatitude(Double.parseDouble(getText(rootElement, "Latitude"))); | |
| 100 | + String latitude = getText(rootElement, "Latitude"); | |
| 101 | + if (latitude != null && NumericUtil.isDouble(latitude)) { | |
| 102 | + deviceAlarm.setLatitude(Double.parseDouble(latitude)); | |
| 106 | 103 | } else { |
| 107 | 104 | deviceAlarm.setLatitude(0.00); |
| 108 | 105 | } |
| 109 | 106 | |
| 110 | 107 | if (!StringUtils.isEmpty(deviceAlarm.getAlarmMethod())) { |
| 111 | - if ( deviceAlarm.getAlarmMethod().equals("4")) { | |
| 108 | + if ( deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.GPS.getVal() + "")) { | |
| 112 | 109 | MobilePosition mobilePosition = new MobilePosition(); |
| 113 | 110 | mobilePosition.setDeviceId(deviceAlarm.getDeviceId()); |
| 114 | 111 | mobilePosition.setTime(deviceAlarm.getAlarmTime()); |
| ... | ... | @@ -128,7 +125,7 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme |
| 128 | 125 | } |
| 129 | 126 | } |
| 130 | 127 | if (!StringUtils.isEmpty(deviceAlarm.getDeviceId())) { |
| 131 | - if (deviceAlarm.getAlarmMethod().equals("5")) { | |
| 128 | + if (deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.Video.getVal() + "")) { | |
| 132 | 129 | deviceAlarm.setAlarmType(getText(rootElement.element("Info"), "AlarmType")); |
| 133 | 130 | } |
| 134 | 131 | } |
| ... | ... | @@ -151,7 +148,7 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme |
| 151 | 148 | } |
| 152 | 149 | |
| 153 | 150 | |
| 154 | - if (offLineDetector.isOnline(device.getDeviceId())) { | |
| 151 | + if (redisCatchStorage.deviceIsOnline(device.getDeviceId())) { | |
| 155 | 152 | publisher.deviceAlarmEventPublish(deviceAlarm); |
| 156 | 153 | } |
| 157 | 154 | } |
| ... | ... | @@ -179,25 +176,28 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme |
| 179 | 176 | deviceAlarm.setAlarmPriority(getText(rootElement, "AlarmPriority")); |
| 180 | 177 | deviceAlarm.setAlarmMethod(getText(rootElement, "AlarmMethod")); |
| 181 | 178 | deviceAlarm.setAlarmTime(getText(rootElement, "AlarmTime")); |
| 182 | - if (getText(rootElement, "AlarmDescription") == null) { | |
| 179 | + String alarmDescription = getText(rootElement, "AlarmDescription"); | |
| 180 | + if (alarmDescription == null) { | |
| 183 | 181 | deviceAlarm.setAlarmDescription(""); |
| 184 | 182 | } else { |
| 185 | - deviceAlarm.setAlarmDescription(getText(rootElement, "AlarmDescription")); | |
| 183 | + deviceAlarm.setAlarmDescription(alarmDescription); | |
| 186 | 184 | } |
| 187 | - if (NumericUtil.isDouble(getText(rootElement, "Longitude"))) { | |
| 188 | - deviceAlarm.setLongitude(Double.parseDouble(getText(rootElement, "Longitude"))); | |
| 185 | + String longitude = getText(rootElement, "Longitude"); | |
| 186 | + if (longitude != null && NumericUtil.isDouble(longitude)) { | |
| 187 | + deviceAlarm.setLongitude(Double.parseDouble(longitude)); | |
| 189 | 188 | } else { |
| 190 | 189 | deviceAlarm.setLongitude(0.00); |
| 191 | 190 | } |
| 192 | - if (NumericUtil.isDouble(getText(rootElement, "Latitude"))) { | |
| 193 | - deviceAlarm.setLatitude(Double.parseDouble(getText(rootElement, "Latitude"))); | |
| 191 | + String latitude = getText(rootElement, "Latitude"); | |
| 192 | + if (latitude != null && NumericUtil.isDouble(latitude)) { | |
| 193 | + deviceAlarm.setLatitude(Double.parseDouble(latitude)); | |
| 194 | 194 | } else { |
| 195 | 195 | deviceAlarm.setLatitude(0.00); |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | if (!StringUtils.isEmpty(deviceAlarm.getAlarmMethod())) { |
| 199 | 199 | |
| 200 | - if (deviceAlarm.getAlarmMethod().equals("5")) { | |
| 200 | + if (deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.Video.getVal() + "")) { | |
| 201 | 201 | deviceAlarm.setAlarmType(getText(rootElement.element("Info"), "AlarmType")); |
| 202 | 202 | } |
| 203 | 203 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java
| ... | ... | @@ -70,7 +70,9 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp |
| 70 | 70 | videoManagerStorager.updateDevice(device); |
| 71 | 71 | redisCatchStorage.updateDevice(device); |
| 72 | 72 | } |
| 73 | - publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE); | |
| 73 | + if (!redisCatchStorage.deviceIsOnline(device.getDeviceId())) { | |
| 74 | + publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE); | |
| 75 | + } | |
| 74 | 76 | } |
| 75 | 77 | } catch (SipException e) { |
| 76 | 78 | e.printStackTrace(); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd; |
| 2 | 2 | |
| 3 | -import com.genersoft.iot.vmp.common.VideoManagerConstants; | |
| 4 | 3 | import com.genersoft.iot.vmp.conf.SipConfig; |
| 5 | 4 | import com.genersoft.iot.vmp.conf.UserSetting; |
| 6 | 5 | import com.genersoft.iot.vmp.gb28181.bean.*; |
| 7 | -import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; | |
| 8 | 6 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 9 | 7 | import com.genersoft.iot.vmp.gb28181.session.CatalogDataCatch; |
| 10 | 8 | import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; |
| 11 | -import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | |
| 12 | 9 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; |
| 13 | 10 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; |
| 14 | 11 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; |
| ... | ... | @@ -17,8 +14,6 @@ import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; |
| 17 | 14 | import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; |
| 18 | 15 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 19 | 16 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| 20 | -import com.genersoft.iot.vmp.utils.GpsUtil; | |
| 21 | -import com.genersoft.iot.vmp.vmanager.bean.WVPResult; | |
| 22 | 17 | import org.dom4j.DocumentException; |
| 23 | 18 | import org.dom4j.Element; |
| 24 | 19 | import org.slf4j.Logger; |
| ... | ... | @@ -59,9 +54,6 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp |
| 59 | 54 | private CatalogDataCatch catalogDataCatch; |
| 60 | 55 | |
| 61 | 56 | @Autowired |
| 62 | - private DeviceOffLineDetector offLineDetector; | |
| 63 | - | |
| 64 | - @Autowired | |
| 65 | 57 | private SipConfig config; |
| 66 | 58 | |
| 67 | 59 | @Autowired | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceInfoResponseMessageHandler.java
| ... | ... | @@ -4,13 +4,13 @@ import com.genersoft.iot.vmp.common.VideoManagerConstants; |
| 4 | 4 | import com.genersoft.iot.vmp.conf.SipConfig; |
| 5 | 5 | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 6 | 6 | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| 7 | -import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; | |
| 8 | 7 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 9 | 8 | import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; |
| 10 | 9 | import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; |
| 11 | 10 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; |
| 12 | 11 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; |
| 13 | 12 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; |
| 13 | +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | |
| 14 | 14 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| 15 | 15 | import org.dom4j.DocumentException; |
| 16 | 16 | import org.dom4j.Element; |
| ... | ... | @@ -42,10 +42,10 @@ public class DeviceInfoResponseMessageHandler extends SIPRequestProcessorParent |
| 42 | 42 | private IVideoManagerStorage storager; |
| 43 | 43 | |
| 44 | 44 | @Autowired |
| 45 | - private DeferredResultHolder deferredResultHolder; | |
| 45 | + private IRedisCatchStorage redisCatchStorage; | |
| 46 | 46 | |
| 47 | 47 | @Autowired |
| 48 | - private DeviceOffLineDetector offLineDetector; | |
| 48 | + private DeferredResultHolder deferredResultHolder; | |
| 49 | 49 | |
| 50 | 50 | @Autowired |
| 51 | 51 | private SipConfig config; |
| ... | ... | @@ -82,7 +82,7 @@ public class DeviceInfoResponseMessageHandler extends SIPRequestProcessorParent |
| 82 | 82 | deferredResultHolder.invokeAllResult(msg); |
| 83 | 83 | // 回复200 OK |
| 84 | 84 | responseAck(evt, Response.OK); |
| 85 | - if (offLineDetector.isOnline(device.getDeviceId())) { | |
| 85 | + if (redisCatchStorage.deviceIsOnline(device.getDeviceId())) { | |
| 86 | 86 | publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_MESSAGE); |
| 87 | 87 | } |
| 88 | 88 | } catch (DocumentException e) { | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceStatusResponseMessageHandler.java
| ... | ... | @@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONObject; |
| 4 | 4 | import com.genersoft.iot.vmp.common.VideoManagerConstants; |
| 5 | 5 | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 6 | 6 | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| 7 | -import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; | |
| 8 | 7 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 9 | 8 | import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; |
| 10 | 9 | import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; |
| ... | ... | @@ -12,6 +11,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorP |
| 12 | 11 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; |
| 13 | 12 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; |
| 14 | 13 | import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; |
| 14 | +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | |
| 15 | 15 | import org.dom4j.Element; |
| 16 | 16 | import org.slf4j.Logger; |
| 17 | 17 | import org.slf4j.LoggerFactory; |
| ... | ... | @@ -34,8 +34,6 @@ public class DeviceStatusResponseMessageHandler extends SIPRequestProcessorParen |
| 34 | 34 | @Autowired |
| 35 | 35 | private ResponseMessageHandler responseMessageHandler; |
| 36 | 36 | |
| 37 | - @Autowired | |
| 38 | - private DeviceOffLineDetector offLineDetector; | |
| 39 | 37 | |
| 40 | 38 | @Autowired |
| 41 | 39 | private DeferredResultHolder deferredResultHolder; |
| ... | ... | @@ -43,6 +41,9 @@ public class DeviceStatusResponseMessageHandler extends SIPRequestProcessorParen |
| 43 | 41 | @Autowired |
| 44 | 42 | private EventPublisher publisher; |
| 45 | 43 | |
| 44 | + @Autowired | |
| 45 | + private IRedisCatchStorage redisCatchStorage; | |
| 46 | + | |
| 46 | 47 | @Override |
| 47 | 48 | public void afterPropertiesSet() throws Exception { |
| 48 | 49 | responseMessageHandler.addHandler(cmdType, this); |
| ... | ... | @@ -74,10 +75,8 @@ public class DeviceStatusResponseMessageHandler extends SIPRequestProcessorParen |
| 74 | 75 | msg.setData(json); |
| 75 | 76 | deferredResultHolder.invokeAllResult(msg); |
| 76 | 77 | |
| 77 | - if (offLineDetector.isOnline(device.getDeviceId())) { | |
| 78 | + if (redisCatchStorage.deviceIsOnline(device.getDeviceId())) { | |
| 78 | 79 | publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_MESSAGE); |
| 79 | - } else { | |
| 80 | - | |
| 81 | 80 | } |
| 82 | 81 | } |
| 83 | 82 | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java
| ... | ... | @@ -25,7 +25,9 @@ public class SipUtils { |
| 25 | 25 | * */ |
| 26 | 26 | public static String getChannelIdFromHeader(Request request) { |
| 27 | 27 | Header subject = request.getHeader("subject"); |
| 28 | - if (subject == null) return null; | |
| 28 | + if (subject == null) { | |
| 29 | + return null; | |
| 30 | + } | |
| 29 | 31 | return ((Subject) subject).getSubject().split(":")[0]; |
| 30 | 32 | } |
| 31 | 33 | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookSubscribe.java
| ... | ... | @@ -85,7 +85,9 @@ public class ZLMHttpHookSubscribe { |
| 85 | 85 | if (result == null) { |
| 86 | 86 | result = key.getString(s).equals(hookResponse.getString(s)); |
| 87 | 87 | }else { |
| 88 | - if (key.getString(s) == null) continue; | |
| 88 | + if (key.getString(s) == null) { | |
| 89 | + continue; | |
| 90 | + } | |
| 89 | 91 | result = result && key.getString(s).equals(hookResponse.getString(s)); |
| 90 | 92 | } |
| 91 | 93 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java
| ... | ... | @@ -67,7 +67,9 @@ public class ZLMMediaListManager { |
| 67 | 67 | |
| 68 | 68 | // 使用异步的当时更新媒体流列表 |
| 69 | 69 | zlmresTfulUtils.getMediaList(mediaServerItem, (mediaList ->{ |
| 70 | - if (mediaList == null) return; | |
| 70 | + if (mediaList == null) { | |
| 71 | + return; | |
| 72 | + } | |
| 71 | 73 | String dataStr = mediaList.getString("data"); |
| 72 | 74 | |
| 73 | 75 | Integer code = mediaList.getInteger("code"); |
| ... | ... | @@ -176,7 +178,9 @@ public class ZLMMediaListManager { |
| 176 | 178 | //使用异步更新推流 |
| 177 | 179 | zlmresTfulUtils.getMediaList(mediaServerItem, app, streamId, "rtmp", json->{ |
| 178 | 180 | |
| 179 | - if (json == null) return; | |
| 181 | + if (json == null) { | |
| 182 | + return; | |
| 183 | + } | |
| 180 | 184 | String dataStr = json.getString("data"); |
| 181 | 185 | |
| 182 | 186 | Integer code = json.getInteger("code"); | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
| ... | ... | @@ -23,7 +23,9 @@ public class ZLMRTPServerFactory { |
| 23 | 23 | private int[] portRangeArray = new int[2]; |
| 24 | 24 | |
| 25 | 25 | public int getFreePort(MediaServerItem mediaServerItem, int startPort, int endPort, List<Integer> usedFreelist) { |
| 26 | - if (endPort <= startPort) return -1; | |
| 26 | + if (endPort <= startPort) { | |
| 27 | + return -1; | |
| 28 | + } | |
| 27 | 29 | if (usedFreelist == null) { |
| 28 | 30 | usedFreelist = new ArrayList<>(); |
| 29 | 31 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java
| ... | ... | @@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.media.zlm; |
| 3 | 3 | import com.alibaba.fastjson.JSON; |
| 4 | 4 | import com.alibaba.fastjson.JSONArray; |
| 5 | 5 | import com.alibaba.fastjson.JSONObject; |
| 6 | +import com.genersoft.iot.vmp.conf.DynamicTask; | |
| 6 | 7 | import com.genersoft.iot.vmp.conf.MediaConfig; |
| 7 | 8 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 8 | 9 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| ... | ... | @@ -51,6 +52,9 @@ public class ZLMRunner implements CommandLineRunner { |
| 51 | 52 | @Autowired |
| 52 | 53 | private MediaConfig mediaConfig; |
| 53 | 54 | |
| 55 | + @Autowired | |
| 56 | + private DynamicTask dynamicTask; | |
| 57 | + | |
| 54 | 58 | @Qualifier("taskExecutor") |
| 55 | 59 | @Autowired |
| 56 | 60 | private ThreadPoolTaskExecutor taskExecutor; |
| ... | ... | @@ -97,27 +101,25 @@ public class ZLMRunner implements CommandLineRunner { |
| 97 | 101 | all.add(mediaConfig.getMediaSerItem()); |
| 98 | 102 | } |
| 99 | 103 | for (MediaServerItem mediaServerItem : all) { |
| 100 | - if (startGetMedia == null) startGetMedia = new HashMap<>(); | |
| 104 | + if (startGetMedia == null) { | |
| 105 | + startGetMedia = new HashMap<>(); | |
| 106 | + } | |
| 101 | 107 | startGetMedia.put(mediaServerItem.getId(), true); |
| 102 | 108 | taskExecutor.execute(()->{ |
| 103 | 109 | connectZlmServer(mediaServerItem); |
| 104 | 110 | }); |
| 105 | 111 | } |
| 106 | - Timer timer = new Timer(); | |
| 107 | - // 10分钟后未连接到则不再去主动连接, TODO 并对重启前使用此在zlm的通道发送bye | |
| 108 | - timer.schedule(new TimerTask() { | |
| 109 | - @Override | |
| 110 | - public void run() { | |
| 112 | + String taskKey = "zlm-connect-timeout"; | |
| 113 | + dynamicTask.startDelay(taskKey, ()->{ | |
| 111 | 114 | if (startGetMedia != null) { |
| 112 | 115 | Set<String> allZlmId = startGetMedia.keySet(); |
| 113 | 116 | for (String id : allZlmId) { |
| 114 | - logger.error("[ {} ]]主动连接失败,不再主动连接", id); | |
| 117 | + logger.error("[ {} ]]主动连接失败,不再尝试连接", id); | |
| 115 | 118 | } |
| 116 | 119 | startGetMedia = null; |
| 117 | 120 | } |
| 118 | - // TODO 清理数据库中与redis不匹配的zlm | |
| 119 | - } | |
| 120 | - }, 60 * 1000 * 10); | |
| 121 | + // TODO 清理数据库中与redis不匹配的zlm | |
| 122 | + }, 6 * 1000 ); | |
| 121 | 123 | } |
| 122 | 124 | |
| 123 | 125 | @Async |
| ... | ... | @@ -139,12 +141,12 @@ public class ZLMRunner implements CommandLineRunner { |
| 139 | 141 | if ( startGetMedia.get(mediaServerItem.getId()) == null || !startGetMedia.get(mediaServerItem.getId())) { |
| 140 | 142 | return null; |
| 141 | 143 | } |
| 142 | - JSONObject responseJSON = zlmresTfulUtils.getMediaServerConfig(mediaServerItem); | |
| 143 | - ZLMServerConfig ZLMServerConfig = null; | |
| 144 | - if (responseJSON != null) { | |
| 145 | - JSONArray data = responseJSON.getJSONArray("data"); | |
| 144 | + JSONObject responseJson = zlmresTfulUtils.getMediaServerConfig(mediaServerItem); | |
| 145 | + ZLMServerConfig zlmServerConfig = null; | |
| 146 | + if (responseJson != null) { | |
| 147 | + JSONArray data = responseJson.getJSONArray("data"); | |
| 146 | 148 | if (data != null && data.size() > 0) { |
| 147 | - ZLMServerConfig = JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class); | |
| 149 | + zlmServerConfig = JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class); | |
| 148 | 150 | } |
| 149 | 151 | } else { |
| 150 | 152 | logger.error("[ {} ]-[ {}:{} ]第{}次主动连接失败, 2s后重试", |
| ... | ... | @@ -159,9 +161,9 @@ public class ZLMRunner implements CommandLineRunner { |
| 159 | 161 | } catch (InterruptedException e) { |
| 160 | 162 | e.printStackTrace(); |
| 161 | 163 | } |
| 162 | - ZLMServerConfig = getMediaServerConfig(mediaServerItem, index += 1); | |
| 164 | + zlmServerConfig = getMediaServerConfig(mediaServerItem, index += 1); | |
| 163 | 165 | } |
| 164 | - return ZLMServerConfig; | |
| 166 | + return zlmServerConfig; | |
| 165 | 167 | |
| 166 | 168 | } |
| 167 | 169 | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamProxyItem.java
| ... | ... | @@ -29,18 +29,22 @@ public class StreamProxyItem extends GbStream { |
| 29 | 29 | this.type = type; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | + @Override | |
| 32 | 33 | public String getApp() { |
| 33 | 34 | return app; |
| 34 | 35 | } |
| 35 | 36 | |
| 37 | + @Override | |
| 36 | 38 | public void setApp(String app) { |
| 37 | 39 | this.app = app; |
| 38 | 40 | } |
| 39 | 41 | |
| 42 | + @Override | |
| 40 | 43 | public String getStream() { |
| 41 | 44 | return stream; |
| 42 | 45 | } |
| 43 | 46 | |
| 47 | + @Override | |
| 44 | 48 | public void setStream(String stream) { |
| 45 | 49 | this.stream = stream; |
| 46 | 50 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamPushItem.java
| ... | ... | @@ -124,18 +124,22 @@ public class StreamPushItem extends GbStream implements Comparable<StreamPushIte |
| 124 | 124 | this.id = id; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | + @Override | |
| 127 | 128 | public String getApp() { |
| 128 | 129 | return app; |
| 129 | 130 | } |
| 130 | 131 | |
| 132 | + @Override | |
| 131 | 133 | public void setApp(String app) { |
| 132 | 134 | this.app = app; |
| 133 | 135 | } |
| 134 | 136 | |
| 137 | + @Override | |
| 135 | 138 | public String getStream() { |
| 136 | 139 | return stream; |
| 137 | 140 | } |
| 138 | 141 | |
| 142 | + @Override | |
| 139 | 143 | public void setStream(String stream) { |
| 140 | 144 | this.stream = stream; |
| 141 | 145 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
| ... | ... | @@ -12,6 +12,8 @@ import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 12 | 12 | import org.slf4j.Logger; |
| 13 | 13 | import org.slf4j.LoggerFactory; |
| 14 | 14 | import org.springframework.beans.factory.annotation.Autowired; |
| 15 | +import org.springframework.beans.factory.annotation.Qualifier; | |
| 16 | +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | |
| 15 | 17 | import org.springframework.stereotype.Service; |
| 16 | 18 | |
| 17 | 19 | import javax.sip.DialogState; |
| ... | ... | @@ -43,7 +45,7 @@ public class DeviceServiceImpl implements IDeviceService { |
| 43 | 45 | } |
| 44 | 46 | logger.info("[添加目录订阅] 设备{}", device.getDeviceId()); |
| 45 | 47 | // 添加目录订阅 |
| 46 | - CatalogSubscribeTask catalogSubscribeTask = new CatalogSubscribeTask(device, sipCommander); | |
| 48 | + CatalogSubscribeTask catalogSubscribeTask = new CatalogSubscribeTask(device, sipCommander, dynamicTask); | |
| 47 | 49 | // 提前开始刷新订阅 |
| 48 | 50 | int subscribeCycleForCatalog = Math.max(device.getSubscribeCycleForCatalog(),30); |
| 49 | 51 | // 设置最小值为30 |
| ... | ... | @@ -68,10 +70,10 @@ public class DeviceServiceImpl implements IDeviceService { |
| 68 | 70 | } |
| 69 | 71 | logger.info("[添加移动位置订阅] 设备{}", device.getDeviceId()); |
| 70 | 72 | // 添加目录订阅 |
| 71 | - MobilePositionSubscribeTask mobilePositionSubscribeTask = new MobilePositionSubscribeTask(device, sipCommander); | |
| 72 | - // 提前开始刷新订阅 | |
| 73 | + MobilePositionSubscribeTask mobilePositionSubscribeTask = new MobilePositionSubscribeTask(device, sipCommander, dynamicTask); | |
| 73 | 74 | // 设置最小值为30 |
| 74 | 75 | int subscribeCycleForCatalog = Math.max(device.getSubscribeCycleForMobilePosition(),30); |
| 76 | + // 提前开始刷新订阅 | |
| 75 | 77 | dynamicTask.startCron(device.getDeviceId() + "mobile_position" , mobilePositionSubscribeTask, subscribeCycleForCatalog -1 ); |
| 76 | 78 | return true; |
| 77 | 79 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java
| ... | ... | @@ -70,7 +70,9 @@ public class GbStreamServiceImpl implements IGbStreamService { |
| 70 | 70 | boolean result = false; |
| 71 | 71 | TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); |
| 72 | 72 | ParentPlatform parentPlatform = platformMapper.getParentPlatByServerGBId(platformId); |
| 73 | - if (catalogId == null) catalogId = parentPlatform.getCatalogId(); | |
| 73 | + if (catalogId == null) { | |
| 74 | + catalogId = parentPlatform.getCatalogId(); | |
| 75 | + } | |
| 74 | 76 | try { |
| 75 | 77 | List<DeviceChannel> deviceChannelList = new ArrayList<>(); |
| 76 | 78 | for (GbStream gbStream : gbStreams) { | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java
| ... | ... | @@ -54,7 +54,9 @@ public class MediaServiceImpl implements IMediaService { |
| 54 | 54 | if (mediaList != null) { |
| 55 | 55 | if (mediaList.getInteger("code") == 0) { |
| 56 | 56 | JSONArray data = mediaList.getJSONArray("data"); |
| 57 | - if (data == null) return null; | |
| 57 | + if (data == null) { | |
| 58 | + return null; | |
| 59 | + } | |
| 58 | 60 | JSONObject mediaJSON = JSON.parseObject(JSON.toJSONString(data.get(0)), JSONObject.class); |
| 59 | 61 | JSONArray tracks = mediaJSON.getJSONArray("tracks"); |
| 60 | 62 | streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks); | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
| ... | ... | @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; |
| 4 | 4 | import com.alibaba.fastjson.JSONArray; |
| 5 | 5 | import com.alibaba.fastjson.JSONObject; |
| 6 | 6 | import com.genersoft.iot.vmp.common.StreamInfo; |
| 7 | +import com.genersoft.iot.vmp.conf.DynamicTask; | |
| 7 | 8 | import com.genersoft.iot.vmp.conf.UserSetting; |
| 8 | 9 | import com.genersoft.iot.vmp.gb28181.bean.*; |
| 9 | 10 | import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; |
| ... | ... | @@ -86,6 +87,9 @@ public class PlayServiceImpl implements IPlayService { |
| 86 | 87 | @Autowired |
| 87 | 88 | private UserSetting userSetting; |
| 88 | 89 | |
| 90 | + @Autowired | |
| 91 | + private DynamicTask dynamicTask; | |
| 92 | + | |
| 89 | 93 | |
| 90 | 94 | |
| 91 | 95 | |
| ... | ... | @@ -100,7 +104,7 @@ public class PlayServiceImpl implements IPlayService { |
| 100 | 104 | String uuid = UUID.randomUUID().toString(); |
| 101 | 105 | msg.setId(uuid); |
| 102 | 106 | playResult.setUuid(uuid); |
| 103 | - DeferredResult<ResponseEntity<String>> result = new DeferredResult<>(userSetting.getPlayTimeout()); | |
| 107 | + DeferredResult<ResponseEntity<String>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue()); | |
| 104 | 108 | playResult.setResult(result); |
| 105 | 109 | // 录像查询以channelId作为deviceId查询 |
| 106 | 110 | resultHolder.put(key, uuid, result); |
| ... | ... | @@ -237,30 +241,27 @@ public class PlayServiceImpl implements IPlayService { |
| 237 | 241 | } |
| 238 | 242 | |
| 239 | 243 | // 超时处理 |
| 240 | - Timer timer = new Timer(); | |
| 244 | + String timeOutTaskKey = UUID.randomUUID().toString(); | |
| 241 | 245 | SSRCInfo finalSsrcInfo = ssrcInfo; |
| 242 | - timer.schedule(new TimerTask() { | |
| 243 | - @Override | |
| 244 | - public void run() { | |
| 245 | - logger.warn(String.format("设备点播超时,deviceId:%s ,channelId:%s", device.getDeviceId(), channelId)); | |
| 246 | - | |
| 247 | - SIPDialog dialog = streamSession.getDialogByStream(device.getDeviceId(), channelId, finalSsrcInfo.getStream()); | |
| 248 | - if (dialog != null) { | |
| 249 | - timeoutCallback.run(1, "收流超时"); | |
| 250 | - // 点播超时回复BYE 同时释放ssrc以及此次点播的资源 | |
| 251 | - cmder.streamByeCmd(device.getDeviceId(), channelId, finalSsrcInfo.getStream(), null); | |
| 252 | - }else { | |
| 253 | - timeoutCallback.run(0, "点播超时"); | |
| 254 | - mediaServerService.releaseSsrc(mediaServerItem.getId(), finalSsrcInfo.getSsrc()); | |
| 255 | - mediaServerService.closeRTPServer(device.getDeviceId(), channelId, finalSsrcInfo.getStream()); | |
| 256 | - streamSession.remove(device.getDeviceId(), channelId, finalSsrcInfo.getStream()); | |
| 257 | - } | |
| 246 | + dynamicTask.startDelay( timeOutTaskKey,()->{ | |
| 247 | + logger.warn(String.format("设备点播超时,deviceId:%s ,channelId:%s", device.getDeviceId(), channelId)); | |
| 248 | + | |
| 249 | + SIPDialog dialog = streamSession.getDialogByStream(device.getDeviceId(), channelId, finalSsrcInfo.getStream()); | |
| 250 | + if (dialog != null) { | |
| 251 | + timeoutCallback.run(1, "收流超时"); | |
| 252 | + // 点播超时回复BYE 同时释放ssrc以及此次点播的资源 | |
| 253 | + cmder.streamByeCmd(device.getDeviceId(), channelId, finalSsrcInfo.getStream(), null); | |
| 254 | + }else { | |
| 255 | + timeoutCallback.run(0, "点播超时"); | |
| 256 | + mediaServerService.releaseSsrc(mediaServerItem.getId(), finalSsrcInfo.getSsrc()); | |
| 257 | + mediaServerService.closeRTPServer(device.getDeviceId(), channelId, finalSsrcInfo.getStream()); | |
| 258 | + streamSession.remove(device.getDeviceId(), channelId, finalSsrcInfo.getStream()); | |
| 258 | 259 | } |
| 259 | - }, userSetting.getPlayTimeout()); | |
| 260 | + }, userSetting.getPlayTimeout()*1000); | |
| 260 | 261 | final String ssrc = ssrcInfo.getSsrc(); |
| 261 | 262 | cmder.playStreamCmd(mediaServerItem, ssrcInfo, device, channelId, (MediaServerItem mediaServerItemInuse, JSONObject response) -> { |
| 262 | 263 | logger.info("收到订阅消息: " + response.toJSONString()); |
| 263 | - timer.cancel(); | |
| 264 | + dynamicTask.stop(timeOutTaskKey); | |
| 264 | 265 | // hook响应 |
| 265 | 266 | onPublishHandlerForPlay(mediaServerItemInuse, response, device.getDeviceId(), channelId, uuid); |
| 266 | 267 | hookEvent.response(mediaServerItemInuse, response); |
| ... | ... | @@ -292,7 +293,7 @@ public class PlayServiceImpl implements IPlayService { |
| 292 | 293 | } |
| 293 | 294 | } |
| 294 | 295 | }, (event) -> { |
| 295 | - timer.cancel(); | |
| 296 | + dynamicTask.stop(timeOutTaskKey); | |
| 296 | 297 | mediaServerService.closeRTPServer(device.getDeviceId(), channelId, finalSsrcInfo.getStream()); |
| 297 | 298 | // 释放ssrc |
| 298 | 299 | mediaServerService.releaseSsrc(mediaServerItem.getId(), finalSsrcInfo.getSsrc()); |
| ... | ... | @@ -334,7 +335,9 @@ public class PlayServiceImpl implements IPlayService { |
| 334 | 335 | |
| 335 | 336 | @Override |
| 336 | 337 | public MediaServerItem getNewMediaServerItem(Device device) { |
| 337 | - if (device == null) return null; | |
| 338 | + if (device == null) { | |
| 339 | + return null; | |
| 340 | + } | |
| 338 | 341 | String mediaServerId = device.getMediaServerId(); |
| 339 | 342 | MediaServerItem mediaServerItem; |
| 340 | 343 | if (mediaServerId == null) { |
| ... | ... | @@ -353,7 +356,9 @@ public class PlayServiceImpl implements IPlayService { |
| 353 | 356 | String endTime,InviteStreamCallback inviteStreamCallback, |
| 354 | 357 | PlayBackCallback callback) { |
| 355 | 358 | Device device = storager.queryVideoDevice(deviceId); |
| 356 | - if (device == null) return null; | |
| 359 | + if (device == null) { | |
| 360 | + return null; | |
| 361 | + } | |
| 357 | 362 | MediaServerItem newMediaServerItem = getNewMediaServerItem(device); |
| 358 | 363 | SSRCInfo ssrcInfo = mediaServerService.openRTPServer(newMediaServerItem, null, true); |
| 359 | 364 | |
| ... | ... | @@ -365,7 +370,9 @@ public class PlayServiceImpl implements IPlayService { |
| 365 | 370 | String deviceId, String channelId, String startTime, |
| 366 | 371 | String endTime, InviteStreamCallback infoCallBack, |
| 367 | 372 | PlayBackCallback playBackCallback) { |
| 368 | - if (mediaServerItem == null || ssrcInfo == null) return null; | |
| 373 | + if (mediaServerItem == null || ssrcInfo == null) { | |
| 374 | + return null; | |
| 375 | + } | |
| 369 | 376 | String uuid = UUID.randomUUID().toString(); |
| 370 | 377 | String key = DeferredResultHolder.CALLBACK_CMD_PLAYBACK + deviceId + channelId; |
| 371 | 378 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<>(30000L); |
| ... | ... | @@ -380,34 +387,31 @@ public class PlayServiceImpl implements IPlayService { |
| 380 | 387 | msg.setId(uuid); |
| 381 | 388 | msg.setKey(key); |
| 382 | 389 | PlayBackResult<RequestMessage> playBackResult = new PlayBackResult<>(); |
| 383 | - | |
| 384 | - Timer timer = new Timer(); | |
| 385 | - timer.schedule(new TimerTask() { | |
| 386 | - @Override | |
| 387 | - public void run() { | |
| 388 | - logger.warn(String.format("设备回放超时,deviceId:%s ,channelId:%s", deviceId, channelId)); | |
| 389 | - playBackResult.setCode(-1); | |
| 390 | - playBackResult.setData(msg); | |
| 391 | - playBackCallback.call(playBackResult); | |
| 392 | - SIPDialog dialog = streamSession.getDialogByStream(deviceId, channelId, ssrcInfo.getStream()); | |
| 390 | + String playBackTimeOutTaskKey = UUID.randomUUID().toString(); | |
| 391 | + dynamicTask.startDelay(playBackTimeOutTaskKey, ()->{ | |
| 392 | + logger.warn(String.format("设备回放超时,deviceId:%s ,channelId:%s", deviceId, channelId)); | |
| 393 | + playBackResult.setCode(-1); | |
| 394 | + playBackResult.setData(msg); | |
| 395 | + playBackCallback.call(playBackResult); | |
| 396 | + SIPDialog dialog = streamSession.getDialogByStream(deviceId, channelId, ssrcInfo.getStream()); | |
| 397 | + // 点播超时回复BYE 同时释放ssrc以及此次点播的资源 | |
| 398 | + if (dialog != null) { | |
| 393 | 399 | // 点播超时回复BYE 同时释放ssrc以及此次点播的资源 |
| 394 | - if (dialog != null) { | |
| 395 | - // 点播超时回复BYE 同时释放ssrc以及此次点播的资源 | |
| 396 | - cmder.streamByeCmd(device.getDeviceId(), channelId, ssrcInfo.getStream(), null); | |
| 397 | - }else { | |
| 398 | - mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); | |
| 399 | - mediaServerService.closeRTPServer(deviceId, channelId, ssrcInfo.getStream()); | |
| 400 | - streamSession.remove(deviceId, channelId, ssrcInfo.getStream()); | |
| 401 | - } | |
| 402 | 400 | cmder.streamByeCmd(device.getDeviceId(), channelId, ssrcInfo.getStream(), null); |
| 403 | - // 回复之前所有的点播请求 | |
| 404 | - playBackCallback.call(playBackResult); | |
| 401 | + }else { | |
| 402 | + mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); | |
| 403 | + mediaServerService.closeRTPServer(deviceId, channelId, ssrcInfo.getStream()); | |
| 404 | + streamSession.remove(deviceId, channelId, ssrcInfo.getStream()); | |
| 405 | 405 | } |
| 406 | - }, userSetting.getPlayTimeout()); | |
| 406 | + cmder.streamByeCmd(device.getDeviceId(), channelId, ssrcInfo.getStream(), null); | |
| 407 | + // 回复之前所有的点播请求 | |
| 408 | + playBackCallback.call(playBackResult); | |
| 409 | + }, userSetting.getPlayTimeout()*1000); | |
| 410 | + | |
| 407 | 411 | cmder.playbackStreamCmd(mediaServerItem, ssrcInfo, device, channelId, startTime, endTime, infoCallBack, |
| 408 | 412 | (InviteStreamInfo inviteStreamInfo) -> { |
| 409 | 413 | logger.info("收到订阅消息: " + inviteStreamInfo.getResponse().toJSONString()); |
| 410 | - timer.cancel(); | |
| 414 | + dynamicTask.stop(playBackTimeOutTaskKey); | |
| 411 | 415 | StreamInfo streamInfo = onPublishHandler(inviteStreamInfo.getMediaServerItem(), inviteStreamInfo.getResponse(), deviceId, channelId); |
| 412 | 416 | if (streamInfo == null) { |
| 413 | 417 | logger.warn("设备回放API调用失败!"); |
| ... | ... | @@ -425,7 +429,7 @@ public class PlayServiceImpl implements IPlayService { |
| 425 | 429 | playBackResult.setResponse(inviteStreamInfo.getResponse()); |
| 426 | 430 | playBackCallback.call(playBackResult); |
| 427 | 431 | }, event -> { |
| 428 | - timer.cancel(); | |
| 432 | + dynamicTask.stop(playBackTimeOutTaskKey); | |
| 429 | 433 | msg.setData(String.format("回放失败, 错误码: %s, %s", event.statusCode, event.msg)); |
| 430 | 434 | playBackResult.setCode(-1); |
| 431 | 435 | playBackResult.setData(msg); |
| ... | ... | @@ -439,7 +443,9 @@ public class PlayServiceImpl implements IPlayService { |
| 439 | 443 | @Override |
| 440 | 444 | public DeferredResult<ResponseEntity<String>> download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) { |
| 441 | 445 | Device device = storager.queryVideoDevice(deviceId); |
| 442 | - if (device == null) return null; | |
| 446 | + if (device == null) { | |
| 447 | + return null; | |
| 448 | + } | |
| 443 | 449 | MediaServerItem newMediaServerItem = getNewMediaServerItem(device); |
| 444 | 450 | SSRCInfo ssrcInfo = mediaServerService.openRTPServer(newMediaServerItem, null, true); |
| 445 | 451 | |
| ... | ... | @@ -448,7 +454,9 @@ public class PlayServiceImpl implements IPlayService { |
| 448 | 454 | |
| 449 | 455 | @Override |
| 450 | 456 | public DeferredResult<ResponseEntity<String>> download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) { |
| 451 | - if (mediaServerItem == null || ssrcInfo == null) return null; | |
| 457 | + if (mediaServerItem == null || ssrcInfo == null) { | |
| 458 | + return null; | |
| 459 | + } | |
| 452 | 460 | String uuid = UUID.randomUUID().toString(); |
| 453 | 461 | String key = DeferredResultHolder.CALLBACK_CMD_DOWNLOAD + deviceId + channelId; |
| 454 | 462 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<>(30000L); |
| ... | ... | @@ -467,34 +475,31 @@ public class PlayServiceImpl implements IPlayService { |
| 467 | 475 | PlayBackResult<RequestMessage> downloadResult = new PlayBackResult<>(); |
| 468 | 476 | downloadResult.setData(msg); |
| 469 | 477 | |
| 470 | - Timer timer = new Timer(); | |
| 471 | - timer.schedule(new TimerTask() { | |
| 472 | - @Override | |
| 473 | - public void run() { | |
| 474 | - logger.warn(String.format("录像下载请求超时,deviceId:%s ,channelId:%s", deviceId, channelId)); | |
| 475 | - wvpResult.setCode(-1); | |
| 476 | - wvpResult.setMsg("录像下载请求超时"); | |
| 477 | - downloadResult.setCode(-1); | |
| 478 | - hookCallBack.call(downloadResult); | |
| 479 | - SIPDialog dialog = streamSession.getDialogByStream(deviceId, channelId, ssrcInfo.getStream()); | |
| 478 | + String downLoadTimeOutTaskKey = UUID.randomUUID().toString(); | |
| 479 | + dynamicTask.startDelay(downLoadTimeOutTaskKey, ()->{ | |
| 480 | + logger.warn(String.format("录像下载请求超时,deviceId:%s ,channelId:%s", deviceId, channelId)); | |
| 481 | + wvpResult.setCode(-1); | |
| 482 | + wvpResult.setMsg("录像下载请求超时"); | |
| 483 | + downloadResult.setCode(-1); | |
| 484 | + hookCallBack.call(downloadResult); | |
| 485 | + SIPDialog dialog = streamSession.getDialogByStream(deviceId, channelId, ssrcInfo.getStream()); | |
| 486 | + // 点播超时回复BYE 同时释放ssrc以及此次点播的资源 | |
| 487 | + if (dialog != null) { | |
| 480 | 488 | // 点播超时回复BYE 同时释放ssrc以及此次点播的资源 |
| 481 | - if (dialog != null) { | |
| 482 | - // 点播超时回复BYE 同时释放ssrc以及此次点播的资源 | |
| 483 | - cmder.streamByeCmd(device.getDeviceId(), channelId, ssrcInfo.getStream(), null); | |
| 484 | - }else { | |
| 485 | - mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); | |
| 486 | - mediaServerService.closeRTPServer(deviceId, channelId, ssrcInfo.getStream()); | |
| 487 | - streamSession.remove(deviceId, channelId, ssrcInfo.getStream()); | |
| 488 | - } | |
| 489 | 489 | cmder.streamByeCmd(device.getDeviceId(), channelId, ssrcInfo.getStream(), null); |
| 490 | - // 回复之前所有的点播请求 | |
| 491 | - hookCallBack.call(downloadResult); | |
| 490 | + }else { | |
| 491 | + mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); | |
| 492 | + mediaServerService.closeRTPServer(deviceId, channelId, ssrcInfo.getStream()); | |
| 493 | + streamSession.remove(deviceId, channelId, ssrcInfo.getStream()); | |
| 492 | 494 | } |
| 493 | - }, userSetting.getPlayTimeout()); | |
| 495 | + cmder.streamByeCmd(device.getDeviceId(), channelId, ssrcInfo.getStream(), null); | |
| 496 | + // 回复之前所有的点播请求 | |
| 497 | + hookCallBack.call(downloadResult); | |
| 498 | + }, userSetting.getPlayTimeout()*1000); | |
| 494 | 499 | cmder.downloadStreamCmd(mediaServerItem, ssrcInfo, device, channelId, startTime, endTime, downloadSpeed, infoCallBack, |
| 495 | 500 | inviteStreamInfo -> { |
| 496 | 501 | logger.info("收到订阅消息: " + inviteStreamInfo.getResponse().toJSONString()); |
| 497 | - timer.cancel(); | |
| 502 | + dynamicTask.stop(downLoadTimeOutTaskKey); | |
| 498 | 503 | StreamInfo streamInfo = onPublishHandler(inviteStreamInfo.getMediaServerItem(), inviteStreamInfo.getResponse(), deviceId, channelId); |
| 499 | 504 | streamInfo.setStartTime(startTime); |
| 500 | 505 | streamInfo.setEndTime(endTime); |
| ... | ... | @@ -515,7 +520,7 @@ public class PlayServiceImpl implements IPlayService { |
| 515 | 520 | downloadResult.setResponse(inviteStreamInfo.getResponse()); |
| 516 | 521 | hookCallBack.call(downloadResult); |
| 517 | 522 | }, event -> { |
| 518 | - timer.cancel(); | |
| 523 | + dynamicTask.stop(downLoadTimeOutTaskKey); | |
| 519 | 524 | downloadResult.setCode(-1); |
| 520 | 525 | wvpResult.setCode(-1); |
| 521 | 526 | wvpResult.setMsg(String.format("录像下载失败, 错误码: %s, %s", event.statusCode, event.msg)); | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
| ... | ... | @@ -194,7 +194,9 @@ public class StreamProxyServiceImpl implements IStreamProxyService { |
| 194 | 194 | |
| 195 | 195 | @Override |
| 196 | 196 | public JSONObject removeStreamProxyFromZlm(StreamProxyItem param) { |
| 197 | - if (param ==null) return null; | |
| 197 | + if (param ==null) { | |
| 198 | + return null; | |
| 199 | + } | |
| 198 | 200 | MediaServerItem mediaServerItem = mediaServerService.getOne(param.getMediaServerId()); |
| 199 | 201 | JSONObject result = zlmresTfulUtils.closeStreams(mediaServerItem, param.getApp(), param.getStream()); |
| 200 | 202 | return result; |
| ... | ... | @@ -230,7 +232,9 @@ public class StreamProxyServiceImpl implements IStreamProxyService { |
| 230 | 232 | StreamProxyItem streamProxy = videoManagerStorager.queryStreamProxy(app, stream); |
| 231 | 233 | if (!streamProxy.isEnable() && streamProxy != null) { |
| 232 | 234 | JSONObject jsonObject = addStreamProxyToZlm(streamProxy); |
| 233 | - if (jsonObject == null) return false; | |
| 235 | + if (jsonObject == null) { | |
| 236 | + return false; | |
| 237 | + } | |
| 234 | 238 | if (jsonObject.getInteger("code") == 0) { |
| 235 | 239 | result = true; |
| 236 | 240 | streamProxy.setEnable(true); | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java
| ... | ... | @@ -66,7 +66,9 @@ public class StreamPushServiceImpl implements IStreamPushService { |
| 66 | 66 | |
| 67 | 67 | @Override |
| 68 | 68 | public List<StreamPushItem> handleJSON(String jsonData, MediaServerItem mediaServerItem) { |
| 69 | - if (jsonData == null) return null; | |
| 69 | + if (jsonData == null) { | |
| 70 | + return null; | |
| 71 | + } | |
| 70 | 72 | |
| 71 | 73 | Map<String, StreamPushItem> result = new HashMap<>(); |
| 72 | 74 | |
| ... | ... | @@ -219,7 +221,9 @@ public class StreamPushServiceImpl implements IStreamPushService { |
| 219 | 221 | } |
| 220 | 222 | } |
| 221 | 223 | zlmresTfulUtils.getMediaList(mediaServerItem, (mediaList ->{ |
| 222 | - if (mediaList == null) return; | |
| 224 | + if (mediaList == null) { | |
| 225 | + return; | |
| 226 | + } | |
| 223 | 227 | String dataStr = mediaList.getString("data"); |
| 224 | 228 | |
| 225 | 229 | Integer code = mediaList.getInteger("code"); | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java
| ... | ... | @@ -34,7 +34,9 @@ public class UserServiceImpl implements IUserService { |
| 34 | 34 | @Override |
| 35 | 35 | public int addUser(User user) { |
| 36 | 36 | User userByUsername = userMapper.getUserByUsername(user.getUsername()); |
| 37 | - if (userByUsername != null) return 0; | |
| 37 | + if (userByUsername != null) { | |
| 38 | + return 0; | |
| 39 | + } | |
| 38 | 40 | return userMapper.add(user); |
| 39 | 41 | } |
| 40 | 42 | @Override | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
| ... | ... | @@ -223,4 +223,11 @@ public interface IRedisCatchStorage { |
| 223 | 223 | |
| 224 | 224 | void sendStreamPushRequestedMsg(MessageForPushChannel messageForPushChannel); |
| 225 | 225 | |
| 226 | + /** | |
| 227 | + * 判断设备状态 | |
| 228 | + * @param deviceId 设备ID | |
| 229 | + * @return | |
| 230 | + */ | |
| 231 | + public boolean deviceIsOnline(String deviceId); | |
| 232 | + | |
| 226 | 233 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
| ... | ... | @@ -103,7 +103,9 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 103 | 103 | */ |
| 104 | 104 | @Override |
| 105 | 105 | public boolean stopPlay(StreamInfo streamInfo) { |
| 106 | - if (streamInfo == null) return false; | |
| 106 | + if (streamInfo == null) { | |
| 107 | + return false; | |
| 108 | + } | |
| 107 | 109 | return redis.del(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, |
| 108 | 110 | userSetting.getServerId(), |
| 109 | 111 | streamInfo.getStream(), |
| ... | ... | @@ -127,7 +129,9 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 127 | 129 | @Override |
| 128 | 130 | public StreamInfo queryPlayByStreamId(String streamId) { |
| 129 | 131 | List<Object> playLeys = redis.scan(String.format("%S_%s_%s_*", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(), streamId)); |
| 130 | - if (playLeys == null || playLeys.size() == 0) return null; | |
| 132 | + if (playLeys == null || playLeys.size() == 0) { | |
| 133 | + return null; | |
| 134 | + } | |
| 131 | 135 | return (StreamInfo)redis.get(playLeys.get(0).toString()); |
| 132 | 136 | } |
| 133 | 137 | |
| ... | ... | @@ -137,7 +141,9 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 137 | 141 | userSetting.getServerId(), |
| 138 | 142 | deviceId, |
| 139 | 143 | channelId)); |
| 140 | - if (playLeys == null || playLeys.size() == 0) return null; | |
| 144 | + if (playLeys == null || playLeys.size() == 0) { | |
| 145 | + return null; | |
| 146 | + } | |
| 141 | 147 | return (StreamInfo)redis.get(playLeys.get(0).toString()); |
| 142 | 148 | } |
| 143 | 149 | |
| ... | ... | @@ -146,7 +152,9 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 146 | 152 | Map<String, StreamInfo> streamInfos = new HashMap<>(); |
| 147 | 153 | // List<Object> playLeys = redis.keys(String.format("%S_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, deviceId)); |
| 148 | 154 | List<Object> players = redis.scan(String.format("%S_%s_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(),deviceId)); |
| 149 | - if (players.size() == 0) return streamInfos; | |
| 155 | + if (players.size() == 0) { | |
| 156 | + return streamInfos; | |
| 157 | + } | |
| 150 | 158 | for (Object player : players) { |
| 151 | 159 | String key = (String) player; |
| 152 | 160 | StreamInfo streamInfo = (StreamInfo) redis.get(key); |
| ... | ... | @@ -182,10 +190,18 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 182 | 190 | deviceChannel.setDeviceId(deviceId); |
| 183 | 191 | deviceChannelMapper.update(deviceChannel); |
| 184 | 192 | } |
| 185 | - if (deviceId == null) deviceId = "*"; | |
| 186 | - if (channelId == null) channelId = "*"; | |
| 187 | - if (stream == null) stream = "*"; | |
| 188 | - if (callId == null) callId = "*"; | |
| 193 | + if (deviceId == null) { | |
| 194 | + deviceId = "*"; | |
| 195 | + } | |
| 196 | + if (channelId == null) { | |
| 197 | + channelId = "*"; | |
| 198 | + } | |
| 199 | + if (stream == null) { | |
| 200 | + stream = "*"; | |
| 201 | + } | |
| 202 | + if (callId == null) { | |
| 203 | + callId = "*"; | |
| 204 | + } | |
| 189 | 205 | String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX, |
| 190 | 206 | userSetting.getServerId(), |
| 191 | 207 | deviceId, |
| ... | ... | @@ -210,10 +226,18 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 210 | 226 | deviceChannel.setDeviceId(deviceId); |
| 211 | 227 | deviceChannelMapper.update(deviceChannel); |
| 212 | 228 | } |
| 213 | - if (deviceId == null) deviceId = "*"; | |
| 214 | - if (channelId == null) channelId = "*"; | |
| 215 | - if (stream == null) stream = "*"; | |
| 216 | - if (callId == null) callId = "*"; | |
| 229 | + if (deviceId == null) { | |
| 230 | + deviceId = "*"; | |
| 231 | + } | |
| 232 | + if (channelId == null) { | |
| 233 | + channelId = "*"; | |
| 234 | + } | |
| 235 | + if (stream == null) { | |
| 236 | + stream = "*"; | |
| 237 | + } | |
| 238 | + if (callId == null) { | |
| 239 | + callId = "*"; | |
| 240 | + } | |
| 217 | 241 | String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, |
| 218 | 242 | userSetting.getServerId(), |
| 219 | 243 | deviceId, |
| ... | ... | @@ -235,10 +259,18 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 235 | 259 | if (stream == null && callId == null) { |
| 236 | 260 | return null; |
| 237 | 261 | } |
| 238 | - if (deviceId == null) deviceId = "*"; | |
| 239 | - if (channelId == null) channelId = "*"; | |
| 240 | - if (stream == null) stream = "*"; | |
| 241 | - if (callId == null) callId = "*"; | |
| 262 | + if (deviceId == null) { | |
| 263 | + deviceId = "*"; | |
| 264 | + } | |
| 265 | + if (channelId == null) { | |
| 266 | + channelId = "*"; | |
| 267 | + } | |
| 268 | + if (stream == null) { | |
| 269 | + stream = "*"; | |
| 270 | + } | |
| 271 | + if (callId == null) { | |
| 272 | + callId = "*"; | |
| 273 | + } | |
| 242 | 274 | String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, |
| 243 | 275 | userSetting.getServerId(), |
| 244 | 276 | deviceId, |
| ... | ... | @@ -328,10 +360,18 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 328 | 360 | |
| 329 | 361 | @Override |
| 330 | 362 | public SendRtpItem querySendRTPServer(String platformGbId, String channelId, String streamId, String callId) { |
| 331 | - if (platformGbId == null) platformGbId = "*"; | |
| 332 | - if (channelId == null) channelId = "*"; | |
| 333 | - if (streamId == null) streamId = "*"; | |
| 334 | - if (callId == null) callId = "*"; | |
| 363 | + if (platformGbId == null) { | |
| 364 | + platformGbId = "*"; | |
| 365 | + } | |
| 366 | + if (channelId == null) { | |
| 367 | + channelId = "*"; | |
| 368 | + } | |
| 369 | + if (streamId == null) { | |
| 370 | + streamId = "*"; | |
| 371 | + } | |
| 372 | + if (callId == null) { | |
| 373 | + callId = "*"; | |
| 374 | + } | |
| 335 | 375 | String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId |
| 336 | 376 | + "_" + channelId + "_" + streamId + "_" + callId; |
| 337 | 377 | List<Object> scan = redis.scan(key); |
| ... | ... | @@ -344,7 +384,9 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 344 | 384 | |
| 345 | 385 | @Override |
| 346 | 386 | public List<SendRtpItem> querySendRTPServer(String platformGbId) { |
| 347 | - if (platformGbId == null) platformGbId = "*"; | |
| 387 | + if (platformGbId == null) { | |
| 388 | + platformGbId = "*"; | |
| 389 | + } | |
| 348 | 390 | String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId + "_*" + "_*" + "_*"; |
| 349 | 391 | List<Object> queryResult = redis.scan(key); |
| 350 | 392 | List<SendRtpItem> result= new ArrayList<>(); |
| ... | ... | @@ -364,8 +406,12 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 364 | 406 | */ |
| 365 | 407 | @Override |
| 366 | 408 | public void deleteSendRTPServer(String platformGbId, String channelId, String callId, String streamId) { |
| 367 | - if (streamId == null) streamId = "*"; | |
| 368 | - if (callId == null) callId = "*"; | |
| 409 | + if (streamId == null) { | |
| 410 | + streamId = "*"; | |
| 411 | + } | |
| 412 | + if (callId == null) { | |
| 413 | + callId = "*"; | |
| 414 | + } | |
| 369 | 415 | String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId |
| 370 | 416 | + "_" + channelId + "_" + streamId + "_" + callId; |
| 371 | 417 | List<Object> scan = redis.scan(key); |
| ... | ... | @@ -473,10 +519,18 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 473 | 519 | if (stream == null && callId == null) { |
| 474 | 520 | return null; |
| 475 | 521 | } |
| 476 | - if (deviceId == null) deviceId = "*"; | |
| 477 | - if (channelId == null) channelId = "*"; | |
| 478 | - if (stream == null) stream = "*"; | |
| 479 | - if (callId == null) callId = "*"; | |
| 522 | + if (deviceId == null) { | |
| 523 | + deviceId = "*"; | |
| 524 | + } | |
| 525 | + if (channelId == null) { | |
| 526 | + channelId = "*"; | |
| 527 | + } | |
| 528 | + if (stream == null) { | |
| 529 | + stream = "*"; | |
| 530 | + } | |
| 531 | + if (callId == null) { | |
| 532 | + callId = "*"; | |
| 533 | + } | |
| 480 | 534 | String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX, |
| 481 | 535 | userSetting.getServerId(), |
| 482 | 536 | deviceId, |
| ... | ... | @@ -645,4 +699,10 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 645 | 699 | logger.info("[redis 报警通知] {}: {}", key, JSON.toJSON(msg)); |
| 646 | 700 | redis.convertAndSend(key, (JSONObject)JSON.toJSON(msg)); |
| 647 | 701 | } |
| 702 | + | |
| 703 | + @Override | |
| 704 | + public boolean deviceIsOnline(String deviceId) { | |
| 705 | + String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetting.getServerId() + "_" + deviceId; | |
| 706 | + return redis.hasKey(key); | |
| 707 | + } | |
| 648 | 708 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
| ... | ... | @@ -460,7 +460,9 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { |
| 460 | 460 | public synchronized boolean outline(String deviceId) { |
| 461 | 461 | logger.info("更新设备离线: " + deviceId); |
| 462 | 462 | Device device = deviceMapper.getDeviceByDeviceId(deviceId); |
| 463 | - if (device == null) return false; | |
| 463 | + if (device == null) { | |
| 464 | + return false; | |
| 465 | + } | |
| 464 | 466 | device.setOnline(0); |
| 465 | 467 | redisCatchStorage.updateDevice(device); |
| 466 | 468 | return deviceMapper.update(device) > 0; |
| ... | ... | @@ -714,6 +716,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { |
| 714 | 716 | * 删除指定设备的所有移动位置 |
| 715 | 717 | * @param deviceId |
| 716 | 718 | */ |
| 719 | + @Override | |
| 717 | 720 | public int clearMobilePositionsByDeviceId(String deviceId) { |
| 718 | 721 | return deviceMobilePositionMapper.clearMobilePositionsByDeviceId(deviceId); |
| 719 | 722 | } |
| ... | ... | @@ -859,7 +862,9 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { |
| 859 | 862 | |
| 860 | 863 | @Override |
| 861 | 864 | public void updateMediaList(List<StreamPushItem> streamPushItems) { |
| 862 | - if (streamPushItems == null || streamPushItems.size() == 0) return; | |
| 865 | + if (streamPushItems == null || streamPushItems.size() == 0) { | |
| 866 | + return; | |
| 867 | + } | |
| 863 | 868 | logger.info("updateMediaList: " + streamPushItems.size()); |
| 864 | 869 | streamPushMapper.addAll(streamPushItems); |
| 865 | 870 | // TODO 待优化 | ... | ... |
src/main/java/com/genersoft/iot/vmp/utils/SpringBeanFactory.java
| ... | ... | @@ -34,7 +34,9 @@ public class SpringBeanFactory implements ApplicationContextAware { |
| 34 | 34 | * 获取对象 这里重写了bean方法,起主要作用 |
| 35 | 35 | */ |
| 36 | 36 | public static Object getBean(String beanId) throws BeansException { |
| 37 | - if (applicationContext == null) return null; | |
| 37 | + if (applicationContext == null) { | |
| 38 | + return null; | |
| 39 | + } | |
| 38 | 40 | return applicationContext.getBean(beanId); |
| 39 | 41 | } |
| 40 | 42 | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java
| ... | ... | @@ -85,16 +85,30 @@ public class AlarmController { |
| 85 | 85 | @RequestParam(required = false) String startTime, |
| 86 | 86 | @RequestParam(required = false) String endTime |
| 87 | 87 | ) { |
| 88 | - if (StringUtils.isEmpty(alarmPriority)) alarmPriority = null; | |
| 89 | - if (StringUtils.isEmpty(alarmMethod)) alarmMethod = null; | |
| 90 | - if (StringUtils.isEmpty(alarmType)) alarmType = null; | |
| 91 | - if (StringUtils.isEmpty(startTime)) startTime = null; | |
| 92 | - if (StringUtils.isEmpty(endTime)) endTime = null; | |
| 88 | + if (StringUtils.isEmpty(alarmPriority)) { | |
| 89 | + alarmPriority = null; | |
| 90 | + } | |
| 91 | + if (StringUtils.isEmpty(alarmMethod)) { | |
| 92 | + alarmMethod = null; | |
| 93 | + } | |
| 94 | + if (StringUtils.isEmpty(alarmType)) { | |
| 95 | + alarmType = null; | |
| 96 | + } | |
| 97 | + if (StringUtils.isEmpty(startTime)) { | |
| 98 | + startTime = null; | |
| 99 | + } | |
| 100 | + if (StringUtils.isEmpty(endTime)) { | |
| 101 | + endTime = null; | |
| 102 | + } | |
| 93 | 103 | |
| 94 | 104 | |
| 95 | 105 | try { |
| 96 | - if (startTime != null) format.parse(startTime); | |
| 97 | - if (endTime != null) format.parse(endTime); | |
| 106 | + if (startTime != null) { | |
| 107 | + format.parse(startTime); | |
| 108 | + } | |
| 109 | + if (endTime != null) { | |
| 110 | + format.parse(endTime); | |
| 111 | + } | |
| 98 | 112 | } catch (ParseException e) { |
| 99 | 113 | return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); |
| 100 | 114 | } |
| ... | ... | @@ -125,9 +139,15 @@ public class AlarmController { |
| 125 | 139 | @RequestParam(required = false) String deviceIds, |
| 126 | 140 | @RequestParam(required = false) String time |
| 127 | 141 | ) { |
| 128 | - if (StringUtils.isEmpty(id)) id = null; | |
| 129 | - if (StringUtils.isEmpty(deviceIds)) deviceIds = null; | |
| 130 | - if (StringUtils.isEmpty(time)) time = null; | |
| 142 | + if (StringUtils.isEmpty(id)) { | |
| 143 | + id = null; | |
| 144 | + } | |
| 145 | + if (StringUtils.isEmpty(deviceIds)) { | |
| 146 | + deviceIds = null; | |
| 147 | + } | |
| 148 | + if (StringUtils.isEmpty(time)) { | |
| 149 | + time = null; | |
| 150 | + } | |
| 131 | 151 | try { |
| 132 | 152 | if (time != null) { |
| 133 | 153 | format.parse(time); | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
| ... | ... | @@ -6,7 +6,6 @@ import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 6 | 6 | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; |
| 7 | 7 | import com.genersoft.iot.vmp.gb28181.bean.SubscribeHolder; |
| 8 | 8 | import com.genersoft.iot.vmp.gb28181.bean.SyncStatus; |
| 9 | -import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; | |
| 10 | 9 | import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask; |
| 11 | 10 | import com.genersoft.iot.vmp.gb28181.task.impl.CatalogSubscribeTask; |
| 12 | 11 | import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeTask; |
| ... | ... | @@ -54,9 +53,6 @@ public class DeviceQuery { |
| 54 | 53 | |
| 55 | 54 | @Autowired |
| 56 | 55 | private DeferredResultHolder resultHolder; |
| 57 | - | |
| 58 | - @Autowired | |
| 59 | - private DeviceOffLineDetector offLineDetector; | |
| 60 | 56 | |
| 61 | 57 | @Autowired |
| 62 | 58 | private IDeviceService deviceService; |
| ... | ... | @@ -310,9 +306,15 @@ public class DeviceQuery { |
| 310 | 306 | |
| 311 | 307 | if (device != null && device.getDeviceId() != null) { |
| 312 | 308 | Device deviceInStore = storager.queryVideoDevice(device.getDeviceId()); |
| 313 | - if (!StringUtils.isEmpty(device.getName())) deviceInStore.setName(device.getName()); | |
| 314 | - if (!StringUtils.isEmpty(device.getCharset())) deviceInStore.setCharset(device.getCharset()); | |
| 315 | - if (!StringUtils.isEmpty(device.getMediaServerId())) deviceInStore.setMediaServerId(device.getMediaServerId()); | |
| 309 | + if (!StringUtils.isEmpty(device.getName())) { | |
| 310 | + deviceInStore.setName(device.getName()); | |
| 311 | + } | |
| 312 | + if (!StringUtils.isEmpty(device.getCharset())) { | |
| 313 | + deviceInStore.setCharset(device.getCharset()); | |
| 314 | + } | |
| 315 | + if (!StringUtils.isEmpty(device.getMediaServerId())) { | |
| 316 | + deviceInStore.setMediaServerId(device.getMediaServerId()); | |
| 317 | + } | |
| 316 | 318 | |
| 317 | 319 | // 目录订阅相关的信息 |
| 318 | 320 | if (device.getSubscribeCycleForCatalog() > 0) { | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java
| ... | ... | @@ -286,7 +286,9 @@ public class PlatformController { |
| 286 | 286 | return new ResponseEntity<>("missing parameters", HttpStatus.BAD_REQUEST); |
| 287 | 287 | } |
| 288 | 288 | ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(serverGBId); |
| 289 | - if (parentPlatform == null) return new ResponseEntity<>("fail", HttpStatus.OK); | |
| 289 | + if (parentPlatform == null) { | |
| 290 | + return new ResponseEntity<>("fail", HttpStatus.OK); | |
| 291 | + } | |
| 290 | 292 | // 发送离线消息,无论是否成功都删除缓存 |
| 291 | 293 | commanderForPlatform.unregister(parentPlatform, (event -> { |
| 292 | 294 | // 清空redis缓存 | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java
| ... | ... | @@ -65,16 +65,26 @@ public class LogController { |
| 65 | 65 | @RequestParam(required = false) String startTime, |
| 66 | 66 | @RequestParam(required = false) String endTime |
| 67 | 67 | ) { |
| 68 | - if (StringUtils.isEmpty(query)) query = null; | |
| 69 | - if (StringUtils.isEmpty(startTime)) startTime = null; | |
| 70 | - if (StringUtils.isEmpty(endTime)) endTime = null; | |
| 68 | + if (StringUtils.isEmpty(query)) { | |
| 69 | + query = null; | |
| 70 | + } | |
| 71 | + if (StringUtils.isEmpty(startTime)) { | |
| 72 | + startTime = null; | |
| 73 | + } | |
| 74 | + if (StringUtils.isEmpty(endTime)) { | |
| 75 | + endTime = null; | |
| 76 | + } | |
| 71 | 77 | if (!userSetting.getLogInDatebase()) { |
| 72 | 78 | logger.warn("自动记录日志功能已关闭,查询结果可能不完整。"); |
| 73 | 79 | } |
| 74 | 80 | |
| 75 | 81 | try { |
| 76 | - if (startTime != null) format.parse(startTime); | |
| 77 | - if (endTime != null) format.parse(endTime); | |
| 82 | + if (startTime != null) { | |
| 83 | + format.parse(startTime); | |
| 84 | + } | |
| 85 | + if (endTime != null) { | |
| 86 | + format.parse(endTime); | |
| 87 | + } | |
| 78 | 88 | } catch (ParseException e) { |
| 79 | 89 | return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); |
| 80 | 90 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java
| ... | ... | @@ -69,9 +69,15 @@ public class StreamProxyController { |
| 69 | 69 | @ResponseBody |
| 70 | 70 | public WVPResult save(@RequestBody StreamProxyItem param){ |
| 71 | 71 | logger.info("添加代理: " + JSONObject.toJSONString(param)); |
| 72 | - if (StringUtils.isEmpty(param.getMediaServerId())) param.setMediaServerId("auto"); | |
| 73 | - if (StringUtils.isEmpty(param.getType())) param.setType("default"); | |
| 74 | - if (StringUtils.isEmpty(param.getGbId())) param.setGbId(null); | |
| 72 | + if (StringUtils.isEmpty(param.getMediaServerId())) { | |
| 73 | + param.setMediaServerId("auto"); | |
| 74 | + } | |
| 75 | + if (StringUtils.isEmpty(param.getType())) { | |
| 76 | + param.setType("default"); | |
| 77 | + } | |
| 78 | + if (StringUtils.isEmpty(param.getGbId())) { | |
| 79 | + param.setGbId(null); | |
| 80 | + } | |
| 75 | 81 | WVPResult<StreamInfo> result = streamProxyService.save(param); |
| 76 | 82 | return result; |
| 77 | 83 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiStreamController.java
| ... | ... | @@ -68,7 +68,7 @@ public class ApiStreamController { |
| 68 | 68 | @RequestParam(required = false)String timeout |
| 69 | 69 | |
| 70 | 70 | ){ |
| 71 | - DeferredResult<JSONObject> resultDeferredResult = new DeferredResult<>(userSetting.getPlayTimeout() + 10); | |
| 71 | + DeferredResult<JSONObject> resultDeferredResult = new DeferredResult<>(userSetting.getPlayTimeout().longValue() + 10); | |
| 72 | 72 | Device device = storager.queryVideoDevice(serial); |
| 73 | 73 | if (device == null ) { |
| 74 | 74 | JSONObject result = new JSONObject(); | ... | ... |
web_src/index.html
| ... | ... | @@ -12,26 +12,7 @@ |
| 12 | 12 | <script type="text/javascript" src="./static/js/jessibuca/jessibuca.js"></script> |
| 13 | 13 | <script type="text/javascript" src="./static/js/EasyWasmPlayer.js"></script> |
| 14 | 14 | <script type="text/javascript" src="./static/js/ZLMRTCClient.js"></script> |
| 15 | + <script type="text/javascript" src="./static/js/mapConfig.js"></script> | |
| 15 | 16 | <div id="app"></div> |
| 16 | - <!-- built files will be auto injected --> | |
| 17 | - <script> | |
| 18 | - // map组件全局参数, 注释此内容可以关闭地图功能 | |
| 19 | - window.mapParam = { | |
| 20 | - // 坐标系 GCJ-02 WGS-84, | |
| 21 | - coordinateSystem: "GCJ-02", | |
| 22 | - // 地图瓦片地址 | |
| 23 | - tilesUrl: "http://webrd0{1-4}.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scale=1&style=8", | |
| 24 | - // 瓦片大小 | |
| 25 | - tileSize: 256, | |
| 26 | - // 默认层级 | |
| 27 | - zoom:10, | |
| 28 | - // 默认地图中心点 | |
| 29 | - center:[116.41020, 39.915119], | |
| 30 | - // 地图最大层级 | |
| 31 | - maxZoom:18, | |
| 32 | - // 地图最小层级 | |
| 33 | - minZoom: 3 | |
| 34 | - } | |
| 35 | - </script> | |
| 36 | 17 | </body> |
| 37 | 18 | </html> | ... | ... |
web_src/src/components/common/jessibuca.vue
| 1 | 1 | <template> |
| 2 | - <div ref="container" @dblclick="fullscreenSwich" style="width:100%;height:100%;background-color: #eee;margin:0 auto;"> | |
| 2 | + <div ref="container" @dblclick="fullscreenSwich" style="width:100%;height:100%;background-color: #000000;margin:0 auto;"> | |
| 3 | 3 | <div class="buttons-box" id="buttonsBox"> |
| 4 | 4 | <div class="buttons-box-left"> |
| 5 | 5 | <i v-if="!playing" class="iconfont icon-play jessibuca-btn" @click="playBtnClick"></i> | ... | ... |
web_src/src/components/devicePosition.vue
| ... | ... | @@ -59,7 +59,7 @@ export default { |
| 59 | 59 | }, |
| 60 | 60 | data() { |
| 61 | 61 | return { |
| 62 | - onOff: typeof window.mapParam !== "undefined", | |
| 62 | + onOff: typeof window.mapParam !== "undefined" && window.mapParam.enable, | |
| 63 | 63 | deviceService: new DeviceService(), |
| 64 | 64 | layer: null, |
| 65 | 65 | lineLayer: null, | ... | ... |
web_src/static/js/mapConfig.js
0 → 100644
| 1 | +// map组件全局参数, 注释此内容可以关闭地图功能 | |
| 2 | +window.mapParam = { | |
| 3 | + // 开启/关闭地图功能 | |
| 4 | + enable: true, | |
| 5 | + // 坐标系 GCJ-02 WGS-84, | |
| 6 | + coordinateSystem: "GCJ-02", | |
| 7 | + // 地图瓦片地址 | |
| 8 | + tilesUrl: "http://webrd0{1-4}.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scale=1&style=8", | |
| 9 | + // 瓦片大小 | |
| 10 | + tileSize: 256, | |
| 11 | + // 默认层级 | |
| 12 | + zoom:10, | |
| 13 | + // 默认地图中心点 | |
| 14 | + center:[116.41020, 39.915119], | |
| 15 | + // 地图最大层级 | |
| 16 | + maxZoom:18, | |
| 17 | + // 地图最小层级 | |
| 18 | + minZoom: 3 | |
| 19 | +} | ... | ... |