如果 无法通过 wvp-assist 下载则 使用 回放实时录制
This commit is contained in:
parent
dfec2e8754
commit
b625dcff7d
@ -52,6 +52,12 @@ public interface WvpProxyClient {
|
|||||||
@PathVariable String channelId,
|
@PathVariable String channelId,
|
||||||
@SpringQueryMap GeneralTimeReq req);
|
@SpringQueryMap GeneralTimeReq req);
|
||||||
|
|
||||||
|
@GetMapping("/api/playback/stop/{deviceId}/{channelId}/{stream}")
|
||||||
|
JsonResponse<StreamContent> playbackStop(@RequestHeader("access-token") String token,
|
||||||
|
@PathVariable String deviceId,
|
||||||
|
@PathVariable String channelId,
|
||||||
|
@PathVariable String stream);
|
||||||
|
|
||||||
// /api/playback/stop/44050100001180000001/44050100001310000001/44050100001180000001_44050100001310000001_20230908083001_20230908083501
|
// /api/playback/stop/44050100001180000001/44050100001310000001/44050100001180000001_44050100001310000001_20230908083001_20230908083501
|
||||||
@GetMapping("/api/gb_record/download/start/{deviceId}/{channelId}")
|
@GetMapping("/api/gb_record/download/start/{deviceId}/{channelId}")
|
||||||
JsonResponse<StreamContent> downloadStart(@RequestHeader("access-token") String token,
|
JsonResponse<StreamContent> downloadStart(@RequestHeader("access-token") String token,
|
||||||
|
@ -48,7 +48,7 @@ public class RecordService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
private void record(ServletResponse response, String url, long time) {
|
public void record(ServletResponse response, String url, long time) {
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
OutputStream outputStream = response.getOutputStream();
|
OutputStream outputStream = response.getOutputStream();
|
||||||
log.info("url {}", url);
|
log.info("url {}", url);
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package cn.skcks.docking.gb28181.wvp.service.wvp;
|
package cn.skcks.docking.gb28181.wvp.service.wvp;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUnit;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.crypto.digest.MD5;
|
import cn.hutool.crypto.digest.MD5;
|
||||||
import cn.skcks.docking.gb28181.common.json.JsonException;
|
import cn.skcks.docking.gb28181.common.json.JsonException;
|
||||||
import cn.skcks.docking.gb28181.common.json.JsonResponse;
|
import cn.skcks.docking.gb28181.common.json.JsonResponse;
|
||||||
import cn.skcks.docking.gb28181.wvp.config.WvpProxyConfig;
|
import cn.skcks.docking.gb28181.wvp.config.WvpProxyConfig;
|
||||||
|
import cn.skcks.docking.gb28181.wvp.dto.common.GeneralTimeReq;
|
||||||
import cn.skcks.docking.gb28181.wvp.dto.device.DeviceChannel;
|
import cn.skcks.docking.gb28181.wvp.dto.device.DeviceChannel;
|
||||||
import cn.skcks.docking.gb28181.wvp.dto.device.GetDeviceChannelsReq;
|
import cn.skcks.docking.gb28181.wvp.dto.device.GetDeviceChannelsReq;
|
||||||
import cn.skcks.docking.gb28181.wvp.dto.device.GetDeviceChannelsResp;
|
import cn.skcks.docking.gb28181.wvp.dto.device.GetDeviceChannelsResp;
|
||||||
@ -22,8 +24,10 @@ import cn.skcks.docking.gb28181.wvp.orm.mybatis.dynamic.model.WvpProxyDevice;
|
|||||||
import cn.skcks.docking.gb28181.wvp.proxy.WvpProxyClient;
|
import cn.skcks.docking.gb28181.wvp.proxy.WvpProxyClient;
|
||||||
import cn.skcks.docking.gb28181.wvp.service.device.DeviceService;
|
import cn.skcks.docking.gb28181.wvp.service.device.DeviceService;
|
||||||
import cn.skcks.docking.gb28181.wvp.service.download.DownloadService;
|
import cn.skcks.docking.gb28181.wvp.service.download.DownloadService;
|
||||||
|
import cn.skcks.docking.gb28181.wvp.service.video.RecordService;
|
||||||
import cn.skcks.docking.gb28181.wvp.utils.RetryUtil;
|
import cn.skcks.docking.gb28181.wvp.utils.RetryUtil;
|
||||||
import com.github.rholder.retry.*;
|
import com.github.rholder.retry.*;
|
||||||
|
import io.swagger.v3.core.util.Json;
|
||||||
import jakarta.servlet.AsyncContext;
|
import jakarta.servlet.AsyncContext;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
@ -49,6 +53,7 @@ public class WvpService {
|
|||||||
private final WvpProxyConfig wvpProxyConfig;
|
private final WvpProxyConfig wvpProxyConfig;
|
||||||
private final DeviceService deviceService;
|
private final DeviceService deviceService;
|
||||||
private final DownloadService downloadService;
|
private final DownloadService downloadService;
|
||||||
|
private final RecordService recordService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -111,7 +116,6 @@ public class WvpService {
|
|||||||
* @param endDateTime 结束时间
|
* @param endDateTime 结束时间
|
||||||
* @return JsonResponse 类型的执行结果 如果 为 null 或 code 不为 0 或 200 则视为执行失败
|
* @return JsonResponse 类型的执行结果 如果 为 null 或 code 不为 0 或 200 则视为执行失败
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("UnstableApiUsage")
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public JsonResponse<?> video(HttpServletResponse response, String deviceCode, String deviceId, String channelId, Date startDateTime, Date endDateTime) {
|
public JsonResponse<?> video(HttpServletResponse response, String deviceCode, String deviceId, String channelId, Date startDateTime, Date endDateTime) {
|
||||||
String passwdMd5 = MD5.create().digestHex(wvpProxyConfig.getPasswd());
|
String passwdMd5 = MD5.create().digestHex(wvpProxyConfig.getPasswd());
|
||||||
@ -163,8 +167,32 @@ public class WvpService {
|
|||||||
log.debug("{}", record);
|
log.debug("{}", record);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
try{
|
||||||
|
JsonResponse<String> 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<JsonResponse<StreamContent>> playBackRetryer = RetryUtil.getDefaultRetryer("通过回放获取实时视频流下载");
|
||||||
|
JsonResponse<StreamContent> 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.record(response, streamUrl, DateUtil.between(startDateTime, endDateTime, DateUnit.SECOND));
|
||||||
|
} finally {
|
||||||
|
wvpProxyClient.playbackStop(token, deviceId, channelId, stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return login;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
|
@SneakyThrows
|
||||||
|
private JsonResponse<String> downloadFromWvpAssist(String deviceCode, String deviceId, String channelId, String startTime, String endTime, String token) {
|
||||||
Retryer<JsonResponse<String>> downloadRetryer = RetryUtil.getDefaultRetryer("调用 wvp 设备历史视频下载 api");
|
Retryer<JsonResponse<String>> downloadRetryer = RetryUtil.getDefaultRetryer("调用 wvp 设备历史视频下载 api");
|
||||||
JsonResponse<String> videoPathResponse = downloadRetryer.call(() -> {
|
return downloadRetryer.call(() -> {
|
||||||
JsonResponse<StreamContent> downloadStart = wvpProxyClient.downloadStart(token, deviceId, channelId, DownloadStartReq.builder()
|
JsonResponse<StreamContent> downloadStart = wvpProxyClient.downloadStart(token, deviceId, channelId, DownloadStartReq.builder()
|
||||||
.startTime(startTime)
|
.startTime(startTime)
|
||||||
.endTime(endTime)
|
.endTime(endTime)
|
||||||
@ -232,10 +260,5 @@ public class WvpService {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
String videoUrl = videoPathResponse.getData();
|
|
||||||
log.info("设备(deviceCode {}) (deviceId {}, channel{}) ({} ~ {}) 视频下载地址 {}", deviceCode, deviceId, channelId, startTime, endTime, videoUrl);
|
|
||||||
downloadService.download(response, videoUrl);
|
|
||||||
return login;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user