From 2eb1ca2d94a09c2d3ced69de28de72d2d6d77d8e Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期四, 03 三月 2022 15:57:28 +0800 Subject: [PATCH] 国标录像支持多端同时播放 --- src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/PlaybackController.java | 64 +++++++------------------------- 1 files changed, 14 insertions(+), 50 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/PlaybackController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/PlaybackController.java index 8f83e7c..3607a8d 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/PlaybackController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/PlaybackController.java @@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -75,52 +76,8 @@ if (logger.isDebugEnabled()) { logger.debug(String.format("璁惧鍥炴斁 API璋冪敤锛宒eviceId锛�%s 锛宑hannelId锛�%s", deviceId, channelId)); } - String uuid = UUID.randomUUID().toString(); - String key = DeferredResultHolder.CALLBACK_CMD_PLAYBACK + deviceId + channelId; - DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(30000L); - Device device = storager.queryVideoDevice(deviceId); - if (device == null) { - result.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST)); - return result; - } - MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device); - SSRCInfo ssrcInfo = mediaServerService.openRTPServer(newMediaServerItem, null, true); - // 瓒呮椂澶勭悊 - result.onTimeout(()->{ - logger.warn(String.format("璁惧鍥炴斁瓒呮椂锛宒eviceId锛�%s 锛宑hannelId锛�%s", deviceId, channelId)); - RequestMessage msg = new RequestMessage(); - msg.setId(uuid); - msg.setKey(key); - msg.setData("Timeout"); - resultHolder.invokeResult(msg); - }); - - StreamInfo streamInfo = redisCatchStorage.queryPlaybackByDevice(deviceId, channelId); - if (streamInfo != null) { - // 鍋滄涔嬪墠鐨勫洖鏀� - cmder.streamByeCmd(deviceId, channelId); - } - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId, uuid, result); - - if (newMediaServerItem == null) { - logger.warn(String.format("璁惧鍥炴斁瓒呮椂锛宒eviceId锛�%s 锛宑hannelId锛�%s", deviceId, channelId)); - RequestMessage msg = new RequestMessage(); - msg.setId(uuid); - msg.setKey(key); - msg.setData("Timeout"); - resultHolder.invokeResult(msg); - return result; - } - - cmder.playbackStreamCmd(newMediaServerItem, ssrcInfo, device, channelId, startTime, endTime, (MediaServerItem mediaServerItem, JSONObject response) -> { - logger.info("鏀跺埌璁㈤槄娑堟伅锛� " + response.toJSONString()); - playService.onPublishHandlerForPlayBack(mediaServerItem, response, deviceId, channelId, uuid.toString()); - }, event -> { - RequestMessage msg = new RequestMessage(); - msg.setId(uuid); - msg.setKey(key); - msg.setData(String.format("鍥炴斁澶辫触锛� 閿欒鐮侊細 %s, %s", event.statusCode, event.msg)); + DeferredResult<ResponseEntity<String>> result = playService.playBack(deviceId, channelId, startTime, endTime, msg->{ resultHolder.invokeResult(msg); }); @@ -131,24 +88,31 @@ @ApiImplicitParams({ @ApiImplicitParam(name = "deviceId", value = "璁惧ID", dataTypeClass = String.class), @ApiImplicitParam(name = "channelId", value = "閫氶亾ID", dataTypeClass = String.class), + @ApiImplicitParam(name = "stream", value = "娴両D", dataTypeClass = String.class), }) - @GetMapping("/stop/{deviceId}/{channelId}") - public ResponseEntity<String> playStop(@PathVariable String deviceId, @PathVariable String channelId) { + @GetMapping("/stop/{deviceId}/{channelId}/{stream}") + public ResponseEntity<String> playStop( + @PathVariable String deviceId, + @PathVariable String channelId, + @PathVariable String stream) { - cmder.streamByeCmd(deviceId, channelId); + cmder.streamByeCmd(deviceId, channelId, stream); if (logger.isDebugEnabled()) { logger.debug(String.format("璁惧褰曞儚鍥炴斁鍋滄 API璋冪敤锛宒eviceId/channelId锛�%s/%s", deviceId, channelId)); + } + if (StringUtils.isEmpty(deviceId) || StringUtils.isEmpty(channelId) || StringUtils.isEmpty(stream)) { + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } if (deviceId != null && channelId != null) { JSONObject json = new JSONObject(); json.put("deviceId", deviceId); json.put("channelId", channelId); - return new ResponseEntity<String>(json.toString(), HttpStatus.OK); + return new ResponseEntity<>(json.toString(), HttpStatus.OK); } else { logger.warn("璁惧褰曞儚鍥炴斁鍋滄API璋冪敤澶辫触锛�"); - return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } -- Gitblit v1.8.0