优化国标录像的异常判断

pull/590/head
648540858 2022-08-23 11:00:46 +08:00
parent 042b28b2d6
commit f24b6fa13f
6 changed files with 59 additions and 23 deletions

View File

@ -11,6 +11,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.service.bean.InviteTimeOutCallback; import com.genersoft.iot.vmp.service.bean.InviteTimeOutCallback;
import com.genersoft.iot.vmp.service.bean.PlayBackCallback; import com.genersoft.iot.vmp.service.bean.PlayBackCallback;
import com.genersoft.iot.vmp.service.bean.SSRCInfo; import com.genersoft.iot.vmp.service.bean.SSRCInfo;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.PlayResult; import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.PlayResult;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.context.request.async.DeferredResult; import org.springframework.web.context.request.async.DeferredResult;
@ -31,13 +32,13 @@ public interface IPlayService {
void onPublishHandlerForDownload(InviteStreamInfo inviteStreamInfo, String deviceId, String channelId, String toString); void onPublishHandlerForDownload(InviteStreamInfo inviteStreamInfo, String deviceId, String channelId, String toString);
DeferredResult<String> playBack(String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack); DeferredResult<WVPResult<StreamInfo>> playBack(String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
DeferredResult<String> playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack); DeferredResult<WVPResult<StreamInfo>> playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
void zlmServerOffline(String mediaServerId); void zlmServerOffline(String mediaServerId);
DeferredResult<String> download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack); DeferredResult<WVPResult<StreamInfo>> download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
DeferredResult<String> download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack); DeferredResult<WVPResult<StreamInfo>> download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
StreamInfo getDownLoadInfo(String deviceId, String channelId, String stream); StreamInfo getDownLoadInfo(String deviceId, String channelId, String stream);

View File

@ -12,6 +12,8 @@ import java.util.EventObject;
*/ */
public class PlayBackResult<T> { public class PlayBackResult<T> {
private int code; private int code;
private String msg;
private T data; private T data;
private MediaServerItem mediaServerItem; private MediaServerItem mediaServerItem;
private JSONObject response; private JSONObject response;
@ -56,4 +58,12 @@ public class PlayBackResult<T> {
public void setEvent(SipSubscribe.EventResult<EventObject> event) { public void setEvent(SipSubscribe.EventResult<EventObject> event) {
this.event = event; this.event = event;
} }
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
} }

View File

@ -384,7 +384,7 @@ public class PlayServiceImpl implements IPlayService {
} }
@Override @Override
public DeferredResult<String> playBack(String deviceId, String channelId, String startTime, public DeferredResult<WVPResult<StreamInfo>> playBack(String deviceId, String channelId, String startTime,
String endTime,InviteStreamCallback inviteStreamCallback, String endTime,InviteStreamCallback inviteStreamCallback,
PlayBackCallback callback) { PlayBackCallback callback) {
Device device = storager.queryVideoDevice(deviceId); Device device = storager.queryVideoDevice(deviceId);
@ -398,7 +398,7 @@ public class PlayServiceImpl implements IPlayService {
} }
@Override @Override
public DeferredResult<String> playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, public DeferredResult<WVPResult<StreamInfo>> playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,
String deviceId, String channelId, String startTime, String deviceId, String channelId, String startTime,
String endTime, InviteStreamCallback infoCallBack, String endTime, InviteStreamCallback infoCallBack,
PlayBackCallback playBackCallback) { PlayBackCallback playBackCallback) {
@ -411,7 +411,7 @@ public class PlayServiceImpl implements IPlayService {
if (device == null) { if (device == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备: " + deviceId + "不存在"); throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备: " + deviceId + "不存在");
} }
DeferredResult<String> result = new DeferredResult<>(30000L); DeferredResult<WVPResult<StreamInfo>> result = new DeferredResult<>(30000L);
resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PLAYBACK + deviceId + channelId, uuid, result); resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PLAYBACK + deviceId + channelId, uuid, result);
RequestMessage requestMessage = new RequestMessage(); RequestMessage requestMessage = new RequestMessage();
requestMessage.setId(uuid); requestMessage.setId(uuid);
@ -420,7 +420,8 @@ public class PlayServiceImpl implements IPlayService {
String playBackTimeOutTaskKey = UUID.randomUUID().toString(); String playBackTimeOutTaskKey = UUID.randomUUID().toString();
dynamicTask.startDelay(playBackTimeOutTaskKey, ()->{ dynamicTask.startDelay(playBackTimeOutTaskKey, ()->{
logger.warn(String.format("设备回放超时deviceId%s channelId%s", deviceId, channelId)); logger.warn(String.format("设备回放超时deviceId%s channelId%s", deviceId, channelId));
playBackResult.setCode(-1); playBackResult.setCode(ErrorCode.ERROR100.getCode());
playBackResult.setMsg("回放超时");
playBackResult.setData(requestMessage); playBackResult.setData(requestMessage);
SIPDialog dialog = streamSession.getDialogByStream(deviceId, channelId, ssrcInfo.getStream()); SIPDialog dialog = streamSession.getDialogByStream(deviceId, channelId, ssrcInfo.getStream());
// 点播超时回复BYE 同时释放ssrc以及此次点播的资源 // 点播超时回复BYE 同时释放ssrc以及此次点播的资源
@ -435,6 +436,8 @@ public class PlayServiceImpl implements IPlayService {
cmder.streamByeCmd(device.getDeviceId(), channelId, ssrcInfo.getStream(), null); cmder.streamByeCmd(device.getDeviceId(), channelId, ssrcInfo.getStream(), null);
// 回复之前所有的点播请求 // 回复之前所有的点播请求
playBackCallback.call(playBackResult); playBackCallback.call(playBackResult);
result.setResult(WVPResult.fail(ErrorCode.ERROR100.getCode(), "回放超时"));
resultHolder.exist(DeferredResultHolder.CALLBACK_CMD_PLAYBACK + deviceId + channelId, uuid);
}, userSetting.getPlayTimeout()); }, userSetting.getPlayTimeout());
cmder.playbackStreamCmd(mediaServerItem, ssrcInfo, device, channelId, startTime, endTime, infoCallBack, cmder.playbackStreamCmd(mediaServerItem, ssrcInfo, device, channelId, startTime, endTime, infoCallBack,
@ -444,14 +447,16 @@ public class PlayServiceImpl implements IPlayService {
StreamInfo streamInfo = onPublishHandler(inviteStreamInfo.getMediaServerItem(), inviteStreamInfo.getResponse(), deviceId, channelId); StreamInfo streamInfo = onPublishHandler(inviteStreamInfo.getMediaServerItem(), inviteStreamInfo.getResponse(), deviceId, channelId);
if (streamInfo == null) { if (streamInfo == null) {
logger.warn("设备回放API调用失败"); logger.warn("设备回放API调用失败");
playBackResult.setCode(-1); playBackResult.setCode(ErrorCode.ERROR100.getCode());
playBackResult.setMsg("设备回放API调用失败");
playBackCallback.call(playBackResult); playBackCallback.call(playBackResult);
return; return;
} }
redisCatchStorage.startPlayback(streamInfo, inviteStreamInfo.getCallId()); redisCatchStorage.startPlayback(streamInfo, inviteStreamInfo.getCallId());
WVPResult<StreamInfo> success = WVPResult.success(streamInfo); WVPResult<StreamInfo> success = WVPResult.success(streamInfo);
requestMessage.setData(success); requestMessage.setData(success);
playBackResult.setCode(0); playBackResult.setCode(ErrorCode.SUCCESS.getCode());
playBackResult.setMsg(ErrorCode.SUCCESS.getMsg());
playBackResult.setData(requestMessage); playBackResult.setData(requestMessage);
playBackResult.setMediaServerItem(inviteStreamInfo.getMediaServerItem()); playBackResult.setMediaServerItem(inviteStreamInfo.getMediaServerItem());
playBackResult.setResponse(inviteStreamInfo.getResponse()); playBackResult.setResponse(inviteStreamInfo.getResponse());
@ -459,7 +464,8 @@ public class PlayServiceImpl implements IPlayService {
}, event -> { }, event -> {
dynamicTask.stop(playBackTimeOutTaskKey); dynamicTask.stop(playBackTimeOutTaskKey);
requestMessage.setData(WVPResult.fail(ErrorCode.ERROR100.getCode(), String.format("回放失败, 错误码: %s, %s", event.statusCode, event.msg))); requestMessage.setData(WVPResult.fail(ErrorCode.ERROR100.getCode(), String.format("回放失败, 错误码: %s, %s", event.statusCode, event.msg)));
playBackResult.setCode(-1); playBackResult.setCode(ErrorCode.ERROR100.getCode());
playBackResult.setMsg(String.format("回放失败, 错误码: %s, %s", event.statusCode, event.msg));
playBackResult.setData(requestMessage); playBackResult.setData(requestMessage);
playBackResult.setEvent(event); playBackResult.setEvent(event);
playBackCallback.call(playBackResult); playBackCallback.call(playBackResult);
@ -469,7 +475,7 @@ public class PlayServiceImpl implements IPlayService {
} }
@Override @Override
public DeferredResult<String> download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) { public DeferredResult<WVPResult<StreamInfo>> download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) {
Device device = storager.queryVideoDevice(deviceId); Device device = storager.queryVideoDevice(deviceId);
if (device == null) { if (device == null) {
return null; return null;
@ -481,13 +487,13 @@ public class PlayServiceImpl implements IPlayService {
} }
@Override @Override
public DeferredResult<String> download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) { public DeferredResult<WVPResult<StreamInfo>> download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) {
if (mediaServerItem == null || ssrcInfo == null) { if (mediaServerItem == null || ssrcInfo == null) {
return null; return null;
} }
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
String key = DeferredResultHolder.CALLBACK_CMD_DOWNLOAD + deviceId + channelId; String key = DeferredResultHolder.CALLBACK_CMD_DOWNLOAD + deviceId + channelId;
DeferredResult<String> result = new DeferredResult<>(30000L); DeferredResult<WVPResult<StreamInfo>> result = new DeferredResult<>(30000L);
Device device = storager.queryVideoDevice(deviceId); Device device = storager.queryVideoDevice(deviceId);
if (device == null) { if (device == null) {
throw new ControllerException(ErrorCode.ERROR400.getCode(), "设备:" + deviceId + "不存在"); throw new ControllerException(ErrorCode.ERROR400.getCode(), "设备:" + deviceId + "不存在");
@ -507,7 +513,8 @@ public class PlayServiceImpl implements IPlayService {
logger.warn(String.format("录像下载请求超时deviceId%s channelId%s", deviceId, channelId)); logger.warn(String.format("录像下载请求超时deviceId%s channelId%s", deviceId, channelId));
wvpResult.setCode(ErrorCode.ERROR100.getCode()); wvpResult.setCode(ErrorCode.ERROR100.getCode());
wvpResult.setMsg("录像下载请求超时"); wvpResult.setMsg("录像下载请求超时");
downloadResult.setCode(-1); downloadResult.setCode(ErrorCode.ERROR100.getCode());
downloadResult.setMsg("录像下载请求超时");
hookCallBack.call(downloadResult); hookCallBack.call(downloadResult);
SIPDialog dialog = streamSession.getDialogByStream(deviceId, channelId, ssrcInfo.getStream()); SIPDialog dialog = streamSession.getDialogByStream(deviceId, channelId, ssrcInfo.getStream());
// 点播超时回复BYE 同时释放ssrc以及此次点播的资源 // 点播超时回复BYE 同时释放ssrc以及此次点播的资源
@ -534,13 +541,15 @@ public class PlayServiceImpl implements IPlayService {
wvpResult.setCode(ErrorCode.SUCCESS.getCode()); wvpResult.setCode(ErrorCode.SUCCESS.getCode());
wvpResult.setMsg(ErrorCode.SUCCESS.getMsg()); wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
wvpResult.setData(streamInfo); wvpResult.setData(streamInfo);
downloadResult.setCode(0); downloadResult.setCode(ErrorCode.SUCCESS.getCode());
downloadResult.setMsg(ErrorCode.SUCCESS.getMsg());
downloadResult.setMediaServerItem(inviteStreamInfo.getMediaServerItem()); downloadResult.setMediaServerItem(inviteStreamInfo.getMediaServerItem());
downloadResult.setResponse(inviteStreamInfo.getResponse()); downloadResult.setResponse(inviteStreamInfo.getResponse());
hookCallBack.call(downloadResult); hookCallBack.call(downloadResult);
}, event -> { }, event -> {
dynamicTask.stop(downLoadTimeOutTaskKey); dynamicTask.stop(downLoadTimeOutTaskKey);
downloadResult.setCode(-1); downloadResult.setCode(ErrorCode.ERROR100.getCode());
downloadResult.setMsg(String.format("录像下载失败, 错误码: %s, %s", event.statusCode, event.msg));
wvpResult.setCode(ErrorCode.ERROR100.getCode()); wvpResult.setCode(ErrorCode.ERROR100.getCode());
wvpResult.setMsg(String.format("录像下载失败, 错误码: %s, %s", event.statusCode, event.msg)); wvpResult.setMsg(String.format("录像下载失败, 错误码: %s, %s", event.statusCode, event.msg));
downloadResult.setEvent(event); downloadResult.setEvent(event);

View File

@ -3,9 +3,11 @@ package com.genersoft.iot.vmp.vmanager.gb28181.playback;
import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.service.IPlayService; import com.genersoft.iot.vmp.service.IPlayService;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
@ -57,8 +59,8 @@ public class PlaybackController {
@Parameter(name = "startTime", description = "开始时间", required = true) @Parameter(name = "startTime", description = "开始时间", required = true)
@Parameter(name = "endTime", description = "结束时间", required = true) @Parameter(name = "endTime", description = "结束时间", required = true)
@GetMapping("/start/{deviceId}/{channelId}") @GetMapping("/start/{deviceId}/{channelId}")
public DeferredResult<String> play(@PathVariable String deviceId, @PathVariable String channelId, public DeferredResult<WVPResult<StreamInfo>> play(@PathVariable String deviceId, @PathVariable String channelId,
String startTime,String endTime) { String startTime, String endTime) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(String.format("设备回放 API调用deviceId%s channelId%s", deviceId, channelId)); logger.debug(String.format("设备回放 API调用deviceId%s channelId%s", deviceId, channelId));
@ -66,7 +68,15 @@ public class PlaybackController {
return playService.playBack(deviceId, channelId, startTime, endTime, null, return playService.playBack(deviceId, channelId, startTime, endTime, null,
playBackResult->resultHolder.invokeResult(playBackResult.getData())); playBackResult->{
if (playBackResult.getCode() != ErrorCode.SUCCESS.getCode()) {
RequestMessage data = playBackResult.getData();
data.setData(WVPResult.fail(playBackResult.getCode(), playBackResult.getMsg()));
resultHolder.invokeResult(data);
}else {
resultHolder.invokeResult(playBackResult.getData());
}
});
} }

View File

@ -110,14 +110,14 @@ public class GBRecordController {
@Parameter(name = "endTime", description = "结束时间", required = true) @Parameter(name = "endTime", description = "结束时间", required = true)
@Parameter(name = "downloadSpeed", description = "下载倍速", required = true) @Parameter(name = "downloadSpeed", description = "下载倍速", required = true)
@GetMapping("/download/start/{deviceId}/{channelId}") @GetMapping("/download/start/{deviceId}/{channelId}")
public DeferredResult<String> download(@PathVariable String deviceId, @PathVariable String channelId, public DeferredResult<WVPResult<StreamInfo>> download(@PathVariable String deviceId, @PathVariable String channelId,
String startTime, String endTime, String downloadSpeed) { String startTime, String endTime, String downloadSpeed) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(String.format("历史媒体下载 API调用deviceId%schannelId%sdownloadSpeed%s", deviceId, channelId, downloadSpeed)); logger.debug(String.format("历史媒体下载 API调用deviceId%schannelId%sdownloadSpeed%s", deviceId, channelId, downloadSpeed));
} }
DeferredResult<String> result = playService.download(deviceId, channelId, startTime, endTime, Integer.parseInt(downloadSpeed), null, hookCallBack->{ DeferredResult<WVPResult<StreamInfo>> result = playService.download(deviceId, channelId, startTime, endTime, Integer.parseInt(downloadSpeed), null, hookCallBack->{
resultHolder.invokeResult(hookCallBack.getData()); resultHolder.invokeResult(hookCallBack.getData());
}); });

View File

@ -564,10 +564,10 @@ export default {
url: '/api/gb_record/query/' + this.deviceId + '/' + this.channelId + '?startTime=' + startTime + '&endTime=' + endTime url: '/api/gb_record/query/' + this.deviceId + '/' + this.channelId + '?startTime=' + startTime + '&endTime=' + endTime
}).then(function (res) { }).then(function (res) {
console.log(res) console.log(res)
that.recordsLoading = false;
if(res.data.code === 0) { if(res.data.code === 0) {
// //
that.videoHistory.searchHistoryResult = res.data.data.recordList; that.videoHistory.searchHistoryResult = res.data.data.recordList;
that.recordsLoading = false;
}else { }else {
this.$message({ this.$message({
showClose: true, showClose: true,
@ -613,6 +613,12 @@ export default {
that.mediaServerId = that.streamInfo.mediaServerId; that.mediaServerId = that.streamInfo.mediaServerId;
that.ssrc = that.streamInfo.ssrc; that.ssrc = that.streamInfo.ssrc;
that.videoUrl = that.getUrlByStreamInfo(); that.videoUrl = that.getUrlByStreamInfo();
}else {
that.$message({
showClose: true,
message: res.data.msg,
type: "error",
});
} }
that.recordPlay = true; that.recordPlay = true;
}); });