From 504eaab19115cad29fe1fe91f1bb478052ac4196 Mon Sep 17 00:00:00 2001
From: zhaowenyu <35589726@qq.com>
Date: Thu, 02 Apr 2026 16:50:29 +0800
Subject: [PATCH] 2026-04-02 优化机场视频推流顺序;在RTMP中先入库再推流,在RTSP单独推流。

---
 ard-sample/src/main/java/com/ard/sample/component/websocket/handler/LiveStreamHandler.java |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/ard-sample/src/main/java/com/ard/sample/component/websocket/handler/LiveStreamHandler.java b/ard-sample/src/main/java/com/ard/sample/component/websocket/handler/LiveStreamHandler.java
index 2a0014e..0cfc482 100644
--- a/ard-sample/src/main/java/com/ard/sample/component/websocket/handler/LiveStreamHandler.java
+++ b/ard-sample/src/main/java/com/ard/sample/component/websocket/handler/LiveStreamHandler.java
@@ -31,16 +31,22 @@
     /**
      * 开启直播
      */
-    public void StartLiveStreaming(String sn) {
+    public void StartLiveStreaming(String sn ,String userId) {
         //调用开始直播
         ResponseResult rlive = null;
         String resultLive = "";
         try {
             // 获取直播参数
             LiveTypeDTO param = getLiveParam(sn);
+            // 判断param是否为空,不为空则返回正确的直播参数,为null则未获取直播参数,不为空则继续操作
+            if (param == null) {
+                log.info("SN: {}-未获取到直播参数param为null,无法开启直播!", sn);
+                return;
+            }
             // 如果存在直播则读取直播地址返回
             if (RedisOpsUtils.checkExist(RedisConst.WEBSOCKET_VIDEO_ADDRESS_PREFIX + sn)) {
                 resultLive = String.valueOf(RedisOpsUtils.get(RedisConst.WEBSOCKET_VIDEO_ADDRESS_PREFIX + sn));
+                log.info("SN: {}-redis中存在相机的播放地址信息,直接返回地址!", sn);
             } else {
                 log.info("SN: {}-redis中未找到相机的播放地址信息!停止直播后再开启直播", sn);
                 StopLiveStreaming(sn);
@@ -59,8 +65,11 @@
                         log.info("SN: {}-更新webrtc地址成功!", sn);
                     }
                 }
+                else {
+                    log.info("SN: {}-开启直播失败!返回值:{}", sn, rlive);
+                }
             }
-            _dockWebSocketHandler.sendMessageToSubscribers(sn, MessageType.LIVESTREAM.getType(), resultLive);
+            _dockWebSocketHandler.sendMessageToSubscribers(sn, MessageType.LIVESTREAM.getType(), resultLive, userId);
             log.info("SN: {}-直播地址:{}", sn, resultLive);
         } catch (Exception e) {
             log.info("SN: {}-开启直播失败!原因:{}", sn, e.getMessage());
@@ -76,6 +85,7 @@
             LiveTypeDTO param = getLiveParam(sn);
             // 停止直播逻辑
             rlive = _liveStreamService.liveStop(param.getVideoId());
+            log.info("SN: {}-停止直播!返回值:{}", sn, rlive);
 //            rlive.setGateway(sn);
 //            rlive.setType(MessageType.LIVESTREAM.getType());
 //            resultLive = _objectMapper.writeValueAsString(rlive);
@@ -121,8 +131,9 @@
         List<CapacityDeviceDTO> devicesList = _liveStreamService.getLiveCapacity();
         if (devicesList == null || devicesList.isEmpty()) {
             log.info("SN: {}-未获得设备直播能力!", sn);
+            return null;
             // 抛弃出异常,给调用者处理
-            throw new Exception("未获得设备直播能力!");
+            // throw new Exception("未获得设备直播能力!");
         }
         for (CapacityDeviceDTO device : devicesList) {
             if (!device.getSn().equals(sn)) {

--
Gitblit v1.9.3