From 667266f387375524a2d4a0b48ab13465dcf83dbb Mon Sep 17 00:00:00 2001 From: Lawrence <1934378145@qq.com> Date: Wed, 27 Jan 2021 15:47:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A7=BB=E5=8A=A8=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E6=9F=A5=E8=AF=A2=E5=92=8C=E8=AE=A2=E9=98=85=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E4=BC=98=E5=8C=96=E4=BF=A1=E4=BB=A4Tag?= =?UTF-8?q?=E7=9A=84=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gb28181/transmit/cmd/ISIPCommander.java | 11 ++- .../transmit/cmd/impl/SIPCommander.java | 78 ++++++++++++++++--- 2 files changed, 78 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java index 67fd9967..7e63af75 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java @@ -214,7 +214,16 @@ public interface ISIPCommander { * * @param device 视频设备 */ - boolean mobilePostitionQuery(Device device); + boolean mobilePostitionQuery(Device device, SipSubscribe.Event errorEvent); + + /** + * 订阅、取消订阅移动位置 + * + * @param device 视频设备 + * @param expires 订阅超时时间(值=0时为取消订阅) + * @param interval 上报时间间隔 + */ + boolean mobilePositionSubscribe(Device device, int expires, int interval); /** * 释放rtpserver 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 7ff5d14a..b661c5e6 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 @@ -235,7 +235,8 @@ public class SIPCommander implements ISIPCommander { ptzXml.append("\r\n"); ptzXml.append("\r\n"); - Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtzTag", null); + String tm = Long.toString(System.currentTimeMillis()); + Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtz" + tm, null); transmitRequest(device, request); return true; @@ -271,7 +272,8 @@ public class SIPCommander implements ISIPCommander { ptzXml.append("\r\n"); ptzXml.append("\r\n"); - Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtzTag", null); + 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) { @@ -383,7 +385,8 @@ public class SIPCommander implements ISIPCommander { content.append("y="+ssrc+"\r\n");//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); @@ -482,7 +485,8 @@ public class SIPCommander implements ISIPCommander { 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); @@ -665,7 +669,8 @@ public class SIPCommander implements ISIPCommander { catalogXml.append("" + device.getDeviceId() + "\r\n"); catalogXml.append("\r\n"); - Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaDeviceInfoBranch", "FromDeviceInfoTag", null); + String tm = Long.toString(System.currentTimeMillis()); + Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaDeviceInfoBranch", "FromDev" + tm, null); transmitRequest(device, request); @@ -694,7 +699,8 @@ public class SIPCommander implements ISIPCommander { catalogXml.append("" + device.getDeviceId() + "\r\n"); catalogXml.append("\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) { @@ -728,7 +734,8 @@ public class SIPCommander implements ISIPCommander { recordInfoXml.append("all\r\n"); recordInfoXml.append("\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) { @@ -777,11 +784,62 @@ public class SIPCommander implements ISIPCommander { * @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("\r\n"); + mobilePostitionXml.append("\r\n"); + mobilePostitionXml.append("MobilePosition\r\n"); + mobilePostitionXml.append("" + (int)((Math.random()*9+1)*100000) + "\r\n"); + mobilePostitionXml.append("" + device.getDeviceId() + "\r\n"); + mobilePostitionXml.append("60\r\n"); + mobilePostitionXml.append("\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("\r\n"); + subscribePostitionXml.append("\r\n"); + subscribePostitionXml.append("MobilePosition\r\n"); + subscribePostitionXml.append("" + (int)((Math.random()*9+1)*100000) + "\r\n"); + subscribePostitionXml.append("" + device.getDeviceId() + "\r\n"); + if (expires > 0) { + subscribePostitionXml.append("" + String.valueOf(interval) + "\r\n"); + } + subscribePostitionXml.append("\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); }