From 455e58f866d7f538422f50362137d9759dc58768 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期二, 21 三月 2023 14:21:45 +0800
Subject: [PATCH] 优化合并对讲broadcast级联模式
---
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java | 103 +++++++++++++++++++++++++++------------------------
1 files changed, 55 insertions(+), 48 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 26940c1..984a377 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,9 +9,9 @@
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.callback.DeferredResultHolder;
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
import com.genersoft.iot.vmp.media.zlm.dto.HookType;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
@@ -249,6 +249,7 @@
String channelId = ssrcTransactionForAll.get(0).getChannelId();
DeviceChannel deviceChannel = storager.queryChannel(deviceId, channelId);
if (deviceChannel != null) {
+
result.setEnable_audio(deviceChannel.isHasAudio());
}
// 濡傛灉鏄綍鍍忎笅杞藉氨璁剧疆瑙嗛闂撮殧鍗佺
@@ -257,6 +258,11 @@
result.setEnable_audio(true);
result.setEnable_mp4(true);
}
+ // 濡傛灉鏄痶alk瀵硅锛屽垯榛樿鑾峰彇澹伴煶
+ if (ssrcTransactionForAll.get(0).getType() == VideoStreamSessionManager.SessionType.talk) {
+ result.setEnable_audio(true);
+ }
+
}
return result;
}
@@ -282,12 +288,12 @@
taskExecutor.execute(() -> {
ZlmHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_stream_changed, json);
if (subscribe != null) {
+
if (mediaInfo != null) {
subscribe.response(mediaInfo, json);
}
}
// 娴佹秷澶辩Щ闄edis play
- List<OnStreamChangedHookParam.MediaTrack> tracks = param.getTracks();
if (param.isRegist()) {
if (param.getOriginType() == OriginType.RTMP_PUSH.ordinal()
|| param.getOriginType() == OriginType.RTSP_PUSH.ordinal()
@@ -361,41 +367,31 @@
}
}
}else if ("talk".equals(param.getApp())){
- // 璇煶鍠婅瘽鎺ㄦ祦 stream闇�瑕佹弧瓒虫牸寮廳eviceId_channelId
- 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.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, param.getStream(), null);
- if (sendRtpItem == null) {
- // TODO 鍙兘鏁版嵁閿欒锛岄噸鏂板紑鍚闊抽�氶亾
- }else {
- logger.info("rtp/{}寮�濮嬪悜涓婄骇鎺ㄦ祦, 鐩爣={}:{}锛孲SRC={}", sendRtpItem.getStreamId(), sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc());
- zlmrtpServerFactory.startSendRtp(mediaInfo, sendRtpItem);
- }
- }else {
- // 寮�鍚闊冲枈璇濋�氶亾
- MediaServerItem mediaServerItem = mediaServerService.getOne(param.getMediaServerId());
- playService.talk(mediaServerItem, device, channelId, (mediaServer, jsonObject)->{
- System.out.println("寮�濮嬫帹娴�");
- }, eventResult -> {
- System.out.println(eventResult.msg);
- }, ()->{
- System.out.println("瓒呮椂");
- });
- }
-
- }
- }
- }
- }
+ // 璇煶瀵硅鎺ㄦ祦 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);
+ }
+ // 寮�鍚闊冲璁查�氶亾
+ playService.talkCmd(device, channelId, mediaInfo, param.getStream(), (msg)->{
+ logger.info("[璇煶瀵硅] 閫氶亾寤虹珛鎴愬姛, device: {}, channel: {}", deviceId, channelId);
+ });
+ }else {
+ // 娴佹敞閿�
+ playService.stopTalk(device, channelId, param.isRegist());
+ }
+ } else{
+ logger.info("[璇煶瀵硅] 鏈壘鍒拌澶囷細{}", deviceId);
+ }
+ }
+ }
}else{
if (!"rtp".equals(param.getApp())){
@@ -455,16 +451,21 @@
ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId);
Device device = deviceService.getDevice(platformId);
- try {
+
if (platform != null) {
- commanderFroPlatform.streamByeCmd(platform, sendRtpItem);
+ try {
+ commanderFroPlatform.streamByeCmd(platform, sendRtpItem);
+ } catch (SipException | InvalidArgumentException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍙戦�丅YE: {}", e.getMessage());
+ }
} else {
- cmder.streamByeCmd(device, sendRtpItem.getChannelId(), param.getStream(), sendRtpItem.getCallId());
+ try {
+ cmder.streamByeCmd(device, sendRtpItem.getChannelId(), param.getStream(), sendRtpItem.getCallId());
+ } catch (SipException | InvalidArgumentException | ParseException |
+ SsrcTransactionNotFoundException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍙戦�丅YE: {}", e.getMessage());
+ }
}
- } catch (SipException | InvalidArgumentException | ParseException |
- SsrcTransactionNotFoundException e) {
- logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍙戦�丅YE: {}", e.getMessage());
- }
}
}
}
@@ -507,7 +508,7 @@
logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍙戦�丅YE: {}", e.getMessage());
}
redisCatchStorage.deleteSendRTPServer(parentPlatform.getServerGBId(), sendRtpItem.getChannelId(),
- sendRtpItem.getCallId(), sendRtpItem.getStreamId());
+ sendRtpItem.getCallId(), sendRtpItem.getStream());
}
}
}
@@ -536,8 +537,7 @@
try {
cmder.streamByeCmd(device, streamInfoForPlayBackCatch.getChannelId(),
streamInfoForPlayBackCatch.getStream(), null);
- } catch (InvalidArgumentException | ParseException | SipException |
- SsrcTransactionNotFoundException e) {
+ } catch (InvalidArgumentException | ParseException | SipException | SsrcTransactionNotFoundException e) {
logger.error("[鏃犱汉瑙傜湅]鍥炴斁锛� 鍙戦�丅YE澶辫触 {}", e.getMessage());
}
}
@@ -553,6 +553,13 @@
ret.put("close", false);
return ret;
}
+ SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(null, null, param.getStream(), null);
+ if ("talk".equals(sendRtpItem.getApp())){
+ ret.put("close", false);
+ return ret;
+ }
+ }else if ("talk".equals(param.getApp()) || "broadcast".equals(param.getApp())){
+ ret.put("close", false);
} else {
// 闈炲浗鏍囨祦 鎺ㄦ祦/鎷夋祦浠g悊
// 鎷夋祦浠g悊
@@ -714,7 +721,7 @@
logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍙戦�丅YE: {}", e.getMessage());
}
redisCatchStorage.deleteSendRTPServer(parentPlatform.getServerGBId(), sendRtpItem.getChannelId(),
- sendRtpItem.getCallId(), sendRtpItem.getStreamId());
+ sendRtpItem.getCallId(), sendRtpItem.getStream());
}
}
});
--
Gitblit v1.8.0