diff --git a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/config/sip/DeviceProxyConfig.java b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/config/sip/DeviceProxyConfig.java index 781ec08..89e6da8 100644 --- a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/config/sip/DeviceProxyConfig.java +++ b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/config/sip/DeviceProxyConfig.java @@ -24,6 +24,12 @@ public class DeviceProxyConfig { * 是否只通过代理拉取指定时间范围内的视频查询请求 */ private Boolean proxyVideoInTimeRange = true; + + /** + * 实时视频单次允许最大播放时长 + */ + private Duration realTimeVideoMaxPlayTime = Duration.ofMinutes(15); + /** * 代理该时间段内的历史视频查询请求 */ diff --git a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/service/device/DeviceProxyService.java b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/service/device/DeviceProxyService.java index e83293f..720d101 100644 --- a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/service/device/DeviceProxyService.java +++ b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/service/device/DeviceProxyService.java @@ -580,6 +580,21 @@ public class DeviceProxyService { MediaDescription mediaDescription = (MediaDescription)gb28181Description.getMediaDescriptions(true).get(0); boolean tcp = StringUtils.containsIgnoreCase(mediaDescription.getMedia().getProtocol(), "TCP"); + ScheduledFuture schedule = scheduledExecutorService.schedule(() -> { + log.warn("到达最长播放时间, 强制关闭实时视频播放"); + sendBye(request, device, ""); + log.info("关闭拉流代理 {}", zlmMediaService.delStreamProxy(proxyKey)); + RedisUtil.KeyOps.delete(cacheKey); + + StopSendRtp stopSendRtp = new StopSendRtp(); + stopSendRtp.setApp(DEFAULT_ZLM_APP); + stopSendRtp.setStream(callId); + stopSendRtp.setSsrc(ssrc); + + log.info("结束 zlm rtp 推流, app {}, stream {}, ssrc {}", DEFAULT_ZLM_APP, callId, ssrc); + zlmMediaService.stopSendRtp(stopSendRtp); + }, proxyConfig.getRealTimeVideoMaxPlayTime().toMillis(), TimeUnit.MILLISECONDS); + Retryer rtpRetryer = rtpRetryer(); zlmStreamChangeHookService.getRegistHandler(DEFAULT_ZLM_APP).put(callId,()->{ try { @@ -599,6 +614,9 @@ public class DeviceProxyService { } catch (Exception e){ log.error("zlm rtp 推流失败, {} {} {}, {}", device.getDeviceCode(),device.getGbChannelId(), callId, e.getMessage()); sendBye(request, device, ""); + log.info("关闭拉流代理 {}", zlmMediaService.delStreamProxy(proxyKey)); + RedisUtil.KeyOps.delete(cacheKey); + schedule.cancel(true); } }); @@ -610,6 +628,8 @@ public class DeviceProxyService { log.info("结束 zlm rtp 推流, app {}, stream {}, ssrc {}", DEFAULT_ZLM_APP, callId, ssrc); zlmMediaService.stopSendRtp(stopSendRtp); + log.info("关闭拉流代理 {}", zlmMediaService.delStreamProxy(proxyKey)); + RedisUtil.KeyOps.delete(cacheKey); }); Flow.Subscriber subscriber = zlmByeSubscriber(key,request,device); @@ -618,7 +638,6 @@ public class DeviceProxyService { subscribe.getByeSubscribe().addPublisher(key); subscribe.getByeSubscribe().addSubscribe(key, subscriber); } catch (Exception e) { - log.error("zlm 代理拉流失败",e); sendBye(request, device, ""); }