From 66eda32ab97d6e94e9f274d6faa4df586c452dfb Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期日, 25 六月 2023 10:18:29 +0800
Subject: [PATCH] 优化端口预占用
---
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java | 25 +++++++++++++++----------
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java | 2 +-
2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
index 7fef8ee..0d4b113 100644
--- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
@@ -228,7 +228,7 @@
int localPort = 0;
if (userSetting.getGbSendStreamStrict()) {
if (userSetting.getGbSendStreamStrict()) {
- localPort = keepPort(serverItem, ssrc);
+ localPort = keepPort(serverItem, ssrc, null);
if (localPort == 0) {
return null;
}
@@ -264,7 +264,7 @@
// 榛樿涓洪殢鏈虹鍙�
int localPort = 0;
if (userSetting.getGbSendStreamStrict()) {
- localPort = keepPort(serverItem, ssrc);
+ localPort = keepPort(serverItem, ssrc, null);
if (localPort == 0) {
return null;
}
@@ -288,23 +288,28 @@
/**
* 淇濇寔绔彛锛岀洿鍒伴渶瑕侀渶瑕佸彂娴佹椂鍐嶉噴鏀�
*/
- public int keepPort(MediaServerItem serverItem, String ssrc) {
- int localPort = 0;
+ public int keepPort(MediaServerItem serverItem, String ssrc, Integer localPort) {
Map<String, Object> param = new HashMap<>(3);
- param.put("port", 0);
+ if (localPort == null) {
+ localPort = 0;
+ }
+ param.put("port", localPort);
param.put("enable_tcp", 1);
param.put("stream_id", ssrc);
JSONObject jsonObject = zlmresTfulUtils.openRtpServer(serverItem, param);
if (jsonObject.getInteger("code") == 0) {
localPort = jsonObject.getInteger("port");
HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, serverItem.getId());
+ Integer finalLocalPort = localPort;
hookSubscribe.addSubscribe(hookSubscribeForRtpServerTimeout,
(MediaServerItem mediaServerItem, JSONObject response)->{
- logger.info("[涓婄骇鐐规挱] {}->鐩戝惉绔彛鍒版湡缁х画淇濇寔鐩戝惉", ssrc);
- int port = keepPort(serverItem, ssrc);
- if (port == 0) {
- logger.info("[涓婄骇鐐规挱] {}->鐩戝惉绔彛澶辫触锛岀Щ闄ょ洃鍚�", ssrc);
- hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout);
+ if (ssrc.equals(response.getString("ssrc"))) {
+ logger.info("[涓婄骇鐐规挱] {}->鐩戝惉绔彛鍒版湡缁х画淇濇寔鐩戝惉", ssrc);
+ int port = keepPort(serverItem, ssrc, finalLocalPort);
+ if (port == 0) {
+ logger.info("[涓婄骇鐐规挱] {}->鐩戝惉绔彛澶辫触锛岀Щ闄ょ洃鍚�", ssrc);
+ hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout);
+ }
}
});
logger.info("[淇濇寔绔彛] {}->鐩戝惉绔彛: {}", ssrc, localPort);
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
index be9d3b1..38811c2 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
@@ -235,7 +235,7 @@
sendRtpItem.setReceiveStream(stream + "_talk");
- int port = zlmrtpServerFactory.keepPort(mediaServerItem, playSsrc);
+ int port = zlmrtpServerFactory.keepPort(mediaServerItem, playSsrc, null);
//绔彛鑾峰彇澶辫触鐨剆srcInfo 娌℃湁蹇呰鍙戦�佺偣鎾寚浠�
if (port <= 0) {
logger.info("[璇煶瀵硅] 绔彛鍒嗛厤寮傚父锛宒eviceId={},channelId={}", device.getDeviceId(), channelId);
--
Gitblit v1.8.0