From 9f327c33730ba10cb2d89aff99b727502232e968 Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Tue, 12 May 2026 17:11:52 +0800
Subject: [PATCH] 优化
---
ard-modules/ard-modules-zlm/src/main/java/com/ard/zlm/service/impl/MediaServerServiceImpl.java | 171 ++++++++++++++++++++++++++++----------------------------
1 files changed, 86 insertions(+), 85 deletions(-)
diff --git a/ard-modules/ard-modules-zlm/src/main/java/com/ard/zlm/service/impl/MediaServerServiceImpl.java b/ard-modules/ard-modules-zlm/src/main/java/com/ard/zlm/service/impl/MediaServerServiceImpl.java
index 1894f59..e6c636f 100644
--- a/ard-modules/ard-modules-zlm/src/main/java/com/ard/zlm/service/impl/MediaServerServiceImpl.java
+++ b/ard-modules/ard-modules-zlm/src/main/java/com/ard/zlm/service/impl/MediaServerServiceImpl.java
@@ -12,6 +12,9 @@
import com.ard.gb28181.api.domain.Device;
import com.ard.qs.api.RemoteQsDeviceService;
import com.ard.qs.api.domain.QsDevice;
+import com.ard.work.api.RemoteCameraService;
+import com.ard.work.api.RemoteChannelService;
+import com.ard.work.api.domian.ArdChannel;
import com.ard.zlm.api.domain.*;
import com.ard.zlm.api.hook.OriginType;
import com.ard.zlm.common.InviteErrorCode;
@@ -33,6 +36,7 @@
import com.ard.zlm.service.*;
import com.ard.zlm.session.SSRCFactory;
import com.ard.zlm.utils.ZLMRESTfulUtils;
+import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -61,57 +65,60 @@
@Service
public class MediaServerServiceImpl implements IMediaServerService {
- @Autowired
+ @Resource
private MediaServerMapper mediaServerMapper;
- @Autowired
+ @Resource
private UserSetting userSetting;
- @Autowired
+ @Resource
private Map<String, IMediaNodeServerService> nodeServerServiceMap;
- @Autowired
+ @Resource
private ApplicationEventPublisher applicationEventPublisher;
- @Autowired
+ @Resource
private RedisTemplate redisTemplate;
- @Autowired
+ @Resource
private IRedisCatchStorage redisCatchStorage;
- @Autowired
+ @Resource
private MediaConfig mediaConfig;
- @Autowired
+ @Resource
private IMediaNodeServerService mediaNodeServerService;
- @Autowired
+ @Resource
private DynamicTask dynamicTask;
- @Autowired
+ @Resource
private HookSubscribe subscribe;
- @Autowired
+ @Resource
private RemoteQsDeviceService remoteQsDeviceService;
- @Autowired
+ @Resource
+ private RemoteChannelService remoteChannelService;
+
+ @Resource
private ZLMRESTfulUtils zlmresTfulUtils;
- @Autowired
+ @Resource
private SSRCFactory ssrcFactory;
- @Autowired
+ @Resource
@Lazy
private IReceiveRtpServerService receiveRtpServerService;
- @Autowired
+ @Resource
@Lazy
private IInviteStreamService inviteStreamService;
- @Autowired
+ @Resource
private IZlmCloudRecordService zlmCloudRecordService;
- @Autowired
+ @Resource
private RemoteGb28181Service remoteGb28181Service;
@@ -624,18 +631,13 @@
callback.run(InviteErrorCode.FAIL.getCode(), "无可用的节点", null);
return;
}
- R<QsDevice> devicer = remoteQsDeviceService.getQsDeviceInfo(streamPullPlay.getDeviceId(), SecurityConstants
- .INNER);
- if (devicer.getCode() != Constants.SUCCESS) {
- throw new RuntimeException("获取设备信息失败" + streamPullPlay.getDeviceId());
+ R<ArdChannel> channel = remoteChannelService.getInfo(streamPullPlay.getChannelId(), SecurityConstants.INNER);
+ if (channel.getCode() != Constants.SUCCESS) {
+ throw new RuntimeException("获取通道信息失败" + streamPullPlay.getChannelId());
}
- if (devicer.getData() == null) {
- throw new RuntimeException("设备不存在" + streamPullPlay.getDeviceId());
- }
-
- if ("OFFLINE".equals(devicer.getData().getDeviceStatus())) {
- throw new RuntimeException("设备不在线" + streamPullPlay.getDeviceId());
+ if (channel.getData() == null) {
+ throw new RuntimeException("通道不存在" + streamPullPlay.getChannelId());
}
StreamInfo stream = getStreamInfoByAppAndStreamWithCheck(streamPullPlay.getApp(), streamPullPlay.getStream(),
@@ -668,10 +670,10 @@
callback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), streamInfo);
subscribe.removeSubscribe(rtpHook);
- QsDevice qsDevice = new QsDevice();
- qsDevice.setId(streamPullPlay.getDeviceId());
- qsDevice.setSnap(filePath);
- R<Boolean> r = remoteQsDeviceService.updateQsDevice(qsDevice, SecurityConstants.INNER);
+ ArdChannel ardChannel = new ArdChannel();
+ ardChannel.setId(streamPullPlay.getChannelId());
+ ardChannel.setSnapUrl(filePath);
+ R<Boolean> r = remoteChannelService.update(ardChannel, SecurityConstants.INNER);
if (r.getCode() != Constants.SUCCESS) {
throw new RuntimeException("更新设备失败");
}
@@ -686,12 +688,12 @@
}
String key = mediaNodeServerService.startProxy(mediaServer, streamPullPlay);
- QsDevice qsDevice = new QsDevice();
- qsDevice.setId(streamPullPlay.getDeviceId());
- qsDevice.setStreamKey(key);
- qsDevice.setMediaServerId(mediaServer.getId());
- qsDevice.setStreamStatus("1");
- R<Boolean> r = remoteQsDeviceService.updateQsDevice(qsDevice, SecurityConstants.INNER);
+ ArdChannel ardChannel = new ArdChannel();
+ ardChannel.setId(streamPullPlay.getChannelId());
+ ardChannel.setStreamKey(key);
+ ardChannel.setMediaServerId(mediaServer.getId());
+ //ardChannel.setStreamStatus("1");
+ R<Boolean> r = remoteChannelService.update(ardChannel, SecurityConstants.INNER);
if (r.getCode() != Constants.SUCCESS) {
log.error("更新设备失败");
callback.run(InviteErrorCode.FAIL.getCode(), "更新设备失败", null);
@@ -767,12 +769,12 @@
stopProxy(mediaServer, streamPullPlay.getStreamKey());
- QsDevice qsDevice = new QsDevice();
- qsDevice.setId(streamPullPlay.getDeviceId());
- qsDevice.setStreamKey("");
- qsDevice.setMediaServerId("");
- qsDevice.setStreamStatus("0");
- R<Boolean> r = remoteQsDeviceService.updateQsDevice(qsDevice, SecurityConstants.INNER);
+ ArdChannel ardChannel = new ArdChannel();
+ ardChannel.setId(streamPullPlay.getChannelId());
+ ardChannel.setStreamKey("");
+ ardChannel.setMediaServerId("");
+ // ardChannel.setStreamStatus("0");
+ R<Boolean> r = remoteChannelService.update(ardChannel, SecurityConstants.INNER);
if (r.getCode() != Constants.SUCCESS) {
throw new RuntimeException("更新设备失败");
}
@@ -797,7 +799,7 @@
throw new RuntimeException("[getSnap] 失败, mediaServer的类型: " + mediaServer.getType() + ",未找到对应的实现类");
}
String filePath = fileDomain + filePrefix + "/snap/" + fileName;
- mediaNodeServerService.getSnap(mediaServer, app, stream, 15, 1, this.filePath + "/snap", fileName);
+ mediaNodeServerService.getSnap(mediaServer, app, stream, 30, 300, this.filePath + "/snap", fileName);
return filePath;
}
@@ -945,7 +947,6 @@
* @param rtpServerParam 创建rtp端口请求参数
* @param device 设备信息
* @param ssrc ssrc
- * @param record 是否录制
* @param callback 回调
* @return
*/
@@ -1420,12 +1421,12 @@
/**
* 开始播放
*
- * @param device 设备信息
+ * @param ardChannel 通道信息
* @param record 是否录制
* @param callback 回调
*/
@Override
- public void play(QsDevice device, Boolean record, ErrorCallback<StreamInfo> callback) {
+ public void play(ArdChannel ardChannel, Boolean record, ErrorCallback<StreamInfo> callback) {
ZlmMediaServer mediaServer = getMediaServerForMinimumLoad(null);
if (mediaServer == null) {
@@ -1434,57 +1435,57 @@
}
// 播放海康sdk/播放海康isup/播放大华sdk
- if (LiveStreamType.HIK_SDK.getCode().equals(device.getType()) || LiveStreamType.HIK_ISUP.getCode().equals(device.getType()) || LiveStreamType.DAHUA_SDK.getCode().equals(device.getType())) {
- RTPServerParam rtpServerParam = new RTPServerParam();
- if (LiveStreamType.HIK_SDK.getCode().equals(device.getType())) {
- rtpServerParam.setApp("haikang");
- } else if (LiveStreamType.HIK_ISUP.getCode().equals(device.getType())) {
- rtpServerParam.setApp("haikang_isup");
- } else if (LiveStreamType.DAHUA_SDK.getCode().equals(device.getType())) {
- rtpServerParam.setApp("dahua");
- }
-
- rtpServerParam.setStreamId(device.getDeviceCode());
- rtpServerParam.setTcpMode(0);
- rtpServerParam.setType(device.getType());
- rtpServerParam.setId(device.getId());
- System.out.println(rtpServerParam);
- play(mediaServer, rtpServerParam, device, null, callback);
+ if (LiveStreamType.HIK_SDK.getCode().equals(ardChannel.getType()) || LiveStreamType.HIK_ISUP.getCode().equals(ardChannel.getType()) || LiveStreamType.DAHUA_SDK.getCode().equals(ardChannel.getType())) {
+// RTPServerParam rtpServerParam = new RTPServerParam();
+// if (LiveStreamType.HIK_SDK.getCode().equals(device.getType())) {
+// rtpServerParam.setApp("haikang");
+// } else if (LiveStreamType.HIK_ISUP.getCode().equals(device.getType())) {
+// rtpServerParam.setApp("haikang_isup");
+// } else if (LiveStreamType.DAHUA_SDK.getCode().equals(device.getType())) {
+// rtpServerParam.setApp("dahua");
+// }
+//
+// rtpServerParam.setStreamId(device.getDeviceCode());
+// rtpServerParam.setTcpMode(0);
+// rtpServerParam.setType(device.getType());
+// rtpServerParam.setId(device.getId());
+// System.out.println(rtpServerParam);
+// play(mediaServer, rtpServerParam, device, null, callback);
}
// rtsp/rtmp/flv/hls/onvif
- if (LiveStreamType.RTSP.getCode().equals(device.getType()) || LiveStreamType.RTMP.getCode().equals(device.getType()) || LiveStreamType.FLV.getCode().equals(device.getType()) || LiveStreamType.HLS.getCode().equals(device.getType()) || LiveStreamType.ONVIF.getCode().equals(device.getType())) {
+ if (LiveStreamType.RTSP.getCode().equals(ardChannel.getType()) || LiveStreamType.RTMP.getCode().equals(ardChannel.getType()) || LiveStreamType.FLV.getCode().equals(ardChannel.getType()) || LiveStreamType.HLS.getCode().equals(ardChannel.getType()) || LiveStreamType.ONVIF.getCode().equals(ardChannel.getType())) {
StreamPullPlay streamPullPlay = new StreamPullPlay();
- streamPullPlay.setDeviceId(device.getId());
- streamPullPlay.setStream(device.getDeviceCode());
- streamPullPlay.setUrl(device.getLiveAddress());
- streamPullPlay.setEnable_mp4("1".equals(device.getEnableMp4()));
- streamPullPlay.setEnable_audio("1".equals(device.getEnableAudio()));
+ streamPullPlay.setChannelId(ardChannel.getId());
+ streamPullPlay.setStream(ardChannel.getId());
+ streamPullPlay.setUrl(ardChannel.getLiveAddress());
+ streamPullPlay.setEnable_mp4(false);
+ streamPullPlay.setEnable_audio(true);
streamPullPlay.setRtp_type("1");
streamPullPlay.setTimeOut(10);
- if (LiveStreamType.RTSP.getCode().equals(device.getType())) {
+ if (LiveStreamType.RTSP.getCode().equals(ardChannel.getType())) {
streamPullPlay.setApp("rtsp");
- } else if (LiveStreamType.RTMP.getCode().equals(device.getType())) {
- streamPullPlay.setApp("rtmp");
- } else if (LiveStreamType.FLV.getCode().equals(device.getType())) {
- streamPullPlay.setApp("flv");
- if ("ws".equals(device.getFlvType())) {
- streamPullPlay.setUrl(convertWsToHttp(device.getLiveAddress()));
- }
- } else if (LiveStreamType.HLS.getCode().equals(device.getType())) {
- streamPullPlay.setApp("hls");
- } else if (LiveStreamType.ONVIF.getCode().equals(device.getType())) {
- streamPullPlay.setApp("onvif");
- }
+ } else if (LiveStreamType.RTMP.getCode().equals(ardChannel.getType())) {
+ streamPullPlay.setApp("rtmp");}
+// } else if (LiveStreamType.FLV.getCode().equals(device.getType())) {
+// streamPullPlay.setApp("flv");
+// if ("ws".equals(device.getFlvType())) {
+// streamPullPlay.setUrl(convertWsToHttp(device.getLiveAddress()));
+// }
+// } else if (LiveStreamType.HLS.getCode().equals(device.getType())) {
+// streamPullPlay.setApp("hls");
+// } else if (LiveStreamType.ONVIF.getCode().equals(device.getType())) {
+// streamPullPlay.setApp("onvif");
+// }
streamPullPlay(streamPullPlay, callback);
}
// 视频文件
- if (LiveStreamType.VIDEO_FILE.getCode().equals(device.getType())) {
- loadRecord(device.getId(), callback);
- }
+// if (LiveStreamType.VIDEO_FILE.getCode().equals(device.getType())) {
+// loadRecord(device.getId(), callback);
+// }
}
/**
--
Gitblit v1.9.3