648540858
2022-10-18 1af77ab5f7c11a4b3d59c1989b51b9fca29679ce
src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java
@@ -1,6 +1,7 @@
package com.genersoft.iot.vmp.gb28181;
import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.gb28181.conf.DefaultProperties;
import com.genersoft.iot.vmp.gb28181.transmit.ISIPProcessorObserver;
import gov.nist.javax.sip.SipProviderImpl;
import gov.nist.javax.sip.SipStackImpl;
@@ -10,14 +11,10 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;
import javax.sip.*;
import java.util.Properties;
import java.util.TooManyListenersException;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Configuration
public class SipLayer{
@@ -44,34 +41,8 @@
   
   @Bean("sipStack")
   @DependsOn({"sipFactory"})
   SipStack createSipStack() throws PeerUnavailableException {
      Properties properties = new Properties();
      properties.setProperty("javax.sip.STACK_NAME", "GB28181_SIP");
      properties.setProperty("javax.sip.IP_ADDRESS", sipConfig.getMonitorIp());
      /**
       * 完整配置参考 gov.nist.javax.sip.SipStackImpl,需要下载源码
       * gov/nist/javax/sip/SipStackImpl.class
       */
      properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "true");
      // 接收所有notify请求,即使没有订阅
      properties.setProperty("gov.nist.javax.sip.DELIVER_UNSOLICITED_NOTIFY", "true");
      // 为_NULL _对话框传递_终止的_事件
      properties.setProperty("gov.nist.javax.sip.DELIVER_TERMINATED_EVENT_FOR_NULL_DIALOG", "true");
      // 会话清理策略
      properties.setProperty("gov.nist.javax.sip.RELEASE_REFERENCES_STRATEGY", "Normal");
      // 处理由该服务器处理的基于底层TCP的保持生存超时
      properties.setProperty("gov.nist.javax.sip.RELIABLE_CONNECTION_KEEP_ALIVE_TIMEOUT", "60");
      /**
       * sip_server_log.log 和 sip_debug_log.log public static final int TRACE_NONE =
       * 0; public static final int TRACE_MESSAGES = 16; public static final int
       * TRACE_EXCEPTION = 17; public static final int TRACE_DEBUG = 32;
       */
      properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "0");
      properties.setProperty("gov.nist.javax.sip.SERVER_LOG", "sip_server_log");
      properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", "sip_debug_log");
      sipStack = (SipStackImpl) sipFactory.createSipStack(properties);
   SipStackImpl createSipStack() throws PeerUnavailableException {
      sipStack = ( SipStackImpl )sipFactory.createSipStack(DefaultProperties.getProperties(sipConfig.getMonitorIp(), false));
      return sipStack;
   }
@@ -85,7 +56,6 @@
         tcpSipProvider = (SipProviderImpl)sipStack.createSipProvider(tcpListeningPoint);
         tcpSipProvider.setDialogErrorsAutomaticallyHandled();
         tcpSipProvider.addSipListener(sipProcessorObserver);
//         tcpSipProvider.setAutomaticDialogSupportEnabled(false);
         logger.info("[Sip Server] TCP 启动成功 {}:{}", sipConfig.getMonitorIp(), sipConfig.getPort());
      } catch (TransportNotSupportedException e) {
         e.printStackTrace();
@@ -109,7 +79,6 @@
         udpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getPort(), "UDP");
         udpSipProvider = (SipProviderImpl)sipStack.createSipProvider(udpListeningPoint);
         udpSipProvider.addSipListener(sipProcessorObserver);
//         udpSipProvider.setAutomaticDialogSupportEnabled(false);
      } catch (TransportNotSupportedException e) {
         e.printStackTrace();
      } catch (InvalidArgumentException e) {