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/media/zlm/ZLMRTPServerFactory.java | 18 +++++++++
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/ByeRequestProcessor.java | 42 +++++++++++++++++++++
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java | 4 ++
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java | 6 +--
4 files changed, 66 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java
index d93ba9c..ad7b070 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java
@@ -22,12 +22,9 @@
@Component
public class AckRequestProcessor extends SIPRequestAbstractProcessor {
- //@Autowired
private IRedisCatchStorage redisCatchStorage;
- //@Autowired
private ZLMRTPServerFactory zlmrtpServerFactory;
-
/**
* 澶勭悊 ACK璇锋眰
@@ -49,6 +46,8 @@
String is_Udp = sendRtpItem.isTcp() ? "0" : "1";
String deviceId = sendRtpItem.getDeviceId();
StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
+ sendRtpItem.setStreamId(streamInfo.getStreamId());
+ redisCatchStorage.updateSendRTPSever(sendRtpItem);
System.out.println(platformGbId);
System.out.println(channelId);
Map<String, Object> param = new HashMap<>();
@@ -113,5 +112,4 @@
public void setZlmrtpServerFactory(ZLMRTPServerFactory zlmrtpServerFactory) {
this.zlmrtpServerFactory = zlmrtpServerFactory;
}
-
}
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 0ba6bd8..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,13 +1,20 @@
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.SipException;
import javax.sip.message.Response;
+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 java.text.ParseException;
+import java.util.HashMap;
+import java.util.Map;
/**
* @Description: BYE璇锋眰澶勭悊鍣�
@@ -15,6 +22,10 @@
* @date: 2020骞�5鏈�3鏃� 涓嬪崍5:32:05
*/
public class ByeRequestProcessor extends SIPRequestAbstractProcessor {
+
+ private IRedisCatchStorage redisCatchStorage;
+
+ private ZLMRTPServerFactory zlmrtpServerFactory;
/**
* 澶勭悊BYE璇锋眰
@@ -24,6 +35,22 @@
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) {
@@ -47,4 +74,19 @@
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;
+ }
}
diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java
index e3cc8a4..42670a7 100644
--- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java
@@ -123,4 +123,8 @@
public JSONObject startSendRtp(Map<String, Object> param) {
return sendPost("startSendRtp",param);
}
+
+ public JSONObject stopSendRtp(Map<String, Object> param) {
+ return sendPost("stopSendRtp",param);
+ }
}
diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
index a25753e..00951ba 100644
--- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
@@ -151,4 +151,22 @@
JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId);
return (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online"));
}
+
+ /**
+ * 璋冪敤zlm RESTful API 鈥斺�� stopSendRtp
+ */
+ public Boolean stopSendRtpStream(Map<String, Object>param) {
+ Boolean result = false;
+ JSONObject jsonObject = zlmresTfulUtils.stopSendRtp(param);
+ System.out.println(jsonObject);
+ if (jsonObject == null) {
+ logger.error("鍋滄RTP鎺ㄦ祦澶辫触: 璇锋鏌LM鏈嶅姟");
+ } else if (jsonObject.getInteger("code") == 0) {
+ result= true;
+ logger.error("鍋滄RTP鎺ㄦ祦鎴愬姛");
+ } else {
+ logger.error("鍋滄RTP鎺ㄦ祦澶辫触: " + jsonObject.getString("msg"));
+ }
+ return result;
+ }
}
--
Gitblit v1.8.0