From 04e7f48fde1b1a653d413eb41186ec7354f5ae31 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期一, 10 七月 2023 14:30:59 +0800
Subject: [PATCH] 合并主线的发流端口管理逻辑
---
src/main/java/com/genersoft/iot/vmp/vmanager/bean/OtherRtpSendInfo.java | 2
src/main/java/com/genersoft/iot/vmp/media/zlm/SendRtpPortManager.java | 55 ++++++
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java | 130 +---------------
src/main/java/com/genersoft/iot/vmp/vmanager/rtp/RtpController.java | 55 +-----
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/HookResultForOnPublish.java | 10 +
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/AckRequestProcessor.java | 10 -
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java | 11 +
web_src/src/components/dialog/MediaServerEdit.vue | 21 ++
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java | 16 -
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaSendRtpPortInfo.java | 50 ++++++
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java | 30 +--
src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java | 4
src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java | 11 +
sql/2.6.8补丁更新.sql | 2
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java | 38 ++++
src/main/java/com/genersoft/iot/vmp/service/redisMsg/RedisGbPlayMsgListener.java | 4
16 files changed, 234 insertions(+), 215 deletions(-)
diff --git "a/sql/2.6.8\350\241\245\344\270\201\346\233\264\346\226\260.sql" "b/sql/2.6.8\350\241\245\344\270\201\346\233\264\346\226\260.sql"
new file mode 100644
index 0000000..8ce9d54
--- /dev/null
+++ "b/sql/2.6.8\350\241\245\344\270\201\346\233\264\346\226\260.sql"
@@ -0,0 +1,2 @@
+alter table media_server
+ add sendRtpPortRange varchar(50) not null;
\ No newline at end of file
diff --git a/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java
index fa12679..cd22880 100644
--- a/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java
+++ b/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java
@@ -75,6 +75,9 @@
@Value("${media.rtp.port-range}")
private String rtpPortRange;
+ @Value("${media.rtp.send-port-range}")
+ private String rtpSendPortRange;
+
@Value("${media.record-assist-port:0}")
private Integer recordAssistPort = 0;
@@ -206,6 +209,7 @@
mediaServerItem.setSecret(secret);
mediaServerItem.setRtpEnable(rtpEnable);
mediaServerItem.setRtpPortRange(rtpPortRange);
+ mediaServerItem.setSendRtpPortRange(rtpSendPortRange);
mediaServerItem.setRecordAssistPort(recordAssistPort);
mediaServerItem.setHookAliveInterval(30.00f);
@@ -222,4 +226,11 @@
return false;
}
+ public String getRtpSendPortRange() {
+ return rtpSendPortRange;
+ }
+
+ public void setRtpSendPortRange(String rtpSendPortRange) {
+ this.rtpSendPortRange = rtpSendPortRange;
+ }
}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/AckRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/AckRequestProcessor.java
index f40e0c8..e7091fb 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/AckRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/AckRequestProcessor.java
@@ -140,15 +140,7 @@
startSendRtpStreamHand(evt, sendRtpItem, parentPlatform, jsonObject, param, callIdHeader);
});
}else {
- // 濡傛灉鏄潪涓ユ牸妯″紡锛岄渶瑕佸叧闂鍙e崰鐢�
- JSONObject startSendRtpStreamResult = null;
- if (sendRtpItem.getLocalPort() != 0) {
- if (zlmrtpServerFactory.releasePort(mediaInfo, sendRtpItem.getSsrc())) {
- startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
- }
- }else {
- startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
- }
+ JSONObject startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
if (startSendRtpStreamResult != null) {
startSendRtpStreamHand(evt, sendRtpItem, parentPlatform, startSendRtpStreamResult, param, callIdHeader);
}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
index b7f600f..073720a 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
@@ -349,9 +349,7 @@
}
logger.info("[涓婄骇Invite] {}, 骞冲彴锛歿}锛� 閫氶亾锛歿}, 鏀舵祦鍦板潃锛歿}:{}锛屾敹娴佹柟寮忥細{}, ssrc锛歿}", sessionName, username, channelId, addressStr, port, streamTypeStr, ssrc);
SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId,
- device.getDeviceId(), channelId, mediaTransmissionTCP, platform.isRtcp(), ssrcFromCallback -> {
- return redisCatchStorage.querySendRTPServer(platform.getServerGBId(), channelId, null, callIdHeader.getCallId()) != null;
- });
+ device.getDeviceId(), channelId, mediaTransmissionTCP, platform.isRtcp());
if (tcpActive != null) {
sendRtpItem.setTcpActive(tcpActive);
@@ -553,9 +551,7 @@
if (streamReady) {
// 鑷钩鍙板唴瀹�
SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId,
- gbStream.getApp(), gbStream.getStream(), channelId, mediaTransmissionTCP, platform.isRtcp(), ssrcFromCallback ->{
- return redisCatchStorage.querySendRTPServer(platform.getServerGBId(), channelId, null, callIdHeader.getCallId()) != null;
- });
+ gbStream.getApp(), gbStream.getStream(), channelId, mediaTransmissionTCP, platform.isRtcp());
if (sendRtpItem == null) {
logger.warn("鏈嶅姟鍣ㄧ鍙h祫婧愪笉瓒�");
@@ -594,9 +590,7 @@
if (streamReady) {
// 鑷钩鍙板唴瀹�
SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId,
- gbStream.getApp(), gbStream.getStream(), channelId, mediaTransmissionTCP, platform.isRtcp(), ssrcFromCallback ->{
- return redisCatchStorage.querySendRTPServer(platform.getServerGBId(), channelId, null, callIdHeader.getCallId()) != null;
- });
+ gbStream.getApp(), gbStream.getStream(), channelId, mediaTransmissionTCP, platform.isRtcp());
if (sendRtpItem == null) {
logger.warn("鏈嶅姟鍣ㄧ鍙h祫婧愪笉瓒�");
@@ -713,9 +707,7 @@
dynamicTask.stop(callIdHeader.getCallId());
if (serverId.equals(userSetting.getServerId())) {
SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, finalPort, ssrc, requesterId,
- app, stream, channelId, mediaTransmissionTCP, platform.isRtcp(), ssrcFromCallback -> {
- return redisCatchStorage.querySendRTPServer(platform.getServerGBId(), channelId, null, callIdHeader.getCallId()) != null;
- });
+ app, stream, channelId, mediaTransmissionTCP, platform.isRtcp());
if (sendRtpItem == null) {
logger.warn("涓婄骇鐐规椂鍒涘缓sendRTPItem澶辫触锛屽彲鑳芥槸鏈嶅姟鍣ㄧ鍙h祫婧愪笉瓒�");
diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/SendRtpPortManager.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/SendRtpPortManager.java
new file mode 100644
index 0000000..8366a4a
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/SendRtpPortManager.java
@@ -0,0 +1,55 @@
+package com.genersoft.iot.vmp.media.zlm;
+
+import com.genersoft.iot.vmp.conf.UserSetting;
+import com.genersoft.iot.vmp.media.zlm.dto.MediaSendRtpPortInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SendRtpPortManager {
+
+ private final static Logger logger = LoggerFactory.getLogger(SendRtpPortManager.class);
+
+ @Autowired
+ private UserSetting userSetting;
+
+ @Autowired
+ private RedisTemplate<Object, Object> redisTemplate;
+
+ private final String KEY = "VM_MEDIA_SEND_RTP_PORT_RANGE_";
+
+
+ public void initServerPort(String mediaServerId, int startPort, int endPort){
+ String key = KEY + userSetting.getServerId() + "_" + mediaServerId;
+ MediaSendRtpPortInfo mediaSendRtpPortInfo = new MediaSendRtpPortInfo(startPort, endPort, mediaServerId);
+ redisTemplate.opsForValue().set(key, mediaSendRtpPortInfo);
+ }
+
+ public int getNextPort(String mediaServerId) {
+ String key = KEY + userSetting.getServerId() + "_" + mediaServerId;
+ MediaSendRtpPortInfo mediaSendRtpPortInfo = (MediaSendRtpPortInfo)redisTemplate.opsForValue().get(key);
+ if (mediaSendRtpPortInfo == null) {
+ logger.warn("[鍙戦�佺鍙g鐞哴 鑾峰彇{}鐨勫彂閫佺鍙f椂鏈壘鍒扮鍙d俊鎭�", mediaSendRtpPortInfo);
+ return 0;
+ }
+ int port;
+ if (mediaSendRtpPortInfo.getCurrent() %2 != 0) {
+ port = mediaSendRtpPortInfo.getCurrent() + 1;
+ }else {
+ port = mediaSendRtpPortInfo.getCurrent() + 2;
+ }
+ if (port > mediaSendRtpPortInfo.getEnd()) {
+ if (mediaSendRtpPortInfo.getStart() %2 != 0) {
+ port = mediaSendRtpPortInfo.getStart() + 1;
+ }else {
+ port = mediaSendRtpPortInfo.getStart();
+ }
+ }
+ mediaSendRtpPortInfo.setCurrent(port);
+ redisTemplate.opsForValue().set(key, mediaSendRtpPortInfo);
+ return port;
+ }
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
index 5df3be4..d23c6c7 100644
--- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
@@ -23,7 +23,6 @@
import com.genersoft.iot.vmp.service.bean.MessageForPushChannel;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
-import com.genersoft.iot.vmp.utils.redis.RedisUtil;
import com.genersoft.iot.vmp.vmanager.bean.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -223,9 +222,6 @@
HookResultForOnPublish result = HookResultForOnPublish.SUCCESS();
- if (!"rtp".equals(param.getApp())) {
- result.setEnable_audio(true);
- }
taskExecutor.execute(() -> {
ZlmHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_publish, json);
@@ -259,20 +255,6 @@
}
}
- String receiveKey = VideoManagerConstants.WVP_OTHER_RECEIVE_RTP_INFO + userSetting.getServerId() + "*";
- // 灏嗕俊鎭啓鍏edis涓紝浠ュ鍚庣敤
- List<Object> scan = RedisUtil.scan(redisTemplate, receiveKey);
- if (scan.size()>0) {
- for (Object o : scan) {
- String key = (String) o;
- OtherRtpSendInfo otherRtpSendInfo = (OtherRtpSendInfo)redisTemplate.opsForValue().get(key);
- if (otherRtpSendInfo != null && otherRtpSendInfo.getStream().equalsIgnoreCase(param.getStream())) {
- result.setEnable_audio(true);
- result.setEnable_mp4(true);
- }
- }
- }
-
if (mediaInfo.getRecordAssistPort() > 0 && userSetting.getRecordPath() == null) {
logger.info("鎺ㄦ祦鏃跺彂鐜板皻鏈缃綍鍍忚矾寰勶紝浠巃ssist鏈嶅姟涓鍙�");
JSONObject info = assistRESTfulUtils.getInfo(mediaInfo, null);
@@ -291,6 +273,18 @@
}
}
}
+ if (param.getApp().equalsIgnoreCase("rtp")) {
+ String receiveKey = VideoManagerConstants.WVP_OTHER_RECEIVE_RTP_INFO + userSetting.getServerId() + "_" + param.getStream();
+ System.out.println(receiveKey);
+ OtherRtpSendInfo otherRtpSendInfo = (OtherRtpSendInfo)redisTemplate.opsForValue().get(receiveKey);
+ System.out.println("otherRtpSendInfo != null ====>" + (otherRtpSendInfo != null));
+ if (otherRtpSendInfo != null) {
+ System.out.println("otherRtpSendInfo != null");
+ result.setEnable_audio(true);
+ result.setEnable_mp4(true);
+ }
+ }
+ logger.info("[ZLM HOOK]鎺ㄦ祦閴存潈 鍝嶅簲锛歿}->{}->>>>{}", param.getMediaServerId(), param, result);
return result;
}
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 9c5a472..af4b391 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
@@ -1,20 +1,18 @@
package com.genersoft.iot.vmp.media.zlm;
import com.alibaba.fastjson2.JSON;
-import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.genersoft.iot.vmp.common.CommonCallback;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
-import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory;
-import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForRtpServerTimeout;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Map;
@Component
public class ZLMRTPServerFactory {
@@ -30,68 +28,8 @@
@Autowired
private ZlmHttpHookSubscribe hookSubscribe;
- private int[] portRangeArray = new int[2];
-
- public int getFreePort(MediaServerItem mediaServerItem, int startPort, int endPort, List<Integer> usedFreelist) {
- if (endPort <= startPort) {
- return -1;
- }
- if (usedFreelist == null) {
- usedFreelist = new ArrayList<>();
- }
- JSONObject listRtpServerJsonResult = zlmresTfulUtils.listRtpServer(mediaServerItem);
- if (listRtpServerJsonResult != null) {
- JSONArray data = listRtpServerJsonResult.getJSONArray("data");
- if (data != null) {
- for (int i = 0; i < data.size(); i++) {
- JSONObject dataItem = data.getJSONObject(i);
- usedFreelist.add(dataItem.getInteger("port"));
- }
- }
- }
-
- Map<String, Object> param = new HashMap<>();
- int result = -1;
- // 璁剧疆鎺ㄦ祦绔彛
- if (startPort%2 == 1) {
- startPort ++;
- }
- boolean checkPort = false;
- for (int i = startPort; i < endPort + 1; i+=2) {
- if (!usedFreelist.contains(i)){
- checkPort = true;
- startPort = i;
- break;
- }
- }
- if (!checkPort) {
- logger.warn("鏈壘鍒拌妭鐐箋}涓婅寖鍥碵{}-{}]鐨勭┖闂茬鍙�", mediaServerItem.getId(), startPort, endPort);
- return -1;
- }
- param.put("port", startPort);
- String stream = UUID.randomUUID().toString();
- param.put("enable_tcp", 1);
- param.put("stream_id", stream);
-// param.put("port", 0);
- JSONObject openRtpServerResultJson = zlmresTfulUtils.openRtpServer(mediaServerItem, param);
-
- if (openRtpServerResultJson != null) {
- if (openRtpServerResultJson.getInteger("code") == 0) {
- result= openRtpServerResultJson.getInteger("port");
- Map<String, Object> closeRtpServerParam = new HashMap<>();
- closeRtpServerParam.put("stream_id", stream);
- zlmresTfulUtils.closeRtpServer(mediaServerItem, closeRtpServerParam);
- }else {
- usedFreelist.add(startPort);
- startPort +=2;
- result = getFreePort(mediaServerItem, startPort, endPort,usedFreelist);
- }
- }else {
- // 妫�鏌LM鐘舵��
- logger.error("鍒涘缓RTP Server 澶辫触 {}: 璇锋鏌LM鏈嶅姟", param.get("port"));
- }
- return result;
- }
+ @Autowired
+ private SendRtpPortManager sendRtpPortManager;
/**
* 寮�鍚痳tpServer
@@ -220,13 +158,13 @@
* @return SendRtpItem
*/
public SendRtpItem createSendRtpItem(MediaServerItem serverItem, String ip, int port, String ssrc, String platformId,
- String deviceId, String channelId, boolean tcp, boolean rtcp, KeepPortCallback callback){
+ String deviceId, String channelId, boolean tcp, boolean rtcp){
// 榛樿涓洪殢鏈虹鍙�
int localPort = 0;
if (userSetting.getGbSendStreamStrict()) {
if (userSetting.getGbSendStreamStrict()) {
- localPort = keepPort(serverItem, ssrc, localPort, callback);
+ localPort = sendRtpPortManager.getNextPort(serverItem.getId());
if (localPort == 0) {
return null;
}
@@ -259,11 +197,11 @@
* @return SendRtpItem
*/
public SendRtpItem createSendRtpItem(MediaServerItem serverItem, String ip, int port, String ssrc, String platformId,
- String app, String stream, String channelId, boolean tcp, boolean rtcp, KeepPortCallback callback){
+ String app, String stream, String channelId, boolean tcp, boolean rtcp){
// 榛樿涓洪殢鏈虹鍙�
int localPort = 0;
if (userSetting.getGbSendStreamStrict()) {
- localPort = keepPort(serverItem, ssrc, localPort, callback);
+ localPort = sendRtpPortManager.getNextPort(serverItem.getId());
if (localPort == 0) {
return null;
}
@@ -282,58 +220,6 @@
sendRtpItem.setMediaServerId(serverItem.getId());
sendRtpItem.setRtcp(rtcp);
return sendRtpItem;
- }
-
- public interface KeepPortCallback{
- Boolean keep(String ssrc);
- }
-
- /**
- * 淇濇寔绔彛锛岀洿鍒伴渶瑕侀渶瑕佸彂娴佹椂鍐嶉噴鏀�
- */
- public int keepPort(MediaServerItem serverItem, String ssrc, int localPort, KeepPortCallback keepPortCallback) {
- Map<String, Object> param = new HashMap<>(3);
- 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());
- // 璁㈤槄 zlm鍚姩浜嬩欢, 鏂扮殑zlm涔熶細浠庤繖閲岃繘鍏ョ郴缁�
- Integer finalLocalPort = localPort;
- hookSubscribe.addSubscribe(hookSubscribeForRtpServerTimeout,
- (MediaServerItem mediaServerItem, JSONObject response)->{
- System.out.println("鐩戝惉绔彛鍒版湡缁х画淇濇寔鐩戝惉");
- System.out.println(response);
- if (ssrc.equals(response.getString("stream_id"))) {
- if (keepPortCallback.keep(ssrc)) {
- logger.info("[涓婄骇鐐规挱] {}->鐩戝惉绔彛鍒版湡缁х画淇濇寔鐩戝惉", ssrc);
- keepPort(serverItem, ssrc, finalLocalPort, keepPortCallback);
- }else {
- logger.info("[涓婄骇鐐规挱] {}->鍙戦�佸彇娑堬紝鏃犻渶缁х画鐩戝惉", ssrc);
- releasePort(serverItem, ssrc);
- }
- }
-
- });
- logger.info("[涓婄骇鐐规挱] {}->鐩戝惉绔彛: {}", ssrc, localPort);
- }else {
- logger.info("[涓婄骇鐐规挱] 鐩戝惉绔彛澶辫触: {}", ssrc);
- }
- return localPort;
- }
-
- /**
- * 閲婃斁淇濇寔鐨勭鍙�
- */
- public boolean releasePort(MediaServerItem serverItem, String ssrc) {
- logger.info("[涓婄骇鐐规挱] {}->閲婃斁鐩戝惉绔彛", ssrc);
- boolean closeRTPServerResult = closeRtpServer(serverItem, ssrc);
- HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, serverItem.getId());
- // 璁㈤槄 zlm鍚姩浜嬩欢, 鏂扮殑zlm涔熶細浠庤繖閲岃繘鍏ョ郴缁�
- hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout);
- return closeRTPServerResult;
}
/**
diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaSendRtpPortInfo.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaSendRtpPortInfo.java
new file mode 100644
index 0000000..2e9f631
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaSendRtpPortInfo.java
@@ -0,0 +1,50 @@
+package com.genersoft.iot.vmp.media.zlm.dto;
+
+public class MediaSendRtpPortInfo {
+
+ private int start;
+ private int end;
+ private String mediaServerId;
+
+ private int current;
+
+
+ public MediaSendRtpPortInfo(int start, int end, String mediaServerId) {
+ this.start = start;
+ this.current = start;
+ this.end = end;
+ this.mediaServerId = mediaServerId;
+ }
+
+ public int getStart() {
+ return start;
+ }
+
+ public void setStart(int start) {
+ this.start = start;
+ }
+
+ public int getEnd() {
+ return end;
+ }
+
+ public void setEnd(int end) {
+ this.end = end;
+ }
+
+ public String getMediaServerId() {
+ return mediaServerId;
+ }
+
+ public void setMediaServerId(String mediaServerId) {
+ this.mediaServerId = mediaServerId;
+ }
+
+ public int getCurrent() {
+ return current;
+ }
+
+ public void setCurrent(int current) {
+ this.current = current;
+ }
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java
index e6bbb5f..066a677 100644
--- a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java
@@ -62,6 +62,9 @@
@Schema(description = "澶氱鍙TP鏀舵祦绔彛鑼冨洿")
private String rtpPortRange;
+ @Schema(description = "RTP鍙戞祦绔彛鑼冨洿")
+ private String sendRtpPortRange;
+
@Schema(description = "assist鏈嶅姟绔彛")
private int recordAssistPort;
@@ -297,4 +300,12 @@
public void setHookAliveInterval(Float hookAliveInterval) {
this.hookAliveInterval = hookAliveInterval;
}
+
+ public String getSendRtpPortRange() {
+ return sendRtpPortRange;
+ }
+
+ public void setSendRtpPortRange(String sendRtpPortRange) {
+ this.sendRtpPortRange = sendRtpPortRange;
+ }
}
diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/HookResultForOnPublish.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/HookResultForOnPublish.java
index cb8e738..68d969f 100644
--- a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/HookResultForOnPublish.java
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/HookResultForOnPublish.java
@@ -50,4 +50,14 @@
public void setMp4_save_path(String mp4_save_path) {
this.mp4_save_path = mp4_save_path;
}
+
+ @Override
+ public String toString() {
+ return "HookResultForOnPublish{" +
+ "enable_audio=" + enable_audio +
+ ", enable_mp4=" + enable_mp4 +
+ ", mp4_max_second=" + mp4_max_second +
+ ", mp4_save_path='" + mp4_save_path + '\'' +
+ '}';
+ }
}
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
index eaa6a9f..789974b 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
@@ -11,10 +11,7 @@
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
import com.genersoft.iot.vmp.gb28181.session.SSRCFactory;
-import com.genersoft.iot.vmp.media.zlm.AssistRESTfulUtils;
-import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
-import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
-import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
+import com.genersoft.iot.vmp.media.zlm.*;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.media.zlm.dto.ServerKeepaliveData;
import com.genersoft.iot.vmp.service.IMediaServerService;
@@ -70,6 +67,10 @@
private UserSetting userSetting;
@Autowired
+ private SendRtpPortManager sendRtpPortManager;
+
+
+ @Autowired
private AssistRESTfulUtils assistRESTfulUtils;
@Autowired
@@ -115,13 +116,40 @@
if (ssrcFactory.hasMediaServerSSRC(mediaServerItem.getId())) {
ssrcFactory.initMediaServerSSRC(mediaServerItem.getId(), null);
}
+ if (userSetting.getGbSendStreamStrict()) {
+ int startPort = 50000;
+ int endPort = 60000;
+ String sendRtpPortRange = mediaServerItem.getSendRtpPortRange();
+ if (sendRtpPortRange == null) {
+ logger.warn("[zlm] ] 鏈厤缃彂娴佺鍙h寖鍥达紝榛樿浣跨敤50000鍒�60000");
+ }else {
+ String[] sendRtpPortRangeArray = sendRtpPortRange.trim().split(",");
+ if (sendRtpPortRangeArray.length != 2) {
+ logger.warn("[zlm] ] 鍙戞祦绔彛鑼冨洿閿欒锛岄粯璁や娇鐢�50000鍒�60000");
+ }else {
+ try {
+ startPort = Integer.parseInt(sendRtpPortRangeArray[0]);
+ endPort = Integer.parseInt(sendRtpPortRangeArray[1]);
+ if (endPort <= startPort) {
+ logger.warn("[zlm] ] 鍙戞祦绔彛鑼冨洿閿欒锛岀粨鏉熺鍙e簲澶т簬寮�濮嬬鍙�,浣跨敤榛樿绔彛");
+ startPort = 50000;
+ endPort = 60000;
+ }
+
+ }catch (NumberFormatException e) {
+ logger.warn("[zlm] ] 鍙戞祦绔彛鑼冨洿閿欒锛岄粯璁や娇鐢�50000鍒�60000");
+ }
+ }
+ }
+ logger.info("[[zlm] ] 閰嶇疆鍙戞祦绔彛鑼冨洿锛寋}-{}", startPort, endPort);
+ sendRtpPortManager.initServerPort(mediaServerItem.getId(), startPort, endPort);
+ }
// 鏌ヨredis鏄惁瀛樺湪姝ediaServer
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + mediaServerItem.getId();
Boolean hasKey = redisTemplate.hasKey(key);
if (hasKey != null && ! hasKey) {
redisTemplate.opsForValue().set(key, mediaServerItem);
}
-
}
}
diff --git a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/RedisGbPlayMsgListener.java b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/RedisGbPlayMsgListener.java
index 8231fb3..33eb5c1 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/RedisGbPlayMsgListener.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/RedisGbPlayMsgListener.java
@@ -317,9 +317,7 @@
SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, content.getIp(),
content.getPort(), content.getSsrc(), content.getPlatformId(),
content.getApp(), content.getStream(), content.getChannelId(),
- content.getTcp(), content.getRtcp(), ssrcFromCallback -> {
- return querySendRTPServer(content.getPlatformId(), content.getChannelId(), content.getStream(), null) != null;
- });
+ content.getTcp(), content.getRtcp());
WVPResult<ResponseSendItemMsg> result = new WVPResult<>();
result.setCode(0);
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java
index 97e74ae..e222ba8 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java
@@ -28,6 +28,7 @@
"secret, " +
"rtpEnable, " +
"rtpPortRange, " +
+ "sendRtpPortRange, " +
"recordAssistPort, " +
"defaultServer, " +
"createTime, " +
@@ -51,6 +52,7 @@
"#{secret}, " +
"#{rtpEnable}, " +
"#{rtpPortRange}, " +
+ "#{sendRtpPortRange}, " +
"#{recordAssistPort}, " +
"#{defaultServer}, " +
"#{createTime}, " +
@@ -75,6 +77,7 @@
"<if test=\"autoConfig != null\">, autoConfig=#{autoConfig}</if>" +
"<if test=\"rtpEnable != null\">, rtpEnable=#{rtpEnable}</if>" +
"<if test=\"rtpPortRange != null\">, rtpPortRange=#{rtpPortRange}</if>" +
+ "<if test=\"sendRtpPortRange != null\">, sendRtpPortRange=#{sendRtpPortRange}</if>" +
"<if test=\"secret != null\">, secret=#{secret}</if>" +
"<if test=\"recordAssistPort != null\">, recordAssistPort=#{recordAssistPort}</if>" +
"<if test=\"hookAliveInterval != null\">, hookAliveInterval=#{hookAliveInterval}</if>" +
@@ -98,6 +101,7 @@
"<if test=\"autoConfig != null\">, autoConfig=#{autoConfig}</if>" +
"<if test=\"rtpEnable != null\">, rtpEnable=#{rtpEnable}</if>" +
"<if test=\"rtpPortRange != null\">, rtpPortRange=#{rtpPortRange}</if>" +
+ "<if test=\"sendRtpPortRange != null\">, sendRtpPortRange=#{sendRtpPortRange}</if>" +
"<if test=\"secret != null\">, secret=#{secret}</if>" +
"<if test=\"recordAssistPort != null\">, recordAssistPort=#{recordAssistPort}</if>" +
"<if test=\"hookAliveInterval != null\">, hookAliveInterval=#{hookAliveInterval}</if>" +
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/bean/OtherRtpSendInfo.java b/src/main/java/com/genersoft/iot/vmp/vmanager/bean/OtherRtpSendInfo.java
index 225e40c..9fea5c5 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/bean/OtherRtpSendInfo.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/bean/OtherRtpSendInfo.java
@@ -124,7 +124,7 @@
@Override
public String toString() {
return "OtherRtpSendInfo{" +
- "ip='" + ip + '\'' +
+ " ip='" + ip + '\'' +
", port=" + port +
", receiveIp='" + receiveIp + '\'' +
", receivePort=" + receivePort +
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/rtp/RtpController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/rtp/RtpController.java
index c06c4af..ad021ba 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/rtp/RtpController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/rtp/RtpController.java
@@ -3,20 +3,16 @@
import com.alibaba.fastjson2.JSONObject;
import com.genersoft.iot.vmp.common.VideoManagerConstants;
import com.genersoft.iot.vmp.conf.DynamicTask;
-import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.conf.UserSetting;
-import com.genersoft.iot.vmp.conf.VersionInfo;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
+import com.genersoft.iot.vmp.media.zlm.SendRtpPortManager;
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory;
import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForRtpServerTimeout;
import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
-import com.genersoft.iot.vmp.service.IDeviceChannelService;
-import com.genersoft.iot.vmp.service.IDeviceService;
import com.genersoft.iot.vmp.service.IMediaServerService;
-import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.OtherRtpSendInfo;
import io.swagger.v3.oas.annotations.Operation;
@@ -27,7 +23,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
@@ -36,6 +31,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
+import java.util.concurrent.TimeUnit;
@SuppressWarnings("rawtypes")
@Tag(name = "绗笁鏂规湇鍔″鎺�")
@@ -56,19 +52,10 @@
private IMediaServerService mediaServerService;
@Autowired
- private VersionInfo versionInfo;
-
- @Autowired
- private SipConfig sipConfig;
+ private SendRtpPortManager sendRtpPortManager;
@Autowired
private UserSetting userSetting;
-
- @Autowired
- private IDeviceService deviceService;
-
- @Autowired
- private IDeviceChannelService channelService;
@Autowired
private DynamicTask dynamicTask;
@@ -76,14 +63,6 @@
@Autowired
private RedisTemplate<Object, Object> redisTemplate;
-
-
- @Value("${server.port}")
- private int serverPort;
-
-
- @Autowired
- private IRedisCatchStorage redisCatchStorage;
@GetMapping(value = "/receive/open")
@@ -145,24 +124,15 @@
otherRtpSendInfo.setReceivePort(localPort);
otherRtpSendInfo.setCallId(callId);
otherRtpSendInfo.setStream(stream);
- String receiveKey = VideoManagerConstants.WVP_OTHER_RECEIVE_RTP_INFO + userSetting.getServerId() + stream;
+ String receiveKey = VideoManagerConstants.WVP_OTHER_RECEIVE_RTP_INFO + userSetting.getServerId() + "_" + stream;
// 灏嗕俊鎭啓鍏edis涓紝浠ュ鍚庣敤
redisTemplate.opsForValue().set(receiveKey, otherRtpSendInfo);
if (isSend != null && isSend) {
- String key = VideoManagerConstants.WVP_OTHER_SEND_RTP_INFO + userSetting.getServerId() + callId;
+ String key = VideoManagerConstants.WVP_OTHER_SEND_RTP_INFO + userSetting.getServerId() + "_" + callId;
// 棰勫垱寤哄彂娴佷俊鎭�
- int port = zlmServerFactory.keepPort(mediaServerItem, callId, 0, ssrc1 -> {
- return redisTemplate.opsForValue().get(key) != null;
- });
-
+ int port = sendRtpPortManager.getNextPort(mediaServerItem.getId());
// 灏嗕俊鎭啓鍏edis涓紝浠ュ鍚庣敤
- redisTemplate.opsForValue().set(key, otherRtpSendInfo);
- // 璁剧疆瓒呮椂浠诲姟锛岃秴鏃舵湭浣跨敤锛屽垯鑷姩绉婚櫎锛屽苟鍏抽棴绔彛淇濇寔, 榛樿浜斿垎閽�
- dynamicTask.startDelay(key, ()->{
- logger.info("[绗笁鏂规湇鍔″鎺�->寮�鍚敹娴佸拰鑾峰彇鍙戞祦淇℃伅] 绔彛淇濇寔瓒呮椂 callId->{}", callId);
- redisTemplate.delete(key);
- zlmServerFactory.releasePort(mediaServerItem, callId);
- }, 15000);
+ redisTemplate.opsForValue().set(key, otherRtpSendInfo, 300, TimeUnit.SECONDS);
otherRtpSendInfo.setIp(mediaServerItem.getSdpIp());
otherRtpSendInfo.setPort(port);
logger.info("[绗笁鏂规湇鍔″鎺�->寮�鍚敹娴佸拰鑾峰彇鍙戞祦淇℃伅] 缁撴灉锛宑allId->{}锛� {}", callId, otherRtpSendInfo);
@@ -178,7 +148,7 @@
logger.info("[绗笁鏂规湇鍔″鎺�->鍏抽棴鏀舵祦] stream->{}", stream);
MediaServerItem mediaServerItem = mediaServerService.getDefaultMediaServer();
zlmServerFactory.closeRtpServer(mediaServerItem,stream);
- String receiveKey = VideoManagerConstants.WVP_OTHER_RECEIVE_RTP_INFO + userSetting.getServerId() + stream;
+ String receiveKey = VideoManagerConstants.WVP_OTHER_RECEIVE_RTP_INFO + userSetting.getServerId() + "_" + stream;
// 灏嗕俊鎭啓鍏edis涓紝浠ュ鍚庣敤
redisTemplate.delete(receiveKey);
}
@@ -203,11 +173,9 @@
streamType = 1;
}
MediaServerItem mediaServerItem = mediaServerService.getDefaultMediaServer();
- String key = VideoManagerConstants.WVP_OTHER_SEND_RTP_INFO + userSetting.getServerId() + callId;
+ String key = VideoManagerConstants.WVP_OTHER_SEND_RTP_INFO + userSetting.getServerId() + "_" + callId;
OtherRtpSendInfo sendInfo = (OtherRtpSendInfo)redisTemplate.opsForValue().get(key);
- if (sendInfo != null) {
- zlmServerFactory.releasePort(mediaServerItem, callId);
- }else {
+ if (sendInfo == null) {
sendInfo = new OtherRtpSendInfo();
}
sendInfo.setPushApp(app);
@@ -229,7 +197,6 @@
param.put("only_audio", onlyAudio ? "1" : "0");
param.put("pt", pt);
- dynamicTask.stop(key);
Boolean streamReady = zlmServerFactory.isStreamReady(mediaServerItem, app, stream);
if (streamReady) {
logger.info("[绗笁鏂规湇鍔″鎺�->鍙戦�佹祦] 娴佸瓨鍦紝寮�濮嬪彂娴侊紝callId->{}", callId);
@@ -279,7 +246,7 @@
@Parameter(name = "callId", description = "鏁翠釜杩囩▼鐨勫敮涓�鏍囪瘑锛屼笉浼犲垯浣跨敤闅忔満绔彛鍙戞祦", required = true)
public void closeSendRTP(String callId) {
logger.info("[绗笁鏂规湇鍔″鎺�->鍏抽棴鍙戦�佹祦] callId->{}", callId);
- String key = VideoManagerConstants.WVP_OTHER_SEND_RTP_INFO + userSetting.getServerId() + callId;
+ String key = VideoManagerConstants.WVP_OTHER_SEND_RTP_INFO + userSetting.getServerId() + "_" + callId;
OtherRtpSendInfo sendInfo = (OtherRtpSendInfo)redisTemplate.opsForValue().get(key);
if (sendInfo == null){
throw new ControllerException(ErrorCode.ERROR100.getCode(), "鏈紑鍚彂娴�");
diff --git a/web_src/src/components/dialog/MediaServerEdit.vue b/web_src/src/components/dialog/MediaServerEdit.vue
index 15923c1..bb55048 100644
--- a/web_src/src/components/dialog/MediaServerEdit.vue
+++ b/web_src/src/components/dialog/MediaServerEdit.vue
@@ -89,6 +89,11 @@
-
<el-input v-model="rtpPortRange2" placeholder="缁堟" @change="portRangeChange" clearable style="width: 100px" prop="rtpPortRange2" :disabled="mediaServerForm.defaultServer"></el-input>
</el-form-item>
+ <el-form-item v-if="mediaServerForm.sendRtpEnable" label="鍙戞祦绔彛" >
+ <el-input v-model="sendRtpPortRange1" placeholder="璧峰" @change="portRangeChange" clearable style="width: 100px" prop="rtpPortRange1" :disabled="mediaServerForm.defaultServer"></el-input>
+ -
+ <el-input v-model="sendRtpPortRange2" placeholder="缁堟" @change="portRangeChange" clearable style="width: 100px" prop="rtpPortRange2" :disabled="mediaServerForm.defaultServer"></el-input>
+ </el-form-item>
<el-form-item label="褰曞儚绠$悊鏈嶅姟绔彛" prop="recordAssistPort">
<el-input v-model.number="mediaServerForm.recordAssistPort" :disabled="mediaServerForm.defaultServer">
<!-- <el-button v-if="mediaServerForm.recordAssistPort > 0" slot="append" type="primary" @click="checkRecordServer">娴嬭瘯</el-button>-->
@@ -172,12 +177,16 @@
rtmpSSlPort: "",
rtpEnable: false,
rtpPortRange: "",
+ sendRtpPortRange: "",
rtpProxyPort: "",
rtspPort: "",
rtspSSLPort: "",
},
rtpPortRange1:30000,
rtpPortRange2:30500,
+
+ sendRtpPortRange1:50000,
+ sendRtpPortRange2:60000,
rules: {
ip: [{ required: true, validator: isValidIp, message: '璇疯緭鍏ユ湁鏁堢殑IP鍦板潃', trigger: 'blur' }],
@@ -214,9 +223,14 @@
this.currentStep = 3;
if (param.rtpPortRange) {
let rtpPortRange = this.mediaServerForm.rtpPortRange.split(",");
+ let sendRtpPortRange = this.mediaServerForm.sendRtpPortRange.split(",");
if (rtpPortRange.length > 0) {
this.rtpPortRange1 = rtpPortRange[0]
this.rtpPortRange2 = rtpPortRange[1]
+ }
+ if (sendRtpPortRange.length > 0) {
+ this.sendRtpPortRange1 = sendRtpPortRange[0]
+ this.sendRtpPortRange2 = sendRtpPortRange[1]
}
}
}
@@ -240,6 +254,8 @@
that.mediaServerForm.autoConfig = true;
that.rtpPortRange1 = 30000
that.rtpPortRange2 = 30500
+ that.sendRtpPortRange1 = 50000
+ that.sendRtpPortRange2 = 60000
that.serverCheck = 1;
}else {
that.serverCheck = -1;
@@ -321,12 +337,15 @@
rtmpSSlPort: "",
rtpEnable: false,
rtpPortRange: "",
+ sendRtpPortRange: "",
rtpProxyPort: "",
rtspPort: "",
rtspSSLPort: "",
};
this.rtpPortRange1 = 30500;
this.rtpPortRange2 = 30500;
+ this.sendRtpPortRange1 = 50000;
+ this.sendRtpPortRange2 = 60000;
this.listChangeCallback = null
this.currentStep = 1;
},
@@ -351,7 +370,7 @@
portRangeChange: function() {
if (this.mediaServerForm.rtpEnable) {
this.mediaServerForm.rtpPortRange = this.rtpPortRange1 + "," + this.rtpPortRange2
- console.log(this.mediaServerForm.rtpPortRange)
+ this.mediaServerForm.sendRtpPortRange = this.sendRtpPortRange1 + "," + this.sendRtpPortRange2
}
}
},
--
Gitblit v1.8.0