diff --git a/src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java b/src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java index f8d58695..1233455f 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java @@ -1,16 +1,12 @@ package com.genersoft.iot.vmp.service; -import com.alibaba.fastjson2.JSONObject; -import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.media.zlm.dto.ServerKeepaliveData; import com.genersoft.iot.vmp.service.bean.MediaServerLoad; import com.genersoft.iot.vmp.service.bean.SSRCInfo; -import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import java.util.List; -import java.util.Map; /** * 媒体服务节点 @@ -41,7 +37,7 @@ public interface IMediaServerService { */ void zlmServerOffline(String mediaServerId); - MediaServerItem getMediaServerForMinimumLoad(); + MediaServerItem getMediaServerForMinimumLoad(Boolean hasAssist); void setZLMConfig(MediaServerItem mediaServerItem, boolean restart); diff --git a/src/main/java/com/genersoft/iot/vmp/service/IPlayService.java b/src/main/java/com/genersoft/iot/vmp/service/IPlayService.java index c04965a3..ad59cb6e 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IPlayService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IPlayService.java @@ -31,6 +31,11 @@ public interface IPlayService { MediaServerItem getNewMediaServerItem(Device device); + /** + * 获取包含assist服务的节点 + */ + MediaServerItem getNewMediaServerItemHasAssist(Device device); + void onPublishHandlerForDownload(InviteStreamInfo inviteStreamInfo, String deviceId, String channelId, String toString); void playBack(String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback playBackCallback); diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java index db4d7b33..64105a63 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java @@ -487,7 +487,7 @@ public class MediaServerServiceImpl implements IMediaServerService { * @return MediaServerItem */ @Override - public MediaServerItem getMediaServerForMinimumLoad() { + public MediaServerItem getMediaServerForMinimumLoad(Boolean hasAssist) { String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetting.getServerId(); if (RedisUtil.zSize(key) == null || RedisUtil.zSize(key) == 0) { @@ -500,9 +500,31 @@ public class MediaServerServiceImpl implements IMediaServerService { // 获取分数最低的,及并发最低的 Set objects = RedisUtil.zRange(key, 0, -1); ArrayList mediaServerObjectS = new ArrayList<>(objects); + MediaServerItem mediaServerItem = null; + if (hasAssist == null) { + String mediaServerId = (String)mediaServerObjectS.get(0); + mediaServerItem = getOne(mediaServerId); + }else if (hasAssist) { + for (Object mediaServerObject : mediaServerObjectS) { + String mediaServerId = (String)mediaServerObject; + MediaServerItem serverItem = getOne(mediaServerId); + if (serverItem.getRecordAssistPort() > 0) { + mediaServerItem = serverItem; + break; + } + } + }else if (!hasAssist) { + for (Object mediaServerObject : mediaServerObjectS) { + String mediaServerId = (String)mediaServerObject; + MediaServerItem serverItem = getOne(mediaServerId); + if (serverItem.getRecordAssistPort() == 0) { + mediaServerItem = serverItem; + break; + } + } + } - String mediaServerId = (String)mediaServerObjectS.get(0); - return getOne(mediaServerId); + return mediaServerItem; } /** diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java index 123c8dd2..b8e7c8e5 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java @@ -39,8 +39,6 @@ import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; @@ -103,10 +101,6 @@ public class PlayServiceImpl implements IPlayService { private ZlmHttpHookSubscribe subscribe; - @Qualifier("taskExecutor") - @Autowired - private ThreadPoolTaskExecutor taskExecutor; - @Override public void play(MediaServerItem mediaServerItem, String deviceId, String channelId, ZlmHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent, @@ -412,7 +406,7 @@ public class PlayServiceImpl implements IPlayService { } MediaServerItem mediaServerItem; if (ObjectUtils.isEmpty(device.getMediaServerId()) || "auto".equals(device.getMediaServerId())) { - mediaServerItem = mediaServerService.getMediaServerForMinimumLoad(); + mediaServerItem = mediaServerService.getMediaServerForMinimumLoad(null); } else { mediaServerItem = mediaServerService.getOne(device.getMediaServerId()); } @@ -422,6 +416,23 @@ public class PlayServiceImpl implements IPlayService { return mediaServerItem; } + @Override + public MediaServerItem getNewMediaServerItemHasAssist(Device device) { + if (device == null) { + return null; + } + MediaServerItem mediaServerItem; + if (ObjectUtils.isEmpty(device.getMediaServerId()) || "auto".equals(device.getMediaServerId())) { + mediaServerItem = mediaServerService.getMediaServerForMinimumLoad(true); + } else { + mediaServerItem = mediaServerService.getOne(device.getMediaServerId()); + } + if (mediaServerItem == null) { + logger.warn("[获取可用的ZLM节点]未找到可使用的ZLM..."); + } + return mediaServerItem; + } + @Override public void playBack(String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback inviteStreamCallback, @@ -566,17 +577,25 @@ public class PlayServiceImpl implements IPlayService { @Override - public void download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) { + public void download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback playBackCallback) { Device device = storager.queryVideoDevice(deviceId); if (device == null) { return; } - MediaServerItem newMediaServerItem = getNewMediaServerItem(device); + MediaServerItem newMediaServerItem = getNewMediaServerItemHasAssist(device); + if (newMediaServerItem == null) { + PlayBackResult downloadResult = new PlayBackResult<>(); + downloadResult.setCode(ErrorCode.ERROR100.getCode()); + downloadResult.setMsg("未找到assist服务"); + playBackCallback.call(downloadResult); + return; + } SSRCInfo ssrcInfo = mediaServerService.openRTPServer(newMediaServerItem, null, device.isSsrcCheck(), true); - download(newMediaServerItem, ssrcInfo, deviceId, channelId, startTime, endTime, downloadSpeed, infoCallBack, hookCallBack); + download(newMediaServerItem, ssrcInfo, deviceId, channelId, startTime, endTime, downloadSpeed, infoCallBack, playBackCallback); } + @Override public void download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) { if (mediaServerItem == null || ssrcInfo == null) { @@ -659,7 +678,10 @@ public class PlayServiceImpl implements IPlayService { } if (mediaServerItem.getRecordAssistPort() > 0) { JSONObject jsonObject = assistRESTfulUtils.fileDuration(mediaServerItem, streamInfo.getApp(), streamInfo.getStream(), null); - if (jsonObject != null && jsonObject.getInteger("code") == 0) { + if (jsonObject == null) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "连接Assist服务失败"); + } + if (jsonObject.getInteger("code") == 0) { long duration = jsonObject.getLong("data"); if (duration == 0) { diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java index a2fd0884..ea0fd501 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java @@ -96,7 +96,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { public StreamInfo save(StreamProxyItem param) { MediaServerItem mediaInfo; if (ObjectUtils.isEmpty(param.getMediaServerId()) || "auto".equals(param.getMediaServerId())){ - mediaInfo = mediaServerService.getMediaServerForMinimumLoad(); + mediaInfo = mediaServerService.getMediaServerForMinimumLoad(null); }else { mediaInfo = mediaServerService.getOne(param.getMediaServerId()); } diff --git a/web_src/src/components/dialog/recordDownload.vue b/web_src/src/components/dialog/recordDownload.vue index b0b8feac..3e8c4271 100644 --- a/web_src/src/components/dialog/recordDownload.vue +++ b/web_src/src/components/dialog/recordDownload.vue @@ -6,18 +6,6 @@ - - - - - - - - - - - - 停止缓存并下载 @@ -51,6 +39,7 @@ export default { taskId: null, getProgressRun: false, getProgressForFileRun: false, + timer: null }; }, @@ -66,7 +55,7 @@ export default { this.percentage = 0.0; this.getProgressTimer() }, - getProgressTimer(){ + getProgressTimer: function (){ if (!this.getProgressRun) { return; } @@ -93,15 +82,24 @@ export default { this.percentage = (parseFloat(res.data.data.progress)*100).toFixed(1); } if (callback)callback(); + }else { + this.$message({ + showClose: true, + message: res.data.msg, + type: "error", + }); + this.close(); } }).catch((e) =>{ - + console.log(e) }); }, close: function (){ - if (this.streamInfo.progress < 100) { - this.stopDownloadRecord(); + this.stopDownloadRecord(); + if (this.timer !== null) { + window.clearTimeout(this.timer); + this.timer = null; } this.showDialog=false; this.getProgressRun = false;