648540858
2022-09-09 221f99c764b51c3cd284c6e5a41492c26c5c7ffc
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java
@@ -2,7 +2,6 @@
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import javax.sip.*;
import javax.sip.address.Address;
@@ -12,6 +11,7 @@
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import gov.nist.javax.sip.SipProviderImpl;
import gov.nist.javax.sip.SipStackImpl;
@@ -61,19 +61,18 @@
      viaHeader.setRPort();
      viaHeaders.add(viaHeader);
      // from
      SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(),
            sipConfig.getIp() + ":" + sipConfig.getPort());
      SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getDomain());
      Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
      FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag);
      // to
      SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), sipConfig.getDomain());
      SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress());
      Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
      ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag);
      // Forwards
      MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
      // ceq
      CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(1L, Request.MESSAGE);
      CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(), Request.MESSAGE);
      request = sipFactory.createMessageFactory().createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader,
            toHeader, viaHeaders, maxForwards);
@@ -93,11 +92,11 @@
      viaHeaders.add(viaHeader);
      //from
      SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(),sipConfig.getDomain());
      SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getDomain());
      Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
      FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack
      //to
      SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId,sipConfig.getDomain());
      SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId, device.getHostAddress());
      Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
      ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,null);
      
@@ -129,11 +128,11 @@
      viaHeader.setRPort();
      viaHeaders.add(viaHeader);
      //from
      SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(),sipConfig.getDomain());
      SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getDomain());
      Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
      FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack
      //to
      SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId, sipConfig.getDomain());
      SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId, device.getHostAddress());
      Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
      ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,null);
      
@@ -169,7 +168,7 @@
      Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
      FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack
      //to
      SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId,sipConfig.getDomain());
      SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId,device.getHostAddress());
      Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
      ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,toTag);
@@ -177,7 +176,7 @@
      MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
      //ceq
      CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(1L, Request.BYE);
      CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(), Request.BYE);
      CallIdHeader callIdHeader = sipFactory.createHeaderFactory().createCallIdHeader(callId);
      request = sipFactory.createMessageFactory().createRequest(requestLine, Request.BYE, callIdHeader, cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards);
@@ -197,12 +196,11 @@
      viaHeader.setRPort();
      viaHeaders.add(viaHeader);
      // from
      SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(),
            sipConfig.getIp() + ":" + sipConfig.getPort());
      SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getDomain());
      Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
      FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag);
      // to
      SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), sipConfig.getDomain());
      SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress());
      Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
      ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag);
@@ -266,15 +264,7 @@
      Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory()
            .createSipURI(sipConfig.getId(), sipConfig.getIp() + ":" + sipConfig.getPort()));
      infoRequest.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
      List<String> agentParam = new ArrayList<>();
      agentParam.add("wvp-pro");
      // TODO 添加版本信息以及日期
      UserAgentHeader userAgentHeader = null;
      try {
         userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam);
      } catch (ParseException e) {
         throw new RuntimeException(e);
      }
      UserAgentHeader userAgentHeader = SipUtils.createUserAgentHeader(sipFactory);
      infoRequest.addHeader(userAgentHeader);
      ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application",