From 3c025a5ac04b7b8fd619ea62d0cfeceb2060cce3 Mon Sep 17 00:00:00 2001 From: xingqiao <xingqiao@uni-ubi.com> Date: 星期五, 26 八月 2022 11:03:43 +0800 Subject: [PATCH] 1.解决轮询内存增长过快问题 --- src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java | 48 +++++++++++++++++++++--------------------------- 1 files changed, 21 insertions(+), 27 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 055cccb..21879ab 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 @@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -98,16 +99,15 @@ @PostMapping(value = "/on_server_keepalive", produces = "application/json;charset=UTF-8") public ResponseEntity<String> onServerKeepalive(@RequestBody JSONObject json){ - if (logger.isDebugEnabled()) { - logger.debug("[ ZLM HOOK ] on_server_keepalive API璋冪敤锛屽弬鏁帮細" + json.toString()); - } + logger.info("[ ZLM HOOK ] on_server_keepalive API璋冪敤锛屽弬鏁帮細" + json.toString()); String mediaServerId = json.getString("mediaServerId"); - List<ZLMHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(ZLMHttpHookSubscribe.HookType.on_server_keepalive); + List<ZLMHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_server_keepalive); if (subscribes != null && subscribes.size() > 0) { for (ZLMHttpHookSubscribe.Event subscribe : subscribes) { subscribe.response(null, json); } } + mediaServerService.updateMediaServerKeepalive(mediaServerId, json.getJSONObject("data")); JSONObject ret = new JSONObject(); ret.put("code", 0); @@ -167,7 +167,7 @@ logger.debug("[ ZLM HOOK ]on_play API璋冪敤锛屽弬鏁帮細" + JSON.toJSONString(param)); } String mediaServerId = param.getMediaServerId(); - ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_play, json); + ZLMHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_play, json); if (subscribe != null ) { MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId); if (mediaInfo != null) { @@ -240,6 +240,8 @@ if (mediaInfo != null) { assistRESTfulUtils.addStreamCallInfo(mediaInfo, param.getApp(), param.getStream(), callId, null); } + }else { + zlmMediaListManager.sendStreamEvent(param.getApp(),param.getStream(), param.getMediaServerId()); } ret.put("code", 0); @@ -250,7 +252,7 @@ } - ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, json); + ZLMHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_publish, json); if (subscribe != null) { if (mediaInfo != null) { subscribe.response(mediaInfo, json); @@ -374,7 +376,7 @@ logger.debug("[ ZLM HOOK ]on_shell_login API璋冪敤锛屽弬鏁帮細" + json.toString()); } String mediaServerId = json.getString("mediaServerId"); - ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_shell_login, json); + ZLMHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_shell_login, json); if (subscribe != null ) { MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId); if (mediaInfo != null) { @@ -400,7 +402,7 @@ logger.info("[ ZLM HOOK ]on_stream_changed API璋冪敤锛屽弬鏁帮細" + JSONObject.toJSONString(item)); String mediaServerId = item.getMediaServerId(); JSONObject json = (JSONObject) JSON.toJSON(item); - ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, json); + ZLMHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_stream_changed, json); if (subscribe != null ) { MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId); if (mediaInfo != null) { @@ -442,13 +444,15 @@ if (streamInfo!=null){ redisCatchStorage.stopPlay(streamInfo); storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId()); + // 濡傛灉姝e湪缁欎笂绾ф帹閫侊紝鍒欏彂閫乥ye + }else{ streamInfo = redisCatchStorage.queryPlayback(null, null, stream, null); if (streamInfo != null) { redisCatchStorage.stopPlayback(streamInfo.getDeviceID(), streamInfo.getChannelId(), streamInfo.getStream(), null); } - + // 濡傛灉姝e湪缁欎笂绾ф帹閫侊紝鍒欏彂閫乥ye } }else { if (!"rtp".equals(app)){ @@ -461,7 +465,6 @@ StreamInfo streamInfoByAppAndStream = mediaService.getStreamInfoByAppAndStream(mediaServerItem, app, stream, tracks, streamAuthorityInfo.getCallId()); item.setStreamInfo(streamInfoByAppAndStream); - item.setSeverId(userSetting.getServerId()); redisCatchStorage.addStream(mediaServerItem, type, app, stream, item); if (item.getOriginType() == OriginType.RTSP_PUSH.ordinal() || item.getOriginType() == OriginType.RTMP_PUSH.ordinal() @@ -469,20 +472,6 @@ item.setSeverId(userSetting.getServerId()); zlmMediaListManager.addPush(item); } - -// List<GbStream> gbStreams = new ArrayList<>(); -// if (streamPushItem == null || streamPushItem.getGbId() == null) { -// GbStream gbStream = storager.getGbStream(app, streamId); -// gbStreams.add(gbStream); -// }else { -// if (streamPushItem.getGbId() != null) { -// gbStreams.add(streamPushItem); -// } -// } -// if (gbStreams.size() > 0) { -// eventPublisher.catalogEventPublishForStream(null, gbStreams, CatalogEvent.ON); -// } - }else { // 鍏煎娴佹敞閿�鏃剁被鍨嬩粠redis璁板綍鑾峰彇 MediaItem mediaItem = redisCatchStorage.getStreamInfo(app, stream, mediaServerId); @@ -626,21 +615,26 @@ } String remoteAddr = request.getRemoteAddr(); jsonObject.put("ip", remoteAddr); - List<ZLMHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(ZLMHttpHookSubscribe.HookType.on_server_started); + List<ZLMHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_server_started); if (subscribes != null && subscribes.size() > 0) { for (ZLMHttpHookSubscribe.Event subscribe : subscribes) { subscribe.response(null, jsonObject); } } + + ZLMServerConfig zlmServerConfig = JSONObject.toJavaObject(jsonObject, ZLMServerConfig.class); + if (zlmServerConfig !=null ) { + mediaServerService.zlmServerOnline(zlmServerConfig); + } JSONObject ret = new JSONObject(); ret.put("code", 0); ret.put("msg", "success"); - return new ResponseEntity<String>(ret.toString(),HttpStatus.OK); + return new ResponseEntity<>(ret.toString(),HttpStatus.OK); } private Map<String, String> urlParamToMap(String params) { HashMap<String, String> map = new HashMap<>(); - if (StringUtils.isEmpty(params)) { + if (ObjectUtils.isEmpty(params)) { return map; } String[] paramsArray = params.split("&"); -- Gitblit v1.8.0