Merge pull request #845 from 648540858/wvp-28181-2.0-test
Wvp 28181 2.0 test
This commit is contained in:
commit
ccecda7859
126
src/main/java/com/genersoft/iot/vmp/common/InviteInfo.java
Normal file
126
src/main/java/com/genersoft/iot/vmp/common/InviteInfo.java
Normal file
@ -0,0 +1,126 @@
|
||||
package com.genersoft.iot.vmp.common;
|
||||
|
||||
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
||||
|
||||
/**
|
||||
* 记录每次发送invite消息的状态
|
||||
*/
|
||||
public class InviteInfo {
|
||||
|
||||
private String deviceId;
|
||||
|
||||
private String channelId;
|
||||
|
||||
private String stream;
|
||||
|
||||
private SSRCInfo ssrcInfo;
|
||||
|
||||
private String receiveIp;
|
||||
|
||||
private Integer receivePort;
|
||||
|
||||
private String streamMode;
|
||||
|
||||
private InviteSessionType type;
|
||||
|
||||
private InviteSessionStatus status;
|
||||
|
||||
private StreamInfo streamInfo;
|
||||
|
||||
|
||||
public static InviteInfo getinviteInfo(String deviceId, String channelId, String stream, SSRCInfo ssrcInfo,
|
||||
String receiveIp, Integer receivePort, String streamMode,
|
||||
InviteSessionType type, InviteSessionStatus status) {
|
||||
InviteInfo inviteInfo = new InviteInfo();
|
||||
inviteInfo.setDeviceId(deviceId);
|
||||
inviteInfo.setChannelId(channelId);
|
||||
inviteInfo.setStream(stream);
|
||||
inviteInfo.setSsrcInfo(ssrcInfo);
|
||||
inviteInfo.setReceiveIp(receiveIp);
|
||||
inviteInfo.setReceivePort(receivePort);
|
||||
inviteInfo.setStreamMode(streamMode);
|
||||
inviteInfo.setType(type);
|
||||
inviteInfo.setStatus(status);
|
||||
return inviteInfo;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public String getChannelId() {
|
||||
return channelId;
|
||||
}
|
||||
|
||||
public void setChannelId(String channelId) {
|
||||
this.channelId = channelId;
|
||||
}
|
||||
|
||||
public InviteSessionType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(InviteSessionType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public InviteSessionStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(InviteSessionStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public StreamInfo getStreamInfo() {
|
||||
return streamInfo;
|
||||
}
|
||||
|
||||
public void setStreamInfo(StreamInfo streamInfo) {
|
||||
this.streamInfo = streamInfo;
|
||||
}
|
||||
|
||||
public String getStream() {
|
||||
return stream;
|
||||
}
|
||||
|
||||
public void setStream(String stream) {
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
public SSRCInfo getSsrcInfo() {
|
||||
return ssrcInfo;
|
||||
}
|
||||
|
||||
public void setSsrcInfo(SSRCInfo ssrcInfo) {
|
||||
this.ssrcInfo = ssrcInfo;
|
||||
}
|
||||
|
||||
public String getReceiveIp() {
|
||||
return receiveIp;
|
||||
}
|
||||
|
||||
public void setReceiveIp(String receiveIp) {
|
||||
this.receiveIp = receiveIp;
|
||||
}
|
||||
|
||||
public Integer getReceivePort() {
|
||||
return receivePort;
|
||||
}
|
||||
|
||||
public void setReceivePort(Integer receivePort) {
|
||||
this.receivePort = receivePort;
|
||||
}
|
||||
|
||||
public String getStreamMode() {
|
||||
return streamMode;
|
||||
}
|
||||
|
||||
public void setStreamMode(String streamMode) {
|
||||
this.streamMode = streamMode;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.genersoft.iot.vmp.common;
|
||||
|
||||
/**
|
||||
* 标识invite消息发出后的各个状态,
|
||||
* 收到ok钱停止invite发送cancel,
|
||||
* 收到200ok后发送BYE停止invite
|
||||
*/
|
||||
public enum InviteSessionStatus {
|
||||
ready,
|
||||
ok,
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.genersoft.iot.vmp.common;
|
||||
|
||||
public enum InviteSessionType {
|
||||
PLAY,
|
||||
PLAYBACK,
|
||||
DOWNLOAD
|
||||
}
|
@ -16,8 +16,6 @@ public class VideoManagerConstants {
|
||||
|
||||
public static final String MEDIA_SERVERS_ONLINE_PREFIX = "VMP_MEDIA_ONLINE_SERVERS_";
|
||||
|
||||
public static final String MEDIA_STREAM_PREFIX = "VMP_MEDIA_STREAM";
|
||||
|
||||
public static final String DEVICE_PREFIX = "VMP_DEVICE_";
|
||||
|
||||
// 设备同步完成
|
||||
@ -28,9 +26,10 @@ public class VideoManagerConstants {
|
||||
public static final String KEEPLIVEKEY_PREFIX = "VMP_KEEPALIVE_";
|
||||
|
||||
// TODO 此处多了一个_,暂不修改
|
||||
public static final String PLAYER_PREFIX = "VMP_PLAYER_";
|
||||
public static final String PLAY_BLACK_PREFIX = "VMP_PLAYBACK_";
|
||||
public static final String DOWNLOAD_PREFIX = "VMP_DOWNLOAD_";
|
||||
public static final String INVITE_PREFIX = "VMP_INVITE";
|
||||
public static final String PLAYER_PREFIX = "VMP_INVITE_PLAY_";
|
||||
public static final String PLAY_BLACK_PREFIX = "VMP_INVITE_PLAYBACK_";
|
||||
public static final String DOWNLOAD_PREFIX = "VMP_INVITE_DOWNLOAD_";
|
||||
|
||||
public static final String PLATFORM_KEEPALIVE_PREFIX = "VMP_PLATFORM_KEEPALIVE_";
|
||||
|
||||
|
@ -2,7 +2,6 @@ package com.genersoft.iot.vmp.conf;
|
||||
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
import org.apache.catalina.connector.ClientAbortException;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
@ -194,11 +193,11 @@ public class ProxyServletConfig {
|
||||
} catch (IOException ioException) {
|
||||
if (ioException instanceof ConnectException) {
|
||||
logger.error("录像服务 连接失败");
|
||||
}else if (ioException instanceof ClientAbortException) {
|
||||
/**
|
||||
* TODO 使用这个代理库实现代理在遇到代理视频文件时,如果是206结果,会遇到报错蛋市目前功能正常,
|
||||
* TODO 暂时去除异常处理。后续使用其他代理框架修改测试
|
||||
*/
|
||||
// }else if (ioException instanceof ClientAbortException) {
|
||||
// /**
|
||||
// * TODO 使用这个代理库实现代理在遇到代理视频文件时,如果是206结果,会遇到报错蛋市目前功能正常,
|
||||
// * TODO 暂时去除异常处理。后续使用其他代理框架修改测试
|
||||
// */
|
||||
|
||||
}else {
|
||||
logger.error("录像服务 代理失败: ", e);
|
||||
|
@ -2,7 +2,7 @@ package com.genersoft.iot.vmp.gb28181.bean;
|
||||
|
||||
public enum InviteStreamType {
|
||||
|
||||
PLAY,PLAYBACK,PUSH,PROXY,CLOUD_RECORD_PUSH,CLOUD_RECORD_PROXY
|
||||
PLAY,PLAYBACK,DOWNLOAD,PUSH,PROXY,CLOUD_RECORD_PUSH,CLOUD_RECORD_PROXY
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.genersoft.iot.vmp.gb28181.bean;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
|
||||
import com.genersoft.iot.vmp.common.InviteSessionType;
|
||||
|
||||
public class SsrcTransaction {
|
||||
|
||||
@ -13,7 +13,7 @@ public class SsrcTransaction {
|
||||
|
||||
private SipTransactionInfo sipTransactionInfo;
|
||||
|
||||
private VideoStreamSessionManager.SessionType type;
|
||||
private InviteSessionType type;
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
@ -63,11 +63,11 @@ public class SsrcTransaction {
|
||||
this.ssrc = ssrc;
|
||||
}
|
||||
|
||||
public VideoStreamSessionManager.SessionType getType() {
|
||||
public InviteSessionType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(VideoStreamSessionManager.SessionType type) {
|
||||
public void setType(InviteSessionType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.genersoft.iot.vmp.gb28181.session;
|
||||
|
||||
import com.genersoft.iot.vmp.common.InviteSessionType;
|
||||
import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SipTransactionInfo;
|
||||
@ -27,12 +28,6 @@ public class VideoStreamSessionManager {
|
||||
@Autowired
|
||||
private RedisTemplate<Object, Object> redisTemplate;
|
||||
|
||||
public enum SessionType {
|
||||
play,
|
||||
playback,
|
||||
download
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一个点播/回放的事务信息
|
||||
* 后续可以通过流Id/callID
|
||||
@ -43,7 +38,7 @@ public class VideoStreamSessionManager {
|
||||
* @param mediaServerId 所使用的流媒体ID
|
||||
* @param response 回复
|
||||
*/
|
||||
public void put(String deviceId, String channelId, String callId, String stream, String ssrc, String mediaServerId, SIPResponse response, SessionType type){
|
||||
public void put(String deviceId, String channelId, String callId, String stream, String ssrc, String mediaServerId, SIPResponse response, InviteSessionType type){
|
||||
SsrcTransaction ssrcTransaction = new SsrcTransaction();
|
||||
ssrcTransaction.setDeviceId(deviceId);
|
||||
ssrcTransaction.setChannelId(channelId);
|
||||
|
@ -4,7 +4,6 @@ import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.InviteStreamCallback;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
@ -109,7 +108,7 @@ public interface ISIPCommander {
|
||||
* @param startTime 开始时间,格式要求:yyyy-MM-dd HH:mm:ss
|
||||
* @param endTime 结束时间,格式要求:yyyy-MM-dd HH:mm:ss
|
||||
*/
|
||||
void playbackStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInf, Device device, String channelId, String startTime, String endTime,InviteStreamCallback inviteStreamCallback, InviteStreamCallback event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException;
|
||||
void playbackStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInf, Device device, String channelId, String startTime, String endTime,ZlmHttpHookSubscribe.Event event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException;
|
||||
|
||||
/**
|
||||
* 请求历史媒体下载
|
||||
@ -121,7 +120,7 @@ public interface ISIPCommander {
|
||||
* @param downloadSpeed 下载倍速参数
|
||||
*/
|
||||
void downloadStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,
|
||||
String startTime, String endTime, int downloadSpeed, InviteStreamCallback inviteStreamCallback, InviteStreamCallback hookEvent,
|
||||
String startTime, String endTime, int downloadSpeed, ZlmHttpHookSubscribe.Event hookEvent,
|
||||
SipSubscribe.Event errorEvent,SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException;
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.InviteSessionType;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.SipConfig;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
@ -350,7 +351,7 @@ public class SIPCommander implements ISIPCommander {
|
||||
// 这里为例避免一个通道的点播只有一个callID这个参数使用一个固定值
|
||||
ResponseEvent responseEvent = (ResponseEvent) e.event;
|
||||
SIPResponse response = (SIPResponse) responseEvent.getResponse();
|
||||
streamSession.put(device.getDeviceId(), channelId, "play", stream, ssrcInfo.getSsrc(), mediaServerItem.getId(), response, VideoStreamSessionManager.SessionType.play);
|
||||
streamSession.put(device.getDeviceId(), channelId, "play", stream, ssrcInfo.getSsrc(), mediaServerItem.getId(), response, InviteSessionType.PLAY);
|
||||
okEvent.response(e);
|
||||
});
|
||||
}
|
||||
@ -365,11 +366,11 @@ public class SIPCommander implements ISIPCommander {
|
||||
*/
|
||||
@Override
|
||||
public void playbackStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,
|
||||
String startTime, String endTime, InviteStreamCallback inviteStreamCallback, InviteStreamCallback hookEvent,
|
||||
String startTime, String endTime, ZlmHttpHookSubscribe.Event hookEvent,
|
||||
SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException {
|
||||
|
||||
|
||||
logger.info("{} 分配的ZLM为: {} [{}:{}]", ssrcInfo.getStream(), mediaServerItem.getSdpIp(), mediaServerItem.getIp(), ssrcInfo.getPort());
|
||||
logger.info("{} 分配的ZLM为: {} [{}:{}]", ssrcInfo.getStream(), mediaServerItem.getId(), mediaServerItem.getSdpIp(), ssrcInfo.getPort());
|
||||
String sdpIp;
|
||||
if (!ObjectUtils.isEmpty(device.getSdpIp())) {
|
||||
sdpIp = device.getSdpIp();
|
||||
@ -442,8 +443,7 @@ public class SIPCommander implements ISIPCommander {
|
||||
// 添加订阅
|
||||
subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject json) -> {
|
||||
if (hookEvent != null) {
|
||||
InviteStreamInfo inviteStreamInfo = new InviteStreamInfo(mediaServerItemInUse, json,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport()).getCallId(), "rtp", ssrcInfo.getStream());
|
||||
hookEvent.call(inviteStreamInfo);
|
||||
hookEvent.response(mediaServerItemInUse, json);
|
||||
}
|
||||
subscribe.removeSubscribe(hookSubscribe);
|
||||
});
|
||||
@ -452,12 +452,9 @@ public class SIPCommander implements ISIPCommander {
|
||||
sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request, errorEvent, event -> {
|
||||
ResponseEvent responseEvent = (ResponseEvent) event.event;
|
||||
SIPResponse response = (SIPResponse) responseEvent.getResponse();
|
||||
streamSession.put(device.getDeviceId(), channelId,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport()).getCallId(), ssrcInfo.getStream(), ssrcInfo.getSsrc(), mediaServerItem.getId(), response, VideoStreamSessionManager.SessionType.playback);
|
||||
streamSession.put(device.getDeviceId(), channelId,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport()).getCallId(), ssrcInfo.getStream(), ssrcInfo.getSsrc(), mediaServerItem.getId(), response, InviteSessionType.PLAYBACK);
|
||||
okEvent.response(event);
|
||||
});
|
||||
if (inviteStreamCallback != null) {
|
||||
inviteStreamCallback.call(new InviteStreamInfo(mediaServerItem, null,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport()).getCallId(), "rtp", ssrcInfo.getStream()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -472,10 +469,10 @@ public class SIPCommander implements ISIPCommander {
|
||||
@Override
|
||||
public void downloadStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,
|
||||
String startTime, String endTime, int downloadSpeed,
|
||||
InviteStreamCallback inviteStreamCallback, InviteStreamCallback hookEvent,
|
||||
ZlmHttpHookSubscribe.Event hookEvent,
|
||||
SipSubscribe.Event errorEvent,SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException {
|
||||
|
||||
logger.info("{} 分配的ZLM为: {} [{}:{}]", ssrcInfo.getStream(), mediaServerItem.getSdpIp(), mediaServerItem.getIp(), ssrcInfo.getPort());
|
||||
logger.info("{} 分配的ZLM为: {} [{}:{}]", ssrcInfo.getStream(), mediaServerItem.getId(), mediaServerItem.getSdpIp(), ssrcInfo.getPort());
|
||||
String sdpIp;
|
||||
if (!ObjectUtils.isEmpty(device.getSdpIp())) {
|
||||
sdpIp = device.getSdpIp();
|
||||
@ -543,13 +540,13 @@ public class SIPCommander implements ISIPCommander {
|
||||
|
||||
content.append("y=" + ssrcInfo.getSsrc() + "\r\n");//ssrc
|
||||
logger.debug("此时请求下载信令的ssrc===>{}",ssrcInfo.getSsrc());
|
||||
HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", ssrcInfo.getStream(), true, null, mediaServerItem.getId());
|
||||
HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", ssrcInfo.getStream(), true, "rtsp", mediaServerItem.getId());
|
||||
// 添加订阅
|
||||
CallIdHeader newCallIdHeader = sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()), device.getTransport());
|
||||
String callId= newCallIdHeader.getCallId();
|
||||
subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject json) -> {
|
||||
logger.debug("sipc 添加订阅===callId {}",callId);
|
||||
hookEvent.call(new InviteStreamInfo(mediaServerItem, json,callId, "rtp", ssrcInfo.getStream()));
|
||||
hookEvent.response(mediaServerItemInUse, json);
|
||||
subscribe.removeSubscribe(hookSubscribe);
|
||||
hookSubscribe.getContent().put("regist", false);
|
||||
hookSubscribe.getContent().put("schema", "rtsp");
|
||||
@ -567,9 +564,6 @@ public class SIPCommander implements ISIPCommander {
|
||||
});
|
||||
|
||||
Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, SipUtils.getNewFromTag(), null,newCallIdHeader, ssrcInfo.getSsrc());
|
||||
if (inviteStreamCallback != null) {
|
||||
inviteStreamCallback.call(new InviteStreamInfo(mediaServerItem, null,callId, "rtp", ssrcInfo.getStream()));
|
||||
}
|
||||
|
||||
sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request, errorEvent, event -> {
|
||||
ResponseEvent responseEvent = (ResponseEvent) event.event;
|
||||
@ -580,7 +574,7 @@ public class SIPCommander implements ISIPCommander {
|
||||
if (ssrcIndex >= 0) {
|
||||
ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
|
||||
}
|
||||
streamSession.put(device.getDeviceId(), channelId, response.getCallIdHeader().getCallId(), ssrcInfo.getStream(), ssrc, mediaServerItem.getId(), response, VideoStreamSessionManager.SessionType.download);
|
||||
streamSession.put(device.getDeviceId(), channelId, response.getCallIdHeader().getCallId(), ssrcInfo.getStream(), ssrc, mediaServerItem.getId(), response, InviteSessionType.DOWNLOAD);
|
||||
okEvent.response(event);
|
||||
});
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
|
||||
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.common.InviteInfo;
|
||||
import com.genersoft.iot.vmp.common.InviteSessionType;
|
||||
import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.InviteStreamType;
|
||||
@ -15,6 +16,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorP
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.service.IDeviceService;
|
||||
import com.genersoft.iot.vmp.service.IInviteStreamService;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.service.bean.MessageForPushChannel;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
@ -26,7 +28,9 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sip.*;
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.RequestEvent;
|
||||
import javax.sip.SipException;
|
||||
import javax.sip.address.SipURI;
|
||||
import javax.sip.header.CallIdHeader;
|
||||
import javax.sip.header.FromHeader;
|
||||
@ -52,6 +56,9 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private IInviteStreamService inviteStreamService;
|
||||
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
@ -136,11 +143,6 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In
|
||||
Device device = storager.queryVideoDeviceByChannelId(platformGbId);
|
||||
if (device != null) {
|
||||
storager.stopPlay(device.getDeviceId(), channelId);
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(device.getDeviceId(), channelId);
|
||||
if (streamInfo != null) {
|
||||
redisCatchStorage.stopPlay(streamInfo);
|
||||
mediaServerService.closeRTPServer(streamInfo.getMediaServerId(), streamInfo.getStream());
|
||||
}
|
||||
SsrcTransaction ssrcTransactionForPlay = streamSession.getSsrcTransaction(device.getDeviceId(), channelId, "play", null);
|
||||
if (ssrcTransactionForPlay != null){
|
||||
if (ssrcTransactionForPlay.getCallId().equals(callIdHeader.getCallId())){
|
||||
@ -151,6 +153,14 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In
|
||||
}
|
||||
streamSession.remove(device.getDeviceId(), channelId, ssrcTransactionForPlay.getStream());
|
||||
}
|
||||
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channelId);
|
||||
|
||||
if (inviteInfo != null) {
|
||||
inviteStreamService.removeInviteInfo(inviteInfo);
|
||||
if (inviteInfo.getStreamInfo() != null) {
|
||||
mediaServerService.closeRTPServer(inviteInfo.getStreamInfo().getMediaServerId(), inviteInfo.getStream());
|
||||
}
|
||||
}
|
||||
}
|
||||
SsrcTransaction ssrcTransactionForPlayBack = streamSession.getSsrcTransaction(device.getDeviceId(), channelId, callIdHeader.getCallId(), null);
|
||||
if (ssrcTransactionForPlayBack != null) {
|
||||
@ -160,6 +170,14 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In
|
||||
mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcTransactionForPlayBack.getSsrc());
|
||||
}
|
||||
streamSession.remove(device.getDeviceId(), channelId, ssrcTransactionForPlayBack.getStream());
|
||||
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAYBACK, device.getDeviceId(), channelId);
|
||||
|
||||
if (inviteInfo != null) {
|
||||
inviteStreamService.removeInviteInfo(inviteInfo);
|
||||
if (inviteInfo.getStreamInfo() != null) {
|
||||
mediaServerService.closeRTPServer(inviteInfo.getStreamInfo().getMediaServerId(), inviteInfo.getStream());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,10 @@
|
||||
package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.gb28181.session.SSRCFactory;
|
||||
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.SIPSender;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
|
||||
@ -21,6 +19,8 @@ import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.service.IPlayService;
|
||||
import com.genersoft.iot.vmp.service.IStreamProxyService;
|
||||
import com.genersoft.iot.vmp.service.IStreamPushService;
|
||||
import com.genersoft.iot.vmp.service.bean.InviteErrorCallback;
|
||||
import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
|
||||
import com.genersoft.iot.vmp.service.bean.MessageForPushChannel;
|
||||
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
||||
import com.genersoft.iot.vmp.service.redisMsg.RedisGbPlayMsgListener;
|
||||
@ -101,9 +101,6 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
@Autowired
|
||||
private SIPProcessorObserver sipProcessorObserver;
|
||||
|
||||
@Autowired
|
||||
private VideoStreamSessionManager sessionManager;
|
||||
|
||||
@Autowired
|
||||
private UserSetting userSetting;
|
||||
|
||||
@ -359,7 +356,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
}else {
|
||||
streamTypeStr = "UDP";
|
||||
}
|
||||
logger.info("[上级点播] 平台:{}, 通道:{}, 收流地址:{}:{},收流方式:{}, ssrc:{}", username, channelId, addressStr, port, streamTypeStr, ssrc);
|
||||
logger.info("[上级Invite] {}, 平台:{}, 通道:{}, 收流地址:{}:{},收流方式:{}, ssrc:{}", sessionName, username, channelId, addressStr, port, streamTypeStr, ssrc);
|
||||
SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId,
|
||||
device.getDeviceId(), channelId, mediaTransmissionTCP, platform.isRtcp());
|
||||
|
||||
@ -380,10 +377,10 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
|
||||
Long finalStartTime = startTime;
|
||||
Long finalStopTime = stopTime;
|
||||
ZlmHttpHookSubscribe.Event hookEvent = (mediaServerItemInUSe, responseJSON) -> {
|
||||
String app = responseJSON.getString("app");
|
||||
String stream = responseJSON.getString("stream");
|
||||
logger.info("[上级点播]下级已经开始推流。 回复200OK(SDP), {}/{}", app, stream);
|
||||
InviteErrorCallback<Object> hookEvent = (code, msg, data) -> {
|
||||
StreamInfo streamInfo = (StreamInfo)data;
|
||||
MediaServerItem mediaServerItemInUSe = mediaServerService.getOne(streamInfo.getMediaServerId());
|
||||
logger.info("[上级Invite]下级已经开始推流。 回复200OK(SDP), {}/{}", streamInfo.getApp(), streamInfo.getStream());
|
||||
// * 0 等待设备推流上来
|
||||
// * 1 下级已经推流,等待上级平台回复ack
|
||||
// * 2 推流中
|
||||
@ -429,11 +426,13 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
logger.error("[命令发送失败] 国标级联 回复SdpAck", e);
|
||||
}
|
||||
};
|
||||
SipSubscribe.Event errorEvent = ((event) -> {
|
||||
InviteErrorCallback<Object> errorEvent = ((statusCode, msg, data) -> {
|
||||
// 未知错误。直接转发设备点播的错误
|
||||
try {
|
||||
Response response = getMessageFactory().createResponse(event.statusCode, evt.getRequest());
|
||||
sipSender.transmitRequest(request.getLocalAddress().getHostAddress(), response);
|
||||
if (statusCode > 0) {
|
||||
Response response = getMessageFactory().createResponse(statusCode, evt.getRequest());
|
||||
sipSender.transmitRequest(request.getLocalAddress().getHostAddress(), response);
|
||||
}
|
||||
} catch (ParseException | SipException e) {
|
||||
logger.error("未处理的异常 ", e);
|
||||
}
|
||||
@ -446,67 +445,70 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
// 写入redis, 超时时回复
|
||||
redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
||||
playService.playBack(mediaServerItem, ssrcInfo, device.getDeviceId(), channelId, DateUtil.formatter.format(start),
|
||||
DateUtil.formatter.format(end), null, result -> {
|
||||
if (result.getCode() != 0) {
|
||||
logger.warn("录像回放失败");
|
||||
if (result.getEvent() != null) {
|
||||
errorEvent.response(result.getEvent());
|
||||
}
|
||||
DateUtil.formatter.format(end),
|
||||
(code, msg, data) -> {
|
||||
if (code == InviteErrorCode.SUCCESS.getCode()){
|
||||
hookEvent.run(code, msg, data);
|
||||
}else if (code == InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode() || code == InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode()){
|
||||
logger.info("[录像回放]超时, 用户:{}, 通道:{}", username, channelId);
|
||||
redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null);
|
||||
try {
|
||||
responseAck(request, Response.REQUEST_TIMEOUT);
|
||||
} catch (SipException | InvalidArgumentException | ParseException e) {
|
||||
logger.error("[命令发送失败] 国标级联 录像回放 发送REQUEST_TIMEOUT: {}", e.getMessage());
|
||||
}
|
||||
} else {
|
||||
if (result.getMediaServerItem() != null) {
|
||||
hookEvent.response(result.getMediaServerItem(), result.getResponse());
|
||||
}
|
||||
errorEvent.run(code, msg, data);
|
||||
}else {
|
||||
errorEvent.run(code, msg, data);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
sendRtpItem.setPlayType(InviteStreamType.PLAY);
|
||||
SsrcTransaction playTransaction = sessionManager.getSsrcTransaction(device.getDeviceId(), channelId, "play", null);
|
||||
if (playTransaction != null) {
|
||||
Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, "rtp", playTransaction.getStream());
|
||||
if (!streamReady) {
|
||||
boolean hasRtpServer = mediaServerService.checkRtpServer(mediaServerItem, "rtp", playTransaction.getStream());
|
||||
if (hasRtpServer) {
|
||||
logger.info("[上级点播]已经开启rtpServer但是尚未收到流,开启监听流的到来");
|
||||
HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", playTransaction.getStream(), true, "rtsp", mediaServerItem.getId());
|
||||
zlmHttpHookSubscribe.addSubscribe(hookSubscribe, hookEvent);
|
||||
}else {
|
||||
playTransaction = null;
|
||||
}
|
||||
}
|
||||
}else if ("Download".equalsIgnoreCase(sessionName)) {
|
||||
// 获取指定的下载速度
|
||||
Vector sdpMediaDescriptions = sdp.getMediaDescriptions(true);
|
||||
MediaDescription mediaDescription = null;
|
||||
String downloadSpeed = "1";
|
||||
if (sdpMediaDescriptions.size() > 0) {
|
||||
mediaDescription = (MediaDescription)sdpMediaDescriptions.get(0);
|
||||
}
|
||||
if (mediaDescription != null) {
|
||||
downloadSpeed = mediaDescription.getAttribute("downloadspeed");
|
||||
}
|
||||
if (playTransaction == null) {
|
||||
// 被点播的通道目前未被点播,则开始点播
|
||||
String streamId = null;
|
||||
if (mediaServerItem.isRtpEnable()) {
|
||||
streamId = String.format("%s_%s", device.getDeviceId(), channelId);
|
||||
}
|
||||
SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, ssrc, device.isSsrcCheck(), false, 0, false, device.getStreamModeForParam());
|
||||
logger.info(JSONObject.toJSONString(ssrcInfo));
|
||||
sendRtpItem.setStreamId(ssrcInfo.getStream());
|
||||
// sendRtpItem.setSsrc(ssrcInfo.getSsrc());
|
||||
|
||||
// 写入redis, 超时时回复
|
||||
redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
||||
playService.play(mediaServerItem, ssrcInfo, device, channelId, hookEvent, errorEvent, (code, msg) -> {
|
||||
sendRtpItem.setPlayType(InviteStreamType.DOWNLOAD);
|
||||
SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, null, null, device.isSsrcCheck(), true, 0, false, device.getStreamModeForParam());
|
||||
sendRtpItem.setStreamId(ssrcInfo.getStream());
|
||||
// 写入redis, 超时时回复
|
||||
redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
||||
playService.download(mediaServerItem, ssrcInfo, device.getDeviceId(), channelId, DateUtil.formatter.format(start),
|
||||
DateUtil.formatter.format(end), Integer.parseInt(downloadSpeed),
|
||||
(code, msg, data) -> {
|
||||
if (code == InviteErrorCode.SUCCESS.getCode()){
|
||||
hookEvent.run(code, msg, data);
|
||||
}else if (code == InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode() || code == InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode()){
|
||||
logger.info("[录像下载]超时, 用户:{}, 通道:{}", username, channelId);
|
||||
redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null);
|
||||
errorEvent.run(code, msg, data);
|
||||
}else {
|
||||
errorEvent.run(code, msg, data);
|
||||
}
|
||||
});
|
||||
}else {
|
||||
sendRtpItem.setPlayType(InviteStreamType.PLAY);
|
||||
String streamId = null;
|
||||
if (mediaServerItem.isRtpEnable()) {
|
||||
streamId = String.format("%s_%s", device.getDeviceId(), channelId);
|
||||
}else {
|
||||
streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase();
|
||||
}
|
||||
sendRtpItem.setStreamId(streamId);
|
||||
redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
||||
playService.play(mediaServerItem, device.getDeviceId(), channelId, ((code, msg, data) -> {
|
||||
if (code == InviteErrorCode.SUCCESS.getCode()){
|
||||
hookEvent.run(code, msg, data);
|
||||
}else if (code == InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode() || code == InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode()){
|
||||
logger.info("[上级点播]超时, 用户:{}, 通道:{}", username, channelId);
|
||||
redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null);
|
||||
});
|
||||
} else {
|
||||
errorEvent.run(code, msg, data);
|
||||
}else {
|
||||
errorEvent.run(code, msg, data);
|
||||
}
|
||||
}));
|
||||
|
||||
sendRtpItem.setStreamId(playTransaction.getStream());
|
||||
// 写入redis, 超时时回复
|
||||
redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("app", sendRtpItem.getApp());
|
||||
jsonObject.put("stream", sendRtpItem.getStreamId());
|
||||
hookEvent.response(mediaServerItem, jsonObject);
|
||||
}
|
||||
}
|
||||
} else if (gbStream != null) {
|
||||
|
||||
@ -559,7 +561,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
int port, Boolean tcpActive, boolean mediaTransmissionTCP,
|
||||
String channelId, String addressStr, String ssrc, String requesterId) {
|
||||
Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, gbStream.getApp(), gbStream.getStream());
|
||||
if (streamReady) {
|
||||
if (streamReady != null && streamReady) {
|
||||
// 自平台内容
|
||||
SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId,
|
||||
gbStream.getApp(), gbStream.getStream(), channelId, mediaTransmissionTCP, platform.isRtcp());
|
||||
@ -598,7 +600,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
// 推流
|
||||
if (streamPushItem.isSelf()) {
|
||||
Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, gbStream.getApp(), gbStream.getStream());
|
||||
if (streamReady) {
|
||||
if (streamReady != null && streamReady) {
|
||||
// 自平台内容
|
||||
SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId,
|
||||
gbStream.getApp(), gbStream.getStream(), channelId, mediaTransmissionTCP, platform.isRtcp());
|
||||
|
@ -80,7 +80,6 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
|
||||
public void process(RequestEvent evt) {
|
||||
try {
|
||||
RequestEventExt evtExt = (RequestEventExt) evt;
|
||||
String requestAddress = evtExt.getRemoteIpAddress() + ":" + evtExt.getRemotePort();
|
||||
|
||||
SIPRequest request = (SIPRequest)evt.getRequest();
|
||||
Response response = null;
|
||||
@ -91,12 +90,13 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
|
||||
AddressImpl address = (AddressImpl) fromHeader.getAddress();
|
||||
SipUri uri = (SipUri) address.getURI();
|
||||
String deviceId = uri.getUser();
|
||||
logger.info("[注册请求] 设备:{}, 开始处理: {}", deviceId, requestAddress);
|
||||
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
|
||||
RemoteAddressInfo remoteAddressInfo = SipUtils.getRemoteAddressFromRequest(request,
|
||||
userSetting.getSipUseSourceIpAsRemoteAddress());
|
||||
logger.info("[注册请求] 设备:{}, 远程地址为: {}:{}", deviceId, remoteAddressInfo.getIp(), remoteAddressInfo.getPort());
|
||||
String requestAddress = remoteAddressInfo.getIp() + ":" + remoteAddressInfo.getPort();
|
||||
logger.info("[注册请求] 设备:{}, 开始处理: {}", deviceId, requestAddress);
|
||||
if (device != null &&
|
||||
device.getSipTransactionInfo() != null &&
|
||||
request.getCallIdHeader().getCallId().equals(device.getSipTransactionInfo().getCallId())) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.info;
|
||||
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.common.InviteInfo;
|
||||
import com.genersoft.iot.vmp.common.InviteSessionType;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
|
||||
@ -9,6 +10,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
|
||||
import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
|
||||
import com.genersoft.iot.vmp.service.IInviteStreamService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
@ -17,10 +19,12 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.RequestEvent;
|
||||
import javax.sip.SipException;
|
||||
import javax.sip.header.*;
|
||||
import javax.sip.header.CallIdHeader;
|
||||
import javax.sip.header.ContentTypeHeader;
|
||||
import javax.sip.message.Response;
|
||||
import java.text.ParseException;
|
||||
|
||||
@ -43,6 +47,9 @@ public class InfoRequestProcessor extends SIPRequestProcessorParent implements I
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private IInviteStreamService inviteStreamService;
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
|
||||
@ -103,27 +110,30 @@ public class InfoRequestProcessor extends SIPRequestProcessorParent implements I
|
||||
if ("Application".equalsIgnoreCase(contentType) && "MANSRTSP".equalsIgnoreCase(contentSubType)) {
|
||||
SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(null, null, null, callIdHeader.getCallId());
|
||||
String streamId = sendRtpItem.getStreamId();
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
|
||||
if (null == streamInfo) {
|
||||
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(InviteSessionType.PLAYBACK, streamId);
|
||||
if (null == inviteInfo) {
|
||||
responseAck(request, Response.NOT_FOUND, "stream " + streamId + " not found");
|
||||
return;
|
||||
}
|
||||
Device device1 = storager.queryVideoDevice(streamInfo.getDeviceID());
|
||||
cmder.playbackControlCmd(device1,streamInfo,new String(evt.getRequest().getRawContent()),eventResult -> {
|
||||
// 失败的回复
|
||||
try {
|
||||
responseAck(request, eventResult.statusCode, eventResult.msg);
|
||||
} catch (SipException | InvalidArgumentException | ParseException e) {
|
||||
logger.error("[命令发送失败] 国标级联 录像控制: {}", e.getMessage());
|
||||
}
|
||||
}, eventResult -> {
|
||||
// 成功的回复
|
||||
try {
|
||||
responseAck(request, eventResult.statusCode);
|
||||
} catch (SipException | InvalidArgumentException | ParseException e) {
|
||||
logger.error("[命令发送失败] 国标级联 录像控制: {}", e.getMessage());
|
||||
}
|
||||
});
|
||||
Device device1 = storager.queryVideoDevice(inviteInfo.getDeviceId());
|
||||
if (inviteInfo.getStreamInfo() != null) {
|
||||
cmder.playbackControlCmd(device1,inviteInfo.getStreamInfo(),new String(evt.getRequest().getRawContent()),eventResult -> {
|
||||
// 失败的回复
|
||||
try {
|
||||
responseAck(request, eventResult.statusCode, eventResult.msg);
|
||||
} catch (SipException | InvalidArgumentException | ParseException e) {
|
||||
logger.error("[命令发送失败] 国标级联 录像控制: {}", e.getMessage());
|
||||
}
|
||||
}, eventResult -> {
|
||||
// 成功的回复
|
||||
try {
|
||||
responseAck(request, eventResult.statusCode);
|
||||
} catch (SipException | InvalidArgumentException | ParseException e) {
|
||||
logger.error("[命令发送失败] 国标级联 录像控制: {}", e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} catch (SipException e) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd;
|
||||
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.common.InviteInfo;
|
||||
import com.genersoft.iot.vmp.common.InviteSessionType;
|
||||
import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
@ -15,6 +16,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.
|
||||
import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange;
|
||||
import com.genersoft.iot.vmp.service.IInviteStreamService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
@ -64,6 +66,12 @@ public class MediaStatusNotifyMessageHandler extends SIPRequestProcessorParent i
|
||||
@Autowired
|
||||
private ZlmHttpHookSubscribe subscribe;
|
||||
|
||||
@Autowired
|
||||
private IInviteStreamService inviteStreamService;
|
||||
|
||||
@Autowired
|
||||
private VideoStreamSessionManager streamSession;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
notifyMessageHandler.addHandler(cmdType, this);
|
||||
@ -82,17 +90,15 @@ public class MediaStatusNotifyMessageHandler extends SIPRequestProcessorParent i
|
||||
String NotifyType =getText(rootElement, "NotifyType");
|
||||
if ("121".equals(NotifyType)){
|
||||
logger.info("[录像流]推送完毕,收到关流通知");
|
||||
// 查询是设备
|
||||
StreamInfo streamInfo = redisCatchStorage.queryDownload(null, null, null, callIdHeader.getCallId());
|
||||
if (streamInfo != null) {
|
||||
// 设置进度100%
|
||||
streamInfo.setProgress(1);
|
||||
redisCatchStorage.startDownload(streamInfo, callIdHeader.getCallId());
|
||||
}
|
||||
|
||||
// 先从会话内查找
|
||||
SsrcTransaction ssrcTransaction = sessionManager.getSsrcTransaction(null, null, callIdHeader.getCallId(), null);
|
||||
if (ssrcTransaction != null) { // 兼容海康 媒体通知 消息from字段不是设备ID的问题
|
||||
SsrcTransaction ssrcTransaction = streamSession.getSsrcTransaction(null, null, callIdHeader.getCallId(), null);
|
||||
if (ssrcTransaction != null) {
|
||||
logger.info("[录像流]推送完毕,关流通知, device: {}, channelId: {}", ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId());
|
||||
InviteInfo inviteInfo = inviteStreamService.getInviteInfo(InviteSessionType.DOWNLOAD, ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId(), ssrcTransaction.getStream());
|
||||
if (inviteInfo.getStreamInfo() != null) {
|
||||
inviteInfo.getStreamInfo().setProgress(1);
|
||||
inviteStreamService.updateInviteInfo(inviteInfo);
|
||||
}
|
||||
|
||||
try {
|
||||
cmder.streamByeCmd(device, ssrcTransaction.getChannelId(), null, callIdHeader.getCallId());
|
||||
@ -117,6 +123,8 @@ public class MediaStatusNotifyMessageHandler extends SIPRequestProcessorParent i
|
||||
logger.error("[命令发送失败] 国标级联 录像播放完毕: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
logger.info("[录像流]推送完毕,关流通知, 但是未找到对应的下载信息");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package com.genersoft.iot.vmp.media.zlm;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.InviteInfo;
|
||||
import com.genersoft.iot.vmp.common.InviteSessionType;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
|
||||
@ -22,10 +24,8 @@ import com.genersoft.iot.vmp.media.zlm.dto.hook.*;
|
||||
import com.genersoft.iot.vmp.service.*;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.DeferredResultEx;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -70,6 +70,9 @@ public class ZLMHttpHookListener {
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private IInviteStreamService inviteStreamService;
|
||||
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
@ -252,7 +255,7 @@ public class ZLMHttpHookListener {
|
||||
result.setEnable_audio(deviceChannel.isHasAudio());
|
||||
}
|
||||
// 如果是录像下载就设置视频间隔十秒
|
||||
if (ssrcTransactionForAll.get(0).getType() == VideoStreamSessionManager.SessionType.download) {
|
||||
if (ssrcTransactionForAll.get(0).getType() == InviteSessionType.DOWNLOAD) {
|
||||
result.setMp4_max_second(10);
|
||||
result.setEnable_audio(true);
|
||||
result.setEnable_mp4(true);
|
||||
@ -342,17 +345,10 @@ public class ZLMHttpHookListener {
|
||||
}
|
||||
|
||||
if ("rtp".equals(param.getApp()) && !param.isRegist()) {
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(param.getStream());
|
||||
if (streamInfo != null) {
|
||||
redisCatchStorage.stopPlay(streamInfo);
|
||||
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
|
||||
} else {
|
||||
streamInfo = redisCatchStorage.queryPlayback(null, null,
|
||||
param.getStream(), null);
|
||||
if (streamInfo != null) {
|
||||
redisCatchStorage.stopPlayback(streamInfo.getDeviceID(), streamInfo.getChannelId(),
|
||||
streamInfo.getStream(), null);
|
||||
}
|
||||
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(null, param.getStream());
|
||||
if (inviteInfo != null && (inviteInfo.getType() == InviteSessionType.PLAY || inviteInfo.getType() == InviteSessionType.PLAYBACK)) {
|
||||
inviteStreamService.removeInviteInfo(inviteInfo);
|
||||
storager.stopPlay(inviteInfo.getDeviceId(), inviteInfo.getChannelId());
|
||||
}
|
||||
} else {
|
||||
if (!"rtp".equals(param.getApp())) {
|
||||
@ -442,7 +438,7 @@ public class ZLMHttpHookListener {
|
||||
@PostMapping(value = "/on_stream_none_reader", produces = "application/json;charset=UTF-8")
|
||||
public JSONObject onStreamNoneReader(@RequestBody OnStreamNoneReaderHookParam param) {
|
||||
|
||||
logger.info("[ZLM HOOK]流无人观看:{]->{}->{}/{}" + param.getMediaServerId(), param.getSchema(),
|
||||
logger.info("[ZLM HOOK]流无人观看:{}->{}->{}/{}", param.getMediaServerId(), param.getSchema(),
|
||||
param.getApp(), param.getStream());
|
||||
JSONObject ret = new JSONObject();
|
||||
ret.put("code", 0);
|
||||
@ -450,13 +446,20 @@ public class ZLMHttpHookListener {
|
||||
if ("rtp".equals(param.getApp())) {
|
||||
ret.put("close", userSetting.getStreamOnDemand());
|
||||
// 国标流, 点播/录像回放/录像下载
|
||||
StreamInfo streamInfoForPlayCatch = redisCatchStorage.queryPlayByStreamId(param.getStream());
|
||||
// StreamInfo streamInfoForPlayCatch = redisCatchStorage.queryPlayByStreamId(param.getStream());
|
||||
|
||||
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(null, param.getStream());
|
||||
// 点播
|
||||
if (streamInfoForPlayCatch != null) {
|
||||
if (inviteInfo != null) {
|
||||
// 录像下载
|
||||
if (inviteInfo.getType() == InviteSessionType.DOWNLOAD) {
|
||||
ret.put("close", false);
|
||||
return ret;
|
||||
}
|
||||
// 收到无人观看说明流也没有在往上级推送
|
||||
if (redisCatchStorage.isChannelSendingRTP(streamInfoForPlayCatch.getChannelId())) {
|
||||
if (redisCatchStorage.isChannelSendingRTP(inviteInfo.getChannelId())) {
|
||||
List<SendRtpItem> sendRtpItems = redisCatchStorage.querySendRTPServerByChnnelId(
|
||||
streamInfoForPlayCatch.getChannelId());
|
||||
inviteInfo.getChannelId());
|
||||
if (sendRtpItems.size() > 0) {
|
||||
for (SendRtpItem sendRtpItem : sendRtpItems) {
|
||||
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(sendRtpItem.getPlatformId());
|
||||
@ -470,49 +473,22 @@ public class ZLMHttpHookListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
Device device = deviceService.getDevice(streamInfoForPlayCatch.getDeviceID());
|
||||
Device device = deviceService.getDevice(inviteInfo.getDeviceId());
|
||||
if (device != null) {
|
||||
try {
|
||||
cmder.streamByeCmd(device, streamInfoForPlayCatch.getChannelId(),
|
||||
streamInfoForPlayCatch.getStream(), null);
|
||||
if (inviteStreamService.getInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId(), inviteInfo.getChannelId(), inviteInfo.getStream()) != null) {
|
||||
cmder.streamByeCmd(device, inviteInfo.getChannelId(),
|
||||
inviteInfo.getStream(), null);
|
||||
}
|
||||
} catch (InvalidArgumentException | ParseException | SipException |
|
||||
SsrcTransactionNotFoundException e) {
|
||||
logger.error("[无人观看]点播, 发送BYE失败 {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
redisCatchStorage.stopPlay(streamInfoForPlayCatch);
|
||||
storager.stopPlay(streamInfoForPlayCatch.getDeviceID(), streamInfoForPlayCatch.getChannelId());
|
||||
return ret;
|
||||
}
|
||||
// 录像回放
|
||||
StreamInfo streamInfoForPlayBackCatch = redisCatchStorage.queryPlayback(null, null,
|
||||
param.getStream(), null);
|
||||
if (streamInfoForPlayBackCatch != null) {
|
||||
if (streamInfoForPlayBackCatch.isPause()) {
|
||||
ret.put("close", false);
|
||||
} else {
|
||||
Device device = deviceService.getDevice(streamInfoForPlayBackCatch.getDeviceID());
|
||||
if (device != null) {
|
||||
try {
|
||||
cmder.streamByeCmd(device, streamInfoForPlayBackCatch.getChannelId(),
|
||||
streamInfoForPlayBackCatch.getStream(), null);
|
||||
} catch (InvalidArgumentException | ParseException | SipException |
|
||||
SsrcTransactionNotFoundException e) {
|
||||
logger.error("[无人观看]回放, 发送BYE失败 {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
redisCatchStorage.stopPlayback(streamInfoForPlayBackCatch.getDeviceID(),
|
||||
streamInfoForPlayBackCatch.getChannelId(), streamInfoForPlayBackCatch.getStream(), null);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
// 录像下载
|
||||
StreamInfo streamInfoForDownload = redisCatchStorage.queryDownload(null, null,
|
||||
param.getStream(), null);
|
||||
// 进行录像下载时无人观看不断流
|
||||
if (streamInfoForDownload != null) {
|
||||
ret.put("close", false);
|
||||
inviteStreamService.removeInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId(),
|
||||
inviteInfo.getChannelId(), inviteInfo.getStream());
|
||||
storager.stopPlay(inviteInfo.getDeviceId(), inviteInfo.getChannelId());
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
@ -582,6 +558,7 @@ public class ZLMHttpHookListener {
|
||||
return defaultResult;
|
||||
}
|
||||
logger.info("[ZLM HOOK] 流未找到, 发起自动点播:{}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream());
|
||||
|
||||
RequestMessage msg = new RequestMessage();
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId;
|
||||
boolean exist = resultHolder.exist(key, null);
|
||||
@ -589,31 +566,22 @@ public class ZLMHttpHookListener {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
msg.setId(uuid);
|
||||
DeferredResult<HookResult> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue());
|
||||
DeferredResultEx<HookResult> deferredResultEx = new DeferredResultEx<>(result);
|
||||
|
||||
result.onTimeout(() -> {
|
||||
logger.info("点播接口等待超时");
|
||||
logger.info("[ZLM HOOK] 自动点播, 等待超时");
|
||||
// 释放rtpserver
|
||||
msg.setData(new HookResult(ErrorCode.ERROR100.getCode(), "点播超时"));
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
// TODO 在点播未成功的情况下在此调用接口点播会导致返回的流地址ip错误
|
||||
deferredResultEx.setFilter(result1 -> {
|
||||
WVPResult<StreamInfo> wvpResult1 = (WVPResult<StreamInfo>) result1;
|
||||
HookResult resultForEnd = new HookResult();
|
||||
resultForEnd.setCode(wvpResult1.getCode());
|
||||
resultForEnd.setMsg(wvpResult1.getMsg());
|
||||
return resultForEnd;
|
||||
});
|
||||
|
||||
// 录像查询以channelId作为deviceId查询
|
||||
resultHolder.put(key, uuid, deferredResultEx);
|
||||
resultHolder.put(key, uuid, result);
|
||||
|
||||
if (!exist) {
|
||||
playService.play(mediaInfo, deviceId, channelId, null, eventResult -> {
|
||||
msg.setData(new HookResult(eventResult.statusCode, eventResult.msg));
|
||||
playService.play(mediaInfo, deviceId, channelId, (code, message, data) -> {
|
||||
msg.setData(new HookResult(code, message));
|
||||
resultHolder.invokeResult(msg);
|
||||
}, null);
|
||||
});
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
|
@ -97,7 +97,8 @@ public class ZLMMediaListManager {
|
||||
public void sendStreamEvent(String app, String stream, String mediaServerId) {
|
||||
MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
|
||||
// 查看推流状态
|
||||
if (zlmrtpServerFactory.isStreamReady(mediaServerItem, app, stream)) {
|
||||
Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, app, stream);
|
||||
if (streamReady != null && streamReady) {
|
||||
ChannelOnlineEvent channelOnlineEventLister = getChannelOnlineEventLister(app, stream);
|
||||
if (channelOnlineEventLister != null) {
|
||||
try {
|
||||
|
@ -293,11 +293,14 @@ public class ZLMRTPServerFactory {
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
localPort = jsonObject.getInteger("port");
|
||||
HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, serverItem.getId());
|
||||
// 订阅 zlm启动事件, 新的zlm也会从这里进入系统
|
||||
hookSubscribe.addSubscribe(hookSubscribeForRtpServerTimeout,
|
||||
(MediaServerItem mediaServerItem, JSONObject response)->{
|
||||
logger.info("[上级点播] {}->监听端口到期继续保持监听", ssrc);
|
||||
keepPort(serverItem, ssrc);
|
||||
int port = keepPort(serverItem, ssrc);
|
||||
if (port == 0) {
|
||||
logger.info("[上级点播] {}->监听端口失败,移除监听", ssrc);
|
||||
hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout);
|
||||
}
|
||||
});
|
||||
logger.info("[上级点播] {}->监听端口: {}", ssrc, localPort);
|
||||
}else {
|
||||
@ -330,6 +333,9 @@ public class ZLMRTPServerFactory {
|
||||
*/
|
||||
public Boolean isRtpReady(MediaServerItem mediaServerItem, String streamId) {
|
||||
JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServerItem,"rtp", "rtsp", streamId);
|
||||
if (mediaInfo.getInteger("code") == -2) {
|
||||
return null;
|
||||
}
|
||||
return (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online"));
|
||||
}
|
||||
|
||||
@ -338,8 +344,10 @@ public class ZLMRTPServerFactory {
|
||||
*/
|
||||
public Boolean isStreamReady(MediaServerItem mediaServerItem, String app, String streamId) {
|
||||
JSONObject mediaInfo = zlmresTfulUtils.getMediaList(mediaServerItem, app, streamId);
|
||||
return mediaInfo != null && (mediaInfo.getInteger("code") == 0
|
||||
|
||||
if (mediaInfo == null || (mediaInfo.getInteger("code") == -2)) {
|
||||
return null;
|
||||
}
|
||||
return (mediaInfo.getInteger("code") == 0
|
||||
&& mediaInfo.getJSONArray("data") != null
|
||||
&& mediaInfo.getJSONArray("data").size() > 0);
|
||||
}
|
||||
|
@ -98,7 +98,10 @@ public class ZlmHttpHookSubscribe {
|
||||
|
||||
if (!CollectionUtils.isEmpty(entriesToRemove)) {
|
||||
for (Map.Entry<IHookSubscribe, ZlmHttpHookSubscribe.Event> entry : entriesToRemove) {
|
||||
entries.remove(entry);
|
||||
eventMap.remove(entry.getKey());
|
||||
}
|
||||
if (eventMap.size() == 0) {
|
||||
allSubscribes.remove(hookSubscribe.getHookType());
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,9 +137,9 @@ public class ZlmHttpHookSubscribe {
|
||||
/**
|
||||
* 对订阅数据进行过期清理
|
||||
*/
|
||||
@Scheduled(cron="0 0/5 * * * ?") //每5分钟执行一次
|
||||
// @Scheduled(cron="0 0/5 * * * ?") //每5分钟执行一次
|
||||
@Scheduled(fixedRate = 2 * 1000)
|
||||
public void execute(){
|
||||
|
||||
Instant instant = Instant.now().minusMillis(TimeUnit.MINUTES.toMillis(5));
|
||||
int total = 0;
|
||||
for (HookType hookType : allSubscribes.keySet()) {
|
||||
|
@ -0,0 +1,68 @@
|
||||
package com.genersoft.iot.vmp.service;
|
||||
|
||||
import com.genersoft.iot.vmp.common.InviteInfo;
|
||||
import com.genersoft.iot.vmp.common.InviteSessionType;
|
||||
import com.genersoft.iot.vmp.service.bean.InviteErrorCallback;
|
||||
|
||||
/**
|
||||
* 记录国标点播的状态,包括实时预览,下载,录像回放
|
||||
*/
|
||||
public interface IInviteStreamService {
|
||||
|
||||
/**
|
||||
* 更新点播的状态信息
|
||||
*/
|
||||
void updateInviteInfo(InviteInfo inviteInfo);
|
||||
|
||||
/**
|
||||
* 获取点播的状态信息
|
||||
*/
|
||||
InviteInfo getInviteInfo(InviteSessionType type,
|
||||
String deviceId,
|
||||
String channelId,
|
||||
String stream);
|
||||
|
||||
/**
|
||||
* 移除点播的状态信息
|
||||
*/
|
||||
void removeInviteInfo(InviteSessionType type,
|
||||
String deviceId,
|
||||
String channelId,
|
||||
String stream);
|
||||
/**
|
||||
* 移除点播的状态信息
|
||||
*/
|
||||
void removeInviteInfo(InviteInfo inviteInfo);
|
||||
/**
|
||||
* 移除点播的状态信息
|
||||
*/
|
||||
void removeInviteInfoByDeviceAndChannel(InviteSessionType inviteSessionType, String deviceId, String channelId);
|
||||
|
||||
/**
|
||||
* 获取点播的状态信息
|
||||
*/
|
||||
InviteInfo getInviteInfoByDeviceAndChannel(InviteSessionType type,
|
||||
String deviceId,
|
||||
String channelId);
|
||||
|
||||
/**
|
||||
* 获取点播的状态信息
|
||||
*/
|
||||
InviteInfo getInviteInfoByStream(InviteSessionType type, String stream);
|
||||
|
||||
|
||||
/**
|
||||
* 添加一个invite回调
|
||||
*/
|
||||
void once(InviteSessionType type, String deviceId, String channelId, String stream, InviteErrorCallback<Object> callback);
|
||||
|
||||
/**
|
||||
* 调用一个invite回调
|
||||
*/
|
||||
void call(InviteSessionType type, String deviceId, String channelId, String stream, int code, String msg, Object data);
|
||||
|
||||
/**
|
||||
* 清空一个设备的所有invite信息
|
||||
*/
|
||||
void clearInviteInfo(String deviceId);
|
||||
}
|
@ -1,16 +1,10 @@
|
||||
package com.genersoft.iot.vmp.service;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.exception.ServiceException;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.InviteStreamCallback;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.InviteStreamInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.service.bean.InviteTimeOutCallback;
|
||||
import com.genersoft.iot.vmp.service.bean.PlayBackCallback;
|
||||
import com.genersoft.iot.vmp.service.bean.InviteErrorCallback;
|
||||
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
@ -22,12 +16,9 @@ import java.text.ParseException;
|
||||
*/
|
||||
public interface IPlayService {
|
||||
|
||||
void onPublishHandlerForPlay(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId);
|
||||
|
||||
void play(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,
|
||||
ZlmHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent,
|
||||
InviteTimeOutCallback timeoutCallback);
|
||||
void play(MediaServerItem mediaServerItem, String deviceId, String channelId, ZlmHttpHookSubscribe.Event event, SipSubscribe.Event errorEvent, Runnable timeoutCallback);
|
||||
InviteErrorCallback<Object> callback);
|
||||
SSRCInfo play(MediaServerItem mediaServerItem, String deviceId, String channelId, InviteErrorCallback<Object> callback);
|
||||
|
||||
MediaServerItem getNewMediaServerItem(Device device);
|
||||
|
||||
@ -36,15 +27,13 @@ public interface IPlayService {
|
||||
*/
|
||||
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);
|
||||
void playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
|
||||
void playBack(String deviceId, String channelId, String startTime, String endTime, InviteErrorCallback<Object> callback);
|
||||
void playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, InviteErrorCallback<Object> callback);
|
||||
|
||||
void zlmServerOffline(String mediaServerId);
|
||||
|
||||
void download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback playBackCallback);
|
||||
void download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
|
||||
void download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteErrorCallback<Object> callback);
|
||||
void download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteErrorCallback<Object> callback);
|
||||
|
||||
StreamInfo getDownLoadInfo(String deviceId, String channelId, String stream);
|
||||
|
||||
|
@ -0,0 +1,6 @@
|
||||
package com.genersoft.iot.vmp.service.bean;
|
||||
|
||||
public interface InviteErrorCallback<T> {
|
||||
|
||||
void run(int code, String msg, T data);
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.genersoft.iot.vmp.service.bean;
|
||||
|
||||
/**
|
||||
* 全局错误码
|
||||
*/
|
||||
public enum InviteErrorCode {
|
||||
SUCCESS(0, "成功"),
|
||||
ERROR_FOR_SIGNALLING_TIMEOUT(-1, "信令超时"),
|
||||
ERROR_FOR_STREAM_TIMEOUT(-2, "收流超时"),
|
||||
ERROR_FOR_RESOURCE_EXHAUSTION(-3, "资源耗尽"),
|
||||
ERROR_FOR_CATCH_DATA(-4, "缓存数据异常"),
|
||||
ERROR_FOR_SIGNALLING_ERROR(-5, "收到信令错误"),
|
||||
ERROR_FOR_STREAM_PARSING_EXCEPTIONS(-6, "流地址解析错误"),
|
||||
ERROR_FOR_SDP_PARSING_EXCEPTIONS(-7, "SDP信息解析失败"),
|
||||
ERROR_FOR_SSRC_UNAVAILABLE(-8, "SSRC不可用"),
|
||||
ERROR_FOR_RESET_SSRC(-9, "重新设置收流信息失败"),
|
||||
ERROR_FOR_SIP_SENDING_FAILED(-10, "命令发送失败"),
|
||||
ERROR_FOR_ASSIST_NOT_READY(-11, "没有可用的assist服务"),
|
||||
ERROR_FOR_PARAMETER_ERROR(-13, "参数异常");
|
||||
|
||||
private final int code;
|
||||
private final String msg;
|
||||
|
||||
InviteErrorCode(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
package com.genersoft.iot.vmp.service.impl;
|
||||
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.common.InviteInfo;
|
||||
import com.genersoft.iot.vmp.common.InviteSessionType;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||
import com.genersoft.iot.vmp.gb28181.utils.Coordtransform;
|
||||
import com.genersoft.iot.vmp.service.IDeviceChannelService;
|
||||
import com.genersoft.iot.vmp.service.IInviteStreamService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
|
||||
import com.genersoft.iot.vmp.storager.dao.DeviceMapper;
|
||||
@ -32,6 +34,9 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private IInviteStreamService inviteStreamService;
|
||||
|
||||
@Autowired
|
||||
private DeviceChannelMapper channelMapper;
|
||||
|
||||
@ -78,9 +83,10 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
|
||||
public void updateChannel(String deviceId, DeviceChannel channel) {
|
||||
String channelId = channel.getChannelId();
|
||||
channel.setDeviceId(deviceId);
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
|
||||
if (streamInfo != null) {
|
||||
channel.setStreamId(streamInfo.getStream());
|
||||
// StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
|
||||
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
|
||||
if (inviteInfo != null && inviteInfo.getStreamInfo() != null) {
|
||||
channel.setStreamId(inviteInfo.getStreamInfo().getStream());
|
||||
}
|
||||
String now = DateUtil.getNow();
|
||||
channel.setUpdateTime(now);
|
||||
@ -106,9 +112,9 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
|
||||
if (channelList.size() == 0) {
|
||||
for (DeviceChannel channel : channels) {
|
||||
channel.setDeviceId(deviceId);
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channel.getChannelId());
|
||||
if (streamInfo != null) {
|
||||
channel.setStreamId(streamInfo.getStream());
|
||||
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channel.getChannelId());
|
||||
if (inviteInfo != null && inviteInfo.getStreamInfo() != null) {
|
||||
channel.setStreamId(inviteInfo.getStreamInfo().getStream());
|
||||
}
|
||||
String now = DateUtil.getNow();
|
||||
channel.setUpdateTime(now);
|
||||
@ -122,9 +128,9 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
|
||||
}
|
||||
for (DeviceChannel channel : channels) {
|
||||
channel.setDeviceId(deviceId);
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channel.getChannelId());
|
||||
if (streamInfo != null) {
|
||||
channel.setStreamId(streamInfo.getStream());
|
||||
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channel.getChannelId());
|
||||
if (inviteInfo != null && inviteInfo.getStreamInfo() != null) {
|
||||
channel.setStreamId(inviteInfo.getStreamInfo().getStream());
|
||||
}
|
||||
String now = DateUtil.getNow();
|
||||
channel.setUpdateTime(now);
|
||||
|
@ -12,6 +12,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd.CatalogResponseMessageHandler;
|
||||
import com.genersoft.iot.vmp.service.IDeviceChannelService;
|
||||
import com.genersoft.iot.vmp.service.IDeviceService;
|
||||
import com.genersoft.iot.vmp.service.IInviteStreamService;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
|
||||
@ -58,6 +59,9 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private IInviteStreamService inviteStreamService;
|
||||
|
||||
@Autowired
|
||||
private DeviceMapper deviceMapper;
|
||||
|
||||
@ -97,7 +101,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
String now = DateUtil.getNow();
|
||||
if (deviceInRedis != null && deviceInDb == null) {
|
||||
// redis 存在脏数据
|
||||
redisCatchStorage.clearCatchByDeviceId(device.getDeviceId());
|
||||
inviteStreamService.clearInviteInfo(device.getDeviceId());
|
||||
}
|
||||
device.setUpdateTime(now);
|
||||
if (device.getKeepaliveIntervalTime() == 0) {
|
||||
@ -497,8 +501,10 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
node.setBasicData(channel);
|
||||
node.setParent(false);
|
||||
if (channel.getChannelId().length() > 8) {
|
||||
String gbCodeType = channel.getChannelId().substring(10, 13);
|
||||
node.setParent(gbCodeType.equals(ChannelIdType.BUSINESS_GROUP) || gbCodeType.equals(ChannelIdType.VIRTUAL_ORGANIZATION) );
|
||||
if (channel.getChannelId().length() > 13) {
|
||||
String gbCodeType = channel.getChannelId().substring(10, 13);
|
||||
node.setParent(gbCodeType.equals(ChannelIdType.BUSINESS_GROUP) || gbCodeType.equals(ChannelIdType.VIRTUAL_ORGANIZATION) );
|
||||
}
|
||||
}else {
|
||||
node.setParent(true);
|
||||
}
|
||||
|
@ -0,0 +1,182 @@
|
||||
package com.genersoft.iot.vmp.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.genersoft.iot.vmp.common.InviteInfo;
|
||||
import com.genersoft.iot.vmp.common.InviteSessionStatus;
|
||||
import com.genersoft.iot.vmp.common.InviteSessionType;
|
||||
import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
||||
import com.genersoft.iot.vmp.service.IInviteStreamService;
|
||||
import com.genersoft.iot.vmp.service.bean.InviteErrorCallback;
|
||||
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
@Service
|
||||
public class InviteStreamServiceImpl implements IInviteStreamService {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(InviteStreamServiceImpl.class);
|
||||
|
||||
private final Map<String, List<InviteErrorCallback<Object>>> inviteErrorCallbackMap = new ConcurrentHashMap<>();
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<Object, Object> redisTemplate;
|
||||
|
||||
@Override
|
||||
public void updateInviteInfo(InviteInfo inviteInfo) {
|
||||
if (inviteInfo == null || (inviteInfo.getDeviceId() == null || inviteInfo.getChannelId() == null)) {
|
||||
logger.warn("[更新Invite信息],参数不全: {}", JSON.toJSON(inviteInfo));
|
||||
return;
|
||||
}
|
||||
InviteInfo inviteInfoForUpdate = null;
|
||||
|
||||
if (InviteSessionStatus.ready == inviteInfo.getStatus()) {
|
||||
if (inviteInfo.getDeviceId() == null
|
||||
|| inviteInfo.getChannelId() == null
|
||||
|| inviteInfo.getType() == null
|
||||
|| inviteInfo.getStream() == null
|
||||
) {
|
||||
return;
|
||||
}
|
||||
inviteInfoForUpdate = inviteInfo;
|
||||
} else {
|
||||
InviteInfo inviteInfoInRedis = getInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId(),
|
||||
inviteInfo.getChannelId(), inviteInfo.getStream());
|
||||
if (inviteInfoInRedis == null) {
|
||||
logger.warn("[更新Invite信息],未从缓存中读取到Invite信息: deviceId: {}, channel: {}, stream: {}",
|
||||
inviteInfo.getDeviceId(), inviteInfo.getChannelId(), inviteInfo.getStream());
|
||||
return;
|
||||
}
|
||||
if (inviteInfo.getStreamInfo() != null) {
|
||||
inviteInfoInRedis.setStreamInfo(inviteInfo.getStreamInfo());
|
||||
}
|
||||
if (inviteInfo.getSsrcInfo() != null) {
|
||||
inviteInfoInRedis.setSsrcInfo(inviteInfo.getSsrcInfo());
|
||||
}
|
||||
if (inviteInfo.getStreamMode() != null) {
|
||||
inviteInfoInRedis.setStreamMode(inviteInfo.getStreamMode());
|
||||
}
|
||||
if (inviteInfo.getReceiveIp() != null) {
|
||||
inviteInfoInRedis.setReceiveIp(inviteInfo.getReceiveIp());
|
||||
}
|
||||
if (inviteInfo.getReceivePort() != null) {
|
||||
inviteInfoInRedis.setReceivePort(inviteInfo.getReceivePort());
|
||||
}
|
||||
if (inviteInfo.getStatus() != null) {
|
||||
inviteInfoInRedis.setStatus(inviteInfo.getStatus());
|
||||
}
|
||||
|
||||
inviteInfoForUpdate = inviteInfoInRedis;
|
||||
|
||||
}
|
||||
String key = VideoManagerConstants.INVITE_PREFIX +
|
||||
"_" + inviteInfoForUpdate.getType() +
|
||||
"_" + inviteInfoForUpdate.getDeviceId() +
|
||||
"_" + inviteInfoForUpdate.getChannelId() +
|
||||
"_" + inviteInfoForUpdate.getStream();
|
||||
redisTemplate.opsForValue().set(key, inviteInfoForUpdate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InviteInfo getInviteInfo(InviteSessionType type, String deviceId, String channelId, String stream) {
|
||||
String key = VideoManagerConstants.INVITE_PREFIX +
|
||||
"_" + (type != null ? type : "*") +
|
||||
"_" + (deviceId != null ? deviceId : "*") +
|
||||
"_" + (channelId != null ? channelId : "*") +
|
||||
"_" + (stream != null ? stream : "*");
|
||||
List<Object> scanResult = RedisUtil.scan(redisTemplate, key);
|
||||
if (scanResult.size() != 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (InviteInfo) redisTemplate.opsForValue().get(scanResult.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InviteInfo getInviteInfoByDeviceAndChannel(InviteSessionType type, String deviceId, String channelId) {
|
||||
return getInviteInfo(type, deviceId, channelId, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InviteInfo getInviteInfoByStream(InviteSessionType type, String stream) {
|
||||
return getInviteInfo(type, null, null, stream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeInviteInfo(InviteSessionType type, String deviceId, String channelId, String stream) {
|
||||
String scanKey = VideoManagerConstants.INVITE_PREFIX +
|
||||
"_" + (type != null ? type : "*") +
|
||||
"_" + (deviceId != null ? deviceId : "*") +
|
||||
"_" + (channelId != null ? channelId : "*") +
|
||||
"_" + (stream != null ? stream : "*");
|
||||
List<Object> scanResult = RedisUtil.scan(redisTemplate, scanKey);
|
||||
if (scanResult.size() > 0) {
|
||||
for (Object keyObj : scanResult) {
|
||||
String key = (String) keyObj;
|
||||
InviteInfo inviteInfo = (InviteInfo) redisTemplate.opsForValue().get(key);
|
||||
if (inviteInfo == null) {
|
||||
continue;
|
||||
}
|
||||
redisTemplate.delete(key);
|
||||
inviteErrorCallbackMap.remove(buildKey(type, deviceId, channelId, inviteInfo.getStream()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeInviteInfoByDeviceAndChannel(InviteSessionType inviteSessionType, String deviceId, String channelId) {
|
||||
removeInviteInfo(inviteSessionType, deviceId, channelId, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeInviteInfo(InviteInfo inviteInfo) {
|
||||
removeInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId(), inviteInfo.getChannelId(), inviteInfo.getStream());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void once(InviteSessionType type, String deviceId, String channelId, String stream, InviteErrorCallback<Object> callback) {
|
||||
String key = buildKey(type, deviceId, channelId, stream);
|
||||
List<InviteErrorCallback<Object>> callbacks = inviteErrorCallbackMap.get(key);
|
||||
if (callbacks == null) {
|
||||
callbacks = new CopyOnWriteArrayList<>();
|
||||
inviteErrorCallbackMap.put(key, callbacks);
|
||||
}
|
||||
callbacks.add(callback);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(InviteSessionType type, String deviceId, String channelId, String stream, int code, String msg, Object data) {
|
||||
String key = buildKey(type, deviceId, channelId, stream);
|
||||
List<InviteErrorCallback<Object>> callbacks = inviteErrorCallbackMap.get(key);
|
||||
if (callbacks == null) {
|
||||
return;
|
||||
}
|
||||
for (InviteErrorCallback<Object> callback : callbacks) {
|
||||
callback.run(code, msg, data);
|
||||
}
|
||||
inviteErrorCallbackMap.remove(key);
|
||||
}
|
||||
|
||||
private String buildKey(InviteSessionType type, String deviceId, String channelId, String stream) {
|
||||
String key = type + "_" + deviceId + "_" + channelId;
|
||||
// 如果ssrc未null那么可以实现一个通道只能一次操作,ssrc不为null则可以支持一个通道多次invite
|
||||
if (stream != null) {
|
||||
key += ("_" + stream);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void clearInviteInfo(String deviceId) {
|
||||
removeInviteInfo(null, deviceId, null, null);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -264,8 +264,8 @@ public class RedisGbPlayMsgListener implements MessageListener {
|
||||
return;
|
||||
}
|
||||
// 确定流是否在线
|
||||
boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, content.getApp(), content.getStream());
|
||||
if (streamReady) {
|
||||
Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, content.getApp(), content.getStream());
|
||||
if (streamReady != null && streamReady) {
|
||||
logger.info("[回复推流信息] {}/{}", content.getApp(), content.getStream());
|
||||
responseSendItem(mediaServerItem, content, toId, serial);
|
||||
}else {
|
||||
@ -301,9 +301,6 @@ public class RedisGbPlayMsgListener implements MessageListener {
|
||||
String key = VideoManagerConstants.VM_MSG_STREAM_PUSH_REQUESTED;
|
||||
logger.info("[redis发送通知] 推流被请求 {}: {}/{}", key, messageForPushChannel.getApp(), messageForPushChannel.getStream());
|
||||
redisTemplate.convertAndSend(key, JSON.toJSON(messageForPushChannel));
|
||||
|
||||
// redisCatchStorage.sendStreamPushRequestedMsg(messageForPushChannel);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,16 @@
|
||||
package com.genersoft.iot.vmp.storager;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.common.SystemAllInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.*;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.AlarmChannelMessage;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam;
|
||||
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
|
||||
import com.genersoft.iot.vmp.service.bean.MessageForPushChannel;
|
||||
import com.genersoft.iot.vmp.service.bean.ThirdPartyGB;
|
||||
import com.genersoft.iot.vmp.storager.dao.dto.PlatformRegisterInfo;
|
||||
|
||||
import java.util.List;
|
||||
@ -23,42 +25,6 @@ public interface IRedisCatchStorage {
|
||||
*/
|
||||
Long getCSEQ();
|
||||
|
||||
/**
|
||||
* 开始播放时将流存入
|
||||
*
|
||||
* @param stream 流信息
|
||||
* @return
|
||||
*/
|
||||
boolean startPlay(StreamInfo stream);
|
||||
|
||||
|
||||
/**
|
||||
* 停止播放时删除
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean stopPlay(StreamInfo streamInfo);
|
||||
|
||||
/**
|
||||
* 查询播放列表
|
||||
* @return
|
||||
*/
|
||||
StreamInfo queryPlay(StreamInfo streamInfo);
|
||||
|
||||
StreamInfo queryPlayByStreamId(String steamId);
|
||||
|
||||
StreamInfo queryPlayByDevice(String deviceId, String channelId);
|
||||
|
||||
Map<String, StreamInfo> queryPlayByDeviceId(String deviceId);
|
||||
|
||||
boolean startPlayback(StreamInfo stream, String callId);
|
||||
|
||||
boolean stopPlayback(String deviceId, String channelId, String stream, String callId);
|
||||
|
||||
StreamInfo queryPlayback(String deviceId, String channelID, String stream, String callId);
|
||||
|
||||
String queryPlaybackForKey(String deviceId, String channelId, String stream, String callId);
|
||||
|
||||
void updatePlatformCatchInfo(ParentPlatformCatch parentPlatformCatch);
|
||||
|
||||
ParentPlatformCatch queryPlatformCatchInfo(String platformGbId);
|
||||
@ -75,8 +41,6 @@ public interface IRedisCatchStorage {
|
||||
|
||||
void delPlatformRegisterInfo(String callId);
|
||||
|
||||
void cleanPlatformRegisterInfos();
|
||||
|
||||
void updateSendRTPSever(SendRtpItem sendRtpItem);
|
||||
|
||||
/**
|
||||
@ -102,12 +66,6 @@ public interface IRedisCatchStorage {
|
||||
*/
|
||||
boolean isChannelSendingRTP(String channelId);
|
||||
|
||||
/**
|
||||
* 清空某个设备的所有缓存
|
||||
* @param deviceId 设备ID
|
||||
*/
|
||||
void clearCatchByDeviceId(String deviceId);
|
||||
|
||||
/**
|
||||
* 在redis添加wvp的信息
|
||||
*/
|
||||
@ -148,23 +106,6 @@ public interface IRedisCatchStorage {
|
||||
*/
|
||||
void removeStream(String mediaServerId, String type);
|
||||
|
||||
/**
|
||||
* 开始下载录像时存入
|
||||
* @param streamInfo
|
||||
*/
|
||||
boolean startDownload(StreamInfo streamInfo, String callId);
|
||||
|
||||
StreamInfo queryDownload(String deviceId, String channelId, String stream, String callId);
|
||||
|
||||
boolean stopDownload(String deviceId, String channelId, String stream, String callId);
|
||||
|
||||
/**
|
||||
* 查找第三方系统留下的国标预设值
|
||||
* @param queryKey
|
||||
* @return
|
||||
*/
|
||||
ThirdPartyGB queryMemberNoGBId(String queryKey);
|
||||
|
||||
List<OnStreamChangedHookParam> getStreams(String mediaServerId, String pull);
|
||||
|
||||
/**
|
||||
|
@ -2,17 +2,18 @@ package com.genersoft.iot.vmp.storager.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.common.SystemAllInfo;
|
||||
import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.AlarmChannelMessage;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam;
|
||||
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
|
||||
import com.genersoft.iot.vmp.service.bean.MessageForPushChannel;
|
||||
import com.genersoft.iot.vmp.service.bean.ThirdPartyGB;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
|
||||
import com.genersoft.iot.vmp.storager.dao.dto.PlatformRegisterInfo;
|
||||
@ -92,241 +93,6 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始播放时将流存入redis
|
||||
*/
|
||||
@Override
|
||||
public boolean startPlay(StreamInfo stream) {
|
||||
|
||||
redisTemplate.opsForValue().set(String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(),
|
||||
stream.getMediaServerId(), stream.getStream(), stream.getDeviceID(), stream.getChannelId()),
|
||||
stream);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止播放时从redis删除
|
||||
*/
|
||||
@Override
|
||||
public boolean stopPlay(StreamInfo streamInfo) {
|
||||
if (streamInfo == null) {
|
||||
return false;
|
||||
}
|
||||
Boolean result = redisTemplate.delete(String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
|
||||
userSetting.getServerId(),
|
||||
streamInfo.getMediaServerId(),
|
||||
streamInfo.getStream(),
|
||||
streamInfo.getDeviceID(),
|
||||
streamInfo.getChannelId()));
|
||||
return result != null && result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询播放列表
|
||||
*/
|
||||
@Override
|
||||
public StreamInfo queryPlay(StreamInfo streamInfo) {
|
||||
return (StreamInfo)redisTemplate.opsForValue().get(String.format("%S_%s_%s_%s_%s_%s",
|
||||
VideoManagerConstants.PLAYER_PREFIX,
|
||||
userSetting.getServerId(),
|
||||
streamInfo.getMediaServerId(),
|
||||
streamInfo.getStream(),
|
||||
streamInfo.getDeviceID(),
|
||||
streamInfo.getChannelId()));
|
||||
}
|
||||
@Override
|
||||
public StreamInfo queryPlayByStreamId(String streamId) {
|
||||
List<Object> playLeys = RedisUtil.scan(redisTemplate, String.format("%S_%s_*_%s_*", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(), streamId));
|
||||
if (playLeys.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
return (StreamInfo)redisTemplate.opsForValue().get(playLeys.get(0).toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamInfo queryPlayByDevice(String deviceId, String channelId) {
|
||||
List<Object> playLeys = RedisUtil.scan(redisTemplate, String.format("%S_%s_*_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
|
||||
userSetting.getServerId(),
|
||||
deviceId,
|
||||
channelId));
|
||||
if (playLeys.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
return (StreamInfo)redisTemplate.opsForValue().get(playLeys.get(0).toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, StreamInfo> queryPlayByDeviceId(String deviceId) {
|
||||
Map<String, StreamInfo> streamInfos = new HashMap<>();
|
||||
List<Object> players = RedisUtil.scan(redisTemplate, String.format("%S_%s_*_*_%s_*", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(),deviceId));
|
||||
if (players.size() == 0) {
|
||||
return streamInfos;
|
||||
}
|
||||
for (Object player : players) {
|
||||
String key = (String) player;
|
||||
StreamInfo streamInfo = JsonUtil.redisJsonToObject(redisTemplate, key, StreamInfo.class);
|
||||
if (Objects.isNull(streamInfo)) {
|
||||
continue;
|
||||
}
|
||||
streamInfos.put(streamInfo.getDeviceID() + "_" + streamInfo.getChannelId(), streamInfo);
|
||||
}
|
||||
return streamInfos;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean startPlayback(StreamInfo stream, String callId) {
|
||||
redisTemplate.opsForValue().set(String.format("%S_%s_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
|
||||
userSetting.getServerId(), stream.getMediaServerId(), stream.getDeviceID(), stream.getChannelId(), stream.getStream(), callId), stream);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startDownload(StreamInfo stream, String callId) {
|
||||
String key=String.format("%S_%s_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
|
||||
userSetting.getServerId(), stream.getMediaServerId(), stream.getDeviceID(), stream.getChannelId(), stream.getStream(), callId);
|
||||
if (stream.getProgress() == 1) {
|
||||
logger.debug("添加下载缓存==已完成下载=》{}",key);
|
||||
redisTemplate.opsForValue().set(key, stream);
|
||||
}else {
|
||||
logger.debug("添加下载缓存==未完成下载=》{}",key);
|
||||
Duration duration = Duration.ofSeconds(60*60L);
|
||||
redisTemplate.opsForValue().set(key, stream, duration);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean stopDownload(String deviceId, String channelId, String stream, String callId) {
|
||||
DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(deviceId, channelId);
|
||||
if (deviceChannel != null) {
|
||||
deviceChannel.setStreamId(null);
|
||||
deviceChannel.setDeviceId(deviceId);
|
||||
deviceChannelMapper.update(deviceChannel);
|
||||
}
|
||||
if (deviceId == null) {
|
||||
deviceId = "*";
|
||||
}
|
||||
if (channelId == null) {
|
||||
channelId = "*";
|
||||
}
|
||||
if (stream == null) {
|
||||
stream = "*";
|
||||
}
|
||||
if (callId == null) {
|
||||
callId = "*";
|
||||
}
|
||||
String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
|
||||
userSetting.getServerId(),
|
||||
deviceId,
|
||||
channelId,
|
||||
stream,
|
||||
callId
|
||||
);
|
||||
List<Object> scan = RedisUtil.scan(redisTemplate, key);
|
||||
if (scan.size() > 0) {
|
||||
for (Object keyObj : scan) {
|
||||
redisTemplate.delete(keyObj);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stopPlayback(String deviceId, String channelId, String stream, String callId) {
|
||||
DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(deviceId, channelId);
|
||||
if (deviceChannel != null) {
|
||||
deviceChannel.setStreamId(null);
|
||||
deviceChannel.setDeviceId(deviceId);
|
||||
deviceChannelMapper.update(deviceChannel);
|
||||
}
|
||||
if (deviceId == null) {
|
||||
deviceId = "*";
|
||||
}
|
||||
if (channelId == null) {
|
||||
channelId = "*";
|
||||
}
|
||||
if (stream == null) {
|
||||
stream = "*";
|
||||
}
|
||||
if (callId == null) {
|
||||
callId = "*";
|
||||
}
|
||||
String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
|
||||
userSetting.getServerId(),
|
||||
deviceId,
|
||||
channelId,
|
||||
stream,
|
||||
callId
|
||||
);
|
||||
List<Object> scan = RedisUtil.scan(redisTemplate, key);
|
||||
if (scan.size() > 0) {
|
||||
for (Object keyObj : scan) {
|
||||
redisTemplate.delete(keyObj);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamInfo queryPlayback(String deviceId, String channelId, String stream, String callId) {
|
||||
if (stream == null && callId == null) {
|
||||
return null;
|
||||
}
|
||||
if (deviceId == null) {
|
||||
deviceId = "*";
|
||||
}
|
||||
if (channelId == null) {
|
||||
channelId = "*";
|
||||
}
|
||||
if (stream == null) {
|
||||
stream = "*";
|
||||
}
|
||||
if (callId == null) {
|
||||
callId = "*";
|
||||
}
|
||||
String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
|
||||
userSetting.getServerId(),
|
||||
deviceId,
|
||||
channelId,
|
||||
stream,
|
||||
callId
|
||||
);
|
||||
List<Object> streamInfoScan = RedisUtil.scan(redisTemplate, key);
|
||||
if (streamInfoScan.size() > 0) {
|
||||
return (StreamInfo) redisTemplate.opsForValue().get(streamInfoScan.get(0));
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String queryPlaybackForKey(String deviceId, String channelId, String stream, String callId) {
|
||||
if (stream == null && callId == null) {
|
||||
return null;
|
||||
}
|
||||
if (deviceId == null) {
|
||||
deviceId = "*";
|
||||
}
|
||||
if (channelId == null) {
|
||||
channelId = "*";
|
||||
}
|
||||
if (stream == null) {
|
||||
stream = "*";
|
||||
}
|
||||
if (callId == null) {
|
||||
callId = "*";
|
||||
}
|
||||
String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
|
||||
userSetting.getServerId(),
|
||||
deviceId,
|
||||
channelId,
|
||||
stream,
|
||||
callId
|
||||
);
|
||||
List<Object> streamInfoScan = RedisUtil.scan(redisTemplate, key);
|
||||
return (String) streamInfoScan.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePlatformCatchInfo(ParentPlatformCatch parentPlatformCatch) {
|
||||
String key = VideoManagerConstants.PLATFORM_CATCH_PREFIX + userSetting.getServerId() + "_" + parentPlatformCatch.getId();
|
||||
@ -372,14 +138,6 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||
redisTemplate.delete(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetting.getServerId() + "_" + callId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanPlatformRegisterInfos() {
|
||||
List regInfos = RedisUtil.scan(redisTemplate, VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetting.getServerId() + "_" + "*");
|
||||
for (Object key : regInfos) {
|
||||
redisTemplate.delete(key.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSendRTPSever(SendRtpItem sendRtpItem) {
|
||||
|
||||
@ -536,36 +294,6 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||
return RtpStreams.size() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCatchByDeviceId(String deviceId) {
|
||||
List<Object> playLeys = RedisUtil.scan(redisTemplate, String.format("%S_%s_*_%s_*", VideoManagerConstants.PLAYER_PREFIX,
|
||||
userSetting.getServerId(),
|
||||
deviceId));
|
||||
if (playLeys.size() > 0) {
|
||||
for (Object key : playLeys) {
|
||||
redisTemplate.delete(key.toString());
|
||||
}
|
||||
}
|
||||
|
||||
List<Object> playBackers = RedisUtil.scan(redisTemplate, String.format("%S_%s_*_%s_*_*_*", VideoManagerConstants.PLAY_BLACK_PREFIX,
|
||||
userSetting.getServerId(),
|
||||
deviceId));
|
||||
if (playBackers.size() > 0) {
|
||||
for (Object key : playBackers) {
|
||||
redisTemplate.delete(key.toString());
|
||||
}
|
||||
}
|
||||
|
||||
List<Object> deviceCache = RedisUtil.scan(redisTemplate, String.format("%S%s_%s", VideoManagerConstants.DEVICE_PREFIX,
|
||||
userSetting.getServerId(),
|
||||
deviceId));
|
||||
if (deviceCache.size() > 0) {
|
||||
for (Object key : deviceCache) {
|
||||
redisTemplate.delete(key.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWVPInfo(JSONObject jsonObject, int time) {
|
||||
String key = VideoManagerConstants.WVP_SERVER_PREFIX + userSetting.getServerId();
|
||||
@ -597,44 +325,6 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||
redisTemplate.delete(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamInfo queryDownload(String deviceId, String channelId, String stream, String callId) {
|
||||
if (stream == null && callId == null) {
|
||||
return null;
|
||||
}
|
||||
if (deviceId == null) {
|
||||
deviceId = "*";
|
||||
}
|
||||
if (channelId == null) {
|
||||
channelId = "*";
|
||||
}
|
||||
if (stream == null) {
|
||||
stream = "*";
|
||||
}
|
||||
if (callId == null) {
|
||||
callId = "*";
|
||||
}
|
||||
String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
|
||||
userSetting.getServerId(),
|
||||
deviceId,
|
||||
channelId,
|
||||
stream,
|
||||
callId
|
||||
);
|
||||
List<Object> streamInfoScan = RedisUtil.scan(redisTemplate, key);
|
||||
if (streamInfoScan.size() > 0) {
|
||||
return (StreamInfo) redisTemplate.opsForValue().get(streamInfoScan.get(0));
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThirdPartyGB queryMemberNoGBId(String queryKey) {
|
||||
String key = VideoManagerConstants.WVP_STREAM_GB_ID_PREFIX + queryKey;
|
||||
return JsonUtil.redisJsonToObject(redisTemplate, key, ThirdPartyGB.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeStream(String mediaServerId, String type) {
|
||||
String key = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetting.getServerId() + "_" + type + "_*_*_" + mediaServerId;
|
||||
|
@ -14,6 +14,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.service.IDeviceChannelService;
|
||||
import com.genersoft.iot.vmp.service.IDeviceService;
|
||||
import com.genersoft.iot.vmp.service.IInviteStreamService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.BaseTree;
|
||||
@ -62,6 +63,9 @@ public class DeviceQuery {
|
||||
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private IInviteStreamService inviteStreamService;
|
||||
|
||||
@Autowired
|
||||
private SIPCommander cmder;
|
||||
@ -184,7 +188,7 @@ public class DeviceQuery {
|
||||
// 清除redis记录
|
||||
boolean isSuccess = deviceService.delete(deviceId);
|
||||
if (isSuccess) {
|
||||
redisCatchStorage.clearCatchByDeviceId(deviceId);
|
||||
inviteStreamService.clearInviteInfo(deviceId);
|
||||
// 停止此设备的订阅更新
|
||||
Set<String> allKeys = dynamicTask.getAllKeys();
|
||||
for (String key : allKeys) {
|
||||
|
@ -2,6 +2,9 @@ package com.genersoft.iot.vmp.vmanager.gb28181.play;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.InviteInfo;
|
||||
import com.genersoft.iot.vmp.common.InviteSessionStatus;
|
||||
import com.genersoft.iot.vmp.common.InviteSessionType;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
@ -14,12 +17,13 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.service.IInviteStreamService;
|
||||
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.InviteErrorCode;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.DeferredResultEx;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
@ -59,6 +63,9 @@ public class PlayController {
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private IInviteStreamService inviteStreamService;
|
||||
|
||||
@Autowired
|
||||
private ZLMRESTfulUtils zlmresTfulUtils;
|
||||
|
||||
@ -88,14 +95,12 @@ public class PlayController {
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device);
|
||||
|
||||
RequestMessage msg = new RequestMessage();
|
||||
RequestMessage requestMessage = new RequestMessage();
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId;
|
||||
boolean exist = resultHolder.exist(key, null);
|
||||
msg.setKey(key);
|
||||
requestMessage.setKey(key);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
msg.setId(uuid);
|
||||
requestMessage.setId(uuid);
|
||||
DeferredResult<WVPResult<StreamContent>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue());
|
||||
DeferredResultEx<WVPResult<StreamContent>> deferredResultEx = new DeferredResultEx<>(result);
|
||||
|
||||
result.onTimeout(()->{
|
||||
logger.info("点播接口等待超时");
|
||||
@ -103,32 +108,33 @@ public class PlayController {
|
||||
WVPResult<StreamInfo> wvpResult = new WVPResult<>();
|
||||
wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
||||
wvpResult.setMsg("点播超时");
|
||||
msg.setData(wvpResult);
|
||||
resultHolder.invokeResult(msg);
|
||||
requestMessage.setData(wvpResult);
|
||||
resultHolder.invokeResult(requestMessage);
|
||||
});
|
||||
// TODO 在点播未成功的情况下在此调用接口点播会导致返回的流地址ip错误
|
||||
deferredResultEx.setFilter(result1 -> {
|
||||
WVPResult<StreamInfo> wvpResult1 = (WVPResult<StreamInfo>)result1;
|
||||
WVPResult<StreamContent> resultStream = new WVPResult<>();
|
||||
resultStream.setCode(wvpResult1.getCode());
|
||||
resultStream.setMsg(wvpResult1.getMsg());
|
||||
if (wvpResult1.getCode() == ErrorCode.SUCCESS.getCode()) {
|
||||
StreamInfo data = wvpResult1.getData().clone();
|
||||
if (userSetting.getUseSourceIpAsStreamIp()) {
|
||||
data.channgeStreamIp(request.getLocalName());
|
||||
}
|
||||
resultStream.setData(new StreamContent(wvpResult1.getData()));
|
||||
}
|
||||
return resultStream;
|
||||
});
|
||||
|
||||
|
||||
// 录像查询以channelId作为deviceId查询
|
||||
resultHolder.put(key, uuid, deferredResultEx);
|
||||
resultHolder.put(key, uuid, result);
|
||||
|
||||
if (!exist) {
|
||||
playService.play(newMediaServerItem, deviceId, channelId, null, null, null);
|
||||
}
|
||||
playService.play(newMediaServerItem, deviceId, channelId, (code, msg, data) -> {
|
||||
WVPResult<StreamContent> wvpResult = new WVPResult<>();
|
||||
if (code == InviteErrorCode.SUCCESS.getCode()) {
|
||||
wvpResult.setCode(ErrorCode.SUCCESS.getCode());
|
||||
wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
|
||||
|
||||
if (data != null) {
|
||||
StreamInfo streamInfo = (StreamInfo)data;
|
||||
if (userSetting.getUseSourceIpAsStreamIp()) {
|
||||
streamInfo.channgeStreamIp(request.getLocalName());
|
||||
}
|
||||
wvpResult.setData(new StreamContent(streamInfo));
|
||||
}
|
||||
}else {
|
||||
wvpResult.setCode(code);
|
||||
wvpResult.setMsg(msg);
|
||||
}
|
||||
requestMessage.setData(wvpResult);
|
||||
resultHolder.invokeResult(requestMessage);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -149,21 +155,22 @@ public class PlayController {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备[" + deviceId + "]不存在");
|
||||
}
|
||||
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
|
||||
if (streamInfo == null) {
|
||||
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
|
||||
if (inviteInfo == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "点播未找到");
|
||||
}
|
||||
|
||||
try {
|
||||
logger.warn("[停止点播] {}/{}", device.getDeviceId(), channelId);
|
||||
cmder.streamByeCmd(device, channelId, streamInfo.getStream(), null, null);
|
||||
} catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) {
|
||||
logger.error("[命令发送失败] 停止点播, 发送BYE: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
if (InviteSessionStatus.ok == inviteInfo.getStatus()) {
|
||||
try {
|
||||
logger.warn("[停止点播] {}/{}", device.getDeviceId(), channelId);
|
||||
cmder.streamByeCmd(device, channelId, inviteInfo.getStream(), null, null);
|
||||
} catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) {
|
||||
logger.error("[命令发送失败] 停止点播, 发送BYE: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
redisCatchStorage.stopPlay(streamInfo);
|
||||
inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
|
||||
|
||||
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
|
||||
storager.stopPlay(deviceId, channelId);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("deviceId", deviceId);
|
||||
json.put("channelId", channelId);
|
||||
@ -178,15 +185,14 @@ public class PlayController {
|
||||
@Parameter(name = "streamId", description = "视频流ID", required = true)
|
||||
@PostMapping("/convert/{streamId}")
|
||||
public JSONObject playConvert(@PathVariable String streamId) {
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
|
||||
if (streamInfo == null) {
|
||||
streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
|
||||
}
|
||||
if (streamInfo == null) {
|
||||
// StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
|
||||
|
||||
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(null, streamId);
|
||||
if (inviteInfo == null || inviteInfo.getStreamInfo() == null) {
|
||||
logger.warn("视频转码API调用失败!, 视频流已经停止!");
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到视频流信息, 视频流可能已经停止");
|
||||
}
|
||||
MediaServerItem mediaInfo = mediaServerService.getOne(streamInfo.getMediaServerId());
|
||||
MediaServerItem mediaInfo = mediaServerService.getOne(inviteInfo.getStreamInfo().getMediaServerId());
|
||||
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaInfo, streamId);
|
||||
if (!rtpInfo.getBoolean("exist")) {
|
||||
logger.warn("视频转码API调用失败!, 视频流已停止推流!");
|
||||
|
@ -1,15 +1,22 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.playback;
|
||||
|
||||
import com.genersoft.iot.vmp.common.InviteInfo;
|
||||
import com.genersoft.iot.vmp.common.InviteSessionType;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.conf.exception.ServiceException;
|
||||
import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.service.IInviteStreamService;
|
||||
import com.genersoft.iot.vmp.service.IPlayService;
|
||||
import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
@ -20,17 +27,13 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.SipException;
|
||||
import java.text.ParseException;
|
||||
@ -59,6 +62,9 @@ public class PlaybackController {
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private IInviteStreamService inviteStreamService;
|
||||
|
||||
@Autowired
|
||||
private IPlayService playService;
|
||||
|
||||
@ -74,8 +80,8 @@ public class PlaybackController {
|
||||
@Parameter(name = "startTime", description = "开始时间", required = true)
|
||||
@Parameter(name = "endTime", description = "结束时间", required = true)
|
||||
@GetMapping("/start/{deviceId}/{channelId}")
|
||||
public DeferredResult<WVPResult<StreamContent>> start(@PathVariable String deviceId, @PathVariable String channelId,
|
||||
String startTime, String endTime) {
|
||||
public DeferredResult<WVPResult<StreamContent>> start(HttpServletRequest request, @PathVariable String deviceId, @PathVariable String channelId,
|
||||
String startTime, String endTime) {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("设备回放 API调用,deviceId:%s ,channelId:%s", deviceId, channelId));
|
||||
@ -86,22 +92,31 @@ public class PlaybackController {
|
||||
DeferredResult<WVPResult<StreamContent>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue());
|
||||
resultHolder.put(key, uuid, result);
|
||||
|
||||
WVPResult<StreamContent> wvpResult = new WVPResult<>();
|
||||
RequestMessage requestMessage = new RequestMessage();
|
||||
requestMessage.setKey(key);
|
||||
requestMessage.setId(uuid);
|
||||
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setKey(key);
|
||||
msg.setId(uuid);
|
||||
playService.playBack(deviceId, channelId, startTime, endTime,
|
||||
(code, msg, data)->{
|
||||
|
||||
playService.playBack(deviceId, channelId, startTime, endTime, null,
|
||||
playBackResult->{
|
||||
wvpResult.setCode(playBackResult.getCode());
|
||||
wvpResult.setMsg(playBackResult.getMsg());
|
||||
if (playBackResult.getCode() == ErrorCode.SUCCESS.getCode()) {
|
||||
StreamInfo streamInfo = (StreamInfo)playBackResult.getData();
|
||||
wvpResult.setData(new StreamContent(streamInfo));
|
||||
WVPResult<StreamContent> wvpResult = new WVPResult<>();
|
||||
if (code == InviteErrorCode.SUCCESS.getCode()) {
|
||||
wvpResult.setCode(ErrorCode.SUCCESS.getCode());
|
||||
wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
|
||||
|
||||
if (data != null) {
|
||||
StreamInfo streamInfo = (StreamInfo)data;
|
||||
if (userSetting.getUseSourceIpAsStreamIp()) {
|
||||
streamInfo.channgeStreamIp(request.getLocalName());
|
||||
}
|
||||
wvpResult.setData(new StreamContent(streamInfo));
|
||||
}
|
||||
}else {
|
||||
wvpResult.setCode(code);
|
||||
wvpResult.setMsg(msg);
|
||||
}
|
||||
msg.setData(wvpResult);
|
||||
resultHolder.invokeResult(msg);
|
||||
requestMessage.setData(wvpResult);
|
||||
resultHolder.invokeResult(requestMessage);
|
||||
});
|
||||
|
||||
return result;
|
||||
@ -169,14 +184,15 @@ public class PlaybackController {
|
||||
@GetMapping("/seek/{streamId}/{seekTime}")
|
||||
public void playSeek(@PathVariable String streamId, @PathVariable long seekTime) {
|
||||
logger.info("playSeek: "+streamId+", "+seekTime);
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
|
||||
if (null == streamInfo) {
|
||||
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(InviteSessionType.PLAYBACK, streamId);
|
||||
|
||||
if (null == inviteInfo || inviteInfo.getStreamInfo() == null) {
|
||||
logger.warn("streamId不存在!");
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "streamId不存在");
|
||||
}
|
||||
Device device = storager.queryVideoDevice(streamInfo.getDeviceID());
|
||||
Device device = storager.queryVideoDevice(inviteInfo.getDeviceId());
|
||||
try {
|
||||
cmder.playSeekCmd(device, streamInfo, seekTime);
|
||||
cmder.playSeekCmd(device, inviteInfo.getStreamInfo(), seekTime);
|
||||
} catch (InvalidArgumentException | ParseException | SipException e) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
|
||||
}
|
||||
@ -188,8 +204,9 @@ public class PlaybackController {
|
||||
@GetMapping("/speed/{streamId}/{speed}")
|
||||
public void playSpeed(@PathVariable String streamId, @PathVariable Double speed) {
|
||||
logger.info("playSpeed: "+streamId+", "+speed);
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
|
||||
if (null == streamInfo) {
|
||||
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(InviteSessionType.PLAYBACK, streamId);
|
||||
|
||||
if (null == inviteInfo || inviteInfo.getStreamInfo() == null) {
|
||||
logger.warn("streamId不存在!");
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "streamId不存在");
|
||||
}
|
||||
@ -197,9 +214,9 @@ public class PlaybackController {
|
||||
logger.warn("不支持的speed: " + speed);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "不支持的speed(0.25 0.5 1、2、4)");
|
||||
}
|
||||
Device device = storager.queryVideoDevice(streamInfo.getDeviceID());
|
||||
Device device = storager.queryVideoDevice(inviteInfo.getDeviceId());
|
||||
try {
|
||||
cmder.playSpeedCmd(device, streamInfo, speed);
|
||||
cmder.playSpeedCmd(device, inviteInfo.getStreamInfo(), speed);
|
||||
} catch (InvalidArgumentException | ParseException | SipException e) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.record;
|
||||
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
@ -10,6 +11,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.service.IDeviceService;
|
||||
import com.genersoft.iot.vmp.service.IPlayService;
|
||||
import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
@ -27,6 +29,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.SipException;
|
||||
import java.text.ParseException;
|
||||
@ -55,8 +58,8 @@ public class GBRecordController {
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
private UserSetting userSetting;
|
||||
|
||||
@Operation(summary = "录像查询")
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@ -119,8 +122,8 @@ public class GBRecordController {
|
||||
@Parameter(name = "endTime", description = "结束时间", required = true)
|
||||
@Parameter(name = "downloadSpeed", description = "下载倍速", required = true)
|
||||
@GetMapping("/download/start/{deviceId}/{channelId}")
|
||||
public DeferredResult<WVPResult<StreamContent>> download(@PathVariable String deviceId, @PathVariable String channelId,
|
||||
String startTime, String endTime, String downloadSpeed) {
|
||||
public DeferredResult<WVPResult<StreamContent>> download(HttpServletRequest request, @PathVariable String deviceId, @PathVariable String channelId,
|
||||
String startTime, String endTime, String downloadSpeed) {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("历史媒体下载 API调用,deviceId:%s,channelId:%s,downloadSpeed:%s", deviceId, channelId, downloadSpeed));
|
||||
@ -130,22 +133,32 @@ public class GBRecordController {
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_DOWNLOAD + deviceId + channelId;
|
||||
DeferredResult<WVPResult<StreamContent>> result = new DeferredResult<>(30000L);
|
||||
resultHolder.put(key, uuid, result);
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
RequestMessage requestMessage = new RequestMessage();
|
||||
requestMessage.setId(uuid);
|
||||
requestMessage.setKey(key);
|
||||
|
||||
WVPResult<StreamContent> wvpResult = new WVPResult<>();
|
||||
|
||||
playService.download(deviceId, channelId, startTime, endTime, Integer.parseInt(downloadSpeed), null, playBackResult->{
|
||||
playService.download(deviceId, channelId, startTime, endTime, Integer.parseInt(downloadSpeed),
|
||||
(code, msg, data)->{
|
||||
|
||||
wvpResult.setCode(playBackResult.getCode());
|
||||
wvpResult.setMsg(playBackResult.getMsg());
|
||||
if (playBackResult.getCode() == ErrorCode.SUCCESS.getCode()) {
|
||||
StreamInfo streamInfo = (StreamInfo)playBackResult.getData();
|
||||
wvpResult.setData(new StreamContent(streamInfo));
|
||||
WVPResult<StreamContent> wvpResult = new WVPResult<>();
|
||||
if (code == InviteErrorCode.SUCCESS.getCode()) {
|
||||
wvpResult.setCode(ErrorCode.SUCCESS.getCode());
|
||||
wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
|
||||
|
||||
if (data != null) {
|
||||
StreamInfo streamInfo = (StreamInfo)data;
|
||||
if (userSetting.getUseSourceIpAsStreamIp()) {
|
||||
streamInfo.channgeStreamIp(request.getLocalName());
|
||||
}
|
||||
wvpResult.setData(new StreamContent(streamInfo));
|
||||
}
|
||||
}else {
|
||||
wvpResult.setCode(code);
|
||||
wvpResult.setMsg(msg);
|
||||
}
|
||||
msg.setData(wvpResult);
|
||||
resultHolder.invokeResult(msg);
|
||||
requestMessage.setData(wvpResult);
|
||||
resultHolder.invokeResult(requestMessage);
|
||||
});
|
||||
|
||||
return result;
|
||||
|
@ -1,7 +1,8 @@
|
||||
package com.genersoft.iot.vmp.web.gb28181;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.common.InviteInfo;
|
||||
import com.genersoft.iot.vmp.common.InviteSessionType;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
@ -9,13 +10,18 @@ import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.service.IDeviceService;
|
||||
import com.genersoft.iot.vmp.service.IInviteStreamService;
|
||||
import com.genersoft.iot.vmp.service.IPlayService;
|
||||
import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
@ -45,6 +51,9 @@ public class ApiStreamController {
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private IInviteStreamService inviteStreamService;
|
||||
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
@ -111,46 +120,53 @@ public class ApiStreamController {
|
||||
return resultDeferredResult;
|
||||
}
|
||||
MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device);
|
||||
playService.play(newMediaServerItem, serial, code, (mediaServerItem, response)->{
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(serial, code);
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("StreamID", streamInfo.getStream());
|
||||
result.put("DeviceID", device.getDeviceId());
|
||||
result.put("ChannelID", code);
|
||||
result.put("ChannelName", deviceChannel.getName());
|
||||
result.put("ChannelCustomName", "");
|
||||
result.put("FLV", streamInfo.getFlv().getUrl());
|
||||
result.put("WS_FLV", streamInfo.getWs_flv().getUrl());
|
||||
result.put("RTMP", streamInfo.getRtmp().getUrl());
|
||||
result.put("HLS", streamInfo.getHls().getUrl());
|
||||
result.put("RTSP", streamInfo.getRtsp().getUrl());
|
||||
result.put("WEBRTC", streamInfo.getRtc().getUrl());
|
||||
result.put("CDN", "");
|
||||
result.put("SnapURL", "");
|
||||
result.put("Transport", device.getTransport());
|
||||
result.put("StartAt", "");
|
||||
result.put("Duration", "");
|
||||
result.put("SourceVideoCodecName", "");
|
||||
result.put("SourceVideoWidth", "");
|
||||
result.put("SourceVideoHeight", "");
|
||||
result.put("SourceVideoFrameRate", "");
|
||||
result.put("SourceAudioCodecName", "");
|
||||
result.put("SourceAudioSampleRate", "");
|
||||
result.put("AudioEnable", "");
|
||||
result.put("Ondemand", "");
|
||||
result.put("InBytes", "");
|
||||
result.put("InBitRate", "");
|
||||
result.put("OutBytes", "");
|
||||
result.put("NumOutputs", "");
|
||||
result.put("CascadeSize", "");
|
||||
result.put("RelaySize", "");
|
||||
result.put("ChannelPTZType", "0");
|
||||
resultDeferredResult.setResult(result);
|
||||
}, (eventResult) -> {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("error", "channel[ " + code + " ] " + eventResult.msg);
|
||||
resultDeferredResult.setResult(result);
|
||||
}, null);
|
||||
|
||||
|
||||
playService.play(newMediaServerItem, serial, code, (errorCode, msg, data) -> {
|
||||
if (errorCode == InviteErrorCode.SUCCESS.getCode()) {
|
||||
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, serial, code);
|
||||
if (inviteInfo != null && inviteInfo.getStreamInfo() != null) {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("StreamID", inviteInfo.getStreamInfo().getStream());
|
||||
result.put("DeviceID", device.getDeviceId());
|
||||
result.put("ChannelID", code);
|
||||
result.put("ChannelName", deviceChannel.getName());
|
||||
result.put("ChannelCustomName", "");
|
||||
result.put("FLV", inviteInfo.getStreamInfo().getFlv().getUrl());
|
||||
result.put("WS_FLV", inviteInfo.getStreamInfo().getWs_flv().getUrl());
|
||||
result.put("RTMP", inviteInfo.getStreamInfo().getRtmp().getUrl());
|
||||
result.put("HLS", inviteInfo.getStreamInfo().getHls().getUrl());
|
||||
result.put("RTSP", inviteInfo.getStreamInfo().getRtsp().getUrl());
|
||||
result.put("WEBRTC", inviteInfo.getStreamInfo().getRtc().getUrl());
|
||||
result.put("CDN", "");
|
||||
result.put("SnapURL", "");
|
||||
result.put("Transport", device.getTransport());
|
||||
result.put("StartAt", "");
|
||||
result.put("Duration", "");
|
||||
result.put("SourceVideoCodecName", "");
|
||||
result.put("SourceVideoWidth", "");
|
||||
result.put("SourceVideoHeight", "");
|
||||
result.put("SourceVideoFrameRate", "");
|
||||
result.put("SourceAudioCodecName", "");
|
||||
result.put("SourceAudioSampleRate", "");
|
||||
result.put("AudioEnable", "");
|
||||
result.put("Ondemand", "");
|
||||
result.put("InBytes", "");
|
||||
result.put("InBitRate", "");
|
||||
result.put("OutBytes", "");
|
||||
result.put("NumOutputs", "");
|
||||
result.put("CascadeSize", "");
|
||||
result.put("RelaySize", "");
|
||||
result.put("ChannelPTZType", "0");
|
||||
resultDeferredResult.setResult(result);
|
||||
}
|
||||
}else {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("error", "channel[ " + code + " ] " + msg);
|
||||
resultDeferredResult.setResult(result);
|
||||
}
|
||||
});
|
||||
|
||||
return resultDeferredResult;
|
||||
}
|
||||
|
||||
@ -171,8 +187,8 @@ public class ApiStreamController {
|
||||
|
||||
){
|
||||
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(serial, code);
|
||||
if (streamInfo == null) {
|
||||
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, serial, code);
|
||||
if (inviteInfo == null) {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("error","未找到流信息");
|
||||
return result;
|
||||
@ -184,14 +200,14 @@ public class ApiStreamController {
|
||||
return result;
|
||||
}
|
||||
try {
|
||||
cmder.streamByeCmd(device, code, streamInfo.getStream(), null);
|
||||
cmder.streamByeCmd(device, code, inviteInfo.getStream(), null);
|
||||
} catch (InvalidArgumentException | ParseException | SipException | SsrcTransactionNotFoundException e) {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("error","发送BYE失败:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
redisCatchStorage.stopPlay(streamInfo);
|
||||
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
|
||||
inviteStreamService.removeInviteInfo(inviteInfo);
|
||||
storager.stopPlay(inviteInfo.getDeviceId(), inviteInfo.getChannelId());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -182,9 +182,11 @@
|
||||
this.playerStyle["height"] = this.winHeight + "px";
|
||||
this.chooseDate = moment().format('YYYY-MM-DD')
|
||||
this.dateChange();
|
||||
window.addEventListener('beforeunload', this.stopPlayRecord)
|
||||
},
|
||||
destroyed() {
|
||||
this.$destroy('recordVideoPlayer');
|
||||
window.removeEventListener('beforeunload', this.stopPlayRecord)
|
||||
},
|
||||
methods: {
|
||||
dateChange(){
|
||||
@ -338,14 +340,18 @@
|
||||
});
|
||||
},
|
||||
stopPlayRecord: function (callback) {
|
||||
this.$refs["recordVideoPlayer"].pause();
|
||||
this.videoUrl = '';
|
||||
this.$axios({
|
||||
method: 'get',
|
||||
url: '/api/playback/stop/' + this.deviceId + "/" + this.channelId + "/" + this.streamId
|
||||
}).then(function (res) {
|
||||
if (callback) callback()
|
||||
});
|
||||
console.log("停止录像回放")
|
||||
if (this.streamId !== "") {
|
||||
this.$refs["recordVideoPlayer"].pause();
|
||||
this.videoUrl = '';
|
||||
this.$axios({
|
||||
method: 'get',
|
||||
url: '/api/playback/stop/' + this.deviceId + "/" + this.channelId + "/" + this.streamId
|
||||
}).then(function (res) {
|
||||
if (callback) callback()
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
getDataWidth(item){
|
||||
let timeForFile = this.getTimeForFile(item);
|
||||
@ -423,8 +429,14 @@
|
||||
return hStr + ":" + mStr + ":" + sStr
|
||||
},
|
||||
goBack(){
|
||||
// 如果正在进行录像回放则,发送停止
|
||||
if (this.streamId !== "") {
|
||||
this.stopPlayRecord(()=> {
|
||||
this.streamId = "";
|
||||
})
|
||||
}
|
||||
window.history.go(-1);
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
@ -7,6 +7,7 @@
|
||||
</el-col>
|
||||
<el-col :span="6" >
|
||||
<el-button icon="el-icon-download" v-if="percentage < 100" size="mini" title="点击下载可将以缓存部分下载到本地" @click="download()">停止缓存并下载</el-button>
|
||||
<el-button icon="el-icon-download" v-if="downloadFile" size="mini" title="点击下载" @click="downloadFileClientEvent()">点击下载</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-dialog>
|
||||
@ -21,7 +22,7 @@ import moment from "moment";
|
||||
export default {
|
||||
name: 'recordDownload',
|
||||
created() {
|
||||
|
||||
window.addEventListener('beforeunload', this.stopDownloadRecord)
|
||||
|
||||
},
|
||||
data() {
|
||||
@ -39,7 +40,8 @@ export default {
|
||||
taskId: null,
|
||||
getProgressRun: false,
|
||||
getProgressForFileRun: false,
|
||||
timer: null
|
||||
timer: null,
|
||||
downloadFile: null,
|
||||
|
||||
};
|
||||
},
|
||||
@ -187,8 +189,9 @@ export default {
|
||||
this.percentage = parseFloat(res.data.data[0].percentage)*100
|
||||
if (res.data.data[0].percentage === '1') {
|
||||
this.getProgressForFileRun = false;
|
||||
window.open(res.data.data[0].downloadFile)
|
||||
this.close();
|
||||
this.downloadFile = res.data.data[0].downloadFile
|
||||
this.title = "文件处理完成,点击按扭下载"
|
||||
// window.open(res.data.data[0].downloadFile)
|
||||
}else {
|
||||
if (callback)callback()
|
||||
}
|
||||
@ -196,7 +199,13 @@ export default {
|
||||
}).catch(function (error) {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
},
|
||||
downloadFileClientEvent: function (){
|
||||
window.open(this.downloadFile )
|
||||
}
|
||||
},
|
||||
destroyed() {
|
||||
window.removeEventListener('beforeunload', this.stopDownloadRecord)
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user