完善语音对讲级联

结构优化
648540858 2023-03-21 15:55:24 +08:00
parent 455e58f866
commit 82adc0cb23
3 changed files with 20 additions and 14 deletions

View File

@ -170,11 +170,11 @@ public class SIPRequestHeaderProvider {
//from //from
SipURI fromSipURI = sipLayer.getSipFactory().createAddressFactory().createSipURI(sipConfig.getId(),sipConfig.getDomain()); SipURI fromSipURI = sipLayer.getSipFactory().createAddressFactory().createSipURI(sipConfig.getId(),sipConfig.getDomain());
Address fromAddress = sipLayer.getSipFactory().createAddressFactory().createAddress(fromSipURI); 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 //to
SipURI toSipURI = sipLayer.getSipFactory().createAddressFactory().createSipURI(channelId,device.getHostAddress()); SipURI toSipURI = sipLayer.getSipFactory().createAddressFactory().createSipURI(channelId,device.getHostAddress());
Address toAddress = sipLayer.getSipFactory().createAddressFactory().createAddress(toSipURI); 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 //Forwards
MaxForwardsHeader maxForwards = sipLayer.getSipFactory().createHeaderFactory().createMaxForwardsHeader(70); MaxForwardsHeader maxForwards = sipLayer.getSipFactory().createHeaderFactory().createMaxForwardsHeader(70);

View File

@ -204,28 +204,33 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In
// case download: // case download:
// break; // break;
case broadcast: case broadcast:
String deviceId = ssrcTransaction.getDeviceId();
String channelId1 = ssrcTransaction.getChannelId(); String channelId1 = ssrcTransaction.getChannelId();
Device deviceFromTransaction = storager.queryVideoDevice(deviceId); Device deviceFromTransaction = storager.queryVideoDevice(ssrcTransaction.getDeviceId());
if (deviceFromTransaction == null) { if (deviceFromTransaction == null) {
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(deviceId); ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(ssrcTransaction.getDeviceId());
if (parentPlatform != null) { if (parentPlatform != null) {
// 来自上级平台的停止对讲 // 来自上级平台的停止对讲
logger.info("[停止对讲] 来自上级,平台:{}, 通道:{}", ssrcTransaction.getDeviceId(), channelId1);
// 释放ssrc // 释放ssrc
MediaServerItem mediaServerItemFromTransaction = mediaServerService.getOne(ssrcTransaction.getMediaServerId());
if (mediaServerItemFromTransaction != null) {
mediaServerService.releaseSsrc(mediaServerItemFromTransaction.getId(), ssrcTransaction.getSsrc());
}
streamSession.remove(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId(), ssrcTransaction.getStream()); 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 { }else {
// 来自设备的停止对讲 // 来自设备的停止对讲
// 如果是来自设备,则听停止推流。 来自上级则停止收流 // 如果是来自设备,则听停止推流。 来自上级则停止收流
AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(deviceId, channelId1); AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(ssrcTransaction.getDeviceId(), channelId1);
if (audioBroadcastCatch != null) { if (audioBroadcastCatch != null) {
// //
SendRtpItem sendRtpItemForBroadcast = redisCatchStorage.querySendRTPServer(deviceId, channelId1, SendRtpItem sendRtpItemForBroadcast = redisCatchStorage.querySendRTPServer(ssrcTransaction.getDeviceId(), channelId1,
audioBroadcastCatch.getStream(), audioBroadcastCatch.getSipTransactionInfo().getCallId()); audioBroadcastCatch.getStream(), audioBroadcastCatch.getSipTransactionInfo().getCallId());
if (sendRtpItemForBroadcast != null) { if (sendRtpItemForBroadcast != null) {
MediaServerItem mediaServerItemForBroadcast = mediaServerService.getOne(sendRtpItem.getMediaServerId()); 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 -> { commanderForPlatform.streamByeCmd(parentPlatform, channelId1, transaction.getStream(), transaction.getCallId(), eventResult -> {
streamSession.remove(transaction.getDeviceId(), transaction.getChannelId(), transaction.getStream()); streamSession.remove(transaction.getDeviceId(), transaction.getChannelId(), transaction.getStream());
}); });
audioBroadcastManager.del(transaction.getDeviceId(), channelId1);
} catch (InvalidArgumentException | SipException | ParseException | } catch (InvalidArgumentException | SipException | ParseException |
SsrcTransactionNotFoundException e) { SsrcTransactionNotFoundException e) {
logger.error("[命令发送失败] 向{}发送bye失败", transaction.getDeviceId()); 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()); audioBroadcastCatch.getStream(), audioBroadcastCatch.getSipTransactionInfo().getCallId());
} }
audioBroadcastManager.del(deviceId, channelId1);
} }
} }
audioBroadcastManager.del(ssrcTransaction.getDeviceId(), channelId1);
break; break;
default: default:
break; break;

View File

@ -1039,6 +1039,7 @@ public class PlayServiceImpl implements IPlayService {
@Override @Override
public void stopAudioBroadcast(String deviceId, String channelId) { public void stopAudioBroadcast(String deviceId, String channelId) {
logger.info("[停止对讲] 设备:{}, 通道:{}", deviceId, channelId);
List<AudioBroadcastCatch> audioBroadcastCatchList = new ArrayList<>(); List<AudioBroadcastCatch> audioBroadcastCatchList = new ArrayList<>();
if (channelId == null) { if (channelId == null) {
audioBroadcastCatchList.addAll(audioBroadcastManager.get(deviceId)); audioBroadcastCatchList.addAll(audioBroadcastManager.get(deviceId));