Merge branch 'wvp-28181-2.0'
# Conflicts:
# src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java
# src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/AckRequestProcessor.java
# src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/ByeRequestProcessor.java
# src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
# src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/BroadcastResponseMessageHandler.java
66个文件已修改
7个文件已添加
3 文件已重命名
4个文件已删除
| | |
| | | @Value("${media.secret}") |
| | | private String secret; |
| | | |
| | | @Value("${media.stream-none-reader-delay-ms:10000}") |
| | | private int streamNoneReaderDelayMS = 10000; |
| | | @Value("${media.stream-none-reader-delay-ms:15000}") |
| | | private int streamNoneReaderDelayMS = 15000; |
| | | |
| | | @Value("${media.rtp.enable}") |
| | | private boolean rtpEnable; |
| | |
| | | |
| | | private Boolean logInDatebase = Boolean.TRUE; |
| | | |
| | | private Boolean usePushingAsStatus = Boolean.TRUE; |
| | | |
| | | private String serverId = "000000"; |
| | | |
| | | private String thirdPartyGBIdReg = "[\\s\\S]*"; |
| | |
| | | public void setPlatformPlayTimeout(int platformPlayTimeout) { |
| | | this.platformPlayTimeout = platformPlayTimeout; |
| | | } |
| | | |
| | | public Boolean isUsePushingAsStatus() { |
| | | return usePushingAsStatus; |
| | | } |
| | | |
| | | public void setUsePushingAsStatus(Boolean usePushingAsStatus) { |
| | | this.usePushingAsStatus = usePushingAsStatus; |
| | | } |
| | | } |
| | |
| | | |
| | | import com.alibaba.fastjson.parser.ParserConfig; |
| | | import com.genersoft.iot.vmp.common.VideoManagerConstants; |
| | | import com.genersoft.iot.vmp.service.impl.*; |
| | | import com.genersoft.iot.vmp.service.redisMsg.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.cache.annotation.CachingConfigurerSupport; |
| | | import org.springframework.context.annotation.Bean; |
| | |
| | | package com.genersoft.iot.vmp.gb28181;
|
| | |
|
| | | import com.genersoft.iot.vmp.conf.SipConfig;
|
| | | import com.genersoft.iot.vmp.gb28181.conf.DefaultProperties;
|
| | | import com.genersoft.iot.vmp.gb28181.transmit.ISIPProcessorObserver;
|
| | | import gov.nist.javax.sip.SipProviderImpl;
|
| | | import gov.nist.javax.sip.SipStackImpl;
|
| | |
| | | @Bean("sipStack")
|
| | | @DependsOn({"sipFactory"})
|
| | | SipStack createSipStack() throws PeerUnavailableException {
|
| | | Properties properties = new Properties();
|
| | | properties.setProperty("javax.sip.STACK_NAME", "GB28181_SIP");
|
| | | properties.setProperty("javax.sip.IP_ADDRESS", sipConfig.getMonitorIp());
|
| | | /**
|
| | | * 完整配置参考 gov.nist.javax.sip.SipStackImpl,需要下载源码
|
| | | * gov/nist/javax/sip/SipStackImpl.class
|
| | | * sip消息的解析在 gov.nist.javax.sip.stack.UDPMessageChannel的processIncomingDataPacket方法
|
| | | */
|
| | |
|
| | | // * gov/nist/javax/sip/SipStackImpl.class
|
| | | if (logger.isDebugEnabled()) {
|
| | | properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "false");
|
| | | }
|
| | | // 接收所有notify请求,即使没有订阅
|
| | | properties.setProperty("gov.nist.javax.sip.DELIVER_UNSOLICITED_NOTIFY", "true");
|
| | | properties.setProperty("gov.nist.javax.sip.AUTOMATIC_DIALOG_ERROR_HANDLING", "false");
|
| | | properties.setProperty("gov.nist.javax.sip.CANCEL_CLIENT_TRANSACTION_CHECKED", "false");
|
| | | // 为_NULL _对话框传递_终止的_事件
|
| | | properties.setProperty("gov.nist.javax.sip.DELIVER_TERMINATED_EVENT_FOR_NULL_DIALOG", "true");
|
| | | // 会话清理策略
|
| | | properties.setProperty("gov.nist.javax.sip.RELEASE_REFERENCES_STRATEGY", "Normal");
|
| | | // 处理由该服务器处理的基于底层TCP的保持生存超时
|
| | | properties.setProperty("gov.nist.javax.sip.RELIABLE_CONNECTION_KEEP_ALIVE_TIMEOUT", "60");
|
| | | // 获取实际内容长度,不使用header中的长度信息
|
| | | properties.setProperty("gov.nist.javax.sip.COMPUTE_CONTENT_LENGTH_FROM_MESSAGE_BODY", "true");
|
| | |
|
| | | /**
|
| | | * sip_server_log.log 和 sip_debug_log.log ERROR, INFO, WARNING, OFF, DEBUG, TRACE
|
| | | */
|
| | | properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "ERROR");
|
| | | // properties.setProperty("gov.nist.javax.sip.SIP_MESSAGE_VALVE", "com.genersoft.iot.vmp.gb28181.session.SipMessagePreprocessing");
|
| | | // if (logger.isDebugEnabled()) {
|
| | | // properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "DEBUG");
|
| | | // }
|
| | |
|
| | | sipStack = (SipStackImpl) sipFactory.createSipStack(properties);
|
| | |
|
| | | sipStack = ( SipStackImpl )sipFactory.createSipStack(DefaultProperties.getProperties(sipConfig.getMonitorIp(), false));
|
| | | return sipStack;
|
| | | }
|
| | |
|
| | |
| | | public void setTreeType(String treeType) { |
| | | this.treeType = treeType; |
| | | } |
| | | |
| | | } |
| | |
| | | package com.genersoft.iot.vmp.gb28181.bean; |
| | | |
| | | import gov.nist.javax.sip.message.SIPRequest; |
| | | |
| | | public class SendRtpItem { |
| | | |
| | | /** |
| | |
| | | private String serverId; |
| | | |
| | | /** |
| | | * invite的callId |
| | | * invite 的 callId |
| | | */ |
| | | private String CallId; |
| | | |
| | | /** |
| | | * invite 的 fromTag |
| | | */ |
| | | private String fromTag; |
| | | |
| | | /** |
| | | * invite 的 toTag |
| | | */ |
| | | private String toTag; |
| | | |
| | | /** |
| | | * 发送时,rtp的pt(uint8_t),不传时默认为96 |
| | |
| | | */ |
| | | private boolean onlyAudio = false; |
| | | |
| | | |
| | | /** |
| | | * 播放类型 |
| | | */ |
| | | private InviteStreamType playType; |
| | | |
| | | private byte[] transaction; |
| | | |
| | | private byte[] dialog; |
| | | |
| | | public String getIp() { |
| | | return ip; |
| | |
| | | this.playType = playType; |
| | | } |
| | | |
| | | public byte[] getTransaction() { |
| | | return transaction; |
| | | } |
| | | |
| | | public void setTransaction(byte[] transaction) { |
| | | this.transaction = transaction; |
| | | } |
| | | |
| | | public byte[] getDialog() { |
| | | return dialog; |
| | | } |
| | | |
| | | public void setDialog(byte[] dialog) { |
| | | this.dialog = dialog; |
| | | } |
| | | |
| | | public int getPt() { |
| | | return pt; |
| | | } |
| | |
| | | public void setServerId(String serverId) { |
| | | this.serverId = serverId; |
| | | } |
| | | |
| | | public String getFromTag() { |
| | | return fromTag; |
| | | } |
| | | |
| | | public void setFromTag(String fromTag) { |
| | | this.fromTag = fromTag; |
| | | } |
| | | |
| | | public String getToTag() { |
| | | return toTag; |
| | | } |
| | | |
| | | public void setToTag(String toTag) { |
| | | this.toTag = toTag; |
| | | } |
| | | } |
New file |
| | |
| | | package com.genersoft.iot.vmp.gb28181.bean; |
| | | |
| | | import org.dom4j.Element; |
| | | |
| | | import javax.sip.RequestEvent; |
| | | |
| | | public class SipMsgInfo { |
| | | private RequestEvent evt; |
| | | private Device device; |
| | | private ParentPlatform platform; |
| | | private Element rootElement; |
| | | |
| | | public SipMsgInfo(RequestEvent evt, Device device, Element rootElement) { |
| | | this.evt = evt; |
| | | this.device = device; |
| | | this.rootElement = rootElement; |
| | | } |
| | | |
| | | public SipMsgInfo(RequestEvent evt, ParentPlatform platform, Element rootElement) { |
| | | this.evt = evt; |
| | | this.platform = platform; |
| | | this.rootElement = rootElement; |
| | | } |
| | | |
| | | public RequestEvent getEvt() { |
| | | return evt; |
| | | } |
| | | |
| | | public void setEvt(RequestEvent evt) { |
| | | this.evt = evt; |
| | | } |
| | | |
| | | public Device getDevice() { |
| | | return device; |
| | | } |
| | | |
| | | public void setDevice(Device device) { |
| | | this.device = device; |
| | | } |
| | | |
| | | public ParentPlatform getPlatform() { |
| | | return platform; |
| | | } |
| | | |
| | | public void setPlatform(ParentPlatform platform) { |
| | | this.platform = platform; |
| | | } |
| | | |
| | | public Element getRootElement() { |
| | | return rootElement; |
| | | } |
| | | |
| | | public void setRootElement(Element rootElement) { |
| | | this.rootElement = rootElement; |
| | | } |
| | | } |
New file |
| | |
| | | package com.genersoft.iot.vmp.gb28181.bean; |
| | | |
| | | import gov.nist.javax.sip.message.SIPRequest; |
| | | |
| | | public class SipTransactionInfo { |
| | | |
| | | private String callId; |
| | | private String fromTag; |
| | | private String toTag; |
| | | private String viaBranch; |
| | | |
| | | public SipTransactionInfo(SIPRequest request) { |
| | | this.callId = request.getCallIdHeader().getCallId(); |
| | | this.fromTag = request.getFromTag(); |
| | | this.toTag = request.getToTag(); |
| | | this.viaBranch = request.getTopmostViaHeader().getBranch(); |
| | | } |
| | | |
| | | public SipTransactionInfo() { |
| | | } |
| | | |
| | | public String getCallId() { |
| | | return callId; |
| | | } |
| | | |
| | | public void setCallId(String callId) { |
| | | this.callId = callId; |
| | | } |
| | | |
| | | public String getFromTag() { |
| | | return fromTag; |
| | | } |
| | | |
| | | public void setFromTag(String fromTag) { |
| | | this.fromTag = fromTag; |
| | | } |
| | | |
| | | public String getToTag() { |
| | | return toTag; |
| | | } |
| | | |
| | | public void setToTag(String toTag) { |
| | | this.toTag = toTag; |
| | | } |
| | | |
| | | public String getViaBranch() { |
| | | return viaBranch; |
| | | } |
| | | |
| | | public void setViaBranch(String viaBranch) { |
| | | this.viaBranch = viaBranch; |
| | | } |
| | | } |
| | |
| | | import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask; |
| | | import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeHandlerTask; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; |
| | | import com.genersoft.iot.vmp.service.IPlatformService; |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | @Autowired |
| | | private DynamicTask dynamicTask; |
| | | |
| | | @Autowired |
| | | private IRedisCatchStorage redisCatchStorage; |
| | | |
| | | @Autowired |
| | | private ISIPCommanderForPlatform sipCommanderForPlatform; |
| | | |
| | | @Autowired |
| | | private IVideoManagerStorage storager; |
| | | |
| | | private final String taskOverduePrefix = "subscribe_overdue_"; |
| | | |
| | |
| | | } |
| | | // 添加任务处理订阅过期 |
| | | dynamicTask.stop(taskOverdueKey); |
| | | |
| | | } |
| | | |
| | | public void putMobilePositionSubscribe(String platformId, SubscribeInfo subscribeInfo) { |
| | | mobilePositionMap.put(platformId, subscribeInfo); |
| | | String key = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + "MobilePosition_" + platformId; |
| | | // 添加任务处理GPS定时推送 |
| | | dynamicTask.startCron(key, new MobilePositionSubscribeHandlerTask(redisCatchStorage, sipCommanderForPlatform, |
| | | storager, platformId, subscribeInfo.getSn(), key, this, dynamicTask), |
| | | dynamicTask.startCron(key, new MobilePositionSubscribeHandlerTask(platformId), |
| | | subscribeInfo.getGpsInterval() * 1000); |
| | | String taskOverdueKey = taskOverduePrefix + "MobilePosition_" + platformId; |
| | | // 添加任务处理订阅过期 |
| | |
| | | package com.genersoft.iot.vmp.gb28181.bean; |
| | | |
| | | import com.genersoft.iot.vmp.utils.SerializeUtils; |
| | | import gov.nist.javax.sip.message.SIPRequest; |
| | | import gov.nist.javax.sip.message.SIPResponse; |
| | | |
| | | import javax.sip.ClientTransaction; |
| | | import javax.sip.Dialog; |
| | | import javax.sip.RequestEvent; |
| | | import javax.sip.ServerTransaction; |
| | |
| | | public class SubscribeInfo { |
| | | |
| | | |
| | | public SubscribeInfo(RequestEvent evt, String id) { |
| | | public SubscribeInfo(ServerTransaction serverTransaction, String id) { |
| | | this.id = id; |
| | | Request request = evt.getRequest(); |
| | | ExpiresHeader expiresHeader = (ExpiresHeader)request.getHeader(ExpiresHeader.NAME); |
| | | this.expires = expiresHeader.getExpires(); |
| | | SIPRequest request = (SIPRequest)serverTransaction.getRequest(); |
| | | this.request = request; |
| | | this.expires = request.getExpires().getExpires(); |
| | | EventHeader eventHeader = (EventHeader)request.getHeader(EventHeader.NAME); |
| | | this.eventId = eventHeader.getEventId(); |
| | | this.eventType = eventHeader.getEventType(); |
| | | this.transaction = evt.getServerTransaction(); |
| | | this.dialog = evt.getDialog(); |
| | | CallIdHeader callIdHeader = (CallIdHeader)evt.getRequest().getHeader(CallIdHeader.NAME); |
| | | this.callId = callIdHeader.getCallId(); |
| | | } |
| | | |
| | | public SubscribeInfo() { |
| | | } |
| | | |
| | | private String id; |
| | | |
| | | private SIPRequest request; |
| | | private int expires; |
| | | private String callId; |
| | | private String eventId; |
| | | private String eventType; |
| | | private ServerTransaction transaction; |
| | | private Dialog dialog; |
| | | private SIPResponse response; |
| | | |
| | | /** |
| | | * 以下为可选字段 |
| | |
| | | private String sn; |
| | | private int gpsInterval; |
| | | |
| | | |
| | | public String getId() { |
| | | return id; |
| | | } |
| | | |
| | | public int getExpires() { |
| | | return expires; |
| | | } |
| | | |
| | | public String getCallId() { |
| | | return callId; |
| | | } |
| | | |
| | | public void setId(String id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public void setExpires(int expires) { |
| | | this.expires = expires; |
| | | public SIPRequest getRequest() { |
| | | return request; |
| | | } |
| | | |
| | | public void setCallId(String callId) { |
| | | this.callId = callId; |
| | | public void setRequest(SIPRequest request) { |
| | | this.request = request; |
| | | } |
| | | |
| | | public int getExpires() { |
| | | return expires; |
| | | } |
| | | |
| | | public void setExpires(int expires) { |
| | | this.expires = expires; |
| | | } |
| | | |
| | | public String getEventId() { |
| | |
| | | this.eventType = eventType; |
| | | } |
| | | |
| | | public ServerTransaction getTransaction() { |
| | | return transaction; |
| | | public SIPResponse getResponse() { |
| | | return response; |
| | | } |
| | | |
| | | public void setTransaction(ServerTransaction transaction) { |
| | | this.transaction = transaction; |
| | | } |
| | | |
| | | public Dialog getDialog() { |
| | | return dialog; |
| | | } |
| | | |
| | | public void setDialog(Dialog dialog) { |
| | | this.dialog = dialog; |
| | | public void setResponse(SIPResponse response) { |
| | | this.response = response; |
| | | } |
| | | |
| | | public String getSn() { |
New file |
| | |
| | | package com.genersoft.iot.vmp.gb28181.conf; |
| | | |
| | | import java.util.Properties; |
| | | |
| | | /** |
| | | * 获取sip默认配置 |
| | | * @author lin |
| | | */ |
| | | public class DefaultProperties { |
| | | |
| | | public static Properties getProperties(String ip, boolean isDebug) { |
| | | Properties properties = new Properties(); |
| | | properties.setProperty("javax.sip.STACK_NAME", "GB28181_SIP"); |
| | | properties.setProperty("javax.sip.IP_ADDRESS", ip); |
| | | properties.setProperty("javax.sip.AUTOMATIC_DIALOG_SUPPORT", "off"); |
| | | /** |
| | | * 完整配置参考 gov.nist.javax.sip.SipStackImpl,需要下载源码 |
| | | * gov/nist/javax/sip/SipStackImpl.class |
| | | * sip消息的解析在 gov.nist.javax.sip.stack.UDPMessageChannel的processIncomingDataPacket方法 |
| | | */ |
| | | |
| | | // * gov/nist/javax/sip/SipStackImpl.class |
| | | if (isDebug) { |
| | | properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "false"); |
| | | } |
| | | // 接收所有notify请求,即使没有订阅 |
| | | properties.setProperty("gov.nist.javax.sip.DELIVER_UNSOLICITED_NOTIFY", "true"); |
| | | properties.setProperty("gov.nist.javax.sip.AUTOMATIC_DIALOG_ERROR_HANDLING", "false"); |
| | | properties.setProperty("gov.nist.javax.sip.CANCEL_CLIENT_TRANSACTION_CHECKED", "false"); |
| | | // 为_NULL _对话框传递_终止的_事件 |
| | | properties.setProperty("gov.nist.javax.sip.DELIVER_TERMINATED_EVENT_FOR_NULL_DIALOG", "true"); |
| | | // 会话清理策略 |
| | | properties.setProperty("gov.nist.javax.sip.RELEASE_REFERENCES_STRATEGY", "Normal"); |
| | | // 处理由该服务器处理的基于底层TCP的保持生存超时 |
| | | properties.setProperty("gov.nist.javax.sip.RELIABLE_CONNECTION_KEEP_ALIVE_TIMEOUT", "60"); |
| | | // 获取实际内容长度,不使用header中的长度信息 |
| | | properties.setProperty("gov.nist.javax.sip.COMPUTE_CONTENT_LENGTH_FROM_MESSAGE_BODY", "true"); |
| | | |
| | | /** |
| | | * sip_server_log.log 和 sip_debug_log.log ERROR, INFO, WARNING, OFF, DEBUG, TRACE |
| | | */ |
| | | properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "ERROR"); |
| | | |
| | | return properties; |
| | | } |
| | | } |
| | |
| | | package com.genersoft.iot.vmp.gb28181.event; |
| | | |
| | | import com.genersoft.iot.vmp.gb28181.bean.DeviceNotFoundEvent; |
| | | import gov.nist.javax.sip.message.SIPRequest; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | |
| | | this.type = EventResultType.timeout; |
| | | this.msg = "消息超时未回复"; |
| | | this.statusCode = -1024; |
| | | this.dialog = timeoutEvent.getClientTransaction().getDialog(); |
| | | this.callId = this.dialog != null?timeoutEvent.getClientTransaction().getDialog().getCallId().getCallId(): null; |
| | | if (timeoutEvent.isServerTransaction()) { |
| | | this.callId = ((SIPRequest)timeoutEvent.getServerTransaction().getRequest()).getCallIdHeader().getCallId(); |
| | | }else { |
| | | this.callId = ((SIPRequest)timeoutEvent.getClientTransaction().getRequest()).getCallIdHeader().getCallId(); |
| | | } |
| | | }else if (event instanceof TransactionTerminatedEvent) { |
| | | TransactionTerminatedEvent transactionTerminatedEvent = (TransactionTerminatedEvent)event; |
| | | this.type = EventResultType.transactionTerminated; |
| | | this.msg = "事务已结束"; |
| | | this.statusCode = -1024; |
| | | this.callId = transactionTerminatedEvent.getClientTransaction().getDialog().getCallId().getCallId(); |
| | | this.dialog = transactionTerminatedEvent.getClientTransaction().getDialog(); |
| | | if (transactionTerminatedEvent.isServerTransaction()) { |
| | | this.callId = ((SIPRequest)transactionTerminatedEvent.getServerTransaction().getRequest()).getCallIdHeader().getCallId(); |
| | | }else { |
| | | this.callId = ((SIPRequest)transactionTerminatedEvent.getClientTransaction().getRequest()).getCallIdHeader().getCallId(); |
| | | } |
| | | }else if (event instanceof DialogTerminatedEvent) { |
| | | DialogTerminatedEvent dialogTerminatedEvent = (DialogTerminatedEvent)event; |
| | | this.type = EventResultType.dialogTerminated; |
| | | this.msg = "会话已结束"; |
| | | this.statusCode = -1024; |
| | | this.callId = dialogTerminatedEvent.getDialog().getCallId().getCallId(); |
| | | this.dialog = dialogTerminatedEvent.getDialog(); |
| | | }else if (event instanceof DeviceNotFoundEvent) { |
| | | DeviceNotFoundEvent deviceNotFoundEvent = (DeviceNotFoundEvent)event; |
| | | this.type = EventResultType.deviceNotFoundEvent; |
| | |
| | | */ |
| | | public interface ISubscribeTask extends Runnable{ |
| | | void stop(); |
| | | |
| | | DialogState getDialogState(); |
| | | } |
| | |
| | | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| | | import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; |
| | | import gov.nist.javax.sip.message.SIPRequest; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.scheduling.annotation.Async; |
| | |
| | | import javax.sip.Dialog; |
| | | import javax.sip.DialogState; |
| | | import javax.sip.ResponseEvent; |
| | | import javax.sip.header.ToHeader; |
| | | import java.text.ParseException; |
| | | import java.util.Timer; |
| | | import java.util.TimerTask; |
| | | |
| | |
| | | private final Logger logger = LoggerFactory.getLogger(CatalogSubscribeTask.class); |
| | | private Device device; |
| | | private final ISIPCommander sipCommander; |
| | | private Dialog dialog; |
| | | private SIPRequest request; |
| | | |
| | | private DynamicTask dynamicTask; |
| | | |
| | |
| | | if (dynamicTask.get(taskKey) != null) { |
| | | dynamicTask.stop(taskKey); |
| | | } |
| | | sipCommander.catalogSubscribe(device, dialog, eventResult -> { |
| | | if (eventResult.dialog != null || eventResult.dialog.getState().equals(DialogState.CONFIRMED)) { |
| | | dialog = eventResult.dialog; |
| | | } |
| | | SIPRequest sipRequest = sipCommander.catalogSubscribe(device, request, eventResult -> { |
| | | ResponseEvent event = (ResponseEvent) eventResult.event; |
| | | if (event.getResponse().getRawContent() != null) { |
| | | // 成功 |
| | | logger.info("[目录订阅]成功: {}", device.getDeviceId()); |
| | | }else { |
| | | // 成功 |
| | | logger.info("[目录订阅]成功: {}", device.getDeviceId()); |
| | | // 成功 |
| | | logger.info("[目录订阅]成功: {}", device.getDeviceId()); |
| | | ToHeader toHeader = (ToHeader)event.getResponse().getHeader(ToHeader.NAME); |
| | | try { |
| | | this.request.getToHeader().setTag(toHeader.getTag()); |
| | | } catch (ParseException e) { |
| | | logger.info("[目录订阅]成功: 但为request设置ToTag失败"); |
| | | this.request = null; |
| | | } |
| | | },eventResult -> { |
| | | dialog = null; |
| | | this.request = null; |
| | | // 失败 |
| | | logger.warn("[目录订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg); |
| | | dynamicTask.startDelay(taskKey, CatalogSubscribeTask.this, 2000); |
| | | }); |
| | | if (sipRequest != null) { |
| | | this.request = sipRequest; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (dynamicTask.get(taskKey) != null) { |
| | | dynamicTask.stop(taskKey); |
| | | } |
| | | if (dialog != null && dialog.getState().equals(DialogState.CONFIRMED)) { |
| | | device.setSubscribeCycleForCatalog(0); |
| | | sipCommander.catalogSubscribe(device, dialog, eventResult -> { |
| | | ResponseEvent event = (ResponseEvent) eventResult.event; |
| | | if (event.getResponse().getRawContent() != null) { |
| | | // 成功 |
| | | logger.info("[取消目录订阅订阅]成功: {}", device.getDeviceId()); |
| | | }else { |
| | | // 成功 |
| | | logger.info("[取消目录订阅订阅]成功: {}", device.getDeviceId()); |
| | | } |
| | | },eventResult -> { |
| | | // 失败 |
| | | logger.warn("[取消目录订阅订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public DialogState getDialogState() { |
| | | if (dialog == null) { |
| | | return null; |
| | | } |
| | | return dialog.getState(); |
| | | device.setSubscribeCycleForCatalog(0); |
| | | sipCommander.catalogSubscribe(device, request, eventResult -> { |
| | | ResponseEvent event = (ResponseEvent) eventResult.event; |
| | | if (event.getResponse().getRawContent() != null) { |
| | | // 成功 |
| | | logger.info("[取消目录订阅订阅]成功: {}", device.getDeviceId()); |
| | | }else { |
| | | // 成功 |
| | | logger.info("[取消目录订阅订阅]成功: {}", device.getDeviceId()); |
| | | } |
| | | },eventResult -> { |
| | | // 失败 |
| | | logger.warn("[取消目录订阅订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg); |
| | | }); |
| | | } |
| | | } |
| | |
| | | import com.genersoft.iot.vmp.gb28181.bean.*; |
| | | import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; |
| | | import com.genersoft.iot.vmp.service.IPlatformService; |
| | | import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| | | import com.genersoft.iot.vmp.utils.SpringBeanFactory; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.scheduling.annotation.Async; |
| | |
| | | */ |
| | | public class MobilePositionSubscribeHandlerTask implements ISubscribeTask { |
| | | |
| | | private Logger logger = LoggerFactory.getLogger(MobilePositionSubscribeHandlerTask.class); |
| | | |
| | | private IRedisCatchStorage redisCatchStorage; |
| | | private IVideoManagerStorage storager; |
| | | private ISIPCommanderForPlatform sipCommanderForPlatform; |
| | | private SubscribeHolder subscribeHolder; |
| | | private ParentPlatform platform; |
| | | private IPlatformService platformService; |
| | | private String platformId; |
| | | |
| | | private String sn; |
| | | private String key; |
| | | |
| | | public MobilePositionSubscribeHandlerTask(IRedisCatchStorage redisCatchStorage, |
| | | ISIPCommanderForPlatform sipCommanderForPlatform, |
| | | IVideoManagerStorage storager, |
| | | String platformId, |
| | | String sn, |
| | | String key, |
| | | SubscribeHolder subscribeInfo, |
| | | DynamicTask dynamicTask) { |
| | | this.redisCatchStorage = redisCatchStorage; |
| | | this.storager = storager; |
| | | this.platform = storager.queryParentPlatByServerGBId(platformId); |
| | | this.sn = sn; |
| | | this.key = key; |
| | | this.sipCommanderForPlatform = sipCommanderForPlatform; |
| | | this.subscribeHolder = subscribeInfo; |
| | | public MobilePositionSubscribeHandlerTask(String platformId) { |
| | | this.platformService = SpringBeanFactory.getBean("platformServiceImpl"); |
| | | this.platformId = platformId; |
| | | } |
| | | |
| | | @Override |
| | | public void run() { |
| | | |
| | | if (platform == null) { |
| | | return; |
| | | } |
| | | SubscribeInfo subscribe = subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId()); |
| | | if (subscribe != null) { |
| | | |
| | | // TODO 暂时只处理视频流的回复,后续增加对国标设备的支持 |
| | | List<DeviceChannel> gbStreams = storager.queryGbStreamListInPlatform(platform.getServerGBId()); |
| | | if (gbStreams.size() == 0) { |
| | | return; |
| | | } |
| | | for (DeviceChannel deviceChannel : gbStreams) { |
| | | String gbId = deviceChannel.getChannelId(); |
| | | GPSMsgInfo gpsMsgInfo = redisCatchStorage.getGpsMsgInfo(gbId); |
| | | // 无最新位置不发送 |
| | | if (gpsMsgInfo != null) { |
| | | // 经纬度都为0不发送 |
| | | if (gpsMsgInfo.getLng() == 0 && gpsMsgInfo.getLat() == 0) { |
| | | continue; |
| | | } |
| | | // 发送GPS消息 |
| | | sipCommanderForPlatform.sendNotifyMobilePosition(platform, gpsMsgInfo, subscribe); |
| | | } |
| | | } |
| | | } |
| | | platformService.sendNotifyMobilePosition(this.platformId); |
| | | } |
| | | |
| | | @Override |
| | | public void stop() { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public DialogState getDialogState() { |
| | | return null; |
| | | } |
| | | } |
| | |
| | | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| | | import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; |
| | | import gov.nist.javax.sip.message.SIPRequest; |
| | | import gov.nist.javax.sip.message.SIPResponse; |
| | | import org.dom4j.Element; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | import javax.sip.Dialog; |
| | | import javax.sip.DialogState; |
| | | import javax.sip.ResponseEvent; |
| | | import javax.sip.header.ToHeader; |
| | | import java.text.ParseException; |
| | | import java.util.Timer; |
| | | import java.util.TimerTask; |
| | | |
| | |
| | | */ |
| | | public class MobilePositionSubscribeTask implements ISubscribeTask { |
| | | private final Logger logger = LoggerFactory.getLogger(MobilePositionSubscribeTask.class); |
| | | private Device device; |
| | | private ISIPCommander sipCommander; |
| | | private Dialog dialog; |
| | | private Device device; |
| | | private ISIPCommander sipCommander; |
| | | |
| | | private SIPRequest request; |
| | | private DynamicTask dynamicTask; |
| | | private String taskKey = "mobile-position-subscribe-timeout"; |
| | | |
| | |
| | | if (dynamicTask.get(taskKey) != null) { |
| | | dynamicTask.stop(taskKey); |
| | | } |
| | | sipCommander.mobilePositionSubscribe(device, dialog, eventResult -> { |
| | | if (eventResult.dialog != null || eventResult.dialog.getState().equals(DialogState.CONFIRMED)) { |
| | | dialog = eventResult.dialog; |
| | | } |
| | | SIPRequest sipRequest = sipCommander.mobilePositionSubscribe(device, request, eventResult -> { |
| | | // 成功 |
| | | logger.info("[移动位置订阅]成功: {}", device.getDeviceId()); |
| | | ResponseEvent event = (ResponseEvent) eventResult.event; |
| | | if (event.getResponse().getRawContent() != null) { |
| | | // 成功 |
| | | logger.info("[移动位置订阅]成功: {}", device.getDeviceId()); |
| | | }else { |
| | | // 成功 |
| | | logger.info("[移动位置订阅]成功: {}", device.getDeviceId()); |
| | | ToHeader toHeader = (ToHeader)event.getResponse().getHeader(ToHeader.NAME); |
| | | try { |
| | | this.request.getToHeader().setTag(toHeader.getTag()); |
| | | } catch (ParseException e) { |
| | | logger.info("[移动位置订阅]成功: 为request设置ToTag失败"); |
| | | this.request = null; |
| | | } |
| | | },eventResult -> { |
| | | dialog = null; |
| | | this.request = null; |
| | | // 失败 |
| | | logger.warn("[移动位置订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg); |
| | | dynamicTask.startDelay(taskKey, MobilePositionSubscribeTask.this, 2000); |
| | | }); |
| | | if (sipRequest != null) { |
| | | this.request = sipRequest; |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | if (dynamicTask.get(taskKey) != null) { |
| | | dynamicTask.stop(taskKey); |
| | | } |
| | | if (dialog != null && dialog.getState().equals(DialogState.CONFIRMED)) { |
| | | logger.info("取消移动订阅时dialog状态为{}", dialog.getState()); |
| | | device.setSubscribeCycleForMobilePosition(0); |
| | | sipCommander.mobilePositionSubscribe(device, dialog, eventResult -> { |
| | | ResponseEvent event = (ResponseEvent) eventResult.event; |
| | | if (event.getResponse().getRawContent() != null) { |
| | | // 成功 |
| | | logger.info("[取消移动位置订阅]成功: {}", device.getDeviceId()); |
| | | }else { |
| | | // 成功 |
| | | logger.info("[取消移动位置订阅]成功: {}", device.getDeviceId()); |
| | | } |
| | | },eventResult -> { |
| | | // 失败 |
| | | logger.warn("[取消移动位置订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg); |
| | | }); |
| | | } |
| | | } |
| | | @Override |
| | | public DialogState getDialogState() { |
| | | if (dialog == null) { |
| | | return null; |
| | | } |
| | | return dialog.getState(); |
| | | device.setSubscribeCycleForMobilePosition(0); |
| | | sipCommander.mobilePositionSubscribe(device, request, eventResult -> { |
| | | ResponseEvent event = (ResponseEvent) eventResult.event; |
| | | if (event.getResponse().getRawContent() != null) { |
| | | // 成功 |
| | | logger.info("[取消移动位置订阅]成功: {}", device.getDeviceId()); |
| | | }else { |
| | | // 成功 |
| | | logger.info("[取消移动位置订阅]成功: {}", device.getDeviceId()); |
| | | } |
| | | },eventResult -> { |
| | | // 失败 |
| | | logger.warn("[取消移动位置订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg); |
| | | }); |
| | | } |
| | | } |
| | |
| | | * @param requestEvent RequestEvent事件 |
| | | */ |
| | | @Override |
| | | @Async |
| | | @Async("taskExecutor") |
| | | public void processRequest(RequestEvent requestEvent) { |
| | | String method = requestEvent.getRequest().getMethod(); |
| | | if ("NOTIFY".equalsIgnoreCase(requestEvent.getRequest().getMethod())) { |
| | | System.out.println(); |
| | | } |
| | | ISIPRequestProcessor sipRequestProcessor = requestProcessorMap.get(method); |
| | | if (sipRequestProcessor == null) { |
| | | logger.warn("不支持方法{}的request", method); |
| | |
| | | * @param responseEvent responseEvent事件 |
| | | */ |
| | | @Override |
| | | @Async |
| | | @Async("taskExecutor") |
| | | public void processResponse(ResponseEvent responseEvent) { |
| | | Response response = responseEvent.getResponse(); |
| | | int status = response.getStatusCode(); |
| | |
| | | |
| | | @Override |
| | | public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) { |
| | | // if (transactionTerminatedEvent.isServerTransaction()) { |
| | | // ServerTransaction serverTransaction = transactionTerminatedEvent.getServerTransaction(); |
| | | // serverTransaction.get |
| | | // } |
| | | |
| | | |
| | | // Transaction transaction = null; |
| | | // System.out.println("processTransactionTerminated"); |
| | | // if (transactionTerminatedEvent.isServerTransaction()) { |
| | |
| | | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
| | | import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
| | | import gov.nist.javax.sip.message.SIPRequest;
|
| | | import gov.nist.javax.sip.message.SIPRequest;
|
| | | import gov.nist.javax.sip.stack.SIPDialog;
|
| | |
|
| | | import javax.sip.Dialog;
|
| | |
| | | */
|
| | | void playbackControlCmd(Device device, StreamInfo streamInfo, String content,SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent);
|
| | |
|
| | | |
| | |
|
| | | /**
|
| | | * 语音广播
|
| | | *
|
| | |
| | | * @param device 视频设备
|
| | | * @return true = 命令发送成功
|
| | | */
|
| | | boolean mobilePositionSubscribe(Device device, Dialog dialog, SipSubscribe.Event okEvent , SipSubscribe.Event errorEvent);
|
| | | SIPRequest mobilePositionSubscribe(Device device, SIPRequest request, SipSubscribe.Event okEvent , SipSubscribe.Event errorEvent);
|
| | |
|
| | | /**
|
| | | * 订阅、取消订阅报警信息
|
| | |
| | | * @param device 视频设备
|
| | | * @return true = 命令发送成功
|
| | | */
|
| | | boolean catalogSubscribe(Device device, Dialog dialog, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent);
|
| | | SIPRequest catalogSubscribe(Device device, SIPRequest request, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent);
|
| | |
|
| | | /**
|
| | | * 拉框控制命令
|
| | |
| | | * @param callId callId |
| | | */ |
| | | void streamByeCmd(ParentPlatform platform, String callId); |
| | | void streamByeCmd(ParentPlatform platform, SendRtpItem sendRtpItem); |
| | | } |
| | |
| | | |
| | | import com.genersoft.iot.vmp.conf.SipConfig; |
| | | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| | | import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; |
| | | import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo; |
| | | import com.genersoft.iot.vmp.gb28181.utils.SipUtils; |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.utils.GitUtil; |
| | | import gov.nist.javax.sip.message.MessageFactoryImpl; |
| | | import gov.nist.javax.sip.message.SIPRequest; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.DigestUtils; |
| | |
| | | return registerRequest; |
| | | } |
| | | |
| | | public Request createMessageRequest(ParentPlatform parentPlatform, String content, SendRtpItem sendRtpItem) throws PeerUnavailableException, ParseException, InvalidArgumentException { |
| | | CallIdHeader callIdHeader = sipFactory.createHeaderFactory().createCallIdHeader(sendRtpItem.getCallId()); |
| | | return createMessageRequest(parentPlatform, content, sendRtpItem.getToTag(), SipUtils.getNewViaTag(), sendRtpItem.getFromTag(), callIdHeader); |
| | | } |
| | | |
| | | public Request createMessageRequest(ParentPlatform parentPlatform, String content, String fromTag, String viaTag, CallIdHeader callIdHeader) throws PeerUnavailableException, ParseException, InvalidArgumentException { |
| | | return createMessageRequest(parentPlatform, content, fromTag, viaTag, null, callIdHeader); |
| | | } |
| | | |
| | | |
| | | public Request createMessageRequest(ParentPlatform parentPlatform, String content, String fromTag, String viaTag, String toTag, CallIdHeader callIdHeader) throws PeerUnavailableException, ParseException, InvalidArgumentException { |
| | | Request request = null; |
| | | String serverAddress = parentPlatform.getServerIP()+ ":" + parentPlatform.getServerPort(); |
| | | // sipuri |
| | |
| | | // to |
| | | SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), serverAddress); |
| | | Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); |
| | | ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, null); |
| | | ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag); |
| | | |
| | | // Forwards |
| | | MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70); |
| | |
| | | request.setContent(content, contentTypeHeader); |
| | | return request; |
| | | } |
| | | |
| | | public SIPRequest createNotifyRequest(ParentPlatform parentPlatform, String content, SubscribeInfo subscribeInfo) throws PeerUnavailableException, ParseException, InvalidArgumentException { |
| | | SIPRequest request = null; |
| | | // sipuri |
| | | SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP()+ ":" + parentPlatform.getServerPort()); |
| | | // via |
| | | ArrayList<ViaHeader> viaHeaders = new ArrayList<>(); |
| | | ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(parentPlatform.getDeviceIp(), Integer.parseInt(parentPlatform.getDevicePort()), |
| | | parentPlatform.getTransport(), SipUtils.getNewViaTag()); |
| | | viaHeader.setRPort(); |
| | | viaHeaders.add(viaHeader); |
| | | // from |
| | | SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getDeviceGBId(), |
| | | parentPlatform.getDeviceIp() + ":" + parentPlatform.getDevicePort()); |
| | | Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); |
| | | FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, subscribeInfo.getResponse().getToTag()); |
| | | // to |
| | | SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerGBDomain()); |
| | | Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); |
| | | ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, subscribeInfo.getRequest().getFromTag()); |
| | | |
| | | // Forwards |
| | | MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70); |
| | | // ceq |
| | | CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(), Request.NOTIFY); |
| | | MessageFactoryImpl messageFactory = (MessageFactoryImpl) sipFactory.createMessageFactory(); |
| | | // 设置编码, 防止中文乱码 |
| | | messageFactory.setDefaultContentEncodingCharset("gb2312"); |
| | | |
| | | CallIdHeader callIdHeader = sipFactory.createHeaderFactory().createCallIdHeader(subscribeInfo.getRequest().getCallIdHeader().getCallId()); |
| | | |
| | | request = (SIPRequest) messageFactory.createRequest(requestURI, Request.NOTIFY, callIdHeader, cSeqHeader, fromHeader, |
| | | toHeader, viaHeaders, maxForwards); |
| | | |
| | | request.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil)); |
| | | |
| | | EventHeader event = sipFactory.createHeaderFactory().createEventHeader(subscribeInfo.getEventType()); |
| | | if (subscribeInfo.getEventId() != null) { |
| | | event.setEventId(subscribeInfo.getEventId()); |
| | | } |
| | | |
| | | request.addHeader(event); |
| | | |
| | | SubscriptionStateHeader active = sipFactory.createHeaderFactory().createSubscriptionStateHeader("active"); |
| | | request.setHeader(active); |
| | | |
| | | String sipAddress = sipConfig.getIp() + ":" + sipConfig.getPort(); |
| | | Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory() |
| | | .createSipURI(parentPlatform.getDeviceGBId(), sipAddress)); |
| | | request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); |
| | | |
| | | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); |
| | | request.setContent(content, contentTypeHeader); |
| | | return request; |
| | | } |
| | | |
| | | public SIPRequest createByeRequest(ParentPlatform platform, SendRtpItem sendRtpItem) throws PeerUnavailableException, ParseException, InvalidArgumentException { |
| | | |
| | | if (sendRtpItem == null ) { |
| | | return null; |
| | | } |
| | | |
| | | SIPRequest request = null; |
| | | // sipuri |
| | | SipURI requestURI = sipFactory.createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIP()+ ":" + platform.getServerPort()); |
| | | // via |
| | | ArrayList<ViaHeader> viaHeaders = new ArrayList<>(); |
| | | ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(platform.getDeviceIp(), Integer.parseInt(platform.getDevicePort()), |
| | | platform.getTransport(), SipUtils.getNewViaTag()); |
| | | viaHeader.setRPort(); |
| | | viaHeaders.add(viaHeader); |
| | | // from |
| | | SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(platform.getDeviceGBId(), |
| | | platform.getDeviceIp() + ":" + platform.getDevicePort()); |
| | | Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); |
| | | FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, sendRtpItem.getToTag()); |
| | | // to |
| | | SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerGBDomain()); |
| | | Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); |
| | | ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, sendRtpItem.getFromTag()); |
| | | |
| | | // Forwards |
| | | MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70); |
| | | // ceq |
| | | CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(), Request.BYE); |
| | | MessageFactoryImpl messageFactory = (MessageFactoryImpl) sipFactory.createMessageFactory(); |
| | | // 设置编码, 防止中文乱码 |
| | | messageFactory.setDefaultContentEncodingCharset("gb2312"); |
| | | |
| | | CallIdHeader callIdHeader = sipFactory.createHeaderFactory().createCallIdHeader(sendRtpItem.getCallId()); |
| | | |
| | | request = (SIPRequest) messageFactory.createRequest(requestURI, Request.BYE, callIdHeader, cSeqHeader, fromHeader, |
| | | toHeader, viaHeaders, maxForwards); |
| | | |
| | | request.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil)); |
| | | |
| | | String sipAddress = sipConfig.getIp() + ":" + sipConfig.getPort(); |
| | | Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory() |
| | | .createSipURI(platform.getDeviceGBId(), sipAddress)); |
| | | request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); |
| | | |
| | | return request; |
| | | } |
| | | } |
| | |
| | | import com.genersoft.iot.vmp.utils.GitUtil;
|
| | | import gov.nist.javax.sip.SipProviderImpl;
|
| | | import gov.nist.javax.sip.SipStackImpl;
|
| | | import gov.nist.javax.sip.message.SIPRequest;
|
| | | import gov.nist.javax.sip.stack.SIPDialog;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.beans.factory.annotation.Qualifier;
|
| | |
| | | return request;
|
| | | }
|
| | |
|
| | | public Request createSubscribeRequest(Device device, String content, String viaTag, String fromTag, String toTag, Integer expires, String event, CallIdHeader callIdHeader) throws ParseException, InvalidArgumentException, PeerUnavailableException {
|
| | | public Request createSubscribeRequest(Device device, String content, SIPRequest requestOld, Integer expires, String event, CallIdHeader callIdHeader) throws ParseException, InvalidArgumentException, PeerUnavailableException {
|
| | | Request request = null;
|
| | | // sipuri
|
| | | SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress());
|
| | | // via
|
| | | ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
|
| | | ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getIp(), sipConfig.getPort(),
|
| | | device.getTransport(), viaTag);
|
| | | device.getTransport(), SipUtils.getNewViaTag());
|
| | | viaHeader.setRPort();
|
| | | viaHeaders.add(viaHeader);
|
| | | // from
|
| | | SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getDomain());
|
| | | Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
|
| | | FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag);
|
| | | FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, requestOld == null ? SipUtils.getNewFromTag() :requestOld.getFromTag());
|
| | | // to
|
| | | SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress());
|
| | | Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
|
| | | ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag);
|
| | | ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, requestOld == null ? null :requestOld.getToTag());
|
| | |
|
| | | // Forwards
|
| | | MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
|
| | |
| | | // Event
|
| | | EventHeader eventHeader = sipFactory.createHeaderFactory().createEventHeader(event);
|
| | |
|
| | | int random = (int)Math.random() * 1000000000;
|
| | | int random = (int) Math.floor(Math.random() * 10000);
|
| | | eventHeader.setEventId(random + "");
|
| | | request.addHeader(eventHeader);
|
| | |
|
| | |
| | | import gov.nist.javax.sip.SipStackImpl;
|
| | | import gov.nist.javax.sip.message.MessageFactoryImpl;
|
| | | import gov.nist.javax.sip.message.SIPRequest;
|
| | | import gov.nist.javax.sip.stack.SIPClientTransaction;
|
| | | import gov.nist.javax.sip.stack.SIPDialog;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | |
| | | }), e ->{
|
| | | // 这里为例避免一个通道的点播只有一个callID这个参数使用一个固定值
|
| | | streamSession.put(device.getDeviceId(), channelId ,"play", stream, ssrcInfo.getSsrc(), mediaServerItem.getId(), ((ResponseEvent)e.event).getClientTransaction(), VideoStreamSessionManager.SessionType.play);
|
| | | streamSession.put(device.getDeviceId(), channelId ,"play", e.dialog);
|
| | | Dialog sipDialog = null;
|
| | | if (e.dialog == null) {
|
| | | SIPClientTransaction clientTransaction = (SIPClientTransaction)((ResponseEvent)e.event).getClientTransaction();
|
| | | sipDialog = new SIPDialog(clientTransaction, clientTransaction.getLastResponse());
|
| | | }else {
|
| | | sipDialog = e.dialog;
|
| | | }
|
| | | streamSession.put(device.getDeviceId(), channelId ,"play", sipDialog);
|
| | | okEvent.response(e);
|
| | | });
|
| | |
|
| | |
| | | * @return true = 命令发送成功
|
| | | */
|
| | | @Override
|
| | | public boolean mobilePositionSubscribe(Device device, Dialog dialog, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent) {
|
| | | public SIPRequest mobilePositionSubscribe(Device device, SIPRequest requestOld, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent) {
|
| | | try {
|
| | | StringBuffer subscribePostitionXml = new StringBuffer(200);
|
| | | String charset = device.getCharset();
|
| | |
| | | subscribePostitionXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | | subscribePostitionXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
| | | if (device.getSubscribeCycleForMobilePosition() > 0) {
|
| | | subscribePostitionXml.append("<Interval>" + String.valueOf(device.getMobilePositionSubmissionInterval()) + "</Interval>\r\n");
|
| | | subscribePostitionXml.append("<Interval>" + device.getMobilePositionSubmissionInterval() + "</Interval>\r\n");
|
| | | }
|
| | | subscribePostitionXml.append("</Query>\r\n");
|
| | |
|
| | | Request request;
|
| | | if (dialog != null) {
|
| | | SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress());
|
| | | request = dialog.createRequest(Request.SUBSCRIBE);
|
| | | ExpiresHeader expiresHeader = sipFactory.createHeaderFactory().createExpiresHeader(device.getSubscribeCycleForCatalog());
|
| | | request.setExpires(expiresHeader);
|
| | | CallIdHeader callIdHeader;
|
| | |
|
| | | request.setRequestURI(requestURI);
|
| | |
|
| | | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
| | | request.setContent(subscribePostitionXml.toString(), contentTypeHeader);
|
| | |
|
| | | CSeqHeader cSeqHeader = (CSeqHeader)request.getHeader(CSeqHeader.NAME);
|
| | | cSeqHeader.setSeqNumber(redisCatchStorage.getCSEQ());
|
| | | request.removeHeader(CSeqHeader.NAME);
|
| | | request.addHeader(cSeqHeader);
|
| | | if (requestOld != null) {
|
| | | callIdHeader = sipFactory.createHeaderFactory().createCallIdHeader(requestOld.getCallIdHeader().getCallId());
|
| | | }else {
|
| | | CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
| | | callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
| | | : udpSipProvider.getNewCallId();
|
| | | request = headerProvider.createSubscribeRequest(device, subscribePostitionXml.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, device.getSubscribeCycleForMobilePosition(), "presence" ,callIdHeader); //Position;id=" + tm.substring(tm.length() - 4));
|
| | | }
|
| | | SIPRequest request = (SIPRequest)headerProvider.createSubscribeRequest(device, subscribePostitionXml.toString(), requestOld, device.getSubscribeCycleForMobilePosition(), "presence" ,callIdHeader); //Position;id=" + tm.substring(tm.length() - 4));
|
| | |
|
| | | transmitRequest(device, request, errorEvent, okEvent);
|
| | |
|
| | | return true;
|
| | | return request;
|
| | |
|
| | | } catch ( NumberFormatException | ParseException | InvalidArgumentException | SipException e) {
|
| | | e.printStackTrace();
|
| | | return false;
|
| | | return null;
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
| | | : udpSipProvider.getNewCallId();
|
| | |
|
| | | Request request = headerProvider.createSubscribeRequest(device, cmdXml.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, expires, "presence" , callIdHeader);
|
| | | Request request = headerProvider.createSubscribeRequest(device, cmdXml.toString(), null, expires, "presence" , callIdHeader);
|
| | | transmitRequest(device, request);
|
| | |
|
| | | return true;
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public boolean catalogSubscribe(Device device, Dialog dialog, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) {
|
| | | public SIPRequest catalogSubscribe(Device device, SIPRequest requestOld, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) {
|
| | | try {
|
| | | StringBuffer cmdXml = new StringBuffer(200);
|
| | | String charset = device.getCharset();
|
| | |
| | | cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
| | | cmdXml.append("</Query>\r\n");
|
| | |
|
| | | CallIdHeader callIdHeader ;
|
| | |
|
| | | Request request;
|
| | | if (dialog != null) {
|
| | | SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress());
|
| | | request = dialog.createRequest(Request.SUBSCRIBE);
|
| | | ExpiresHeader expiresHeader = sipFactory.createHeaderFactory().createExpiresHeader(device.getSubscribeCycleForCatalog());
|
| | | request.setExpires(expiresHeader);
|
| | |
|
| | | request.setRequestURI(requestURI);
|
| | |
|
| | | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
| | | request.setContent(cmdXml.toString(), contentTypeHeader);
|
| | |
|
| | | CSeqHeader cSeqHeader = (CSeqHeader)request.getHeader(CSeqHeader.NAME);
|
| | | cSeqHeader.setSeqNumber(redisCatchStorage.getCSEQ());
|
| | | request.removeHeader(CSeqHeader.NAME);
|
| | | request.addHeader(cSeqHeader);
|
| | |
|
| | | if (requestOld != null) {
|
| | | callIdHeader = sipFactory.createHeaderFactory().createCallIdHeader(requestOld.getCallIdHeader().getCallId());
|
| | | }else {
|
| | | CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
| | | callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
| | | : udpSipProvider.getNewCallId();
|
| | |
|
| | | // 有效时间默认为60秒以上
|
| | | request = headerProvider.createSubscribeRequest(device, cmdXml.toString(), SipUtils.getNewViaTag(),
|
| | | SipUtils.getNewFromTag(), null, device.getSubscribeCycleForCatalog(), "Catalog" ,
|
| | | callIdHeader);
|
| | |
|
| | | }
|
| | |
|
| | | // 有效时间默认为60秒以上
|
| | | SIPRequest request = (SIPRequest)headerProvider.createSubscribeRequest(device, cmdXml.toString(), requestOld, device.getSubscribeCycleForCatalog(), "Catalog" ,
|
| | | callIdHeader);
|
| | | transmitRequest(device, request, errorEvent, okEvent);
|
| | | return true;
|
| | | return request;
|
| | |
|
| | | } catch ( NumberFormatException | ParseException | InvalidArgumentException | SipException e) {
|
| | | e.printStackTrace();
|
| | | return false;
|
| | | return null;
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | throw new RuntimeException(e);
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | | private void sendNotify(Device device, String catalogXmlContent,
|
| | | SubscribeInfo subscribeInfo, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent )
|
| | | throws SipException, ParseException {
|
| | | MessageFactoryImpl messageFactory = (MessageFactoryImpl) sipFactory.createMessageFactory();
|
| | | String characterSet = device.getCharset();
|
| | | // 设置编码, 防止中文乱码
|
| | | messageFactory.setDefaultContentEncodingCharset(characterSet);
|
| | | Dialog dialog = subscribeInfo.getDialog();
|
| | | if (dialog == null || !dialog.getState().equals(DialogState.CONFIRMED)) {
|
| | | return;
|
| | | }
|
| | | SIPRequest notifyRequest = (SIPRequest)dialog.createRequest(Request.NOTIFY);
|
| | | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
| | | notifyRequest.setContent(catalogXmlContent, contentTypeHeader);
|
| | |
|
| | | SubscriptionStateHeader subscriptionState = sipFactory.createHeaderFactory()
|
| | | .createSubscriptionStateHeader(SubscriptionStateHeader.ACTIVE);
|
| | | notifyRequest.addHeader(subscriptionState);
|
| | |
|
| | | EventHeader event = sipFactory.createHeaderFactory().createEventHeader(subscribeInfo.getEventType());
|
| | | if (subscribeInfo.getEventId() != null) {
|
| | | event.setEventId(subscribeInfo.getEventId());
|
| | | }
|
| | | notifyRequest.addHeader(event);
|
| | |
|
| | | SipURI sipURI = (SipURI) notifyRequest.getRequestURI();
|
| | | if (subscribeInfo.getTransaction() != null) {
|
| | | SIPRequest request = (SIPRequest) subscribeInfo.getTransaction().getRequest();
|
| | | sipURI.setHost(request.getRemoteAddress().getHostAddress());
|
| | | sipURI.setPort(request.getRemotePort());
|
| | | }else {
|
| | | sipURI.setHost(device.getIp());
|
| | | sipURI.setPort(device.getPort());
|
| | | }
|
| | |
|
| | | ClientTransaction transaction = null;
|
| | | if ("TCP".equals(device.getTransport())) {
|
| | | transaction = tcpSipProvider.getNewClientTransaction(notifyRequest);
|
| | | } else if ("UDP".equals(device.getTransport())) {
|
| | | transaction = udpSipProvider.getNewClientTransaction(notifyRequest);
|
| | | }
|
| | | // 添加错误订阅
|
| | | if (errorEvent != null) {
|
| | | sipSubscribe.addErrorSubscribe(subscribeInfo.getCallId(), errorEvent);
|
| | | }
|
| | | // 添加订阅
|
| | | if (okEvent != null) {
|
| | | sipSubscribe.addOkSubscribe(subscribeInfo.getCallId(), okEvent);
|
| | | }
|
| | | if (transaction == null) {
|
| | | logger.error("平台{}的Transport错误:{}",device.getDeviceId(), device.getTransport());
|
| | | return;
|
| | | }
|
| | | dialog.sendRequest(transaction);
|
| | |
|
| | | }
|
| | | }
|
| | |
| | | package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.genersoft.iot.vmp.gb28181.bean.*; |
| | | import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; |
| | |
| | | private final Logger logger = LoggerFactory.getLogger(SIPCommanderFroPlatform.class); |
| | | |
| | | @Autowired |
| | | private SIPRequestHeaderPlarformProvider headerProviderPlarformProvider; |
| | | private SIPRequestHeaderPlarformProvider headerProviderPlatformProvider; |
| | | |
| | | @Autowired |
| | | private IRedisCatchStorage redisCatchStorage; |
| | |
| | | @Autowired |
| | | private SipFactory sipFactory; |
| | | |
| | | @Autowired |
| | | private SubscribeHolder subscribeHolder; |
| | | |
| | | @Override |
| | | public boolean register(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) { |
| | | return register(parentPlatform, null, null, errorEvent, okEvent, false, true); |
| | |
| | | callIdHeader = udpSipProvider.getNewCallId(); |
| | | } |
| | | |
| | | request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, |
| | | request = headerProviderPlatformProvider.createRegisterRequest(parentPlatform, |
| | | redisCatchStorage.getCSEQ(), SipUtils.getNewFromTag(), |
| | | SipUtils.getNewViaTag(), callIdHeader, isRegister); |
| | | // 将 callid 写入缓存, 等注册成功可以更新状态 |
| | |
| | | }else { |
| | | CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() |
| | | : udpSipProvider.getNewCallId(); |
| | | request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, SipUtils.getNewFromTag(), null, callId, www, callIdHeader, isRegister); |
| | | request = headerProviderPlatformProvider.createRegisterRequest(parentPlatform, SipUtils.getNewFromTag(), null, callId, www, callIdHeader, isRegister); |
| | | } |
| | | |
| | | transmitRequest(parentPlatform, request, null, okEvent); |
| | |
| | | CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() |
| | | : udpSipProvider.getNewCallId(); |
| | | |
| | | Request request = headerProviderPlarformProvider.createMessageRequest( |
| | | Request request = headerProviderPlatformProvider.createMessageRequest( |
| | | parentPlatform, |
| | | keepaliveXml.toString(), |
| | | SipUtils.getNewFromTag(), |
| | |
| | | CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() |
| | | : udpSipProvider.getNewCallId(); |
| | | |
| | | Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, catalogXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader); |
| | | Request request = headerProviderPlatformProvider.createMessageRequest(parentPlatform, catalogXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader); |
| | | transmitRequest(parentPlatform, request); |
| | | |
| | | } catch (SipException | ParseException | InvalidArgumentException e) { |
| | |
| | | CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() |
| | | : udpSipProvider.getNewCallId(); |
| | | |
| | | Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, catalogXml, fromTag, SipUtils.getNewViaTag(), callIdHeader); |
| | | Request request = headerProviderPlatformProvider.createMessageRequest(parentPlatform, catalogXml, fromTag, SipUtils.getNewViaTag(), callIdHeader); |
| | | transmitRequest(parentPlatform, request, null, eventResult -> { |
| | | int indexNext = index + parentPlatform.getCatalogGroup(); |
| | | sendCatalogResponse(channels, parentPlatform, sn, fromTag, indexNext); |
| | |
| | | CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() |
| | | : udpSipProvider.getNewCallId(); |
| | | |
| | | Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, deviceInfoXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader); |
| | | Request request = headerProviderPlatformProvider.createMessageRequest(parentPlatform, deviceInfoXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader); |
| | | transmitRequest(parentPlatform, request); |
| | | |
| | | } catch (SipException | ParseException | InvalidArgumentException e) { |
| | |
| | | CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() |
| | | : udpSipProvider.getNewCallId(); |
| | | |
| | | Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, deviceStatusXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader); |
| | | Request request = headerProviderPlatformProvider.createMessageRequest(parentPlatform, deviceStatusXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader); |
| | | transmitRequest(parentPlatform, request); |
| | | |
| | | } catch (SipException | ParseException | InvalidArgumentException e) { |
| | |
| | | deviceStatusXml.append("<Altitude>" + gpsMsgInfo.getAltitude() + "</Altitude>\r\n"); |
| | | deviceStatusXml.append("</Notify>\r\n"); |
| | | |
| | | CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() |
| | | : udpSipProvider.getNewCallId(); |
| | | callIdHeader.setCallId(subscribeInfo.getCallId()); |
| | | |
| | | sendNotify(parentPlatform, deviceStatusXml.toString(), subscribeInfo, eventResult -> { |
| | | sendNotify(parentPlatform, deviceStatusXml.toString(), subscribeInfo, eventResult -> { |
| | | logger.error("发送NOTIFY通知消息失败。错误:{} {}", eventResult.statusCode, eventResult.msg); |
| | | }, null); |
| | | |
| | |
| | | if (parentPlatform == null) { |
| | | return false; |
| | | } |
| | | logger.info("[发送 报警订阅] {}/{}->{},{}", parentPlatform.getServerGBId(), deviceAlarm.getChannelId(), |
| | | deviceAlarm.getLongitude(), deviceAlarm.getLatitude()); |
| | | logger.info("[发送报警通知] {}/{}->{},{}: {}", parentPlatform.getServerGBId(), deviceAlarm.getChannelId(), |
| | | deviceAlarm.getLongitude(), deviceAlarm.getLatitude(), JSONObject.toJSON(deviceAlarm)); |
| | | try { |
| | | String characterSet = parentPlatform.getCharacterSet(); |
| | | StringBuffer deviceStatusXml = new StringBuffer(600); |
| | |
| | | CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() |
| | | : udpSipProvider.getNewCallId(); |
| | | |
| | | Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, deviceStatusXml.toString(), SipUtils.getNewFromTag(), SipUtils.getNewViaTag(), callIdHeader); |
| | | Request request = headerProviderPlatformProvider.createMessageRequest(parentPlatform, deviceStatusXml.toString(), SipUtils.getNewFromTag(), SipUtils.getNewViaTag(), callIdHeader); |
| | | transmitRequest(parentPlatform, request); |
| | | |
| | | } catch (SipException | ParseException e) { |
| | |
| | | return true; |
| | | } |
| | | |
| | | private void sendNotify(ParentPlatform parentPlatform, String catalogXmlContent, |
| | | private ClientTransaction sendNotify(ParentPlatform parentPlatform, String catalogXmlContent, |
| | | SubscribeInfo subscribeInfo, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent ) |
| | | throws NoSuchFieldException, IllegalAccessException, SipException, ParseException, InvalidArgumentException { |
| | | MessageFactoryImpl messageFactory = (MessageFactoryImpl) sipFactory.createMessageFactory(); |
| | | String characterSet = parentPlatform.getCharacterSet(); |
| | | // 设置编码, 防止中文乱码 |
| | | messageFactory.setDefaultContentEncodingCharset(characterSet); |
| | | Dialog dialog = subscribeInfo.getDialog(); |
| | | if (dialog == null || !dialog.getState().equals(DialogState.CONFIRMED)) { |
| | | return; |
| | | } |
| | | SIPRequest notifyRequest = (SIPRequest)dialog.createRequest(Request.NOTIFY); |
| | | |
| | | SIPRequest notifyRequest = headerProviderPlatformProvider.createNotifyRequest(parentPlatform, catalogXmlContent, subscribeInfo); |
| | | |
| | | notifyRequest.getCSeqHeader().setSeqNumber(redisCatchStorage.getCSEQ()); |
| | | |
| | |
| | | sipURI.setHost(parentPlatform.getServerIP()); |
| | | sipURI.setPort(parentPlatform.getServerPort()); |
| | | |
| | | // ClientTransaction transaction = subscribeInfo.getClientTransaction(); |
| | | // if (transaction == null || transaction.getState().equals(TransactionState.COMPLETED)) { |
| | | // if ("TCP".equals(parentPlatform.getTransport())) { |
| | | // transaction = tcpSipProvider.getNewClientTransaction(notifyRequest); |
| | | // } else if ("UDP".equals(parentPlatform.getTransport())) { |
| | | // transaction = udpSipProvider.getNewClientTransaction(notifyRequest); |
| | | // } |
| | | // } |
| | | |
| | | ClientTransaction transaction = null; |
| | | if ("TCP".equals(parentPlatform.getTransport())) { |
| | | transaction = tcpSipProvider.getNewClientTransaction(notifyRequest); |
| | | } else if ("UDP".equals(parentPlatform.getTransport())) { |
| | | transaction = udpSipProvider.getNewClientTransaction(notifyRequest); |
| | | } |
| | | |
| | | // 添加错误订阅 |
| | | if (errorEvent != null) { |
| | | sipSubscribe.addErrorSubscribe(subscribeInfo.getCallId(), errorEvent); |
| | | sipSubscribe.addErrorSubscribe(subscribeInfo.getRequest().getCallIdHeader().getCallId(), errorEvent); |
| | | } |
| | | // 添加订阅 |
| | | if (okEvent != null) { |
| | | sipSubscribe.addOkSubscribe(subscribeInfo.getCallId(), okEvent); |
| | | sipSubscribe.addOkSubscribe(subscribeInfo.getRequest().getCallIdHeader().getCallId(), okEvent); |
| | | } |
| | | if (transaction == null) { |
| | | logger.error("平台{}的Transport错误:{}",parentPlatform.getServerGBId(), parentPlatform.getTransport()); |
| | | return; |
| | | } |
| | | dialog.sendRequest(transaction); |
| | | |
| | | transaction.sendRequest(); |
| | | return transaction; |
| | | } |
| | | |
| | | private String getCatalogXmlContentForCatalogAddOrUpdate(ParentPlatform parentPlatform, List<DeviceChannel> channels, int sumNum, String type, SubscribeInfo subscribeInfo) { |
| | |
| | | // callid |
| | | CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() |
| | | : udpSipProvider.getNewCallId(); |
| | | Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, recordXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader); |
| | | Request request = headerProviderPlatformProvider.createMessageRequest(parentPlatform, recordXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader); |
| | | transmitRequest(parentPlatform, request); |
| | | |
| | | } catch (SipException | ParseException | InvalidArgumentException e) { |
| | |
| | | return false; |
| | | } |
| | | |
| | | byte[] dialogByteArray = sendRtpItem.getDialog(); |
| | | if (dialogByteArray == null) { |
| | | return false; |
| | | } |
| | | try{ |
| | | SIPDialog dialog = (SIPDialog) SerializeUtils.deSerialize(dialogByteArray); |
| | | SipStack sipStack; |
| | | if ("TCP".equals(platform.getTransport())) { |
| | | sipStack = tcpSipProvider.getSipStack(); |
| | | } else { |
| | | sipStack = udpSipProvider.getSipStack(); |
| | | } |
| | | SIPDialog sipDialog = ((SipStackImpl) sipStack).putDialog(dialog); |
| | | if (dialog != sipDialog) { |
| | | dialog = sipDialog; |
| | | } |
| | | if ("TCP".equals(platform.getTransport())) { |
| | | dialog.setSipProvider(tcpSipProvider); |
| | | } else { |
| | | dialog.setSipProvider(udpSipProvider); |
| | | } |
| | | |
| | | Field sipStackField = SIPDialog.class.getDeclaredField("sipStack"); |
| | | sipStackField.setAccessible(true); |
| | | sipStackField.set(dialog, sipStack); |
| | | Field eventListenersField = SIPDialog.class.getDeclaredField("eventListeners"); |
| | | eventListenersField.setAccessible(true); |
| | | eventListenersField.set(dialog, new HashSet<>()); |
| | | |
| | | SIPRequest messageRequest = (SIPRequest)dialog.createRequest(Request.MESSAGE); |
| | | String characterSet = platform.getCharacterSet(); |
| | | StringBuffer mediaStatusXml = new StringBuffer(200); |
| | | mediaStatusXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n"); |
| | |
| | | mediaStatusXml.append("<DeviceID>" + sendRtpItem.getChannelId() + "</DeviceID>\r\n"); |
| | | mediaStatusXml.append("<NotifyType>121</NotifyType>\r\n"); |
| | | mediaStatusXml.append("</Notify>\r\n"); |
| | | |
| | | SIPRequest messageRequest = (SIPRequest)headerProviderPlatformProvider.createMessageRequest(platform, mediaStatusXml.toString(), |
| | | sendRtpItem); |
| | | |
| | | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); |
| | | messageRequest.setContent(mediaStatusXml.toString(), contentTypeHeader); |
| | | SipURI sipURI = (SipURI) messageRequest.getRequestURI(); |
| | |
| | | }else { |
| | | clientTransaction = udpSipProvider.getNewClientTransaction(messageRequest); |
| | | } |
| | | dialog.sendRequest(clientTransaction); |
| | | clientTransaction.sendRequest(); |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } catch (NoSuchFieldException e) { |
| | | e.printStackTrace(); |
| | | } catch (IllegalAccessException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | return true; |
| | | |
| | |
| | | } |
| | | SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(platform.getServerGBId(), null, null, callId); |
| | | if (sendRtpItem != null) { |
| | | String mediaServerId = sendRtpItem.getMediaServerId(); |
| | | MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId); |
| | | if (mediaServerItem != null) { |
| | | mediaServerService.releaseSsrc(mediaServerItem.getId(), sendRtpItem.getSsrc()); |
| | | zlmrtpServerFactory.closeRTPServer(mediaServerItem, sendRtpItem.getStreamId()); |
| | | streamByeCmd(platform, sendRtpItem); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void streamByeCmd(ParentPlatform platform, SendRtpItem sendRtpItem) { |
| | | if (sendRtpItem == null ) { |
| | | logger.info("[向上级发送BYE], sendRtpItem 为NULL"); |
| | | return; |
| | | } |
| | | if (platform == null) { |
| | | logger.info("[向上级发送BYE], platform 为NULL"); |
| | | return; |
| | | } |
| | | logger.info("[向上级发送BYE], {}/{}", platform.getServerGBId(), sendRtpItem.getChannelId()); |
| | | String mediaServerId = sendRtpItem.getMediaServerId(); |
| | | MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId); |
| | | if (mediaServerItem != null) { |
| | | mediaServerService.releaseSsrc(mediaServerItem.getId(), sendRtpItem.getSsrc()); |
| | | zlmrtpServerFactory.closeRTPServer(mediaServerItem, sendRtpItem.getStreamId()); |
| | | } |
| | | try { |
| | | |
| | | SIPRequest byeRequest = headerProviderPlatformProvider.createByeRequest(platform, sendRtpItem); |
| | | if (byeRequest == null) { |
| | | logger.warn("[向上级发送bye]:无法创建 byeRequest"); |
| | | } |
| | | byte[] dialogByteArray = sendRtpItem.getDialog(); |
| | | if (dialogByteArray != null) { |
| | | SIPDialog dialog = (SIPDialog) SerializeUtils.deSerialize(dialogByteArray); |
| | | SipStack sipStack; |
| | | if ("TCP".equals(platform.getTransport())) { |
| | | sipStack = tcpSipProvider.getSipStack(); |
| | | } else { |
| | | sipStack = udpSipProvider.getSipStack(); |
| | | } |
| | | SIPDialog sipDialog = ((SipStackImpl) sipStack).putDialog(dialog); |
| | | if (dialog != sipDialog) { |
| | | dialog = sipDialog; |
| | | } |
| | | try { |
| | | if ("TCP".equals(platform.getTransport())) { |
| | | dialog.setSipProvider(tcpSipProvider); |
| | | } else { |
| | | dialog.setSipProvider(udpSipProvider); |
| | | } |
| | | Field sipStackField = SIPDialog.class.getDeclaredField("sipStack"); |
| | | sipStackField.setAccessible(true); |
| | | sipStackField.set(dialog, sipStack); |
| | | Field eventListenersField = SIPDialog.class.getDeclaredField("eventListeners"); |
| | | eventListenersField.setAccessible(true); |
| | | eventListenersField.set(dialog, new HashSet<>()); |
| | | |
| | | Request byeRequest = dialog.createRequest(Request.BYE); |
| | | |
| | | SipURI byeURI = (SipURI) byeRequest.getRequestURI(); |
| | | byeURI.setHost(platform.getServerIP()); |
| | | byeURI.setPort(platform.getServerPort()); |
| | | ClientTransaction clientTransaction; |
| | | if ("TCP".equals(platform.getTransport())) { |
| | | clientTransaction = tcpSipProvider.getNewClientTransaction(byeRequest); |
| | | } else { |
| | | clientTransaction = udpSipProvider.getNewClientTransaction(byeRequest); |
| | | } |
| | | dialog.sendRequest(clientTransaction); |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } catch (NoSuchFieldException e) { |
| | | e.printStackTrace(); |
| | | } catch (IllegalAccessException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | ClientTransaction clientTransaction; |
| | | if ("TCP".equals(platform.getTransport())) { |
| | | clientTransaction = tcpSipProvider.getNewClientTransaction(byeRequest); |
| | | } else { |
| | | clientTransaction = udpSipProvider.getNewClientTransaction(byeRequest); |
| | | } |
| | | clientTransaction.sendRequest(); |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | } |
| | |
| | | package com.genersoft.iot.vmp.gb28181.transmit.event.request; |
| | | |
| | | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| | | import com.genersoft.iot.vmp.gb28181.utils.SipUtils; |
| | | import gov.nist.javax.sip.SipProviderImpl; |
| | | import gov.nist.javax.sip.SipStackImpl; |
| | | import gov.nist.javax.sip.message.SIPRequest; |
| | | import gov.nist.javax.sip.message.SIPResponse; |
| | | import gov.nist.javax.sip.stack.SIPServerTransaction; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import org.dom4j.Document; |
| | |
| | | import javax.sip.address.Address; |
| | | import javax.sip.address.AddressFactory; |
| | | import javax.sip.address.SipURI; |
| | | import javax.sip.header.ContentTypeHeader; |
| | | import javax.sip.header.ExpiresHeader; |
| | | import javax.sip.header.HeaderFactory; |
| | | import javax.sip.header.ViaHeader; |
| | | import javax.sip.header.*; |
| | | import javax.sip.message.MessageFactory; |
| | | import javax.sip.message.Request; |
| | | import javax.sip.message.Response; |
| | |
| | | public ServerTransaction getServerTransaction(RequestEvent evt) { |
| | | Request request = evt.getRequest(); |
| | | ServerTransaction serverTransaction = evt.getServerTransaction(); |
| | | if (serverTransaction != null) { |
| | | System.out.println(serverTransaction.getState().toString()); |
| | | } |
| | | // 判断TCP还是UDP |
| | | ViaHeader reqViaHeader = (ViaHeader) request.getHeader(ViaHeader.NAME); |
| | | String transport = reqViaHeader.getTransport(); |
| | |
| | | return null; |
| | | } |
| | | |
| | | class ResponseAckExtraParam{ |
| | | String content; |
| | | ContentTypeHeader contentTypeHeader; |
| | | SipURI sipURI; |
| | | int expires = -1; |
| | | } |
| | | |
| | | /*** |
| | | * 回复状态码 |
| | | * 100 trying |
| | | * 200 OK |
| | | * 400 |
| | | * 404 |
| | | * @param evt |
| | | * @throws SipException |
| | | * @throws InvalidArgumentException |
| | | * @throws ParseException |
| | | */ |
| | | public void responseAck(RequestEvent evt, int statusCode) throws SipException, InvalidArgumentException, ParseException { |
| | | Response response = getMessageFactory().createResponse(statusCode, evt.getRequest()); |
| | | ServerTransaction serverTransaction = getServerTransaction(evt); |
| | | if (serverTransaction == null) { |
| | | logger.warn("回复失败:{}", response); |
| | | return; |
| | | } |
| | | serverTransaction.sendResponse(response); |
| | | if (statusCode >= 200 && !"NOTIFY".equalsIgnoreCase(evt.getRequest().getMethod())) { |
| | | |
| | | if (serverTransaction.getDialog() != null) { |
| | | serverTransaction.getDialog().delete(); |
| | | } |
| | | } |
| | | public SIPResponse responseAck(ServerTransaction serverTransaction, int statusCode) throws SipException, InvalidArgumentException, ParseException { |
| | | return responseAck(serverTransaction, statusCode, null); |
| | | } |
| | | |
| | | public void responseAck(RequestEvent evt, int statusCode, String msg) throws SipException, InvalidArgumentException, ParseException { |
| | | Response response = getMessageFactory().createResponse(statusCode, evt.getRequest()); |
| | | response.setReasonPhrase(msg); |
| | | ServerTransaction serverTransaction = getServerTransaction(evt); |
| | | public SIPResponse responseAck(ServerTransaction serverTransaction, int statusCode, String msg) throws SipException, InvalidArgumentException, ParseException { |
| | | return responseAck(serverTransaction, statusCode, msg, null); |
| | | } |
| | | |
| | | public SIPResponse responseAck(ServerTransaction serverTransaction, int statusCode, String msg, ResponseAckExtraParam responseAckExtraParam) throws SipException, InvalidArgumentException, ParseException { |
| | | ToHeader toHeader = (ToHeader) serverTransaction.getRequest().getHeader(ToHeader.NAME); |
| | | if (toHeader.getTag() == null) { |
| | | toHeader.setTag(SipUtils.getNewTag()); |
| | | } |
| | | SIPResponse response = (SIPResponse)getMessageFactory().createResponse(statusCode, serverTransaction.getRequest()); |
| | | if (msg != null) { |
| | | response.setReasonPhrase(msg); |
| | | } |
| | | if (responseAckExtraParam != null) { |
| | | if (responseAckExtraParam.sipURI != null && serverTransaction.getRequest().getMethod().equals(Request.INVITE)) { |
| | | logger.debug("responseSdpAck SipURI: {}:{}", responseAckExtraParam.sipURI.getHost(), responseAckExtraParam.sipURI.getPort()); |
| | | Address concatAddress = SipFactory.getInstance().createAddressFactory().createAddress( |
| | | SipFactory.getInstance().createAddressFactory().createSipURI(responseAckExtraParam.sipURI.getUser(), responseAckExtraParam.sipURI.getHost()+":"+responseAckExtraParam.sipURI.getPort() |
| | | )); |
| | | response.addHeader(SipFactory.getInstance().createHeaderFactory().createContactHeader(concatAddress)); |
| | | } |
| | | if (responseAckExtraParam.contentTypeHeader != null) { |
| | | response.setContent(responseAckExtraParam.content, responseAckExtraParam.contentTypeHeader); |
| | | } |
| | | |
| | | if (serverTransaction.getRequest().getMethod().equals(Request.SUBSCRIBE)) { |
| | | if (responseAckExtraParam.expires == -1) { |
| | | logger.error("[参数不全] 2xx的SUBSCRIBE回复,必须设置Expires header"); |
| | | }else { |
| | | ExpiresHeader expiresHeader = SipFactory.getInstance().createHeaderFactory().createExpiresHeader(responseAckExtraParam.expires); |
| | | response.addHeader(expiresHeader); |
| | | } |
| | | } |
| | | }else { |
| | | if (serverTransaction.getRequest().getMethod().equals(Request.SUBSCRIBE)) { |
| | | logger.error("[参数不全] 2xx的SUBSCRIBE回复,必须设置Expires header"); |
| | | } |
| | | } |
| | | serverTransaction.sendResponse(response); |
| | | if (statusCode >= 200 && !"NOTIFY".equalsIgnoreCase(evt.getRequest().getMethod())) { |
| | | if (statusCode >= 200 && !"NOTIFY".equalsIgnoreCase(serverTransaction.getRequest().getMethod())) { |
| | | if (serverTransaction.getDialog() != null) { |
| | | serverTransaction.getDialog().delete(); |
| | | } |
| | | } |
| | | return response; |
| | | } |
| | | |
| | | /** |
| | | * 回复带sdp的200 |
| | | * @param evt |
| | | * @param sdp |
| | | * @throws SipException |
| | | * @throws InvalidArgumentException |
| | | * @throws ParseException |
| | | */ |
| | | public void responseSdpAck(RequestEvent evt, String sdp, ParentPlatform platform) throws SipException, InvalidArgumentException, ParseException { |
| | | Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest()); |
| | | SipFactory sipFactory = SipFactory.getInstance(); |
| | | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "SDP"); |
| | | response.setContent(sdp, contentTypeHeader); |
| | | public SIPResponse responseSdpAck(ServerTransaction serverTransaction, String sdp, ParentPlatform platform) throws SipException, InvalidArgumentException, ParseException { |
| | | |
| | | ContentTypeHeader contentTypeHeader = SipFactory.getInstance().createHeaderFactory().createContentTypeHeader("APPLICATION", "SDP"); |
| | | |
| | | // 兼容国标中的使用编码@域名作为RequestURI的情况 |
| | | SipURI sipURI = (SipURI)evt.getRequest().getRequestURI(); |
| | | SipURI sipURI = (SipURI)serverTransaction.getRequest().getRequestURI(); |
| | | if (sipURI.getPort() == -1) { |
| | | sipURI = sipFactory.createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIP()+":"+platform.getServerPort()); |
| | | sipURI = SipFactory.getInstance().createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIP()+":"+platform.getServerPort()); |
| | | } |
| | | logger.debug("responseSdpAck SipURI: {}:{}", sipURI.getHost(), sipURI.getPort()); |
| | | ResponseAckExtraParam responseAckExtraParam = new ResponseAckExtraParam(); |
| | | responseAckExtraParam.contentTypeHeader = contentTypeHeader; |
| | | responseAckExtraParam.content = sdp; |
| | | responseAckExtraParam.sipURI = sipURI; |
| | | |
| | | Address concatAddress = sipFactory.createAddressFactory().createAddress( |
| | | sipFactory.createAddressFactory().createSipURI(sipURI.getUser(), sipURI.getHost()+":"+sipURI.getPort() |
| | | )); |
| | | response.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); |
| | | ServerTransaction serverTransaction = getServerTransaction(evt); |
| | | if (serverTransaction == null) { |
| | | |
| | | } |
| | | getServerTransaction(evt).sendResponse(response); |
| | | return responseAck(serverTransaction, Response.OK, null, responseAckExtraParam); |
| | | } |
| | | |
| | | /** |
| | | * 回复带xml的200 |
| | | * @param evt |
| | | * @param xml |
| | | * @throws SipException |
| | | * @throws InvalidArgumentException |
| | | * @throws ParseException |
| | | */ |
| | | public Response responseXmlAck(RequestEvent evt, String xml, ParentPlatform platform) throws SipException, InvalidArgumentException, ParseException { |
| | | Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest()); |
| | | SipFactory sipFactory = SipFactory.getInstance(); |
| | | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); |
| | | response.setContent(xml, contentTypeHeader); |
| | | public SIPResponse responseXmlAck(ServerTransaction serverTransaction, String xml, ParentPlatform platform, Integer expires) throws SipException, InvalidArgumentException, ParseException { |
| | | ContentTypeHeader contentTypeHeader = SipFactory.getInstance().createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); |
| | | |
| | | // 兼容国标中的使用编码@域名作为RequestURI的情况 |
| | | SipURI sipURI = (SipURI)evt.getRequest().getRequestURI(); |
| | | SipURI sipURI = (SipURI)serverTransaction.getRequest().getRequestURI(); |
| | | if (sipURI.getPort() == -1) { |
| | | sipURI = sipFactory.createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIP()+":"+platform.getServerPort()); |
| | | sipURI = SipFactory.getInstance().createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIP()+":"+platform.getServerPort()); |
| | | } |
| | | logger.debug("responseXmlAck SipURI: {}:{}", sipURI.getHost(), sipURI.getPort()); |
| | | |
| | | Address concatAddress = sipFactory.createAddressFactory().createAddress( |
| | | sipFactory.createAddressFactory().createSipURI(sipURI.getUser(), sipURI.getHost()+":"+sipURI.getPort() |
| | | )); |
| | | response.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); |
| | | response.addHeader(evt.getRequest().getHeader(ExpiresHeader.NAME)); |
| | | getServerTransaction(evt).sendResponse(response); |
| | | return response; |
| | | ResponseAckExtraParam responseAckExtraParam = new ResponseAckExtraParam(); |
| | | responseAckExtraParam.contentTypeHeader = contentTypeHeader; |
| | | responseAckExtraParam.content = xml; |
| | | responseAckExtraParam.sipURI = sipURI; |
| | | responseAckExtraParam.expires = expires; |
| | | return responseAck(serverTransaction, Response.OK, null, responseAckExtraParam); |
| | | } |
| | | |
| | | public Element getRootElement(RequestEvent evt) throws DocumentException { |
| | |
| | | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| | | import com.genersoft.iot.vmp.service.IMediaServerService; |
| | | import com.genersoft.iot.vmp.service.bean.RequestPushStreamMsg; |
| | | import com.genersoft.iot.vmp.service.impl.RedisGbPlayMsgListener; |
| | | import com.genersoft.iot.vmp.service.redisMsg.RedisGbPlayMsgListener; |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| | | import gov.nist.javax.sip.message.SIPRequest; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.sip.*; |
| | | import javax.sip.RequestEvent; |
| | | import javax.sip.address.SipURI; |
| | | import javax.sip.header.CallIdHeader; |
| | | import javax.sip.header.FromHeader; |
| | |
| | | */ |
| | | @Override |
| | | public void process(RequestEvent evt) { |
| | | Dialog dialog = evt.getDialog(); |
| | | CallIdHeader callIdHeader = (CallIdHeader) evt.getRequest().getHeader(CallIdHeader.NAME); |
| | | if (dialog == null) { |
| | | return; |
| | | CallIdHeader callIdHeader = (CallIdHeader)evt.getRequest().getHeader(CallIdHeader.NAME); |
| | | |
| | | String platformGbId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(FromHeader.NAME)).getAddress().getURI()).getUser(); |
| | | logger.info("[收到ACK]: platformGbId->{}", platformGbId); |
| | | ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformGbId); |
| | | // 取消设置的超时任务 |
| | | dynamicTask.stop(callIdHeader.getCallId()); |
| | | String channelId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(ToHeader.NAME)).getAddress().getURI()).getUser(); |
| | | SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(platformGbId, channelId, null, callIdHeader.getCallId()); |
| | | String is_Udp = sendRtpItem.isTcp() ? "0" : "1"; |
| | | MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId()); |
| | | logger.info("收到ACK,rtp/{}开始向上级推流, 目标 {}:{},SSRC={}", sendRtpItem.getStreamId(), sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc()); |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("vhost","__defaultVhost__"); |
| | | param.put("app",sendRtpItem.getApp()); |
| | | param.put("stream",sendRtpItem.getStreamId()); |
| | | param.put("ssrc", sendRtpItem.getSsrc()); |
| | | param.put("src_port", sendRtpItem.getLocalPort()); |
| | | param.put("pt", sendRtpItem.getPt()); |
| | | param.put("use_ps", sendRtpItem.isUsePs() ? "1" : "0"); |
| | | param.put("only_audio", sendRtpItem.isOnlyAudio() ? "1" : "0"); |
| | | if (!sendRtpItem.isTcp() && parentPlatform.isRtcp()) { |
| | | // 开启rtcp保活 |
| | | param.put("udp_rtcp_timeout", "1"); |
| | | } |
| | | if (dialog.getState() == DialogState.CONFIRMED) { |
| | | String platformGbId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(FromHeader.NAME)).getAddress().getURI()).getUser(); |
| | | logger.info("ACK请求: platformGbId->{}", platformGbId); |
| | | ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformGbId); |
| | | // 取消设置的超时任务 |
| | | dynamicTask.stop(callIdHeader.getCallId()); |
| | | // String channelId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(ToHeader.NAME)).getAddress().getURI()).getUser(); |
| | | SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(platformGbId, null, null, callIdHeader.getCallId()); |
| | | String is_Udp = sendRtpItem.isTcp() ? "0" : "1"; |
| | | MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId()); |
| | | logger.info("[收到ACK],开始使用{}向上级推流 {}/{}->{}:{}({})", sendRtpItem.isTcp() ? "TCP" : "UDP", |
| | | sendRtpItem.getApp(), sendRtpItem.getStreamId(), |
| | | sendRtpItem.getIp(), sendRtpItem.getPort(), |
| | | sendRtpItem.getSsrc()); |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("vhost", "__defaultVhost__"); |
| | | param.put("app", sendRtpItem.getApp()); |
| | | param.put("stream", sendRtpItem.getStreamId()); |
| | | param.put("ssrc", sendRtpItem.getSsrc()); |
| | | param.put("src_port", sendRtpItem.getLocalPort()); |
| | | param.put("pt", sendRtpItem.getPt()); |
| | | param.put("use_ps", sendRtpItem.isUsePs() ? "1" : "0"); |
| | | param.put("only_audio", sendRtpItem.isOnlyAudio() ? "1" : "0"); |
| | | if (!sendRtpItem.isTcp() && parentPlatform.isRtcp()) { |
| | | // 开启rtcp保活 |
| | | param.put("udp_rtcp_timeout", "1"); |
| | | } |
| | | JSONObject jsonObject; |
| | | if (sendRtpItem.isTcpActive()) { |
| | | jsonObject = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param); |
| | | } else { |
| | | param.put("is_udp", is_Udp); |
| | | param.put("dst_url", sendRtpItem.getIp()); |
| | | param.put("dst_port", sendRtpItem.getPort()); |
| | | jsonObject = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param); |
| | | } |
| | | |
| | | JSONObject jsonObject; |
| | | if (sendRtpItem.isTcpActive()) { |
| | | jsonObject = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param); |
| | | } else { |
| | | param.put("is_udp", is_Udp); |
| | | param.put("dst_url", sendRtpItem.getIp()); |
| | | param.put("dst_port", sendRtpItem.getPort()); |
| | | jsonObject = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param); |
| | | } |
| | | |
| | | if (jsonObject == null) { |
| | | logger.error("RTP推流失败: 请检查ZLM服务"); |
| | |
| | | // 语音对讲 |
| | | try { |
| | | cmder.streamByeCmd((SIPDialog) evt.getDialog(), sendRtpItem.getChannelId(), (SIPRequest) evt.getRequest(), null); |
| | | } catch (SipException e) { |
| | | throw new RuntimeException(e); |
| | | } catch (ParseException e) { |
| | | throw new RuntimeException(e); |
| | | } catch (InvalidArgumentException e) { |
| | | throw new RuntimeException(e); |
| | | } catch (SipException | ParseException | InvalidArgumentException e) { |
| | | logger.error("[命令发送失败] 停止语音对讲: {}", e.getMessage()); |
| | | } |
| | | } else { |
| | | // 向上级平台 |
| | |
| | | if (jsonObject == null) { |
| | | logger.error("RTP推流失败: 请检查ZLM服务"); |
| | | } else if (jsonObject.getInteger("code") == 0) { |
| | | logger.info("调用ZLM推流接口, 结果: {}", jsonObject); |
| | | logger.info("RTP推流成功[ {}/{} ],{}->{}:{}, " ,param.get("app"), param.get("stream"), jsonObject.getString("local_port"), param.get("dst_url"), param.get("dst_port")); |
| | | byte[] dialogByteArray = SerializeUtils.serialize(evt.getDialog()); |
| | | sendRtpItem.setDialog(dialogByteArray); |
| | | byte[] transactionByteArray = SerializeUtils.serialize(evt.getServerTransaction()); |
| | | sendRtpItem.setTransaction(transactionByteArray); |
| | | redisCatchStorage.updateSendRTPSever(sendRtpItem); |
| | | } else { |
| | | logger.error("RTP推流失败: {}, 参数:{}",jsonObject.getString("msg"),JSONObject.toJSON(param)); |
| | | if (sendRtpItem.isOnlyAudio()) { |
| | |
| | | @Override |
| | | public void process(RequestEvent evt) { |
| | | try { |
| | | responseAck(evt, Response.OK); |
| | | Dialog dialog = evt.getDialog(); |
| | | responseAck(getServerTransaction(evt), Response.OK); |
| | | CallIdHeader callIdHeader = (CallIdHeader)evt.getRequest().getHeader(CallIdHeader.NAME); |
| | | if (dialog == null) { |
| | | return; |
| | | } |
| | | if (dialog.getState().equals(DialogState.TERMINATED)) { |
| | | String platformGbId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(FromHeader.NAME)).getAddress().getURI()).getUser(); |
| | | String channelId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(ToHeader.NAME)).getAddress().getURI()).getUser(); |
| | | SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(platformGbId, null, null, callIdHeader.getCallId()); |
| | | logger.info("收到bye, [{}/{}]", platformGbId, channelId); |
| | | if (sendRtpItem != null ){ |
| | | String streamId = sendRtpItem.getStreamId(); |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("vhost","__defaultVhost__"); |
| | | param.put("app",sendRtpItem.getApp()); |
| | | param.put("stream",streamId); |
| | | param.put("ssrc",sendRtpItem.getSsrc()); |
| | | logger.info("收到bye:停止向上级推流:" + streamId); |
| | | MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId()); |
| | | zlmrtpServerFactory.stopSendRtpStream(mediaInfo, param); |
| | | redisCatchStorage.deleteSendRTPServer(platformGbId, sendRtpItem.getChannelId(), callIdHeader.getCallId(), null); |
| | | redisCatchStorage.deleteSendRTPServer(platformGbId, channelId, callIdHeader.getCallId(), null); |
| | | zlmrtpServerFactory.stopSendRtpStream(mediaInfo, param); |
| | | int totalReaderCount = zlmrtpServerFactory.totalReaderCount(mediaInfo, sendRtpItem.getApp(), streamId); |
| | | if (totalReaderCount <= 0) { |
| | | logger.info("收到bye: {} 无其它观看者,通知设备停止推流", streamId); |
| | | if (sendRtpItem.getPlayType().equals(InviteStreamType.PLAY)) { |
| | | cmder.streamByeCmd(sendRtpItem.getDeviceId(), sendRtpItem.getChannelId(), streamId, null); |
| | | } |
| | | if (sendRtpItem.isOnlyAudio()) { |
| | | playService.stopAudioBroadcast(sendRtpItem.getDeviceId(), sendRtpItem.getChannelId()); |
| | | } |
| | | if (sendRtpItem.getPlayType().equals(InviteStreamType.PUSH)) { |
| | | MessageForPushChannel messageForPushChannel = MessageForPushChannel.getInstance(0, |
| | | sendRtpItem.getApp(), sendRtpItem.getStreamId(), sendRtpItem.getChannelId(), |
| | | sendRtpItem.getPlatformId(), null, null, sendRtpItem.getMediaServerId()); |
| | | redisCatchStorage.sendStreamPushRequestedMsg(messageForPushChannel); |
| | | } |
| | | String platformGbId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(FromHeader.NAME)).getAddress().getURI()).getUser(); |
| | | String channelId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(ToHeader.NAME)).getAddress().getURI()).getUser(); |
| | | SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(platformGbId, channelId, null, callIdHeader.getCallId()); |
| | | logger.info("[收到bye] {}/{}", platformGbId, channelId); |
| | | if (sendRtpItem != null){ |
| | | String streamId = sendRtpItem.getStreamId(); |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("vhost","__defaultVhost__"); |
| | | param.put("app",sendRtpItem.getApp()); |
| | | param.put("stream",streamId); |
| | | param.put("ssrc",sendRtpItem.getSsrc()); |
| | | logger.info("[收到bye] 停止向上级推流:{}", streamId); |
| | | MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId()); |
| | | redisCatchStorage.deleteSendRTPServer(platformGbId, channelId, callIdHeader.getCallId(), null); |
| | | zlmrtpServerFactory.stopSendRtpStream(mediaInfo, param); |
| | | int totalReaderCount = zlmrtpServerFactory.totalReaderCount(mediaInfo, sendRtpItem.getApp(), streamId); |
| | | if (totalReaderCount <= 0) { |
| | | logger.info("[收到bye] {} 无其它观看者,通知设备停止推流", streamId); |
| | | if (sendRtpItem.getPlayType().equals(InviteStreamType.PLAY)) { |
| | | cmder.streamByeCmd(sendRtpItem.getDeviceId(), channelId, streamId, null); |
| | | } |
| | | if (sendRtpItem.isOnlyAudio()) { |
| | | playService.stopAudioBroadcast(sendRtpItem.getDeviceId(), sendRtpItem.getChannelId()); |
| | | } |
| | | if (sendRtpItem.getPlayType().equals(InviteStreamType.PUSH)) { |
| | | MessageForPushChannel messageForPushChannel = MessageForPushChannel.getInstance(0, |
| | | sendRtpItem.getApp(), sendRtpItem.getStreamId(), sendRtpItem.getChannelId(), |
| | | sendRtpItem.getPlatformId(), null, null, sendRtpItem.getMediaServerId()); |
| | | redisCatchStorage.sendStreamPushRequestedMsg(messageForPushChannel); |
| | | } |
| | | } |
| | | // 可能是设备主动停止 |
| | | 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){ |
| | | SIPDialog dialogForPlay = (SIPDialog) SerializeUtils.deSerialize(ssrcTransactionForPlay.getDialog()); |
| | | if (dialogForPlay.getCallId().getCallId().equals(callIdHeader.getCallId())){ |
| | | // 释放ssrc |
| | | MediaServerItem mediaServerItem = mediaServerService.getOne(ssrcTransactionForPlay.getMediaServerId()); |
| | | if (mediaServerItem != null) { |
| | | mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcTransactionForPlay.getSsrc()); |
| | | } |
| | | streamSession.remove(device.getDeviceId(), channelId, ssrcTransactionForPlay.getStream()); |
| | | } |
| | | } |
| | | SsrcTransaction ssrcTransactionForPlayBack = streamSession.getSsrcTransaction(device.getDeviceId(), channelId, callIdHeader.getCallId(), null); |
| | | if (ssrcTransactionForPlayBack != null) { |
| | | } |
| | | // 可能是设备主动停止 |
| | | 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){ |
| | | SIPDialog dialogForPlay = (SIPDialog) SerializeUtils.deSerialize(ssrcTransactionForPlay.getDialog()); |
| | | if (dialogForPlay.getCallId().getCallId().equals(callIdHeader.getCallId())){ |
| | | // 释放ssrc |
| | | MediaServerItem mediaServerItem = mediaServerService.getOne(ssrcTransactionForPlayBack.getMediaServerId()); |
| | | MediaServerItem mediaServerItem = mediaServerService.getOne(ssrcTransactionForPlay.getMediaServerId()); |
| | | if (mediaServerItem != null) { |
| | | mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcTransactionForPlayBack.getSsrc()); |
| | | mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcTransactionForPlay.getSsrc()); |
| | | } |
| | | streamSession.remove(device.getDeviceId(), channelId, ssrcTransactionForPlayBack.getStream()); |
| | | streamSession.remove(device.getDeviceId(), channelId, ssrcTransactionForPlay.getStream()); |
| | | } |
| | | } |
| | | SsrcTransaction ssrcTransactionForPlayBack = streamSession.getSsrcTransaction(device.getDeviceId(), channelId, callIdHeader.getCallId(), null); |
| | | if (ssrcTransactionForPlayBack != null) { |
| | | // 释放ssrc |
| | | MediaServerItem mediaServerItem = mediaServerService.getOne(ssrcTransactionForPlayBack.getMediaServerId()); |
| | | if (mediaServerItem != null) { |
| | | mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcTransactionForPlayBack.getSsrc()); |
| | | } |
| | | streamSession.remove(device.getDeviceId(), channelId, ssrcTransactionForPlayBack.getStream()); |
| | | } |
| | | } |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | |
| | | 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.ISIPCommander; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; |
| | | 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.service.bean.MessageForPushChannel; |
| | | import com.genersoft.iot.vmp.service.bean.SSRCInfo; |
| | | import com.genersoft.iot.vmp.service.impl.RedisGbPlayMsgListener; |
| | | import com.genersoft.iot.vmp.service.impl.RedisPushStreamResponseListener; |
| | | import com.genersoft.iot.vmp.service.redisMsg.RedisGbPlayMsgListener; |
| | | import com.genersoft.iot.vmp.service.redisMsg.RedisPushStreamResponseListener; |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| | | import com.genersoft.iot.vmp.utils.DateUtil; |
| | |
| | | import gov.nist.javax.sdp.fields.TimeField; |
| | | import gov.nist.javax.sip.message.SIPRequest; |
| | | import gov.nist.javax.sip.stack.SIPDialog; |
| | | import gov.nist.javax.sip.message.SIPRequest; |
| | | import gov.nist.javax.sip.message.SIPResponse; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.InitializingBean; |
| | |
| | | String channelId = SipUtils.getChannelIdFromRequest(request); |
| | | String requesterId = SipUtils.getUserIdFromFromHeader(request); |
| | | CallIdHeader callIdHeader = (CallIdHeader) request.getHeader(CallIdHeader.NAME); |
| | | ServerTransaction serverTransaction = getServerTransaction(evt); |
| | | if (requesterId == null || channelId == null) { |
| | | logger.info("无法从FromHeader的Address中获取到平台id,返回400"); |
| | | // 参数不全, 发400,请求错误 |
| | | responseAck(evt, Response.BAD_REQUEST); |
| | | responseAck(serverTransaction, Response.BAD_REQUEST); |
| | | return; |
| | | } |
| | | |
| | | |
| | | // 查询请求是否来自上级平台\设备 |
| | | ParentPlatform platform = storager.queryParentPlatByServerGBId(requesterId); |
| | | if (platform == null) { |
| | | inviteFromDeviceHandle(evt, requesterId, channelId); |
| | | inviteFromDeviceHandle(serverTransaction, requesterId); |
| | | } else { |
| | | // 查询平台下是否有该通道 |
| | | DeviceChannel channel = storager.queryChannelInParentPlatform(requesterId, channelId); |
| | |
| | | StreamProxyItem proxyByAppAndStream =null; |
| | | // 不是通道可能是直播流 |
| | | if (channel != null && gbStream == null) { |
| | | if (channel.getStatus() == 0) { |
| | | logger.info("通道离线,返回400"); |
| | | responseAck(evt, Response.BAD_REQUEST, "channel [" + channel.getChannelId() + "] offline"); |
| | | return; |
| | | } |
| | | responseAck(evt, Response.CALL_IS_BEING_FORWARDED); // 通道存在,发181,呼叫转接中 |
| | | // if (channel.getStatus() == 0) { |
| | | // logger.info("通道离线,返回400"); |
| | | // responseAck(serverTransaction, Response.BAD_REQUEST, "channel [" + channel.getChannelId() + "] offline"); |
| | | // return; |
| | | // } |
| | | // 通道存在,发100,TRYING |
| | | responseAck(serverTransaction, Response.TRYING); |
| | | } else if (channel == null && gbStream != null) { |
| | | |
| | | String mediaServerId = gbStream.getMediaServerId(); |
| | |
| | | if (mediaServerItem == null) { |
| | | if ("proxy".equals(gbStream.getStreamType())) { |
| | | logger.info("[ app={}, stream={} ]找不到zlm {},返回410", gbStream.getApp(), gbStream.getStream(), mediaServerId); |
| | | responseAck(evt, Response.GONE); |
| | | responseAck(serverTransaction, Response.GONE); |
| | | return; |
| | | } else { |
| | | streamPushItem = streamPushService.getPush(gbStream.getApp(), gbStream.getStream()); |
| | | if (streamPushItem == null || streamPushItem.getServerId().equals(userSetting.getServerId())) { |
| | | logger.info("[ app={}, stream={} ]找不到zlm {},返回410", gbStream.getApp(), gbStream.getStream(), mediaServerId); |
| | | responseAck(evt, Response.GONE); |
| | | responseAck(serverTransaction, Response.GONE); |
| | | return; |
| | | } |
| | | } |
| | |
| | | streamPushItem = streamPushService.getPush(gbStream.getApp(), gbStream.getStream()); |
| | | if (streamPushItem == null) { |
| | | logger.info("[ app={}, stream={} ]找不到zlm {},返回410", gbStream.getApp(), gbStream.getStream(), mediaServerId); |
| | | responseAck(evt, Response.GONE); |
| | | responseAck(serverTransaction, Response.GONE); |
| | | return; |
| | | } |
| | | }else if("proxy".equals(gbStream.getStreamType())){ |
| | | proxyByAppAndStream = streamProxyService.getStreamProxyByAppAndStream(gbStream.getApp(), gbStream.getStream()); |
| | | if (proxyByAppAndStream == null) { |
| | | logger.info("[ app={}, stream={} ]找不到zlm {},返回410", gbStream.getApp(), gbStream.getStream(), mediaServerId); |
| | | responseAck(evt, Response.GONE); |
| | | responseAck(serverTransaction, Response.GONE); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | responseAck(evt, Response.CALL_IS_BEING_FORWARDED); // 通道存在,发181,呼叫转接中 |
| | | responseAck(serverTransaction, Response.CALL_IS_BEING_FORWARDED); // 通道存在,发181,呼叫转接中 |
| | | } else if (catalog != null) { |
| | | responseAck(evt, Response.BAD_REQUEST, "catalog channel can not play"); // 目录不支持点播 |
| | | responseAck(serverTransaction, Response.BAD_REQUEST, "catalog channel can not play"); // 目录不支持点播 |
| | | return; |
| | | } else { |
| | | logger.info("通道不存在,返回404"); |
| | | responseAck(evt, Response.NOT_FOUND); // 通道不存在,发404,资源不存在 |
| | | responseAck(serverTransaction, Response.NOT_FOUND); // 通道不存在,发404,资源不存在 |
| | | return; |
| | | } |
| | | // 解析sdp消息, 使用jainsip 自带的sdp解析方式 |
| | |
| | | String ssrc; |
| | | SessionDescription sdp; |
| | | if (ssrcIndex >= 0) { |
| | | //ssrc规定长度为10字节,不取余下长度以避免后续还有“f=”字段 |
| | | //ssrc规定长度为10个字节,不取余下长度以避免后续还有“f=”字段 |
| | | ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12); |
| | | String substring = contentString.substring(0, contentString.indexOf("y=")); |
| | | sdp = SdpFactory.getInstance().createSessionDescription(substring); |
| | |
| | | mediaTransmissionTCP = true; |
| | | if ("active".equalsIgnoreCase(setup)) { |
| | | tcpActive = true; |
| | | // 不支持tcp主动 |
| | | responseAck(evt, Response.NOT_IMPLEMENTED, "tcp active not support"); // 目录不支持点播 |
| | | return; |
| | | } else if ("passive".equalsIgnoreCase(setup)) { |
| | | tcpActive = false; |
| | | } |
| | |
| | | if (port == -1) { |
| | | logger.info("不支持的媒体格式,返回415"); |
| | | // 回复不支持的格式 |
| | | responseAck(evt, Response.UNSUPPORTED_MEDIA_TYPE); // 不支持的格式,发415 |
| | | responseAck(serverTransaction, Response.UNSUPPORTED_MEDIA_TYPE); // 不支持的格式,发415 |
| | | return; |
| | | } |
| | | String username = sdp.getOrigin().getUsername(); |
| | |
| | | device = storager.queryVideoDeviceByPlatformIdAndChannelId(requesterId, channelId); |
| | | if (device == null) { |
| | | logger.warn("点播平台{}的通道{}时未找到设备信息", requesterId, channel); |
| | | responseAck(evt, Response.SERVER_INTERNAL_ERROR); |
| | | responseAck(serverTransaction, Response.SERVER_INTERNAL_ERROR); |
| | | return; |
| | | } |
| | | mediaServerItem = playService.getNewMediaServerItem(device); |
| | | if (mediaServerItem == null) { |
| | | logger.warn("未找到可用的zlm"); |
| | | responseAck(evt, Response.BUSY_HERE); |
| | | responseAck(serverTransaction, Response.BUSY_HERE); |
| | | return; |
| | | } |
| | | SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId, |
| | | device.getDeviceId(), channelId, |
| | | mediaTransmissionTCP); |
| | | |
| | | if (tcpActive != null) { |
| | | sendRtpItem.setTcpActive(tcpActive); |
| | | } |
| | | if (sendRtpItem == null) { |
| | | logger.warn("服务器端口资源不足"); |
| | | responseAck(evt, Response.BUSY_HERE); |
| | | responseAck(serverTransaction, Response.BUSY_HERE); |
| | | return; |
| | | } |
| | | sendRtpItem.setCallId(callIdHeader.getCallId()); |
| | |
| | | // 回复bye |
| | | cmderFroPlatform.streamByeCmd(platform, callIdHeader.getCallId()); |
| | | }, 60 * 1000); |
| | | responseSdpAck(evt, content.toString(), platform); |
| | | responseSdpAck(serverTransaction, content.toString(), platform); |
| | | |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | |
| | | Response response = null; |
| | | try { |
| | | response = getMessageFactory().createResponse(event.statusCode, evt.getRequest()); |
| | | ServerTransaction serverTransaction = getServerTransaction(evt); |
| | | serverTransaction.sendResponse(response); |
| | | System.out.println("未知错误。直接转发设备点播的错误"); |
| | | if (serverTransaction.getDialog() != null) { |
| | | serverTransaction.getDialog().delete(); |
| | | } |
| | |
| | | } |
| | | redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null); |
| | | try { |
| | | responseAck(evt, Response.REQUEST_TIMEOUT); |
| | | responseAck(serverTransaction, Response.REQUEST_TIMEOUT); |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, null, device.isSsrcCheck(), false); |
| | | logger.info(JSONObject.toJSONString(ssrcInfo)); |
| | | sendRtpItem.setStreamId(ssrcInfo.getStream()); |
| | | |
| | | // 写入redis, 超时时回复 |
| | | redisCatchStorage.updateSendRTPSever(sendRtpItem); |
| | | playService.play(mediaServerItem, ssrcInfo, device, channelId, hookEvent, errorEvent, (code, msg) -> { |
| | |
| | | if("push".equals(gbStream.getStreamType())) { |
| | | if (streamPushItem != null && streamPushItem.isPushIng()) { |
| | | // 推流状态 |
| | | pushStream(evt, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | pushStream(evt, serverTransaction, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId); |
| | | } else { |
| | | // 未推流 拉起 |
| | | notifyStreamOnline(evt, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | notifyStreamOnline(evt, serverTransaction,gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId); |
| | | } |
| | | }else if ("proxy".equals(gbStream.getStreamType())){ |
| | | if(null != proxyByAppAndStream &&proxyByAppAndStream.isStatus()){ |
| | | pushProxyStream(evt, gbStream, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | pushProxyStream(evt, serverTransaction, gbStream, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId); |
| | | }else{ |
| | | //开启代理拉流 |
| | | boolean start1 = streamProxyService.start(gbStream.getApp(), gbStream.getStream()); |
| | | if(start1) { |
| | | pushProxyStream(evt, gbStream, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | pushProxyStream(evt, serverTransaction, gbStream, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId); |
| | | }else{ |
| | | //失败后通知 |
| | | notifyStreamOnline(evt, gbStream, null, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | notifyStreamOnline(evt, serverTransaction,gbStream, null, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId); |
| | | } |
| | | } |
| | |
| | | /** |
| | | * 安排推流 |
| | | */ |
| | | private void pushProxyStream(RequestEvent evt, GbStream gbStream, ParentPlatform platform, |
| | | private void pushProxyStream(RequestEvent evt, ServerTransaction serverTransaction, GbStream gbStream, ParentPlatform platform, |
| | | CallIdHeader callIdHeader, MediaServerItem mediaServerItem, |
| | | int port, Boolean tcpActive, boolean mediaTransmissionTCP, |
| | | String channelId, String addressStr, String ssrc, String requesterId) throws InvalidArgumentException, ParseException, SipException { |
| | |
| | | |
| | | if (sendRtpItem == null) { |
| | | logger.warn("服务器端口资源不足"); |
| | | responseAck(evt, Response.BUSY_HERE); |
| | | responseAck(serverTransaction, Response.BUSY_HERE); |
| | | return; |
| | | } |
| | | if (tcpActive != null) { |
| | |
| | | // 写入redis, 超时时回复 |
| | | sendRtpItem.setStatus(1); |
| | | sendRtpItem.setCallId(callIdHeader.getCallId()); |
| | | byte[] dialogByteArray = SerializeUtils.serialize(evt.getDialog()); |
| | | sendRtpItem.setDialog(dialogByteArray); |
| | | byte[] transactionByteArray = SerializeUtils.serialize(evt.getServerTransaction()); |
| | | sendRtpItem.setTransaction(transactionByteArray); |
| | | SIPRequest request = (SIPRequest) evt.getRequest(); |
| | | sendRtpItem.setFromTag(request.getFromTag()); |
| | | |
| | | SIPResponse response = sendStreamAck(mediaServerItem, serverTransaction, sendRtpItem, platform, evt); |
| | | if (response != null) { |
| | | sendRtpItem.setToTag(response.getToTag()); |
| | | } |
| | | redisCatchStorage.updateSendRTPSever(sendRtpItem); |
| | | sendStreamAck(mediaServerItem, sendRtpItem, platform, evt); |
| | | |
| | | } |
| | | |
| | | } |
| | | private void pushStream(RequestEvent evt, GbStream gbStream, StreamPushItem streamPushItem, ParentPlatform platform, |
| | | private void pushStream(RequestEvent evt, ServerTransaction serverTransaction, GbStream gbStream, StreamPushItem streamPushItem, ParentPlatform platform, |
| | | CallIdHeader callIdHeader, MediaServerItem mediaServerItem, |
| | | int port, Boolean tcpActive, boolean mediaTransmissionTCP, |
| | | String channelId, String addressStr, String ssrc, String requesterId) throws InvalidArgumentException, ParseException, SipException { |
| | |
| | | |
| | | if (sendRtpItem == null) { |
| | | logger.warn("服务器端口资源不足"); |
| | | responseAck(evt, Response.BUSY_HERE); |
| | | responseAck(serverTransaction, Response.BUSY_HERE); |
| | | return; |
| | | } |
| | | if (tcpActive != null) { |
| | |
| | | // 写入redis, 超时时回复 |
| | | sendRtpItem.setStatus(1); |
| | | sendRtpItem.setCallId(callIdHeader.getCallId()); |
| | | byte[] dialogByteArray = SerializeUtils.serialize(evt.getDialog()); |
| | | sendRtpItem.setDialog(dialogByteArray); |
| | | byte[] transactionByteArray = SerializeUtils.serialize(evt.getServerTransaction()); |
| | | sendRtpItem.setTransaction(transactionByteArray); |
| | | |
| | | SIPRequest request = (SIPRequest) evt.getRequest(); |
| | | sendRtpItem.setFromTag(request.getFromTag()); |
| | | SIPResponse response = sendStreamAck(mediaServerItem, serverTransaction, sendRtpItem, platform, evt); |
| | | if (response != null) { |
| | | sendRtpItem.setToTag(response.getToTag()); |
| | | } |
| | | |
| | | redisCatchStorage.updateSendRTPSever(sendRtpItem); |
| | | sendStreamAck(mediaServerItem, sendRtpItem, platform, evt); |
| | | |
| | | } else { |
| | | // 不在线 拉起 |
| | | notifyStreamOnline(evt, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | notifyStreamOnline(evt, serverTransaction,gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId); |
| | | } |
| | | |
| | | } else { |
| | | // 其他平台内容 |
| | | otherWvpPushStream(evt, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | otherWvpPushStream(evt, serverTransaction, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId); |
| | | } |
| | | } |
| | | /** |
| | | * 通知流上线 |
| | | */ |
| | | private void notifyStreamOnline(RequestEvent evt, GbStream gbStream, StreamPushItem streamPushItem, ParentPlatform platform, |
| | | private void notifyStreamOnline(RequestEvent evt, ServerTransaction serverTransaction, GbStream gbStream, StreamPushItem streamPushItem, ParentPlatform platform, |
| | | CallIdHeader callIdHeader, MediaServerItem mediaServerItem, |
| | | int port, Boolean tcpActive, boolean mediaTransmissionTCP, |
| | | String channelId, String addressStr, String ssrc, String requesterId) throws InvalidArgumentException, ParseException, SipException { |
| | | if ("proxy".equals(gbStream.getStreamType())) { |
| | | // TODO 控制启用以使设备上线 |
| | | logger.info("[ app={}, stream={} ]通道未推流,启用流后开始推流", gbStream.getApp(), gbStream.getStream()); |
| | | responseAck(evt, Response.BAD_REQUEST, "channel [" + gbStream.getGbId() + "] offline"); |
| | | responseAck(serverTransaction, Response.BAD_REQUEST, "channel [" + gbStream.getGbId() + "] offline"); |
| | | } else if ("push".equals(gbStream.getStreamType())) { |
| | | if (!platform.isStartOfflinePush()) { |
| | | // 平台设置中关闭了拉起离线的推流则直接回复 |
| | | responseAck(evt, Response.TEMPORARILY_UNAVAILABLE, "channel stream not pushing"); |
| | | responseAck(serverTransaction, Response.TEMPORARILY_UNAVAILABLE, "channel stream not pushing"); |
| | | return; |
| | | } |
| | | // 发送redis消息以使设备上线 |
| | |
| | | logger.info("[ app={}, stream={} ] 等待设备开始推流超时", gbStream.getApp(), gbStream.getStream()); |
| | | try { |
| | | mediaListManager.removedChannelOnlineEventLister(gbStream.getApp(), gbStream.getStream()); |
| | | responseAck(evt, Response.REQUEST_TIMEOUT); // 超时 |
| | | responseAck(serverTransaction, Response.REQUEST_TIMEOUT); // 超时 |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | if (sendRtpItem == null) { |
| | | logger.warn("上级点时创建sendRTPItem失败,可能是服务器端口资源不足"); |
| | | try { |
| | | responseAck(evt, Response.BUSY_HERE); |
| | | responseAck(serverTransaction, Response.BUSY_HERE); |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | // 写入redis, 超时时回复 |
| | | sendRtpItem.setStatus(1); |
| | | sendRtpItem.setCallId(callIdHeader.getCallId()); |
| | | byte[] dialogByteArray = SerializeUtils.serialize(evt.getDialog()); |
| | | sendRtpItem.setDialog(dialogByteArray); |
| | | byte[] transactionByteArray = SerializeUtils.serialize(evt.getServerTransaction()); |
| | | sendRtpItem.setTransaction(transactionByteArray); |
| | | |
| | | SIPRequest request = (SIPRequest) evt.getRequest(); |
| | | sendRtpItem.setFromTag(request.getFromTag()); |
| | | SIPResponse response = sendStreamAck(mediaServerItem, serverTransaction, sendRtpItem, platform, evt); |
| | | if (response != null) { |
| | | sendRtpItem.setToTag(response.getToTag()); |
| | | } |
| | | redisCatchStorage.updateSendRTPSever(sendRtpItem); |
| | | sendStreamAck(mediaServerItem, sendRtpItem, platform, evt); |
| | | } else { |
| | | // 其他平台内容 |
| | | otherWvpPushStream(evt, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | otherWvpPushStream(evt, serverTransaction, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId); |
| | | } |
| | | }); |
| | |
| | | dynamicTask.stop(callIdHeader.getCallId()); |
| | | mediaListManager.removedChannelOnlineEventLister(gbStream.getApp(), gbStream.getStream()); |
| | | try { |
| | | responseAck(evt, Response.TEMPORARILY_UNAVAILABLE, response.getMsg()); |
| | | responseAck(serverTransaction, Response.TEMPORARILY_UNAVAILABLE, response.getMsg()); |
| | | } catch (SipException e) { |
| | | throw new RuntimeException(e); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | /** |
| | | * 来自其他wvp的推流 |
| | | */ |
| | | private void otherWvpPushStream(RequestEvent evt, GbStream gbStream, StreamPushItem streamPushItem, ParentPlatform platform, |
| | | private void otherWvpPushStream(RequestEvent evt, ServerTransaction serverTransaction, GbStream gbStream, StreamPushItem streamPushItem, ParentPlatform platform, |
| | | CallIdHeader callIdHeader, MediaServerItem mediaServerItem, |
| | | int port, Boolean tcpActive, boolean mediaTransmissionTCP, |
| | | String channelId, String addressStr, String ssrc, String requesterId) { |
| | |
| | | if (sendRtpItem == null || responseSendItemMsg.getMediaServerItem() == null) { |
| | | logger.warn("服务器端口资源不足"); |
| | | try { |
| | | responseAck(evt, Response.BUSY_HERE); |
| | | responseAck(serverTransaction, Response.BUSY_HERE); |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | // 写入redis, 超时时回复 |
| | | sendRtpItem.setStatus(1); |
| | | sendRtpItem.setCallId(callIdHeader.getCallId()); |
| | | byte[] dialogByteArray = SerializeUtils.serialize(evt.getDialog()); |
| | | sendRtpItem.setDialog(dialogByteArray); |
| | | byte[] transactionByteArray = SerializeUtils.serialize(evt.getServerTransaction()); |
| | | sendRtpItem.setTransaction(transactionByteArray); |
| | | |
| | | SIPRequest request = (SIPRequest) evt.getRequest(); |
| | | sendRtpItem.setFromTag(request.getFromTag()); |
| | | SIPResponse response = sendStreamAck(responseSendItemMsg.getMediaServerItem(), serverTransaction,sendRtpItem, platform, evt); |
| | | if (response != null) { |
| | | sendRtpItem.setToTag(response.getToTag()); |
| | | } |
| | | redisCatchStorage.updateSendRTPSever(sendRtpItem); |
| | | sendStreamAck(responseSendItemMsg.getMediaServerItem(), sendRtpItem, platform, evt); |
| | | }, (wvpResult) -> { |
| | | try { |
| | | // 错误 |
| | |
| | | StreamPushItem currentStreamPushItem = streamPushService.getPush(streamPushItem.getApp(), streamPushItem.getStream()); |
| | | if (currentStreamPushItem.isPushIng()) { |
| | | // 在线状态 |
| | | pushStream(evt, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | pushStream(evt, serverTransaction, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId); |
| | | |
| | | } else { |
| | | // 不在线 拉起 |
| | | notifyStreamOnline(evt, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | notifyStreamOnline(evt, serverTransaction, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| | | mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId); |
| | | } |
| | | } |
| | |
| | | |
| | | |
| | | try { |
| | | responseAck(evt, Response.BUSY_HERE); |
| | | responseAck(serverTransaction, Response.BUSY_HERE); |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | }); |
| | | } |
| | | |
| | | public void sendStreamAck(MediaServerItem mediaServerItem, SendRtpItem sendRtpItem, ParentPlatform platform, RequestEvent evt) { |
| | | public SIPResponse sendStreamAck(MediaServerItem mediaServerItem, ServerTransaction serverTransaction, SendRtpItem sendRtpItem, ParentPlatform platform, RequestEvent evt) { |
| | | |
| | | StringBuffer content = new StringBuffer(200); |
| | | content.append("v=0\r\n"); |
| | |
| | | content.append("f=\r\n"); |
| | | |
| | | try { |
| | | responseSdpAck(evt, content.toString(), platform); |
| | | return responseSdpAck(serverTransaction, content.toString(), platform); |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public void inviteFromDeviceHandle(RequestEvent evt, String requesterId, String channelId) throws InvalidArgumentException, ParseException, SipException, SdpException { |
| | | public void inviteFromDeviceHandle(ServerTransaction serverTransaction, String requesterId, String channelId) throws InvalidArgumentException, ParseException, SipException, SdpException { |
| | | |
| | | // 非上级平台请求,查询是否设备请求(通常为接收语音广播的设备) |
| | | Device device = redisCatchStorage.getDevice(requesterId); |
| | | AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(requesterId, channelId); |
| | | if (audioBroadcastCatch == null) { |
| | | logger.warn("来自设备的Invite请求非语音广播,已忽略,requesterId: {}/{}", requesterId, channelId); |
| | | responseAck(evt, Response.FORBIDDEN); |
| | | responseAck(serverTransaction, Response.FORBIDDEN); |
| | | return; |
| | | } |
| | | Request request = evt.getRequest(); |
| | | Request request = serverTransaction.getRequest(); |
| | | if (device != null) { |
| | | logger.info("收到设备" + requesterId + "的语音广播Invite请求"); |
| | | responseAck(evt, Response.TRYING); |
| | | responseAck(serverTransaction, Response.TRYING); |
| | | |
| | | String contentString = new String(request.getRawContent()); |
| | | String contentString = new String(serverTransaction.getRequest().getRawContent()); |
| | | // jainSip不支持y=字段, 移除移除以解析。 |
| | | String substring = contentString; |
| | | String ssrc = "0000000404"; |
| | |
| | | if (port == -1) { |
| | | logger.info("不支持的媒体格式,返回415"); |
| | | // 回复不支持的格式 |
| | | responseAck(evt, Response.UNSUPPORTED_MEDIA_TYPE); // 不支持的格式,发415 |
| | | responseAck(serverTransaction, Response.UNSUPPORTED_MEDIA_TYPE); // 不支持的格式,发415 |
| | | return; |
| | | } |
| | | String addressStr = sdp.getOrigin().getAddress(); |
| | |
| | | MediaServerItem mediaServerItem = playService.getNewMediaServerItem(device); |
| | | if (mediaServerItem == null) { |
| | | logger.warn("未找到可用的zlm"); |
| | | responseAck(evt, Response.BUSY_HERE); |
| | | responseAck(serverTransaction, Response.BUSY_HERE); |
| | | return; |
| | | } |
| | | SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId, |
| | |
| | | mediaTransmissionTCP); |
| | | if (sendRtpItem == null) { |
| | | logger.warn("服务器端口资源不足"); |
| | | responseAck(evt, Response.BUSY_HERE); |
| | | responseAck(serverTransaction, Response.BUSY_HERE); |
| | | return; |
| | | } |
| | | sendRtpItem.setTcp(mediaTransmissionTCP); |
| | |
| | | parentPlatform.setServerPort(device.getPort()); |
| | | parentPlatform.setServerGBId(device.getDeviceId()); |
| | | |
| | | responseSdpAck(evt, content.toString(), parentPlatform); |
| | | responseSdpAck(serverTransaction, content.toString(), parentPlatform); |
| | | Dialog dialog = evt.getDialog(); |
| | | audioBroadcastCatch.setDialog((SIPDialog) dialog); |
| | | audioBroadcastCatch.setRequest((SIPRequest) request); |
| | | audioBroadcastManager.update(audioBroadcastCatch); |
| | | } catch (SipException e) { |
| | | throw new RuntimeException(e); |
| | | } catch (InvalidArgumentException e) { |
| | | throw new RuntimeException(e); |
| | | } catch (ParseException e) { |
| | | throw new RuntimeException(e); |
| | | } catch (SdpParseException e) { |
| | | throw new RuntimeException(e); |
| | | } catch (SipException | InvalidArgumentException | ParseException | SdpParseException e) { |
| | | logger.error("[命令发送失败] 语音对讲: {}", e.getMessage()); |
| | | } |
| | | }); |
| | | // } |
| | |
| | | resultHolder.invokeAllResult(requestMessage); |
| | | } else { |
| | | logger.warn("来自无效设备/平台的请求"); |
| | | responseAck(evt, Response.BAD_REQUEST); |
| | | responseAck(serverTransaction, Response.BAD_REQUEST); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | import javax.sip.InvalidArgumentException; |
| | | import javax.sip.RequestEvent; |
| | | import javax.sip.ServerTransaction; |
| | | import javax.sip.SipException; |
| | | import javax.sip.header.FromHeader; |
| | | import javax.sip.message.Response; |
| | |
| | | |
| | | private boolean taskQueueHandlerRun = false; |
| | | |
| | | private final ConcurrentLinkedQueue<HandlerCatchData> taskQueue = new ConcurrentLinkedQueue<>(); |
| | | private ConcurrentLinkedQueue<HandlerCatchData> taskQueue = new ConcurrentLinkedQueue<>(); |
| | | |
| | | @Qualifier("taskExecutor") |
| | | @Autowired |
| | |
| | | public void process(RequestEvent evt) { |
| | | try { |
| | | taskQueue.offer(new HandlerCatchData(evt, null, null)); |
| | | responseAck(evt, Response.OK); |
| | | ServerTransaction serverTransaction = getServerTransaction(evt); |
| | | responseAck(serverTransaction, Response.OK); |
| | | if (!taskQueueHandlerRun) { |
| | | taskQueueHandlerRun = true; |
| | | taskExecutor.execute(()-> { |
| | |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| | | import gov.nist.javax.sip.SipProviderImpl; |
| | | import gov.nist.javax.sip.message.SIPRequest; |
| | | import gov.nist.javax.sip.message.SIPResponse; |
| | | import gov.nist.javax.sip.stack.SIPClientTransaction; |
| | | import gov.nist.javax.sip.stack.SIPDialog; |
| | | import gov.nist.javax.sip.stack.SIPServerTransaction; |
| | | import gov.nist.javax.sip.stack.SIPServerTransactionImpl; |
| | | import org.dom4j.DocumentException; |
| | | import org.dom4j.Element; |
| | | import org.slf4j.Logger; |
| | |
| | | @Autowired |
| | | private IVideoManagerStorage storager; |
| | | |
| | | @Lazy |
| | | @Autowired |
| | | @Qualifier(value="tcpSipProvider") |
| | | private SipProviderImpl tcpSipProvider; |
| | | |
| | | @Lazy |
| | | @Autowired |
| | | @Qualifier(value="udpSipProvider") |
| | | private SipProviderImpl udpSipProvider; |
| | | |
| | | @Autowired |
| | | private DynamicTask dynamicTask; |
| | | |
| | | @Autowired |
| | | private UserSetting userSetting; |
| | | |
| | | @Autowired |
| | | private SubscribeHolder subscribeHolder; |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void process(RequestEvent evt) { |
| | | ServerTransaction serverTransaction = getServerTransaction(evt); |
| | | Request request = evt.getRequest(); |
| | | try { |
| | | Element rootElement = getRootElement(evt); |
| | |
| | | } |
| | | String cmd = XmlUtil.getText(rootElement, "CmdType"); |
| | | if (CmdType.MOBILE_POSITION.equals(cmd)) { |
| | | processNotifyMobilePosition(evt, rootElement); |
| | | processNotifyMobilePosition(serverTransaction, rootElement); |
| | | // } else if (CmdType.ALARM.equals(cmd)) { |
| | | // logger.info("接收到Alarm订阅"); |
| | | // processNotifyAlarm(evt, rootElement); |
| | | // processNotifyAlarm(serverTransaction, rootElement); |
| | | } else if (CmdType.CATALOG.equals(cmd)) { |
| | | processNotifyCatalogList(evt, rootElement); |
| | | processNotifyCatalogList(serverTransaction, rootElement); |
| | | } else { |
| | | logger.info("接收到消息:" + cmd); |
| | | |
| | |
| | | ServerTransaction transaction = getServerTransaction(evt); |
| | | if (transaction != null) { |
| | | transaction.sendResponse(response); |
| | | transaction.getDialog().delete(); |
| | | transaction.terminate(); |
| | | } else { |
| | | logger.info("processRequest serverTransactionId is null."); |
| | |
| | | /** |
| | | * 处理移动位置订阅消息 |
| | | */ |
| | | private void processNotifyMobilePosition(RequestEvent evt, Element rootElement) throws SipException { |
| | | String platformId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); |
| | | private void processNotifyMobilePosition(ServerTransaction serverTransaction, Element rootElement) throws SipException { |
| | | if (serverTransaction == null) { |
| | | return; |
| | | } |
| | | String platformId = SipUtils.getUserIdFromFromHeader(serverTransaction.getRequest()); |
| | | String deviceId = XmlUtil.getText(rootElement, "DeviceID"); |
| | | ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId); |
| | | SubscribeInfo subscribeInfo = new SubscribeInfo(evt, platformId); |
| | | SubscribeInfo subscribeInfo = new SubscribeInfo(serverTransaction, platformId); |
| | | if (platform == null) { |
| | | return; |
| | | } |
| | | if (evt.getServerTransaction() == null) { |
| | | ServerTransaction serverTransaction = "TCP".equalsIgnoreCase(platform.getTransport()) ? tcpSipProvider.getNewServerTransaction(evt.getRequest()) |
| | | : udpSipProvider.getNewServerTransaction(evt.getRequest()); |
| | | subscribeInfo.setTransaction(serverTransaction); |
| | | Dialog dialog = serverTransaction.getDialog(); |
| | | dialog.terminateOnBye(false); |
| | | subscribeInfo.setDialog(dialog); |
| | | } |
| | | |
| | | String sn = XmlUtil.getText(rootElement, "SN"); |
| | | logger.info("[回复 移动位置订阅]: {}", platformId); |
| | | logger.info("[回复上级的移动位置订阅请求]: {}", platformId); |
| | | StringBuilder resultXml = new StringBuilder(200); |
| | | resultXml.append("<?xml version=\"1.0\" ?>\r\n") |
| | | .append("<Response>\r\n") |
| | |
| | | }else { |
| | | subscribeInfo.setGpsInterval(Integer.parseInt(interval)); |
| | | } |
| | | |
| | | subscribeInfo.setSn(sn); |
| | | subscribeHolder.putMobilePositionSubscribe(platformId, subscribeInfo); |
| | | |
| | | }else if (subscribeInfo.getExpires() == 0) { |
| | | subscribeHolder.removeMobilePositionSubscribe(platformId); |
| | | } |
| | | |
| | | try { |
| | | ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId); |
| | | responseXmlAck(evt, resultXml.toString(), parentPlatform); |
| | | SIPResponse response = responseXmlAck(serverTransaction, resultXml.toString(), parentPlatform, subscribeInfo.getExpires()); |
| | | if (subscribeInfo.getExpires() == 0) { |
| | | subscribeHolder.removeMobilePositionSubscribe(platformId); |
| | | }else { |
| | | subscribeInfo.setResponse(response); |
| | | subscribeHolder.putMobilePositionSubscribe(platformId, subscribeInfo); |
| | | } |
| | | |
| | | } catch (SipException | InvalidArgumentException | ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | private void processNotifyCatalogList(RequestEvent evt, Element rootElement) throws SipException { |
| | | |
| | | String platformId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); |
| | | private void processNotifyCatalogList(ServerTransaction serverTransaction, Element rootElement) throws SipException { |
| | | if (serverTransaction == null) { |
| | | return; |
| | | } |
| | | String platformId = SipUtils.getUserIdFromFromHeader(serverTransaction.getRequest()); |
| | | String deviceId = XmlUtil.getText(rootElement, "DeviceID"); |
| | | ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId); |
| | | if (platform == null){ |
| | | return; |
| | | } |
| | | SubscribeInfo subscribeInfo = new SubscribeInfo(evt, platformId); |
| | | if (evt.getServerTransaction() == null) { |
| | | ServerTransaction serverTransaction = "TCP".equalsIgnoreCase(platform.getTransport()) ? tcpSipProvider.getNewServerTransaction(evt.getRequest()) |
| | | : udpSipProvider.getNewServerTransaction(evt.getRequest()); |
| | | subscribeInfo.setTransaction(serverTransaction); |
| | | Dialog dialog = serverTransaction.getDialog(); |
| | | dialog.terminateOnBye(false); |
| | | subscribeInfo.setDialog(dialog); |
| | | } |
| | | SubscribeInfo subscribeInfo = new SubscribeInfo(serverTransaction, platformId); |
| | | |
| | | String sn = XmlUtil.getText(rootElement, "SN"); |
| | | logger.info("[回复 目录订阅]: {}/{}", platformId, deviceId); |
| | | logger.info("[回复上级的目录订阅请求]: {}/{}", platformId, deviceId); |
| | | StringBuilder resultXml = new StringBuilder(200); |
| | | resultXml.append("<?xml version=\"1.0\" ?>\r\n") |
| | | .append("<Response>\r\n") |
| | |
| | | } |
| | | try { |
| | | ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId); |
| | | responseXmlAck(evt, resultXml.toString(), parentPlatform); |
| | | SIPResponse response = responseXmlAck(serverTransaction, resultXml.toString(), parentPlatform, subscribeInfo.getExpires()); |
| | | if (subscribeInfo.getExpires() == 0) { |
| | | subscribeHolder.removeCatalogSubscribe(platformId); |
| | | }else { |
| | | subscribeInfo.setResponse(response); |
| | | subscribeHolder.putCatalogSubscribe(platformId, subscribeInfo); |
| | | } |
| | | } catch (SipException | InvalidArgumentException | ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | import org.springframework.stereotype.Component;
|
| | | import javax.sip.InvalidArgumentException;
|
| | | import javax.sip.RequestEvent;
|
| | | import javax.sip.ServerTransaction;
|
| | | import javax.sip.SipException;
|
| | | import javax.sip.header.*;
|
| | | import javax.sip.message.Response;
|
| | |
| | | CallIdHeader callIdHeader = (CallIdHeader)evt.getRequest().getHeader(CallIdHeader.NAME);
|
| | | // 先从会话内查找
|
| | | SsrcTransaction ssrcTransaction = sessionManager.getSsrcTransaction(null, null, callIdHeader.getCallId(), null);
|
| | | if (ssrcTransaction != null) { // 兼容海康 媒体通知 消息from字段不是设备ID的问题
|
| | |
|
| | | // 兼容海康 媒体通知 消息from字段不是设备ID的问题
|
| | | if (ssrcTransaction != null) {
|
| | | deviceId = ssrcTransaction.getDeviceId();
|
| | | }
|
| | | ServerTransaction serverTransaction = getServerTransaction(evt);
|
| | | // 查询设备是否存在
|
| | | Device device = redisCatchStorage.getDevice(deviceId);
|
| | | // 查询上级平台是否存在
|
| | |
| | | }
|
| | | if (device == null && parentPlatform == null) {
|
| | | // 不存在则回复404
|
| | | responseAck(evt, Response.NOT_FOUND, "device "+ deviceId +" not found");
|
| | | responseAck(serverTransaction, Response.NOT_FOUND, "device "+ deviceId +" not found");
|
| | | logger.warn("[设备未找到 ]: {}", deviceId);
|
| | | if (sipSubscribe.getErrorSubscribe(callIdHeader.getCallId()) != null){
|
| | | SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(new DeviceNotFoundEvent(evt.getDialog()));
|
| | |
| | | String streamId = sendRtpItem.getStreamId();
|
| | | StreamInfo streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
|
| | | if (null == streamInfo) {
|
| | | responseAck(evt, Response.NOT_FOUND, "stream " + streamId + " not found");
|
| | | responseAck(serverTransaction, 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(evt, eventResult.statusCode, eventResult.msg);
|
| | | responseAck(serverTransaction, eventResult.statusCode, eventResult.msg);
|
| | | } catch (SipException e) {
|
| | | e.printStackTrace();
|
| | | } catch (InvalidArgumentException e) {
|
| | |
| | | }, eventResult -> {
|
| | | // 成功的回复
|
| | | try {
|
| | | responseAck(evt, eventResult.statusCode);
|
| | | responseAck(serverTransaction, eventResult.statusCode);
|
| | | } catch (SipException e) {
|
| | | e.printStackTrace();
|
| | | } catch (InvalidArgumentException e) {
|
| | |
| | | |
| | | import javax.sip.InvalidArgumentException; |
| | | import javax.sip.RequestEvent; |
| | | import javax.sip.ServerTransaction; |
| | | import javax.sip.SipException; |
| | | import javax.sip.address.SipURI; |
| | | import javax.sip.header.CSeqHeader; |
| | |
| | | if (ssrcTransaction != null) { |
| | | deviceId = ssrcTransaction.getDeviceId(); |
| | | } |
| | | |
| | | ServerTransaction serverTransaction = getServerTransaction(evt); |
| | | |
| | | // 查询设备是否存在 |
| | | Device device = redisCatchStorage.getDevice(deviceId); |
| | | // 查询上级平台是否存在 |
| | |
| | | } |
| | | if (device == null && parentPlatform == null) { |
| | | // 不存在则回复404 |
| | | responseAck(evt, Response.NOT_FOUND, "device "+ deviceId +" not found"); |
| | | responseAck(serverTransaction, Response.NOT_FOUND, "device "+ deviceId +" not found"); |
| | | logger.warn("[设备未找到 ]: {}", deviceId); |
| | | if (sipSubscribe.getErrorSubscribe(callIdHeader.getCallId()) != null){ |
| | | SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(new DeviceNotFoundEvent(evt.getDialog())); |
| | |
| | | rootElement = getRootElement(evt); |
| | | if (rootElement == null) { |
| | | logger.error("处理MESSAGE请求 未获取到消息体{}", evt.getRequest()); |
| | | responseAck(evt, Response.BAD_REQUEST, "content is null"); |
| | | responseAck(serverTransaction, Response.BAD_REQUEST, "content is null"); |
| | | return; |
| | | } |
| | | } catch (DocumentException e) { |
| | | logger.warn("解析XML消息内容异常", e); |
| | | // 不存在则回复404 |
| | | responseAck(evt, Response.BAD_REQUEST, e.getMessage()); |
| | | responseAck(serverTransaction, Response.BAD_REQUEST, e.getMessage()); |
| | | } |
| | | String name = rootElement.getName(); |
| | | IMessageHandler messageHandler = messageHandlerMap.get(name); |
| | |
| | | }else { |
| | | // 不支持的message |
| | | // 不存在则回复415 |
| | | responseAck(evt, Response.UNSUPPORTED_MEDIA_TYPE, "Unsupported message type, must Control/Notify/Query/Response"); |
| | | responseAck(serverTransaction, Response.UNSUPPORTED_MEDIA_TYPE, "Unsupported message type, must Control/Notify/Query/Response"); |
| | | } |
| | | } |
| | | } catch (SipException e) { |
| | |
| | | @Override |
| | | public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) { |
| | | |
| | | ServerTransaction serverTransaction = getServerTransaction(evt); |
| | | |
| | | // 此处是上级发出的DeviceControl指令 |
| | | String targetGBId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(ToHeader.NAME)).getAddress().getURI()).getUser(); |
| | | String channelId = getText(rootElement, "DeviceID"); |
| | |
| | | Device deviceForPlatform = storager.queryVideoDeviceByPlatformIdAndChannelId(parentPlatform.getServerGBId(), channelId); |
| | | if (deviceForPlatform == null) { |
| | | try { |
| | | responseAck(evt, Response.NOT_FOUND); |
| | | responseAck(serverTransaction, Response.NOT_FOUND); |
| | | return; |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | |
| | | cmder.fronEndCmd(deviceForPlatform, channelId, cmdString, eventResult -> { |
| | | // 失败的回复 |
| | | try { |
| | | responseAck(evt, eventResult.statusCode, eventResult.msg); |
| | | responseAck(serverTransaction, eventResult.statusCode, eventResult.msg); |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | }, eventResult -> { |
| | | // 成功的回复 |
| | | try { |
| | | responseAck(evt, eventResult.statusCode); |
| | | responseAck(serverTransaction, eventResult.statusCode); |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.InitializingBean; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.util.StringUtils; |
| | |
| | | import javax.sip.message.Response; |
| | | |
| | | import java.text.ParseException; |
| | | import java.util.concurrent.ConcurrentLinkedQueue; |
| | | |
| | | import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.*; |
| | | |
| | |
| | | @Autowired |
| | | private IDeviceChannelService deviceChannelService; |
| | | |
| | | private boolean taskQueueHandlerRun = false; |
| | | |
| | | private ConcurrentLinkedQueue<SipMsgInfo> taskQueue = new ConcurrentLinkedQueue<>(); |
| | | |
| | | @Qualifier("taskExecutor") |
| | | @Autowired |
| | | private ThreadPoolTaskExecutor taskExecutor; |
| | | |
| | | |
| | | @Override |
| | | public void afterPropertiesSet() throws Exception { |
| | | notifyMessageHandler.addHandler(cmdType, this); |
| | |
| | | @Override |
| | | public void handForDevice(RequestEvent evt, Device device, Element rootElement) { |
| | | logger.info("[收到报警通知]设备:{}", device.getDeviceId()); |
| | | // 回复200 OK |
| | | try { |
| | | responseAck(evt, Response.OK); |
| | | } catch (SipException | InvalidArgumentException | ParseException e) { |
| | | logger.error("[收到报警通知], 回复200OK失败", e); |
| | | } |
| | | |
| | | Element deviceIdElement = rootElement.element("DeviceID"); |
| | | String channelId = deviceIdElement.getText().toString(); |
| | | taskQueue.offer(new SipMsgInfo(evt, device, rootElement)); |
| | | if (!taskQueueHandlerRun) { |
| | | taskQueueHandlerRun = true; |
| | | taskExecutor.execute(() -> { |
| | | logger.info("[处理报警通知]待处理数量:{}", taskQueue.size() ); |
| | | while (!taskQueue.isEmpty()) { |
| | | SipMsgInfo sipMsgInfo = taskQueue.poll(); |
| | | // 回复200 OK |
| | | try { |
| | | responseAck(getServerTransaction(sipMsgInfo.getEvt()), Response.OK); |
| | | } catch (SipException | InvalidArgumentException | ParseException e) { |
| | | logger.error("[处理报警通知], 回复200OK失败", e); |
| | | } |
| | | |
| | | DeviceAlarm deviceAlarm = new DeviceAlarm(); |
| | | deviceAlarm.setCreateTime(DateUtil.getNow()); |
| | | deviceAlarm.setDeviceId(device.getDeviceId()); |
| | | deviceAlarm.setChannelId(channelId); |
| | | deviceAlarm.setAlarmPriority(getText(rootElement, "AlarmPriority")); |
| | | deviceAlarm.setAlarmMethod(getText(rootElement, "AlarmMethod")); |
| | | String alarmTime = XmlUtil.getText(rootElement, "AlarmTime"); |
| | | if (alarmTime == null) { |
| | | return; |
| | | } |
| | | deviceAlarm.setAlarmTime(DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(alarmTime)); |
| | | String alarmDescription = getText(rootElement, "AlarmDescription"); |
| | | if (alarmDescription == null) { |
| | | deviceAlarm.setAlarmDescription(""); |
| | | } else { |
| | | deviceAlarm.setAlarmDescription(alarmDescription); |
| | | } |
| | | String longitude = getText(rootElement, "Longitude"); |
| | | if (longitude != null && NumericUtil.isDouble(longitude)) { |
| | | deviceAlarm.setLongitude(Double.parseDouble(longitude)); |
| | | } else { |
| | | deviceAlarm.setLongitude(0.00); |
| | | } |
| | | String latitude = getText(rootElement, "Latitude"); |
| | | if (latitude != null && NumericUtil.isDouble(latitude)) { |
| | | deviceAlarm.setLatitude(Double.parseDouble(latitude)); |
| | | } else { |
| | | deviceAlarm.setLatitude(0.00); |
| | | } |
| | | Element deviceIdElement = sipMsgInfo.getRootElement().element("DeviceID"); |
| | | String channelId = deviceIdElement.getText().toString(); |
| | | |
| | | if (!ObjectUtils.isEmpty(deviceAlarm.getAlarmMethod())) { |
| | | if ( deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.GPS.getVal() + "")) { |
| | | MobilePosition mobilePosition = new MobilePosition(); |
| | | mobilePosition.setCreateTime(DateUtil.getNow()); |
| | | mobilePosition.setDeviceId(deviceAlarm.getDeviceId()); |
| | | mobilePosition.setTime(deviceAlarm.getAlarmTime()); |
| | | mobilePosition.setLongitude(deviceAlarm.getLongitude()); |
| | | mobilePosition.setLatitude(deviceAlarm.getLatitude()); |
| | | mobilePosition.setReportSource("GPS Alarm"); |
| | | DeviceAlarm deviceAlarm = new DeviceAlarm(); |
| | | deviceAlarm.setCreateTime(DateUtil.getNow()); |
| | | deviceAlarm.setDeviceId(sipMsgInfo.getDevice().getDeviceId()); |
| | | deviceAlarm.setChannelId(channelId); |
| | | deviceAlarm.setAlarmPriority(getText(sipMsgInfo.getRootElement(), "AlarmPriority")); |
| | | deviceAlarm.setAlarmMethod(getText(sipMsgInfo.getRootElement(), "AlarmMethod")); |
| | | String alarmTime = XmlUtil.getText(sipMsgInfo.getRootElement(), "AlarmTime"); |
| | | if (alarmTime == null) { |
| | | continue; |
| | | } |
| | | deviceAlarm.setAlarmTime(DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(alarmTime)); |
| | | String alarmDescription = getText(sipMsgInfo.getRootElement(), "AlarmDescription"); |
| | | if (alarmDescription == null) { |
| | | deviceAlarm.setAlarmDescription(""); |
| | | } else { |
| | | deviceAlarm.setAlarmDescription(alarmDescription); |
| | | } |
| | | String longitude = getText(sipMsgInfo.getRootElement(), "Longitude"); |
| | | if (longitude != null && NumericUtil.isDouble(longitude)) { |
| | | deviceAlarm.setLongitude(Double.parseDouble(longitude)); |
| | | } else { |
| | | deviceAlarm.setLongitude(0.00); |
| | | } |
| | | String latitude = getText(sipMsgInfo.getRootElement(), "Latitude"); |
| | | if (latitude != null && NumericUtil.isDouble(latitude)) { |
| | | deviceAlarm.setLatitude(Double.parseDouble(latitude)); |
| | | } else { |
| | | deviceAlarm.setLatitude(0.00); |
| | | } |
| | | |
| | | // 更新device channel 的经纬度 |
| | | DeviceChannel deviceChannel = new DeviceChannel(); |
| | | deviceChannel.setDeviceId(device.getDeviceId()); |
| | | deviceChannel.setChannelId(channelId); |
| | | deviceChannel.setLongitude(mobilePosition.getLongitude()); |
| | | deviceChannel.setLatitude(mobilePosition.getLatitude()); |
| | | deviceChannel.setGpsTime(mobilePosition.getTime()); |
| | | if (!ObjectUtils.isEmpty(deviceAlarm.getAlarmMethod())) { |
| | | if ( deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.GPS.getVal() + "")) { |
| | | MobilePosition mobilePosition = new MobilePosition(); |
| | | mobilePosition.setCreateTime(DateUtil.getNow()); |
| | | mobilePosition.setDeviceId(deviceAlarm.getDeviceId()); |
| | | mobilePosition.setTime(deviceAlarm.getAlarmTime()); |
| | | mobilePosition.setLongitude(deviceAlarm.getLongitude()); |
| | | mobilePosition.setLatitude(deviceAlarm.getLatitude()); |
| | | mobilePosition.setReportSource("GPS Alarm"); |
| | | |
| | | deviceChannel = deviceChannelService.updateGps(deviceChannel, device); |
| | | // 更新device channel 的经纬度 |
| | | DeviceChannel deviceChannel = new DeviceChannel(); |
| | | deviceChannel.setDeviceId(sipMsgInfo.getDevice().getDeviceId()); |
| | | deviceChannel.setChannelId(channelId); |
| | | deviceChannel.setLongitude(mobilePosition.getLongitude()); |
| | | deviceChannel.setLatitude(mobilePosition.getLatitude()); |
| | | deviceChannel.setGpsTime(mobilePosition.getTime()); |
| | | |
| | | mobilePosition.setLongitudeWgs84(deviceChannel.getLongitudeWgs84()); |
| | | mobilePosition.setLatitudeWgs84(deviceChannel.getLatitudeWgs84()); |
| | | mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02()); |
| | | mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02()); |
| | | deviceChannel = deviceChannelService.updateGps(deviceChannel, sipMsgInfo.getDevice()); |
| | | |
| | | if (userSetting.getSavePositionHistory()) { |
| | | storager.insertMobilePosition(mobilePosition); |
| | | mobilePosition.setLongitudeWgs84(deviceChannel.getLongitudeWgs84()); |
| | | mobilePosition.setLatitudeWgs84(deviceChannel.getLatitudeWgs84()); |
| | | mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02()); |
| | | mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02()); |
| | | |
| | | if (userSetting.getSavePositionHistory()) { |
| | | storager.insertMobilePosition(mobilePosition); |
| | | } |
| | | storager.updateChannelPosition(deviceChannel); |
| | | |
| | | // 发送redis消息。 通知位置信息的变化 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("time", mobilePosition.getTime()); |
| | | jsonObject.put("serial", deviceChannel.getDeviceId()); |
| | | jsonObject.put("code", deviceChannel.getChannelId()); |
| | | jsonObject.put("longitude", mobilePosition.getLongitude()); |
| | | jsonObject.put("latitude", mobilePosition.getLatitude()); |
| | | jsonObject.put("altitude", mobilePosition.getAltitude()); |
| | | jsonObject.put("direction", mobilePosition.getDirection()); |
| | | jsonObject.put("speed", mobilePosition.getSpeed()); |
| | | redisCatchStorage.sendMobilePositionMsg(jsonObject); |
| | | } |
| | | } |
| | | if (!ObjectUtils.isEmpty(deviceAlarm.getDeviceId())) { |
| | | if (deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.Video.getVal() + "")) { |
| | | deviceAlarm.setAlarmType(getText(sipMsgInfo.getRootElement().element("Info"), "AlarmType")); |
| | | } |
| | | } |
| | | logger.info("[收到报警通知]内容:{}", JSONObject.toJSON(deviceAlarm)); |
| | | if ("7".equals(deviceAlarm.getAlarmMethod()) ) { |
| | | // 发送给平台的报警信息。 发送redis通知 |
| | | AlarmChannelMessage alarmChannelMessage = new AlarmChannelMessage(); |
| | | alarmChannelMessage.setAlarmSn(Integer.parseInt(deviceAlarm.getAlarmMethod())); |
| | | alarmChannelMessage.setAlarmDescription(deviceAlarm.getAlarmDescription()); |
| | | alarmChannelMessage.setGbId(channelId); |
| | | redisCatchStorage.sendAlarmMsg(alarmChannelMessage); |
| | | continue; |
| | | } |
| | | |
| | | logger.debug("存储报警信息、报警分类"); |
| | | // 存储报警信息、报警分类 |
| | | if (sipConfig.isAlarm()) { |
| | | deviceAlarmService.add(deviceAlarm); |
| | | } |
| | | |
| | | if (redisCatchStorage.deviceIsOnline(sipMsgInfo.getDevice().getDeviceId())) { |
| | | publisher.deviceAlarmEventPublish(deviceAlarm); |
| | | } |
| | | } |
| | | storager.updateChannelPosition(deviceChannel); |
| | | |
| | | // 发送redis消息。 通知位置信息的变化 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("time", mobilePosition.getTime()); |
| | | jsonObject.put("serial", deviceChannel.getDeviceId()); |
| | | jsonObject.put("code", deviceChannel.getChannelId()); |
| | | jsonObject.put("longitude", mobilePosition.getLongitude()); |
| | | jsonObject.put("latitude", mobilePosition.getLatitude()); |
| | | jsonObject.put("altitude", mobilePosition.getAltitude()); |
| | | jsonObject.put("direction", mobilePosition.getDirection()); |
| | | jsonObject.put("speed", mobilePosition.getSpeed()); |
| | | redisCatchStorage.sendMobilePositionMsg(jsonObject); |
| | | } |
| | | } |
| | | if (!ObjectUtils.isEmpty(deviceAlarm.getDeviceId())) { |
| | | if (deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.Video.getVal() + "")) { |
| | | deviceAlarm.setAlarmType(getText(rootElement.element("Info"), "AlarmType")); |
| | | } |
| | | taskQueueHandlerRun = false; |
| | | }); |
| | | } |
| | | |
| | | if ("7".equals(deviceAlarm.getAlarmMethod()) ) { |
| | | // 发送给平台的报警信息。 发送redis通知 |
| | | AlarmChannelMessage alarmChannelMessage = new AlarmChannelMessage(); |
| | | alarmChannelMessage.setAlarmSn(Integer.parseInt(deviceAlarm.getAlarmMethod())); |
| | | alarmChannelMessage.setAlarmDescription(deviceAlarm.getAlarmDescription()); |
| | | alarmChannelMessage.setGbId(channelId); |
| | | redisCatchStorage.sendAlarmMsg(alarmChannelMessage); |
| | | return; |
| | | } |
| | | |
| | | logger.debug("存储报警信息、报警分类"); |
| | | // 存储报警信息、报警分类 |
| | | if (sipConfig.isAlarm()) { |
| | | deviceAlarmService.add(deviceAlarm); |
| | | } |
| | | |
| | | if (redisCatchStorage.deviceIsOnline(device.getDeviceId())) { |
| | | publisher.deviceAlarmEventPublish(deviceAlarm); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | logger.info("收到来自平台[{}]的报警通知", parentPlatform.getServerGBId()); |
| | | // 回复200 OK |
| | | try { |
| | | responseAck(evt, Response.OK); |
| | | responseAck(getServerTransaction(evt), Response.OK); |
| | | } catch (SipException e) { |
| | | throw new RuntimeException(e); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | } |
| | | device.setKeepaliveTime(DateUtil.getNow()); |
| | | // 回复200 OK |
| | | responseAck(evt, Response.OK); |
| | | responseAck(getServerTransaction(evt), Response.OK); |
| | | if (device.getOnline() == 1) { |
| | | deviceService.updateDevice(device); |
| | | }else { |
| | |
| | | |
| | | // 回复200 OK |
| | | try { |
| | | responseAck(evt, Response.OK); |
| | | responseAck(getServerTransaction(evt), Response.OK); |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.InitializingBean; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.util.StringUtils; |
| | |
| | | import javax.sip.SipException; |
| | | import javax.sip.message.Response; |
| | | import java.text.ParseException; |
| | | import java.util.concurrent.ConcurrentLinkedQueue; |
| | | |
| | | import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; |
| | | |
| | |
| | | @Autowired |
| | | private IDeviceChannelService deviceChannelService; |
| | | |
| | | private boolean taskQueueHandlerRun = false; |
| | | |
| | | private ConcurrentLinkedQueue<SipMsgInfo> taskQueue = new ConcurrentLinkedQueue<>(); |
| | | |
| | | @Qualifier("taskExecutor") |
| | | @Autowired |
| | | private ThreadPoolTaskExecutor taskExecutor; |
| | | |
| | | @Override |
| | | public void afterPropertiesSet() throws Exception { |
| | | notifyMessageHandler.addHandler(cmdType, this); |
| | |
| | | @Override |
| | | public void handForDevice(RequestEvent evt, Device device, Element rootElement) { |
| | | |
| | | try { |
| | | rootElement = getRootElement(evt, device.getCharset()); |
| | | if (rootElement == null) { |
| | | logger.warn("[ 移动设备位置数据通知 ] content cannot be null, {}", evt.getRequest()); |
| | | responseAck(evt, Response.BAD_REQUEST); |
| | | return; |
| | | } |
| | | MobilePosition mobilePosition = new MobilePosition(); |
| | | mobilePosition.setCreateTime(DateUtil.getNow()); |
| | | if (!ObjectUtils.isEmpty(device.getName())) { |
| | | mobilePosition.setDeviceName(device.getName()); |
| | | } |
| | | mobilePosition.setDeviceId(device.getDeviceId()); |
| | | mobilePosition.setChannelId(getText(rootElement, "DeviceID")); |
| | | mobilePosition.setTime(getText(rootElement, "Time")); |
| | | mobilePosition.setLongitude(Double.parseDouble(getText(rootElement, "Longitude"))); |
| | | mobilePosition.setLatitude(Double.parseDouble(getText(rootElement, "Latitude"))); |
| | | if (NumericUtil.isDouble(getText(rootElement, "Speed"))) { |
| | | mobilePosition.setSpeed(Double.parseDouble(getText(rootElement, "Speed"))); |
| | | } else { |
| | | mobilePosition.setSpeed(0.0); |
| | | } |
| | | if (NumericUtil.isDouble(getText(rootElement, "Direction"))) { |
| | | mobilePosition.setDirection(Double.parseDouble(getText(rootElement, "Direction"))); |
| | | } else { |
| | | mobilePosition.setDirection(0.0); |
| | | } |
| | | if (NumericUtil.isDouble(getText(rootElement, "Altitude"))) { |
| | | mobilePosition.setAltitude(Double.parseDouble(getText(rootElement, "Altitude"))); |
| | | } else { |
| | | mobilePosition.setAltitude(0.0); |
| | | } |
| | | mobilePosition.setReportSource("Mobile Position"); |
| | | taskQueue.offer(new SipMsgInfo(evt, device, rootElement)); |
| | | if (!taskQueueHandlerRun) { |
| | | taskQueueHandlerRun = true; |
| | | taskExecutor.execute(() -> { |
| | | while (!taskQueue.isEmpty()) { |
| | | SipMsgInfo sipMsgInfo = taskQueue.poll(); |
| | | try { |
| | | Element rootElementAfterCharset = getRootElement(sipMsgInfo.getEvt(), sipMsgInfo.getDevice().getCharset()); |
| | | if (rootElementAfterCharset == null) { |
| | | logger.warn("[ 移动设备位置数据通知 ] content cannot be null, {}", sipMsgInfo.getEvt().getRequest()); |
| | | responseAck(getServerTransaction(sipMsgInfo.getEvt()), Response.BAD_REQUEST); |
| | | continue; |
| | | } |
| | | MobilePosition mobilePosition = new MobilePosition(); |
| | | mobilePosition.setCreateTime(DateUtil.getNow()); |
| | | if (!ObjectUtils.isEmpty(sipMsgInfo.getDevice().getName())) { |
| | | mobilePosition.setDeviceName(sipMsgInfo.getDevice().getName()); |
| | | } |
| | | mobilePosition.setDeviceId(sipMsgInfo.getDevice().getDeviceId()); |
| | | mobilePosition.setChannelId(getText(rootElementAfterCharset, "DeviceID")); |
| | | mobilePosition.setTime(getText(rootElementAfterCharset, "Time")); |
| | | mobilePosition.setLongitude(Double.parseDouble(getText(rootElementAfterCharset, "Longitude"))); |
| | | mobilePosition.setLatitude(Double.parseDouble(getText(rootElementAfterCharset, "Latitude"))); |
| | | if (NumericUtil.isDouble(getText(rootElementAfterCharset, "Speed"))) { |
| | | mobilePosition.setSpeed(Double.parseDouble(getText(rootElementAfterCharset, "Speed"))); |
| | | } else { |
| | | mobilePosition.setSpeed(0.0); |
| | | } |
| | | if (NumericUtil.isDouble(getText(rootElementAfterCharset, "Direction"))) { |
| | | mobilePosition.setDirection(Double.parseDouble(getText(rootElementAfterCharset, "Direction"))); |
| | | } else { |
| | | mobilePosition.setDirection(0.0); |
| | | } |
| | | if (NumericUtil.isDouble(getText(rootElementAfterCharset, "Altitude"))) { |
| | | mobilePosition.setAltitude(Double.parseDouble(getText(rootElementAfterCharset, "Altitude"))); |
| | | } else { |
| | | mobilePosition.setAltitude(0.0); |
| | | } |
| | | mobilePosition.setReportSource("Mobile Position"); |
| | | |
| | | |
| | | // 更新device channel 的经纬度 |
| | | DeviceChannel deviceChannel = new DeviceChannel(); |
| | | deviceChannel.setDeviceId(device.getDeviceId()); |
| | | deviceChannel.setChannelId(mobilePosition.getChannelId()); |
| | | deviceChannel.setLongitude(mobilePosition.getLongitude()); |
| | | deviceChannel.setLatitude(mobilePosition.getLatitude()); |
| | | deviceChannel.setGpsTime(mobilePosition.getTime()); |
| | | // 更新device channel 的经纬度 |
| | | DeviceChannel deviceChannel = new DeviceChannel(); |
| | | deviceChannel.setDeviceId(sipMsgInfo.getDevice().getDeviceId()); |
| | | deviceChannel.setChannelId(mobilePosition.getChannelId()); |
| | | deviceChannel.setLongitude(mobilePosition.getLongitude()); |
| | | deviceChannel.setLatitude(mobilePosition.getLatitude()); |
| | | deviceChannel.setGpsTime(mobilePosition.getTime()); |
| | | |
| | | deviceChannel = deviceChannelService.updateGps(deviceChannel, device); |
| | | deviceChannel = deviceChannelService.updateGps(deviceChannel, sipMsgInfo.getDevice()); |
| | | |
| | | mobilePosition.setLongitudeWgs84(deviceChannel.getLongitudeWgs84()); |
| | | mobilePosition.setLatitudeWgs84(deviceChannel.getLatitudeWgs84()); |
| | | mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02()); |
| | | mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02()); |
| | | mobilePosition.setLongitudeWgs84(deviceChannel.getLongitudeWgs84()); |
| | | mobilePosition.setLatitudeWgs84(deviceChannel.getLatitudeWgs84()); |
| | | mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02()); |
| | | mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02()); |
| | | |
| | | if (userSetting.getSavePositionHistory()) { |
| | | storager.insertMobilePosition(mobilePosition); |
| | | } |
| | | storager.updateChannelPosition(deviceChannel); |
| | | //回复 200 OK |
| | | responseAck(evt, Response.OK); |
| | | if (userSetting.getSavePositionHistory()) { |
| | | storager.insertMobilePosition(mobilePosition); |
| | | } |
| | | storager.updateChannelPosition(deviceChannel); |
| | | //回复 200 OK |
| | | responseAck(getServerTransaction(sipMsgInfo.getEvt()), Response.OK); |
| | | |
| | | // 发送redis消息。 通知位置信息的变化 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("time", mobilePosition.getTime()); |
| | | jsonObject.put("serial", deviceChannel.getDeviceId()); |
| | | jsonObject.put("code", deviceChannel.getChannelId()); |
| | | jsonObject.put("longitude", mobilePosition.getLongitude()); |
| | | jsonObject.put("latitude", mobilePosition.getLatitude()); |
| | | jsonObject.put("altitude", mobilePosition.getAltitude()); |
| | | jsonObject.put("direction", mobilePosition.getDirection()); |
| | | jsonObject.put("speed", mobilePosition.getSpeed()); |
| | | redisCatchStorage.sendMobilePositionMsg(jsonObject); |
| | | // 发送redis消息。 通知位置信息的变化 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("time", mobilePosition.getTime()); |
| | | jsonObject.put("serial", deviceChannel.getDeviceId()); |
| | | jsonObject.put("code", deviceChannel.getChannelId()); |
| | | jsonObject.put("longitude", mobilePosition.getLongitude()); |
| | | jsonObject.put("latitude", mobilePosition.getLatitude()); |
| | | jsonObject.put("altitude", mobilePosition.getAltitude()); |
| | | jsonObject.put("direction", mobilePosition.getDirection()); |
| | | jsonObject.put("speed", mobilePosition.getSpeed()); |
| | | redisCatchStorage.sendMobilePositionMsg(jsonObject); |
| | | |
| | | } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { |
| | | e.printStackTrace(); |
| | | } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | taskQueueHandlerRun = false; |
| | | }); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | logger.info("不支持alarm查询"); |
| | | try { |
| | | responseAck(evt, Response.NOT_FOUND, "not support alarm query"); |
| | | responseAck(getServerTransaction(evt), Response.NOT_FOUND, "not support alarm query"); |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME); |
| | | try { |
| | | // 回复200 OK |
| | | responseAck(evt, Response.OK); |
| | | responseAck(getServerTransaction(evt), Response.OK); |
| | | Element snElement = rootElement.element("SN"); |
| | | String sn = snElement.getText(); |
| | | // 准备回复通道信息 |
| | |
| | | FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME); |
| | | try { |
| | | // 回复200 OK |
| | | responseAck(evt, Response.OK); |
| | | responseAck(getServerTransaction(evt), Response.OK); |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME); |
| | | // 回复200 OK |
| | | try { |
| | | responseAck(evt, Response.OK); |
| | | responseAck(getServerTransaction(evt), Response.OK); |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | |
| | | import javax.sip.InvalidArgumentException; |
| | | import javax.sip.RequestEvent; |
| | | import javax.sip.ServerTransaction; |
| | | import javax.sip.SipException; |
| | | import javax.sip.header.FromHeader; |
| | | import javax.sip.message.Response; |
| | |
| | | public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) { |
| | | |
| | | FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME); |
| | | |
| | | ServerTransaction serverTransaction = getServerTransaction(evt); |
| | | Element snElement = rootElement.element("SN"); |
| | | int sn = Integer.parseInt(snElement.getText()); |
| | | Element deviceIDElement = rootElement.element("DeviceID"); |
| | |
| | | DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(endTime), sn, secrecy, type, (eventResult -> { |
| | | // 回复200 OK |
| | | try { |
| | | responseAck(evt, Response.OK); |
| | | responseAck(serverTransaction, Response.OK); |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | }),(eventResult -> { |
| | | // 查询失败 |
| | | try { |
| | | responseAck(evt, eventResult.statusCode, eventResult.msg); |
| | | responseAck(serverTransaction, eventResult.statusCode, eventResult.msg); |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | }else if (channelSources.get(1).getCount() > 0) { // 直播流 |
| | | // TODO |
| | | try { |
| | | responseAck(evt, Response.NOT_IMPLEMENTED); // 回复未实现 |
| | | responseAck(serverTransaction, Response.NOT_IMPLEMENTED); // 回复未实现 |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | } |
| | | }else { // 错误的请求 |
| | | try { |
| | | responseAck(evt, Response.BAD_REQUEST); |
| | | responseAck(serverTransaction, Response.BAD_REQUEST); |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | |
| | | import javax.sip.InvalidArgumentException; |
| | | import javax.sip.RequestEvent; |
| | | import javax.sip.ServerTransaction; |
| | | import javax.sip.SipException; |
| | | import javax.sip.message.Response; |
| | | import java.text.ParseException; |
| | |
| | | |
| | | import javax.sip.InvalidArgumentException; |
| | | import javax.sip.RequestEvent; |
| | | import javax.sip.ServerTransaction; |
| | | import javax.sip.SipException; |
| | | import javax.sip.message.Response; |
| | | import java.text.ParseException; |
| | |
| | | taskQueue.offer(new HandlerCatchData(evt, device, element)); |
| | | // 回复200 OK |
| | | try { |
| | | responseAck(evt, Response.OK); |
| | | ServerTransaction serverTransaction = getServerTransaction(evt); |
| | | responseAck(serverTransaction, Response.OK); |
| | | if (!taskQueueHandlerRun) { |
| | | taskQueueHandlerRun = true; |
| | | taskExecutor.execute(()-> { |
| | |
| | | Element sumNumElement = rootElement.element("SumNum"); |
| | | Element snElement = rootElement.element("SN"); |
| | | if (snElement == null || sumNumElement == null || deviceListElement == null) { |
| | | responseAck(take.getEvt(), Response.BAD_REQUEST, "xml error"); |
| | | responseAck(serverTransaction, Response.BAD_REQUEST, "xml error"); |
| | | continue; |
| | | } |
| | | int sumNum = Integer.parseInt(sumNumElement.getText()); |
| | |
| | | String key = DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + device.getDeviceId() + channelId; |
| | | try { |
| | | // 回复200 OK |
| | | responseAck(evt, Response.OK); |
| | | responseAck(getServerTransaction(evt), Response.OK); |
| | | // 此处是对本平台发出DeviceControl指令的应答 |
| | | JSONObject json = new JSONObject(); |
| | | XmlUtil.node2Json(element, json); |
| | |
| | | public void handForDevice(RequestEvent evt, Device device, Element element) { |
| | | // 此处是对本平台发出DeviceControl指令的应答 |
| | | try { |
| | | responseAck(evt, Response.OK); |
| | | responseAck(getServerTransaction(evt), Response.OK); |
| | | JSONObject json = new JSONObject(); |
| | | String channelId = getText(element, "DeviceID"); |
| | | XmlUtil.node2Json(element, json); |
| | |
| | | |
| | | import javax.sip.InvalidArgumentException; |
| | | import javax.sip.RequestEvent; |
| | | import javax.sip.ServerTransaction; |
| | | import javax.sip.SipException; |
| | | import javax.sip.message.Response; |
| | | import java.text.ParseException; |
| | |
| | | logger.warn("[接收到DeviceInfo应答消息,但是设备已经离线]:" + (device != null ? device.getDeviceId():"" )); |
| | | return; |
| | | } |
| | | ServerTransaction serverTransaction = getServerTransaction(evt); |
| | | try { |
| | | rootElement = getRootElement(evt, device.getCharset()); |
| | | if (rootElement == null) { |
| | | logger.warn("[ 接收到DeviceInfo应答消息 ] content cannot be null, {}", evt.getRequest()); |
| | | responseAck(evt, Response.BAD_REQUEST); |
| | | responseAck(serverTransaction, Response.BAD_REQUEST); |
| | | return; |
| | | } |
| | | Element deviceIdElement = rootElement.element("DeviceID"); |
| | |
| | | msg.setData(device); |
| | | deferredResultHolder.invokeAllResult(msg); |
| | | // 回复200 OK |
| | | responseAck(evt, Response.OK); |
| | | responseAck(serverTransaction, Response.OK); |
| | | } catch (DocumentException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | } |
| | | // 回复200 OK |
| | | try { |
| | | responseAck(evt, Response.OK); |
| | | responseAck(getServerTransaction(evt), Response.OK); |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | |
| | | import javax.sip.InvalidArgumentException; |
| | | import javax.sip.RequestEvent; |
| | | import javax.sip.ServerTransaction; |
| | | import javax.sip.SipException; |
| | | import javax.sip.message.Response; |
| | | import java.text.ParseException; |
| | |
| | | @Override |
| | | public void handForDevice(RequestEvent evt, Device device, Element rootElement) { |
| | | |
| | | ServerTransaction serverTransaction = getServerTransaction(evt); |
| | | |
| | | try { |
| | | rootElement = getRootElement(evt, device.getCharset()); |
| | | if (rootElement == null) { |
| | | logger.warn("[ 移动设备位置数据查询回复 ] content cannot be null, {}", evt.getRequest()); |
| | | responseAck(evt, Response.BAD_REQUEST); |
| | | responseAck(serverTransaction, Response.BAD_REQUEST); |
| | | return; |
| | | } |
| | | MobilePosition mobilePosition = new MobilePosition(); |
| | |
| | | jsonObject.put("speed", mobilePosition.getSpeed()); |
| | | redisCatchStorage.sendMobilePositionMsg(jsonObject); |
| | | //回复 200 OK |
| | | responseAck(evt, Response.OK); |
| | | responseAck(serverTransaction, Response.OK); |
| | | } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | |
| | | import javax.sip.InvalidArgumentException; |
| | | import javax.sip.RequestEvent; |
| | | import javax.sip.ServerTransaction; |
| | | import javax.sip.SipException; |
| | | import javax.sip.message.Response; |
| | | import java.text.ParseException; |
| | |
| | | public void handForDevice(RequestEvent evt, Device device, Element element) { |
| | | Element rootElement = null; |
| | | try { |
| | | |
| | | ServerTransaction serverTransaction = getServerTransaction(evt); |
| | | |
| | | rootElement = getRootElement(evt, device.getCharset()); |
| | | if (rootElement == null) { |
| | | logger.warn("[ 设备预置位查询应答 ] content cannot be null, {}", evt.getRequest()); |
| | | responseAck(evt, Response.BAD_REQUEST); |
| | | responseAck(serverTransaction, Response.BAD_REQUEST); |
| | | return; |
| | | } |
| | | Element presetListNumElement = rootElement.element("PresetList"); |
| | |
| | | String deviceId = getText(rootElement, "DeviceID"); |
| | | String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + deviceId; |
| | | if (snElement == null || presetListNumElement == null) { |
| | | responseAck(evt, Response.BAD_REQUEST, "xml error"); |
| | | responseAck(serverTransaction, Response.BAD_REQUEST, "xml error"); |
| | | return; |
| | | } |
| | | int sumNum = Integer.parseInt(presetListNumElement.attributeValue("Num")); |
| | |
| | | requestMessage.setKey(key); |
| | | requestMessage.setData(presetQuerySipReqList); |
| | | deferredResultHolder.invokeAllResult(requestMessage); |
| | | responseAck(evt, Response.OK); |
| | | responseAck(serverTransaction, Response.OK); |
| | | } catch (DocumentException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | |
| | | |
| | | // 回复200 OK |
| | | try { |
| | | responseAck(evt, Response.OK); |
| | | responseAck(getServerTransaction(evt), Response.OK); |
| | | taskQueue.offer(new HandlerCatchData(evt, device, rootElement)); |
| | | if (!taskQueueHandlerRun) { |
| | | taskQueueHandlerRun = true; |
| | |
| | | import com.genersoft.iot.vmp.gb28181.utils.SipUtils; |
| | | import com.genersoft.iot.vmp.utils.GitUtil; |
| | | import gov.nist.javax.sip.ResponseEventExt; |
| | | import gov.nist.javax.sip.message.SIPResponse; |
| | | import gov.nist.javax.sip.stack.SIPClientTransaction; |
| | | import gov.nist.javax.sip.stack.SIPDialog; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | // 下发ack |
| | | if (statusCode == Response.OK) { |
| | | ResponseEventExt event = (ResponseEventExt)evt; |
| | | SIPDialog dialog = (SIPDialog)evt.getDialog(); |
| | | SIPDialog dialog = new SIPDialog((SIPClientTransaction) event.getClientTransaction(), (SIPResponse) event.getResponse()); |
| | | CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME); |
| | | Request reqAck = dialog.createAck(cseq.getSeqNumber()); |
| | | SipURI requestURI = (SipURI) reqAck.getRequestURI(); |
| | |
| | | @PostMapping(value = "/on_server_keepalive", produces = "application/json;charset=UTF-8")
|
| | | public JSONObject onServerKeepalive(@RequestBody JSONObject json){
|
| | |
|
| | | logger.info("[ ZLM HOOK ] on_server_keepalive API调用,参数:" + json.toString());
|
| | | logger.info("[ ZLM HOOK ]on_server_keepalive API调用,参数:" + json.toString());
|
| | | String mediaServerId = json.getString("mediaServerId");
|
| | | List<ZlmHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_server_keepalive);
|
| | | if (subscribes != null && subscribes.size() > 0) {
|
| | |
| | | String schema = item.getSchema();
|
| | | List<MediaItem.MediaTrack> tracks = item.getTracks();
|
| | | boolean regist = item.isRegist();
|
| | | if (item.getOriginType() == OriginType.RTMP_PUSH.ordinal()
|
| | | || item.getOriginType() == OriginType.RTSP_PUSH.ordinal()
|
| | | || item.getOriginType() == OriginType.RTC_PUSH.ordinal()) {
|
| | | if (regist) {
|
| | | if (regist) {
|
| | | if (item.getOriginType() == OriginType.RTMP_PUSH.ordinal()
|
| | | || item.getOriginType() == OriginType.RTSP_PUSH.ordinal()
|
| | | || item.getOriginType() == OriginType.RTC_PUSH.ordinal()) {
|
| | |
|
| | | StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream);
|
| | | if (streamAuthorityInfo == null) {
|
| | | streamAuthorityInfo = StreamAuthorityInfo.getInstanceByHook(item);
|
| | |
| | | streamAuthorityInfo.setOriginTypeStr(item.getOriginTypeStr());
|
| | | }
|
| | | redisCatchStorage.updateStreamAuthorityInfo(app, stream, streamAuthorityInfo);
|
| | | }else {
|
| | | redisCatchStorage.removeStreamAuthorityInfo(app, stream);
|
| | | }
|
| | | }else {
|
| | | redisCatchStorage.removeStreamAuthorityInfo(app, stream);
|
| | | }
|
| | |
|
| | | if ("rtsp".equals(schema)){
|
| | |
| | | if (streamInfo!=null){
|
| | | redisCatchStorage.stopPlay(streamInfo);
|
| | | storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
|
| | | // 如果正在给上级推送,则发送bye
|
| | |
|
| | | }else{
|
| | | streamInfo = redisCatchStorage.queryPlayback(null, null, stream, null);
|
| | | if (streamInfo != null) {
|
| | | redisCatchStorage.stopPlayback(streamInfo.getDeviceID(), streamInfo.getChannelId(),
|
| | | streamInfo.getStream(), null);
|
| | | }
|
| | | // 如果正在给上级推送,则发送bye
|
| | | }
|
| | | }else {
|
| | | if (!"rtp".equals(app)){
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | if (!regist) {
|
| | | List<SendRtpItem> sendRtpItems = redisCatchStorage.querySendRTPServerByStream(stream);
|
| | | if (sendRtpItems.size() > 0) {
|
| | | for (SendRtpItem sendRtpItem : sendRtpItems) {
|
| | | if (sendRtpItem.getApp().equals(app)) {
|
| | | String platformId = sendRtpItem.getPlatformId();
|
| | | ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId);
|
| | |
|
| | | commanderFroPlatform.streamByeCmd(platform, sendRtpItem);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | JSONObject ret = new JSONObject();
|
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.text.ParseException; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | |
| | | } |
| | | if (transform != null) { |
| | | if (getChannelOnlineEventLister(transform.getApp(), transform.getStream()) != null) { |
| | | getChannelOnlineEventLister(transform.getApp(), transform.getStream()).run(transform.getApp(), transform.getStream(), transform.getServerId()); |
| | | try { |
| | | getChannelOnlineEventLister(transform.getApp(), transform.getStream()).run(transform.getApp(), transform.getStream(), transform.getServerId()); |
| | | } catch (ParseException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | removedChannelOnlineEventLister(transform.getApp(), transform.getStream()); |
| | | } |
| | | } |
| | |
| | | // 查看推流状态 |
| | | if (zlmrtpServerFactory.isStreamReady(mediaServerItem, app, stream)) { |
| | | if (getChannelOnlineEventLister(app, stream) != null) { |
| | | getChannelOnlineEventLister(app, stream).run(app, stream, mediaServerId); |
| | | try { |
| | | getChannelOnlineEventLister(app, stream).run(app, stream, mediaServerId); |
| | | } catch (ParseException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | removedChannelOnlineEventLister(app, stream); |
| | | } |
| | | } |
| | |
| | | result = rtpInfo.getInteger("local_port"); |
| | | if (result == 0) { |
| | | // 此时说明rtpServer已经创建但是流还没有推上来 |
| | | |
| | | // 此时重新打开rtpServer |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("stream_id", streamId); |
| | | JSONObject jsonObject = zlmresTfulUtils.closeRtpServer(mediaServerItem, param); |
| | | if (jsonObject != null ) { |
| | | System.out.println(jsonObject); |
| | | if (jsonObject.getInteger("code") == 0) { |
| | | return createRTPServer(mediaServerItem, streamId, ssrc, port); |
| | | }else { |
| | | logger.warn("[开启rtpServer], 重启RtpServer错误"); |
| | | } |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | |
| | | Boolean result = false; |
| | | JSONObject jsonObject = zlmresTfulUtils.stopSendRtp(mediaServerItem, param); |
| | | if (jsonObject == null) { |
| | | logger.error("停止RTP推流失败: 请检查ZLM服务"); |
| | | logger.error("[停止RTP推流] 失败: 请检查ZLM服务"); |
| | | } else if (jsonObject.getInteger("code") == 0) { |
| | | result= true; |
| | | logger.info("停止RTP推流成功"); |
| | | logger.info("[停止RTP推流] 成功"); |
| | | } else { |
| | | logger.error("停止RTP推流失败: {}, 参数:{}",jsonObject.getString("msg"),JSONObject.toJSON(param)); |
| | | logger.error("[停止RTP推流] 失败: {}, 参数:{}->\r\n{}",jsonObject.getString("msg"),JSONObject.toJSON(param), jsonObject); |
| | | } |
| | | return result; |
| | | } |
| | |
| | | }, 60 * 1000 ); |
| | | } |
| | | |
| | | @Async |
| | | @Async("taskExecutor") |
| | | public void connectZlmServer(MediaServerItem mediaServerItem){ |
| | | String connectZlmServerTaskKey = "connect-zlm-" + mediaServerItem.getId(); |
| | | ZLMServerConfig zlmServerConfigFirst = getMediaServerConfig(mediaServerItem); |
| | |
| | | @Scheduled(cron="0 0/5 * * * ?") //每5分钟执行一次 |
| | | public void execute(){ |
| | | |
| | | logger.info("[hook订阅] 清理"); |
| | | |
| | | Instant instant = Instant.now().minusMillis(TimeUnit.MINUTES.toMillis(5)); |
| | | int total = 0; |
| | | for (HookType hookType : allSubscribes.keySet()) { |
| | |
| | | } |
| | | } |
| | | } |
| | | logger.info("[hook订阅] 清理结束,共清理{}条过期数据", total); |
| | | } |
| | | } |
| | |
| | | package com.genersoft.iot.vmp.media.zlm.dto; |
| | | |
| | | import java.text.ParseException; |
| | | |
| | | /** |
| | | * @author lin |
| | | */ |
| | | public interface ChannelOnlineEvent { |
| | | |
| | | void run(String app, String stream, String serverId); |
| | | void run(String app, String stream, String serverId) throws ParseException; |
| | | } |
| | |
| | | @Autowired |
| | | private IPlayService playService; |
| | | |
| | | @Async |
| | | @Async("taskExecutor") |
| | | @EventListener |
| | | public void onApplicationEvent(ZLMOnlineEvent event) { |
| | | logger.info("[ZLM] 上线 ID:" + event.getMediaServerId()); |
| | |
| | | playService.zlmServerOnline(event.getMediaServerId()); |
| | | } |
| | | |
| | | @Async |
| | | @Async("taskExecutor") |
| | | @EventListener |
| | | public void onApplicationEvent(ZLMOfflineEvent event) { |
| | | |
| | |
| | | package com.genersoft.iot.vmp.service; |
| | | |
| | | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; |
| | | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| | | import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo; |
| | | import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; |
| | | import com.github.pagehelper.PageInfo; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 国标平台的业务类 |
| | |
| | | * @param parentPlatform |
| | | */ |
| | | void login(ParentPlatform parentPlatform); |
| | | |
| | | /** |
| | | * 向上级平台发送位置订阅 |
| | | * @param platformId 平台 |
| | | */ |
| | | void sendNotifyMobilePosition(String platformId); |
| | | } |
| | |
| | | result = platformChannelMapper.addChannels(platformId, channelReducesToAdd); |
| | | // TODO 后续给平台增加控制开关以控制是否响应目录订阅 |
| | | List<DeviceChannel> deviceChannelList = getDeviceChannelListByChannelReduceList(channelReducesToAdd, catalogId, platform); |
| | | eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD); |
| | | if (deviceChannelList != null) { |
| | | eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD); |
| | | } |
| | | } |
| | | |
| | | return result; |
| | |
| | | List<DeviceChannel> deviceChannelList = new ArrayList<>(); |
| | | if (channelReduces.size() > 0){ |
| | | PlatformCatalog catalog = catalogManager.select(catalogId); |
| | | if (catalog == null && !catalogId.equals(platform.getServerGBId())) { |
| | | if (catalog == null && !catalogId.equals(platform.getDeviceGBId())) { |
| | | logger.warn("未查询到目录{}的信息", catalogId); |
| | | return null; |
| | | } |
| | |
| | | package com.genersoft.iot.vmp.service.impl; |
| | | |
| | | import com.genersoft.iot.vmp.conf.DynamicTask; |
| | | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| | | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch; |
| | | import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; |
| | | import com.genersoft.iot.vmp.gb28181.bean.SubscribeHolder; |
| | | 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.transmit.cmd.impl.SIPCommanderFroPlatform; |
| | | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; |
| | | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| | | import com.genersoft.iot.vmp.service.IMediaServerService; |
| | | import com.genersoft.iot.vmp.service.IPlatformService; |
| | | import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.storager.dao.GbStreamMapper; |
| | | import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | |
| | | |
| | | @Autowired |
| | | private SubscribeHolder subscribeHolder; |
| | | |
| | | @Autowired |
| | | private GbStreamMapper gbStreamMapper; |
| | | |
| | | @Autowired |
| | | private UserSetting userSetting; |
| | | |
| | | |
| | | |
| | |
| | | 60*1000); |
| | | }, null); |
| | | } |
| | | |
| | | @Override |
| | | public void sendNotifyMobilePosition(String platformId) { |
| | | ParentPlatform platform = platformMapper.getParentPlatByServerGBId(platformId); |
| | | if (platform == null) { |
| | | return; |
| | | } |
| | | SubscribeInfo subscribe = subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId()); |
| | | if (subscribe != null) { |
| | | |
| | | // TODO 暂时只处理视频流的回复,后续增加对国标设备的支持 |
| | | List<DeviceChannel> gbStreams = gbStreamMapper.queryGbStreamListInPlatform(platform.getServerGBId(), userSetting.isUsePushingAsStatus()); |
| | | if (gbStreams.size() == 0) { |
| | | return; |
| | | } |
| | | for (DeviceChannel deviceChannel : gbStreams) { |
| | | String gbId = deviceChannel.getChannelId(); |
| | | GPSMsgInfo gpsMsgInfo = redisCatchStorage.getGpsMsgInfo(gbId); |
| | | // 无最新位置不发送 |
| | | if (gpsMsgInfo != null) { |
| | | // 经纬度都为0不发送 |
| | | if (gpsMsgInfo.getLng() == 0 && gpsMsgInfo.getLat() == 0) { |
| | | continue; |
| | | } |
| | | // 发送GPS消息 |
| | | commanderForPlatform.sendNotifyMobilePosition(platform, gpsMsgInfo, subscribe); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | }); |
| | | }); |
| | | |
| | | if (streamInfo != null) { |
| | | String streamId = streamInfo.getStream(); |
| | | if (streamId == null) { |
| | |
| | | if (ssrcInfo == null) { |
| | | ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, device.isSsrcCheck(), false); |
| | | } |
| | | logger.info("[点播开始] deviceId: {}, channelId: {}, SSRC: {}", device.getDeviceId(), channelId, ssrcInfo.getSsrc() ); |
| | | logger.info("[点播开始] deviceId: {}, channelId: {},收流端口: {}, 收流模式:{}, SSRC: {}, SSRC校验:{}", device.getDeviceId(), channelId, ssrcInfo.getPort(), device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck() ); |
| | | // 超时处理 |
| | | String timeOutTaskKey = UUID.randomUUID().toString(); |
| | | SSRCInfo finalSsrcInfo = ssrcInfo; |
| | |
| | | |
| | | SIPDialog dialog = streamSession.getDialogByStream(device.getDeviceId(), channelId, finalSsrcInfo.getStream()); |
| | | if (dialog != null) { |
| | | logger.info("[点播超时] 收流超时 deviceId: {}, channelId: {}", device.getDeviceId(), channelId); |
| | | logger.info("[点播超时] 收流超时 deviceId: {}, channelId: {},端口:{}, SSRC: {}", device.getDeviceId(), channelId, finalSsrcInfo.getPort(), finalSsrcInfo.getSsrc()); |
| | | timeoutCallback.run(1, "收流超时"); |
| | | // 点播超时回复BYE 同时释放ssrc以及此次点播的资源 |
| | | cmder.streamByeCmd(device.getDeviceId(), channelId, finalSsrcInfo.getStream(), null); |
| | | }else { |
| | | logger.info("[点播超时] 消息未响应 deviceId: {}, channelId: {}", device.getDeviceId(), channelId); |
| | | logger.info("[点播超时] 消息未响应 deviceId: {}, channelId: {},端口:{}, SSRC: {}", device.getDeviceId(), channelId, finalSsrcInfo.getPort(), finalSsrcInfo.getSsrc()); |
| | | timeoutCallback.run(0, "点播超时"); |
| | | mediaServerService.releaseSsrc(mediaServerItem.getId(), finalSsrcInfo.getSsrc()); |
| | | mediaServerService.closeRTPServer(mediaServerItem, finalSsrcInfo.getStream()); |
New file |
| | |
| | | package com.genersoft.iot.vmp.service.redisMsg; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.genersoft.iot.vmp.gb28181.bean.*; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| | | import com.genersoft.iot.vmp.utils.DateUtil; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.data.redis.connection.Message; |
| | | import org.springframework.data.redis.connection.MessageListener; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import javax.validation.constraints.NotNull; |
| | | import java.util.List; |
| | | import java.util.concurrent.ConcurrentLinkedQueue; |
| | | |
| | | |
| | | @Component |
| | | public class RedisAlarmMsgListener implements MessageListener { |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(RedisAlarmMsgListener.class); |
| | | |
| | | @Autowired |
| | | private ISIPCommander commander; |
| | | |
| | | @Autowired |
| | | private ISIPCommanderForPlatform commanderForPlatform; |
| | | |
| | | @Autowired |
| | | private IVideoManagerStorage storage; |
| | | |
| | | private boolean taskQueueHandlerRun = false; |
| | | |
| | | private ConcurrentLinkedQueue<Message> taskQueue = new ConcurrentLinkedQueue<>(); |
| | | |
| | | @Qualifier("taskExecutor") |
| | | @Autowired |
| | | private ThreadPoolTaskExecutor taskExecutor; |
| | | |
| | | @Override |
| | | public void onMessage(@NotNull Message message, byte[] bytes) { |
| | | logger.info("收到来自REDIS的ALARM通知: {}", new String(message.getBody())); |
| | | |
| | | taskQueue.offer(message); |
| | | if (!taskQueueHandlerRun) { |
| | | taskQueueHandlerRun = true; |
| | | logger.info("[线程池信息]活动线程数:{}, 最大线程数: {}", taskExecutor.getActiveCount(), taskExecutor.getMaxPoolSize()); |
| | | taskExecutor.execute(() -> { |
| | | while (!taskQueue.isEmpty()) { |
| | | Message msg = taskQueue.poll(); |
| | | |
| | | AlarmChannelMessage alarmChannelMessage = JSON.parseObject(msg.getBody(), AlarmChannelMessage.class); |
| | | if (alarmChannelMessage == null) { |
| | | logger.warn("[REDIS的ALARM通知]消息解析失败"); |
| | | continue; |
| | | } |
| | | String gbId = alarmChannelMessage.getGbId(); |
| | | |
| | | DeviceAlarm deviceAlarm = new DeviceAlarm(); |
| | | deviceAlarm.setCreateTime(DateUtil.getNow()); |
| | | deviceAlarm.setChannelId(gbId); |
| | | deviceAlarm.setAlarmDescription(alarmChannelMessage.getAlarmDescription()); |
| | | deviceAlarm.setAlarmMethod("" + alarmChannelMessage.getAlarmSn()); |
| | | deviceAlarm.setAlarmPriority("1"); |
| | | deviceAlarm.setAlarmTime(DateUtil.getNowForISO8601()); |
| | | deviceAlarm.setAlarmType("1"); |
| | | deviceAlarm.setLongitude(0); |
| | | deviceAlarm.setLatitude(0); |
| | | |
| | | if (ObjectUtils.isEmpty(gbId)) { |
| | | // 发送给所有的上级 |
| | | List<ParentPlatform> parentPlatforms = storage.queryEnableParentPlatformList(true); |
| | | if (parentPlatforms.size() > 0) { |
| | | for (ParentPlatform parentPlatform : parentPlatforms) { |
| | | commanderForPlatform.sendAlarmMessage(parentPlatform, deviceAlarm); |
| | | } |
| | | } |
| | | }else { |
| | | Device device = storage.queryVideoDevice(gbId); |
| | | ParentPlatform platform = storage.queryParentPlatByServerGBId(gbId); |
| | | if (device != null && platform == null) { |
| | | commander.sendAlarmMessage(device, deviceAlarm); |
| | | }else if (device == null && platform != null){ |
| | | commanderForPlatform.sendAlarmMessage(platform, deviceAlarm); |
| | | }else { |
| | | logger.warn("无法确定" + gbId + "是平台还是设备"); |
| | | } |
| | | } |
| | | } |
| | | taskQueueHandlerRun = false; |
| | | }); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
File was renamed from src/main/java/com/genersoft/iot/vmp/service/impl/RedisGbPlayMsgListener.java |
| | |
| | | package com.genersoft.iot.vmp.service.impl; |
| | | package com.genersoft.iot.vmp.service.redisMsg; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.data.redis.connection.Message; |
| | | import org.springframework.data.redis.connection.MessageListener; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.text.ParseException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.ConcurrentLinkedQueue; |
| | | |
| | | |
| | | /** |
| | |
| | | @Autowired |
| | | private ZlmHttpHookSubscribe subscribe; |
| | | |
| | | private boolean taskQueueHandlerRun = false; |
| | | |
| | | private ConcurrentLinkedQueue<Message> taskQueue = new ConcurrentLinkedQueue<>(); |
| | | |
| | | @Qualifier("taskExecutor") |
| | | @Autowired |
| | | private ThreadPoolTaskExecutor taskExecutor; |
| | | |
| | | |
| | | public interface PlayMsgCallback{ |
| | | void handler(ResponseSendItemMsg responseSendItemMsg); |
| | | void handler(ResponseSendItemMsg responseSendItemMsg) throws ParseException; |
| | | } |
| | | |
| | | public interface PlayMsgCallbackForStartSendRtpStream{ |
| | |
| | | |
| | | @Override |
| | | public void onMessage(Message message, byte[] bytes) { |
| | | JSONObject msgJSON = JSON.parseObject(message.getBody(), JSONObject.class); |
| | | WvpRedisMsg wvpRedisMsg = JSON.toJavaObject(msgJSON, WvpRedisMsg.class); |
| | | if (!userSetting.getServerId().equals(wvpRedisMsg.getToId())) { |
| | | return; |
| | | } |
| | | if (WvpRedisMsg.isRequest(wvpRedisMsg)) { |
| | | logger.info("[收到REDIS通知] 请求: {}", new String(message.getBody())); |
| | | |
| | | switch (wvpRedisMsg.getCmd()){ |
| | | case WvpRedisMsgCmd.GET_SEND_ITEM: |
| | | RequestSendItemMsg content = JSON.toJavaObject((JSONObject)wvpRedisMsg.getContent(), RequestSendItemMsg.class); |
| | | requestSendItemMsgHand(content, wvpRedisMsg.getFromId(), wvpRedisMsg.getSerial()); |
| | | break; |
| | | case WvpRedisMsgCmd.REQUEST_PUSH_STREAM: |
| | | RequestPushStreamMsg param = JSON.toJavaObject((JSONObject)wvpRedisMsg.getContent(), RequestPushStreamMsg.class);; |
| | | requestPushStreamMsgHand(param, wvpRedisMsg.getFromId(), wvpRedisMsg.getSerial()); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | }else { |
| | | logger.info("[收到REDIS通知] 回复: {}", new String(message.getBody())); |
| | | switch (wvpRedisMsg.getCmd()){ |
| | | case WvpRedisMsgCmd.GET_SEND_ITEM: |
| | | |
| | | WVPResult content = JSON.toJavaObject((JSONObject)wvpRedisMsg.getContent(), WVPResult.class); |
| | | |
| | | String key = wvpRedisMsg.getSerial(); |
| | | switch (content.getCode()) { |
| | | case 0: |
| | | ResponseSendItemMsg responseSendItemMsg =JSON.toJavaObject((JSONObject)content.getData(), ResponseSendItemMsg.class); |
| | | PlayMsgCallback playMsgCallback = callbacks.get(key); |
| | | if (playMsgCallback != null) { |
| | | callbacksForError.remove(key); |
| | | playMsgCallback.handler(responseSendItemMsg); |
| | | } |
| | | break; |
| | | case ERROR_CODE_MEDIA_SERVER_NOT_FOUND: |
| | | case ERROR_CODE_OFFLINE: |
| | | case ERROR_CODE_TIMEOUT: |
| | | PlayMsgErrorCallback errorCallback = callbacksForError.get(key); |
| | | if (errorCallback != null) { |
| | | callbacks.remove(key); |
| | | errorCallback.handler(content); |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | | taskQueue.offer(message); |
| | | if (!taskQueueHandlerRun) { |
| | | taskQueueHandlerRun = true; |
| | | taskExecutor.execute(() -> { |
| | | while (!taskQueue.isEmpty()) { |
| | | Message msg = taskQueue.poll(); |
| | | JSONObject msgJSON = JSON.parseObject(msg.getBody(), JSONObject.class); |
| | | WvpRedisMsg wvpRedisMsg = JSON.toJavaObject(msgJSON, WvpRedisMsg.class); |
| | | if (!userSetting.getServerId().equals(wvpRedisMsg.getToId())) { |
| | | continue; |
| | | } |
| | | break; |
| | | case WvpRedisMsgCmd.REQUEST_PUSH_STREAM: |
| | | WVPResult wvpResult = JSON.toJavaObject((JSONObject)wvpRedisMsg.getContent(), WVPResult.class); |
| | | String serial = wvpRedisMsg.getSerial(); |
| | | switch (wvpResult.getCode()) { |
| | | case 0: |
| | | JSONObject jsonObject = (JSONObject)wvpResult.getData(); |
| | | PlayMsgCallbackForStartSendRtpStream playMsgCallback = callbacksForStartSendRtpStream.get(serial); |
| | | if (playMsgCallback != null) { |
| | | callbacksForError.remove(serial); |
| | | playMsgCallback.handler(jsonObject); |
| | | } |
| | | break; |
| | | case ERROR_CODE_MEDIA_SERVER_NOT_FOUND: |
| | | case ERROR_CODE_OFFLINE: |
| | | case ERROR_CODE_TIMEOUT: |
| | | PlayMsgErrorCallback errorCallback = callbacksForError.get(serial); |
| | | if (errorCallback != null) { |
| | | callbacks.remove(serial); |
| | | errorCallback.handler(wvpResult); |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | | if (WvpRedisMsg.isRequest(wvpRedisMsg)) { |
| | | logger.info("[收到REDIS通知] 请求: {}", new String(msg.getBody())); |
| | | |
| | | switch (wvpRedisMsg.getCmd()){ |
| | | case WvpRedisMsgCmd.GET_SEND_ITEM: |
| | | RequestSendItemMsg content = JSON.toJavaObject((JSONObject)wvpRedisMsg.getContent(), RequestSendItemMsg.class); |
| | | requestSendItemMsgHand(content, wvpRedisMsg.getFromId(), wvpRedisMsg.getSerial()); |
| | | break; |
| | | case WvpRedisMsgCmd.REQUEST_PUSH_STREAM: |
| | | RequestPushStreamMsg param = JSON.toJavaObject((JSONObject)wvpRedisMsg.getContent(), RequestPushStreamMsg.class);; |
| | | requestPushStreamMsgHand(param, wvpRedisMsg.getFromId(), wvpRedisMsg.getSerial()); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | }else { |
| | | logger.info("[收到REDIS通知] 回复: {}", new String(msg.getBody())); |
| | | switch (wvpRedisMsg.getCmd()){ |
| | | case WvpRedisMsgCmd.GET_SEND_ITEM: |
| | | |
| | | WVPResult content = JSON.toJavaObject((JSONObject)wvpRedisMsg.getContent(), WVPResult.class); |
| | | |
| | | String key = wvpRedisMsg.getSerial(); |
| | | switch (content.getCode()) { |
| | | case 0: |
| | | ResponseSendItemMsg responseSendItemMsg =JSON.toJavaObject((JSONObject)content.getData(), ResponseSendItemMsg.class); |
| | | PlayMsgCallback playMsgCallback = callbacks.get(key); |
| | | if (playMsgCallback != null) { |
| | | callbacksForError.remove(key); |
| | | try { |
| | | playMsgCallback.handler(responseSendItemMsg); |
| | | } catch (ParseException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | break; |
| | | case ERROR_CODE_MEDIA_SERVER_NOT_FOUND: |
| | | case ERROR_CODE_OFFLINE: |
| | | case ERROR_CODE_TIMEOUT: |
| | | PlayMsgErrorCallback errorCallback = callbacksForError.get(key); |
| | | if (errorCallback != null) { |
| | | callbacks.remove(key); |
| | | errorCallback.handler(content); |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | break; |
| | | case WvpRedisMsgCmd.REQUEST_PUSH_STREAM: |
| | | WVPResult wvpResult = JSON.toJavaObject((JSONObject)wvpRedisMsg.getContent(), WVPResult.class); |
| | | String serial = wvpRedisMsg.getSerial(); |
| | | switch (wvpResult.getCode()) { |
| | | case 0: |
| | | JSONObject jsonObject = (JSONObject)wvpResult.getData(); |
| | | PlayMsgCallbackForStartSendRtpStream playMsgCallback = callbacksForStartSendRtpStream.get(serial); |
| | | if (playMsgCallback != null) { |
| | | callbacksForError.remove(serial); |
| | | playMsgCallback.handler(jsonObject); |
| | | } |
| | | break; |
| | | case ERROR_CODE_MEDIA_SERVER_NOT_FOUND: |
| | | case ERROR_CODE_OFFLINE: |
| | | case ERROR_CODE_TIMEOUT: |
| | | PlayMsgErrorCallback errorCallback = callbacksForError.get(serial); |
| | | if (errorCallback != null) { |
| | | callbacks.remove(serial); |
| | | errorCallback.handler(wvpResult); |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | taskQueueHandlerRun = false; |
| | | }); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
File was renamed from src/main/java/com/genersoft/iot/vmp/service/impl/RedisGpsMsgListener.java |
| | |
| | | package com.genersoft.iot.vmp.service.impl; |
| | | package com.genersoft.iot.vmp.service.redisMsg; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.genersoft.iot.vmp.gb28181.bean.HandlerCatchData; |
| | | import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| | |
| | | @Autowired |
| | | private IVideoManagerStorage storager; |
| | | |
| | | private final ConcurrentLinkedQueue<Message> taskQueue = new ConcurrentLinkedQueue<>(); |
| | | private ConcurrentLinkedQueue<Message> taskQueue = new ConcurrentLinkedQueue<>(); |
| | | |
| | | @Qualifier("taskExecutor") |
| | | @Autowired |
New file |
| | |
| | | package com.genersoft.iot.vmp.service.redisMsg; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; |
| | | import com.genersoft.iot.vmp.service.bean.MessageForPushChannelResponse; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.data.redis.connection.Message; |
| | | import org.springframework.data.redis.connection.MessageListener; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.ConcurrentLinkedQueue; |
| | | |
| | | /** |
| | | * 接收redis返回的推流结果 |
| | | * @author lin |
| | | */ |
| | | @Component |
| | | public class RedisPushStreamResponseListener implements MessageListener { |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(RedisPushStreamResponseListener.class); |
| | | |
| | | private boolean taskQueueHandlerRun = false; |
| | | |
| | | private ConcurrentLinkedQueue<Message> taskQueue = new ConcurrentLinkedQueue<>(); |
| | | |
| | | @Qualifier("taskExecutor") |
| | | @Autowired |
| | | private ThreadPoolTaskExecutor taskExecutor; |
| | | |
| | | |
| | | private Map<String, PushStreamResponseEvent> responseEvents = new ConcurrentHashMap<>(); |
| | | |
| | | public interface PushStreamResponseEvent{ |
| | | void run(MessageForPushChannelResponse response); |
| | | } |
| | | |
| | | @Override |
| | | public void onMessage(Message message, byte[] bytes) { |
| | | logger.warn("[REDIS消息-请求推流结果]: {}", new String(message.getBody())); |
| | | taskQueue.offer(message); |
| | | if (!taskQueueHandlerRun) { |
| | | taskQueueHandlerRun = true; |
| | | taskExecutor.execute(() -> { |
| | | while (!taskQueue.isEmpty()) { |
| | | Message msg = taskQueue.poll(); |
| | | MessageForPushChannelResponse response = JSON.parseObject(new String(msg.getBody()), MessageForPushChannelResponse.class); |
| | | if (response == null || ObjectUtils.isEmpty(response.getApp()) || ObjectUtils.isEmpty(response.getStream())){ |
| | | logger.info("[REDIS消息-请求推流结果]:参数不全"); |
| | | continue; |
| | | } |
| | | // 查看正在等待的invite消息 |
| | | if (responseEvents.get(response.getApp() + response.getStream()) != null) { |
| | | responseEvents.get(response.getApp() + response.getStream()).run(response); |
| | | } |
| | | } |
| | | taskQueueHandlerRun = false; |
| | | }); |
| | | } |
| | | } |
| | | |
| | | public void addEvent(String app, String stream, PushStreamResponseEvent callback) { |
| | | responseEvents.put(app + stream, callback); |
| | | } |
| | | |
| | | public void removeEvent(String app, String stream) { |
| | | responseEvents.remove(app + stream); |
| | | } |
| | | } |
New file |
| | |
| | | package com.genersoft.iot.vmp.service.redisMsg; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; |
| | | import com.genersoft.iot.vmp.service.IGbStreamService; |
| | | import com.genersoft.iot.vmp.service.IMediaServerService; |
| | | import com.genersoft.iot.vmp.service.IStreamPushService; |
| | | import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; |
| | | import com.genersoft.iot.vmp.utils.DateUtil; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.data.redis.connection.Message; |
| | | import org.springframework.data.redis.connection.MessageListener; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentLinkedQueue; |
| | | |
| | | /** |
| | | * @Auther: JiangFeng |
| | | * @Date: 2022/8/16 11:32 |
| | | * @Description: 接收redis发送的推流设备列表更新通知 |
| | | */ |
| | | @Component |
| | | public class RedisPushStreamStatusListMsgListener implements MessageListener { |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(RedisPushStreamStatusListMsgListener.class); |
| | | @Resource |
| | | private IMediaServerService mediaServerService; |
| | | |
| | | @Resource |
| | | private IStreamPushService streamPushService; |
| | | @Resource |
| | | private IGbStreamService gbStreamService; |
| | | |
| | | private boolean taskQueueHandlerRun = false; |
| | | |
| | | private ConcurrentLinkedQueue<Message> taskQueue = new ConcurrentLinkedQueue<>(); |
| | | |
| | | @Qualifier("taskExecutor") |
| | | @Autowired |
| | | private ThreadPoolTaskExecutor taskExecutor; |
| | | |
| | | @Override |
| | | public void onMessage(Message message, byte[] bytes) { |
| | | logger.info("[REDIS消息-推流设备列表更新]: {}", new String(message.getBody())); |
| | | |
| | | taskQueue.offer(message); |
| | | if (!taskQueueHandlerRun) { |
| | | taskQueueHandlerRun = true; |
| | | taskExecutor.execute(() -> { |
| | | while (!taskQueue.isEmpty()) { |
| | | Message msg = taskQueue.poll(); |
| | | List<StreamPushItem> streamPushItems = JSON.parseArray(new String(msg.getBody()), StreamPushItem.class); |
| | | //查询全部的app+stream 用于判断是添加还是修改 |
| | | List<String> allAppAndStream = streamPushService.getAllAppAndStream(); |
| | | |
| | | /** |
| | | * 用于存储更具APP+Stream过滤后的数据,可以直接存入stream_push表与gb_stream表 |
| | | */ |
| | | List<StreamPushItem> streamPushItemForSave = new ArrayList<>(); |
| | | List<StreamPushItem> streamPushItemForUpdate = new ArrayList<>(); |
| | | for (StreamPushItem streamPushItem : streamPushItems) { |
| | | String app = streamPushItem.getApp(); |
| | | String stream = streamPushItem.getStream(); |
| | | boolean contains = allAppAndStream.contains(app + stream); |
| | | //不存在就添加 |
| | | if (!contains) { |
| | | streamPushItem.setStreamType("push"); |
| | | streamPushItem.setCreateTime(DateUtil.getNow()); |
| | | streamPushItem.setMediaServerId(mediaServerService.getDefaultMediaServer().getId()); |
| | | streamPushItem.setOriginType(2); |
| | | streamPushItem.setOriginTypeStr("rtsp_push"); |
| | | streamPushItem.setTotalReaderCount("0"); |
| | | streamPushItemForSave.add(streamPushItem); |
| | | } else { |
| | | //存在就只修改 name和gbId |
| | | streamPushItemForUpdate.add(streamPushItem); |
| | | } |
| | | } |
| | | if (streamPushItemForSave.size() > 0) { |
| | | |
| | | logger.info("添加{}条",streamPushItemForSave.size()); |
| | | logger.info(JSONObject.toJSONString(streamPushItemForSave)); |
| | | streamPushService.batchAdd(streamPushItemForSave); |
| | | |
| | | } |
| | | if(streamPushItemForUpdate.size()>0){ |
| | | logger.info("修改{}条",streamPushItemForUpdate.size()); |
| | | logger.info(JSONObject.toJSONString(streamPushItemForUpdate)); |
| | | gbStreamService.updateGbIdOrName(streamPushItemForUpdate); |
| | | } |
| | | } |
| | | taskQueueHandlerRun = false; |
| | | }); |
| | | } |
| | | } |
| | | } |
File was renamed from src/main/java/com/genersoft/iot/vmp/service/impl/RedisPushStreamStatusMsgListener.java |
| | |
| | | package com.genersoft.iot.vmp.service.impl; |
| | | package com.genersoft.iot.vmp.service.redisMsg; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.genersoft.iot.vmp.common.VideoManagerConstants; |
| | | import com.genersoft.iot.vmp.conf.DynamicTask; |
| | | import com.genersoft.iot.vmp.conf.UserSetting; |
| | | import com.genersoft.iot.vmp.gb28181.bean.GbStream; |
| | | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| | | import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; |
| | | import com.genersoft.iot.vmp.media.zlm.ZLMMediaListManager; |
| | | import com.genersoft.iot.vmp.media.zlm.dto.MediaItem; |
| | | import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; |
| | | import com.genersoft.iot.vmp.service.IStreamPushService; |
| | | import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; |
| | | import com.genersoft.iot.vmp.service.bean.PushStreamStatusChangeFromRedisDto; |
| | | import com.genersoft.iot.vmp.service.bean.StreamPushItemFromRedis; |
| | | 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.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.concurrent.ConcurrentLinkedQueue; |
| | | |
| | | |
| | |
| | | |
| | | |
| | | |
| | | private final ConcurrentLinkedQueue<Message> taskQueue = new ConcurrentLinkedQueue<>(); |
| | | private ConcurrentLinkedQueue<Message> taskQueue = new ConcurrentLinkedQueue<>(); |
| | | |
| | | @Qualifier("taskExecutor") |
| | | @Autowired |
| | |
| | | |
| | | @Override |
| | | public void onMessage(Message message, byte[] bytes) { |
| | | // TODO 增加队列 |
| | | logger.warn("[REDIS消息-推流设备状态变化]: {}", new String(message.getBody())); |
| | | taskQueue.offer(message); |
| | | |
| | |
| | | PushStreamStatusChangeFromRedisDto statusChangeFromPushStream = JSON.parseObject(msg.getBody(), PushStreamStatusChangeFromRedisDto.class); |
| | | if (statusChangeFromPushStream == null) { |
| | | logger.warn("[REDIS消息]推流设备状态变化消息解析失败"); |
| | | return; |
| | | continue; |
| | | } |
| | | // 取消定时任务 |
| | | dynamicTask.stop(VideoManagerConstants.VM_MSG_GET_ALL_ONLINE_REQUESTED); |
New file |
| | |
| | | package com.genersoft.iot.vmp.service.redisMsg; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.genersoft.iot.vmp.conf.UserSetting; |
| | | |
| | | import com.genersoft.iot.vmp.media.zlm.ZLMMediaListManager; |
| | | import com.genersoft.iot.vmp.media.zlm.dto.MediaItem; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.data.redis.connection.Message; |
| | | import org.springframework.data.redis.connection.MessageListener; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.concurrent.ConcurrentLinkedQueue; |
| | | |
| | | |
| | | /** |
| | | * 接收其他wvp发送流变化通知 |
| | | * @author lin |
| | | */ |
| | | @Component |
| | | public class RedisStreamMsgListener implements MessageListener { |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(RedisStreamMsgListener.class); |
| | | |
| | | @Autowired |
| | | private UserSetting userSetting; |
| | | |
| | | @Autowired |
| | | private ZLMMediaListManager zlmMediaListManager; |
| | | |
| | | private boolean taskQueueHandlerRun = false; |
| | | |
| | | private ConcurrentLinkedQueue<Message> taskQueue = new ConcurrentLinkedQueue<>(); |
| | | |
| | | @Qualifier("taskExecutor") |
| | | @Autowired |
| | | private ThreadPoolTaskExecutor taskExecutor; |
| | | |
| | | @Override |
| | | public void onMessage(Message message, byte[] bytes) { |
| | | |
| | | taskQueue.offer(message); |
| | | if (!taskQueueHandlerRun) { |
| | | taskQueueHandlerRun = true; |
| | | taskExecutor.execute(() -> { |
| | | while (!taskQueue.isEmpty()) { |
| | | Message msg = taskQueue.poll(); |
| | | JSONObject steamMsgJson = JSON.parseObject(msg.getBody(), JSONObject.class); |
| | | if (steamMsgJson == null) { |
| | | logger.warn("[收到redis 流变化]消息解析失败"); |
| | | continue; |
| | | } |
| | | String serverId = steamMsgJson.getString("serverId"); |
| | | |
| | | if (userSetting.getServerId().equals(serverId)) { |
| | | // 自己发送的消息忽略即可 |
| | | continue; |
| | | } |
| | | logger.info("[收到redis 流变化]: {}", new String(message.getBody())); |
| | | String app = steamMsgJson.getString("app"); |
| | | String stream = steamMsgJson.getString("stream"); |
| | | boolean register = steamMsgJson.getBoolean("register"); |
| | | String mediaServerId = steamMsgJson.getString("mediaServerId"); |
| | | MediaItem mediaItem = new MediaItem(); |
| | | mediaItem.setSeverId(serverId); |
| | | mediaItem.setApp(app); |
| | | mediaItem.setStream(stream); |
| | | mediaItem.setRegist(register); |
| | | mediaItem.setMediaServerId(mediaServerId); |
| | | mediaItem.setCreateStamp(System.currentTimeMillis()/1000); |
| | | mediaItem.setAliveSecond(0L); |
| | | mediaItem.setTotalReaderCount("0"); |
| | | mediaItem.setOriginType(0); |
| | | mediaItem.setOriginTypeStr("0"); |
| | | mediaItem.setOriginTypeStr("unknown"); |
| | | if (register) { |
| | | zlmMediaListManager.addPush(mediaItem); |
| | | }else { |
| | | zlmMediaListManager.removeMedia(app, stream); |
| | | } |
| | | } |
| | | taskQueueHandlerRun = false; |
| | | }); |
| | | } |
| | | } |
| | | } |
| | |
| | | "WHERE gs.gbId = '${gbId}' AND pgs.platformId = '${platformId}'") |
| | | GbStream queryStreamInPlatform(String platformId, String gbId); |
| | | |
| | | @Select("select gt.gbId as channelId, gt.name, 'wvp-pro' as manufacture, st.status, gt.longitude, gt.latitude, pc.id as parentId," + |
| | | @Select("<script> "+ |
| | | "select gt.gbId as channelId, gt.name, 'wvp-pro' as manufacture, st.status, gt.longitude, gt.latitude, pc.id as parentId," + |
| | | " '1' as registerWay, pc.civilCode, 'live' as model, 'wvp-pro' as owner, '0' as parental,'0' as secrecy" + |
| | | " from gb_stream gt " + |
| | | " left join (" + |
| | | " select sp.status, sp.app, sp.stream from stream_push sp" + |
| | | " select " + |
| | | " <if test='usPushingAsStatus != true'> sp.status as status, </if>" + |
| | | " <if test='usPushingAsStatus == true'> sp.pushIng as status, </if>" + |
| | | "sp.app, sp.stream from stream_push sp" + |
| | | " union all" + |
| | | " select spxy.status, spxy.app, spxy.stream from stream_proxy spxy" + |
| | | " ) st on st.app = gt.app and st.stream = gt.stream" + |
| | | " left join platform_gb_stream pgs on gt.gbStreamId = pgs.gbStreamId" + |
| | | " left join platform_catalog pc on pgs.catalogId = pc.id and pgs.platformId = pc.platformId" + |
| | | " where pgs.platformId=#{platformId}") |
| | | List<DeviceChannel> queryGbStreamListInPlatform(String platformId); |
| | | " where pgs.platformId=#{platformId}" + |
| | | "</script>") |
| | | List<DeviceChannel> queryGbStreamListInPlatform(String platformId, boolean usPushingAsStatus); |
| | | |
| | | |
| | | @Select("SELECT gs.* FROM gb_stream gs LEFT JOIN platform_gb_stream pgs " + |
| | |
| | | @Override |
| | | public void sendMobilePositionMsg(JSONObject jsonObject) { |
| | | String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_MOBILE_POSITION; |
| | | logger.info("[redis发送通知]移动位置 {}: {}", key, jsonObject.toString()); |
| | | logger.info("[redis发送通知] 移动位置 {}: {}", key, jsonObject.toString()); |
| | | RedisUtil.convertAndSend(key, jsonObject); |
| | | } |
| | | |
| | | @Override |
| | | public void sendStreamPushRequestedMsg(MessageForPushChannel msg) { |
| | | String key = VideoManagerConstants.VM_MSG_STREAM_PUSH_REQUESTED; |
| | | logger.info("[redis发送通知]推流被请求 {}: {}/{}", key, msg.getApp(), msg.getStream()); |
| | | logger.info("[redis发送通知] 推流被请求 {}: {}/{}", key, msg.getApp(), msg.getStream()); |
| | | RedisUtil.convertAndSend(key, (JSONObject)JSON.toJSON(msg)); |
| | | } |
| | | |
| | |
| | | |
| | | import com.genersoft.iot.vmp.common.StreamInfo; |
| | | import com.genersoft.iot.vmp.conf.SipConfig; |
| | | import com.genersoft.iot.vmp.conf.UserSetting; |
| | | import com.genersoft.iot.vmp.gb28181.bean.*; |
| | | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| | | import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; |
| | |
| | | |
| | | @Autowired |
| | | private GbStreamMapper gbStreamMapper; |
| | | |
| | | @Autowired |
| | | private UserSetting userSetting; |
| | | |
| | | @Autowired |
| | | private PlatformCatalogMapper catalogMapper; |
| | |
| | | */ |
| | | @Override |
| | | public List<DeviceChannel> queryGbStreamListInPlatform(String platformId) { |
| | | return gbStreamMapper.queryGbStreamListInPlatform(platformId); |
| | | return gbStreamMapper.queryGbStreamListInPlatform(platformId, userSetting.isUsePushingAsStatus()); |
| | | } |
| | | |
| | | /** |
| | |
| | | @GetMapping("/{deviceId}/subscribe_info") |
| | | @Operation(summary = "获取设备的订阅状态") |
| | | @Parameter(name = "deviceId", description = "设备国标编号", required = true) |
| | | public WVPResult<Map<String, String>> getSubscribeInfo(@PathVariable String deviceId) { |
| | | public WVPResult<Map<String, Integer>> getSubscribeInfo(@PathVariable String deviceId) { |
| | | Set<String> allKeys = dynamicTask.getAllKeys(); |
| | | Map<String, String> dialogStateMap = new HashMap<>(); |
| | | Map<String, Integer> dialogStateMap = new HashMap<>(); |
| | | for (String key : allKeys) { |
| | | if (key.startsWith(deviceId)) { |
| | | ISubscribeTask subscribeTask = (ISubscribeTask)dynamicTask.get(key); |
| | | DialogState dialogState = subscribeTask.getDialogState(); |
| | | if (dialogState == null) { |
| | | continue; |
| | | } |
| | | if (subscribeTask instanceof CatalogSubscribeTask) { |
| | | dialogStateMap.put("catalog", dialogState.toString()); |
| | | dialogStateMap.put("catalog", 1); |
| | | }else if (subscribeTask instanceof MobilePositionSubscribeTask) { |
| | | dialogStateMap.put("mobilePosition", dialogState.toString()); |
| | | dialogStateMap.put("mobilePosition", 1); |
| | | } |
| | | } |
| | | } |
| | | WVPResult<Map<String, String>> wvpResult = new WVPResult<>(); |
| | | WVPResult<Map<String, Integer>> wvpResult = new WVPResult<>(); |
| | | wvpResult.setCode(0); |
| | | wvpResult.setData(dialogStateMap); |
| | | return wvpResult; |
| | |
| | | record-sip: true |
| | | # 是否将日志存储进数据库 |
| | | logInDatebase: true |
| | | # 使用推流状态作为推流通道状态 |
| | | use-pushing-as-status: true |
| | | |
| | | # 关闭在线文档(生产环境建议关闭) |
| | | springdoc: |
| | |
| | | console.log(this.videoUrl) |
| | | }, |
| | | openDialog: function (tab, deviceId, channelId, param) { |
| | | if (this.showVideoDialog) { |
| | | return; |
| | | } |
| | | this.tabActiveName = tab; |
| | | this.channelId = channelId; |
| | | this.deviceId = deviceId; |
| | |
| | | method: 'get', |
| | | url: `/api/gb_record/download/progress/${this.deviceId}/${this.channelId}/${this.stream}` |
| | | }).then((res)=> { |
| | | console.log(res) |
| | | if (res.data.code === 0) { |
| | | this.streamInfo = res.data.data; |
| | | if (parseFloat(res.data.progress) == 1) { |
| | | this.percentage = 100; |
| | | }else { |
| | | this.percentage = (res.data.progress*100).toFixed(1); |
| | | this.percentage = (parseFloat(res.data.data.progress)*100).toFixed(1); |
| | | } |
| | | if (callback)callback(); |
| | | } |
| | |
| | | }).then((res) => { |
| | | console.log(res) |
| | | if (res.data.code === 0) { |
| | | if (res.data.data.length === 0){ |
| | | this.percentage = 0 |
| | | return |
| | | } |
| | | this.percentage = parseFloat(res.data.data.percentage)*100 |
| | | if (res.data.data[0].percentage === '1') { |
| | | this.getProgressForFileRun = false; |