From 85ec74771aa81bfbdbff12c3085a05b5c5a86191 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Mon, 15 Jan 2024 10:30:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=95=E5=83=8F=E5=9B=9E=E6=94=BE/=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E6=B7=BB=E5=8A=A0=20=E6=98=AF=E5=90=A6=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=97=B6=E9=97=B4=E8=8C=83=E5=9B=B4=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mocking/config/sip/DeviceProxyConfig.java | 13 ++++++++++ .../request/InviteRequestProcessor.java | 26 ++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) 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 6444e92..4bc2878 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 @@ -4,9 +4,22 @@ import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; +import java.time.Duration; + @Data @Configuration @ConfigurationProperties(prefix = "proxy.device") public class DeviceProxyConfig { + /** + * 通过其他 代理 agent 拉取历史视频 的地址 + */ private String url; + /** + * 是否只通过代理拉取指定时间范围内的视频查询请求 + */ + private Boolean proxyVideoInTimeRange = true; + /** + * 代理该时间段内的历史视频查询请求 + */ + private Duration proxyTimeRange = Duration.ofMinutes(3); } diff --git a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/processor/invite/request/InviteRequestProcessor.java b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/processor/invite/request/InviteRequestProcessor.java index 3ed1222..b0ddca4 100644 --- a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/processor/invite/request/InviteRequestProcessor.java +++ b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/processor/invite/request/InviteRequestProcessor.java @@ -1,8 +1,11 @@ package cn.skcks.docking.gb28181.mocking.core.sip.message.processor.invite.request; +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; import cn.skcks.docking.gb28181.core.sip.listener.SipListener; import cn.skcks.docking.gb28181.core.sip.message.processor.MessageProcessor; import cn.skcks.docking.gb28181.core.sip.message.subscribe.GenericSubscribe; +import cn.skcks.docking.gb28181.mocking.config.sip.DeviceProxyConfig; import cn.skcks.docking.gb28181.mocking.config.sip.FfmpegConfig; import cn.skcks.docking.gb28181.mocking.core.sip.message.subscribe.SipSubscribe; import cn.skcks.docking.gb28181.mocking.core.sip.response.SipResponseBuilder; @@ -50,6 +53,8 @@ public class InviteRequestProcessor implements MessageProcessor { private final FfmpegConfig ffmpegConfig; + private final DeviceProxyConfig deviceProxyConfig; + @PostConstruct @Override public void init() { @@ -126,6 +131,11 @@ public class InviteRequestProcessor implements MessageProcessor { "Unsupported Media Type"); } + private SipSender.SendResponse forbidden(SIPRequest request) { + return (provider, ip, port) -> SipResponseBuilder.response(request, Response.FORBIDDEN, + "Only support playback with " + deviceProxyConfig.getProxyTimeRange().getSeconds() + " secs video"); + } + /** * 视频点播 * @@ -209,6 +219,19 @@ public class InviteRequestProcessor implements MessageProcessor { Date start = new Date(time.getStartTime() * 1000); Date stop = new Date(time.getStopTime() * 1000); log.info("{} ~ {}", start, stop); + + String senderIp = request.getLocalAddress().getHostAddress(); + String transport = request.getTopmostViaHeader().getTransport(); + if(deviceProxyConfig.getProxyVideoInTimeRange()){ + long between = DateUtil.between(start, stop, DateUnit.SECOND); + long seconds = deviceProxyConfig.getProxyTimeRange().getSeconds(); + if( between > seconds ){ + log.info("请求回放/下载时长 {} 大于所设定 支持时长范围 {}",between, seconds); + sender.sendResponse(senderIp, transport, forbidden(request)); + return; + } + } + String channelId = gb28181Description.getOrigin().getUsername(); log.info("通道id: {}", channelId); String address = gb28181Description.getOrigin().getAddress(); @@ -216,9 +239,6 @@ public class InviteRequestProcessor implements MessageProcessor { Media media = mediaDescription.getMedia(); int port = media.getMediaPort(); log.info("目标端口号: {}", port); - - String senderIp = request.getLocalAddress().getHostAddress(); - String transport = request.getTopmostViaHeader().getTransport(); int taskNum = DeviceProxyService.getTaskNum().get(); log.info("当前任务数 {}", taskNum); if(ffmpegConfig.getTask().getMax() > 0 && taskNum >= ffmpegConfig.getTask().getMax()){