From ffb21248cb270475ce9156b5056e591e14cbc20d Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期二, 30 五月 2023 11:20:22 +0800
Subject: [PATCH] 去除多余配置
---
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java | 228 ++++++++++++++++++++++++++++++++------------------------
1 files changed, 131 insertions(+), 97 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
index 81dd8d8..07a1538 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
@@ -1,11 +1,10 @@
package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
-import com.alibaba.fastjson2.JSONObject;
+import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.DynamicTask;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.*;
-import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
-import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
+import com.genersoft.iot.vmp.gb28181.session.SSRCFactory;
import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver;
import com.genersoft.iot.vmp.gb28181.transmit.SIPSender;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
@@ -20,6 +19,8 @@
import com.genersoft.iot.vmp.service.IPlayService;
import com.genersoft.iot.vmp.service.IStreamProxyService;
import com.genersoft.iot.vmp.service.IStreamPushService;
+import com.genersoft.iot.vmp.service.bean.ErrorCallback;
+import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
import com.genersoft.iot.vmp.service.bean.MessageForPushChannel;
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
import com.genersoft.iot.vmp.service.redisMsg.RedisGbPlayMsgListener;
@@ -74,6 +75,9 @@
private IRedisCatchStorage redisCatchStorage;
@Autowired
+ private SSRCFactory ssrcFactory;
+
+ @Autowired
private DynamicTask dynamicTask;
@Autowired
@@ -96,9 +100,6 @@
@Autowired
private SIPProcessorObserver sipProcessorObserver;
-
- @Autowired
- private VideoStreamSessionManager sessionManager;
@Autowired
private UserSetting userSetting;
@@ -241,18 +242,15 @@
String contentString = new String(request.getRawContent());
// jainSip涓嶆敮鎸亂=瀛楁锛� 绉婚櫎浠ヨВ鏋愩��
- int ssrcIndex = contentString.indexOf("y=");
// 妫�鏌ユ槸鍚︽湁y瀛楁
- String ssrcDefault = "0000000000";
- String ssrc;
+ int ssrcIndex = contentString.indexOf("y=");
+
SessionDescription sdp;
if (ssrcIndex >= 0) {
//ssrc瑙勫畾闀垮害涓�10涓瓧鑺傦紝涓嶅彇浣欎笅闀垮害浠ラ伩鍏嶅悗缁繕鏈夆�渇=鈥濆瓧娈�
- ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
- String substring = contentString.substring(0, contentString.indexOf("y="));
+ String substring = contentString.substring(0, ssrcIndex);
sdp = SdpFactory.getInstance().createSessionDescription(substring);
} else {
- ssrc = ssrcDefault;
sdp = SdpFactory.getInstance().createSessionDescription(contentString);
}
String sessionName = sdp.getSessionName().getValue();
@@ -316,7 +314,7 @@
String username = sdp.getOrigin().getUsername();
String addressStr = sdp.getConnection().getAddress();
- logger.info("[涓婄骇鐐规挱]鐢ㄦ埛锛歿}锛� 閫氶亾锛歿}, 鍦板潃锛歿}:{}锛� ssrc锛歿}", username, channelId, addressStr, port, ssrc);
+
Device device = null;
// 閫氳繃 channel 鍜� gbStream 鏄惁涓簄ull 鍊煎垽鏂潵婧愭槸鐩存挱娴佸悎閫傚浗鏍�
if (channel != null) {
@@ -340,6 +338,25 @@
}
return;
}
+
+ String ssrc;
+ if (userSetting.getUseCustomSsrcForParentInvite() || ssrcIndex < 0) {
+ // 涓婄骇骞冲彴鐐规挱鏃朵笉浣跨敤涓婄骇骞冲彴鎸囧畾鐨剆src锛屼娇鐢ㄨ嚜瀹氫箟鐨剆src锛屽弬鑰冨浗鏍囨枃妗�-鐐规挱澶栧煙璁惧濯掍綋娴丼SRC澶勭悊鏂瑰紡
+ ssrc = "Play".equalsIgnoreCase(sessionName) ? ssrcFactory.getPlaySsrc(mediaServerItem.getId()) : ssrcFactory.getPlayBackSsrc(mediaServerItem.getId());
+ }else {
+ ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
+ }
+ String streamTypeStr = null;
+ if (mediaTransmissionTCP) {
+ if (tcpActive) {
+ streamTypeStr = "TCP-ACTIVE";
+ }else {
+ streamTypeStr = "TCP-PASSIVE";
+ }
+ }else {
+ streamTypeStr = "UDP";
+ }
+ logger.info("[涓婄骇Invite] {}, 骞冲彴锛歿}锛� 閫氶亾锛歿}, 鏀舵祦鍦板潃锛歿}:{}锛屾敹娴佹柟寮忥細{}, ssrc锛歿}", sessionName, username, channelId, addressStr, port, streamTypeStr, ssrc);
SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId,
device.getDeviceId(), channelId, mediaTransmissionTCP, platform.isRtcp());
@@ -360,10 +377,10 @@
Long finalStartTime = startTime;
Long finalStopTime = stopTime;
- ZlmHttpHookSubscribe.Event hookEvent = (mediaServerItemInUSe, responseJSON) -> {
- String app = responseJSON.getString("app");
- String stream = responseJSON.getString("stream");
- logger.info("[涓婄骇鐐规挱]涓嬬骇宸茬粡寮�濮嬫帹娴併�� 鍥炲200OK(SDP)锛� {}/{}", app, stream);
+ ErrorCallback<Object> hookEvent = (code, msg, data) -> {
+ StreamInfo streamInfo = (StreamInfo)data;
+ MediaServerItem mediaServerItemInUSe = mediaServerService.getOne(streamInfo.getMediaServerId());
+ logger.info("[涓婄骇Invite]涓嬬骇宸茬粡寮�濮嬫帹娴併�� 鍥炲200OK(SDP)锛� {}/{}", streamInfo.getApp(), streamInfo.getStream());
// * 0 绛夊緟璁惧鎺ㄦ祦涓婃潵
// * 1 涓嬬骇宸茬粡鎺ㄦ祦锛岀瓑寰呬笂绾у钩鍙板洖澶峚ck
// * 2 鎺ㄦ祦涓�
@@ -405,93 +422,104 @@
}, 60 * 1000);
responseSdpAck(request, content.toString(), platform);
- } catch (SipException e) {
- e.printStackTrace();
- } catch (InvalidArgumentException e) {
- e.printStackTrace();
- } catch (ParseException e) {
- e.printStackTrace();
+ } catch (SipException | InvalidArgumentException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍥炲SdpAck", e);
}
};
- SipSubscribe.Event errorEvent = ((event) -> {
+ ErrorCallback<Object> errorEvent = ((statusCode, msg, data) -> {
// 鏈煡閿欒銆傜洿鎺ヨ浆鍙戣澶囩偣鎾殑閿欒
try {
- Response response = getMessageFactory().createResponse(event.statusCode, evt.getRequest());
- sipSender.transmitRequest(request.getLocalAddress().getHostAddress(), response);
+ if (statusCode > 0) {
+ Response response = getMessageFactory().createResponse(statusCode, evt.getRequest());
+ sipSender.transmitRequest(request.getLocalAddress().getHostAddress(), response);
+ }
} catch (ParseException | SipException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
}
});
sendRtpItem.setApp("rtp");
if ("Playback".equalsIgnoreCase(sessionName)) {
sendRtpItem.setPlayType(InviteStreamType.PLAYBACK);
- SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, null, device.isSsrcCheck(), true);
+ SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, null, null, device.isSsrcCheck(), true, 0, false, device.getStreamModeForParam());
sendRtpItem.setStreamId(ssrcInfo.getStream());
// 鍐欏叆redis锛� 瓒呮椂鏃跺洖澶�
redisCatchStorage.updateSendRTPSever(sendRtpItem);
playService.playBack(mediaServerItem, ssrcInfo, device.getDeviceId(), channelId, DateUtil.formatter.format(start),
- DateUtil.formatter.format(end), null, result -> {
- if (result.getCode() != 0) {
- logger.warn("褰曞儚鍥炴斁澶辫触");
- if (result.getEvent() != null) {
- errorEvent.response(result.getEvent());
- }
+ DateUtil.formatter.format(end),
+ (code, msg, data) -> {
+ if (code == InviteErrorCode.SUCCESS.getCode()){
+ hookEvent.run(code, msg, data);
+ }else if (code == InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode() || code == InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode()){
+ logger.info("[褰曞儚鍥炴斁]瓒呮椂, 鐢ㄦ埛锛歿}锛� 閫氶亾锛歿}", username, channelId);
redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null);
- try {
- responseAck(request, Response.REQUEST_TIMEOUT);
- } catch (SipException | InvalidArgumentException | ParseException e) {
- logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 褰曞儚鍥炴斁 鍙戦�丷EQUEST_TIMEOUT: {}", e.getMessage());
- }
- } else {
- if (result.getMediaServerItem() != null) {
- hookEvent.response(result.getMediaServerItem(), result.getResponse());
- }
+ errorEvent.run(code, msg, data);
+ }else {
+ errorEvent.run(code, msg, data);
}
});
- } else {
- sendRtpItem.setPlayType(InviteStreamType.PLAY);
- SsrcTransaction playTransaction = sessionManager.getSsrcTransaction(device.getDeviceId(), channelId, "play", null);
- if (playTransaction != null) {
- Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, "rtp", playTransaction.getStream());
- if (!streamReady) {
- boolean hasRtpServer = mediaServerService.checkRtpServer(mediaServerItem, "rtp", playTransaction.getStream());
- if (hasRtpServer) {
- logger.info("[涓婄骇鐐规挱]宸茬粡寮�鍚痳tpServer浣嗘槸灏氭湭鏀跺埌娴侊紝寮�鍚洃鍚祦鐨勫埌鏉�");
- HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", playTransaction.getStream(), true, "rtsp", mediaServerItem.getId());
- zlmHttpHookSubscribe.addSubscribe(hookSubscribe, hookEvent);
- }else {
- playTransaction = null;
- }
- }
+ }else if ("Download".equalsIgnoreCase(sessionName)) {
+ // 鑾峰彇鎸囧畾鐨勪笅杞介�熷害
+ Vector sdpMediaDescriptions = sdp.getMediaDescriptions(true);
+ MediaDescription mediaDescription = null;
+ String downloadSpeed = "1";
+ if (sdpMediaDescriptions.size() > 0) {
+ mediaDescription = (MediaDescription)sdpMediaDescriptions.get(0);
}
- if (playTransaction == null) {
- String streamId = null;
- if (mediaServerItem.isRtpEnable()) {
- streamId = String.format("%s_%s", device.getDeviceId(), channelId);
- }
- SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, null, device.isSsrcCheck(), false);
- logger.info(JSONObject.toJSONString(ssrcInfo));
- sendRtpItem.setStreamId(ssrcInfo.getStream());
- sendRtpItem.setSsrc(ssrc.equals(ssrcDefault) ? ssrcInfo.getSsrc() : ssrc);
+ if (mediaDescription != null) {
+ downloadSpeed = mediaDescription.getAttribute("downloadspeed");
+ }
- // 鍐欏叆redis锛� 瓒呮椂鏃跺洖澶�
- redisCatchStorage.updateSendRTPSever(sendRtpItem);
- MediaServerItem finalMediaServerItem = mediaServerItem;
- playService.play(mediaServerItem, ssrcInfo, device, channelId, hookEvent, errorEvent, (code, msg) -> {
+ sendRtpItem.setPlayType(InviteStreamType.DOWNLOAD);
+ SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, null, null, device.isSsrcCheck(), true, 0, false, device.getStreamModeForParam());
+ sendRtpItem.setStreamId(ssrcInfo.getStream());
+ // 鍐欏叆redis锛� 瓒呮椂鏃跺洖澶�
+ redisCatchStorage.updateSendRTPSever(sendRtpItem);
+ playService.download(mediaServerItem, ssrcInfo, device.getDeviceId(), channelId, DateUtil.formatter.format(start),
+ DateUtil.formatter.format(end), Integer.parseInt(downloadSpeed),
+ (code, msg, data) -> {
+ if (code == InviteErrorCode.SUCCESS.getCode()){
+ hookEvent.run(code, msg, data);
+ }else if (code == InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode() || code == InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode()){
+ logger.info("[褰曞儚涓嬭浇]瓒呮椂, 鐢ㄦ埛锛歿}锛� 閫氶亾锛歿}", username, channelId);
+ redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null);
+ errorEvent.run(code, msg, data);
+ }else {
+ errorEvent.run(code, msg, data);
+ }
+ });
+ }else {
+ sendRtpItem.setPlayType(InviteStreamType.PLAY);
+ String streamId = null;
+ if (mediaServerItem.isRtpEnable()) {
+ streamId = String.format("%s_%s", device.getDeviceId(), channelId);
+ }else {
+ streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase();
+ }
+ sendRtpItem.setStreamId(streamId);
+ redisCatchStorage.updateSendRTPSever(sendRtpItem);
+ playService.play(mediaServerItem, device.getDeviceId(), channelId, ((code, msg, data) -> {
+ if (code == InviteErrorCode.SUCCESS.getCode()){
+ hookEvent.run(code, msg, data);
+ }else if (code == InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode() || code == InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode()){
logger.info("[涓婄骇鐐规挱]瓒呮椂, 鐢ㄦ埛锛歿}锛� 閫氶亾锛歿}", username, channelId);
redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null);
- });
- } else {
- sendRtpItem.setStreamId(playTransaction.getStream());
- // 鍐欏叆redis锛� 瓒呮椂鏃跺洖澶�
- redisCatchStorage.updateSendRTPSever(sendRtpItem);
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("app", sendRtpItem.getApp());
- jsonObject.put("stream", sendRtpItem.getStreamId());
- hookEvent.response(mediaServerItem, jsonObject);
- }
+ errorEvent.run(code, msg, data);
+ }else {
+ errorEvent.run(code, msg, data);
+ }
+ }));
+
}
} else if (gbStream != null) {
+
+ String ssrc;
+ if (userSetting.getUseCustomSsrcForParentInvite() || ssrcIndex < 0) {
+ // 涓婄骇骞冲彴鐐规挱鏃朵笉浣跨敤涓婄骇骞冲彴鎸囧畾鐨剆src锛屼娇鐢ㄨ嚜瀹氫箟鐨剆src锛屽弬鑰冨浗鏍囨枃妗�-鐐规挱澶栧煙璁惧濯掍綋娴丼SRC澶勭悊鏂瑰紡
+ ssrc = "Play".equalsIgnoreCase(sessionName) ? ssrcFactory.getPlaySsrc(mediaServerItem.getId()) : ssrcFactory.getPlayBackSsrc(mediaServerItem.getId());
+ }else {
+ ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
+ }
+
if("push".equals(gbStream.getStreamType())) {
if (streamPushItem != null && streamPushItem.isPushIng()) {
// 鎺ㄦ祦鐘舵��
@@ -521,7 +549,7 @@
} catch (SdpParseException e) {
logger.error("sdp瑙f瀽閿欒", e);
} catch (SdpException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
}
}
@@ -533,7 +561,7 @@
int port, Boolean tcpActive, boolean mediaTransmissionTCP,
String channelId, String addressStr, String ssrc, String requesterId) {
Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, gbStream.getApp(), gbStream.getStream());
- if (streamReady) {
+ if (streamReady != null && streamReady) {
// 鑷钩鍙板唴瀹�
SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId,
gbStream.getApp(), gbStream.getStream(), channelId, mediaTransmissionTCP, platform.isRtcp());
@@ -572,7 +600,7 @@
// 鎺ㄦ祦
if (streamPushItem.isSelf()) {
Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, gbStream.getApp(), gbStream.getStream());
- if (streamReady) {
+ if (streamReady != null && streamReady) {
// 鑷钩鍙板唴瀹�
SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId,
gbStream.getApp(), gbStream.getStream(), channelId, mediaTransmissionTCP, platform.isRtcp());
@@ -676,11 +704,11 @@
mediaListManager.removedChannelOnlineEventLister(gbStream.getApp(), gbStream.getStream());
responseAck(request, Response.REQUEST_TIMEOUT); // 瓒呮椂
} catch (SipException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
} catch (InvalidArgumentException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
} catch (ParseException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
}
}, userSetting.getPlatformPlayTimeout());
// 娣诲姞鐩戝惉
@@ -699,11 +727,11 @@
try {
responseAck(request, Response.BUSY_HERE);
} catch (SipException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
} catch (InvalidArgumentException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
} catch (ParseException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
}
return;
}
@@ -761,11 +789,11 @@
try {
responseAck(request, Response.BUSY_HERE);
} catch (SipException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
} catch (InvalidArgumentException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
} catch (ParseException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
}
return;
}
@@ -818,7 +846,13 @@
content.append("s=Play\r\n");
content.append("c=IN IP4 " + mediaServerItem.getSdpIp() + "\r\n");
content.append("t=0 0\r\n");
- content.append("m=video " + sendRtpItem.getLocalPort() + " RTP/AVP 96\r\n");
+ // 闈炰弗鏍兼ā寮忕鍙d笉缁熶竴, 澧炲姞鍏煎鎬э紝淇敼涓轰竴涓笉涓�0鐨勭鍙�
+ int localPort = sendRtpItem.getLocalPort();
+ if(localPort == 0)
+ {
+ localPort = new Random().nextInt(65535) + 1;
+ }
+ content.append("m=video " + localPort + " RTP/AVP 96\r\n");
content.append("a=sendonly\r\n");
content.append("a=rtpmap:96 PS/90000\r\n");
if (sendRtpItem.isTcp()) {
@@ -835,11 +869,11 @@
try {
return responseSdpAck(request, content.toString(), platform);
} catch (SipException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
} catch (InvalidArgumentException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
} catch (ParseException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
}
return null;
}
--
Gitblit v1.8.0