fix(aiot): 修复配置推送 rtsp_url 为空的问题
- selectByCameraCode 返回 null 时跳过该摄像头,不再推送空 rtsp_url - ZLM 回退 URL 改用 proxy 的 app/stream 构建,修复原先用 camera_code 格式导致的无效路径 - 行为与 buildPayloadFromFlat (HTTP推送) 保持一致 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -492,15 +492,19 @@ public class AiRedisConfigServiceImpl implements IAiRedisConfigService {
|
|||||||
// 摄像头信息
|
// 摄像头信息
|
||||||
Map<String, Object> cameraMap = new LinkedHashMap<>();
|
Map<String, Object> cameraMap = new LinkedHashMap<>();
|
||||||
|
|
||||||
// cameraId 现在是 camera_code 格式(从 ROI 表)
|
// 使用 camera_code 查询 StreamProxy 获取 RTSP 源地址
|
||||||
// 使用 camera_code 查询 StreamProxy 获取详细信息
|
|
||||||
StreamProxy proxy = streamProxyMapper.selectByCameraCode(cameraId);
|
StreamProxy proxy = streamProxyMapper.selectByCameraCode(cameraId);
|
||||||
|
|
||||||
cameraMap.put("camera_code", cameraId); // 新字段名
|
if (proxy == null) {
|
||||||
cameraMap.put("camera_id", cameraId); // 保持向后兼容
|
log.warn("[AiRedis] 摄像头 {} 在 stream_proxy 表中未找到(camera_code 不匹配),跳过。" +
|
||||||
|
"请确认该摄像头的 camera_code 已正确写入 wvp_stream_proxy 表", cameraId);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// 获取 RTSP URL 和摄像头名称
|
cameraMap.put("camera_code", cameraId);
|
||||||
String rtspUrl = "";
|
cameraMap.put("camera_id", cameraId);
|
||||||
|
|
||||||
|
// 获取摄像头名称
|
||||||
String cameraName = "";
|
String cameraName = "";
|
||||||
List<AiRoi> cameraRois = roiMapper.queryAllByCameraId(cameraId);
|
List<AiRoi> cameraRois = roiMapper.queryAllByCameraId(cameraId);
|
||||||
|
|
||||||
@@ -518,48 +522,44 @@ public class AiRedisConfigServiceImpl implements IAiRedisConfigService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 优先使用 StreamProxy 中的源 URL
|
// 获取 RTSP URL:优先使用 StreamProxy 的源 URL
|
||||||
if (proxy != null && proxy.getSrcUrl() != null && !proxy.getSrcUrl().isEmpty()) {
|
String rtspUrl = "";
|
||||||
|
if (proxy.getSrcUrl() != null && !proxy.getSrcUrl().isEmpty()) {
|
||||||
rtspUrl = proxy.getSrcUrl();
|
rtspUrl = proxy.getSrcUrl();
|
||||||
log.debug("[AiRedis] 使用StreamProxy源URL: cameraCode={}, srcUrl={}", cameraId, rtspUrl);
|
log.debug("[AiRedis] 使用StreamProxy源URL: cameraCode={}, srcUrl={}", cameraId, rtspUrl);
|
||||||
} else {
|
} else {
|
||||||
// 降级方案:构建 RTSP 代理地址(通过ZLM媒体服务器)
|
// 降级方案:用 proxy 的 app/stream 通过 ZLM 媒体服务器构建代理地址
|
||||||
// cameraId格式为 {app}/{stream},ZLM的RTSP路径直接使用该格式
|
|
||||||
try {
|
try {
|
||||||
MediaServer mediaServer = mediaServerService.getDefaultMediaServer();
|
MediaServer mediaServer = mediaServerService.getDefaultMediaServer();
|
||||||
if (mediaServer == null) {
|
if (mediaServer != null && proxy.getApp() != null && proxy.getStream() != null) {
|
||||||
log.warn("[AiRedis] 无法获取媒体服务器配置,请检查 ZLM 媒体服务器是否已配置");
|
if (mediaServer.getRtspPort() != 0) {
|
||||||
} else if (mediaServer.getRtspPort() != 0) {
|
rtspUrl = String.format("rtsp://%s:%s/%s/%s",
|
||||||
rtspUrl = String.format("rtsp://%s:%s/%s",
|
mediaServer.getStreamIp() != null ? mediaServer.getStreamIp() : mediaServer.getIp(),
|
||||||
mediaServer.getStreamIp() != null ? mediaServer.getStreamIp() : mediaServer.getIp(),
|
mediaServer.getRtspPort(), proxy.getApp(), proxy.getStream());
|
||||||
mediaServer.getRtspPort(), cameraId);
|
log.debug("[AiRedis] 使用ZLM代理构建RTSP: {}", rtspUrl);
|
||||||
log.debug("[AiRedis] 使用媒体服务器构建RTSP: {}", rtspUrl);
|
} else if (mediaServer.getHttpPort() != 0) {
|
||||||
} else if (mediaServer.getHttpPort() != 0) {
|
rtspUrl = String.format("http://%s:%s/%s/%s.live.flv",
|
||||||
rtspUrl = String.format("http://%s:%s/%s.live.flv",
|
mediaServer.getStreamIp() != null ? mediaServer.getStreamIp() : mediaServer.getIp(),
|
||||||
mediaServer.getStreamIp() != null ? mediaServer.getStreamIp() : mediaServer.getIp(),
|
mediaServer.getHttpPort(), proxy.getApp(), proxy.getStream());
|
||||||
mediaServer.getHttpPort(), cameraId);
|
log.debug("[AiRedis] 使用ZLM代理构建HTTP-FLV: {}", rtspUrl);
|
||||||
log.debug("[AiRedis] 使用媒体服务器构建HTTP: {}", rtspUrl);
|
}
|
||||||
} else {
|
|
||||||
log.warn("[AiRedis] 媒体服务器 {} 未配置 RTSP/HTTP 端口", mediaServer.getIp());
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("[AiRedis] 获取媒体服务器信息失败: {}", e.getMessage());
|
log.warn("[AiRedis] 获取媒体服务器信息失败: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 无有效 RTSP URL 则跳过,不推送空地址给 Edge
|
||||||
|
if (rtspUrl == null || rtspUrl.isEmpty()) {
|
||||||
|
log.warn("[AiRedis] 摄像头 {} 有 stream_proxy 记录但无有效 RTSP 地址(srcUrl 为空且 ZLM 不可用),跳过", cameraId);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
cameraMap.put("camera_name", cameraName);
|
cameraMap.put("camera_name", cameraName);
|
||||||
cameraMap.put("enabled", true);
|
cameraMap.put("enabled", true);
|
||||||
cameraMap.put("location", "");
|
cameraMap.put("location", "");
|
||||||
|
cameraMap.put("rtsp_url", rtspUrl);
|
||||||
// 如果没有有效的 RTSP URL,记录警告但仍然添加摄像头(让 Edge 知道它的存在)
|
cameraMap.put("rtsp_url_valid", true);
|
||||||
if (rtspUrl == null || rtspUrl.isEmpty()) {
|
|
||||||
log.warn("[AiRedis] 摄像头 {} 没有有效的 RTSP 地址(请检查 stream_proxy 表或媒体服务器配置)", cameraId);
|
|
||||||
cameraMap.put("rtsp_url", "");
|
|
||||||
cameraMap.put("rtsp_url_valid", false);
|
|
||||||
} else {
|
|
||||||
cameraMap.put("rtsp_url", rtspUrl);
|
|
||||||
cameraMap.put("rtsp_url_valid", true);
|
|
||||||
}
|
|
||||||
cameras.add(cameraMap);
|
cameras.add(cameraMap);
|
||||||
|
|
||||||
// 该摄像头下的 ROI 和绑定
|
// 该摄像头下的 ROI 和绑定
|
||||||
|
|||||||
Reference in New Issue
Block a user