From 2c1dbe63de3d370d0b0f20fea474326e88b9ca23 Mon Sep 17 00:00:00 2001
From: lawrencehj <1934378145@qq.com>
Date: 星期三, 10 三月 2021 14:39:40 +0800
Subject: [PATCH] 增加接收Bye请求后停止向上级推流功能

---
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/ByeRequestProcessor.java |   89 +++++++++++++++++++++++++++++++++++++-------
 1 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/ByeRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/ByeRequestProcessor.java
index 20dd82f..a14a4cc 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/ByeRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/ByeRequestProcessor.java
@@ -1,33 +1,92 @@
 package com.genersoft.iot.vmp.gb28181.transmit.request.impl;
 
+import javax.sip.Dialog;
+import javax.sip.DialogState;
+import javax.sip.InvalidArgumentException;
 import javax.sip.RequestEvent;
-import javax.sip.ServerTransaction;
+import javax.sip.SipException;
+import javax.sip.message.Response;
 
-import org.springframework.stereotype.Component;
+import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
+import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcessor;
+import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
+import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
 
-import com.genersoft.iot.vmp.gb28181.SipLayer;
-import com.genersoft.iot.vmp.gb28181.transmit.request.ISIPRequestProcessor;
+import java.text.ParseException;
+import java.util.HashMap;
+import java.util.Map;
 
 /**    
  * @Description: BYE璇锋眰澶勭悊鍣�
- * @author: songww
+ * @author: swwheihei
  * @date:   2020骞�5鏈�3鏃� 涓嬪崍5:32:05     
  */
-@Component
-public class ByeRequestProcessor implements ISIPRequestProcessor {
+public class ByeRequestProcessor extends SIPRequestAbstractProcessor {
 
-	/**   
+    private IRedisCatchStorage redisCatchStorage;
+
+	private ZLMRTPServerFactory zlmrtpServerFactory;
+
+	/**
 	 * 澶勭悊BYE璇锋眰
-	 * 
 	 * @param evt
-	 * @param layer
-	 * @param transaction
-	 * @param config    
-	 */  
+	 */
 	@Override
-	public void process(RequestEvent evt, SipLayer layer, ServerTransaction transaction) {
-		// TODO Auto-generated method stub
+	public void process(RequestEvent evt) {
+		try {
+			responseAck(evt);
+			Dialog dialog = evt.getDialog();
+			if (dialog == null) return;
+			if (dialog.getState().equals(DialogState.TERMINATED)) {
+				String remoteUri = dialog.getRemoteParty().getURI().toString();
+				String localUri = dialog.getLocalParty().getURI().toString();
+				String platformGbId = remoteUri.substring(remoteUri.indexOf(":") + 1, remoteUri.indexOf("@"));
+				String channelId = localUri.substring(remoteUri.indexOf(":") + 1, remoteUri.indexOf("@"));
+				SendRtpItem sendRtpItem =  redisCatchStorage.querySendRTPServer(platformGbId, channelId);
+				String streamId = sendRtpItem.getStreamId();
+				Map<String, Object> param = new HashMap<>();
+				param.put("vhost","__defaultVhost__");
+				param.put("app","rtp");
+				param.put("stream",streamId);
+				System.out.println("鍋滄鍚戜笂绾ф帹娴侊細" + streamId);
+				zlmrtpServerFactory.stopSendRtpStream(param);
+			}
+		} catch (SipException e) {
+			e.printStackTrace();
+		} catch (InvalidArgumentException e) {
+			e.printStackTrace();
+		} catch (ParseException e) {
+			e.printStackTrace();
+		}
+		// TODO 浼樺厛绾�99 Bye Request娑堟伅瀹炵幇锛屾娑堟伅涓�鑸负绾ц仈娑堟伅锛屼笂绾х粰涓嬬骇鍙戦�佽棰戝仠姝㈡寚浠�
 		
 	}
 
+	/***
+	 * 鍥炲200 OK
+	 * @param evt
+	 * @throws SipException
+	 * @throws InvalidArgumentException
+	 * @throws ParseException
+	 */
+	private void responseAck(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException {
+		Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest());
+		getServerTransaction(evt).sendResponse(response);
+	}
+
+	public IRedisCatchStorage getRedisCatchStorage() {
+		return redisCatchStorage;
+	}
+
+	public void setRedisCatchStorage(IRedisCatchStorage redisCatchStorage) {
+		this.redisCatchStorage = redisCatchStorage;
+	}
+
+	public ZLMRTPServerFactory getZlmrtpServerFactory() {
+		return zlmrtpServerFactory;
+	}
+
+	public void setZlmrtpServerFactory(ZLMRTPServerFactory zlmrtpServerFactory) {
+		this.zlmrtpServerFactory = zlmrtpServerFactory;
+	}
 }

--
Gitblit v1.8.0