增加对设备的兼容性

This commit is contained in:
panlinlin 2021-04-22 17:33:07 +08:00
parent ef742e715b
commit a29a0a0785
6 changed files with 24 additions and 23 deletions

View File

@ -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<String> 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);

View File

@ -42,7 +42,9 @@ public class VideoStreamSessionManager {
public void remove(String deviceId, String channelId) {
sessionMap.remove(deviceId + "_" + channelId);
if (ssrcMap.get(deviceId + "_" + channelId) != null) {
SsrcUtil.releaseSsrc(ssrcMap.get(deviceId + "_" + channelId));
}
ssrcMap.remove(deviceId + "_" + channelId);
streamIdMap.remove(deviceId + "_" + channelId);
}

View File

@ -69,8 +69,7 @@ public class SIPRequestHeaderProvider {
SipURI requestLine = sipFactory.createAddressFactory().createSipURI(channelId, device.getHostAddress());
//via
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
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);

View File

@ -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;

View File

@ -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) {

View File

@ -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)){