From 4604aaea99925415db8d9efe1d7e68d6f59e93c8 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期日, 02 七月 2023 13:53:45 +0800
Subject: [PATCH] 优化语音对讲支持根据设备设置释放收到ACK后开始发流
---
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java | 60 ++++++++++++++++++++++++------------------------------------
1 files changed, 24 insertions(+), 36 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
index 65c479f..ea998e9 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
@@ -16,16 +16,11 @@
import com.genersoft.iot.vmp.gb28181.session.AudioBroadcastManager;
import com.genersoft.iot.vmp.gb28181.session.SSRCFactory;
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
-import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
-import com.genersoft.iot.vmp.media.zlm.AssistRESTfulUtils;
-import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
-import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
-import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
+import com.genersoft.iot.vmp.media.zlm.*;
import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory;
-import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForRtpServerTimeout;
import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.media.zlm.dto.hook.HookParam;
@@ -95,7 +90,7 @@
private IInviteStreamService inviteStreamService;
@Autowired
- private DeferredResultHolder resultHolder;
+ private SendRtpPortManager sendRtpPortManager;
@Autowired
private ZLMRESTfulUtils zlmresTfulUtils;
@@ -235,8 +230,8 @@
sendRtpItem.setUsePs(false);
sendRtpItem.setReceiveStream(stream + "_talk");
-
- int port = zlmrtpServerFactory.keepPort(mediaServerItem, playSsrc, null);
+ String callId = SipUtils.getNewCallId();
+ int port = sendRtpPortManager.getNextPort(mediaServerItem.getId());
//绔彛鑾峰彇澶辫触鐨剆srcInfo 娌℃湁蹇呰鍙戦�佺偣鎾寚浠�
if (port <= 0) {
logger.info("[璇煶瀵硅] 绔彛鍒嗛厤寮傚父锛宒eviceId={},channelId={}", device.getDeviceId(), channelId);
@@ -264,9 +259,6 @@
}
}, userSetting.getPlayTimeout());
- String callId = SipUtils.getNewCallId();
-
- zlmrtpServerFactory.releasePort(mediaServerItem, playSsrc);
Map<String, Object> param = new HashMap<>(12);
param.put("vhost","__defaultVhost__");
param.put("app", sendRtpItem.getApp());
@@ -362,7 +354,7 @@
null);
return;
}
- logger.info("[鐐规挱寮�濮媇 deviceId: {}, channelId: {},鐮佹祦绫诲瀷锛歿},鏀舵祦绔彛锛� {}, 鏀舵祦妯″紡锛歿}, SSRC: {}, SSRC鏍¢獙锛歿}",
+ logger.info("[鐐规挱寮�濮媇 deviceId: {}, channelId: {},鐮佹祦绫诲瀷锛歿}, 鏀舵祦绔彛锛� {}, 鏀舵祦妯″紡锛歿}, SSRC: {}, SSRC鏍¢獙锛歿}",
device.getDeviceId(), channelId, device.isSwitchPrimarySubStream() ? "杈呯爜娴�" : "涓荤爜娴�", ssrcInfo.getPort(),
device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck());
//绔彛鑾峰彇澶辫触鐨剆srcInfo 娌℃湁蹇呰鍙戦�佺偣鎾寚浠�
@@ -445,7 +437,7 @@
InviteErrorCode.SUCCESS.getCode(),
InviteErrorCode.SUCCESS.getMsg(),
streamInfo);
- logger.info("[鐐规挱鎴愬姛] deviceId: {}, channelId: {},鐮佹祦绫诲瀷锛歿}", device.getDeviceId(),
+ logger.info("[鐐规挱鎴愬姛] deviceId: {}, channelId:{}, 鐮佹祦绫诲瀷锛歿}", device.getDeviceId(),
device.isSwitchPrimarySubStream() ? "杈呯爜娴�" : "涓荤爜娴�");
String streamUrl;
if (mediaServerItemInuse.getRtspPort() != 0) {
@@ -1434,14 +1426,10 @@
@Override
public void startPushStream(SendRtpItem sendRtpItem, SIPResponse sipResponse, ParentPlatform platform, CallIdHeader callIdHeader) {
-
// 寮�濮嬪彂娴�
- // 鍙栨秷璁剧疆鐨勮秴鏃朵换鍔�
-// String channelId = request.getCallIdHeader().getCallId();
-
String is_Udp = sendRtpItem.isTcp() ? "0" : "1";
MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
- logger.info("鏀跺埌ACK锛宺tp/{}寮�濮嬫帹娴�, 鐩爣={}:{}锛孲SRC={}, RTCP={}", sendRtpItem.getStream(),
+ logger.info("[寮�濮嬫帹娴乚 rtp/{}, 鐩爣={}:{}锛孲SRC={}, RTCP={}", sendRtpItem.getStream(),
sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc(), sendRtpItem.isRtcp());
Map<String, Object> param = new HashMap<>(12);
param.put("vhost", "__defaultVhost__");
@@ -1467,19 +1455,15 @@
startSendRtpStreamHand(sendRtpItem, platform, json, param, callIdHeader);
});
} else {
- // 濡傛灉鏄潪涓ユ牸妯″紡锛岄渶瑕佸叧闂鍙e崰鐢�
+ // 濡傛灉鏄弗鏍兼ā寮忥紝闇�瑕佸叧闂鍙e崰鐢�
JSONObject startSendRtpStreamResult = null;
if (sendRtpItem.getLocalPort() != 0) {
- HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(sendRtpItem.getSsrc(), null, mediaInfo.getId());
- hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout);
- if (zlmrtpServerFactory.releasePort(mediaInfo, sendRtpItem.getSsrc())) {
- if (sendRtpItem.isTcpActive()) {
- startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param);
- } else {
- param.put("dst_url", sendRtpItem.getIp());
- param.put("dst_port", sendRtpItem.getPort());
- startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
- }
+ if (sendRtpItem.isTcpActive()) {
+ startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param);
+ } else {
+ param.put("dst_url", sendRtpItem.getIp());
+ param.put("dst_port", sendRtpItem.getPort());
+ startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
}
} else {
if (sendRtpItem.isTcpActive()) {
@@ -1497,13 +1481,14 @@
}
@Override
- public void startSendRtpStreamHand(SendRtpItem sendRtpItem, ParentPlatform parentPlatform,
+ public void startSendRtpStreamHand(SendRtpItem sendRtpItem, Object correlationInfo,
JSONObject jsonObject, Map<String, Object> param, CallIdHeader callIdHeader) {
if (jsonObject == null) {
logger.error("RTP鎺ㄦ祦澶辫触: 璇锋鏌LM鏈嶅姟");
} else if (jsonObject.getInteger("code") == 0) {
logger.info("璋冪敤ZLM鎺ㄦ祦鎺ュ彛, 缁撴灉锛� {}", jsonObject);
- logger.info("RTP鎺ㄦ祦鎴愬姛[ {}/{} ]锛寋}->{}:{}, ", param.get("app"), param.get("stream"), jsonObject.getString("local_port"), param.get("dst_url"), param.get("dst_port"));
+ logger.info("RTP鎺ㄦ祦鎴愬姛[ {}/{} ]锛寋}->{}, ", param.get("app"), param.get("stream"), jsonObject.getString("local_port"),
+ sendRtpItem.isTcpActive()?"琚姩鍙戞祦": param.get("dst_url") + ":" + param.get("dst_port"));
} else {
logger.error("RTP鎺ㄦ祦澶辫触: {}, 鍙傛暟锛歿}", jsonObject.getString("msg"), JSONObject.toJSONString(param));
if (sendRtpItem.isOnlyAudio()) {
@@ -1519,10 +1504,13 @@
}
} else {
// 鍚戜笂绾у钩鍙�
- try {
- commanderForPlatform.streamByeCmd(parentPlatform, callIdHeader.getCallId());
- } catch (SipException | InvalidArgumentException | ParseException e) {
- logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍙戦�丅YE: {}", e.getMessage());
+ if (correlationInfo instanceof ParentPlatform) {
+ try {
+ ParentPlatform parentPlatform = (ParentPlatform)correlationInfo;
+ commanderForPlatform.streamByeCmd(parentPlatform, callIdHeader.getCallId());
+ } catch (SipException | InvalidArgumentException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍙戦�丅YE: {}", e.getMessage());
+ }
}
}
}
--
Gitblit v1.8.0