From ac1a4a027a7bd88efb32e9da666bdba4b5fa166f Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期五, 14 一月 2022 17:04:26 +0800 Subject: [PATCH] 支持国标级联的目录订阅功能 --- src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java | 197 ++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 163 insertions(+), 34 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 0d36d52..59e2192 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 @@ -1,20 +1,18 @@ package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl; -import java.lang.reflect.Field; -import java.text.ParseException; -import java.util.HashSet; - -import javax.sip.*; -import javax.sip.address.SipURI; -import javax.sip.header.CallIdHeader; -import javax.sip.header.ViaHeader; -import javax.sip.message.Request; - import com.alibaba.fastjson.JSONObject; +import com.genersoft.iot.vmp.common.StreamInfo; +import com.genersoft.iot.vmp.conf.SipConfig; import com.genersoft.iot.vmp.conf.UserSetup; +import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction; -import com.genersoft.iot.vmp.media.zlm.*; 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; +import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider; +import com.genersoft.iot.vmp.gb28181.utils.DateUtil; +import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; +import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.service.IMediaServerService; import com.genersoft.iot.vmp.service.bean.SSRCInfo; @@ -29,20 +27,20 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.DependsOn; -import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; - -import com.genersoft.iot.vmp.conf.SipConfig; -import com.genersoft.iot.vmp.gb28181.bean.Device; -import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; -import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; -import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider; -import com.genersoft.iot.vmp.gb28181.utils.DateUtil; -import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; import org.springframework.util.StringUtils; +import javax.sip.*; +import javax.sip.address.SipURI; +import javax.sip.header.CallIdHeader; +import javax.sip.header.ViaHeader; +import javax.sip.message.Request; +import java.lang.reflect.Field; +import java.text.ParseException; +import java.util.HashSet; + /** - * @Description:璁惧鑳藉姏鎺ュ彛锛岀敤浜庡畾涔夎澶囩殑鎺у埗銆佹煡璇㈣兘鍔� + * @description:璁惧鑳藉姏鎺ュ彛锛岀敤浜庡畾涔夎澶囩殑鎺у埗銆佹煡璇㈣兘鍔� * @author: swwheihei * @date: 2020骞�5鏈�3鏃� 涓嬪崍9:22:48 */ @@ -55,12 +53,10 @@ @Autowired private SipConfig sipConfig; - @Lazy @Autowired @Qualifier(value="tcpSipProvider") private SipProviderImpl tcpSipProvider; - @Lazy @Autowired @Qualifier(value="udpSipProvider") private SipProviderImpl udpSipProvider; @@ -89,11 +85,6 @@ @Autowired private IMediaServerService mediaServerService; - private SIPDialog dialog; - - public SipConfig getSipConfig() { - return sipConfig; - } /** * 浜戝彴鏂瑰悜鏀炬帶鍒讹紝浣跨敤閰嶇疆鏂囦欢涓殑榛樿闀滃ご绉诲姩閫熷害 @@ -271,7 +262,7 @@ public boolean frontEndCmd(Device device, String channelId, int cmdCode, int parameter1, int parameter2, int combineCode2) { try { String cmdStr= frontEndCmdString(cmdCode, parameter1, parameter2, combineCode2); - logger.info("鎺у埗瀛楃涓诧細" + cmdStr); + logger.debug("鎺у埗瀛楃涓诧細" + cmdStr); StringBuffer ptzXml = new StringBuffer(200); ptzXml.append("<?xml version=\"1.0\" ?>\r\n"); ptzXml.append("<Control>\r\n"); @@ -1171,7 +1162,7 @@ @Override public boolean catalogQuery(Device device, SipSubscribe.Event errorEvent) { // 娓呯┖閫氶亾 - storager.cleanChannelsForDevice(device.getDeviceId()); +// storager.cleanChannelsForDevice(device.getDeviceId()); try { StringBuffer catalogXml = new StringBuffer(200); catalogXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n"); @@ -1204,14 +1195,15 @@ * @param endTime 缁撴潫鏃堕棿,鏍煎紡瑕佹眰锛歽yyy-MM-dd HH:mm:ss */ @Override - public boolean recordInfoQuery(Device device, String channelId, String startTime, String endTime) { - + public boolean recordInfoQuery(Device device, String channelId, String startTime, String endTime, int sn, SipSubscribe.Event errorEvent) { + + try { StringBuffer recordInfoXml = new StringBuffer(200); 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("<SN>" + sn + "</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"); @@ -1228,7 +1220,7 @@ Request request = headerProvider.createMessageRequest(device, recordInfoXml.toString(), "z9hG4bK-ViaRecordInfo-" + tm, "fromRec" + tm, null, callIdHeader); - transmitRequest(device, request); + transmitRequest(device, request, errorEvent); } catch (SipException | ParseException | InvalidArgumentException e) { e.printStackTrace(); return false; @@ -1490,6 +1482,33 @@ } } + @Override + public boolean catalogSubscribe(Device device, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) { + try { + StringBuffer cmdXml = new StringBuffer(200); + cmdXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n"); + cmdXml.append("<Query>\r\n"); + cmdXml.append("<CmdType>Catalog</CmdType>\r\n"); + cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n"); + cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n"); + cmdXml.append("</Query>\r\n"); + + String tm = Long.toString(System.currentTimeMillis()); + + CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() + : udpSipProvider.getNewCallId(); + + Request request = headerProvider.createSubscribeRequest(device, cmdXml.toString(), "z9hG4bK-viaPos-" + tm, "fromTagPos" + tm, null, device.getSubscribeCycleForCatalog(), "Catalog" , callIdHeader); + transmitRequest(device, request, errorEvent, okEvent); + + 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); @@ -1526,4 +1545,114 @@ clientTransaction.sendRequest(); return clientTransaction; } + + /** + * 鍥炴斁鏆傚仠 + */ + @Override + public void playPauseCmd(Device device, StreamInfo streamInfo) { + try { + Long cseq = redisCatchStorage.getCSEQ(Request.INFO); + StringBuffer content = new StringBuffer(200); + content.append("PAUSE RTSP/1.0\r\n"); + content.append("CSeq: " + cseq + "\r\n"); + content.append("PauseTime: now\r\n"); + Request request = headerProvider.createInfoRequest(device, streamInfo, content.toString(), cseq); + logger.info(request.toString()); + ClientTransaction clientTransaction = null; + if ("TCP".equals(device.getTransport())) { + clientTransaction = tcpSipProvider.getNewClientTransaction(request); + } else if ("UDP".equals(device.getTransport())) { + clientTransaction = udpSipProvider.getNewClientTransaction(request); + } + if (clientTransaction != null) { + clientTransaction.sendRequest(); + } + + } catch (SipException | ParseException | InvalidArgumentException e) { + e.printStackTrace(); + } + } + + /** + * 鍥炴斁鎭㈠ + */ + @Override + public void playResumeCmd(Device device, StreamInfo streamInfo) { + try { + Long cseq = redisCatchStorage.getCSEQ(Request.INFO); + StringBuffer content = new StringBuffer(200); + content.append("PLAY RTSP/1.0\r\n"); + content.append("CSeq: " + cseq + "\r\n"); + content.append("Range: npt=now-\r\n"); + Request request = headerProvider.createInfoRequest(device, streamInfo, content.toString(), cseq); + logger.info(request.toString()); + ClientTransaction clientTransaction = null; + if ("TCP".equals(device.getTransport())) { + clientTransaction = tcpSipProvider.getNewClientTransaction(request); + } else if ("UDP".equals(device.getTransport())) { + clientTransaction = udpSipProvider.getNewClientTransaction(request); + } + + clientTransaction.sendRequest(); + + } catch (SipException | ParseException | InvalidArgumentException e) { + e.printStackTrace(); + } + } + + /** + * 鍥炴斁鎷栧姩鎾斁 + */ + @Override + public void playSeekCmd(Device device, StreamInfo streamInfo, long seekTime) { + try { + Long cseq = redisCatchStorage.getCSEQ(Request.INFO); + StringBuffer content = new StringBuffer(200); + content.append("PLAY RTSP/1.0\r\n"); + content.append("CSeq: " + cseq + "\r\n"); + content.append("Range: npt=" + Math.abs(seekTime) + "-\r\n"); + + Request request = headerProvider.createInfoRequest(device, streamInfo, content.toString(), cseq); + logger.info(request.toString()); + ClientTransaction clientTransaction = null; + if ("TCP".equals(device.getTransport())) { + clientTransaction = tcpSipProvider.getNewClientTransaction(request); + } else if ("UDP".equals(device.getTransport())) { + clientTransaction = udpSipProvider.getNewClientTransaction(request); + } + + clientTransaction.sendRequest(); + + } catch (SipException | ParseException | InvalidArgumentException e) { + e.printStackTrace(); + } + } + + /** + * 鍥炴斁鍊嶉�熸挱鏀� + */ + @Override + public void playSpeedCmd(Device device, StreamInfo streamInfo, Double speed) { + try { + Long cseq = redisCatchStorage.getCSEQ(Request.INFO); + StringBuffer content = new StringBuffer(200); + content.append("PLAY RTSP/1.0\r\n"); + content.append("CSeq: " + cseq + "\r\n"); + content.append("Scale: " + String.format("%.1f",speed) + "\r\n"); + Request request = headerProvider.createInfoRequest(device, streamInfo, content.toString(), cseq); + logger.info(request.toString()); + ClientTransaction clientTransaction = null; + if ("TCP".equals(device.getTransport())) { + clientTransaction = tcpSipProvider.getNewClientTransaction(request); + } else if ("UDP".equals(device.getTransport())) { + clientTransaction = udpSipProvider.getNewClientTransaction(request); + } + + clientTransaction.sendRequest(); + + } catch (SipException | ParseException | InvalidArgumentException e) { + e.printStackTrace(); + } + } } -- Gitblit v1.8.0