添加 useDownload 参数
This commit is contained in:
parent
9c8883823a
commit
d3a828fa13
@ -59,7 +59,7 @@ public class VideoController {
|
||||
if(proxyConfig.getEnable()){
|
||||
wvpService.video(request,response,req.getDeviceCode(), req.getStartTime(), req.getEndTime());
|
||||
} else {
|
||||
gb28181DownloadService.video(request,response,req.getDeviceCode(), req.getStartTime(), req.getEndTime(), req.getFileHeader());
|
||||
gb28181DownloadService.video(request,response,req.getDeviceCode(), req.getStartTime(), req.getEndTime(), req.getFileHeader(), req.getUseDownload());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,9 @@ public class VideoReq {
|
||||
@Schema(description = "http 头是否需要文件名 (没有文件名时浏览器会试图直接播放,会导致短时间内重复访问同一设备,导致失败)")
|
||||
private Boolean fileHeader = true;
|
||||
|
||||
@Schema(description = "使用哪种方式拉取历史视频 (true 为 使用 Download 方式拉取 4倍速流, false 为 使用 Playback 原始速率拉取 视频回放)")
|
||||
private Boolean useDownload = true;
|
||||
|
||||
public void setDevice_id(String deviceCode){
|
||||
this.deviceCode = deviceCode;
|
||||
}
|
||||
@ -58,4 +61,8 @@ public class VideoReq {
|
||||
public void setEnd_time(Date endTime){
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public void setUse_download(Boolean useDownload){
|
||||
this.useDownload = useDownload;
|
||||
}
|
||||
}
|
||||
|
@ -150,13 +150,13 @@ public class Gb28181DownloadService {
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void video(HttpServletRequest request, HttpServletResponse response, String deviceCode, Date startTime, Date endTime, Boolean fileHeader) {
|
||||
public void video(HttpServletRequest request, HttpServletResponse response, String deviceCode, Date startTime, Date endTime, Boolean fileHeader, Boolean useDownload) {
|
||||
AsyncContext asyncContext = request.startAsync();
|
||||
asyncContext.setTimeout(0);
|
||||
asyncContext.start(()->{
|
||||
HttpServletResponse asyncResponse = (HttpServletResponse)asyncContext.getResponse();
|
||||
try{
|
||||
download(deviceCode, startTime,endTime).whenComplete((videoInfo, e)->{
|
||||
download(deviceCode, startTime,endTime, useDownload).whenComplete((videoInfo, e)->{
|
||||
writeFileHeader(response,deviceCode,startTime,endTime,fileHeader);
|
||||
if(e != null){
|
||||
writeErrorToResponse(asyncResponse, JsonResponse.error(e.getMessage()));
|
||||
@ -404,8 +404,12 @@ public class Gb28181DownloadService {
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public CompletableFuture<VideoInfo> download(String deviceCode, Date startTime, Date endTime) {
|
||||
return download(deviceCode,startTime,endTime, proxySipConfig.isUsePlaybackToDownload());
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public CompletableFuture<VideoInfo> download(String deviceCode, Date startTime, Date endTime, Boolean useDownload) {
|
||||
Optional<WvpProxyDevice> deviceByDeviceCode = deviceService.getDeviceByDeviceCode(deviceCode);
|
||||
if (deviceByDeviceCode.isEmpty()) {
|
||||
String reason = MessageFormat.format("未能找到 设备编码 为 {0} 的设备", deviceCode);
|
||||
@ -413,12 +417,12 @@ public class Gb28181DownloadService {
|
||||
throw new JsonException(reason);
|
||||
} else {
|
||||
WvpProxyDevice device = deviceByDeviceCode.get();
|
||||
return download(device.getGbDeviceId(), device.getGbDeviceChannelId(), startTime, endTime);
|
||||
return download(device.getGbDeviceId(), device.getGbDeviceChannelId(), startTime, endTime, useDownload);
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public CompletableFuture<VideoInfo> download(String gbDeviceId, String channel, Date startTime, Date endTime){
|
||||
public CompletableFuture<VideoInfo> download(String gbDeviceId, String channel, Date startTime, Date endTime, Boolean useDownload){
|
||||
CompletableFuture<VideoInfo> result = new CompletableFuture<>();
|
||||
Optional<WvpProxyDocking> deviceByGbDeviceId = dockingService.getDeviceByGbDeviceId(gbDeviceId);
|
||||
long time = DateUtil.between(startTime, endTime, DateUnit.SECOND);
|
||||
@ -456,7 +460,7 @@ public class Gb28181DownloadService {
|
||||
timeField.setStopTime(end);
|
||||
TimeDescription timeDescription = SdpFactory.getInstance().createTimeDescription(timeField);
|
||||
GB28181SDPBuilder.Action action = GB28181SDPBuilder.Action.DOWNLOAD;
|
||||
if(proxySipConfig.isUsePlaybackToDownload()){
|
||||
if(useDownload == null ? proxySipConfig.isUsePlaybackToDownload(): !useDownload){
|
||||
action = GB28181SDPBuilder.Action.PLAY_BACK;
|
||||
}
|
||||
GB28181Description gb28181Description = GB28181SDPBuilder.Receiver.build(action, gbDeviceId, channel, Connection.IP4, ip, port, ssrc, streamMode, timeDescription);
|
||||
@ -466,7 +470,7 @@ public class Gb28181DownloadService {
|
||||
if(proxySipConfig.getStreamMode() != MediaStreamMode.UDP){
|
||||
media.getMedia().setProtocol("RTP/AVP/TCP");
|
||||
}
|
||||
if(!proxySipConfig.isUsePlaybackToDownload()){
|
||||
if(useDownload == null ? !proxySipConfig.isUsePlaybackToDownload(): useDownload){
|
||||
media.setAttribute("downloadspeed", String.valueOf(4));
|
||||
}
|
||||
URIField uriField = new URIField();
|
||||
|
Loading…
Reference in New Issue
Block a user