From b4048fbe80dba8e7756ae557a15ab60b4f80a44b Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期二, 04 四月 2023 09:09:07 +0800 Subject: [PATCH] 合并开源主线 --- src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java | 88 +++++++++++++++++++++++++++++--------------- 1 files changed, 58 insertions(+), 30 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 eebb461..db40961 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 @@ -119,10 +119,11 @@ * 鏈嶅姟鍣ㄥ畾鏃朵笂鎶ユ椂闂达紝涓婃姤闂撮殧鍙厤缃紝榛樿10s涓婃姤涓�娆� */ @ResponseBody + @PostMapping(value = "/on_server_keepalive", produces = "application/json;charset=UTF-8") public HookResult onServerKeepalive(@RequestBody OnServerKeepaliveHookParam param) { - logger.info("[ZLM HOOK] 鏀跺埌zlm蹇冭烦锛�" + param.getMediaServerId()); +// logger.info("[ZLM HOOK] 鏀跺埌zlm蹇冭烦锛�" + param.getMediaServerId()); taskExecutor.execute(() -> { List<ZlmHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_server_keepalive); @@ -142,6 +143,7 @@ * 鎾斁鍣ㄩ壌鏉冧簨浠讹紝rtsp/rtmp/http-flv/ws-flv/hls鐨勬挱鏀鹃兘灏嗚Е鍙戞閴存潈浜嬩欢銆� */ @ResponseBody + @PostMapping(value = "/on_play", produces = "application/json;charset=UTF-8") public HookResult onPlay(@RequestBody OnPlayHookParam param) { if (logger.isDebugEnabled()) { @@ -264,8 +266,27 @@ } } + if (mediaInfo.getRecordAssistPort() > 0 && userSetting.getRecordPath() == null) { + logger.info("鎺ㄦ祦鏃跺彂鐜板皻鏈缃綍鍍忚矾寰勶紝浠巃ssist鏈嶅姟涓鍙�"); + JSONObject info = assistRESTfulUtils.getInfo(mediaInfo, null); + if (info != null && info.getInteger("code") != null && info.getInteger("code") == 0 ) { + JSONObject dataJson = info.getJSONObject("data"); + if (dataJson != null) { + String recordPath = dataJson.getString("record"); + userSetting.setRecordPath(recordPath); + result.setMp4_save_path(recordPath); + // 淇敼zlm涓殑褰曞儚璺緞 + if (mediaInfo.isAutoConfig()) { + taskExecutor.execute(() -> { + mediaServerService.setZLMConfig(mediaInfo, false); + }); + } + } + } + } return result; } + /** * rtsp/rtmp娴佹敞鍐屾垨娉ㄩ攢鏃惰Е鍙戞浜嬩欢锛涙浜嬩欢瀵瑰洖澶嶄笉鏁忔劅銆� @@ -280,6 +301,9 @@ 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(() -> { @@ -290,8 +314,12 @@ subscribe.response(mediaInfo, json); } } - // 娴佹秷澶辩Щ闄edis play + + List<OnStreamChangedHookParam.MediaTrack> tracks = param.getTracks(); + // TODO 閲嶆瀯姝ゅ閫昏緫 + if (param.isRegist()) { + // 澶勭悊娴佹敞鍐岀殑閴存潈淇℃伅 if (param.getOriginType() == OriginType.RTMP_PUSH.ordinal() || param.getOriginType() == OriginType.RTSP_PUSH.ordinal() || param.getOriginType() == OriginType.RTC_PUSH.ordinal()) { @@ -335,34 +363,34 @@ } }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, mediaInfo, param.getApp(), param.getStream(), (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 if (param.getStream().indexOf("_") > 0) { -- Gitblit v1.8.0