|
@@ -21,6 +21,8 @@ import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
|
|
|
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
|
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
|
|
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
|
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
|
|
import com.genersoft.iot.vmp.service.IMediaServerService;
|
|
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.InviteTimeOutCallback;
|
|
|
import com.genersoft.iot.vmp.service.bean.PlayBackCallback;
|
|
import com.genersoft.iot.vmp.service.bean.PlayBackCallback;
|
|
|
import com.genersoft.iot.vmp.service.bean.PlayBackResult;
|
|
import com.genersoft.iot.vmp.service.bean.PlayBackResult;
|
|
@@ -32,8 +34,6 @@ import com.genersoft.iot.vmp.vmanager.bean.AudioBroadcastResult;
|
|
|
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
|
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
|
|
import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.AudioBroadcastEvent;
|
|
import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.AudioBroadcastEvent;
|
|
|
import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.PlayResult;
|
|
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 gov.nist.javax.sip.stack.SIPDialog;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -49,6 +49,7 @@ import javax.sip.SipException;
|
|
|
import java.io.FileNotFoundException;
|
|
import java.io.FileNotFoundException;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
import java.util.stream.Stream;
|
|
@@ -74,9 +75,6 @@ public class PlayServiceImpl implements IPlayService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IRedisCatchStorage redisCatchStorage;
|
|
private IRedisCatchStorage redisCatchStorage;
|
|
|
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private RedisUtil redis;
|
|
|
|
|
-
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private DeferredResultHolder resultHolder;
|
|
private DeferredResultHolder resultHolder;
|
|
|
|
|
|
|
@@ -140,36 +138,19 @@ public class PlayServiceImpl implements IPlayService {
|
|
|
result.onCompletion(()->{
|
|
result.onCompletion(()->{
|
|
|
// 点播结束时调用截图接口
|
|
// 点播结束时调用截图接口
|
|
|
// TODO 应该在上流时调用更好,结束也可能是错误结束
|
|
// TODO 应该在上流时调用更好,结束也可能是错误结束
|
|
|
- try {
|
|
|
|
|
- String classPath = ResourceUtils.getURL("classpath:").getPath();
|
|
|
|
|
- // 兼容打包为jar的class路径
|
|
|
|
|
- if(classPath.contains("jar")) {
|
|
|
|
|
- classPath = classPath.substring(0, classPath.lastIndexOf("."));
|
|
|
|
|
- classPath = classPath.substring(0, classPath.lastIndexOf("/") + 1);
|
|
|
|
|
- }
|
|
|
|
|
- if (classPath.startsWith("file:")) {
|
|
|
|
|
- classPath = classPath.substring(classPath.indexOf(":") + 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);
|
|
|
}
|
|
}
|
|
|
- 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) {
|
|
if (streamInfo != null) {
|
|
@@ -186,24 +167,33 @@ public class PlayServiceImpl implements IPlayService {
|
|
|
MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);
|
|
MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);
|
|
|
|
|
|
|
|
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaInfo, streamId);
|
|
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 {
|
|
}else {
|
|
|
|
|
+ //zlm连接失败
|
|
|
redisCatchStorage.stopPlay(streamInfo);
|
|
redisCatchStorage.stopPlay(streamInfo);
|
|
|
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
|
|
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
|
|
|
streamInfo = null;
|
|
streamInfo = null;
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
if (streamInfo == null) {
|
|
if (streamInfo == null) {
|
|
|
String streamId = null;
|
|
String streamId = null;
|
|
@@ -256,33 +246,41 @@ public class PlayServiceImpl implements IPlayService {
|
|
|
if (ssrcInfo == null) {
|
|
if (ssrcInfo == null) {
|
|
|
ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, device.isSsrcCheck(), false);
|
|
ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, device.isSsrcCheck(), false);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ logger.info("[点播开始] deviceId: {}, channelId: {}, SSRC: {}", device.getDeviceId(), channelId, ssrcInfo.getSsrc() );
|
|
|
// 超时处理
|
|
// 超时处理
|
|
|
String timeOutTaskKey = UUID.randomUUID().toString();
|
|
String timeOutTaskKey = UUID.randomUUID().toString();
|
|
|
SSRCInfo finalSsrcInfo = ssrcInfo;
|
|
SSRCInfo finalSsrcInfo = ssrcInfo;
|
|
|
dynamicTask.startDelay( timeOutTaskKey,()->{
|
|
dynamicTask.startDelay( timeOutTaskKey,()->{
|
|
|
- logger.warn(String.format("设备点播超时,deviceId:%s ,channelId:%s", device.getDeviceId(), channelId));
|
|
|
|
|
|
|
|
|
|
SIPDialog dialog = streamSession.getDialogByStream(device.getDeviceId(), channelId, finalSsrcInfo.getStream());
|
|
SIPDialog dialog = streamSession.getDialogByStream(device.getDeviceId(), channelId, finalSsrcInfo.getStream());
|
|
|
if (dialog != null) {
|
|
if (dialog != null) {
|
|
|
|
|
+ logger.info("[点播超时] 收流超时 deviceId: {}, channelId: {}", device.getDeviceId(), channelId);
|
|
|
timeoutCallback.run(1, "收流超时");
|
|
timeoutCallback.run(1, "收流超时");
|
|
|
// 点播超时回复BYE 同时释放ssrc以及此次点播的资源
|
|
// 点播超时回复BYE 同时释放ssrc以及此次点播的资源
|
|
|
cmder.streamByeCmd(device.getDeviceId(), channelId, finalSsrcInfo.getStream(), null);
|
|
cmder.streamByeCmd(device.getDeviceId(), channelId, finalSsrcInfo.getStream(), null);
|
|
|
}else {
|
|
}else {
|
|
|
|
|
+ logger.info("[点播超时] 消息未响应 deviceId: {}, channelId: {}", device.getDeviceId(), channelId);
|
|
|
timeoutCallback.run(0, "点播超时");
|
|
timeoutCallback.run(0, "点播超时");
|
|
|
mediaServerService.releaseSsrc(mediaServerItem.getId(), finalSsrcInfo.getSsrc());
|
|
mediaServerService.releaseSsrc(mediaServerItem.getId(), finalSsrcInfo.getSsrc());
|
|
|
mediaServerService.closeRTPServer(device.getDeviceId(), channelId, finalSsrcInfo.getStream());
|
|
mediaServerService.closeRTPServer(device.getDeviceId(), channelId, finalSsrcInfo.getStream());
|
|
|
streamSession.remove(device.getDeviceId(), channelId, finalSsrcInfo.getStream());
|
|
streamSession.remove(device.getDeviceId(), channelId, finalSsrcInfo.getStream());
|
|
|
}
|
|
}
|
|
|
- }, userSetting.getPlayTimeout()*1000);
|
|
|
|
|
|
|
+ }, userSetting.getPlayTimeout());
|
|
|
final String ssrc = ssrcInfo.getSsrc();
|
|
final String ssrc = ssrcInfo.getSsrc();
|
|
|
final String stream = ssrcInfo.getStream();
|
|
final String stream = ssrcInfo.getStream();
|
|
|
|
|
+ //端口获取失败的ssrcInfo 没有必要发送点播指令
|
|
|
|
|
+ if(ssrcInfo.getPort() <= 0){
|
|
|
|
|
+ logger.info("[点播端口分配异常],deviceId={},channelId={},ssrcInfo={}", device.getDeviceId(), channelId, ssrcInfo);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
cmder.playStreamCmd(mediaServerItem, ssrcInfo, device, channelId, (MediaServerItem mediaServerItemInuse, JSONObject response) -> {
|
|
cmder.playStreamCmd(mediaServerItem, ssrcInfo, device, channelId, (MediaServerItem mediaServerItemInuse, JSONObject response) -> {
|
|
|
logger.info("收到订阅消息: " + response.toJSONString());
|
|
logger.info("收到订阅消息: " + response.toJSONString());
|
|
|
dynamicTask.stop(timeOutTaskKey);
|
|
dynamicTask.stop(timeOutTaskKey);
|
|
|
// hook响应
|
|
// hook响应
|
|
|
onPublishHandlerForPlay(mediaServerItemInuse, response, device.getDeviceId(), channelId, uuid);
|
|
onPublishHandlerForPlay(mediaServerItemInuse, response, device.getDeviceId(), channelId, uuid);
|
|
|
hookEvent.response(mediaServerItemInuse, response);
|
|
hookEvent.response(mediaServerItemInuse, response);
|
|
|
|
|
+ logger.info("[点播成功] deviceId: {}, channelId: {}", device.getDeviceId(), channelId);
|
|
|
|
|
+
|
|
|
}, (event) -> {
|
|
}, (event) -> {
|
|
|
ResponseEvent responseEvent = (ResponseEvent)event.event;
|
|
ResponseEvent responseEvent = (ResponseEvent)event.event;
|
|
|
String contentString = new String(responseEvent.getResponse().getRawContent());
|
|
String contentString = new String(responseEvent.getResponse().getRawContent());
|
|
@@ -296,8 +294,10 @@ public class PlayServiceImpl implements IPlayService {
|
|
|
if (ssrc.equals(ssrcInResponse)) {
|
|
if (ssrc.equals(ssrcInResponse)) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- logger.info("[SIP 消息] 收到invite 200, 发现下级自定义了ssrc 开启修正");
|
|
|
|
|
|
|
+ logger.info("[点播消息] 收到invite 200, 发现下级自定义了ssrc: {}", ssrcInResponse );
|
|
|
if (!mediaServerItem.isRtpEnable() || device.isSsrcCheck()) {
|
|
if (!mediaServerItem.isRtpEnable() || device.isSsrcCheck()) {
|
|
|
|
|
+ logger.info("[SIP 消息] SSRC修正 {}->{}", ssrc, ssrcInResponse);
|
|
|
|
|
+
|
|
|
if (!mediaServerItem.getSsrcConfig().checkSsrc(ssrcInResponse)) {
|
|
if (!mediaServerItem.getSsrcConfig().checkSsrc(ssrcInResponse)) {
|
|
|
// ssrc 不可用
|
|
// ssrc 不可用
|
|
|
// 释放ssrc
|
|
// 释放ssrc
|
|
@@ -450,7 +450,7 @@ public class PlayServiceImpl implements IPlayService {
|
|
|
cmder.streamByeCmd(device.getDeviceId(), channelId, ssrcInfo.getStream(), null);
|
|
cmder.streamByeCmd(device.getDeviceId(), channelId, ssrcInfo.getStream(), null);
|
|
|
// 回复之前所有的点播请求
|
|
// 回复之前所有的点播请求
|
|
|
playBackCallback.call(playBackResult);
|
|
playBackCallback.call(playBackResult);
|
|
|
- }, userSetting.getPlayTimeout()*1000);
|
|
|
|
|
|
|
+ }, userSetting.getPlayTimeout());
|
|
|
|
|
|
|
|
cmder.playbackStreamCmd(mediaServerItem, ssrcInfo, device, channelId, startTime, endTime, infoCallBack,
|
|
cmder.playbackStreamCmd(mediaServerItem, ssrcInfo, device, channelId, startTime, endTime, infoCallBack,
|
|
|
(InviteStreamInfo inviteStreamInfo) -> {
|
|
(InviteStreamInfo inviteStreamInfo) -> {
|
|
@@ -539,7 +539,7 @@ public class PlayServiceImpl implements IPlayService {
|
|
|
cmder.streamByeCmd(device.getDeviceId(), channelId, ssrcInfo.getStream(), null);
|
|
cmder.streamByeCmd(device.getDeviceId(), channelId, ssrcInfo.getStream(), null);
|
|
|
// 回复之前所有的点播请求
|
|
// 回复之前所有的点播请求
|
|
|
hookCallBack.call(downloadResult);
|
|
hookCallBack.call(downloadResult);
|
|
|
- }, userSetting.getPlayTimeout()*1000);
|
|
|
|
|
|
|
+ }, userSetting.getPlayTimeout());
|
|
|
cmder.downloadStreamCmd(mediaServerItem, ssrcInfo, device, channelId, startTime, endTime, downloadSpeed, infoCallBack,
|
|
cmder.downloadStreamCmd(mediaServerItem, ssrcInfo, device, channelId, startTime, endTime, downloadSpeed, infoCallBack,
|
|
|
inviteStreamInfo -> {
|
|
inviteStreamInfo -> {
|
|
|
logger.info("收到订阅消息: " + inviteStreamInfo.getResponse().toJSONString());
|
|
logger.info("收到订阅消息: " + inviteStreamInfo.getResponse().toJSONString());
|
|
@@ -605,7 +605,7 @@ public class PlayServiceImpl implements IPlayService {
|
|
|
|
|
|
|
|
BigDecimal currentCount = new BigDecimal(duration/1000);
|
|
BigDecimal currentCount = new BigDecimal(duration/1000);
|
|
|
BigDecimal totalCount = new BigDecimal(end-start);
|
|
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();
|
|
double process = divide.doubleValue();
|
|
|
streamInfo.setProgress(process);
|
|
streamInfo.setProgress(process);
|
|
|
}
|
|
}
|
|
@@ -728,4 +728,9 @@ public class PlayServiceImpl implements IPlayService {
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void zlmServerOnline(String mediaServerId) {
|
|
|
|
|
+ // 似乎没啥需要做的
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|