From a29a0a0785f966294ba01982fba62c1ff0f23bea Mon Sep 17 00:00:00 2001 From: panlinlin <648540858@qq.com> Date: Thu, 22 Apr 2021 17:33:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E7=9A=84=E5=85=BC=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/gb28181/session/SsrcUtil.java | 9 +++++++++ .../session/VideoStreamSessionManager.java | 4 +++- .../transmit/cmd/SIPRequestHeaderProvider.java | 3 +-- .../gb28181/transmit/cmd/impl/SIPCommander.java | 13 ++++--------- .../response/impl/InviteResponseProcessor.java | 16 ++++++---------- .../iot/vmp/media/zlm/ZLMHttpHookListener.java | 2 +- 6 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/session/SsrcUtil.java b/src/main/java/com/genersoft/iot/vmp/gb28181/session/SsrcUtil.java index d6b75f85..6a1401d2 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/session/SsrcUtil.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/session/SsrcUtil.java @@ -5,7 +5,10 @@ import java.util.List; import java.util.Random; import com.genersoft.iot.vmp.conf.SipConfig; +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; import com.genersoft.iot.vmp.utils.SpringBeanFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @Description:SIP信令中的SSRC工具类。SSRC值由10位十进制整数组成的字符串,第一位为0代表实况,为1则代表回放;第二位至第六位由监控域ID的第4位到第8位组成;最后4位为不重复的4个整数 @@ -14,6 +17,8 @@ import com.genersoft.iot.vmp.utils.SpringBeanFactory; */ public class SsrcUtil { + private final static Logger logger = LoggerFactory.getLogger(SsrcUtil.class); + private static String ssrcPrefix; private static List isUsed; @@ -59,6 +64,10 @@ public class SsrcUtil { * */ public static void releaseSsrc(String ssrc) { + if (ssrc == null) { + logger.error("要释放ssrc为null"); + return; + } String sn = ssrc.substring(6); isUsed.remove(sn); notUsed.add(sn); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java b/src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java index b6c0dfc4..5ea57c15 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java @@ -42,7 +42,9 @@ public class VideoStreamSessionManager { public void remove(String deviceId, String channelId) { sessionMap.remove(deviceId + "_" + channelId); - SsrcUtil.releaseSsrc(ssrcMap.get(deviceId + "_" + channelId)); + if (ssrcMap.get(deviceId + "_" + channelId) != null) { + SsrcUtil.releaseSsrc(ssrcMap.get(deviceId + "_" + channelId)); + } ssrcMap.remove(deviceId + "_" + channelId); streamIdMap.remove(deviceId + "_" + channelId); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java index 44bfc549..cecbe3c0 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java @@ -69,8 +69,7 @@ public class SIPRequestHeaderProvider { SipURI requestLine = sipFactory.createAddressFactory().createSipURI(channelId, device.getHostAddress()); //via ArrayList viaHeaders = new ArrayList(); - ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(device.getIp(), device.getPort(), device.getTransport(), viaTag); -// ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(), device.getTransport(), viaTag); + ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(), device.getTransport(), viaTag); viaHeader.setRPort(); viaHeaders.add(viaHeader); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java index 5f31d87b..529feaf0 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java @@ -21,6 +21,7 @@ import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorager; +import gov.nist.javax.sip.message.SIPRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -625,15 +626,9 @@ public class SIPCommander implements ISIPCommander { } Request byeRequest = dialog.createRequest(Request.BYE); SipURI byeURI = (SipURI) byeRequest.getRequestURI(); - String vh = transaction.getRequest().getHeader(ViaHeader.NAME).toString(); - Pattern p = Pattern.compile("(\\d+\\.\\d+\\.\\d+\\.\\d+)\\:(\\d+)"); - Matcher matcher = p.matcher(vh); - if (matcher.find()) { - String ip = matcher.group(1); - byeURI.setHost(ip); - String port = matcher.group(2); - byeURI.setPort(Integer.parseInt(port)); - } + SIPRequest request = (SIPRequest)transaction.getRequest(); + byeURI.setHost(request.getRemoteAddress().getHostName()); + byeURI.setPort(request.getRemotePort()); ViaHeader viaHeader = (ViaHeader) byeRequest.getHeader(ViaHeader.NAME); String protocol = viaHeader.getTransport().toUpperCase(); ClientTransaction clientTransaction = null; diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/response/impl/InviteResponseProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/response/impl/InviteResponseProcessor.java index 83500aa3..0e238b04 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/response/impl/InviteResponseProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/response/impl/InviteResponseProcessor.java @@ -2,16 +2,13 @@ package com.genersoft.iot.vmp.gb28181.transmit.response.impl; import java.text.ParseException; -import javax.sip.Dialog; -import javax.sip.InvalidArgumentException; -import javax.sip.ResponseEvent; -import javax.sip.SipException; +import javax.sip.*; import javax.sip.address.SipURI; import javax.sip.header.CSeqHeader; -import javax.sip.header.ViaHeader; import javax.sip.message.Request; import javax.sip.message.Response; +import gov.nist.javax.sip.ResponseEventExt; import org.springframework.stereotype.Component; import com.genersoft.iot.vmp.conf.SipConfig; @@ -46,16 +43,15 @@ public class InviteResponseProcessor implements ISIPResponseProcessor { // 成功响应 // 下发ack if (statusCode == Response.OK) { + ResponseEventExt event = (ResponseEventExt)evt; Dialog dialog = evt.getDialog(); CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME); Request reqAck = dialog.createAck(cseq.getSeqNumber()); - SipURI requestURI = (SipURI) reqAck.getRequestURI(); - ViaHeader viaHeader = (ViaHeader) response.getHeader(ViaHeader.NAME); - requestURI.setHost(viaHeader.getHost()); - requestURI.setPort(viaHeader.getPort()); + requestURI.setHost(event.getRemoteIpAddress()); + requestURI.setPort(event.getRemotePort()); reqAck.setRequestURI(requestURI); - + System.out.println("向 " + event.getRemoteIpAddress() + ":" + event.getRemotePort() + "回复ack"); dialog.sendAck(reqAck); } } catch (InvalidArgumentException | SipException e) { diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java index cf1ce4cd..14719cc4 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java @@ -251,7 +251,7 @@ public class ZLMHttpHookListener { JSONArray tracks = json.getJSONArray("tracks"); boolean regist = json.getBoolean("regist"); if (tracks != null) { - System.out.println("222222" + schema); + System.out.println("on_stream_changed->>" + schema); } if ("rtmp".equals(schema)){