From 2b3b7dbc7973def2342eecd8caf7514f0a367c1b Mon Sep 17 00:00:00 2001
From: panlinlin <648540858@qq.com>
Date: 星期五, 16 四月 2021 17:52:30 +0800
Subject: [PATCH] 使用设备Id+通道Id作为session的识别标识,解决点播异常时无法释放session的问题

---
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java |   48 +++++++++++++++++++++++-------------------------
 1 files changed, 23 insertions(+), 25 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
index 84c0898..e0d0bf3 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
@@ -332,17 +332,17 @@
 	
 	 /**
 	 * 	璇锋眰棰勮瑙嗛娴�
-	 * @param device  瑙嗛璁惧
-	 * @param channelId  棰勮閫氶亾
-	 * @param event hook璁㈤槄
-	 * @param errorEvent sip閿欒璁㈤槄
-	 */
+	  * @param device  瑙嗛璁惧
+	  * @param channelId  棰勮閫氶亾
+	  * @param event hook璁㈤槄
+	  * @param errorEvent sip閿欒璁㈤槄
+	  */
 	@Override
 	public void playStreamCmd(Device device, String channelId, ZLMHttpHookSubscribe.Event event, SipSubscribe.Event errorEvent) {
+		String streamId = null;
 		try {
 			if (device == null) return;
 			String ssrc = streamSession.createPlaySsrc();
-			String streamId = null;
 			if (rtpEnable) {
 				streamId = String.format("gb_play_%s_%s", device.getDeviceId(), channelId);
 			}else {
@@ -444,9 +444,12 @@
 
 			Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "FromInvt" + tm, null, ssrc, callIdHeader);
 
-			ClientTransaction transaction = transmitRequest(device, request, errorEvent);
-			streamSession.put(streamId,ssrc, transaction);
-
+			ClientTransaction transaction = transmitRequest(device, request, (e -> {
+				streamSession.remove(device.getDeviceId(), channelId);
+				errorEvent.response(e);
+			}));
+			streamSession.put(device.getDeviceId(), channelId ,ssrc,streamId, transaction);
+			
 		} catch ( SipException | ParseException | InvalidArgumentException e) {
 			e.printStackTrace();
 		}
@@ -552,7 +555,7 @@
 	        Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "fromplybck" + tm, null, callIdHeader);
 
 	        ClientTransaction transaction = transmitRequest(device, request, errorEvent);
-	        streamSession.put(streamId, ssrc, transaction);
+	        streamSession.put(device.getDeviceId(), channelId, ssrc, streamId, transaction);
 
 		} catch ( SipException | ParseException | InvalidArgumentException e) {
 			e.printStackTrace();
@@ -566,17 +569,17 @@
 	 * 
 	 */
 	@Override
-	public void streamByeCmd(String ssrc) {
-		streamByeCmd(ssrc, null);
+	public void streamByeCmd(String deviceId, String channelId) {
+		streamByeCmd(deviceId, channelId, null);
 	}
 	@Override
-	public void streamByeCmd(String streamId, SipSubscribe.Event okEvent) {
+	public void streamByeCmd(String deviceId, String channelId, SipSubscribe.Event okEvent) {
 		
 		try {
-			ClientTransaction transaction = streamSession.get(streamId);
+			ClientTransaction transaction = streamSession.getTransaction(deviceId, channelId);
 			// 鏈嶅姟閲嶅惎鍚�
 			if (transaction == null) {
-				StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
+				StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
 				if (streamInfo != null) {
 
 				}
@@ -613,14 +616,9 @@
 			}
 
 			dialog.sendRequest(clientTransaction);
-
-			streamSession.remove(streamId);
-			zlmrtpServerFactory.closeRTPServer(streamId);
-		} catch (TransactionDoesNotExistException e) {
-			e.printStackTrace();
-		} catch (SipException e) {
-			e.printStackTrace();
-		} catch (ParseException e) {
+			zlmrtpServerFactory.closeRTPServer(streamSession.getStreamId(deviceId, channelId));
+			streamSession.remove(deviceId, channelId);
+		} catch (SipException | ParseException e) {
 			e.printStackTrace();
 		}
 	}
@@ -641,7 +639,6 @@
 	 * 璇煶骞挎挱
 	 * 
 	 * @param device  瑙嗛璁惧
-	 * @param channelId  棰勮閫氶亾
 	 */
 	@Override
 	public boolean audioBroadcastCmd(Device device) {
@@ -1140,7 +1137,7 @@
 	 * @param device		瑙嗛璁惧
 	 * @param startPriority	鎶ヨ璧峰绾у埆锛堝彲閫夛級
 	 * @param endPriority	鎶ヨ缁堟绾у埆锛堝彲閫夛級
-	 * @param alarmMethods	鎶ヨ鏂瑰紡鏉′欢锛堝彲閫夛級
+	 * @param alarmMethod	鎶ヨ鏂瑰紡鏉′欢锛堝彲閫夛級
 	 * @param alarmType		鎶ヨ绫诲瀷
 	 * @param startTime		鎶ヨ鍙戠敓璧峰鏃堕棿锛堝彲閫夛級
 	 * @param endTime		鎶ヨ鍙戠敓缁堟鏃堕棿锛堝彲閫夛級
@@ -1428,5 +1425,6 @@
 			String streamId = String.format("gb_play_%s_%s", device.getDeviceId(), channelId);
 			zlmrtpServerFactory.closeRTPServer(streamId);
 		}
+		streamSession.remove(device.getDeviceId(), channelId);
 	}
 }

--
Gitblit v1.8.0