From d5f26faf15ec2b9fbbd5225d86297364b48876b7 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期二, 14 二月 2023 11:29:22 +0800
Subject: [PATCH] 优化语音对讲级联,目前等待zlm支持openRTPServer仅收音频

---
 src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java |   90 +++++++++++++++++---------------------------
 1 files changed, 35 insertions(+), 55 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 dae42c7..26940c1 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
@@ -274,12 +274,14 @@
             logger.info("[ZLM HOOK] 娴佹敞閿�, {}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream());
         }
 
-
+		JSONObject ret = new JSONObject();
+		ret.put("code", 0);
+		ret.put("msg", "success");
+        MediaServerItem mediaInfo = mediaServerService.getOne(param.getMediaServerId());
         JSONObject json = (JSONObject) JSON.toJSON(param);
         taskExecutor.execute(() -> {
             ZlmHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_stream_changed, json);
             if (subscribe != null) {
-                MediaServerItem mediaInfo = mediaServerService.getOne(param.getMediaServerId());
                 if (mediaInfo != null) {
                     subscribe.response(mediaInfo, json);
                 }
@@ -330,36 +332,36 @@
 				}
 			}else if ("broadcast".equals(param.getApp())){
 				// 璇煶瀵硅鎺ㄦ祦  stream闇�瑕佹弧瓒虫牸寮廳eviceId_channelId
-				if (param.getStream().indexOf("_") > 0) {
-					String[] streamArray = param.getStream().split("_");
-					if (streamArray.length == 2) {
-						String deviceId = streamArray[0];
-						String channelId = streamArray[1];
-						Device device = deviceService.getDevice(deviceId);
-						if (device != null) {
-							if (param.isRegist()) {
-								if (audioBroadcastManager.exit(deviceId, channelId)) {
-									playService.stopAudioBroadcast(deviceId, channelId);
-								}
-								// 寮�鍚闊冲璁查�氶亾
-								try {
-									playService.audioBroadcastCmd(device, channelId, 60, (msg)->{
-										logger.info("[璇煶瀵硅] 閫氶亾寤虹珛鎴愬姛, device: {}, channel: {}", deviceId, channelId);
-									});
-								} catch (InvalidArgumentException | ParseException | SipException e) {
-									logger.error("[鍛戒护鍙戦�佸け璐 璇煶瀵硅: {}", e.getMessage());
-								}
-							}else {
-								// 娴佹敞閿�
-								playService.stopAudioBroadcast(deviceId, channelId);
-							}
-						} else{
-							logger.info("[璇煶瀵硅] 鏈壘鍒拌澶囷細{}", deviceId);
-						}
-					}
-				}
+                if (param.getStream().indexOf("_") > 0) {
+                    String[] streamArray = param.getStream().split("_");
+                    if (streamArray.length == 2) {
+                        String deviceId = streamArray[0];
+                        String channelId = streamArray[1];
+                        Device device = deviceService.getDevice(deviceId);
+                        if (device != null) {
+                            if (param.isRegist()) {
+                                if (audioBroadcastManager.exit(deviceId, channelId)) {
+                                    playService.stopAudioBroadcast(deviceId, channelId);
+                                }
+                                // 寮�鍚闊冲璁查�氶亾
+                                try {
+                                    playService.audioBroadcastCmd(device, channelId, mediaInfo, param.getApp(), param.getStream(), 60, false, (msg)->{
+                                        logger.info("[璇煶瀵硅] 閫氶亾寤虹珛鎴愬姛, device: {}, channel: {}", deviceId, channelId);
+                                    });
+                                } catch (InvalidArgumentException | ParseException | SipException e) {
+                                    logger.error("[鍛戒护鍙戦�佸け璐 璇煶瀵硅: {}", e.getMessage());
+                                }
+                            }else {
+                                // 娴佹敞閿�
+                                playService.stopAudioBroadcast(deviceId, channelId);
+                            }
+                        } else{
+                            logger.info("[璇煶瀵硅] 鏈壘鍒拌澶囷細{}", deviceId);
+                        }
+                    }
+                }
 			}else if ("talk".equals(param.getApp())){
-				// 璇煶瀵硅鎺ㄦ祦  stream闇�瑕佹弧瓒虫牸寮廳eviceId_channelId
+				// 璇煶鍠婅瘽鎺ㄦ祦  stream闇�瑕佹弧瓒虫牸寮廳eviceId_channelId
 				if (param.isRegist() && param.getStream().indexOf("_") > 0) {
 					String[] streamArray = param.getStream().split("_");
 					if (streamArray.length == 2) {
@@ -375,33 +377,11 @@
 									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> 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, sendParam);
-										} else {
-											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);
-										}
+										zlmrtpServerFactory.startSendRtp(mediaInfo, sendRtpItem);
 									}
 								}else {
-									// 寮�鍚闊冲璁查�氶亾
+									// 寮�鍚闊冲枈璇濋�氶亾
 									MediaServerItem mediaServerItem = mediaServerService.getOne(param.getMediaServerId());
 									playService.talk(mediaServerItem, device, channelId, (mediaServer, jsonObject)->{
 										System.out.println("寮�濮嬫帹娴�");

--
Gitblit v1.8.0