From f7b8960a9864cb576ff24bb20156e0a3297c56cf Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Mon, 11 Sep 2023 11:37:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20proxy.wvp.use-wvp-assist?= =?UTF-8?q?=20=E9=85=8D=E7=BD=AE=20=E6=94=AF=E6=8C=81=E9=85=8D=E7=BD=AE=20?= =?UTF-8?q?=E6=98=AF=E5=90=A6=20=E5=B0=9D=E8=AF=95=E4=BD=BF=E7=94=A8=20wvp?= =?UTF-8?q?-assist=20=E4=B8=8B=E8=BD=BD=E8=A7=86=E9=A2=91=E5=9B=9E?= =?UTF-8?q?=E6=94=BE=20=E5=90=A6=E5=88=99=E4=BD=BF=E7=94=A8=20playback=20?= =?UTF-8?q?=E5=9B=9E=E6=94=BE=E5=BD=95=E5=88=B6=E8=A7=86=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gb28181/wvp/config/WvpProxyConfig.java | 4 ++ .../gb28181/wvp/service/wvp/WvpService.java | 48 ++++++++++++------- .../src/main/resources/application.yml | 1 + 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/config/WvpProxyConfig.java b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/config/WvpProxyConfig.java index c03cc85..cd2e801 100644 --- a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/config/WvpProxyConfig.java +++ b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/config/WvpProxyConfig.java @@ -11,4 +11,8 @@ public class WvpProxyConfig { private String url; private String user; private String passwd; + /** + * 是否尝试通过 wvp-assist 服务下载 + */ + private Boolean useWvpAssist = true; } diff --git a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/wvp/WvpService.java b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/wvp/WvpService.java index fd8b5d6..4373e97 100644 --- a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/wvp/WvpService.java +++ b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/wvp/WvpService.java @@ -169,28 +169,44 @@ public class WvpService { log.debug("{}", record); }); - try{ - JsonResponse videoPathResponse = downloadFromWvpAssist(deviceCode, deviceId, channelId, startTime, endTime, token); - String videoUrl = videoPathResponse.getData(); - log.info("设备(deviceCode {}) (deviceId {}, channel{}) ({} ~ {}) 视频下载地址 {}", deviceCode, deviceId, channelId, startTime, endTime, videoUrl); - downloadService.download(response, videoUrl); - } catch (Exception e){ - Retryer> playBackRetryer = RetryUtil.getDefaultRetryer("通过回放获取实时视频流下载"); - JsonResponse videoStreamResponse = playBackRetryer.call(() -> wvpProxyClient.playbackStart(token, deviceId, channelId, new GeneralTimeReq(startTime, endTime))); - StreamContent streamContent = videoStreamResponse.getData(); - String stream = streamContent.getStream(); - String streamUrl = streamContent.getFlv(); - try { - recordService.header(response); - recordService.record(response, streamUrl, DateUtil.between(startDateTime, endDateTime, DateUnit.SECOND)); - } finally { - wvpProxyClient.playbackStop(token, deviceId, channelId, stream); + Boolean useWvpAssist = wvpProxyConfig.getUseWvpAssist(); + log.info("准备下载 deviceCode: {}, deviceId: {}, channelId:{}, ({}~{}) 历史视频, 通过 wvp-assist: {}", deviceCode, deviceId, channelId, startTime, endTime, useWvpAssist); + if(useWvpAssist){ + try{ + downloadFromWvpAssist(response, token, deviceCode, deviceId, channelId, startTime, endTime); + } catch (Exception e){ + log.warn("尝试通过 wvp-assist 下载视频失败, 尝试通过 视频回放 拉取视频"); + downloadFromPlayback(response, token, deviceId, channelId, startTime, endTime); } + } else { + downloadFromPlayback(response, token, deviceId, channelId, startTime, endTime); } return login; } + private void downloadFromWvpAssist(HttpServletResponse response, String token, String deviceCode, String deviceId, String channelId, String startTime, String endTime){ + JsonResponse videoPathResponse = downloadFromWvpAssist(deviceCode, deviceId, channelId, startTime, endTime, token); + String videoUrl = videoPathResponse.getData(); + log.info("设备(deviceCode {}) (deviceId {}, channel{}) ({} ~ {}) 视频下载地址 {}", deviceCode, deviceId, channelId, startTime, endTime, videoUrl); + downloadService.download(response, videoUrl); + } + + @SneakyThrows + private void downloadFromPlayback(HttpServletResponse response, String token, String deviceId, String channelId, String startTime, String endTime){ + Retryer> playBackRetryer = RetryUtil.getDefaultRetryer("通过回放获取实时视频流下载"); + JsonResponse videoStreamResponse = playBackRetryer.call(() -> wvpProxyClient.playbackStart(token, deviceId, channelId, new GeneralTimeReq(startTime, endTime))); + StreamContent streamContent = videoStreamResponse.getData(); + String stream = streamContent.getStream(); + String streamUrl = streamContent.getFlv(); + try { + recordService.header(response); + recordService.record(response, streamUrl, DateUtil.between(DateUtil.parseDateTime(startTime), DateUtil.parseDateTime(endTime), DateUnit.SECOND)); + } finally { + wvpProxyClient.playbackStop(token, deviceId, channelId, stream); + } + } + @SuppressWarnings("UnstableApiUsage") @SneakyThrows private JsonResponse downloadFromWvpAssist(String deviceCode, String deviceId, String channelId, String startTime, String endTime, String token) { diff --git a/gb28181-wvp-proxy-starter/src/main/resources/application.yml b/gb28181-wvp-proxy-starter/src/main/resources/application.yml index 8a756fa..78cb19d 100644 --- a/gb28181-wvp-proxy-starter/src/main/resources/application.yml +++ b/gb28181-wvp-proxy-starter/src/main/resources/application.yml @@ -47,3 +47,4 @@ proxy: url: http://192.168.1.241:18978 user: admin passwd: admin + use-wvp-assist: false