From a8c424e49db9213e879bf6c44cebccdfddaa1808 Mon Sep 17 00:00:00 2001 From: BradyXu <brady_xu@outlook.com> Date: 星期日, 12 五月 2024 02:00:55 +0800 Subject: [PATCH] 修复sip绑定监听多网卡IP时,新增上级平台新增失败的问题,本地IP改成从配置的多IP下拉选择 --- src/main/java/com/genersoft/iot/vmp/media/event/hook/HookSubscribe.java | 34 ++++++++++++++++------------------ 1 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/media/event/hook/HookSubscribe.java b/src/main/java/com/genersoft/iot/vmp/media/event/hook/HookSubscribe.java index 598178f..58e3761 100755 --- a/src/main/java/com/genersoft/iot/vmp/media/event/hook/HookSubscribe.java +++ b/src/main/java/com/genersoft/iot/vmp/media/event/hook/HookSubscribe.java @@ -1,9 +1,6 @@ package com.genersoft.iot.vmp.media.event.hook; -import com.genersoft.iot.vmp.media.event.media.MediaArrivalEvent; -import com.genersoft.iot.vmp.media.event.media.MediaDepartureEvent; -import com.genersoft.iot.vmp.media.event.media.MediaEvent; -import com.genersoft.iot.vmp.media.event.media.MediaPublishEvent; +import com.genersoft.iot.vmp.media.event.media.*; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; @@ -22,7 +19,7 @@ /** * 璁㈤槄鏁版嵁杩囨湡鏃堕棿 */ - private final long subscribeExpire = 5 * 1000; + private final long subscribeExpire = 5 * 60 * 1000; @FunctionalInterface public interface Event{ @@ -35,11 +32,7 @@ @Async("taskExecutor") @EventListener public void onApplicationEvent(MediaArrivalEvent event) { - if ("rtsp".equals(event.getSchema())) { - System.out.println("娴佸埌鏉ョ殑澶勭悊: " + allSubscribes.size()); - for (String s : allSubscribes.keySet()) { - System.out.println("key: " + s); - } + if (event.getSchema() == null || "rtsp".equals(event.getSchema())) { sendNotify(HookType.on_media_arrival, event); } @@ -51,7 +44,7 @@ @Async("taskExecutor") @EventListener public void onApplicationEvent(MediaDepartureEvent event) { - if ("rtsp".equals(event.getSchema())) { + if (event.getSchema() == null || "rtsp".equals(event.getSchema())) { sendNotify(HookType.on_media_departure, event); } @@ -64,13 +57,20 @@ public void onApplicationEvent(MediaPublishEvent event) { sendNotify(HookType.on_publish, event); } + /** + * 鐢熸垚褰曞儚鏂囦欢浜嬩欢 + */ + @Async("taskExecutor") + @EventListener + public void onApplicationEvent(MediaRecordMp4Event event) { + sendNotify(HookType.on_record_mp4, event); + } private final Map<String, Event> allSubscribes = new ConcurrentHashMap<>(); private final Map<String, Hook> allHook = new ConcurrentHashMap<>(); private void sendNotify(HookType hookType, MediaEvent event) { Hook paramHook = Hook.getInstance(hookType, event.getApp(), event.getStream(), event.getMediaServer().getId()); - System.out.println("sendNotify: " + paramHook.toString()); Event hookSubscribeEvent = allSubscribes.get(paramHook.toString()); if (hookSubscribeEvent != null) { HookData data = HookData.getInstance(event); @@ -79,15 +79,14 @@ } public void addSubscribe(Hook hook, HookSubscribe.Event event) { - if (hook.getCreateTime() == null) { - hook.setCreateTime(System.currentTimeMillis()); + if (hook.getExpireTime() == null) { + hook.setExpireTime(System.currentTimeMillis() + subscribeExpire); } allSubscribes.put(hook.toString(), event); allHook.put(hook.toString(), hook); } public void removeSubscribe(Hook hook) { - System.out.println("removeSubscribe: " + hook.toString()); allSubscribes.remove(hook.toString()); allHook.remove(hook.toString()); } @@ -97,10 +96,9 @@ */ @Scheduled(fixedRate=subscribeExpire) //姣�5鍒嗛挓鎵ц涓�娆� public void execute(){ - long expireTime = System.currentTimeMillis() - subscribeExpire; + long expireTime = System.currentTimeMillis(); for (Hook hook : allHook.values()) { - if (hook.getCreateTime() < expireTime) { - System.out.println("execute removeSubscribe: " + hook.toString()); + if (hook.getExpireTime() < expireTime) { allSubscribes.remove(hook.toString()); allHook.remove(hook.toString()); } -- Gitblit v1.8.0