From c807572bdfe41723da86d0e2934cb77d858c60fe Mon Sep 17 00:00:00 2001
From: Lawrence <1934378145@qq.com>
Date: 星期三, 27 一月 2021 16:05:08 +0800
Subject: [PATCH] 修改说明
---
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java | 202 ++++++++++++++++++++++++++++++++++++--------------
1 files changed, 145 insertions(+), 57 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 5da4b8d..b661c5e 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
@@ -77,6 +77,9 @@
@Value("${media.seniorSdp}")
private boolean seniorSdp;
+ @Value("${media.autoApplyPlay}")
+ private boolean autoApplyPlay;
+
@Autowired
private ZLMHttpHookSubscribe subscribe;
@@ -182,11 +185,11 @@
/**
* 浜戝彴鎸囦护鐮佽绠�
*
- * @param cmdCode 鎸囦护鐮�
- * @param parameter1 鏁版嵁1
- * @param parameter2 鏁版嵁2
- * @param combineCode2 缁勫悎鐮�2
- */
+ * @param cmdCode 鎸囦护鐮�
+ * @param parameter1 鏁版嵁1
+ * @param parameter2 鏁版嵁2
+ * @param combineCode2 缁勫悎鐮�2
+ */
public static String frontEndCmdString(int cmdCode, int parameter1, int parameter2, int combineCode2) {
StringBuilder builder = new StringBuilder("A50F01");
String strTmp;
@@ -208,13 +211,13 @@
/**
* 浜戝彴鎺у埗锛屾敮鎸佹柟鍚戜笌缂╂斁鎺у埗
*
- * @param device 鎺у埗璁惧
- * @param channelId 棰勮閫氶亾
- * @param leftRight 闀滃ご宸︾Щ鍙崇Щ 0:鍋滄 1:宸︾Щ 2:鍙崇Щ
- * @param upDown 闀滃ご涓婄Щ涓嬬Щ 0:鍋滄 1:涓婄Щ 2:涓嬬Щ
- * @param inOut 闀滃ご鏀惧ぇ缂╁皬 0:鍋滄 1:缂╁皬 2:鏀惧ぇ
- * @param moveSpeed 闀滃ご绉诲姩閫熷害
- * @param zoomSpeed 闀滃ご缂╂斁閫熷害
+ * @param device 鎺у埗璁惧
+ * @param channelId 棰勮閫氶亾
+ * @param leftRight 闀滃ご宸︾Щ鍙崇Щ 0:鍋滄 1:宸︾Щ 2:鍙崇Щ
+ * @param upDown 闀滃ご涓婄Щ涓嬬Щ 0:鍋滄 1:涓婄Щ 2:涓嬬Щ
+ * @param inOut 闀滃ご鏀惧ぇ缂╁皬 0:鍋滄 1:缂╁皬 2:鏀惧ぇ
+ * @param moveSpeed 闀滃ご绉诲姩閫熷害
+ * @param zoomSpeed 闀滃ご缂╂斁閫熷害
*/
@Override
public boolean ptzCmd(Device device, String channelId, int leftRight, int upDown, int inOut, int moveSpeed,
@@ -232,7 +235,8 @@
ptzXml.append("</Info>\r\n");
ptzXml.append("</Control>\r\n");
- Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtzTag", "ToPtzTag");
+ String tm = Long.toString(System.currentTimeMillis());
+ Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtz" + tm, null);
transmitRequest(device, request);
return true;
@@ -268,7 +272,8 @@
ptzXml.append("</Info>\r\n");
ptzXml.append("</Control>\r\n");
- Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtzTag", "ToPtzTag");
+ String tm = Long.toString(System.currentTimeMillis());
+ Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtz" + tm, null);
transmitRequest(device, request);
return true;
} catch (SipException | ParseException | InvalidArgumentException e) {
@@ -323,36 +328,65 @@
content.append("s=Play\r\n");
content.append("c=IN IP4 "+mediaInfo.getWanIp()+"\r\n");
content.append("t=0 0\r\n");
- if("TCP-PASSIVE".equals(streamMode)) {
- content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n");
- }else if ("TCP-ACTIVE".equals(streamMode)) {
- content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n");
- }else if("UDP".equals(streamMode)) {
- content.append("m=video "+ mediaPort +" RTP/AVP 126 125 99 34 98 97 96\r\n");
+
+ if (seniorSdp) {
+ if("TCP-PASSIVE".equals(streamMode)) {
+ content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
+ }else if ("TCP-ACTIVE".equals(streamMode)) {
+ content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
+ }else if("UDP".equals(streamMode)) {
+ content.append("m=video "+ mediaPort +" RTP/AVP 96 126 125 99 34 98 97\r\n");
+ }
+ content.append("a=recvonly\r\n");
+ content.append("a=rtpmap:96 PS/90000\r\n");
+ content.append("a=fmtp:126 profile-level-id=42e01e\r\n");
+ content.append("a=rtpmap:126 H264/90000\r\n");
+ content.append("a=rtpmap:125 H264S/90000\r\n");
+ content.append("a=fmtp:125 profile-level-id=42e01e\r\n");
+ content.append("a=rtpmap:99 MP4V-ES/90000\r\n");
+ content.append("a=fmtp:99 profile-level-id=3\r\n");
+ content.append("a=rtpmap:98 H264/90000\r\n");
+ content.append("a=rtpmap:97 MPEG4/90000\r\n");
+ if("TCP-PASSIVE".equals(streamMode)){ // tcp琚姩妯″紡
+ content.append("a=setup:passive\r\n");
+ content.append("a=connection:new\r\n");
+ }else if ("TCP-ACTIVE".equals(streamMode)) { // tcp涓诲姩妯″紡
+ content.append("a=setup:active\r\n");
+ content.append("a=connection:new\r\n");
+ }
+ }else {
+ if("TCP-PASSIVE".equals(streamMode)) {
+ content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
+ }else if ("TCP-ACTIVE".equals(streamMode)) {
+ content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
+ }else if("UDP".equals(streamMode)) {
+ content.append("m=video "+ mediaPort +" RTP/AVP 96 98 97\r\n");
+ }
+ content.append("a=recvonly\r\n");
+ content.append("a=rtpmap:96 PS/90000\r\n");
+ content.append("a=rtpmap:98 H264/90000\r\n");
+ content.append("a=rtpmap:97 MPEG4/90000\r\n");
+ if("TCP-PASSIVE".equals(streamMode)) { // tcp琚姩妯″紡
+ content.append("a=setup:passive\r\n");
+ content.append("a=recvonly\r\n");
+ content.append("a=rtpmap:96 PS/90000\r\n");
+ content.append("a=rtpmap:98 H264/90000\r\n");
+ content.append("a=rtpmap:97 MPEG4/90000\r\n");
+ if ("TCP-PASSIVE".equals(streamMode)) { // tcp琚姩妯″紡
+ content.append("a=setup:passive\r\n");
+ content.append("a=connection:new\r\n");
+ } else if ("TCP-ACTIVE".equals(streamMode)) { // tcp涓诲姩妯″紡
+ } else if ("TCP-ACTIVE".equals(streamMode)) { // tcp涓诲姩妯″紡
+ content.append("a=setup:active\r\n");
+ content.append("a=connection:new\r\n");
+ }
+ }
}
- content.append("a=recvonly\r\n");
- content.append("a=fmtp:126 profile-level-id=42e01e\r\n");
- content.append("a=rtpmap:126 H264/90000\r\n");
- content.append("a=rtpmap:125 H264S/90000\r\n");
- content.append("a=fmtp:125 profile-level-id=42e01e\r\n");
- content.append("a=rtpmap:99 MP4V-ES/90000\r\n");
- content.append("a=fmtp:99 profile-level-id=3\r\n");
- content.append("a=rtpmap:98 H264/90000\r\n");
- content.append("a=rtpmap:97 MPEG4/90000\r\n");
- content.append("a=rtpmap:96 PS/90000\r\n");
- if("TCP-PASSIVE".equals(streamMode)){ // tcp琚姩妯″紡
- content.append("a=setup:passive\r\n");
- content.append("a=connection:new\r\n");
- }else if ("TCP-ACTIVE".equals(streamMode)) { // tcp涓诲姩妯″紡
- content.append("a=setup:active\r\n");
- content.append("a=connection:new\r\n");
- }
+
content.append("y="+ssrc+"\r\n");//ssrc
-// String fromTag = UUID.randomUUID().toString();
-// Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, fromTag, null, ssrc);
-
- Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "live", null, ssrc);
+ String tm = Long.toString(System.currentTimeMillis());
+ Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "FromInvt" + tm, null, ssrc);
ClientTransaction transaction = transmitRequest(device, request, errorEvent);
streamSession.put(streamId, transaction);
@@ -386,7 +420,6 @@
subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, subscribeKey, event);
- //
StringBuffer content = new StringBuffer(200);
content.append("v=0\r\n");
content.append("o="+sipConfig.getSipId()+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n");
@@ -406,13 +439,14 @@
if (seniorSdp) {
if("TCP-PASSIVE".equals(streamMode)) {
- content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n");
+ content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
}else if ("TCP-ACTIVE".equals(streamMode)) {
- content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n");
+ content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
}else if("UDP".equals(streamMode)) {
- content.append("m=video "+ mediaPort +" RTP/AVP 126 125 99 34 98 97 96\r\n");
+ content.append("m=video "+ mediaPort +" RTP/AVP 96 126 125 99 34 98 97\r\n");
}
content.append("a=recvonly\r\n");
+ content.append("a=rtpmap:96 PS/90000\r\n");
content.append("a=fmtp:126 profile-level-id=42e01e\r\n");
content.append("a=rtpmap:126 H264/90000\r\n");
content.append("a=rtpmap:125 H264S/90000\r\n");
@@ -421,7 +455,6 @@
content.append("a=fmtp:99 profile-level-id=3\r\n");
content.append("a=rtpmap:98 H264/90000\r\n");
content.append("a=rtpmap:97 MPEG4/90000\r\n");
- content.append("a=rtpmap:96 PS/90000\r\n");
if("TCP-PASSIVE".equals(streamMode)){ // tcp琚姩妯″紡
content.append("a=setup:passive\r\n");
content.append("a=connection:new\r\n");
@@ -452,7 +485,8 @@
content.append("y="+ssrc+"\r\n");//ssrc
- Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "playback", null);
+ String tm = Long.toString(System.currentTimeMillis());
+ Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "fromplybck" + tm, null);
ClientTransaction transaction = transmitRequest(device, request, errorEvent);
streamSession.put(streamId, transaction);
@@ -490,16 +524,16 @@
if (dialog == null) {
return;
}
-
-
-
Request byeRequest = dialog.createRequest(Request.BYE);
SipURI byeURI = (SipURI) byeRequest.getRequestURI();
String vh = transaction.getRequest().getHeader(ViaHeader.NAME).toString();
Pattern p = Pattern.compile("(\\d+\\.\\d+\\.\\d+\\.\\d+)\\:(\\d+)");
Matcher matcher = p.matcher(vh);
if (matcher.find()) {
- byeURI.setHost(matcher.group(1));
+ String ip = matcher.group(1);
+ byeURI.setHost(ip);
+ String port = matcher.group(2);
+ byeURI.setPort(Integer.parseInt(port));
}
ViaHeader viaHeader = (ViaHeader) byeRequest.getHeader(ViaHeader.NAME);
String protocol = viaHeader.getTransport().toUpperCase();
@@ -635,7 +669,8 @@
catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
catalogXml.append("</Query>\r\n");
- Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaDeviceInfoBranch", "FromDeviceInfoTag", "ToDeviceInfoTag");
+ String tm = Long.toString(System.currentTimeMillis());
+ Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaDeviceInfoBranch", "FromDev" + tm, null);
transmitRequest(device, request);
@@ -664,7 +699,8 @@
catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
catalogXml.append("</Query>\r\n");
- Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaCatalogBranch", "FromCatalogTag", null);
+ String tm = Long.toString(System.currentTimeMillis());
+ Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaCatalogBranch", "FromCat" + tm, null);
transmitRequest(device, request, errorEvent);
} catch (SipException | ParseException | InvalidArgumentException e) {
@@ -698,7 +734,8 @@
recordInfoXml.append("<Type>all</Type>\r\n");
recordInfoXml.append("</Query>\r\n");
- Request request = headerProvider.createMessageRequest(device, recordInfoXml.toString(), "ViaRecordInfoBranch", "FromRecordInfoTag", null);
+ String tm = Long.toString(System.currentTimeMillis());
+ Request request = headerProvider.createMessageRequest(device, recordInfoXml.toString(), "ViaRecordInfoBranch", "fromRec" + tm, null);
transmitRequest(device, request);
} catch (SipException | ParseException | InvalidArgumentException e) {
@@ -747,11 +784,62 @@
* @param device 瑙嗛璁惧
*/
@Override
- public boolean mobilePostitionQuery(Device device) {
- // TODO Auto-generated method stub
- return false;
+ public boolean mobilePostitionQuery(Device device, SipSubscribe.Event errorEvent) {
+ try {
+ StringBuffer mobilePostitionXml = new StringBuffer(200);
+ mobilePostitionXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
+ mobilePostitionXml.append("<Query>\r\n");
+ mobilePostitionXml.append("<CmdType>MobilePosition</CmdType>\r\n");
+ mobilePostitionXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
+ mobilePostitionXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
+ mobilePostitionXml.append("<Interval>60</Interval>\r\n");
+ mobilePostitionXml.append("</Query>\r\n");
+
+ String tm = Long.toString(System.currentTimeMillis());
+ Request request = headerProvider.createMessageRequest(device, mobilePostitionXml.toString(), "viaTagPos" + tm, "fromTagPos" + tm, null);
+
+ transmitRequest(device, request, errorEvent);
+
+ } catch (SipException | ParseException | InvalidArgumentException e) {
+ e.printStackTrace();
+ return false;
+ }
+ return true;
}
+ /**
+ * 璁㈤槄銆佸彇娑堣闃呯Щ鍔ㄤ綅缃�
+ *
+ * @param device 瑙嗛璁惧
+ * @param expires 璁㈤槄瓒呮椂鏃堕棿
+ * @param interval 涓婃姤鏃堕棿闂撮殧
+ */
+ public boolean mobilePositionSubscribe(Device device, int expires, int interval) {
+ try {
+ StringBuffer subscribePostitionXml = new StringBuffer(200);
+ subscribePostitionXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
+ subscribePostitionXml.append("<Query>\r\n");
+ subscribePostitionXml.append("<CmdType>MobilePosition</CmdType>\r\n");
+ subscribePostitionXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
+ subscribePostitionXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
+ if (expires > 0) {
+ subscribePostitionXml.append("<Interval>" + String.valueOf(interval) + "</Interval>\r\n");
+ }
+ subscribePostitionXml.append("</Query>\r\n");
+
+ String tm = Long.toString(System.currentTimeMillis());
+ Request request = headerProvider.createSubscribeRequest(device, subscribePostitionXml.toString(), "viaTagPos" + tm, "fromTagPos" + tm, null, expires, "Position;id=" + tm.substring(tm.length() - 4));
+ transmitRequest(device, request);
+
+ return true;
+
+ } catch ( NumberFormatException | ParseException | InvalidArgumentException | SipException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+
private ClientTransaction transmitRequest(Device device, Request request) throws SipException {
return transmitRequest(device, request, null, null);
}
--
Gitblit v1.8.0