648540858
2022-02-24 a42dda2bd3cc1cf8c20cc61e7ad9211eadecbaf3
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
@@ -1,43 +1,46 @@
package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl;
import java.text.ParseException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.conf.UserSetup;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider;
import com.genersoft.iot.vmp.gb28181.utils.DateUtil;
import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.service.IMediaServerService;
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
import gov.nist.javax.sip.SipProviderImpl;
import gov.nist.javax.sip.SipStackImpl;
import gov.nist.javax.sip.message.SIPRequest;
import gov.nist.javax.sip.stack.SIPDialog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.sip.*;
import javax.sip.address.SipURI;
import javax.sip.header.CallIdHeader;
import javax.sip.header.ViaHeader;
import javax.sip.message.Request;
import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.MediaServerConfig;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider;
import com.genersoft.iot.vmp.gb28181.utils.DateUtil;
import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
import java.lang.reflect.Field;
import java.text.ParseException;
import java.util.HashSet;
/**    
 * @Description:设备能力接口,用于定义设备的控制、查询能力
 * @description:设备能力接口,用于定义设备的控制、查询能力
 * @author: swwheihei
 * @date:   2020年5月3日 下午9:22:48     
 */
@@ -50,15 +53,13 @@
   @Autowired
   private SipConfig sipConfig;
   @Lazy
   @Autowired
   @Qualifier(value="tcpSipProvider")
   private SipProvider tcpSipProvider;
   private SipProviderImpl tcpSipProvider;
   @Lazy
   @Autowired
   @Qualifier(value="udpSipProvider")
   private SipProvider udpSipProvider;
   private SipProviderImpl udpSipProvider;
   @Autowired
   private SIPRequestHeaderProvider headerProvider;
@@ -73,16 +74,7 @@
   private IRedisCatchStorage redisCatchStorage;
   @Autowired
   private ZLMRTPServerFactory zlmrtpServerFactory;
   @Value("${media.rtp.enable}")
   private boolean rtpEnable;
   @Value("${media.seniorSdp}")
   private boolean seniorSdp;
   @Value("${media.autoApplyPlay}")
   private boolean autoApplyPlay;
   private UserSetup userSetup;
   @Autowired
   private ZLMHttpHookSubscribe subscribe;
@@ -90,9 +82,9 @@
   @Autowired
   private SipSubscribe sipSubscribe;
   public SipConfig getSipConfig() {
      return sipConfig;
   }
   @Autowired
   private IMediaServerService mediaServerService;
   /**
    * 云台方向放控制,使用配置文件中的默认镜头移动速度
@@ -104,7 +96,7 @@
    */
   @Override
   public boolean ptzdirectCmd(Device device, String channelId, int leftRight, int upDown) {
      return ptzCmd(device, channelId, leftRight, upDown, 0, sipConfig.getSpeed(), 0);
      return ptzCmd(device, channelId, leftRight, upDown, 0, sipConfig.getPtzSpeed(), 0);
   }
   /**
@@ -130,7 +122,7 @@
    */  
   @Override
   public boolean ptzZoomCmd(Device device, String channelId, int inOut) {
      return ptzCmd(device, channelId, 0, 0, inOut, 0, sipConfig.getSpeed());
      return ptzCmd(device, channelId, 0, 0, inOut, 0, sipConfig.getPtzSpeed());
   }
   /**
@@ -270,7 +262,7 @@
   public boolean frontEndCmd(Device device, String channelId, int cmdCode, int parameter1, int parameter2, int combineCode2) {
      try {
         String cmdStr= frontEndCmdString(cmdCode, parameter1, parameter2, combineCode2);
         System.out.println("控制字符串:" + cmdStr);
         logger.debug("控制字符串:" + cmdStr);
         StringBuffer ptzXml = new StringBuffer(200);
         ptzXml.append("<?xml version=\"1.0\" ?>\r\n");
         ptzXml.append("<Control>\r\n");
@@ -338,57 +330,40 @@
     * @param errorEvent sip错误订阅
     */
   @Override
   public void playStreamCmd(Device device, String channelId, ZLMHttpHookSubscribe.Event event, SipSubscribe.Event errorEvent) {
      String streamId = null;
   public void playStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId, ZLMHttpHookSubscribe.Event event, SipSubscribe.Event errorEvent) {
      String streamId = ssrcInfo.getStreamId();
      try {
         if (device == null) return;
         String ssrc = streamSession.createPlaySsrc();
         if (rtpEnable) {
            streamId = String.format("gb_play_%s_%s", device.getDeviceId(), channelId);
         }else {
            streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase();
         }
         String streamMode = device.getStreamMode().toUpperCase();
         MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
         if (mediaInfo == null) {
            logger.warn("点播时发现ZLM尚未连接...");
            return;
         }
         String mediaPort = null;
         // 使用动态udp端口
         if (rtpEnable) {
            mediaPort = zlmrtpServerFactory.createRTPServer(streamId) + "";
         }else {
            mediaPort = mediaInfo.getRtpProxyPort();
         }
         logger.info("{} 分配的ZLM为: {} [{}:{}]", streamId, mediaServerItem.getId(), mediaServerItem.getIp(), ssrcInfo.getPort());
         // 添加订阅
         JSONObject subscribeKey = new JSONObject();
         subscribeKey.put("app", "rtp");
         subscribeKey.put("stream", streamId);
         subscribeKey.put("regist", true);
         subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey, json->{
            if (json.getJSONArray("tracks") == null) return;
            event.response(json);
         subscribeKey.put("mediaServerId", mediaServerItem.getId());
         subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey,
               (MediaServerItem mediaServerItemInUse, JSONObject json)->{
            if (userSetup.isWaitTrack() && json.getJSONArray("tracks") == null) return;
            event.response(mediaServerItemInUse, json);
            subscribe.removeSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey);
         });
         //
         StringBuffer content = new StringBuffer(200);
         content.append("v=0\r\n");
//         content.append("o="+channelId+" 0 0 IN IP4 "+mediaInfo.getWanIp()+"\r\n");
         content.append("o="+"00000"+" 0 0 IN IP4 "+mediaInfo.getWanIp()+"\r\n");
         content.append("o="+ sipConfig.getId()+" 0 0 IN IP4 "+ mediaServerItem.getSdpIp() +"\r\n");
         content.append("s=Play\r\n");
         content.append("c=IN IP4 "+mediaInfo.getWanIp()+"\r\n");
         content.append("c=IN IP4 "+ mediaServerItem.getSdpIp() +"\r\n");
         content.append("t=0 0\r\n");
         if (seniorSdp) {
         if (userSetup.isSeniorSdp()) {
            if("TCP-PASSIVE".equals(streamMode)) {
               content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
               content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
            }else if ("TCP-ACTIVE".equals(streamMode)) {
               content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
               content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
            }else if("UDP".equals(streamMode)) {
               content.append("m=video "+ mediaPort +" RTP/AVP 96 126 125 99 34 98 97\r\n");
               content.append("m=video "+ ssrcInfo.getPort() +" RTP/AVP 96 126 125 99 34 98 97\r\n");
            }
            content.append("a=recvonly\r\n");
            content.append("a=rtpmap:96 PS/90000\r\n");
@@ -409,46 +384,44 @@
            }
         }else {
            if("TCP-PASSIVE".equals(streamMode)) {
               content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
               content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 98 97\r\n");
            }else if ("TCP-ACTIVE".equals(streamMode)) {
               content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
               content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 98 97\r\n");
            }else if("UDP".equals(streamMode)) {
               content.append("m=video "+ mediaPort +" RTP/AVP 96 98 97\r\n");
               content.append("m=video "+ ssrcInfo.getPort() +" RTP/AVP 96 98 97\r\n");
            }
            content.append("a=recvonly\r\n");
            content.append("a=rtpmap:96 PS/90000\r\n");
            content.append("a=rtpmap:98 H264/90000\r\n");
            content.append("a=rtpmap:97 MPEG4/90000\r\n");
            if("TCP-PASSIVE".equals(streamMode)) { // tcp被动模式
            if ("TCP-PASSIVE".equals(streamMode)) { // tcp被动模式
               content.append("a=setup:passive\r\n");
               content.append("a=recvonly\r\n");
               content.append("a=rtpmap:96 PS/90000\r\n");
               content.append("a=rtpmap:98 H264/90000\r\n");
               content.append("a=rtpmap:97 MPEG4/90000\r\n");
               if ("TCP-PASSIVE".equals(streamMode)) { // tcp被动模式
                  content.append("a=setup:passive\r\n");
                  content.append("a=connection:new\r\n");
               } else if ("TCP-ACTIVE".equals(streamMode)) { // tcp主动模式
                  content.append("a=setup:active\r\n");
                  content.append("a=connection:new\r\n");
               }
               content.append("a=connection:new\r\n");
            } else if ("TCP-ACTIVE".equals(streamMode)) { // tcp主动模式
               content.append("a=setup:active\r\n");
               content.append("a=connection:new\r\n");
            }
         }
         content.append("y="+ssrc+"\r\n");//ssrc
         content.append("y="+ssrcInfo.getSsrc()+"\r\n");//ssrc
         String tm = Long.toString(System.currentTimeMillis());
         CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
               : udpSipProvider.getNewCallId();
         Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "FromInvt" + tm, null, ssrc, callIdHeader);
         Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "FromInvt" + tm, null, ssrcInfo.getSsrc(), callIdHeader);
         ClientTransaction transaction = transmitRequest(device, request, (e -> {
         String finalStreamId = streamId;
         transmitRequest(device, request, (e -> {
            streamSession.remove(device.getDeviceId(), channelId);
            mediaServerService.releaseSsrc(mediaServerItem, ssrcInfo.getSsrc());
            errorEvent.response(e);
         }));
         streamSession.put(device.getDeviceId(), channelId ,ssrc,streamId, transaction);
         }), e ->{
            streamSession.put(device.getDeviceId(), channelId ,ssrcInfo.getSsrc(), finalStreamId, mediaServerItem.getId(), ((ResponseEvent)e.event).getClientTransaction());
            streamSession.put(device.getDeviceId(), channelId , e.dialog);
         });
         
      } catch ( SipException | ParseException | InvalidArgumentException e) {
         e.printStackTrace();
@@ -464,48 +437,46 @@
    * @param endTime 结束时间,格式要求:yyyy-MM-dd HH:mm:ss
    */ 
   @Override
   public void playbackStreamCmd(Device device, String channelId, String startTime, String endTime, ZLMHttpHookSubscribe.Event event
   public void playbackStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId, String startTime, String endTime, ZLMHttpHookSubscribe.Event event
         , SipSubscribe.Event errorEvent) {
      try {
         MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
         String ssrc = streamSession.createPlayBackSsrc();
         String streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase();
         logger.info("{} 分配的ZLM为: {} [{}:{}]", ssrcInfo.getStreamId(), mediaServerItem.getId(), mediaServerItem.getIp(), ssrcInfo.getPort());
         // 添加订阅
         JSONObject subscribeKey = new JSONObject();
         subscribeKey.put("app", "rtp");
         subscribeKey.put("stream", streamId);
         subscribeKey.put("stream", ssrcInfo.getStreamId());
         subscribeKey.put("regist", true);
         subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey, json->{
            if (json.getJSONArray("tracks") == null) return;
            event.response(json);
         subscribeKey.put("mediaServerId", mediaServerItem.getId());
         logger.debug("录像回放添加订阅,订阅内容:" + subscribeKey.toString());
         subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey,
               (MediaServerItem mediaServerItemInUse, JSONObject json)->{
            if (userSetup.isWaitTrack() && json.getJSONArray("tracks") == null) return;
            event.response(mediaServerItemInUse, json);
            subscribe.removeSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey);
         });
         StringBuffer content = new StringBuffer(200);
           content.append("v=0\r\n");
           content.append("o="+sipConfig.getSipId()+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n");
           content.append("o="+sipConfig.getId()+" 0 0 IN IP4 " + mediaServerItem.getSdpIp() + "\r\n");
           content.append("s=Playback\r\n");
           content.append("u="+channelId+":0\r\n");
           content.append("c=IN IP4 "+mediaInfo.getWanIp()+"\r\n");
           content.append("c=IN IP4 "+mediaServerItem.getSdpIp()+"\r\n");
           content.append("t="+DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(startTime)+" "
               +DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(endTime) +"\r\n");
         String mediaPort = null;
         // 使用动态udp端口
         if (rtpEnable) {
            mediaPort = zlmrtpServerFactory.createRTPServer(streamId) + "";
         }else {
            mediaPort = mediaInfo.getRtpProxyPort();
         }
         String streamMode = device.getStreamMode().toUpperCase();
         if (seniorSdp) {
         if (userSetup.isSeniorSdp()) {
            if("TCP-PASSIVE".equals(streamMode)) {
               content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
               content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
            }else if ("TCP-ACTIVE".equals(streamMode)) {
               content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
               content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
            }else if("UDP".equals(streamMode)) {
               content.append("m=video "+ mediaPort +" RTP/AVP 96 126 125 99 34 98 97\r\n");
               content.append("m=video "+ ssrcInfo.getPort() +" RTP/AVP 96 126 125 99 34 98 97\r\n");
            }
            content.append("a=recvonly\r\n");
            content.append("a=rtpmap:96 PS/90000\r\n");
@@ -526,11 +497,11 @@
            }
         }else {
            if("TCP-PASSIVE".equals(streamMode)) {
               content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
               content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 98 97\r\n");
            }else if ("TCP-ACTIVE".equals(streamMode)) {
               content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
               content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 98 97\r\n");
            }else if("UDP".equals(streamMode)) {
               content.append("m=video "+ mediaPort +" RTP/AVP 96 98 97\r\n");
               content.append("m=video "+ ssrcInfo.getPort() +" RTP/AVP 96 98 97\r\n");
            }
            content.append("a=recvonly\r\n");
            content.append("a=rtpmap:96 PS/90000\r\n");
@@ -545,62 +516,182 @@
            }
         }
           content.append("y="+ssrc+"\r\n");//ssrc
           content.append("y=" + ssrcInfo.getSsrc() + "\r\n");//ssrc
           
         String tm = Long.toString(System.currentTimeMillis());
         CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
               : udpSipProvider.getNewCallId();
           Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "fromplybck" + tm, null, callIdHeader);
           Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "fromplybck" + tm, null, callIdHeader, ssrcInfo.getSsrc());
           transmitRequest(device, request, errorEvent, okEvent -> {
            ResponseEvent responseEvent = (ResponseEvent) okEvent.event;
              streamSession.put(device.getDeviceId(), channelId, ssrcInfo.getSsrc(), ssrcInfo.getStreamId(), mediaServerItem.getId(), responseEvent.getClientTransaction());
            streamSession.put(device.getDeviceId(), channelId, okEvent.dialog);
         });
      } catch ( SipException | ParseException | InvalidArgumentException e) {
         e.printStackTrace();
      }
   }
   /**
    * 请求历史媒体下载
    *
    * @param device  视频设备
    * @param channelId  预览通道
    * @param startTime 开始时间,格式要求:yyyy-MM-dd HH:mm:ss
    * @param endTime 结束时间,格式要求:yyyy-MM-dd HH:mm:ss
    * @param downloadSpeed 下载倍速参数
    */
   @Override
   public void downloadStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId, String startTime, String endTime, String downloadSpeed, ZLMHttpHookSubscribe.Event event
         , SipSubscribe.Event errorEvent) {
      try {
         logger.info("{} 分配的ZLM为: {} [{}:{}]", ssrcInfo.getStreamId(), mediaServerItem.getId(), mediaServerItem.getIp(), ssrcInfo.getPort());
         // 添加订阅
         JSONObject subscribeKey = new JSONObject();
         subscribeKey.put("app", "rtp");
         subscribeKey.put("stream", ssrcInfo.getStreamId());
         subscribeKey.put("regist", true);
         subscribeKey.put("mediaServerId", mediaServerItem.getId());
         logger.debug("录像回放添加订阅,订阅内容:" + subscribeKey.toString());
         subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey,
               (MediaServerItem mediaServerItemInUse, JSONObject json)->{
            if (userSetup.isWaitTrack() && json.getJSONArray("tracks") == null) return;
            event.response(mediaServerItemInUse, json);
            subscribe.removeSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey);
         });
         StringBuffer content = new StringBuffer(200);
           content.append("v=0\r\n");
           content.append("o="+sipConfig.getId()+" 0 0 IN IP4 " + mediaServerItem.getSdpIp() + "\r\n");
           content.append("s=Download\r\n");
           content.append("u="+channelId+":0\r\n");
           content.append("c=IN IP4 "+mediaServerItem.getSdpIp()+"\r\n");
           content.append("t="+DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(startTime)+" "
               +DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(endTime) +"\r\n");
         String streamMode = device.getStreamMode().toUpperCase();
         if (userSetup.isSeniorSdp()) {
            if("TCP-PASSIVE".equals(streamMode)) {
               content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
            }else if ("TCP-ACTIVE".equals(streamMode)) {
               content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
            }else if("UDP".equals(streamMode)) {
               content.append("m=video "+ ssrcInfo.getPort() +" RTP/AVP 96 126 125 99 34 98 97\r\n");
            }
            content.append("a=recvonly\r\n");
            content.append("a=rtpmap:96 PS/90000\r\n");
            content.append("a=fmtp:126 profile-level-id=42e01e\r\n");
            content.append("a=rtpmap:126 H264/90000\r\n");
            content.append("a=rtpmap:125 H264S/90000\r\n");
            content.append("a=fmtp:125 profile-level-id=42e01e\r\n");
            content.append("a=rtpmap:99 MP4V-ES/90000\r\n");
            content.append("a=fmtp:99 profile-level-id=3\r\n");
            content.append("a=rtpmap:98 H264/90000\r\n");
            content.append("a=rtpmap:97 MPEG4/90000\r\n");
            if("TCP-PASSIVE".equals(streamMode)){ // tcp被动模式
               content.append("a=setup:passive\r\n");
               content.append("a=connection:new\r\n");
            }else if ("TCP-ACTIVE".equals(streamMode)) { // tcp主动模式
               content.append("a=setup:active\r\n");
               content.append("a=connection:new\r\n");
            }
         }else {
            if("TCP-PASSIVE".equals(streamMode)) {
               content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 98 97\r\n");
            }else if ("TCP-ACTIVE".equals(streamMode)) {
               content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 98 97\r\n");
            }else if("UDP".equals(streamMode)) {
               content.append("m=video "+ ssrcInfo.getPort() +" RTP/AVP 96 98 97\r\n");
            }
            content.append("a=recvonly\r\n");
            content.append("a=rtpmap:96 PS/90000\r\n");
            content.append("a=rtpmap:98 H264/90000\r\n");
            content.append("a=rtpmap:97 MPEG4/90000\r\n");
            if("TCP-PASSIVE".equals(streamMode)){ // tcp被动模式
               content.append("a=setup:passive\r\n");
               content.append("a=connection:new\r\n");
            }else if ("TCP-ACTIVE".equals(streamMode)) { // tcp主动模式
               content.append("a=setup:active\r\n");
               content.append("a=connection:new\r\n");
            }
         }
         content.append("a=downloadspeed:" + downloadSpeed + "\r\n");
           content.append("y=" + ssrcInfo.getSsrc() + "\r\n");//ssrc
         String tm = Long.toString(System.currentTimeMillis());
         CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
               : udpSipProvider.getNewCallId();
           Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "fromplybck" + tm, null, callIdHeader, ssrcInfo.getSsrc());
           ClientTransaction transaction = transmitRequest(device, request, errorEvent);
           streamSession.put(device.getDeviceId(), channelId, ssrc, streamId, transaction);
           streamSession.put(device.getDeviceId(), channelId, ssrcInfo.getSsrc(), ssrcInfo.getStreamId(), mediaServerItem.getId(), transaction);
      } catch ( SipException | ParseException | InvalidArgumentException e) {
         e.printStackTrace();
      }
   }
   /**
    * 视频流停止
    *
    * 视频流停止, 不使用回调
    */
   @Override
   public void streamByeCmd(String deviceId, String channelId) {
      streamByeCmd(deviceId, channelId, null);
   }
   /**
    * 视频流停止
    */
   @Override
   public void streamByeCmd(String deviceId, String channelId, SipSubscribe.Event okEvent) {
      try {
         ClientTransaction transaction = streamSession.getTransaction(deviceId, channelId);
         // 服务重启后
         if (transaction == null) {
            StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
            if (streamInfo != null) {
            logger.warn("[ {} -> {}]停止视频流的时候发现事务已丢失", deviceId, channelId);
            SipSubscribe.EventResult<Object> eventResult = new SipSubscribe.EventResult<>();
            if (okEvent != null) {
               okEvent.response(eventResult);
            }
            return;
         }
         Dialog dialog = transaction.getDialog();
         SIPDialog dialog = streamSession.getDialog(deviceId, channelId);
         if (dialog == null) {
            logger.warn("[ {} -> {}]停止视频流的时候发现对话已丢失", deviceId, channelId);
            return;
         }
         SipStack sipStack = udpSipProvider.getSipStack();
         SIPDialog sipDialog = ((SipStackImpl) sipStack).putDialog(dialog);
         if (dialog != sipDialog) {
            dialog = sipDialog;
         }else {
            dialog.setSipProvider(udpSipProvider);
            try {
               Field sipStackField = SIPDialog.class.getDeclaredField("sipStack");
               sipStackField.setAccessible(true);
               sipStackField.set(dialog, sipStack);
               Field eventListenersField = SIPDialog.class.getDeclaredField("eventListeners");
               eventListenersField.setAccessible(true);
               eventListenersField.set(dialog, new HashSet<>());
            } catch (NoSuchFieldException | IllegalAccessException e) {
               e.printStackTrace();
            }
         }
         Request byeRequest = dialog.createRequest(Request.BYE);
         SipURI byeURI = (SipURI) byeRequest.getRequestURI();
         String vh = transaction.getRequest().getHeader(ViaHeader.NAME).toString();
         Pattern p = Pattern.compile("(\\d+\\.\\d+\\.\\d+\\.\\d+)\\:(\\d+)");
         Matcher matcher = p.matcher(vh);
         if (matcher.find()) {
            String ip = matcher.group(1);
            byeURI.setHost(ip);
            String port = matcher.group(2);
            byeURI.setPort(Integer.parseInt(port));
         }
         SIPRequest request = (SIPRequest)transaction.getRequest();
         byeURI.setHost(request.getRemoteAddress().getHostName());
         byeURI.setPort(request.getRemotePort());
         ViaHeader viaHeader = (ViaHeader) byeRequest.getHeader(ViaHeader.NAME);
         String protocol = viaHeader.getTransport().toUpperCase();
         ClientTransaction clientTransaction = null;
@@ -616,8 +707,13 @@
         }
         dialog.sendRequest(clientTransaction);
         zlmrtpServerFactory.closeRTPServer(streamSession.getStreamId(deviceId, channelId));
         streamSession.remove(deviceId, channelId);
         SsrcTransaction ssrcTransaction = streamSession.getSsrcTransaction(deviceId, channelId);
         if (ssrcTransaction != null) {
            MediaServerItem mediaServerItem = mediaServerService.getOne(ssrcTransaction.getMediaServerId());
            mediaServerService.releaseSsrc(mediaServerItem, ssrcTransaction.getSsrc());
            streamSession.remove(deviceId, channelId);
         }
      } catch (SipException | ParseException e) {
         e.printStackTrace();
      }
@@ -648,7 +744,7 @@
         broadcastXml.append("<Notify>\r\n");
         broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n");
         broadcastXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         broadcastXml.append("<SourceID>" + sipConfig.getSipId() + "</SourceID>\r\n");
         broadcastXml.append("<SourceID>" + sipConfig.getId() + "</SourceID>\r\n");
         broadcastXml.append("<TargetID>" + device.getDeviceId() + "</TargetID>\r\n");
         broadcastXml.append("</Notify>\r\n");
         
@@ -673,7 +769,7 @@
         broadcastXml.append("<Notify>\r\n");
         broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n");
         broadcastXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         broadcastXml.append("<SourceID>" + sipConfig.getSipId() + "</SourceID>\r\n");
         broadcastXml.append("<SourceID>" + sipConfig.getId() + "</SourceID>\r\n");
         broadcastXml.append("<TargetID>" + device.getDeviceId() + "</TargetID>\r\n");
         broadcastXml.append("</Notify>\r\n");
         
@@ -705,7 +801,7 @@
         cmdXml.append("<Control>\r\n");
         cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
         cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         if (XmlUtil.isEmpty(channelId)) {
         if (StringUtils.isEmpty(channelId)) {
            cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         } else {
            cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
@@ -805,16 +901,16 @@
         cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         cmdXml.append("<AlarmCmd>ResetAlarm</AlarmCmd>\r\n");
         if (!XmlUtil.isEmpty(alarmMethod) || !XmlUtil.isEmpty(alarmType)) {
         if (!StringUtils.isEmpty(alarmMethod) || !StringUtils.isEmpty(alarmType)) {
            cmdXml.append("<Info>\r\n");
         }
         if (!XmlUtil.isEmpty(alarmMethod)) {
         if (!StringUtils.isEmpty(alarmMethod)) {
            cmdXml.append("<AlarmMethod>" + alarmMethod + "</AlarmMethod>\r\n");
         }
         if (!XmlUtil.isEmpty(alarmType)) {
         if (!StringUtils.isEmpty(alarmType)) {
            cmdXml.append("<AlarmType>" + alarmType + "</AlarmType>\r\n");
         }
         if (!XmlUtil.isEmpty(alarmMethod) || !XmlUtil.isEmpty(alarmType)) {
         if (!StringUtils.isEmpty(alarmMethod) || !StringUtils.isEmpty(alarmType)) {
            cmdXml.append("</Info>\r\n");
         }
         cmdXml.append("</Control>\r\n");
@@ -847,7 +943,7 @@
         cmdXml.append("<Control>\r\n");
         cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
         cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         if (XmlUtil.isEmpty(channelId)) {
         if (StringUtils.isEmpty(channelId)) {
            cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         } else {
            cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
@@ -885,7 +981,7 @@
         cmdXml.append("<Control>\r\n");
         cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
         cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         if (XmlUtil.isEmpty(channelId)) {
         if (StringUtils.isEmpty(channelId)) {
            cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         } else {
            cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
@@ -953,13 +1049,13 @@
         cmdXml.append("<Control>\r\n");
         cmdXml.append("<CmdType>DeviceConfig</CmdType>\r\n");
         cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         if (XmlUtil.isEmpty(channelId)) {
         if (StringUtils.isEmpty(channelId)) {
            cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         } else {
            cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
         }
         cmdXml.append("<BasicParam>\r\n");
         if (!XmlUtil.isEmpty(name)) {
         if (!StringUtils.isEmpty(name)) {
            cmdXml.append("<Name>" + name + "</Name>\r\n");
         }
         if (NumericUtil.isInteger(expiration)) {
@@ -1066,7 +1162,7 @@
   @Override
   public boolean catalogQuery(Device device, SipSubscribe.Event errorEvent) {
      // 清空通道
      storager.cleanChannelsForDevice(device.getDeviceId());
//      storager.cleanChannelsForDevice(device.getDeviceId());
      try {
         StringBuffer catalogXml = new StringBuffer(200);
         catalogXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
@@ -1099,14 +1195,15 @@
    * @param endTime 结束时间,格式要求:yyyy-MM-dd HH:mm:ss
    */  
   @Override
   public boolean recordInfoQuery(Device device, String channelId, String startTime, String endTime) {
   public boolean recordInfoQuery(Device device, String channelId, String startTime, String endTime, int sn, SipSubscribe.Event errorEvent) {
      try {
         StringBuffer recordInfoXml = new StringBuffer(200);
         recordInfoXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
         recordInfoXml.append("<Query>\r\n");
         recordInfoXml.append("<CmdType>RecordInfo</CmdType>\r\n");
         recordInfoXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         recordInfoXml.append("<SN>" + sn + "</SN>\r\n");
         recordInfoXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
         recordInfoXml.append("<StartTime>" + DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(startTime) + "</StartTime>\r\n");
         recordInfoXml.append("<EndTime>" + DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(endTime) + "</EndTime>\r\n");
@@ -1123,7 +1220,7 @@
         Request request = headerProvider.createMessageRequest(device, recordInfoXml.toString(),
               "z9hG4bK-ViaRecordInfo-" + tm, "fromRec" + tm, null, callIdHeader);
         transmitRequest(device, request);
         transmitRequest(device, request, errorEvent);
      } catch (SipException | ParseException | InvalidArgumentException e) {
         e.printStackTrace();
         return false;
@@ -1153,22 +1250,22 @@
         cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
         cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         if (!XmlUtil.isEmpty(startPriority)) {
         if (!StringUtils.isEmpty(startPriority)) {
            cmdXml.append("<StartAlarmPriority>" + startPriority + "</StartAlarmPriority>\r\n");
         }
         if (!XmlUtil.isEmpty(endPriority)) {
         if (!StringUtils.isEmpty(endPriority)) {
            cmdXml.append("<EndAlarmPriority>" + endPriority + "</EndAlarmPriority>\r\n");
         }
         if (!XmlUtil.isEmpty(alarmMethod)) {
         if (!StringUtils.isEmpty(alarmMethod)) {
            cmdXml.append("<AlarmMethod>" + alarmMethod + "</AlarmMethod>\r\n");
         }
         if (!XmlUtil.isEmpty(alarmType)) {
         if (!StringUtils.isEmpty(alarmType)) {
            cmdXml.append("<AlarmType>" + alarmType + "</AlarmType>\r\n");
         }
         if (!XmlUtil.isEmpty(startTime)) {
         if (!StringUtils.isEmpty(startTime)) {
            cmdXml.append("<StartAlarmTime>" + startTime + "</StartAlarmTime>\r\n");
         }
         if (!XmlUtil.isEmpty(endTime)) {
         if (!StringUtils.isEmpty(endTime)) {
            cmdXml.append("<EndAlarmTime>" + endTime + "</EndAlarmTime>\r\n");
         }
         cmdXml.append("</Query>\r\n");
@@ -1202,7 +1299,7 @@
         cmdXml.append("<Query>\r\n");
         cmdXml.append("<CmdType>ConfigDownload</CmdType>\r\n");
         cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         if (XmlUtil.isEmpty(channelId)) {
         if (StringUtils.isEmpty(channelId)) {
            cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         } else {
            cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
@@ -1237,7 +1334,7 @@
         cmdXml.append("<Query>\r\n");
         cmdXml.append("<CmdType>PresetQuery</CmdType>\r\n");
         cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         if (XmlUtil.isEmpty(channelId)) {
         if (StringUtils.isEmpty(channelId)) {
            cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         } else {
            cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
@@ -1349,22 +1446,22 @@
         cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
         cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         if (!XmlUtil.isEmpty(startPriority)) {
         if (!StringUtils.isEmpty(startPriority)) {
            cmdXml.append("<StartAlarmPriority>" + startPriority + "</StartAlarmPriority>\r\n");
         }
         if (!XmlUtil.isEmpty(endPriority)) {
         if (!StringUtils.isEmpty(endPriority)) {
            cmdXml.append("<EndAlarmPriority>" + endPriority + "</EndAlarmPriority>\r\n");
         }
         if (!XmlUtil.isEmpty(alarmMethod)) {
         if (!StringUtils.isEmpty(alarmMethod)) {
            cmdXml.append("<AlarmMethod>" + alarmMethod + "</AlarmMethod>\r\n");
         }
         if (!XmlUtil.isEmpty(alarmType)) {
         if (!StringUtils.isEmpty(alarmType)) {
            cmdXml.append("<AlarmType>" + alarmType + "</AlarmType>\r\n");
         }
         if (!XmlUtil.isEmpty(startTime)) {
         if (!StringUtils.isEmpty(startTime)) {
            cmdXml.append("<StartAlarmTime>" + startTime + "</StartAlarmTime>\r\n");
         }
         if (!XmlUtil.isEmpty(endTime)) {
         if (!StringUtils.isEmpty(endTime)) {
            cmdXml.append("<EndAlarmTime>" + endTime + "</EndAlarmTime>\r\n");
         }
         cmdXml.append("</Query>\r\n");
@@ -1383,6 +1480,64 @@
         e.printStackTrace();
         return false;
      }
   }
   @Override
   public boolean catalogSubscribe(Device device, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) {
      try {
         StringBuffer cmdXml = new StringBuffer(200);
         cmdXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
         cmdXml.append("<Query>\r\n");
         cmdXml.append("<CmdType>Catalog</CmdType>\r\n");
         cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         cmdXml.append("</Query>\r\n");
         String tm = Long.toString(System.currentTimeMillis());
         CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
               : udpSipProvider.getNewCallId();
         // 有效时间默认为60秒以上
         Request request = headerProvider.createSubscribeRequest(device, cmdXml.toString(), "z9hG4bK-viaPos-" + tm,
               "fromTagPos" + tm, null, device.getSubscribeCycleForCatalog() + 60, "Catalog" ,
               callIdHeader);
         transmitRequest(device, request, errorEvent, okEvent);
         return true;
      } catch ( NumberFormatException | ParseException | InvalidArgumentException   | SipException e) {
         e.printStackTrace();
         return false;
      }
   }
   @Override
   public boolean dragZoomCmd(Device device, String channelId, String cmdString) {
      try {
         StringBuffer dragXml = new StringBuffer(200);
         dragXml.append("<?xml version=\"1.0\" ?>\r\n");
         dragXml.append("<Control>\r\n");
         dragXml.append("<CmdType>DeviceControl</CmdType>\r\n");
         dragXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
         if (StringUtils.isEmpty(channelId)) {
            dragXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         } else {
            dragXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
         }
         dragXml.append(cmdString);
         dragXml.append("</Control>\r\n");
         String tm = Long.toString(System.currentTimeMillis());
         CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
               : udpSipProvider.getNewCallId();
         Request request = headerProvider.createMessageRequest(device, dragXml.toString(), "z9hG4bK-ViaPtz-" + tm, "FromPtz" + tm, null, callIdHeader);
         logger.debug("拉框信令: " + request.toString());
         transmitRequest(device, request);
         return true;
      } catch (SipException | ParseException | InvalidArgumentException e) {
         e.printStackTrace();
      }
      return false;
   }
@@ -1405,26 +1560,136 @@
      CallIdHeader callIdHeader = (CallIdHeader)request.getHeader(CallIdHeader.NAME);
      // 添加错误订阅
      if (errorEvent != null) {
         sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), errorEvent);
         sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), (eventResult -> {
            errorEvent.response(eventResult);
            sipSubscribe.removeErrorSubscribe(eventResult.callId);
         }));
      }
      // 添加订阅
      if (okEvent != null) {
         sipSubscribe.addOkSubscribe(callIdHeader.getCallId(), okEvent);
         sipSubscribe.addOkSubscribe(callIdHeader.getCallId(), eventResult ->{
            okEvent.response(eventResult);
            sipSubscribe.removeOkSubscribe(eventResult.callId);
         });
      }
      clientTransaction.sendRequest();
      return clientTransaction;
   }
   /**
    * 回放暂停
    */
   @Override
   public void closeRTPServer(Device device, String channelId) {
      if (rtpEnable) {
         String streamId = String.format("gb_play_%s_%s", device.getDeviceId(), channelId);
         zlmrtpServerFactory.closeRTPServer(streamId);
   public void playPauseCmd(Device device, StreamInfo streamInfo) {
      try {
         Long cseq = redisCatchStorage.getCSEQ(Request.INFO);
         StringBuffer content = new StringBuffer(200);
         content.append("PAUSE RTSP/1.0\r\n");
         content.append("CSeq: " + cseq + "\r\n");
         content.append("PauseTime: now\r\n");
         Request request = headerProvider.createInfoRequest(device, streamInfo, content.toString(), cseq);
         if (request == null) {
            return;
         }
         logger.info(request.toString());
         ClientTransaction clientTransaction = null;
         if ("TCP".equals(device.getTransport())) {
            clientTransaction = tcpSipProvider.getNewClientTransaction(request);
         } else if ("UDP".equals(device.getTransport())) {
            clientTransaction = udpSipProvider.getNewClientTransaction(request);
         }
         if (clientTransaction != null) {
            clientTransaction.sendRequest();
         }
      } catch (SipException | ParseException | InvalidArgumentException e) {
         e.printStackTrace();
      }
      streamSession.remove(device.getDeviceId(), channelId);
   }
   /**
    * 回放恢复
    */
   @Override
   public void playResumeCmd(Device device, StreamInfo streamInfo) {
      try {
         Long cseq = redisCatchStorage.getCSEQ(Request.INFO);
         StringBuffer content = new StringBuffer(200);
         content.append("PLAY RTSP/1.0\r\n");
         content.append("CSeq: " + cseq + "\r\n");
         content.append("Range: npt=now-\r\n");
         Request request = headerProvider.createInfoRequest(device, streamInfo, content.toString(), cseq);
         if (request == null) return;
         logger.info(request.toString());
         ClientTransaction clientTransaction = null;
         if ("TCP".equals(device.getTransport())) {
            clientTransaction = tcpSipProvider.getNewClientTransaction(request);
         } else if ("UDP".equals(device.getTransport())) {
            clientTransaction = udpSipProvider.getNewClientTransaction(request);
         }
         clientTransaction.sendRequest();
      } catch (SipException | ParseException | InvalidArgumentException e) {
         e.printStackTrace();
      }
   }
   /**
    * 回放拖动播放
    */
   @Override
   public void playSeekCmd(Device device, StreamInfo streamInfo, long seekTime) {
      try {
         Long cseq = redisCatchStorage.getCSEQ(Request.INFO);
         StringBuffer content = new StringBuffer(200);
         content.append("PLAY RTSP/1.0\r\n");
         content.append("CSeq: " + cseq + "\r\n");
         content.append("Range: npt=" + Math.abs(seekTime) + "-\r\n");
         Request request = headerProvider.createInfoRequest(device, streamInfo, content.toString(), cseq);
         if (request == null) return;
         logger.info(request.toString());
         ClientTransaction clientTransaction = null;
         if ("TCP".equals(device.getTransport())) {
            clientTransaction = tcpSipProvider.getNewClientTransaction(request);
         } else if ("UDP".equals(device.getTransport())) {
            clientTransaction = udpSipProvider.getNewClientTransaction(request);
         }
         clientTransaction.sendRequest();
      } catch (SipException | ParseException | InvalidArgumentException e) {
         e.printStackTrace();
      }
   }
   /**
    * 回放倍速播放
    */
   @Override
   public void playSpeedCmd(Device device, StreamInfo streamInfo, Double speed) {
      try {
         Long cseq = redisCatchStorage.getCSEQ(Request.INFO);
         StringBuffer content = new StringBuffer(200);
         content.append("PLAY RTSP/1.0\r\n");
         content.append("CSeq: " + cseq + "\r\n");
         content.append("Scale: " + String.format("%.1f",speed) + "\r\n");
         Request request = headerProvider.createInfoRequest(device, streamInfo, content.toString(), cseq);
         if (request == null) return;
         logger.info(request.toString());
         ClientTransaction clientTransaction = null;
         if ("TCP".equals(device.getTransport())) {
            clientTransaction = tcpSipProvider.getNewClientTransaction(request);
         } else if ("UDP".equals(device.getTransport())) {
            clientTransaction = udpSipProvider.getNewClientTransaction(request);
         }
         clientTransaction.sendRequest();
      } catch (SipException | ParseException | InvalidArgumentException e) {
         e.printStackTrace();
      }
   }
}