Commit cb213f4417def6ea7b3cc07d8b4a3534c3e971c2
1 parent
90c29240
修复 #223与去除警告
Showing
1 changed file
with
15 additions
and
15 deletions
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
| ... | ... | @@ -40,6 +40,7 @@ import javax.sip.TimeoutEvent; |
| 40 | 40 | import javax.sip.TransactionTerminatedEvent; |
| 41 | 41 | import javax.sip.message.Response; |
| 42 | 42 | import java.io.FileNotFoundException; |
| 43 | +import java.util.Objects; | |
| 43 | 44 | import java.util.UUID; |
| 44 | 45 | |
| 45 | 46 | @SuppressWarnings(value = {"rawtypes", "unchecked"}) |
| ... | ... | @@ -85,7 +86,13 @@ public class PlayServiceImpl implements IPlayService { |
| 85 | 86 | RequestMessage msg = new RequestMessage(); |
| 86 | 87 | String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId; |
| 87 | 88 | msg.setKey(key); |
| 88 | - msg.setId(playResult.getUuid()); | |
| 89 | + String uuid = UUID.randomUUID().toString(); | |
| 90 | + msg.setId(uuid); | |
| 91 | + playResult.setUuid(uuid); | |
| 92 | + DeferredResult<ResponseEntity<String>> result = new DeferredResult<>(userSetup.getPlayTimeout()); | |
| 93 | + playResult.setResult(result); | |
| 94 | + // 录像查询以channelId作为deviceId查询 | |
| 95 | + resultHolder.put(key, uuid, result); | |
| 89 | 96 | if (mediaServerItem == null) { |
| 90 | 97 | WVPResult wvpResult = new WVPResult(); |
| 91 | 98 | wvpResult.setCode(-1); |
| ... | ... | @@ -94,16 +101,9 @@ public class PlayServiceImpl implements IPlayService { |
| 94 | 101 | resultHolder.invokeResult(msg); |
| 95 | 102 | return playResult; |
| 96 | 103 | } |
| 97 | - | |
| 98 | 104 | Device device = storager.queryVideoDevice(deviceId); |
| 99 | 105 | StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId); |
| 100 | 106 | playResult.setDevice(device); |
| 101 | - String uuid = UUID.randomUUID().toString(); | |
| 102 | - playResult.setUuid(uuid); | |
| 103 | - DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(userSetup.getPlayTimeout()); | |
| 104 | - playResult.setResult(result); | |
| 105 | - // 录像查询以channelId作为deviceId查询 | |
| 106 | - resultHolder.put(key, uuid, result); | |
| 107 | 107 | // 超时处理 |
| 108 | 108 | result.onTimeout(()->{ |
| 109 | 109 | logger.warn(String.format("设备点播超时,deviceId:%s ,channelId:%s", deviceId, channelId)); |
| ... | ... | @@ -134,18 +134,18 @@ public class PlayServiceImpl implements IPlayService { |
| 134 | 134 | classPath = classPath.substring(0, classPath.lastIndexOf("/") + 1); |
| 135 | 135 | } |
| 136 | 136 | if (classPath.startsWith("file:")) { |
| 137 | - classPath = classPath.substring(classPath.indexOf(":") + 1, classPath.length()); | |
| 137 | + classPath = classPath.substring(classPath.indexOf(":") + 1); | |
| 138 | 138 | } |
| 139 | 139 | String path = classPath + "static/static/snap/"; |
| 140 | 140 | // 兼容Windows系统路径(去除前面的“/”) |
| 141 | 141 | if(System.getProperty("os.name").contains("indows")) { |
| 142 | - path = path.substring(1, path.length()); | |
| 142 | + path = path.substring(1); | |
| 143 | 143 | } |
| 144 | 144 | String fileName = deviceId + "_" + channelId + ".jpg"; |
| 145 | 145 | ResponseEntity responseEntity = (ResponseEntity)result.getResult(); |
| 146 | 146 | if (responseEntity != null && responseEntity.getStatusCode() == HttpStatus.OK) { |
| 147 | 147 | WVPResult wvpResult = (WVPResult)responseEntity.getBody(); |
| 148 | - if (wvpResult.getCode() == 0) { | |
| 148 | + if (Objects.requireNonNull(wvpResult).getCode() == 0) { | |
| 149 | 149 | StreamInfo streamInfoForSuccess = (StreamInfo)wvpResult.getData(); |
| 150 | 150 | MediaServerItem mediaInfo = mediaServerService.getOne(streamInfoForSuccess.getMediaServerId()); |
| 151 | 151 | String streamUrl = streamInfoForSuccess.getFmp4(); |
| ... | ... | @@ -169,7 +169,7 @@ public class PlayServiceImpl implements IPlayService { |
| 169 | 169 | // 发送点播消息 |
| 170 | 170 | cmder.playStreamCmd(mediaServerItem, ssrcInfo, device, channelId, (MediaServerItem mediaServerItemInUse, JSONObject response) -> { |
| 171 | 171 | logger.info("收到订阅消息: " + response.toJSONString()); |
| 172 | - onPublishHandlerForPlay(mediaServerItemInUse, response, deviceId, channelId, uuid.toString()); | |
| 172 | + onPublishHandlerForPlay(mediaServerItemInUse, response, deviceId, channelId, uuid); | |
| 173 | 173 | if (hookEvent != null) { |
| 174 | 174 | hookEvent.response(mediaServerItem, response); |
| 175 | 175 | } |
| ... | ... | @@ -192,7 +192,7 @@ public class PlayServiceImpl implements IPlayService { |
| 192 | 192 | if (streamId == null) { |
| 193 | 193 | WVPResult wvpResult = new WVPResult(); |
| 194 | 194 | wvpResult.setCode(-1); |
| 195 | - wvpResult.setMsg(String.format("点播失败, redis缓存streamId等于null")); | |
| 195 | + wvpResult.setMsg("点播失败, redis缓存streamId等于null"); | |
| 196 | 196 | msg.setData(wvpResult); |
| 197 | 197 | resultHolder.invokeAllResult(msg); |
| 198 | 198 | return playResult; |
| ... | ... | @@ -226,7 +226,7 @@ public class PlayServiceImpl implements IPlayService { |
| 226 | 226 | |
| 227 | 227 | cmder.playStreamCmd(mediaServerItem, ssrcInfo, device, channelId, (MediaServerItem mediaServerItemInuse, JSONObject response) -> { |
| 228 | 228 | logger.info("收到订阅消息: " + response.toJSONString()); |
| 229 | - onPublishHandlerForPlay(mediaServerItemInuse, response, deviceId, channelId, uuid.toString()); | |
| 229 | + onPublishHandlerForPlay(mediaServerItemInuse, response, deviceId, channelId, uuid); | |
| 230 | 230 | }, (event) -> { |
| 231 | 231 | mediaServerService.closeRTPServer(playResult.getDevice(), channelId); |
| 232 | 232 | WVPResult wvpResult = new WVPResult(); |
| ... | ... | @@ -274,7 +274,7 @@ public class PlayServiceImpl implements IPlayService { |
| 274 | 274 | public MediaServerItem getNewMediaServerItem(Device device) { |
| 275 | 275 | if (device == null) return null; |
| 276 | 276 | String mediaServerId = device.getMediaServerId(); |
| 277 | - MediaServerItem mediaServerItem = null; | |
| 277 | + MediaServerItem mediaServerItem; | |
| 278 | 278 | if (mediaServerId == null) { |
| 279 | 279 | mediaServerItem = mediaServerService.getMediaServerForMinimumLoad(); |
| 280 | 280 | }else { | ... | ... |