| | |
| | | @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; |
| | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | 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); |
| | | }); |
| | | } |
| | | } |
| | |
| | | @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); |
| | |
| | | |
| | | @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.ZlmHttpHookSubscribe;
|
| | | 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 javax.sip.Dialog;
|
| | |
|
| | |
| | | * @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);
|
| | |
|
| | |
| | | * @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 |
| | | boolean isTcp = false; |
| | | ViaHeader reqViaHeader = (ViaHeader) request.getHeader(ViaHeader.NAME); |
| | |
| | | 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 { |
| | |
| | | */ |
| | | @Override |
| | | public void process(RequestEvent evt) { |
| | | Dialog dialog = evt.getDialog(); |
| | | CallIdHeader callIdHeader = (CallIdHeader)evt.getRequest().getHeader(CallIdHeader.NAME); |
| | | if (dialog == null) { |
| | | return; |
| | | |
| | | 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("dst_url",sendRtpItem.getIp()); |
| | | param.put("dst_port", sendRtpItem.getPort()); |
| | | param.put("is_udp", is_Udp); |
| | | 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, 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("dst_url",sendRtpItem.getIp()); |
| | | param.put("dst_port", sendRtpItem.getPort()); |
| | | param.put("is_udp", is_Udp); |
| | | 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 (mediaInfo == null) { |
| | | RequestPushStreamMsg requestPushStreamMsg = RequestPushStreamMsg.getInstance( |
| | | sendRtpItem.getMediaServerId(), sendRtpItem.getApp(), sendRtpItem.getStreamId(), |
| | | sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc(), sendRtpItem.isTcp(), |
| | | sendRtpItem.getLocalPort(), sendRtpItem.getPt(), sendRtpItem.isUsePs(), sendRtpItem.isOnlyAudio()); |
| | | redisGbPlayMsgListener.sendMsgForStartSendRtpStream(sendRtpItem.getServerId(), requestPushStreamMsg, jsonObject->{ |
| | | startSendRtpStreamHand(evt, sendRtpItem, parentPlatform, jsonObject, param, callIdHeader); |
| | | }); |
| | | }else { |
| | | JSONObject jsonObject = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param); |
| | | if (mediaInfo == null) { |
| | | RequestPushStreamMsg requestPushStreamMsg = RequestPushStreamMsg.getInstance( |
| | | sendRtpItem.getMediaServerId(), sendRtpItem.getApp(), sendRtpItem.getStreamId(), |
| | | sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc(), sendRtpItem.isTcp(), |
| | | sendRtpItem.getLocalPort(), sendRtpItem.getPt(), sendRtpItem.isUsePs(), sendRtpItem.isOnlyAudio()); |
| | | redisGbPlayMsgListener.sendMsgForStartSendRtpStream(sendRtpItem.getServerId(), requestPushStreamMsg, jsonObject->{ |
| | | startSendRtpStreamHand(evt, sendRtpItem, parentPlatform, jsonObject, param, callIdHeader); |
| | | } |
| | | |
| | | |
| | | }); |
| | | }else { |
| | | JSONObject jsonObject = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param); |
| | | startSendRtpStreamHand(evt, sendRtpItem, parentPlatform, jsonObject, param, callIdHeader); |
| | | } |
| | | } |
| | | private void startSendRtpStreamHand(RequestEvent evt, SendRtpItem sendRtpItem, ParentPlatform parentPlatform, |
| | |
| | | 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, 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.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.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.session.VideoStreamSessionManager; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; |
| | | 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.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| | | import com.genersoft.iot.vmp.utils.DateUtil; |
| | | import com.genersoft.iot.vmp.utils.SerializeUtils; |
| | | import gov.nist.javax.sdp.TimeDescriptionImpl; |
| | | import gov.nist.javax.sdp.fields.TimeField; |
| | | 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); |
| | | 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) throws InvalidArgumentException, ParseException, SipException, SdpException { |
| | | public void inviteFromDeviceHandle(ServerTransaction serverTransaction, String requesterId) throws InvalidArgumentException, ParseException, SipException, SdpException { |
| | | |
| | | // 非上级平台请求,查询是否设备请求(通常为接收语音广播的设备) |
| | | Device device = redisCatchStorage.getDevice(requesterId); |
| | | Request request = evt.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 username = sdp.getOrigin().getUsername(); |
| | |
| | | |
| | | } 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; |
| | |
| | | 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) { |
| | |
| | | logger.info("[收到报警通知]设备:{}", device.getDeviceId()); |
| | | // 回复200 OK |
| | | try { |
| | | responseAck(evt, Response.OK); |
| | | responseAck(getServerTransaction(evt), Response.OK); |
| | | } catch (SipException | InvalidArgumentException | ParseException e) { |
| | | logger.error("[收到报警通知], 回复200OK失败", e); |
| | | } |
| | |
| | | if (sipConfig.isAlarm()) { |
| | | deviceAlarmService.add(deviceAlarm); |
| | | } |
| | | |
| | | logger.info("[收到报警通知]内容:{}", JSONObject.toJSON(deviceAlarm)); |
| | | if (redisCatchStorage.deviceIsOnline(device.getDeviceId())) { |
| | | publisher.deviceAlarmEventPublish(deviceAlarm); |
| | | } |
| | |
| | | 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) { |
| | |
| | | rootElement = getRootElement(evt, device.getCharset()); |
| | | if (rootElement == null) { |
| | | logger.warn("[ 移动设备位置数据通知 ] content cannot be null, {}", evt.getRequest()); |
| | | responseAck(evt, Response.BAD_REQUEST); |
| | | responseAck(getServerTransaction(evt), Response.BAD_REQUEST); |
| | | return; |
| | | } |
| | | MobilePosition mobilePosition = new MobilePosition(); |
| | |
| | | } |
| | | storager.updateChannelPosition(deviceChannel); |
| | | //回复 200 OK |
| | | responseAck(evt, Response.OK); |
| | | responseAck(getServerTransaction(evt), Response.OK); |
| | | |
| | | // 发送redis消息。 通知位置信息的变化 |
| | | JSONObject jsonObject = new JSONObject(); |
| | |
| | | |
| | | 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; |
| | |
| | | try { |
| | | String channelId = getText(rootElement, "DeviceID"); |
| | | String key = DeferredResultHolder.CALLBACK_CMD_BROADCAST + device.getDeviceId() + channelId; |
| | | ServerTransaction serverTransaction = getServerTransaction(evt); |
| | | // 回复200 OK |
| | | responseAck(evt, Response.OK); |
| | | responseAck(serverTransaction, Response.OK); |
| | | // 此处是对本平台发出Broadcast指令的应答 |
| | | JSONObject json = new JSONObject(); |
| | | XmlUtil.node2Json(rootElement, 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; |
| | |
| | | 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) {
|
| | |
| | | storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
|
| | | // 如果正在给上级推送,则发送bye
|
| | |
|
| | |
|
| | | }else{
|
| | | streamInfo = redisCatchStorage.queryPlayback(null, null, stream, null);
|
| | | if (streamInfo != null) {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | 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); |
| | | } |
| | | } |
| | |
| | | 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; |
| | | } |
| | |
| | | @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; |
| | | } |
| | |
| | | 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.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; |
| | | |
| | | |
| | | |
| | |
| | | 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()); |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | import org.springframework.data.redis.connection.MessageListener; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.text.ParseException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | |
| | | |
| | | |
| | | public interface PlayMsgCallback{ |
| | | void handler(ResponseSendItemMsg responseSendItemMsg); |
| | | void handler(ResponseSendItemMsg responseSendItemMsg) throws ParseException; |
| | | } |
| | | |
| | | public interface PlayMsgCallbackForStartSendRtpStream{ |
| | |
| | | PlayMsgCallback playMsgCallback = callbacks.get(key); |
| | | if (playMsgCallback != null) { |
| | | callbacksForError.remove(key); |
| | | playMsgCallback.handler(responseSendItemMsg); |
| | | try { |
| | | playMsgCallback.handler(responseSendItemMsg); |
| | | } catch (ParseException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | break; |
| | | case ERROR_CODE_MEDIA_SERVER_NOT_FOUND: |
| | |
| | | @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)); |
| | | } |
| | | |
| | |
| | | @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; |
| | |
| | | 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.data.progress*100).toFixed(1); |
| | | this.percentage = (parseFloat(res.data.data.progress)*100).toFixed(1); |
| | | } |
| | | if (callback)callback(); |
| | | } |