From bd570d167be9671f46ec27568b2a591713897323 Mon Sep 17 00:00:00 2001 From: panlinlin <648540858@qq.com> Date: Fri, 7 May 2021 17:24:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=9B=B4=E6=92=AD=E6=B5=81?= =?UTF-8?q?=E7=82=B9=E6=92=AD=E6=B5=81=E7=A8=8B=EF=BC=8C=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=B5=81=E4=BB=A3=E7=90=86=E6=8E=A5=E5=8F=A3=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=9B=B4=E6=8E=A5=E5=85=B3=E8=81=94=E5=9B=BD=E6=A0=87?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/impl/InviteRequestProcessor.java | 62 ++++++++++--------- .../vmp/media/zlm/dto/StreamProxyItem.java | 8 +++ .../vmp/service/impl/MediaServiceImpl.java | 4 -- .../service/impl/StreamProxyServiceImpl.java | 20 ++++++ .../streamProxy/StreamProxyController.java | 11 +++- web_src/src/components/ParentPlatformList.vue | 2 +- web_src/src/components/StreamProxyList.vue | 17 ++--- .../src/components/dialog/StreamProxyEdit.vue | 49 +++++++++++++++ .../src/components/dialog/platformEdit.vue | 3 - 9 files changed, 128 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java index f2a2dec6..a6f0ae77 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java @@ -92,13 +92,21 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor { DeviceChannel channel = storager.queryChannelInParentPlatform(requesterId, channelId); GbStream gbStream = storager.queryStreamInParentPlatform(requesterId, channelId); // 不是通道可能是直播流 - if (channel != null || gbStream != null ) { + if (channel != null && gbStream == null ) { if (channel.getStatus() == 0) { logger.info("通道离线,返回400"); responseAck(evt, Response.BAD_REQUEST, "channel [" + channel.getChannelId() + "] offline"); return; } responseAck(evt, Response.CALL_IS_BEING_FORWARDED); // 通道存在,发181,呼叫转接中 + }else if(channel == null && gbStream != null){ + Boolean streamReady = zlmrtpServerFactory.isStreamReady(gbStream.getApp(), gbStream.getStream()); + if (!streamReady) { + logger.info("[ app={}, stream={} ]通道离线,返回400",gbStream.getApp(), gbStream.getStream()); + responseAck(evt, Response.BAD_REQUEST, "channel [" + gbStream.getGbId() + "] offline"); + return; + } + responseAck(evt, Response.CALL_IS_BEING_FORWARDED); // 通道存在,发181,呼叫转接中 }else { logger.info("通道不存在,返回404"); responseAck(evt, Response.NOT_FOUND); // 通道不存在,发404,资源不存在 @@ -240,34 +248,30 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor { // 写入redis, 超时时回复 redisCatchStorage.updateSendRTPSever(sendRtpItem); - // 检测直播流是否在线 - Boolean streamReady = zlmrtpServerFactory.isStreamReady(gbStream.getApp(), gbStream.getStream()); - if (streamReady) { - sendRtpItem.setStatus(1); - redisCatchStorage.updateSendRTPSever(sendRtpItem); - // TODO 添加对tcp的支持 - ZLMServerConfig mediaInfo = redisCatchStorage.getMediaInfo(); - StringBuffer content = new StringBuffer(200); - content.append("v=0\r\n"); - content.append("o="+"00000"+" 0 0 IN IP4 "+mediaInfo.getWanIp()+"\r\n"); - content.append("s=Play\r\n"); - content.append("c=IN IP4 "+mediaInfo.getWanIp()+"\r\n"); - content.append("t=0 0\r\n"); - content.append("m=video "+ sendRtpItem.getLocalPort()+" RTP/AVP 96\r\n"); - content.append("a=sendonly\r\n"); - content.append("a=rtpmap:96 PS/90000\r\n"); - content.append("y="+ ssrc + "\r\n"); - content.append("f=\r\n"); - - try { - responseAck(evt, content.toString()); - } catch (SipException e) { - e.printStackTrace(); - } catch (InvalidArgumentException e) { - e.printStackTrace(); - } catch (ParseException e) { - e.printStackTrace(); - } + sendRtpItem.setStatus(1); + redisCatchStorage.updateSendRTPSever(sendRtpItem); + // TODO 添加对tcp的支持 + ZLMServerConfig mediaInfo = redisCatchStorage.getMediaInfo(); + StringBuffer content = new StringBuffer(200); + content.append("v=0\r\n"); + content.append("o="+"00000"+" 0 0 IN IP4 "+mediaInfo.getWanIp()+"\r\n"); + content.append("s=Play\r\n"); + content.append("c=IN IP4 "+mediaInfo.getWanIp()+"\r\n"); + content.append("t=0 0\r\n"); + content.append("m=video "+ sendRtpItem.getLocalPort()+" RTP/AVP 96\r\n"); + content.append("a=sendonly\r\n"); + content.append("a=rtpmap:96 PS/90000\r\n"); + content.append("y="+ ssrc + "\r\n"); + content.append("f=\r\n"); + + try { + responseAck(evt, content.toString()); + } catch (SipException e) { + e.printStackTrace(); + } catch (InvalidArgumentException e) { + e.printStackTrace(); + } catch (ParseException e) { + e.printStackTrace(); } } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamProxyItem.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamProxyItem.java index f04e7566..3f997a66 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamProxyItem.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamProxyItem.java @@ -16,6 +16,7 @@ public class StreamProxyItem extends GbStream { private boolean enable; private boolean enable_hls; private boolean enable_mp4; + private String platformGbId; public String getType() { return type; @@ -114,4 +115,11 @@ public class StreamProxyItem extends GbStream { } + public String getPlatformGbId() { + return platformGbId; + } + + public void setPlatformGbId(String platformGbId) { + this.platformGbId = platformGbId; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java index ab23a113..b2626e34 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java @@ -59,11 +59,7 @@ public class MediaServiceImpl implements IMediaService { JSONArray tracks = mediaJSON.getJSONArray("tracks"); streamInfo = getStreamInfoByAppAndStream(app, stream, tracks); } - } return streamInfo; } - - - } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java index b27970a6..a77371f3 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java @@ -1,9 +1,11 @@ package com.genersoft.iot.vmp.service.impl; import com.alibaba.fastjson.JSONObject; +import com.genersoft.iot.vmp.gb28181.bean.GbStream; import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig; import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; +import com.genersoft.iot.vmp.service.IGbStreamService; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorager; import com.genersoft.iot.vmp.storager.dao.GbStreamMapper; @@ -14,6 +16,9 @@ import com.github.pagehelper.PageInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + /** * 视频代理业务 */ @@ -38,6 +43,9 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @Autowired private PlatformGbStreamMapper platformGbStreamMapper; + @Autowired + private IGbStreamService gbStreamService; + @Override public String save(StreamProxyItem param) { @@ -46,6 +54,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { param.getStream() ); param.setDst_url(dstUrl); StringBuffer result = new StringBuffer(); + boolean streamLive = false; // 更新 if (videoManagerStorager.queryStreamProxy(param.getApp(), param.getStream()) != null) { if (videoManagerStorager.updateStreamProxy(param)) { @@ -62,9 +71,11 @@ public class StreamProxyServiceImpl implements IStreamProxyService { }else { // 新增 if (videoManagerStorager.addStreamProxy(param)){ result.append("保存成功"); + streamLive = true; if (param.isEnable()) { JSONObject jsonObject = addStreamProxyToZlm(param); if (jsonObject == null) { + streamLive = false; result.append(", 但是启用失败,请检查流地址是否可用"); param.setEnable(false); videoManagerStorager.updateStreamProxy(param); @@ -73,6 +84,15 @@ public class StreamProxyServiceImpl implements IStreamProxyService { } } + if (param.getPlatformGbId() != null && streamLive) { + List gbStreams = new ArrayList<>(); + gbStreams.add(param); + if (gbStreamService.addPlatformInfo(gbStreams, param.getPlatformGbId())){ + result.append(", 关联国标平台[ " + param.getPlatformGbId() + " ]成功"); + }else { + result.append(", 关联国标平台[ " + param.getPlatformGbId() + " ]失败"); + } + } return result.toString(); } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java index 62f732ec..2baa9999 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java @@ -75,10 +75,15 @@ public class StreamProxyController { @ResponseBody public WVPResult del(String app, String stream){ logger.info("移除代理: " + app + "/" + stream); - streamProxyService.del(app, stream); WVPResult result = new WVPResult<>(); - result.setCode(0); - result.setMsg("success"); + if (app == null || stream == null) { + result.setCode(400); + result.setMsg(app == null ?"app不能为null":"stream不能为null"); + }else { + streamProxyService.del(app, stream); + result.setCode(0); + result.setMsg("success"); + } return result; } diff --git a/web_src/src/components/ParentPlatformList.vue b/web_src/src/components/ParentPlatformList.vue index c4e6b0a5..ecc174a5 100644 --- a/web_src/src/components/ParentPlatformList.vue +++ b/web_src/src/components/ParentPlatformList.vue @@ -156,7 +156,7 @@ export default { this.$axios({ method: 'get', - url:`/api/platform/query/${that.count}/${that.currentPage}` + url:`/api/platform/query/${that.count}/${that.currentPage}` }).then(function (res) { that.total = res.data.total; that.platformList = res.data.list; diff --git a/web_src/src/components/StreamProxyList.vue b/web_src/src/components/StreamProxyList.vue index d71de84b..72b878f4 100644 --- a/web_src/src/components/StreamProxyList.vue +++ b/web_src/src/components/StreamProxyList.vue @@ -33,6 +33,14 @@ + + + - - - +