添加播放 ssrc缓存

pull/38/head
lolkt 2020-09-24 18:03:26 +08:00
parent 956fd47ed6
commit 2246ffa187
2 changed files with 42 additions and 3 deletions

View File

@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.gb28181.session; package com.genersoft.iot.vmp.gb28181.session;
import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import javax.sip.ClientTransaction; import javax.sip.ClientTransaction;
@ -16,6 +17,8 @@ public class VideoStreamSessionManager {
private ConcurrentHashMap<String, ClientTransaction> sessionMap = new ConcurrentHashMap<>(); private ConcurrentHashMap<String, ClientTransaction> sessionMap = new ConcurrentHashMap<>();
private ConcurrentHashMap<String, String> deviceSessionMap = new ConcurrentHashMap<>();
public String createPlaySsrc(){ public String createPlaySsrc(){
String ssrc = SsrcUtil.getPlaySsrc(); String ssrc = SsrcUtil.getPlaySsrc();
return ssrc; return ssrc;
@ -33,9 +36,29 @@ public class VideoStreamSessionManager {
public ClientTransaction get(String ssrc){ public ClientTransaction get(String ssrc){
return sessionMap.get(ssrc); return sessionMap.get(ssrc);
} }
public void remove(String ssrc) { public void remove(String ssrc) {
sessionMap.remove(ssrc); sessionMap.remove(ssrc);
SsrcUtil.releaseSsrc(ssrc); SsrcUtil.releaseSsrc(ssrc);
/**
* device-ssr
*/
Collection<String> 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);
}
}

View File

@ -223,7 +223,7 @@ public class SIPCommander implements ISIPCommander {
ClientTransaction transaction = transmitRequest(device, request); ClientTransaction transaction = transmitRequest(device, request);
streamSession.put(ssrc, transaction); streamSession.put(ssrc, transaction);
return ssrc; streamSession.putDevice("0"+device.getDeviceId()+channelId,ssrc); return ssrc;
} catch ( SipException | ParseException | InvalidArgumentException e) { } catch ( SipException | ParseException | InvalidArgumentException e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
@ -271,6 +271,7 @@ public class SIPCommander implements ISIPCommander {
ClientTransaction transaction = transmitRequest(device, request); ClientTransaction transaction = transmitRequest(device, request);
streamSession.put(ssrc, transaction); streamSession.put(ssrc, transaction);
streamSession.putDevice("1"+device.getDeviceId()+channelId,ssrc);
return ssrc; return ssrc;
} catch ( SipException | ParseException | InvalidArgumentException e) { } catch ( SipException | ParseException | InvalidArgumentException e) {
e.printStackTrace(); e.printStackTrace();
@ -553,4 +554,19 @@ public class SIPCommander implements ISIPCommander {
return clientTransaction; 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);
}*/
} }