优化级联时的异常处理

This commit is contained in:
panlinlin
2021-04-26 18:38:57 +08:00
parent bc2b288547
commit 39078225f1
25 changed files with 226 additions and 31 deletions

View File

@@ -1,6 +1,9 @@
package com.genersoft.iot.vmp.media.zlm;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.conf.MediaServerConfig;
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
@@ -119,4 +122,33 @@ public class ZLMMediaListManager {
storager.mediaOutline(app, streamId);
}
}
public void clearAllSessions() {
logger.info("清空所有国标相关的session");
JSONObject allSessionJSON = zlmresTfulUtils.getAllSession();
MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
HashSet<String> allLocalPorts = new HashSet();
if (allSessionJSON.getInteger("code") == 0) {
JSONArray data = allSessionJSON.getJSONArray("data");
if (data.size() > 0) {
for (int i = 0; i < data.size(); i++) {
JSONObject sessionJOSN = data.getJSONObject(i);
Integer local_port = sessionJOSN.getInteger("local_port");
if (!local_port.equals(Integer.valueOf(mediaInfo.getHttpPort())) &&
!local_port.equals(Integer.valueOf(mediaInfo.getHttpSSLport())) &&
!local_port.equals(Integer.valueOf(mediaInfo.getRtmpPort())) &&
!local_port.equals(Integer.valueOf(mediaInfo.getRtspPort())) &&
!local_port.equals(Integer.valueOf(mediaInfo.getRtspSSlport())) &&
!local_port.equals(Integer.valueOf(mediaInfo.getHookOnFlowReport()))){
allLocalPorts.add(sessionJOSN.getInteger("local_port") + "");
}
}
}
}
if (allLocalPorts.size() > 0) {
List<String> result = new ArrayList<>(allLocalPorts);
String localPortSStr = String.join(",", result);
zlmresTfulUtils.kickSessions(localPortSStr);
}
}
}

View File

@@ -194,4 +194,14 @@ public class ZLMRESTfulUtils {
param.put("force", 1);
return sendPost("close_streams",param, null);
}
public JSONObject getAllSession() {
return sendPost("getAllSession",null, null);
}
public void kickSessions(String localPortSStr) {
Map<String, Object> param = new HashMap<>();
param.put("local_port", localPortSStr);
sendPost("kick_sessions",param, null);
}
}

View File

@@ -18,13 +18,13 @@ public class ZLMRTPServerFactory {
private Logger logger = LoggerFactory.getLogger("ZLMRTPServerFactory");
@Value("${media.rtp.udpPortRange}")
private String udpPortRange;
@Value("${media.rtp.portRange}")
private String portRange;
@Autowired
private ZLMRESTfulUtils zlmresTfulUtils;
private int[] udpPortRangeArray = new int[2];
private int[] portRangeArray = new int[2];
private int currentPort = 0;
@@ -52,7 +52,7 @@ public class ZLMRTPServerFactory {
Map<String, Object> param = new HashMap<>();
int result = -1;
int newPort = getPortFromUdpPortRange();
int newPort = getPortFromportRange();
param.put("port", newPort);
param.put("enable_tcp", 1);
param.put("stream_id", streamId);
@@ -101,16 +101,16 @@ public class ZLMRTPServerFactory {
return result;
}
private int getPortFromUdpPortRange() {
private int getPortFromportRange() {
if (currentPort == 0) {
String[] udpPortRangeStrArray = udpPortRange.split(",");
udpPortRangeArray[0] = Integer.parseInt(udpPortRangeStrArray[0]);
udpPortRangeArray[1] = Integer.parseInt(udpPortRangeStrArray[1]);
String[] portRangeStrArray = portRange.split(",");
portRangeArray[0] = Integer.parseInt(portRangeStrArray[0]);
portRangeArray[1] = Integer.parseInt(portRangeStrArray[1]);
}
if (currentPort == 0 || currentPort++ > udpPortRangeArray[1]) {
currentPort = udpPortRangeArray[0];
return udpPortRangeArray[0];
if (currentPort == 0 || currentPort++ > portRangeArray[1]) {
currentPort = portRangeArray[0];
return portRangeArray[0];
} else {
if (currentPort % 2 == 1) {
currentPort++;
@@ -244,4 +244,8 @@ public class ZLMRTPServerFactory {
}
return result;
}
public void closeAllSendRtpStream() {
}
}

View File

@@ -164,6 +164,10 @@ public class ZLMRunner implements CommandLineRunner {
mediaServerConfig.setLocalIP(mediaIp);
mediaServerConfig.setWanIp(StringUtils.isEmpty(mediaWanIp)? mediaIp: mediaWanIp);
redisCatchStorage.updateMediaInfo(mediaServerConfig);
// 清空所有session
// zlmMediaListManager.clearAllSessions();
// 更新流列表
zlmMediaListManager.updateMediaList();
// 恢复流代理