From 01519c25746512ef10e9e2ef2d86ea7b60b9046e Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Fri, 17 Dec 2021 16:06:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A6=96=E6=AC=A1=E8=AE=BE?= =?UTF-8?q?=E7=BD=AEzlm=E6=97=B6=E9=87=8D=E5=90=AFzlm=E4=BB=A5=E4=BF=9D?= =?UTF-8?q?=E8=AF=81=E5=BF=83=E8=B7=B3=E6=AD=A3=E5=B8=B8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/media/zlm/ZLMRESTfulUtils.java | 4 ++++ .../iot/vmp/service/IMediaServerService.java | 2 +- .../service/impl/MediaServerServiceImpl.java | 19 +++++++++++++++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java index e4bcd31a..c5e01d89 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java @@ -238,6 +238,10 @@ public class ZLMRESTfulUtils { return sendPost(mediaServerItem, "stopSendRtp",param, null); } + public JSONObject restartServer(MediaServerItem mediaServerItem) { + return sendPost(mediaServerItem, "restartServer",null, null); + } + public JSONObject addStreamProxy(MediaServerItem mediaServerItem, String app, String stream, String url, boolean enable_hls, boolean enable_mp4, String rtp_type) { Map param = new HashMap<>(); param.put("vhost", "__defaultVhost__"); diff --git a/src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java b/src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java index fcba07f8..56ffbf0a 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java @@ -40,7 +40,7 @@ public interface IMediaServerService { MediaServerItem getMediaServerForMinimumLoad(); - void setZLMConfig(MediaServerItem mediaServerItem); + void setZLMConfig(MediaServerItem mediaServerItem, boolean restart); SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId); diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java index 5b170681..cd5f8ab0 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java @@ -373,7 +373,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR redisUtil.set(key, serverItem); resetOnlineServerItem(serverItem); updateMediaServerKeepalive(serverItem.getId(), null); - setZLMConfig(serverItem); + setZLMConfig(serverItem, "0".equals(zlmServerConfig.getHookEnable())); publisher.zlmOnlineEventPublish(serverItem.getId()); } @@ -448,9 +448,10 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR /** * 对zlm服务器进行基础配置 * @param mediaServerItem 服务ID + * @param restart 是否重启zlm */ @Override - public void setZLMConfig(MediaServerItem mediaServerItem) { + public void setZLMConfig(MediaServerItem mediaServerItem, boolean restart) { logger.info("[ ZLM:{} ]-[ {}:{} ]设置zlm", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); String protocol = sslEnabled ? "https" : "http"; @@ -483,12 +484,22 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR JSONObject responseJSON = zlmresTfulUtils.setServerConfig(mediaServerItem, param); if (responseJSON != null && responseJSON.getInteger("code") == 0) { - logger.info("[ ZLM:{} ]-[ {}:{} ]设置zlm成功", - mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); + if (restart) { + logger.info("[ ZLM:{} ]-[ {}:{} ]设置zlm成功, 开始重启以保证配置生效", + mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); + zlmresTfulUtils.restartServer(mediaServerItem); + }else { + logger.info("[ ZLM:{} ]-[ {}:{} ]设置zlm成功", + mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); + } + + }else { logger.info("[ ZLM:{} ]-[ {}:{} ]设置zlm失败", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); } + + }