From 02c0a45f115cba09828bebc36532148313bec75e Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Tue, 30 Jan 2024 19:14:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=9B=BD=E6=A0=87=E7=BA=A7?= =?UTF-8?q?=E8=81=94=E5=BD=95=E5=83=8F=E6=92=AD=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gb28181/GB28181ResourceServiceImpl.java | 37 ++++++++++++++++++- .../request/impl/InviteRequestProcessor.java | 27 +++++++------- .../iot/vmp/service/IResourceService.java | 6 ++- .../impl/StreamProxyResourceServiceImpl.java | 6 ++- .../impl/StreamPushResourceServiceImpl.java | 6 ++- 5 files changed, 61 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/GB28181ResourceServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/GB28181ResourceServiceImpl.java index 67596817..5129f11a 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/GB28181ResourceServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/GB28181ResourceServiceImpl.java @@ -13,11 +13,13 @@ import com.genersoft.iot.vmp.gb28181.bean.command.PTZCommand; import com.genersoft.iot.vmp.gb28181.event.record.RecordEndEventListener; import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; +import com.genersoft.iot.vmp.service.IMediaServerService; import com.genersoft.iot.vmp.service.IPlayService; import com.genersoft.iot.vmp.service.IResourcePlayCallback; import com.genersoft.iot.vmp.service.IResourceService; import com.genersoft.iot.vmp.service.bean.CommonGbChannelType; import com.genersoft.iot.vmp.service.bean.InviteErrorCode; +import com.genersoft.iot.vmp.service.bean.SSRCInfo; import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; import com.genersoft.iot.vmp.storager.dao.DeviceMapper; import com.genersoft.iot.vmp.utils.DateUtil; @@ -30,6 +32,7 @@ import org.springframework.stereotype.Service; import javax.sip.InvalidArgumentException; import javax.sip.SipException; import java.text.ParseException; +import java.time.Instant; import java.util.ArrayList; @@ -50,6 +53,10 @@ public class GB28181ResourceServiceImpl implements IResourceService { @Autowired private IPlayService playService; + + @Autowired + private IMediaServerService mediaServerService; + @Autowired private ISIPCommander commander; @@ -322,12 +329,38 @@ public class GB28181ResourceServiceImpl implements IResourceService { } @Override - public void startPlayback(CommonGbChannel channel, Long startTime, Long stopTime, IResourcePlayCallback callback) { + public void startPlayback(CommonGbChannel commonGbChannel, Instant startTime, Instant stopTime, IResourcePlayCallback callback) { + assert callback != null; + CheckCommonGbChannelResult checkResult = checkCommonGbChannel(commonGbChannel); + if (checkResult.errorMsg != null) { + callback.call(commonGbChannel, null, ErrorCode.SUCCESS.getCode(), checkResult.errorMsg, null); + return; + } + if (checkResult.device == null || checkResult.channel == null) { + callback.call(commonGbChannel, null, ErrorCode.SUCCESS.getCode(), "设备获取失败", null); + return; + } + String startTimeStr = DateUtil.formatter.format(startTime); + String endTimeStr = DateUtil.formatter.format(stopTime); + String stream = checkResult.device.getDeviceId() + "_" + checkResult.channel.getChannelId() + "_" + + startTimeStr + "_" + endTimeStr; + MediaServerItem mediaServerItem = playService.getNewMediaServerItem(checkResult.device); + SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, stream, null, + checkResult.device.isSsrcCheck(), true, 0, false, checkResult.device.getStreamModeForParam()); + playService.playBack(mediaServerItem, ssrcInfo, checkResult.channel.getDeviceId(), checkResult.channel.getChannelId(), + startTimeStr, endTimeStr, (code, msg, data) -> { + if (code == InviteErrorCode.SUCCESS.getCode()) { + StreamInfo streamInfo = (StreamInfo)data; + callback.call(commonGbChannel, mediaServerItem, ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), streamInfo); + }else { + callback.call(commonGbChannel, null, code, msg, null); + } + }); } @Override - public void startDownload(CommonGbChannel channel, Long startTime, Long stopTime, Integer downloadSpeed, IResourcePlayCallback playCallback) { + public void startDownload(CommonGbChannel channel, Instant startTime, Instant stopTime, Integer downloadSpeed, IResourcePlayCallback playCallback) { } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java index 776c5650..48a01278 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java @@ -3,13 +3,11 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.genersoft.iot.vmp.common.CommonGbChannel; -import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.conf.DynamicTask; import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.session.SSRCFactory; import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; -import com.genersoft.iot.vmp.gb28181.transmit.SIPSender; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor; import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; @@ -18,22 +16,18 @@ import com.genersoft.iot.vmp.media.zlm.IStreamSendManager; import com.genersoft.iot.vmp.media.zlm.ZLMMediaListManager; import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory; import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; -import com.genersoft.iot.vmp.media.zlm.dto.*; +import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; +import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange; +import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; +import com.genersoft.iot.vmp.media.zlm.dto.StreamPush; import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam; -import com.genersoft.iot.vmp.media.zlm.service.ISendRtpService; import com.genersoft.iot.vmp.service.*; -import com.genersoft.iot.vmp.service.bean.ErrorCallback; -import com.genersoft.iot.vmp.service.bean.InviteErrorCode; import com.genersoft.iot.vmp.service.bean.MessageForPushChannel; -import com.genersoft.iot.vmp.service.bean.SSRCInfo; import com.genersoft.iot.vmp.service.redisMsg.RedisGbPlayMsgListener; import com.genersoft.iot.vmp.service.redisMsg.RedisPushStreamResponseListener; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; -import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; -import gov.nist.javax.sdp.TimeDescriptionImpl; -import gov.nist.javax.sdp.fields.TimeField; import gov.nist.javax.sip.message.SIPRequest; import gov.nist.javax.sip.message.SIPResponse; import org.slf4j.Logger; @@ -337,13 +331,20 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements logger.error("[命令发送失败] 国标级联 回复SdpAck", e); } }; + Instant start = null; + Instant stop = null; + if (gb28181Sdp.getStartTime() != null) { + start = Instant.ofEpochSecond(gb28181Sdp.getStartTime()); + } + if (gb28181Sdp.getStopTime() != null) { + stop = Instant.ofEpochSecond(gb28181Sdp.getStopTime()); + } if ("Play".equalsIgnoreCase(sessionName)) { resourceService.startPlay(channel, callback); }else if ("Playback".equalsIgnoreCase(sessionName)) { - resourceService.startPlayback(channel, gb28181Sdp.getStartTime(), gb28181Sdp.getStopTime(), callback); + resourceService.startPlayback(channel, start, stop, callback); }else if ("Download".equalsIgnoreCase(sessionName)) { - resourceService.startDownload(channel, gb28181Sdp.getStartTime(), gb28181Sdp.getStopTime(), - gb28181Sdp.getDownloadSpeed(), callback); + resourceService.startDownload(channel, start, stop, gb28181Sdp.getDownloadSpeed(), callback); } } } catch (SdpParseException e) { diff --git a/src/main/java/com/genersoft/iot/vmp/service/IResourceService.java b/src/main/java/com/genersoft/iot/vmp/service/IResourceService.java index 5fea6e7e..c51abc62 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IResourceService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IResourceService.java @@ -6,6 +6,8 @@ import com.genersoft.iot.vmp.gb28181.bean.DragZoomRequest; import com.genersoft.iot.vmp.gb28181.bean.RecordInfo; import com.genersoft.iot.vmp.gb28181.bean.command.PTZCommand; +import java.time.Instant; + /** * 同用资源接入接口,待接入的资源实现此接口即可自动接入, * 包括GIS,分屏播放,国标级联等功能 @@ -42,12 +44,12 @@ public interface IResourceService { /** * 录像回放 */ - void startPlayback(CommonGbChannel channel, Long startTime, Long stopTime, IResourcePlayCallback callback); + void startPlayback(CommonGbChannel channel, Instant startTime, Instant stopTime, IResourcePlayCallback callback); /** * 录像下载 */ - void startDownload(CommonGbChannel channel, Long startTime, Long stopTime, Integer downloadSpeed, IResourcePlayCallback playCallback); + void startDownload(CommonGbChannel channel, Instant startTime, Instant stopTime, Integer downloadSpeed, IResourcePlayCallback playCallback); /** * 报警复位 diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyResourceServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyResourceServiceImpl.java index 1f625bd9..a29e21a2 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyResourceServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyResourceServiceImpl.java @@ -21,6 +21,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; +import java.time.Instant; + @Service(CommonGbChannelType.PROXY) public class StreamProxyResourceServiceImpl implements IResourceService { @@ -90,12 +92,12 @@ public class StreamProxyResourceServiceImpl implements IResourceService { } @Override - public void startPlayback(CommonGbChannel channel, Long startTime, Long stopTime, IResourcePlayCallback callback) { + public void startPlayback(CommonGbChannel channel, Instant startTime, Instant stopTime, IResourcePlayCallback callback) { } @Override - public void startDownload(CommonGbChannel channel, Long startTime, Long stopTime, Integer downloadSpeed, IResourcePlayCallback playCallback) { + public void startDownload(CommonGbChannel channel, Instant startTime, Instant stopTime, Integer downloadSpeed, IResourcePlayCallback playCallback) { } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushResourceServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushResourceServiceImpl.java index c7e85951..b1abbcae 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushResourceServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushResourceServiceImpl.java @@ -10,6 +10,8 @@ import com.genersoft.iot.vmp.service.IResourceService; import com.genersoft.iot.vmp.service.bean.CommonGbChannelType; import org.springframework.stereotype.Service; +import java.time.Instant; + @Service(CommonGbChannelType.PUSH) public class StreamPushResourceServiceImpl implements IResourceService { @Override @@ -38,12 +40,12 @@ public class StreamPushResourceServiceImpl implements IResourceService { } @Override - public void startPlayback(CommonGbChannel channel, Long startTime, Long stopTime, IResourcePlayCallback callback) { + public void startPlayback(CommonGbChannel channel, Instant startTime, Instant stopTime, IResourcePlayCallback callback) { } @Override - public void startDownload(CommonGbChannel channel, Long startTime, Long stopTime, Integer downloadSpeed, IResourcePlayCallback playCallback) { + public void startDownload(CommonGbChannel channel, Instant startTime, Instant stopTime, Integer downloadSpeed, IResourcePlayCallback playCallback) { }