songww
2020-05-08 bf7ab3fe2ba246208d729901c33a9402209ee26a
src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java
@@ -2,6 +2,7 @@
import java.util.Properties;
import javax.annotation.PostConstruct;
import javax.sip.DialogTerminatedEvent;
import javax.sip.IOExceptionEvent;
import javax.sip.ListeningPoint;
@@ -26,7 +27,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import com.genersoft.iot.vmp.conf.SipConfig;
@@ -37,7 +37,7 @@
import gov.nist.javax.sip.SipStackImpl;
@Component
public class SipLayer implements SipListener{
public class SipLayer implements SipListener, Runnable {
   
   private final static Logger logger = LoggerFactory.getLogger(SipLayer.class);
   
@@ -57,37 +57,45 @@
   private HeaderFactory headerFactory;
   private MessageFactory messageFactory;
   @Bean
   private boolean initSipServer() throws Exception {
   @PostConstruct
   private void initSipServer() {
      Thread thread=new Thread(this);
        thread.setDaemon(true);
        thread.setName("sip server thread start");
        thread.start();
   }
   @Override
   public void run() {
      SipFactory sipFactory = SipFactory.getInstance();
      sipFactory.setPathName("gov.nist");
      try {
      headerFactory = sipFactory.createHeaderFactory();
      addressFactory = sipFactory.createAddressFactory();
      messageFactory = sipFactory.createMessageFactory();
      
      Properties properties = new Properties();
      properties.setProperty("javax.sip.STACK_NAME", "GB28181_SIP");
      properties.setProperty("javax.sip.IP_ADDRESS", config.getSipIp());
         properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "false");
      /**
       * 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", "16");
         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);
      
      try {
         startTcpListener();
         startUdpListener();
      } catch (Exception e) {
         logger.error("Sip Server 启动失败! port {"+config.getSipPort()+"}");
         e.printStackTrace();
         throw e;
      }
      logger.info("Sip Server 启动成功 port {"+config.getSipPort()+"}");
      return true;
   }
   
   private void startTcpListener() throws Exception {
@@ -129,8 +137,13 @@
   }
   /**   
    * <p>Title: processTimeout</p>
    * <p>Description: </p>
    * <p>
    * Title: processTimeout
    * </p>
    * <p>
    * Description:
    * </p>
    *
    * @param timeoutEvent    
    */  
   @Override
@@ -140,8 +153,13 @@
   }
   /**   
    * <p>Title: processIOException</p>
    * <p>Description: </p>
    * <p>
    * Title: processIOException
    * </p>
    * <p>
    * Description:
    * </p>
    *
    * @param exceptionEvent    
    */  
   @Override
@@ -151,8 +169,13 @@
   }
   /**   
    * <p>Title: processTransactionTerminated</p>
    * <p>Description: </p>
    * <p>
    * Title: processTransactionTerminated
    * </p>
    * <p>
    * Description:
    * </p>
    *
    * @param transactionTerminatedEvent    
    */  
   @Override
@@ -162,8 +185,13 @@
   }
   /**   
    * <p>Title: processDialogTerminated</p>
    * <p>Description: </p>
    * <p>
    * Title: processDialogTerminated
    * </p>
    * <p>
    * Description:
    * </p>
    *
    * @param dialogTerminatedEvent    
    */  
   @Override
@@ -198,7 +226,6 @@
      }
      return serverTransaction;
   }
   public AddressFactory getAddressFactory() {
      return addressFactory;