收流时设置re_use_port参数解决端口关闭快速打开造成的端口未释放问题, 支持点播的tcp主动

This commit is contained in:
648540858
2023-04-19 16:21:28 +08:00
parent f68f6d20e0
commit 0f3898910c
8 changed files with 79 additions and 30 deletions

View File

@@ -346,4 +346,12 @@ public class ZLMRESTfulUtils {
param.put("stream_id", streamId);
return sendPost(mediaServerItem, "resumeRtpCheck",param, null);
}
public JSONObject connectRtpServer(MediaServerItem mediaServerItem, String dst_url, int dst_port, String stream_id) {
Map<String, Object> param = new HashMap<>(1);
param.put("dst_url", dst_url);
param.put("dst_port", dst_port);
param.put("stream_id", stream_id);
return sendPost(mediaServerItem, "connectRtpServer",param, null);
}
}

View File

@@ -91,7 +91,17 @@ public class ZLMRTPServerFactory {
return result;
}
public int createRTPServer(MediaServerItem mediaServerItem, String streamId, int ssrc, Integer port) {
/**
* 开启rtpServer
* @param mediaServerItem zlm服务实例
* @param streamId 流Id
* @param ssrc ssrc
* @param port 端口, 0/null为使用随机
* @param reUsePort 是否重用端口
* @param tcpMode 0/null udp 模式1 tcp 被动模式, 2 tcp 主动模式。
* @return
*/
public int createRTPServer(MediaServerItem mediaServerItem, String streamId, int ssrc, Integer port, Boolean reUsePort, Integer tcpMode) {
int result = -1;
// 查询此rtp server 是否已经存在
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaServerItem, streamId);
@@ -107,7 +117,7 @@ public class ZLMRTPServerFactory {
JSONObject jsonObject = zlmresTfulUtils.closeRtpServer(mediaServerItem, param);
if (jsonObject != null ) {
if (jsonObject.getInteger("code") == 0) {
return createRTPServer(mediaServerItem, streamId, ssrc, port);
return createRTPServer(mediaServerItem, streamId, ssrc, port, reUsePort, tcpMode);
}else {
logger.warn("[开启rtpServer], 重启RtpServer错误");
}
@@ -121,8 +131,14 @@ public class ZLMRTPServerFactory {
Map<String, Object> param = new HashMap<>();
param.put("enable_tcp", 1);
if (tcpMode == null) {
tcpMode = 0;
}
param.put("tcp_mode", tcpMode);
param.put("stream_id", streamId);
if (reUsePort != null) {
param.put("re_use_port", reUsePort?"1":"0");
}
// 推流端口设置0则使用随机端口
if (port == null) {
param.put("port", 0);