Prechádzať zdrojové kódy

Merge branch 'wvp-28181-2.0'

# Conflicts:
#	src/main/java/com/genersoft/iot/vmp/service/IPlayService.java
648540858 3 rokov pred
rodič
commit
020f9ea8a0

+ 5 - 4
src/main/java/com/genersoft/iot/vmp/service/IPlayService.java

@@ -12,6 +12,7 @@ import com.genersoft.iot.vmp.service.bean.InviteTimeOutCallback;
 import com.genersoft.iot.vmp.service.bean.PlayBackCallback;
 import com.genersoft.iot.vmp.service.bean.SSRCInfo;
 import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.AudioBroadcastEvent;
+import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
 import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.PlayResult;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.context.request.async.DeferredResult;
@@ -32,13 +33,13 @@ public interface IPlayService {
 
     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<String> playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,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<WVPResult<StreamInfo>> playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
 
     void zlmServerOffline(String mediaServerId);
 
-    DeferredResult<String> 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(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);
 

+ 10 - 0
src/main/java/com/genersoft/iot/vmp/service/bean/PlayBackResult.java

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

+ 22 - 13
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java

@@ -410,7 +410,7 @@ public class PlayServiceImpl implements IPlayService {
     }
 
     @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,
                                                            PlayBackCallback callback) {
         Device device = storager.queryVideoDevice(deviceId);
@@ -424,7 +424,7 @@ public class PlayServiceImpl implements IPlayService {
     }
 
     @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 endTime, InviteStreamCallback infoCallBack,
                                                            PlayBackCallback playBackCallback) {
@@ -437,7 +437,7 @@ public class PlayServiceImpl implements IPlayService {
         if (device == null) {
             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);
         RequestMessage requestMessage = new RequestMessage();
         requestMessage.setId(uuid);
@@ -446,7 +446,8 @@ public class PlayServiceImpl implements IPlayService {
         String playBackTimeOutTaskKey = UUID.randomUUID().toString();
         dynamicTask.startDelay(playBackTimeOutTaskKey, ()->{
             logger.warn(String.format("设备回放超时,deviceId:%s ,channelId:%s", deviceId, channelId));
-            playBackResult.setCode(-1);
+            playBackResult.setCode(ErrorCode.ERROR100.getCode());
+            playBackResult.setMsg("回放超时");
             playBackResult.setData(requestMessage);
             SIPDialog dialog = streamSession.getDialogByStream(deviceId, channelId, ssrcInfo.getStream());
             // 点播超时回复BYE 同时释放ssrc以及此次点播的资源
@@ -461,6 +462,8 @@ public class PlayServiceImpl implements IPlayService {
             cmder.streamByeCmd(device.getDeviceId(), channelId, ssrcInfo.getStream(), null);
             // 回复之前所有的点播请求
             playBackCallback.call(playBackResult);
+            result.setResult(WVPResult.fail(ErrorCode.ERROR100.getCode(), "回放超时"));
+            resultHolder.exist(DeferredResultHolder.CALLBACK_CMD_PLAYBACK + deviceId + channelId, uuid);
         }, userSetting.getPlayTimeout());
 
         cmder.playbackStreamCmd(mediaServerItem, ssrcInfo, device, channelId, startTime, endTime, infoCallBack,
@@ -470,14 +473,16 @@ public class PlayServiceImpl implements IPlayService {
                     StreamInfo streamInfo = onPublishHandler(inviteStreamInfo.getMediaServerItem(), inviteStreamInfo.getResponse(), deviceId, channelId);
                     if (streamInfo == null) {
                         logger.warn("设备回放API调用失败!");
-                        playBackResult.setCode(-1);
+                        playBackResult.setCode(ErrorCode.ERROR100.getCode());
+                        playBackResult.setMsg("设备回放API调用失败!");
                         playBackCallback.call(playBackResult);
                         return;
                     }
                     redisCatchStorage.startPlayback(streamInfo, inviteStreamInfo.getCallId());
                     WVPResult<StreamInfo> success = WVPResult.success(streamInfo);
                     requestMessage.setData(success);
-                    playBackResult.setCode(0);
+                    playBackResult.setCode(ErrorCode.SUCCESS.getCode());
+                    playBackResult.setMsg(ErrorCode.SUCCESS.getMsg());
                     playBackResult.setData(requestMessage);
                     playBackResult.setMediaServerItem(inviteStreamInfo.getMediaServerItem());
                     playBackResult.setResponse(inviteStreamInfo.getResponse());
@@ -485,7 +490,8 @@ public class PlayServiceImpl implements IPlayService {
                 }, event -> {
                     dynamicTask.stop(playBackTimeOutTaskKey);
                     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.setEvent(event);
                     playBackCallback.call(playBackResult);
@@ -495,7 +501,7 @@ public class PlayServiceImpl implements IPlayService {
     }
 
     @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);
         if (device == null) {
             return null;
@@ -507,13 +513,13 @@ public class PlayServiceImpl implements IPlayService {
     }
 
     @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) {
             return null;
         }
         String uuid = UUID.randomUUID().toString();
         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);
         if (device == null) {
             throw new ControllerException(ErrorCode.ERROR400.getCode(), "设备:" + deviceId + "不存在");
@@ -533,7 +539,8 @@ public class PlayServiceImpl implements IPlayService {
             logger.warn(String.format("录像下载请求超时,deviceId:%s ,channelId:%s", deviceId, channelId));
             wvpResult.setCode(ErrorCode.ERROR100.getCode());
             wvpResult.setMsg("录像下载请求超时");
-            downloadResult.setCode(-1);
+            downloadResult.setCode(ErrorCode.ERROR100.getCode());
+            downloadResult.setMsg("录像下载请求超时");
             hookCallBack.call(downloadResult);
             SIPDialog dialog = streamSession.getDialogByStream(deviceId, channelId, ssrcInfo.getStream());
             // 点播超时回复BYE 同时释放ssrc以及此次点播的资源
@@ -568,13 +575,15 @@ public class PlayServiceImpl implements IPlayService {
                     wvpResult.setCode(ErrorCode.SUCCESS.getCode());
                     wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
                     wvpResult.setData(streamInfo);
-                    downloadResult.setCode(0);
+                    downloadResult.setCode(ErrorCode.SUCCESS.getCode());
+                    downloadResult.setMsg(ErrorCode.SUCCESS.getMsg());
                     downloadResult.setMediaServerItem(inviteStreamInfo.getMediaServerItem());
                     downloadResult.setResponse(inviteStreamInfo.getResponse());
                     hookCallBack.call(downloadResult);
                 }, event -> {
                     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.setMsg(String.format("录像下载失败, 错误码: %s, %s", event.statusCode, event.msg));
                     downloadResult.setEvent(event);

+ 13 - 3
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/PlaybackController.java

@@ -3,9 +3,11 @@ package com.genersoft.iot.vmp.vmanager.gb28181.playback;
 import com.genersoft.iot.vmp.common.StreamInfo;
 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.RequestMessage;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
 import com.genersoft.iot.vmp.service.IPlayService;
 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.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -57,8 +59,8 @@ public class PlaybackController {
 	@Parameter(name = "startTime", description = "开始时间", required = true)
 	@Parameter(name = "endTime", description = "结束时间", required = true)
 	@GetMapping("/start/{deviceId}/{channelId}")
-	public DeferredResult<String> play(@PathVariable String deviceId, @PathVariable String channelId,
-													   String startTime,String endTime) {
+	public DeferredResult<WVPResult<StreamInfo>> play(@PathVariable String deviceId, @PathVariable String channelId,
+										  String startTime, String endTime) {
 
 		if (logger.isDebugEnabled()) {
 			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,
-				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());
+					}
+				});
 	}
 
 

+ 2 - 2
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java

@@ -110,14 +110,14 @@ public class GBRecordController {
 	@Parameter(name = "endTime", description = "结束时间", required = true)
 	@Parameter(name = "downloadSpeed", description = "下载倍速", required = true)
 	@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) {
 
 		if (logger.isDebugEnabled()) {
 			logger.debug(String.format("历史媒体下载 API调用,deviceId:%s,channelId:%s,downloadSpeed:%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());
 		});
 

+ 7 - 1
web_src/src/components/dialog/devicePlayer.vue

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