From 6fa5b37b962b05b3aa4b7bf019eb47c4cdbb5738 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期四, 05 一月 2023 11:07:06 +0800 Subject: [PATCH] Merge branch 'main' into main2 --- src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java | 167 +++++++++++++++++++++++-------------------------------- 1 files changed, 70 insertions(+), 97 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..fd4f391 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; @@ -292,15 +287,19 @@ logger.info("[ZLM HOOK] 娴佹敞閿�, {}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream()); } + JSONObject ret = new JSONObject(); + ret.put("code", 0); + ret.put("msg", "success"); JSONObject json = (JSONObject) JSON.toJSON(param); - taskExecutor.execute(()->{ + MediaServerItem mediaInfo = mediaServerService.getOne(param.getMediaServerId()); + if (mediaInfo == null) { + return ret; + } + 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); - } + subscribe.response(mediaInfo, json); } // 娴佹秷澶辩Щ闄edis play List<OnStreamChangedHookParam.MediaTrack> tracks = param.getTracks(); @@ -312,29 +311,30 @@ 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()); + logger.info("娴佸彉鍖栵細娉ㄥ唽->{}, app->{}, stream->{}", param.isRegist(), param.getApp(), param.getStream()); if (param.isRegist()) { mediaServerService.addCount(param.getMediaServerId()); }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,111 +346,76 @@ streamInfo.getStream(), null); } } - }else if ("broadcast".equals(app)){ - // 璇煶瀵硅鎺ㄦ祦 stream闇�瑕佹弧瓒虫牸寮廳eviceId_channelId - if (regist && param.getStream().indexOf("_") > 0) { + }else if ("broadcast".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.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"); - - JSONObject jsonObject; - if (sendRtpItem.isTcpActive()) { - jsonObject = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param); - } else { - param.put("is_udp", is_Udp); - param.put("dst_url", sendRtpItem.getIp()); - param.put("dst_port", sendRtpItem.getPort()); - jsonObject = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param); - } - if (jsonObject != null && jsonObject.getInteger("code") == 0) { - logger.info("[璇煶瀵硅] 鑷姩鎺ㄦ祦鎴愬姛, device: {}, channel: {}", deviceId, channelId); + JSONObject jsonObject = zlmrtpServerFactory.startSendRtp(mediaInfo, sendRtpItem); + if (jsonObject != null && jsonObject.getInteger("code") == 0 ) { + logger.info("[璇煶鍠婅瘽] 鑷姩鎺ㄦ祦鎴愬姛, device: {}, channel: {}", device.getDeviceId(), channelId); + }else { + logger.info("[璇煶鍠婅瘽] 鎺ㄦ祦澶辫触, 缁撴灉锛� {}", jsonObject); } } }else { - // 寮�鍚闊冲璁查�氶亾 + // 寮�鍚闊冲枈璇濋�氶亾 try { - playService.audioBroadcastCmd(device, channelId, 60, (msg)->{ - logger.info("[璇煶瀵硅] 閫氶亾寤虹珛鎴愬姛, device: {}, channel: {}", deviceId, channelId); + 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()); + logger.error("[鍛戒护鍙戦�佸け璐 璇煶鍠婅瘽: {}", e.getMessage()); } } + }else { + logger.info("[璇煶瀵硅] 鏈壘鍒伴�氶亾锛歿}", channelId); } + }else{ + logger.info("[璇煶瀵硅] 鏈壘鍒拌澶囷細{}", deviceId); } + }else { + logger.info("[璇煶鍠婅瘽] 鎺ㄦ祦鏍煎紡鏈夎, 鏍煎紡涓猴細 broadcast/璁惧缂栧彿_閫氶亾缂栧彿 "); } } - }else if ("talk".equals(app)){ - // 璇煶瀵硅鎺ㄦ祦 stream闇�瑕佹弧瓒虫牸寮廳eviceId_channelId - if (regist && stream.indexOf("_") > 0) { - String[] streamArray = stream.split("_"); + }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.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"); - - JSONObject jsonObject; - if (sendRtpItem.isTcpActive()) { - jsonObject = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param); - } 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); - } - if (jsonObject != null && jsonObject.getInteger("code") == 0) { - logger.info("[璇煶瀵硅] 鑷姩鎺ㄦ祦鎴愬姛, device: {}, channel: {}", deviceId, channelId); - } + zlmrtpServerFactory.startSendRtp(mediaInfo, sendRtpItem); } }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 +431,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 +443,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 +454,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,17 +492,22 @@ if (platform != null) { commanderFroPlatform.streamByeCmd(platform, sendRtpItem); }else { - if ("talk".equals(app) && sendRtpItem.isOnlyAudio()) { + if (sendRtpItem.isOnlyAudio()) { AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(sendRtpItem.getDeviceId(), sendRtpItem.getChannelId()); - if (device != null && audioBroadcastCatch != null) { -// cmder.streamByeCmd(device, sendRtpItem.getChannelId(), audioBroadcastCatch.getSipTransactionInfo(), null); + if (audioBroadcastCatch != null) { +// playService.stopAudioBroadcast(device.getDeviceId(), sendRtpItem.getChannelId()); + if ("talk".equals(param.getApp())) { +// cmder.streamByeCmd(device, sendRtpItem.getChannelId(), audioBroadcastCatch.getSipTransactionInfo(), null); + }else { +// cmder.streamByeCmd(device, sendRtpItem.getChannelId(), audioBroadcastCatch.getSipTransactionInfo(), null); + } } - }else { - cmder.streamByeCmd(device, sendRtpItem.getChannelId(), stream, sendRtpItem.getCallId()); } + + } - } catch (SipException | InvalidArgumentException | ParseException | SsrcTransactionNotFoundException e) { + } catch (SipException | InvalidArgumentException | ParseException e) { logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍙戦�丅YE: {}", e.getMessage()); } } @@ -545,9 +516,7 @@ } } - JSONObject ret = new JSONObject(); - ret.put("code", 0); - ret.put("msg", "success"); + return ret; } @@ -575,6 +544,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) { @@ -644,6 +616,7 @@ // 淇敼鏁版嵁 streamProxyService.stop(param.getApp(), param.getStream()); }else { + // 鏃犱汉瑙傜湅涓嶅仛澶勭悊 ret.put("close", false); } return ret; @@ -769,7 +742,7 @@ @ResponseBody @PostMapping(value = "/on_rtp_server_timeout", produces = "application/json;charset=UTF-8") public JSONObject onRtpServerTimeout(HttpServletRequest request, @RequestBody OnRtpServerTimeoutHookParam param){ - logger.info("[ZLM HOOK] rtpServer鏀舵祦瓒呮椂锛歿}->{}({})", param.getMediaServerId(), param.getStream_id(), param.getSsrc()); + logger.info("[ZLM HOOK] rtpServer rtp瓒呮椂锛歿}->{}({})", param.getMediaServerId(), param.getStream_id(), param.getSsrc()); JSONObject ret = new JSONObject(); ret.put("code", 0); -- Gitblit v1.8.0