Commit 2c1dbe63de3d370d0b0f20fea474326e88b9ca23

Authored by lawrencehj
1 parent 343882e4

增加接收Bye请求后停止向上级推流功能

src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java
... ... @@ -22,13 +22,10 @@ import org.springframework.stereotype.Component;
22 22 @Component
23 23 public class AckRequestProcessor extends SIPRequestAbstractProcessor {
24 24  
25   - //@Autowired
26 25 private IRedisCatchStorage redisCatchStorage;
27 26  
28   - //@Autowired
29 27 private ZLMRTPServerFactory zlmrtpServerFactory;
30 28  
31   -
32 29 /**
33 30 * 处理 ACK请求
34 31 *
... ... @@ -49,6 +46,8 @@ public class AckRequestProcessor extends SIPRequestAbstractProcessor {
49 46 String is_Udp = sendRtpItem.isTcp() ? "0" : "1";
50 47 String deviceId = sendRtpItem.getDeviceId();
51 48 StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
  49 + sendRtpItem.setStreamId(streamInfo.getStreamId());
  50 + redisCatchStorage.updateSendRTPSever(sendRtpItem);
52 51 System.out.println(platformGbId);
53 52 System.out.println(channelId);
54 53 Map<String, Object> param = new HashMap<>();
... ... @@ -113,5 +112,4 @@ public class AckRequestProcessor extends SIPRequestAbstractProcessor {
113 112 public void setZlmrtpServerFactory(ZLMRTPServerFactory zlmrtpServerFactory) {
114 113 this.zlmrtpServerFactory = zlmrtpServerFactory;
115 114 }
116   -
117 115 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/ByeRequestProcessor.java
1 1 package com.genersoft.iot.vmp.gb28181.transmit.request.impl;
2 2  
  3 +import javax.sip.Dialog;
  4 +import javax.sip.DialogState;
3 5 import javax.sip.InvalidArgumentException;
4 6 import javax.sip.RequestEvent;
5 7 import javax.sip.SipException;
6 8 import javax.sip.message.Response;
7 9  
  10 +import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
8 11 import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcessor;
  12 +import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
  13 +import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
9 14  
10 15 import java.text.ParseException;
  16 +import java.util.HashMap;
  17 +import java.util.Map;
11 18  
12 19 /**
13 20 * @Description: BYE请求处理器
... ... @@ -16,6 +23,10 @@ import java.text.ParseException;
16 23 */
17 24 public class ByeRequestProcessor extends SIPRequestAbstractProcessor {
18 25  
  26 + private IRedisCatchStorage redisCatchStorage;
  27 +
  28 + private ZLMRTPServerFactory zlmrtpServerFactory;
  29 +
19 30 /**
20 31 * 处理BYE请求
21 32 * @param evt
... ... @@ -24,6 +35,22 @@ public class ByeRequestProcessor extends SIPRequestAbstractProcessor {
24 35 public void process(RequestEvent evt) {
25 36 try {
26 37 responseAck(evt);
  38 + Dialog dialog = evt.getDialog();
  39 + if (dialog == null) return;
  40 + if (dialog.getState().equals(DialogState.TERMINATED)) {
  41 + String remoteUri = dialog.getRemoteParty().getURI().toString();
  42 + String localUri = dialog.getLocalParty().getURI().toString();
  43 + String platformGbId = remoteUri.substring(remoteUri.indexOf(":") + 1, remoteUri.indexOf("@"));
  44 + String channelId = localUri.substring(remoteUri.indexOf(":") + 1, remoteUri.indexOf("@"));
  45 + SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(platformGbId, channelId);
  46 + String streamId = sendRtpItem.getStreamId();
  47 + Map<String, Object> param = new HashMap<>();
  48 + param.put("vhost","__defaultVhost__");
  49 + param.put("app","rtp");
  50 + param.put("stream",streamId);
  51 + System.out.println("停止向上级推流:" + streamId);
  52 + zlmrtpServerFactory.stopSendRtpStream(param);
  53 + }
27 54 } catch (SipException e) {
28 55 e.printStackTrace();
29 56 } catch (InvalidArgumentException e) {
... ... @@ -47,4 +74,19 @@ public class ByeRequestProcessor extends SIPRequestAbstractProcessor {
47 74 getServerTransaction(evt).sendResponse(response);
48 75 }
49 76  
  77 + public IRedisCatchStorage getRedisCatchStorage() {
  78 + return redisCatchStorage;
  79 + }
  80 +
  81 + public void setRedisCatchStorage(IRedisCatchStorage redisCatchStorage) {
  82 + this.redisCatchStorage = redisCatchStorage;
  83 + }
  84 +
  85 + public ZLMRTPServerFactory getZlmrtpServerFactory() {
  86 + return zlmrtpServerFactory;
  87 + }
  88 +
  89 + public void setZlmrtpServerFactory(ZLMRTPServerFactory zlmrtpServerFactory) {
  90 + this.zlmrtpServerFactory = zlmrtpServerFactory;
  91 + }
50 92 }
... ...
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java
... ... @@ -123,4 +123,8 @@ public class ZLMRESTfulUtils {
123 123 public JSONObject startSendRtp(Map<String, Object> param) {
124 124 return sendPost("startSendRtp",param);
125 125 }
  126 +
  127 + public JSONObject stopSendRtp(Map<String, Object> param) {
  128 + return sendPost("stopSendRtp",param);
  129 + }
126 130 }
... ...
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
... ... @@ -151,4 +151,22 @@ public class ZLMRTPServerFactory {
151 151 JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId);
152 152 return (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online"));
153 153 }
  154 +
  155 + /**
  156 + * 调用zlm RESTful API —— stopSendRtp
  157 + */
  158 + public Boolean stopSendRtpStream(Map<String, Object>param) {
  159 + Boolean result = false;
  160 + JSONObject jsonObject = zlmresTfulUtils.stopSendRtp(param);
  161 + System.out.println(jsonObject);
  162 + if (jsonObject == null) {
  163 + logger.error("停止RTP推流失败: 请检查ZLM服务");
  164 + } else if (jsonObject.getInteger("code") == 0) {
  165 + result= true;
  166 + logger.error("停止RTP推流成功");
  167 + } else {
  168 + logger.error("停止RTP推流失败: " + jsonObject.getString("msg"));
  169 + }
  170 + return result;
  171 + }
154 172 }
... ...