From c429a34e5390b0245da276c2c03a6116822167c3 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期一, 08 五月 2023 17:18:08 +0800
Subject: [PATCH] 修复国标视频点播三种级联并发点播和录像下载的问题

---
 src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/PlaybackController.java                                           |   75 ++-
 src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java                                                         |    6 
 src/main/java/com/genersoft/iot/vmp/service/bean/InviteErrorCode.java                                                           |    6 
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java                                                 |   19 
 src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java                                                          |    7 
 src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java                                                           |  566 ++++++++++++++++------------
 src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java                                                    |    6 
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/info/InfoRequestProcessor.java                          |   50 +-
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusNotifyMessageHandler.java |   30 
 src/main/java/com/genersoft/iot/vmp/service/IInviteStreamService.java                                                           |    5 
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java                           |    6 
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java                                                     |    5 
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java                             |   29 
 src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java                                                          |   35 -
 src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java                                                    |  239 -----------
 src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java                                                            |   43 -
 src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java                                                   |    6 
 src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java                                             |   45 +
 src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java                                                   |    4 
 src/main/java/com/genersoft/iot/vmp/service/IPlayService.java                                                                   |   10 
 20 files changed, 517 insertions(+), 675 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java
index fdd2288..d684056 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java
@@ -4,7 +4,6 @@
 import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
 import com.genersoft.iot.vmp.gb28181.bean.Device;
 import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
-import com.genersoft.iot.vmp.gb28181.bean.InviteStreamCallback;
 import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
 import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
@@ -109,7 +108,7 @@
 	 * @param startTime 寮�濮嬫椂闂�,鏍煎紡瑕佹眰锛歽yyy-MM-dd HH:mm:ss
 	 * @param endTime 缁撴潫鏃堕棿,鏍煎紡瑕佹眰锛歽yyy-MM-dd HH:mm:ss
 	 */
-	void playbackStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInf, Device device, String channelId, String startTime, String endTime,InviteStreamCallback inviteStreamCallback, InviteStreamCallback event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException;
+	void playbackStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInf, Device device, String channelId, String startTime, String endTime,ZlmHttpHookSubscribe.Event event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException;
 
 	/**
 	 * 璇锋眰鍘嗗彶濯掍綋涓嬭浇
@@ -121,7 +120,7 @@
 	 * @param downloadSpeed 涓嬭浇鍊嶉�熷弬鏁�
 	 */ 
 	void downloadStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,
-						   String startTime, String endTime, int downloadSpeed, InviteStreamCallback inviteStreamCallback, InviteStreamCallback hookEvent,
+						   String startTime, String endTime, int downloadSpeed, ZlmHttpHookSubscribe.Event hookEvent,
 						   SipSubscribe.Event errorEvent,SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException;
 
 	/**
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
index e26d6ed..88de963 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
@@ -366,11 +366,11 @@
      */
     @Override
     public void playbackStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,
-                                  String startTime, String endTime, InviteStreamCallback inviteStreamCallback, InviteStreamCallback hookEvent,
+                                  String startTime, String endTime, ZlmHttpHookSubscribe.Event hookEvent,
                                   SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException {
 
 
-        logger.info("{} 鍒嗛厤鐨刏LM涓�: {} [{}:{}]", ssrcInfo.getStream(), mediaServerItem.getSdpIp(), mediaServerItem.getIp(), ssrcInfo.getPort());
+        logger.info("{} 鍒嗛厤鐨刏LM涓�: {} [{}:{}]", ssrcInfo.getStream(), mediaServerItem.getId(), mediaServerItem.getSdpIp(), ssrcInfo.getPort());
         String sdpIp;
         if (!ObjectUtils.isEmpty(device.getSdpIp())) {
             sdpIp = device.getSdpIp();
@@ -443,8 +443,7 @@
         // 娣诲姞璁㈤槄
         subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject json) -> {
             if (hookEvent != null) {
-                InviteStreamInfo inviteStreamInfo = new InviteStreamInfo(mediaServerItemInUse, json,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport()).getCallId(), "rtp", ssrcInfo.getStream());
-                hookEvent.call(inviteStreamInfo);
+                hookEvent.response(mediaServerItemInUse, json);
             }
             subscribe.removeSubscribe(hookSubscribe);
         });
@@ -456,9 +455,6 @@
             streamSession.put(device.getDeviceId(), channelId,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport()).getCallId(), ssrcInfo.getStream(), ssrcInfo.getSsrc(), mediaServerItem.getId(), response, InviteSessionType.PLAYBACK);
             okEvent.response(event);
         });
-        if (inviteStreamCallback != null) {
-            inviteStreamCallback.call(new InviteStreamInfo(mediaServerItem, null,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport()).getCallId(), "rtp", ssrcInfo.getStream()));
-        }
     }
 
     /**
@@ -473,10 +469,10 @@
     @Override
     public void downloadStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,
                                   String startTime, String endTime, int downloadSpeed,
-                                  InviteStreamCallback inviteStreamCallback, InviteStreamCallback hookEvent,
+                                  ZlmHttpHookSubscribe.Event hookEvent,
                                   SipSubscribe.Event errorEvent,SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException {
 
-        logger.info("{} 鍒嗛厤鐨刏LM涓�: {} [{}:{}]", ssrcInfo.getStream(), mediaServerItem.getSdpIp(), mediaServerItem.getIp(), ssrcInfo.getPort());
+        logger.info("{} 鍒嗛厤鐨刏LM涓�: {} [{}:{}]", ssrcInfo.getStream(), mediaServerItem.getId(), mediaServerItem.getSdpIp(), ssrcInfo.getPort());
         String sdpIp;
         if (!ObjectUtils.isEmpty(device.getSdpIp())) {
             sdpIp = device.getSdpIp();
@@ -550,7 +546,7 @@
         String callId= newCallIdHeader.getCallId();
         subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject json) -> {
             logger.debug("sipc 娣诲姞璁㈤槄===callId {}",callId);
-            hookEvent.call(new InviteStreamInfo(mediaServerItem, json,callId, "rtp", ssrcInfo.getStream()));
+            hookEvent.response(mediaServerItemInUse, json);
             subscribe.removeSubscribe(hookSubscribe);
             hookSubscribe.getContent().put("regist", false);
             hookSubscribe.getContent().put("schema", "rtsp");
@@ -568,9 +564,6 @@
         });
 
         Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, SipUtils.getNewFromTag(), null,newCallIdHeader, ssrcInfo.getSsrc());
-        if (inviteStreamCallback != null) {
-            inviteStreamCallback.call(new InviteStreamInfo(mediaServerItem, null,callId, "rtp", ssrcInfo.getStream()));
-        }
 
         sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request, errorEvent, event -> {
             ResponseEvent responseEvent = (ResponseEvent) event.event;
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 2acf402..44f0349 100644
--- 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
@@ -356,7 +356,7 @@
                     }else {
                         streamTypeStr = "UDP";
                     }
-                    logger.info("[涓婄骇鐐规挱] 骞冲彴锛歿}锛� 閫氶亾锛歿}, 鏀舵祦鍦板潃锛歿}:{}锛屾敹娴佹柟寮忥細{}, ssrc锛歿}", username, channelId, addressStr, port, streamTypeStr, ssrc);
+                    logger.info("[涓婄骇Invite] {}, 骞冲彴锛歿}锛� 閫氶亾锛歿}, 鏀舵祦鍦板潃锛歿}:{}锛屾敹娴佹柟寮忥細{}, ssrc锛歿}", sessionName, username, channelId, addressStr, port, streamTypeStr, ssrc);
                     SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId,
                             device.getDeviceId(), channelId, mediaTransmissionTCP, platform.isRtcp());
 
@@ -380,7 +380,7 @@
                     InviteErrorCallback<Object> hookEvent = (code, msg, data) -> {
                         StreamInfo streamInfo = (StreamInfo)data;
                         MediaServerItem mediaServerItemInUSe = mediaServerService.getOne(streamInfo.getMediaServerId());
-                        logger.info("[涓婄骇鐐规挱]涓嬬骇宸茬粡寮�濮嬫帹娴併�� 鍥炲200OK(SDP)锛� {}/{}", streamInfo.getApp(), streamInfo.getStream());
+                        logger.info("[涓婄骇Invite]涓嬬骇宸茬粡寮�濮嬫帹娴併�� 鍥炲200OK(SDP)锛� {}/{}", streamInfo.getApp(), streamInfo.getStream());
                         //     * 0 绛夊緟璁惧鎺ㄦ祦涓婃潵
                         //     * 1 涓嬬骇宸茬粡鎺ㄦ祦锛岀瓑寰呬笂绾у钩鍙板洖澶峚ck
                         //     * 2 鎺ㄦ祦涓�
@@ -443,22 +443,16 @@
                         // 鍐欏叆redis锛� 瓒呮椂鏃跺洖澶�
                         redisCatchStorage.updateSendRTPSever(sendRtpItem);
                         playService.playBack(mediaServerItem, ssrcInfo, device.getDeviceId(), channelId, DateUtil.formatter.format(start),
-                                DateUtil.formatter.format(end), null, result -> {
-                                    if (result.getCode() != 0) {
-                                        logger.warn("褰曞儚鍥炴斁澶辫触");
-                                        if (result.getEvent() != null) {
-//                                            errorEvent.response(result.getEvent());
-                                        }
+                                DateUtil.formatter.format(end),
+                                (code, msg, data) -> {
+                                    if (code == InviteErrorCode.SUCCESS.getCode()){
+                                        hookEvent.run(code, msg, data);
+                                    }else if (code == InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode() || code == InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode()){
+                                        logger.info("[褰曞儚鍥炴斁]瓒呮椂, 鐢ㄦ埛锛歿}锛� 閫氶亾锛歿}", username, channelId);
                                         redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null);
-                                        try {
-                                            responseAck(request, Response.REQUEST_TIMEOUT);
-                                        } catch (SipException | InvalidArgumentException | ParseException e) {
-                                            logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 褰曞儚鍥炴斁 鍙戦�丷EQUEST_TIMEOUT: {}", e.getMessage());
-                                        }
-                                    } else {
-                                        if (result.getMediaServerItem() != null) {
-//                                            hookEvent.response(result.getMediaServerItem(), result.getResponse());
-                                        }
+                                        errorEvent.run(code, msg, data);
+                                    }else {
+                                        errorEvent.run(code, msg, data);
                                     }
                                 });
                     } else {
@@ -477,6 +471,7 @@
                             }else if (code == InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode() || code == InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode()){
                                 logger.info("[涓婄骇鐐规挱]瓒呮椂, 鐢ㄦ埛锛歿}锛� 閫氶亾锛歿}", username, channelId);
                                 redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null);
+                                errorEvent.run(code, msg, data);
                             }else {
                                 errorEvent.run(code, msg, data);
                             }
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java
index 81e7fa6..3e1c673 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java
@@ -80,7 +80,6 @@
     public void process(RequestEvent evt) {
         try {
             RequestEventExt evtExt = (RequestEventExt) evt;
-            String requestAddress = evtExt.getRemoteIpAddress() + ":" + evtExt.getRemotePort();
 
             SIPRequest request = (SIPRequest)evt.getRequest();
             Response response = null;
@@ -91,12 +90,13 @@
             AddressImpl address = (AddressImpl) fromHeader.getAddress();
             SipUri uri = (SipUri) address.getURI();
             String deviceId = uri.getUser();
-            logger.info("[娉ㄥ唽璇锋眰] 璁惧锛歿}, 寮�濮嬪鐞�: {}", deviceId, requestAddress);
+
             Device device = deviceService.getDevice(deviceId);
 
             RemoteAddressInfo remoteAddressInfo = SipUtils.getRemoteAddressFromRequest(request,
                     userSetting.getSipUseSourceIpAsRemoteAddress());
-            logger.info("[娉ㄥ唽璇锋眰] 璁惧锛歿}, 杩滅▼鍦板潃涓�: {}:{}", deviceId, remoteAddressInfo.getIp(), remoteAddressInfo.getPort());
+            String requestAddress = remoteAddressInfo.getIp() + ":" + remoteAddressInfo.getPort();
+                    logger.info("[娉ㄥ唽璇锋眰] 璁惧锛歿}, 寮�濮嬪鐞�: {}", deviceId, requestAddress);
             if (device != null &&
                 device.getSipTransactionInfo() != null &&
                 request.getCallIdHeader().getCallId().equals(device.getSipTransactionInfo().getCallId())) {
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/info/InfoRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/info/InfoRequestProcessor.java
index a4d49d5..fedf0ec 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/info/InfoRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/info/InfoRequestProcessor.java
@@ -1,6 +1,7 @@
 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.info;
 
-import com.genersoft.iot.vmp.common.StreamInfo;
+import com.genersoft.iot.vmp.common.InviteInfo;
+import com.genersoft.iot.vmp.common.InviteSessionType;
 import com.genersoft.iot.vmp.gb28181.bean.*;
 import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
 import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
@@ -9,6 +10,7 @@
 import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor;
 import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
 import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
+import com.genersoft.iot.vmp.service.IInviteStreamService;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
 import gov.nist.javax.sip.message.SIPRequest;
@@ -17,10 +19,12 @@
 import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+
 import javax.sip.InvalidArgumentException;
 import javax.sip.RequestEvent;
 import javax.sip.SipException;
-import javax.sip.header.*;
+import javax.sip.header.CallIdHeader;
+import javax.sip.header.ContentTypeHeader;
 import javax.sip.message.Response;
 import java.text.ParseException;
 
@@ -42,6 +46,9 @@
 
     @Autowired
     private IRedisCatchStorage redisCatchStorage;
+
+    @Autowired
+    private IInviteStreamService inviteStreamService;
 
     @Autowired
     private IVideoManagerStorage storager;
@@ -103,27 +110,30 @@
                 if ("Application".equalsIgnoreCase(contentType) && "MANSRTSP".equalsIgnoreCase(contentSubType)) {
                     SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(null, null, null, callIdHeader.getCallId());
                     String streamId = sendRtpItem.getStreamId();
-                    StreamInfo streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
-                    if (null == streamInfo) {
+                    InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(InviteSessionType.PLAYBACK, streamId);
+                    if (null == inviteInfo) {
                         responseAck(request, Response.NOT_FOUND, "stream " + streamId + " not found");
                         return;
                     }
-                    Device device1 = storager.queryVideoDevice(streamInfo.getDeviceID());
-                    cmder.playbackControlCmd(device1,streamInfo,new String(evt.getRequest().getRawContent()),eventResult -> {
-                        // 澶辫触鐨勫洖澶�
-                        try {
-                            responseAck(request, eventResult.statusCode, eventResult.msg);
-                        } catch (SipException | InvalidArgumentException | ParseException e) {
-                            logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 褰曞儚鎺у埗: {}", e.getMessage());
-                        }
-                    }, eventResult -> {
-                        // 鎴愬姛鐨勫洖澶�
-                        try {
-                            responseAck(request, eventResult.statusCode);
-                        } catch (SipException | InvalidArgumentException | ParseException e) {
-                            logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 褰曞儚鎺у埗: {}", e.getMessage());
-                        }
-                    });
+                    Device device1 = storager.queryVideoDevice(inviteInfo.getDeviceId());
+                    if (inviteInfo.getStreamInfo() != null) {
+                        cmder.playbackControlCmd(device1,inviteInfo.getStreamInfo(),new String(evt.getRequest().getRawContent()),eventResult -> {
+                            // 澶辫触鐨勫洖澶�
+                            try {
+                                responseAck(request, eventResult.statusCode, eventResult.msg);
+                            } catch (SipException | InvalidArgumentException | ParseException e) {
+                                logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 褰曞儚鎺у埗: {}", e.getMessage());
+                            }
+                        }, eventResult -> {
+                            // 鎴愬姛鐨勫洖澶�
+                            try {
+                                responseAck(request, eventResult.statusCode);
+                            } catch (SipException | InvalidArgumentException | ParseException e) {
+                                logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 褰曞儚鎺у埗: {}", e.getMessage());
+                            }
+                        });
+                    }
+
                 }
             }
         } catch (SipException e) {
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusNotifyMessageHandler.java
index 728ff0e..fdcd5e4 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusNotifyMessageHandler.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusNotifyMessageHandler.java
@@ -1,6 +1,7 @@
 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd;
 
-import com.genersoft.iot.vmp.common.StreamInfo;
+import com.genersoft.iot.vmp.common.InviteInfo;
+import com.genersoft.iot.vmp.common.InviteSessionType;
 import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
 import com.genersoft.iot.vmp.gb28181.bean.Device;
 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
@@ -15,6 +16,7 @@
 import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
 import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory;
 import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange;
+import com.genersoft.iot.vmp.service.IInviteStreamService;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
 import gov.nist.javax.sip.message.SIPRequest;
@@ -64,6 +66,12 @@
     @Autowired
     private ZlmHttpHookSubscribe subscribe;
 
+    @Autowired
+    private IInviteStreamService inviteStreamService;
+
+    @Autowired
+    private VideoStreamSessionManager streamSession;
+
     @Override
     public void afterPropertiesSet() throws Exception {
         notifyMessageHandler.addHandler(cmdType, this);
@@ -82,17 +90,15 @@
         String NotifyType =getText(rootElement, "NotifyType");
         if ("121".equals(NotifyType)){
             logger.info("[褰曞儚娴乚鎺ㄩ�佸畬姣曪紝鏀跺埌鍏虫祦閫氱煡");
-            // 鏌ヨ鏄澶�
-            StreamInfo streamInfo = redisCatchStorage.queryDownload(null, null, null, callIdHeader.getCallId());
-            if (streamInfo != null) {
-                // 璁剧疆杩涘害100%
-                streamInfo.setProgress(1);
-                redisCatchStorage.startDownload(streamInfo, callIdHeader.getCallId());
-            }
 
-            // 鍏堜粠浼氳瘽鍐呮煡鎵�
-            SsrcTransaction ssrcTransaction = sessionManager.getSsrcTransaction(null, null, callIdHeader.getCallId(), null);
-            if (ssrcTransaction != null) { // 鍏煎娴峰悍 濯掍綋閫氱煡 娑堟伅from瀛楁涓嶆槸璁惧ID鐨勯棶棰�
+            SsrcTransaction ssrcTransaction = streamSession.getSsrcTransaction(null, null, callIdHeader.getCallId(), null);
+            if (ssrcTransaction != null) {
+                logger.info("[褰曞儚娴乚鎺ㄩ�佸畬姣曪紝鍏虫祦閫氱煡锛� device: {}, channelId: {}", ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId());
+                InviteInfo inviteInfo = inviteStreamService.getInviteInfo(InviteSessionType.DOWNLOAD, ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId(), ssrcTransaction.getStream());
+                if (inviteInfo.getStreamInfo() != null) {
+                    inviteInfo.getStreamInfo().setProgress(1);
+                    inviteStreamService.updateInviteInfo(inviteInfo);
+                }
 
                 try {
                     cmder.streamByeCmd(device, ssrcTransaction.getChannelId(), null, callIdHeader.getCallId());
@@ -117,6 +123,8 @@
                         logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 褰曞儚鎾斁瀹屾瘯: {}", e.getMessage());
                     }
                 }
+            }else {
+                logger.info("[褰曞儚娴乚鎺ㄩ�佸畬姣曪紝鍏虫祦閫氱煡锛� 浣嗘槸鏈壘鍒板搴旂殑涓嬭浇淇℃伅");
             }
         }
     }
diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
index 1681835..fae90fe 100644
--- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
@@ -451,6 +451,11 @@
             InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(null, param.getStream());
             // 鐐规挱
             if (inviteInfo != null) {
+                // 褰曞儚涓嬭浇
+                if (inviteInfo.getType() == InviteSessionType.DOWNLOAD) {
+                    ret.put("close", false);
+                    return ret;
+                }
                 // 鏀跺埌鏃犱汉瑙傜湅璇存槑娴佷篃娌℃湁鍦ㄥ線涓婄骇鎺ㄩ��
                 if (redisCatchStorage.isChannelSendingRTP(inviteInfo.getChannelId())) {
                     List<SendRtpItem> sendRtpItems = redisCatchStorage.querySendRTPServerByChnnelId(
@@ -484,36 +489,6 @@
                 inviteStreamService.removeInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId(),
                         inviteInfo.getChannelId(), inviteInfo.getStream());
                 storager.stopPlay(inviteInfo.getDeviceId(), inviteInfo.getChannelId());
-                return ret;
-            }
-            // 褰曞儚鍥炴斁
-            StreamInfo streamInfoForPlayBackCatch = redisCatchStorage.queryPlayback(null, null,
-                    param.getStream(), null);
-            if (streamInfoForPlayBackCatch != null) {
-                if (streamInfoForPlayBackCatch.isPause()) {
-                    ret.put("close", false);
-                } else {
-                    Device device = deviceService.getDevice(streamInfoForPlayBackCatch.getDeviceID());
-                    if (device != null) {
-                        try {
-                            cmder.streamByeCmd(device, streamInfoForPlayBackCatch.getChannelId(),
-                                    streamInfoForPlayBackCatch.getStream(), null);
-                        } catch (InvalidArgumentException | ParseException | SipException |
-                                 SsrcTransactionNotFoundException e) {
-                            logger.error("[鏃犱汉瑙傜湅]鍥炴斁锛� 鍙戦�丅YE澶辫触 {}", e.getMessage());
-                        }
-                    }
-                    redisCatchStorage.stopPlayback(streamInfoForPlayBackCatch.getDeviceID(),
-                            streamInfoForPlayBackCatch.getChannelId(), streamInfoForPlayBackCatch.getStream(), null);
-                }
-                return ret;
-            }
-            // 褰曞儚涓嬭浇
-            StreamInfo streamInfoForDownload = redisCatchStorage.queryDownload(null, null,
-                    param.getStream(), null);
-            // 杩涜褰曞儚涓嬭浇鏃舵棤浜鸿鐪嬩笉鏂祦
-            if (streamInfoForDownload != null) {
-                ret.put("close", false);
                 return ret;
             }
         } else {
diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
index 423777f..9a642d8 100644
--- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
@@ -293,11 +293,14 @@
         if (jsonObject.getInteger("code") == 0) {
             localPort = jsonObject.getInteger("port");
             HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, serverItem.getId());
-            // 璁㈤槄 zlm鍚姩浜嬩欢, 鏂扮殑zlm涔熶細浠庤繖閲岃繘鍏ョ郴缁�
             hookSubscribe.addSubscribe(hookSubscribeForRtpServerTimeout,
                     (MediaServerItem mediaServerItem, JSONObject response)->{
                         logger.info("[涓婄骇鐐规挱] {}->鐩戝惉绔彛鍒版湡缁х画淇濇寔鐩戝惉", ssrc);
-                        keepPort(serverItem, ssrc);
+                        int port = keepPort(serverItem, ssrc);
+                        if (port == 0) {
+                            logger.info("[涓婄骇鐐规挱] {}->鐩戝惉绔彛澶辫触锛岀Щ闄ょ洃鍚�", ssrc);
+                            hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout);
+                        }
                     });
             logger.info("[涓婄骇鐐规挱] {}->鐩戝惉绔彛: {}", ssrc, localPort);
         }else {
diff --git a/src/main/java/com/genersoft/iot/vmp/service/IInviteStreamService.java b/src/main/java/com/genersoft/iot/vmp/service/IInviteStreamService.java
index 439cdde..ca90095 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/IInviteStreamService.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/IInviteStreamService.java
@@ -60,4 +60,9 @@
      * 璋冪敤涓�涓猧nvite鍥炶皟
      */
     void call(InviteSessionType type, String deviceId, String channelId, String stream,  int code, String msg, Object data);
+
+    /**
+     * 娓呯┖涓�涓澶囩殑鎵�鏈塱nvite淇℃伅
+     */
+    void clearInviteInfo(String deviceId);
 }
diff --git a/src/main/java/com/genersoft/iot/vmp/service/IPlayService.java b/src/main/java/com/genersoft/iot/vmp/service/IPlayService.java
index b2b0308..f6e41c6 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/IPlayService.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/IPlayService.java
@@ -3,10 +3,8 @@
 import com.genersoft.iot.vmp.common.StreamInfo;
 import com.genersoft.iot.vmp.conf.exception.ServiceException;
 import com.genersoft.iot.vmp.gb28181.bean.Device;
-import com.genersoft.iot.vmp.gb28181.bean.InviteStreamCallback;
 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
 import com.genersoft.iot.vmp.service.bean.InviteErrorCallback;
-import com.genersoft.iot.vmp.service.bean.PlayBackCallback;
 import com.genersoft.iot.vmp.service.bean.SSRCInfo;
 
 import javax.sip.InvalidArgumentException;
@@ -29,13 +27,13 @@
      */
     MediaServerItem getNewMediaServerItemHasAssist(Device device);
 
-    void playBack(String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback playBackCallback);
-    void playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
+    void playBack(String deviceId, String channelId, String startTime, String endTime, InviteErrorCallback<Object> callback);
+    void playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, InviteErrorCallback<Object> callback);
 
     void zlmServerOffline(String mediaServerId);
 
-    void download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback playBackCallback);
-    void download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId,  String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
+    void download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteErrorCallback<Object> callback);
+    void download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId,  String channelId, String startTime, String endTime, int downloadSpeed, InviteErrorCallback<Object> callback);
 
     StreamInfo getDownLoadInfo(String deviceId, String channelId, String stream);
 
diff --git a/src/main/java/com/genersoft/iot/vmp/service/bean/InviteErrorCode.java b/src/main/java/com/genersoft/iot/vmp/service/bean/InviteErrorCode.java
index 3f3c76b..16c112b 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/bean/InviteErrorCode.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/bean/InviteErrorCode.java
@@ -5,7 +5,7 @@
  */
 public enum InviteErrorCode {
     SUCCESS(0, "鎴愬姛"),
-    ERROR_FOR_SIGNALLING_TIMEOUT(-1, "鐐规挱瓒呮椂"),
+    ERROR_FOR_SIGNALLING_TIMEOUT(-1, "淇′护瓒呮椂"),
     ERROR_FOR_STREAM_TIMEOUT(-2, "鏀舵祦瓒呮椂"),
     ERROR_FOR_RESOURCE_EXHAUSTION(-3, "璧勬簮鑰楀敖"),
     ERROR_FOR_CATCH_DATA(-4, "缂撳瓨鏁版嵁寮傚父"),
@@ -14,7 +14,9 @@
     ERROR_FOR_SDP_PARSING_EXCEPTIONS(-7, "SDP淇℃伅瑙f瀽澶辫触"),
     ERROR_FOR_SSRC_UNAVAILABLE(-8, "SSRC涓嶅彲鐢�"),
     ERROR_FOR_RESET_SSRC(-9, "閲嶆柊璁剧疆鏀舵祦淇℃伅澶辫触"),
-    ERROR_FOR_SIP_SENDING_FAILED(-10, "鍛戒护鍙戦�佸け璐�");
+    ERROR_FOR_SIP_SENDING_FAILED(-10, "鍛戒护鍙戦�佸け璐�"),
+    ERROR_FOR_ASSIST_NOT_READY(-11, "娌℃湁鍙敤鐨刟ssist鏈嶅姟"),
+    ERROR_FOR_PARAMETER_ERROR(-13, "鍙傛暟寮傚父");
 
     private final int code;
     private final String msg;
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
index 106caec..b171c71 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
@@ -12,6 +12,7 @@
 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd.CatalogResponseMessageHandler;
 import com.genersoft.iot.vmp.service.IDeviceChannelService;
 import com.genersoft.iot.vmp.service.IDeviceService;
+import com.genersoft.iot.vmp.service.IInviteStreamService;
 import com.genersoft.iot.vmp.service.IMediaServerService;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
 import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
@@ -59,6 +60,9 @@
     private IRedisCatchStorage redisCatchStorage;
 
     @Autowired
+    private IInviteStreamService inviteStreamService;
+
+    @Autowired
     private DeviceMapper deviceMapper;
 
     @Autowired
@@ -97,7 +101,7 @@
         String now = DateUtil.getNow();
         if (deviceInRedis != null && deviceInDb == null) {
             // redis 瀛樺湪鑴忔暟鎹�
-            redisCatchStorage.clearCatchByDeviceId(device.getDeviceId());
+            inviteStreamService.clearInviteInfo(device.getDeviceId());
         }
         device.setUpdateTime(now);
         if (device.getKeepaliveIntervalTime() == 0) {
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java
index 8b8c839..f067cf0 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java
@@ -175,4 +175,8 @@
     }
 
 
+    @Override
+    public void clearInviteInfo(String deviceId) {
+        removeInviteInfo(null, deviceId, null, null);
+    }
 }
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
index e43f8db..879e9ca 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
@@ -1,6 +1,5 @@
 package com.genersoft.iot.vmp.service.impl;
 
-import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import com.genersoft.iot.vmp.common.InviteInfo;
@@ -17,7 +16,6 @@
 import com.genersoft.iot.vmp.gb28181.session.SSRCFactory;
 import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
-import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
 import com.genersoft.iot.vmp.media.zlm.AssistRESTfulUtils;
@@ -28,12 +26,13 @@
 import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange;
 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
 import com.genersoft.iot.vmp.service.*;
-import com.genersoft.iot.vmp.service.bean.*;
+import com.genersoft.iot.vmp.service.bean.InviteErrorCallback;
+import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
+import com.genersoft.iot.vmp.service.bean.SSRCInfo;
 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 com.genersoft.iot.vmp.vmanager.bean.WVPResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -182,6 +181,12 @@
     public void play(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,
                      InviteErrorCallback<Object> callback) {
 
+        if (mediaServerItem == null || ssrcInfo == null) {
+            callback.run(InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getCode(),
+                    InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getMsg(),
+                    null);
+            return;
+        }
         logger.info("[鐐规挱寮�濮媇 deviceId: {}, channelId: {},鏀舵祦绔彛锛歿}, 鏀舵祦妯″紡锛歿}, SSRC: {}, SSRC鏍¢獙锛歿}", device.getDeviceId(), channelId, ssrcInfo.getPort(), device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck());
 
         //绔彛鑾峰彇澶辫触鐨剆srcInfo 娌℃湁蹇呰鍙戦�佺偣鎾寚浠�
@@ -375,11 +380,10 @@
                         Boolean result = mediaServerService.updateRtpServerSSRC(mediaServerItem, ssrcInfo.getStream(), ssrcInResponse);
                         if (!result) {
                             try {
-                                logger.warn("[鍋滄鐐规挱] {}/{}", device.getDeviceId(), channelId);
+                                logger.warn("[鐐规挱] 鏇存柊ssrc澶辫触锛屽仠姝㈢偣鎾� {}/{}", device.getDeviceId(), channelId);
                                 cmder.streamByeCmd(device, channelId, ssrcInfo.getStream(), null, null);
                             } catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) {
                                 logger.error("[鍛戒护鍙戦�佸け璐 鍋滄鐐规挱锛� 鍙戦�丅YE: {}", e.getMessage());
-                                throw new ControllerException(ErrorCode.ERROR100.getCode(), "鍛戒护鍙戦�佸け璐�: " + e.getMessage());
                             }
 
                             dynamicTask.stop(timeOutTaskKey);
@@ -459,11 +463,12 @@
 
     }
 
-    private void onPublishHandlerForPlayback(MediaServerItem mediaServerItem, JSONObject response, String deviceId, String channelId, PlayBackCallback playBackCallback) {
+    private StreamInfo onPublishHandlerForPlayback(MediaServerItem mediaServerItem, JSONObject response, String deviceId, String channelId, String startTime, String endTime) {
 
         StreamInfo streamInfo = onPublishHandler(mediaServerItem, response, deviceId, channelId);
-        PlayBackResult<StreamInfo> playBackResult = new PlayBackResult<>();
         if (streamInfo != null) {
+            streamInfo.setStartTime(startTime);
+            streamInfo.setEndTime(endTime);
             DeviceChannel deviceChannel = storager.queryChannel(deviceId, channelId);
             if (deviceChannel != null) {
                 deviceChannel.setStreamId(streamInfo.getStream());
@@ -472,20 +477,13 @@
             InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAYBACK, deviceId, channelId);
             if (inviteInfo != null) {
                 inviteInfo.setStatus(InviteSessionStatus.ok);
+
                 inviteInfo.setStreamInfo(streamInfo);
                 inviteStreamService.updateInviteInfo(inviteInfo);
             }
 
-            playBackResult.setCode(ErrorCode.SUCCESS.getCode());
-            playBackResult.setMsg(ErrorCode.SUCCESS.getMsg());
-            playBackResult.setData(streamInfo);
-            playBackCallback.call(playBackResult);
-        } else {
-            logger.warn("褰曞儚鍥炴斁璋冪敤澶辫触锛�");
-            playBackResult.setCode(ErrorCode.ERROR100.getCode());
-            playBackResult.setMsg("褰曞儚鍥炴斁璋冪敤澶辫触锛�");
-            playBackCallback.call(playBackResult);
         }
+        return streamInfo;
     }
 
     @Override
@@ -524,23 +522,24 @@
 
     @Override
     public void playBack(String deviceId, String channelId, String startTime,
-                                                          String endTime, InviteStreamCallback inviteStreamCallback,
-                                                          PlayBackCallback callback) {
+                                                          String endTime, InviteErrorCallback<Object> callback) {
         Device device = storager.queryVideoDevice(deviceId);
         if (device == null) {
             return;
         }
         MediaServerItem newMediaServerItem = getNewMediaServerItem(device);
         SSRCInfo ssrcInfo = mediaServerService.openRTPServer(newMediaServerItem, null, null, device.isSsrcCheck(),  true, 0, false, device.getStreamModeForParam());
-        playBack(newMediaServerItem, ssrcInfo, deviceId, channelId, startTime, endTime, inviteStreamCallback, callback);
+        playBack(newMediaServerItem, ssrcInfo, deviceId, channelId, startTime, endTime, callback);
     }
 
     @Override
     public void playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,
                                                           String deviceId, String channelId, String startTime,
-                                                          String endTime, InviteStreamCallback infoCallBack,
-                                                          PlayBackCallback playBackCallback) {
+                                                          String endTime, InviteErrorCallback<Object> callback) {
         if (mediaServerItem == null || ssrcInfo == null) {
+            callback.run(InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getCode(),
+                    InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getMsg(),
+                    null);
             return;
         }
 
@@ -548,133 +547,169 @@
         if (device == null) {
             throw new ControllerException(ErrorCode.ERROR100.getCode(), "璁惧锛� " + deviceId + "涓嶅瓨鍦�");
         }
-        logger.info("[鍥炴斁娑堟伅] deviceId: {}, channelId: {},鏀舵祦绔彛锛歿}, 鏀舵祦妯″紡锛歿}, SSRC: {}, SSRC鏍¢獙锛歿}", device.getDeviceId(), channelId, ssrcInfo.getPort(), device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck());
-        PlayBackResult<StreamInfo> playBackResult = new PlayBackResult<>();
+        logger.info("[褰曞儚鍥炴斁] deviceId: {}, channelId: {}, 寮�濮嬫椂闂�: {}, 缁撴潫鏃堕棿锛� {}, 鏀舵祦绔彛锛歿}, 鏀舵祦妯″紡锛歿}, SSRC: {}, SSRC鏍¢獙锛歿}",
+                device.getDeviceId(), channelId, startTime, endTime, ssrcInfo.getPort(), device.getStreamMode(),
+                ssrcInfo.getSsrc(), device.isSsrcCheck());
+        // 鍒濆鍖杛edis涓殑invite娑堟伅鐘舵��
+        InviteInfo inviteInfo = InviteInfo.getinviteInfo(device.getDeviceId(), channelId, ssrcInfo.getStream(), ssrcInfo,
+                mediaServerItem.getSdpIp(), ssrcInfo.getPort(), device.getStreamMode(), InviteSessionType.PLAYBACK,
+                InviteSessionStatus.ready);
+        inviteStreamService.updateInviteInfo(inviteInfo);
         String playBackTimeOutTaskKey = UUID.randomUUID().toString();
         dynamicTask.startDelay(playBackTimeOutTaskKey, () -> {
-            logger.warn(String.format("璁惧鍥炴斁瓒呮椂锛宒eviceId锛�%s 锛宑hannelId锛�%s", deviceId, channelId));
-            playBackResult.setCode(ErrorCode.ERROR100.getCode());
-            playBackResult.setMsg("鍥炴斁瓒呮椂");
+            logger.warn("[褰曞儚鍥炴斁] 瓒呮椂锛宒eviceId锛歿} 锛宑hannelId锛歿}", deviceId, channelId);
+            inviteStreamService.removeInviteInfo(inviteInfo);
+            callback.run(InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode(), InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getMsg(), null);
 
             try {
                 cmder.streamByeCmd(device, channelId, ssrcInfo.getStream(), null);
             } catch (InvalidArgumentException | ParseException | SipException e) {
-                logger.error("[褰曞儚娴乚鍥炴斁瓒呮椂 鍙戦�丅YE澶辫触 {}", e.getMessage());
+                logger.error("[褰曞儚鍥炴斁] 瓒呮椂 鍙戦�丅YE澶辫触 {}", e.getMessage());
             } catch (SsrcTransactionNotFoundException e) {
                 // 鐐规挱瓒呮椂鍥炲BYE 鍚屾椂閲婃斁ssrc浠ュ強姝ゆ鐐规挱鐨勮祫婧�
                 mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
                 mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream());
                 streamSession.remove(deviceId, channelId, ssrcInfo.getStream());
             }
-            // 鍥炲涔嬪墠鎵�鏈夌殑鐐规挱璇锋眰
-            playBackCallback.call(playBackResult);
         }, userSetting.getPlayTimeout());
 
         SipSubscribe.Event errorEvent = event -> {
+            logger.info("[褰曞儚鍥炴斁] 澶辫触锛寋} {}", event.statusCode, event.msg);
             dynamicTask.stop(playBackTimeOutTaskKey);
-            playBackResult.setCode(ErrorCode.ERROR100.getCode());
-            playBackResult.setMsg(String.format("鍥炴斁澶辫触锛� 閿欒鐮侊細 %s, %s", event.statusCode, event.msg));
-            playBackResult.setEvent(event);
-            playBackCallback.call(playBackResult);
+            callback.run(InviteErrorCode.ERROR_FOR_SIGNALLING_ERROR.getCode(),
+                    String.format("鍥炴斁澶辫触锛� 閿欒鐮侊細 %s, %s", event.statusCode, event.msg), null);
+            mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
+            mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream());
             streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
+            inviteStreamService.removeInviteInfo(inviteInfo);
         };
 
-        InviteStreamCallback hookEvent = (InviteStreamInfo inviteStreamInfo) -> {
-            logger.info("鏀跺埌鍥炴斁璁㈤槄娑堟伅锛� " + inviteStreamInfo.getResponse().toJSONString());
+        ZlmHttpHookSubscribe.Event hookEvent = (mediaServerItemInuse, jsonObject) -> {
+            logger.info("鏀跺埌鍥炴斁璁㈤槄娑堟伅锛� " + jsonObject);
             dynamicTask.stop(playBackTimeOutTaskKey);
-            StreamInfo streamInfo = onPublishHandler(inviteStreamInfo.getMediaServerItem(), inviteStreamInfo.getResponse(), deviceId, channelId);
+            StreamInfo streamInfo = onPublishHandlerForPlayback(mediaServerItemInuse, jsonObject, deviceId, channelId, startTime, endTime);
             if (streamInfo == null) {
                 logger.warn("璁惧鍥炴斁API璋冪敤澶辫触锛�");
-                playBackResult.setCode(ErrorCode.ERROR100.getCode());
-                playBackResult.setMsg("璁惧鍥炴斁API璋冪敤澶辫触锛�");
-                playBackCallback.call(playBackResult);
+                callback.run(InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(),
+                        InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null);
                 return;
             }
-            redisCatchStorage.startPlayback(streamInfo, inviteStreamInfo.getCallId());
-
-            playBackResult.setCode(ErrorCode.SUCCESS.getCode());
-            playBackResult.setMsg(ErrorCode.SUCCESS.getMsg());
-            playBackResult.setData(streamInfo);
-            playBackResult.setMediaServerItem(inviteStreamInfo.getMediaServerItem());
-            playBackResult.setResponse(inviteStreamInfo.getResponse());
-            playBackCallback.call(playBackResult);
+            callback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), streamInfo);
+            logger.info("[褰曞儚鍥炴斁] 鎴愬姛 deviceId: {}, channelId: {},  寮�濮嬫椂闂�: {}, 缁撴潫鏃堕棿锛� {}", device.getDeviceId(), channelId, startTime, endTime);
         };
 
         try {
-            cmder.playbackStreamCmd(mediaServerItem, ssrcInfo, device, channelId, startTime, endTime, infoCallBack,
+            cmder.playbackStreamCmd(mediaServerItem, ssrcInfo, device, channelId, startTime, endTime,
                     hookEvent, eventResult -> {
-                        if (eventResult.type == SipSubscribe.EventResultType.response) {
-                            ResponseEvent responseEvent = (ResponseEvent) eventResult.event;
-                            String contentString = new String(responseEvent.getResponse().getRawContent());
-                            // 鑾峰彇ssrc
-                            int ssrcIndex = contentString.indexOf("y=");
-                            // 妫�鏌ユ槸鍚︽湁y瀛楁
-                            if (ssrcIndex >= 0) {
-                                //ssrc瑙勫畾闀垮害涓�10瀛楄妭锛屼笉鍙栦綑涓嬮暱搴︿互閬垮厤鍚庣画杩樻湁鈥渇=鈥濆瓧娈� TODO 鍚庣画瀵逛笉瑙勮寖鐨勯潪10浣峴src鍏煎
-                                String ssrcInResponse = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
-                                // 鏌ヨ鍒皊src涓嶄竴鑷翠笖寮�鍚簡ssrc鏍¢獙鍒欓渶瑕侀拡瀵瑰鐞�
-                                if (ssrcInfo.getSsrc().equals(ssrcInResponse)) {
+                        inviteInfo.setStatus(InviteSessionStatus.ok);
+                        ResponseEvent responseEvent = (ResponseEvent) eventResult.event;
+                        String contentString = new String(responseEvent.getResponse().getRawContent());
+                        // 鑾峰彇ssrc
+                        int ssrcIndex = contentString.indexOf("y=");
+                        // 妫�鏌ユ槸鍚︽湁y瀛楁
+                        if (ssrcIndex >= 0) {
+                            //ssrc瑙勫畾闀垮害涓�10瀛楄妭锛屼笉鍙栦綑涓嬮暱搴︿互閬垮厤鍚庣画杩樻湁鈥渇=鈥濆瓧娈� TODO 鍚庣画瀵逛笉瑙勮寖鐨勯潪10浣峴src鍏煎
+                            String ssrcInResponse = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
+                            // 鏌ヨ鍒皊src涓嶄竴鑷翠笖寮�鍚簡ssrc鏍¢獙鍒欓渶瑕侀拡瀵瑰鐞�
+                            if (ssrcInfo.getSsrc().equals(ssrcInResponse)) {
+                                if (device.getStreamMode().equalsIgnoreCase("TCP-ACTIVE")) {
+                                    String substring = contentString.substring(0, contentString.indexOf("y="));
+                                    try {
+                                        SessionDescription sdp = SdpFactory.getInstance().createSessionDescription(substring);
+                                        int port = -1;
+                                        Vector mediaDescriptions = sdp.getMediaDescriptions(true);
+                                        for (Object description : mediaDescriptions) {
+                                            MediaDescription mediaDescription = (MediaDescription) description;
+                                            Media media = mediaDescription.getMedia();
+
+                                            Vector mediaFormats = media.getMediaFormats(false);
+                                            if (mediaFormats.contains("96")) {
+                                                port = media.getMediaPort();
+                                                break;
+                                            }
+                                        }
+                                        logger.info("[褰曞儚鍥炴斁-TCP涓诲姩杩炴帴瀵规柟] deviceId: {}, channelId: {}, 杩炴帴瀵规柟鐨勫湴鍧�锛歿}:{}, 鏀舵祦妯″紡锛歿}, SSRC: {}, SSRC鏍¢獙锛歿}", device.getDeviceId(), channelId, sdp.getConnection().getAddress(), port, device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck());
+                                        JSONObject jsonObject = zlmresTfulUtils.connectRtpServer(mediaServerItem, sdp.getConnection().getAddress(), port, ssrcInfo.getStream());
+                                        logger.info("[褰曞儚鍥炴斁-TCP涓诲姩杩炴帴瀵规柟] 缁撴灉锛� {}", jsonObject);
+                                    } catch (SdpException e) {
+                                        logger.error("[褰曞儚鍥炴斁-TCP涓诲姩杩炴帴瀵规柟] deviceId: {}, channelId: {}, 瑙f瀽200OK鐨凷DP淇℃伅澶辫触", device.getDeviceId(), channelId, e);
+                                        dynamicTask.stop(playBackTimeOutTaskKey);
+                                        mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream());
+                                        // 閲婃斁ssrc
+                                        mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
+
+                                        streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
+
+                                        callback.run(InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getCode(),
+                                                InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getMsg(), null);
+                                        inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,
+                                                InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getCode(),
+                                                InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getMsg(), null);
+                                    }
+                                }
+                                return;
+                            }
+                            logger.info("[褰曞儚鍥炴斁] 鏀跺埌invite 200, 鍙戠幇涓嬬骇鑷畾涔変簡ssrc: {}", ssrcInResponse);
+                            if (!mediaServerItem.isRtpEnable() || device.isSsrcCheck()) {
+                                logger.info("[褰曞儚鍥炴斁] SSRC淇 {}->{}", ssrcInfo.getSsrc(), ssrcInResponse);
+
+                                if (!ssrcFactory.checkSsrc(mediaServerItem.getId(),ssrcInResponse)) {
+                                    // ssrc 涓嶅彲鐢�
+                                    logger.info("[褰曞儚鍥炴斁] SSRC淇鏃跺彂鐜皊src涓嶅彲浣跨敤 {}->{}", ssrcInfo.getSsrc(), ssrcInResponse);
+                                    // 閲婃斁ssrc
+                                    dynamicTask.stop(playBackTimeOutTaskKey);
+                                    mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
+                                    streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
+                                    callback.run(InviteErrorCode.ERROR_FOR_SSRC_UNAVAILABLE.getCode(),
+                                            InviteErrorCode.ERROR_FOR_SSRC_UNAVAILABLE.getMsg(), null);
                                     return;
                                 }
-                                logger.info("[鍥炴斁娑堟伅] 鏀跺埌invite 200, 鍙戠幇涓嬬骇鑷畾涔変簡ssrc: {}", ssrcInResponse);
-                                if (!mediaServerItem.isRtpEnable() || device.isSsrcCheck()) {
-                                    logger.info("[鍥炴斁娑堟伅] SSRC淇 {}->{}", ssrcInfo.getSsrc(), ssrcInResponse);
 
-                                    if (!ssrcFactory.checkSsrc(mediaServerItem.getId(),ssrcInResponse)) {
-                                        // ssrc 涓嶅彲鐢�
-                                        // 閲婃斁ssrc
+                                // 鍗曠鍙fā寮弒treamId涔熸湁鍙樺寲锛岄渶瑕侀噸鏂拌缃洃鍚�
+                                if (!mediaServerItem.isRtpEnable()) {
+                                    // 娣诲姞璁㈤槄
+                                    HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", ssrcInfo.getStream(), true, "rtsp", mediaServerItem.getId());
+                                    subscribe.removeSubscribe(hookSubscribe);
+                                    String stream = String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase();
+                                    hookSubscribe.getContent().put("stream", stream);
+                                    inviteInfo.setStream(stream);
+                                    subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject response) -> {
+                                        logger.info("[ZLM HOOK] ssrc淇鍚庢敹鍒拌闃呮秷鎭細 " + response.toJSONString());
                                         dynamicTask.stop(playBackTimeOutTaskKey);
-                                        mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
-                                        streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
-                                        eventResult.msg = "涓嬬骇鑷畾涔変簡ssrc,浣嗘槸姝src涓嶅彲鐢�";
-                                        eventResult.statusCode = 400;
-                                        errorEvent.response(eventResult);
-                                        return;
-                                    }
-
-                                    // 鍗曠鍙fā寮弒treamId涔熸湁鍙樺寲锛岄渶瑕侀噸鏂拌缃洃鍚�
-                                    if (!mediaServerItem.isRtpEnable()) {
-                                        // 娣诲姞璁㈤槄
-                                        HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", ssrcInfo.getStream(), true, "rtsp", mediaServerItem.getId());
-                                        subscribe.removeSubscribe(hookSubscribe);
-                                        hookSubscribe.getContent().put("stream", String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase());
-                                        subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject response) -> {
-                                            logger.info("[ZLM HOOK] ssrc淇鍚庢敹鍒拌闃呮秷鎭細 " + response.toJSONString());
-                                            dynamicTask.stop(playBackTimeOutTaskKey);
-                                            // hook鍝嶅簲
-                                            onPublishHandlerForPlayback(mediaServerItemInUse, response, device.getDeviceId(), channelId, playBackCallback);
-                                            hookEvent.call(new InviteStreamInfo(mediaServerItem, null, eventResult.callId, "rtp", ssrcInfo.getStream()));
-                                        });
-                                    }
-
-                                    // 鍏抽棴rtp server
-                                    mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream(), result->{
-                                        if (result) {
-                                            // 閲嶆柊寮�鍚痵src server
-                                            mediaServerService.openRTPServer(mediaServerItem, ssrcInfo.getStream(), ssrcInResponse, device.isSsrcCheck(), true, ssrcInfo.getPort(), true, device.getStreamModeForParam());
-                                        }else {
-                                            try {
-                                                logger.warn("[鍥炴斁娑堟伅]鍋滄 {}/{}", device.getDeviceId(), channelId);
-                                                cmder.streamByeCmd(device, channelId, ssrcInfo.getStream(), null, null);
-                                            } catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) {
-                                                logger.error("[鍛戒护鍙戦�佸け璐 鍋滄鐐规挱 鍋滄锛� 鍙戦�丅YE: {}", e.getMessage());
-                                                throw new ControllerException(ErrorCode.ERROR100.getCode(), "鍛戒护鍙戦�佸け璐�: " + e.getMessage());
-                                            }
-
-                                            dynamicTask.stop(playBackTimeOutTaskKey);
-                                            // 閲婃斁ssrc
-                                            mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
-                                            streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
-                                            errorEvent.response(eventResult);
-                                            eventResult.msg = "涓嬬骇鑷畾涔変簡ssrc,閲嶆柊璁剧疆鏀舵祦淇℃伅澶辫触";
-                                            eventResult.statusCode = 500;
-                                            errorEvent.response(eventResult);
-                                        }
+                                        // hook鍝嶅簲
+                                        hookEvent.response(mediaServerItemInUse, response);
                                     });
                                 }
+                                // 鏇存柊ssrc
+                                Boolean result = mediaServerService.updateRtpServerSSRC(mediaServerItem, ssrcInfo.getStream(), ssrcInResponse);
+                                if (!result) {
+                                    try {
+                                        logger.warn("[褰曞儚鍥炴斁] 鏇存柊ssrc澶辫触锛屽仠姝㈠綍鍍忓洖鏀� {}/{}", device.getDeviceId(), channelId);
+                                        cmder.streamByeCmd(device, channelId, ssrcInfo.getStream(), null, null);
+                                    } catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) {
+                                        logger.error("[鍛戒护鍙戦�佸け璐 鍋滄鐐规挱锛� 鍙戦�丅YE: {}", e.getMessage());
+
+                                    }
+
+                                    dynamicTask.stop(playBackTimeOutTaskKey);
+                                    // 閲婃斁ssrc
+                                    mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
+
+                                    streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
+
+                                    callback.run(InviteErrorCode.ERROR_FOR_RESET_SSRC.getCode(),
+                                            "涓嬬骇鑷畾涔変簡ssrc,閲嶆柊璁剧疆鏀舵祦淇℃伅澶辫触", null);
+
+                                }else {
+                                    ssrcInfo.setSsrc(ssrcInResponse);
+                                    inviteInfo.setSsrcInfo(ssrcInfo);
+                                    inviteInfo.setStream(ssrcInfo.getStream());
+                                }
+                            }else {
+                                logger.info("[鐐规挱娑堟伅] 鏀跺埌invite 200, 涓嬬骇鑷畾涔変簡ssrc, 浣嗘槸褰撳墠妯″紡鏃犻渶淇");
                             }
                         }
-
+                        inviteStreamService.updateInviteInfo(inviteInfo);
                     }, errorEvent);
         } catch (InvalidArgumentException | SipException | ParseException e) {
             logger.error("[鍛戒护鍙戦�佸け璐 鍥炴斁: {}", e.getMessage());
@@ -690,42 +725,50 @@
 
 
     @Override
-    public void download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback playBackCallback) {
+    public void download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteErrorCallback<Object> callback) {
         Device device = storager.queryVideoDevice(deviceId);
         if (device == null) {
             return;
         }
         MediaServerItem newMediaServerItem = getNewMediaServerItemHasAssist(device);
         if (newMediaServerItem == null) {
-            PlayBackResult<StreamInfo> downloadResult = new PlayBackResult<>();
-            downloadResult.setCode(ErrorCode.ERROR100.getCode());
-            downloadResult.setMsg("鏈壘鍒癮ssist鏈嶅姟");
-            playBackCallback.call(downloadResult);
+            callback.run(InviteErrorCode.ERROR_FOR_ASSIST_NOT_READY.getCode(),
+                    InviteErrorCode.ERROR_FOR_ASSIST_NOT_READY.getMsg(),
+                    null);
             return;
         }
         SSRCInfo ssrcInfo = mediaServerService.openRTPServer(newMediaServerItem, null, null, device.isSsrcCheck(),  true, 0, false, device.getStreamModeForParam());
-        download(newMediaServerItem, ssrcInfo, deviceId, channelId, startTime, endTime, downloadSpeed, infoCallBack, playBackCallback);
+        download(newMediaServerItem, ssrcInfo, deviceId, channelId, startTime, endTime, downloadSpeed, callback);
     }
 
 
     @Override
-    public void download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) {
+    public void download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteErrorCallback<Object> callback) {
         if (mediaServerItem == null || ssrcInfo == null) {
+            callback.run(InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getCode(),
+                    InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getMsg(),
+                    null);
             return;
         }
-
         Device device = storager.queryVideoDevice(deviceId);
         if (device == null) {
-            throw new ControllerException(ErrorCode.ERROR400.getCode(), "璁惧锛�" + deviceId + "涓嶅瓨鍦�");
+            callback.run(InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getCode(),
+                    "璁惧锛�" + deviceId + "涓嶅瓨鍦�",
+                    null);
+            return;
         }
-        PlayBackResult<StreamInfo> downloadResult = new PlayBackResult<>();
         logger.info("[褰曞儚涓嬭浇] deviceId: {}, channelId: {},鏀舵祦绔彛锛歿}, 鏀舵祦妯″紡锛歿}, SSRC: {}, SSRC鏍¢獙锛歿}", device.getDeviceId(), channelId, ssrcInfo.getPort(), device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck());
+        // 鍒濆鍖杛edis涓殑invite娑堟伅鐘舵��
+        InviteInfo inviteInfo = InviteInfo.getinviteInfo(device.getDeviceId(), channelId, ssrcInfo.getStream(), ssrcInfo,
+                mediaServerItem.getSdpIp(), ssrcInfo.getPort(), device.getStreamMode(), InviteSessionType.DOWNLOAD,
+                InviteSessionStatus.ready);
+        inviteStreamService.updateInviteInfo(inviteInfo);
         String downLoadTimeOutTaskKey = UUID.randomUUID().toString();
         dynamicTask.startDelay(downLoadTimeOutTaskKey, () -> {
             logger.warn(String.format("褰曞儚涓嬭浇璇锋眰瓒呮椂锛宒eviceId锛�%s 锛宑hannelId锛�%s", deviceId, channelId));
-            downloadResult.setCode(ErrorCode.ERROR100.getCode());
-            downloadResult.setMsg("褰曞儚涓嬭浇璇锋眰瓒呮椂");
-            hookCallBack.call(downloadResult);
+            inviteStreamService.removeInviteInfo(inviteInfo);
+            callback.run(InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode(),
+                    InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getMsg(), null);
 
             // 鐐规挱瓒呮椂鍥炲BYE 鍚屾椂閲婃斁ssrc浠ュ強姝ゆ鐐规挱鐨勮祫婧�
             try {
@@ -741,98 +784,129 @@
 
         SipSubscribe.Event errorEvent = event -> {
             dynamicTask.stop(downLoadTimeOutTaskKey);
-            downloadResult.setCode(ErrorCode.ERROR100.getCode());
-            downloadResult.setMsg(String.format("褰曞儚涓嬭浇澶辫触锛� 閿欒鐮侊細 %s, %s", event.statusCode, event.msg));
-            downloadResult.setEvent(event);
-            hookCallBack.call(downloadResult);
+            callback.run(InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode(),
+                    String.format("褰曞儚涓嬭浇澶辫触锛� 閿欒鐮侊細 %s, %s", event.statusCode, event.msg), null);
             streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
+            inviteStreamService.removeInviteInfo(inviteInfo);
         };
-        InviteStreamCallback hookEvent = (InviteStreamInfo inviteStreamInfo) -> {
-            logger.info("[褰曞儚涓嬭浇]鏀跺埌璁㈤槄娑堟伅锛� " + inviteStreamInfo.getCallId());
+        ZlmHttpHookSubscribe.Event hookEvent = (mediaServerItemInuse, jsonObject) -> {
+            logger.info("[褰曞儚涓嬭浇]鏀跺埌璁㈤槄娑堟伅锛� " + jsonObject);
             dynamicTask.stop(downLoadTimeOutTaskKey);
-            StreamInfo streamInfo = onPublishHandler(inviteStreamInfo.getMediaServerItem(), inviteStreamInfo.getResponse(), deviceId, channelId);
-            streamInfo.setStartTime(startTime);
-            streamInfo.setEndTime(endTime);
-            redisCatchStorage.startDownload(streamInfo, inviteStreamInfo.getCallId());
-            downloadResult.setCode(ErrorCode.SUCCESS.getCode());
-            downloadResult.setMsg(ErrorCode.SUCCESS.getMsg());
-            downloadResult.setData(streamInfo);
-            downloadResult.setMediaServerItem(inviteStreamInfo.getMediaServerItem());
-            downloadResult.setResponse(inviteStreamInfo.getResponse());
-            hookCallBack.call(downloadResult);
+            StreamInfo streamInfo = onPublishHandlerForDownload(mediaServerItemInuse, jsonObject, deviceId, channelId, startTime, endTime);
+            if (streamInfo == null) {
+                logger.warn("[褰曞儚涓嬭浇] 鑾峰彇娴佸湴鍧�淇℃伅澶辫触");
+                callback.run(InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(),
+                        InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null);
+                return;
+            }
+            callback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), streamInfo);
+            logger.info("[褰曞儚涓嬭浇] 璋冪敤鎴愬姛 deviceId: {}, channelId: {},  寮�濮嬫椂闂�: {}, 缁撴潫鏃堕棿锛� {}", device.getDeviceId(), channelId, startTime, endTime);
         };
         try {
-            cmder.downloadStreamCmd(mediaServerItem, ssrcInfo, device, channelId, startTime, endTime, downloadSpeed, infoCallBack,
-                    hookEvent, errorEvent, eventResult ->
-                    {
-                        if (eventResult.type == SipSubscribe.EventResultType.response) {
-                            ResponseEvent responseEvent = (ResponseEvent) eventResult.event;
-                            String contentString = new String(responseEvent.getResponse().getRawContent());
-                            // 鑾峰彇ssrc
-                            int ssrcIndex = contentString.indexOf("y=");
-                            // 妫�鏌ユ槸鍚︽湁y瀛楁
-                            if (ssrcIndex >= 0) {
-                                //ssrc瑙勫畾闀垮害涓�10瀛楄妭锛屼笉鍙栦綑涓嬮暱搴︿互閬垮厤鍚庣画杩樻湁鈥渇=鈥濆瓧娈� TODO 鍚庣画瀵逛笉瑙勮寖鐨勯潪10浣峴src鍏煎
-                                String ssrcInResponse = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
-                                // 鏌ヨ鍒皊src涓嶄竴鑷翠笖寮�鍚簡ssrc鏍¢獙鍒欓渶瑕侀拡瀵瑰鐞�
-                                if (ssrcInfo.getSsrc().equals(ssrcInResponse)) {
-                                    return;
-                                }
-                                logger.info("[褰曞儚涓嬭浇] 鏀跺埌invite 200, 鍙戠幇涓嬬骇鑷畾涔変簡ssrc: {}", ssrcInResponse);
-                                if (!mediaServerItem.isRtpEnable() || device.isSsrcCheck()) {
-                                    logger.info("[褰曞儚涓嬭浇] SSRC淇 {}->{}", ssrcInfo.getSsrc(), ssrcInResponse);
+            cmder.downloadStreamCmd(mediaServerItem, ssrcInfo, device, channelId, startTime, endTime, downloadSpeed,
+                    hookEvent, errorEvent, eventResult ->{
+                        inviteInfo.setStatus(InviteSessionStatus.ok);
+                        ResponseEvent responseEvent = (ResponseEvent) eventResult.event;
+                        String contentString = new String(responseEvent.getResponse().getRawContent());
+                        // 鑾峰彇ssrc
+                        int ssrcIndex = contentString.indexOf("y=");
+                        // 妫�鏌ユ槸鍚︽湁y瀛楁
+                        if (ssrcIndex >= 0) {
+                            //ssrc瑙勫畾闀垮害涓�10瀛楄妭锛屼笉鍙栦綑涓嬮暱搴︿互閬垮厤鍚庣画杩樻湁鈥渇=鈥濆瓧娈� TODO 鍚庣画瀵逛笉瑙勮寖鐨勯潪10浣峴src鍏煎
+                            String ssrcInResponse = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
+                            // 鏌ヨ鍒皊src涓嶄竴鑷翠笖寮�鍚簡ssrc鏍¢獙鍒欓渶瑕侀拡瀵瑰鐞�
+                            if (ssrcInfo.getSsrc().equals(ssrcInResponse)) {
+                                if (device.getStreamMode().equalsIgnoreCase("TCP-ACTIVE")) {
+                                    String substring = contentString.substring(0, contentString.indexOf("y="));
+                                    try {
+                                        SessionDescription sdp = SdpFactory.getInstance().createSessionDescription(substring);
+                                        int port = -1;
+                                        Vector mediaDescriptions = sdp.getMediaDescriptions(true);
+                                        for (Object description : mediaDescriptions) {
+                                            MediaDescription mediaDescription = (MediaDescription) description;
+                                            Media media = mediaDescription.getMedia();
 
-                                    if (!ssrcFactory.checkSsrc(mediaServerItem.getId(),ssrcInResponse)) {
-                                        // ssrc 涓嶅彲鐢�
+                                            Vector mediaFormats = media.getMediaFormats(false);
+                                            if (mediaFormats.contains("96")) {
+                                                port = media.getMediaPort();
+                                                break;
+                                            }
+                                        }
+                                        logger.info("[褰曞儚涓嬭浇-TCP涓诲姩杩炴帴瀵规柟] deviceId: {}, channelId: {}, 杩炴帴瀵规柟鐨勫湴鍧�锛歿}:{}, 鏀舵祦妯″紡锛歿}, SSRC: {}, SSRC鏍¢獙锛歿}", device.getDeviceId(), channelId, sdp.getConnection().getAddress(), port, device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck());
+                                        JSONObject jsonObject = zlmresTfulUtils.connectRtpServer(mediaServerItem, sdp.getConnection().getAddress(), port, ssrcInfo.getStream());
+                                        logger.info("[褰曞儚涓嬭浇-TCP涓诲姩杩炴帴瀵规柟] 缁撴灉锛� {}", jsonObject);
+                                    } catch (SdpException e) {
+                                        logger.error("[褰曞儚涓嬭浇-TCP涓诲姩杩炴帴瀵规柟] deviceId: {}, channelId: {}, 瑙f瀽200OK鐨凷DP淇℃伅澶辫触", device.getDeviceId(), channelId, e);
+                                        dynamicTask.stop(downLoadTimeOutTaskKey);
+                                        mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream());
                                         // 閲婃斁ssrc
                                         mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
+
                                         streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
-                                        eventResult.msg = "涓嬬骇鑷畾涔変簡ssrc,浣嗘槸姝src涓嶅彲鐢�";
-                                        eventResult.statusCode = 400;
-                                        errorEvent.response(eventResult);
-                                        return;
+
+                                        callback.run(InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getCode(),
+                                                InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getMsg(), null);
+                                        inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,
+                                                InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getCode(),
+                                                InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getMsg(), null);
                                     }
+                                }
+                                return;
+                            }
+                            logger.info("[褰曞儚涓嬭浇] 鏀跺埌invite 200, 鍙戠幇涓嬬骇鑷畾涔変簡ssrc: {}", ssrcInResponse);
+                            if (!mediaServerItem.isRtpEnable() || device.isSsrcCheck()) {
+                                logger.info("[褰曞儚涓嬭浇] SSRC淇 {}->{}", ssrcInfo.getSsrc(), ssrcInResponse);
 
-                                    // 鍗曠鍙fā寮弒treamId涔熸湁鍙樺寲锛岄渶瑕侀噸鏂拌缃洃鍚�
-                                    if (!mediaServerItem.isRtpEnable()) {
-                                        // 娣诲姞璁㈤槄
-                                        HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", ssrcInfo.getStream(), true, "rtsp", mediaServerItem.getId());
-                                        subscribe.removeSubscribe(hookSubscribe);
-                                        hookSubscribe.getContent().put("stream", String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase());
-                                        subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject response) -> {
-                                            logger.info("[ZLM HOOK] ssrc淇鍚庢敹鍒拌闃呮秷鎭細 " + response.toJSONString());
-                                            dynamicTask.stop(downLoadTimeOutTaskKey);
-                                            // hook鍝嶅簲
-                                            onPublishHandlerForPlayback(mediaServerItemInUse, response, device.getDeviceId(), channelId, hookCallBack);
-                                            hookEvent.call(new InviteStreamInfo(mediaServerItem, null, eventResult.callId, "rtp", ssrcInfo.getStream()));
-                                        });
-                                    }
+                                if (!ssrcFactory.checkSsrc(mediaServerItem.getId(),ssrcInResponse)) {
+                                    // ssrc 涓嶅彲鐢�
+                                    // 閲婃斁ssrc
+                                    mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
+                                    streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
+                                    callback.run(InviteErrorCode.ERROR_FOR_SSRC_UNAVAILABLE.getCode(),
+                                            InviteErrorCode.ERROR_FOR_SSRC_UNAVAILABLE.getMsg(), null);
+                                    return;
+                                }
 
-                                    // 鍏抽棴rtp server
-                                    mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream(), result->{
-                                        if (result) {
-                                            // 閲嶆柊寮�鍚痵src server
-                                            mediaServerService.openRTPServer(mediaServerItem, ssrcInfo.getStream(), ssrcInResponse, device.isSsrcCheck(), true, ssrcInfo.getPort(), true, device.getStreamModeForParam());
-                                        }else {
-                                            try {
-                                                logger.warn("[褰曞儚涓嬭浇] 鍋滄{}/{}", device.getDeviceId(), channelId);
-                                                cmder.streamByeCmd(device, channelId, ssrcInfo.getStream(), null, null);
-                                            } catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) {
-                                                logger.error("[鍛戒护鍙戦�佸け璐 褰曞儚涓嬭浇鍋滄锛� 鍙戦�丅YE: {}", e.getMessage());
-                                                throw new ControllerException(ErrorCode.ERROR100.getCode(), "鍛戒护鍙戦�佸け璐�: " + e.getMessage());
-                                            }
-
-                                            dynamicTask.stop(downLoadTimeOutTaskKey);
-                                            // 閲婃斁ssrc
-                                            mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
-
-                                            streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
-                                            eventResult.msg = "涓嬬骇鑷畾涔変簡ssrc,閲嶆柊璁剧疆鏀舵祦淇℃伅澶辫触";
-                                            eventResult.statusCode = 500;
-                                            errorEvent.response(eventResult);
-                                        }
+                                // 鍗曠鍙fā寮弒treamId涔熸湁鍙樺寲锛岄渶瑕侀噸鏂拌缃洃鍚�
+                                if (!mediaServerItem.isRtpEnable()) {
+                                    // 娣诲姞璁㈤槄
+                                    HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", ssrcInfo.getStream(), true, "rtsp", mediaServerItem.getId());
+                                    subscribe.removeSubscribe(hookSubscribe);
+                                    hookSubscribe.getContent().put("stream", String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase());
+                                    subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject response) -> {
+                                        logger.info("[ZLM HOOK] ssrc淇鍚庢敹鍒拌闃呮秷鎭細 " + response.toJSONString());
+                                        dynamicTask.stop(downLoadTimeOutTaskKey);
+                                        hookEvent.response(mediaServerItemInUse, response);
                                     });
                                 }
+
+                                // 鏇存柊ssrc
+                                Boolean result = mediaServerService.updateRtpServerSSRC(mediaServerItem, ssrcInfo.getStream(), ssrcInResponse);
+                                if (!result) {
+                                    try {
+                                        logger.warn("[褰曞儚涓嬭浇] 鏇存柊ssrc澶辫触锛屽仠姝㈠綍鍍忓洖鏀� {}/{}", device.getDeviceId(), channelId);
+                                        cmder.streamByeCmd(device, channelId, ssrcInfo.getStream(), null, null);
+                                    } catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) {
+                                        logger.error("[鍛戒护鍙戦�佸け璐 鍋滄鐐规挱锛� 鍙戦�丅YE: {}", e.getMessage());
+
+                                    }
+
+                                    dynamicTask.stop(downLoadTimeOutTaskKey);
+                                    // 閲婃斁ssrc
+                                    mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
+
+                                    streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
+
+                                    callback.run(InviteErrorCode.ERROR_FOR_RESET_SSRC.getCode(),
+                                            "涓嬬骇鑷畾涔変簡ssrc,閲嶆柊璁剧疆鏀舵祦淇℃伅澶辫触", null);
+
+                                }else {
+                                    ssrcInfo.setSsrc(ssrcInResponse);
+                                    inviteInfo.setSsrcInfo(ssrcInfo);
+                                    inviteInfo.setStream(ssrcInfo.getStream());
+                                }
+                            }else {
+                                logger.info("[褰曞儚涓嬭浇] 鏀跺埌invite 200, 涓嬬骇鑷畾涔変簡ssrc, 浣嗘槸褰撳墠妯″紡鏃犻渶淇");
                             }
                         }
                     });
@@ -849,21 +923,22 @@
 
     @Override
     public StreamInfo getDownLoadInfo(String deviceId, String channelId, String stream) {
-        StreamInfo streamInfo = redisCatchStorage.queryDownload(deviceId, channelId, stream, null);
-        if (streamInfo != null) {
-            if (streamInfo.getProgress() == 1) {
-                return streamInfo;
+        InviteInfo inviteInfo = inviteStreamService.getInviteInfo(InviteSessionType.DOWNLOAD, deviceId, channelId, stream);
+
+        if (inviteInfo != null && inviteInfo.getStreamInfo() != null) {
+            if (inviteInfo.getStreamInfo().getProgress() == 1) {
+                return inviteInfo.getStreamInfo();
             }
 
             // 鑾峰彇褰撳墠宸蹭笅杞芥椂闀�
-            String mediaServerId = streamInfo.getMediaServerId();
+            String mediaServerId = inviteInfo.getStreamInfo().getMediaServerId();
             MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
             if (mediaServerItem == null) {
                 logger.warn("鏌ヨ褰曞儚淇℃伅鏃跺彂鐜拌妭鐐瑰凡绂荤嚎");
                 return null;
             }
             if (mediaServerItem.getRecordAssistPort() > 0) {
-                JSONObject jsonObject = assistRESTfulUtils.fileDuration(mediaServerItem, streamInfo.getApp(), streamInfo.getStream(), null);
+                JSONObject jsonObject = assistRESTfulUtils.fileDuration(mediaServerItem, inviteInfo.getStreamInfo().getApp(), inviteInfo.getStreamInfo().getStream(), null);
                 if (jsonObject == null) {
                     throw new ControllerException(ErrorCode.ERROR100.getCode(), "杩炴帴Assist鏈嶅姟澶辫触");
                 }
@@ -871,10 +946,10 @@
                     long duration = jsonObject.getLong("data");
 
                     if (duration == 0) {
-                        streamInfo.setProgress(0);
+                        inviteInfo.getStreamInfo().setProgress(0);
                     } else {
-                        String startTime = streamInfo.getStartTime();
-                        String endTime = streamInfo.getEndTime();
+                        String startTime = inviteInfo.getStreamInfo().getStartTime();
+                        String endTime = inviteInfo.getStreamInfo().getEndTime();
                         long start = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(startTime);
                         long end = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(endTime);
 
@@ -882,28 +957,29 @@
                         BigDecimal totalCount = new BigDecimal(end - start);
                         BigDecimal divide = currentCount.divide(totalCount, 2, RoundingMode.HALF_UP);
                         double process = divide.doubleValue();
-                        streamInfo.setProgress(process);
+                        inviteInfo.getStreamInfo().setProgress(process);
                     }
+                    inviteStreamService.updateInviteInfo(inviteInfo);
                 }
+            }
+            return inviteInfo.getStreamInfo();
+        }
+        return null;
+    }
+
+    private StreamInfo onPublishHandlerForDownload(MediaServerItem mediaServerItemInuse, JSONObject response, String deviceId, String channelId, String startTime, String endTime) {
+        StreamInfo streamInfo = onPublishHandler(mediaServerItemInuse, response, deviceId, channelId);
+        if (streamInfo != null) {
+            streamInfo.setStartTime(startTime);
+            streamInfo.setEndTime(endTime);
+            InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.DOWNLOAD, deviceId, channelId);
+            if (inviteInfo != null) {
+                inviteInfo.setStatus(InviteSessionStatus.ok);
+                inviteInfo.setStreamInfo(streamInfo);
+                inviteStreamService.updateInviteInfo(inviteInfo);
             }
         }
         return streamInfo;
-    }
-
-    private void onPublishHandlerForDownload(InviteStreamInfo inviteStreamInfo, String deviceId, String channelId, String uuid) {
-        RequestMessage msg = new RequestMessage();
-        msg.setKey(DeferredResultHolder.CALLBACK_CMD_DOWNLOAD + deviceId + channelId);
-        msg.setId(uuid);
-        StreamInfo streamInfo = onPublishHandler(inviteStreamInfo.getMediaServerItem(), inviteStreamInfo.getResponse(), deviceId, channelId);
-        if (streamInfo != null) {
-            redisCatchStorage.startDownload(streamInfo, inviteStreamInfo.getCallId());
-            msg.setData(JSON.toJSONString(streamInfo));
-            resultHolder.invokeResult(msg);
-        } else {
-            logger.warn("璁惧棰勮API璋冪敤澶辫触锛�");
-            msg.setData(WVPResult.fail(ErrorCode.ERROR100.getCode(), "璁惧棰勮API璋冪敤澶辫触锛�"));
-            resultHolder.invokeResult(msg);
-        }
     }
 
 
@@ -1007,15 +1083,14 @@
 
     @Override
     public void pauseRtp(String streamId) throws ServiceException, InvalidArgumentException, ParseException, SipException {
-        String key = redisCatchStorage.queryPlaybackForKey(null, null, streamId, null);
-        StreamInfo streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
-        if (null == streamInfo) {
+        InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(InviteSessionType.PLAYBACK, streamId);
+        if (null == inviteInfo || inviteInfo.getStreamInfo() == null) {
             logger.warn("streamId涓嶅瓨鍦�!");
             throw new ServiceException("streamId涓嶅瓨鍦�");
         }
-        streamInfo.setPause(true);
-        redisTemplate.opsForValue().set(key, streamInfo);
-        MediaServerItem mediaServerItem = mediaServerService.getOne(streamInfo.getMediaServerId());
+        inviteInfo.getStreamInfo().setPause(true);
+        inviteStreamService.updateInviteInfo(inviteInfo);
+        MediaServerItem mediaServerItem = mediaServerService.getOne(inviteInfo.getStreamInfo().getMediaServerId());
         if (null == mediaServerItem) {
             logger.warn("mediaServer 涓嶅瓨鍦�!");
             throw new ServiceException("mediaServer涓嶅瓨鍦�");
@@ -1025,21 +1100,20 @@
         if (jsonObject == null || jsonObject.getInteger("code") != 0) {
             throw new ServiceException("鏆傚仠RTP鎺ユ敹澶辫触");
         }
-        Device device = storager.queryVideoDevice(streamInfo.getDeviceID());
-        cmder.playPauseCmd(device, streamInfo);
+        Device device = storager.queryVideoDevice(inviteInfo.getDeviceId());
+        cmder.playPauseCmd(device, inviteInfo.getStreamInfo());
     }
 
     @Override
     public void resumeRtp(String streamId) throws ServiceException, InvalidArgumentException, ParseException, SipException {
-        String key = redisCatchStorage.queryPlaybackForKey(null, null, streamId, null);
-        StreamInfo streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
-        if (null == streamInfo) {
+        InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(InviteSessionType.PLAYBACK, streamId);
+        if (null == inviteInfo || inviteInfo.getStreamInfo() == null) {
             logger.warn("streamId涓嶅瓨鍦�!");
             throw new ServiceException("streamId涓嶅瓨鍦�");
         }
-        streamInfo.setPause(false);
-        redisTemplate.opsForValue().set(key, streamInfo);
-        MediaServerItem mediaServerItem = mediaServerService.getOne(streamInfo.getMediaServerId());
+        inviteInfo.getStreamInfo().setPause(false);
+        inviteStreamService.updateInviteInfo(inviteInfo);
+        MediaServerItem mediaServerItem = mediaServerService.getOne(inviteInfo.getStreamInfo().getMediaServerId());
         if (null == mediaServerItem) {
             logger.warn("mediaServer 涓嶅瓨鍦�!");
             throw new ServiceException("mediaServer涓嶅瓨鍦�");
@@ -1049,7 +1123,7 @@
         if (jsonObject == null || jsonObject.getInteger("code") != 0) {
             throw new ServiceException("缁х画RTP鎺ユ敹澶辫触");
         }
-        Device device = storager.queryVideoDevice(streamInfo.getDeviceID());
-        cmder.playResumeCmd(device, streamInfo);
+        Device device = storager.queryVideoDevice(inviteInfo.getDeviceId());
+        cmder.playResumeCmd(device, inviteInfo.getStreamInfo());
     }
 }
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
index b6cfab4..ec93e78 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
@@ -1,14 +1,16 @@
 package com.genersoft.iot.vmp.storager;
 
 import com.alibaba.fastjson2.JSONObject;
-import com.genersoft.iot.vmp.common.StreamInfo;
 import com.genersoft.iot.vmp.common.SystemAllInfo;
-import com.genersoft.iot.vmp.gb28181.bean.*;
-import com.genersoft.iot.vmp.media.zlm.dto.*;
+import com.genersoft.iot.vmp.gb28181.bean.AlarmChannelMessage;
+import com.genersoft.iot.vmp.gb28181.bean.Device;
+import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
+import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
+import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
+import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
 import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam;
 import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
 import com.genersoft.iot.vmp.service.bean.MessageForPushChannel;
-import com.genersoft.iot.vmp.service.bean.ThirdPartyGB;
 import com.genersoft.iot.vmp.storager.dao.dto.PlatformRegisterInfo;
 
 import java.util.List;
@@ -22,14 +24,6 @@
      * @return
      */
     Long getCSEQ();
-
-    boolean startPlayback(StreamInfo stream, String callId);
-
-    boolean stopPlayback(String deviceId, String channelId, String stream, String callId);
-
-    StreamInfo queryPlayback(String deviceId, String channelID, String stream, String callId);
-
-    String queryPlaybackForKey(String deviceId, String channelId, String stream, String callId);
 
     void updatePlatformCatchInfo(ParentPlatformCatch parentPlatformCatch);
 
@@ -46,8 +40,6 @@
     PlatformRegisterInfo queryPlatformRegisterInfo(String callId);
 
     void delPlatformRegisterInfo(String callId);
-
-    void cleanPlatformRegisterInfos();
 
     void updateSendRTPSever(SendRtpItem sendRtpItem);
 
@@ -73,12 +65,6 @@
      * @param channelId
      */
     boolean isChannelSendingRTP(String channelId);
-
-    /**
-     * 娓呯┖鏌愪釜璁惧鐨勬墍鏈夌紦瀛�
-     * @param deviceId 璁惧ID
-     */
-    void clearCatchByDeviceId(String deviceId);
 
     /**
      * 鍦╮edis娣诲姞wvp鐨勪俊鎭�
@@ -119,23 +105,6 @@
      * @param mediaServerId
      */
     void removeStream(String mediaServerId, String type);
-
-    /**
-     * 寮�濮嬩笅杞藉綍鍍忔椂瀛樺叆
-     * @param streamInfo
-     */
-    boolean startDownload(StreamInfo streamInfo, String callId);
-
-    StreamInfo queryDownload(String deviceId, String channelId, String stream, String callId);
-
-    boolean stopDownload(String deviceId, String channelId, String stream, String callId);
-
-    /**
-     * 鏌ユ壘绗笁鏂圭郴缁熺暀涓嬬殑鍥芥爣棰勮鍊�
-     * @param queryKey
-     * @return
-     */
-    ThirdPartyGB queryMemberNoGBId(String queryKey);
 
     List<OnStreamChangedHookParam> getStreams(String mediaServerId, String pull);
 
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
index dabe9f8..98327ab 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
@@ -2,17 +2,18 @@
 
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
-import com.genersoft.iot.vmp.common.StreamInfo;
 import com.genersoft.iot.vmp.common.SystemAllInfo;
 import com.genersoft.iot.vmp.common.VideoManagerConstants;
 import com.genersoft.iot.vmp.conf.UserSetting;
-import com.genersoft.iot.vmp.gb28181.bean.*;
-import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam;
+import com.genersoft.iot.vmp.gb28181.bean.AlarmChannelMessage;
+import com.genersoft.iot.vmp.gb28181.bean.Device;
+import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
+import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
 import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
+import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam;
 import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
 import com.genersoft.iot.vmp.service.bean.MessageForPushChannel;
-import com.genersoft.iot.vmp.service.bean.ThirdPartyGB;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
 import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
 import com.genersoft.iot.vmp.storager.dao.dto.PlatformRegisterInfo;
@@ -92,160 +93,6 @@
         }
     }
 
-
-    @Override
-    public boolean startPlayback(StreamInfo stream, String callId) {
-        redisTemplate.opsForValue().set(String.format("%S_%s_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
-                userSetting.getServerId(), stream.getMediaServerId(), stream.getDeviceID(), stream.getChannelId(), stream.getStream(), callId), stream);
-        return true;
-    }
-
-    @Override
-    public boolean startDownload(StreamInfo stream, String callId) {
-        String key=String.format("%S_%s_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
-                userSetting.getServerId(), stream.getMediaServerId(), stream.getDeviceID(), stream.getChannelId(), stream.getStream(), callId);
-        if (stream.getProgress() == 1) {
-            logger.debug("娣诲姞涓嬭浇缂撳瓨==宸插畬鎴愪笅杞�=銆媨}",key);
-            redisTemplate.opsForValue().set(key, stream);
-        }else {
-            logger.debug("娣诲姞涓嬭浇缂撳瓨==鏈畬鎴愪笅杞�=銆媨}",key);
-            Duration duration = Duration.ofSeconds(60*60L);
-            redisTemplate.opsForValue().set(key, stream, duration);
-        }
-        return true;
-    }
-    @Override
-    public boolean stopDownload(String deviceId, String channelId, String stream, String callId) {
-        DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(deviceId, channelId);
-        if (deviceChannel != null) {
-            deviceChannel.setStreamId(null);
-            deviceChannel.setDeviceId(deviceId);
-            deviceChannelMapper.update(deviceChannel);
-        }
-        if (deviceId == null) {
-            deviceId = "*";
-        }
-        if (channelId == null) {
-            channelId = "*";
-        }
-        if (stream == null) {
-            stream = "*";
-        }
-        if (callId == null) {
-            callId = "*";
-        }
-        String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
-                userSetting.getServerId(),
-                deviceId,
-                channelId,
-                stream,
-                callId
-        );
-        List<Object> scan = RedisUtil.scan(redisTemplate, key);
-        if (scan.size() > 0) {
-            for (Object keyObj : scan) {
-                redisTemplate.delete(keyObj);
-            }
-        }
-        return true;
-    }
-
-    @Override
-    public boolean stopPlayback(String deviceId, String channelId, String stream, String callId) {
-        DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(deviceId, channelId);
-        if (deviceChannel != null) {
-            deviceChannel.setStreamId(null);
-            deviceChannel.setDeviceId(deviceId);
-            deviceChannelMapper.update(deviceChannel);
-        }
-        if (deviceId == null) {
-            deviceId = "*";
-        }
-        if (channelId == null) {
-            channelId = "*";
-        }
-        if (stream == null) {
-            stream = "*";
-        }
-        if (callId == null) {
-            callId = "*";
-        }
-        String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
-                userSetting.getServerId(),
-                deviceId,
-                channelId,
-                stream,
-                callId
-        );
-        List<Object> scan = RedisUtil.scan(redisTemplate, key);
-        if (scan.size() > 0) {
-            for (Object keyObj : scan) {
-                redisTemplate.delete(keyObj);
-            }
-        }
-        return true;
-    }
-
-    @Override
-    public StreamInfo queryPlayback(String deviceId, String channelId, String stream, String callId) {
-        if (stream == null && callId == null) {
-            return null;
-        }
-        if (deviceId == null) {
-            deviceId = "*";
-        }
-        if (channelId == null) {
-            channelId = "*";
-        }
-        if (stream == null) {
-            stream = "*";
-        }
-        if (callId == null) {
-            callId = "*";
-        }
-        String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
-                userSetting.getServerId(),
-                deviceId,
-                channelId,
-                stream,
-                callId
-        );
-        List<Object> streamInfoScan = RedisUtil.scan(redisTemplate, key);
-        if (streamInfoScan.size() > 0) {
-            return (StreamInfo) redisTemplate.opsForValue().get(streamInfoScan.get(0));
-        }else {
-            return null;
-        }
-    }
-
-    @Override
-    public String queryPlaybackForKey(String deviceId, String channelId, String stream, String callId) {
-        if (stream == null && callId == null) {
-            return null;
-        }
-        if (deviceId == null) {
-            deviceId = "*";
-        }
-        if (channelId == null) {
-            channelId = "*";
-        }
-        if (stream == null) {
-            stream = "*";
-        }
-        if (callId == null) {
-            callId = "*";
-        }
-        String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
-                userSetting.getServerId(),
-                deviceId,
-                channelId,
-                stream,
-                callId
-        );
-        List<Object> streamInfoScan = RedisUtil.scan(redisTemplate, key);
-        return (String) streamInfoScan.get(0);
-    }
-
     @Override
     public void updatePlatformCatchInfo(ParentPlatformCatch parentPlatformCatch) {
         String key = VideoManagerConstants.PLATFORM_CATCH_PREFIX  + userSetting.getServerId() + "_" +  parentPlatformCatch.getId();
@@ -289,14 +136,6 @@
     @Override
     public void delPlatformRegisterInfo(String callId) {
          redisTemplate.delete(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetting.getServerId() + "_" + callId);
-    }
-
-    @Override
-    public void cleanPlatformRegisterInfos() {
-        List regInfos = RedisUtil.scan(redisTemplate, VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetting.getServerId() + "_" + "*");
-        for (Object key : regInfos) {
-            redisTemplate.delete(key.toString());
-        }
     }
 
     @Override
@@ -456,36 +295,6 @@
     }
 
     @Override
-    public void clearCatchByDeviceId(String deviceId) {
-        List<Object> playLeys = RedisUtil.scan(redisTemplate, String.format("%S_%s_*_%s_*", VideoManagerConstants.PLAYER_PREFIX,
-                userSetting.getServerId(),
-                deviceId));
-        if (playLeys.size() > 0) {
-            for (Object key : playLeys) {
-                redisTemplate.delete(key.toString());
-            }
-        }
-
-        List<Object> playBackers = RedisUtil.scan(redisTemplate, String.format("%S_%s_*_%s_*_*_*", VideoManagerConstants.PLAY_BLACK_PREFIX,
-                userSetting.getServerId(),
-                deviceId));
-        if (playBackers.size() > 0) {
-            for (Object key : playBackers) {
-                redisTemplate.delete(key.toString());
-            }
-        }
-
-        List<Object> deviceCache = RedisUtil.scan(redisTemplate, String.format("%S%s_%s", VideoManagerConstants.DEVICE_PREFIX,
-                userSetting.getServerId(),
-                deviceId));
-        if (deviceCache.size() > 0) {
-            for (Object key : deviceCache) {
-                redisTemplate.delete(key.toString());
-            }
-        }
-    }
-
-    @Override
     public void updateWVPInfo(JSONObject jsonObject, int time) {
         String key = VideoManagerConstants.WVP_SERVER_PREFIX + userSetting.getServerId();
         Duration duration = Duration.ofSeconds(time);
@@ -514,44 +323,6 @@
     public void removeStream(String mediaServerId, String type, String app, String streamId) {
         String key = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetting.getServerId() + "_" + type + "_"  + app + "_" + streamId + "_" + mediaServerId;
         redisTemplate.delete(key);
-    }
-
-    @Override
-    public StreamInfo queryDownload(String deviceId, String channelId, String stream, String callId) {
-        if (stream == null && callId == null) {
-            return null;
-        }
-        if (deviceId == null) {
-            deviceId = "*";
-        }
-        if (channelId == null) {
-            channelId = "*";
-        }
-        if (stream == null) {
-            stream = "*";
-        }
-        if (callId == null) {
-            callId = "*";
-        }
-        String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
-                userSetting.getServerId(),
-                deviceId,
-                channelId,
-                stream,
-                callId
-        );
-        List<Object> streamInfoScan = RedisUtil.scan(redisTemplate, key);
-        if (streamInfoScan.size() > 0) {
-            return (StreamInfo) redisTemplate.opsForValue().get(streamInfoScan.get(0));
-        }else {
-            return null;
-        }
-    }
-
-    @Override
-    public ThirdPartyGB queryMemberNoGBId(String queryKey) {
-        String key = VideoManagerConstants.WVP_STREAM_GB_ID_PREFIX + queryKey;
-        return JsonUtil.redisJsonToObject(redisTemplate, key, ThirdPartyGB.class);
     }
 
     @Override
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
index d0accf4..0ff8ba1 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
@@ -14,6 +14,7 @@
 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
 import com.genersoft.iot.vmp.service.IDeviceChannelService;
 import com.genersoft.iot.vmp.service.IDeviceService;
+import com.genersoft.iot.vmp.service.IInviteStreamService;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
 import com.genersoft.iot.vmp.vmanager.bean.BaseTree;
@@ -62,6 +63,9 @@
 
 	@Autowired
 	private IRedisCatchStorage redisCatchStorage;
+
+	@Autowired
+	private IInviteStreamService inviteStreamService;
 	
 	@Autowired
 	private SIPCommander cmder;
@@ -184,7 +188,7 @@
 		// 娓呴櫎redis璁板綍
 		boolean isSuccess = deviceService.delete(deviceId);
 		if (isSuccess) {
-			redisCatchStorage.clearCatchByDeviceId(deviceId);
+			inviteStreamService.clearInviteInfo(deviceId);
 			// 鍋滄姝よ澶囩殑璁㈤槄鏇存柊
 			Set<String> allKeys = dynamicTask.getAllKeys();
 			for (String key : allKeys) {
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java
index f6f42b3..a4fa8dd 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java
@@ -1,6 +1,5 @@
 package com.genersoft.iot.vmp.vmanager.gb28181.play;
 
-import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import com.genersoft.iot.vmp.common.InviteInfo;
@@ -116,7 +115,7 @@
 		// 褰曞儚鏌ヨ浠hannelId浣滀负deviceId鏌ヨ
 		resultHolder.put(key, uuid, result);
 
-		playService.play(newMediaServerItem, deviceId, channelId, ((code, msg, data) -> {
+		playService.play(newMediaServerItem, deviceId, channelId, (code, msg, data) -> {
 			WVPResult<StreamContent> wvpResult = new WVPResult<>();
 			if (code == InviteErrorCode.SUCCESS.getCode()) {
 				wvpResult.setCode(ErrorCode.SUCCESS.getCode());
@@ -133,10 +132,9 @@
 				wvpResult.setCode(code);
 				wvpResult.setMsg(msg);
 			}
-			System.out.println(JSON.toJSONString(wvpResult));
 			requestMessage.setData(wvpResult);
 			resultHolder.invokeResult(requestMessage);
-		}));
+		});
 		return result;
 	}
 
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/PlaybackController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/PlaybackController.java
index 8bab3fd..9db6417 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/PlaybackController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/PlaybackController.java
@@ -1,15 +1,22 @@
 package com.genersoft.iot.vmp.vmanager.gb28181.playback;
 
+import com.genersoft.iot.vmp.common.InviteInfo;
+import com.genersoft.iot.vmp.common.InviteSessionType;
 import com.genersoft.iot.vmp.common.StreamInfo;
 import com.genersoft.iot.vmp.conf.UserSetting;
 import com.genersoft.iot.vmp.conf.exception.ControllerException;
 import com.genersoft.iot.vmp.conf.exception.ServiceException;
 import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
+import com.genersoft.iot.vmp.gb28181.bean.Device;
 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
 import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
-import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
+import com.genersoft.iot.vmp.service.IInviteStreamService;
 import com.genersoft.iot.vmp.service.IPlayService;
+import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
+import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
+import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
 import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
 import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
@@ -20,17 +27,13 @@
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.ObjectUtils;
-import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
-
-import com.genersoft.iot.vmp.gb28181.bean.Device;
-import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
-import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
 import org.springframework.web.context.request.async.DeferredResult;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.sip.InvalidArgumentException;
 import javax.sip.SipException;
 import java.text.ParseException;
@@ -60,6 +63,9 @@
 	private IRedisCatchStorage redisCatchStorage;
 
 	@Autowired
+	private IInviteStreamService inviteStreamService;
+
+	@Autowired
 	private IPlayService playService;
 
 	@Autowired
@@ -74,8 +80,8 @@
 	@Parameter(name = "startTime", description = "寮�濮嬫椂闂�", required = true)
 	@Parameter(name = "endTime", description = "缁撴潫鏃堕棿", required = true)
 	@GetMapping("/start/{deviceId}/{channelId}")
-	public DeferredResult<WVPResult<StreamContent>> start(@PathVariable String deviceId, @PathVariable String channelId,
-														 String startTime, String endTime) {
+	public DeferredResult<WVPResult<StreamContent>> start(HttpServletRequest request, @PathVariable String deviceId, @PathVariable String channelId,
+														  String startTime, String endTime) {
 
 		if (logger.isDebugEnabled()) {
 			logger.debug(String.format("璁惧鍥炴斁 API璋冪敤锛宒eviceId锛�%s 锛宑hannelId锛�%s", deviceId, channelId));
@@ -86,22 +92,31 @@
 		DeferredResult<WVPResult<StreamContent>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue());
 		resultHolder.put(key, uuid, result);
 
-		WVPResult<StreamContent> wvpResult = new WVPResult<>();
+		RequestMessage requestMessage = new RequestMessage();
+		requestMessage.setKey(key);
+		requestMessage.setId(uuid);
 
-		RequestMessage msg = new RequestMessage();
-		msg.setKey(key);
-		msg.setId(uuid);
+		playService.playBack(deviceId, channelId, startTime, endTime,
+				(code, msg, data)->{
 
-		playService.playBack(deviceId, channelId, startTime, endTime, null,
-				playBackResult->{
-					wvpResult.setCode(playBackResult.getCode());
-					wvpResult.setMsg(playBackResult.getMsg());
-					if (playBackResult.getCode() == ErrorCode.SUCCESS.getCode()) {
-						StreamInfo streamInfo = (StreamInfo)playBackResult.getData();
-						wvpResult.setData(new StreamContent(streamInfo));
+					WVPResult<StreamContent> wvpResult = new WVPResult<>();
+					if (code == InviteErrorCode.SUCCESS.getCode()) {
+						wvpResult.setCode(ErrorCode.SUCCESS.getCode());
+						wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
+
+						if (data != null) {
+							StreamInfo streamInfo = (StreamInfo)data;
+							if (userSetting.getUseSourceIpAsStreamIp()) {
+								streamInfo.channgeStreamIp(request.getLocalName());
+							}
+							wvpResult.setData(new StreamContent(streamInfo));
+						}
+					}else {
+						wvpResult.setCode(code);
+						wvpResult.setMsg(msg);
 					}
-					msg.setData(wvpResult);
-					resultHolder.invokeResult(msg);
+					requestMessage.setData(wvpResult);
+					resultHolder.invokeResult(requestMessage);
 				});
 
 		return result;
@@ -169,14 +184,15 @@
 	@GetMapping("/seek/{streamId}/{seekTime}")
 	public void playSeek(@PathVariable String streamId, @PathVariable long seekTime) {
 		logger.info("playSeek: "+streamId+", "+seekTime);
-		StreamInfo streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
-		if (null == streamInfo) {
+		InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(InviteSessionType.PLAYBACK, streamId);
+
+		if (null == inviteInfo || inviteInfo.getStreamInfo() == null) {
 			logger.warn("streamId涓嶅瓨鍦�!");
 			throw new ControllerException(ErrorCode.ERROR400.getCode(), "streamId涓嶅瓨鍦�");
 		}
-		Device device = storager.queryVideoDevice(streamInfo.getDeviceID());
+		Device device = storager.queryVideoDevice(inviteInfo.getDeviceId());
 		try {
-			cmder.playSeekCmd(device, streamInfo, seekTime);
+			cmder.playSeekCmd(device, inviteInfo.getStreamInfo(), seekTime);
 		} catch (InvalidArgumentException | ParseException | SipException e) {
 			throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
 		}
@@ -188,8 +204,9 @@
 	@GetMapping("/speed/{streamId}/{speed}")
 	public void playSpeed(@PathVariable String streamId, @PathVariable Double speed) {
 		logger.info("playSpeed: "+streamId+", "+speed);
-		StreamInfo streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
-		if (null == streamInfo) {
+		InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(InviteSessionType.PLAYBACK, streamId);
+
+		if (null == inviteInfo || inviteInfo.getStreamInfo() == null) {
 			logger.warn("streamId涓嶅瓨鍦�!");
 			throw new ControllerException(ErrorCode.ERROR400.getCode(), "streamId涓嶅瓨鍦�");
 		}
@@ -197,9 +214,9 @@
 			logger.warn("涓嶆敮鎸佺殑speed锛� " + speed);
 			throw new ControllerException(ErrorCode.ERROR100.getCode(), "涓嶆敮鎸佺殑speed锛�0.25 0.5 1銆�2銆�4锛�");
 		}
-		Device device = storager.queryVideoDevice(streamInfo.getDeviceID());
+		Device device = storager.queryVideoDevice(inviteInfo.getDeviceId());
 		try {
-			cmder.playSpeedCmd(device, streamInfo, speed);
+			cmder.playSpeedCmd(device, inviteInfo.getStreamInfo(), speed);
 		} catch (InvalidArgumentException | ParseException | SipException e) {
 			throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
 		}
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java
index 0dcc5ad..6de5483 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java
@@ -1,6 +1,7 @@
 package com.genersoft.iot.vmp.vmanager.gb28181.record;
 
 import com.genersoft.iot.vmp.common.StreamInfo;
+import com.genersoft.iot.vmp.conf.UserSetting;
 import com.genersoft.iot.vmp.conf.exception.ControllerException;
 import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
 import com.genersoft.iot.vmp.gb28181.bean.Device;
@@ -10,6 +11,7 @@
 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
 import com.genersoft.iot.vmp.service.IDeviceService;
 import com.genersoft.iot.vmp.service.IPlayService;
+import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
 import com.genersoft.iot.vmp.utils.DateUtil;
 import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
@@ -27,6 +29,7 @@
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.context.request.async.DeferredResult;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.sip.InvalidArgumentException;
 import javax.sip.SipException;
 import java.text.ParseException;
@@ -55,8 +58,8 @@
 	@Autowired
 	private IDeviceService deviceService;
 
-
-
+	@Autowired
+	private UserSetting userSetting;
 
 	@Operation(summary = "褰曞儚鏌ヨ")
 	@Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿", required = true)
@@ -119,8 +122,8 @@
 	@Parameter(name = "endTime", description = "缁撴潫鏃堕棿", required = true)
 	@Parameter(name = "downloadSpeed", description = "涓嬭浇鍊嶉��", required = true)
 	@GetMapping("/download/start/{deviceId}/{channelId}")
-	public DeferredResult<WVPResult<StreamContent>> download(@PathVariable String deviceId, @PathVariable String channelId,
-													   String startTime, String endTime, String downloadSpeed) {
+	public DeferredResult<WVPResult<StreamContent>> download(HttpServletRequest request, @PathVariable String deviceId, @PathVariable String channelId,
+															 String startTime, String endTime, String downloadSpeed) {
 
 		if (logger.isDebugEnabled()) {
 			logger.debug(String.format("鍘嗗彶濯掍綋涓嬭浇 API璋冪敤锛宒eviceId锛�%s锛宑hannelId锛�%s锛宒ownloadSpeed锛�%s", deviceId, channelId, downloadSpeed));
@@ -130,22 +133,32 @@
 		String key = DeferredResultHolder.CALLBACK_CMD_DOWNLOAD + deviceId + channelId;
 		DeferredResult<WVPResult<StreamContent>> result = new DeferredResult<>(30000L);
 		resultHolder.put(key, uuid, result);
-		RequestMessage msg = new RequestMessage();
-		msg.setId(uuid);
-		msg.setKey(key);
+		RequestMessage requestMessage = new RequestMessage();
+		requestMessage.setId(uuid);
+		requestMessage.setKey(key);
 
-		WVPResult<StreamContent> wvpResult = new WVPResult<>();
 
-		playService.download(deviceId, channelId, startTime, endTime, Integer.parseInt(downloadSpeed), null, playBackResult->{
+		playService.download(deviceId, channelId, startTime, endTime, Integer.parseInt(downloadSpeed),
+		(code, msg, data)->{
 
-			wvpResult.setCode(playBackResult.getCode());
-			wvpResult.setMsg(playBackResult.getMsg());
-			if (playBackResult.getCode() == ErrorCode.SUCCESS.getCode()) {
-				StreamInfo streamInfo = (StreamInfo)playBackResult.getData();
-				wvpResult.setData(new StreamContent(streamInfo));
+			WVPResult<StreamContent> wvpResult = new WVPResult<>();
+			if (code == InviteErrorCode.SUCCESS.getCode()) {
+				wvpResult.setCode(ErrorCode.SUCCESS.getCode());
+				wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
+
+				if (data != null) {
+					StreamInfo streamInfo = (StreamInfo)data;
+					if (userSetting.getUseSourceIpAsStreamIp()) {
+						streamInfo.channgeStreamIp(request.getLocalName());
+					}
+					wvpResult.setData(new StreamContent(streamInfo));
+				}
+			}else {
+				wvpResult.setCode(code);
+				wvpResult.setMsg(msg);
 			}
-			msg.setData(wvpResult);
-			resultHolder.invokeResult(msg);
+			requestMessage.setData(wvpResult);
+			resultHolder.invokeResult(requestMessage);
 		});
 
 		return result;

--
Gitblit v1.8.0