From c25a99d60bef3d3bbd59fee895bd658928fd00db Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期三, 10 一月 2024 16:17:29 +0800 Subject: [PATCH] 修复空指针异常 --- src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java | 66 +++++++++++++++++++++------------ 1 files changed, 42 insertions(+), 24 deletions(-) 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 f2653f7..0d1bad6 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java @@ -27,11 +27,13 @@ import com.genersoft.iot.vmp.media.zlm.dto.hook.HookParam; import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam; import com.genersoft.iot.vmp.service.*; +import com.genersoft.iot.vmp.service.bean.CloudRecordItem; import com.genersoft.iot.vmp.service.bean.ErrorCallback; import com.genersoft.iot.vmp.service.bean.InviteErrorCode; import com.genersoft.iot.vmp.service.bean.SSRCInfo; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; +import com.genersoft.iot.vmp.storager.dao.CloudRecordServiceMapper; import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import gov.nist.javax.sip.message.SIPResponse; @@ -106,6 +108,9 @@ @Autowired private ZlmHttpHookSubscribe subscribe; + + @Autowired + private CloudRecordServiceMapper cloudRecordServiceMapper; @Override @@ -749,31 +754,44 @@ logger.warn("鏌ヨ褰曞儚淇℃伅鏃跺彂鐜拌妭鐐瑰凡绂荤嚎"); return null; } - if (mediaServerItem.getRecordAssistPort() > 0) { - JSONObject jsonObject = assistRESTfulUtils.fileDuration(mediaServerItem, inviteInfo.getStreamInfo().getApp(), inviteInfo.getStreamInfo().getStream(), null); - if (jsonObject == null) { - throw new ControllerException(ErrorCode.ERROR100.getCode(), "杩炴帴Assist鏈嶅姟澶辫触"); - } - if (jsonObject.getInteger("code") == 0) { - long duration = jsonObject.getLong("data"); - - if (duration == 0) { - inviteInfo.getStreamInfo().setProgress(0); - } else { - String startTime = inviteInfo.getStreamInfo().getStartTime(); - String endTime = inviteInfo.getStreamInfo().getEndTime(); - long start = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(startTime); - long end = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(endTime); - - BigDecimal currentCount = new BigDecimal(duration / 1000); - BigDecimal totalCount = new BigDecimal(end - start); - BigDecimal divide = currentCount.divide(totalCount, 2, RoundingMode.HALF_UP); - double process = divide.doubleValue(); - inviteInfo.getStreamInfo().setProgress(process); - } - inviteStreamService.updateInviteInfo(inviteInfo); - } + if (mediaServerItem.getRecordAssistPort() == 0) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "鏈厤缃瓵ssist鏈嶅姟锛屾棤娉曞畬鎴愬綍鍍忎笅杞�"); } + SsrcTransaction ssrcTransaction = streamSession.getSsrcTransaction(deviceId, channelId, null, stream); + + if (ssrcTransaction == null) { + logger.warn("[鑾峰彇涓嬭浇杩涘害]锛屾湭鎵惧埌涓嬭浇浜嬪姟淇℃伅"); + return null; + } + + // 涓轰簡鏀寔澶氫釜鏁版嵁搴擄紝杩欓噷涓嶈兘浣跨敤姹傚拰鍑芥暟鏉ョ洿鎺ヨ幏鍙栨�绘暟浜� + List<CloudRecordItem> cloudRecordItemList = cloudRecordServiceMapper.getList(null, "rtp", inviteInfo.getStream(), null, null, ssrcTransaction.getCallId(), null); + + if (cloudRecordItemList.isEmpty()) { + logger.warn("[鑾峰彇涓嬭浇杩涘害]锛屾湭鎵惧埌涓嬭浇瑙嗛淇℃伅"); + return null; + } + long duration = 0; + for (CloudRecordItem cloudRecordItem : cloudRecordItemList) { + duration += cloudRecordItem.getTimeLen(); + } + if (duration == 0) { + inviteInfo.getStreamInfo().setProgress(0); + } else { + String startTime = inviteInfo.getStreamInfo().getStartTime(); + String endTime = inviteInfo.getStreamInfo().getEndTime(); + // 姝ゆ椂start鍜宔nd鍗曚綅鏄 + long start = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(startTime); + long end = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(endTime); + + BigDecimal currentCount = new BigDecimal(duration); + BigDecimal totalCount = new BigDecimal((end - start) * 1000); + BigDecimal divide = currentCount.divide(totalCount, 2, RoundingMode.HALF_UP); + double process = divide.doubleValue(); + inviteInfo.getStreamInfo().setProgress(process); + } + inviteStreamService.updateInviteInfo(inviteInfo); + return inviteInfo.getStreamInfo(); } return null; -- Gitblit v1.8.0