From 983c7c351f3790d0effe2894ce435552ff0f2feb Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期四, 17 八月 2023 14:20:04 +0800 Subject: [PATCH] 优化对讲释放流程 --- src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/ByeRequestProcessor.java | 99 ++++++++++++++++++++++++++++--------------------- 1 files changed, 57 insertions(+), 42 deletions(-) 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 304830e..34dce99 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 @@ -113,6 +113,7 @@ CallIdHeader callIdHeader = (CallIdHeader)evt.getRequest().getHeader(CallIdHeader.NAME); SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(null, null, null, callIdHeader.getCallId()); + // 鏀舵祦绔彂閫佺殑鍋滄 if (sendRtpItem != null){ logger.info("[鏀跺埌bye] 鏉ヨ嚜{}锛屽仠姝㈤�氶亾锛歿}, 绫诲瀷锛� {}", sendRtpItem.getPlatformId(), sendRtpItem.getChannelId(), sendRtpItem.getPlayType()); @@ -139,6 +140,7 @@ logger.info("[涓婄骇骞冲彴鍋滄瑙傜湅] 鏈壘鍒板钩鍙皗}鐨勪俊鎭紝鍙戦�乺edis娑堟伅澶辫触", sendRtpItem.getPlatformId()); } } + AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(sendRtpItem.getDeviceId(), sendRtpItem.getChannelId()); if (audioBroadcastCatch != null && audioBroadcastCatch.getSipTransactionInfo().getCallId().equals(callIdHeader.getCallId())) { // 鏉ヨ嚜涓婄骇骞冲彴鐨勫仠姝㈠璁� @@ -165,54 +167,67 @@ } } - // 鍙兘鏄澶囧彂閫佺殑鍋滄 - SsrcTransaction ssrcTransaction = streamSession.getSsrcTransaction(null, null, callIdHeader.getCallId(), null); - if (ssrcTransaction == null && sendRtpItem == null) { - logger.info("[鏀跺埌bye] 浣嗘槸鏃犳硶鑾峰彇鎺ㄦ祦淇℃伅鍜屽彂娴佷俊鎭紝蹇界暐姝よ姹�"); - logger.info(request.toString()); - return; - } - if (ssrcTransaction != null) { - logger.info("[鏀跺埌bye] 鏉ヨ嚜璁惧锛歿}, 閫氶亾宸插仠姝㈡帹娴�: {}", ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId()); + // 鍙戞祦绔彂閫佺殑鍋滄 + SsrcTransaction ssrcTransaction = streamSession.getSsrcTransaction(null, null, callIdHeader.getCallId(), null); + if (ssrcTransaction == null ) { + logger.info("[鏀跺埌bye] 浣嗘槸鏃犳硶鑾峰彇鎺ㄦ祦淇℃伅鍜屽彂娴佷俊鎭紝蹇界暐姝よ姹�"); + logger.info(request.toString()); + return; + } - Device device = deviceService.getDevice(ssrcTransaction.getDeviceId()); - if (device == null) { - logger.info("[鏀跺埌bye] 鏈壘鍒拌澶囷細{} ", ssrcTransaction.getDeviceId()); - return; - } - DeviceChannel channel = channelService.getOne(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId()); + + ParentPlatform platform = platformService.queryPlatformByServerGBId(ssrcTransaction.getDeviceId()); + if (platform != null ) { + if (ssrcTransaction.getType().equals(InviteSessionType.BROADCAST)) { + logger.info("[鏀跺埌bye] 涓婄骇鍋滄璇煶瀵硅锛屾潵鑷細{}, 閫氶亾宸插仠姝㈡帹娴�: {}", ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId()); + DeviceChannel channel = storager.queryChannelInParentPlatform(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId()); if (channel == null) { logger.info("[鏀跺埌bye] 鏈壘鍒伴�氶亾锛岃澶囷細{}锛� 閫氶亾锛歿}", ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId()); return; } - storager.stopPlay(device.getDeviceId(), channel.getChannelId()); - InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channel.getChannelId()); - if (inviteInfo != null) { - inviteStreamService.removeInviteInfo(inviteInfo); - if (inviteInfo.getStreamInfo() != null) { - mediaServerService.closeRTPServer(inviteInfo.getStreamInfo().getMediaServerId(), inviteInfo.getStreamInfo().getStream()); - } - } - // 閲婃斁ssrc - MediaServerItem mediaServerItem = mediaServerService.getOne(ssrcTransaction.getMediaServerId()); - if (mediaServerItem != null) { - mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcTransaction.getSsrc()); - } - streamSession.remove(device.getDeviceId(), channel.getChannelId(), ssrcTransaction.getStream()); - if (ssrcTransaction.getType() == InviteSessionType.BROADCAST) { - // 鏌ユ壘鏉ユ簮鐨勫璁茶澶囷紝鍙戦�佸仠姝� - Device sourceDevice = storager.queryVideoDeviceByPlatformIdAndChannelId(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId()); - if (sourceDevice != null) { - playService.stopAudioBroadcast(sourceDevice.getDeviceId(), channel.getChannelId()); - } - } - AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(ssrcTransaction.getDeviceId(), channel.getChannelId()); - if (audioBroadcastCatch != null) { - // 鏉ヨ嚜涓婄骇骞冲彴鐨勫仠姝㈠璁� - logger.info("[鍋滄瀵硅] 鏉ヨ嚜涓婄骇锛屽钩鍙帮細{}, 閫氶亾锛歿}", ssrcTransaction.getDeviceId(), channel.getChannelId()); - audioBroadcastManager.del(ssrcTransaction.getDeviceId(), channel.getChannelId()); - } + String mediaServerId = ssrcTransaction.getMediaServerId(); + platformService.stopBroadcast(platform, channel, ssrcTransaction.getStream(), false, + mediaServerService.getOne(mediaServerId)); } + }else { + Device device = deviceService.getDevice(ssrcTransaction.getDeviceId()); + if (device == null) { + logger.info("[鏀跺埌bye] 鏈壘鍒拌澶囷細{} ", ssrcTransaction.getDeviceId()); + return; + } + DeviceChannel channel = channelService.getOne(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId()); + if (channel == null) { + logger.info("[鏀跺埌bye] 鏈壘鍒伴�氶亾锛岃澶囷細{}锛� 閫氶亾锛歿}", ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId()); + return; + } + storager.stopPlay(device.getDeviceId(), channel.getChannelId()); + InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channel.getChannelId()); + if (inviteInfo != null) { + inviteStreamService.removeInviteInfo(inviteInfo); + if (inviteInfo.getStreamInfo() != null) { + mediaServerService.closeRTPServer(inviteInfo.getStreamInfo().getMediaServerId(), inviteInfo.getStreamInfo().getStream()); + } + } + // 閲婃斁ssrc + MediaServerItem mediaServerItem = mediaServerService.getOne(ssrcTransaction.getMediaServerId()); + if (mediaServerItem != null) { + mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcTransaction.getSsrc()); + } + streamSession.remove(device.getDeviceId(), channel.getChannelId(), ssrcTransaction.getStream()); + if (ssrcTransaction.getType() == InviteSessionType.BROADCAST) { + // 鏌ユ壘鏉ユ簮鐨勫璁茶澶囷紝鍙戦�佸仠姝� + Device sourceDevice = storager.queryVideoDeviceByPlatformIdAndChannelId(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId()); + if (sourceDevice != null) { + playService.stopAudioBroadcast(sourceDevice.getDeviceId(), channel.getChannelId()); + } + } + AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(ssrcTransaction.getDeviceId(), channel.getChannelId()); + if (audioBroadcastCatch != null) { + // 鏉ヨ嚜涓婄骇骞冲彴鐨勫仠姝㈠璁� + logger.info("[鍋滄瀵硅] 鏉ヨ嚜涓婄骇锛屽钩鍙帮細{}, 閫氶亾锛歿}", ssrcTransaction.getDeviceId(), channel.getChannelId()); + audioBroadcastManager.del(ssrcTransaction.getDeviceId(), channel.getChannelId()); + } + } } } -- Gitblit v1.8.0