From 999192fa8afd1a5739953db8dc875ca1d0b0d811 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期六, 23 三月 2024 23:40:32 +0800 Subject: [PATCH] 支持读取abl配置信息 --- src/main/java/com/genersoft/iot/vmp/media/abl/ABLMediaServerStatusManger.java | 185 ++++++++++++++++++++++----------------------- 1 files changed, 91 insertions(+), 94 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/media/abl/ABLMediaServerStatusManger.java b/src/main/java/com/genersoft/iot/vmp/media/abl/ABLMediaServerStatusManger.java index 28181e8..0d2f043 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/abl/ABLMediaServerStatusManger.java +++ b/src/main/java/com/genersoft/iot/vmp/media/abl/ABLMediaServerStatusManger.java @@ -1,6 +1,5 @@ package com.genersoft.iot.vmp.media.abl; -import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.genersoft.iot.vmp.conf.DynamicTask; @@ -12,9 +11,6 @@ import com.genersoft.iot.vmp.media.event.MediaServerDeleteEvent; import com.genersoft.iot.vmp.media.service.IMediaServerService; import com.genersoft.iot.vmp.media.zlm.dto.MediaServer; -import com.genersoft.iot.vmp.media.zlm.dto.ZLMServerConfig; -import com.genersoft.iot.vmp.media.zlm.event.HookZlmServerKeepaliveEvent; -import com.genersoft.iot.vmp.media.zlm.event.HookZlmServerStartEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -28,7 +24,6 @@ import java.io.File; import java.util.HashMap; import java.util.Map; -import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; /** @@ -136,17 +131,18 @@ continue; } logger.info("[ABL-灏濊瘯杩炴帴] ID锛歿}, 鍦板潃锛� {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); - JSONObject responseJson = ablResTfulUtils.getMediaServerConfig(mediaServerItem); + JSONObject responseJson = ablResTfulUtils.getServerConfig(mediaServerItem); AblServerConfig ablServerConfig = null; if (responseJson == null) { logger.info("[ABL-灏濊瘯杩炴帴]澶辫触, ID锛歿}, 鍦板潃锛� {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); continue; } - JSONArray data = responseJson.getJSONArray("data"); + JSONArray data = responseJson.getJSONArray("params"); if (data == null || data.isEmpty()) { logger.info("[ABL-灏濊瘯杩炴帴]澶辫触, ID锛歿}, 鍦板潃锛� {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); }else { - ablServerConfig = JSON.parseObject(JSON.toJSONString(data.get(0)), AblServerConfig.class); +// ablServerConfig = JSON.parseObject(JSON.toJSONString(data.get(0)), AblServerConfig.class); + ablServerConfig = AblServerConfig.getInstance(data); initPort(mediaServerItem, ablServerConfig); online(mediaServerItem, ablServerConfig); } @@ -158,21 +154,22 @@ continue; } logger.info("[ABL-灏濊瘯杩炴帴] ID锛歿}, 鍦板潃锛� {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); - JSONObject responseJson = ablResTfulUtils.getMediaServerConfig(mediaServerItem); - ZLMServerConfig zlmServerConfig = null; + JSONObject responseJson = ablResTfulUtils.getServerConfig(mediaServerItem); + AblServerConfig ablServerConfig = null; if (responseJson == null) { logger.info("[ABL-灏濊瘯杩炴帴]澶辫触, ID锛歿}, 鍦板潃锛� {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); offlineAblTimeMap.put(mediaServerItem.getId(), System.currentTimeMillis()); continue; } - JSONArray data = responseJson.getJSONArray("data"); + JSONArray data = responseJson.getJSONArray("params"); if (data == null || data.isEmpty()) { logger.info("[ABL-灏濊瘯杩炴帴]澶辫触, ID锛歿}, 鍦板潃锛� {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); offlineAblTimeMap.put(mediaServerItem.getId(), System.currentTimeMillis()); }else { - zlmServerConfig = JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class); - initPort(mediaServerItem, zlmServerConfig); - online(mediaServerItem, zlmServerConfig); +// ablServerConfig = JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class); + ablServerConfig = AblServerConfig.getInstance(data); + initPort(mediaServerItem, ablServerConfig); + online(mediaServerItem, ablServerConfig); } } } @@ -189,16 +186,16 @@ mediaServerService.update(mediaServerItem); if(mediaServerItem.isAutoConfig()) { if (config == null) { - JSONObject responseJSON = ablResTfulUtils.getMediaServerConfig(mediaServerItem); - JSONArray data = responseJSON.getJSONArray("data"); + JSONObject responseJSON = ablResTfulUtils.getServerConfig(mediaServerItem); + JSONArray data = responseJSON.getJSONArray("params"); if (data != null && !data.isEmpty()) { - config = JSON.parseObject(JSON.toJSONString(data.get(0)), AblServerConfig.class); +// config = JSON.parseObject(JSON.toJSONString(data.get(0)), AblServerConfig.class); + config = AblServerConfig.getInstance(data); } } if (config != null) { initPort(mediaServerItem, config); - setZLMConfig(mediaServerItem, "0".equals(config.getHookEnable()) - || !Objects.equals(mediaServerItem.getHookAliveInterval(), config.getHookAliveInterval())); + setAblConfig(mediaServerItem, false); } } mediaServerService.update(mediaServerItem); @@ -216,90 +213,90 @@ } private void initPort(MediaServer mediaServerItem, AblServerConfig ablServerConfig) { // 绔彛鍙細浠庨厤缃腑璇诲彇涓�娆★紝涓�鏃﹁嚜宸遍厤缃垨鑰呰鍙栬繃浜嗗皢涓嶅湪閰嶇疆 - if (mediaServerItem.getHttpSSlPort() == 0) { - mediaServerItem.setHttpSSlPort(ablServerConfig.getHttpSSLport()); - } +// if (mediaServerItem.getHttpSSlPort() == 0) { +// mediaServerItem.setHttpSSlPort(ablServerConfig.getHttpSSLport()); +// } if (mediaServerItem.getRtmpPort() == 0) { mediaServerItem.setRtmpPort(ablServerConfig.getRtmpPort()); } - if (mediaServerItem.getRtmpSSlPort() == 0) { - mediaServerItem.setRtmpSSlPort(ablServerConfig.getRtmpSslPort()); - } +// if (mediaServerItem.getRtmpSSlPort() == 0) { +// mediaServerItem.setRtmpSSlPort(ablServerConfig.getRtmpSslPort()); +// } if (mediaServerItem.getRtspPort() == 0) { mediaServerItem.setRtspPort(ablServerConfig.getRtspPort()); } - if (mediaServerItem.getRtspSSLPort() == 0) { - mediaServerItem.setRtspSSLPort(ablServerConfig.getRtspSSlport()); - } - if (mediaServerItem.getRtpProxyPort() == 0) { - mediaServerItem.setRtpProxyPort(ablServerConfig.getRtpProxyPort()); - } +// if (mediaServerItem.getRtspSSLPort() == 0) { +// mediaServerItem.setRtspSSLPort(ablServerConfig.getRtspSSlport()); +// } +// if (mediaServerItem.getRtpProxyPort() == 0) { +// mediaServerItem.setRtpProxyPort(ablServerConfig.getRtpProxyPort()); +// } mediaServerItem.setHookAliveInterval(10F); } - public void setZLMConfig(MediaServer mediaServerItem, boolean restart) { - logger.info("[濯掍綋鏈嶅姟鑺傜偣] 姝e湪璁剧疆 锛歿} -> {}:{}", - mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); - String protocol = sslEnabled ? "https" : "http"; - String hookPrefix = String.format("%s://%s:%s/index/hook", protocol, mediaServerItem.getHookIp(), serverPort); - - Map<String, Object> param = new HashMap<>(); - param.put("api.secret",mediaServerItem.getSecret()); // -profile:v Baseline - if (mediaServerItem.getRtspPort() != 0) { - param.put("ffmpeg.snap", "%s -rtsp_transport tcp -i %s -y -f mjpeg -frames:v 1 %s"); - } - param.put("hook.enable","1"); - param.put("hook.on_flow_report",""); - param.put("hook.on_play",String.format("%s/on_play", hookPrefix)); - param.put("hook.on_http_access",""); - param.put("hook.on_publish", String.format("%s/on_publish", hookPrefix)); - param.put("hook.on_record_ts",""); - param.put("hook.on_rtsp_auth",""); - param.put("hook.on_rtsp_realm",""); - param.put("hook.on_server_started",String.format("%s/on_server_started", hookPrefix)); - param.put("hook.on_shell_login",""); - param.put("hook.on_stream_changed",String.format("%s/on_stream_changed", hookPrefix)); - param.put("hook.on_stream_none_reader",String.format("%s/on_stream_none_reader", hookPrefix)); - param.put("hook.on_stream_not_found",String.format("%s/on_stream_not_found", hookPrefix)); - param.put("hook.on_server_keepalive",String.format("%s/on_server_keepalive", hookPrefix)); - param.put("hook.on_send_rtp_stopped",String.format("%s/on_send_rtp_stopped", hookPrefix)); - param.put("hook.on_rtp_server_timeout",String.format("%s/on_rtp_server_timeout", hookPrefix)); - param.put("hook.on_record_mp4",String.format("%s/on_record_mp4", hookPrefix)); - param.put("hook.timeoutSec","30"); - param.put("hook.alive_interval", mediaServerItem.getHookAliveInterval()); - // 鎺ㄦ祦鏂紑鍚庡彲浠ュ湪瓒呮椂鏃堕棿鍐呴噸鏂拌繛鎺ヤ笂缁х画鎺ㄦ祦锛岃繖鏍锋挱鏀惧櫒浼氭帴鐫�鎾斁銆� - // 缃�0鍏抽棴姝ょ壒鎬�(鎺ㄦ祦鏂紑浼氬鑷寸珛鍗虫柇寮�鎾斁鍣�) - // 姝ゅ弬鏁颁笉搴斿ぇ浜庢挱鏀惧櫒瓒呮椂鏃堕棿 - // 浼樺寲姝ゆ秷鎭互鏇村揩鐨勬敹鍒版祦娉ㄩ攢浜嬩欢 - param.put("protocol.continue_push_ms", "3000" ); - // 鏈�澶氱瓑寰呮湭鍒濆鍖栫殑Track鏃堕棿锛屽崟浣嶆绉掞紝瓒呮椂涔嬪悗浼氬拷鐣ユ湭鍒濆鍖栫殑Track, 璁剧疆姝ら�夐」浼樺寲閭d簺闊抽閿欒鐨勪笉瑙勮寖娴侊紝 - // 绛墇lm鏀寔缁欐瘡涓猺tpServer璁剧疆鍏抽棴闊抽鐨勬椂鍊欏彲浠ヤ笉璁剧疆姝ら�夐」 - if (mediaServerItem.isRtpEnable() && !ObjectUtils.isEmpty(mediaServerItem.getRtpPortRange())) { - param.put("rtp_proxy.port_range", mediaServerItem.getRtpPortRange().replace(",", "-")); - } - - if (!ObjectUtils.isEmpty(mediaServerItem.getRecordPath())) { - File recordPathFile = new File(mediaServerItem.getRecordPath()); - param.put("protocol.mp4_save_path", recordPathFile.getParentFile().getPath()); - param.put("protocol.downloadRoot", recordPathFile.getParentFile().getPath()); - param.put("record.appName", recordPathFile.getName()); - } - - JSONObject responseJSON = ablResTfulUtils.setServerConfig(mediaServerItem, param); - - if (responseJSON != null && responseJSON.getInteger("code") == 0) { - if (restart) { - logger.info("[濯掍綋鏈嶅姟鑺傜偣] 璁剧疆鎴愬姛,寮�濮嬮噸鍚互淇濊瘉閰嶇疆鐢熸晥 {} -> {}:{}", - mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); - ablResTfulUtils.restartServer(mediaServerItem); - }else { - logger.info("[濯掍綋鏈嶅姟鑺傜偣] 璁剧疆鎴愬姛 {} -> {}:{}", - mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); - } - }else { - logger.info("[濯掍綋鏈嶅姟鑺傜偣] 璁剧疆濯掍綋鏈嶅姟鑺傜偣澶辫触 {} -> {}:{}", - mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); - } + public void setAblConfig(MediaServer mediaServerItem, boolean restart) { +// logger.info("[濯掍綋鏈嶅姟鑺傜偣] 姝e湪璁剧疆 锛歿} -> {}:{}", +// mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); +// String protocol = sslEnabled ? "https" : "http"; +// String hookPrefix = String.format("%s://%s:%s/index/hook", protocol, mediaServerItem.getHookIp(), serverPort); +// +// Map<String, Object> param = new HashMap<>(); +// param.put("api.secret",mediaServerItem.getSecret()); // -profile:v Baseline +// if (mediaServerItem.getRtspPort() != 0) { +// param.put("ffmpeg.snap", "%s -rtsp_transport tcp -i %s -y -f mjpeg -frames:v 1 %s"); +// } +// param.put("hook.enable","1"); +// param.put("hook.on_flow_report",""); +// param.put("hook.on_play",String.format("%s/on_play", hookPrefix)); +// param.put("hook.on_http_access",""); +// param.put("hook.on_publish", String.format("%s/on_publish", hookPrefix)); +// param.put("hook.on_record_ts",""); +// param.put("hook.on_rtsp_auth",""); +// param.put("hook.on_rtsp_realm",""); +// param.put("hook.on_server_started",String.format("%s/on_server_started", hookPrefix)); +// param.put("hook.on_shell_login",""); +// param.put("hook.on_stream_changed",String.format("%s/on_stream_changed", hookPrefix)); +// param.put("hook.on_stream_none_reader",String.format("%s/on_stream_none_reader", hookPrefix)); +// param.put("hook.on_stream_not_found",String.format("%s/on_stream_not_found", hookPrefix)); +// param.put("hook.on_server_keepalive",String.format("%s/on_server_keepalive", hookPrefix)); +// param.put("hook.on_send_rtp_stopped",String.format("%s/on_send_rtp_stopped", hookPrefix)); +// param.put("hook.on_rtp_server_timeout",String.format("%s/on_rtp_server_timeout", hookPrefix)); +// param.put("hook.on_record_mp4",String.format("%s/on_record_mp4", hookPrefix)); +// param.put("hook.timeoutSec","30"); +// param.put("hook.alive_interval", mediaServerItem.getHookAliveInterval()); +// // 鎺ㄦ祦鏂紑鍚庡彲浠ュ湪瓒呮椂鏃堕棿鍐呴噸鏂拌繛鎺ヤ笂缁х画鎺ㄦ祦锛岃繖鏍锋挱鏀惧櫒浼氭帴鐫�鎾斁銆� +// // 缃�0鍏抽棴姝ょ壒鎬�(鎺ㄦ祦鏂紑浼氬鑷寸珛鍗虫柇寮�鎾斁鍣�) +// // 姝ゅ弬鏁颁笉搴斿ぇ浜庢挱鏀惧櫒瓒呮椂鏃堕棿 +// // 浼樺寲姝ゆ秷鎭互鏇村揩鐨勬敹鍒版祦娉ㄩ攢浜嬩欢 +// param.put("protocol.continue_push_ms", "3000" ); +// // 鏈�澶氱瓑寰呮湭鍒濆鍖栫殑Track鏃堕棿锛屽崟浣嶆绉掞紝瓒呮椂涔嬪悗浼氬拷鐣ユ湭鍒濆鍖栫殑Track, 璁剧疆姝ら�夐」浼樺寲閭d簺闊抽閿欒鐨勪笉瑙勮寖娴侊紝 +// // 绛墇lm鏀寔缁欐瘡涓猺tpServer璁剧疆鍏抽棴闊抽鐨勬椂鍊欏彲浠ヤ笉璁剧疆姝ら�夐」 +// if (mediaServerItem.isRtpEnable() && !ObjectUtils.isEmpty(mediaServerItem.getRtpPortRange())) { +// param.put("rtp_proxy.port_range", mediaServerItem.getRtpPortRange().replace(",", "-")); +// } +// +// if (!ObjectUtils.isEmpty(mediaServerItem.getRecordPath())) { +// File recordPathFile = new File(mediaServerItem.getRecordPath()); +// param.put("protocol.mp4_save_path", recordPathFile.getParentFile().getPath()); +// param.put("protocol.downloadRoot", recordPathFile.getParentFile().getPath()); +// param.put("record.appName", recordPathFile.getName()); +// } +// +// JSONObject responseJSON = ablResTfulUtils.setServerConfig(mediaServerItem, param); +// +// if (responseJSON != null && responseJSON.getInteger("code") == 0) { +// if (restart) { +// logger.info("[濯掍綋鏈嶅姟鑺傜偣] 璁剧疆鎴愬姛,寮�濮嬮噸鍚互淇濊瘉閰嶇疆鐢熸晥 {} -> {}:{}", +// mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); +// ablResTfulUtils.restartServer(mediaServerItem); +// }else { +// logger.info("[濯掍綋鏈嶅姟鑺傜偣] 璁剧疆鎴愬姛 {} -> {}:{}", +// mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); +// } +// }else { +// logger.info("[濯掍綋鏈嶅姟鑺傜偣] 璁剧疆濯掍綋鏈嶅姟鑺傜偣澶辫触 {} -> {}:{}", +// mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); +// } } } -- Gitblit v1.8.0