Commit 74ad4235f1738ea8ca954bd396a35ddf90a6e37b

Authored by 648540858
1 parent fb90dfda

修复tcp主动的推流

src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
@@ -302,7 +302,6 @@ public class ZLMRTPServerFactory { @@ -302,7 +302,6 @@ public class ZLMRTPServerFactory {
302 param.put("port", localPort); 302 param.put("port", localPort);
303 param.put("enable_tcp", 1); 303 param.put("enable_tcp", 1);
304 param.put("stream_id", ssrc); 304 param.put("stream_id", ssrc);
305 - param.put("re_use_port", 1);  
306 JSONObject jsonObject = zlmresTfulUtils.openRtpServer(serverItem, param); 305 JSONObject jsonObject = zlmresTfulUtils.openRtpServer(serverItem, param);
307 if (jsonObject.getInteger("code") == 0) { 306 if (jsonObject.getInteger("code") == 0) {
308 localPort = jsonObject.getInteger("port"); 307 localPort = jsonObject.getInteger("port");
@@ -313,7 +312,7 @@ public class ZLMRTPServerFactory { @@ -313,7 +312,7 @@ public class ZLMRTPServerFactory {
313 (MediaServerItem mediaServerItem, HookParam hookParam)->{ 312 (MediaServerItem mediaServerItem, HookParam hookParam)->{
314 logger.info("[上级点播] {}->监听端口到期继续保持监听: {}", ssrc, finalLocalPort); 313 logger.info("[上级点播] {}->监听端口到期继续保持监听: {}", ssrc, finalLocalPort);
315 OnRtpServerTimeoutHookParam rtpServerTimeoutHookParam = (OnRtpServerTimeoutHookParam) hookParam; 314 OnRtpServerTimeoutHookParam rtpServerTimeoutHookParam = (OnRtpServerTimeoutHookParam) hookParam;
316 - if (ssrc.equals(rtpServerTimeoutHookParam.getSsrc())) { 315 + if (ssrc.equals(rtpServerTimeoutHookParam.getStream_id())) {
317 if (keepPortCallback.keep(ssrc)) { 316 if (keepPortCallback.keep(ssrc)) {
318 logger.info("[上级点播] {}->监听端口到期继续保持监听", ssrc); 317 logger.info("[上级点播] {}->监听端口到期继续保持监听", ssrc);
319 keepPort(serverItem, ssrc, finalLocalPort, keepPortCallback); 318 keepPort(serverItem, ssrc, finalLocalPort, keepPortCallback);
@@ -337,11 +336,6 @@ public class ZLMRTPServerFactory { @@ -337,11 +336,6 @@ public class ZLMRTPServerFactory {
337 public boolean releasePort(MediaServerItem serverItem, String ssrc) { 336 public boolean releasePort(MediaServerItem serverItem, String ssrc) {
338 logger.info("[保持端口] {}->释放监听端口", ssrc); 337 logger.info("[保持端口] {}->释放监听端口", ssrc);
339 boolean closeRTPServerResult = closeRtpServer(serverItem, ssrc); 338 boolean closeRTPServerResult = closeRtpServer(serverItem, ssrc);
340 - try {  
341 - Thread.sleep(1000);  
342 - } catch (InterruptedException e) {  
343 - throw new RuntimeException(e);  
344 - }  
345 HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, serverItem.getId()); 339 HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, serverItem.getId());
346 // 订阅 zlm启动事件, 新的zlm也会从这里进入系统 340 // 订阅 zlm启动事件, 新的zlm也会从这里进入系统
347 hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout); 341 hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout);
@@ -359,6 +353,11 @@ public class ZLMRTPServerFactory { @@ -359,6 +353,11 @@ public class ZLMRTPServerFactory {
359 * 调用zlm RESTFUL API —— startSendRtpPassive 353 * 调用zlm RESTFUL API —— startSendRtpPassive
360 */ 354 */
361 public JSONObject startSendRtpPassive(MediaServerItem mediaServerItem, Map<String, Object>param) { 355 public JSONObject startSendRtpPassive(MediaServerItem mediaServerItem, Map<String, Object>param) {
  356 + System.out.println("=====================");
  357 + for (String s : param.keySet()) {
  358 + System.out.println(s + ": " + param.get(s));
  359 + }
  360 + System.out.println("=========END============");
362 return zlmresTfulUtils.startSendRtpPassive(mediaServerItem, param); 361 return zlmresTfulUtils.startSendRtpPassive(mediaServerItem, param);
363 } 362 }
364 363
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
@@ -1467,14 +1467,18 @@ public class PlayServiceImpl implements IPlayService { @@ -1467,14 +1467,18 @@ public class PlayServiceImpl implements IPlayService {
1467 // 如果是严格模式,需要关闭端口占用 1467 // 如果是严格模式,需要关闭端口占用
1468 JSONObject startSendRtpStreamResult = null; 1468 JSONObject startSendRtpStreamResult = null;
1469 if (sendRtpItem.getLocalPort() != 0) { 1469 if (sendRtpItem.getLocalPort() != 0) {
1470 - zlmrtpServerFactory.releasePort(mediaInfo, sendRtpItem.getSsrc());  
1471 - if (sendRtpItem.isTcpActive()) {  
1472 - startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param);  
1473 - } else {  
1474 - param.put("dst_url", sendRtpItem.getIp());  
1475 - param.put("dst_port", sendRtpItem.getPort());  
1476 - startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param); 1470 + if (zlmrtpServerFactory.releasePort(mediaInfo, sendRtpItem.getSsrc())) {
  1471 + if (sendRtpItem.isTcpActive()) {
  1472 + startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param);
  1473 + } else {
  1474 + param.put("dst_url", sendRtpItem.getIp());
  1475 + param.put("dst_port", sendRtpItem.getPort());
  1476 + startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
  1477 + }
  1478 + }else {
  1479 + // TODO 释放失败的处理
1477 } 1480 }
  1481 +
1478 } else { 1482 } else {
1479 if (sendRtpItem.isTcpActive()) { 1483 if (sendRtpItem.isTcpActive()) {
1480 startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param); 1484 startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param);