临时提交

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

@@ -7,29 +7,37 @@ import java.util.List;
public interface ISendRtpServerService {
SendRtpInfo createSendRtpInfo(MediaServer mediaServer, String ip, int port, String ssrc, String requesterId,
String deviceId, Integer channelId, boolean isTcp, boolean rtcp);
SendRtpInfo createSendRtpInfo(MediaServer mediaServer, String ip, Integer port, String ssrc, String requesterId,
String deviceId, Integer channelId, Boolean isTcp, Boolean rtcp);
SendRtpInfo createSendRtpInfo(MediaServer mediaServer, String ip, int port, String ssrc, String platformId,
String app, String stream, Integer channelId, boolean tcp, boolean rtcp);
SendRtpInfo createSendRtpInfo(MediaServer mediaServer, String ip, Integer port, String ssrc, String platformId,
String app, String stream, Integer channelId, Boolean tcp, Boolean rtcp);
void update(SendRtpInfo sendRtpItem);
SendRtpInfo queryByChannelId(Integer channelId);
SendRtpInfo queryByChannelId(Integer channelId, String targetId);
SendRtpInfo queryByCallId(String callId);
SendRtpInfo queryByStream(String stream);
List<SendRtpInfo> queryByStream(String stream);
SendRtpInfo queryByStream(String stream, String targetId);
void delete(SendRtpInfo sendRtpInfo);
void deleteByCallId(String callId);
void deleteByStream(String Stream);
void deleteByStream(String Stream, String targetId);
void deleteByChannel(Integer channelId);
void deleteByChannel(Integer channelId, String targetId);
List<SendRtpInfo> queryAll();
boolean isChannelSendingRTP(Integer channelId);
List<SendRtpInfo> queryForPlatform(String platformId);
List<SendRtpInfo> queryByChannelId(int id);
void deleteByStream(String stream);
}

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;
}
}

View File

@@ -13,7 +13,7 @@ public interface IRedisRpcService {
WVPResult stopSendRtp(Integer sendRtpChannelId);
long waitePushStreamOnline(SendRtpInfo sendRtpItem, CommonCallback<String> callback);
long waitePushStreamOnline(SendRtpInfo sendRtpItem, CommonCallback<Integer> callback);
void stopWaitePushStreamOnline(SendRtpInfo sendRtpItem);

View File

@@ -13,6 +13,7 @@ import com.genersoft.iot.vmp.media.event.hook.Hook;
import com.genersoft.iot.vmp.media.event.hook.HookSubscribe;
import com.genersoft.iot.vmp.media.event.hook.HookType;
import com.genersoft.iot.vmp.media.service.IMediaServerService;
import com.genersoft.iot.vmp.service.ISendRtpServerService;
import com.genersoft.iot.vmp.service.redisMsg.IRedisRpcService;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
@@ -25,6 +26,7 @@ import org.springframework.stereotype.Service;
@Service
public class RedisRpcServiceImpl implements IRedisRpcService {
@Autowired
private RedisRpcConfig redisRpcConfig;
@@ -40,10 +42,12 @@ public class RedisRpcServiceImpl implements IRedisRpcService {
@Autowired
private RedisTemplate<Object, Object> redisTemplate;
@Autowired
private IMediaServerService mediaServerService;
@Autowired
private ISendRtpServerService sendRtpServerService;
private RedisRpcRequest buildRequest(String uri, Object param) {
RedisRpcRequest request = new RedisRpcRequest();
request.setFromId(userSetting.getServerId());
@@ -53,7 +57,7 @@ public class RedisRpcServiceImpl implements IRedisRpcService {
}
@Override
public SendRtpInfo getSendRtpItem(String sendRtpItemKey) {
public SendRtpInfo getSendRtpItem(Integer sendRtpItemKey) {
RedisRpcRequest request = buildRequest("getSendRtpItem", sendRtpItemKey);
RedisRpcResponse response = redisRpcConfig.request(request, 10);
if (response.getBody() == null) {
@@ -63,7 +67,7 @@ public class RedisRpcServiceImpl implements IRedisRpcService {
}
@Override
public WVPResult startSendRtp(String sendRtpItemKey, SendRtpInfo sendRtpItem) {
public WVPResult startSendRtp(Integer sendRtpItemKey, SendRtpInfo sendRtpItem) {
log.info("[请求其他WVP] 开始推流wvp{} {}/{}", sendRtpItem.getServerId(), sendRtpItem.getApp(), sendRtpItem.getStream());
RedisRpcRequest request = buildRequest("startSendRtp", sendRtpItemKey);
request.setToId(sendRtpItem.getServerId());
@@ -72,7 +76,7 @@ public class RedisRpcServiceImpl implements IRedisRpcService {
}
@Override
public WVPResult stopSendRtp(String sendRtpItemKey) {
public WVPResult stopSendRtp(Integer sendRtpItemKey) {
SendRtpInfo sendRtpItem = (SendRtpInfo)redisTemplate.opsForValue().get(sendRtpItemKey);
if (sendRtpItem == null) {
log.info("[请求其他WVP] 停止推流, 未找到redis中的发流信息 key{}", sendRtpItemKey);
@@ -86,7 +90,7 @@ public class RedisRpcServiceImpl implements IRedisRpcService {
}
@Override
public long waitePushStreamOnline(SendRtpInfo sendRtpItem, CommonCallback<String> callback) {
public long waitePushStreamOnline(SendRtpInfo sendRtpItem, CommonCallback<Integer> callback) {
log.info("[请求所有WVP监听流上线] {}/{}", sendRtpItem.getApp(), sendRtpItem.getStream());
// 监听流上线。 流上线直接发送sendRtpItem消息给实际的信令处理者
Hook hook = Hook.getInstance(HookType.on_media_arrival, sendRtpItem.getApp(), sendRtpItem.getStream(), null);
@@ -103,9 +107,9 @@ public class RedisRpcServiceImpl implements IRedisRpcService {
sendRtpItem.setMediaServerId(hookData.getMediaServer().getId());
sendRtpItem.setLocalIp(hookData.getMediaServer().getSdpIp());
sendRtpItem.setServerId(userSetting.getServerId());
redisTemplate.opsForValue().set(sendRtpItem.getRedisKey(), sendRtpItem);
sendRtpServerService.update(sendRtpItem);
if (callback != null) {
callback.run(sendRtpItem.getRedisKey());
callback.run(sendRtpItem.getChannelId());
}
hookSubscribe.removeSubscribe(hook);
redisRpcConfig.removeCallback(request.getSn());
@@ -119,7 +123,7 @@ public class RedisRpcServiceImpl implements IRedisRpcService {
log.info("[请求所有WVP监听流上线] 流上线 {}/{}->{}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.toString());
if (callback != null) {
callback.run(response.getBody().toString());
callback.run(Integer.parseInt(response.getBody().toString()));
}
hookSubscribe.removeSubscribe(hook);
});
@@ -137,7 +141,7 @@ public class RedisRpcServiceImpl implements IRedisRpcService {
}
@Override
public void rtpSendStopped(String sendRtpItemKey) {
public void rtpSendStopped(Integer sendRtpItemKey) {
SendRtpInfo sendRtpItem = (SendRtpInfo)redisTemplate.opsForValue().get(sendRtpItemKey);
if (sendRtpItem == null) {
log.info("[停止WVP监听流上线] 未找到redis中的发流信息 key{}", sendRtpItemKey);