From 2de6d080cfe9e3b4604928dd32dcdb3c89823ec2 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Mon, 18 Mar 2024 14:40:44 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=90=E5=88=B6=E5=AE=9E=E6=97=B6=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E6=9C=80=E5=A4=A7=E6=92=AD=E6=94=BE=E6=97=B6=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mocking/config/sip/DeviceProxyConfig.java | 6 ++++++ .../service/device/DeviceProxyService.java | 21 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) 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, ""); }