From 764d04b497356ba6bcbb75fd42b51eca750f7223 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 29 五月 2024 15:02:51 +0800
Subject: [PATCH] 调整上级观看消息的发送

---
 src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaNodeServerService.java |  100 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 98 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaNodeServerService.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaNodeServerService.java
index 8fbe530..d9a6c6b 100644
--- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaNodeServerService.java
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaNodeServerService.java
@@ -6,6 +6,7 @@
 import com.genersoft.iot.vmp.common.CommonCallback;
 import com.genersoft.iot.vmp.common.StreamInfo;
 import com.genersoft.iot.vmp.conf.exception.ControllerException;
+import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
 import com.genersoft.iot.vmp.media.bean.MediaInfo;
 import com.genersoft.iot.vmp.media.service.IMediaNodeServerService;
 import com.genersoft.iot.vmp.media.bean.MediaServer;
@@ -45,7 +46,7 @@
 
     @Override
     public void closeRtpServer(MediaServer mediaServer, String streamId) {
-        zlmresTfulUtils.closeStreams(mediaServer, "rtp", streamId);
+        zlmServerFactory.closeRtpServer(mediaServer, streamId);
     }
 
     @Override
@@ -93,6 +94,8 @@
         MediaServer mediaServer = new MediaServer();
         mediaServer.setIp(ip);
         mediaServer.setHttpPort(port);
+        mediaServer.setFlvPort(port);
+        mediaServer.setWsFlvPort(port);
         mediaServer.setSecret(secret);
         JSONObject responseJSON = zlmresTfulUtils.getMediaServerConfig(mediaServer);
         if (responseJSON == null) {
@@ -108,12 +111,15 @@
         }
         mediaServer.setId(zlmServerConfig.getGeneralMediaServerId());
         mediaServer.setHttpSSlPort(zlmServerConfig.getHttpPort());
+        mediaServer.setFlvSSLPort(zlmServerConfig.getHttpPort());
+        mediaServer.setWsFlvSSLPort(zlmServerConfig.getHttpPort());
         mediaServer.setRtmpPort(zlmServerConfig.getRtmpPort());
         mediaServer.setRtmpSSlPort(zlmServerConfig.getRtmpSslPort());
         mediaServer.setRtspPort(zlmServerConfig.getRtspPort());
         mediaServer.setRtspSSLPort(zlmServerConfig.getRtspSSlport());
         mediaServer.setRtpProxyPort(zlmServerConfig.getRtpProxyPort());
         mediaServer.setStreamIp(ip);
+
         mediaServer.setHookIp(sipIp.split(",")[0]);
         mediaServer.setSdpIp(ip);
         mediaServer.setType("zlm");
@@ -130,8 +136,29 @@
             param.put("ssrc", ssrc);
         }
         JSONObject jsonObject = zlmresTfulUtils.stopSendRtp(mediaInfo, param);
-        return (jsonObject != null && jsonObject.getInteger("code") == 0);
+        if (jsonObject == null || jsonObject.getInteger("code") != 0 ) {
+            logger.error("鍋滄鍙戞祦澶辫触: {}, 鍙傛暟锛歿}", jsonObject.getString("msg"), JSON.toJSONString(param));
+            throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
+        }
+        return true;
 
+    }
+
+    @Override
+    public boolean initStopSendRtp(MediaServer mediaInfo, String app, String stream, String ssrc) {
+        Map<String, Object> param = new HashMap<>();
+        param.put("vhost", "__defaultVhost__");
+        param.put("app", app);
+        param.put("stream", stream);
+        if (!ObjectUtils.isEmpty(ssrc)) {
+            param.put("ssrc", ssrc);
+        }
+        JSONObject jsonObject = zlmresTfulUtils.stopSendRtp(mediaInfo, param);
+        if (jsonObject == null || jsonObject.getInteger("code") != 0 ) {
+            logger.error("鍋滄鍙戞祦澶辫触: {}, 鍙傛暟锛歿}", jsonObject.getString("msg"), JSON.toJSONString(param));
+            return false;
+        }
+        return true;
     }
 
     @Override
@@ -298,4 +325,73 @@
         }
         return result;
     }
+
+    @Override
+    public void startSendRtpPassive(MediaServer mediaServer, SendRtpItem sendRtpItem, Integer timeout) {
+        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");
+        param.put("is_udp", sendRtpItem.isTcp() ? "0" : "1");
+        param.put("recv_stream_id", sendRtpItem.getReceiveStream());
+        if (timeout  != null) {
+            param.put("close_delay_ms", timeout);
+        }
+        if (!sendRtpItem.isTcp()) {
+            // 寮�鍚痳tcp淇濇椿
+            param.put("udp_rtcp_timeout", sendRtpItem.isRtcp()? "1":"0");
+        }
+        if (!sendRtpItem.isTcpActive()) {
+            param.put("dst_url",sendRtpItem.getIp());
+            param.put("dst_port", sendRtpItem.getPort());
+        }
+
+        JSONObject jsonObject = zlmServerFactory.startSendRtpPassive(mediaServer, param, null);
+        if (jsonObject == null || jsonObject.getInteger("code") != 0 ) {
+            logger.error("鍚姩鐩戝惉TCP琚姩鎺ㄦ祦澶辫触: {}, 鍙傛暟锛歿}", jsonObject.getString("msg"), JSON.toJSONString(param));
+            throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
+        }
+        logger.info("璋冪敤ZLM-TCP琚姩鎺ㄦ祦鎺ュ彛, 缁撴灉锛� {}",  jsonObject);
+        logger.info("鍚姩鐩戝惉TCP琚姩鎺ㄦ祦鎴愬姛[ {}/{} ]锛寋}->{}:{}, " , sendRtpItem.getApp(), sendRtpItem.getStream(),
+                jsonObject.getString("local_port"), param.get("dst_url"), param.get("dst_port"));
+    }
+
+    @Override
+    public void startSendRtpStream(MediaServer mediaServer, SendRtpItem sendRtpItem) {
+        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");
+        param.put("is_udp", sendRtpItem.isTcp() ? "0" : "1");
+        if (!sendRtpItem.isTcp()) {
+            // udp妯″紡涓嬪紑鍚痳tcp淇濇椿
+            param.put("udp_rtcp_timeout", sendRtpItem.isRtcp() ? "1" : "0");
+        }
+        param.put("dst_url", sendRtpItem.getIp());
+        param.put("dst_port", sendRtpItem.getPort());
+        JSONObject jsonObject = zlmresTfulUtils.startSendRtp(mediaServer, param);
+        if (jsonObject == null || jsonObject.getInteger("code") != 0 ) {
+            throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
+        }
+    }
+
+    @Override
+    public Long updateDownloadProcess(MediaServer mediaServer, String app, String stream) {
+        MediaInfo mediaInfo = getMediaInfo(mediaServer, app, stream);
+        if (mediaInfo == null) {
+            logger.warn("[鑾峰彇涓嬭浇杩涘害] 鏌ヨ杩涘害澶辫触, 鑺傜偣Id锛� {}锛� {}/{}", mediaServer.getId(), app, stream);
+            return null;
+        }
+        return mediaInfo.getDuration();
+    }
 }

--
Gitblit v1.8.0