64850858
2021-07-16 89a9ab4534f10a224f70e546db838423e84a1965
src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java
@@ -16,7 +16,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;
@@ -73,7 +72,7 @@
   private SipStack createSipStack() throws PeerUnavailableException {
      Properties properties = new Properties();
      properties.setProperty("javax.sip.STACK_NAME", "GB28181_SIP");
      properties.setProperty("javax.sip.IP_ADDRESS", sipConfig.getSipIp());
      properties.setProperty("javax.sip.IP_ADDRESS", sipConfig.getMonitorIp());
      properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "false");
      /**
       * sip_server_log.log 和 sip_debug_log.log public static final int TRACE_NONE =
@@ -93,23 +92,46 @@
      ListeningPoint tcpListeningPoint = null;
      SipProvider tcpSipProvider  = null;
      try {
         tcpListeningPoint = sipStack.createListeningPoint(sipConfig.getSipIp(), sipConfig.getSipPort(), "TCP");
         tcpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getSipPort(), "TCP");
         tcpSipProvider = sipStack.createSipProvider(tcpListeningPoint);
         tcpSipProvider.addSipListener(this);
         logger.info("Sip Server TCP 启动成功 port {" + sipConfig.getSipPort() + "}");
      } catch (TransportNotSupportedException | InvalidArgumentException | TooManyListenersException | ObjectInUseException e) {
         logger.error(String.format("创建SIP服务失败: %s", e.getMessage()));
         logger.info("Sip Server TCP 启动成功 port {" + sipConfig.getMonitorIp() + ":" + sipConfig.getSipPort() + "}");
//      } catch (TransportNotSupportedException | InvalidArgumentException | TooManyListenersException | ObjectInUseException e) {
//         logger.error(String.format("创建SIP服务失败: %s", e.getMessage()));
//      }
      } catch (TransportNotSupportedException e) {
         e.printStackTrace();
      } catch (InvalidArgumentException e) {
         logger.error("无法使用 [ {}:{} ]作为SIP[ TCP ]服务,可排查: 1. sip.monitor-ip 是否为本机网卡IP; 2. sip.port 是否已被占用"
               , sipConfig.getMonitorIp(), sipConfig.getSipPort());
      } catch (TooManyListenersException e) {
         e.printStackTrace();
      } catch (ObjectInUseException e) {
         e.printStackTrace();
      }
      return tcpSipProvider;
   }
   
   @Bean("udpSipProvider")
   @DependsOn("sipStack")
   private SipProvider startUdpListener() throws Exception {
      ListeningPoint udpListeningPoint = sipStack.createListeningPoint(sipConfig.getSipIp(), sipConfig.getSipPort(), "UDP");
      SipProvider udpSipProvider = sipStack.createSipProvider(udpListeningPoint);
      udpSipProvider.addSipListener(this);
      logger.info("Sip Server UDP 启动成功 port {" + sipConfig.getSipPort() + "}");
   private SipProvider startUdpListener() {
      ListeningPoint udpListeningPoint = null;
      SipProvider udpSipProvider = null;
      try {
         udpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getSipPort(), "UDP");
         udpSipProvider = sipStack.createSipProvider(udpListeningPoint);
         udpSipProvider.addSipListener(this);
      } catch (TransportNotSupportedException e) {
         e.printStackTrace();
      } catch (InvalidArgumentException e) {
         logger.error("无法使用 [ {}:{} ]作为SIP[ UDP ]服务,可排查: 1. sip.monitor-ip 是否为本机网卡IP; 2. sip.port 是否已被占用"
               , sipConfig.getMonitorIp(), sipConfig.getSipPort());
      } catch (TooManyListenersException e) {
         e.printStackTrace();
      } catch (ObjectInUseException e) {
         e.printStackTrace();
      }
      logger.info("Sip Server UDP 启动成功 port [" + sipConfig.getMonitorIp() + ":" + sipConfig.getSipPort() + "]");
      return udpSipProvider;
   }
@@ -119,7 +141,7 @@
    */
   @Override
   public void processRequest(RequestEvent evt) {
      logger.debug(evt.getRequest().toString());
//      logger.debug(evt.getRequest().toString());
      // 由于jainsip是单线程程序,为提高性能并发处理
      processThreadPool.execute(() -> {
         if (processorFactory != null) {
@@ -131,7 +153,7 @@
   @Override
   public void processResponse(ResponseEvent evt) {
      Response response = evt.getResponse();
      logger.debug(evt.getResponse().toString());
//      logger.debug(evt.getResponse().toString());
      int status = response.getStatusCode();
      if (((status >= 200) && (status < 300)) || status == 401) { // Success!
         ISIPResponseProcessor processor = processorFactory.createResponseProcessor(evt);