From 3e71e0bdf1e4b2e527d491d426f67e34b7d3c148 Mon Sep 17 00:00:00 2001
From: xiaoQQya <xiaoQQya@126.com>
Date: 星期六, 05 十一月 2022 11:35:01 +0800
Subject: [PATCH] perf(rtcPlayer): 修改控制台 log 级别
---
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java | 87 ++++++++++++++++++++++++++++---------------
1 files changed, 57 insertions(+), 30 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 a36593e..24e0dcf 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
@@ -2,12 +2,14 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
+import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
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 org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.*;
@@ -20,10 +22,15 @@
@Autowired
private ZLMRESTfulUtils zlmresTfulUtils;
+ @Autowired
+ private UserSetting userSetting;
+
private int[] portRangeArray = new int[2];
public int getFreePort(MediaServerItem mediaServerItem, int startPort, int endPort, List<Integer> usedFreelist) {
- if (endPort <= startPort) return -1;
+ if (endPort <= startPort) {
+ return -1;
+ }
if (usedFreelist == null) {
usedFreelist = new ArrayList<>();
}
@@ -60,7 +67,7 @@
String stream = UUID.randomUUID().toString();
param.put("enable_tcp", 1);
param.put("stream_id", stream);
- param.put("port", 0);
+// param.put("port", 0);
JSONObject openRtpServerResultJson = zlmresTfulUtils.openRtpServer(mediaServerItem, param);
if (openRtpServerResultJson != null) {
@@ -81,21 +88,47 @@
return result;
}
- public int createRTPServer(MediaServerItem mediaServerItem, String streamId) {
+ public int createRTPServer(MediaServerItem mediaServerItem, String streamId, int ssrc, Integer port) {
int result = -1;
// 鏌ヨ姝tp server 鏄惁宸茬粡瀛樺湪
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaServerItem, streamId);
- if (rtpInfo != null && rtpInfo.getInteger("code") == 0 && rtpInfo.getBoolean("exist")) {
- result = rtpInfo.getInteger("local_port");
+ logger.info(JSONObject.toJSONString(rtpInfo));
+ if(rtpInfo.getInteger("code") == 0){
+ if (rtpInfo.getBoolean("exist")) {
+ result = rtpInfo.getInteger("local_port");
+ if (result == 0) {
+ // 姝ゆ椂璇存槑rtpServer宸茬粡鍒涘缓浣嗘槸娴佽繕娌℃湁鎺ㄤ笂鏉�
+ // 姝ゆ椂閲嶆柊鎵撳紑rtpServer
+ Map<String, Object> param = new HashMap<>();
+ param.put("stream_id", streamId);
+ JSONObject jsonObject = zlmresTfulUtils.closeRtpServer(mediaServerItem, param);
+ if (jsonObject != null ) {
+ if (jsonObject.getInteger("code") == 0) {
+ return createRTPServer(mediaServerItem, streamId, ssrc, port);
+ }else {
+ logger.warn("[寮�鍚痳tpServer], 閲嶅惎RtpServer閿欒");
+ }
+ }
+ }
+ return result;
+ }
+ }else if(rtpInfo.getInteger("code") == -2){
return result;
}
+
Map<String, Object> param = new HashMap<>();
- // 鎺ㄦ祦绔彛璁剧疆0鍒欎娇鐢ㄩ殢鏈虹鍙�
+
param.put("enable_tcp", 1);
param.put("stream_id", streamId);
- param.put("port", 0);
+ // 鎺ㄦ祦绔彛璁剧疆0鍒欎娇鐢ㄩ殢鏈虹鍙�
+ if (port == null) {
+ param.put("port", 0);
+ }else {
+ param.put("port", port);
+ }
+ param.put("ssrc", ssrc);
JSONObject openRtpServerResultJson = zlmresTfulUtils.openRtpServer(mediaServerItem, param);
-
+ logger.info(JSONObject.toJSONString(openRtpServerResultJson));
if (openRtpServerResultJson != null) {
if (openRtpServerResultJson.getInteger("code") == 0) {
result= openRtpServerResultJson.getInteger("port");
@@ -170,7 +203,7 @@
// 浣跨敤RTPServer 鍔熻兘鎵句竴涓彲鐢ㄧ殑绔彛
String sendRtpPortRange = serverItem.getSendRtpPortRange();
- if (StringUtils.isEmpty(sendRtpPortRange)) {
+ if (ObjectUtils.isEmpty(sendRtpPortRange)) {
return null;
}
String[] portRangeStrArray = serverItem.getSendRtpPortRange().split(",");
@@ -194,6 +227,7 @@
sendRtpItem.setTcp(tcp);
sendRtpItem.setApp("rtp");
sendRtpItem.setLocalPort(localPort);
+ sendRtpItem.setServerId(userSetting.getServerId());
sendRtpItem.setMediaServerId(serverItem.getId());
return sendRtpItem;
}
@@ -211,7 +245,7 @@
public SendRtpItem createSendRtpItem(MediaServerItem serverItem, String ip, int port, String ssrc, String platformId, String app, String stream, String channelId, boolean tcp){
// 浣跨敤RTPServer 鍔熻兘鎵句竴涓彲鐢ㄧ殑绔彛
String sendRtpPortRange = serverItem.getSendRtpPortRange();
- if (StringUtils.isEmpty(sendRtpPortRange)) {
+ if (ObjectUtils.isEmpty(sendRtpPortRange)) {
return null;
}
String[] portRangeStrArray = serverItem.getSendRtpPortRange().split(",");
@@ -235,6 +269,7 @@
sendRtpItem.setChannelId(channelId);
sendRtpItem.setTcp(tcp);
sendRtpItem.setLocalPort(localPort);
+ sendRtpItem.setServerId(userSetting.getServerId());
sendRtpItem.setMediaServerId(serverItem.getId());
return sendRtpItem;
}
@@ -243,24 +278,14 @@
* 璋冪敤zlm RESTFUL API 鈥斺�� startSendRtp
*/
public JSONObject startSendRtpStream(MediaServerItem mediaServerItem, Map<String, Object>param) {
- Boolean result = false;
- JSONObject jsonObject = zlmresTfulUtils.startSendRtp(mediaServerItem, param);
- if (jsonObject == null) {
- logger.error("RTP鎺ㄦ祦澶辫触: 璇锋鏌LM鏈嶅姟");
- } else if (jsonObject.getInteger("code") == 0) {
- result= true;
- logger.info("RTP鎺ㄦ祦鎴愬姛[ {}/{} ]锛寋}->{}:{}, " ,param.get("app"), param.get("stream"), jsonObject.getString("local_port"), param.get("dst_url"), param.get("dst_port"));
- } else {
- logger.error("RTP鎺ㄦ祦澶辫触: {}, 鍙傛暟锛歿}",jsonObject.getString("msg"),JSONObject.toJSON(param));
- }
- return jsonObject;
+ return zlmresTfulUtils.startSendRtp(mediaServerItem, param);
}
/**
* 鏌ヨ寰呰浆鎺ㄧ殑娴佹槸鍚﹀氨缁�
*/
public Boolean isRtpReady(MediaServerItem mediaServerItem, String streamId) {
- JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServerItem,"rtp", "rtmp", streamId);
+ JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServerItem,"rtp", "rtsp", streamId);
return (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online"));
}
@@ -268,8 +293,10 @@
* 鏌ヨ寰呰浆鎺ㄧ殑娴佹槸鍚﹀氨缁�
*/
public Boolean isStreamReady(MediaServerItem mediaServerItem, String app, String streamId) {
- JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServerItem, app, "rtmp", streamId);
- return (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online"));
+ JSONObject mediaInfo = zlmresTfulUtils.getMediaList(mediaServerItem, app, streamId);
+ return (mediaInfo.getInteger("code") == 0
+ && mediaInfo.getJSONArray("data") != null
+ && mediaInfo.getJSONArray("data").size() > 0);
}
/**
@@ -278,16 +305,16 @@
* @return
*/
public int totalReaderCount(MediaServerItem mediaServerItem, String app, String streamId) {
- JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServerItem, app, "rtmp", streamId);
- Integer code = mediaInfo.getInteger("code");
+ JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServerItem, app, "rtsp", streamId);
if (mediaInfo == null) {
return 0;
}
+ Integer code = mediaInfo.getInteger("code");
if ( code < 0) {
logger.warn("鏌ヨ娴�({}/{})鏄惁鏈夊叾瀹冭鐪嬭�呮椂寰楀埌锛� {}", app, streamId, mediaInfo.getString("msg"));
return -1;
}
- if ( code == 0 && ! mediaInfo.getBoolean("online")) {
+ if ( code == 0 && mediaInfo.getBoolean("online") != null && !mediaInfo.getBoolean("online")) {
logger.warn("鏌ヨ娴�({}/{})鏄惁鏈夊叾瀹冭鐪嬭�呮椂寰楀埌锛� {}", app, streamId, mediaInfo.getString("msg"));
return -1;
}
@@ -301,12 +328,12 @@
Boolean result = false;
JSONObject jsonObject = zlmresTfulUtils.stopSendRtp(mediaServerItem, param);
if (jsonObject == null) {
- logger.error("鍋滄RTP鎺ㄦ祦澶辫触: 璇锋鏌LM鏈嶅姟");
+ logger.error("[鍋滄RTP鎺ㄦ祦] 澶辫触: 璇锋鏌LM鏈嶅姟");
} else if (jsonObject.getInteger("code") == 0) {
result= true;
- logger.info("鍋滄RTP鎺ㄦ祦鎴愬姛");
+ logger.info("[鍋滄RTP鎺ㄦ祦] 鎴愬姛");
} else {
- logger.error("鍋滄RTP鎺ㄦ祦澶辫触: {}, 鍙傛暟锛歿}",jsonObject.getString("msg"),JSONObject.toJSON(param));
+ logger.error("[鍋滄RTP鎺ㄦ祦] 澶辫触: {}, 鍙傛暟锛歿}->\r\n{}",jsonObject.getString("msg"),JSONObject.toJSON(param), jsonObject);
}
return result;
}
--
Gitblit v1.8.0