优化端口预占用,防止占用无法释放
This commit is contained in:
@@ -1,14 +1,22 @@
|
||||
package com.genersoft.iot.vmp.gb28181.utils;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Gb28181Sdp;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.RemoteAddressInfo;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.utils.GitUtil;
|
||||
import gov.nist.javax.sip.address.AddressImpl;
|
||||
import gov.nist.javax.sip.address.SipUri;
|
||||
import gov.nist.javax.sip.header.Subject;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import javax.sdp.SdpFactory;
|
||||
import javax.sdp.SdpParseException;
|
||||
import javax.sdp.SessionDescription;
|
||||
import javax.sip.PeerUnavailableException;
|
||||
import javax.sip.SipFactory;
|
||||
import javax.sip.header.FromHeader;
|
||||
@@ -16,6 +24,8 @@ import javax.sip.header.Header;
|
||||
import javax.sip.header.UserAgentHeader;
|
||||
import javax.sip.message.Request;
|
||||
import java.text.ParseException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -28,6 +38,8 @@ import java.util.UUID;
|
||||
*/
|
||||
public class SipUtils {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(SipUtils.class);
|
||||
|
||||
public static String getUserIdFromFromHeader(Request request) {
|
||||
FromHeader fromHeader = (FromHeader)request.getHeader(FromHeader.NAME);
|
||||
return getUserIdFromFromHeader(fromHeader);
|
||||
@@ -51,7 +63,7 @@ public class SipUtils {
|
||||
}
|
||||
|
||||
public static String getNewViaTag() {
|
||||
return "z9hG4bK" + System.currentTimeMillis();
|
||||
return "z9hG4bK" + RandomStringUtils.randomNumeric(10);
|
||||
}
|
||||
|
||||
public static UserAgentHeader createUserAgentHeader(GitUtil gitUtil) throws PeerUnavailableException, ParseException {
|
||||
@@ -113,6 +125,12 @@ public class SipUtils {
|
||||
strTmp = String.format("%02X", moveSpeed);
|
||||
builder.append(strTmp, 0, 2);
|
||||
builder.append(strTmp, 0, 2);
|
||||
|
||||
//优化zoom低倍速下的变倍速率
|
||||
if ((zoomSpeed > 0) && (zoomSpeed <16))
|
||||
{
|
||||
zoomSpeed = 16;
|
||||
}
|
||||
strTmp = String.format("%X", zoomSpeed);
|
||||
builder.append(strTmp, 0, 1).append("0");
|
||||
//计算校验码
|
||||
@@ -183,4 +201,66 @@ public class SipUtils {
|
||||
}
|
||||
return deviceChannel;
|
||||
}
|
||||
}
|
||||
|
||||
public static Gb28181Sdp parseSDP(String sdpStr) throws SdpParseException {
|
||||
|
||||
// jainSip不支持y= f=字段, 移除以解析。
|
||||
int ssrcIndex = sdpStr.indexOf("y=");
|
||||
int mediaDescriptionIndex = sdpStr.indexOf("f=");
|
||||
// 检查是否有y字段
|
||||
SessionDescription sdp;
|
||||
String ssrc = null;
|
||||
String mediaDescription = null;
|
||||
if (mediaDescriptionIndex == 0 && ssrcIndex == 0) {
|
||||
sdp = SdpFactory.getInstance().createSessionDescription(sdpStr);
|
||||
}else {
|
||||
String lines[] = sdpStr.split("\\r?\\n");
|
||||
StringBuilder sdpBuffer = new StringBuilder();
|
||||
for (String line : lines) {
|
||||
if (line.trim().startsWith("y=")) {
|
||||
ssrc = line.substring(2);
|
||||
}else if (line.trim().startsWith("f=")) {
|
||||
mediaDescription = line.substring(2);
|
||||
}else {
|
||||
sdpBuffer.append(line.trim()).append("\r\n");
|
||||
}
|
||||
}
|
||||
sdp = SdpFactory.getInstance().createSessionDescription(sdpBuffer.toString());
|
||||
}
|
||||
return Gb28181Sdp.getInstance(sdp, ssrc, mediaDescription);
|
||||
}
|
||||
|
||||
public static String getSsrcFromSdp(String sdpStr) {
|
||||
|
||||
// jainSip不支持y= f=字段, 移除以解析。
|
||||
int ssrcIndex = sdpStr.indexOf("y=");
|
||||
if (ssrcIndex == 0) {
|
||||
return null;
|
||||
}
|
||||
String lines[] = sdpStr.split("\\r?\\n");
|
||||
for (String line : lines) {
|
||||
if (line.trim().startsWith("y=")) {
|
||||
return line.substring(2);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String parseTime(String timeStr) {
|
||||
if (ObjectUtils.isEmpty(timeStr)){
|
||||
return null;
|
||||
}
|
||||
LocalDateTime localDateTime;
|
||||
try {
|
||||
localDateTime = LocalDateTime.parse(timeStr);
|
||||
}catch (DateTimeParseException e) {
|
||||
try {
|
||||
localDateTime = LocalDateTime.parse(timeStr, DateUtil.formatterISO8601);
|
||||
}catch (DateTimeParseException e2) {
|
||||
logger.error("[格式化时间] 无法格式化时间: {}", timeStr);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return localDateTime.format(DateUtil.formatterISO8601);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user