From ecf84bb0f1952c4a044ff6c8aa18226b31593f3f Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期五, 18 十一月 2022 21:52:02 +0800
Subject: [PATCH] 合并主线

---
 src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java |  120 ++++++++++++++++++++++++++++++-----------------------------
 1 files changed, 61 insertions(+), 59 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 758a3d7..32163df 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
@@ -9,21 +9,16 @@
 import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
 import com.genersoft.iot.vmp.gb28181.session.AudioBroadcastManager;
 import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
+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.transmit.cmd.impl.SIPCommanderFroPlatform;
 import com.genersoft.iot.vmp.media.zlm.dto.HookType;
 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
 import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
 import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
 import com.genersoft.iot.vmp.media.zlm.dto.hook.*;
-import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
-import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
-import com.genersoft.iot.vmp.media.zlm.dto.*;
 import com.genersoft.iot.vmp.service.*;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
-import com.genersoft.iot.vmp.vmanager.bean.AudioBroadcastResult;
-import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -294,9 +289,9 @@
 
 
 		JSONObject json = (JSONObject) JSON.toJSON(param);
-		taskExecutor.execute(()->{
+		taskExecutor.execute(()-> {
 			ZlmHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_stream_changed, json);
-			if (subscribe != null ) {
+			if (subscribe != null) {
 				MediaServerItem mediaInfo = mediaServerService.getOne(param.getMediaServerId());
 				if (mediaInfo != null) {
 					subscribe.response(mediaInfo, json);
@@ -312,15 +307,16 @@
 					StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(param.getApp(), param.getStream());
 					if (streamAuthorityInfo == null) {
 						streamAuthorityInfo = StreamAuthorityInfo.getInstanceByHook(param);
-					}else {
+					} else {
 						streamAuthorityInfo.setOriginType(param.getOriginType());
 						streamAuthorityInfo.setOriginTypeStr(param.getOriginTypeStr());
 					}
 					redisCatchStorage.updateStreamAuthorityInfo(param.getApp(), param.getStream(), streamAuthorityInfo);
 				}
-			}else {
+			} else {
 				redisCatchStorage.removeStreamAuthorityInfo(param.getApp(), param.getStream());
 			}
+		});
 
 		if ("rtsp".equals(param.getSchema())){
 			logger.info("on_stream_changed锛氭敞鍐�->{}, app->{}, stream->{}", param.isRegist(), param.getApp(), param.getStream());
@@ -329,12 +325,12 @@
 			}else {
 				mediaServerService.removeCount(param.getMediaServerId());
 			}
-			if (item.getOriginType() == OriginType.PULL.ordinal()
-					|| item.getOriginType() == OriginType.FFMPEG_PULL.ordinal()) {
+			if (param.getOriginType() == OriginType.PULL.ordinal()
+					|| param.getOriginType() == OriginType.FFMPEG_PULL.ordinal()) {
 				// 璁剧疆鎷夋祦浠g悊涓婄嚎/绂荤嚎
-				streamProxyService.updateStatus(param.isRegist(), app, param.getStream());
+				streamProxyService.updateStatus(param.isRegist(), param.getApp(), param.getStream());
 			}
-			if ("rtp".equals(app) && !regist ) {
+			if ("rtp".equals(param.getApp()) && !param.isRegist() ) {
 				StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(param.getStream());
 				if (streamInfo!=null){
 					redisCatchStorage.stopPlay(streamInfo);
@@ -346,47 +342,49 @@
 								streamInfo.getStream(), null);
 					}
 				}
-			}else if ("broadcast".equals(app)){
+			}else if ("broadcast".equals(param.getApp())){
 				// 璇煶瀵硅鎺ㄦ祦  stream闇�瑕佹弧瓒虫牸寮廳eviceId_channelId
-				if (regist && param.getStream().indexOf("_") > 0) {
+				if (param.isRegist() && param.getStream().indexOf("_") > 0) {
 					String[] streamArray = param.getStream().split("_");
 					if (streamArray.length == 2) {
 						String deviceId = streamArray[0];
 						String channelId = streamArray[1];
-						Device device = deviceService.queryDevice(deviceId);
+						Device device = deviceService.getDevice(deviceId);
 						if (device != null) {
 							DeviceChannel deviceChannel = storager.queryChannel(deviceId, channelId);
 							if (deviceChannel != null) {
 								if (audioBroadcastManager.exit(deviceId, channelId)) {
 									// 鐩存帴鎺ㄦ祦
-									SendRtpItem sendRtpItem =  redisCatchStorage.querySendRTPServer(null, null, stream, null);
+									SendRtpItem sendRtpItem =  redisCatchStorage.querySendRTPServer(null, null, param.getStream(), null);
 									if (sendRtpItem == null) {
 										// TODO 鍙兘鏁版嵁閿欒锛岄噸鏂板紑鍚闊抽�氶亾
 									}else {
 										String is_Udp = sendRtpItem.isTcp() ? "0" : "1";
 										MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
 										logger.info("rtp/{}寮�濮嬪悜涓婄骇鎺ㄦ祦, 鐩爣={}:{}锛孲SRC={}", sendRtpItem.getStreamId(), sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc());
-										Map<String, Object> param = new HashMap<>(12);
-										param.put("vhost","__defaultVhost__");
-										param.put("app",sendRtpItem.getApp());
-										param.put("stream",sendRtpItem.getStreamId());
-										param.put("ssrc", sendRtpItem.getSsrc());
-										param.put("src_port", sendRtpItem.getLocalPort());
-										param.put("pt", sendRtpItem.getPt());
-										param.put("use_ps", sendRtpItem.isUsePs() ? "1" : "0");
-										param.put("only_audio", sendRtpItem.isOnlyAudio() ? "1" : "0");
+										Map<String, Object> sendParam = new HashMap<>(12);
+										sendParam.put("vhost","__defaultVhost__");
+										sendParam.put("app",sendRtpItem.getApp());
+										sendParam.put("stream",sendRtpItem.getStreamId());
+										sendParam.put("ssrc", sendRtpItem.getSsrc());
+										sendParam.put("src_port", sendRtpItem.getLocalPort());
+										sendParam.put("pt", sendRtpItem.getPt());
+										sendParam.put("use_ps", sendRtpItem.isUsePs() ? "1" : "0");
+										sendParam.put("only_audio", sendRtpItem.isOnlyAudio() ? "1" : "0");
 
 										JSONObject jsonObject;
 										if (sendRtpItem.isTcpActive()) {
-											jsonObject = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param);
+											jsonObject = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, sendParam);
 										} else {
-											param.put("is_udp", is_Udp);
-											param.put("dst_url", sendRtpItem.getIp());
-											param.put("dst_port", sendRtpItem.getPort());
-											jsonObject = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
+											sendParam.put("is_udp", is_Udp);
+											sendParam.put("dst_url", sendRtpItem.getIp());
+											sendParam.put("dst_port", sendRtpItem.getPort());
+											jsonObject = zlmrtpServerFactory.startSendRtpStream(mediaInfo, sendParam);
 										}
 										if (jsonObject != null && jsonObject.getInteger("code") == 0) {
 											logger.info("[璇煶瀵硅] 鑷姩鎺ㄦ祦鎴愬姛, device: {}, channel: {}", deviceId, channelId);
+										}else {
+											logger.info("[璇煶瀵硅] 鎺ㄦ祦澶辫触, 缁撴灉锛� {}", jsonObject);
 										}
 
 									}
@@ -406,43 +404,43 @@
 					}
 				}
 
-			}else if ("talk".equals(app)){
+			}else if ("talk".equals(param.getApp())){
 				// 璇煶瀵硅鎺ㄦ祦  stream闇�瑕佹弧瓒虫牸寮廳eviceId_channelId
-				if (regist && stream.indexOf("_") > 0) {
-					String[] streamArray = stream.split("_");
+				if (param.isRegist() && param.getStream().indexOf("_") > 0) {
+					String[] streamArray = param.getStream().split("_");
 					if (streamArray.length == 2) {
 						String deviceId = streamArray[0];
 						String channelId = streamArray[1];
-						Device device = deviceService.queryDevice(deviceId);
+						Device device = deviceService.getDevice(deviceId);
 						if (device != null) {
 							DeviceChannel deviceChannel = storager.queryChannel(deviceId, channelId);
 							if (deviceChannel != null) {
 								if (audioBroadcastManager.exit(deviceId, channelId)) {
 									// 鐩存帴鎺ㄦ祦
-									SendRtpItem sendRtpItem =  redisCatchStorage.querySendRTPServer(null, null, stream, null);
+									SendRtpItem sendRtpItem =  redisCatchStorage.querySendRTPServer(null, null, param.getStream(), null);
 									if (sendRtpItem == null) {
 										// TODO 鍙兘鏁版嵁閿欒锛岄噸鏂板紑鍚闊抽�氶亾
 									}else {
 										MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
 										logger.info("rtp/{}寮�濮嬪悜涓婄骇鎺ㄦ祦, 鐩爣={}:{}锛孲SRC={}", sendRtpItem.getStreamId(), sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc());
-										Map<String, Object> param = new HashMap<>(12);
-										param.put("vhost","__defaultVhost__");
-										param.put("app",sendRtpItem.getApp());
-										param.put("stream",sendRtpItem.getStreamId());
-										param.put("ssrc", sendRtpItem.getSsrc());
-										param.put("src_port", sendRtpItem.getLocalPort());
-										param.put("pt", sendRtpItem.getPt());
-										param.put("use_ps", sendRtpItem.isUsePs() ? "1" : "0");
-										param.put("only_audio", sendRtpItem.isOnlyAudio() ? "1" : "0");
+										Map<String, Object> sendParam = new HashMap<>(12);
+										sendParam.put("vhost","__defaultVhost__");
+										sendParam.put("app",sendRtpItem.getApp());
+										sendParam.put("stream",sendRtpItem.getStreamId());
+										sendParam.put("ssrc", sendRtpItem.getSsrc());
+										sendParam.put("src_port", sendRtpItem.getLocalPort());
+										sendParam.put("pt", sendRtpItem.getPt());
+										sendParam.put("use_ps", sendRtpItem.isUsePs() ? "1" : "0");
+										sendParam.put("only_audio", sendRtpItem.isOnlyAudio() ? "1" : "0");
 
 										JSONObject jsonObject;
 										if (sendRtpItem.isTcpActive()) {
-											jsonObject = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param);
+											jsonObject = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, sendParam);
 										} else {
-											param.put("is_udp", sendRtpItem.isTcp() ? "0" : "1");
-											param.put("dst_url", sendRtpItem.getIp());
-											param.put("dst_port", sendRtpItem.getPort());
-											jsonObject = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
+											sendParam.put("is_udp", sendRtpItem.isTcp() ? "0" : "1");
+											sendParam.put("dst_url", sendRtpItem.getIp());
+											sendParam.put("dst_port", sendRtpItem.getPort());
+											jsonObject = zlmrtpServerFactory.startSendRtpStream(mediaInfo, sendParam);
 										}
 										if (jsonObject != null && jsonObject.getInteger("code") == 0) {
 											logger.info("[璇煶瀵硅] 鑷姩鎺ㄦ祦鎴愬姛, device: {}, channel: {}", deviceId, channelId);
@@ -450,7 +448,7 @@
 									}
 								}else {
 									// 寮�鍚闊冲璁查�氶亾
-									MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
+									MediaServerItem mediaServerItem = mediaServerService.getOne(param.getMediaServerId());
 									playService.talk(mediaServerItem, device, channelId, (mediaServer, jsonObject)->{
 										System.out.println("寮�濮嬫帹娴�");
 									}, eventResult -> {
@@ -466,9 +464,9 @@
 				}
 
 			}else{
-				if (!"rtp".equals(app)){
-					String type = OriginType.values()[item.getOriginType()].getType();
-					MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
+				if (!"rtp".equals(param.getApp())){
+					String type = OriginType.values()[param.getOriginType()].getType();
+					MediaServerItem mediaServerItem = mediaServerService.getOne(param.getMediaServerId());
 
 						if (mediaServerItem != null){
 							if (param.isRegist()) {
@@ -478,7 +476,7 @@
 									callId = streamAuthorityInfo.getCallId();
 								}
 								StreamInfo streamInfoByAppAndStream = mediaService.getStreamInfoByAppAndStream(mediaServerItem,
-										param.getApp(), param.getStream(), tracks, callId);
+										param.getApp(), param.getStream(), param.getTracks(), callId);
 								param.setStreamInfo(streamInfoByAppAndStream);
 								redisCatchStorage.addStream(mediaServerItem, type, param.getApp(), param.getStream(), param);
 								if (param.getOriginType() == OriginType.RTSP_PUSH.ordinal()
@@ -489,7 +487,8 @@
 								}
 							}else {
 								// 鍏煎娴佹敞閿�鏃剁被鍨嬩粠redis璁板綍鑾峰彇
-								OnStreamChangedHookParam onStreamChangedHookParam = redisCatchStorage.getStreamInfo(param.getApp(), param.getStream(), param.getMediaServerId());
+								OnStreamChangedHookParam onStreamChangedHookParam = redisCatchStorage.getStreamInfo(
+										param.getApp(), param.getStream(), param.getMediaServerId());
 								if (onStreamChangedHookParam != null) {
 									type = OriginType.values()[onStreamChangedHookParam.getOriginType()].getType();
 									redisCatchStorage.removeStream(mediaServerItem.getId(), type, param.getApp(), param.getStream());
@@ -526,13 +525,13 @@
 								if (platform != null) {
 									commanderFroPlatform.streamByeCmd(platform, sendRtpItem);
 								}else {
-									if ("talk".equals(app) && sendRtpItem.isOnlyAudio()) {
+									if ("talk".equals(param.getApp()) && sendRtpItem.isOnlyAudio()) {
 										AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(sendRtpItem.getDeviceId(), sendRtpItem.getChannelId());
 										if (device != null && audioBroadcastCatch != null) {
 //											cmder.streamByeCmd(device, sendRtpItem.getChannelId(), audioBroadcastCatch.getSipTransactionInfo(), null);
 										}
 									}else {
-										cmder.streamByeCmd(device, sendRtpItem.getChannelId(), stream, sendRtpItem.getCallId());
+										cmder.streamByeCmd(device, sendRtpItem.getChannelId(), param.getStream(), sendRtpItem.getCallId());
 									}
 
 								}
@@ -575,6 +574,9 @@
 					if (sendRtpItems.size() > 0) {
 						for (SendRtpItem sendRtpItem : sendRtpItems) {
 							ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(sendRtpItem.getPlatformId());
+							if (parentPlatform == null) {
+								continue;
+							}
 							try {
 								commanderFroPlatform.streamByeCmd(parentPlatform, sendRtpItem.getCallId());
 							} catch (SipException | InvalidArgumentException | ParseException e) {

--
Gitblit v1.8.0