From e5370bbd6e74b7746db12ced5302ef97ef58a4ce Mon Sep 17 00:00:00 2001
From: mrjackwang <30337754+mrjackwang@users.noreply.github.com>
Date: 星期四, 03 三月 2022 19:52:16 +0800
Subject: [PATCH] Merge branch 'wvp-28181-2.0' into wvp-28181-2.0

---
 src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java |   36 +++++++++++++++++++++++++++++++++---
 1 files changed, 33 insertions(+), 3 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 5919619..75b0dea 100644
--- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
@@ -83,6 +83,9 @@
 	@Autowired
 	private MediaConfig mediaConfig;
 
+	@Autowired
+	private ZLMRESTfulUtils zlmresTfulUtils;
+
 	/**
 	 * 鏈嶅姟鍣ㄥ畾鏃朵笂鎶ユ椂闂达紝涓婃姤闂撮殧鍙厤缃紝榛樿10s涓婃姤涓�娆�
 	 *
@@ -186,7 +189,6 @@
 		ret.put("code", 0);
 		ret.put("msg", "success");
 		ret.put("enableHls", true);
-		ret.put("enableMP4", userSetup.isRecordPushLive());
 		String mediaServerId = json.getString("mediaServerId");
 		ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, json);
 		if (subscribe != null) {
@@ -200,6 +202,11 @@
 		}
 	 	String app = json.getString("app");
 	 	String stream = json.getString("stream");
+		if ("rtp".equals(app)) {
+			ret.put("enableMP4", userSetup.getRecordSip());
+		}else {
+			ret.put("enableMP4", userSetup.isRecordPushLive());
+		}
 		StreamInfo streamInfo = redisCatchStorage.queryPlaybackByStreamId(stream);
 
 		// 褰曞儚鍥炴斁鏃朵笉杩涜褰曞儚涓嬭浇
@@ -332,6 +339,11 @@
 			}else {
 				mediaServerService.removeCount(mediaServerId);
 			}
+			if (item.getOriginType() == OriginType.PULL.ordinal()
+					|| item.getOriginType() == OriginType.FFMPEG_PULL.ordinal()) {
+				// 璁剧疆鎷夋祦浠g悊涓婄嚎/绂荤嚎
+				streamProxyService.updateStatus(regist, app, streamId);
+			}
 			if ("rtp".equals(app) && !regist ) {
 				StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
 				if (streamInfo!=null){
@@ -349,12 +361,16 @@
 					if (mediaServerItem != null){
 						if (regist) {
 							StreamPushItem streamPushItem = null;
+							StreamInfo streamInfoByAppAndStream = mediaService.getStreamInfoByAppAndStream(mediaServerItem, app, streamId, tracks);
+							item.setStreamInfo(streamInfoByAppAndStream);
+
 							redisCatchStorage.addStream(mediaServerItem, type, app, streamId, item);
 							if (item.getOriginType() == OriginType.RTSP_PUSH.ordinal()
 									|| item.getOriginType() == OriginType.RTMP_PUSH.ordinal()
 									|| item.getOriginType() == OriginType.RTC_PUSH.ordinal() ) {
 								streamPushItem = zlmMediaListManager.addPush(item);
 							}
+
 							List<GbStream> gbStreams = new ArrayList<>();
 							if (streamPushItem == null || streamPushItem.getGbId() == null) {
 								GbStream gbStream = storager.getGbStream(app, streamId);
@@ -426,14 +442,16 @@
 				if (redisCatchStorage.isChannelSendingRTP(streamInfoForPlayCatch.getChannelId())) {
 					ret.put("close", false);
 				} else {
-					cmder.streamByeCmd(streamInfoForPlayCatch.getDeviceID(), streamInfoForPlayCatch.getChannelId());
+					cmder.streamByeCmd(streamInfoForPlayCatch.getDeviceID(), streamInfoForPlayCatch.getChannelId(),
+							streamInfoForPlayCatch.getStream());
 					redisCatchStorage.stopPlay(streamInfoForPlayCatch);
 					storager.stopPlay(streamInfoForPlayCatch.getDeviceID(), streamInfoForPlayCatch.getChannelId());
 				}
 			}else{
 				StreamInfo streamInfoForPlayBackCatch = redisCatchStorage.queryPlaybackByStreamId(streamId);
 				if (streamInfoForPlayBackCatch != null) {
-					cmder.streamByeCmd(streamInfoForPlayBackCatch.getDeviceID(), streamInfoForPlayBackCatch.getChannelId());
+					cmder.streamByeCmd(streamInfoForPlayBackCatch.getDeviceID(),
+							streamInfoForPlayBackCatch.getChannelId(), streamInfoForPlayBackCatch.getStream());
 					redisCatchStorage.stopPlayback(streamInfoForPlayBackCatch);
 				}else {
 					StreamInfo streamInfoForDownload = redisCatchStorage.queryDownloadByStreamId(streamId);
@@ -455,6 +473,18 @@
 				streamProxyService.del(app, streamId);
 				String url = streamProxyItem.getUrl() != null?streamProxyItem.getUrl():streamProxyItem.getSrc_url();
 				logger.info("[{}/{}]<-[{}] 鎷夋祦浠g悊鏃犱汉瑙傜湅宸茬粡绉婚櫎",  app, streamId, url);
+
+			}else if (streamProxyItem != null && streamProxyItem.isEnable()) {
+				MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
+				if(null!=mediaServerItem){
+					JSONObject jsonObject = zlmresTfulUtils.closeStreams(mediaServerItem,streamProxyItem.getApp(), streamProxyItem.getStream());
+					if (jsonObject.getInteger("code") == 0) {
+						streamProxyItem.setEnable(false);
+						storager.updateStreamProxy(streamProxyItem);
+					}
+				}else {
+					ret.put("close", false);
+				}
 			}else {
 				ret.put("close", false);
 			}

--
Gitblit v1.8.0