Commit d5f26faf15ec2b9fbbd5225d86297364b48876b7
1 parent
5cae58c6
优化语音对讲级联,目前等待zlm支持openRTPServer仅收音频
Showing
3 changed files
with
39 additions
and
55 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java
| ... | ... | @@ -310,24 +310,24 @@ public class SIPRequestHeaderPlarformProvider { |
| 310 | 310 | return request; |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - 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 { | |
| 313 | + public Request createInviteRequest(ParentPlatform platform, String channelId, String content, String viaTag, String fromTag, String ssrc, CallIdHeader callIdHeader) throws PeerUnavailableException, ParseException, InvalidArgumentException { | |
| 314 | 314 | Request request = null; |
| 315 | 315 | //请求行 |
| 316 | - String deviceHostAddress = platform.getDeviceIp() + ":" + platform.getDevicePort(); | |
| 317 | - SipURI requestLine = sipLayer.getSipFactory().createAddressFactory().createSipURI(channelId, deviceHostAddress); | |
| 316 | + String platformHostAddress = platform.getServerIP() + ":" + platform.getServerPort(); | |
| 317 | + String localHostAddress = sipLayer.getLocalIp(platform.getDeviceIp())+":"+ platform.getDevicePort(); | |
| 318 | + SipURI requestLine = sipLayer.getSipFactory().createAddressFactory().createSipURI(channelId, platformHostAddress); | |
| 318 | 319 | //via |
| 319 | 320 | ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>(); |
| 320 | - HeaderFactory headerFactory = sipLayer.getSipFactory().createHeaderFactory(); | |
| 321 | 321 | ViaHeader viaHeader = sipLayer.getSipFactory().createHeaderFactory().createViaHeader(sipLayer.getLocalIp(platform.getDeviceIp()), platform.getDevicePort(), platform.getTransport(), viaTag); |
| 322 | 322 | viaHeader.setRPort(); |
| 323 | 323 | viaHeaders.add(viaHeader); |
| 324 | 324 | |
| 325 | 325 | //from |
| 326 | - SipURI fromSipURI = sipLayer.getSipFactory().createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getDomain()); | |
| 326 | + SipURI fromSipURI = sipLayer.getSipFactory().createAddressFactory().createSipURI(platform.getDeviceGBId(), sipConfig.getDomain()); | |
| 327 | 327 | Address fromAddress = sipLayer.getSipFactory().createAddressFactory().createAddress(fromSipURI); |
| 328 | 328 | FromHeader fromHeader = sipLayer.getSipFactory().createHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack |
| 329 | 329 | //to |
| 330 | - SipURI toSipURI = sipLayer.getSipFactory().createAddressFactory().createSipURI(channelId, deviceHostAddress); | |
| 330 | + SipURI toSipURI = sipLayer.getSipFactory().createAddressFactory().createSipURI(channelId, platformHostAddress); | |
| 331 | 331 | Address toAddress = sipLayer.getSipFactory().createAddressFactory().createAddress(toSipURI); |
| 332 | 332 | ToHeader toHeader = sipLayer.getSipFactory().createHeaderFactory().createToHeader(toAddress,null); |
| 333 | 333 | |
| ... | ... | @@ -340,8 +340,7 @@ public class SIPRequestHeaderPlarformProvider { |
| 340 | 340 | |
| 341 | 341 | request.addHeader(SipUtils.createUserAgentHeader(sipLayer.getSipFactory(), gitUtil)); |
| 342 | 342 | |
| 343 | - Address concatAddress = sipLayer.getSipFactory().createAddressFactory().createAddress(sipLayer.getSipFactory().createAddressFactory().createSipURI(sipConfig.getId(), sipLayer.getLocalIp(platform.getDeviceIp())+":"+ deviceHostAddress)); | |
| 344 | - // Address concatAddress = sipLayer.getSipFactory().createAddressFactory().createAddress(sipLayer.getSipFactory().createAddressFactory().createSipURI(sipConfig.getId(), device.getHost().getIp()+":"+device.getHost().getPort())); | |
| 343 | + Address concatAddress = sipLayer.getSipFactory().createAddressFactory().createAddress(sipLayer.getSipFactory().createAddressFactory().createSipURI(sipConfig.getId(),localHostAddress)); | |
| 345 | 344 | request.addHeader(sipLayer.getSipFactory().createHeaderFactory().createContactHeader(concatAddress)); |
| 346 | 345 | // Subject |
| 347 | 346 | SubjectHeader subjectHeader = sipLayer.getSipFactory().createHeaderFactory().createSubjectHeader(String.format("%s:%s,%s:%s", channelId, ssrc, sipConfig.getId(), 0)); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
| ... | ... | @@ -728,12 +728,12 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { |
| 728 | 728 | String characterSet = platform.getCharacterSet(); |
| 729 | 729 | StringBuffer mediaStatusXml = new StringBuffer(200); |
| 730 | 730 | mediaStatusXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n"); |
| 731 | - mediaStatusXml.append("<Notify>\r\n"); | |
| 731 | + mediaStatusXml.append("<Response>\r\n"); | |
| 732 | 732 | mediaStatusXml.append("<CmdType>Broadcast</CmdType>\r\n"); |
| 733 | 733 | mediaStatusXml.append("<SN>" + sn + "</SN>\r\n"); |
| 734 | 734 | mediaStatusXml.append("<DeviceID>" + deviceChannel.getChannelId() + "</DeviceID>\r\n"); |
| 735 | 735 | mediaStatusXml.append("<Result>" + (result?"OK":"ERROR") + "</Result>\r\n"); |
| 736 | - mediaStatusXml.append("</Notify>\r\n"); | |
| 736 | + mediaStatusXml.append("</Response>\r\n"); | |
| 737 | 737 | |
| 738 | 738 | CallIdHeader callIdHeader = sipSender.getNewCallIdHeader(platform.getDeviceIp(), platform.getTransport()); |
| 739 | 739 | |
| ... | ... | @@ -793,8 +793,8 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { |
| 793 | 793 | CallIdHeader callIdHeader = sipSender.getNewCallIdHeader(sipLayer.getLocalIp(platform.getDeviceIp()), platform.getTransport()); |
| 794 | 794 | |
| 795 | 795 | Request request = headerProviderPlatformProvider.createInviteRequest(platform, channelId, |
| 796 | - content.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, ssrcInfo.getSsrc(), | |
| 797 | - callIdHeader ,platform.getTransport()); | |
| 796 | + content.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), ssrcInfo.getSsrc(), | |
| 797 | + callIdHeader); | |
| 798 | 798 | sipSender.transmitRequest(sipLayer.getLocalIp(platform.getDeviceIp()), request, (e -> { |
| 799 | 799 | streamSession.remove(platform.getServerGBId(), channelId, ssrcInfo.getStream()); |
| 800 | 800 | mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
| ... | ... | @@ -332,49 +332,34 @@ public class ZLMHttpHookListener { |
| 332 | 332 | } |
| 333 | 333 | }else if ("broadcast".equals(param.getApp())){ |
| 334 | 334 | // 语音对讲推流 stream需要满足格式deviceId_channelId |
| 335 | - if (param.isRegist() && param.getStream().indexOf("_") > 0) { | |
| 336 | - String[] streamArray = param.getStream().split("_"); | |
| 337 | - if (streamArray.length == 2) { | |
| 338 | - String deviceId = streamArray[0]; | |
| 339 | - String channelId = streamArray[1]; | |
| 340 | - Device device = deviceService.getDevice(deviceId); | |
| 341 | - if (device != null) { | |
| 342 | - if (param.isRegist()) { | |
| 343 | - if (audioBroadcastManager.exit(deviceId, channelId)) { | |
| 344 | - // 直接推流 | |
| 345 | - SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(null, null, param.getStream(), null); | |
| 346 | - if (sendRtpItem == null) { | |
| 347 | - // TODO 可能数据错误,重新开启语音通道 | |
| 348 | - }else { | |
| 349 | - JSONObject jsonObject = zlmrtpServerFactory.startSendRtp(mediaInfo, sendRtpItem); | |
| 350 | - if (jsonObject != null && jsonObject.getInteger("code") == 0 ) { | |
| 351 | - logger.info("[语音喊话] 自动推流成功, device: {}, channel: {}", device.getDeviceId(), channelId); | |
| 352 | - }else { | |
| 353 | - logger.info("[语音喊话] 推流失败, 结果: {}", jsonObject); | |
| 354 | - } | |
| 355 | - | |
| 356 | - } | |
| 357 | - }else { | |
| 358 | - // 开启语音喊话通道 | |
| 359 | - try { | |
| 360 | - playService.audioBroadcastCmd(device, channelId, mediaInfo, param.getApp(), param.getStream(),60, false, (msg)->{ | |
| 361 | - logger.info("[语音喊话] 通道建立成功, device: {}, channel: {}", deviceId, channelId); | |
| 362 | - }); | |
| 363 | - } catch (InvalidArgumentException | ParseException | SipException e) { | |
| 364 | - logger.error("[命令发送失败] 语音喊话: {}", e.getMessage()); | |
| 365 | - } | |
| 366 | - } | |
| 367 | - }else { | |
| 368 | - // 流注销 | |
| 369 | - playService.stopAudioBroadcast(deviceId, channelId); | |
| 370 | - } | |
| 371 | - } else{ | |
| 372 | - logger.info("[语音对讲] 未找到设备:{}", deviceId); | |
| 373 | - } | |
| 374 | - }else { | |
| 375 | - logger.info("[语音喊话] 推流格式有误, 格式为: broadcast/设备编号_通道编号 "); | |
| 376 | - } | |
| 377 | - } | |
| 335 | + if (param.getStream().indexOf("_") > 0) { | |
| 336 | + String[] streamArray = param.getStream().split("_"); | |
| 337 | + if (streamArray.length == 2) { | |
| 338 | + String deviceId = streamArray[0]; | |
| 339 | + String channelId = streamArray[1]; | |
| 340 | + Device device = deviceService.getDevice(deviceId); | |
| 341 | + if (device != null) { | |
| 342 | + if (param.isRegist()) { | |
| 343 | + if (audioBroadcastManager.exit(deviceId, channelId)) { | |
| 344 | + playService.stopAudioBroadcast(deviceId, channelId); | |
| 345 | + } | |
| 346 | + // 开启语音对讲通道 | |
| 347 | + try { | |
| 348 | + playService.audioBroadcastCmd(device, channelId, mediaInfo, param.getApp(), param.getStream(), 60, false, (msg)->{ | |
| 349 | + logger.info("[语音对讲] 通道建立成功, device: {}, channel: {}", deviceId, channelId); | |
| 350 | + }); | |
| 351 | + } catch (InvalidArgumentException | ParseException | SipException e) { | |
| 352 | + logger.error("[命令发送失败] 语音对讲: {}", e.getMessage()); | |
| 353 | + } | |
| 354 | + }else { | |
| 355 | + // 流注销 | |
| 356 | + playService.stopAudioBroadcast(deviceId, channelId); | |
| 357 | + } | |
| 358 | + } else{ | |
| 359 | + logger.info("[语音对讲] 未找到设备:{}", deviceId); | |
| 360 | + } | |
| 361 | + } | |
| 362 | + } | |
| 378 | 363 | }else if ("talk".equals(param.getApp())){ |
| 379 | 364 | // 语音喊话推流 stream需要满足格式deviceId_channelId |
| 380 | 365 | if (param.isRegist() && param.getStream().indexOf("_") > 0) { | ... | ... |