This commit is contained in:
shikong 2023-12-14 16:47:16 +08:00
parent cbba1c7be7
commit a5faf10138
2 changed files with 1 additions and 60 deletions

View File

@ -85,14 +85,6 @@ public class VideoController {
return gb28181DownloadService.realtimeVideoUrl(req.getDeviceCode());
}
@Operation(summary = "续签实时视频 +60s")
@GetMapping(value = "/device/realtime/renew")
@ResponseBody
public JsonResponse<Void> renew(@ParameterObject RealtimeVideoReq req) {
gb28181DownloadService.renewRealtimeVideoUrl(req.getDeviceCode());
return JsonResponse.success(null);
}
@Operation(summary = "关闭实时视频")
@GetMapping(value = "/device/realtime/close")
@ResponseBody

View File

@ -81,7 +81,6 @@ public class Gb28181DownloadService {
private final WvpProxyConfig wvpProxyConfig;
private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
private final ConcurrentMap<String, DeferredResult<JsonResponse<String>>> requestMap = new ConcurrentHashMap<>();
private final ConcurrentMap<String, ScheduledFuture<?>> realtimeMap = new ConcurrentHashMap<>();
private final ConcurrentMap<String, VideoInfo> realtimeVideoInfoMap = new ConcurrentHashMap<>();
@Getter
@ -249,8 +248,6 @@ public class Gb28181DownloadService {
log.info("获取媒体信息 {}", videoInfo);
String cacheKey = CacheUtil.getKey(docking.getGbDeviceId(), device.getGbDeviceChannelId());
realtimeVideoInfoMap.put(cacheKey, videoInfo);
String existCallId = RedisUtil.StringOps.get(cacheKey);
autoCloseRealtimeVideo(docking,device,videoInfo,cacheKey,existCallId);
String url = StringUtils.isNotBlank(proxySipConfig.getProxyMediaUrl()) ?
StringUtils.replace(videoInfo.getUrl(), zlmMediaConfig.getUrl(), proxySipConfig.getProxyMediaUrl()):
videoInfo.getUrl();
@ -260,45 +257,9 @@ public class Gb28181DownloadService {
return result;
}
public void renewRealtimeVideoUrl(String deviceCode){
WvpProxyDevice device = deviceService.getDeviceByDeviceCode(deviceCode).orElse(null);
if(device == null){
return;
}
WvpProxyDocking docking = dockingService.getDeviceByDeviceCode(device.getGbDeviceId()).orElse(null);
if(docking == null){
return;
}
String cacheKey = CacheUtil.getKey(docking.getGbDeviceId(), device.getGbDeviceChannelId());
realtimeMap.computeIfPresent(cacheKey,(key, scheduledFuture) -> {
scheduledFuture.cancel(true);
return null;
});
autoCloseRealtimeVideo(deviceCode);
}
public void autoCloseRealtimeVideo(String deviceCode){
WvpProxyDevice device = deviceService.getDeviceByDeviceCode(deviceCode).orElse(null);
if(device == null){
return;
}
WvpProxyDocking docking = dockingService.getDeviceByDeviceCode(device.getGbDeviceId()).orElse(null);
if(docking == null){
return;
}
String cacheKey = CacheUtil.getKey(docking.getGbDeviceId(), device.getGbDeviceChannelId());
String existCallId = RedisUtil.StringOps.get(cacheKey);
realtimeVideoInfoMap.computeIfPresent(cacheKey, (key, videoInfo) -> {
autoCloseRealtimeVideo(docking,device,videoInfo,cacheKey,existCallId);
return videoInfo;
});
}
private void closeExistRequest(String deviceCode, WvpProxyDevice device, WvpProxyDocking docking) {
requestMap.computeIfPresent(deviceCode,(key,requestResult)->{
log.info("关闭已存在的视频请求 {}", deviceCode);
if(!requestResult.hasResult()){
requestResult.setResult(JsonResponse.error("同一设备重复请求, 本次请求结束"));
String cacheKey = CacheUtil.getKey(docking.getGbDeviceId(), device.getGbDeviceChannelId());
@ -315,14 +276,6 @@ public class Gb28181DownloadService {
});
}
public void autoCloseRealtimeVideo(WvpProxyDocking docking, WvpProxyDevice device, Gb28181DownloadService.VideoInfo videoInfo, String cacheKey, String existCallId){
ScheduledFuture<?> schedule = scheduledExecutorService.schedule(() -> {
closeRealtimeVideoNow(docking, device, videoInfo, cacheKey, existCallId);
}, 60, TimeUnit.SECONDS);
realtimeMap.put(cacheKey,schedule);
}
public void closeRealtimeVideoNow(String deviceCode){
WvpProxyDevice device = deviceService.getDeviceByDeviceCode(deviceCode).orElse(null);
if(device == null){
@ -337,10 +290,6 @@ public class Gb28181DownloadService {
String existCallId = RedisUtil.StringOps.get(cacheKey);
realtimeVideoInfoMap.computeIfPresent(cacheKey, (key, videoInfo) -> {
closeRealtimeVideoNow(docking,device,videoInfo,cacheKey,existCallId);
realtimeMap.computeIfPresent(cacheKey,(k, scheduledFuture)->{
scheduledFuture.cancel(true);
return null;
});
return null;
});
}