From d883de7f9a13f14ca68727e6548b9e89535f7614 Mon Sep 17 00:00:00 2001
From: quangz <quangz@bluewisdom.com.cn>
Date: 星期六, 02 四月 2022 08:06:30 +0800
Subject: [PATCH] 修复ConcurrentModificationException

---
 src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/OfflineEventListener.java |   52 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/OfflineEventListener.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/OfflineEventListener.java
index e991a29..b7992e4 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/OfflineEventListener.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/OfflineEventListener.java
@@ -1,5 +1,13 @@
 package com.genersoft.iot.vmp.gb28181.event.offline;
 
+import com.genersoft.iot.vmp.conf.UserSetting;
+import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
+import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction;
+import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
+import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
+import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
+import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
+import com.genersoft.iot.vmp.service.IMediaServerService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -7,12 +15,14 @@
 import org.springframework.stereotype.Component;
 
 import com.genersoft.iot.vmp.common.VideoManagerConstants;
-import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
+import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
 import com.genersoft.iot.vmp.utils.redis.RedisUtil;
 
+import java.util.List;
+
 /**
- * @Description: 绂荤嚎浜嬩欢鐩戝惉鍣紝鐩戝惉鍒扮绾垮悗锛屼慨鏀硅澶囩鍦ㄧ嚎鐘舵�併�� 璁惧绂荤嚎鏈変袱涓潵婧愶細
- *               1銆佽澶囦富鍔ㄦ敞閿�锛屽彂閫佹敞閿�鎸囦护锛寋@link com.genersoft.iot.vmp.gb28181.transmit.request.impl.RegisterRequestProcessor}
+ * @description: 绂荤嚎浜嬩欢鐩戝惉鍣紝鐩戝惉鍒扮绾垮悗锛屼慨鏀硅澶囩鍦ㄧ嚎鐘舵�併�� 璁惧绂荤嚎鏈変袱涓潵婧愶細
+ *               1銆佽澶囦富鍔ㄦ敞閿�锛屽彂閫佹敞閿�鎸囦护锛寋@link com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.RegisterRequestProcessor}
  *               2銆佽澶囨湭鐭ュ師鍥犵绾匡紝蹇冭烦瓒呮椂,{@link com.genersoft.iot.vmp.gb28181.event.offline.OfflineEventListener}
  * @author: swwheihei
  * @date: 2020骞�5鏈�6鏃� 涓嬪崍1:51:23
@@ -23,10 +33,27 @@
 	private final static Logger logger = LoggerFactory.getLogger(OfflineEventListener.class);
 	
 	@Autowired
-	private IVideoManagerStorager storager;
+	private IVideoManagerStorage storager;
+
+	@Autowired
+	private VideoStreamSessionManager streamSession;
 	
 	@Autowired
     private RedisUtil redis;
+
+	@Autowired
+    private UserSetting userSetting;
+
+	@Autowired
+    private EventPublisher eventPublisher;
+
+
+	@Autowired
+    private IMediaServerService mediaServerService;
+
+
+	@Autowired
+    private ZLMRTPServerFactory zlmrtpServerFactory;
 
 	@Override
 	public void onApplicationEvent(OfflineEvent event) {
@@ -35,7 +62,7 @@
 			logger.debug("璁惧绂荤嚎浜嬩欢瑙﹀彂锛宒eviceId锛�" + event.getDeviceId() + ",from:" + event.getFrom());
 		}
 
-		String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + event.getDeviceId();
+		String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetting.getServerId() + "_" + event.getDeviceId();
 
 		switch (event.getFrom()) {
 			// 蹇冭烦瓒呮椂瑙﹀彂鐨勭绾夸簨浠讹紝璇存槑redis涓凡鍒犻櫎锛屾棤闇�澶勭悊
@@ -52,9 +79,22 @@
 				}
 		}
 
+		List<DeviceChannel> deviceChannelList = storager.queryOnlineChannelsByDeviceId(event.getDeviceId());
+		eventPublisher.catalogEventPublish(null, deviceChannelList, CatalogEvent.OFF);
 		// 澶勭悊绂荤嚎鐩戝惉
 		storager.outline(event.getDeviceId());
 
-		//
+		// TODO 绂荤嚎鍙栨秷璁㈤槄
+
+		// 绂荤嚎閲婃斁鎵�鏈塻src
+		List<SsrcTransaction> ssrcTransactions = streamSession.getSsrcTransactionForAll(event.getDeviceId(), null, null, null);
+		if (ssrcTransactions != null && ssrcTransactions.size() > 0) {
+			for (SsrcTransaction ssrcTransaction : ssrcTransactions) {
+				mediaServerService.releaseSsrc(ssrcTransaction.getMediaServerId(), ssrcTransaction.getSsrc());
+				mediaServerService.closeRTPServer(event.getDeviceId(), ssrcTransaction.getChannelId(), ssrcTransaction.getStream());
+				streamSession.remove(event.getDeviceId(), ssrcTransaction.getChannelId(), ssrcTransaction.getStream());
+			}
+		}
+
 	}
 }

--
Gitblit v1.8.0