Commit cb213f4417def6ea7b3cc07d8b4a3534c3e971c2

Authored by 648540858
1 parent 90c29240

修复 #223与去除警告

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