Commit 667266f387375524a2d4a0b48ab13465dcf83dbb
1 parent
5d541e4a
增加移动位置查询和订阅功能,优化信令Tag的生成
Showing
2 changed files
with
78 additions
and
11 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java
| @@ -214,7 +214,16 @@ public interface ISIPCommander { | @@ -214,7 +214,16 @@ public interface ISIPCommander { | ||
| 214 | * | 214 | * |
| 215 | * @param device 视频设备 | 215 | * @param device 视频设备 |
| 216 | */ | 216 | */ |
| 217 | - boolean mobilePostitionQuery(Device device); | 217 | + boolean mobilePostitionQuery(Device device, SipSubscribe.Event errorEvent); |
| 218 | + | ||
| 219 | + /** | ||
| 220 | + * 订阅、取消订阅移动位置 | ||
| 221 | + * | ||
| 222 | + * @param device 视频设备 | ||
| 223 | + * @param expires 订阅超时时间(值=0时为取消订阅) | ||
| 224 | + * @param interval 上报时间间隔 | ||
| 225 | + */ | ||
| 226 | + boolean mobilePositionSubscribe(Device device, int expires, int interval); | ||
| 218 | 227 | ||
| 219 | /** | 228 | /** |
| 220 | * 释放rtpserver | 229 | * 释放rtpserver |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
| @@ -235,7 +235,8 @@ public class SIPCommander implements ISIPCommander { | @@ -235,7 +235,8 @@ public class SIPCommander implements ISIPCommander { | ||
| 235 | ptzXml.append("</Info>\r\n"); | 235 | ptzXml.append("</Info>\r\n"); |
| 236 | ptzXml.append("</Control>\r\n"); | 236 | ptzXml.append("</Control>\r\n"); |
| 237 | 237 | ||
| 238 | - Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtzTag", null); | 238 | + String tm = Long.toString(System.currentTimeMillis()); |
| 239 | + Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtz" + tm, null); | ||
| 239 | 240 | ||
| 240 | transmitRequest(device, request); | 241 | transmitRequest(device, request); |
| 241 | return true; | 242 | return true; |
| @@ -271,7 +272,8 @@ public class SIPCommander implements ISIPCommander { | @@ -271,7 +272,8 @@ public class SIPCommander implements ISIPCommander { | ||
| 271 | ptzXml.append("</Info>\r\n"); | 272 | ptzXml.append("</Info>\r\n"); |
| 272 | ptzXml.append("</Control>\r\n"); | 273 | ptzXml.append("</Control>\r\n"); |
| 273 | 274 | ||
| 274 | - Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtzTag", null); | 275 | + String tm = Long.toString(System.currentTimeMillis()); |
| 276 | + Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtz" + tm, null); | ||
| 275 | transmitRequest(device, request); | 277 | transmitRequest(device, request); |
| 276 | return true; | 278 | return true; |
| 277 | } catch (SipException | ParseException | InvalidArgumentException e) { | 279 | } catch (SipException | ParseException | InvalidArgumentException e) { |
| @@ -383,7 +385,8 @@ public class SIPCommander implements ISIPCommander { | @@ -383,7 +385,8 @@ public class SIPCommander implements ISIPCommander { | ||
| 383 | 385 | ||
| 384 | content.append("y="+ssrc+"\r\n");//ssrc | 386 | content.append("y="+ssrc+"\r\n");//ssrc |
| 385 | 387 | ||
| 386 | - Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "live", null, ssrc); | 388 | + String tm = Long.toString(System.currentTimeMillis()); |
| 389 | + Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "FromInvt" + tm, null, ssrc); | ||
| 387 | 390 | ||
| 388 | ClientTransaction transaction = transmitRequest(device, request, errorEvent); | 391 | ClientTransaction transaction = transmitRequest(device, request, errorEvent); |
| 389 | streamSession.put(streamId, transaction); | 392 | streamSession.put(streamId, transaction); |
| @@ -482,7 +485,8 @@ public class SIPCommander implements ISIPCommander { | @@ -482,7 +485,8 @@ public class SIPCommander implements ISIPCommander { | ||
| 482 | 485 | ||
| 483 | content.append("y="+ssrc+"\r\n");//ssrc | 486 | content.append("y="+ssrc+"\r\n");//ssrc |
| 484 | 487 | ||
| 485 | - Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "playback", null); | 488 | + String tm = Long.toString(System.currentTimeMillis()); |
| 489 | + Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "fromplybck" + tm, null); | ||
| 486 | 490 | ||
| 487 | ClientTransaction transaction = transmitRequest(device, request, errorEvent); | 491 | ClientTransaction transaction = transmitRequest(device, request, errorEvent); |
| 488 | streamSession.put(streamId, transaction); | 492 | streamSession.put(streamId, transaction); |
| @@ -665,7 +669,8 @@ public class SIPCommander implements ISIPCommander { | @@ -665,7 +669,8 @@ public class SIPCommander implements ISIPCommander { | ||
| 665 | catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n"); | 669 | catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n"); |
| 666 | catalogXml.append("</Query>\r\n"); | 670 | catalogXml.append("</Query>\r\n"); |
| 667 | 671 | ||
| 668 | - Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaDeviceInfoBranch", "FromDeviceInfoTag", null); | 672 | + String tm = Long.toString(System.currentTimeMillis()); |
| 673 | + Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaDeviceInfoBranch", "FromDev" + tm, null); | ||
| 669 | 674 | ||
| 670 | transmitRequest(device, request); | 675 | transmitRequest(device, request); |
| 671 | 676 | ||
| @@ -694,7 +699,8 @@ public class SIPCommander implements ISIPCommander { | @@ -694,7 +699,8 @@ public class SIPCommander implements ISIPCommander { | ||
| 694 | catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n"); | 699 | catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n"); |
| 695 | catalogXml.append("</Query>\r\n"); | 700 | catalogXml.append("</Query>\r\n"); |
| 696 | 701 | ||
| 697 | - Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaCatalogBranch", "FromCatalogTag", null); | 702 | + String tm = Long.toString(System.currentTimeMillis()); |
| 703 | + Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaCatalogBranch", "FromCat" + tm, null); | ||
| 698 | 704 | ||
| 699 | transmitRequest(device, request, errorEvent); | 705 | transmitRequest(device, request, errorEvent); |
| 700 | } catch (SipException | ParseException | InvalidArgumentException e) { | 706 | } catch (SipException | ParseException | InvalidArgumentException e) { |
| @@ -728,7 +734,8 @@ public class SIPCommander implements ISIPCommander { | @@ -728,7 +734,8 @@ public class SIPCommander implements ISIPCommander { | ||
| 728 | recordInfoXml.append("<Type>all</Type>\r\n"); | 734 | recordInfoXml.append("<Type>all</Type>\r\n"); |
| 729 | recordInfoXml.append("</Query>\r\n"); | 735 | recordInfoXml.append("</Query>\r\n"); |
| 730 | 736 | ||
| 731 | - Request request = headerProvider.createMessageRequest(device, recordInfoXml.toString(), "ViaRecordInfoBranch", "FromRecordInfoTag", null); | 737 | + String tm = Long.toString(System.currentTimeMillis()); |
| 738 | + Request request = headerProvider.createMessageRequest(device, recordInfoXml.toString(), "ViaRecordInfoBranch", "fromRec" + tm, null); | ||
| 732 | 739 | ||
| 733 | transmitRequest(device, request); | 740 | transmitRequest(device, request); |
| 734 | } catch (SipException | ParseException | InvalidArgumentException e) { | 741 | } catch (SipException | ParseException | InvalidArgumentException e) { |
| @@ -777,11 +784,62 @@ public class SIPCommander implements ISIPCommander { | @@ -777,11 +784,62 @@ public class SIPCommander implements ISIPCommander { | ||
| 777 | * @param device 视频设备 | 784 | * @param device 视频设备 |
| 778 | */ | 785 | */ |
| 779 | @Override | 786 | @Override |
| 780 | - public boolean mobilePostitionQuery(Device device) { | ||
| 781 | - // TODO Auto-generated method stub | ||
| 782 | - return false; | 787 | + public boolean mobilePostitionQuery(Device device, SipSubscribe.Event errorEvent) { |
| 788 | + try { | ||
| 789 | + StringBuffer mobilePostitionXml = new StringBuffer(200); | ||
| 790 | + mobilePostitionXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n"); | ||
| 791 | + mobilePostitionXml.append("<Query>\r\n"); | ||
| 792 | + mobilePostitionXml.append("<CmdType>MobilePosition</CmdType>\r\n"); | ||
| 793 | + mobilePostitionXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n"); | ||
| 794 | + mobilePostitionXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n"); | ||
| 795 | + mobilePostitionXml.append("<Interval>60</Interval>\r\n"); | ||
| 796 | + mobilePostitionXml.append("</Query>\r\n"); | ||
| 797 | + | ||
| 798 | + String tm = Long.toString(System.currentTimeMillis()); | ||
| 799 | + Request request = headerProvider.createMessageRequest(device, mobilePostitionXml.toString(), "viaTagPos" + tm, "fromTagPos" + tm, null); | ||
| 800 | + | ||
| 801 | + transmitRequest(device, request, errorEvent); | ||
| 802 | + | ||
| 803 | + } catch (SipException | ParseException | InvalidArgumentException e) { | ||
| 804 | + e.printStackTrace(); | ||
| 805 | + return false; | ||
| 806 | + } | ||
| 807 | + return true; | ||
| 808 | + } | ||
| 809 | + | ||
| 810 | + /** | ||
| 811 | + * 订阅、取消订阅移动位置 | ||
| 812 | + * | ||
| 813 | + * @param device 视频设备 | ||
| 814 | + * @param expires 订阅超时时间 | ||
| 815 | + * @param interval 上报时间间隔 | ||
| 816 | + */ | ||
| 817 | + public boolean mobilePositionSubscribe(Device device, int expires, int interval) { | ||
| 818 | + try { | ||
| 819 | + StringBuffer subscribePostitionXml = new StringBuffer(200); | ||
| 820 | + subscribePostitionXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n"); | ||
| 821 | + subscribePostitionXml.append("<Query>\r\n"); | ||
| 822 | + subscribePostitionXml.append("<CmdType>MobilePosition</CmdType>\r\n"); | ||
| 823 | + subscribePostitionXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n"); | ||
| 824 | + subscribePostitionXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n"); | ||
| 825 | + if (expires > 0) { | ||
| 826 | + subscribePostitionXml.append("<Interval>" + String.valueOf(interval) + "</Interval>\r\n"); | ||
| 827 | + } | ||
| 828 | + subscribePostitionXml.append("</Query>\r\n"); | ||
| 829 | + | ||
| 830 | + String tm = Long.toString(System.currentTimeMillis()); | ||
| 831 | + Request request = headerProvider.createSubscribeRequest(device, subscribePostitionXml.toString(), "viaTagPos" + tm, "fromTagPos" + tm, null, expires, "Position;id=" + tm.substring(tm.length() - 4)); | ||
| 832 | + transmitRequest(device, request); | ||
| 833 | + | ||
| 834 | + return true; | ||
| 835 | + | ||
| 836 | + } catch ( NumberFormatException | ParseException | InvalidArgumentException | SipException e) { | ||
| 837 | + e.printStackTrace(); | ||
| 838 | + return false; | ||
| 839 | + } | ||
| 783 | } | 840 | } |
| 784 | 841 | ||
| 842 | + | ||
| 785 | private ClientTransaction transmitRequest(Device device, Request request) throws SipException { | 843 | private ClientTransaction transmitRequest(Device device, Request request) throws SipException { |
| 786 | return transmitRequest(device, request, null, null); | 844 | return transmitRequest(device, request, null, null); |
| 787 | } | 845 | } |