解决单端口兼容宇视平台

This commit is contained in:
smy 2024-04-17 17:31:59 +08:00
parent 3cd3e97cd7
commit 24c3f459f2
3 changed files with 73 additions and 10 deletions

View File

@ -14,6 +14,11 @@ public interface IInviteStreamService {
*/ */
void updateInviteInfo(InviteInfo inviteInfo); void updateInviteInfo(InviteInfo inviteInfo);
/**
* 新增点播的状态信息
*/
void insertInviteInfo(InviteInfo inviteInfo);
InviteInfo updateInviteInfoForStream(InviteInfo inviteInfo, String stream); InviteInfo updateInviteInfoForStream(InviteInfo inviteInfo, String stream);
/** /**
@ -31,6 +36,16 @@ public interface IInviteStreamService {
String deviceId, String deviceId,
String channelId, String channelId,
String stream); String stream);
/**
* 移除点播的状态信息
*/
void removeInviteInfo(InviteSessionType type,
String deviceId,
String channelId,
String stream,
String ssrc);
/** /**
* 移除点播的状态信息 * 移除点播的状态信息
*/ */

View File

@ -121,6 +121,23 @@ public class InviteStreamServiceImpl implements IInviteStreamService {
redisTemplate.opsForValue().set(key, inviteInfoForUpdate); redisTemplate.opsForValue().set(key, inviteInfoForUpdate);
} }
@Override
public void insertInviteInfo(InviteInfo inviteInfo) {
if (inviteInfo == null || (inviteInfo.getDeviceId() == null || inviteInfo.getChannelId() == null)) {
logger.warn("[更新Invite信息],参数不全: {}", JSON.toJSON(inviteInfo));
return;
}
InviteInfo inviteInfoForUpdate = inviteInfo;
String key = VideoManagerConstants.INVITE_PREFIX +
":" + inviteInfoForUpdate.getType() +
":" + inviteInfoForUpdate.getDeviceId() +
":" + inviteInfoForUpdate.getChannelId() +
":" + inviteInfoForUpdate.getStream()+
":" + inviteInfoForUpdate.getSsrcInfo().getSsrc();
redisTemplate.opsForValue().set(key, inviteInfoForUpdate);
}
@Override @Override
public InviteInfo updateInviteInfoForStream(InviteInfo inviteInfo, String stream) { public InviteInfo updateInviteInfoForStream(InviteInfo inviteInfo, String stream) {
@ -194,6 +211,19 @@ public class InviteStreamServiceImpl implements IInviteStreamService {
} }
} }
@Override
public void removeInviteInfo(InviteSessionType type, String deviceId, String channelId, String stream, String ssrc) {
String key = VideoManagerConstants.INVITE_PREFIX +
":" + (type != null ? type : "*") +
":" + (deviceId != null ? deviceId : "*") +
":" + (channelId != null ? channelId : "*") +
":" + (stream != null ? stream : "*") +
":" + (ssrc != null ? ssrc : "*");
logger.warn("删除指定key:{}", key);
redisTemplate.delete(key);
}
@Override @Override
public void removeInviteInfoByDeviceAndChannel(InviteSessionType inviteSessionType, String deviceId, String channelId) { public void removeInviteInfoByDeviceAndChannel(InviteSessionType inviteSessionType, String deviceId, String channelId) {
removeInviteInfo(inviteSessionType, deviceId, channelId, null); removeInviteInfo(inviteSessionType, deviceId, channelId, null);

View File

@ -921,17 +921,35 @@ public class PlayServiceImpl implements IPlayService {
} }
} }
}else { }else {
if (ssrcInResponse != null) { //1.将ssrc释放回队列
// 单端口 mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
// 重新订阅流上线 //2.redis中获取此ssrc的数据
SsrcTransaction ssrcTransaction = streamSession.getSsrcTransaction(inviteInfo.getDeviceId(), InviteInfo inviteInfoBySSRC = inviteStreamService.getInviteInfoBySSRC(ssrcInfo.getSsrc());
inviteInfo.getChannelId(), null, inviteInfo.getStream()); //3.如果redis中有此数据则删除+替换ssrc
streamSession.remove(inviteInfo.getDeviceId(), if(inviteInfoBySSRC != null){
inviteInfo.getChannelId(), inviteInfo.getStream()); //删除
inviteStreamService.updateInviteInfoForSSRC(inviteInfo, ssrcInResponse); inviteStreamService.removeInviteInfo(
streamSession.put(device.getDeviceId(), channelId, ssrcTransaction.getCallId(), InviteSessionType.PLAY,
inviteInfo.getStream(), ssrcInResponse, mediaServerItem.getId(), (SIPResponse) responseEvent.getResponse(), inviteSessionType); inviteInfoBySSRC.getDeviceId(),
inviteInfoBySSRC.getChannelId(),
inviteInfoBySSRC.getStream(),
ssrcInfo.getSsrc());
//添加
ssrcInfo.setSsrc(ssrcInResponse);
inviteInfo.setSsrcInfo(ssrcInfo);
inviteInfo.setStream(ssrcInfo.getStream());
inviteStreamService.insertInviteInfo(inviteInfoBySSRC);
} }
// 单端口
// 重新订阅流上线
SsrcTransaction ssrcTransaction = streamSession.getSsrcTransaction(inviteInfo.getDeviceId(),
inviteInfo.getChannelId(), null, inviteInfo.getStream());
streamSession.remove(inviteInfo.getDeviceId(),
inviteInfo.getChannelId(), inviteInfo.getStream());
inviteStreamService.updateInviteInfoForSSRC(inviteInfo, ssrcInResponse);
streamSession.put(device.getDeviceId(), channelId, ssrcTransaction.getCallId(),
inviteInfo.getStream(), ssrcInResponse, mediaServerItem.getId(), (SIPResponse) responseEvent.getResponse(), inviteSessionType);
} }
} }
} }