Commit bb226c431e28ffdda284ba2420a93cf4ed4e0c30
1 parent
29525119
修复订阅sip消息导致的内存溢出以及录像回放的问题
Showing
17 changed files
with
160 additions
and
60 deletions
src/main/java/com/genersoft/iot/vmp/conf/WVPTimerTask.java
| ... | ... | @@ -17,8 +17,8 @@ public class WVPTimerTask { |
| 17 | 17 | @Autowired |
| 18 | 18 | private MediaConfig mediaConfig; |
| 19 | 19 | |
| 20 | - @Scheduled(cron="0/2 * * * * ? ") //每3秒执行一次 | |
| 21 | - public void execute(){ | |
| 22 | -// redisCatchStorage.updateWVPInfo(); | |
| 23 | - } | |
| 20 | +// @Scheduled(cron="0/2 * * * * ? ") //每3秒执行一次 | |
| 21 | +// public void execute(){ | |
| 22 | +//// redisCatchStorage.updateWVPInfo(); | |
| 23 | +// } | |
| 24 | 24 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java
| ... | ... | @@ -9,6 +9,7 @@ import java.util.concurrent.TimeUnit; |
| 9 | 9 | |
| 10 | 10 | import javax.sip.*; |
| 11 | 11 | import javax.sip.header.CallIdHeader; |
| 12 | +import javax.sip.header.Header; | |
| 12 | 13 | import javax.sip.message.Response; |
| 13 | 14 | |
| 14 | 15 | import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; |
| ... | ... | @@ -168,7 +169,8 @@ public class SipLayer implements SipListener { |
| 168 | 169 | if (callIdHeader != null) { |
| 169 | 170 | SipSubscribe.Event subscribe = sipSubscribe.getOkSubscribe(callIdHeader.getCallId()); |
| 170 | 171 | if (subscribe != null) { |
| 171 | - subscribe.response(evt); | |
| 172 | + SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(evt); | |
| 173 | + subscribe.response(eventResult); | |
| 172 | 174 | } |
| 173 | 175 | } |
| 174 | 176 | } |
| ... | ... | @@ -181,7 +183,8 @@ public class SipLayer implements SipListener { |
| 181 | 183 | if (callIdHeader != null) { |
| 182 | 184 | SipSubscribe.Event subscribe = sipSubscribe.getErrorSubscribe(callIdHeader.getCallId()); |
| 183 | 185 | if (subscribe != null) { |
| 184 | - subscribe.response(evt); | |
| 186 | + SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(evt); | |
| 187 | + subscribe.response(eventResult); | |
| 185 | 188 | } |
| 186 | 189 | } |
| 187 | 190 | } |
| ... | ... | @@ -204,7 +207,11 @@ public class SipLayer implements SipListener { |
| 204 | 207 | @Override |
| 205 | 208 | public void processTimeout(TimeoutEvent timeoutEvent) { |
| 206 | 209 | // TODO Auto-generated method stub |
| 207 | - | |
| 210 | + CallIdHeader callIdHeader = timeoutEvent.getClientTransaction().getDialog().getCallId(); | |
| 211 | + String callId = callIdHeader.getCallId(); | |
| 212 | + SipSubscribe.Event errorSubscribe = sipSubscribe.getErrorSubscribe(callId); | |
| 213 | + SipSubscribe.EventResult<TimeoutEvent> timeoutEventEventResult = new SipSubscribe.EventResult<>(timeoutEvent); | |
| 214 | + errorSubscribe.response(timeoutEventEventResult); | |
| 208 | 215 | } |
| 209 | 216 | |
| 210 | 217 | /** |
| ... | ... | @@ -220,6 +227,7 @@ public class SipLayer implements SipListener { |
| 220 | 227 | @Override |
| 221 | 228 | public void processIOException(IOExceptionEvent exceptionEvent) { |
| 222 | 229 | // TODO Auto-generated method stub |
| 230 | + | |
| 223 | 231 | } |
| 224 | 232 | |
| 225 | 233 | /** |
| ... | ... | @@ -235,6 +243,11 @@ public class SipLayer implements SipListener { |
| 235 | 243 | @Override |
| 236 | 244 | public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) { |
| 237 | 245 | // TODO Auto-generated method stub |
| 246 | +// CallIdHeader callIdHeader = transactionTerminatedEvent.getClientTransaction().getDialog().getCallId(); | |
| 247 | +// String callId = callIdHeader.getCallId(); | |
| 248 | +// SipSubscribe.Event errorSubscribe = sipSubscribe.getErrorSubscribe(callId); | |
| 249 | +// SipSubscribe.EventResult<TransactionTerminatedEvent> eventResult = new SipSubscribe.EventResult<>(transactionTerminatedEvent); | |
| 250 | +// errorSubscribe.response(eventResult); | |
| 238 | 251 | } |
| 239 | 252 | |
| 240 | 253 | /** |
| ... | ... | @@ -250,6 +263,11 @@ public class SipLayer implements SipListener { |
| 250 | 263 | @Override |
| 251 | 264 | public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) { |
| 252 | 265 | // TODO Auto-generated method stub |
| 266 | +// CallIdHeader callIdHeader = dialogTerminatedEvent.getDialog().getCallId(); | |
| 267 | +// String callId = callIdHeader.getCallId(); | |
| 268 | +// SipSubscribe.Event errorSubscribe = sipSubscribe.getErrorSubscribe(callId); | |
| 269 | +// SipSubscribe.EventResult<DialogTerminatedEvent> eventResult = new SipSubscribe.EventResult<>(dialogTerminatedEvent); | |
| 270 | +// errorSubscribe.response(eventResult); | |
| 253 | 271 | |
| 254 | 272 | } |
| 255 | 273 | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/event/SipSubscribe.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.event; |
| 2 | 2 | |
| 3 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | |
| 4 | +import org.slf4j.Logger; | |
| 5 | +import org.slf4j.LoggerFactory; | |
| 6 | +import org.springframework.scheduling.annotation.Scheduled; | |
| 3 | 7 | import org.springframework.stereotype.Component; |
| 4 | 8 | |
| 5 | -import javax.sip.ResponseEvent; | |
| 9 | +import javax.sip.*; | |
| 10 | +import java.util.Calendar; | |
| 11 | +import java.util.Date; | |
| 6 | 12 | import java.util.Map; |
| 7 | 13 | import java.util.concurrent.ConcurrentHashMap; |
| 8 | 14 | |
| 9 | 15 | @Component |
| 10 | 16 | public class SipSubscribe { |
| 11 | 17 | |
| 18 | + private final Logger logger = LoggerFactory.getLogger(SipSubscribe.class); | |
| 19 | + | |
| 12 | 20 | private Map<String, SipSubscribe.Event> errorSubscribes = new ConcurrentHashMap<>(); |
| 13 | 21 | |
| 14 | 22 | private Map<String, SipSubscribe.Event> okSubscribes = new ConcurrentHashMap<>(); |
| 15 | 23 | |
| 24 | + private Map<String, Date> timeSubscribes = new ConcurrentHashMap<>(); | |
| 25 | + | |
| 26 | +// @Scheduled(cron="*/5 * * * * ?") //每五秒执行一次 | |
| 27 | + @Scheduled(cron="0 * */1 * * ?") //每小时执行一次 | |
| 28 | + public void execute(){ | |
| 29 | + logger.info("[定时任务] 清理过期的订阅信息"); | |
| 30 | + Calendar calendar = Calendar.getInstance(); | |
| 31 | + calendar.setTime(new Date()); | |
| 32 | + calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) - 1); | |
| 33 | + for (String key : timeSubscribes.keySet()) { | |
| 34 | + if (timeSubscribes.get(key).before(calendar.getTime())){ | |
| 35 | + logger.info("[定时任务] 清理过期的订阅信息: {}", key); | |
| 36 | + errorSubscribes.remove(key); | |
| 37 | + okSubscribes.remove(key); | |
| 38 | + timeSubscribes.remove(key); | |
| 39 | + } | |
| 40 | + } | |
| 41 | + } | |
| 42 | + | |
| 16 | 43 | public interface Event { |
| 17 | - void response(ResponseEvent event); | |
| 44 | + void response(EventResult eventResult); | |
| 45 | + } | |
| 46 | + | |
| 47 | + public static class EventResult<EventObject>{ | |
| 48 | + public int statusCode; | |
| 49 | + public String type; | |
| 50 | + public String msg; | |
| 51 | + public String callId; | |
| 52 | + public Dialog dialog; | |
| 53 | + public EventObject event; | |
| 54 | + | |
| 55 | + public EventResult() { | |
| 56 | + } | |
| 57 | + | |
| 58 | + public EventResult(EventObject event) { | |
| 59 | + this.event = event; | |
| 60 | + if (event instanceof ResponseEvent) { | |
| 61 | + ResponseEvent responseEvent = (ResponseEvent)event; | |
| 62 | + this.type = "response"; | |
| 63 | + this.msg = responseEvent.getResponse().getReasonPhrase(); | |
| 64 | + this.statusCode = responseEvent.getResponse().getStatusCode(); | |
| 65 | + this.callId = responseEvent.getDialog().getCallId().getCallId(); | |
| 66 | + this.dialog = responseEvent.getDialog(); | |
| 67 | + }else if (event instanceof TimeoutEvent) { | |
| 68 | + TimeoutEvent timeoutEvent = (TimeoutEvent)event; | |
| 69 | + this.type = "timeout"; | |
| 70 | + this.msg = "消息超时未回复"; | |
| 71 | + this.statusCode = -1024; | |
| 72 | + this.callId = timeoutEvent.getClientTransaction().getDialog().getCallId().getCallId(); | |
| 73 | + this.dialog = timeoutEvent.getClientTransaction().getDialog(); | |
| 74 | + }else if (event instanceof TransactionTerminatedEvent) { | |
| 75 | + TransactionTerminatedEvent transactionTerminatedEvent = (TransactionTerminatedEvent)event; | |
| 76 | + this.type = "transactionTerminated"; | |
| 77 | + this.msg = "事务已结束"; | |
| 78 | + this.statusCode = -1024; | |
| 79 | + this.callId = transactionTerminatedEvent.getClientTransaction().getDialog().getCallId().getCallId(); | |
| 80 | + this.dialog = transactionTerminatedEvent.getClientTransaction().getDialog(); | |
| 81 | + }else if (event instanceof DialogTerminatedEvent) { | |
| 82 | + DialogTerminatedEvent dialogTerminatedEvent = (DialogTerminatedEvent)event; | |
| 83 | + this.type = "dialogTerminated"; | |
| 84 | + this.msg = "会话已结束"; | |
| 85 | + this.statusCode = -1024; | |
| 86 | + this.callId = dialogTerminatedEvent.getDialog().getCallId().getCallId(); | |
| 87 | + this.dialog = dialogTerminatedEvent.getDialog(); | |
| 88 | + } | |
| 89 | + } | |
| 18 | 90 | } |
| 19 | 91 | |
| 20 | 92 | public void addErrorSubscribe(String key, SipSubscribe.Event event) { |
| 21 | 93 | errorSubscribes.put(key, event); |
| 94 | + timeSubscribes.put(key, new Date()); | |
| 22 | 95 | } |
| 23 | 96 | |
| 24 | 97 | public void addOkSubscribe(String key, SipSubscribe.Event event) { |
| 25 | 98 | okSubscribes.put(key, event); |
| 99 | + timeSubscribes.put(key, new Date()); | |
| 26 | 100 | } |
| 27 | 101 | |
| 28 | 102 | public SipSubscribe.Event getErrorSubscribe(String key) { |
| 29 | 103 | return errorSubscribes.get(key); |
| 30 | 104 | } |
| 31 | 105 | |
| 106 | + public void removeErrorSubscribe(String key) { | |
| 107 | + errorSubscribes.remove(key); | |
| 108 | + timeSubscribes.remove(key); | |
| 109 | + } | |
| 110 | + | |
| 32 | 111 | public SipSubscribe.Event getOkSubscribe(String key) { |
| 33 | 112 | return okSubscribes.get(key); |
| 34 | 113 | } |
| 35 | 114 | |
| 115 | + public void removeOkSubscribe(String key) { | |
| 116 | + okSubscribes.remove(key); | |
| 117 | + timeSubscribes.remove(key); | |
| 118 | + } | |
| 36 | 119 | public int getErrorSubscribesSize(){ |
| 37 | 120 | return errorSubscribes.size(); |
| 38 | 121 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/event/platformKeepaliveExpire/PlatformKeepaliveExpireEventLister.java
| ... | ... | @@ -75,8 +75,8 @@ public class PlatformKeepaliveExpireEventLister implements ApplicationListener<P |
| 75 | 75 | redisCatchStorage.updatePlatformKeepalive(parentPlatform); |
| 76 | 76 | redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch); |
| 77 | 77 | |
| 78 | - sipSubscribe.addOkSubscribe(callId, (ResponseEvent responseEvent) ->{ | |
| 79 | - if (responseEvent.getResponse().getStatusCode() == Response.OK) { | |
| 78 | + sipSubscribe.addOkSubscribe(callId, (SipSubscribe.EventResult eventResult) ->{ | |
| 79 | + if (eventResult.statusCode == Response.OK) { | |
| 80 | 80 | // 收到心跳响应信息, |
| 81 | 81 | parentPlatformCatch.setKeepAliveReply(0); |
| 82 | 82 | redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
| ... | ... | @@ -427,8 +427,8 @@ public class SIPCommander implements ISIPCommander { |
| 427 | 427 | mediaServerService.releaseSsrc(mediaServerItem, ssrcInfo.getSsrc()); |
| 428 | 428 | errorEvent.response(e); |
| 429 | 429 | }), e ->{ |
| 430 | - streamSession.put(device.getDeviceId(), channelId ,ssrcInfo.getSsrc(), finalStreamId, mediaServerItem.getId(),e.getClientTransaction()); | |
| 431 | - streamSession.put(device.getDeviceId(), channelId , e.getDialog()); | |
| 430 | + streamSession.put(device.getDeviceId(), channelId ,ssrcInfo.getSsrc(), finalStreamId, mediaServerItem.getId(), ((ResponseEvent)e.event).getClientTransaction()); | |
| 431 | + streamSession.put(device.getDeviceId(), channelId , e.dialog); | |
| 432 | 432 | }); |
| 433 | 433 | |
| 434 | 434 | |
| ... | ... | @@ -535,9 +535,9 @@ public class SIPCommander implements ISIPCommander { |
| 535 | 535 | Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "fromplybck" + tm, null, callIdHeader, ssrcInfo.getSsrc()); |
| 536 | 536 | |
| 537 | 537 | transmitRequest(device, request, errorEvent, okEvent -> { |
| 538 | - Dialog dialog = okEvent.getClientTransaction().getDialog(); | |
| 539 | - streamSession.put(device.getDeviceId(), channelId, ssrcInfo.getSsrc(), ssrcInfo.getStreamId(), mediaServerItem.getId(), okEvent.getClientTransaction()); | |
| 540 | - streamSession.put(device.getDeviceId(), channelId, dialog); | |
| 538 | + ResponseEvent responseEvent = (ResponseEvent) okEvent.event; | |
| 539 | + streamSession.put(device.getDeviceId(), channelId, ssrcInfo.getSsrc(), ssrcInfo.getStreamId(), mediaServerItem.getId(), responseEvent.getClientTransaction()); | |
| 540 | + streamSession.put(device.getDeviceId(), channelId, okEvent.dialog); | |
| 541 | 541 | }); |
| 542 | 542 | } catch ( SipException | ParseException | InvalidArgumentException e) { |
| 543 | 543 | e.printStackTrace(); |
| ... | ... | @@ -667,6 +667,10 @@ public class SIPCommander implements ISIPCommander { |
| 667 | 667 | ClientTransaction transaction = streamSession.getTransaction(deviceId, channelId); |
| 668 | 668 | if (transaction == null) { |
| 669 | 669 | logger.warn("[ {} -> {}]停止视频流的时候发现事务已丢失", deviceId, channelId); |
| 670 | + SipSubscribe.EventResult<Object> eventResult = new SipSubscribe.EventResult<>(); | |
| 671 | + if (okEvent != null) { | |
| 672 | + okEvent.response(eventResult); | |
| 673 | + } | |
| 670 | 674 | return; |
| 671 | 675 | } |
| 672 | 676 | SIPDialog dialog = streamSession.getDialog(deviceId, channelId); |
| ... | ... | @@ -1506,11 +1510,17 @@ public class SIPCommander implements ISIPCommander { |
| 1506 | 1510 | CallIdHeader callIdHeader = (CallIdHeader)request.getHeader(CallIdHeader.NAME); |
| 1507 | 1511 | // 添加错误订阅 |
| 1508 | 1512 | if (errorEvent != null) { |
| 1509 | - sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), errorEvent); | |
| 1513 | + sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), (eventResult -> { | |
| 1514 | + errorEvent.response(eventResult); | |
| 1515 | + sipSubscribe.removeErrorSubscribe(eventResult.callId); | |
| 1516 | + })); | |
| 1510 | 1517 | } |
| 1511 | 1518 | // 添加订阅 |
| 1512 | 1519 | if (okEvent != null) { |
| 1513 | - sipSubscribe.addOkSubscribe(callIdHeader.getCallId(), okEvent); | |
| 1520 | + sipSubscribe.addOkSubscribe(callIdHeader.getCallId(), eventResult ->{ | |
| 1521 | + okEvent.response(eventResult); | |
| 1522 | + sipSubscribe.removeOkSubscribe(eventResult.callId); | |
| 1523 | + }); | |
| 1514 | 1524 | } |
| 1515 | 1525 | |
| 1516 | 1526 | clientTransaction.sendRequest(); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
| ... | ... | @@ -100,7 +100,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { |
| 100 | 100 | if (event != null) { |
| 101 | 101 | logger.info("向上级平台 [ {} ] 注册发上错误: {} ", |
| 102 | 102 | parentPlatform.getServerGBId(), |
| 103 | - event.getResponse().getReasonPhrase()); | |
| 103 | + event.msg); | |
| 104 | 104 | } |
| 105 | 105 | if (errorEvent != null ) { |
| 106 | 106 | errorEvent.response(event); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java
| ... | ... | @@ -235,7 +235,7 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor { |
| 235 | 235 | // 未知错误。直接转发设备点播的错误 |
| 236 | 236 | Response response = null; |
| 237 | 237 | try { |
| 238 | - response = getMessageFactory().createResponse(event.getResponse().getStatusCode(), evt.getRequest()); | |
| 238 | + response = getMessageFactory().createResponse(event.statusCode, evt.getRequest()); | |
| 239 | 239 | ServerTransaction serverTransaction = getServerTransaction(evt); |
| 240 | 240 | serverTransaction.sendResponse(response); |
| 241 | 241 | if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
| ... | ... | @@ -806,7 +806,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { |
| 806 | 806 | storager.insertMobilePosition(mobilePosition); |
| 807 | 807 | } |
| 808 | 808 | } |
| 809 | - System.out.println("存储报警信息、报警分类"); | |
| 809 | + logger.debug("存储报警信息、报警分类"); | |
| 810 | 810 | // 存储报警信息、报警分类 |
| 811 | 811 | deviceAlarmService.add(deviceAlarm); |
| 812 | 812 | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
| ... | ... | @@ -34,6 +34,10 @@ import org.springframework.stereotype.Service; |
| 34 | 34 | import org.springframework.util.ResourceUtils; |
| 35 | 35 | import org.springframework.web.context.request.async.DeferredResult; |
| 36 | 36 | |
| 37 | +import javax.sip.DialogTerminatedEvent; | |
| 38 | +import javax.sip.ResponseEvent; | |
| 39 | +import javax.sip.TimeoutEvent; | |
| 40 | +import javax.sip.TransactionTerminatedEvent; | |
| 37 | 41 | import javax.sip.message.Response; |
| 38 | 42 | import java.io.FileNotFoundException; |
| 39 | 43 | import java.util.UUID; |
| ... | ... | @@ -170,18 +174,18 @@ public class PlayServiceImpl implements IPlayService { |
| 170 | 174 | hookEvent.response(mediaServerItem, response); |
| 171 | 175 | } |
| 172 | 176 | }, (event) -> { |
| 173 | - // 点播返回sip错误 | |
| 174 | - Response response = event.getResponse(); | |
| 175 | - mediaServerService.closeRTPServer(playResult.getDevice(), channelId); | |
| 176 | 177 | WVPResult wvpResult = new WVPResult(); |
| 177 | 178 | wvpResult.setCode(-1); |
| 178 | - wvpResult.setMsg(String.format("点播失败, 错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 179 | + // 点播返回sip错误 | |
| 180 | + mediaServerService.closeRTPServer(playResult.getDevice(), channelId); | |
| 181 | + wvpResult.setMsg(String.format("点播失败, 错误码: %s, %s", event.statusCode, event.msg)); | |
| 179 | 182 | msg.setData(wvpResult); |
| 180 | 183 | resultHolder.invokeAllResult(msg); |
| 181 | 184 | if (errorEvent != null) { |
| 182 | 185 | errorEvent.response(event); |
| 183 | 186 | } |
| 184 | 187 | |
| 188 | + | |
| 185 | 189 | }); |
| 186 | 190 | } else { |
| 187 | 191 | String streamId = streamInfo.getStreamId(); |
| ... | ... | @@ -225,11 +229,9 @@ public class PlayServiceImpl implements IPlayService { |
| 225 | 229 | onPublishHandlerForPlay(mediaServerItemInuse, response, deviceId, channelId, uuid.toString()); |
| 226 | 230 | }, (event) -> { |
| 227 | 231 | mediaServerService.closeRTPServer(playResult.getDevice(), channelId); |
| 228 | - Response response = event.getResponse(); | |
| 229 | - | |
| 230 | 232 | WVPResult wvpResult = new WVPResult(); |
| 231 | 233 | wvpResult.setCode(-1); |
| 232 | - wvpResult.setMsg(String.format("点播失败, 错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 234 | + wvpResult.setMsg(String.format("点播失败, 错误码: %s, %s", event.statusCode, event.msg)); | |
| 233 | 235 | msg.setData(wvpResult); |
| 234 | 236 | resultHolder.invokeAllResult(msg); |
| 235 | 237 | }); |
| ... | ... | @@ -287,7 +289,8 @@ public class PlayServiceImpl implements IPlayService { |
| 287 | 289 | @Override |
| 288 | 290 | public void onPublishHandlerForPlayBack(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId, String uuid) { |
| 289 | 291 | RequestMessage msg = new RequestMessage(); |
| 290 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_PLAY + uuid); | |
| 292 | + msg.setKey(DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId); | |
| 293 | + msg.setId(uuid); | |
| 291 | 294 | StreamInfo streamInfo = onPublishHandler(mediaServerItem, resonse, deviceId, channelId, uuid); |
| 292 | 295 | if (streamInfo != null) { |
| 293 | 296 | redisCatchStorage.startPlayback(streamInfo); | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java
| ... | ... | @@ -115,11 +115,10 @@ public class MobilePositionController { |
| 115 | 115 | String uuid = UUID.randomUUID().toString(); |
| 116 | 116 | String key = DeferredResultHolder.CALLBACK_CMD_MOBILEPOSITION + deviceId; |
| 117 | 117 | cmder.mobilePostitionQuery(device, event -> { |
| 118 | - Response response = event.getResponse(); | |
| 119 | 118 | RequestMessage msg = new RequestMessage(); |
| 120 | 119 | msg.setId(uuid); |
| 121 | 120 | msg.setKey(key); |
| 122 | - msg.setData(String.format("获取移动位置信息失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 121 | + msg.setData(String.format("获取移动位置信息失败,错误码: %s, %s", event.statusCode, event.msg)); | |
| 123 | 122 | resultHolder.invokeResult(msg); |
| 124 | 123 | }); |
| 125 | 124 | DeferredResult<ResponseEntity<MobilePosition>> result = new DeferredResult<ResponseEntity<MobilePosition>>(5*1000L); | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceConfig.java
| ... | ... | @@ -80,11 +80,10 @@ public class DeviceConfig { |
| 80 | 80 | String uuid = UUID.randomUUID().toString(); |
| 81 | 81 | String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG + deviceId + channelId; |
| 82 | 82 | cmder.deviceBasicConfigCmd(device, channelId, name, expiration, heartBeatInterval, heartBeatCount, event -> { |
| 83 | - Response response = event.getResponse(); | |
| 84 | 83 | RequestMessage msg = new RequestMessage(); |
| 85 | 84 | msg.setId(uuid); |
| 86 | 85 | msg.setKey(key); |
| 87 | - msg.setData(String.format("设备配置操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 86 | + msg.setData(String.format("设备配置操作失败,错误码: %s, %s", event.statusCode, event.msg)); | |
| 88 | 87 | resultHolder.invokeResult(msg); |
| 89 | 88 | }); |
| 90 | 89 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); |
| ... | ... | @@ -129,11 +128,10 @@ public class DeviceConfig { |
| 129 | 128 | String uuid = UUID.randomUUID().toString(); |
| 130 | 129 | Device device = storager.queryVideoDevice(deviceId); |
| 131 | 130 | cmder.deviceConfigQuery(device, channelId, configType, event -> { |
| 132 | - Response response = event.getResponse(); | |
| 133 | 131 | RequestMessage msg = new RequestMessage(); |
| 134 | 132 | msg.setId(uuid); |
| 135 | 133 | msg.setKey(key); |
| 136 | - msg.setData(String.format("获取设备配置失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 134 | + msg.setData(String.format("获取设备配置失败,错误码: %s, %s", event.statusCode, event.msg)); | |
| 137 | 135 | resultHolder.invokeResult(msg); |
| 138 | 136 | }); |
| 139 | 137 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String >> (3 * 1000L); | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceControl.java
| ... | ... | @@ -113,11 +113,10 @@ public class DeviceControl { |
| 113 | 113 | return result; |
| 114 | 114 | } |
| 115 | 115 | cmder.recordCmd(device, channelId, recordCmdStr, event -> { |
| 116 | - Response response = event.getResponse(); | |
| 117 | 116 | RequestMessage msg = new RequestMessage(); |
| 118 | 117 | msg.setId(uuid); |
| 119 | 118 | msg.setKey(key); |
| 120 | - msg.setData(String.format("开始/停止录像操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 119 | + msg.setData(String.format("开始/停止录像操作失败,错误码: %s, %s", event.statusCode, event.msg)); | |
| 121 | 120 | resultHolder.invokeAllResult(msg); |
| 122 | 121 | }); |
| 123 | 122 | |
| ... | ... | @@ -146,11 +145,10 @@ public class DeviceControl { |
| 146 | 145 | String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId + channelId; |
| 147 | 146 | String uuid =UUID.randomUUID().toString(); |
| 148 | 147 | cmder.guardCmd(device, guardCmdStr, event -> { |
| 149 | - Response response = event.getResponse(); | |
| 150 | 148 | RequestMessage msg = new RequestMessage(); |
| 151 | 149 | msg.setId(uuid); |
| 152 | 150 | msg.setKey(key); |
| 153 | - msg.setData(String.format("布防/撤防操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 151 | + msg.setData(String.format("布防/撤防操作失败,错误码: %s, %s", event.statusCode, event.msg)); | |
| 154 | 152 | resultHolder.invokeResult(msg); |
| 155 | 153 | }); |
| 156 | 154 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); |
| ... | ... | @@ -193,11 +191,10 @@ public class DeviceControl { |
| 193 | 191 | String uuid = UUID.randomUUID().toString(); |
| 194 | 192 | String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId + channelId; |
| 195 | 193 | cmder.alarmCmd(device, alarmMethod, alarmType, event -> { |
| 196 | - Response response = event.getResponse(); | |
| 197 | 194 | RequestMessage msg = new RequestMessage(); |
| 198 | 195 | msg.setId(uuid); |
| 199 | 196 | msg.setKey(key); |
| 200 | - msg.setData(String.format("报警复位操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 197 | + msg.setData(String.format("报警复位操作失败,错误码: %s, %s", event.statusCode, event.msg)); | |
| 201 | 198 | resultHolder.invokeResult(msg); |
| 202 | 199 | }); |
| 203 | 200 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); |
| ... | ... | @@ -276,11 +273,10 @@ public class DeviceControl { |
| 276 | 273 | String uuid = UUID.randomUUID().toString(); |
| 277 | 274 | Device device = storager.queryVideoDevice(deviceId); |
| 278 | 275 | cmder.homePositionCmd(device, channelId, enabled, resetTime, presetIndex, event -> { |
| 279 | - Response response = event.getResponse(); | |
| 280 | 276 | RequestMessage msg = new RequestMessage(); |
| 281 | 277 | msg.setId(uuid); |
| 282 | 278 | msg.setKey(key); |
| 283 | - msg.setData(String.format("看守位控制操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 279 | + msg.setData(String.format("看守位控制操作失败,错误码: %s, %s", event.statusCode, event.msg)); | |
| 284 | 280 | resultHolder.invokeResult(msg); |
| 285 | 281 | }); |
| 286 | 282 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
| ... | ... | @@ -161,11 +161,10 @@ public class DeviceQuery { |
| 161 | 161 | return result; |
| 162 | 162 | } |
| 163 | 163 | cmder.catalogQuery(device, event -> { |
| 164 | - Response response = event.getResponse(); | |
| 165 | 164 | RequestMessage msg = new RequestMessage(); |
| 166 | 165 | msg.setKey(key); |
| 167 | 166 | msg.setId(uuid); |
| 168 | - msg.setData(String.format("同步通道失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 167 | + msg.setData(String.format("同步通道失败,错误码: %s, %s", event.statusCode, event.msg)); | |
| 169 | 168 | resultHolder.invokeAllResult(msg); |
| 170 | 169 | }); |
| 171 | 170 | |
| ... | ... | @@ -329,11 +328,10 @@ public class DeviceQuery { |
| 329 | 328 | String uuid = UUID.randomUUID().toString(); |
| 330 | 329 | String key = DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId; |
| 331 | 330 | cmder.deviceStatusQuery(device, event -> { |
| 332 | - Response response = event.getResponse(); | |
| 333 | 331 | RequestMessage msg = new RequestMessage(); |
| 334 | 332 | msg.setId(uuid); |
| 335 | 333 | msg.setKey(key); |
| 336 | - msg.setData(String.format("获取设备状态失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 334 | + msg.setData(String.format("获取设备状态失败,错误码: %s, %s", event.statusCode, event.msg)); | |
| 337 | 335 | resultHolder.invokeResult(msg); |
| 338 | 336 | }); |
| 339 | 337 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(2*1000L); |
| ... | ... | @@ -386,11 +384,10 @@ public class DeviceQuery { |
| 386 | 384 | String key = DeferredResultHolder.CALLBACK_CMD_ALARM + deviceId; |
| 387 | 385 | String uuid = UUID.randomUUID().toString(); |
| 388 | 386 | cmder.alarmInfoQuery(device, startPriority, endPriority, alarmMethod, alarmType, startTime, endTime, event -> { |
| 389 | - Response response = event.getResponse(); | |
| 390 | 387 | RequestMessage msg = new RequestMessage(); |
| 391 | 388 | msg.setId(uuid); |
| 392 | 389 | msg.setKey(key); |
| 393 | - msg.setData(String.format("设备报警查询失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 390 | + msg.setData(String.format("设备报警查询失败,错误码: %s, %s",event.statusCode, event.msg)); | |
| 394 | 391 | resultHolder.invokeResult(msg); |
| 395 | 392 | }); |
| 396 | 393 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String >> (3 * 1000L); | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java
| ... | ... | @@ -287,7 +287,6 @@ public class PlayController { |
| 287 | 287 | return result; |
| 288 | 288 | } |
| 289 | 289 | cmder.audioBroadcastCmd(device, (event) -> { |
| 290 | - Response response = event.getResponse(); | |
| 291 | 290 | RequestMessage msg = new RequestMessage(); |
| 292 | 291 | msg.setKey(key); |
| 293 | 292 | msg.setId(uuid); |
| ... | ... | @@ -295,7 +294,7 @@ public class PlayController { |
| 295 | 294 | json.put("DeviceID", deviceId); |
| 296 | 295 | json.put("CmdType", "Broadcast"); |
| 297 | 296 | json.put("Result", "Failed"); |
| 298 | - json.put("Description", String.format("语音广播操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 297 | + json.put("Description", String.format("语音广播操作失败,错误码: %s, %s", event.statusCode, event.msg)); | |
| 299 | 298 | msg.setData(json); |
| 300 | 299 | resultHolder.invokeResult(msg); |
| 301 | 300 | }); | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/DownloadController.java
| ... | ... | @@ -76,7 +76,7 @@ public class DownloadController { |
| 76 | 76 | if (logger.isDebugEnabled()) { |
| 77 | 77 | logger.debug(String.format("历史媒体下载 API调用,deviceId:%s,channelId:%s,downloadSpeed:%s", deviceId, channelId, downloadSpeed)); |
| 78 | 78 | } |
| 79 | - String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId + startTime + endTime; | |
| 79 | + String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId; | |
| 80 | 80 | String uuid = UUID.randomUUID().toString(); |
| 81 | 81 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(30000L); |
| 82 | 82 | // 超时处理 |
| ... | ... | @@ -116,11 +116,10 @@ public class DownloadController { |
| 116 | 116 | logger.info("收到订阅消息: " + response.toJSONString()); |
| 117 | 117 | playService.onPublishHandlerForPlayBack(mediaServerItem, response, deviceId, channelId, uuid.toString()); |
| 118 | 118 | }, event -> { |
| 119 | - Response response = event.getResponse(); | |
| 120 | 119 | RequestMessage msg = new RequestMessage(); |
| 121 | 120 | msg.setId(uuid); |
| 122 | 121 | msg.setKey(key); |
| 123 | - msg.setData(String.format("回放失败, 错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 122 | + msg.setData(String.format("回放失败, 错误码: %s, %s", event.statusCode, event.msg)); | |
| 124 | 123 | resultHolder.invokeAllResult(msg); |
| 125 | 124 | }); |
| 126 | 125 | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/PlaybackController.java
| ... | ... | @@ -77,7 +77,7 @@ public class PlaybackController { |
| 77 | 77 | logger.debug(String.format("设备回放 API调用,deviceId:%s ,channelId:%s", deviceId, channelId)); |
| 78 | 78 | } |
| 79 | 79 | String uuid = UUID.randomUUID().toString(); |
| 80 | - String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId + startTime + endTime; | |
| 80 | + String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId; | |
| 81 | 81 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(30000L); |
| 82 | 82 | Device device = storager.queryVideoDevice(deviceId); |
| 83 | 83 | if (device == null) { |
| ... | ... | @@ -102,7 +102,7 @@ public class PlaybackController { |
| 102 | 102 | // 停止之前的回放 |
| 103 | 103 | cmder.streamByeCmd(deviceId, channelId); |
| 104 | 104 | } |
| 105 | - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId + startTime + endTime, uuid, result); | |
| 105 | + resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId, uuid, result); | |
| 106 | 106 | |
| 107 | 107 | if (newMediaServerItem == null) { |
| 108 | 108 | logger.warn(String.format("设备回放超时,deviceId:%s ,channelId:%s", deviceId, channelId)); |
| ... | ... | @@ -118,11 +118,10 @@ public class PlaybackController { |
| 118 | 118 | logger.info("收到订阅消息: " + response.toJSONString()); |
| 119 | 119 | playService.onPublishHandlerForPlayBack(mediaServerItem, response, deviceId, channelId, uuid.toString()); |
| 120 | 120 | }, event -> { |
| 121 | - Response response = event.getResponse(); | |
| 122 | 121 | RequestMessage msg = new RequestMessage(); |
| 123 | 122 | msg.setId(uuid); |
| 124 | 123 | msg.setKey(key); |
| 125 | - msg.setData(String.format("回放失败, 错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 124 | + msg.setData(String.format("回放失败, 错误码: %s, %s", event.statusCode, event.msg)); | |
| 126 | 125 | resultHolder.invokeResult(msg); |
| 127 | 126 | }); |
| 128 | 127 | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/ptz/PtzController.java
| ... | ... | @@ -120,11 +120,10 @@ public class PtzController { |
| 120 | 120 | return result; |
| 121 | 121 | } |
| 122 | 122 | cmder.presetQuery(device, channelId, event -> { |
| 123 | - Response response = event.getResponse(); | |
| 124 | 123 | RequestMessage msg = new RequestMessage(); |
| 125 | 124 | msg.setId(uuid); |
| 126 | 125 | msg.setKey(key); |
| 127 | - msg.setData(String.format("获取设备预置位失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 126 | + msg.setData(String.format("获取设备预置位失败,错误码: %s, %s", event.statusCode, event.msg)); | |
| 128 | 127 | resultHolder.invokeResult(msg); |
| 129 | 128 | }); |
| 130 | 129 | ... | ... |