Commit 47783946fe62819317f73eecc377d0c0316e0154
Committed by
GitHub
Merge pull request #1105 from lunasaw/dev-wvp-1011
feat:支持代理拉流状态检测,离线查询流是否离线
Showing
3 changed files
with
59 additions
and
0 deletions
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java
| @@ -215,6 +215,21 @@ public class ZLMRESTfulUtils { | @@ -215,6 +215,21 @@ public class ZLMRESTfulUtils { | ||
| 215 | } | 215 | } |
| 216 | } | 216 | } |
| 217 | 217 | ||
| 218 | + public JSONObject isMediaOnline(MediaServerItem mediaServerItem, String app, String stream, String schema){ | ||
| 219 | + Map<String, Object> param = new HashMap<>(); | ||
| 220 | + if (app != null) { | ||
| 221 | + param.put("app",app); | ||
| 222 | + } | ||
| 223 | + if (stream != null) { | ||
| 224 | + param.put("stream",stream); | ||
| 225 | + } | ||
| 226 | + if (schema != null) { | ||
| 227 | + param.put("schema",schema); | ||
| 228 | + } | ||
| 229 | + param.put("vhost","__defaultVhost__"); | ||
| 230 | + return sendPost(mediaServerItem, "isMediaOnline", param, null); | ||
| 231 | + } | ||
| 232 | + | ||
| 218 | public JSONObject getMediaList(MediaServerItem mediaServerItem, String app, String stream, String schema, RequestCallback callback){ | 233 | public JSONObject getMediaList(MediaServerItem mediaServerItem, String app, String stream, String schema, RequestCallback callback){ |
| 219 | Map<String, Object> param = new HashMap<>(); | 234 | Map<String, Object> param = new HashMap<>(); |
| 220 | if (app != null) { | 235 | if (app != null) { |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java
| @@ -9,6 +9,7 @@ import com.genersoft.iot.vmp.gb28181.event.EventPublisher; | @@ -9,6 +9,7 @@ import com.genersoft.iot.vmp.gb28181.event.EventPublisher; | ||
| 9 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; | 9 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; |
| 10 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForServerStarted; | 10 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForServerStarted; |
| 11 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | 11 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 12 | +import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; | ||
| 12 | import com.genersoft.iot.vmp.service.IMediaServerService; | 13 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| 13 | import org.slf4j.Logger; | 14 | import org.slf4j.Logger; |
| 14 | import org.slf4j.LoggerFactory; | 15 | import org.slf4j.LoggerFactory; |
src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
| @@ -35,15 +35,19 @@ import org.slf4j.Logger; | @@ -35,15 +35,19 @@ import org.slf4j.Logger; | ||
| 35 | import org.slf4j.LoggerFactory; | 35 | import org.slf4j.LoggerFactory; |
| 36 | import org.springframework.beans.factory.annotation.Autowired; | 36 | import org.springframework.beans.factory.annotation.Autowired; |
| 37 | import org.springframework.jdbc.datasource.DataSourceTransactionManager; | 37 | import org.springframework.jdbc.datasource.DataSourceTransactionManager; |
| 38 | +import org.springframework.scheduling.annotation.Scheduled; | ||
| 38 | import org.springframework.stereotype.Service; | 39 | import org.springframework.stereotype.Service; |
| 39 | import org.springframework.transaction.TransactionDefinition; | 40 | import org.springframework.transaction.TransactionDefinition; |
| 40 | import org.springframework.transaction.TransactionStatus; | 41 | import org.springframework.transaction.TransactionStatus; |
| 42 | +import org.springframework.util.CollectionUtils; | ||
| 41 | import org.springframework.util.ObjectUtils; | 43 | import org.springframework.util.ObjectUtils; |
| 42 | 44 | ||
| 43 | import java.util.HashMap; | 45 | import java.util.HashMap; |
| 44 | import java.util.List; | 46 | import java.util.List; |
| 45 | import java.util.Map; | 47 | import java.util.Map; |
| 46 | import java.util.UUID; | 48 | import java.util.UUID; |
| 49 | +import java.util.function.Function; | ||
| 50 | +import java.util.stream.Collectors; | ||
| 47 | 51 | ||
| 48 | /** | 52 | /** |
| 49 | * 视频代理业务 | 53 | * 视频代理业务 |
| @@ -560,4 +564,43 @@ public class StreamProxyServiceImpl implements IStreamProxyService { | @@ -560,4 +564,43 @@ public class StreamProxyServiceImpl implements IStreamProxyService { | ||
| 560 | 564 | ||
| 561 | return new ResourceBaseInfo(total, online); | 565 | return new ResourceBaseInfo(total, online); |
| 562 | } | 566 | } |
| 567 | + | ||
| 568 | + | ||
| 569 | + @Scheduled(cron = "* 0/10 * * * ?") | ||
| 570 | + public void asyncCheckStreamProxyStatus() { | ||
| 571 | + | ||
| 572 | + List<MediaServerItem> all = mediaServerService.getAllOnline(); | ||
| 573 | + | ||
| 574 | + if (CollectionUtils.isEmpty(all)){ | ||
| 575 | + return; | ||
| 576 | + } | ||
| 577 | + | ||
| 578 | + Map<String, MediaServerItem> serverItemMap = all.stream().collect(Collectors.toMap(MediaServerItem::getId, Function.identity(), (m1, m2) -> m1)); | ||
| 579 | + | ||
| 580 | + List<StreamProxyItem> list = videoManagerStorager.getStreamProxyListForEnable(true); | ||
| 581 | + | ||
| 582 | + if (CollectionUtils.isEmpty(list)){ | ||
| 583 | + return; | ||
| 584 | + } | ||
| 585 | + | ||
| 586 | + for (StreamProxyItem streamProxyItem : list) { | ||
| 587 | + | ||
| 588 | + MediaServerItem mediaServerItem = serverItemMap.get(streamProxyItem.getMediaServerId()); | ||
| 589 | + | ||
| 590 | + // TODO 支持其他 schema | ||
| 591 | + JSONObject mediaInfo = zlmresTfulUtils.isMediaOnline(mediaServerItem, streamProxyItem.getApp(), streamProxyItem.getStream(), "rtsp"); | ||
| 592 | + | ||
| 593 | + if (mediaInfo == null){ | ||
| 594 | + streamProxyItem.setStatus(false); | ||
| 595 | + } else { | ||
| 596 | + if (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")) { | ||
| 597 | + streamProxyItem.setStatus(true); | ||
| 598 | + } else { | ||
| 599 | + streamProxyItem.setStatus(false); | ||
| 600 | + } | ||
| 601 | + } | ||
| 602 | + | ||
| 603 | + updateStreamProxy(streamProxyItem); | ||
| 604 | + } | ||
| 605 | + } | ||
| 563 | } | 606 | } |