From b78769f9972b1d8efe59b74868ce6adf7eccc2b6 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期一, 01 四月 2024 18:35:26 +0800 Subject: [PATCH] 临时提交 --- src/main/java/com/genersoft/iot/vmp/media/abl/ABLMediaServerStatusManger.java | 85 ++++++++++++++++++++++++++++++++++-------- 1 files changed, 68 insertions(+), 17 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 0d2f043..5895ce2 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 @@ -5,12 +5,13 @@ import com.genersoft.iot.vmp.conf.DynamicTask; import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.media.abl.bean.AblServerConfig; +import com.genersoft.iot.vmp.media.abl.bean.ConfigKeyId; import com.genersoft.iot.vmp.media.abl.event.HookAblServerKeepaliveEvent; import com.genersoft.iot.vmp.media.abl.event.HookAblServerStartEvent; -import com.genersoft.iot.vmp.media.event.MediaServerChangeEvent; -import com.genersoft.iot.vmp.media.event.MediaServerDeleteEvent; +import com.genersoft.iot.vmp.media.event.mediaServer.MediaServerChangeEvent; +import com.genersoft.iot.vmp.media.event.mediaServer.MediaServerDeleteEvent; import com.genersoft.iot.vmp.media.service.IMediaServerService; -import com.genersoft.iot.vmp.media.zlm.dto.MediaServer; +import com.genersoft.iot.vmp.media.bean.MediaServer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -19,10 +20,8 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import org.springframework.util.ObjectUtils; -import java.io.File; -import java.util.HashMap; +import java.lang.reflect.Field; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -141,7 +140,6 @@ 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 = AblServerConfig.getInstance(data); initPort(mediaServerItem, ablServerConfig); online(mediaServerItem, ablServerConfig); @@ -166,7 +164,6 @@ logger.info("[ABL-灏濊瘯杩炴帴]澶辫触, ID锛歿}, 鍦板潃锛� {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); offlineAblTimeMap.put(mediaServerItem.getId(), System.currentTimeMillis()); }else { -// ablServerConfig = JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class); ablServerConfig = AblServerConfig.getInstance(data); initPort(mediaServerItem, ablServerConfig); online(mediaServerItem, ablServerConfig); @@ -189,13 +186,12 @@ 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 = AblServerConfig.getInstance(data); } } if (config != null) { initPort(mediaServerItem, config); - setAblConfig(mediaServerItem, false); + setAblConfig(mediaServerItem, false, config); } } mediaServerService.update(mediaServerItem); @@ -234,12 +230,67 @@ mediaServerItem.setHookAliveInterval(10F); } - 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); -// + public void setAblConfig(MediaServer mediaServerItem, boolean restart, AblServerConfig config) { + try { + if (config.getHookEnable() == 0) { + logger.info("[濯掍綋鏈嶅姟鑺傜偣-ABL] 寮�鍚疕OOK鍔熻兘 锛歿}", mediaServerItem.getId()); + JSONObject responseJSON = ablResTfulUtils.setConfigParamValue(mediaServerItem, "hook_enable", "1"); + if (responseJSON.getInteger("code") == 0) { + logger.info("[濯掍綋鏈嶅姟鑺傜偣-ABL] 寮�鍚疕OOK鍔熻兘鎴愬姛 锛歿}", mediaServerItem.getId()); + }else { + logger.info("[濯掍綋鏈嶅姟鑺傜偣-ABL] 寮�鍚疕OOK鍔熻兘澶辫触 锛歿}->{}", mediaServerItem.getId(), responseJSON.getString("memo")); + } + } + }catch (Exception e) { + logger.info("[濯掍綋鏈嶅姟鑺傜偣-ABL] 寮�鍚疕OOK鍔熻兘澶辫触 锛歿}", mediaServerItem.getId(), e); + } + // 璁剧疆鐩稿叧鐨凥OOK + String[] hookUrlArray = { + "on_stream_arrive", + "on_stream_none_reader", + "on_record_mp4", + "on_stream_disconnect", + "on_stream_not_found", + "on_server_started", + "on_publish", + "on_play", + "on_record_progress", + "on_server_keepalive", + "on_stream_not_arrive", + "on_delete_record_mp4", + }; + + String protocol = sslEnabled ? "https" : "http"; + String hookPrefix = String.format("%s://%s:%s/index/hook/abl", protocol, mediaServerItem.getHookIp(), serverPort); + Field[] fields = AblServerConfig.class.getDeclaredFields(); + for (Field field : fields) { + try { + if (field.isAnnotationPresent(ConfigKeyId.class)) { + ConfigKeyId configKeyId = field.getAnnotation(ConfigKeyId.class); + for (String hook : hookUrlArray) { + if (configKeyId.value().equals(hook)) { + String hookUrl = String.format("%s/%s", hookPrefix, hook); + field.setAccessible(true); + // 鍒╃敤鍙嶅皠鑾峰彇鍊煎悗瀵规瘮鏄惁涓庨厤缃腑鐩稿悓锛屼笉鍚屽垯杩涜璁剧疆 + if (!hookUrl.equals(field.get(config))) { + JSONObject responseJSON = ablResTfulUtils.setConfigParamValue(mediaServerItem, hook, hookUrl); + if (responseJSON.getInteger("code") == 0) { + logger.info("[濯掍綋鏈嶅姟鑺傜偣-ABL] 璁剧疆HOOK {} 鎴愬姛 锛歿}", hook, mediaServerItem.getId()); + }else { + logger.info("[濯掍綋鏈嶅姟鑺傜偣-ABL] 璁剧疆HOOK {} 澶辫触 锛歿}->{}", hook, mediaServerItem.getId(), responseJSON.getString("memo")); + } + } + } + } + } + }catch (Exception e) { + logger.info("[濯掍綋鏈嶅姟鑺傜偣-ABL] 璁剧疆HOOK 澶辫触 锛歿}", mediaServerItem.getId(), e); + } + } + + + + // Map<String, Object> param = new HashMap<>(); // param.put("api.secret",mediaServerItem.getSecret()); // -profile:v Baseline // if (mediaServerItem.getRtspPort() != 0) { @@ -282,7 +333,7 @@ // param.put("record.appName", recordPathFile.getName()); // } // -// JSONObject responseJSON = ablResTfulUtils.setServerConfig(mediaServerItem, param); +// JSONObject responseJSON = ablResTfulUtils.setConfigParamValue(mediaServerItem, param); // // if (responseJSON != null && responseJSON.getInteger("code") == 0) { // if (restart) { -- Gitblit v1.8.0