Merge pull request #1105 from lunasaw/dev-wvp-1011

feat:支持代理拉流状态检测,离线查询流是否离线
pull/1138/head
648540858 2023-10-27 15:41:26 +08:00 committed by GitHub
commit 47783946fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 0 deletions

View File

@ -215,6 +215,21 @@ public class ZLMRESTfulUtils {
}
}
public JSONObject isMediaOnline(MediaServerItem mediaServerItem, String app, String stream, String schema){
Map<String, Object> param = new HashMap<>();
if (app != null) {
param.put("app",app);
}
if (stream != null) {
param.put("stream",stream);
}
if (schema != null) {
param.put("schema",schema);
}
param.put("vhost","__defaultVhost__");
return sendPost(mediaServerItem, "isMediaOnline", param, null);
}
public JSONObject getMediaList(MediaServerItem mediaServerItem, String app, String stream, String schema, RequestCallback callback){
Map<String, Object> param = new HashMap<>();
if (app != null) {

View File

@ -9,6 +9,7 @@ import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory;
import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForServerStarted;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -35,15 +35,19 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
*
@ -560,4 +564,43 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
return new ResourceBaseInfo(total, online);
}
@Scheduled(cron = "* 0/10 * * * ?")
public void asyncCheckStreamProxyStatus() {
List<MediaServerItem> all = mediaServerService.getAllOnline();
if (CollectionUtils.isEmpty(all)){
return;
}
Map<String, MediaServerItem> serverItemMap = all.stream().collect(Collectors.toMap(MediaServerItem::getId, Function.identity(), (m1, m2) -> m1));
List<StreamProxyItem> list = videoManagerStorager.getStreamProxyListForEnable(true);
if (CollectionUtils.isEmpty(list)){
return;
}
for (StreamProxyItem streamProxyItem : list) {
MediaServerItem mediaServerItem = serverItemMap.get(streamProxyItem.getMediaServerId());
// TODO 支持其他 schema
JSONObject mediaInfo = zlmresTfulUtils.isMediaOnline(mediaServerItem, streamProxyItem.getApp(), streamProxyItem.getStream(), "rtsp");
if (mediaInfo == null){
streamProxyItem.setStatus(false);
} else {
if (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")) {
streamProxyItem.setStatus(true);
} else {
streamProxyItem.setStatus(false);
}
}
updateStreamProxy(streamProxyItem);
}
}
}