From 3d6db7478d79b824f93708f936c598cc622221f2 Mon Sep 17 00:00:00 2001
From: mk1990 <153958232@qq.com>
Date: 星期一, 20 六月 2022 15:10:31 +0800
Subject: [PATCH] fix设备状态查询接口
---
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java | 106 +++++++++++++++++++++++++++-------------------------
1 files changed, 55 insertions(+), 51 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 be66b0e..41eca5d 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
@@ -19,17 +19,16 @@
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.service.IMediaServerService;
+import com.genersoft.iot.vmp.service.IMediaService;
+import com.genersoft.iot.vmp.service.IPlayService;
import com.genersoft.iot.vmp.service.bean.InviteTimeOutCallback;
import com.genersoft.iot.vmp.service.bean.PlayBackCallback;
import com.genersoft.iot.vmp.service.bean.PlayBackResult;
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.utils.redis.RedisUtil;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.PlayResult;
-import com.genersoft.iot.vmp.service.IMediaService;
-import com.genersoft.iot.vmp.service.IPlayService;
import gov.nist.javax.sip.stack.SIPDialog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,6 +42,7 @@
import javax.sip.ResponseEvent;
import java.io.FileNotFoundException;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.util.*;
@SuppressWarnings(value = {"rawtypes", "unchecked"})
@@ -62,9 +62,6 @@
@Autowired
private IRedisCatchStorage redisCatchStorage;
-
- @Autowired
- private RedisUtil redis;
@Autowired
private DeferredResultHolder resultHolder;
@@ -126,36 +123,19 @@
result.onCompletion(()->{
// 鐐规挱缁撴潫鏃惰皟鐢ㄦ埅鍥炬帴鍙�
// TODO 搴旇鍦ㄤ笂娴佹椂璋冪敤鏇村ソ锛岀粨鏉熶篃鍙兘鏄敊璇粨鏉�
- try {
- String classPath = ResourceUtils.getURL("classpath:").getPath();
- // 鍏煎鎵撳寘涓簀ar鐨刢lass璺緞
- if(classPath.contains("jar")) {
- classPath = classPath.substring(0, classPath.lastIndexOf("."));
- classPath = classPath.substring(0, classPath.lastIndexOf("/") + 1);
+ String path = "static/static/snap/";
+ String fileName = deviceId + "_" + channelId + ".jpg";
+ ResponseEntity responseEntity = (ResponseEntity)result.getResult();
+ if (responseEntity != null && responseEntity.getStatusCode() == HttpStatus.OK) {
+ WVPResult wvpResult = (WVPResult)responseEntity.getBody();
+ if (Objects.requireNonNull(wvpResult).getCode() == 0) {
+ StreamInfo streamInfoForSuccess = (StreamInfo)wvpResult.getData();
+ MediaServerItem mediaInfo = mediaServerService.getOne(streamInfoForSuccess.getMediaServerId());
+ String streamUrl = streamInfoForSuccess.getFmp4();
+ // 璇锋眰鎴浘
+ logger.info("[璇锋眰鎴浘]: " + fileName);
+ zlmresTfulUtils.getSnap(mediaInfo, streamUrl, 15, 1, path, fileName);
}
- if (classPath.startsWith("file:")) {
- classPath = classPath.substring(classPath.indexOf(":") + 1);
- }
- String path = classPath + "static/static/snap/";
- // 鍏煎Windows绯荤粺璺緞锛堝幓闄ゅ墠闈㈢殑鈥�/鈥濓級
- if(System.getProperty("os.name").contains("indows")) {
- path = path.substring(1);
- }
- String fileName = deviceId + "_" + channelId + ".jpg";
- ResponseEntity responseEntity = (ResponseEntity)result.getResult();
- if (responseEntity != null && responseEntity.getStatusCode() == HttpStatus.OK) {
- WVPResult wvpResult = (WVPResult)responseEntity.getBody();
- if (Objects.requireNonNull(wvpResult).getCode() == 0) {
- StreamInfo streamInfoForSuccess = (StreamInfo)wvpResult.getData();
- MediaServerItem mediaInfo = mediaServerService.getOne(streamInfoForSuccess.getMediaServerId());
- String streamUrl = streamInfoForSuccess.getFmp4();
- // 璇锋眰鎴浘
- logger.info("[璇锋眰鎴浘]: " + fileName);
- zlmresTfulUtils.getSnap(mediaInfo, streamUrl, 15, 1, path, fileName);
- }
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
}
});
if (streamInfo != null) {
@@ -172,23 +152,32 @@
MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaInfo, streamId);
- if (rtpInfo != null && rtpInfo.getBoolean("exist")) {
+ if(rtpInfo.getInteger("code") == 0){
+ if (rtpInfo.getBoolean("exist")) {
- WVPResult wvpResult = new WVPResult();
- wvpResult.setCode(0);
- wvpResult.setMsg("success");
- wvpResult.setData(streamInfo);
- msg.setData(wvpResult);
+ WVPResult wvpResult = new WVPResult();
+ wvpResult.setCode(0);
+ wvpResult.setMsg("success");
+ wvpResult.setData(streamInfo);
+ msg.setData(wvpResult);
- resultHolder.invokeAllResult(msg);
- if (hookEvent != null) {
- hookEvent.response(mediaServerItem, JSONObject.parseObject(JSON.toJSONString(streamInfo)));
+ resultHolder.invokeAllResult(msg);
+ if (hookEvent != null) {
+ hookEvent.response(mediaServerItem, JSONObject.parseObject(JSON.toJSONString(streamInfo)));
+ }
+ }else {
+ redisCatchStorage.stopPlay(streamInfo);
+ storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
+ streamInfo = null;
}
}else {
+ //zlm杩炴帴澶辫触
redisCatchStorage.stopPlay(streamInfo);
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
streamInfo = null;
+
}
+
}
if (streamInfo == null) {
@@ -242,33 +231,41 @@
if (ssrcInfo == null) {
ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, device.isSsrcCheck(), false);
}
-
+ logger.info("[鐐规挱寮�濮媇 deviceId: {}, channelId: {}, SSRC: {}", device.getDeviceId(), channelId, ssrcInfo.getSsrc() );
// 瓒呮椂澶勭悊
String timeOutTaskKey = UUID.randomUUID().toString();
SSRCInfo finalSsrcInfo = ssrcInfo;
dynamicTask.startDelay( timeOutTaskKey,()->{
- logger.warn(String.format("璁惧鐐规挱瓒呮椂锛宒eviceId锛�%s 锛宑hannelId锛�%s", device.getDeviceId(), channelId));
SIPDialog dialog = streamSession.getDialogByStream(device.getDeviceId(), channelId, finalSsrcInfo.getStream());
if (dialog != null) {
+ logger.info("[鐐规挱瓒呮椂] 鏀舵祦瓒呮椂 deviceId: {}, channelId: {}", device.getDeviceId(), channelId);
timeoutCallback.run(1, "鏀舵祦瓒呮椂");
// 鐐规挱瓒呮椂鍥炲BYE 鍚屾椂閲婃斁ssrc浠ュ強姝ゆ鐐规挱鐨勮祫婧�
cmder.streamByeCmd(device.getDeviceId(), channelId, finalSsrcInfo.getStream(), null);
}else {
+ logger.info("[鐐规挱瓒呮椂] 娑堟伅鏈搷搴� deviceId: {}, channelId: {}", device.getDeviceId(), channelId);
timeoutCallback.run(0, "鐐规挱瓒呮椂");
mediaServerService.releaseSsrc(mediaServerItem.getId(), finalSsrcInfo.getSsrc());
mediaServerService.closeRTPServer(device.getDeviceId(), channelId, finalSsrcInfo.getStream());
streamSession.remove(device.getDeviceId(), channelId, finalSsrcInfo.getStream());
}
- }, userSetting.getPlayTimeout()*1000);
+ }, userSetting.getPlayTimeout());
final String ssrc = ssrcInfo.getSsrc();
final String stream = ssrcInfo.getStream();
+ //绔彛鑾峰彇澶辫触鐨剆srcInfo 娌℃湁蹇呰鍙戦�佺偣鎾寚浠�
+ if(ssrcInfo.getPort() <= 0){
+ logger.info("[鐐规挱绔彛鍒嗛厤寮傚父]锛宒eviceId={},channelId={},ssrcInfo={}", device.getDeviceId(), channelId, ssrcInfo);
+ return;
+ }
cmder.playStreamCmd(mediaServerItem, ssrcInfo, device, channelId, (MediaServerItem mediaServerItemInuse, JSONObject response) -> {
logger.info("鏀跺埌璁㈤槄娑堟伅锛� " + response.toJSONString());
dynamicTask.stop(timeOutTaskKey);
// hook鍝嶅簲
onPublishHandlerForPlay(mediaServerItemInuse, response, device.getDeviceId(), channelId, uuid);
hookEvent.response(mediaServerItemInuse, response);
+ logger.info("[鐐规挱鎴愬姛] deviceId: {}, channelId: {}", device.getDeviceId(), channelId);
+
}, (event) -> {
ResponseEvent responseEvent = (ResponseEvent)event.event;
String contentString = new String(responseEvent.getResponse().getRawContent());
@@ -282,8 +279,10 @@
if (ssrc.equals(ssrcInResponse)) {
return;
}
- logger.info("[SIP 娑堟伅] 鏀跺埌invite 200, 鍙戠幇涓嬬骇鑷畾涔変簡ssrc 寮�鍚慨姝�");
+ logger.info("[鐐规挱娑堟伅] 鏀跺埌invite 200, 鍙戠幇涓嬬骇鑷畾涔変簡ssrc: {}", ssrcInResponse );
if (!mediaServerItem.isRtpEnable() || device.isSsrcCheck()) {
+ logger.info("[SIP 娑堟伅] SSRC淇 {}->{}", ssrc, ssrcInResponse);
+
if (!mediaServerItem.getSsrcConfig().checkSsrc(ssrcInResponse)) {
// ssrc 涓嶅彲鐢�
// 閲婃斁ssrc
@@ -436,7 +435,7 @@
cmder.streamByeCmd(device.getDeviceId(), channelId, ssrcInfo.getStream(), null);
// 鍥炲涔嬪墠鎵�鏈夌殑鐐规挱璇锋眰
playBackCallback.call(playBackResult);
- }, userSetting.getPlayTimeout()*1000);
+ }, userSetting.getPlayTimeout());
cmder.playbackStreamCmd(mediaServerItem, ssrcInfo, device, channelId, startTime, endTime, infoCallBack,
(InviteStreamInfo inviteStreamInfo) -> {
@@ -525,7 +524,7 @@
cmder.streamByeCmd(device.getDeviceId(), channelId, ssrcInfo.getStream(), null);
// 鍥炲涔嬪墠鎵�鏈夌殑鐐规挱璇锋眰
hookCallBack.call(downloadResult);
- }, userSetting.getPlayTimeout()*1000);
+ }, userSetting.getPlayTimeout());
cmder.downloadStreamCmd(mediaServerItem, ssrcInfo, device, channelId, startTime, endTime, downloadSpeed, infoCallBack,
inviteStreamInfo -> {
logger.info("鏀跺埌璁㈤槄娑堟伅锛� " + inviteStreamInfo.getResponse().toJSONString());
@@ -591,7 +590,7 @@
BigDecimal currentCount = new BigDecimal(duration/1000);
BigDecimal totalCount = new BigDecimal(end-start);
- BigDecimal divide = currentCount.divide(totalCount,2, BigDecimal.ROUND_HALF_UP);
+ BigDecimal divide = currentCount.divide(totalCount,2, RoundingMode.HALF_UP);
double process = divide.doubleValue();
streamInfo.setProgress(process);
}
@@ -651,4 +650,9 @@
}
}
}
+
+ @Override
+ public void zlmServerOnline(String mediaServerId) {
+ // 浼间箮娌″暐闇�瑕佸仛鐨�
+ }
}
--
Gitblit v1.8.0