From 80d96042e7b6f2942585bde482f02a3392477033 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期四, 24 十一月 2022 20:01:03 +0800
Subject: [PATCH] 优化语音对讲

---
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/AckRequestProcessor.java |  100 ++++++++++++++++++++-----------------------------
 1 files changed, 41 insertions(+), 59 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/AckRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/AckRequestProcessor.java
index d1308a4..c8d02d0 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/AckRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/AckRequestProcessor.java
@@ -4,6 +4,7 @@
 import com.alibaba.fastjson2.JSONObject;
 import com.genersoft.iot.vmp.conf.DynamicTask;
 import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
+import com.genersoft.iot.vmp.gb28181.bean.AudioBroadcastCatch;
 import com.genersoft.iot.vmp.gb28181.bean.Device;
 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
 import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
@@ -134,69 +135,41 @@
 			param.put("udp_rtcp_timeout", sendRtpItem.isRtcp()? "1":"0");
 		}
 
-		JSONObject jsonObject;
-		if (sendRtpItem.isTcpActive()) {
-			jsonObject = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param);
+		if (mediaInfo == null) {
+			RequestPushStreamMsg requestPushStreamMsg = RequestPushStreamMsg.getInstance(
+					sendRtpItem.getMediaServerId(), sendRtpItem.getApp(), sendRtpItem.getStreamId(),
+					sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc(), sendRtpItem.isTcp(),
+					sendRtpItem.getLocalPort(), sendRtpItem.getPt(), sendRtpItem.isUsePs(), sendRtpItem.isOnlyAudio());
+			redisGbPlayMsgListener.sendMsgForStartSendRtpStream(sendRtpItem.getServerId(), requestPushStreamMsg, json -> {
+				startSendRtpStreamHand(evt, sendRtpItem, parentPlatform, json, param, callIdHeader);
+			});
 		} else {
-			param.put("is_udp", is_Udp);
-			param.put("dst_url", sendRtpItem.getIp());
-			param.put("dst_port", sendRtpItem.getPort());
-			jsonObject = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
-			System.out.println(JSON.toJSONString(param));
-			System.out.println();
-			System.out.println(jsonObject);
-		}
-
-			if (jsonObject == null) {
-				logger.error("RTP鎺ㄦ祦澶辫触: 璇锋鏌LM鏈嶅姟");
-			} else if (jsonObject.getInteger("code") == 0) {
-				logger.info("RTP鎺ㄦ祦鎴愬姛[ {}/{} ]锛寋}->{}:{}, ", param.get("app"), param.get("stream"), jsonObject.getString("local_port"), param.get("dst_url"), param.get("dst_port"));
-			} else {
-				logger.error("RTP鎺ㄦ祦澶辫触: {}, 鍙傛暟锛歿}", jsonObject.getString("msg"), JSON.toJSON(param));
-				if (sendRtpItem.isOnlyAudio()) {
-					// 璇煶瀵硅
-					Device device = deviceService.getDevice(platformGbId);
-					if (device != null) {
-						try {
-							cmder.streamByeCmd(device, sendRtpItem.getChannelId(), sendRtpItem.getStreamId(), null);
-						} catch (SipException | ParseException | InvalidArgumentException |
-								 SsrcTransactionNotFoundException e) {
-							logger.error("[鍛戒护鍙戦�佸け璐 鍋滄璇煶瀵硅: {}", e.getMessage());
-						}
-					}
-
-				} else {
-					// 鍚戜笂绾у钩鍙�
-					try {
-						commanderForPlatform.streamByeCmd(parentPlatform, callIdHeader.getCallId());
-					} catch (SipException | InvalidArgumentException | ParseException e) {
-						logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈锛� 鍥炲BYE: {}", e.getMessage());
-					}
-				}
-				if (mediaInfo == null) {
-					RequestPushStreamMsg requestPushStreamMsg = RequestPushStreamMsg.getInstance(
-							sendRtpItem.getMediaServerId(), sendRtpItem.getApp(), sendRtpItem.getStreamId(),
-							sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc(), sendRtpItem.isTcp(),
-							sendRtpItem.getLocalPort(), sendRtpItem.getPt(), sendRtpItem.isUsePs(), sendRtpItem.isOnlyAudio());
-					redisGbPlayMsgListener.sendMsgForStartSendRtpStream(sendRtpItem.getServerId(), requestPushStreamMsg, json -> {
-						startSendRtpStreamHand(evt, sendRtpItem, parentPlatform, json, param, callIdHeader);
-					});
-				} else {
-					// 濡傛灉鏄潪涓ユ牸妯″紡锛岄渶瑕佸叧闂鍙e崰鐢�
-					JSONObject startSendRtpStreamResult = null;
-					if (sendRtpItem.getLocalPort() != 0) {
-						if (zlmrtpServerFactory.releasePort(mediaInfo, sendRtpItem.getSsrc())) {
-							startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
-						}
+			// 濡傛灉鏄潪涓ユ牸妯″紡锛岄渶瑕佸叧闂鍙e崰鐢�
+			JSONObject startSendRtpStreamResult = null;
+			if (sendRtpItem.getLocalPort() != 0) {
+				if (zlmrtpServerFactory.releasePort(mediaInfo, sendRtpItem.getSsrc())) {
+					if (sendRtpItem.isTcpActive()) {
+						startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param);
 					}else {
+						param.put("is_udp", is_Udp);
+						param.put("dst_url", sendRtpItem.getIp());
+						param.put("dst_port", sendRtpItem.getPort());
 						startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
 					}
-					if (startSendRtpStreamResult != null) {
-						startSendRtpStreamHand(evt, sendRtpItem, parentPlatform, startSendRtpStreamResult, param, callIdHeader);
-					}
 				}
-
-
+			}else {
+				if (sendRtpItem.isTcpActive()) {
+					startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param);
+				}else {
+					param.put("is_udp", is_Udp);
+					param.put("dst_url", sendRtpItem.getIp());
+					param.put("dst_port", sendRtpItem.getPort());
+					startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
+				}
+			}
+			if (startSendRtpStreamResult != null) {
+				startSendRtpStreamHand(evt, sendRtpItem, parentPlatform, startSendRtpStreamResult, param, callIdHeader);
+			}
 		}
 	}
 	private void startSendRtpStreamHand(RequestEvent evt, SendRtpItem sendRtpItem, ParentPlatform parentPlatform,
@@ -209,7 +182,16 @@
 		} else {
 			logger.error("RTP鎺ㄦ祦澶辫触: {}, 鍙傛暟锛歿}",jsonObject.getString("msg"), JSON.toJSONString(param));
 			if (sendRtpItem.isOnlyAudio()) {
-				// TODO 鍙兘鏄闊冲璁�
+				Device device = deviceService.getDevice(sendRtpItem.getDeviceId());
+				AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(sendRtpItem.getDeviceId(), sendRtpItem.getChannelId());
+				if (audioBroadcastCatch != null) {
+					try {
+						cmder.streamByeCmd(device, sendRtpItem.getChannelId(), audioBroadcastCatch.getSipTransactionInfo(), null);
+					} catch (SipException | ParseException | InvalidArgumentException |
+							 SsrcTransactionNotFoundException e) {
+						logger.error("[鍛戒护鍙戦�佸け璐 鍋滄璇煶瀵硅: {}", e.getMessage());
+					}
+				}
 			}else {
 				// 鍚戜笂绾у钩鍙�
 				try {

--
Gitblit v1.8.0