Browse Source

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

pull/64/head
lawrencehj 4 years ago
parent
commit
2c1dbe63de
  1. 6
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java
  2. 42
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/ByeRequestProcessor.java
  3. 4
      src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java
  4. 18
      src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java

6
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java

@ -22,13 +22,10 @@ import org.springframework.stereotype.Component;
@Component
public class AckRequestProcessor extends SIPRequestAbstractProcessor {
//@Autowired
private IRedisCatchStorage redisCatchStorage;
//@Autowired
private ZLMRTPServerFactory zlmrtpServerFactory;
/**
* 处理 ACK请求
*
@ -49,6 +46,8 @@ public class AckRequestProcessor extends SIPRequestAbstractProcessor {
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 class AckRequestProcessor extends SIPRequestAbstractProcessor {
public void setZlmrtpServerFactory(ZLMRTPServerFactory zlmrtpServerFactory) {
this.zlmrtpServerFactory = zlmrtpServerFactory;
}
}

42
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请求处理器
@ -16,6 +23,10 @@ import java.text.ParseException;
*/
public class ByeRequestProcessor extends SIPRequestAbstractProcessor {
private IRedisCatchStorage redisCatchStorage;
private ZLMRTPServerFactory zlmrtpServerFactory;
/**
* 处理BYE请求
* @param evt
@ -24,6 +35,22 @@ public class ByeRequestProcessor extends SIPRequestAbstractProcessor {
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 @@ public class ByeRequestProcessor extends SIPRequestAbstractProcessor {
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;
}
}

4
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java

@ -123,4 +123,8 @@ public class ZLMRESTfulUtils {
public JSONObject startSendRtp(Map<String, Object> param) {
return sendPost("startSendRtp",param);
}
public JSONObject stopSendRtp(Map<String, Object> param) {
return sendPost("stopSendRtp",param);
}
}

18
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java

@ -151,4 +151,22 @@ public class ZLMRTPServerFactory {
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推流失败: 请检查ZLM服务");
} else if (jsonObject.getInteger("code") == 0) {
result= true;
logger.error("停止RTP推流成功");
} else {
logger.error("停止RTP推流失败: " + jsonObject.getString("msg"));
}
return result;
}
}

Loading…
Cancel
Save