临时提交

This commit is contained in:
648540858
2024-09-09 11:16:02 +08:00
parent 489fbe31a5
commit 2e90344c89
16 changed files with 271 additions and 265 deletions

View File

@@ -15,6 +15,7 @@ import com.genersoft.iot.vmp.media.bean.MediaServer;
import com.genersoft.iot.vmp.media.bean.ResultForOnPublish;
import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
import com.genersoft.iot.vmp.service.IMediaService;
import com.genersoft.iot.vmp.service.ISendRtpServerService;
import com.genersoft.iot.vmp.service.IUserService;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.streamProxy.bean.StreamProxy;
@@ -78,6 +79,9 @@ public class MediaServiceImpl implements IMediaService {
@Autowired
private ISIPCommander commander;
@Autowired
private ISendRtpServerService sendRtpServerService;
@Override
public boolean authenticatePlay(String app, String stream, String callId) {
if (app == null || stream == null) {
@@ -234,11 +238,11 @@ public class MediaServiceImpl implements IMediaService {
return false;
}
// 收到无人观看说明流也没有在往上级推送
if (redisCatchStorage.isChannelSendingRTP(deviceChannel.getDeviceId())) {
List<SendRtpInfo> sendRtpItems = redisCatchStorage.querySendRTPServerByChannelId(deviceChannel.getDeviceId());
if (sendRtpServerService.isChannelSendingRTP(deviceChannel.getId())) {
List<SendRtpInfo> sendRtpItems = sendRtpServerService.queryByChannelId(deviceChannel.getId());
if (!sendRtpItems.isEmpty()) {
for (SendRtpInfo sendRtpItem : sendRtpItems) {
Platform parentPlatform = platformService.queryPlatformByServerGBId(sendRtpItem.getPlatformId());
Platform parentPlatform = platformService.queryPlatformByServerGBId(sendRtpItem.getTargetId());
CommonGBChannel channel = channelService.getOne(sendRtpItem.getChannelId());
if (channel == null) {
continue;
@@ -248,8 +252,7 @@ public class MediaServiceImpl implements IMediaService {
} catch (SipException | InvalidArgumentException | ParseException e) {
log.error("[命令发送失败] 国标级联 发送BYE: {}", e.getMessage());
}
redisCatchStorage.deleteSendRTPServer(parentPlatform.getServerGBId(), channel.getGbDeviceId(),
sendRtpItem.getCallId(), sendRtpItem.getStream());
sendRtpServerService.delete(sendRtpItem);
if (InviteStreamType.PUSH == sendRtpItem.getPlayType()) {
redisCatchStorage.sendPlatformStopPlayMsg(sendRtpItem, parentPlatform, channel);
redisCatchStorage.sendPlatformStopPlayMsg(sendRtpItem, parentPlatform, channel);
@@ -280,8 +283,8 @@ public class MediaServiceImpl implements IMediaService {
deviceChannelService.stopPlay(inviteInfo.getChannelId());
return result;
}
SendRtpInfo sendRtpItem = redisCatchStorage.querySendRTPServer(null, null, stream, null);
if (sendRtpItem != null && "talk".equals(sendRtpItem.getApp())) {
List<SendRtpInfo> sendRtpItemList = sendRtpServerService.queryByStream(stream);
if (!sendRtpItemList.isEmpty()) {
return false;
}
} else if ("talk".equals(app) || "broadcast".equals(app)) {

View File

@@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.common.VideoManagerConstants;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.PlayException;
import com.genersoft.iot.vmp.gb28181.bean.SendRtpInfo;
import com.genersoft.iot.vmp.gb28181.conf.StackLoggerImpl;
import com.genersoft.iot.vmp.media.bean.MediaServer;
import com.genersoft.iot.vmp.media.zlm.SendRtpPortManager;
import com.genersoft.iot.vmp.service.ISendRtpServerService;
@@ -29,10 +30,12 @@ public class SendRtpServerServiceImpl implements ISendRtpServerService {
@Autowired
private RedisTemplate<Object, Object> redisTemplate;
@Autowired
private StackLoggerImpl stackLoggerImpl;
@Override
public SendRtpInfo createSendRtpInfo(MediaServer mediaServer, String ip, int port, String ssrc, String requesterId,
String deviceId, Integer channelId, boolean isTcp, boolean rtcp) {
public SendRtpInfo createSendRtpInfo(MediaServer mediaServer, String ip, Integer port, String ssrc, String requesterId,
String deviceId, Integer channelId, Boolean isTcp, Boolean rtcp) {
int localPort = sendRtpPortManager.getNextPort(mediaServer);
if (localPort == 0) {
return null;
@@ -42,8 +45,8 @@ public class SendRtpServerServiceImpl implements ISendRtpServerService {
}
@Override
public SendRtpInfo createSendRtpInfo(MediaServer mediaServer, String ip, int port, String ssrc, String platformId,
String app, String stream, Integer channelId, boolean tcp, boolean rtcp){
public SendRtpInfo createSendRtpInfo(MediaServer mediaServer, String ip, Integer port, String ssrc, String platformId,
String app, String stream, Integer channelId, Boolean tcp, Boolean rtcp){
int localPort = sendRtpPortManager.getNextPort(mediaServer);
if (localPort <= 0) {
@@ -56,13 +59,13 @@ public class SendRtpServerServiceImpl implements ISendRtpServerService {
@Override
public void update(SendRtpInfo sendRtpItem) {
redisTemplate.opsForValue().set(VideoManagerConstants.SEND_RTP_INFO_CALLID + sendRtpItem.getCallId(), sendRtpItem);
redisTemplate.opsForValue().set(VideoManagerConstants.SEND_RTP_INFO_STREAM + sendRtpItem.getStream(), sendRtpItem);
redisTemplate.opsForValue().set(VideoManagerConstants.SEND_RTP_INFO_CHANNEL + sendRtpItem.getChannelId(), sendRtpItem);
redisTemplate.opsForValue().set(VideoManagerConstants.SEND_RTP_INFO_STREAM + sendRtpItem.getStream() + ":" + sendRtpItem.getTargetId(), sendRtpItem);
redisTemplate.opsForValue().set(VideoManagerConstants.SEND_RTP_INFO_CHANNEL + sendRtpItem.getChannelId() + ":" + sendRtpItem.getTargetId(), sendRtpItem);
}
@Override
public SendRtpInfo queryByChannelId(Integer channelId) {
String key = VideoManagerConstants.SEND_RTP_INFO_CHANNEL + channelId;
public SendRtpInfo queryByChannelId(Integer channelId, String targetId) {
String key = VideoManagerConstants.SEND_RTP_INFO_CHANNEL + channelId + ":" + targetId;
return JsonUtil.redisJsonToObject(redisTemplate, key, SendRtpInfo.class);
}
@@ -74,10 +77,24 @@ public class SendRtpServerServiceImpl implements ISendRtpServerService {
@Override
public SendRtpInfo queryByStream(String stream, String targetId) {
String key = VideoManagerConstants.SEND_RTP_INFO_STREAM + stream;
String key = VideoManagerConstants.SEND_RTP_INFO_STREAM + stream + ":" + targetId;
return JsonUtil.redisJsonToObject(redisTemplate, key, SendRtpInfo.class);
}
@Override
public List<SendRtpInfo> queryByStream(String stream) {
String key = VideoManagerConstants.SEND_RTP_INFO_STREAM + stream + ":*";
List<Object> queryResult = RedisUtil.scan(redisTemplate, key);
List<SendRtpInfo> result= new ArrayList<>();
for (Object o : queryResult) {
String keyItem = (String) o;
result.add((SendRtpInfo) redisTemplate.opsForValue().get(keyItem));
}
return result;
}
/**
* 删除RTP推送信息缓存
*/
@@ -87,8 +104,8 @@ public class SendRtpServerServiceImpl implements ISendRtpServerService {
return;
}
redisTemplate.delete(VideoManagerConstants.SEND_RTP_INFO_CALLID + sendRtpInfo.getCallId());
redisTemplate.delete(VideoManagerConstants.SEND_RTP_INFO_STREAM + sendRtpInfo.getStream());
redisTemplate.delete(VideoManagerConstants.SEND_RTP_INFO_CHANNEL + sendRtpInfo.getChannelId());
redisTemplate.delete(VideoManagerConstants.SEND_RTP_INFO_STREAM + sendRtpInfo.getStream() + ":" + sendRtpInfo.getTargetId());
redisTemplate.delete(VideoManagerConstants.SEND_RTP_INFO_CHANNEL + sendRtpInfo.getChannelId() + ":" + sendRtpInfo.getTargetId());
}
@Override
public void deleteByCallId(String callId) {
@@ -99,22 +116,45 @@ public class SendRtpServerServiceImpl implements ISendRtpServerService {
delete(sendRtpInfo);
}
@Override
public void deleteByStream(String Stream) {
SendRtpInfo sendRtpInfo = queryByStream(Stream);
public void deleteByStream(String stream, String targetId) {
SendRtpInfo sendRtpInfo = queryByStream(stream, targetId);
if (sendRtpInfo == null) {
return;
}
delete(sendRtpInfo);
}
@Override
public void deleteByChannel(Integer channelId) {
SendRtpInfo sendRtpInfo = queryByChannelId(channelId);
public void deleteByStream(String stream) {
List<SendRtpInfo> sendRtpInfos = queryByStream(stream);
for (SendRtpInfo sendRtpInfo : sendRtpInfos) {
delete(sendRtpInfo);
}
}
@Override
public void deleteByChannel(Integer channelId, String targetId) {
SendRtpInfo sendRtpInfo = queryByChannelId(channelId, targetId);
if (sendRtpInfo == null) {
return;
}
delete(sendRtpInfo);
}
@Override
public List<SendRtpInfo> queryByChannelId(int channelId) {
String key = VideoManagerConstants.SEND_RTP_INFO_CHANNEL + channelId + ":*";
List<Object> queryResult = RedisUtil.scan(redisTemplate, key);
List<SendRtpInfo> result= new ArrayList<>();
for (Object o : queryResult) {
String keyItem = (String) o;
result.add((SendRtpInfo) redisTemplate.opsForValue().get(keyItem));
}
return result;
}
@Override
public List<SendRtpInfo> queryAll() {
String key = VideoManagerConstants.SEND_RTP_INFO_CALLID
@@ -135,8 +175,16 @@ public class SendRtpServerServiceImpl implements ISendRtpServerService {
*/
@Override
public boolean isChannelSendingRTP(Integer channelId) {
SendRtpInfo sendRtpInfo = queryByChannelId(channelId);
return sendRtpInfo != null;
List<SendRtpInfo> sendRtpInfoList = queryByChannelId(channelId);
return !sendRtpInfoList.isEmpty();
}
@Override
public List<SendRtpInfo> queryForPlatform(String platformId) {
List<SendRtpInfo> sendRtpInfos = queryAll();
if (!sendRtpInfos.isEmpty()) {
sendRtpInfos.removeIf(sendRtpInfo -> !sendRtpInfo.isSendToPlatform() || !sendRtpInfo.getTargetId().equals(platformId));
}
return sendRtpInfos;
}
}