支持使用udp端口段来启用高性能udp
parent
3ec3b88456
commit
b55374c75a
|
@ -93,7 +93,7 @@ public class SIPProcessorFactory {
|
||||||
public ISIPRequestProcessor createRequestProcessor(RequestEvent evt) {
|
public ISIPRequestProcessor createRequestProcessor(RequestEvent evt) {
|
||||||
Request request = evt.getRequest();
|
Request request = evt.getRequest();
|
||||||
String method = request.getMethod();
|
String method = request.getMethod();
|
||||||
logger.info("接收到消息:"+request.getMethod());
|
// logger.info("接收到消息:"+request.getMethod());
|
||||||
if (Request.INVITE.equals(method)) {
|
if (Request.INVITE.equals(method)) {
|
||||||
InviteRequestProcessor processor = new InviteRequestProcessor();
|
InviteRequestProcessor processor = new InviteRequestProcessor();
|
||||||
processor.setRequestEvent(evt);
|
processor.setRequestEvent(evt);
|
||||||
|
|
|
@ -19,6 +19,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||||
import com.genersoft.iot.vmp.conf.MediaServerConfig;
|
import com.genersoft.iot.vmp.conf.MediaServerConfig;
|
||||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||||
|
import com.genersoft.iot.vmp.media.zlm.ZLMUtils;
|
||||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
@ -60,6 +61,13 @@ public class SIPCommander implements ISIPCommander {
|
||||||
@Qualifier(value="udpSipProvider")
|
@Qualifier(value="udpSipProvider")
|
||||||
private SipProvider udpSipProvider;
|
private SipProvider udpSipProvider;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ZLMUtils zlmUtils;
|
||||||
|
|
||||||
|
@Value("${media.rtp.enable}")
|
||||||
|
private boolean rtpEnable;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 云台方向放控制,使用配置文件中的默认镜头移动速度
|
* 云台方向放控制,使用配置文件中的默认镜头移动速度
|
||||||
|
@ -206,6 +214,13 @@ public class SIPCommander implements ISIPCommander {
|
||||||
String ssrc = streamSession.createPlaySsrc();
|
String ssrc = streamSession.createPlaySsrc();
|
||||||
String transport = device.getTransport();
|
String transport = device.getTransport();
|
||||||
MediaServerConfig mediaInfo = storager.getMediaInfo();
|
MediaServerConfig mediaInfo = storager.getMediaInfo();
|
||||||
|
String mediaPort = null;
|
||||||
|
// 使用动态udp端口
|
||||||
|
if (rtpEnable) {
|
||||||
|
mediaPort = zlmUtils.getNewRTPPort(ssrc) + "";
|
||||||
|
}else {
|
||||||
|
mediaPort = mediaInfo.getRtpProxyPort();
|
||||||
|
}
|
||||||
//
|
//
|
||||||
StringBuffer content = new StringBuffer(200);
|
StringBuffer content = new StringBuffer(200);
|
||||||
content.append("v=0\r\n");
|
content.append("v=0\r\n");
|
||||||
|
@ -214,10 +229,10 @@ public class SIPCommander implements ISIPCommander {
|
||||||
content.append("c=IN IP4 "+mediaInfo.getLocalIP()+"\r\n");
|
content.append("c=IN IP4 "+mediaInfo.getLocalIP()+"\r\n");
|
||||||
content.append("t=0 0\r\n");
|
content.append("t=0 0\r\n");
|
||||||
if("TCP".equals(transport)) {
|
if("TCP".equals(transport)) {
|
||||||
content.append("m=video "+mediaInfo.getRtpProxyPort()+" TCP/RTP/AVP 96 98 97\r\n");
|
content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
|
||||||
}
|
}
|
||||||
if("UDP".equals(transport)) {
|
if("UDP".equals(transport)) {
|
||||||
content.append("m=video "+mediaInfo.getRtpProxyPort()+" RTP/AVP 96 98 97\r\n");
|
content.append("m=video "+ mediaPort +" RTP/AVP 96 98 97\r\n");
|
||||||
}
|
}
|
||||||
content.append("a=recvonly\r\n");
|
content.append("a=recvonly\r\n");
|
||||||
content.append("a=rtpmap:96 PS/90000\r\n");
|
content.append("a=rtpmap:96 PS/90000\r\n");
|
||||||
|
@ -575,4 +590,5 @@ public class SIPCommander implements ISIPCommander {
|
||||||
return clientTransaction;
|
return clientTransaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,4 +83,8 @@ public class ZLMRESTfulUtils {
|
||||||
public JSONObject setServerConfig(Map<String, Object> param){
|
public JSONObject setServerConfig(Map<String, Object> param){
|
||||||
return sendPost("setServerConfig",param);
|
return sendPost("setServerConfig",param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JSONObject openRtpServer(Map<String, Object> param){
|
||||||
|
return sendPost("openRtpServer",param);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
package com.genersoft.iot.vmp.media.zlm;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class ZLMUtils {
|
||||||
|
|
||||||
|
@Value("${media.rtp.udpPortRange}")
|
||||||
|
private String udpPortRange;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ZLMRESTfulUtils zlmresTfulUtils;
|
||||||
|
|
||||||
|
private int[] udpPortRangeArray = new int[2];
|
||||||
|
|
||||||
|
private int currentPort = 0;
|
||||||
|
|
||||||
|
public int getNewRTPPort(String ssrc) {
|
||||||
|
String streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase();
|
||||||
|
Map<String, Object> param = new HashMap<>();
|
||||||
|
int newPort = getPortFromUdpPortRange();
|
||||||
|
param.put("port", newPort);
|
||||||
|
param.put("enable_tcp", 0);
|
||||||
|
param.put("stream_id", streamId);
|
||||||
|
JSONObject jsonObject = zlmresTfulUtils.openRtpServer(param);
|
||||||
|
if (jsonObject.getInteger("code") == 0) {
|
||||||
|
System.out.println(11111111);
|
||||||
|
System.out.println(streamId);
|
||||||
|
System.out.println(ssrc);
|
||||||
|
System.out.println(newPort);
|
||||||
|
System.out.println(jsonObject.toJSONString());
|
||||||
|
return newPort;
|
||||||
|
}else {
|
||||||
|
return getNewRTPPort(streamId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getPortFromUdpPortRange() {
|
||||||
|
if (currentPort == 0) {
|
||||||
|
String[] udpPortRangeStrArray = udpPortRange.split(",");
|
||||||
|
udpPortRangeArray[0] = Integer.parseInt(udpPortRangeStrArray[0]);
|
||||||
|
udpPortRangeArray[1] = Integer.parseInt(udpPortRangeStrArray[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentPort == 0 || currentPort ++ > udpPortRangeArray[1]) {
|
||||||
|
currentPort = udpPortRangeArray[0];
|
||||||
|
return udpPortRangeArray[0];
|
||||||
|
}else {
|
||||||
|
return currentPort ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
|
@ -69,8 +70,8 @@ public class PlayController {
|
||||||
return new ResponseEntity<String>("timeout",HttpStatus.OK);
|
return new ResponseEntity<String>("timeout",HttpStatus.OK);
|
||||||
}else {
|
}else {
|
||||||
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(streamId);
|
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(streamId);
|
||||||
Boolean exist = rtpInfo.getBoolean("exist");
|
if (rtpInfo == null || !rtpInfo.getBoolean("exist") || storager.queryPlayByDevice(deviceId, channelId).getFlv() == null){
|
||||||
if (rtpInfo == null || !rtpInfo.getBoolean("exist") || streamInfo.getFlv() != null){
|
Thread.sleep(2000);
|
||||||
continue;
|
continue;
|
||||||
}else {
|
}else {
|
||||||
lockFlag = false;
|
lockFlag = false;
|
||||||
|
@ -91,7 +92,6 @@ public class PlayController {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Thread.sleep(200);
|
|
||||||
streamInfo = storager.queryPlayByDevice(deviceId, channelId);
|
streamInfo = storager.queryPlayByDevice(deviceId, channelId);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -43,5 +43,9 @@ media: #zlm服务器的ip与http端口, 重点: 这是http端口
|
||||||
ip: 192.168.1.20
|
ip: 192.168.1.20
|
||||||
port: 9080
|
port: 9080
|
||||||
secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc
|
secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc
|
||||||
streamNoneReaderDelayMS: 1800000 # 无人观看多久关闭流
|
streamNoneReaderDelayMS: 1800000 # 无人观看多久自动关闭流
|
||||||
|
rtp: # 启用udp多端口模式
|
||||||
|
enable: false
|
||||||
|
udpPortRange: 30000,300500 # 端口范围
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue