648540858
2021-12-20 22efd0f56c20e1aedb18fa7b9bcdc48007fcc954
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
@@ -1,6 +1,7 @@
package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl;
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;
@@ -261,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);
         logger.info("控制字符串:" + cmdStr);
         logger.debug("控制字符串:" + cmdStr);
         StringBuffer ptzXml = new StringBuffer(200);
         ptzXml.append("<?xml version=\"1.0\" ?>\r\n");
         ptzXml.append("<Control>\r\n");
@@ -1161,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");
@@ -1194,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");
@@ -1218,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;
@@ -1496,7 +1498,7 @@
         CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
               : udpSipProvider.getNewCallId();
         Request request = headerProvider.createSubscribeRequest(device, cmdXml.toString(), "z9hG4bK-viaPos-" + tm, "fromTagPos" + tm, null, device.getSubscribeCycleForCatalog(), "presence" , callIdHeader);
         Request request = headerProvider.createSubscribeRequest(device, cmdXml.toString(), "z9hG4bK-viaPos-" + tm, "fromTagPos" + tm, null, device.getSubscribeCycleForCatalog(), "Catalog" , callIdHeader);
         transmitRequest(device, request, errorEvent, okEvent);
         return true;
@@ -1543,4 +1545,114 @@
      clientTransaction.sendRequest();
      return clientTransaction;
   }
   /**
    * 回放暂停
    */
   @Override
   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);
         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();
      }
   }
   /**
    * 回放恢复
    */
   @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);
         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);
         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);
         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();
      }
   }
}