mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-18 00:45:55 +08:00
1.代码更新
This commit is contained in:
@@ -28,35 +28,10 @@ public class PlayerController extends BaseController {
|
||||
public AjaxResult play(@PathVariable String deviceId, @PathVariable String channelId) {
|
||||
return AjaxResult.success("success!", playService.play(deviceId, channelId,false));
|
||||
}
|
||||
@ApiOperation("回放播放")
|
||||
@GetMapping("/playback/{deviceId}/{channelId}")
|
||||
public AjaxResult playback(@PathVariable String deviceId,
|
||||
@PathVariable String channelId, String start, String end) {
|
||||
return AjaxResult.success("success!", playService.playback(deviceId, channelId, start, end));
|
||||
}
|
||||
|
||||
@ApiOperation("停止推流")
|
||||
@GetMapping("/closeStream/{deviceId}/{channelId}/{streamId}")
|
||||
public AjaxResult closeStream(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String streamId) {
|
||||
return AjaxResult.success("success!", playService.closeStream(deviceId, channelId, streamId));
|
||||
}
|
||||
@ApiOperation("回放暂停")
|
||||
@GetMapping("/playbackPause/{deviceId}/{channelId}/{streamId}")
|
||||
public AjaxResult playbackPause(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String streamId) {
|
||||
return AjaxResult.success("success!", playService.playbackPause(deviceId, channelId, streamId));
|
||||
}
|
||||
@ApiOperation("回放恢复")
|
||||
@GetMapping("/playbackReplay/{deviceId}/{channelId}/{streamId}")
|
||||
public AjaxResult playbackReplay(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String streamId) {
|
||||
return AjaxResult.success("success!", playService.playbackReplay(deviceId, channelId, streamId));
|
||||
}
|
||||
@ApiOperation("录像回放定位")
|
||||
@GetMapping("/playbackSeek/{deviceId}/{channelId}/{streamId}")
|
||||
public AjaxResult playbackSeek(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String streamId, long seek) {
|
||||
return AjaxResult.success("success!", playService.playbackSeek(deviceId, channelId, streamId, seek));
|
||||
}
|
||||
@ApiOperation("录像倍速播放")
|
||||
@GetMapping("/playbackSpeed/{deviceId}/{channelId}/{streamId}")
|
||||
public AjaxResult playbackSpeed(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String streamId, Integer speed) {
|
||||
return AjaxResult.success("success!", playService.playbackSpeed(deviceId, channelId, streamId, speed));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.fastbee.sip.server;
|
||||
|
||||
import com.fastbee.sip.domain.SipDevice;
|
||||
|
||||
public interface IRtspCmd {
|
||||
void playPause(SipDevice device, String channelId, String streamId);
|
||||
void playReplay(SipDevice device, String channelId, String streamId);
|
||||
void playBackSeek(SipDevice device, String channelId, String streamId, long seektime);
|
||||
void playBackSpeed(SipDevice device, String channelId, String streamId, Integer speed);
|
||||
void setCseq(String streamId);
|
||||
}
|
||||
@@ -5,8 +5,6 @@ import com.fastbee.sip.model.VideoSessionInfo;
|
||||
|
||||
public interface ISipCmd {
|
||||
VideoSessionInfo playStreamCmd(SipDevice device, String channelId, boolean record);
|
||||
VideoSessionInfo playbackStreamCmd(SipDevice device, String channelId, String startTime, String endTime);
|
||||
VideoSessionInfo downloadStreamCmd(SipDevice device, String channelId, String startTime, String endTime, int downloadSpeed);
|
||||
void streamByeCmd(SipDevice device, String channelId, String stream, String ssrc);
|
||||
void streamByeCmd(String deviceId, String channelId, String stream, String ssrc);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
package com.fastbee.sip.server;
|
||||
|
||||
import com.fastbee.sip.domain.SipDevice;
|
||||
import com.fastbee.sip.server.msg.ConfigDownload;
|
||||
import com.fastbee.sip.server.msg.DeviceControl;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.sip.ClientTransaction;
|
||||
import javax.sip.PeerUnavailableException;
|
||||
import javax.sip.RequestEvent;
|
||||
import javax.sip.message.Request;
|
||||
import java.util.Date;
|
||||
|
||||
public interface MessageInvoker {
|
||||
@@ -59,48 +55,6 @@ public interface MessageInvoker {
|
||||
*/
|
||||
boolean catalogQuery(SipDevice device);
|
||||
|
||||
boolean recordInfoQuery(SipDevice device, String sn, String channelId, Date start, Date end);
|
||||
|
||||
|
||||
/**
|
||||
* 订阅通道目录,发送订阅请求后
|
||||
*
|
||||
* @param device device
|
||||
* @param from 订阅有效期从
|
||||
* @param to 订阅有效期止
|
||||
* @return void
|
||||
*/
|
||||
void subscribeCatalog(SipDevice device, Date from, Date to) throws PeerUnavailableException;
|
||||
|
||||
|
||||
/**
|
||||
* 下载设备配置信息,可指定配置类型,如果未指定类型则获取所有类型的配置
|
||||
*
|
||||
* @param device 设备信息
|
||||
* @param configType 要下载的配置类型
|
||||
* @return 配置信息
|
||||
*/
|
||||
ConfigDownload downloadConfig(SipDevice device, ConfigDownload.ConfigType... configType);
|
||||
SipMessage messageToObj(RequestEvent event);
|
||||
/**
|
||||
* 发送SIP原始请求
|
||||
*
|
||||
* @param device 设备
|
||||
* @param request 原始请求
|
||||
* @param awaitAck 是否等待响应
|
||||
* @return 事务信息
|
||||
*/
|
||||
ClientTransaction request(SipDevice device, Request request, boolean awaitAck);
|
||||
|
||||
/**
|
||||
* 发起一个请求,并等待响应,不同的请求方式以及内容,响应的内容不同。
|
||||
*
|
||||
* @param transaction ClientTransaction
|
||||
* @param request Request
|
||||
* @param awaitAck 是否等待响应
|
||||
* @return 响应结果
|
||||
*/
|
||||
Object request(ClientTransaction transaction, Request request, boolean awaitAck);
|
||||
|
||||
<T> T getExecResult(String key, long timeout);
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package com.fastbee.sip.server;
|
||||
import com.fastbee.sip.domain.SipConfig;
|
||||
import com.fastbee.sip.domain.SipDevice;
|
||||
import com.fastbee.sip.model.InviteInfo;
|
||||
import com.fastbee.sip.model.VideoSessionInfo;
|
||||
import com.fastbee.sip.service.IInviteService;
|
||||
import com.fastbee.sip.service.ISipCacheService;
|
||||
import com.fastbee.sip.util.SipUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -29,64 +27,9 @@ public class ReqMsgHeaderBuilder {
|
||||
@Qualifier(value = "udpSipServer")
|
||||
private SipProvider sipserver;
|
||||
|
||||
@Autowired
|
||||
private VideoSessionManager streamSession;
|
||||
|
||||
@Autowired
|
||||
private ISipCacheService sipCacheService;
|
||||
|
||||
@Autowired
|
||||
private IInviteService inviteService;
|
||||
|
||||
/**
|
||||
* 创建请求消息
|
||||
*
|
||||
* @param device
|
||||
* @param content
|
||||
* @param fromTag
|
||||
* @return
|
||||
* @throws ParseException
|
||||
* @throws InvalidArgumentException
|
||||
* @throws PeerUnavailableException
|
||||
*/
|
||||
public Request createMessageRequest(SipDevice device, SipConfig sipConfig, String content, String fromTag)
|
||||
throws ParseException, InvalidArgumentException, PeerUnavailableException {
|
||||
Request request = null;
|
||||
// sipuri
|
||||
SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceSipId(),
|
||||
device.getHostaddress());
|
||||
// via
|
||||
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
|
||||
ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getIp(),
|
||||
sipConfig.getPort(), device.getTransport(), SipUtil.getNewViaTag());
|
||||
viaHeader.setRPort();
|
||||
viaHeaders.add(viaHeader);
|
||||
// from
|
||||
SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getServerSipid(),
|
||||
sipConfig.getIp() + ":" + sipConfig.getPort());
|
||||
Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
|
||||
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag);
|
||||
// to
|
||||
SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceSipId(),
|
||||
sipConfig.getDomain());
|
||||
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
|
||||
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, SipUtil.getNewTag());
|
||||
// callid
|
||||
CallIdHeader callIdHeader = sipserver.getNewCallId();
|
||||
// Forwards
|
||||
MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
|
||||
// ceq
|
||||
CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(sipCacheService.getCSEQ(sipConfig.getServerSipid()), Request.MESSAGE);
|
||||
|
||||
request = sipFactory.createMessageFactory().createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader,
|
||||
fromHeader, toHeader, viaHeaders, maxForwards);
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION",
|
||||
"MANSCDP+xml");
|
||||
request.setContent(content, contentTypeHeader);
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
public Request createInviteRequest(SipDevice device, SipConfig sipConfig, String channelId, String content, String ssrc, String fromTag) throws ParseException, InvalidArgumentException, PeerUnavailableException {
|
||||
Request request = null;
|
||||
// 请求行
|
||||
@@ -132,49 +75,6 @@ public class ReqMsgHeaderBuilder {
|
||||
return request;
|
||||
}
|
||||
|
||||
public Request createPlaybackInviteRequest(SipDevice device, SipConfig sipConfig, String channelId, String content, String viaTag, String fromTag) throws ParseException, InvalidArgumentException, PeerUnavailableException {
|
||||
Request request = null;
|
||||
// 请求行
|
||||
SipURI requestLine = sipFactory.createAddressFactory().createSipURI(channelId,
|
||||
device.getHostaddress());
|
||||
// via
|
||||
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
|
||||
ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(device.getIp(), device.getPort(),
|
||||
device.getTransport(), viaTag);
|
||||
viaHeader.setRPort();
|
||||
viaHeaders.add(viaHeader);
|
||||
// from
|
||||
SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getServerSipid(),
|
||||
sipConfig.getDomain());
|
||||
Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
|
||||
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); // 必须要有标记,否则无法创建会话,无法回应ack
|
||||
// to
|
||||
SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId, device.getHostaddress());
|
||||
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
|
||||
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, null);
|
||||
|
||||
// callid
|
||||
CallIdHeader callIdHeader = sipserver.getNewCallId();
|
||||
|
||||
// Forwards
|
||||
MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
|
||||
|
||||
// ceq
|
||||
CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(sipCacheService.getCSEQ(sipConfig.getServerSipid()), Request.INVITE);
|
||||
request = sipFactory.createMessageFactory().createRequest(requestLine, Request.INVITE, callIdHeader, cSeqHeader,
|
||||
fromHeader, toHeader, viaHeaders, maxForwards);
|
||||
|
||||
Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory()
|
||||
.createSipURI(sipConfig.getServerSipid(), sipConfig.getIp() + ":" + sipConfig.getPort()));
|
||||
|
||||
request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
|
||||
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION",
|
||||
"SDP");
|
||||
request.setContent(content, contentTypeHeader);
|
||||
return request;
|
||||
}
|
||||
|
||||
public Request createByeRequest(SipDevice device, SipConfig sipConfig, String channelId, InviteInfo invite) throws ParseException, InvalidArgumentException, PeerUnavailableException {
|
||||
Request request = null;
|
||||
//请求行
|
||||
@@ -205,63 +105,4 @@ public class ReqMsgHeaderBuilder {
|
||||
request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
|
||||
return request;
|
||||
}
|
||||
|
||||
public Request createRtspRequest(SipDevice device, SipConfig sipConfig, String channelId, String streamId, String content)
|
||||
throws PeerUnavailableException, ParseException, InvalidArgumentException {
|
||||
Request request = null;
|
||||
VideoSessionInfo info = streamSession.getSessionInfo(device.getDeviceSipId(), channelId, streamId, null);
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
Dialog dialog = streamSession.getclientTransaction(info).getDialog();
|
||||
if (dialog == null) {
|
||||
return null;
|
||||
}
|
||||
InviteInfo invite = inviteService.getInviteInfoBySSRC(info.getSsrc());
|
||||
if (invite == null) {
|
||||
return null;
|
||||
}
|
||||
// 请求行
|
||||
SipURI requestLine = sipFactory.createAddressFactory().createSipURI(channelId, device.getHostaddress());
|
||||
// via
|
||||
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
|
||||
ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(getLocalIp(sipConfig.getIp()), sipConfig.getPort(),
|
||||
device.getTransport(), invite.getViaTag());
|
||||
viaHeader.setRPort();
|
||||
viaHeaders.add(viaHeader);
|
||||
// from
|
||||
SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getServerSipid(),
|
||||
sipConfig.getDomain());
|
||||
Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
|
||||
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, invite.getFromTag());
|
||||
// to
|
||||
SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId, device.getHostaddress());
|
||||
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
|
||||
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, dialog.getRemoteTag());
|
||||
// callid
|
||||
CallIdHeader callIdHeader = SipFactory.getInstance().createHeaderFactory().createCallIdHeader(invite.getCallId());;
|
||||
// Forwards
|
||||
MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
|
||||
// ceq
|
||||
CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(sipCacheService.getCSEQ(sipConfig.getServerSipid()), Request.INFO);
|
||||
|
||||
request = sipFactory.createMessageFactory().createRequest(requestLine, Request.INFO, callIdHeader, cSeqHeader,
|
||||
fromHeader, toHeader, viaHeaders, maxForwards);
|
||||
|
||||
Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory()
|
||||
.createSipURI(sipConfig.getServerSipid(), sipConfig.getIp() + ":" + sipConfig.getPort()));
|
||||
request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
|
||||
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application",
|
||||
"MANSRTSP");
|
||||
request.setContent(content, contentTypeHeader);
|
||||
return request;
|
||||
}
|
||||
|
||||
public String getLocalIp(String deviceLocalIp) {
|
||||
if (!ObjectUtils.isEmpty(deviceLocalIp)) {
|
||||
return deviceLocalIp;
|
||||
}
|
||||
return sipserver.getListeningPoint().getIPAddress();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.fastbee.sip.server.impl;
|
||||
|
||||
import com.fastbee.common.core.redis.RedisCache;
|
||||
import com.fastbee.sip.domain.SipConfig;
|
||||
import com.fastbee.sip.domain.SipDevice;
|
||||
import com.fastbee.sip.server.MessageInvoker;
|
||||
@@ -28,7 +27,6 @@ import javax.sip.message.Request;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Slf4j
|
||||
@@ -38,10 +36,6 @@ public class MessageInvokerImpl implements MessageInvoker {
|
||||
private SipFactory sipFactory;
|
||||
@Autowired
|
||||
private ISipConfigService sipConfigService;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Autowired
|
||||
@Qualifier(value = "udpSipServer")
|
||||
private SipProvider sipserver;
|
||||
@@ -59,15 +53,6 @@ public class MessageInvokerImpl implements MessageInvoker {
|
||||
createTransaction(requestMethod, bodyBuilder.apply(id), device.getDeviceSipId(), device, viaTag, fromTag, toTag, headers);
|
||||
}
|
||||
|
||||
private void sendRequest(String xml,
|
||||
String requestMethod,
|
||||
SipDevice device,
|
||||
String viaTag,
|
||||
String fromTag,
|
||||
String toTag,
|
||||
Header... headers) {
|
||||
createTransaction(requestMethod, xml, device.getDeviceSipId(), device, viaTag, fromTag, toTag, headers);
|
||||
}
|
||||
@SneakyThrows
|
||||
private ClientTransaction createTransaction(String method,
|
||||
String xml,
|
||||
@@ -175,33 +160,6 @@ public class MessageInvokerImpl implements MessageInvoker {
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void subscribeCatalog(SipDevice device, Date from, Date to) {
|
||||
String fromTimeString = SipUtil.dateToISO8601(from);
|
||||
String toTimeString = SipUtil.dateToISO8601(to);
|
||||
;
|
||||
int expires = (int) ((to.getTime() - from.getTime()) / 1000);
|
||||
|
||||
ExpiresHeader header = sipFactory.createHeaderFactory().createExpiresHeader(expires);
|
||||
this.sendRequest(sn ->
|
||||
"<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n" +
|
||||
"<Query>\r\n" +
|
||||
"<CmdType>Catalog</CmdType>\r\n" +
|
||||
"<SN>" + sn + "</SN>\r\n" +
|
||||
"<DeviceID>" + device.getDeviceSipId() + "</DeviceID>\r\n" +
|
||||
"<StartTime>" + fromTimeString + "</StartTime>\r\n" +
|
||||
"<EndTime>" + toTimeString + "</EndTime>\r\n" +
|
||||
"</Query>\r\n",
|
||||
Request.SUBSCRIBE,
|
||||
device,
|
||||
"ViaSubscribeCatalog",
|
||||
"SubscribeCatalogTag",
|
||||
null,
|
||||
header
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deviceControl(SipDevice device, DeviceControl command) {
|
||||
this.sendRequest(sn -> command.toXml(sn, "GB2312"),
|
||||
@@ -249,69 +207,5 @@ public class MessageInvokerImpl implements MessageInvoker {
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean recordInfoQuery(SipDevice device, String sn, String channelId, Date start, Date end) {
|
||||
String startTimeString = SipUtil.dateToISO8601(start);
|
||||
String endTimeString = SipUtil.dateToISO8601(end);
|
||||
;
|
||||
this.sendRequest("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n" +
|
||||
"<Query>\r\n" +
|
||||
"<CmdType>RecordInfo</CmdType>\r\n" +
|
||||
"<SN>" + sn + "</SN>\r\n" +
|
||||
"<DeviceID>" + channelId + "</DeviceID>\r\n" +
|
||||
"<StartTime>" + startTimeString + "</StartTime>\r\n" +
|
||||
"<EndTime>" + endTimeString + "</EndTime>\r\n" +
|
||||
"<Secrecy>0</Secrecy>\r\n" +
|
||||
"<Type>all</Type>\r\n" +
|
||||
"</Query>\r\n",
|
||||
Request.MESSAGE,
|
||||
device,
|
||||
"ViarecordInfoBranch",
|
||||
"FromrecordInfoTag",
|
||||
null
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigDownload downloadConfig(SipDevice device, ConfigDownload.ConfigType... configType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientTransaction request(SipDevice device, Request request, boolean awaitAck) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object request(ClientTransaction transaction, Request request, boolean awaitAck) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T> T getExecResult(String key, long timeout) {
|
||||
long time = 0;
|
||||
while (true) {
|
||||
try {
|
||||
T instance = redisCache.getCacheObject(key);
|
||||
if (null == instance) {
|
||||
if (time >= timeout) {
|
||||
log.error("key:{} get Response timeout", key);
|
||||
return null;
|
||||
}
|
||||
time += 1000;
|
||||
TimeUnit.MILLISECONDS.sleep(1000L);
|
||||
} else {
|
||||
return instance;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
log.error("key:{} can't get Response", key);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
package com.fastbee.sip.server.impl;
|
||||
|
||||
import com.fastbee.sip.domain.SipConfig;
|
||||
import com.fastbee.sip.domain.SipDevice;
|
||||
import com.fastbee.sip.server.IRtspCmd;
|
||||
import com.fastbee.sip.server.ReqMsgHeaderBuilder;
|
||||
import com.fastbee.sip.service.ISipConfigService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sip.ClientTransaction;
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.SipException;
|
||||
import javax.sip.SipProvider;
|
||||
import javax.sip.message.Request;
|
||||
import java.text.ParseException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class RtspCmdImpl implements IRtspCmd {
|
||||
public static Map<String, Long> CSEQCACHE = new ConcurrentHashMap<>();
|
||||
|
||||
@Autowired
|
||||
private ReqMsgHeaderBuilder headerBuilder;
|
||||
|
||||
@Autowired
|
||||
@Qualifier(value = "udpSipServer")
|
||||
private SipProvider sipserver;
|
||||
|
||||
@Autowired
|
||||
private ISipConfigService sipConfigService;
|
||||
|
||||
public void playPause(SipDevice device, String channelId, String streamId) {
|
||||
try {
|
||||
SipConfig sipConfig = sipConfigService.selectSipConfigBydeviceSipId(device.getDeviceSipId());
|
||||
if (sipConfig == null) {
|
||||
log.error("[playPause] sipConfig is null");
|
||||
return ;
|
||||
}
|
||||
String content = "PAUSE RTSP/1.0\r\n" +
|
||||
"CSeq: " + getInfoCseq() + "\r\n" +
|
||||
"PauseTime: now\r\n";
|
||||
Request request = headerBuilder.createRtspRequest(device, sipConfig, channelId, streamId, content);
|
||||
ClientTransaction clientTransaction = sipserver.getNewClientTransaction(request);
|
||||
clientTransaction.sendRequest();
|
||||
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void playReplay(SipDevice device, String channelId, String streamId) {
|
||||
try {
|
||||
SipConfig sipConfig = sipConfigService.selectSipConfigBydeviceSipId(device.getDeviceSipId());
|
||||
if (sipConfig == null) {
|
||||
log.error("[playReplay] sipConfig is null");
|
||||
return ;
|
||||
}
|
||||
String content = "PLAY RTSP/1.0\r\n" +
|
||||
"CSeq: " + getInfoCseq() + "\r\n" +
|
||||
"Range: npt=now-\r\n";
|
||||
Request request = headerBuilder.createRtspRequest(device, sipConfig, channelId, streamId, content);
|
||||
ClientTransaction clientTransaction = sipserver.getNewClientTransaction(request);
|
||||
clientTransaction.sendRequest();
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void playBackSeek(SipDevice device, String channelId, String streamId, long seektime) {
|
||||
try {
|
||||
SipConfig sipConfig = sipConfigService.selectSipConfigBydeviceSipId(device.getDeviceSipId());
|
||||
if (sipConfig == null) {
|
||||
log.error("[playBackSeek] sipConfig is null");
|
||||
return ;
|
||||
}
|
||||
String content = "PLAY RTSP/1.0\r\n" +
|
||||
"CSeq: " + getInfoCseq() + "\r\n" +
|
||||
"Range: npt=" + Math.abs(seektime) + "-\r\n";
|
||||
Request request = headerBuilder.createRtspRequest(device, sipConfig, channelId, streamId, content);
|
||||
ClientTransaction clientTransaction = sipserver.getNewClientTransaction(request);
|
||||
clientTransaction.sendRequest();
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void playBackSpeed(SipDevice device, String channelId, String streamId, Integer speed) {
|
||||
try {
|
||||
SipConfig sipConfig = sipConfigService.selectSipConfigBydeviceSipId(device.getDeviceSipId());
|
||||
if (sipConfig == null) {
|
||||
log.error("[playBackSpeed] sipConfig is null");
|
||||
return ;
|
||||
}
|
||||
String content = "PLAY RTSP/1.0\r\n" +
|
||||
"CSeq: " + getInfoCseq() + "\r\n" +
|
||||
"Scale: " + speed + ".000000\r\n";
|
||||
Request request = headerBuilder.createRtspRequest(device, sipConfig, channelId, streamId, content);
|
||||
ClientTransaction clientTransaction = sipserver.getNewClientTransaction(request);
|
||||
clientTransaction.sendRequest();
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setCseq(String streamId) {
|
||||
if (CSEQCACHE.containsKey(streamId)) {
|
||||
CSEQCACHE.put(streamId, CSEQCACHE.get(streamId) + 1);
|
||||
} else {
|
||||
CSEQCACHE.put(streamId, 2l);
|
||||
}
|
||||
}
|
||||
|
||||
private int getInfoCseq() {
|
||||
return (int) ((Math.random() * 9 + 1) * Math.pow(10, 8));
|
||||
}
|
||||
}
|
||||
@@ -108,105 +108,6 @@ public class SipCmdImpl implements ISipCmd {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VideoSessionInfo playbackStreamCmd(SipDevice device, String channelId, String startTime, String endTime) {
|
||||
try {
|
||||
SipConfig sipConfig = sipConfigService.selectSipConfigBydeviceSipId(device.getDeviceSipId());
|
||||
if (sipConfig == null) {
|
||||
log.error("playbackStreamCmd sipConfig is null");
|
||||
return null;
|
||||
}
|
||||
MediaServer mediaInfo = mediaServerService.selectMediaServerBydeviceSipId(device.getDeviceSipId());
|
||||
if (mediaInfo == null) {
|
||||
log.error("playbackStreamCmd mediaInfo is null");
|
||||
return null;
|
||||
}
|
||||
VideoSessionInfo info = VideoSessionInfo.builder()
|
||||
.mediaServerId(mediaInfo.getServerId())
|
||||
.deviceId(device.getDeviceSipId())
|
||||
.channelId(channelId)
|
||||
.streamMode(device.getStreammode().toUpperCase())
|
||||
.type(SessionType.playback)
|
||||
.startTime(startTime)
|
||||
.endTime(endTime)
|
||||
.build();
|
||||
//创建rtp服务器
|
||||
info = mediaServerService.createRTPServer(sipConfig, mediaInfo, device, info);
|
||||
//创建Invite会话
|
||||
String fromTag = "playback" + SipUtil.getNewFromTag();
|
||||
String viaTag = SipUtil.getNewViaTag();
|
||||
String content = buildRequestContent(sipConfig, mediaInfo, info);
|
||||
Request request = headerBuilder.createPlaybackInviteRequest(device, sipConfig, channelId, content, viaTag, fromTag);
|
||||
//发送消息
|
||||
ClientTransaction transaction = transmitRequest(request);
|
||||
log.info("playbackStreamCmd streamSession: {}", info);
|
||||
InviteInfo invite = InviteInfo.builder()
|
||||
.ssrc(info.getSsrc())
|
||||
.fromTag(fromTag)
|
||||
.viaTag(viaTag)
|
||||
.callId(transaction.getDialog().getCallId().getCallId())
|
||||
.port(info.getPort()).build();
|
||||
log.warn("playbackStreamCmd invite: {}", invite);
|
||||
inviteService.updateInviteInfo(info, invite);
|
||||
streamSession.put(info, transaction);
|
||||
return info;
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VideoSessionInfo downloadStreamCmd(SipDevice device, String channelId,
|
||||
String startTime, String endTime, int downloadSpeed) {
|
||||
try {
|
||||
SipConfig sipConfig = sipConfigService.selectSipConfigBydeviceSipId(device.getDeviceSipId());
|
||||
if (sipConfig == null) {
|
||||
log.error("downloadStreamCmd sipConfig is null");
|
||||
return null;
|
||||
}
|
||||
MediaServer mediaInfo = mediaServerService.selectMediaServerBydeviceSipId(device.getDeviceSipId());
|
||||
if (mediaInfo == null) {
|
||||
log.error("downloadStreamCmd mediaInfo is null");
|
||||
return null;
|
||||
}
|
||||
VideoSessionInfo info = VideoSessionInfo.builder()
|
||||
.mediaServerId(mediaInfo.getServerId())
|
||||
.deviceId(device.getDeviceSipId())
|
||||
.channelId(channelId)
|
||||
.streamMode(device.getStreammode().toUpperCase())
|
||||
.type(SessionType.download)
|
||||
.startTime(startTime)
|
||||
.endTime(endTime)
|
||||
.downloadSpeed(downloadSpeed)
|
||||
.build();
|
||||
;
|
||||
//创建rtp服务器
|
||||
info = mediaServerService.createRTPServer(sipConfig, mediaInfo, device, info);
|
||||
//创建Invite会话
|
||||
String fromTag = "download" + SipUtil.getNewFromTag();;
|
||||
String viaTag = SipUtil.getNewViaTag();
|
||||
String content = buildRequestContent(sipConfig, mediaInfo, info);
|
||||
Request request = headerBuilder.createPlaybackInviteRequest(device, sipConfig, channelId, content, viaTag, fromTag);
|
||||
//发送消息
|
||||
ClientTransaction transaction = transmitRequest(request);
|
||||
log.info("downloadStreamCmd streamSession: {}", info);
|
||||
InviteInfo invite = InviteInfo.builder()
|
||||
.ssrc(info.getSsrc())
|
||||
.fromTag(fromTag)
|
||||
.viaTag(viaTag)
|
||||
.callId(transaction.getDialog().getCallId().getCallId())
|
||||
.port(info.getPort()).build();
|
||||
log.warn("downloadStreamCmd invite: {}", invite);
|
||||
inviteService.updateInviteInfo(info, invite);
|
||||
streamSession.put(info, transaction);
|
||||
return info;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void streamByeCmd(SipDevice device, String channelId, String stream, String ssrc) {
|
||||
SipConfig sipConfig = sipConfigService.selectSipConfigBydeviceSipId(device.getDeviceSipId());
|
||||
if (sipConfig == null) {
|
||||
@@ -300,26 +201,6 @@ public class SipCmdImpl implements ISipCmd {
|
||||
content.append("c=IN IP4 ").append(mediaInfo.getIp()).append("\r\n");
|
||||
content.append("t=0 0\r\n");
|
||||
break;
|
||||
case playrecord:
|
||||
content.append("o=").append(info.getChannelId()).append(" 0 0 IN IP4 ").append(mediaInfo.getIp()).append("\r\n");
|
||||
content.append("s=Play\r\n");
|
||||
content.append("c=IN IP4 ").append(mediaInfo.getIp()).append("\r\n");
|
||||
content.append("t=0 0\r\n");
|
||||
break;
|
||||
case playback:
|
||||
content.append("o=").append(info.getChannelId()).append(" 0 0 IN IP4 ").append(mediaInfo.getIp()).append("\r\n");
|
||||
content.append("s=Playback\r\n");
|
||||
content.append("u=").append(info.getChannelId()).append(":0\r\n");
|
||||
content.append("c=IN IP4 ").append(mediaInfo.getIp()).append("\r\n");
|
||||
content.append("t=").append(info.getStartTime()).append(" ").append(info.getEndTime()).append("\r\n");
|
||||
break;
|
||||
case download:
|
||||
content.append("o=").append(info.getChannelId()).append(" 0 0 IN IP4 ").append(mediaInfo.getIp()).append("\r\n");
|
||||
content.append("s=Download\r\n");
|
||||
content.append("u=").append(info.getChannelId()).append(":0\r\n");
|
||||
content.append("c=IN IP4 ").append(mediaInfo.getIp()).append("\r\n");
|
||||
content.append("t=").append(info.getStartTime()).append(" ").append(info.getEndTime()).append("\r\n");
|
||||
break;
|
||||
}
|
||||
if (sipConfig.getSeniorsdp() != null && sipConfig.getSeniorsdp() == 1) {
|
||||
if ("TCP-PASSIVE".equals(streamMode)) {
|
||||
|
||||
@@ -3,18 +3,6 @@ package com.fastbee.sip.service;
|
||||
import com.fastbee.sip.model.Stream;
|
||||
|
||||
public interface IPlayService {
|
||||
|
||||
Stream play(String deviceId, String channelId, boolean record);
|
||||
|
||||
Stream playback(String deviceId, String channelId, String startTime, String endTime);
|
||||
|
||||
String closeStream(String deviceId, String channelId, String streamId);
|
||||
|
||||
String playbackPause(String deviceId, String channelId, String streamId);
|
||||
|
||||
String playbackReplay(String deviceId, String channelId, String streamId);
|
||||
|
||||
String playbackSeek(String deviceId, String channelId, String streamId, long seektime);
|
||||
|
||||
String playbackSpeed(String deviceId, String channelId, String streamId, Integer speed);
|
||||
}
|
||||
|
||||
@@ -1,31 +1,8 @@
|
||||
package com.fastbee.sip.service;
|
||||
|
||||
import com.fastbee.sip.model.RecordList;
|
||||
import com.fastbee.sip.model.Stream;
|
||||
import com.fastbee.sip.model.ZlmMediaServer;
|
||||
|
||||
public interface ISipCacheService {
|
||||
Long getCSEQ(String serverSipId);
|
||||
|
||||
void startPlay(Stream stream);
|
||||
|
||||
Stream queryStreamByStreamId(String streamId);
|
||||
|
||||
Stream queryPlayByDevice(String deviceId, String channelId, boolean record);
|
||||
|
||||
void startPlayback(Stream stream);
|
||||
|
||||
Stream queryPlaybackByStreamId(String streamId);
|
||||
Stream queryPlaybackByDevice(String deviceId, String channelId);
|
||||
|
||||
void startDownload(Stream stream);
|
||||
|
||||
Stream queryDownloadByStreamId(String streamId);
|
||||
Stream queryDownloadByDevice(String deviceId, String channelId);
|
||||
|
||||
boolean stopStream(String streamId);
|
||||
|
||||
void updateMediaInfo(ZlmMediaServer mediaServerConfig);
|
||||
|
||||
void setRecordList(String key, RecordList recordList);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.fastbee.sip.domain.MediaServer;
|
||||
import com.fastbee.sip.domain.SipDevice;
|
||||
import com.fastbee.sip.model.Stream;
|
||||
import com.fastbee.sip.model.VideoSessionInfo;
|
||||
import com.fastbee.sip.server.IRtspCmd;
|
||||
import com.fastbee.sip.server.ISipCmd;
|
||||
import com.fastbee.sip.server.VideoSessionManager;
|
||||
import com.fastbee.sip.service.*;
|
||||
@@ -21,9 +20,6 @@ public class PlayServiceImpl implements IPlayService {
|
||||
@Autowired
|
||||
private ISipCmd sipCmd;
|
||||
|
||||
@Autowired
|
||||
private IRtspCmd rtspCmd;
|
||||
|
||||
@Autowired
|
||||
private IZmlHookService zmlHookService;
|
||||
|
||||
@@ -96,59 +92,4 @@ public class PlayServiceImpl implements IPlayService {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream playback(String deviceId, String channelId, String startTime, String endTime) {
|
||||
SipDevice dev = sipDeviceService.selectSipDeviceBySipId(deviceId);
|
||||
VideoSessionInfo info = sipCmd.playbackStreamCmd(dev, channelId, startTime, endTime);
|
||||
return zmlHookService.updateStream(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String playbackPause(String deviceId, String channelId, String streamId) {
|
||||
SipDevice dev = sipDeviceService.selectSipDeviceBySipId(deviceId);
|
||||
VideoSessionInfo sinfo = streamSession.getSessionInfo(deviceId, channelId, streamId, null);
|
||||
if (null == sinfo) {
|
||||
return "streamId不存在";
|
||||
}
|
||||
rtspCmd.setCseq(sinfo.getStream());
|
||||
rtspCmd.playPause(dev, channelId, streamId);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String playbackReplay(String deviceId, String channelId, String streamId) {
|
||||
SipDevice dev = sipDeviceService.selectSipDeviceBySipId(deviceId);
|
||||
VideoSessionInfo sinfo = streamSession.getSessionInfo(deviceId, channelId, streamId, null);
|
||||
if (null == sinfo) {
|
||||
return "streamId不存在";
|
||||
}
|
||||
rtspCmd.setCseq(streamId);
|
||||
rtspCmd.playReplay(dev, channelId, streamId);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String playbackSeek(String deviceId, String channelId, String streamId, long seektime) {
|
||||
SipDevice dev = sipDeviceService.selectSipDeviceBySipId(deviceId);
|
||||
VideoSessionInfo sinfo = streamSession.getSessionInfo(deviceId, channelId, streamId, null);
|
||||
if (null == sinfo) {
|
||||
return "streamId不存在";
|
||||
}
|
||||
rtspCmd.setCseq(streamId);
|
||||
rtspCmd.playBackSeek(dev, channelId, streamId, seektime);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String playbackSpeed(String deviceId, String channelId, String streamId, Integer speed) {
|
||||
SipDevice dev = sipDeviceService.selectSipDeviceBySipId(deviceId);
|
||||
VideoSessionInfo sinfo = streamSession.getSessionInfo(deviceId, channelId, streamId, null);
|
||||
if (null == sinfo) {
|
||||
return "streamId不存在";
|
||||
}
|
||||
rtspCmd.setCseq(streamId);
|
||||
rtspCmd.playBackSpeed(dev, channelId, streamId, speed);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package com.fastbee.sip.service.impl;
|
||||
import com.fastbee.common.constant.FastBeeConstant;
|
||||
import com.fastbee.common.core.redis.RedisCache;
|
||||
import com.fastbee.common.core.redis.RedisKeyBuilder;
|
||||
import com.fastbee.sip.model.RecordList;
|
||||
import com.fastbee.sip.model.Stream;
|
||||
import com.fastbee.sip.model.ZlmMediaServer;
|
||||
import com.fastbee.sip.service.ISipCacheService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -29,74 +27,8 @@ public class SipCacheServiceImpl implements ISipCacheService {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream queryStreamByStreamId(String streamId) {
|
||||
String key = RedisKeyBuilder.buildStreamCacheKey(streamId);
|
||||
return (Stream) redisCache.getCacheObject(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startPlay(Stream stream) {
|
||||
String key = RedisKeyBuilder.buildStreamCacheKey(stream.getStreamId());
|
||||
redisCache.setCacheObject(key, stream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stopStream(String streamId) {
|
||||
String key = RedisKeyBuilder.buildStreamCacheKey(streamId);
|
||||
return redisCache.deleteObject(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream queryPlayByDevice(String deviceId, String channelId, boolean record) {
|
||||
String streamId;
|
||||
streamId = String.format("gb_play_%s_%s", deviceId, channelId);
|
||||
String key = RedisKeyBuilder.buildStreamCacheKey(streamId);
|
||||
return (Stream) redisCache.getCacheObject(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startPlayback(Stream stream) {
|
||||
String key = RedisKeyBuilder.buildStreamCacheKey(stream.getStreamId());
|
||||
redisCache.setCacheObject(key, stream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream queryPlaybackByStreamId(String streamId) {
|
||||
String key = RedisKeyBuilder.buildStreamCacheKey(streamId);
|
||||
return (Stream) redisCache.getCacheObject(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream queryPlaybackByDevice(String deviceId, String channelId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startDownload(Stream stream) {
|
||||
String key = RedisKeyBuilder.buildStreamCacheKey(stream.getStreamId());
|
||||
redisCache.setCacheObject(key, stream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream queryDownloadByStreamId(String streamId) {
|
||||
String key = RedisKeyBuilder.buildStreamCacheKey(streamId);
|
||||
return (Stream) redisCache.getCacheObject(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream queryDownloadByDevice(String deviceId, String channelId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMediaInfo(ZlmMediaServer mediaServerConfig) {
|
||||
redisCache.setCacheObject(FastBeeConstant.REDIS.DEFAULT_MEDIA_CONFIG, mediaServerConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecordList(String key, RecordList recordList) {
|
||||
String catchkey = RedisKeyBuilder.buildSipRecordinfoCacheKey(key);
|
||||
redisCache.setCacheObject(catchkey, recordList);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user