From f3454caaf6241c44e82704711a3a1efe264f400f Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期二, 25 十月 2022 14:43:12 +0800 Subject: [PATCH] Merge pull request #647 from L120820/wvp-28181-2.0 --- src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java | 19 +++++++++++-------- 1 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java index b24d0a1..195315a 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java @@ -8,7 +8,6 @@ import com.genersoft.iot.vmp.gb28181.event.EventPublisher; import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForServerStarted; -import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.service.IMediaServerService; import org.slf4j.Logger; @@ -19,9 +18,7 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; -import java.time.Instant; import java.util.*; -import java.util.concurrent.TimeUnit; @Component @Order(value=1) @@ -35,7 +32,7 @@ private ZLMRESTfulUtils zlmresTfulUtils; @Autowired - private ZLMHttpHookSubscribe hookSubscribe; + private ZlmHttpHookSubscribe hookSubscribe; @Autowired private EventPublisher publisher; @@ -62,8 +59,6 @@ } mediaServerService.syncCatchFromDatabase(); HookSubscribeForServerStarted hookSubscribeForServerStarted = HookSubscribeFactory.on_server_started(); -// Instant expiresInstant = Instant.now().plusSeconds(TimeUnit.SECONDS.toSeconds(60)); -// hookSubscribeForStreamChange.setExpires(expiresInstant); // 璁㈤槄 zlm鍚姩浜嬩欢, 鏂扮殑zlm涔熶細浠庤繖閲岃繘鍏ョ郴缁� hookSubscribe.addSubscribe(hookSubscribeForServerStarted, (MediaServerItem mediaServerItem, JSONObject response)->{ @@ -85,6 +80,7 @@ // 鑾峰彇鎵�鏈夌殑zlm锛� 骞跺紑鍚富鍔ㄨ繛鎺� List<MediaServerItem> all = mediaServerService.getAllFromDatabase(); + Map<String, MediaServerItem> allMap = new HashMap<>(); mediaServerService.updateVmServer(all); if (all.size() == 0) { all.add(mediaConfig.getMediaSerItem()); @@ -95,6 +91,7 @@ } startGetMedia.put(mediaServerItem.getId(), true); connectZlmServer(mediaServerItem); + allMap.put(mediaServerItem.getId(), mediaServerItem); } String taskKey = "zlm-connect-timeout"; dynamicTask.startDelay(taskKey, ()->{ @@ -105,11 +102,17 @@ } startGetMedia = null; } - // TODO 娓呯悊鏁版嵁搴撲腑涓巖edis涓嶅尮閰嶇殑zlm + // 鑾峰彇redis涓墍鏈夌殑zlm + List<MediaServerItem> allInRedis = mediaServerService.getAll(); + for (MediaServerItem mediaServerItem : allInRedis) { + if (!allMap.containsKey(mediaServerItem.getId())) { + mediaServerService.delete(mediaServerItem.getId()); + } + } }, 60 * 1000 ); } - @Async + @Async("taskExecutor") public void connectZlmServer(MediaServerItem mediaServerItem){ String connectZlmServerTaskKey = "connect-zlm-" + mediaServerItem.getId(); ZLMServerConfig zlmServerConfigFirst = getMediaServerConfig(mediaServerItem); -- Gitblit v1.8.0