From c5f2aba9b20089f184ce175b58a33a881ea9e0b1 Mon Sep 17 00:00:00 2001 From: panlinlin <648540858@qq.com> Date: 星期五, 16 四月 2021 18:23:13 +0800 Subject: [PATCH] 修复 流已经关闭后,再次调用关闭流的接口,返回超时 --- src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java | 103 +++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 75 insertions(+), 28 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 51f61ef..183a544 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,14 +1,16 @@ package com.genersoft.iot.vmp.media.zlm; +import java.util.List; import java.util.UUID; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.conf.MediaServerConfig; 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; @@ -51,8 +53,8 @@ @Autowired private IRedisCatchStorage redisCatchStorage; - // @Autowired - // private ZLMRESTfulUtils zlmresTfulUtils; + @Autowired + private ZLMMediaListManager zlmMediaListManager; @Autowired private ZLMHttpHookSubscribe subscribe; @@ -115,6 +117,10 @@ if (logger.isDebugEnabled()) { logger.debug("ZLM HOOK on_play API璋冪敤锛屽弬鏁帮細" + json.toString()); + } + ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_play, json); + if (subscribe != null ) { + subscribe.response(json); } JSONObject ret = new JSONObject(); ret.put("code", 0); @@ -214,7 +220,7 @@ // String app = json.getString("app"); // String stream = json.getString("stream"); - ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, json); + ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_shell_login, json); if (subscribe != null) subscribe.response(json); JSONObject ret = new JSONObject(); @@ -234,20 +240,41 @@ if (logger.isDebugEnabled()) { logger.debug("ZLM HOOK on_stream_changed API璋冪敤锛屽弬鏁帮細" + json.toString()); } + + ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, json); + if (subscribe != null) subscribe.response(json); + // 娴佹秷澶辩Щ闄edis play String app = json.getString("app"); String streamId = json.getString("stream"); + String schema = json.getString("schema"); + JSONArray tracks = json.getJSONArray("tracks"); boolean regist = json.getBoolean("regist"); - StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); - if ("rtp".equals(app) && !regist ) { - if (streamInfo!=null){ - redisCatchStorage.stopPlay(streamInfo); - storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId()); - }else{ - streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId); - redisCatchStorage.stopPlayback(streamInfo); + if (tracks != null) { + System.out.println("222222" + schema); + } + if ("rtmp".equals(schema)){ + + if ("rtp".equals(app) && !regist ) { + StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); + if (streamInfo!=null){ + redisCatchStorage.stopPlay(streamInfo); + storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId()); + }else{ + streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId); + redisCatchStorage.stopPlayback(streamInfo); + } + }else { + if (!"rtp".equals(app) ){ + if (regist) { + zlmMediaListManager.addMedia(app, streamId); + }else { + zlmMediaListManager.removeMedia(app, streamId); + } + } } } + JSONObject ret = new JSONObject(); ret.put("code", 0); ret.put("msg", "success"); @@ -267,26 +294,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 { - cmder.streamByeCmd(streamId); - redisCatchStorage.stopPlay(streamInfo); - storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId()); + 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(streamInfo.getDeviceID(), streamInfo.getChannelId()); + redisCatchStorage.stopPlay(streamInfo); + storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId()); + } + }else{ + cmder.streamByeCmd(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); + } /** @@ -304,7 +340,7 @@ String app = json.getString("app"); String streamId = json.getString("stream"); StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); - if ("rtp".equals(app) && streamId.indexOf("gb_play") > -1 && streamInfo == null) { + if ("rtp".equals(app) && streamId.contains("gb_play") && streamInfo == null) { String[] s = streamId.split("_"); if (s.length == 4) { String deviceId = s[2]; @@ -345,10 +381,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