From 71fe60d885b09d53fcd4c58afcfccf18d24a94c2 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期四, 11 四月 2024 15:34:56 +0800
Subject: [PATCH] 更新README
---
src/main/java/com/genersoft/iot/vmp/vmanager/ps/PsController.java | 79 ++++++++++++---------------------------
1 files changed, 25 insertions(+), 54 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/ps/PsController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/ps/PsController.java
index dc01c43..74e155b 100755
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/ps/PsController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/ps/PsController.java
@@ -6,14 +6,15 @@
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.conf.security.JwtUtils;
+import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
import com.genersoft.iot.vmp.media.event.hook.Hook;
import com.genersoft.iot.vmp.media.event.hook.HookType;
import com.genersoft.iot.vmp.media.zlm.SendRtpPortManager;
import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory;
import com.genersoft.iot.vmp.media.event.hook.HookSubscribe;
-import com.genersoft.iot.vmp.media.zlm.dto.MediaServer;
-import com.genersoft.iot.vmp.media.zlm.dto.hook.OnRtpServerTimeoutHookParam;
+import com.genersoft.iot.vmp.media.bean.MediaServer;
import com.genersoft.iot.vmp.media.service.IMediaServerService;
+import com.genersoft.iot.vmp.service.bean.SSRCInfo;
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.OtherPsSendInfo;
@@ -44,9 +45,6 @@
public class PsController {
private final static Logger logger = LoggerFactory.getLogger(PsController.class);
-
- @Autowired
- private ZLMServerFactory zlmServerFactory;
@Autowired
private HookSubscribe hookSubscribe;
@@ -82,8 +80,8 @@
logger.info("[绗笁鏂筆S鏈嶅姟瀵规帴->寮�鍚敹娴佸拰鑾峰彇鍙戞祦淇℃伅] isSend->{}, ssrc->{}, callId->{}, stream->{}, tcpMode->{}, callBack->{}",
isSend, ssrc, callId, stream, tcpMode==0?"UDP":"TCP琚姩", callBack);
- MediaServer mediaServerItem = mediaServerService.getDefaultMediaServer();
- if (mediaServerItem == null) {
+ MediaServer mediaServer = mediaServerService.getDefaultMediaServer();
+ if (mediaServer == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(),"娌℃湁鍙敤鐨凪ediaServer");
}
if (stream == null) {
@@ -101,13 +99,14 @@
}
}
String receiveKey = VideoManagerConstants.WVP_OTHER_RECEIVE_PS_INFO + userSetting.getServerId() + "_" + callId + "_" + stream;
- int localPort = zlmServerFactory.createRTPServer(mediaServerItem, stream, ssrcInt, null, false, false, tcpMode);
- if (localPort == 0) {
+ SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServer, stream, ssrcInt + "", false, false, null, false, false, false, tcpMode);
+
+ if (ssrcInfo.getPort() == 0) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "鑾峰彇绔彛澶辫触");
}
// 娉ㄥ唽鍥炶皟濡傛灉rtp鏀舵祦瓒呮椂鍒欓�氳繃鍥炶皟鍙戦�侀�氱煡
if (callBack != null) {
- Hook hook = Hook.getInstance(HookType.on_rtp_server_timeout, "rtp", stream, mediaServerItem.getId());
+ Hook hook = Hook.getInstance(HookType.on_rtp_server_timeout, "rtp", stream, mediaServer.getId());
// 璁㈤槄 zlm鍚姩浜嬩欢, 鏂扮殑zlm涔熶細浠庤繖閲岃繘鍏ョ郴缁�
hookSubscribe.addSubscribe(hook,
(hookData)->{
@@ -129,8 +128,8 @@
});
}
OtherPsSendInfo otherPsSendInfo = new OtherPsSendInfo();
- otherPsSendInfo.setReceiveIp(mediaServerItem.getSdpIp());
- otherPsSendInfo.setReceivePort(localPort);
+ otherPsSendInfo.setReceiveIp(mediaServer.getSdpIp());
+ otherPsSendInfo.setReceivePort(ssrcInfo.getPort());
otherPsSendInfo.setCallId(callId);
otherPsSendInfo.setStream(stream);
@@ -139,9 +138,9 @@
if (isSend != null && isSend) {
String key = VideoManagerConstants.WVP_OTHER_SEND_PS_INFO + userSetting.getServerId() + "_" + callId;
// 棰勫垱寤哄彂娴佷俊鎭�
- int port = sendRtpPortManager.getNextPort(mediaServerItem);
+ int port = sendRtpPortManager.getNextPort(mediaServer);
- otherPsSendInfo.setSendLocalIp(mediaServerItem.getSdpIp());
+ otherPsSendInfo.setSendLocalIp(mediaServer.getSdpIp());
otherPsSendInfo.setSendLocalPort(port);
// 灏嗕俊鎭啓鍏edis涓紝浠ュ鍚庣敤
redisTemplate.opsForValue().set(key, otherPsSendInfo, 300, TimeUnit.SECONDS);
@@ -157,7 +156,7 @@
public void closeRtpServer(String stream) {
logger.info("[绗笁鏂筆S鏈嶅姟瀵规帴->鍏抽棴鏀舵祦] stream->{}", stream);
MediaServer mediaServerItem = mediaServerService.getDefaultMediaServer();
- zlmServerFactory.closeRtpServer(mediaServerItem,stream);
+ mediaServerService.closeRTPServer(mediaServerItem, stream);
String receiveKey = VideoManagerConstants.WVP_OTHER_RECEIVE_PS_INFO + userSetting.getServerId() + "_*_" + stream;
List<Object> scan = RedisUtil.scan(redisTemplate, receiveKey);
if (!scan.isEmpty()) {
@@ -199,7 +198,7 @@
app,
stream,
callId);
- MediaServer mediaServerItem = mediaServerService.getDefaultMediaServer();
+ MediaServer mediaServer = mediaServerService.getDefaultMediaServer();
String key = VideoManagerConstants.WVP_OTHER_SEND_PS_INFO + userSetting.getServerId() + "_" + callId;
OtherPsSendInfo sendInfo = (OtherPsSendInfo)redisTemplate.opsForValue().get(key);
if (sendInfo == null) {
@@ -208,38 +207,16 @@
sendInfo.setPushApp(app);
sendInfo.setPushStream(stream);
sendInfo.setPushSSRC(ssrc);
-
- Map<String, Object> param;
-
-
- param = new HashMap<>();
- param.put("vhost","__defaultVhost__");
- param.put("app",app);
- param.put("stream",stream);
- param.put("ssrc", ssrc);
-
- param.put("dst_url", dstIp);
- param.put("dst_port", dstPort);
- String is_Udp = isUdp ? "1" : "0";
- param.put("is_udp", is_Udp);
- param.put("src_port", sendInfo.getSendLocalPort());
-
-
- Boolean streamReady = zlmServerFactory.isStreamReady(mediaServerItem, app, stream);
+ SendRtpItem sendRtpItem = SendRtpItem.getInstance(app, stream, ssrc, dstIp, dstPort, !isUdp, sendInfo.getSendLocalPort(), null);
+ Boolean streamReady = mediaServerService.isStreamReady(mediaServer, app, stream);
if (streamReady) {
- JSONObject jsonObject = zlmServerFactory.startSendRtpStream(mediaServerItem, param);
- if (jsonObject.getInteger("code") == 0) {
- logger.info("[绗笁鏂筆S鏈嶅姟瀵规帴->鍙戦�佹祦] 瑙嗛娴佸彂娴佹垚鍔燂紝callId->{}锛宲aram->{}", callId, param);
- redisTemplate.opsForValue().set(key, sendInfo);
- }else {
- redisTemplate.delete(key);
- logger.info("[绗笁鏂筆S鏈嶅姟瀵规帴->鍙戦�佹祦] 瑙嗛娴佸彂娴佸け璐ワ紝callId->{}, {}", callId, jsonObject.getString("msg"));
- throw new ControllerException(ErrorCode.ERROR100.getCode(), "[瑙嗛娴佸彂娴佸け璐 " + jsonObject.getString("msg"));
- }
+ mediaServerService.startSendRtp(mediaServer, null, sendRtpItem);
+ logger.info("[绗笁鏂筆S鏈嶅姟瀵规帴->鍙戦�佹祦] 瑙嗛娴佸彂娴佹垚鍔燂紝callId->{}锛宲aram->{}", callId, sendRtpItem);
+ redisTemplate.opsForValue().set(key, sendInfo);
}else {
logger.info("[绗笁鏂筆S鏈嶅姟瀵规帴->鍙戦�佹祦] 娴佷笉瀛樺湪锛岀瓑寰呮祦涓婄嚎锛宑allId->{}", callId);
String uuid = UUID.randomUUID().toString();
- Hook hook = Hook.getInstance(HookType.on_media_arrival, app, stream, mediaServerItem.getId());
+ Hook hook = Hook.getInstance(HookType.on_media_arrival, app, stream, mediaServer.getId());
dynamicTask.startDelay(uuid, ()->{
logger.info("[绗笁鏂筆S鏈嶅姟瀵规帴->鍙戦�佹祦] 绛夊緟娴佷笂绾胯秴鏃� callId->{}", callId);
redisTemplate.delete(key);
@@ -258,15 +235,9 @@
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
- JSONObject jsonObject = zlmServerFactory.startSendRtpStream(mediaServerItem, param);
- if (jsonObject.getInteger("code") == 0) {
- logger.info("[绗笁鏂筆S鏈嶅姟瀵规帴->鍙戦�佹祦] 瑙嗛娴佸彂娴佹垚鍔燂紝callId->{}锛宲aram->{}", callId, param);
- redisTemplate.opsForValue().set(key, finalSendInfo);
- }else {
- redisTemplate.delete(key);
- logger.info("[绗笁鏂筆S鏈嶅姟瀵规帴->鍙戦�佹祦] 瑙嗛娴佸彂娴佸け璐ワ紝callId->{}, {}", callId, jsonObject.getString("msg"));
- throw new ControllerException(ErrorCode.ERROR100.getCode(), "[瑙嗛娴佸彂娴佸け璐 " + jsonObject.getString("msg"));
- }
+ mediaServerService.startSendRtp(mediaServer, null, sendRtpItem);
+ logger.info("[绗笁鏂筆S鏈嶅姟瀵规帴->鍙戦�佹祦] 瑙嗛娴佸彂娴佹垚鍔燂紝callId->{}锛宲aram->{}", callId, sendRtpItem);
+ redisTemplate.opsForValue().set(key, finalSendInfo);
hookSubscribe.removeSubscribe(hook);
});
}
@@ -289,7 +260,7 @@
param.put("stream",sendInfo.getPushStream());
param.put("ssrc",sendInfo.getPushSSRC());
MediaServer mediaServerItem = mediaServerService.getDefaultMediaServer();
- Boolean result = zlmServerFactory.stopSendRtpStream(mediaServerItem, param);
+ boolean result = mediaServerService.stopSendRtp(mediaServerItem, sendInfo.getPushApp(), sendInfo.getStream(), sendInfo.getPushSSRC());
if (!result) {
logger.info("[绗笁鏂筆S鏈嶅姟瀵规帴->鍏抽棴鍙戦�佹祦] 澶辫触 callId->{}", callId);
throw new ControllerException(ErrorCode.ERROR100.getCode(), "鍋滄鍙戞祦澶辫触");
--
Gitblit v1.8.0