修复订阅sip消息导致的内存溢出以及录像回放的问题
| | |
| | | @Autowired |
| | | private MediaConfig mediaConfig; |
| | | |
| | | @Scheduled(cron="0/2 * * * * ? ") //每3秒执行一次 |
| | | public void execute(){ |
| | | // redisCatchStorage.updateWVPInfo(); |
| | | } |
| | | // @Scheduled(cron="0/2 * * * * ? ") //每3秒执行一次 |
| | | // public void execute(){ |
| | | //// redisCatchStorage.updateWVPInfo(); |
| | | // } |
| | | } |
| | |
| | |
|
| | | import javax.sip.*;
|
| | | import javax.sip.header.CallIdHeader;
|
| | | import javax.sip.header.Header;
|
| | | import javax.sip.message.Response;
|
| | |
|
| | | import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
| | |
| | | if (callIdHeader != null) {
|
| | | SipSubscribe.Event subscribe = sipSubscribe.getOkSubscribe(callIdHeader.getCallId());
|
| | | if (subscribe != null) {
|
| | | subscribe.response(evt);
|
| | | SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(evt);
|
| | | subscribe.response(eventResult);
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | if (callIdHeader != null) {
|
| | | SipSubscribe.Event subscribe = sipSubscribe.getErrorSubscribe(callIdHeader.getCallId());
|
| | | if (subscribe != null) {
|
| | | subscribe.response(evt);
|
| | | SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(evt);
|
| | | subscribe.response(eventResult);
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | @Override
|
| | | public void processTimeout(TimeoutEvent timeoutEvent) {
|
| | | // TODO Auto-generated method stub
|
| | |
|
| | | CallIdHeader callIdHeader = timeoutEvent.getClientTransaction().getDialog().getCallId();
|
| | | String callId = callIdHeader.getCallId();
|
| | | SipSubscribe.Event errorSubscribe = sipSubscribe.getErrorSubscribe(callId);
|
| | | SipSubscribe.EventResult<TimeoutEvent> timeoutEventEventResult = new SipSubscribe.EventResult<>(timeoutEvent);
|
| | | errorSubscribe.response(timeoutEventEventResult);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @Override
|
| | | public void processIOException(IOExceptionEvent exceptionEvent) {
|
| | | // TODO Auto-generated method stub
|
| | |
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @Override
|
| | | public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) {
|
| | | // TODO Auto-generated method stub
|
| | | // CallIdHeader callIdHeader = transactionTerminatedEvent.getClientTransaction().getDialog().getCallId();
|
| | | // String callId = callIdHeader.getCallId();
|
| | | // SipSubscribe.Event errorSubscribe = sipSubscribe.getErrorSubscribe(callId);
|
| | | // SipSubscribe.EventResult<TransactionTerminatedEvent> eventResult = new SipSubscribe.EventResult<>(transactionTerminatedEvent);
|
| | | // errorSubscribe.response(eventResult);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @Override
|
| | | public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) {
|
| | | // TODO Auto-generated method stub
|
| | | // CallIdHeader callIdHeader = dialogTerminatedEvent.getDialog().getCallId();
|
| | | // String callId = callIdHeader.getCallId();
|
| | | // SipSubscribe.Event errorSubscribe = sipSubscribe.getErrorSubscribe(callId);
|
| | | // SipSubscribe.EventResult<DialogTerminatedEvent> eventResult = new SipSubscribe.EventResult<>(dialogTerminatedEvent);
|
| | | // errorSubscribe.response(eventResult);
|
| | |
|
| | | }
|
| | |
|
| | |
| | | package com.genersoft.iot.vmp.gb28181.event; |
| | | |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.sip.ResponseEvent; |
| | | import javax.sip.*; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | @Component |
| | | public class SipSubscribe { |
| | | |
| | | private final Logger logger = LoggerFactory.getLogger(SipSubscribe.class); |
| | | |
| | | private Map<String, SipSubscribe.Event> errorSubscribes = new ConcurrentHashMap<>(); |
| | | |
| | | private Map<String, SipSubscribe.Event> okSubscribes = new ConcurrentHashMap<>(); |
| | | |
| | | private Map<String, Date> timeSubscribes = new ConcurrentHashMap<>(); |
| | | |
| | | // @Scheduled(cron="*/5 * * * * ?") //每五秒执行一次 |
| | | @Scheduled(cron="0 * */1 * * ?") //每小时执行一次 |
| | | public void execute(){ |
| | | logger.info("[定时任务] 清理过期的订阅信息"); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(new Date()); |
| | | calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) - 1); |
| | | for (String key : timeSubscribes.keySet()) { |
| | | if (timeSubscribes.get(key).before(calendar.getTime())){ |
| | | logger.info("[定时任务] 清理过期的订阅信息: {}", key); |
| | | errorSubscribes.remove(key); |
| | | okSubscribes.remove(key); |
| | | timeSubscribes.remove(key); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public interface Event { |
| | | void response(ResponseEvent event); |
| | | void response(EventResult eventResult); |
| | | } |
| | | |
| | | public static class EventResult<EventObject>{ |
| | | public int statusCode; |
| | | public String type; |
| | | public String msg; |
| | | public String callId; |
| | | public Dialog dialog; |
| | | public EventObject event; |
| | | |
| | | public EventResult() { |
| | | } |
| | | |
| | | public EventResult(EventObject event) { |
| | | this.event = event; |
| | | if (event instanceof ResponseEvent) { |
| | | ResponseEvent responseEvent = (ResponseEvent)event; |
| | | this.type = "response"; |
| | | this.msg = responseEvent.getResponse().getReasonPhrase(); |
| | | this.statusCode = responseEvent.getResponse().getStatusCode(); |
| | | this.callId = responseEvent.getDialog().getCallId().getCallId(); |
| | | this.dialog = responseEvent.getDialog(); |
| | | }else if (event instanceof TimeoutEvent) { |
| | | TimeoutEvent timeoutEvent = (TimeoutEvent)event; |
| | | this.type = "timeout"; |
| | | this.msg = "消息超时未回复"; |
| | | this.statusCode = -1024; |
| | | this.callId = timeoutEvent.getClientTransaction().getDialog().getCallId().getCallId(); |
| | | this.dialog = timeoutEvent.getClientTransaction().getDialog(); |
| | | }else if (event instanceof TransactionTerminatedEvent) { |
| | | TransactionTerminatedEvent transactionTerminatedEvent = (TransactionTerminatedEvent)event; |
| | | this.type = "transactionTerminated"; |
| | | this.msg = "事务已结束"; |
| | | this.statusCode = -1024; |
| | | this.callId = transactionTerminatedEvent.getClientTransaction().getDialog().getCallId().getCallId(); |
| | | this.dialog = transactionTerminatedEvent.getClientTransaction().getDialog(); |
| | | }else if (event instanceof DialogTerminatedEvent) { |
| | | DialogTerminatedEvent dialogTerminatedEvent = (DialogTerminatedEvent)event; |
| | | this.type = "dialogTerminated"; |
| | | this.msg = "会话已结束"; |
| | | this.statusCode = -1024; |
| | | this.callId = dialogTerminatedEvent.getDialog().getCallId().getCallId(); |
| | | this.dialog = dialogTerminatedEvent.getDialog(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void addErrorSubscribe(String key, SipSubscribe.Event event) { |
| | | errorSubscribes.put(key, event); |
| | | timeSubscribes.put(key, new Date()); |
| | | } |
| | | |
| | | public void addOkSubscribe(String key, SipSubscribe.Event event) { |
| | | okSubscribes.put(key, event); |
| | | timeSubscribes.put(key, new Date()); |
| | | } |
| | | |
| | | public SipSubscribe.Event getErrorSubscribe(String key) { |
| | | return errorSubscribes.get(key); |
| | | } |
| | | |
| | | public void removeErrorSubscribe(String key) { |
| | | errorSubscribes.remove(key); |
| | | timeSubscribes.remove(key); |
| | | } |
| | | |
| | | public SipSubscribe.Event getOkSubscribe(String key) { |
| | | return okSubscribes.get(key); |
| | | } |
| | | |
| | | public void removeOkSubscribe(String key) { |
| | | okSubscribes.remove(key); |
| | | timeSubscribes.remove(key); |
| | | } |
| | | public int getErrorSubscribesSize(){ |
| | | return errorSubscribes.size(); |
| | | } |
| | |
| | | redisCatchStorage.updatePlatformKeepalive(parentPlatform); |
| | | redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch); |
| | | |
| | | sipSubscribe.addOkSubscribe(callId, (ResponseEvent responseEvent) ->{ |
| | | if (responseEvent.getResponse().getStatusCode() == Response.OK) { |
| | | sipSubscribe.addOkSubscribe(callId, (SipSubscribe.EventResult eventResult) ->{ |
| | | if (eventResult.statusCode == Response.OK) { |
| | | // 收到心跳响应信息, |
| | | parentPlatformCatch.setKeepAliveReply(0); |
| | | redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch); |
| | |
| | | mediaServerService.releaseSsrc(mediaServerItem, ssrcInfo.getSsrc());
|
| | | errorEvent.response(e);
|
| | | }), e ->{
|
| | | streamSession.put(device.getDeviceId(), channelId ,ssrcInfo.getSsrc(), finalStreamId, mediaServerItem.getId(),e.getClientTransaction());
|
| | | streamSession.put(device.getDeviceId(), channelId , e.getDialog());
|
| | | streamSession.put(device.getDeviceId(), channelId ,ssrcInfo.getSsrc(), finalStreamId, mediaServerItem.getId(), ((ResponseEvent)e.event).getClientTransaction());
|
| | | streamSession.put(device.getDeviceId(), channelId , e.dialog);
|
| | | });
|
| | |
|
| | |
|
| | |
| | | Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "fromplybck" + tm, null, callIdHeader, ssrcInfo.getSsrc());
|
| | |
|
| | | transmitRequest(device, request, errorEvent, okEvent -> {
|
| | | Dialog dialog = okEvent.getClientTransaction().getDialog();
|
| | | streamSession.put(device.getDeviceId(), channelId, ssrcInfo.getSsrc(), ssrcInfo.getStreamId(), mediaServerItem.getId(), okEvent.getClientTransaction());
|
| | | streamSession.put(device.getDeviceId(), channelId, dialog);
|
| | | ResponseEvent responseEvent = (ResponseEvent) okEvent.event;
|
| | | streamSession.put(device.getDeviceId(), channelId, ssrcInfo.getSsrc(), ssrcInfo.getStreamId(), mediaServerItem.getId(), responseEvent.getClientTransaction());
|
| | | streamSession.put(device.getDeviceId(), channelId, okEvent.dialog);
|
| | | });
|
| | | } catch ( SipException | ParseException | InvalidArgumentException e) {
|
| | | e.printStackTrace();
|
| | |
| | | ClientTransaction transaction = streamSession.getTransaction(deviceId, channelId);
|
| | | if (transaction == null) {
|
| | | logger.warn("[ {} -> {}]停止视频流的时候发现事务已丢失", deviceId, channelId);
|
| | | SipSubscribe.EventResult<Object> eventResult = new SipSubscribe.EventResult<>();
|
| | | if (okEvent != null) {
|
| | | okEvent.response(eventResult);
|
| | | }
|
| | | return;
|
| | | }
|
| | | SIPDialog dialog = streamSession.getDialog(deviceId, channelId);
|
| | |
| | | CallIdHeader callIdHeader = (CallIdHeader)request.getHeader(CallIdHeader.NAME);
|
| | | // 添加错误订阅
|
| | | if (errorEvent != null) {
|
| | | sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), errorEvent);
|
| | | sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), (eventResult -> {
|
| | | errorEvent.response(eventResult);
|
| | | sipSubscribe.removeErrorSubscribe(eventResult.callId);
|
| | | }));
|
| | | }
|
| | | // 添加订阅
|
| | | if (okEvent != null) {
|
| | | sipSubscribe.addOkSubscribe(callIdHeader.getCallId(), okEvent);
|
| | | sipSubscribe.addOkSubscribe(callIdHeader.getCallId(), eventResult ->{
|
| | | okEvent.response(eventResult);
|
| | | sipSubscribe.removeOkSubscribe(eventResult.callId);
|
| | | });
|
| | | }
|
| | |
|
| | | clientTransaction.sendRequest();
|
| | |
| | | if (event != null) { |
| | | logger.info("向上级平台 [ {} ] 注册发上错误: {} ", |
| | | parentPlatform.getServerGBId(), |
| | | event.getResponse().getReasonPhrase()); |
| | | event.msg); |
| | | } |
| | | if (errorEvent != null ) { |
| | | errorEvent.response(event); |
| | |
| | | // 未知错误。直接转发设备点播的错误
|
| | | Response response = null;
|
| | | try {
|
| | | response = getMessageFactory().createResponse(event.getResponse().getStatusCode(), evt.getRequest());
|
| | | response = getMessageFactory().createResponse(event.statusCode, evt.getRequest());
|
| | | ServerTransaction serverTransaction = getServerTransaction(evt);
|
| | | serverTransaction.sendResponse(response);
|
| | | if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
|
| | |
| | | storager.insertMobilePosition(mobilePosition);
|
| | | }
|
| | | }
|
| | | System.out.println("存储报警信息、报警分类");
|
| | | logger.debug("存储报警信息、报警分类");
|
| | | // 存储报警信息、报警分类
|
| | | deviceAlarmService.add(deviceAlarm);
|
| | |
|
| | |
| | | import org.springframework.util.ResourceUtils; |
| | | import org.springframework.web.context.request.async.DeferredResult; |
| | | |
| | | import javax.sip.DialogTerminatedEvent; |
| | | import javax.sip.ResponseEvent; |
| | | import javax.sip.TimeoutEvent; |
| | | import javax.sip.TransactionTerminatedEvent; |
| | | import javax.sip.message.Response; |
| | | import java.io.FileNotFoundException; |
| | | import java.util.UUID; |
| | |
| | | hookEvent.response(mediaServerItem, response); |
| | | } |
| | | }, (event) -> { |
| | | // 点播返回sip错误 |
| | | Response response = event.getResponse(); |
| | | mediaServerService.closeRTPServer(playResult.getDevice(), channelId); |
| | | WVPResult wvpResult = new WVPResult(); |
| | | wvpResult.setCode(-1); |
| | | wvpResult.setMsg(String.format("点播失败, 错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | // 点播返回sip错误 |
| | | mediaServerService.closeRTPServer(playResult.getDevice(), channelId); |
| | | wvpResult.setMsg(String.format("点播失败, 错误码: %s, %s", event.statusCode, event.msg)); |
| | | msg.setData(wvpResult); |
| | | resultHolder.invokeAllResult(msg); |
| | | if (errorEvent != null) { |
| | | errorEvent.response(event); |
| | | } |
| | | |
| | | |
| | | }); |
| | | } else { |
| | |
| | | onPublishHandlerForPlay(mediaServerItemInuse, response, deviceId, channelId, uuid.toString()); |
| | | }, (event) -> { |
| | | mediaServerService.closeRTPServer(playResult.getDevice(), channelId); |
| | | Response response = event.getResponse(); |
| | | |
| | | WVPResult wvpResult = new WVPResult(); |
| | | wvpResult.setCode(-1); |
| | | wvpResult.setMsg(String.format("点播失败, 错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | wvpResult.setMsg(String.format("点播失败, 错误码: %s, %s", event.statusCode, event.msg)); |
| | | msg.setData(wvpResult); |
| | | resultHolder.invokeAllResult(msg); |
| | | }); |
| | |
| | | @Override |
| | | public void onPublishHandlerForPlayBack(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId, String uuid) { |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(DeferredResultHolder.CALLBACK_CMD_PLAY + uuid); |
| | | msg.setKey(DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId); |
| | | msg.setId(uuid); |
| | | StreamInfo streamInfo = onPublishHandler(mediaServerItem, resonse, deviceId, channelId, uuid); |
| | | if (streamInfo != null) { |
| | | redisCatchStorage.startPlayback(streamInfo); |
| | |
| | | String uuid = UUID.randomUUID().toString(); |
| | | String key = DeferredResultHolder.CALLBACK_CMD_MOBILEPOSITION + deviceId; |
| | | cmder.mobilePostitionQuery(device, event -> { |
| | | Response response = event.getResponse(); |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(uuid); |
| | | msg.setKey(key); |
| | | msg.setData(String.format("获取移动位置信息失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | msg.setData(String.format("获取移动位置信息失败,错误码: %s, %s", event.statusCode, event.msg)); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | DeferredResult<ResponseEntity<MobilePosition>> result = new DeferredResult<ResponseEntity<MobilePosition>>(5*1000L); |
| | |
| | | String uuid = UUID.randomUUID().toString(); |
| | | String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG + deviceId + channelId; |
| | | cmder.deviceBasicConfigCmd(device, channelId, name, expiration, heartBeatInterval, heartBeatCount, event -> { |
| | | Response response = event.getResponse(); |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(uuid); |
| | | msg.setKey(key); |
| | | msg.setData(String.format("设备配置操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | msg.setData(String.format("设备配置操作失败,错误码: %s, %s", event.statusCode, event.msg)); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); |
| | |
| | | String uuid = UUID.randomUUID().toString(); |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | cmder.deviceConfigQuery(device, channelId, configType, event -> { |
| | | Response response = event.getResponse(); |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(uuid); |
| | | msg.setKey(key); |
| | | msg.setData(String.format("获取设备配置失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | msg.setData(String.format("获取设备配置失败,错误码: %s, %s", event.statusCode, event.msg)); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String >> (3 * 1000L); |
| | |
| | | return result; |
| | | } |
| | | cmder.recordCmd(device, channelId, recordCmdStr, event -> { |
| | | Response response = event.getResponse(); |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(uuid); |
| | | msg.setKey(key); |
| | | msg.setData(String.format("开始/停止录像操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | msg.setData(String.format("开始/停止录像操作失败,错误码: %s, %s", event.statusCode, event.msg)); |
| | | resultHolder.invokeAllResult(msg); |
| | | }); |
| | | |
| | |
| | | String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId + channelId; |
| | | String uuid =UUID.randomUUID().toString(); |
| | | cmder.guardCmd(device, guardCmdStr, event -> { |
| | | Response response = event.getResponse(); |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(uuid); |
| | | msg.setKey(key); |
| | | msg.setData(String.format("布防/撤防操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | msg.setData(String.format("布防/撤防操作失败,错误码: %s, %s", event.statusCode, event.msg)); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); |
| | |
| | | String uuid = UUID.randomUUID().toString(); |
| | | String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId + channelId; |
| | | cmder.alarmCmd(device, alarmMethod, alarmType, event -> { |
| | | Response response = event.getResponse(); |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(uuid); |
| | | msg.setKey(key); |
| | | msg.setData(String.format("报警复位操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | msg.setData(String.format("报警复位操作失败,错误码: %s, %s", event.statusCode, event.msg)); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); |
| | |
| | | String uuid = UUID.randomUUID().toString(); |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | cmder.homePositionCmd(device, channelId, enabled, resetTime, presetIndex, event -> { |
| | | Response response = event.getResponse(); |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(uuid); |
| | | msg.setKey(key); |
| | | msg.setData(String.format("看守位控制操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | msg.setData(String.format("看守位控制操作失败,错误码: %s, %s", event.statusCode, event.msg)); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); |
| | |
| | | return result; |
| | | } |
| | | cmder.catalogQuery(device, event -> { |
| | | Response response = event.getResponse(); |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setKey(key); |
| | | msg.setId(uuid); |
| | | msg.setData(String.format("同步通道失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | msg.setData(String.format("同步通道失败,错误码: %s, %s", event.statusCode, event.msg)); |
| | | resultHolder.invokeAllResult(msg); |
| | | }); |
| | | |
| | |
| | | String uuid = UUID.randomUUID().toString(); |
| | | String key = DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId; |
| | | cmder.deviceStatusQuery(device, event -> { |
| | | Response response = event.getResponse(); |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(uuid); |
| | | msg.setKey(key); |
| | | msg.setData(String.format("获取设备状态失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | msg.setData(String.format("获取设备状态失败,错误码: %s, %s", event.statusCode, event.msg)); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(2*1000L); |
| | |
| | | String key = DeferredResultHolder.CALLBACK_CMD_ALARM + deviceId; |
| | | String uuid = UUID.randomUUID().toString(); |
| | | cmder.alarmInfoQuery(device, startPriority, endPriority, alarmMethod, alarmType, startTime, endTime, event -> { |
| | | Response response = event.getResponse(); |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(uuid); |
| | | msg.setKey(key); |
| | | msg.setData(String.format("设备报警查询失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | msg.setData(String.format("设备报警查询失败,错误码: %s, %s",event.statusCode, event.msg)); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String >> (3 * 1000L); |
| | |
| | | return result; |
| | | } |
| | | cmder.audioBroadcastCmd(device, (event) -> { |
| | | Response response = event.getResponse(); |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setKey(key); |
| | | msg.setId(uuid); |
| | |
| | | json.put("DeviceID", deviceId); |
| | | json.put("CmdType", "Broadcast"); |
| | | json.put("Result", "Failed"); |
| | | json.put("Description", String.format("语音广播操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | json.put("Description", String.format("语音广播操作失败,错误码: %s, %s", event.statusCode, event.msg)); |
| | | msg.setData(json); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | |
| | | if (logger.isDebugEnabled()) { |
| | | logger.debug(String.format("历史媒体下载 API调用,deviceId:%s,channelId:%s,downloadSpeed:%s", deviceId, channelId, downloadSpeed)); |
| | | } |
| | | String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId + startTime + endTime; |
| | | String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId; |
| | | String uuid = UUID.randomUUID().toString(); |
| | | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(30000L); |
| | | // 超时处理 |
| | |
| | | logger.info("收到订阅消息: " + response.toJSONString()); |
| | | playService.onPublishHandlerForPlayBack(mediaServerItem, response, deviceId, channelId, uuid.toString()); |
| | | }, event -> { |
| | | Response response = event.getResponse(); |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(uuid); |
| | | msg.setKey(key); |
| | | msg.setData(String.format("回放失败, 错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | msg.setData(String.format("回放失败, 错误码: %s, %s", event.statusCode, event.msg)); |
| | | resultHolder.invokeAllResult(msg); |
| | | }); |
| | | |
| | |
| | | logger.debug(String.format("设备回放 API调用,deviceId:%s ,channelId:%s", deviceId, channelId)); |
| | | } |
| | | String uuid = UUID.randomUUID().toString(); |
| | | String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId + startTime + endTime; |
| | | String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId; |
| | | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(30000L); |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | if (device == null) { |
| | |
| | | // 停止之前的回放 |
| | | cmder.streamByeCmd(deviceId, channelId); |
| | | } |
| | | resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId + startTime + endTime, uuid, result); |
| | | resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId, uuid, result); |
| | | |
| | | if (newMediaServerItem == null) { |
| | | logger.warn(String.format("设备回放超时,deviceId:%s ,channelId:%s", deviceId, channelId)); |
| | |
| | | logger.info("收到订阅消息: " + response.toJSONString()); |
| | | playService.onPublishHandlerForPlayBack(mediaServerItem, response, deviceId, channelId, uuid.toString()); |
| | | }, event -> { |
| | | Response response = event.getResponse(); |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(uuid); |
| | | msg.setKey(key); |
| | | msg.setData(String.format("回放失败, 错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | msg.setData(String.format("回放失败, 错误码: %s, %s", event.statusCode, event.msg)); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | |
| | |
| | | return result; |
| | | } |
| | | cmder.presetQuery(device, channelId, event -> { |
| | | Response response = event.getResponse(); |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(uuid); |
| | | msg.setKey(key); |
| | | msg.setData(String.format("获取设备预置位失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | msg.setData(String.format("获取设备预置位失败,错误码: %s, %s", event.statusCode, event.msg)); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | |