diff --git a/src/main/java/com/genersoft/iot/vmp/service/IInviteStreamService.java b/src/main/java/com/genersoft/iot/vmp/service/IInviteStreamService.java index c06400dce..f8c0c8a57 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/IInviteStreamService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IInviteStreamService.java @@ -14,6 +14,11 @@ public interface IInviteStreamService { */ void updateInviteInfo(InviteInfo inviteInfo); + /** + * 新增点播的状态信息 + */ + void insertInviteInfo(InviteInfo inviteInfo); + InviteInfo updateInviteInfoForStream(InviteInfo inviteInfo, String stream); /** @@ -31,6 +36,16 @@ public interface IInviteStreamService { String deviceId, String channelId, String stream); + + /** + * 移除点播的状态信息 + */ + void removeInviteInfo(InviteSessionType type, + String deviceId, + String channelId, + String stream, + String ssrc); + /** * 移除点播的状态信息 */ diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java index 6e0096099..c9efc5b9a 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java @@ -121,6 +121,23 @@ public class InviteStreamServiceImpl implements IInviteStreamService { 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 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 public void removeInviteInfoByDeviceAndChannel(InviteSessionType inviteSessionType, String deviceId, String channelId) { removeInviteInfo(inviteSessionType, deviceId, channelId, null); diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java index 40de0d2ee..641057ce0 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java @@ -921,17 +921,35 @@ public class PlayServiceImpl implements IPlayService { } } }else { - if (ssrcInResponse != null) { - // 单端口 - // 重新订阅流上线 - 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); + //1.将ssrc释放回队列 + mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); + //2.redis中获取此ssrc的数据 + InviteInfo inviteInfoBySSRC = inviteStreamService.getInviteInfoBySSRC(ssrcInfo.getSsrc()); + //3.如果redis中有此数据则删除+替换ssrc + if(inviteInfoBySSRC != null){ + //删除 + inviteStreamService.removeInviteInfo( + InviteSessionType.PLAY, + 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); } } }