From f840c85666369d407ff08ceb6ba30b17aa9d0d4e Mon Sep 17 00:00:00 2001 From: lawrencehj <1934378145@qq.com> Date: Wed, 10 Mar 2021 12:21:05 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=B8=80=E5=A4=84?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=AF=BC=E8=87=B4=E6=AD=BB=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/impl/AckRequestProcessor.java | 5 +++ .../vmp/media/zlm/ZLMRTPServerFactory.java | 36 +++++-------------- 2 files changed, 14 insertions(+), 27 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 7f58de5e..d93ba9cc 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 @@ -68,11 +68,16 @@ public class AckRequestProcessor extends SIPRequestAbstractProcessor { if (System.currentTimeMillis() - startTime < 30 * 1000) { if (zlmrtpServerFactory.isRtpReady(streamInfo.getStreamId())) { rtpPushed = true; + System.out.println("已获取设备推流,开始向上级推流"); zlmrtpServerFactory.startSendRtpStream(param); } else { + System.out.println("等待设备推流......."); Thread.sleep(2000); continue; } + } else { + rtpPushed = true; + System.out.println("设备推流超时,终止向上级推流"); } } catch (InterruptedException e) { e.printStackTrace(); 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 819c6a82..a25753e1 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 @@ -127,46 +127,28 @@ public class ZLMRTPServerFactory { } /** - * + * 调用zlm RESTful API —— startSendRtp */ public Boolean startSendRtpStream(Mapparam) { Boolean result = false; JSONObject jsonObject = zlmresTfulUtils.startSendRtp(param); System.out.println(jsonObject); - if (jsonObject != null) { - switch (jsonObject.getInteger("code")){ - case 0: - result= true; - logger.error("RTP推流请求成功,本地推流端口:" + jsonObject.getString("local_port")); - break; - // case -300: // id已经存在 - // result = false; - // break; - // case -400: // 端口占用 - // result= false; - // break; - default: - logger.error("RTP推流失败: " + jsonObject.getString("msg")); - break; - } - }else { - // 检查ZLM状态 + if (jsonObject == null) { logger.error("RTP推流失败: 请检查ZLM服务"); + } else if (jsonObject.getInteger("code") == 0) { + result= true; + logger.error("RTP推流请求成功,本地推流端口:" + jsonObject.getString("local_port")); + } else { + logger.error("RTP推流失败: " + jsonObject.getString("msg")); } return result; } /** - * + * 查询待转推的流是否就绪 */ public Boolean isRtpReady(String streamId) { JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId); - if (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")) { - logger.info("设备RTP推流成功"); - return true; - } else { - logger.info("设备RTP推流未完成"); - return false; - } + return (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")); } } From b01ec1d72738de24777aee67313539b50f98a15a Mon Sep 17 00:00:00 2001 From: lawrencehj <1934378145@qq.com> Date: Wed, 10 Mar 2021 14:37:17 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=B9=B3=E5=8F=B0Keepali?= =?UTF-8?q?ve=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlatformKeepaliveExpireEventLister.java | 1 + .../iot/vmp/gb28181/transmit/SIPProcessorFactory.java | 2 ++ .../gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java | 6 +++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformKeepaliveExpire/PlatformKeepaliveExpireEventLister.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformKeepaliveExpire/PlatformKeepaliveExpireEventLister.java index c02b7e19..a52a9256 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformKeepaliveExpire/PlatformKeepaliveExpireEventLister.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformKeepaliveExpire/PlatformKeepaliveExpireEventLister.java @@ -64,6 +64,7 @@ public class PlatformKeepaliveExpireEventLister implements ApplicationListener

\r\n"); + keepaliveXml.append("\r\n");//" encoding=\"GB2312\"?>\r\n"); keepaliveXml.append("\r\n"); keepaliveXml.append("Keepalive\r\n"); keepaliveXml.append("" + (int)((Math.random()*9+1)*100000) + "\r\n"); - keepaliveXml.append("" + parentPlatform.getServerGBId() + "\r\n"); + keepaliveXml.append("" + parentPlatform.getDeviceGBId() + "\r\n"); keepaliveXml.append("OK\r\n"); keepaliveXml.append("\r\n"); Request request = headerProviderPlarformProvider.createKeetpaliveMessageRequest( parentPlatform, keepaliveXml.toString(), - UUID.randomUUID().toString().replace("-", ""), + "z9hG4bK-" + UUID.randomUUID().toString().replace("-", ""), UUID.randomUUID().toString().replace("-", ""), null); transmitRequest(parentPlatform, request); From 343882e4c49c7c504fa9c33412819b7288c2bc38 Mon Sep 17 00:00:00 2001 From: lawrencehj <1934378145@qq.com> Date: Wed, 10 Mar 2021 14:38:31 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=9F=90=E4=BA=9Bbranch?= =?UTF-8?q?=E4=B8=8D=E7=AC=A6=E5=90=88GB=E4=B9=8B=E5=A4=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 980c8565..912189c9 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 @@ -893,7 +893,7 @@ public class SIPCommander implements ISIPCommander { catalogXml.append("\r\n"); String tm = Long.toString(System.currentTimeMillis()); - Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaDeviceInfoBranch", "FromDev" + tm, null); + Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "z9hG4bK-ViaDeviceInfo" + tm, "FromDev" + tm, null); transmitRequest(device, request); @@ -923,7 +923,7 @@ public class SIPCommander implements ISIPCommander { catalogXml.append("\r\n"); String tm = Long.toString(System.currentTimeMillis()); - Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaCatalogBranch", "FromCat" + tm, null); + Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "z9hG4bK-ViaCatalog" + tm, "FromCat" + tm, null); transmitRequest(device, request, errorEvent); } catch (SipException | ParseException | InvalidArgumentException e) { From 2c1dbe63de3d370d0b0f20fea474326e88b9ca23 Mon Sep 17 00:00:00 2001 From: lawrencehj <1934378145@qq.com> Date: Wed, 10 Mar 2021 14:39:40 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A5=E6=94=B6Bye?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=90=8E=E5=81=9C=E6=AD=A2=E5=90=91=E4=B8=8A?= =?UTF-8?q?=E7=BA=A7=E6=8E=A8=E6=B5=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/impl/AckRequestProcessor.java | 6 +-- .../request/impl/ByeRequestProcessor.java | 42 +++++++++++++++++++ .../iot/vmp/media/zlm/ZLMRESTfulUtils.java | 4 ++ .../vmp/media/zlm/ZLMRTPServerFactory.java | 18 ++++++++ 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 d93ba9cc..ad7b0708 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,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 param = new HashMap<>(); @@ -113,5 +112,4 @@ public class AckRequestProcessor extends SIPRequestAbstractProcessor { 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 0ba6bd83..a14a4cc6 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请求处理器 @@ -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 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; + } } 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 e3cc8a48..42670a71 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 class ZLMRESTfulUtils { public JSONObject startSendRtp(Map param) { return sendPost("startSendRtp",param); } + + public JSONObject stopSendRtp(Map 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 a25753e1..00951ba2 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 @@ 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(Mapparam) { + 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; + } }