From e531e497c823a1216be6462acd94fd2262465324 Mon Sep 17 00:00:00 2001 From: panlinlin <648540858@qq.com> Date: Sat, 29 Jun 2024 23:35:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../streamProxy/dao/StreamProxyMapper.java | 3 ++ .../service/impl/StreamProxyServiceImpl.java | 47 +++++++++++-------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/streamProxy/dao/StreamProxyMapper.java b/src/main/java/com/genersoft/iot/vmp/streamProxy/dao/StreamProxyMapper.java index 2561b7f3..7be3d821 100755 --- a/src/main/java/com/genersoft/iot/vmp/streamProxy/dao/StreamProxyMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/streamProxy/dao/StreamProxyMapper.java @@ -92,4 +92,7 @@ public interface StreamProxyMapper { * 查询设置了自动移除并且没有国标编号的代理 */ List selectWithAutoRemoveAndWithoutGbDeviceIdByMediaServerId(String mediaServerId); + + int delete(int id); + } diff --git a/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyServiceImpl.java index ac957963..4c29585f 100755 --- a/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyServiceImpl.java @@ -191,8 +191,6 @@ public class StreamProxyServiceImpl implements IStreamProxyService { return null; } - - /** * 新增代理流 */ @@ -233,24 +231,22 @@ public class StreamProxyServiceImpl implements IStreamProxyService { } @Override + @Transactional public void del(String app, String stream) { - StreamProxy streamProxyItem = streamProxyMapper.selectOne(app, stream); - if (streamProxyItem != null) { - gbStreamService.sendCatalogMsg(streamProxyItem, CatalogEvent.DEL); - - // 如果关联了国标那么移除关联 - platformGbStreamMapper.delByAppAndStream(app, stream); - gbStreamMapper.del(app, stream); - streamProxyMapper.del(app, stream); - redisCatchStorage.removeStream(streamProxyItem.getMediaServerId(), "PULL", app, stream); - redisCatchStorage.removeStream(streamProxyItem.getMediaServerId(), "PUSH", app, stream); - Boolean result = removeStreamProxyFromZlm(streamProxyItem); - if (result != null && result) { - log.info("[移除代理]: 代理: {}/{}, 从zlm移除成功", app, stream); - }else { - log.info("[移除代理]: 代理: {}/{}, 从zlm移除失败", app, stream); + StreamProxy streamProxy = streamProxyMapper.selectOne(app, stream); + if (streamProxy == null) { + return; + } + if (streamProxy.getStreamKey() != null) { + MediaServer mediaServer = mediaServerService.getOne(streamProxy.getMediaServerId()); + if (mediaServer != null) { + mediaServerService.stopProxy(mediaServer, streamProxy.getStreamKey()); } } + if (streamProxy.getGbId() > 0) { + gbChannelService.delete(streamProxy.getGbId()); + } + streamProxyMapper.delete(streamProxy.getId()); } @Override @@ -306,9 +302,20 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @Override public void zlmServerOnline(String mediaServerId) { + MediaServer mediaServer = mediaServerService.getOne(mediaServerId); + if (mediaServer == null) { + return; + } + // 这里主要是控制数据库/redis缓存/以及zlm中存在的代理流 三者状态一致。以数据库中数据为根本 + List streamProxies = streamProxyMapper.selectForEnableInMediaServer(mediaServerId, true); + if (streamProxies.isEmpty()){ + return; + } + + // 移除开启了无人观看自动移除的流 - List streamProxyItemList = streamProxyMapper.selectWithAutoRemoveAndWithoutGbDeviceIdByMediaServerId(mediaServerId); - streamProxyMapper.deleteAutoRemoveItemByMediaServerId(mediaServerId); +// List streamProxyItemList = streamProxyMapper.selectWithAutoRemoveAndWithoutGbDeviceIdByMediaServerId(mediaServerId); + streamProxyMapper.deleteWithAutoRemoveAndWithoutGbDeviceIdByMediaServerId(mediaServerId); // 移除拉流代理生成的流信息 syncPullStream(mediaServerId); @@ -318,7 +325,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { mediaServerId, true); for (StreamProxy streamProxyDto : streamProxyListForEnable) { log.info("恢复流代理," + streamProxyDto.getApp() + "/" + streamProxyDto.getStream()); - mediaServerService.startProxy(me) + StreamInfo streamInfo = mediaServerService.startProxy(mediaServer, streamProxy); WVPResult wvpResult = addStreamProxyToZlm(streamProxyDto); if (wvpResult == null) { // 设置为离线