From 605aa9c7f94c2c2d765c5a9bce20771b9863f3c5 Mon Sep 17 00:00:00 2001 From: 648540858 <456panlinlin> Date: Wed, 6 Apr 2022 11:07:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=87=8D=E5=90=AF=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=90=8E=E6=8B=89=E6=B5=81=E4=BB=A3=E7=90=86=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../subscribe/catalog/CatalogEventLister.java | 1 + .../service/impl/StreamProxyServiceImpl.java | 47 ++++++++++++++++++- .../vmp/storager/IVideoManagerStorage.java | 3 +- .../vmp/storager/dao/StreamProxyMapper.java | 4 +- .../impl/VideoManagerStorageImpl.java | 4 +- .../gb28181/media/MediaController.java | 3 -- 6 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java index 95578efb..f9546f0c 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java @@ -175,3 +175,4 @@ public class CatalogEventLister implements ApplicationListener { } } } + \ No newline at end of file diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java index aca30825..b30a5b23 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.service.impl; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.conf.SipConfig; @@ -285,9 +286,12 @@ public class StreamProxyServiceImpl implements IStreamProxyService { } streamProxyMapper.deleteAutoRemoveItemByMediaServerId(mediaServerId); + // 移除拉流代理生成的流信息 +// syncPullStream(mediaServerId); + // 恢复流代理, 只查找这个这个流媒体 List streamProxyListForEnable = storager.getStreamProxyListForEnableInMediaServer( - mediaServerId, true, false); + mediaServerId, true); for (StreamProxyItem streamProxyDto : streamProxyListForEnable) { logger.info("恢复流代理," + streamProxyDto.getApp() + "/" + streamProxyDto.getStream()); JSONObject jsonObject = addStreamProxyToZlm(streamProxyDto); @@ -339,4 +343,45 @@ public class StreamProxyServiceImpl implements IStreamProxyService { public int updateStatus(boolean status, String app, String stream) { return streamProxyMapper.updateStatus(status, app, stream); } + + private void syncPullStream(String mediaServerId){ + MediaServerItem mediaServer = mediaServerService.getOne(mediaServerId); + if (mediaServer != null) { + List allPullStream = redisCatchStorage.getStreams(mediaServerId, "PULL"); + if (allPullStream.size() > 0) { + zlmresTfulUtils.getMediaList(mediaServer, jsonObject->{ + Map stringStreamInfoMap = new HashMap<>(); + if (jsonObject.getInteger("code") == 0) { + JSONArray data = jsonObject.getJSONArray("data"); + if(data != null && data.size() > 0) { + for (int i = 0; i < data.size(); i++) { + JSONObject streamJSONObj = data.getJSONObject(i); + if ("rtmp".equals(streamJSONObj.getString("schema"))) { + StreamInfo streamInfo = new StreamInfo(); + String app = streamJSONObj.getString("app"); + String stream = streamJSONObj.getString("stream"); + streamInfo.setApp(app); + streamInfo.setStream(stream); + stringStreamInfoMap.put(app+stream, streamInfo); + } + } + } + } + if (stringStreamInfoMap.size() == 0) { + redisCatchStorage.removeStream(mediaServerId, "PULL"); + }else { + for (String key : stringStreamInfoMap.keySet()) { + StreamInfo streamInfo = stringStreamInfoMap.get(key); + if (stringStreamInfoMap.get(streamInfo.getApp() + streamInfo.getStream()) == null) { + redisCatchStorage.removeStream(mediaServerId, "PULL", streamInfo.getApp(), + streamInfo.getStream()); + } + } + } + }); + } + + } + + } } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java b/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java index 11d8b840..9d12eb58 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java @@ -401,10 +401,9 @@ public interface IVideoManagerStorage { * 根据媒体ID获取启用/不启用的代理列表 * @param id 媒体ID * @param enable 启用/不启用 - * @param status 状态 * @return */ - List getStreamProxyListForEnableInMediaServer(String id, boolean enable, boolean status); + List getStreamProxyListForEnableInMediaServer(String id, boolean enable); /** * 根据通道ID获取其所在设备 diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/StreamProxyMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/StreamProxyMapper.java index 2447ad98..29c0b012 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/StreamProxyMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/StreamProxyMapper.java @@ -51,8 +51,8 @@ public interface StreamProxyMapper { @Select("SELECT st.*, pgs.gbId, pgs.name, pgs.longitude, pgs.latitude FROM stream_proxy st " + "LEFT JOIN gb_stream pgs on st.app = pgs.app AND st.stream = pgs.stream " + - "WHERE st.enable=${enable} and st.status=${status} and st.mediaServerId = '${id}' order by st.createTime desc") - List selectForEnableInMediaServer(String id, boolean enable, boolean status); + "WHERE st.enable=${enable} and st.mediaServerId = #{id} order by st.createTime desc") + List selectForEnableInMediaServer(String id, boolean enable); @Select("SELECT st.*, pgs.gbId, pgs.name, pgs.longitude, pgs.latitude FROM stream_proxy st " + "LEFT JOIN gb_stream pgs on st.app = pgs.app AND st.stream = pgs.stream " + diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java index 16655735..439ecd87 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java @@ -911,8 +911,8 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { } @Override - public List getStreamProxyListForEnableInMediaServer(String id, boolean enable, boolean status) { - return streamProxyMapper.selectForEnableInMediaServer(id, enable, status); + public List getStreamProxyListForEnableInMediaServer(String id, boolean enable) { + return streamProxyMapper.selectForEnableInMediaServer(id, enable); } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java index a2619fad..d4995a01 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java @@ -65,7 +65,4 @@ public class MediaController { } return result; } - - - }