feat(aiot): 配置推送使用camera_code查询StreamProxy
- 修改 buildFlatConfig 方法,使用 camera_code 查询 StreamProxy - 注入 StreamProxyMapper 依赖 - 优先使用 StreamProxy 的 srcUrl 作为 rtsp_url - 添加 camera_code 字段,保留 camera_id 字段向后兼容 - 当 StreamProxy 不存在时,降级使用 MediaServer 构建 URL Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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.gb28181.dao.CommonGBChannelMapper;
|
||||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||||
import com.genersoft.iot.vmp.media.service.IMediaServerService;
|
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 lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.connection.stream.MapRecord;
|
import org.springframework.data.redis.connection.stream.MapRecord;
|
||||||
@@ -53,6 +55,9 @@ public class AiRedisConfigServiceImpl implements IAiRedisConfigService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IMediaServerService mediaServerService;
|
private IMediaServerService mediaServerService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StreamProxyMapper streamProxyMapper;
|
||||||
|
|
||||||
private static final long KEY_EXPIRE_SECONDS = 86400 * 7; // 7天过期
|
private static final long KEY_EXPIRE_SECONDS = 86400 * 7; // 7天过期
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -486,7 +491,13 @@ public class AiRedisConfigServiceImpl implements IAiRedisConfigService {
|
|||||||
for (String cameraId : cameraIds) {
|
for (String cameraId : cameraIds) {
|
||||||
// 摄像头信息
|
// 摄像头信息
|
||||||
Map<String, Object> cameraMap = new LinkedHashMap<>();
|
Map<String, Object> 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 和摄像头名称
|
// 获取 RTSP URL 和摄像头名称
|
||||||
String rtspUrl = "";
|
String rtspUrl = "";
|
||||||
@@ -507,20 +518,27 @@ public class AiRedisConfigServiceImpl implements IAiRedisConfigService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建 RTSP 代理地址
|
// 优先使用 StreamProxy 中的源 URL
|
||||||
try {
|
if (proxy != null && proxy.getSrcUrl() != null && !proxy.getSrcUrl().isEmpty()) {
|
||||||
MediaServer mediaServer = mediaServerService.getDefaultMediaServer();
|
rtspUrl = proxy.getSrcUrl();
|
||||||
if (mediaServer != null && mediaServer.getRtspPort() != 0) {
|
log.debug("[AiRedis] 使用StreamProxy源URL: cameraCode={}, srcUrl={}", cameraId, rtspUrl);
|
||||||
rtspUrl = String.format("rtsp://%s:%s/%s",
|
} else {
|
||||||
mediaServer.getStreamIp() != null ? mediaServer.getStreamIp() : mediaServer.getIp(),
|
// 降级方案:构建 RTSP 代理地址(通过ZLM媒体服务器)
|
||||||
mediaServer.getRtspPort(), cameraId);
|
// cameraId格式为 {app}/{stream},ZLM的RTSP路径直接使用该格式
|
||||||
} else if (mediaServer != null) {
|
try {
|
||||||
rtspUrl = String.format("http://%s:%s/%s.live.flv",
|
MediaServer mediaServer = mediaServerService.getDefaultMediaServer();
|
||||||
mediaServer.getStreamIp() != null ? mediaServer.getStreamIp() : mediaServer.getIp(),
|
if (mediaServer != null && mediaServer.getRtspPort() != 0) {
|
||||||
mediaServer.getHttpPort(), cameraId);
|
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);
|
cameraMap.put("rtsp_url", rtspUrl);
|
||||||
|
|||||||
Reference in New Issue
Block a user