From 3d88881f670c4404bf8c7c984a8f484a8f69f60f Mon Sep 17 00:00:00 2001
From: lawrencehj <1934378145@qq.com>
Date: 星期二, 22 六月 2021 11:33:37 +0800
Subject: [PATCH] SSE推送请求应为GET
---
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java | 87 +++++++++++++++++--------------------------
1 files changed, 35 insertions(+), 52 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 5f31d87..2c9339c 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,8 +1,6 @@
package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl;
import java.text.ParseException;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import javax.sip.*;
import javax.sip.address.SipURI;
@@ -10,22 +8,23 @@
import javax.sip.header.ViaHeader;
import javax.sip.message.Request;
-import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.common.StreamInfo;
-import com.genersoft.iot.vmp.conf.MediaServerConfig;
+import com.genersoft.iot.vmp.conf.MediaConfig;
+import com.genersoft.iot.vmp.conf.UserSetup;
+import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
+import gov.nist.javax.sip.message.SIPRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
@@ -81,14 +80,11 @@
@Autowired
private ZLMRESTfulUtils zlmresTfulUtils;
- @Value("${media.rtp.enable}")
- private boolean rtpEnable;
+ @Autowired
+ private MediaConfig mediaConfig;
- @Value("${media.seniorSdp}")
- private boolean seniorSdp;
-
- @Value("${media.autoApplyPlay}")
- private boolean autoApplyPlay;
+ @Autowired
+ private UserSetup userSetup;
@Autowired
private ZLMHttpHookSubscribe subscribe;
@@ -276,7 +272,7 @@
public boolean frontEndCmd(Device device, String channelId, int cmdCode, int parameter1, int parameter2, int combineCode2) {
try {
String cmdStr= frontEndCmdString(cmdCode, parameter1, parameter2, combineCode2);
- System.out.println("鎺у埗瀛楃涓诧細" + cmdStr);
+ logger.info("鎺у埗瀛楃涓诧細" + cmdStr);
StringBuffer ptzXml = new StringBuffer(200);
ptzXml.append("<?xml version=\"1.0\" ?>\r\n");
ptzXml.append("<Control>\r\n");
@@ -349,21 +345,21 @@
try {
if (device == null) return;
String ssrc = streamSession.createPlaySsrc();
- if (rtpEnable) {
+ if (mediaConfig.isRtpEnable()) {
streamId = String.format("gb_play_%s_%s", device.getDeviceId(), channelId);
}else {
streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase();
}
String streamMode = device.getStreamMode().toUpperCase();
- MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
+ ZLMServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
if (mediaInfo == null) {
logger.warn("鐐规挱鏃跺彂鐜癦LM灏氭湭杩炴帴...");
return;
}
- String mediaPort = null;
+ Integer mediaPort = null;
// 浣跨敤鍔ㄦ�乽dp绔彛
- if (rtpEnable) {
- mediaPort = zlmrtpServerFactory.createRTPServer(streamId) + "";
+ if (mediaConfig.isRtpEnable()) {
+ mediaPort = zlmrtpServerFactory.createRTPServer(streamId);
}else {
mediaPort = mediaInfo.getRtpProxyPort();
}
@@ -375,7 +371,7 @@
subscribeKey.put("regist", true);
subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey, json->{
- if (json.getJSONArray("tracks") == null) return;
+ if (userSetup.isWaitTrack() && json.getJSONArray("tracks") == null) return;
event.response(json);
subscribe.removeSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey);
});
@@ -383,12 +379,12 @@
StringBuffer content = new StringBuffer(200);
content.append("v=0\r\n");
// content.append("o=" + sipConfig.getSipId() + " 0 0 IN IP4 "+mediaInfo.getWanIp()+"\r\n");
- content.append("o="+"00000"+" 0 0 IN IP4 "+mediaInfo.getWanIp()+"\r\n");
+ content.append("o="+"00000"+" 0 0 IN IP4 "+mediaInfo.getSdpIp()+"\r\n");
content.append("s=Play\r\n");
- content.append("c=IN IP4 "+mediaInfo.getWanIp()+"\r\n");
+ content.append("c=IN IP4 "+mediaInfo.getSdpIp()+"\r\n");
content.append("t=0 0\r\n");
- if (seniorSdp) {
+ if (userSetup.isSeniorSdp()) {
if("TCP-PASSIVE".equals(streamMode)) {
content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
}else if ("TCP-ACTIVE".equals(streamMode)) {
@@ -425,19 +421,12 @@
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-PASSIVE".equals(streamMode)) { // tcp琚姩妯″紡
+ if ("TCP-PASSIVE".equals(streamMode)) { // tcp琚姩妯″紡
content.append("a=setup:passive\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-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("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");
}
}
@@ -473,7 +462,7 @@
public void playbackStreamCmd(Device device, String channelId, String startTime, String endTime, ZLMHttpHookSubscribe.Event event
, SipSubscribe.Event errorEvent) {
try {
- MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
+ ZLMServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
String ssrc = streamSession.createPlayBackSsrc();
String streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase();
// 娣诲姞璁㈤槄
@@ -481,9 +470,9 @@
subscribeKey.put("app", "rtp");
subscribeKey.put("stream", streamId);
subscribeKey.put("regist", true);
-
+ logger.debug("褰曞儚鍥炴斁娣诲姞璁㈤槄锛岃闃呭唴瀹癸細" + subscribeKey.toString());
subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey, json->{
- if (json.getJSONArray("tracks") == null) return;
+ if (userSetup.isWaitTrack() && json.getJSONArray("tracks") == null) return;
event.response(json);
subscribe.removeSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey);
});
@@ -493,19 +482,19 @@
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 "+mediaInfo.getWanIp()+"\r\n");
+ content.append("c=IN IP4 "+mediaInfo.getSdpIp()+"\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;
+ Integer mediaPort = null;
// 浣跨敤鍔ㄦ�乽dp绔彛
- if (rtpEnable) {
- mediaPort = zlmrtpServerFactory.createRTPServer(streamId) + "";
+ if (mediaConfig.isRtpEnable()) {
+ mediaPort = zlmrtpServerFactory.createRTPServer(streamId);
}else {
mediaPort = mediaInfo.getRtpProxyPort();
}
String streamMode = device.getStreamMode().toUpperCase();
- if (seniorSdp) {
+ if (userSetup.isSeniorSdp()) {
if("TCP-PASSIVE".equals(streamMode)) {
content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
}else if ("TCP-ACTIVE".equals(streamMode)) {
@@ -625,15 +614,9 @@
}
Request byeRequest = dialog.createRequest(Request.BYE);
SipURI byeURI = (SipURI) byeRequest.getRequestURI();
- String vh = transaction.getRequest().getHeader(ViaHeader.NAME).toString();
- Pattern p = Pattern.compile("(\\d+\\.\\d+\\.\\d+\\.\\d+)\\:(\\d+)");
- Matcher matcher = p.matcher(vh);
- if (matcher.find()) {
- String ip = matcher.group(1);
- byeURI.setHost(ip);
- String port = matcher.group(2);
- byeURI.setPort(Integer.parseInt(port));
- }
+ SIPRequest request = (SIPRequest)transaction.getRequest();
+ byeURI.setHost(request.getRemoteAddress().getHostName());
+ byeURI.setPort(request.getRemotePort());
ViaHeader viaHeader = (ViaHeader) byeRequest.getHeader(ViaHeader.NAME);
String protocol = viaHeader.getTransport().toUpperCase();
ClientTransaction clientTransaction = null;
@@ -1454,7 +1437,7 @@
@Override
public void closeRTPServer(Device device, String channelId) {
- if (rtpEnable) {
+ if (mediaConfig.isRtpEnable()) {
String streamId = String.format("gb_play_%s_%s", device.getDeviceId(), channelId);
zlmrtpServerFactory.closeRTPServer(streamId);
}
--
Gitblit v1.8.0