From 19c996774edc4fd915eb4d61008df7e42461405f Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 19 七月 2023 15:37:59 +0800
Subject: [PATCH] 合并主线
---
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java | 143 ++++++++++++++++++++++++-----------------------
1 files changed, 73 insertions(+), 70 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 c345770..e248fd1 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,15 @@
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.*;
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.ZLMServerFactory;
import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
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;
@@ -89,13 +88,13 @@
private IRedisCatchStorage redisCatchStorage;
@Autowired
- private ZLMRTPServerFactory zlmrtpServerFactory;
+ private ZLMServerFactory zlmServerFactory;
@Autowired
private IInviteStreamService inviteStreamService;
@Autowired
- private DeferredResultHolder resultHolder;
+ private SendRtpPortManager sendRtpPortManager;
@Autowired
private ZLMRESTfulUtils zlmresTfulUtils;
@@ -146,7 +145,7 @@
@Override
- public SSRCInfo play(MediaServerItem mediaServerItem, String deviceId, String channelId, ErrorCallback<Object> callback) {
+ public SSRCInfo play(MediaServerItem mediaServerItem, String deviceId, String channelId, String ssrc, ErrorCallback<Object> callback) {
if (mediaServerItem == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "鏈壘鍒板彲鐢ㄧ殑zlm");
}
@@ -172,7 +171,7 @@
String mediaServerId = streamInfo.getMediaServerId();
MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);
- Boolean ready = zlmrtpServerFactory.isStreamReady(mediaInfo, "rtp", streamId);
+ Boolean ready = zlmServerFactory.isStreamReady(mediaInfo, "rtp", streamId);
if (ready != null && ready) {
callback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), streamInfo);
inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,
@@ -188,12 +187,11 @@
}
}
}
-
String streamId = null;
if (mediaServerItem.isRtpEnable()) {
streamId = String.format("%s_%s", device.getDeviceId(), channelId);
}
- SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, null, device.isSsrcCheck(), false, 0, false, false, device.getStreamModeForParam());
+ SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, null, device.isSsrcCheck(), false, 0, false, false,device.getStreamModeForParam());
if (ssrcInfo == null) {
callback.run(InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getCode(), InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getMsg(), null);
inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,
@@ -235,8 +233,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 +262,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());
@@ -280,7 +275,7 @@
param.put("recv_stream_id", sendRtpItem.getReceiveStream());
param.put("close_delay_ms", userSetting.getPlayTimeout() * 1000);
- zlmrtpServerFactory.startSendRtpPassive(mediaServerItem, param, jsonObject -> {
+ zlmServerFactory.startSendRtpPassive(mediaServerItem, param, jsonObject -> {
if (jsonObject == null || jsonObject.getInteger("code") != 0 ) {
mediaServerService.releaseSsrc(mediaServerItem.getId(), sendRtpItem.getSsrc());
logger.info("[璇煶瀵硅]澶辫触 deviceId: {}, channelId: {}", device.getDeviceId(), channelId);
@@ -293,12 +288,12 @@
// 鏌ョ湅璁惧鏄惁宸茬粡鍦ㄦ帹娴�
try {
- cmder.talkStreamCmd(mediaServerItem, sendRtpItem, device, channelId, callId, (MediaServerItem mediaServerItemInuse, JSONObject response) -> {
- logger.info("[璇煶瀵硅] 娴佸凡鐢熸垚锛� 寮�濮嬫帹娴侊細 " + response.toJSONString());
+ cmder.talkStreamCmd(mediaServerItem, sendRtpItem, device, channelId, callId, (mediaServerItemInuse, hookParam) -> {
+ logger.info("[璇煶瀵硅] 娴佸凡鐢熸垚锛� 寮�濮嬫帹娴侊細 " + hookParam);
dynamicTask.stop(timeOutTaskKey);
// TODO 鏆備笉鍋氬鐞�
- }, (MediaServerItem mediaServerItemInuse, JSONObject json) -> {
- logger.info("[璇煶瀵硅] 璁惧寮�濮嬫帹娴侊細 " + json.toJSONString());
+ }, (mediaServerItemInuse, hookParam) -> {
+ logger.info("[璇煶瀵硅] 璁惧寮�濮嬫帹娴侊細 " + hookParam);
dynamicTask.stop(timeOutTaskKey);
}, (event) -> {
@@ -362,7 +357,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,20 +440,9 @@
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) {
- streamUrl = String.format("rtsp://127.0.0.1:%s/%s/%s", mediaServerItemInuse.getRtspPort(), "rtp", ssrcInfo.getStream());
- }else {
- streamUrl = String.format("http://127.0.0.1:%s/%s/%s.live.mp4", mediaServerItemInuse.getHttpPort(), "rtp", ssrcInfo.getStream());
- }
- String path = "snap";
- String fileName = device.getDeviceId() + "_" + channelId + ".jpg";
- // 璇锋眰鎴浘
- logger.info("[璇锋眰鎴浘]: " + fileName);
- zlmresTfulUtils.getSnap(mediaServerItemInuse, streamUrl, 15, 1, path, fileName);
-
+ snapOnPlay(mediaServerItemInuse, device.getDeviceId(), channelId, ssrcInfo.getStream());
}, (event) -> {
inviteInfo.setStatus(InviteSessionStatus.ok);
@@ -541,6 +525,7 @@
InviteErrorCode.SUCCESS.getCode(),
InviteErrorCode.SUCCESS.getMsg(),
streamInfo);
+ snapOnPlay(mediaServerItemInUse, device.getDeviceId(), channelId, stream);
});
return;
}
@@ -616,11 +601,33 @@
}
}
- @Override
- public StreamInfo onPublishHandlerForPlay(MediaServerItem mediaServerItem, JSONObject response, String deviceId, String channelId) {
- StreamInfo streamInfo = onPublishHandler(mediaServerItem, response, deviceId, channelId);
+ /**
+ * 鐐规挱鎴愬姛鏃惰皟鐢ㄦ埅鍥�.
+ *
+ * @param mediaServerItemInuse media
+ * @param deviceId 璁惧 ID
+ * @param channelId 閫氶亾 ID
+ * @param stream ssrc
+ */
+ private void snapOnPlay(MediaServerItem mediaServerItemInuse, String deviceId, String channelId, String stream) {
+ String streamUrl;
+ if (mediaServerItemInuse.getRtspPort() != 0) {
+ streamUrl = String.format("rtsp://127.0.0.1:%s/%s/%s", mediaServerItemInuse.getRtspPort(), "rtp", stream);
+ } else {
+ streamUrl = String.format("http://127.0.0.1:%s/%s/%s.live.mp4", mediaServerItemInuse.getHttpPort(), "rtp", stream);
+ }
+ String path = "snap";
+ String fileName = deviceId + "_" + channelId + ".jpg";
+ // 璇锋眰鎴浘
+ logger.info("[璇锋眰鎴浘]: " + fileName);
+ zlmresTfulUtils.getSnap(mediaServerItemInuse, streamUrl, 15, 1, path, fileName);
+ }
+
+ public StreamInfo onPublishHandlerForPlay(MediaServerItem mediaServerItem, HookParam hookParam, String deviceId, String channelId) {
+ StreamInfo streamInfo = null;
Device device = redisCatchStorage.getDevice(deviceId);
OnStreamChangedHookParam streamChangedHookParam = (OnStreamChangedHookParam)hookParam;
+ streamInfo = onPublishHandler(mediaServerItem, streamChangedHookParam, deviceId, channelId);
if (streamInfo != null) {
DeviceChannel deviceChannel = storager.queryChannel(deviceId, channelId);
if (deviceChannel != null) {
@@ -1241,7 +1248,7 @@
SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(device.getDeviceId(), channelId, null, null);
if (sendRtpItem != null && sendRtpItem.isOnlyAudio()) {
// 鏌ヨ娴佹槸鍚﹀瓨鍦紝涓嶅瓨鍦ㄥ垯璁や负鏄紓甯哥姸鎬�
- Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, sendRtpItem.getApp(), sendRtpItem.getStream());
+ Boolean streamReady = zlmServerFactory.isStreamReady(mediaServerItem, sendRtpItem.getApp(), sendRtpItem.getStream());
if (streamReady) {
logger.warn("璇煶骞挎挱宸茬粡寮�鍚細 {}", channelId);
event.call("璇煶骞挎挱宸茬粡寮�鍚�");
@@ -1254,7 +1261,7 @@
SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(device.getDeviceId(), channelId, null, null);
if (sendRtpItem != null) {
MediaServerItem mediaServer = mediaServerService.getOne(sendRtpItem.getMediaServerId());
- Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServer, "rtp", sendRtpItem.getReceiveStream());
+ Boolean streamReady = zlmServerFactory.isStreamReady(mediaServer, "rtp", sendRtpItem.getReceiveStream());
if (streamReady) {
logger.warn("[璇煶瀵硅] 杩涜涓細 {}", channelId);
event.call("璇煶瀵硅杩涜涓�");
@@ -1285,7 +1292,7 @@
if (sendRtpItem != null && sendRtpItem.isOnlyAudio()) {
// 鏌ヨ娴佹槸鍚﹀瓨鍦紝涓嶅瓨鍦ㄥ垯璁や负鏄紓甯哥姸鎬�
MediaServerItem mediaServerServiceOne = mediaServerService.getOne(sendRtpItem.getMediaServerId());
- Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerServiceOne, sendRtpItem.getApp(), sendRtpItem.getStream());
+ Boolean streamReady = zlmServerFactory.isStreamReady(mediaServerServiceOne, sendRtpItem.getApp(), sendRtpItem.getStream());
if (streamReady) {
logger.warn("璇煶骞挎挱閫氶亾浣跨敤涓細 {}", channelId);
return true;
@@ -1434,14 +1441,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,27 +1470,23 @@
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);
- }
- }
- } else {
if (sendRtpItem.isTcpActive()) {
- startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param);
+ startSendRtpStreamResult = zlmServerFactory.startSendRtpPassive(mediaInfo, param);
} else {
param.put("dst_url", sendRtpItem.getIp());
param.put("dst_port", sendRtpItem.getPort());
- startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
+ startSendRtpStreamResult = zlmServerFactory.startSendRtpStream(mediaInfo, param);
+ }
+ } else {
+ if (sendRtpItem.isTcpActive()) {
+ startSendRtpStreamResult = zlmServerFactory.startSendRtpPassive(mediaInfo, param);
+ } else {
+ param.put("dst_url", sendRtpItem.getIp());
+ param.put("dst_port", sendRtpItem.getPort());
+ startSendRtpStreamResult = zlmServerFactory.startSendRtpStream(mediaInfo, param);
}
}
if (startSendRtpStreamResult != null) {
@@ -1497,13 +1496,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 +1519,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());
+ }
}
}
}
@@ -1547,7 +1550,7 @@
if (sendRtpItem != null && sendRtpItem.isOnlyAudio()) {
// 鏌ヨ娴佹槸鍚﹀瓨鍦紝涓嶅瓨鍦ㄥ垯璁や负鏄紓甯哥姸鎬�
MediaServerItem mediaServer = mediaServerService.getOne(sendRtpItem.getMediaServerId());
- Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServer, sendRtpItem.getApp(), sendRtpItem.getStream());
+ Boolean streamReady = zlmServerFactory.isStreamReady(mediaServer, sendRtpItem.getApp(), sendRtpItem.getStream());
if (streamReady) {
logger.warn("[璇煶瀵硅] 姝e湪璇煶骞挎挱锛屾棤娉曞紑鍚闊抽�氳瘽锛� {}", channelId);
event.call("姝e湪璇煶骞挎挱");
@@ -1561,7 +1564,7 @@
SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(device.getDeviceId(), channelId, stream, null);
if (sendRtpItem != null) {
MediaServerItem mediaServer = mediaServerService.getOne(sendRtpItem.getMediaServerId());
- Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServer, "rtp", sendRtpItem.getReceiveStream());
+ Boolean streamReady = zlmServerFactory.isStreamReady(mediaServer, "rtp", sendRtpItem.getReceiveStream());
if (streamReady) {
logger.warn("[璇煶瀵硅] 杩涜涓細 {}", channelId);
event.call("璇煶瀵硅杩涜涓�");
@@ -1571,7 +1574,7 @@
}
}
- talk(mediaServerItem, device, channelId, stream, (MediaServerItem mediaServerItem1, JSONObject response) -> {
+ talk(mediaServerItem, device, channelId, stream, (mediaServerItem1, hookParam) -> {
logger.info("[璇煶瀵硅] 鏀跺埌璁惧鍙戞潵鐨勬祦");
}, eventResult -> {
logger.warn("[璇煶瀵硅] 澶辫触锛寋}/{}, 閿欒鐮� {} {}", device.getDeviceId(), channelId, eventResult.statusCode, eventResult.msg);
@@ -1613,7 +1616,7 @@
param.put("app", sendRtpItem.getApp());
param.put("stream", sendRtpItem.getStream());
param.put("ssrc", sendRtpItem.getSsrc());
- zlmrtpServerFactory.stopSendRtpStream(mediaServer, param);
+ zlmServerFactory.stopSendRtpStream(mediaServer, param);
}
ssrcFactory.releaseSsrc(mediaServerId, sendRtpItem.getSsrc());
@@ -1662,7 +1665,7 @@
}
MediaServerItem newMediaServerItem = getNewMediaServerItem(device);
- play(newMediaServerItem, deviceId, channelId, (code, msg, data)->{
+ play(newMediaServerItem, deviceId, channelId, null, (code, msg, data)->{
if (code == InviteErrorCode.SUCCESS.getCode()) {
InviteInfo inviteInfoForPlay = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
if (inviteInfoForPlay != null && inviteInfoForPlay.getStreamInfo() != null) {
--
Gitblit v1.8.0