添加重启后拉流代理自动恢复

This commit is contained in:
648540858
2022-01-27 18:08:19 +08:00
parent 66cadafd1c
commit f33c3a3630
12 changed files with 90 additions and 16 deletions

View File

@@ -55,6 +55,16 @@ public interface IStreamProxyService {
*/
boolean start(String app, String stream);
/**
* 更新状态
* @param status 状态
* @param app
* @param stream
*/
int updateStatus(boolean status, String app, String stream);
/**
* 停用用视频代理
* @param app

View File

@@ -14,8 +14,11 @@ import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
import com.genersoft.iot.vmp.service.IMediaServerService;
import com.genersoft.iot.vmp.service.IStreamProxyService;
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
import com.genersoft.iot.vmp.storager.dao.MediaServerMapper;
import com.genersoft.iot.vmp.utils.redis.JedisUtil;
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
@@ -70,6 +73,12 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
@Autowired
private RedisUtil redisUtil;
@Autowired
private IVideoManagerStorager storager;
@Autowired
private IStreamProxyService streamProxyService;
@Autowired
private EventPublisher publisher;
@@ -231,6 +240,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
public List<MediaServerItem> getAllOnline() {
String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetup.getServerId();
Set<String> mediaServerIdSet = redisUtil.zRevRange(key, 0, -1);
List<MediaServerItem> result = new ArrayList<>();
if (mediaServerIdSet != null && mediaServerIdSet.size() > 0) {
for (String mediaServerId : mediaServerIdSet) {
@@ -238,6 +248,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
result.add((MediaServerItem) redisUtil.get(serverKey));
}
}
Collections.reverse(result);
return result;
}
@@ -374,6 +385,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
resetOnlineServerItem(serverItem);
updateMediaServerKeepalive(serverItem.getId(), null);
setZLMConfig(serverItem, "0".equals(zlmServerConfig.getHookEnable()));
publisher.zlmOnlineEventPublish(serverItem.getId());
}

View File

@@ -58,6 +58,9 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
@Autowired
private IRedisCatchStorage redisCatchStorage;
@Autowired
private IVideoManagerStorager storager;
@Autowired
private UserSetup userSetup;
@@ -278,7 +281,27 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
@Override
public void zlmServerOnline(String mediaServerId) {
zlmServerOffline(mediaServerId);
// 移除开启了无人观看自动移除的流
List<StreamProxyItem> streamProxyItemList = streamProxyMapper.selecAutoRemoveItemByMediaServerId(mediaServerId);
if (streamProxyItemList.size() > 0) {
gbStreamMapper.batchDel(streamProxyItemList);
}
streamProxyMapper.deleteAutoRemoveItemByMediaServerId(mediaServerId);
// 恢复流代理, 只查找这个这个流媒体
List<StreamProxyItem> streamProxyListForEnable = storager.getStreamProxyListForEnableInMediaServer(
mediaServerId, true, false);
for (StreamProxyItem streamProxyDto : streamProxyListForEnable) {
logger.info("恢复流代理," + streamProxyDto.getApp() + "/" + streamProxyDto.getStream());
JSONObject jsonObject = addStreamProxyToZlm(streamProxyDto);
if (jsonObject == null) {
// 设置为离线
logger.info("恢复流代理失败" + streamProxyDto.getApp() + "/" + streamProxyDto.getStream());
updateStatus(false, streamProxyDto.getApp(), streamProxyDto.getStream());
}else {
updateStatus(true, streamProxyDto.getApp(), streamProxyDto.getStream());
}
}
}
@Override
@@ -289,8 +312,8 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
gbStreamMapper.batchDel(streamProxyItemList);
}
streamProxyMapper.deleteAutoRemoveItemByMediaServerId(mediaServerId);
// 其他的流设置未启用
streamProxyMapper.updateStatus(false, mediaServerId);
// 其他的流设置离线
streamProxyMapper.updateStatusByMediaServerId(false, mediaServerId);
String type = "PULL";
// 发送redis消息
@@ -314,4 +337,9 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
public void clean() {
}
@Override
public int updateStatus(boolean status, String app, String stream) {
return streamProxyMapper.updateStatus(status, app, stream);
}
}