From 450afb81129e86b5dc8610a0c91117d5198bacf9 Mon Sep 17 00:00:00 2001 From: 16337 <1633794139@qq.com> Date: Fri, 13 Feb 2026 11:09:50 +0800 Subject: [PATCH] =?UTF-8?q?feat(aiot):=20=E9=85=8D=E7=BD=AE=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E4=BD=BF=E7=94=A8camera=5Fcode=E6=9F=A5=E8=AF=A2Strea?= =?UTF-8?q?mProxy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 buildFlatConfig 方法,使用 camera_code 查询 StreamProxy - 注入 StreamProxyMapper 依赖 - 优先使用 StreamProxy 的 srcUrl 作为 rtsp_url - 添加 camera_code 字段,保留 camera_id 字段向后兼容 - 当 StreamProxy 不存在时,降级使用 MediaServer 构建 URL Co-Authored-By: Claude Opus 4.6 --- .../impl/AiRedisConfigServiceImpl.java | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/aiot/service/impl/AiRedisConfigServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/aiot/service/impl/AiRedisConfigServiceImpl.java index 4db90055e..f6048a321 100644 --- a/src/main/java/com/genersoft/iot/vmp/aiot/service/impl/AiRedisConfigServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/aiot/service/impl/AiRedisConfigServiceImpl.java @@ -15,6 +15,8 @@ import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel; import com.genersoft.iot.vmp.gb28181.dao.CommonGBChannelMapper; import com.genersoft.iot.vmp.media.bean.MediaServer; import com.genersoft.iot.vmp.media.service.IMediaServerService; +import com.genersoft.iot.vmp.streamProxy.bean.StreamProxy; +import com.genersoft.iot.vmp.streamProxy.dao.StreamProxyMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.connection.stream.MapRecord; @@ -53,6 +55,9 @@ public class AiRedisConfigServiceImpl implements IAiRedisConfigService { @Autowired private IMediaServerService mediaServerService; + @Autowired + private StreamProxyMapper streamProxyMapper; + private static final long KEY_EXPIRE_SECONDS = 86400 * 7; // 7天过期 @Override @@ -486,7 +491,13 @@ public class AiRedisConfigServiceImpl implements IAiRedisConfigService { for (String cameraId : cameraIds) { // 摄像头信息 Map cameraMap = new LinkedHashMap<>(); - cameraMap.put("camera_id", cameraId); + + // cameraId 现在是 camera_code 格式(从 ROI 表) + // 使用 camera_code 查询 StreamProxy 获取详细信息 + StreamProxy proxy = streamProxyMapper.selectByCameraCode(cameraId); + + cameraMap.put("camera_code", cameraId); // 新字段名 + cameraMap.put("camera_id", cameraId); // 保持向后兼容 // 获取 RTSP URL 和摄像头名称 String rtspUrl = ""; @@ -507,20 +518,27 @@ public class AiRedisConfigServiceImpl implements IAiRedisConfigService { } } - // 构建 RTSP 代理地址 - try { - MediaServer mediaServer = mediaServerService.getDefaultMediaServer(); - if (mediaServer != null && mediaServer.getRtspPort() != 0) { - rtspUrl = String.format("rtsp://%s:%s/%s", - mediaServer.getStreamIp() != null ? mediaServer.getStreamIp() : mediaServer.getIp(), - mediaServer.getRtspPort(), cameraId); - } else if (mediaServer != null) { - rtspUrl = String.format("http://%s:%s/%s.live.flv", - mediaServer.getStreamIp() != null ? mediaServer.getStreamIp() : mediaServer.getIp(), - mediaServer.getHttpPort(), cameraId); + // 优先使用 StreamProxy 中的源 URL + if (proxy != null && proxy.getSrcUrl() != null && !proxy.getSrcUrl().isEmpty()) { + rtspUrl = proxy.getSrcUrl(); + log.debug("[AiRedis] 使用StreamProxy源URL: cameraCode={}, srcUrl={}", cameraId, rtspUrl); + } else { + // 降级方案:构建 RTSP 代理地址(通过ZLM媒体服务器) + // cameraId格式为 {app}/{stream},ZLM的RTSP路径直接使用该格式 + try { + MediaServer mediaServer = mediaServerService.getDefaultMediaServer(); + if (mediaServer != null && mediaServer.getRtspPort() != 0) { + rtspUrl = String.format("rtsp://%s:%s/%s", + mediaServer.getStreamIp() != null ? mediaServer.getStreamIp() : mediaServer.getIp(), + mediaServer.getRtspPort(), cameraId); + } else if (mediaServer != null) { + rtspUrl = String.format("http://%s:%s/%s.live.flv", + mediaServer.getStreamIp() != null ? mediaServer.getStreamIp() : mediaServer.getIp(), + mediaServer.getHttpPort(), cameraId); + } + } catch (Exception e) { + log.warn("[AiRedis] 获取媒体服务器信息失败: {}", e.getMessage()); } - } catch (Exception e) { - log.warn("[AiRedis] 获取媒体服务器信息失败: {}", e.getMessage()); } cameraMap.put("rtsp_url", rtspUrl);