From d295f3c51271c26a5f65c0184bfa27fe1af80f54 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期二, 18 四月 2023 14:06:07 +0800
Subject: [PATCH] 修复合并后的问题
---
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java | 86 +++++++++++++++++++++++++++++++++++++------
1 files changed, 74 insertions(+), 12 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 9bf1a3a..a1524dd 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
@@ -5,7 +5,9 @@
import com.alibaba.fastjson2.JSONObject;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
-import com.genersoft.iot.vmp.media.zlm.dto.*;
+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;
@@ -90,7 +92,7 @@
return result;
}
- public int createRTPServer(MediaServerItem mediaServerItem, String streamId, int ssrc, Integer port) {
+ public int createRTPServer(MediaServerItem mediaServerItem, String streamId, int ssrc, Integer port, Boolean onlyAuto) {
int result = -1;
// 鏌ヨ姝tp server 鏄惁宸茬粡瀛樺湪
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaServerItem, streamId);
@@ -106,7 +108,7 @@
JSONObject jsonObject = zlmresTfulUtils.closeRtpServer(mediaServerItem, param);
if (jsonObject != null ) {
if (jsonObject.getInteger("code") == 0) {
- return createRTPServer(mediaServerItem, streamId, ssrc, port);
+ return createRTPServer(mediaServerItem, streamId, ssrc, port, onlyAuto);
}else {
logger.warn("[寮�鍚痳tpServer], 閲嶅惎RtpServer閿欒");
}
@@ -129,6 +131,9 @@
param.put("port", port);
}
param.put("ssrc", ssrc);
+ if (onlyAuto != null) {
+ param.put("only_audio", onlyAuto?"1":"0");
+ }
JSONObject openRtpServerResultJson = zlmresTfulUtils.openRtpServer(mediaServerItem, param);
logger.info(JSONObject.toJSONString(openRtpServerResultJson));
if (openRtpServerResultJson != null) {
@@ -227,7 +232,7 @@
sendRtpItem.setPort(port);
sendRtpItem.setSsrc(ssrc);
sendRtpItem.setApp(app);
- sendRtpItem.setStreamId(stream);
+ sendRtpItem.setStream(stream);
sendRtpItem.setPlatformId(platformId);
sendRtpItem.setChannelId(channelId);
sendRtpItem.setTcp(tcp);
@@ -254,12 +259,13 @@
// 璁㈤槄 zlm鍚姩浜嬩欢, 鏂扮殑zlm涔熶細浠庤繖閲岃繘鍏ョ郴缁�
hookSubscribe.addSubscribe(hookSubscribeForRtpServerTimeout,
(MediaServerItem mediaServerItem, JSONObject response)->{
- logger.info("[涓婄骇鐐规挱] {}->鐩戝惉绔彛鍒版湡缁х画淇濇寔鐩戝惉", ssrc);
+ logger.info("[淇濇寔绔彛] {}->鐩戝惉绔彛鍒版湡缁х画淇濇寔鐩戝惉", ssrc);
keepPort(serverItem, ssrc);
});
- logger.info("[涓婄骇鐐规挱] {}->鐩戝惉绔彛: {}", ssrc, localPort);
+ logger.info("[淇濇寔绔彛] {}->鐩戝惉绔彛: {}", ssrc, localPort);
+ logger.info("[淇濇寔绔彛] {}->鐩戝惉绔彛: {}", ssrc, localPort);
}else {
- logger.info("[涓婄骇鐐规挱] 鐩戝惉绔彛澶辫触: {}", ssrc);
+ logger.info("[淇濇寔绔彛] 鐩戝惉绔彛澶辫触: {}", ssrc);
}
return localPort;
}
@@ -268,7 +274,7 @@
* 閲婃斁淇濇寔鐨勭鍙�
*/
public boolean releasePort(MediaServerItem serverItem, String ssrc) {
- logger.info("[涓婄骇鐐规挱] {}->閲婃斁鐩戝惉绔彛", ssrc);
+ logger.info("[淇濇寔绔彛] {}->閲婃斁鐩戝惉绔彛", ssrc);
boolean closeRTPServerResult = closeRtpServer(serverItem, ssrc);
HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, serverItem.getId());
// 璁㈤槄 zlm鍚姩浜嬩欢, 鏂扮殑zlm涔熶細浠庤繖閲岃繘鍏ョ郴缁�
@@ -281,6 +287,17 @@
*/
public JSONObject startSendRtpStream(MediaServerItem mediaServerItem, Map<String, Object>param) {
return zlmresTfulUtils.startSendRtp(mediaServerItem, param);
+ }
+
+ /**
+ * 璋冪敤zlm RESTFUL API 鈥斺�� startSendRtpPassive
+ */
+ public JSONObject startSendRtpPassive(MediaServerItem mediaServerItem, Map<String, Object>param) {
+ return zlmresTfulUtils.startSendRtpPassive(mediaServerItem, param);
+ }
+
+ public JSONObject startSendRtpPassive(MediaServerItem mediaServerItem, Map<String, Object>param, ZLMRESTfulUtils.RequestCallback callback) {
+ return zlmresTfulUtils.startSendRtpPassive(mediaServerItem, param, callback);
}
/**
@@ -313,11 +330,11 @@
return 0;
}
Integer code = mediaInfo.getInteger("code");
- if ( code < 0) {
+ if (code < 0) {
logger.warn("鏌ヨ娴�({}/{})鏄惁鏈夊叾瀹冭鐪嬭�呮椂寰楀埌锛� {}", app, streamId, mediaInfo.getString("msg"));
return -1;
}
- if ( code == 0 && mediaInfo.getBoolean("online") != null && !mediaInfo.getBoolean("online")) {
+ if ( code == 0 && mediaInfo.getBoolean("online") != null && ! mediaInfo.getBoolean("online")) {
logger.warn("鏌ヨ娴�({}/{})鏄惁鏈夊叾瀹冭鐪嬭�呮椂寰楀埌锛� {}", app, streamId, mediaInfo.getString("msg"));
return -1;
}
@@ -336,12 +353,57 @@
result= true;
logger.info("[鍋滄RTP鎺ㄦ祦] 鎴愬姛");
} else {
- logger.error("[鍋滄RTP鎺ㄦ祦] 澶辫触: {}, 鍙傛暟锛歿}->\r\n{}",jsonObject.getString("msg"), JSON.toJSON(param), jsonObject);
+ logger.warn("[鍋滄RTP鎺ㄦ祦] 澶辫触: {}, 鍙傛暟锛歿}->\r\n{}",jsonObject.getString("msg"), JSON.toJSON(param), jsonObject);
}
return result;
}
- public void closeAllSendRtpStream() {
+ public JSONObject startSendRtp(MediaServerItem mediaInfo, SendRtpItem sendRtpItem) {
+ String is_Udp = sendRtpItem.isTcp() ? "0" : "1";
+ logger.info("rtp/{}寮�濮嬫帹娴�, 鐩爣={}:{}锛孲SRC={}", sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc());
+ Map<String, Object> param = new HashMap<>(12);
+ param.put("vhost","__defaultVhost__");
+ param.put("app",sendRtpItem.getApp());
+ param.put("stream",sendRtpItem.getStream());
+ param.put("ssrc", sendRtpItem.getSsrc());
+ param.put("src_port", sendRtpItem.getLocalPort());
+ param.put("pt", sendRtpItem.getPt());
+ param.put("use_ps", sendRtpItem.isUsePs() ? "1" : "0");
+ param.put("only_audio", sendRtpItem.isOnlyAudio() ? "1" : "0");
+ if (!sendRtpItem.isTcp()) {
+ // udp妯″紡涓嬪紑鍚痳tcp淇濇椿
+ param.put("udp_rtcp_timeout", sendRtpItem.isRtcp()? "1":"0");
+ }
+ if (mediaInfo == null) {
+ return null;
+ }
+ // 濡傛灉鏄潪涓ユ牸妯″紡锛岄渶瑕佸叧闂鍙e崰鐢�
+ JSONObject startSendRtpStreamResult = null;
+ if (sendRtpItem.getLocalPort() != 0) {
+ HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(sendRtpItem.getSsrc(), null, mediaInfo.getId());
+ hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout);
+ if (releasePort(mediaInfo, sendRtpItem.getSsrc())) {
+ if (sendRtpItem.isTcpActive()) {
+ startSendRtpStreamResult = startSendRtpPassive(mediaInfo, param);
+ System.out.println(JSON.toJSON(param));
+ }else {
+ param.put("is_udp", is_Udp);
+ param.put("dst_url", sendRtpItem.getIp());
+ param.put("dst_port", sendRtpItem.getPort());
+ startSendRtpStreamResult = startSendRtpStream(mediaInfo, param);
+ }
+ }
+ }else {
+ if (sendRtpItem.isTcpActive()) {
+ startSendRtpStreamResult = startSendRtpPassive(mediaInfo, param);
+ }else {
+ param.put("is_udp", is_Udp);
+ param.put("dst_url", sendRtpItem.getIp());
+ param.put("dst_port", sendRtpItem.getPort());
+ startSendRtpStreamResult = startSendRtpStream(mediaInfo, param);
+ }
+ }
+ return startSendRtpStreamResult;
}
}
--
Gitblit v1.8.0