Commit 8b0662ebfeecad2b646689aacb4d7d6a45973eb4
1 parent
88878940
优化国标录像下载错误提示
Showing
6 changed files
with
79 additions
and
36 deletions
src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java
| 1 | package com.genersoft.iot.vmp.service; | 1 | package com.genersoft.iot.vmp.service; |
| 2 | 2 | ||
| 3 | -import com.alibaba.fastjson2.JSONObject; | ||
| 4 | -import com.genersoft.iot.vmp.gb28181.bean.Device; | ||
| 5 | import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig; | 3 | import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig; |
| 6 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | 4 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 7 | import com.genersoft.iot.vmp.media.zlm.dto.ServerKeepaliveData; | 5 | import com.genersoft.iot.vmp.media.zlm.dto.ServerKeepaliveData; |
| 8 | import com.genersoft.iot.vmp.service.bean.MediaServerLoad; | 6 | import com.genersoft.iot.vmp.service.bean.MediaServerLoad; |
| 9 | import com.genersoft.iot.vmp.service.bean.SSRCInfo; | 7 | import com.genersoft.iot.vmp.service.bean.SSRCInfo; |
| 10 | -import com.genersoft.iot.vmp.vmanager.bean.WVPResult; | ||
| 11 | 8 | ||
| 12 | import java.util.List; | 9 | import java.util.List; |
| 13 | -import java.util.Map; | ||
| 14 | 10 | ||
| 15 | /** | 11 | /** |
| 16 | * 媒体服务节点 | 12 | * 媒体服务节点 |
| @@ -41,7 +37,7 @@ public interface IMediaServerService { | @@ -41,7 +37,7 @@ public interface IMediaServerService { | ||
| 41 | */ | 37 | */ |
| 42 | void zlmServerOffline(String mediaServerId); | 38 | void zlmServerOffline(String mediaServerId); |
| 43 | 39 | ||
| 44 | - MediaServerItem getMediaServerForMinimumLoad(); | 40 | + MediaServerItem getMediaServerForMinimumLoad(Boolean hasAssist); |
| 45 | 41 | ||
| 46 | void setZLMConfig(MediaServerItem mediaServerItem, boolean restart); | 42 | void setZLMConfig(MediaServerItem mediaServerItem, boolean restart); |
| 47 | 43 |
src/main/java/com/genersoft/iot/vmp/service/IPlayService.java
| @@ -31,6 +31,11 @@ public interface IPlayService { | @@ -31,6 +31,11 @@ public interface IPlayService { | ||
| 31 | 31 | ||
| 32 | MediaServerItem getNewMediaServerItem(Device device); | 32 | MediaServerItem getNewMediaServerItem(Device device); |
| 33 | 33 | ||
| 34 | + /** | ||
| 35 | + * 获取包含assist服务的节点 | ||
| 36 | + */ | ||
| 37 | + MediaServerItem getNewMediaServerItemHasAssist(Device device); | ||
| 38 | + | ||
| 34 | void onPublishHandlerForDownload(InviteStreamInfo inviteStreamInfo, String deviceId, String channelId, String toString); | 39 | void onPublishHandlerForDownload(InviteStreamInfo inviteStreamInfo, String deviceId, String channelId, String toString); |
| 35 | 40 | ||
| 36 | void playBack(String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback playBackCallback); | 41 | void playBack(String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback playBackCallback); |
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
| @@ -487,7 +487,7 @@ public class MediaServerServiceImpl implements IMediaServerService { | @@ -487,7 +487,7 @@ public class MediaServerServiceImpl implements IMediaServerService { | ||
| 487 | * @return MediaServerItem | 487 | * @return MediaServerItem |
| 488 | */ | 488 | */ |
| 489 | @Override | 489 | @Override |
| 490 | - public MediaServerItem getMediaServerForMinimumLoad() { | 490 | + public MediaServerItem getMediaServerForMinimumLoad(Boolean hasAssist) { |
| 491 | String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetting.getServerId(); | 491 | String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetting.getServerId(); |
| 492 | 492 | ||
| 493 | if (RedisUtil.zSize(key) == null || RedisUtil.zSize(key) == 0) { | 493 | if (RedisUtil.zSize(key) == null || RedisUtil.zSize(key) == 0) { |
| @@ -500,9 +500,31 @@ public class MediaServerServiceImpl implements IMediaServerService { | @@ -500,9 +500,31 @@ public class MediaServerServiceImpl implements IMediaServerService { | ||
| 500 | // 获取分数最低的,及并发最低的 | 500 | // 获取分数最低的,及并发最低的 |
| 501 | Set<Object> objects = RedisUtil.zRange(key, 0, -1); | 501 | Set<Object> objects = RedisUtil.zRange(key, 0, -1); |
| 502 | ArrayList<Object> mediaServerObjectS = new ArrayList<>(objects); | 502 | ArrayList<Object> mediaServerObjectS = new ArrayList<>(objects); |
| 503 | + MediaServerItem mediaServerItem = null; | ||
| 504 | + if (hasAssist == null) { | ||
| 505 | + String mediaServerId = (String)mediaServerObjectS.get(0); | ||
| 506 | + mediaServerItem = getOne(mediaServerId); | ||
| 507 | + }else if (hasAssist) { | ||
| 508 | + for (Object mediaServerObject : mediaServerObjectS) { | ||
| 509 | + String mediaServerId = (String)mediaServerObject; | ||
| 510 | + MediaServerItem serverItem = getOne(mediaServerId); | ||
| 511 | + if (serverItem.getRecordAssistPort() > 0) { | ||
| 512 | + mediaServerItem = serverItem; | ||
| 513 | + break; | ||
| 514 | + } | ||
| 515 | + } | ||
| 516 | + }else if (!hasAssist) { | ||
| 517 | + for (Object mediaServerObject : mediaServerObjectS) { | ||
| 518 | + String mediaServerId = (String)mediaServerObject; | ||
| 519 | + MediaServerItem serverItem = getOne(mediaServerId); | ||
| 520 | + if (serverItem.getRecordAssistPort() == 0) { | ||
| 521 | + mediaServerItem = serverItem; | ||
| 522 | + break; | ||
| 523 | + } | ||
| 524 | + } | ||
| 525 | + } | ||
| 503 | 526 | ||
| 504 | - String mediaServerId = (String)mediaServerObjectS.get(0); | ||
| 505 | - return getOne(mediaServerId); | 527 | + return mediaServerItem; |
| 506 | } | 528 | } |
| 507 | 529 | ||
| 508 | /** | 530 | /** |
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
| @@ -39,8 +39,6 @@ import com.genersoft.iot.vmp.vmanager.bean.WVPResult; | @@ -39,8 +39,6 @@ import com.genersoft.iot.vmp.vmanager.bean.WVPResult; | ||
| 39 | import org.slf4j.Logger; | 39 | import org.slf4j.Logger; |
| 40 | import org.slf4j.LoggerFactory; | 40 | import org.slf4j.LoggerFactory; |
| 41 | import org.springframework.beans.factory.annotation.Autowired; | 41 | import org.springframework.beans.factory.annotation.Autowired; |
| 42 | -import org.springframework.beans.factory.annotation.Qualifier; | ||
| 43 | -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
| 44 | import org.springframework.stereotype.Service; | 42 | import org.springframework.stereotype.Service; |
| 45 | import org.springframework.util.ObjectUtils; | 43 | import org.springframework.util.ObjectUtils; |
| 46 | 44 | ||
| @@ -103,10 +101,6 @@ public class PlayServiceImpl implements IPlayService { | @@ -103,10 +101,6 @@ public class PlayServiceImpl implements IPlayService { | ||
| 103 | private ZlmHttpHookSubscribe subscribe; | 101 | private ZlmHttpHookSubscribe subscribe; |
| 104 | 102 | ||
| 105 | 103 | ||
| 106 | - @Qualifier("taskExecutor") | ||
| 107 | - @Autowired | ||
| 108 | - private ThreadPoolTaskExecutor taskExecutor; | ||
| 109 | - | ||
| 110 | @Override | 104 | @Override |
| 111 | public void play(MediaServerItem mediaServerItem, String deviceId, String channelId, | 105 | public void play(MediaServerItem mediaServerItem, String deviceId, String channelId, |
| 112 | ZlmHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent, | 106 | ZlmHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent, |
| @@ -412,7 +406,7 @@ public class PlayServiceImpl implements IPlayService { | @@ -412,7 +406,7 @@ public class PlayServiceImpl implements IPlayService { | ||
| 412 | } | 406 | } |
| 413 | MediaServerItem mediaServerItem; | 407 | MediaServerItem mediaServerItem; |
| 414 | if (ObjectUtils.isEmpty(device.getMediaServerId()) || "auto".equals(device.getMediaServerId())) { | 408 | if (ObjectUtils.isEmpty(device.getMediaServerId()) || "auto".equals(device.getMediaServerId())) { |
| 415 | - mediaServerItem = mediaServerService.getMediaServerForMinimumLoad(); | 409 | + mediaServerItem = mediaServerService.getMediaServerForMinimumLoad(null); |
| 416 | } else { | 410 | } else { |
| 417 | mediaServerItem = mediaServerService.getOne(device.getMediaServerId()); | 411 | mediaServerItem = mediaServerService.getOne(device.getMediaServerId()); |
| 418 | } | 412 | } |
| @@ -423,6 +417,23 @@ public class PlayServiceImpl implements IPlayService { | @@ -423,6 +417,23 @@ public class PlayServiceImpl implements IPlayService { | ||
| 423 | } | 417 | } |
| 424 | 418 | ||
| 425 | @Override | 419 | @Override |
| 420 | + public MediaServerItem getNewMediaServerItemHasAssist(Device device) { | ||
| 421 | + if (device == null) { | ||
| 422 | + return null; | ||
| 423 | + } | ||
| 424 | + MediaServerItem mediaServerItem; | ||
| 425 | + if (ObjectUtils.isEmpty(device.getMediaServerId()) || "auto".equals(device.getMediaServerId())) { | ||
| 426 | + mediaServerItem = mediaServerService.getMediaServerForMinimumLoad(true); | ||
| 427 | + } else { | ||
| 428 | + mediaServerItem = mediaServerService.getOne(device.getMediaServerId()); | ||
| 429 | + } | ||
| 430 | + if (mediaServerItem == null) { | ||
| 431 | + logger.warn("[获取可用的ZLM节点]未找到可使用的ZLM..."); | ||
| 432 | + } | ||
| 433 | + return mediaServerItem; | ||
| 434 | + } | ||
| 435 | + | ||
| 436 | + @Override | ||
| 426 | public void playBack(String deviceId, String channelId, String startTime, | 437 | public void playBack(String deviceId, String channelId, String startTime, |
| 427 | String endTime, InviteStreamCallback inviteStreamCallback, | 438 | String endTime, InviteStreamCallback inviteStreamCallback, |
| 428 | PlayBackCallback callback) { | 439 | PlayBackCallback callback) { |
| @@ -566,17 +577,25 @@ public class PlayServiceImpl implements IPlayService { | @@ -566,17 +577,25 @@ public class PlayServiceImpl implements IPlayService { | ||
| 566 | 577 | ||
| 567 | 578 | ||
| 568 | @Override | 579 | @Override |
| 569 | - public void download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) { | 580 | + public void download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback playBackCallback) { |
| 570 | Device device = storager.queryVideoDevice(deviceId); | 581 | Device device = storager.queryVideoDevice(deviceId); |
| 571 | if (device == null) { | 582 | if (device == null) { |
| 572 | return; | 583 | return; |
| 573 | } | 584 | } |
| 574 | - MediaServerItem newMediaServerItem = getNewMediaServerItem(device); | 585 | + MediaServerItem newMediaServerItem = getNewMediaServerItemHasAssist(device); |
| 586 | + if (newMediaServerItem == null) { | ||
| 587 | + PlayBackResult<StreamInfo> downloadResult = new PlayBackResult<>(); | ||
| 588 | + downloadResult.setCode(ErrorCode.ERROR100.getCode()); | ||
| 589 | + downloadResult.setMsg("未找到assist服务"); | ||
| 590 | + playBackCallback.call(downloadResult); | ||
| 591 | + return; | ||
| 592 | + } | ||
| 575 | SSRCInfo ssrcInfo = mediaServerService.openRTPServer(newMediaServerItem, null, device.isSsrcCheck(), true); | 593 | SSRCInfo ssrcInfo = mediaServerService.openRTPServer(newMediaServerItem, null, device.isSsrcCheck(), true); |
| 576 | 594 | ||
| 577 | - download(newMediaServerItem, ssrcInfo, deviceId, channelId, startTime, endTime, downloadSpeed, infoCallBack, hookCallBack); | 595 | + download(newMediaServerItem, ssrcInfo, deviceId, channelId, startTime, endTime, downloadSpeed, infoCallBack, playBackCallback); |
| 578 | } | 596 | } |
| 579 | 597 | ||
| 598 | + | ||
| 580 | @Override | 599 | @Override |
| 581 | public void download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) { | 600 | public void download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) { |
| 582 | if (mediaServerItem == null || ssrcInfo == null) { | 601 | if (mediaServerItem == null || ssrcInfo == null) { |
| @@ -659,7 +678,10 @@ public class PlayServiceImpl implements IPlayService { | @@ -659,7 +678,10 @@ public class PlayServiceImpl implements IPlayService { | ||
| 659 | } | 678 | } |
| 660 | if (mediaServerItem.getRecordAssistPort() > 0) { | 679 | if (mediaServerItem.getRecordAssistPort() > 0) { |
| 661 | JSONObject jsonObject = assistRESTfulUtils.fileDuration(mediaServerItem, streamInfo.getApp(), streamInfo.getStream(), null); | 680 | JSONObject jsonObject = assistRESTfulUtils.fileDuration(mediaServerItem, streamInfo.getApp(), streamInfo.getStream(), null); |
| 662 | - if (jsonObject != null && jsonObject.getInteger("code") == 0) { | 681 | + if (jsonObject == null) { |
| 682 | + throw new ControllerException(ErrorCode.ERROR100.getCode(), "连接Assist服务失败"); | ||
| 683 | + } | ||
| 684 | + if (jsonObject.getInteger("code") == 0) { | ||
| 663 | long duration = jsonObject.getLong("data"); | 685 | long duration = jsonObject.getLong("data"); |
| 664 | 686 | ||
| 665 | if (duration == 0) { | 687 | if (duration == 0) { |
src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
| @@ -96,7 +96,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { | @@ -96,7 +96,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { | ||
| 96 | public StreamInfo save(StreamProxyItem param) { | 96 | public StreamInfo save(StreamProxyItem param) { |
| 97 | MediaServerItem mediaInfo; | 97 | MediaServerItem mediaInfo; |
| 98 | if (ObjectUtils.isEmpty(param.getMediaServerId()) || "auto".equals(param.getMediaServerId())){ | 98 | if (ObjectUtils.isEmpty(param.getMediaServerId()) || "auto".equals(param.getMediaServerId())){ |
| 99 | - mediaInfo = mediaServerService.getMediaServerForMinimumLoad(); | 99 | + mediaInfo = mediaServerService.getMediaServerForMinimumLoad(null); |
| 100 | }else { | 100 | }else { |
| 101 | mediaInfo = mediaServerService.getOne(param.getMediaServerId()); | 101 | mediaInfo = mediaServerService.getOne(param.getMediaServerId()); |
| 102 | } | 102 | } |
web_src/src/components/dialog/recordDownload.vue
| @@ -6,18 +6,6 @@ | @@ -6,18 +6,6 @@ | ||
| 6 | <el-progress :percentage="percentage"></el-progress> | 6 | <el-progress :percentage="percentage"></el-progress> |
| 7 | </el-col> | 7 | </el-col> |
| 8 | <el-col :span="6" > | 8 | <el-col :span="6" > |
| 9 | -<!-- <el-dropdown size="mini" title="播放倍速" style="margin-left: 1px;" @command="gbScale">--> | ||
| 10 | -<!-- <el-button-group>--> | ||
| 11 | -<!-- <el-button size="mini" style="width: 100%">--> | ||
| 12 | -<!-- {{scale}}倍速 <i class="el-icon-arrow-down el-icon--right"></i>--> | ||
| 13 | -<!-- </el-button>--> | ||
| 14 | -<!-- </el-button-group>--> | ||
| 15 | -<!-- <el-dropdown-menu slot="dropdown">--> | ||
| 16 | -<!-- <el-dropdown-item command="1">1倍速</el-dropdown-item>--> | ||
| 17 | -<!-- <el-dropdown-item command="2">2倍速</el-dropdown-item>--> | ||
| 18 | -<!-- <el-dropdown-item command="4">4倍速</el-dropdown-item>--> | ||
| 19 | -<!-- </el-dropdown-menu>--> | ||
| 20 | -<!-- </el-dropdown>--> | ||
| 21 | <el-button icon="el-icon-download" v-if="percentage < 100" size="mini" title="点击下载可将以缓存部分下载到本地" @click="download()">停止缓存并下载</el-button> | 9 | <el-button icon="el-icon-download" v-if="percentage < 100" size="mini" title="点击下载可将以缓存部分下载到本地" @click="download()">停止缓存并下载</el-button> |
| 22 | </el-col> | 10 | </el-col> |
| 23 | </el-row> | 11 | </el-row> |
| @@ -51,6 +39,7 @@ export default { | @@ -51,6 +39,7 @@ export default { | ||
| 51 | taskId: null, | 39 | taskId: null, |
| 52 | getProgressRun: false, | 40 | getProgressRun: false, |
| 53 | getProgressForFileRun: false, | 41 | getProgressForFileRun: false, |
| 42 | + timer: null | ||
| 54 | 43 | ||
| 55 | }; | 44 | }; |
| 56 | }, | 45 | }, |
| @@ -66,7 +55,7 @@ export default { | @@ -66,7 +55,7 @@ export default { | ||
| 66 | this.percentage = 0.0; | 55 | this.percentage = 0.0; |
| 67 | this.getProgressTimer() | 56 | this.getProgressTimer() |
| 68 | }, | 57 | }, |
| 69 | - getProgressTimer(){ | 58 | + getProgressTimer: function (){ |
| 70 | if (!this.getProgressRun) { | 59 | if (!this.getProgressRun) { |
| 71 | return; | 60 | return; |
| 72 | } | 61 | } |
| @@ -93,15 +82,24 @@ export default { | @@ -93,15 +82,24 @@ export default { | ||
| 93 | this.percentage = (parseFloat(res.data.data.progress)*100).toFixed(1); | 82 | this.percentage = (parseFloat(res.data.data.progress)*100).toFixed(1); |
| 94 | } | 83 | } |
| 95 | if (callback)callback(); | 84 | if (callback)callback(); |
| 85 | + }else { | ||
| 86 | + this.$message({ | ||
| 87 | + showClose: true, | ||
| 88 | + message: res.data.msg, | ||
| 89 | + type: "error", | ||
| 90 | + }); | ||
| 91 | + this.close(); | ||
| 96 | } | 92 | } |
| 97 | 93 | ||
| 98 | }).catch((e) =>{ | 94 | }).catch((e) =>{ |
| 99 | - | 95 | + console.log(e) |
| 100 | }); | 96 | }); |
| 101 | }, | 97 | }, |
| 102 | close: function (){ | 98 | close: function (){ |
| 103 | - if (this.streamInfo.progress < 100) { | ||
| 104 | - this.stopDownloadRecord(); | 99 | + this.stopDownloadRecord(); |
| 100 | + if (this.timer !== null) { | ||
| 101 | + window.clearTimeout(this.timer); | ||
| 102 | + this.timer = null; | ||
| 105 | } | 103 | } |
| 106 | this.showDialog=false; | 104 | this.showDialog=false; |
| 107 | this.getProgressRun = false; | 105 | this.getProgressRun = false; |