From 2bac0b3c222734aeb9087fee443af198bd67f06c Mon Sep 17 00:00:00 2001
From: 648540858 <456PANlinlin>
Date: 星期四, 02 十二月 2021 23:01:06 +0800
Subject: [PATCH] 存储所有流信息到redis

---
 src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java |   49 ++++++++++++++++++++++++++++++-------------------
 1 files changed, 30 insertions(+), 19 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 d6e77c7..f211fd6 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
@@ -11,6 +11,7 @@
 import com.genersoft.iot.vmp.gb28181.bean.Device;
 import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
+import com.genersoft.iot.vmp.media.zlm.dto.OriginType;
 import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
 import com.genersoft.iot.vmp.service.IMediaServerService;
 import com.genersoft.iot.vmp.service.IMediaService;
@@ -164,12 +165,20 @@
 				subscribe.response(mediaInfo, json);
 			}
 		}
+	 	String app = json.getString("app");
+	 	String stream = json.getString("stream");
+		StreamInfo streamInfo = redisCatchStorage.queryPlaybackByStreamId(stream);
 		JSONObject ret = new JSONObject();
+		// 褰曞儚鍥炴斁鏃朵笉杩涜褰曞儚涓嬭浇
+		if (streamInfo != null) {
+			ret.put("enableMP4", false);
+		}else {
+			ret.put("enableMP4", userSetup.isRecordPushLive());
+		}
 		ret.put("code", 0);
 		ret.put("msg", "success");
 		ret.put("enableHls", true);
 		ret.put("enableMP4", userSetup.isRecordPushLive());
-		ret.put("enableRtxp", true);
 		return new ResponseEntity<String>(ret.toString(), HttpStatus.OK);
 	}
 	
@@ -307,24 +316,23 @@
 			}else {
 				if (!"rtp".equals(app)){
 
-					boolean pushChange = false;
-
 					MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
 					if (regist) {
-						if ((item.getOriginType() == 1 || item.getOriginType() == 2 || item.getOriginType() == 8)) {
-							pushChange = true;
+						StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(mediaServerItem, app, streamId, tracks);
+						redisCatchStorage.addStream(mediaServerItem, OriginType.values()[item.getOriginType()].getType(), app, streamId, streamInfo);
+						if (item.getOriginType() == OriginType.RTSP_PUSH.ordinal()
+								|| item.getOriginType() == OriginType.RTMP_PUSH.ordinal()
+								|| item.getOriginType() == OriginType.RTC_PUSH.ordinal() ) {
 							zlmMediaListManager.addMedia(item);
-							StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(mediaServerItem, app, streamId, tracks);
-							redisCatchStorage.addPushStream(mediaServerItem, app, streamId, streamInfo);
 						}
 					}else {
-						int result = zlmMediaListManager.removeMedia( app, streamId);
-						redisCatchStorage.removePushStream(mediaServerItem, app, streamId);
-						if (result > 0) {
-							pushChange = true;
-						}
+						zlmMediaListManager.removeMedia( app, streamId);
+						redisCatchStorage.removeStream(mediaServerItem, OriginType.values()[item.getOriginType()].getType(), app, streamId);
+
 					}
-					if(pushChange) {
+					if (item.getOriginType() == OriginType.RTSP_PUSH.ordinal()
+							|| item.getOriginType() == OriginType.RTMP_PUSH.ordinal()
+							|| item.getOriginType() == OriginType.RTC_PUSH.ordinal() ) {
 						// 鍙戦�佹祦鍙樺寲redis娑堟伅
 						JSONObject jsonObject = new JSONObject();
 						jsonObject.put("serverId", userSetup.getServerId());
@@ -358,14 +366,13 @@
 		String mediaServerId = json.getString("mediaServerId");
 		String streamId = json.getString("stream");
 		String app = json.getString("app");
-
-		// TODO 濡傛灉鍦ㄧ粰涓婄骇鎺ㄦ祦锛屼篃涓嶅仠姝€��
+		JSONObject ret = new JSONObject();
+		ret.put("code", 0);
 		if ("rtp".equals(app)){
-			JSONObject ret = new JSONObject();
-			ret.put("code", 0);
 			ret.put("close", true);
 			StreamInfo streamInfoForPlayCatch = redisCatchStorage.queryPlayByStreamId(streamId);
 			if (streamInfoForPlayCatch != null) {
+				// 濡傛灉鍦ㄧ粰涓婄骇鎺ㄦ祦锛屼篃涓嶅仠姝€��
 				if (redisCatchStorage.isChannelSendingRTP(streamInfoForPlayCatch.getChannelId())) {
 					ret.put("close", false);
 				} else {
@@ -378,6 +385,12 @@
 				if (streamInfoForPlayBackCatch != null) {
 					cmder.streamByeCmd(streamInfoForPlayBackCatch.getDeviceID(), streamInfoForPlayBackCatch.getChannelId());
 					redisCatchStorage.stopPlayback(streamInfoForPlayBackCatch);
+				}else {
+					StreamInfo streamInfoForDownload = redisCatchStorage.queryDownloadByStreamId(streamId);
+					// 杩涜褰曞儚涓嬭浇鏃舵棤浜鸿鐪嬩笉鏂祦
+					if (streamInfoForDownload != null) {
+						ret.put("close", false);
+					}
 				}
 			}
 			MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
@@ -386,8 +399,6 @@
 			}
 			return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
 		}else {
-			JSONObject ret = new JSONObject();
-			ret.put("code", 0);
 			StreamProxyItem streamProxyItem = streamProxyService.getStreamProxyByAppAndStream(app, streamId);
 			if (streamProxyItem != null && streamProxyItem.isEnable_remove_none_reader()) {
 				ret.put("close", true);

--
Gitblit v1.8.0