From 2b1e56973edb72f990ee0d4a1b3e6d06ba3aa4d7 Mon Sep 17 00:00:00 2001 From: panlinlin <648540858@qq.com> Date: 星期六, 03 四月 2021 21:19:08 +0800 Subject: [PATCH] 移除推流的国标关联移除未推流的数据 --- src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java | 62 ++++++++++++++++++++++--------- 1 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java index 51c6e1b..0065b21 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.media.zlm; +import java.util.List; import java.util.UUID; import com.alibaba.fastjson.JSON; @@ -8,7 +9,7 @@ import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorager; -import com.genersoft.iot.vmp.vmanager.service.IPlayService; +import com.genersoft.iot.vmp.service.IPlayService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -239,8 +240,9 @@ String streamId = json.getString("stream"); String schema = json.getString("schema"); boolean regist = json.getBoolean("regist"); - StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); + if ("rtp".equals(app) && !regist ) { + StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); if (streamInfo!=null){ redisCatchStorage.stopPlay(streamInfo); storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId()); @@ -249,8 +251,12 @@ redisCatchStorage.stopPlayback(streamInfo); } }else { - if (!"rtp".equals(app) && "rtsp".equals(schema)){ - zlmMediaListManager.updateMediaList(); + if (!"rtp".equals(app) && "rtmp".equals(schema)){ + if (regist) { + zlmMediaListManager.addMedia(app, streamId); + }else { + zlmMediaListManager.removeMedia(app, streamId); + } } } JSONObject ret = new JSONObject(); @@ -272,26 +278,35 @@ } String streamId = json.getString("stream"); + String app = json.getString("app"); StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); - JSONObject ret = new JSONObject(); - ret.put("code", 0); - ret.put("close", true); - if (streamInfo != null) { - if (redisCatchStorage.isChannelSendingRTP(streamInfo.getChannelId())) { - ret.put("close", false); - } else { + if ("rtp".equals(app)){ + JSONObject ret = new JSONObject(); + ret.put("code", 0); + ret.put("close", true); + if (streamInfo != null) { + if (redisCatchStorage.isChannelSendingRTP(streamInfo.getChannelId())) { + ret.put("close", false); + } else { + cmder.streamByeCmd(streamId); + redisCatchStorage.stopPlay(streamInfo); + storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId()); + } + }else{ cmder.streamByeCmd(streamId); - redisCatchStorage.stopPlay(streamInfo); - storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId()); + streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId); + redisCatchStorage.stopPlayback(streamInfo); } - }else{ - cmder.streamByeCmd(streamId); - streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId); - redisCatchStorage.stopPlayback(streamInfo); + return new ResponseEntity<String>(ret.toString(),HttpStatus.OK); + }else { + JSONObject ret = new JSONObject(); + ret.put("code", 0); + ret.put("close", false); + return new ResponseEntity<String>(ret.toString(),HttpStatus.OK); } - return new ResponseEntity<String>(ret.toString(),HttpStatus.OK); + } /** @@ -350,10 +365,21 @@ // String data = json.getString("data"); // List<MediaServerConfig> mediaServerConfigs = JSON.parseArray(JSON.toJSONString(json), MediaServerConfig.class); // MediaServerConfig mediaServerConfig = mediaServerConfigs.get(0); + + List<ZLMHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(ZLMHttpHookSubscribe.HookType.on_server_started); + if (subscribes != null && subscribes.size() > 0) { + for (ZLMHttpHookSubscribe.Event subscribe : subscribes) { + subscribe.response(json); + } + } + MediaServerConfig mediaServerConfig = JSON.toJavaObject(json, MediaServerConfig.class); mediaServerConfig.setWanIp(StringUtils.isEmpty(mediaWanIp)? mediaIp: mediaWanIp); mediaServerConfig.setLocalIP(mediaIp); redisCatchStorage.updateMediaInfo(mediaServerConfig); + + // 閲嶆柊鍙戣捣浠g悊 + JSONObject ret = new JSONObject(); ret.put("code", 0); ret.put("msg", "success"); -- Gitblit v1.8.0