From f23b64038dd66a1cc45c1b532f2ce10801b8cc24 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Thu, 31 Aug 2023 15:02:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gb28181/service/play/PlayService.java | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/play/PlayService.java b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/play/PlayService.java index 588c204..bcef74c 100644 --- a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/play/PlayService.java +++ b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/play/PlayService.java @@ -40,6 +40,7 @@ import javax.sip.header.CallIdHeader; import javax.sip.message.Request; import javax.sip.message.Response; import java.text.MessageFormat; +import java.util.Date; import java.util.concurrent.Flow; import java.util.concurrent.TimeUnit; @@ -59,6 +60,17 @@ public class PlayService { return StringUtils.joinWith("/", zlmMediaConfig.getUrl(),"rtp", streamId + ".live.flv"); } + private DeferredResult> makeResult(String deviceId, String channelId, long timeout, DockingDevice device) { + DeferredResult> result = new DeferredResult<>(TimeUnit.SECONDS.toMillis(timeout)); + if (device == null) { + log.info("未能找到 编码为 => {} 的设备", deviceId); + result.setResult(JsonResponse.error(null, "未找到设备")); + return result; + } + + return result; + } + /** * 实时视频点播 * @param deviceId 设备id @@ -66,24 +78,22 @@ public class PlayService { */ @SneakyThrows public DeferredResult> realTimePlay(String deviceId, String channelId, long timeout){ - DeferredResult> result = new DeferredResult<>(TimeUnit.SECONDS.toMillis(timeout)); DockingDevice device = deviceService.getDevice(deviceId); - if (device == null) { - log.info("未能找到 编码为 => {} 的设备", deviceId); - result.setResult(JsonResponse.error(null, "未找到设备")); + DeferredResult> result = makeResult(deviceId,channelId,timeout, device); + if(result.hasResult()){ return result; } String streamId = MediaSdpHelper.getStreamId(deviceId,channelId); String key = CacheUtil.getKey(MediaSdpHelper.Action.PLAY.getAction(), deviceId, channelId); - if(RedisUtil.KeyOps.hasKey(key)){ + if (RedisUtil.KeyOps.hasKey(key)) { result.setResult(JsonResponse.success(videoUrl(streamId))); return result; } GetRtpInfoResp rtpInfo = zlmMediaService.getRtpInfo(streamId); if(rtpInfo.getExist()){ - result.setResult(JsonResponse.error(MessageFormat.format("实时流 {0} 已存在", streamId))); + result.setResult(JsonResponse.error(MessageFormat.format("流 {0} 已存在", streamId))); return result; } @@ -188,4 +198,23 @@ public class PlayService { RedisUtil.KeyOps.delete(key); return JsonResponse.success(null); } + + @SneakyThrows + public DeferredResult> recordPlay(String deviceId, String channelId, Date startTime, Date endTime, long timeout){ + DockingDevice device = deviceService.getDevice(deviceId); + long start = startTime.toInstant().getEpochSecond(); + long end = endTime.toInstant().getEpochSecond(); + String streamId = MediaSdpHelper.getStreamId(deviceId,channelId,String.valueOf(start), String.valueOf(end)); + DeferredResult> result = makeResult(deviceId,channelId,timeout,device); + if(result.hasResult()){ + return result; + } + + String key = CacheUtil.getKey(MediaSdpHelper.Action.PLAY_BACK.getAction(), deviceId, channelId); + if(RedisUtil.KeyOps.hasKey(key)){ + result.setResult(JsonResponse.success(videoUrl(streamId))); + return result; + } + return result; + } }