Commit 66eda32ab97d6e94e9f274d6faa4df586c452dfb

Authored by 648540858
1 parent a45fab42

优化端口预占用

src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
@@ -228,7 +228,7 @@ public class ZLMRTPServerFactory { @@ -228,7 +228,7 @@ public class ZLMRTPServerFactory {
228 int localPort = 0; 228 int localPort = 0;
229 if (userSetting.getGbSendStreamStrict()) { 229 if (userSetting.getGbSendStreamStrict()) {
230 if (userSetting.getGbSendStreamStrict()) { 230 if (userSetting.getGbSendStreamStrict()) {
231 - localPort = keepPort(serverItem, ssrc); 231 + localPort = keepPort(serverItem, ssrc, null);
232 if (localPort == 0) { 232 if (localPort == 0) {
233 return null; 233 return null;
234 } 234 }
@@ -264,7 +264,7 @@ public class ZLMRTPServerFactory { @@ -264,7 +264,7 @@ public class ZLMRTPServerFactory {
264 // 默认为随机端口 264 // 默认为随机端口
265 int localPort = 0; 265 int localPort = 0;
266 if (userSetting.getGbSendStreamStrict()) { 266 if (userSetting.getGbSendStreamStrict()) {
267 - localPort = keepPort(serverItem, ssrc); 267 + localPort = keepPort(serverItem, ssrc, null);
268 if (localPort == 0) { 268 if (localPort == 0) {
269 return null; 269 return null;
270 } 270 }
@@ -288,23 +288,28 @@ public class ZLMRTPServerFactory { @@ -288,23 +288,28 @@ public class ZLMRTPServerFactory {
288 /** 288 /**
289 * 保持端口,直到需要需要发流时再释放 289 * 保持端口,直到需要需要发流时再释放
290 */ 290 */
291 - public int keepPort(MediaServerItem serverItem, String ssrc) {  
292 - int localPort = 0; 291 + public int keepPort(MediaServerItem serverItem, String ssrc, Integer localPort) {
293 Map<String, Object> param = new HashMap<>(3); 292 Map<String, Object> param = new HashMap<>(3);
294 - param.put("port", 0); 293 + if (localPort == null) {
  294 + localPort = 0;
  295 + }
  296 + param.put("port", localPort);
295 param.put("enable_tcp", 1); 297 param.put("enable_tcp", 1);
296 param.put("stream_id", ssrc); 298 param.put("stream_id", ssrc);
297 JSONObject jsonObject = zlmresTfulUtils.openRtpServer(serverItem, param); 299 JSONObject jsonObject = zlmresTfulUtils.openRtpServer(serverItem, param);
298 if (jsonObject.getInteger("code") == 0) { 300 if (jsonObject.getInteger("code") == 0) {
299 localPort = jsonObject.getInteger("port"); 301 localPort = jsonObject.getInteger("port");
300 HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, serverItem.getId()); 302 HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, serverItem.getId());
  303 + Integer finalLocalPort = localPort;
301 hookSubscribe.addSubscribe(hookSubscribeForRtpServerTimeout, 304 hookSubscribe.addSubscribe(hookSubscribeForRtpServerTimeout,
302 (MediaServerItem mediaServerItem, JSONObject response)->{ 305 (MediaServerItem mediaServerItem, JSONObject response)->{
303 - logger.info("[上级点播] {}->监听端口到期继续保持监听", ssrc);  
304 - int port = keepPort(serverItem, ssrc);  
305 - if (port == 0) {  
306 - logger.info("[上级点播] {}->监听端口失败,移除监听", ssrc);  
307 - hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout); 306 + if (ssrc.equals(response.getString("ssrc"))) {
  307 + logger.info("[上级点播] {}->监听端口到期继续保持监听", ssrc);
  308 + int port = keepPort(serverItem, ssrc, finalLocalPort);
  309 + if (port == 0) {
  310 + logger.info("[上级点播] {}->监听端口失败,移除监听", ssrc);
  311 + hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout);
  312 + }
308 } 313 }
309 }); 314 });
310 logger.info("[保持端口] {}->监听端口: {}", ssrc, localPort); 315 logger.info("[保持端口] {}->监听端口: {}", ssrc, localPort);
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
@@ -235,7 +235,7 @@ public class PlayServiceImpl implements IPlayService { @@ -235,7 +235,7 @@ public class PlayServiceImpl implements IPlayService {
235 sendRtpItem.setReceiveStream(stream + "_talk"); 235 sendRtpItem.setReceiveStream(stream + "_talk");
236 236
237 237
238 - int port = zlmrtpServerFactory.keepPort(mediaServerItem, playSsrc); 238 + int port = zlmrtpServerFactory.keepPort(mediaServerItem, playSsrc, null);
239 //端口获取失败的ssrcInfo 没有必要发送点播指令 239 //端口获取失败的ssrcInfo 没有必要发送点播指令
240 if (port <= 0) { 240 if (port <= 0) {
241 logger.info("[语音对讲] 端口分配异常,deviceId={},channelId={}", device.getDeviceId(), channelId); 241 logger.info("[语音对讲] 端口分配异常,deviceId={},channelId={}", device.getDeviceId(), channelId);