From d5f26faf15ec2b9fbbd5225d86297364b48876b7 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Tue, 14 Feb 2023 11:29:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=AD=E9=9F=B3=E5=AF=B9?= =?UTF-8?q?=E8=AE=B2=E7=BA=A7=E8=81=94=EF=BC=8C=E7=9B=AE=E5=89=8D=E7=AD=89?= =?UTF-8?q?=E5=BE=85zlm=E6=94=AF=E6=8C=81openRTPServer=E4=BB=85=E6=94=B6?= =?UTF-8?q?=E9=9F=B3=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cmd/SIPRequestHeaderPlarformProvider.java | 15 ++-- .../cmd/impl/SIPCommanderFroPlatform.java | 8 +-- .../vmp/media/zlm/ZLMHttpHookListener.java | 71 ++++++++----------- 3 files changed, 39 insertions(+), 55 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java index 46ea3c6d..b77a0a48 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java @@ -310,24 +310,24 @@ public class SIPRequestHeaderPlarformProvider { return request; } - public Request createInviteRequest(ParentPlatform platform, String channelId, String toString, String viaTag, String fromTag, Object content, String ssrc, CallIdHeader callIdHeader, String transport) throws PeerUnavailableException, ParseException, InvalidArgumentException { + public Request createInviteRequest(ParentPlatform platform, String channelId, String content, String viaTag, String fromTag, String ssrc, CallIdHeader callIdHeader) throws PeerUnavailableException, ParseException, InvalidArgumentException { Request request = null; //请求行 - String deviceHostAddress = platform.getDeviceIp() + ":" + platform.getDevicePort(); - SipURI requestLine = sipLayer.getSipFactory().createAddressFactory().createSipURI(channelId, deviceHostAddress); + String platformHostAddress = platform.getServerIP() + ":" + platform.getServerPort(); + String localHostAddress = sipLayer.getLocalIp(platform.getDeviceIp())+":"+ platform.getDevicePort(); + SipURI requestLine = sipLayer.getSipFactory().createAddressFactory().createSipURI(channelId, platformHostAddress); //via ArrayList viaHeaders = new ArrayList(); - HeaderFactory headerFactory = sipLayer.getSipFactory().createHeaderFactory(); ViaHeader viaHeader = sipLayer.getSipFactory().createHeaderFactory().createViaHeader(sipLayer.getLocalIp(platform.getDeviceIp()), platform.getDevicePort(), platform.getTransport(), viaTag); viaHeader.setRPort(); viaHeaders.add(viaHeader); //from - SipURI fromSipURI = sipLayer.getSipFactory().createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getDomain()); + SipURI fromSipURI = sipLayer.getSipFactory().createAddressFactory().createSipURI(platform.getDeviceGBId(), sipConfig.getDomain()); Address fromAddress = sipLayer.getSipFactory().createAddressFactory().createAddress(fromSipURI); FromHeader fromHeader = sipLayer.getSipFactory().createHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack //to - SipURI toSipURI = sipLayer.getSipFactory().createAddressFactory().createSipURI(channelId, deviceHostAddress); + SipURI toSipURI = sipLayer.getSipFactory().createAddressFactory().createSipURI(channelId, platformHostAddress); Address toAddress = sipLayer.getSipFactory().createAddressFactory().createAddress(toSipURI); ToHeader toHeader = sipLayer.getSipFactory().createHeaderFactory().createToHeader(toAddress,null); @@ -340,8 +340,7 @@ public class SIPRequestHeaderPlarformProvider { request.addHeader(SipUtils.createUserAgentHeader(sipLayer.getSipFactory(), gitUtil)); - Address concatAddress = sipLayer.getSipFactory().createAddressFactory().createAddress(sipLayer.getSipFactory().createAddressFactory().createSipURI(sipConfig.getId(), sipLayer.getLocalIp(platform.getDeviceIp())+":"+ deviceHostAddress)); - // Address concatAddress = sipLayer.getSipFactory().createAddressFactory().createAddress(sipLayer.getSipFactory().createAddressFactory().createSipURI(sipConfig.getId(), device.getHost().getIp()+":"+device.getHost().getPort())); + Address concatAddress = sipLayer.getSipFactory().createAddressFactory().createAddress(sipLayer.getSipFactory().createAddressFactory().createSipURI(sipConfig.getId(),localHostAddress)); request.addHeader(sipLayer.getSipFactory().createHeaderFactory().createContactHeader(concatAddress)); // Subject SubjectHeader subjectHeader = sipLayer.getSipFactory().createHeaderFactory().createSubjectHeader(String.format("%s:%s,%s:%s", channelId, ssrc, sipConfig.getId(), 0)); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java index 3a617aed..e5d0343c 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java @@ -728,12 +728,12 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { String characterSet = platform.getCharacterSet(); StringBuffer mediaStatusXml = new StringBuffer(200); mediaStatusXml.append("\r\n"); - mediaStatusXml.append("\r\n"); + mediaStatusXml.append("\r\n"); mediaStatusXml.append("Broadcast\r\n"); mediaStatusXml.append("" + sn + "\r\n"); mediaStatusXml.append("" + deviceChannel.getChannelId() + "\r\n"); mediaStatusXml.append("" + (result?"OK":"ERROR") + "\r\n"); - mediaStatusXml.append("\r\n"); + mediaStatusXml.append("\r\n"); CallIdHeader callIdHeader = sipSender.getNewCallIdHeader(platform.getDeviceIp(), platform.getTransport()); @@ -793,8 +793,8 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { CallIdHeader callIdHeader = sipSender.getNewCallIdHeader(sipLayer.getLocalIp(platform.getDeviceIp()), platform.getTransport()); Request request = headerProviderPlatformProvider.createInviteRequest(platform, channelId, - content.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, ssrcInfo.getSsrc(), - callIdHeader ,platform.getTransport()); + content.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), ssrcInfo.getSsrc(), + callIdHeader); sipSender.transmitRequest(sipLayer.getLocalIp(platform.getDeviceIp()), request, (e -> { streamSession.remove(platform.getServerGBId(), channelId, ssrcInfo.getStream()); mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java index 11343299..26940c1e 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java @@ -332,49 +332,34 @@ public class ZLMHttpHookListener { } }else if ("broadcast".equals(param.getApp())){ // 语音对讲推流 stream需要满足格式deviceId_channelId - if (param.isRegist() && param.getStream().indexOf("_") > 0) { - String[] streamArray = param.getStream().split("_"); - if (streamArray.length == 2) { - String deviceId = streamArray[0]; - String channelId = streamArray[1]; - Device device = deviceService.getDevice(deviceId); - if (device != null) { - if (param.isRegist()) { - if (audioBroadcastManager.exit(deviceId, channelId)) { - // 直接推流 - SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(null, null, param.getStream(), null); - if (sendRtpItem == null) { - // TODO 可能数据错误,重新开启语音通道 - }else { - JSONObject jsonObject = zlmrtpServerFactory.startSendRtp(mediaInfo, sendRtpItem); - if (jsonObject != null && jsonObject.getInteger("code") == 0 ) { - logger.info("[语音喊话] 自动推流成功, device: {}, channel: {}", device.getDeviceId(), channelId); - }else { - logger.info("[语音喊话] 推流失败, 结果: {}", jsonObject); - } - - } - }else { - // 开启语音喊话通道 - try { - playService.audioBroadcastCmd(device, channelId, mediaInfo, param.getApp(), param.getStream(),60, false, (msg)->{ - logger.info("[语音喊话] 通道建立成功, device: {}, channel: {}", deviceId, channelId); - }); - } catch (InvalidArgumentException | ParseException | SipException e) { - logger.error("[命令发送失败] 语音喊话: {}", e.getMessage()); - } - } - }else { - // 流注销 - playService.stopAudioBroadcast(deviceId, channelId); - } - } else{ - logger.info("[语音对讲] 未找到设备:{}", deviceId); - } - }else { - logger.info("[语音喊话] 推流格式有误, 格式为: broadcast/设备编号_通道编号 "); - } - } + if (param.getStream().indexOf("_") > 0) { + String[] streamArray = param.getStream().split("_"); + if (streamArray.length == 2) { + String deviceId = streamArray[0]; + String channelId = streamArray[1]; + Device device = deviceService.getDevice(deviceId); + if (device != null) { + if (param.isRegist()) { + if (audioBroadcastManager.exit(deviceId, channelId)) { + playService.stopAudioBroadcast(deviceId, channelId); + } + // 开启语音对讲通道 + try { + playService.audioBroadcastCmd(device, channelId, mediaInfo, param.getApp(), param.getStream(), 60, false, (msg)->{ + logger.info("[语音对讲] 通道建立成功, device: {}, channel: {}", deviceId, channelId); + }); + } catch (InvalidArgumentException | ParseException | SipException e) { + logger.error("[命令发送失败] 语音对讲: {}", e.getMessage()); + } + }else { + // 流注销 + playService.stopAudioBroadcast(deviceId, channelId); + } + } else{ + logger.info("[语音对讲] 未找到设备:{}", deviceId); + } + } + } }else if ("talk".equals(param.getApp())){ // 语音喊话推流 stream需要满足格式deviceId_channelId if (param.isRegist() && param.getStream().indexOf("_") > 0) {