From b55374c75a17c87b9ccb8d5c12abe188875af256 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期三, 14 十月 2020 16:13:39 +0800 Subject: [PATCH] 支持使用udp端口段来启用高性能udp --- src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java | 68 ++++++++++++++++++++++++++------- 1 files changed, 53 insertions(+), 15 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 aaf347d..f901e5e 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 @@ -15,8 +15,15 @@ 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.MediaServerConfig; +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; +import com.genersoft.iot.vmp.media.zlm.ZLMUtils; +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import com.genersoft.iot.vmp.conf.SipConfig; @@ -42,6 +49,9 @@ @Autowired private VideoStreamSessionManager streamSession; + + @Autowired + private IVideoManagerStorager storager; @Autowired @Qualifier(value="tcpSipProvider") @@ -50,7 +60,15 @@ @Autowired @Qualifier(value="udpSipProvider") private SipProvider udpSipProvider; - + + @Autowired + private ZLMUtils zlmUtils; + + @Value("${media.rtp.enable}") + private boolean rtpEnable; + + + /** * 浜戝彴鏂瑰悜鏀炬帶鍒讹紝浣跨敤閰嶇疆鏂囦欢涓殑榛樿闀滃ご绉诲姩閫熷害 * @@ -58,7 +76,6 @@ * @param channelId 棰勮閫氶亾 * @param leftRight 闀滃ご宸︾Щ鍙崇Щ 0:鍋滄 1:宸︾Щ 2:鍙崇Щ * @param upDown 闀滃ご涓婄Щ涓嬬Щ 0:鍋滄 1:涓婄Щ 2:涓嬬Щ - * @param moveSpeed 闀滃ご绉诲姩閫熷害 */ @Override public boolean ptzdirectCmd(Device device, String channelId, int leftRight, int upDown) { @@ -191,23 +208,31 @@ * @param channelId 棰勮閫氶亾 */ @Override - public String playStreamCmd(Device device, String channelId) { + public StreamInfo playStreamCmd(Device device, String channelId) { try { - + String ssrc = streamSession.createPlaySsrc(); String transport = device.getTransport(); + MediaServerConfig mediaInfo = storager.getMediaInfo(); + String mediaPort = null; + // 浣跨敤鍔ㄦ�乽dp绔彛 + if (rtpEnable) { + mediaPort = zlmUtils.getNewRTPPort(ssrc) + ""; + }else { + mediaPort = mediaInfo.getRtpProxyPort(); + } // StringBuffer content = new StringBuffer(200); content.append("v=0\r\n"); - content.append("o="+channelId+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n"); + content.append("o="+channelId+" 0 0 IN IP4 "+mediaInfo.getLocalIP()+"\r\n"); content.append("s=Play\r\n"); - content.append("c=IN IP4 "+sipConfig.getMediaIp()+"\r\n"); + content.append("c=IN IP4 "+mediaInfo.getLocalIP()+"\r\n"); content.append("t=0 0\r\n"); if("TCP".equals(transport)) { - content.append("m=video "+sipConfig.getMediaPort()+" TCP/RTP/AVP 96 98 97\r\n"); + content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n"); } if("UDP".equals(transport)) { - content.append("m=video "+sipConfig.getMediaPort()+" RTP/AVP 96 98 97\r\n"); + 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"); @@ -223,7 +248,18 @@ ClientTransaction transaction = transmitRequest(device, request); streamSession.put(ssrc, transaction); - return ssrc; + DeviceChannel deviceChannel = storager.queryChannel(device.getDeviceId(), channelId); + if (deviceChannel != null) { + deviceChannel.setSsrc(ssrc); + storager.updateChannel(device.getDeviceId(), deviceChannel); + } + + StreamInfo streamInfo = new StreamInfo(); + streamInfo.setSsrc(ssrc); + streamInfo.setCahnnelId(channelId); + streamInfo.setDeviceID(device.getDeviceId()); + storager.startPlay(streamInfo); + return streamInfo; } catch ( SipException | ParseException | InvalidArgumentException e) { e.printStackTrace(); return null; @@ -241,7 +277,7 @@ @Override public String playbackStreamCmd(Device device, String channelId, String startTime, String endTime) { try { - + MediaServerConfig mediaInfo = storager.getMediaInfo(); String ssrc = streamSession.createPlayBackSsrc(); // StringBuffer content = new StringBuffer(200); @@ -249,13 +285,13 @@ content.append("o="+sipConfig.getSipId()+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n"); content.append("s=Playback\r\n"); content.append("u="+channelId+":0\r\n"); - content.append("c=IN IP4 "+sipConfig.getMediaIp()+"\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 "+sipConfig.getMediaPort()+" TCP/RTP/AVP 96 98 97\r\n"); + content.append("m=video "+mediaInfo.getRtpProxyPort()+" TCP/RTP/AVP 96 98 97\r\n"); } if(device.getTransport().equals("UDP")) { - content.append("m=video "+sipConfig.getMediaPort()+" RTP/AVP 96 98 97\r\n"); + content.append("m=video "+mediaInfo.getRtpProxyPort()+" RTP/AVP 96 98 97\r\n"); } content.append("a=recvonly\r\n"); content.append("a=rtpmap:96 PS/90000\r\n"); @@ -272,6 +308,7 @@ ClientTransaction transaction = transmitRequest(device, request); streamSession.put(ssrc, transaction); return ssrc; + } catch ( SipException | ParseException | InvalidArgumentException e) { e.printStackTrace(); return null; @@ -281,8 +318,6 @@ /** * 瑙嗛娴佸仠姝� * - * @param device 瑙嗛璁惧 - * @param channelId 棰勮閫氶亾 */ @Override public void streamByeCmd(String ssrc) { @@ -447,6 +482,8 @@ */ @Override public boolean catalogQuery(Device device) { + // 娓呯┖閫氶亾 + storager.cleanChannelsForDevice(device.getDeviceId()); try { StringBuffer catalogXml = new StringBuffer(200); catalogXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>"); @@ -553,4 +590,5 @@ return clientTransaction; } + } -- Gitblit v1.8.0