From f7a2d2a92d7e25780c91dd74ecf52e094b62ef4c Mon Sep 17 00:00:00 2001
From: panlinlin <648540858@qq.com>
Date: 星期一, 26 四月 2021 11:37:54 +0800
Subject: [PATCH] 去除所有的system.print, 优化日志显示

---
 src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java |   32 ++++++++++++++++++++++++++++----
 1 files changed, 28 insertions(+), 4 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 02fb742..97db56c 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
@@ -1,5 +1,6 @@
 package com.genersoft.iot.vmp.media.zlm;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
 import com.genersoft.iot.vmp.gb28181.session.SsrcUtil;
@@ -27,7 +28,28 @@
 
     private int currentPort = 0;
 
+    private Map<String, Integer> currentStreams = null;
+
     public int createRTPServer(String streamId) {
+        if (currentStreams == null) {
+            currentStreams = new HashMap<>();
+            JSONObject jsonObject = zlmresTfulUtils.listRtpServer();
+            JSONArray data = jsonObject.getJSONArray("data");
+            if (data != null) {
+                for (int i = 0; i < data.size(); i++) {
+                    JSONObject dataItem = data.getJSONObject(i);
+                    currentStreams.put(dataItem.getString("stream_id"), dataItem.getInteger("port"));
+                }
+            }
+        }
+        // 宸茬粡鍦ㄦ帹娴�
+        if (currentStreams.get(streamId) != null) {
+            Map<String, Object> closeRtpServerParam = new HashMap<>();
+            closeRtpServerParam.put("stream_id", streamId);
+            zlmresTfulUtils.closeRtpServer(closeRtpServerParam);
+            currentStreams.remove(streamId);
+        }
+
         Map<String, Object> param = new HashMap<>();
         int result = -1;
         int newPort = getPortFromUdpPortRange();
@@ -35,14 +57,16 @@
         param.put("enable_tcp", 1);
         param.put("stream_id", streamId);
         JSONObject jsonObject = zlmresTfulUtils.openRtpServer(param);
-        System.out.println(jsonObject);
 
         if (jsonObject != null) {
             switch (jsonObject.getInteger("code")){
                 case 0:
                     result= newPort;
                     break;
-                case -300: // id宸茬粡瀛樺湪
+                case -300: // id宸茬粡瀛樺湪, 鍙兘宸茬粡鍦ㄥ叾浠栫鍙f帹娴�
+                    Map<String, Object> closeRtpServerParam = new HashMap<>();
+                    closeRtpServerParam.put("stream_id", streamId);
+                    zlmresTfulUtils.closeRtpServer(closeRtpServerParam);
                     result = newPort;
                     break;
                 case -400: // 绔彛鍗犵敤
@@ -165,7 +189,7 @@
     public Boolean startSendRtpStream(Map<String, Object>param) {
         Boolean result = false;
         JSONObject jsonObject = zlmresTfulUtils.startSendRtp(param);
-        System.out.println(jsonObject);
+        logger.info(jsonObject.toJSONString());
         if (jsonObject == null) {
             logger.error("RTP鎺ㄦ祦澶辫触: 璇锋鏌LM鏈嶅姟");
         } else if (jsonObject.getInteger("code") == 0) {
@@ -209,7 +233,7 @@
     public Boolean stopSendRtpStream(Map<String, Object>param) {
         Boolean result = false;
         JSONObject jsonObject = zlmresTfulUtils.stopSendRtp(param);
-        System.out.println(jsonObject);
+        logger.info(jsonObject.toJSONString());
         if (jsonObject == null) {
             logger.error("鍋滄RTP鎺ㄦ祦澶辫触: 璇锋鏌LM鏈嶅姟");
         } else if (jsonObject.getInteger("code") == 0) {

--
Gitblit v1.8.0