From 733a11f265778f9f9fa64210cceae7ae8e6fdfd4 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期一, 03 七月 2023 17:55:34 +0800
Subject: [PATCH] 修复单端口点播
---
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java | 6 ++++--
src/main/java/com/genersoft/iot/vmp/vmanager/rtp/RtpController.java | 35 ++++++++++++++---------------------
2 files changed, 18 insertions(+), 23 deletions(-)
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 b5deea2..397fb76 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
@@ -158,8 +158,10 @@
}
}
}
-
- String streamId = String.format("%s_%s", device.getDeviceId(), channelId);
+ String streamId = null;
+ if (mediaServerItem.isRtpEnable()) {
+ streamId = String.format("%s_%s", device.getDeviceId(), channelId);
+ }
SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, null, device.isSsrcCheck(), false, 0, false, device.getStreamModeForParam());
if (ssrcInfo == null) {
callback.run(InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getCode(), InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getMsg(), null);
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 2012625..689231d 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
@@ -7,13 +7,13 @@
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.gb28181.bean.SendRtpItem;
+import com.genersoft.iot.vmp.media.zlm.SendRtpPortManager;
import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory;
-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.MediaServerItem;
+import com.genersoft.iot.vmp.media.zlm.dto.hook.OnRtpServerTimeoutHookParam;
import com.genersoft.iot.vmp.service.IDeviceChannelService;
import com.genersoft.iot.vmp.service.IDeviceService;
import com.genersoft.iot.vmp.service.IMediaServerService;
@@ -38,6 +38,7 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.TimeUnit;
@SuppressWarnings("rawtypes")
@Tag(name = "绗笁鏂规湇鍔″鎺�")
@@ -48,6 +49,9 @@
@Autowired
private ZLMServerFactory zlmServerFactory;
+
+ @Autowired
+ private SendRtpPortManager sendRtpPortManager;
private final static Logger logger = LoggerFactory.getLogger(RtpController.class);
@@ -127,8 +131,9 @@
HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, mediaServerItem.getId());
// 璁㈤槄 zlm鍚姩浜嬩欢, 鏂扮殑zlm涔熶細浠庤繖閲岃繘鍏ョ郴缁�
hookSubscribe.addSubscribe(hookSubscribeForRtpServerTimeout,
- (mediaServerItemInUse, response)->{
- if (stream.equals(response.getString("stream_id"))) {
+ (mediaServerItemInUse, hookParam)->{
+ OnRtpServerTimeoutHookParam serverTimeoutHookParam = (OnRtpServerTimeoutHookParam) hookParam;
+ if (stream.equals(serverTimeoutHookParam.getStream_id())) {
logger.info("[寮�鍚敹娴佸拰鑾峰彇鍙戞祦淇℃伅] 绛夊緟鏀舵祦瓒呮椂 callId->{}, 鍙戦�佸洖璋�", callId);
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
OkHttpClient client = httpClientBuilder.build();
@@ -142,30 +147,20 @@
}
});
}
+ String key = VideoManagerConstants.WVP_OTHER_SEND_RTP_INFO + userSetting.getServerId() + callId;
OtherRtpSendInfo otherRtpSendInfo = new OtherRtpSendInfo();
otherRtpSendInfo.setReceiveIp(mediaServerItem.getSdpIp());
otherRtpSendInfo.setReceivePort(localPort);
otherRtpSendInfo.setCallId(callId);
otherRtpSendInfo.setStream(stream);
if (isSend != null && isSend) {
- 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;
- });
-
- // 灏嗕俊鎭啓鍏edis涓紝浠ュ鍚庣敤
- redisTemplate.opsForValue().set(key, otherRtpSendInfo);
- // 璁剧疆瓒呮椂浠诲姟锛岃秴鏃舵湭浣跨敤锛屽垯鑷姩绉婚櫎锛屽苟鍏抽棴绔彛淇濇寔, 榛樿浜斿垎閽�
- dynamicTask.startDelay(key, ()->{
- logger.info("[绗笁鏂规湇鍔″鎺�->寮�鍚敹娴佸拰鑾峰彇鍙戞祦淇℃伅] 绔彛淇濇寔瓒呮椂 callId->{}", callId);
- redisTemplate.delete(key);
- zlmServerFactory.releasePort(mediaServerItem, callId);
- }, 300000);
+ int port = sendRtpPortManager.getNextPort(mediaServerItem.getId());
otherRtpSendInfo.setIp(mediaServerItem.getSdpIp());
otherRtpSendInfo.setPort(port);
logger.info("[寮�鍚敹娴佸拰鑾峰彇鍙戞祦淇℃伅] 缁撴灉锛宑allId->{}锛� {}", callId, otherRtpSendInfo);
}
+ // 灏嗕俊鎭啓鍏edis涓紝浠ュ鍚庣敤
+ redisTemplate.opsForValue().set(key, otherRtpSendInfo, 300, TimeUnit.SECONDS);
return otherRtpSendInfo;
}
@@ -197,9 +192,7 @@
MediaServerItem mediaServerItem = mediaServerService.getDefaultMediaServer();
String key = VideoManagerConstants.WVP_OTHER_SEND_RTP_INFO + userSetting.getServerId() + callId;
OtherRtpSendInfo sendInfo = (OtherRtpSendInfo)redisTemplate.opsForValue().get(key);
- if (sendInfo != null) {
- zlmServerFactory.releasePort(mediaServerItem, sendInfo.getCallId());
- }else {
+ if (sendInfo == null) {
sendInfo = new OtherRtpSendInfo();
}
sendInfo.setPushApp(app);
--
Gitblit v1.8.0