Lawrence
2020-10-24 e30e28712f7ec5a3c5514484b34bdde11d0954c3
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
@@ -181,15 +181,15 @@
      try {
         String cmdStr= cmdString(leftRight, upDown, inOut, moveSpeed, zoomSpeed);
         StringBuffer ptzXml = new StringBuffer(200);
         ptzXml.append("<?xml version=\"1.0\" ?>");
         ptzXml.append("<Control>");
         ptzXml.append("<CmdType>DeviceControl</CmdType>");
         ptzXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>");
         ptzXml.append("<DeviceID>" + channelId + "</DeviceID>");
         ptzXml.append("<PTZCmd>" + cmdStr + "</PTZCmd>");
         ptzXml.append("<Info>");
         ptzXml.append("</Info>");
         ptzXml.append("</Control>");
         ptzXml.append("<?xml version=\"1.0\" ?>\r\n");
         ptzXml.append("<Control>\r\n");
         ptzXml.append("<CmdType>DeviceControl</CmdType>\r\n");
         ptzXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         ptzXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
         ptzXml.append("<PTZCmd>" + cmdStr + "</PTZCmd>\r\n");
         ptzXml.append("<Info>\r\n");
         ptzXml.append("</Info>\r\n");
         ptzXml.append("</Control>\r\n");
         
         Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtzTag", "ToPtzTag");
         
@@ -212,7 +212,7 @@
      try {
         String ssrc = streamSession.createPlaySsrc();
         String transport = device.getTransport();
         String streamMode = device.getStreamMode().toUpperCase();
         MediaServerConfig mediaInfo = storager.getMediaInfo();
         String mediaPort = null;
         // 使用动态udp端口
@@ -228,20 +228,24 @@
           content.append("s=Play\r\n");
           content.append("c=IN IP4 "+mediaInfo.getLocalIP()+"\r\n");
           content.append("t=0 0\r\n");
           if("TCP".equals(transport)) {
           if("TCP-PASSIVE".equals(streamMode)) {
              content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
         }
           if("UDP".equals(transport)) {
         }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".equals(transport)){
                content.append("a=setup:passive\r\n");
                content.append("a=connection:new\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
           
           Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "live", null);
@@ -286,21 +290,34 @@
           content.append("s=Playback\r\n");
           content.append("u="+channelId+":0\r\n");
           content.append("c=IN IP4 "+mediaInfo.getLocalIP()+"\r\n");
           content.append("t="+DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(startTime)+" "+DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(endTime) +"\r\n");
           if(device.getTransport().equals("TCP")) {
              content.append("m=video "+mediaInfo.getRtpProxyPort()+" TCP/RTP/AVP 96 98 97\r\n");
           content.append("t="+DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(startTime)+" "
               +DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(endTime) +"\r\n");
         String mediaPort = null;
         // 使用动态udp端口
         if (rtpEnable) {
            mediaPort = zlmUtils.getNewRTPPort(ssrc) + "";
         }else {
            mediaPort = mediaInfo.getRtpProxyPort();
         }
           if(device.getTransport().equals("UDP")) {
              content.append("m=video "+mediaInfo.getRtpProxyPort()+" RTP/AVP 96 98 97\r\n");
         String streamMode = device.getStreamMode().toUpperCase();
         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(device.getTransport().equals("TCP")){
                content.append("a=setup:passive\r\n");
                content.append("a=connection:new\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
           
           Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "playback", null);
@@ -458,12 +475,12 @@
   public boolean deviceInfoQuery(Device device) {
      try {
         StringBuffer catalogXml = new StringBuffer(200);
         catalogXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>");
         catalogXml.append("<Query>");
         catalogXml.append("<CmdType>DeviceInfo</CmdType>");
         catalogXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>");
         catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>");
         catalogXml.append("</Query>");
         catalogXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
         catalogXml.append("<Query>\r\n");
         catalogXml.append("<CmdType>DeviceInfo</CmdType>\r\n");
         catalogXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         catalogXml.append("</Query>\r\n");
         
         Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaDeviceInfoBranch", "FromDeviceInfoTag", "ToDeviceInfoTag");
         transmitRequest(device, request);
@@ -486,12 +503,12 @@
      storager.cleanChannelsForDevice(device.getDeviceId());
      try {
         StringBuffer catalogXml = new StringBuffer(200);
         catalogXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>");
         catalogXml.append("<Query>");
         catalogXml.append("<CmdType>Catalog</CmdType>");
         catalogXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>");
         catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>");
         catalogXml.append("</Query>");
         catalogXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
         catalogXml.append("<Query>\r\n");
         catalogXml.append("<CmdType>Catalog</CmdType>\r\n");
         catalogXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         catalogXml.append("</Query>\r\n");
         
         Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaCatalogBranch", "FromCatalogTag", "ToCatalogTag");
         transmitRequest(device, request);
@@ -514,17 +531,17 @@
      
      try {
         StringBuffer recordInfoXml = new StringBuffer(200);
         recordInfoXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>");
         recordInfoXml.append("<Query>");
         recordInfoXml.append("<CmdType>RecordInfo</CmdType>");
         recordInfoXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>");
         recordInfoXml.append("<DeviceID>" + channelId + "</DeviceID>");
         recordInfoXml.append("<StartTime>" + DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(startTime) + "</StartTime>");
         recordInfoXml.append("<EndTime>" + DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(endTime) + "</EndTime>");
         recordInfoXml.append("<Secrecy>0</Secrecy>");
         recordInfoXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
         recordInfoXml.append("<Query>\r\n");
         recordInfoXml.append("<CmdType>RecordInfo</CmdType>\r\n");
         recordInfoXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         recordInfoXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
         recordInfoXml.append("<StartTime>" + DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(startTime) + "</StartTime>\r\n");
         recordInfoXml.append("<EndTime>" + DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(endTime) + "</EndTime>\r\n");
         recordInfoXml.append("<Secrecy>0</Secrecy>\r\n");
         // 大华NVR要求必须增加一个值为all的文本元素节点Type
         recordInfoXml.append("<Type>all</Type>");
         recordInfoXml.append("</Query>");
         recordInfoXml.append("<Type>all</Type>\r\n");
         recordInfoXml.append("</Query>\r\n");
         
         Request request = headerProvider.createMessageRequest(device, recordInfoXml.toString(), "ViaRecordInfoBranch", "FromRecordInfoTag", "ToRecordInfoTag");
         transmitRequest(device, request);