From 78b39ebd5a99da3dca367b4ed3ee2c97e91a333c Mon Sep 17 00:00:00 2001 From: xiaoxie <hotcoffie@163.com> Date: 星期五, 05 十一月 2021 22:44:10 +0800 Subject: [PATCH] 尝试docker-compose启动 --- src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java | 62 +++++++++++++++++++----------- 1 files changed, 39 insertions(+), 23 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 0a76f69..1afabb7 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java @@ -9,9 +9,11 @@ import javax.sip.*; import javax.sip.header.CallIdHeader; +import javax.sip.header.Header; import javax.sip.message.Response; import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; +import gov.nist.javax.sip.SipProviderImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -39,7 +41,7 @@ @Autowired private SipSubscribe sipSubscribe; - private SipStack sipStack; + private SipStackImpl sipStack; private SipFactory sipFactory; @@ -52,7 +54,7 @@ private ThreadPoolExecutor initSipServer() { int processThreadNum = Runtime.getRuntime().availableProcessors() * 10; - LinkedBlockingQueue<Runnable> processQueue = new LinkedBlockingQueue<Runnable>(10000); + LinkedBlockingQueue<Runnable> processQueue = new LinkedBlockingQueue<>(10000); processThreadPool = new ThreadPoolExecutor(processThreadNum,processThreadNum, 0L,TimeUnit.MILLISECONDS,processQueue, new ThreadPoolExecutor.CallerRunsPolicy()); @@ -88,22 +90,19 @@ @Bean("tcpSipProvider") @DependsOn("sipStack") - private SipProvider startTcpListener() { + private SipProviderImpl startTcpListener() { ListeningPoint tcpListeningPoint = null; - SipProvider tcpSipProvider = null; + SipProviderImpl tcpSipProvider = null; try { - tcpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getSipPort(), "TCP"); - tcpSipProvider = sipStack.createSipProvider(tcpListeningPoint); + tcpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getPort(), "TCP"); + tcpSipProvider = (SipProviderImpl)sipStack.createSipProvider(tcpListeningPoint); tcpSipProvider.addSipListener(this); - logger.info("Sip Server TCP 鍚姩鎴愬姛 port {" + sipConfig.getMonitorIp() + ":" + 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.getPort() + "}"); } catch (TransportNotSupportedException e) { e.printStackTrace(); } catch (InvalidArgumentException e) { logger.error("鏃犳硶浣跨敤 [ {}:{} ]浣滀负SIP[ TCP ]鏈嶅姟锛屽彲鎺掓煡: 1. sip.monitor-ip 鏄惁涓烘湰鏈虹綉鍗P; 2. sip.port 鏄惁宸茶鍗犵敤" - , sipConfig.getMonitorIp(), sipConfig.getSipPort()); + , sipConfig.getMonitorIp(), sipConfig.getPort()); } catch (TooManyListenersException e) { e.printStackTrace(); } catch (ObjectInUseException e) { @@ -114,24 +113,25 @@ @Bean("udpSipProvider") @DependsOn("sipStack") - private SipProvider startUdpListener() { + private SipProviderImpl startUdpListener() { ListeningPoint udpListeningPoint = null; - SipProvider udpSipProvider = null; + SipProviderImpl udpSipProvider = null; try { - udpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getSipPort(), "UDP"); - udpSipProvider = sipStack.createSipProvider(udpListeningPoint); + udpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getPort(), "UDP"); + udpSipProvider = (SipProviderImpl)sipStack.createSipProvider(udpListeningPoint); udpSipProvider.addSipListener(this); +// udpSipProvider.setAutomaticDialogSupportEnabled(false); } catch (TransportNotSupportedException e) { e.printStackTrace(); } catch (InvalidArgumentException e) { logger.error("鏃犳硶浣跨敤 [ {}:{} ]浣滀负SIP[ UDP ]鏈嶅姟锛屽彲鎺掓煡: 1. sip.monitor-ip 鏄惁涓烘湰鏈虹綉鍗P; 2. sip.port 鏄惁宸茶鍗犵敤" - , sipConfig.getMonitorIp(), sipConfig.getSipPort()); + , sipConfig.getMonitorIp(), sipConfig.getPort()); } catch (TooManyListenersException e) { e.printStackTrace(); } catch (ObjectInUseException e) { e.printStackTrace(); } - logger.info("Sip Server UDP 鍚姩鎴愬姛 port [" + sipConfig.getMonitorIp() + ":" + sipConfig.getSipPort() + "]"); + logger.info("Sip Server UDP 鍚姩鎴愬姛 port [" + sipConfig.getMonitorIp() + ":" + sipConfig.getPort() + "]"); return udpSipProvider; } @@ -141,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) { @@ -153,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); @@ -163,12 +163,14 @@ // TODO Auto-generated catch block e.printStackTrace(); } + 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); + SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(evt); + subscribe.response(eventResult); } } } @@ -181,7 +183,8 @@ if (callIdHeader != null) { SipSubscribe.Event subscribe = sipSubscribe.getErrorSubscribe(callIdHeader.getCallId()); if (subscribe != null) { - subscribe.response(evt); + SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(evt); + subscribe.response(eventResult); } } } @@ -204,7 +207,11 @@ @Override public void processTimeout(TimeoutEvent timeoutEvent) { // TODO Auto-generated method stub - + CallIdHeader callIdHeader = timeoutEvent.getClientTransaction().getDialog().getCallId(); + String callId = callIdHeader.getCallId(); + SipSubscribe.Event errorSubscribe = sipSubscribe.getErrorSubscribe(callId); + SipSubscribe.EventResult<TimeoutEvent> timeoutEventEventResult = new SipSubscribe.EventResult<>(timeoutEvent); + errorSubscribe.response(timeoutEventEventResult); } /** @@ -236,7 +243,11 @@ @Override public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) { // TODO Auto-generated method stub - +// CallIdHeader callIdHeader = transactionTerminatedEvent.getClientTransaction().getDialog().getCallId(); +// String callId = callIdHeader.getCallId(); +// SipSubscribe.Event errorSubscribe = sipSubscribe.getErrorSubscribe(callId); +// SipSubscribe.EventResult<TransactionTerminatedEvent> eventResult = new SipSubscribe.EventResult<>(transactionTerminatedEvent); +// errorSubscribe.response(eventResult); } /** @@ -252,6 +263,11 @@ @Override public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) { // TODO Auto-generated method stub +// CallIdHeader callIdHeader = dialogTerminatedEvent.getDialog().getCallId(); +// String callId = callIdHeader.getCallId(); +// SipSubscribe.Event errorSubscribe = sipSubscribe.getErrorSubscribe(callId); +// SipSubscribe.EventResult<DialogTerminatedEvent> eventResult = new SipSubscribe.EventResult<>(dialogTerminatedEvent); +// errorSubscribe.response(eventResult); } -- Gitblit v1.8.0