From becea82736dcfc833d1d68021fc3baf1e23acc36 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期二, 04 七月 2023 10:10:48 +0800
Subject: [PATCH] Merge branch 'wvp-28181-2.0' into main-dev
---
src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java | 467 +++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 399 insertions(+), 68 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java
index 708d693..caa72b4 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java
@@ -1,18 +1,32 @@
package com.genersoft.iot.vmp.service.impl;
+import com.genersoft.iot.vmp.common.InviteInfo;
+import com.genersoft.iot.vmp.common.InviteSessionType;
import com.genersoft.iot.vmp.conf.DynamicTask;
-import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
-import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
-import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
-import com.genersoft.iot.vmp.gb28181.bean.SubscribeHolder;
+import com.genersoft.iot.vmp.conf.UserSetting;
+import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
+import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
+import com.genersoft.iot.vmp.gb28181.session.SSRCFactory;
+import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
+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.HookSubscribeForStreamChange;
+import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
+import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam;
+import com.genersoft.iot.vmp.service.IInviteStreamService;
import com.genersoft.iot.vmp.service.IMediaServerService;
import com.genersoft.iot.vmp.service.IPlatformService;
+import com.genersoft.iot.vmp.service.IPlayService;
+import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
+import com.genersoft.iot.vmp.service.bean.InviteTimeOutCallback;
+import com.genersoft.iot.vmp.service.bean.SSRCInfo;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
-import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper;
+import com.genersoft.iot.vmp.storager.dao.*;
+import com.genersoft.iot.vmp.utils.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
@@ -20,10 +34,14 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import javax.sip.TimeoutEvent;
+import javax.sip.InvalidArgumentException;
+import javax.sip.ResponseEvent;
+import javax.sip.SipException;
+import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
/**
* @author lin
@@ -32,6 +50,8 @@
public class PlatformServiceImpl implements IPlatformService {
private final static String REGISTER_KEY_PREFIX = "platform_register_";
+
+ private final static String REGISTER_FAIL_AGAIN_KEY_PREFIX = "platform_register_fail_again_";
private final static String KEEPALIVE_KEY_PREFIX = "platform_keepalive_";
private final static Logger logger = LoggerFactory.getLogger(PlatformServiceImpl.class);
@@ -40,7 +60,19 @@
private ParentPlatformMapper platformMapper;
@Autowired
+ private PlatformCatalogMapper catalogMapper;
+
+ @Autowired
+ private PlatformChannelMapper platformChannelMapper;
+
+ @Autowired
+ private PlatformGbStreamMapper platformGbStreamMapper;
+
+ @Autowired
private IRedisCatchStorage redisCatchStorage;
+
+ @Autowired
+ private SSRCFactory ssrcFactory;
@Autowired
private IMediaServerService mediaServerService;
@@ -52,11 +84,29 @@
private DynamicTask dynamicTask;
@Autowired
- private ZLMRTPServerFactory zlmrtpServerFactory;
+ private ZLMServerFactory ZLMServerFactory;
@Autowired
private SubscribeHolder subscribeHolder;
+ @Autowired
+ private GbStreamMapper gbStreamMapper;
+
+ @Autowired
+ private UserSetting userSetting;
+
+ @Autowired
+ private ZlmHttpHookSubscribe subscribe;
+
+ @Autowired
+ private VideoStreamSessionManager streamSession;
+
+
+ @Autowired
+ private IPlayService playService;
+
+ @Autowired
+ private IInviteStreamService inviteStreamService;
@Override
@@ -93,83 +143,173 @@
if (parentPlatform.isEnable()) {
// 淇濆瓨鏃跺惎鐢ㄥ氨鍙戦�佹敞鍐�
// 娉ㄥ唽鎴愬姛鏃剁敱绋嬪簭鐩存帴璋冪敤浜唎nline鏂规硶
- commanderForPlatform.register(parentPlatform, eventResult -> {
- logger.info("[鍥芥爣绾ц仈] {},娣诲姞鍚戜笂绾ф敞鍐屽け璐ワ紝璇风‘瀹氫笂绾у钩鍙板彲鐢ㄦ椂閲嶆柊淇濆瓨", parentPlatform.getServerGBId());
- }, null);
+ try {
+ commanderForPlatform.register(parentPlatform, eventResult -> {
+ logger.info("[鍥芥爣绾ц仈] {},娣诲姞鍚戜笂绾ф敞鍐屽け璐ワ紝璇风‘瀹氫笂绾у钩鍙板彲鐢ㄦ椂閲嶆柊淇濆瓨", parentPlatform.getServerGBId());
+ }, null);
+ } catch (InvalidArgumentException | ParseException | SipException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈: {}", e.getMessage());
+ }
}
return result > 0;
}
@Override
- public void online(ParentPlatform parentPlatform) {
- logger.info("[鍥芥爣绾ц仈]锛歿}, 骞冲彴涓婄嚎/鏇存柊娉ㄥ唽", parentPlatform.getServerGBId());
+ public boolean update(ParentPlatform parentPlatform) {
+ logger.info("[鍥芥爣绾ц仈]鏇存柊骞冲彴 {}", parentPlatform.getDeviceGBId());
+ parentPlatform.setCharacterSet(parentPlatform.getCharacterSet().toUpperCase());
+ ParentPlatform parentPlatformOld = platformMapper.getParentPlatById(parentPlatform.getId());
+ ParentPlatformCatch parentPlatformCatchOld = redisCatchStorage.queryPlatformCatchInfo(parentPlatformOld.getServerGBId());
+ parentPlatform.setUpdateTime(DateUtil.getNow());
+
+ // 鍋滄蹇冭烦瀹氭椂
+ final String keepaliveTaskKey = KEEPALIVE_KEY_PREFIX + parentPlatformOld.getServerGBId();
+ dynamicTask.stop(keepaliveTaskKey);
+ // 鍋滄娉ㄥ唽瀹氭椂
+ final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatformOld.getServerGBId();
+ dynamicTask.stop(registerTaskKey);
+ // 娉ㄩ攢鏃х殑
+ try {
+ if (parentPlatformOld.isStatus()) {
+ logger.info("淇濆瓨骞冲彴{}鏃跺彂鐜版棫骞冲彴鍦ㄧ嚎锛屽彂閫佹敞閿�鍛戒护", parentPlatformOld.getServerGBId());
+ commanderForPlatform.unregister(parentPlatformOld, parentPlatformCatchOld.getSipTransactionInfo(), null, eventResult -> {
+ logger.info("[鍥芥爣绾ц仈] 娉ㄩ攢鎴愬姛锛� 骞冲彴锛歿}", parentPlatformOld.getServerGBId());
+ });
+ }
+ } catch (InvalidArgumentException | ParseException | SipException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 娉ㄩ攢: {}", e.getMessage());
+ }
+
+ // 鏇存柊鏁版嵁搴�
+ if (parentPlatform.getCatalogGroup() == 0) {
+ parentPlatform.setCatalogGroup(1);
+ }
+ if (parentPlatform.getAdministrativeDivision() == null) {
+ parentPlatform.setAdministrativeDivision(parentPlatform.getAdministrativeDivision());
+ }
+
+ platformMapper.updateParentPlatform(parentPlatform);
+ // 鏇存柊redis
+ redisCatchStorage.delPlatformCatchInfo(parentPlatformOld.getServerGBId());
+ ParentPlatformCatch parentPlatformCatch = new ParentPlatformCatch();
+ parentPlatformCatch.setParentPlatform(parentPlatform);
+ parentPlatformCatch.setId(parentPlatform.getServerGBId());
+ redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
+ // 娉ㄥ唽
+ if (parentPlatform.isEnable()) {
+ // 淇濆瓨鏃跺惎鐢ㄥ氨鍙戦�佹敞鍐�
+ // 娉ㄥ唽鎴愬姛鏃剁敱绋嬪簭鐩存帴璋冪敤浜唎nline鏂规硶
+ try {
+ logger.info("[鍥芥爣绾ц仈] 骞冲彴娉ㄥ唽 {}", parentPlatform.getDeviceGBId());
+ commanderForPlatform.register(parentPlatform, eventResult -> {
+ logger.info("[鍥芥爣绾ц仈] {},娣诲姞鍚戜笂绾ф敞鍐屽け璐ワ紝璇风‘瀹氫笂绾у钩鍙板彲鐢ㄦ椂閲嶆柊淇濆瓨", parentPlatform.getServerGBId());
+ }, null);
+ } catch (InvalidArgumentException | ParseException | SipException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈: {}", e.getMessage());
+ }
+ }
+
+ return false;
+ }
+
+
+ @Override
+ public void online(ParentPlatform parentPlatform, SipTransactionInfo sipTransactionInfo) {
+ logger.info("[鍥芥爣绾ц仈]锛歿}, 骞冲彴涓婄嚎", parentPlatform.getServerGBId());
+ final String registerFailAgainTaskKey = REGISTER_FAIL_AGAIN_KEY_PREFIX + parentPlatform.getServerGBId();
+ dynamicTask.stop(registerFailAgainTaskKey);
+
platformMapper.updateParentPlatformStatus(parentPlatform.getServerGBId(), true);
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
- if (parentPlatformCatch != null) {
- parentPlatformCatch.getParentPlatform().setStatus(true);
- redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
- }else {
+ if (parentPlatformCatch == null) {
parentPlatformCatch = new ParentPlatformCatch();
parentPlatformCatch.setParentPlatform(parentPlatform);
parentPlatformCatch.setId(parentPlatform.getServerGBId());
parentPlatform.setStatus(true);
parentPlatformCatch.setParentPlatform(parentPlatform);
- redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
}
+ parentPlatformCatch.getParentPlatform().setStatus(true);
+ parentPlatformCatch.setSipTransactionInfo(sipTransactionInfo);
+ redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
+
final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatform.getServerGBId();
- if (dynamicTask.contains(registerTaskKey)) {
- dynamicTask.stop(registerTaskKey);
- }
- // 娣诲姞娉ㄥ唽浠诲姟
- dynamicTask.startDelay(registerTaskKey,
+ if (!dynamicTask.isAlive(registerTaskKey)) {
+ logger.info("[鍥芥爣绾ц仈]锛歿}, 娣诲姞瀹氭椂娉ㄥ唽浠诲姟", parentPlatform.getServerGBId());
+ // 娣诲姞娉ㄥ唽浠诲姟
+ dynamicTask.startCron(registerTaskKey,
// 娉ㄥ唽澶辫触锛堟敞鍐屾垚鍔熸椂鐢辩▼搴忕洿鎺ヨ皟鐢ㄤ簡online鏂规硶锛�
- ()->commanderForPlatform.register(parentPlatform, eventResult -> offline(parentPlatform),null),
- parentPlatform.getExpires()*1000);
+ ()-> registerTask(parentPlatform, sipTransactionInfo),
+ parentPlatform.getExpires() * 1000);
+ }
+
final String keepaliveTaskKey = KEEPALIVE_KEY_PREFIX + parentPlatform.getServerGBId();
if (!dynamicTask.contains(keepaliveTaskKey)) {
+ logger.info("[鍥芥爣绾ц仈]锛歿}, 娣诲姞瀹氭椂蹇冭烦浠诲姟", parentPlatform.getServerGBId());
// 娣诲姞蹇冭烦浠诲姟
dynamicTask.startCron(keepaliveTaskKey,
- ()-> commanderForPlatform.keepalive(parentPlatform, eventResult -> {
- // 蹇冭烦澶辫触
- if (eventResult.type == SipSubscribe.EventResultType.timeout) {
- // 蹇冭烦瓒呮椂
- ParentPlatformCatch platformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
- // 姝ゆ椂鏄涓夋蹇冭烦瓒呮椂锛� 骞冲彴绂荤嚎
- if (platformCatch.getKeepAliveReply() == 2) {
- // 璁剧疆骞冲彴绂荤嚎锛屽苟閲嶆柊娉ㄥ唽
- offline(parentPlatform);
- logger.info("[鍥芥爣绾ц仈] {}锛屼笁娆″績璺宠秴鏃跺悗鍐嶆鍙戣捣娉ㄥ唽", parentPlatform.getServerGBId());
- commanderForPlatform.register(parentPlatform, eventResult1 -> {
- logger.info("[鍥芥爣绾ц仈] {}锛屼笁娆″績璺宠秴鏃跺悗鍐嶆鍙戣捣娉ㄥ唽浠嶇劧澶辫触锛屽紑濮嬪畾鏃跺彂璧锋敞鍐岋紝闂撮殧涓�1鍒嗛挓", parentPlatform.getServerGBId());
- // 娣诲姞娉ㄥ唽浠诲姟
- dynamicTask.startCron(registerTaskKey,
- // 娉ㄥ唽澶辫触锛堟敞鍐屾垚鍔熸椂鐢辩▼搴忕洿鎺ヨ皟鐢ㄤ簡online鏂规硶锛�
- ()->logger.info("[鍥芥爣绾ц仈] {},骞冲彴绂荤嚎鍚庢寔缁彂璧锋敞鍐岋紝澶辫触", parentPlatform.getServerGBId()),
- 60*1000);
- }, null);
- }
+ ()-> {
+ try {
+ commanderForPlatform.keepalive(parentPlatform, eventResult -> {
+ // 蹇冭烦澶辫触
+ if (eventResult.type == SipSubscribe.EventResultType.timeout) {
+ // 蹇冭烦瓒呮椂
+ ParentPlatformCatch platformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
+ // 姝ゆ椂鏄涓夋蹇冭烦瓒呮椂锛� 骞冲彴绂荤嚎
+ if (platformCatch.getKeepAliveReply() == 2) {
+ // 璁剧疆骞冲彴绂荤嚎锛屽苟閲嶆柊娉ㄥ唽
+ logger.info("[鍥芥爣绾ц仈] 涓夋蹇冭烦瓒呮椂, 骞冲彴{}({})绂荤嚎", parentPlatform.getName(), parentPlatform.getServerGBId());
+ offline(parentPlatform, false);
- }else {
- logger.warn("[鍥芥爣绾ц仈]鍙戦�佸績璺虫敹鍒伴敊璇紝code锛� {}, msg: {}", eventResult.statusCode, eventResult.msg);
- }
+ }
- }, eventResult -> {
- // 蹇冭烦鎴愬姛
- // 娓呯┖涔嬪墠鐨勫績璺宠秴鏃惰鏁�
- ParentPlatformCatch platformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
- if (platformCatch.getKeepAliveReply() > 0) {
- platformCatch.setKeepAliveReply(0);
- redisCatchStorage.updatePlatformCatchInfo(platformCatch);
+ }else {
+ logger.warn("[鍥芥爣绾ц仈]鍙戦�佸績璺虫敹鍒伴敊璇紝code锛� {}, msg: {}", eventResult.statusCode, eventResult.msg);
+ }
+
+ }, eventResult -> {
+ // 蹇冭烦鎴愬姛
+ // 娓呯┖涔嬪墠鐨勫績璺宠秴鏃惰鏁�
+ ParentPlatformCatch platformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
+ if (platformCatch != null && platformCatch.getKeepAliveReply() > 0) {
+ platformCatch.setKeepAliveReply(0);
+ redisCatchStorage.updatePlatformCatchInfo(platformCatch);
+ }
+ });
+ } catch (SipException | InvalidArgumentException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍙戦�佸績璺�: {}", e.getMessage());
}
- }),
- parentPlatform.getExpires()*1000);
+ },
+ (parentPlatform.getKeepTimeout())*1000);
+ }
+ }
+
+ private void registerTask(ParentPlatform parentPlatform, SipTransactionInfo sipTransactionInfo){
+ try {
+ // 涓嶅湪鍚屼竴涓細璇濅腑缁鍒欐瘡娆″叏鏂版敞鍐�
+ if (!userSetting.isRegisterKeepIntDialog()) {
+ sipTransactionInfo = null;
+ }
+
+ if (sipTransactionInfo == null) {
+ logger.info("[鍥芥爣绾ц仈] 骞冲彴锛歿}娉ㄥ唽鍗冲皢鍒版湡锛屽紑濮嬮噸鏂版敞鍐�", parentPlatform.getServerGBId());
+ }else {
+ logger.info("[鍥芥爣绾ц仈] 骞冲彴锛歿}娉ㄥ唽鍗冲皢鍒版湡锛屽紑濮嬬画璁�", parentPlatform.getServerGBId());
+ }
+
+ commanderForPlatform.register(parentPlatform, sipTransactionInfo, eventResult -> {
+ logger.info("[鍥芥爣绾ц仈] 骞冲彴锛歿}娉ㄥ唽澶辫触锛寋}:{}", parentPlatform.getServerGBId(),
+ eventResult.statusCode, eventResult.msg);
+ offline(parentPlatform, false);
+ }, null);
+ } catch (InvalidArgumentException | ParseException | SipException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈瀹氭椂娉ㄥ唽: {}", e.getMessage());
}
}
@Override
- public void offline(ParentPlatform parentPlatform) {
+ public void offline(ParentPlatform parentPlatform, boolean stopRegister) {
logger.info("[骞冲彴绂荤嚎]锛歿}", parentPlatform.getServerGBId());
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
parentPlatformCatch.setKeepAliveReply(0);
@@ -183,6 +323,7 @@
// 鍋滄鎵�鏈夋帹娴�
logger.info("[骞冲彴绂荤嚎] {}, 鍋滄鎵�鏈夋帹娴�", parentPlatform.getServerGBId());
stopAllPush(parentPlatform.getServerGBId());
+
// 娓呴櫎娉ㄥ唽瀹氭椂
logger.info("[骞冲彴绂荤嚎] {}, 鍋滄瀹氭椂娉ㄥ唽浠诲姟", parentPlatform.getServerGBId());
final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatform.getServerGBId();
@@ -193,40 +334,230 @@
logger.info("[骞冲彴绂荤嚎] {}, 鍋滄瀹氭椂鍙戦�佸績璺充换鍔�", parentPlatform.getServerGBId());
final String keepaliveTaskKey = KEEPALIVE_KEY_PREFIX + parentPlatform.getServerGBId();
if (dynamicTask.contains(keepaliveTaskKey)) {
- // 娣诲姞蹇冭烦浠诲姟
+ // 娓呴櫎蹇冭烦浠诲姟
dynamicTask.stop(keepaliveTaskKey);
}
// 鍋滄鐩綍璁㈤槄鍥炲
logger.info("[骞冲彴绂荤嚎] {}, 鍋滄璁㈤槄鍥炲", parentPlatform.getServerGBId());
subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId());
+ // 鍙戣捣瀹氭椂鑷姩閲嶆柊娉ㄥ唽
+ if (!stopRegister) {
+ // 璁剧疆涓�60绉掕嚜鍔ㄥ皾璇曢噸鏂版敞鍐�
+ final String registerFailAgainTaskKey = REGISTER_FAIL_AGAIN_KEY_PREFIX + parentPlatform.getServerGBId();
+ ParentPlatform platform = platformMapper.getParentPlatById(parentPlatform.getId());
+ if (platform.isEnable()) {
+ dynamicTask.startCron(registerFailAgainTaskKey,
+ ()-> registerTask(platform, null),
+ userSetting.getRegisterAgainAfterTime() * 1000);
+ }
+
+ }
}
private void stopAllPush(String platformId) {
List<SendRtpItem> sendRtpItems = redisCatchStorage.querySendRTPServer(platformId);
if (sendRtpItems != null && sendRtpItems.size() > 0) {
for (SendRtpItem sendRtpItem : sendRtpItems) {
+ ssrcFactory.releaseSsrc(sendRtpItem.getMediaServerId(), sendRtpItem.getSsrc());
redisCatchStorage.deleteSendRTPServer(platformId, sendRtpItem.getChannelId(), null, null);
MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
Map<String, Object> param = new HashMap<>(3);
param.put("vhost", "__defaultVhost__");
param.put("app", sendRtpItem.getApp());
- param.put("stream", sendRtpItem.getStreamId());
- zlmrtpServerFactory.stopSendRtpStream(mediaInfo, param);
+ param.put("stream", sendRtpItem.getStream());
+ ZLMServerFactory.stopSendRtpStream(mediaInfo, param);
}
-
}
}
@Override
public void login(ParentPlatform parentPlatform) {
final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatform.getServerGBId();
- commanderForPlatform.register(parentPlatform, eventResult1 -> {
- logger.info("[鍥芥爣绾ц仈] {}锛屽紑濮嬪畾鏃跺彂璧锋敞鍐岋紝闂撮殧涓�1鍒嗛挓", parentPlatform.getServerGBId());
- // 娣诲姞娉ㄥ唽浠诲姟
- dynamicTask.startCron(registerTaskKey,
- // 娉ㄥ唽澶辫触锛堟敞鍐屾垚鍔熸椂鐢辩▼搴忕洿鎺ヨ皟鐢ㄤ簡online鏂规硶锛�
- ()->logger.info("[鍥芥爣绾ц仈] {},骞冲彴绂荤嚎鍚庢寔缁彂璧锋敞鍐岋紝澶辫触", parentPlatform.getServerGBId()),
- 60*1000);
- }, null);
+ try {
+ commanderForPlatform.register(parentPlatform, eventResult1 -> {
+ logger.info("[鍥芥爣绾ц仈] {}锛屽紑濮嬪畾鏃跺彂璧锋敞鍐岋紝闂撮殧涓�1鍒嗛挓", parentPlatform.getServerGBId());
+ // 娣诲姞娉ㄥ唽浠诲姟
+ dynamicTask.startCron(registerTaskKey,
+ // 娉ㄥ唽澶辫触锛堟敞鍐屾垚鍔熸椂鐢辩▼搴忕洿鎺ヨ皟鐢ㄤ簡online鏂规硶锛�
+ ()->logger.info("[鍥芥爣绾ц仈] {},骞冲彴绂荤嚎鍚庢寔缁彂璧锋敞鍐岋紝澶辫触", parentPlatform.getServerGBId()),
+ 60*1000);
+ }, null);
+ } catch (InvalidArgumentException | ParseException | SipException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈娉ㄥ唽: {}", e.getMessage());
+ }
+ }
+
+ @Override
+ public void sendNotifyMobilePosition(String platformId) {
+ ParentPlatform platform = platformMapper.getParentPlatByServerGBId(platformId);
+ if (platform == null) {
+ return;
+ }
+ SubscribeInfo subscribe = subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId());
+ if (subscribe != null) {
+
+ // TODO 鏆傛椂鍙鐞嗚棰戞祦鐨勫洖澶�,鍚庣画澧炲姞瀵瑰浗鏍囪澶囩殑鏀寔
+ List<DeviceChannel> gbStreams = gbStreamMapper.queryGbStreamListInPlatform(platform.getServerGBId(), userSetting.isUsePushingAsStatus());
+ if (gbStreams.size() == 0) {
+ return;
+ }
+ for (DeviceChannel deviceChannel : gbStreams) {
+ String gbId = deviceChannel.getChannelId();
+ GPSMsgInfo gpsMsgInfo = redisCatchStorage.getGpsMsgInfo(gbId);
+ // 鏃犳渶鏂颁綅缃笉鍙戦��
+ if (gpsMsgInfo != null) {
+ // 缁忕含搴﹂兘涓�0涓嶅彂閫�
+ if (gpsMsgInfo.getLng() == 0 && gpsMsgInfo.getLat() == 0) {
+ continue;
+ }
+ // 鍙戦�丟PS娑堟伅
+ try {
+ commanderForPlatform.sendNotifyMobilePosition(platform, gpsMsgInfo, subscribe);
+ } catch (InvalidArgumentException | ParseException | NoSuchFieldException | SipException |
+ IllegalAccessException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 绉诲姩浣嶇疆閫氱煡: {}", e.getMessage());
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public void broadcastInvite(ParentPlatform platform, String channelId, MediaServerItem mediaServerItem, ZlmHttpHookSubscribe.Event hookEvent,
+ SipSubscribe.Event errorEvent, InviteTimeOutCallback timeoutCallback) throws InvalidArgumentException, ParseException, SipException {
+
+ if (mediaServerItem == null) {
+ logger.info("[鍥芥爣绾ц仈] 璇煶鍠婅瘽鏈壘鍒板彲鐢ㄧ殑zlm. platform: {}", platform.getServerGBId());
+ return;
+ }
+ InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, platform.getServerGBId(), channelId);
+
+
+ if (inviteInfo != null && inviteInfo.getStreamInfo() != null) {
+ // 濡傛灉zlm涓嶅瓨鍦ㄨ繖涓祦锛屽垯鍒犻櫎鏁版嵁鍗冲彲
+ MediaServerItem mediaServerItemForStreamInfo = mediaServerService.getOne(inviteInfo.getStreamInfo().getMediaServerId());
+ if (mediaServerItemForStreamInfo != null) {
+ Boolean ready = zlmrtpServerFactory.isStreamReady(mediaServerItemForStreamInfo, inviteInfo.getStreamInfo().getApp(), inviteInfo.getStreamInfo().getStream());
+ if (!ready) {
+ // 閿欒瀛樺湪浜巖edis涓殑鏁版嵁
+ inviteStreamService.removeInviteInfo(inviteInfo);
+ }else {
+ // 娴佺‘瀹炲皻鍦ㄦ帹娴侊紝鐩存帴鍥炶皟缁撴灉
+ OnStreamChangedHookParam hookParam = new OnStreamChangedHookParam();
+ hookParam.setApp(inviteInfo.getStreamInfo().getApp());
+ hookParam.setStream(inviteInfo.getStreamInfo().getStream());
+
+ hookEvent.response(mediaServerItemForStreamInfo, hookParam);
+ return;
+ }
+ }
+ }
+
+ String streamId = null;
+ if (mediaServerItem.isRtpEnable()) {
+ streamId = String.format("%s_%s", platform.getServerGBId(), channelId);
+ }
+ // 榛樿涓嶈繘琛孲SRC鏍¢獙锛� TODO 鍚庣画鍙敼涓洪厤缃�
+ boolean ssrcCheck = false;
+ int tcpMode;
+ if (userSetting.getBroadcastForPlatform().equalsIgnoreCase("TCP-PASSIVE")) {
+ tcpMode = 1;
+ }else if (userSetting.getBroadcastForPlatform().equalsIgnoreCase("TCP-ACTIVE")) {
+ tcpMode = 2;
+ } else {
+ tcpMode = 0;
+ }
+ SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, null, ssrcCheck, false, null, true, false, tcpMode);
+ if (ssrcInfo == null || ssrcInfo.getPort() < 0) {
+ logger.info("[鍥芥爣绾ц仈] 鍙戣捣璇煶鍠婅瘽 寮�鍚鍙g洃鍚け璐ワ紝 platform: {}, channel锛� {}", platform.getServerGBId(), channelId);
+ SipSubscribe.EventResult<Object> eventResult = new SipSubscribe.EventResult<>();
+ eventResult.statusCode = -1;
+ eventResult.msg = "绔彛鐩戝惉澶辫触";
+ eventResult.type = SipSubscribe.EventResultType.failedToGetPort;
+ errorEvent.response(eventResult);
+ return;
+ }
+ logger.info("[鍥芥爣绾ц仈] 璇煶鍠婅瘽锛屽彂璧稩nvite娑堟伅 deviceId: {}, channelId: {},鏀舵祦绔彛锛� {}, 鏀舵祦妯″紡锛歿}, SSRC: {}, SSRC鏍¢獙锛歿}",
+ platform.getServerGBId(), channelId, ssrcInfo.getPort(), userSetting.getBroadcastForPlatform(), ssrcInfo.getSsrc(), ssrcCheck);
+
+ String timeOutTaskKey = UUID.randomUUID().toString();
+ dynamicTask.startDelay(timeOutTaskKey, () -> {
+ // 鎵ц瓒呮椂浠诲姟鏃舵煡璇㈡槸鍚﹀凡缁忔垚鍔燂紝鎴愬姛浜嗗垯涓嶆墽琛岃秴鏃朵换鍔★紝闃叉瓒呮椂浠诲姟鍙栨秷澶辫触鐨勬儏鍐�
+ InviteInfo inviteInfoForBroadcast = inviteStreamService.getInviteInfo(InviteSessionType.BROADCAST, platform.getServerGBId(), channelId, null);
+ if (inviteInfoForBroadcast == null) {
+ logger.info("[鍥芥爣绾ц仈] 鍙戣捣璇煶鍠婅瘽 鏀舵祦瓒呮椂 deviceId: {}, channelId: {}锛岀鍙o細{}, SSRC: {}", platform.getServerGBId(), channelId, ssrcInfo.getPort(), ssrcInfo.getSsrc());
+ // 鐐规挱瓒呮椂鍥炲BYE 鍚屾椂閲婃斁ssrc浠ュ強姝ゆ鐐规挱鐨勮祫婧�
+ try {
+ commanderForPlatform.streamByeCmd(platform, channelId, ssrcInfo.getStream(), null, null);
+ } catch (InvalidArgumentException | ParseException | SipException | SsrcTransactionNotFoundException e) {
+ logger.error("[鐐规挱瓒呮椂]锛� 鍙戦�丅YE澶辫触 {}", e.getMessage());
+ } finally {
+ timeoutCallback.run(1, "鏀舵祦瓒呮椂");
+ mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
+ mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream());
+ streamSession.remove(platform.getServerGBId(), channelId, ssrcInfo.getStream());
+ mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream());
+ }
+ }
+ }, userSetting.getPlayTimeout());
+ commanderForPlatform.broadcastInviteCmd(platform, channelId, mediaServerItem, ssrcInfo, (mediaServerItemForInvite, hookParam)->{
+ logger.info("[鍥芥爣绾ц仈] 鍙戣捣璇煶鍠婅瘽 鏀跺埌涓婄骇鎺ㄦ祦 deviceId: {}, channelId: {}", platform.getServerGBId(), channelId);
+ dynamicTask.stop(timeOutTaskKey);
+ // hook鍝嶅簲
+ playService.onPublishHandlerForPlay(mediaServerItemForInvite, hookParam, platform.getServerGBId(), channelId);
+ // 鏀跺埌娴�
+ if (hookEvent != null) {
+ hookEvent.response(mediaServerItem, hookParam);
+ }
+ }, event -> {
+ // 鏀跺埌200OK 妫�娴媠src鏄惁鏈夊彉鍖栵紝闃叉涓婄骇鑷畾涔変簡ssrc
+ ResponseEvent responseEvent = (ResponseEvent) event.event;
+ String contentString = new String(responseEvent.getResponse().getRawContent());
+ // 鑾峰彇ssrc
+ int ssrcIndex = contentString.indexOf("y=");
+ // 妫�鏌ユ槸鍚︽湁y瀛楁
+ if (ssrcIndex >= 0) {
+ //ssrc瑙勫畾闀垮害涓�10瀛楄妭锛屼笉鍙栦綑涓嬮暱搴︿互閬垮厤鍚庣画杩樻湁鈥渇=鈥濆瓧娈� TODO 鍚庣画瀵逛笉瑙勮寖鐨勯潪10浣峴src鍏煎
+ String ssrcInResponse = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
+ // 鏌ヨ鍒皊src涓嶄竴鑷翠笖寮�鍚簡ssrc鏍¢獙鍒欓渶瑕侀拡瀵瑰鐞�
+ if (ssrcInfo.getSsrc().equals(ssrcInResponse) || ssrcCheck) {
+ return;
+ }
+ logger.info("[鐐规挱娑堟伅] 鏀跺埌invite 200, 鍙戠幇涓嬬骇鑷畾涔変簡ssrc: {}", ssrcInResponse);
+ if (!mediaServerItem.isRtpEnable()) {
+ logger.info("[鐐规挱娑堟伅] SSRC淇 {}->{}", ssrcInfo.getSsrc(), ssrcInResponse);
+ // 閲婃斁ssrc
+ mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
+ // 鍗曠鍙fā寮弒treamId涔熸湁鍙樺寲锛岄渶瑕侀噸鏂拌缃洃鍚�
+ if (!mediaServerItem.isRtpEnable()) {
+ // 娣诲姞璁㈤槄
+ HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", ssrcInfo.getStream(), true, "rtsp", mediaServerItem.getId());
+ subscribe.removeSubscribe(hookSubscribe);
+ hookSubscribe.getContent().put("stream", String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase());
+ subscribe.addSubscribe(hookSubscribe, (mediaServerItemInUse, hookParam) -> {
+ logger.info("[ZLM HOOK] ssrc淇鍚庢敹鍒拌闃呮秷鎭細 " + hookParam);
+ dynamicTask.stop(timeOutTaskKey);
+ // hook鍝嶅簲
+ playService.onPublishHandlerForPlay(mediaServerItemInUse, hookParam, platform.getServerGBId(), channelId);
+ hookEvent.response(mediaServerItemInUse, hookParam);
+ });
+ }
+ // 鍏抽棴rtp server
+ mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream());
+ // 閲嶆柊寮�鍚痵src server
+ mediaServerService.openRTPServer(mediaServerItem, ssrcInfo.getStream(), ssrcInResponse, false, false, ssrcInfo.getPort(), true, false, tcpMode);
+ }
+ }
+ }, eventResult -> {
+ // 鏀跺埌閿欒鍥炲
+ if (errorEvent != null) {
+ errorEvent.response(eventResult);
+ }
+ });
+ }
+
+ @Override
+ public void stopBroadcast(ParentPlatform platform, String channelId, String stream) throws InvalidArgumentException, ParseException, SsrcTransactionNotFoundException, SipException {
+ commanderForPlatform.streamByeCmd(platform, channelId, stream, null, null);
}
}
--
Gitblit v1.8.0