diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java index ee462734..62abe5ed 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java @@ -170,11 +170,11 @@ public class SIPRequestHeaderProvider { //from SipURI fromSipURI = sipLayer.getSipFactory().createAddressFactory().createSipURI(sipConfig.getId(),sipConfig.getDomain()); Address fromAddress = sipLayer.getSipFactory().createAddressFactory().createAddress(fromSipURI); - FromHeader fromHeader = sipLayer.getSipFactory().createHeaderFactory().createFromHeader(fromAddress, transactionInfo.getFromTag()); + FromHeader fromHeader = sipLayer.getSipFactory().createHeaderFactory().createFromHeader(fromAddress, !transactionInfo.isAsSender()? transactionInfo.getToTag():transactionInfo.getFromTag()); //to SipURI toSipURI = sipLayer.getSipFactory().createAddressFactory().createSipURI(channelId,device.getHostAddress()); Address toAddress = sipLayer.getSipFactory().createAddressFactory().createAddress(toSipURI); - ToHeader toHeader = sipLayer.getSipFactory().createHeaderFactory().createToHeader(toAddress, transactionInfo.getToTag()); + ToHeader toHeader = sipLayer.getSipFactory().createHeaderFactory().createToHeader(toAddress, !transactionInfo.isAsSender()? transactionInfo.getToTag(): transactionInfo.getFromTag()); //Forwards MaxForwardsHeader maxForwards = sipLayer.getSipFactory().createHeaderFactory().createMaxForwardsHeader(70); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/ByeRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/ByeRequestProcessor.java index 025f3470..202d1c66 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/ByeRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/ByeRequestProcessor.java @@ -204,28 +204,33 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In // case download: // break; case broadcast: - String deviceId = ssrcTransaction.getDeviceId(); String channelId1 = ssrcTransaction.getChannelId(); - Device deviceFromTransaction = storager.queryVideoDevice(deviceId); + Device deviceFromTransaction = storager.queryVideoDevice(ssrcTransaction.getDeviceId()); if (deviceFromTransaction == null) { - ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(deviceId); + ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(ssrcTransaction.getDeviceId()); if (parentPlatform != null) { // 来自上级平台的停止对讲 + logger.info("[停止对讲] 来自上级,平台:{}, 通道:{}", ssrcTransaction.getDeviceId(), channelId1); // 释放ssrc - MediaServerItem mediaServerItemFromTransaction = mediaServerService.getOne(ssrcTransaction.getMediaServerId()); - if (mediaServerItemFromTransaction != null) { - mediaServerService.releaseSsrc(mediaServerItemFromTransaction.getId(), ssrcTransaction.getSsrc()); - } streamSession.remove(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId(), ssrcTransaction.getStream()); + if (mediaServerItem != null) { + zlmrtpServerFactory.closeRtpServer(mediaServerItem, ssrcTransaction.getStream()); + } + // 查找来源的对讲设备,发送停止 + Device sourceDevice = storager.queryVideoDeviceByPlatformIdAndChannelId(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId()); + if (sourceDevice != null) { + playService.stopAudioBroadcast(sourceDevice.getDeviceId(), channelId); + } } }else { // 来自设备的停止对讲 + // 如果是来自设备,则听停止推流。 来自上级则停止收流 - AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(deviceId, channelId1); + AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(ssrcTransaction.getDeviceId(), channelId1); if (audioBroadcastCatch != null) { // - SendRtpItem sendRtpItemForBroadcast = redisCatchStorage.querySendRTPServer(deviceId, channelId1, + SendRtpItem sendRtpItemForBroadcast = redisCatchStorage.querySendRTPServer(ssrcTransaction.getDeviceId(), channelId1, audioBroadcastCatch.getStream(), audioBroadcastCatch.getSipTransactionInfo().getCallId()); if (sendRtpItemForBroadcast != null) { MediaServerItem mediaServerItemForBroadcast = mediaServerService.getOne(sendRtpItem.getMediaServerId()); @@ -257,6 +262,7 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In commanderForPlatform.streamByeCmd(parentPlatform, channelId1, transaction.getStream(), transaction.getCallId(), eventResult -> { streamSession.remove(transaction.getDeviceId(), transaction.getChannelId(), transaction.getStream()); }); + audioBroadcastManager.del(transaction.getDeviceId(), channelId1); } catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) { logger.error("[命令发送失败] 向{}发送bye失败", transaction.getDeviceId()); @@ -273,14 +279,13 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In } } - redisCatchStorage.deleteSendRTPServer(deviceId, channelId1, + redisCatchStorage.deleteSendRTPServer(ssrcTransaction.getDeviceId(), channelId1, audioBroadcastCatch.getStream(), audioBroadcastCatch.getSipTransactionInfo().getCallId()); } - - audioBroadcastManager.del(deviceId, channelId1); } } + audioBroadcastManager.del(ssrcTransaction.getDeviceId(), channelId1); break; default: break; diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java index 8d8e011a..68c2f777 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java @@ -1039,6 +1039,7 @@ public class PlayServiceImpl implements IPlayService { @Override public void stopAudioBroadcast(String deviceId, String channelId) { + logger.info("[停止对讲] 设备:{}, 通道:{}", deviceId, channelId); List audioBroadcastCatchList = new ArrayList<>(); if (channelId == null) { audioBroadcastCatchList.addAll(audioBroadcastManager.get(deviceId));