From 3496700a5ba18be8ca0590a79e21a867782d1ea9 Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Mon, 01 Jun 2026 16:56:57 +0800
Subject: [PATCH] 优化
---
ard-modules/ard-modules-zlm/src/main/java/com/ard/zlm/controller/ZlmController.java | 221 +++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 181 insertions(+), 40 deletions(-)
diff --git a/ard-modules/ard-modules-zlm/src/main/java/com/ard/zlm/controller/ZlmController.java b/ard-modules/ard-modules-zlm/src/main/java/com/ard/zlm/controller/ZlmController.java
index 940b32e..54a3f88 100644
--- a/ard-modules/ard-modules-zlm/src/main/java/com/ard/zlm/controller/ZlmController.java
+++ b/ard-modules/ard-modules-zlm/src/main/java/com/ard/zlm/controller/ZlmController.java
@@ -11,8 +11,8 @@
import com.ard.gb28181.api.domain.Device;
import com.ard.gb28181.api.domain.DeviceChannel;
import com.ard.gb28181.api.domain.GbChannelDTO;
-import com.ard.qs.api.RemoteQsDeviceService;
-import com.ard.qs.api.domain.QsDevice;
+import com.ard.zlm.domain.StreamChannel;
+import com.ard.zlm.service.ZlmStreamService;
import com.ard.work.api.RemoteCameraService;
import com.ard.zlm.api.domain.*;
import com.ard.zlm.common.InviteErrorCode;
@@ -68,7 +68,7 @@
private RemoteGb28181Service remoteGb28181Service;
@Resource
- private RemoteQsDeviceService remoteQsDeviceService;
+ private ZlmStreamService zlmStreamService;
@Resource
@Lazy
@@ -502,50 +502,50 @@
log.info("[gb28181 开始点播] id:{} ", id);
Assert.notNull(id, "设备id");
- R<QsDevice> qsDevicer = remoteQsDeviceService.getQsDeviceInfo(id, SecurityConstants.INNER);
+ R<StreamChannel> qsDevicer = zlmStreamService.getQsDeviceInfo(id, SecurityConstants.INNER);
if (qsDevicer.getCode() != Constants.SUCCESS) {
throw new RuntimeException("获取设备信息失败 id:" + id);
}
Assert.notNull(qsDevicer.getData(), "设备不存在 id:" + id);
- QsDevice qsDevice = qsDevicer.getData();
+ StreamChannel streamChannel = qsDevicer.getData();
- if ("OFFLINE".equals(qsDevice.getDeviceStatus())) {
+ if (!Boolean.TRUE.equals(streamChannel.getDeviceOnLine())) {
throw new RuntimeException("设备不在线 id:" + id);
}
- R<Device> deviceR = remoteGb28181Service.getDeviceByDeviceId(qsDevice.getGbDeviceId(), SecurityConstants.INNER);
+ R<Device> deviceR = remoteGb28181Service.getDeviceByDeviceId(streamChannel.getGbDeviceId(), SecurityConstants.INNER);
if (deviceR.getCode() != Constants.SUCCESS) {
- throw new RuntimeException("gb28181 获取设备信息失败 id:" + qsDevice.getGbDeviceId());
+ throw new RuntimeException("gb28181 获取设备信息失败 id:" + streamChannel.getGbDeviceId());
}
- Assert.notNull(deviceR.getData(), "gb28181 国标设备不存在 id:" + qsDevice.getGbDeviceId());
+ Assert.notNull(deviceR.getData(), "gb28181 国标设备不存在 id:" + streamChannel.getGbDeviceId());
if (!deviceR.getData().isOnLine()) {
- throw new RuntimeException("gb28181 国标设备不在线失败 id:" + qsDevice.getGbDeviceId());
+ throw new RuntimeException("gb28181 国标设备不在线失败 id:" + streamChannel.getGbDeviceId());
}
- R<DeviceChannel> deviceChannelR = remoteGb28181Service.getDeviceChannelByChannelId(qsDevice.getGbDeviceId(), qsDevice.getGbChannelId(), SecurityConstants.INNER);
+ R<DeviceChannel> deviceChannelR = remoteGb28181Service.getDeviceChannelByChannelId(streamChannel.getGbDeviceId(), streamChannel.getGbChannelId(), SecurityConstants.INNER);
if (deviceChannelR.getCode() != Constants.SUCCESS) {
- throw new RuntimeException("gb28181 获取设备通道失败 gbDeviceId:" + qsDevice.getGbDeviceId() + ",gbChannelId:" + qsDevice.getGbChannelId());
+ throw new RuntimeException("gb28181 获取设备通道失败 gbDeviceId:" + streamChannel.getGbDeviceId() + ",gbChannelId:" + streamChannel.getGbChannelId());
}
- Assert.notNull(deviceChannelR.getData(), "gb28181 获取设备通道失败不存在 gbDeviceId:" + qsDevice.getGbDeviceId() + ",gbChannelId:" + qsDevice.getGbChannelId());
+ Assert.notNull(deviceChannelR.getData(), "gb28181 获取设备通道失败不存在 gbDeviceId:" + streamChannel.getGbDeviceId() + ",gbChannelId:" + streamChannel.getGbChannelId());
if (!"ON".equals(deviceChannelR.getData().getStatus())) {
- throw new RuntimeException("gb28181 国标设备通道不在线失败 gbDeviceId:" + qsDevice.getGbDeviceId() + ",gbChannelId:" + qsDevice.getGbChannelId());
+ throw new RuntimeException("gb28181 国标设备通道不在线失败 gbDeviceId:" + streamChannel.getGbDeviceId() + ",gbChannelId:" + streamChannel.getGbChannelId());
}
DeferredResult<R<StreamContent>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue());
result.onTimeout(() -> {
- log.info("[点播等待超时] gbDeviceId:{}, gbChannelId:{}, ", qsDevice.getGbDeviceId(), qsDevice.getGbChannelId());
+ log.info("[点播等待超时] gbDeviceId:{}, gbChannelId:{}, ", streamChannel.getGbDeviceId(), streamChannel.getGbChannelId());
// 释放rtpserver
R<StreamContent> wvpResult = R.fail();
wvpResult.setMsg("点播超时");
result.setResult(wvpResult);
- inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, qsDevice.getId());
- mediaServerService.stopGb28181Play(InviteSessionType.PLAY, qsDevice, deviceR.getData(), qsDevice.getDeviceCode());
+ inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, streamChannel.getId());
+ mediaServerService.stopGb28181Play(InviteSessionType.PLAY, streamChannel, deviceR.getData(), streamChannel.getDeviceCode());
});
ErrorCallback<StreamInfo> callback = (code, msg, streamInfo) -> {
@@ -578,8 +578,8 @@
}
};
- qsDevice.setStreamMode(deviceR.getData().getStreamMode());
- mediaServerService.startGb28181Play(qsDevice, deviceR.getData(), callback);
+ streamChannel.setStreamMode(deviceR.getData().getStreamMode());
+ mediaServerService.startGb28181Play(streamChannel, deviceR.getData(), callback);
return result;
}
@@ -595,43 +595,43 @@
log.info("[gb28181 停止点播] id:{} ", id);
Assert.notNull(id, "设备id");
- R<QsDevice> qsDevicer = remoteQsDeviceService.getQsDeviceInfo(id, SecurityConstants.INNER);
+ R<StreamChannel> qsDevicer = zlmStreamService.getQsDeviceInfo(id, SecurityConstants.INNER);
if (qsDevicer.getCode() != Constants.SUCCESS) {
throw new RuntimeException("获取设备信息失败 id:" + id);
}
Assert.notNull(qsDevicer.getData(), "设备不存在 id:" + id);
- QsDevice qsDevice = qsDevicer.getData();
+ StreamChannel streamChannel = qsDevicer.getData();
- if ("OFFLINE".equals(qsDevice.getDeviceStatus())) {
+ if (!Boolean.TRUE.equals(streamChannel.getDeviceOnLine())) {
throw new RuntimeException("设备不在线 id:" + id);
}
- R<Device> deviceR = remoteGb28181Service.getDeviceByDeviceId(qsDevice.getGbDeviceId(), SecurityConstants.INNER);
+ R<Device> deviceR = remoteGb28181Service.getDeviceByDeviceId(streamChannel.getGbDeviceId(), SecurityConstants.INNER);
if (deviceR.getCode() != Constants.SUCCESS) {
- throw new RuntimeException("gb28181 获取设备信息失败 id:" + qsDevice.getGbDeviceId());
+ throw new RuntimeException("gb28181 获取设备信息失败 id:" + streamChannel.getGbDeviceId());
}
- Assert.notNull(deviceR.getData(), "gb28181 国标设备不存在 id:" + qsDevice.getGbDeviceId());
+ Assert.notNull(deviceR.getData(), "gb28181 国标设备不存在 id:" + streamChannel.getGbDeviceId());
if (!deviceR.getData().isOnLine()) {
- throw new RuntimeException("gb28181 国标设备不在线失败 id:" + qsDevice.getGbDeviceId());
+ throw new RuntimeException("gb28181 国标设备不在线失败 id:" + streamChannel.getGbDeviceId());
}
- R<DeviceChannel> deviceChannelR = remoteGb28181Service.getDeviceChannelByChannelId(qsDevice.getGbDeviceId(), qsDevice.getGbChannelId(), SecurityConstants.INNER);
+ R<DeviceChannel> deviceChannelR = remoteGb28181Service.getDeviceChannelByChannelId(streamChannel.getGbDeviceId(), streamChannel.getGbChannelId(), SecurityConstants.INNER);
if (deviceChannelR.getCode() != Constants.SUCCESS) {
- throw new RuntimeException("gb28181 获取设备通道失败 gbDeviceId:" + qsDevice.getGbDeviceId() + ",gbChannelId:" + qsDevice.getGbChannelId());
+ throw new RuntimeException("gb28181 获取设备通道失败 gbDeviceId:" + streamChannel.getGbDeviceId() + ",gbChannelId:" + streamChannel.getGbChannelId());
}
- Assert.notNull(deviceChannelR.getData(), "gb28181 获取设备通道失败不存在 gbDeviceId:" + qsDevice.getGbDeviceId() + ",gbChannelId:" + qsDevice.getGbChannelId());
+ Assert.notNull(deviceChannelR.getData(), "gb28181 获取设备通道失败不存在 gbDeviceId:" + streamChannel.getGbDeviceId() + ",gbChannelId:" + streamChannel.getGbChannelId());
if (!"ON".equals(deviceChannelR.getData().getStatus())) {
- throw new RuntimeException("gb28181 国标设备通道不在线失败 gbDeviceId:" + qsDevice.getGbDeviceId() + ",gbChannelId:" + qsDevice.getGbChannelId());
+ throw new RuntimeException("gb28181 国标设备通道不在线失败 gbDeviceId:" + streamChannel.getGbDeviceId() + ",gbChannelId:" + streamChannel.getGbChannelId());
}
- mediaServerService.stopGb28181Play(InviteSessionType.PLAY, qsDevice, deviceR.getData(), qsDevice.getDeviceCode());
+ mediaServerService.stopGb28181Play(InviteSessionType.PLAY, streamChannel, deviceR.getData(), streamChannel.getDeviceCode());
JSONObject json = new JSONObject();
- json.put("deviceId", qsDevice.getGbDeviceId());
- json.put("channelId", qsDevice.getGbChannelId());
+ json.put("deviceId", streamChannel.getGbDeviceId());
+ json.put("channelId", streamChannel.getGbChannelId());
return AjaxResult.success(json);
}
@@ -662,7 +662,7 @@
}
Assert.notNull(channelR.getData(), "GbChannel不存在 gbDeviceId:" + gbDeviceId + " gbChannelId:" + gbChannelId);
- GbChannelDTO gbChannelDTO = channelR.getData();
+ StreamChannel streamChannel = ZlmStreamService.toStreamChannel(channelR.getData());
// 2. 查询国标设备
R<Device> deviceR = remoteGb28181Service.getDeviceByDeviceId(gbDeviceId, SecurityConstants.INNER);
@@ -694,8 +694,8 @@
fail.setMsg("点播超时");
result.setResult(fail);
- inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, gbChannelDTO.getId());
- mediaServerService.stopGb28181PlayByGbChannel(InviteSessionType.PLAY, gbChannelDTO, deviceR.getData(), gbChannelDTO.getDeviceCode());
+ inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, streamChannel.getId());
+ mediaServerService.stopGb28181PlayByGbChannel(InviteSessionType.PLAY, streamChannel, deviceR.getData(), streamChannel.getDeviceCode());
});
ErrorCallback<StreamInfo> callback = (code, msg, streamInfo) -> {
@@ -728,7 +728,7 @@
}
};
- mediaServerService.startGb28181PlayByGbChannel(gbChannelDTO, deviceR.getData(), callback);
+ mediaServerService.startGb28181PlayByGbChannel(streamChannel, deviceR.getData(), callback);
return result;
}
@@ -755,7 +755,7 @@
throw new RuntimeException("GbChannel不存在 gbDeviceId:" + gbDeviceId + " gbChannelId:" + gbChannelId);
}
- GbChannelDTO gbChannelDTO = channelR.getData();
+ StreamChannel streamChannel = ZlmStreamService.toStreamChannel(channelR.getData());
// 2. 查询国标设备
R<Device> deviceR = remoteGb28181Service.getDeviceByDeviceId(gbDeviceId, SecurityConstants.INNER);
@@ -771,8 +771,8 @@
}
Assert.notNull(deviceChannelR.getData(), "gb28181 国标设备通道不存在 gbDeviceId:" + gbDeviceId + " gbChannelId:" + gbChannelId);
- mediaServerService.stopGb28181PlayByGbChannel(InviteSessionType.PLAY, gbChannelDTO,
- deviceR.getData(), gbChannelDTO.getDeviceCode());
+ mediaServerService.stopGb28181PlayByGbChannel(InviteSessionType.PLAY, streamChannel,
+ deviceR.getData(), streamChannel.getDeviceCode());
JSONObject json = new JSONObject();
json.put("gbDeviceId", gbDeviceId);
@@ -780,4 +780,145 @@
return AjaxResult.success(json);
}
+ /**
+ * gb28181 播放(基于GbChannel主键ID)
+ *
+ * @param request
+ * @param channelId GbChannel主键ID
+ * @return
+ */
+ @Operation(summary = "gb28181播放(按通道主键ID)")
+ @GetMapping("/startGb28181PlayByChannelId/{channelId}")
+ public DeferredResult<R<StreamContent>> startGb28181PlayByChannelId(
+ HttpServletRequest request,
+ @PathVariable Long channelId
+ ) {
+ log.info("[gb28181 开始点播] channelId:{}", channelId);
+ Assert.notNull(channelId, "通道ID不可为空");
+
+ // 1. 根据主键ID查询 GbChannel
+ R<GbChannelDTO> channelR = remoteGb28181Service.getGbChannelById(channelId, SecurityConstants.INNER);
+ if (channelR.getCode() != Constants.SUCCESS) {
+ throw new RuntimeException("获取GbChannel失败 channelId:" + channelId);
+ }
+ Assert.notNull(channelR.getData(), "GbChannel不存在 channelId:" + channelId);
+
+ StreamChannel streamChannel = ZlmStreamService.toStreamChannel(channelR.getData());
+ String gbDeviceId = streamChannel.getGbDeviceId();
+ String gbChannelId = streamChannel.getGbChannelId();
+
+ // 2. 查询国标设备
+ R<Device> deviceR = remoteGb28181Service.getDeviceByDeviceId(gbDeviceId, SecurityConstants.INNER);
+ if (deviceR.getCode() != Constants.SUCCESS) {
+ throw new RuntimeException("gb28181 获取设备信息失败 deviceId:" + gbDeviceId);
+ }
+ Assert.notNull(deviceR.getData(), "gb28181 国标设备不存在 deviceId:" + gbDeviceId);
+
+ if (!deviceR.getData().isOnLine()) {
+ throw new RuntimeException("gb28181 国标设备不在线 deviceId:" + gbDeviceId);
+ }
+
+ // 3. 查询国标通道
+ R<DeviceChannel> deviceChannelR = remoteGb28181Service.getDeviceChannelByChannelId(gbDeviceId, gbChannelId, SecurityConstants.INNER);
+ if (deviceChannelR.getCode() != Constants.SUCCESS) {
+ throw new RuntimeException("gb28181 获取设备通道失败 gbDeviceId:" + gbDeviceId + " gbChannelId:" + gbChannelId);
+ }
+ Assert.notNull(deviceChannelR.getData(), "gb28181 国标设备通道不存在 gbDeviceId:" + gbDeviceId + " gbChannelId:" + gbChannelId);
+
+ if (!"ON".equals(deviceChannelR.getData().getStatus())) {
+ throw new RuntimeException("gb28181 国标设备通道不在线 gbDeviceId:" + gbDeviceId + " gbChannelId:" + gbChannelId);
+ }
+
+ DeferredResult<R<StreamContent>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue());
+
+ result.onTimeout(() -> {
+ log.info("[点播等待超时] channelId:{}, gbDeviceId:{}, gbChannelId:{}", channelId, gbDeviceId, gbChannelId);
+ R<StreamContent> fail = R.fail();
+ fail.setMsg("点播超时");
+ result.setResult(fail);
+
+ inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, streamChannel.getId());
+ mediaServerService.stopGb28181PlayByGbChannel(InviteSessionType.PLAY, streamChannel, deviceR.getData(), streamChannel.getDeviceCode());
+ });
+
+ ErrorCallback<StreamInfo> callback = (code, msg, streamInfo) -> {
+ if (code == InviteErrorCode.SUCCESS.getCode()) {
+ R<StreamContent> r = R.ok();
+ if (streamInfo != null) {
+ if (userSetting.getUseSourceIpAsStreamIp()) {
+ streamInfo = streamInfo.clone();
+ String host;
+ try {
+ URL url = new URL(request.getRequestURL().toString());
+ host = url.getHost();
+ } catch (MalformedURLException e) {
+ host = request.getLocalAddr();
+ }
+ streamInfo.changeStreamIp(host);
+ }
+ if (!ObjectUtils.isEmpty(streamInfo.getMediaServer().getTranscodeSuffix())
+ && !"null".equalsIgnoreCase(streamInfo.getMediaServer().getTranscodeSuffix())) {
+ streamInfo.setStream(streamInfo.getStream() + "_" + streamInfo.getMediaServer().getTranscodeSuffix());
+ }
+ r.setData(new StreamContent(streamInfo));
+ } else {
+ r.setCode(code);
+ r.setMsg(msg);
+ }
+ result.setResult(r);
+ } else {
+ result.setResult(R.fail(code, msg));
+ }
+ };
+
+ mediaServerService.startGb28181PlayByGbChannel(streamChannel, deviceR.getData(), callback);
+ return result;
+ }
+
+ /**
+ * gb28181 停止点播(基于GbChannel主键ID)
+ *
+ * @param channelId GbChannel主键ID
+ * @return
+ */
+ @Operation(summary = "gb28181停止点播(按通道主键ID)")
+ @GetMapping("/stopGb28181PlayByChannelId/{channelId}")
+ public AjaxResult stopGb28181PlayByChannelId(@PathVariable Long channelId) {
+ log.info("[gb28181 停止点播] channelId:{}", channelId);
+ Assert.notNull(channelId, "通道ID不可为空");
+
+ // 1. 根据主键ID查询 GbChannel
+ R<GbChannelDTO> channelR = remoteGb28181Service.getGbChannelById(channelId, SecurityConstants.INNER);
+ if (channelR.getCode() != Constants.SUCCESS || channelR.getData() == null) {
+ throw new RuntimeException("GbChannel不存在 channelId:" + channelId);
+ }
+
+ StreamChannel streamChannel = ZlmStreamService.toStreamChannel(channelR.getData());
+ String gbDeviceId = streamChannel.getGbDeviceId();
+ String gbChannelId = streamChannel.getGbChannelId();
+
+ // 2. 查询国标设备
+ R<Device> deviceR = remoteGb28181Service.getDeviceByDeviceId(gbDeviceId, SecurityConstants.INNER);
+ if (deviceR.getCode() != Constants.SUCCESS) {
+ throw new RuntimeException("gb28181 获取设备信息失败 deviceId:" + gbDeviceId);
+ }
+ Assert.notNull(deviceR.getData(), "gb28181 国标设备不存在 deviceId:" + gbDeviceId);
+
+ // 3. 查询国标通道
+ R<DeviceChannel> deviceChannelR = remoteGb28181Service.getDeviceChannelByChannelId(gbDeviceId, gbChannelId, SecurityConstants.INNER);
+ if (deviceChannelR.getCode() != Constants.SUCCESS) {
+ throw new RuntimeException("gb28181 获取设备通道失败 gbDeviceId:" + gbDeviceId + " gbChannelId:" + gbChannelId);
+ }
+ Assert.notNull(deviceChannelR.getData(), "gb28181 国标设备通道不存在 gbDeviceId:" + gbDeviceId + " gbChannelId:" + gbChannelId);
+
+ mediaServerService.stopGb28181PlayByGbChannel(InviteSessionType.PLAY, streamChannel,
+ deviceR.getData(), streamChannel.getDeviceCode());
+
+ JSONObject json = new JSONObject();
+ json.put("channelId", channelId);
+ json.put("gbDeviceId", gbDeviceId);
+ json.put("gbChannelId", gbChannelId);
+ return AjaxResult.success(json);
+ }
+
}
--
Gitblit v1.9.3