From bfaa519e49c7bc3a09f398bd903275f4d59659db Mon Sep 17 00:00:00 2001
From: hotcoffie <35990065+hotcoffie@users.noreply.github.com>
Date: 星期五, 06 五月 2022 10:59:33 +0800
Subject: [PATCH] Merge branch '648540858:wvp-28181-2.0' into wvp-28181-2.0
---
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java | 137 ++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 122 insertions(+), 15 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
index 89e70d0..7689a7b 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
@@ -5,10 +5,7 @@
import com.genersoft.iot.vmp.conf.DynamicTask;
import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.conf.UserSetting;
-import com.genersoft.iot.vmp.gb28181.bean.Device;
-import com.genersoft.iot.vmp.gb28181.bean.InviteStreamCallback;
-import com.genersoft.iot.vmp.gb28181.bean.InviteStreamInfo;
-import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction;
+import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
@@ -23,6 +20,7 @@
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import gov.nist.javax.sip.SipProviderImpl;
import gov.nist.javax.sip.SipStackImpl;
+import gov.nist.javax.sip.message.MessageFactoryImpl;
import gov.nist.javax.sip.message.SIPRequest;
import gov.nist.javax.sip.stack.SIPDialog;
import org.slf4j.Logger;
@@ -35,10 +33,7 @@
import javax.sip.*;
import javax.sip.address.SipURI;
-import javax.sip.header.CallIdHeader;
-import javax.sip.header.ContentTypeHeader;
-import javax.sip.header.ExpiresHeader;
-import javax.sip.header.ViaHeader;
+import javax.sip.header.*;
import javax.sip.message.Request;
import java.lang.reflect.Field;
import java.text.ParseException;
@@ -345,13 +340,15 @@
* @param channelId 棰勮閫氶亾
* @param event hook璁㈤槄
* @param errorEvent sip閿欒璁㈤槄
- */
+ */
@Override
public void playStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,
- ZLMHttpHookSubscribe.Event event, SipSubscribe.Event errorEvent) {
+ ZLMHttpHookSubscribe.Event event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) {
String streamId = ssrcInfo.getStream();
try {
- if (device == null) return;
+ if (device == null) {
+ return;
+ }
String streamMode = device.getStreamMode().toUpperCase();
logger.info("{} 鍒嗛厤鐨刏LM涓�: {} [{}:{}]", streamId, mediaServerItem.getId(), mediaServerItem.getIp(), ssrcInfo.getPort());
@@ -441,6 +438,7 @@
// 杩欓噷涓轰緥閬垮厤涓�涓�氶亾鐨勭偣鎾彧鏈変竴涓猚allID杩欎釜鍙傛暟浣跨敤涓�涓浐瀹氬��
streamSession.put(device.getDeviceId(), channelId ,"play", streamId, ssrcInfo.getSsrc(), mediaServerItem.getId(), ((ResponseEvent)e.event).getClientTransaction(), VideoStreamSessionManager.SessionType.play);
streamSession.put(device.getDeviceId(), channelId ,"play", e.dialog);
+ okEvent.response(e);
});
@@ -698,7 +696,9 @@
if (callId != null) {
dialog = streamSession.getDialogByCallId(deviceId, channelId, callId);
}else {
- if (stream == null) return;
+ if (stream == null) {
+ return;
+ }
dialog = streamSession.getDialogByStream(deviceId, channelId, stream);
}
if (ssrcTransaction != null) {
@@ -1458,6 +1458,7 @@
* @param device 瑙嗛璁惧
* @return true = 鍛戒护鍙戦�佹垚鍔�
*/
+ @Override
public boolean mobilePositionSubscribe(Device device, Dialog dialog, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent) {
try {
StringBuffer subscribePostitionXml = new StringBuffer(200);
@@ -1509,6 +1510,7 @@
* @param endTime 鎶ヨ鍙戠敓缁堟鏃堕棿锛堝彲閫夛級
* @return true = 鍛戒护鍙戦�佹垚鍔�
*/
+ @Override
public boolean alarmSubscribe(Device device, int expires, String startPriority, String endPriority, String alarmMethod, String alarmType, String startTime, String endTime) {
try {
StringBuffer cmdXml = new StringBuffer(200);
@@ -1705,7 +1707,9 @@
content.append("CSeq: " + cseq + "\r\n");
content.append("Range: npt=now-\r\n");
Request request = headerProvider.createInfoRequest(device, streamInfo, content.toString());
- if (request == null) return;
+ if (request == null) {
+ return;
+ }
logger.info(request.toString());
ClientTransaction clientTransaction = null;
if ("TCP".equals(device.getTransport())) {
@@ -1734,7 +1738,9 @@
content.append("Range: npt=" + Math.abs(seekTime) + "-\r\n");
Request request = headerProvider.createInfoRequest(device, streamInfo, content.toString());
- if (request == null) return;
+ if (request == null) {
+ return;
+ }
logger.info(request.toString());
ClientTransaction clientTransaction = null;
if ("TCP".equals(device.getTransport())) {
@@ -1762,7 +1768,9 @@
content.append("CSeq: " + cseq + "\r\n");
content.append("Scale: " + String.format("%.1f",speed) + "\r\n");
Request request = headerProvider.createInfoRequest(device, streamInfo, content.toString());
- if (request == null) return;
+ if (request == null) {
+ return;
+ }
logger.info(request.toString());
ClientTransaction clientTransaction = null;
if ("TCP".equals(device.getTransport())) {
@@ -1777,4 +1785,103 @@
e.printStackTrace();
}
}
+
+ @Override
+ public boolean sendAlarmMessage(Device device, DeviceAlarm deviceAlarm) {
+ if (device == null) {
+ return false;
+ }
+ logger.info("[鍙戦�� 鎶ヨ閫氱煡] {}/{}->{},{}", device.getDeviceId(), deviceAlarm.getChannelId(),
+ deviceAlarm.getLongitude(), deviceAlarm.getLatitude());
+ try {
+ String characterSet = device.getCharset();
+ StringBuffer deviceStatusXml = new StringBuffer(600);
+ deviceStatusXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n");
+ deviceStatusXml.append("<Notify>\r\n");
+ deviceStatusXml.append("<CmdType>Alarm</CmdType>\r\n");
+ deviceStatusXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
+ deviceStatusXml.append("<DeviceID>" + deviceAlarm.getChannelId() + "</DeviceID>\r\n");
+ deviceStatusXml.append("<AlarmPriority>" + deviceAlarm.getAlarmPriority() + "</AlarmPriority>\r\n");
+ deviceStatusXml.append("<AlarmMethod>" + deviceAlarm.getAlarmMethod() + "</AlarmMethod>\r\n");
+ deviceStatusXml.append("<AlarmTime>" + deviceAlarm.getAlarmTime() + "</AlarmTime>\r\n");
+ deviceStatusXml.append("<AlarmDescription>" + deviceAlarm.getAlarmDescription() + "</AlarmDescription>\r\n");
+ deviceStatusXml.append("<Longitude>" + deviceAlarm.getLongitude() + "</Longitude>\r\n");
+ deviceStatusXml.append("<Latitude>" + deviceAlarm.getLatitude() + "</Latitude>\r\n");
+ deviceStatusXml.append("<info>\r\n");
+ deviceStatusXml.append("<AlarmType>" + deviceAlarm.getAlarmType() + "</AlarmType>\r\n");
+ deviceStatusXml.append("</info>\r\n");
+ deviceStatusXml.append("</Notify>\r\n");
+
+ CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
+ : udpSipProvider.getNewCallId();
+ String tm = Long.toString(System.currentTimeMillis());
+ Request request = headerProvider.createMessageRequest(device, deviceStatusXml.toString(), "z9hG4bK-ViaPtz-" + tm, "FromPtz" + tm, null, callIdHeader);
+ transmitRequest(device, request);
+
+
+ } catch (SipException | ParseException e) {
+ e.printStackTrace();
+ return false;
+ } catch (InvalidArgumentException e) {
+ throw new RuntimeException(e);
+ }
+ return true;
+ }
+
+ private void sendNotify(Device device, String catalogXmlContent,
+ SubscribeInfo subscribeInfo, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent )
+ throws NoSuchFieldException, IllegalAccessException, 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("骞冲彴{}鐨凾ransport閿欒锛歿}",device.getDeviceId(), device.getTransport());
+ return;
+ }
+ dialog.sendRequest(transaction);
+
+ }
}
--
Gitblit v1.8.0