From 2246ffa187a95f777c293db75add47e855c3e8c6 Mon Sep 17 00:00:00 2001 From: lolkt <969070578@qq.com> Date: Thu, 24 Sep 2020 18:03:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=92=AD=E6=94=BE=20ssrc?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../session/VideoStreamSessionManager.java | 27 +++++++++++++++++-- .../transmit/cmd/impl/SIPCommander.java | 18 ++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java b/src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java index 4a4a538..f0d71d2 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.gb28181.session; +import java.util.Collection; import java.util.concurrent.ConcurrentHashMap; import javax.sip.ClientTransaction; @@ -16,6 +17,8 @@ public class VideoStreamSessionManager { private ConcurrentHashMap sessionMap = new ConcurrentHashMap<>(); + private ConcurrentHashMap deviceSessionMap = new ConcurrentHashMap<>(); + public String createPlaySsrc(){ String ssrc = SsrcUtil.getPlaySsrc(); return ssrc; @@ -33,9 +36,29 @@ public class VideoStreamSessionManager { public ClientTransaction get(String ssrc){ return sessionMap.get(ssrc); } - + public void remove(String ssrc) { sessionMap.remove(ssrc); SsrcUtil.releaseSsrc(ssrc); + + /** + * 停止播放 删除device-ssr关联 + */ + Collection col = deviceSessionMap.values(); + while (true == col.contains(ssrc)) { + col.remove(ssrc); + } + System.out.println(deviceSessionMap); } -} + + public void putDevice(String deviceAndChannel,String ssrc){ + deviceSessionMap.put(deviceAndChannel, ssrc); + } + public String getSsrcByDevice(String deviceAndChannel){ + return deviceSessionMap.get(deviceAndChannel); + } + + public void removeDevice(String deviceAndChannel) { + deviceSessionMap.remove(deviceAndChannel); + } +} \ No newline at end of file diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java index aaf347d..947b9be 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java @@ -223,7 +223,7 @@ public class SIPCommander implements ISIPCommander { ClientTransaction transaction = transmitRequest(device, request); streamSession.put(ssrc, transaction); - return ssrc; + streamSession.putDevice("0"+device.getDeviceId()+channelId,ssrc); return ssrc; } catch ( SipException | ParseException | InvalidArgumentException e) { e.printStackTrace(); return null; @@ -271,6 +271,7 @@ public class SIPCommander implements ISIPCommander { ClientTransaction transaction = transmitRequest(device, request); streamSession.put(ssrc, transaction); + streamSession.putDevice("1"+device.getDeviceId()+channelId,ssrc); return ssrc; } catch ( SipException | ParseException | InvalidArgumentException e) { e.printStackTrace(); @@ -553,4 +554,19 @@ public class SIPCommander implements ISIPCommander { return clientTransaction; } + /** + * 清除缓存的ssrc + * @param ssrc + */ + public void remove(String ssrc){ + streamSession.remove(ssrc); + } + + + public String getPlaySsrcByDevice(String deviceId,String channelId){ + return streamSession.getSsrcByDevice("0"+deviceId+channelId); + } + /*public String getPlaybackSsrcByDevice(String deviceId,String channelId){ + return streamSession.getSsrcByDevice("1"+deviceId+channelId); + }*/ }