From e48ef997c03b49c8090970f5fbb29ce80b0ac6df Mon Sep 17 00:00:00 2001
From: 64850858 <648540858@qq.com>
Date: 星期三, 14 七月 2021 15:57:39 +0800
Subject: [PATCH] 更换播放器, 修正和优化sql脚本,

---
 src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java |   44 +++++++++++++++++++++++++++++++++-----------
 1 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java b/src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java
index 54c0711..0dca4af 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java
@@ -8,8 +8,10 @@
 import java.util.concurrent.TimeUnit;
 
 import javax.sip.*;
+import javax.sip.header.CallIdHeader;
 import javax.sip.message.Response;
 
+import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -33,6 +35,9 @@
 
 	@Autowired
 	private SIPProcessorFactory processorFactory;
+
+	@Autowired
+	private SipSubscribe sipSubscribe;
 
 	private SipStack sipStack;
 
@@ -67,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 =
@@ -87,7 +92,7 @@
 		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() + "}");
@@ -100,7 +105,7 @@
 	@Bean("udpSipProvider")
 	@DependsOn("sipStack")
 	private SipProvider startUdpListener() throws Exception {
-		ListeningPoint udpListeningPoint = sipStack.createListeningPoint(sipConfig.getSipIp(), sipConfig.getSipPort(), "UDP");
+		ListeningPoint udpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getSipPort(), "UDP");
 		SipProvider udpSipProvider = sipStack.createSipProvider(udpListeningPoint);
 		udpSipProvider.addSipListener(this);
 		logger.info("Sip Server UDP 鍚姩鎴愬姛 port {" + sipConfig.getSipPort() + "}");
@@ -113,17 +118,19 @@
 	 */
 	@Override
 	public void processRequest(RequestEvent evt) {
-		logger.debug(evt.getRequest().toString());
+//		logger.debug(evt.getRequest().toString());
 		// 鐢变簬jainsip鏄崟绾跨▼绋嬪簭锛屼负鎻愰珮鎬ц兘骞跺彂澶勭悊
 		processThreadPool.execute(() -> {
-			processorFactory.createRequestProcessor(evt).process();
+			if (processorFactory != null) {
+				processorFactory.createRequestProcessor(evt).process();
+			}
 		});
 	}
 
 	@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);
@@ -133,17 +140,32 @@
 				// TODO Auto-generated catch block
 				e.printStackTrace();
 			}
-		// } else if (status == Response.TRYING) {
-			// trying涓嶄細鍥炲
+			if (evt.getResponse() != null && sipSubscribe.getOkSubscribesSize() > 0 ) {
+				CallIdHeader callIdHeader = (CallIdHeader)evt.getResponse().getHeader(CallIdHeader.NAME);
+				if (callIdHeader != null) {
+					SipSubscribe.Event subscribe = sipSubscribe.getOkSubscribe(callIdHeader.getCallId());
+					if (subscribe != null) {
+						subscribe.response(evt);
+					}
+				}
+			}
 		} else if ((status >= 100) && (status < 200)) {
 			// 澧炲姞鍏跺畠鏃犻渶鍥炲鐨勫搷搴旓紝濡�101銆�180绛�
 		} else {
 			logger.warn("鎺ユ敹鍒板け璐ョ殑response鍝嶅簲锛乻tatus锛�" + status + ",message:" + response.getReasonPhrase()/* .getContent().toString()*/);
+			if (evt.getResponse() != null && sipSubscribe.getErrorSubscribesSize() > 0 ) {
+				CallIdHeader callIdHeader = (CallIdHeader)evt.getResponse().getHeader(CallIdHeader.NAME);
+				if (callIdHeader != null) {
+					SipSubscribe.Event subscribe = sipSubscribe.getErrorSubscribe(callIdHeader.getCallId());
+					if (subscribe != null) {
+						subscribe.response(evt);
+					}
+				}
+			}
 		}
-		// trying涓嶄細鍥炲
-		// if (status == Response.TRYING) {
 
-		// }
+
+
 	}
 
 	/**

--
Gitblit v1.8.0