From 039fbf7e243d4bf0f46b44e7dae2a5d36e978056 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期一, 20 三月 2023 14:32:53 +0800 Subject: [PATCH] Merge branch 'talk' into main-dev --- src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java | 121 +++++++++++++++++---------------------- 1 files changed, 53 insertions(+), 68 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 8770d0e..eebb461 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; } @@ -359,62 +365,30 @@ } }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 { - MediaServerItem mediaServerItem = 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(mediaServerItem, 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(mediaServerItem, sendParam); - } - if (jsonObject != null && jsonObject.getInteger("code") == 0) { - logger.info("[璇煶瀵硅] 鑷姩鎺ㄦ祦鎴愬姛, device: {}, channel: {}", deviceId, channelId); - } - } - }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("瓒呮椂"); - }); - } - - } - } - } - } + 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())){ @@ -474,16 +448,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()); - } } } } @@ -526,7 +505,7 @@ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍙戦�丅YE: {}", e.getMessage()); } redisCatchStorage.deleteSendRTPServer(parentPlatform.getServerGBId(), sendRtpItem.getChannelId(), - sendRtpItem.getCallId(), sendRtpItem.getStreamId()); + sendRtpItem.getCallId(), sendRtpItem.getStream()); } } } @@ -555,8 +534,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()); } } @@ -572,6 +550,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悊 @@ -733,7 +718,7 @@ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍙戦�丅YE: {}", e.getMessage()); } redisCatchStorage.deleteSendRTPServer(parentPlatform.getServerGBId(), sendRtpItem.getChannelId(), - sendRtpItem.getCallId(), sendRtpItem.getStreamId()); + sendRtpItem.getCallId(), sendRtpItem.getStream()); } } }); -- Gitblit v1.8.0