Commit 74ad4235f1738ea8ca954bd396a35ddf90a6e37b
1 parent
fb90dfda
修复tcp主动的推流
Showing
2 changed files
with
17 additions
and
14 deletions
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
| ... | ... | @@ -302,7 +302,6 @@ public class ZLMRTPServerFactory { |
| 302 | 302 | param.put("port", localPort); |
| 303 | 303 | param.put("enable_tcp", 1); |
| 304 | 304 | param.put("stream_id", ssrc); |
| 305 | - param.put("re_use_port", 1); | |
| 306 | 305 | JSONObject jsonObject = zlmresTfulUtils.openRtpServer(serverItem, param); |
| 307 | 306 | if (jsonObject.getInteger("code") == 0) { |
| 308 | 307 | localPort = jsonObject.getInteger("port"); |
| ... | ... | @@ -313,7 +312,7 @@ public class ZLMRTPServerFactory { |
| 313 | 312 | (MediaServerItem mediaServerItem, HookParam hookParam)->{ |
| 314 | 313 | logger.info("[上级点播] {}->监听端口到期继续保持监听: {}", ssrc, finalLocalPort); |
| 315 | 314 | OnRtpServerTimeoutHookParam rtpServerTimeoutHookParam = (OnRtpServerTimeoutHookParam) hookParam; |
| 316 | - if (ssrc.equals(rtpServerTimeoutHookParam.getSsrc())) { | |
| 315 | + if (ssrc.equals(rtpServerTimeoutHookParam.getStream_id())) { | |
| 317 | 316 | if (keepPortCallback.keep(ssrc)) { |
| 318 | 317 | logger.info("[上级点播] {}->监听端口到期继续保持监听", ssrc); |
| 319 | 318 | keepPort(serverItem, ssrc, finalLocalPort, keepPortCallback); |
| ... | ... | @@ -337,11 +336,6 @@ public class ZLMRTPServerFactory { |
| 337 | 336 | public boolean releasePort(MediaServerItem serverItem, String ssrc) { |
| 338 | 337 | logger.info("[保持端口] {}->释放监听端口", ssrc); |
| 339 | 338 | boolean closeRTPServerResult = closeRtpServer(serverItem, ssrc); |
| 340 | - try { | |
| 341 | - Thread.sleep(1000); | |
| 342 | - } catch (InterruptedException e) { | |
| 343 | - throw new RuntimeException(e); | |
| 344 | - } | |
| 345 | 339 | HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, serverItem.getId()); |
| 346 | 340 | // 订阅 zlm启动事件, 新的zlm也会从这里进入系统 |
| 347 | 341 | hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout); |
| ... | ... | @@ -359,6 +353,11 @@ public class ZLMRTPServerFactory { |
| 359 | 353 | * 调用zlm RESTFUL API —— startSendRtpPassive |
| 360 | 354 | */ |
| 361 | 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 | 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 | 1467 | // 如果是严格模式,需要关闭端口占用 |
| 1468 | 1468 | JSONObject startSendRtpStreamResult = null; |
| 1469 | 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 | 1482 | } else { |
| 1479 | 1483 | if (sendRtpItem.isTcpActive()) { |
| 1480 | 1484 | startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param); | ... | ... |