优化语音对讲级联,目前等待zlm支持openRTPServer仅收音频

结构优化
648540858 2023-02-14 11:29:22 +08:00
parent 5cae58c691
commit d5f26faf15
3 changed files with 39 additions and 55 deletions

View File

@ -310,24 +310,24 @@ public class SIPRequestHeaderPlarformProvider {
return request; 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; Request request = null;
//请求行 //请求行
String deviceHostAddress = platform.getDeviceIp() + ":" + platform.getDevicePort(); String platformHostAddress = platform.getServerIP() + ":" + platform.getServerPort();
SipURI requestLine = sipLayer.getSipFactory().createAddressFactory().createSipURI(channelId, deviceHostAddress); String localHostAddress = sipLayer.getLocalIp(platform.getDeviceIp())+":"+ platform.getDevicePort();
SipURI requestLine = sipLayer.getSipFactory().createAddressFactory().createSipURI(channelId, platformHostAddress);
//via //via
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>(); ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
HeaderFactory headerFactory = sipLayer.getSipFactory().createHeaderFactory();
ViaHeader viaHeader = sipLayer.getSipFactory().createHeaderFactory().createViaHeader(sipLayer.getLocalIp(platform.getDeviceIp()), platform.getDevicePort(), platform.getTransport(), viaTag); ViaHeader viaHeader = sipLayer.getSipFactory().createHeaderFactory().createViaHeader(sipLayer.getLocalIp(platform.getDeviceIp()), platform.getDevicePort(), platform.getTransport(), viaTag);
viaHeader.setRPort(); viaHeader.setRPort();
viaHeaders.add(viaHeader); viaHeaders.add(viaHeader);
//from //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); Address fromAddress = sipLayer.getSipFactory().createAddressFactory().createAddress(fromSipURI);
FromHeader fromHeader = sipLayer.getSipFactory().createHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记否则无法创建会话无法回应ack FromHeader fromHeader = sipLayer.getSipFactory().createHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记否则无法创建会话无法回应ack
//to //to
SipURI toSipURI = sipLayer.getSipFactory().createAddressFactory().createSipURI(channelId, deviceHostAddress); SipURI toSipURI = sipLayer.getSipFactory().createAddressFactory().createSipURI(channelId, platformHostAddress);
Address toAddress = sipLayer.getSipFactory().createAddressFactory().createAddress(toSipURI); Address toAddress = sipLayer.getSipFactory().createAddressFactory().createAddress(toSipURI);
ToHeader toHeader = sipLayer.getSipFactory().createHeaderFactory().createToHeader(toAddress,null); ToHeader toHeader = sipLayer.getSipFactory().createHeaderFactory().createToHeader(toAddress,null);
@ -340,8 +340,7 @@ public class SIPRequestHeaderPlarformProvider {
request.addHeader(SipUtils.createUserAgentHeader(sipLayer.getSipFactory(), gitUtil)); 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(),localHostAddress));
// Address concatAddress = sipLayer.getSipFactory().createAddressFactory().createAddress(sipLayer.getSipFactory().createAddressFactory().createSipURI(sipConfig.getId(), device.getHost().getIp()+":"+device.getHost().getPort()));
request.addHeader(sipLayer.getSipFactory().createHeaderFactory().createContactHeader(concatAddress)); request.addHeader(sipLayer.getSipFactory().createHeaderFactory().createContactHeader(concatAddress));
// Subject // Subject
SubjectHeader subjectHeader = sipLayer.getSipFactory().createHeaderFactory().createSubjectHeader(String.format("%s:%s,%s:%s", channelId, ssrc, sipConfig.getId(), 0)); SubjectHeader subjectHeader = sipLayer.getSipFactory().createHeaderFactory().createSubjectHeader(String.format("%s:%s,%s:%s", channelId, ssrc, sipConfig.getId(), 0));

View File

@ -728,12 +728,12 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
String characterSet = platform.getCharacterSet(); String characterSet = platform.getCharacterSet();
StringBuffer mediaStatusXml = new StringBuffer(200); StringBuffer mediaStatusXml = new StringBuffer(200);
mediaStatusXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n"); mediaStatusXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n");
mediaStatusXml.append("<Notify>\r\n"); mediaStatusXml.append("<Response>\r\n");
mediaStatusXml.append("<CmdType>Broadcast</CmdType>\r\n"); mediaStatusXml.append("<CmdType>Broadcast</CmdType>\r\n");
mediaStatusXml.append("<SN>" + sn + "</SN>\r\n"); mediaStatusXml.append("<SN>" + sn + "</SN>\r\n");
mediaStatusXml.append("<DeviceID>" + deviceChannel.getChannelId() + "</DeviceID>\r\n"); mediaStatusXml.append("<DeviceID>" + deviceChannel.getChannelId() + "</DeviceID>\r\n");
mediaStatusXml.append("<Result>" + (result?"OK":"ERROR") + "</Result>\r\n"); mediaStatusXml.append("<Result>" + (result?"OK":"ERROR") + "</Result>\r\n");
mediaStatusXml.append("</Notify>\r\n"); mediaStatusXml.append("</Response>\r\n");
CallIdHeader callIdHeader = sipSender.getNewCallIdHeader(platform.getDeviceIp(), platform.getTransport()); 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()); CallIdHeader callIdHeader = sipSender.getNewCallIdHeader(sipLayer.getLocalIp(platform.getDeviceIp()), platform.getTransport());
Request request = headerProviderPlatformProvider.createInviteRequest(platform, channelId, Request request = headerProviderPlatformProvider.createInviteRequest(platform, channelId,
content.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, ssrcInfo.getSsrc(), content.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), ssrcInfo.getSsrc(),
callIdHeader ,platform.getTransport()); callIdHeader);
sipSender.transmitRequest(sipLayer.getLocalIp(platform.getDeviceIp()), request, (e -> { sipSender.transmitRequest(sipLayer.getLocalIp(platform.getDeviceIp()), request, (e -> {
streamSession.remove(platform.getServerGBId(), channelId, ssrcInfo.getStream()); streamSession.remove(platform.getServerGBId(), channelId, ssrcInfo.getStream());
mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());

View File

@ -332,7 +332,7 @@ public class ZLMHttpHookListener {
} }
}else if ("broadcast".equals(param.getApp())){ }else if ("broadcast".equals(param.getApp())){
// 语音对讲推流 stream需要满足格式deviceId_channelId // 语音对讲推流 stream需要满足格式deviceId_channelId
if (param.isRegist() && param.getStream().indexOf("_") > 0) { if (param.getStream().indexOf("_") > 0) {
String[] streamArray = param.getStream().split("_"); String[] streamArray = param.getStream().split("_");
if (streamArray.length == 2) { if (streamArray.length == 2) {
String deviceId = streamArray[0]; String deviceId = streamArray[0];
@ -341,28 +341,15 @@ public class ZLMHttpHookListener {
if (device != null) { if (device != null) {
if (param.isRegist()) { if (param.isRegist()) {
if (audioBroadcastManager.exit(deviceId, channelId)) { if (audioBroadcastManager.exit(deviceId, channelId)) {
// 直接推流 playService.stopAudioBroadcast(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 { try {
playService.audioBroadcastCmd(device, channelId, mediaInfo, param.getApp(), param.getStream(),60, false, (msg)->{ playService.audioBroadcastCmd(device, channelId, mediaInfo, param.getApp(), param.getStream(), 60, false, (msg)->{
logger.info("[语音喊话] 通道建立成功, device: {}, channel: {}", deviceId, channelId); logger.info("[语音对讲] 通道建立成功, device: {}, channel: {}", deviceId, channelId);
}); });
} catch (InvalidArgumentException | ParseException | SipException e) { } catch (InvalidArgumentException | ParseException | SipException e) {
logger.error("[命令发送失败] 语音喊话: {}", e.getMessage()); logger.error("[命令发送失败] 语音对讲: {}", e.getMessage());
}
} }
}else { }else {
// 流注销 // 流注销
@ -371,8 +358,6 @@ public class ZLMHttpHookListener {
} else{ } else{
logger.info("[语音对讲] 未找到设备:{}", deviceId); logger.info("[语音对讲] 未找到设备:{}", deviceId);
} }
}else {
logger.info("[语音喊话] 推流格式有误, 格式为: broadcast/设备编号_通道编号 ");
} }
} }
}else if ("talk".equals(param.getApp())){ }else if ("talk".equals(param.getApp())){