From e8770eec36cb7294899ee96f0f66028e9358caf8 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期一, 22 一月 2024 16:02:28 +0800
Subject: [PATCH] Merge branch '2.6.9' into wvp-28181-2.0
---
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java | 132 +++++++++++++++++++++++++++----------------
1 files changed, 83 insertions(+), 49 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
index 3c76883..ed26bda 100755
--- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
@@ -111,6 +111,9 @@
private IUserService userService;
@Autowired
+ private ICloudRecordService cloudRecordService;
+
+ @Autowired
private VideoStreamSessionManager sessionManager;
@Autowired
@@ -231,12 +234,6 @@
streamAuthorityInfo.setSign(sign);
// 閴存潈閫氳繃
redisCatchStorage.updateStreamAuthorityInfo(param.getApp(), param.getStream(), streamAuthorityInfo);
- // 閫氱煡assist鏂扮殑callId
- if (mediaInfo != null && mediaInfo.getRecordAssistPort() > 0) {
- taskExecutor.execute(() -> {
- assistRESTfulUtils.addStreamCallInfo(mediaInfo, param.getApp(), param.getStream(), callId, null);
- });
- }
}
} else {
zlmMediaListManager.sendStreamEvent(param.getApp(), param.getStream(), param.getMediaServerId());
@@ -262,43 +259,51 @@
} else {
result.setEnable_mp4(userSetting.isRecordPushLive());
}
- // 鏇挎崲娴佸湴鍧�
- if ("rtp".equals(param.getApp()) && !mediaInfo.isRtpEnable()) {
- String ssrc = String.format("%010d", Long.parseLong(param.getStream(), 16));;
- InviteInfo inviteInfo = inviteStreamService.getInviteInfoBySSRC(ssrc);
- if (inviteInfo != null) {
- result.setStream_replace(inviteInfo.getStream());
- logger.info("[ZLM HOOK]鎺ㄦ祦閴存潈 stream: {} 鏇挎崲涓� {}", param.getStream(), inviteInfo.getStream());
+ // 鍥芥爣娴�
+ if ("rtp".equals(param.getApp()) ) {
+
+ InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(null, param.getStream());
+
+ // 鍗曠鍙fā寮忎笅淇敼娴� ID
+ if (!mediaInfo.isRtpEnable() && inviteInfo == null) {
+ String ssrc = String.format("%010d", Long.parseLong(param.getStream(), 16));
+ inviteInfo = inviteStreamService.getInviteInfoBySSRC(ssrc);
+ if (inviteInfo != null) {
+ result.setStream_replace(inviteInfo.getStream());
+ logger.info("[ZLM HOOK]鎺ㄦ祦閴存潈 stream: {} 鏇挎崲涓� {}", param.getStream(), inviteInfo.getStream());
+ }
}
- }
- List<SsrcTransaction> ssrcTransactionForAll = sessionManager.getSsrcTransactionForAll(null, null, null, param.getStream());
- if (ssrcTransactionForAll != null && ssrcTransactionForAll.size() == 1) {
- String deviceId = ssrcTransactionForAll.get(0).getDeviceId();
- String channelId = ssrcTransactionForAll.get(0).getChannelId();
- DeviceChannel deviceChannel = storager.queryChannel(deviceId, channelId);
- if (deviceChannel != null) {
- result.setEnable_audio(deviceChannel.isHasAudio());
- }
- // 濡傛灉鏄綍鍍忎笅杞藉氨璁剧疆瑙嗛闂撮殧鍗佺
- if (ssrcTransactionForAll.get(0).getType() == InviteSessionType.DOWNLOAD) {
- result.setMp4_max_second(10);
- result.setEnable_mp4(true);
- }
- }
- if (mediaInfo.getRecordAssistPort() > 0 && userSetting.getRecordPath() == null) {
- logger.info("鎺ㄦ祦鏃跺彂鐜板皻鏈缃綍鍍忚矾寰勶紝浠巃ssist鏈嶅姟涓鍙�");
- JSONObject info = assistRESTfulUtils.getInfo(mediaInfo, null);
- if (info != null && info.getInteger("code") != null && info.getInteger("code") == 0 ) {
- JSONObject dataJson = info.getJSONObject("data");
- if (dataJson != null) {
- String recordPath = dataJson.getString("record");
- userSetting.setRecordPath(recordPath);
- result.setMp4_save_path(recordPath);
- // 淇敼zlm涓殑褰曞儚璺緞
- if (mediaInfo.isAutoConfig()) {
- taskExecutor.execute(() -> {
- mediaServerService.setZLMConfig(mediaInfo, false);
- });
+
+ // 璁剧疆闊抽淇℃伅鍙婂綍鍒朵俊鎭�
+ List<SsrcTransaction> ssrcTransactionForAll = sessionManager.getSsrcTransactionForAll(null, null, null, param.getStream());
+ if (ssrcTransactionForAll != null && ssrcTransactionForAll.size() == 1) {
+
+ // 涓哄綍鍒跺浗鏍囨ā鎷熶竴涓壌鏉冧俊鎭�, 鏂逛究鍚庣画鍐欏叆褰曞儚鏂囦欢鏃朵娇鐢�
+ StreamAuthorityInfo streamAuthorityInfo = StreamAuthorityInfo.getInstanceByHook(param);
+ streamAuthorityInfo.setApp(param.getApp());
+ streamAuthorityInfo.setStream(ssrcTransactionForAll.get(0).getStream());
+ streamAuthorityInfo.setCallId(ssrcTransactionForAll.get(0).getSipTransactionInfo().getCallId());
+
+ redisCatchStorage.updateStreamAuthorityInfo(param.getApp(), ssrcTransactionForAll.get(0).getStream(), streamAuthorityInfo);
+
+ String deviceId = ssrcTransactionForAll.get(0).getDeviceId();
+ String channelId = ssrcTransactionForAll.get(0).getChannelId();
+ DeviceChannel deviceChannel = storager.queryChannel(deviceId, channelId);
+ if (deviceChannel != null) {
+ result.setEnable_audio(deviceChannel.isHasAudio());
+ }
+ // 濡傛灉鏄綍鍍忎笅杞藉氨璁剧疆瑙嗛闂撮殧鍗佺
+ if (ssrcTransactionForAll.get(0).getType() == InviteSessionType.DOWNLOAD) {
+ // 鑾峰彇褰曞儚鐨勬�绘椂闀匡紝鐒跺悗璁剧疆涓鸿繖涓棰戠殑鏃堕暱
+ InviteInfo inviteInfoForDownload = inviteStreamService.getInviteInfo(InviteSessionType.DOWNLOAD, deviceId, channelId, param.getStream());
+ if (inviteInfoForDownload != null && inviteInfoForDownload.getStreamInfo() != null) {
+ String startTime = inviteInfoForDownload.getStreamInfo().getStartTime();
+ String endTime = inviteInfoForDownload.getStreamInfo().getEndTime();
+ long difference = DateUtil.getDifference(startTime, endTime) / 1000;
+ result.setMp4_max_second((int) difference);
+ result.setEnable_mp4(true);
+ // 璁剧疆涓�2淇濊瘉寰楀埌鐨刴p4鐨勬椂闀挎槸姝e父鐨�
+ result.setModify_stamp(2);
}
}
}
@@ -346,13 +351,11 @@
List<OnStreamChangedHookParam.MediaTrack> tracks = param.getTracks();
// TODO 閲嶆瀯姝ゅ閫昏緫
- boolean isPush = false;
if (param.isRegist()) {
- // 澶勭悊娴佹敞鍐岀殑閴存潈淇℃伅
+ // 澶勭悊娴佹敞鍐岀殑閴存潈淇℃伅锛� 娴佹敞閿�杩欓噷涓嶅啀鍒犻櫎閴存潈淇℃伅锛屼笅娆℃潵浜嗘柊鐨勯壌鏉冧俊鎭細瀵瑰氨鐨勮繘琛岃鐩�
if (param.getOriginType() == OriginType.RTMP_PUSH.ordinal()
|| param.getOriginType() == OriginType.RTSP_PUSH.ordinal()
|| param.getOriginType() == OriginType.RTC_PUSH.ordinal()) {
- isPush = true;
StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(param.getApp(), param.getStream());
if (streamAuthorityInfo == null) {
streamAuthorityInfo = StreamAuthorityInfo.getInstanceByHook(param);
@@ -362,8 +365,6 @@
}
redisCatchStorage.updateStreamAuthorityInfo(param.getApp(), param.getStream(), streamAuthorityInfo);
}
- } else {
- redisCatchStorage.removeStreamAuthorityInfo(param.getApp(), param.getStream());
}
if ("rtsp".equals(param.getSchema())) {
@@ -404,6 +405,9 @@
|| param.getOriginType() == OriginType.RTC_PUSH.ordinal()) {
param.setSeverId(userSetting.getServerId());
zlmMediaListManager.addPush(param);
+
+ // 鍐椾綑鏁版嵁锛岃嚜宸辩郴缁熶腑鑷敤
+ redisCatchStorage.addPushListItem(param.getApp(), param.getStream(), param);
}
} else {
// 鍏煎娴佹敞閿�鏃剁被鍨嬩粠redis璁板綍鑾峰彇
@@ -412,6 +416,10 @@
if (onStreamChangedHookParam != null) {
type = OriginType.values()[onStreamChangedHookParam.getOriginType()].getType();
redisCatchStorage.removeStream(mediaInfo.getId(), type, param.getApp(), param.getStream());
+ if ("PUSH".equalsIgnoreCase(type)) {
+ // 鍐椾綑鏁版嵁锛岃嚜宸辩郴缁熶腑鑷敤
+ redisCatchStorage.removePushListItem(param.getApp(), param.getStream(), param.getMediaServerId());
+ }
}
GbStream gbStream = storager.getGbStream(param.getApp(), param.getStream());
if (gbStream != null) {
@@ -524,11 +532,15 @@
if (info != null) {
cmder.streamByeCmd(device, inviteInfo.getChannelId(),
inviteInfo.getStream(), null);
+ }else {
+ logger.info("[鏃犱汉瑙傜湅] 鏈壘鍒拌澶囩殑鐐规挱淇℃伅锛� {}锛� 娴侊細{}", inviteInfo.getDeviceId(), param.getStream());
}
} catch (InvalidArgumentException | ParseException | SipException |
SsrcTransactionNotFoundException e) {
logger.error("[鏃犱汉瑙傜湅]鐐规挱锛� 鍙戦�丅YE澶辫触 {}", e.getMessage());
}
+ }else {
+ logger.info("[鏃犱汉瑙傜湅] 鏈壘鍒拌澶囷細 {}锛屾祦锛歿}", inviteInfo.getDeviceId(), param.getStream());
}
inviteStreamService.removeInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId(),
@@ -593,7 +605,7 @@
String deviceId = s[0];
String channelId = s[1];
Device device = redisCatchStorage.getDevice(deviceId);
- if (device == null) {
+ if (device == null || !device.isOnLine()) {
defaultResult.setResult(new HookResult(ErrorCode.ERROR404.getCode(), ErrorCode.ERROR404.getMsg()));
return defaultResult;
}
@@ -756,7 +768,7 @@
taskExecutor.execute(() -> {
JSONObject json = (JSONObject) JSON.toJSON(param);
List<ZlmHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_rtp_server_timeout);
- if (subscribes != null && subscribes.size() > 0) {
+ if (subscribes != null && !subscribes.isEmpty()) {
for (ZlmHttpHookSubscribe.Event subscribe : subscribes) {
subscribe.response(null, param);
}
@@ -766,6 +778,28 @@
return HookResult.SUCCESS();
}
+ /**
+ * 褰曞儚瀹屾垚浜嬩欢
+ */
+ @ResponseBody
+ @PostMapping(value = "/on_record_mp4", produces = "application/json;charset=UTF-8")
+ public HookResult onRecordMp4(HttpServletRequest request, @RequestBody OnRecordMp4HookParam param) {
+ logger.info("[ZLM HOOK] 褰曞儚瀹屾垚浜嬩欢锛歿}->{}", param.getMediaServerId(), param.getFile_path());
+
+ taskExecutor.execute(() -> {
+ List<ZlmHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_record_mp4);
+ if (subscribes != null && !subscribes.isEmpty()) {
+ for (ZlmHttpHookSubscribe.Event subscribe : subscribes) {
+ subscribe.response(null, param);
+ }
+ }
+ cloudRecordService.addRecord(param);
+
+ });
+
+ return HookResult.SUCCESS();
+ }
+
private Map<String, String> urlParamToMap(String params) {
HashMap<String, String> map = new HashMap<>();
if (ObjectUtils.isEmpty(params)) {
--
Gitblit v1.8.0