| | |
| | | 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 org.springframework.util.ObjectUtils; |
| | | |
| | | import java.io.File; |
| | | import java.lang.reflect.Field; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | mediaServerItem.setHookAliveInterval(10F); |
| | | } |
| | | |
| | | public void setAblConfig(MediaServer mediaServerItem, boolean restart) { |
| | | // logger.info("[媒体服务节点] 正在设置 :{} -> {}:{}", |
| | | // 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] 开启HOOK功能 :{}", mediaServerItem.getId()); |
| | | JSONObject responseJSON = ablResTfulUtils.setConfigParamValue(mediaServerItem, "hook_enable", "1"); |
| | | if (responseJSON.getInteger("code") == 0) { |
| | | logger.info("[媒体服务节点-ABL] 开启HOOK功能成功 :{}", mediaServerItem.getId()); |
| | | }else { |
| | | logger.info("[媒体服务节点-ABL] 开启HOOK功能失败 :{}->{}", mediaServerItem.getId(), responseJSON.getString("memo")); |
| | | } |
| | | } |
| | | }catch (Exception e) { |
| | | logger.info("[媒体服务节点-ABL] 开启HOOK功能失败 :{}", mediaServerItem.getId(), e); |
| | | } |
| | | // 设置相关的HOOK |
| | | 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) { |
| | |
| | | // 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) { |