From 8198b48abfa59dfd4ab2e9b10996d84fc8402bdf Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Sat, 2 Sep 2023 17:32:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E5=90=88=20ssrc=20=E5=88=B0=20transac?= =?UTF-8?q?tionInfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gb28181/core/sip/dto/SipTransactionInfo.java | 6 ++++++ .../gb28181/service/play/PlayService.java | 16 ++++------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/core/sip/dto/SipTransactionInfo.java b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/core/sip/dto/SipTransactionInfo.java index 34fbdc6..40d856b 100644 --- a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/core/sip/dto/SipTransactionInfo.java +++ b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/core/sip/dto/SipTransactionInfo.java @@ -12,6 +12,7 @@ public class SipTransactionInfo { private String fromTag; private String toTag; private String viaBranch; + private String ssrc; public SipTransactionInfo(SIPResponse response) { this.callId = response.getCallIdHeader().getCallId(); @@ -19,4 +20,9 @@ public class SipTransactionInfo { this.toTag = response.getToTag(); this.viaBranch = response.getTopmostViaHeader().getBranch(); } + + public SipTransactionInfo(SIPResponse response, String ssrc) { + this(response); + this.ssrc = ssrc; + } } diff --git a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/play/PlayService.java b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/play/PlayService.java index 2b3984f..b08b009 100644 --- a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/play/PlayService.java +++ b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/play/PlayService.java @@ -139,14 +139,12 @@ public class PlayService { subscription.request(1); } else if(statusCode>=Response.OK && statusCode < Response.MULTIPLE_CHOICES){ log.info("订阅 {} {} 流媒体服务连接成功, 开始推送视频流", MessageProcessor.Method.INVITE,subscribeKey); - RedisUtil.StringOps.set(key, JsonUtils.toCompressJson(new SipTransactionInfo(item))); - RedisUtil.StringOps.set(CacheUtil.getKey(key,"ssrc"), ssrc); + RedisUtil.StringOps.set(key, JsonUtils.toCompressJson(new SipTransactionInfo(item,ssrc))); result.setResult(JsonResponse.success(videoUrl(streamId))); onComplete(); } else { log.info("订阅 {} {} 连接流媒体服务时出现异常, 终止订阅", MessageProcessor.Method.INVITE,subscribeKey); RedisUtil.KeyOps.delete(key); - RedisUtil.KeyOps.delete(CacheUtil.getKey(key,"ssrc")); result.setResult(JsonResponse.error("连接流媒体服务失败")); ssrcService.releaseSsrc(zlmMediaConfig.getId(), ssrc); onComplete(); @@ -182,7 +180,6 @@ public class PlayService { String streamId = MediaSdpHelper.getStreamId(deviceId,channelId); String key = CacheUtil.getKey(MediaSdpHelper.Action.PLAY.getAction(), deviceId, channelId); - String ssrcKey = CacheUtil.getKey(key,"ssrc"); zlmMediaService.closeRtpServer(new CloseRtpServer(streamId)); SipTransactionInfo transactionInfo = JsonUtils.parse(RedisUtil.StringOps.get(key), SipTransactionInfo.class); if(transactionInfo == null){ @@ -192,9 +189,8 @@ public class PlayService { String senderIp = device.getLocalIp(); sender.send(senderIp, request); - String ssrc = RedisUtil.StringOps.get(ssrcKey); + String ssrc = transactionInfo.getSsrc(); ssrcService.releaseSsrc(zlmMediaConfig.getId(),ssrc); - RedisUtil.KeyOps.delete(ssrcKey); RedisUtil.KeyOps.delete(key); return JsonResponse.success(null); } @@ -265,14 +261,12 @@ public class PlayService { subscription.request(1); } else if(statusCode>=Response.OK && statusCode < Response.MULTIPLE_CHOICES){ log.info("订阅 {} {} 流媒体服务连接成功, 开始推送视频流", MessageProcessor.Method.INVITE,subscribeKey); - RedisUtil.StringOps.set(key, JsonUtils.toCompressJson(new SipTransactionInfo(item))); - RedisUtil.StringOps.set(CacheUtil.getKey(key,"ssrc"), ssrc); + RedisUtil.StringOps.set(key, JsonUtils.toCompressJson(new SipTransactionInfo(item, ssrc))); result.setResult(JsonResponse.success(videoUrl(streamId))); onComplete(); } else { log.info("订阅 {} {} 连接流媒体服务时出现异常, 终止订阅", MessageProcessor.Method.INVITE,subscribeKey); RedisUtil.KeyOps.delete(key); - RedisUtil.KeyOps.delete(CacheUtil.getKey(key,"ssrc")); result.setResult(JsonResponse.error("连接流媒体服务失败")); ssrcService.releaseSsrc(zlmMediaConfig.getId(), ssrc); onComplete(); @@ -310,7 +304,6 @@ public class PlayService { long end = endTime.toInstant().getEpochSecond(); String streamId = MediaSdpHelper.getStreamId(deviceId,channelId,String.valueOf(start), String.valueOf(end)); String key = CacheUtil.getKey(MediaSdpHelper.Action.PLAY_BACK.getAction(), deviceId, channelId); - String ssrcKey = CacheUtil.getKey(key,"ssrc"); zlmMediaService.closeRtpServer(new CloseRtpServer(streamId)); SipTransactionInfo transactionInfo = JsonUtils.parse(RedisUtil.StringOps.get(key), SipTransactionInfo.class); if(transactionInfo == null){ @@ -320,9 +313,8 @@ public class PlayService { String senderIp = device.getLocalIp(); sender.send(senderIp, request); - String ssrc = RedisUtil.StringOps.get(ssrcKey); + String ssrc = transactionInfo.getSsrc(); ssrcService.releaseSsrc(zlmMediaConfig.getId(),ssrc); - RedisUtil.KeyOps.delete(ssrcKey); RedisUtil.KeyOps.delete(key); return JsonResponse.success(null); }