From f95ca2248ed0a0ea8f92f9ed2dd3145ce520f8a6 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期五, 08 三月 2024 09:39:19 +0800
Subject: [PATCH] 更新readme
---
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMServerFactory.java | 93 +++++++++++++++++++++++++++++++++++-----------
1 files changed, 71 insertions(+), 22 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMServerFactory.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMServerFactory.java
old mode 100644
new mode 100755
index 34acf15..2422206
--- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMServerFactory.java
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMServerFactory.java
@@ -42,7 +42,7 @@
* @param tcpMode 0/null udp 妯″紡锛�1 tcp 琚姩妯″紡, 2 tcp 涓诲姩妯″紡銆�
* @return
*/
- public int createRTPServer(MediaServerItem mediaServerItem, String streamId, int ssrc, Integer port, Boolean reUsePort, Integer tcpMode) {
+ public int createRTPServer(MediaServerItem mediaServerItem, String streamId, long ssrc, Integer port, Boolean onlyAuto, Boolean reUsePort, Integer tcpMode) {
int result = -1;
// 鏌ヨ姝tp server 鏄惁宸茬粡瀛樺湪
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaServerItem, streamId);
@@ -58,7 +58,7 @@
JSONObject jsonObject = zlmresTfulUtils.closeRtpServer(mediaServerItem, param);
if (jsonObject != null ) {
if (jsonObject.getInteger("code") == 0) {
- return createRTPServer(mediaServerItem, streamId, ssrc, port, reUsePort, tcpMode);
+ return createRTPServer(mediaServerItem, streamId, ssrc, port,onlyAuto, reUsePort, tcpMode);
}else {
logger.warn("[寮�鍚痳tpServer], 閲嶅惎RtpServer閿欒");
}
@@ -86,6 +86,9 @@
}else {
param.put("port", port);
}
+ if (onlyAuto != null) {
+ param.put("only_audio", onlyAuto?"1":"0");
+ }
if (ssrc != 0) {
param.put("ssrc", ssrc);
}
@@ -111,9 +114,10 @@
Map<String, Object> param = new HashMap<>();
param.put("stream_id", streamId);
JSONObject jsonObject = zlmresTfulUtils.closeRtpServer(serverItem, param);
+ logger.info("鍏抽棴RTP Server " + jsonObject);
if (jsonObject != null ) {
if (jsonObject.getInteger("code") == 0) {
- result = jsonObject.getInteger("hit") == 1;
+ result = jsonObject.getInteger("hit") >= 1;
}else {
logger.error("鍏抽棴RTP Server 澶辫触: " + jsonObject.getString("msg"));
}
@@ -164,13 +168,9 @@
public SendRtpItem createSendRtpItem(MediaServerItem serverItem, String ip, int port, String ssrc, String platformId,
String deviceId, String channelId, boolean tcp, boolean rtcp){
- // 榛樿涓洪殢鏈虹鍙�
- int localPort = 0;
- if (userSetting.getGbSendStreamStrict()) {
- localPort = sendRtpPortManager.getNextPort(serverItem);
- if (localPort == 0) {
- return null;
- }
+ int localPort = sendRtpPortManager.getNextPort(serverItem);
+ if (localPort == 0) {
+ return null;
}
SendRtpItem sendRtpItem = new SendRtpItem();
sendRtpItem.setIp(ip);
@@ -200,20 +200,17 @@
*/
public SendRtpItem createSendRtpItem(MediaServerItem serverItem, String ip, int port, String ssrc, String platformId,
String app, String stream, String channelId, boolean tcp, boolean rtcp){
- // 榛樿涓洪殢鏈虹鍙�
- int localPort = 0;
- if (userSetting.getGbSendStreamStrict()) {
- localPort = sendRtpPortManager.getNextPort(serverItem);
- if (localPort == 0) {
- return null;
- }
+
+ int localPort = sendRtpPortManager.getNextPort(serverItem);
+ if (localPort == 0) {
+ return null;
}
SendRtpItem sendRtpItem = new SendRtpItem();
sendRtpItem.setIp(ip);
sendRtpItem.setPort(port);
sendRtpItem.setSsrc(ssrc);
sendRtpItem.setApp(app);
- sendRtpItem.setStreamId(stream);
+ sendRtpItem.setStream(stream);
sendRtpItem.setPlatformId(platformId);
sendRtpItem.setChannelId(channelId);
sendRtpItem.setTcp(tcp);
@@ -229,6 +226,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);
}
/**
@@ -266,11 +274,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;
}
@@ -289,13 +297,54 @@
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) {
+ 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;
}
public Boolean updateRtpServerSSRC(MediaServerItem mediaServerItem, String streamId, String ssrc) {
--
Gitblit v1.8.0